Skip to content

Conversation

SeppoTakalo
Copy link
Contributor

drivers: modem: cellular: Close down CMUX before shut down

Properly close down the CMUX channel before shutting down
the modem.

The CMUX Close-Down command should indicate the remote end
to clean up, even if we don't have shutdown script or power-key GPIO.

Requires also minor fix to CMUX so we send disconnect event only after responding to CLD (Multiplexer Close Down).

If we immediately send disconnected event when CLD is received,
we might close the UART pipe before the response is actually send.

Contains changes from PR #97570

Refactor internal event bits to use state enum values
and define set_state() and wait_state() so we don't need
two set of variables to maintain.

Signed-off-by: Seppo Takalo <[email protected]>
Instead of dropping all responses, handle the CLD.

Signed-off-by: Seppo Takalo <[email protected]>
If we immediately send disconnected event when CLD is received,
we might close the UART pipe before the response is actually send.

Also, shutdown_handler should not retry indefinitely.

Signed-off-by: Seppo Takalo <[email protected]>
Properly close down the CMUX channel before shutting down
the modem.

The CMUX Close-Down command should indicate the remote end
to clean up, even if we don't have shutdown script or power-key GPIO.

Signed-off-by: Seppo Takalo <[email protected]>
Copy link

case MODEM_CMUX_COMMAND_CLD:
modem_cmux_on_cld_command(cmux, command);
break;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: In case you are wondering why switch-case with only one case, see the PR #97362 there is PSC command handler coming.
This is just split into its own PR.

Comment on lines +469 to +476
set_state(cmux, MODEM_CMUX_STATE_DISCONNECTED);
k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER);
cmux->flow_control_on = false;
k_mutex_unlock(&cmux->transmit_rb_lock);
modem_cmux_raise_event(cmux, MODEM_CMUX_EVENT_DISCONNECTED);
} else {
set_state(cmux, MODEM_CMUX_STATE_DISCONNECTING);
k_work_schedule(&cmux->disconnect_work, MODEM_CMUX_T1_TIMEOUT);
Copy link
Member

Choose a reason for hiding this comment

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

This code is duplicated in two spots. Maybe make it a function?

@tomi-font tomi-font removed their request for review October 16, 2025 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Modem Drivers area: Modem area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants