Skip to content

Commit

Permalink
Merge pull request ARMmbed#9837 from jarvte/drop_bg96_cgact_support
Browse files Browse the repository at this point in the history
Cellular: CGACT not supported in coming firmware in BG96
  • Loading branch information
0xc0170 committed Mar 14, 2019
2 parents 76fe726 + 4077898 commit cf76b74
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 61 deletions.
10 changes: 10 additions & 0 deletions UNITTESTS/stubs/AT_CellularContext_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ nsapi_error_t AT_CellularContext::do_activate_context()
return NSAPI_ERROR_OK;
}

void AT_CellularContext::activate_context()
{

}

void AT_CellularContext::deactivate_context()
{

}

void AT_CellularContext::do_connect()
{
}
Expand Down
6 changes: 5 additions & 1 deletion UNITTESTS/stubs/AT_CellularNetwork_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
return NSAPI_ERROR_OK;
}

bool AT_CellularNetwork::is_active_context()
bool AT_CellularNetwork::is_active_context(int *number_of_active_contexts, int cid)
{
return false;
}
Expand All @@ -162,3 +162,7 @@ nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnol
{
return NSAPI_ERROR_OK;
}

void AT_CellularNetwork::get_context_state_command()
{
}
9 changes: 6 additions & 3 deletions features/cellular/framework/API/CellularNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,14 @@ class CellularNetwork {
*/
virtual nsapi_error_t get_operator_names(operator_names_list &op_names) = 0;

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

/** Gets the latest received registration parameters from the network:
* type, status, access technology, cell_id, lac, active_time, periodic_tau.
Expand Down
71 changes: 29 additions & 42 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,26 @@ nsapi_error_t AT_CellularContext::do_activate_context()

nsapi_error_t AT_CellularContext::activate_ip_context()
{
return activate_context();
return find_and_activate_context();
}

nsapi_error_t AT_CellularContext::activate_non_ip_context()
{
return activate_context();
return find_and_activate_context();
}

nsapi_error_t AT_CellularContext::activate_context()
void AT_CellularContext::activate_context()
{
tr_info("Activate PDP context %d", _cid);
_at.cmd_start("AT+CGACT=1,");
_at.write_int(_cid);
_at.cmd_stop_read_resp();
if (_at.get_last_error() == NSAPI_ERROR_OK) {
_is_context_activated = true;
}
}

nsapi_error_t AT_CellularContext::find_and_activate_context()
{
_at.lock();

Expand Down Expand Up @@ -510,26 +521,11 @@ nsapi_error_t AT_CellularContext::activate_context()

_is_context_active = false;
_is_context_activated = false;
_at.cmd_start("AT+CGACT?");
_at.cmd_stop();
_at.resp_start("+CGACT:");
while (_at.info_resp()) {
int context_id = _at.read_int();
int context_activation_state = _at.read_int();
if (context_id == _cid && context_activation_state == 1) {
_is_context_active = true;
}
}
_at.resp_stop();

_is_context_active = _nw->is_active_context(NULL, _cid);

if (!_is_context_active) {
tr_info("Activate PDP context %d", _cid);
_at.cmd_start("AT+CGACT=1,");
_at.write_int(_cid);
_at.cmd_stop_read_resp();
if (_at.get_last_error() == NSAPI_ERROR_OK) {
_is_context_activated = true;
}
activate_context();
}

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

void AT_CellularContext::deactivate_ip_context()
{
deactivate_context();
check_and_deactivate_context();
}

void AT_CellularContext::deactivate_non_ip_context()
{
deactivate_context();
check_and_deactivate_context();
}

void AT_CellularContext::deactivate_context()
{
_at.cmd_start("AT+CGACT=0,");
_at.write_int(_cid);
_at.cmd_stop_read_resp();
}

void AT_CellularContext::check_and_deactivate_context()
{
// CGACT and CGATT commands might take up to 3 minutes to respond.
_at.set_at_timeout(180 * 1000);
_is_context_active = false;
size_t active_contexts_count = 0;
_at.cmd_start("AT+CGACT?");
_at.cmd_stop();
_at.resp_start("+CGACT:");
while (_at.info_resp()) {
int context_id = _at.read_int();
int context_activation_state = _at.read_int();
if (context_activation_state == 1) {
active_contexts_count++;
if (context_id == _cid) {
_is_context_active = true;
}
}
}
_at.resp_stop();
int active_contexts_count = 0;
_is_context_active = _nw->is_active_context(&active_contexts_count, _cid);

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

if (_new_context_set) {
Expand Down
9 changes: 5 additions & 4 deletions features/cellular/framework/AT/AT_CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,20 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
virtual nsapi_error_t activate_non_ip_context();
virtual nsapi_error_t setup_control_plane_opt();
virtual void deactivate_non_ip_context();
virtual void deactivate_ip_context();
virtual void set_disconnect();

virtual void deactivate_context();
private:
#if NSAPI_PPP_AVAILABLE
nsapi_error_t open_data_channel();
void ppp_status_cb(nsapi_event_t ev, intptr_t ptr);
void ppp_disconnected();
#endif // #if NSAPI_PPP_AVAILABLE
nsapi_error_t do_activate_context();
nsapi_error_t activate_context();
virtual void activate_context();
nsapi_error_t find_and_activate_context();
nsapi_error_t activate_ip_context();
void deactivate_context();
void deactivate_ip_context();
void check_and_deactivate_context();
bool set_new_context(int cid);
bool get_context();
nsapi_error_t delete_current_context();
Expand Down
33 changes: 26 additions & 7 deletions features/cellular/framework/AT/AT_CellularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,21 +565,40 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
return _at.unlock_return_error();
}

bool AT_CellularNetwork::is_active_context()
void AT_CellularNetwork::get_context_state_command()
{
_at.cmd_start("AT+CGACT?");
_at.cmd_stop();
_at.resp_start("+CGACT:");
}

bool AT_CellularNetwork::is_active_context(int *number_of_active_contexts, int cid)
{
_at.lock();

if (number_of_active_contexts) {
*number_of_active_contexts = 0;
}
bool active_found = false;
int context_id;
// read active contexts
_at.cmd_start("AT+CGACT?");
_at.cmd_stop();
_at.resp_start("+CGACT:");
get_context_state_command();

while (_at.info_resp()) {
(void)_at.read_int(); // discard context id
context_id = _at.read_int(); // discard context id
if (_at.read_int() == 1) { // check state
tr_debug("Found active context");
active_found = true;
break;
if (number_of_active_contexts) {
(*number_of_active_contexts)++;
}
if (cid == -1) {
active_found = true;
} else if (context_id == cid) {
active_found = true;
}
if (!number_of_active_contexts && active_found) {
break;
}
}
}
_at.resp_stop();
Expand Down
6 changes: 5 additions & 1 deletion features/cellular/framework/AT/AT_CellularNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase {

virtual nsapi_error_t get_operator_names(operator_names_list &op_names);

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

virtual nsapi_error_t get_registration_params(registration_params_t &reg_params);

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

/** Sends a command to query the active state of the PDP contexts.
* Can be overridden by the target class.
*/
virtual void get_context_state_command();
private:
// "NO CARRIER" urc
void urc_no_carrier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,31 @@ nsapi_error_t QUECTEL_BG96_CellularContext::activate_non_ip_context()
return (ret == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
}

void QUECTEL_BG96_CellularContext::activate_context()
{
tr_info("Activate PDP context %d", _cid);
_at.cmd_start("AT+QIACT=");
_at.write_int(_cid);
_at.cmd_stop_read_resp();
if (_at.get_last_error() == NSAPI_ERROR_OK) {
_is_context_activated = true;
}
}

void QUECTEL_BG96_CellularContext::deactivate_context()
{
_at.cmd_start("AT+QIDEACT=");
_at.write_int(_cid);
_at.cmd_stop_read_resp();
}

void QUECTEL_BG96_CellularContext::deactivate_non_ip_context()
{
// Close the NIDD connection
_at.cmd_start("AT+QCFGEXT=\"nipd\",0");
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();

}

void QUECTEL_BG96_CellularContext::urc_nidd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class QUECTEL_BG96_CellularContext: public AT_CellularContext {
virtual nsapi_error_t activate_non_ip_context();
virtual nsapi_error_t setup_control_plane_opt();
virtual void deactivate_non_ip_context();
virtual void deactivate_context();
virtual void activate_context();
rtos::Semaphore _semaphore;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* limitations under the License.
*/

#include "QUECTEL/BG96/QUECTEL_BG96_CellularNetwork.h"
#include "QUECTEL/BG96/QUECTEL_BG96_CellularStack.h"
#include "QUECTEL_BG96_CellularNetwork.h"
#include "QUECTEL_BG96_CellularStack.h"
#include "CellularLog.h"

using namespace mbed;

Expand Down Expand Up @@ -72,3 +73,12 @@ nsapi_error_t QUECTEL_BG96_CellularNetwork::set_access_technology_impl(RadioAcce

return _at.unlock_return_error();
}

void QUECTEL_BG96_CellularNetwork::get_context_state_command()
{
// read active contexts
_at.cmd_start("AT+QIACT?");
_at.cmd_stop();
_at.resp_start("+QIACT:");
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class QUECTEL_BG96_CellularNetwork : public AT_CellularNetwork {

protected:
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
virtual void get_context_state_command();

};

} // namespace mbed
Expand Down

0 comments on commit cf76b74

Please sign in to comment.