-
Notifications
You must be signed in to change notification settings - Fork 3k
Cellular: more gracefully disconnect. #8772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#define DEVICE_TIMEOUT 5 * 60 * 1000 // 5 minutes | ||
|
||
#if NSAPI_PPP_AVAILABLE | ||
#define AT_SYNC_TIMEOUT 1000 // 1 second timeout | ||
#include "nsapi_ppp.h" | ||
#endif | ||
|
||
|
@@ -555,6 +556,8 @@ void AT_CellularContext::do_connect() | |
tr_error("Failed to open data channel!"); | ||
call_network_cb(NSAPI_STATUS_DISCONNECTED); | ||
_is_connected = false; | ||
} else { | ||
_is_context_activated = true; | ||
} | ||
} | ||
#else | ||
|
@@ -627,13 +630,17 @@ nsapi_error_t AT_CellularContext::disconnect() | |
_at.lock(); | ||
_at.set_file_handle(_at.get_file_handle()); | ||
_at.set_is_filehandle_usable(true); | ||
//_at.sync(); // consume extra characters after ppp disconnect, also it may take a while until modem listens AT commands | ||
if (!_at.sync(AT_SYNC_TIMEOUT)) { // consume extra characters after ppp disconnect, also it may take a while until modem listens AT commands | ||
tr_error("AT sync failed after PPP Disconnect"); | ||
} | ||
_at.unlock(); | ||
#endif // NSAPI_PPP_AVAILABLE | ||
_at.lock(); | ||
|
||
// deactivate a context only if we have activated | ||
if (_is_context_activated) { | ||
// 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?"); | ||
|
@@ -659,17 +666,27 @@ nsapi_error_t AT_CellularContext::disconnect() | |
// 3GPP TS 27.007: | ||
// 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(); | ||
} | ||
} | ||
|
||
if (!_at.get_last_error()) { | ||
_is_connected = false; | ||
call_network_cb(NSAPI_STATUS_DISCONNECTED); | ||
if (_new_context_set) { | ||
_at.clear_error(); | ||
_at.cmd_start("AT+CGDCONT="); | ||
_at.write_int(_cid); | ||
_at.cmd_stop_read_resp(); | ||
} | ||
_at.clear_error(); | ||
_at.cmd_start("AT+CGATT=0"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added register to CellularNetwork::detach |
||
_at.cmd_stop_read_resp(); | ||
_at.restore_at_timeout(); | ||
} | ||
|
||
_is_connected = false; | ||
call_network_cb(NSAPI_STATUS_DISCONNECTED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess disconnected event should be handled by +CGEV, when really disconnected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reasons for sending NSAPI_STATUS_DISCONNECTED here:
|
||
|
||
return _at.unlock_return_error(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value is actually meaningless due to
clear_error
calls?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost, CGACT can still fail. CGACT is more powerful than commands above. So we try to do thing properly but the last CGACT will finally detach from the network and then it should not matter that the above commands have failed.