Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cellular: Fix setting of PDP context ID (cid) #11581

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UNITTESTS/stubs/AT_CellularContext_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ void AT_CellularContext::set_disconnect()
{
}

void AT_CellularContext::set_cid(int cid)
{
}

void AT_CellularContext::do_connect_with_retry()
{

Expand Down
3 changes: 3 additions & 0 deletions UNITTESTS/stubs/AT_CellularStack_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(voi
{
}

void AT_CellularStack::set_cid(int cid)
{
}
4 changes: 4 additions & 0 deletions UNITTESTS/target_h/myCellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ class myCellularContext : public CellularContext {
{
};

void set_cid(int cid)
{
};

void do_connect_with_retry()
{
};
Expand Down
22 changes: 16 additions & 6 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -994,13 +994,15 @@ 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();
}
}
#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
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions features/cellular/framework/AT/AT_CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
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;
Expand Down
5 changes: 5 additions & 0 deletions features/cellular/framework/AT/AT_CellularStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions features/cellular/framework/AT/AT_CellularStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class AT_CellularStack : public NetworkStack, public AT_CellularBase {
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

/**
Expand Down