Cellular: Fix setting of PDP context ID (cid)

pull/11696/head
Ari Parkkila 2019-09-27 02:09:36 -07:00 committed by adbridge
parent 89ce27b3fc
commit 78f3292036
7 changed files with 41 additions and 6 deletions

View File

@ -279,6 +279,10 @@ void AT_CellularContext::set_disconnect()
{
}
void AT_CellularContext::set_cid(int cid)
{
}
void AT_CellularContext::do_connect_with_retry()
{

View File

@ -94,3 +94,6 @@ void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(voi
{
}
void AT_CellularStack::set_cid(int cid)
{
}

View File

@ -216,6 +216,10 @@ public:
{
};
void set_cid(int cid)
{
};
void do_connect_with_retry()
{
};

View File

@ -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<AT_CellularStack *>(_stack)->set_cid(_cid);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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
/**