mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: fix possible crash in state machine
_sim_pin was changed to pointer from array and length was checked with strlen. If _sim_pin was null it caused crash. Fix by checking _sim_pin against NULL. Power class could have been called without checking if power is NULL. Fix by checking that power class is not null. Fix state machine to return correct states when queried.pull/9472/head
parent
fa5d0fc358
commit
97709f52ec
|
@ -153,7 +153,7 @@ bool CellularStateMachine::open_sim()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == CellularDevice::SimStatePinNeeded) {
|
if (state == CellularDevice::SimStatePinNeeded) {
|
||||||
if (strlen(_sim_pin)) {
|
if (_sim_pin) {
|
||||||
tr_info("Entering PIN to open SIM");
|
tr_info("Entering PIN to open SIM");
|
||||||
_cb_data.error = _cellularDevice.set_pin(_sim_pin);
|
_cb_data.error = _cellularDevice.set_pin(_sim_pin);
|
||||||
if (_cb_data.error) {
|
if (_cb_data.error) {
|
||||||
|
@ -428,13 +428,13 @@ void CellularStateMachine::state_sim_pin()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_network->is_active_context()) { // check if context was already activated
|
if (_network->is_active_context()) { // check if context was already activated
|
||||||
tr_debug("ACTIVE CONTEXT FOUND, skip registering.");
|
tr_debug("Active context found.");
|
||||||
_network_status |= ACTIVE_PDP_CONTEXT;
|
_network_status |= ACTIVE_PDP_CONTEXT;
|
||||||
}
|
}
|
||||||
CellularNetwork::AttachStatus status; // check if modem is already attached to a network
|
CellularNetwork::AttachStatus status; // check if modem is already attached to a network
|
||||||
if (_network->get_attach(status) == NSAPI_ERROR_OK && status == CellularNetwork::Attached) {
|
if (_network->get_attach(status) == NSAPI_ERROR_OK && status == CellularNetwork::Attached) {
|
||||||
_network_status |= ATTACHED_TO_NETWORK;
|
_network_status |= ATTACHED_TO_NETWORK;
|
||||||
tr_debug("DEVICE IS ALREADY ATTACHED TO NETWORK, skip registering and attach.");
|
tr_debug("Cellular already attached.");
|
||||||
}
|
}
|
||||||
if (_plmn) {
|
if (_plmn) {
|
||||||
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);
|
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);
|
||||||
|
|
|
@ -42,6 +42,7 @@ private:
|
||||||
// friend of CellularDevice so that it's the only way to close/delete this class.
|
// friend of CellularDevice so that it's the only way to close/delete this class.
|
||||||
friend class CellularDevice;
|
friend class CellularDevice;
|
||||||
friend class AT_CellularDevice;
|
friend class AT_CellularDevice;
|
||||||
|
friend class UT_CellularStateMachine; // for unit tests
|
||||||
/** Constructor
|
/** Constructor
|
||||||
*
|
*
|
||||||
* @param device reference to CellularDevice
|
* @param device reference to CellularDevice
|
||||||
|
@ -98,7 +99,7 @@ private:
|
||||||
* @param timeout timeout array using seconds
|
* @param timeout timeout array using seconds
|
||||||
* @param array_len length of the array
|
* @param array_len length of the array
|
||||||
*/
|
*/
|
||||||
void set_retry_timeout_array(uint16_t timeout[], int array_len);
|
void set_retry_timeout_array(uint16_t *timeout, int array_len);
|
||||||
|
|
||||||
/** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic
|
/** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic
|
||||||
* registering is used when registering to a cellular network. Does not start any operations.
|
* registering is used when registering to a cellular network. Does not start any operations.
|
||||||
|
|
Loading…
Reference in New Issue