Skip to content

Cellular: Delete created context if activation fails #12399

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

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,28 +530,25 @@ nsapi_error_t AT_CellularContext::find_and_activate_context()
}

if (err != NSAPI_ERROR_OK) {
_at.unlock();
tr_error("Failed to activate network context! (%d)", err);
return err;
}

// do check for stack to validate that we have support for stack
if (!(_nonip_req && _cp_in_use) && !get_stack()) {
_at.unlock();
} else if (!(_nonip_req && _cp_in_use) && !get_stack()) {
// do check for stack to validate that we have support for stack
tr_error("No cellular stack!");
return NSAPI_ERROR_UNSUPPORTED;
err = NSAPI_ERROR_UNSUPPORTED;
}

_is_context_active = false;
_is_context_activated = false;

_is_context_active = _nw->is_active_context(NULL, _cid);
if (err == NSAPI_ERROR_OK) {
_is_context_active = _nw->is_active_context(NULL, _cid);

if (!_is_context_active) {
activate_context();
}
if (!_is_context_active) {
activate_context();
}

err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
}

// If new PDP context was created and failed to activate, delete it
if (err != NSAPI_ERROR_OK && _new_context_set) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this _new_context_set condition ?
Ex: A wrong context configuration was already present in modem,
Maybe we should delete all context when connection has failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should remove contexts not created automatically by cellular. Could it cause problems with devices roaming in different networks? We have "cellular.clear-on-connect" setting which can be (kind of) used to handle this case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh
Let's try in my mbed_app:

"cellular.clear-on-connect": true

Maybe it can also help @soleilplanet ?

Expand Down