diff --git a/app/src/sm_cmux.c b/app/src/sm_cmux.c index 4b1b6548..50640b80 100644 --- a/app/src/sm_cmux.c +++ b/app/src/sm_cmux.c @@ -220,6 +220,7 @@ static int do_at_and_ppp_channel_switch(int new_at_channel) LOG_DBG("Switching CMUX PPP channel to %d", !cmux.at_channel + 1); sm_at_host_release(sm_at_host_get_ctx_from(ppp_pipe)); sm_ppp_attach(ppp_pipe); + sm_ppp_detach_after_disconnect(); } return -SILENT_AT_COMMAND_RET; } @@ -293,17 +294,13 @@ static int handle_at_xcmux(enum at_parser_cmd_type cmd_type, struct at_parser *p const unsigned int at_channel = DLCI_TO_INDEX(at_dlci); if (IS_ENABLED(CONFIG_SM_PPP)) { - if (!sm_ppp_is_stopped() && at_channel != cmux.at_channel) { + if (ppp_is_running() && at_channel != cmux.at_channel) { /* The AT channel cannot be changed when PPP has a channel reserved. */ return -ENOTSUP; } } if (sm_cmux_is_started()) { - if (at_channel == cmux.at_channel) { - /* No channel change requested and CMUX is already running */ - return -EALREADY; - } return do_at_and_ppp_channel_switch(at_channel); } cmux.at_channel = at_channel; diff --git a/app/src/sm_ppp.c b/app/src/sm_ppp.c index d739bd1d..262dd81c 100644 --- a/app/src/sm_ppp.c +++ b/app/src/sm_ppp.c @@ -241,7 +241,7 @@ static void delegate_ppp_event(enum ppp_action action, enum ppp_reason reason) } } -static bool ppp_is_running(void) +bool ppp_is_running(void) { return (ppp_state == PPP_STATE_RUNNING); } @@ -719,7 +719,7 @@ static int handle_at_ppp(enum at_parser_cmd_type cmd_type, struct at_parser *par } else { rsp_send_ok(); sm_ppp_set_auto_start(false); - delegate_ppp_event(PPP_STOP, PPP_REASON_CMD); + sm_ppp_detach(); } return -SILENT_AT_COMMAND_RET; } @@ -943,4 +943,13 @@ void sm_ppp_detach(void) { ppp_pipe = NULL; sm_ppp_keep_pipe_attached = false; + sm_ppp_auto_start = false; + if (!sm_ppp_is_stopped()) { + delegate_ppp_event(PPP_STOP, PPP_REASON_CMD); + } +} + +void sm_ppp_detach_after_disconnect(void) +{ + sm_ppp_keep_pipe_attached = false; } diff --git a/app/src/sm_ppp.h b/app/src/sm_ppp.h index 512d0b13..f78fa103 100644 --- a/app/src/sm_ppp.h +++ b/app/src/sm_ppp.h @@ -13,6 +13,7 @@ extern bool sm_fwd_cgev_notifs; bool sm_ppp_is_stopped(void); +bool ppp_is_running(void); void sm_ppp_set_auto_start(bool enable); /** Set the permanent modem pipe for PPP communication */ @@ -21,4 +22,7 @@ void sm_ppp_attach(struct modem_pipe *pipe); /** Detach the modem pipe from PPP communication */ void sm_ppp_detach(void); +/** Ask to detach from PIPE after disconnecting PPP */ +void sm_ppp_detach_after_disconnect(void); + #endif