Skip to content

Commit 2fe3223

Browse files
committed
Make MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP default in mbed_lib.json while
ensuring that, if there is a user-specified APN, it is still used.
1 parent 1d1eef4 commit 2fe3223

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

features/netsocket/cellular/generic_modem_driver/PPPCellularInterface.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#endif //MBED_CONF_PPP_CELL_IFACE_AT_PARSER_TIMEOUT
5454

5555
static bool initialized;
56-
static bool set_credentials_api_used;
5756
static bool set_sim_pin_check_request;
5857
static bool change_pin;
5958
static device_info dev_info;
@@ -257,7 +256,7 @@ PPPCellularInterface::PPPCellularInterface(FileHandle *fh, bool debug)
257256
_new_pin = NULL;
258257
_pin = NULL;
259258
_at = NULL;
260-
_apn = "internet";
259+
_apn = NULL;
261260
_uname = NULL;
262261
_pwd = NULL;
263262
_fh = fh;
@@ -500,16 +499,13 @@ nsapi_error_t PPPCellularInterface::setup_context_and_credentials()
500499
}
501500

502501
void PPPCellularInterface::set_credentials(const char *apn, const char *uname,
503-
const char *pwd)
502+
const char *pwd)
504503
{
505504
_apn = apn;
506505
_uname = uname;
507506
_pwd = pwd;
508-
set_credentials_api_used = true;
509507
}
510508

511-
512-
513509
void PPPCellularInterface::setup_at_parser()
514510
{
515511
if (_at) {
@@ -542,20 +538,15 @@ nsapi_error_t PPPCellularInterface::connect(const char *sim_pin, const char *apn
542538
return NSAPI_ERROR_PARAMETER;
543539
}
544540

545-
if (apn) {
546-
_apn = apn;
547-
}
541+
_pin = sim_pin;
548542

549-
if (uname && pwd) {
550-
_uname = uname;
551-
_pwd = pwd;
552-
} else {
553-
_uname = NULL;
554-
_pwd = NULL;
543+
if (apn) {
544+
if (pwd && !uname) {
545+
return NSAPI_ERROR_PARAMETER;
546+
}
547+
set_credentials(apn, uname, pwd);
555548
}
556549

557-
_pin = sim_pin;
558-
559550
return connect();
560551
}
561552

@@ -565,7 +556,21 @@ nsapi_error_t PPPCellularInterface::connect()
565556
bool success;
566557
bool did_init = false;
567558
const char *apn_config = NULL;
568-
559+
bool user_specified_apn = false;
560+
561+
/* If the user has specified the APN then use that or,
562+
* if we are not using the APN database, set _apn to
563+
* "internet" as a best guess
564+
*/
565+
if (_apn) {
566+
user_specified_apn = true;
567+
} else {
568+
#ifndef MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
569+
_apn = "internet";
570+
user_specified_apn = true;
571+
#endif
572+
}
573+
569574
if (is_connected()) {
570575
return NSAPI_ERROR_IS_CONNECTED;
571576
} else if (_connect_status == NSAPI_STATUS_CONNECTING) {
@@ -580,7 +585,6 @@ nsapi_error_t PPPCellularInterface::connect()
580585
do {
581586
retry_init:
582587

583-
584588
retcode = NSAPI_ERROR_OK;
585589

586590
/* setup AT parser */
@@ -643,7 +647,7 @@ nsapi_error_t PPPCellularInterface::connect()
643647
}
644648

645649
#if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
646-
if (apn_config) {
650+
if (!user_specified_apn && apn_config) {
647651
_apn = _APN_GET(apn_config);
648652
_uname = _APN_GET(apn_config);
649653
_pwd = _APN_GET(apn_config);
@@ -672,6 +676,8 @@ nsapi_error_t PPPCellularInterface::connect()
672676
success = _at->send("AT") && _at->recv("OK");
673677
}
674678

679+
tr_info("The APN being used is %s.\n", _apn);
680+
675681
/* Attempt to enter data mode */
676682
success = set_atd(_at); //enter into Data mode with the modem
677683
if (!success) {

features/netsocket/cellular/generic_modem_driver/mbed_lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ppp-cell-iface",
33
"config": {
44
"baud-rate": 115200,
5-
"apn-lookup": false,
5+
"apn-lookup": true,
66
"at-parser-buffer-size": 256,
77
"at-parser-timeout": 8000
88
}

0 commit comments

Comments
 (0)