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

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.

rerickson1
rerickson1 previously approved these changes Oct 15, 2025
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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed

@tomi-font tomi-font removed their request for review October 16, 2025 08:45
@cfriedt
Copy link
Member

cfriedt commented Oct 17, 2025

@SeppoTakalo - needs a rebase

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]>
@sonarqubecloud
Copy link

@SeppoTakalo
Copy link
Contributor Author

Rebased and fixed the duplicated code as @rerickson1 suggested.

@tomi-font and @bjarki-andreasen please review again.

@kartben kartben merged commit 7270168 into zephyrproject-rtos:main Oct 20, 2025
26 checks passed
@SeppoTakalo SeppoTakalo deleted the cmux_close branch October 20, 2025 11:12
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.

6 participants