Skip to content

Commit 828fd23

Browse files
authored
Merge pull request #11581 from AriParkkila/cell-pdp-cid
Cellular: Fix setting of PDP context ID (cid)
2 parents fda544a + e449e6d commit 828fd23

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ void AT_CellularContext::set_disconnect()
279279
{
280280
}
281281

282+
void AT_CellularContext::set_cid(int cid)
283+
{
284+
}
285+
282286
void AT_CellularContext::do_connect_with_retry()
283287
{
284288

UNITTESTS/stubs/AT_CellularStack_stub.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,6 @@ void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(voi
9494
{
9595
}
9696

97+
void AT_CellularStack::set_cid(int cid)
98+
{
99+
}

UNITTESTS/target_h/myCellularContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ class myCellularContext : public CellularContext {
216216
{
217217
};
218218

219+
void set_cid(int cid)
220+
{
221+
};
222+
219223
void do_connect_with_retry()
220224
{
221225
};

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
119119
void ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt);
120120
virtual void do_connect_with_retry();
121121
void do_disconnect();
122+
void set_cid(int cid);
122123
private:
123124
bool _is_connected;
124125
ContextOperation _current_op;

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ const char *AT_CellularStack::get_ip_address()
9898
return (ipv4 || ipv6) ? _ip : NULL;
9999
}
100100

101+
void AT_CellularStack::set_cid(int cid)
102+
{
103+
_cid = cid;
104+
}
105+
101106
nsapi_error_t AT_CellularStack::socket_stack_init()
102107
{
103108
return NSAPI_ERROR_OK;

features/cellular/framework/AT/AT_CellularStack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ class AT_CellularStack : public NetworkStack, public AT_CellularBase {
4444
public: // NetworkStack
4545

4646
virtual const char *get_ip_address();
47+
48+
/**
49+
* Set PDP context ID for this stack
50+
*
51+
* @param cid value from AT+CGDCONT, where -1 is undefined
52+
*/
53+
void set_cid(int cid);
54+
4755
protected: // NetworkStack
4856

4957
/**

0 commit comments

Comments
 (0)