diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index 4983d117af..8ecf796b21 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -279,6 +279,10 @@ void AT_CellularContext::set_disconnect() { } +void AT_CellularContext::set_cid(int cid) +{ +} + void AT_CellularContext::do_connect_with_retry() { diff --git a/UNITTESTS/stubs/AT_CellularStack_stub.cpp b/UNITTESTS/stubs/AT_CellularStack_stub.cpp index 998cd20c93..054396a2a9 100644 --- a/UNITTESTS/stubs/AT_CellularStack_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularStack_stub.cpp @@ -94,3 +94,6 @@ void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(voi { } +void AT_CellularStack::set_cid(int cid) +{ +} diff --git a/UNITTESTS/target_h/myCellularContext.h b/UNITTESTS/target_h/myCellularContext.h index 0da0096fd2..172e4e0ff2 100644 --- a/UNITTESTS/target_h/myCellularContext.h +++ b/UNITTESTS/target_h/myCellularContext.h @@ -216,6 +216,10 @@ public: { }; + void set_cid(int cid) + { + }; + void do_connect_with_retry() { }; diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 2d782a5c85..e0e192e8fb 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -299,7 +299,7 @@ void AT_CellularContext::delete_current_context() _at.at_cmd_discard("+CGDCONT", "=", "%d", _cid); if (_at.get_last_error() == NSAPI_ERROR_OK) { - _cid = -1; + set_cid(-1); _new_context_set = false; } @@ -347,7 +347,7 @@ bool AT_CellularContext::get_context() { _at.cmd_start_stop("+CGDCONT", "?"); _at.resp_start("+CGDCONT:"); - _cid = -1; + set_cid(-1); int cid_max = 0; // needed when creating new context char apn[MAX_ACCESSPOINT_NAME_LENGTH]; int apn_len = 0; @@ -373,7 +373,7 @@ bool AT_CellularContext::get_context() if (get_property(pdp_type_t_to_cellular_property(pdp_type)) || ((pdp_type == IPV4V6_PDP_TYPE && (get_property(PROPERTY_IPV4_PDP_TYPE) && get_property(PROPERTY_IPV6_PDP_TYPE))) && !_nonip_req)) { _pdp_type = pdp_type; - _cid = cid; + set_cid(cid); } } } @@ -423,7 +423,7 @@ bool AT_CellularContext::set_new_context(int cid) if (success) { _pdp_type = pdp_type; - _cid = cid; + set_cid(cid); _new_context_set = true; tr_info("New PDP context %d, type %d", _cid, pdp_type); } @@ -661,7 +661,7 @@ void AT_CellularContext::do_disconnect() if (_new_context_set) { delete_current_context(); } - _cid = -1; + set_cid(-1); _cb_data.error = NSAPI_ERROR_NO_CONNECTION; } @@ -697,7 +697,7 @@ void AT_CellularContext::do_disconnect() if (_new_context_set) { delete_current_context(); } - _cid = -1; + set_cid(-1); _cb_data.error = _at.unlock_return_error(); } @@ -994,6 +994,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) } else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) { tr_info("cellular_callback: PPP mode and NSAPI_STATUS_DISCONNECTED"); _cb_data.error = NSAPI_ERROR_NO_CONNECTION; + set_cid(-1); _is_connected = false; ppp_disconnected(); } @@ -1001,6 +1002,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) #else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) { tr_info("cb: CellularContext disconnected"); + set_cid(-1); _is_connected = false; } #endif // NSAPI_PPP_AVAILABLE @@ -1065,3 +1067,11 @@ void AT_CellularContext::set_disconnect() _is_connected = false; _device->cellular_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED, this); } + +void AT_CellularContext::set_cid(int cid) +{ + _cid = cid; + if (_stack) { + static_cast(_stack)->set_cid(_cid); + } +} diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index 439127273a..173a836a3c 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -119,6 +119,7 @@ private: void ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt); virtual void do_connect_with_retry(); void do_disconnect(); + void set_cid(int cid); private: bool _is_connected; ContextOperation _current_op; diff --git a/features/cellular/framework/AT/AT_CellularStack.cpp b/features/cellular/framework/AT/AT_CellularStack.cpp index 621431eabe..a1410fd027 100644 --- a/features/cellular/framework/AT/AT_CellularStack.cpp +++ b/features/cellular/framework/AT/AT_CellularStack.cpp @@ -98,6 +98,11 @@ const char *AT_CellularStack::get_ip_address() return (ipv4 || ipv6) ? _ip : NULL; } +void AT_CellularStack::set_cid(int cid) +{ + _cid = cid; +} + nsapi_error_t AT_CellularStack::socket_stack_init() { return NSAPI_ERROR_OK; diff --git a/features/cellular/framework/AT/AT_CellularStack.h b/features/cellular/framework/AT/AT_CellularStack.h index 5015aeee48..2402289bf2 100644 --- a/features/cellular/framework/AT/AT_CellularStack.h +++ b/features/cellular/framework/AT/AT_CellularStack.h @@ -44,6 +44,14 @@ public: public: // NetworkStack virtual const char *get_ip_address(); + + /** + * Set PDP context ID for this stack + * + * @param cid value from AT+CGDCONT, where -1 is undefined + */ + void set_cid(int cid); + protected: // NetworkStack /**