Skip to content

Commit 4077898

Browse files
author
Teppo Järvelin
committed
Cellular: fix issue where CGACT not supported in coming firmware in BG96.
1 parent 5f38878 commit 4077898

11 files changed

+120
-61
lines changed

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ nsapi_error_t AT_CellularContext::do_activate_context()
191191
return NSAPI_ERROR_OK;
192192
}
193193

194+
void AT_CellularContext::activate_context()
195+
{
196+
197+
}
198+
199+
void AT_CellularContext::deactivate_context()
200+
{
201+
202+
}
203+
194204
void AT_CellularContext::do_connect()
195205
{
196206
}

UNITTESTS/stubs/AT_CellularNetwork_stub.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
158158
return NSAPI_ERROR_OK;
159159
}
160160

161-
bool AT_CellularNetwork::is_active_context()
161+
bool AT_CellularNetwork::is_active_context(int *number_of_active_contexts, int cid)
162162
{
163163
return false;
164164
}
@@ -167,3 +167,7 @@ nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnol
167167
{
168168
return NSAPI_ERROR_OK;
169169
}
170+
171+
void AT_CellularNetwork::get_context_state_command()
172+
{
173+
}

features/cellular/framework/API/CellularNetwork.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,14 @@ class CellularNetwork {
338338
*/
339339
virtual nsapi_error_t get_operator_names(operator_names_list &op_names) = 0;
340340

341-
/** Check if there is any PDP context active
341+
/** Check if there is any PDP context active. If cid is given, then check is done only for that cid.
342342
*
343-
* @return true is any context is active, false otherwise or in case of error
343+
* @param number_of_active_contexts If given then in return contains the number of active contexts
344+
* @param cid If given then active contexts are checked only against this cid
345+
*
346+
* @return true if any (or the given cid) context is active, false otherwise or in case of error
344347
*/
345-
virtual bool is_active_context() = 0;
348+
virtual bool is_active_context(int *number_of_active_contexts = NULL, int cid = -1) = 0;
346349

347350
/** Gets the latest received registration parameters from the network:
348351
* type, status, access technology, cell_id, lac, active_time, periodic_tau.

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,26 @@ nsapi_error_t AT_CellularContext::do_activate_context()
467467

468468
nsapi_error_t AT_CellularContext::activate_ip_context()
469469
{
470-
return activate_context();
470+
return find_and_activate_context();
471471
}
472472

473473
nsapi_error_t AT_CellularContext::activate_non_ip_context()
474474
{
475-
return activate_context();
475+
return find_and_activate_context();
476476
}
477477

478-
nsapi_error_t AT_CellularContext::activate_context()
478+
void AT_CellularContext::activate_context()
479+
{
480+
tr_info("Activate PDP context %d", _cid);
481+
_at.cmd_start("AT+CGACT=1,");
482+
_at.write_int(_cid);
483+
_at.cmd_stop_read_resp();
484+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
485+
_is_context_activated = true;
486+
}
487+
}
488+
489+
nsapi_error_t AT_CellularContext::find_and_activate_context()
479490
{
480491
_at.lock();
481492

@@ -511,26 +522,11 @@ nsapi_error_t AT_CellularContext::activate_context()
511522

512523
_is_context_active = false;
513524
_is_context_activated = false;
514-
_at.cmd_start("AT+CGACT?");
515-
_at.cmd_stop();
516-
_at.resp_start("+CGACT:");
517-
while (_at.info_resp()) {
518-
int context_id = _at.read_int();
519-
int context_activation_state = _at.read_int();
520-
if (context_id == _cid && context_activation_state == 1) {
521-
_is_context_active = true;
522-
}
523-
}
524-
_at.resp_stop();
525+
526+
_is_context_active = _nw->is_active_context(NULL, _cid);
525527

526528
if (!_is_context_active) {
527-
tr_info("Activate PDP context %d", _cid);
528-
_at.cmd_start("AT+CGACT=1,");
529-
_at.write_int(_cid);
530-
_at.cmd_stop_read_resp();
531-
if (_at.get_last_error() == NSAPI_ERROR_OK) {
532-
_is_context_activated = true;
533-
}
529+
activate_context();
534530
}
535531

536532
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
@@ -692,34 +688,27 @@ nsapi_error_t AT_CellularContext::disconnect()
692688

693689
void AT_CellularContext::deactivate_ip_context()
694690
{
695-
deactivate_context();
691+
check_and_deactivate_context();
696692
}
697693

698694
void AT_CellularContext::deactivate_non_ip_context()
699695
{
700-
deactivate_context();
696+
check_and_deactivate_context();
701697
}
702698

703699
void AT_CellularContext::deactivate_context()
700+
{
701+
_at.cmd_start("AT+CGACT=0,");
702+
_at.write_int(_cid);
703+
_at.cmd_stop_read_resp();
704+
}
705+
706+
void AT_CellularContext::check_and_deactivate_context()
704707
{
705708
// CGACT and CGATT commands might take up to 3 minutes to respond.
706709
_at.set_at_timeout(180 * 1000);
707-
_is_context_active = false;
708-
size_t active_contexts_count = 0;
709-
_at.cmd_start("AT+CGACT?");
710-
_at.cmd_stop();
711-
_at.resp_start("+CGACT:");
712-
while (_at.info_resp()) {
713-
int context_id = _at.read_int();
714-
int context_activation_state = _at.read_int();
715-
if (context_activation_state == 1) {
716-
active_contexts_count++;
717-
if (context_id == _cid) {
718-
_is_context_active = true;
719-
}
720-
}
721-
}
722-
_at.resp_stop();
710+
int active_contexts_count = 0;
711+
_is_context_active = _nw->is_active_context(&active_contexts_count, _cid);
723712

724713
CellularNetwork::RadioAccessTechnology rat = CellularNetwork::RAT_GSM;
725714
// always return NSAPI_ERROR_OK
@@ -730,9 +719,7 @@ void AT_CellularContext::deactivate_context()
730719
// For EPS, if an attempt is made to disconnect the last PDN connection, then the MT responds with ERROR
731720
if (_is_context_active && (rat < CellularNetwork::RAT_E_UTRAN || active_contexts_count > 1)) {
732721
_at.clear_error();
733-
_at.cmd_start("AT+CGACT=0,");
734-
_at.write_int(_cid);
735-
_at.cmd_stop_read_resp();
722+
deactivate_context();
736723
}
737724

738725
if (_new_context_set) {

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,20 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
9797
virtual nsapi_error_t activate_non_ip_context();
9898
virtual nsapi_error_t setup_control_plane_opt();
9999
virtual void deactivate_non_ip_context();
100+
virtual void deactivate_ip_context();
100101
virtual void set_disconnect();
101-
102+
virtual void deactivate_context();
102103
private:
103104
#if NSAPI_PPP_AVAILABLE
104105
nsapi_error_t open_data_channel();
105106
void ppp_status_cb(nsapi_event_t ev, intptr_t ptr);
106107
void ppp_disconnected();
107108
#endif // #if NSAPI_PPP_AVAILABLE
108109
nsapi_error_t do_activate_context();
109-
nsapi_error_t activate_context();
110+
virtual void activate_context();
111+
nsapi_error_t find_and_activate_context();
110112
nsapi_error_t activate_ip_context();
111-
void deactivate_context();
112-
void deactivate_ip_context();
113+
void check_and_deactivate_context();
113114
bool set_new_context(int cid);
114115
bool get_context();
115116
nsapi_error_t delete_current_context();

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -573,21 +573,40 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
573573
return _at.unlock_return_error();
574574
}
575575

576-
bool AT_CellularNetwork::is_active_context()
576+
void AT_CellularNetwork::get_context_state_command()
577+
{
578+
_at.cmd_start("AT+CGACT?");
579+
_at.cmd_stop();
580+
_at.resp_start("+CGACT:");
581+
}
582+
583+
bool AT_CellularNetwork::is_active_context(int *number_of_active_contexts, int cid)
577584
{
578585
_at.lock();
579586

587+
if (number_of_active_contexts) {
588+
*number_of_active_contexts = 0;
589+
}
580590
bool active_found = false;
591+
int context_id;
581592
// read active contexts
582-
_at.cmd_start("AT+CGACT?");
583-
_at.cmd_stop();
584-
_at.resp_start("+CGACT:");
593+
get_context_state_command();
594+
585595
while (_at.info_resp()) {
586-
(void)_at.read_int(); // discard context id
596+
context_id = _at.read_int(); // discard context id
587597
if (_at.read_int() == 1) { // check state
588598
tr_debug("Found active context");
589-
active_found = true;
590-
break;
599+
if (number_of_active_contexts) {
600+
(*number_of_active_contexts)++;
601+
}
602+
if (cid == -1) {
603+
active_found = true;
604+
} else if (context_id == cid) {
605+
active_found = true;
606+
}
607+
if (!number_of_active_contexts && active_found) {
608+
break;
609+
}
591610
}
592611
}
593612
_at.resp_stop();

features/cellular/framework/AT/AT_CellularNetwork.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase {
8888

8989
virtual nsapi_error_t get_operator_names(operator_names_list &op_names);
9090

91-
virtual bool is_active_context();
91+
virtual bool is_active_context(int *number_of_active_contexts = NULL, int cid = -1);
9292

9393
virtual nsapi_error_t get_registration_params(registration_params_t &reg_params);
9494

@@ -106,6 +106,10 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase {
106106
*/
107107
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat);
108108

109+
/** Sends a command to query the active state of the PDP contexts.
110+
* Can be overridden by the target class.
111+
*/
112+
virtual void get_context_state_command();
109113
private:
110114
// "NO CARRIER" urc
111115
void urc_no_carrier();

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,31 @@ nsapi_error_t QUECTEL_BG96_CellularContext::activate_non_ip_context()
112112
return (ret == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
113113
}
114114

115+
void QUECTEL_BG96_CellularContext::activate_context()
116+
{
117+
tr_info("Activate PDP context %d", _cid);
118+
_at.cmd_start("AT+QIACT=");
119+
_at.write_int(_cid);
120+
_at.cmd_stop_read_resp();
121+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
122+
_is_context_activated = true;
123+
}
124+
}
125+
126+
void QUECTEL_BG96_CellularContext::deactivate_context()
127+
{
128+
_at.cmd_start("AT+QIDEACT=");
129+
_at.write_int(_cid);
130+
_at.cmd_stop_read_resp();
131+
}
132+
115133
void QUECTEL_BG96_CellularContext::deactivate_non_ip_context()
116134
{
117135
// Close the NIDD connection
118136
_at.cmd_start("AT+QCFGEXT=\"nipd\",0");
119137
_at.cmd_stop();
120138
_at.resp_start();
121139
_at.resp_stop();
122-
123140
}
124141

125142
void QUECTEL_BG96_CellularContext::urc_nidd()

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class QUECTEL_BG96_CellularContext: public AT_CellularContext {
3535
virtual nsapi_error_t activate_non_ip_context();
3636
virtual nsapi_error_t setup_control_plane_opt();
3737
virtual void deactivate_non_ip_context();
38+
virtual void deactivate_context();
39+
virtual void activate_context();
3840
rtos::Semaphore _semaphore;
3941

4042
private:

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularNetwork.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include "QUECTEL/BG96/QUECTEL_BG96_CellularNetwork.h"
19-
#include "QUECTEL/BG96/QUECTEL_BG96_CellularStack.h"
18+
#include "QUECTEL_BG96_CellularNetwork.h"
19+
#include "QUECTEL_BG96_CellularStack.h"
20+
#include "CellularLog.h"
2021

2122
using namespace mbed;
2223

@@ -72,3 +73,12 @@ nsapi_error_t QUECTEL_BG96_CellularNetwork::set_access_technology_impl(RadioAcce
7273

7374
return _at.unlock_return_error();
7475
}
76+
77+
void QUECTEL_BG96_CellularNetwork::get_context_state_command()
78+
{
79+
// read active contexts
80+
_at.cmd_start("AT+QIACT?");
81+
_at.cmd_stop();
82+
_at.resp_start("+QIACT:");
83+
}
84+

0 commit comments

Comments
 (0)