Skip to content

Commit

Permalink
Cellular: call AT+CGEREP after sim is ready
Browse files Browse the repository at this point in the history
Current implementation did call AT+CGEREP before sim was ready
and it was failing in most modems.
  • Loading branch information
Teppo Järvelin committed Mar 18, 2019
1 parent e417ad2 commit dba3d42
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,19 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_receive_period)
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_receive_period(1, CellularNetwork::EDRXUTRAN_Iu_mode, 3));
}

TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_packet_domain_event_reporting)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");

AT_CellularNetwork cn(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_packet_domain_event_reporting(true));
EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_packet_domain_event_reporting(false));

ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_packet_domain_event_reporting(true));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_packet_domain_event_reporting(false));
}
5 changes: 5 additions & 0 deletions UNITTESTS/stubs/AT_CellularNetwork_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,8 @@ nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnol
void AT_CellularNetwork::get_context_state_command()
{
}

nsapi_error_t AT_CellularNetwork::set_packet_domain_event_reporting(bool on)
{
return NSAPI_ERROR_OK;
}
13 changes: 13 additions & 0 deletions features/cellular/framework/API/CellularNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,19 @@ class CellularNetwork {
};
virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0;

/** Sets the packet domain network reporting. Useful for getting events when detached from the
* network. When detach event arrives it is propagated as NSAPI_STATUS_DISCONNECTED to callback set
* with attach(...).
*
* @param on true for enabling event reporting, false for disabling
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED is command is not supported by the modem
* NSAPI_ERROR_DEVICE_ERROR on failure
*/
virtual nsapi_error_t set_packet_domain_event_reporting(bool on)
{
return NSAPI_ERROR_UNSUPPORTED;
}
};

/**
Expand Down
1 change: 1 addition & 0 deletions features/cellular/framework/AT/AT_CellularBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AT_CellularBase {
PROPERTY_IPV6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV6?
PROPERTY_IPV4V6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support dual stack IPV4V6?
PROPERTY_NON_IP_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support Non-IP?
PROPERTY_AT_CGEREP, // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
PROPERTY_MAX
};

Expand Down
24 changes: 15 additions & 9 deletions features/cellular/framework/AT/AT_CellularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,11 @@ AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(a
// additional urc to get better disconnect info for application. Not critical.
_at.set_urc_handler("+CGEV:", callback(this, &AT_CellularNetwork::urc_cgev));
_at.set_urc_handler("+CCIOTOPTI:", callback(this, &AT_CellularNetwork::urc_cciotopti));
_at.lock();
_at.cmd_start("AT+CGEREP=1");// discard unsolicited result codes when MT TE link is reserved (e.g. in on line data mode); otherwise forward them directly to the TE
_at.cmd_stop_read_resp();
_at.unlock();
}

AT_CellularNetwork::~AT_CellularNetwork()
{
_at.lock();
_at.cmd_start("AT+CGEREP=0");// buffer unsolicited result codes in the MT; if MT result code buffer is full, the oldest ones can be discarded. No codes are forwarded to the TE
_at.cmd_stop_read_resp();
_at.unlock();

(void)set_packet_domain_event_reporting(false);
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
if (get_property((AT_CellularBase::CellularProperty)type) != RegistrationModeDisable) {
_at.set_urc_handler(at_reg[type].urc_prefix, 0);
Expand Down Expand Up @@ -713,3 +705,17 @@ nsapi_error_t AT_CellularNetwork::set_receive_period(int mode, EDRXAccessTechnol

return _at.unlock_return_error();
}

nsapi_error_t AT_CellularNetwork::set_packet_domain_event_reporting(bool on)
{
if (!get_property(AT_CellularBase::PROPERTY_AT_CGEREP)) {
return NSAPI_ERROR_UNSUPPORTED;
}

_at.lock();
_at.cmd_start("AT+CGEREP=");// discard unsolicited result codes when MT TE link is reserved (e.g. in on line data mode); otherwise forward them directly to the TE
_at.write_int(on ? 1 : 0);
_at.cmd_stop_read_resp();

return _at.unlock_return_error();
}
2 changes: 2 additions & 0 deletions features/cellular/framework/AT/AT_CellularNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase {

virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value);

virtual nsapi_error_t set_packet_domain_event_reporting(bool on);

protected:

/** Sets access technology to be scanned. Modem specific implementation.
Expand Down
8 changes: 8 additions & 0 deletions features/cellular/framework/device/CellularStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ void CellularStateMachine::state_sim_pin()
tr_debug("Cellular already attached.");
}

// if packet domain event reporting is not set it's not a stopper. We might lack some events when we are
// dropped from the network.
_cb_data.error = _network->set_packet_domain_event_reporting(true);
if (_cb_data.error == NSAPI_STATUS_ERROR_UNSUPPORTED) {
tr_warning("Packet domain event reporting not supported!");
} else if (_cb_data.error) {
tr_warning("Packet domain event reporting set failed!");
}
enter_to_state(STATE_REGISTERING_NETWORK);
} else {
retry_state_or_fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void GEMALTO_CINTERION::init_module_bgs2()
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
AT_CellularBase::set_cellular_properties(cellular_properties);
_module = ModuleBGS2;
Expand All @@ -126,6 +128,8 @@ void GEMALTO_CINTERION::init_module_els61()
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
AT_CellularBase::set_cellular_properties(cellular_properties);
_module = ModuleELS61;
Expand All @@ -144,6 +148,8 @@ void GEMALTO_CINTERION::init_module_ems31()
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
1, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
AT_CellularBase::set_cellular_properties(cellular_properties);
_module = ModuleEMS31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
1, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

GENERIC_AT3GPP::GENERIC_AT3GPP(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
1, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};

TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh)
Expand Down
4 changes: 4 additions & 0 deletions features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
#else
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
Expand All @@ -53,6 +55,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
#endif

Expand Down
4 changes: 4 additions & 0 deletions features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
#else
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
Expand All @@ -52,6 +54,8 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_AT_CGEREP
};
#endif

Expand Down

0 comments on commit dba3d42

Please sign in to comment.