@@ -299,7 +299,7 @@ void AT_CellularContext::delete_current_context()
299299 _at.at_cmd_discard (" +CGDCONT" , " =" , " %d" , _cid);
300300
301301 if (_at.get_last_error () == NSAPI_ERROR_OK) {
302- _cid = - 1 ;
302+ set_cid (- 1 ) ;
303303 _new_context_set = false ;
304304 }
305305
@@ -347,7 +347,7 @@ bool AT_CellularContext::get_context()
347347{
348348 _at.cmd_start_stop (" +CGDCONT" , " ?" );
349349 _at.resp_start (" +CGDCONT:" );
350- _cid = - 1 ;
350+ set_cid (- 1 ) ;
351351 int cid_max = 0 ; // needed when creating new context
352352 char apn[MAX_ACCESSPOINT_NAME_LENGTH];
353353 int apn_len = 0 ;
@@ -373,7 +373,7 @@ bool AT_CellularContext::get_context()
373373 if (get_property (pdp_type_t_to_cellular_property (pdp_type)) ||
374374 ((pdp_type == IPV4V6_PDP_TYPE && (get_property (PROPERTY_IPV4_PDP_TYPE) && get_property (PROPERTY_IPV6_PDP_TYPE))) && !_nonip_req)) {
375375 _pdp_type = pdp_type;
376- _cid = cid;
376+ set_cid ( cid) ;
377377 }
378378 }
379379 }
@@ -423,7 +423,7 @@ bool AT_CellularContext::set_new_context(int cid)
423423
424424 if (success) {
425425 _pdp_type = pdp_type;
426- _cid = cid;
426+ set_cid ( cid) ;
427427 _new_context_set = true ;
428428 tr_info (" New PDP context %d, type %d" , _cid, pdp_type);
429429 }
@@ -661,7 +661,7 @@ void AT_CellularContext::do_disconnect()
661661 if (_new_context_set) {
662662 delete_current_context ();
663663 }
664- _cid = - 1 ;
664+ set_cid (- 1 ) ;
665665 _cb_data.error = NSAPI_ERROR_NO_CONNECTION;
666666 }
667667
@@ -697,7 +697,7 @@ void AT_CellularContext::do_disconnect()
697697 if (_new_context_set) {
698698 delete_current_context ();
699699 }
700- _cid = - 1 ;
700+ set_cid (- 1 ) ;
701701 _cb_data.error = _at.unlock_return_error ();
702702}
703703
@@ -994,13 +994,15 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
994994 } else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) {
995995 tr_info (" cellular_callback: PPP mode and NSAPI_STATUS_DISCONNECTED" );
996996 _cb_data.error = NSAPI_ERROR_NO_CONNECTION;
997+ set_cid (-1 );
997998 _is_connected = false ;
998999 ppp_disconnected ();
9991000 }
10001001 }
10011002#else
10021003 if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) {
10031004 tr_info (" cb: CellularContext disconnected" );
1005+ set_cid (-1 );
10041006 _is_connected = false ;
10051007 }
10061008#endif // NSAPI_PPP_AVAILABLE
@@ -1065,3 +1067,11 @@ void AT_CellularContext::set_disconnect()
10651067 _is_connected = false ;
10661068 _device->cellular_callback (NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED, this );
10671069}
1070+
1071+ void AT_CellularContext::set_cid (int cid)
1072+ {
1073+ _cid = cid;
1074+ if (_stack) {
1075+ static_cast <AT_CellularStack *>(_stack)->set_cid (_cid);
1076+ }
1077+ }
0 commit comments