Skip to content

Make APN lookup the default behaviour for PPPCellularInterface #6166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#endif //MBED_CONF_PPP_CELL_IFACE_AT_PARSER_TIMEOUT

static bool initialized;
static bool set_credentials_api_used;
static bool set_sim_pin_check_request;
static bool change_pin;
static device_info dev_info;
Expand Down Expand Up @@ -257,7 +256,7 @@ PPPCellularInterface::PPPCellularInterface(FileHandle *fh, bool debug)
_new_pin = NULL;
_pin = NULL;
_at = NULL;
_apn = "internet";
_apn = NULL;
_uname = NULL;
_pwd = NULL;
_fh = fh;
Expand Down Expand Up @@ -500,16 +499,13 @@ nsapi_error_t PPPCellularInterface::setup_context_and_credentials()
}

void PPPCellularInterface::set_credentials(const char *apn, const char *uname,
const char *pwd)
const char *pwd)
{
_apn = apn;
_uname = uname;
_pwd = pwd;
set_credentials_api_used = true;
}



void PPPCellularInterface::setup_at_parser()
{
if (_at) {
Expand Down Expand Up @@ -542,20 +538,15 @@ nsapi_error_t PPPCellularInterface::connect(const char *sim_pin, const char *apn
return NSAPI_ERROR_PARAMETER;
}

if (apn) {
_apn = apn;
}
_pin = sim_pin;

if (uname && pwd) {
_uname = uname;
_pwd = pwd;
} else {
_uname = NULL;
_pwd = NULL;
if (apn) {
if (pwd && !uname) {
return NSAPI_ERROR_PARAMETER;
}
set_credentials(apn, uname, pwd);
}

_pin = sim_pin;

return connect();
}

Expand All @@ -565,7 +556,21 @@ nsapi_error_t PPPCellularInterface::connect()
bool success;
bool did_init = false;
const char *apn_config = NULL;

bool user_specified_apn = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you have connect(credentials) actually call set_credentials() itself. Just to make sure that call is functionally equivalent to the set_credentials/connect pair, as appears to be the intent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.


/* If the user has specified the APN then use that or,
* if we are not using the APN database, set _apn to
* "internet" as a best guess
*/
if (_apn) {
user_specified_apn = true;
} else {
#ifndef MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
_apn = "internet";
user_specified_apn = true;
#endif
}

if (is_connected()) {
return NSAPI_ERROR_IS_CONNECTED;
} else if (_connect_status == NSAPI_STATUS_CONNECTING) {
Expand All @@ -580,7 +585,6 @@ nsapi_error_t PPPCellularInterface::connect()
do {
retry_init:


retcode = NSAPI_ERROR_OK;

/* setup AT parser */
Expand Down Expand Up @@ -643,7 +647,7 @@ nsapi_error_t PPPCellularInterface::connect()
}

#if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
if (apn_config) {
if (!user_specified_apn && apn_config) {
_apn = _APN_GET(apn_config);
_uname = _APN_GET(apn_config);
_pwd = _APN_GET(apn_config);
Expand Down Expand Up @@ -672,6 +676,8 @@ nsapi_error_t PPPCellularInterface::connect()
success = _at->send("AT") && _at->recv("OK");
}

tr_info("The APN being used is %s.\n", _apn);

/* Attempt to enter data mode */
success = set_atd(_at); //enter into Data mode with the modem
if (!success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ppp-cell-iface",
"config": {
"baud-rate": 115200,
"apn-lookup": false,
"apn-lookup": true,
"at-parser-buffer-size": 256,
"at-parser-timeout": 8000
}
Expand Down