Skip to content

Commit cf76b74

Browse files
authored
Merge pull request #9837 from jarvte/drop_bg96_cgact_support
Cellular: CGACT not supported in coming firmware in BG96
2 parents 76fe726 + 4077898 commit cf76b74

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
@@ -153,7 +153,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
153153
return NSAPI_ERROR_OK;
154154
}
155155

156-
bool AT_CellularNetwork::is_active_context()
156+
bool AT_CellularNetwork::is_active_context(int *number_of_active_contexts, int cid)
157157
{
158158
return false;
159159
}
@@ -162,3 +162,7 @@ nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnol
162162
{
163163
return NSAPI_ERROR_OK;
164164
}
165+
166+
void AT_CellularNetwork::get_context_state_command()
167+
{
168+
}

features/cellular/framework/API/CellularNetwork.h

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

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

345348
/** Gets the latest received registration parameters from the network:
346349
* 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

@@ -510,26 +521,11 @@ nsapi_error_t AT_CellularContext::activate_context()
510521

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

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

535531
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
@@ -704,34 +700,27 @@ nsapi_error_t AT_CellularContext::disconnect()
704700

705701
void AT_CellularContext::deactivate_ip_context()
706702
{
707-
deactivate_context();
703+
check_and_deactivate_context();
708704
}
709705

710706
void AT_CellularContext::deactivate_non_ip_context()
711707
{
712-
deactivate_context();
708+
check_and_deactivate_context();
713709
}
714710

715711
void AT_CellularContext::deactivate_context()
712+
{
713+
_at.cmd_start("AT+CGACT=0,");
714+
_at.write_int(_cid);
715+
_at.cmd_stop_read_resp();
716+
}
717+
718+
void AT_CellularContext::check_and_deactivate_context()
716719
{
717720
// CGACT and CGATT commands might take up to 3 minutes to respond.
718721
_at.set_at_timeout(180 * 1000);
719-
_is_context_active = false;
720-
size_t active_contexts_count = 0;
721-
_at.cmd_start("AT+CGACT?");
722-
_at.cmd_stop();
723-
_at.resp_start("+CGACT:");
724-
while (_at.info_resp()) {
725-
int context_id = _at.read_int();
726-
int context_activation_state = _at.read_int();
727-
if (context_activation_state == 1) {
728-
active_contexts_count++;
729-
if (context_id == _cid) {
730-
_is_context_active = true;
731-
}
732-
}
733-
}
734-
_at.resp_stop();
722+
int active_contexts_count = 0;
723+
_is_context_active = _nw->is_active_context(&active_contexts_count, _cid);
735724

736725
CellularNetwork::RadioAccessTechnology rat = CellularNetwork::RAT_GSM;
737726
// always return NSAPI_ERROR_OK
@@ -742,9 +731,7 @@ void AT_CellularContext::deactivate_context()
742731
// For EPS, if an attempt is made to disconnect the last PDN connection, then the MT responds with ERROR
743732
if (_is_context_active && (rat < CellularNetwork::RAT_E_UTRAN || active_contexts_count > 1)) {
744733
_at.clear_error();
745-
_at.cmd_start("AT+CGACT=0,");
746-
_at.write_int(_cid);
747-
_at.cmd_stop_read_resp();
734+
deactivate_context();
748735
}
749736

750737
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
@@ -565,21 +565,40 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
565565
return _at.unlock_return_error();
566566
}
567567

568-
bool AT_CellularNetwork::is_active_context()
568+
void AT_CellularNetwork::get_context_state_command()
569+
{
570+
_at.cmd_start("AT+CGACT?");
571+
_at.cmd_stop();
572+
_at.resp_start("+CGACT:");
573+
}
574+
575+
bool AT_CellularNetwork::is_active_context(int *number_of_active_contexts, int cid)
569576
{
570577
_at.lock();
571578

579+
if (number_of_active_contexts) {
580+
*number_of_active_contexts = 0;
581+
}
572582
bool active_found = false;
583+
int context_id;
573584
// read active contexts
574-
_at.cmd_start("AT+CGACT?");
575-
_at.cmd_stop();
576-
_at.resp_start("+CGACT:");
585+
get_context_state_command();
586+
577587
while (_at.info_resp()) {
578-
(void)_at.read_int(); // discard context id
588+
context_id = _at.read_int(); // discard context id
579589
if (_at.read_int() == 1) { // check state
580590
tr_debug("Found active context");
581-
active_found = true;
582-
break;
591+
if (number_of_active_contexts) {
592+
(*number_of_active_contexts)++;
593+
}
594+
if (cid == -1) {
595+
active_found = true;
596+
} else if (context_id == cid) {
597+
active_found = true;
598+
}
599+
if (!number_of_active_contexts && active_found) {
600+
break;
601+
}
583602
}
584603
}
585604
_at.resp_stop();

features/cellular/framework/AT/AT_CellularNetwork.h

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

8787
virtual nsapi_error_t get_operator_names(operator_names_list &op_names);
8888

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

9191
virtual nsapi_error_t get_registration_params(registration_params_t &reg_params);
9292

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

107+
/** Sends a command to query the active state of the PDP contexts.
108+
* Can be overridden by the target class.
109+
*/
110+
virtual void get_context_state_command();
107111
private:
108112
// "NO CARRIER" urc
109113
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)