diff --git a/features/cellular/easy_cellular/CellularConnectionFSM.cpp b/features/cellular/easy_cellular/CellularConnectionFSM.cpp index cb5e08eea1..340a0ab474 100644 --- a/features/cellular/easy_cellular/CellularConnectionFSM.cpp +++ b/features/cellular/easy_cellular/CellularConnectionFSM.cpp @@ -402,6 +402,8 @@ void CellularConnectionFSM::device_ready() _event_status_cb((nsapi_event_t)CellularDeviceReady, 0); } _power->remove_device_ready_urc_cb(mbed::callback(this, &CellularConnectionFSM::ready_urc_cb)); + _cellularDevice->close_power(); + _power = NULL; } void CellularConnectionFSM::state_device_ready() @@ -434,7 +436,8 @@ void CellularConnectionFSM::state_sim_pin() retry_state_or_fail(); return; } - + _cellularDevice->close_sim(); + _sim = NULL; if (_plmn) { enter_to_state(STATE_MANUAL_REGISTERING_NETWORK); } else { diff --git a/features/cellular/easy_cellular/CellularConnectionFSM.h b/features/cellular/easy_cellular/CellularConnectionFSM.h index 78dc1f232a..b0c2bdda6b 100644 --- a/features/cellular/easy_cellular/CellularConnectionFSM.h +++ b/features/cellular/easy_cellular/CellularConnectionFSM.h @@ -117,7 +117,9 @@ public: */ CellularDevice *get_device(); - /** Get cellular sim interface + /** Get cellular sim interface. SIM interface is released after SIM is open and ready for use (moving from STATE_SIM_PIN to next state). + * After SIM interface is closed this method will return NULL. SIM interface can be created again via CellularDevice + * which you can get with the method get_device(). * @return sim interface, NULL on failure */ CellularSIM *get_sim(); diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index fbf01f403e..5dbc834609 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -72,6 +72,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char _fh_sigio_set(false), _processing(false), _ref_count(1), + _is_fh_usable(true), _stop_tag(NULL), _delimiter(DEFAULT_DELIMITER), _prefix_matched(false), @@ -151,6 +152,11 @@ void ATHandler::set_file_handle(FileHandle *fh) _fileHandle = fh; } +void ATHandler::set_is_filehandle_usable(bool usable) +{ + _is_fh_usable = usable; +} + nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback callback) { if (find_urc_handler(prefix, callback)) { @@ -269,6 +275,10 @@ void ATHandler::restore_at_timeout() void ATHandler::process_oob() { + if (!_is_fh_usable) { + tr_debug("process_oob, filehandle is not usable, return..."); + return; + } lock(); tr_debug("process_oob readable=%d, pos=%u, len=%u", _fileHandle->readable(), _recv_pos, _recv_len); if (_fileHandle->readable() || (_recv_pos < _recv_len)) { diff --git a/features/cellular/framework/AT/ATHandler.h b/features/cellular/framework/AT/ATHandler.h index ad5d8a787d..93e5053598 100644 --- a/features/cellular/framework/AT/ATHandler.h +++ b/features/cellular/framework/AT/ATHandler.h @@ -175,6 +175,13 @@ public: */ void set_file_handle(FileHandle *fh); + /** Set is file handle usable. Some situations like after going to data mode, file handle is not usable anymore. + * Any items in queue are not to be processed. + * + * @param usable true for usable filehandle + */ + void set_is_filehandle_usable(bool usable); + protected: void event(); #ifdef AT_HANDLER_MUTEX @@ -209,6 +216,7 @@ private: bool _processing; int32_t _ref_count; + bool _is_fh_usable; //************************************* public: diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index b1d17a205a..6daa79b59a 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -360,8 +360,12 @@ nsapi_error_t AT_CellularNetwork::open_data_channel() _at.resp_start("CONNECT", true); if (_at.get_last_error()) { - tr_warn("Failed to CONNECT"); + tr_error("Failed to CONNECT"); + return _at.get_last_error(); } + + _at.set_is_filehandle_usable(false); + /* Initialize PPP * If blocking: mbed_ppp_init() is a blocking call, it will block until connected, or timeout after 30 seconds*/ @@ -385,6 +389,7 @@ nsapi_error_t AT_CellularNetwork::disconnect() // will set the correct sigio and nonblocking _at.lock(); _at.set_file_handle(_at.get_file_handle()); + _at.set_is_filehandle_usable(true); _at.unlock(); return err; #else