Skip to content

Commit 4ef72a9

Browse files
committed
app: Handle PPP pipes properly
In case of AT#XCMUX command is used, PPP is permanently attached to one of the pipes. PPP module keeps this pipe until CMUX stops. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 74505b3 commit 4ef72a9

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

app/src/sm_cmux.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ static void stop_work_fn(struct k_work *work)
122122
{
123123
ARG_UNUSED(work);
124124

125-
/* Will stop the UART when calling the close_pipe() function. */
126125
if (sm_cmux_is_started()) {
127126
modem_cmux_release(&cmux.instance);
128127

129128
cmux.at_channel = 0;
129+
if (IS_ENABLED(CONFIG_SM_PPP)) {
130+
sm_ppp_detach();
131+
}
130132

131133
/* Return AT host to UART pipe */
132134
sm_at_host_set_pipe(sm_at_host_get_urc_ctx(), cmux.uart_pipe);

app/src/sm_ppp.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bool sm_fwd_cgev_notifs;
3333

3434
static struct net_if *ppp_iface;
3535
static bool sm_ppp_auto_start;
36+
static bool sm_ppp_keep_pipe_attached;
3637
static uint8_t ppp_data_buf[1500];
3738
static struct sockaddr_ll ppp_zephyr_dst_addr;
3839

@@ -383,7 +384,7 @@ bool sm_ppp_is_stopped(void)
383384

384385
static int ppp_stop(enum ppp_reason reason)
385386
{
386-
bool restarting;
387+
bool restarting = false;
387388

388389
if (ppp_state == PPP_STATE_STOPPED) {
389390
LOG_INF("PPP already stopped");
@@ -392,14 +393,15 @@ static int ppp_stop(enum ppp_reason reason)
392393

393394
ppp_state = PPP_STATE_STOPPING;
394395

395-
switch (reason) {
396-
case PPP_REASON_PEER_DISCONNECTED:
397-
case PPP_REASON_CMD:
398-
restarting = false;
399-
break;
400-
default:
401-
restarting = true;
402-
break;
396+
if (sm_ppp_keep_pipe_attached) {
397+
switch (reason) {
398+
case PPP_REASON_NETWORK:
399+
case PPP_REASON_ERROR:
400+
restarting = true;
401+
break;
402+
default:
403+
break;
404+
}
403405
}
404406

405407
if (!restarting) {
@@ -417,7 +419,7 @@ static int ppp_stop(enum ppp_reason reason)
417419

418420
modem_ppp_release(&ppp_module);
419421

420-
if (!restarting) {
422+
if (!sm_ppp_keep_pipe_attached) {
421423
/* Return the pipe back to AT host */
422424
sm_at_host_attach(ppp_pipe);
423425
ppp_pipe = NULL;
@@ -428,7 +430,6 @@ static int ppp_stop(enum ppp_reason reason)
428430
close_ppp_sockets();
429431

430432
ppp_state = PPP_STATE_STOPPED;
431-
ppp_pipe = NULL;
432433
send_status_notification();
433434

434435
return 0;
@@ -839,4 +840,11 @@ void sm_ppp_attach(struct modem_pipe *pipe)
839840
modem_pipe_release(pipe);
840841
}
841842
ppp_pipe = pipe;
843+
sm_ppp_keep_pipe_attached = true;
844+
}
845+
846+
void sm_ppp_detach(void)
847+
{
848+
ppp_pipe = NULL;
849+
sm_ppp_keep_pipe_attached = false;
842850
}

app/src/sm_ppp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ extern bool sm_fwd_cgev_notifs;
1515
bool sm_ppp_is_stopped(void);
1616
void sm_ppp_set_auto_start(bool enable);
1717

18-
/** Set the modem pipe for PPP communication */
18+
/** Set the permanent modem pipe for PPP communication */
1919
void sm_ppp_attach(struct modem_pipe *pipe);
2020

21+
/** Detach the modem pipe from PPP communication */
22+
void sm_ppp_detach(void);
23+
2124
#endif

0 commit comments

Comments
 (0)