53
53
#endif // MBED_CONF_PPP_CELL_IFACE_AT_PARSER_TIMEOUT
54
54
55
55
static bool initialized;
56
- static bool set_credentials_api_used;
57
56
static bool set_sim_pin_check_request;
58
57
static bool change_pin;
59
58
static device_info dev_info;
@@ -257,7 +256,7 @@ PPPCellularInterface::PPPCellularInterface(FileHandle *fh, bool debug)
257
256
_new_pin = NULL ;
258
257
_pin = NULL ;
259
258
_at = NULL ;
260
- _apn = " internet " ;
259
+ _apn = NULL ;
261
260
_uname = NULL ;
262
261
_pwd = NULL ;
263
262
_fh = fh;
@@ -500,16 +499,13 @@ nsapi_error_t PPPCellularInterface::setup_context_and_credentials()
500
499
}
501
500
502
501
void PPPCellularInterface::set_credentials (const char *apn, const char *uname,
503
- const char *pwd)
502
+ const char *pwd)
504
503
{
505
504
_apn = apn;
506
505
_uname = uname;
507
506
_pwd = pwd;
508
- set_credentials_api_used = true ;
509
507
}
510
508
511
-
512
-
513
509
void PPPCellularInterface::setup_at_parser ()
514
510
{
515
511
if (_at) {
@@ -542,20 +538,15 @@ nsapi_error_t PPPCellularInterface::connect(const char *sim_pin, const char *apn
542
538
return NSAPI_ERROR_PARAMETER;
543
539
}
544
540
545
- if (apn) {
546
- _apn = apn;
547
- }
541
+ _pin = sim_pin;
548
542
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);
555
548
}
556
549
557
- _pin = sim_pin;
558
-
559
550
return connect ();
560
551
}
561
552
@@ -565,7 +556,21 @@ nsapi_error_t PPPCellularInterface::connect()
565
556
bool success;
566
557
bool did_init = false ;
567
558
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
+
569
574
if (is_connected ()) {
570
575
return NSAPI_ERROR_IS_CONNECTED;
571
576
} else if (_connect_status == NSAPI_STATUS_CONNECTING) {
@@ -580,7 +585,6 @@ nsapi_error_t PPPCellularInterface::connect()
580
585
do {
581
586
retry_init:
582
587
583
-
584
588
retcode = NSAPI_ERROR_OK;
585
589
586
590
/* setup AT parser */
@@ -643,7 +647,7 @@ nsapi_error_t PPPCellularInterface::connect()
643
647
}
644
648
645
649
#if MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
646
- if (apn_config) {
650
+ if (!user_specified_apn && apn_config) {
647
651
_apn = _APN_GET (apn_config);
648
652
_uname = _APN_GET (apn_config);
649
653
_pwd = _APN_GET (apn_config);
@@ -672,6 +676,8 @@ nsapi_error_t PPPCellularInterface::connect()
672
676
success = _at->send (" AT" ) && _at->recv (" OK" );
673
677
}
674
678
679
+ tr_info (" The APN being used is %s.\n " , _apn);
680
+
675
681
/* Attempt to enter data mode */
676
682
success = set_atd (_at); // enter into Data mode with the modem
677
683
if (!success) {
0 commit comments