@@ -43,7 +43,7 @@ namespace mbed
43
43
CellularConnectionFSM::CellularConnectionFSM () :
44
44
_serial (0 ), _state(STATE_INIT), _next_state(_state), _status_callback(0 ), _event_status_cb(0 ), _network(0 ), _power(0 ), _sim(0 ),
45
45
_queue (8 * EVENTS_EVENT_SIZE), _queue_thread(0 ), _cellularDevice(0 ), _retry_count(0 ), _event_timeout(-1 ),
46
- _at_queue (8 * EVENTS_EVENT_SIZE), _event_id(0 )
46
+ _at_queue (8 * EVENTS_EVENT_SIZE), _event_id(0 ), _plmn( 0 )
47
47
{
48
48
memset (_sim_pin, 0 , sizeof (_sim_pin));
49
49
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@@ -146,6 +146,11 @@ void CellularConnectionFSM::set_sim_pin(const char * sim_pin)
146
146
_sim_pin[sizeof (_sim_pin)-1 ] = ' \0 ' ;
147
147
}
148
148
149
+ void CellularConnectionFSM::set_plmn (const char * plmn)
150
+ {
151
+ _plmn = plmn;
152
+ }
153
+
149
154
bool CellularConnectionFSM::open_sim ()
150
155
{
151
156
CellularSIM::SimState state = CellularSIM::SimStateUnknown;
@@ -175,11 +180,10 @@ bool CellularConnectionFSM::open_sim()
175
180
return state == CellularSIM::SimStateReady;
176
181
}
177
182
178
- bool CellularConnectionFSM::set_network_registration (char *plmn )
183
+ bool CellularConnectionFSM::set_network_registration ()
179
184
{
180
- nsapi_error_t error = _network->set_registration (plmn);
181
- if (error != NSAPI_ERROR_OK) {
182
- tr_error (" Set network registration mode failing (%d)" , error);
185
+ if (_network->set_registration (_plmn) != NSAPI_ERROR_OK) {
186
+ tr_error (" Failed to set network registration." );
183
187
return false ;
184
188
}
185
189
return true ;
@@ -279,8 +283,12 @@ void CellularConnectionFSM::report_failure(const char* msg)
279
283
280
284
const char * CellularConnectionFSM::get_state_string (CellularState state)
281
285
{
282
- static const char *strings[] = { " Init" , " Power" , " Device ready" , " SIM pin" , " Registering network" , " Attaching network" , " Activating PDP Context" , " Connecting network" , " Connected" };
286
+ #if MBED_CONF_MBED_TRACE_ENABLE
287
+ static const char *strings[] = { " Init" , " Power" , " Device ready" , " SIM pin" , " Registering network" , " Attaching network" , " Connecting network" , " Connected" };
283
288
return strings[state];
289
+ #else
290
+ return NULL ;
291
+ #endif // #if MBED_CONF_MBED_TRACE_ENABLE
284
292
}
285
293
286
294
nsapi_error_t CellularConnectionFSM::is_automatic_registering (bool & auto_reg)
@@ -416,15 +424,26 @@ void CellularConnectionFSM::state_registering()
416
424
{
417
425
_cellularDevice->set_timeout (TIMEOUT_NETWORK);
418
426
if (is_registered ()) {
419
- // we are already registered, go to attach
420
- enter_to_state (STATE_ATTACHING_NETWORK);
421
- } else {
422
- bool auto_reg = false ;
423
- nsapi_error_t err = is_automatic_registering (auto_reg);
424
- if (err == NSAPI_ERROR_OK && !auto_reg) { // when we support plmn add this : || plmn
425
- // automatic registering is not on, set registration and retry
427
+ if (_plmn && _retry_count == 0 ) {
428
+ // we don't know which network we are registered, try to register to specific network
426
429
_cellularDevice->set_timeout (TIMEOUT_REGISTRATION);
427
430
set_network_registration ();
431
+ retry_state_or_fail ();
432
+ } else {
433
+ // we are already registered, go to attach
434
+ enter_to_state (STATE_ATTACHING_NETWORK);
435
+ }
436
+ } else {
437
+ if (_plmn) {
438
+ set_network_registration ();
439
+ } else {
440
+ bool auto_reg = false ;
441
+ nsapi_error_t err = is_automatic_registering (auto_reg);
442
+ if (err == NSAPI_ERROR_OK && !auto_reg) {
443
+ // automatic registering is not on, set registration and retry
444
+ _cellularDevice->set_timeout (TIMEOUT_REGISTRATION);
445
+ set_network_registration ();
446
+ }
428
447
}
429
448
retry_state_or_fail ();
430
449
}
0 commit comments