Skip to content

Commit

Permalink
application: serial_lte_modem: integrate CMUX with PPP
Browse files Browse the repository at this point in the history
The UART-based PPP driver is replaced by
the PPP module of the modem subsystem.

When both CMUX and PPP are enabled, CMUX automatically configures
a second channel for PPP which can only be used through it.

Thus, CMUX should be started before PPP, which means before activating
LTE as PPP starts automatically when the LTE link goes up. However,
SLM tolerates that CMUX is started only after LTE and PPP are up.

As of now, upstream Zephyr commits are needed for this to work properly.

Signed-off-by: Tomi Fontanilles <[email protected]>
  • Loading branch information
tomi-font authored and cvinayak committed Feb 7, 2024
1 parent 88fbaa7 commit 5458ab1
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/* Include this overlay only if using PPP without CMUX. */

/ {
chosen {
zephyr,ppp-uart = &uart1;
ncs,slm-ppp-uart = &uart1;
};
};

Expand Down
21 changes: 7 additions & 14 deletions applications/serial_lte_modem/overlay-ppp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ CONFIG_TFM_SECURE_UART_SHARE_INSTANCE=y
# Zephyr PPP support
CONFIG_NET_NATIVE=y
CONFIG_NET_L2_PPP=y
CONFIG_NET_DRIVERS=y
CONFIG_NET_PPP=y
CONFIG_MODEM_MODULES=y
CONFIG_MODEM_PPP=y
CONFIG_MODEM_BACKEND_UART=y
# Allow large UART TXs to go through @115200.
CONFIG_MODEM_BACKEND_UART_ASYNC_TRANSMIT_TIMEOUT_MS=400

# L2 protocol
CONFIG_NET_L2_PPP_MGMT=y
Expand All @@ -39,16 +42,6 @@ CONFIG_NET_L2_PPP_OPTION_SERVE_DNS=y
CONFIG_NET_L2_PPP_TIMEOUT=5000
CONFIG_NET_L2_PPP_MAX_CONFIGURE_REQ_RETRANSMITS=20

# UART driver
CONFIG_NET_PPP_ASYNC_UART=y
CONFIG_NET_PPP_UART_BUF_LEN=2048
CONFIG_NET_PPP_ASYNC_UART_TX_BUF_LEN=4096
CONFIG_NET_PPP_RINGBUF_SIZE=4096
CONFIG_NET_PPP_RX_STACK_SIZE=2048
CONFIG_NET_PPP_VERIFY_FCS=n
CONFIG_PPP_CLIENT_CLIENTSERVER=y # Windows support
CONFIG_PPP_NET_IF_NO_AUTO_START=y

# IP stack
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
Expand All @@ -66,9 +59,9 @@ CONFIG_NET_TC_RX_COUNT=0

# debug options
#CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096
#CONFIG_LOG_DEFAULT_LEVEL=4
#CONFIG_NET_LOG=y
#CONFIG_NET_PKT_LOG_LEVEL_DBG=y
#CONFIG_NET_PPP_LOG_LEVEL_DBG=y
#CONFIG_NET_L2_PPP_LOG_LEVEL_DBG=y
#CONFIG_NET_MGMT_EVENT_LOG_LEVEL_DBG=y
#CONFIG_MODEM_MODULES_LOG_LEVEL_DBG=y
#CONFIG_UART_LOG_LEVEL_DBG=y
3 changes: 2 additions & 1 deletion applications/serial_lte_modem/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ CONFIG_SLM_EXTERNAL_XTAL=n
CONFIG_SLM_START_SLEEP=n
CONFIG_SLM_DATAMODE_URC=n

# Debug configurations
# debug options
#CONFIG_ASSERT=y
#CONFIG_LOG_BUFFER_SIZE=16384
#CONFIG_SLM_LOG_LEVEL_DBG=y
#CONFIG_LOG_PRINTK=n
Expand Down
11 changes: 10 additions & 1 deletion applications/serial_lte_modem/src/slm_at_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,16 @@ int slm_at_init(void)
return -EFAULT;
}
#endif

#if defined(CONFIG_SLM_CMUX)
slm_cmux_init();
#endif
#if defined(CONFIG_SLM_PPP)
err = slm_ppp_init();
if (err) {
LOG_ERR("PPP initialization failed. (%d)", err);
return err;
}
#endif
return err;
}

Expand Down
8 changes: 0 additions & 8 deletions applications/serial_lte_modem/src/slm_at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,14 +892,6 @@ int slm_at_host_init(void)
return -EFAULT;
}

#if defined(CONFIG_SLM_PPP)
err = slm_ppp_init();
if (err) {
LOG_ERR("PPP initialization failed (%d).", err);
return err;
}
#endif

k_work_init(&raw_send_scheduled_work, raw_send_scheduled);

err = slm_uart_handler_enable();
Expand Down
48 changes: 30 additions & 18 deletions applications/serial_lte_modem/src/slm_cmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ LOG_MODULE_REGISTER(slm_cmux, CONFIG_SLM_LOG_LEVEL);

enum cmux_channel {
AT_CHANNEL,
#if defined(CONFIG_SLM_PPP)
PPP_CHANNEL,
#endif
CHANNEL_COUNT
};

Expand Down Expand Up @@ -77,8 +80,9 @@ static void dlci_pipe_event_handler(struct modem_pipe *pipe,

static void cmux_event_handler(struct modem_cmux *, enum modem_cmux_event event, void *)
{
assert(event == MODEM_CMUX_EVENT_CONNECTED || event == MODEM_CMUX_EVENT_DISCONNECTED);
LOG_INF("CMUX %sconnected.", (event == MODEM_CMUX_EVENT_CONNECTED) ? "" : "dis");
if (event == MODEM_CMUX_EVENT_CONNECTED || event == MODEM_CMUX_EVENT_DISCONNECTED) {
LOG_INF("CMUX %sconnected.", (event == MODEM_CMUX_EVENT_CONNECTED) ? "" : "dis");
}
}

static void init_dlci(size_t dlci_idx, uint16_t recv_buf_size,
Expand Down Expand Up @@ -151,6 +155,30 @@ static bool cmux_is_initialized(void)
return (cmux.uart_pipe != NULL);
}

void slm_cmux_init(void)
{
const struct modem_cmux_config cmux_config = {
.callback = cmux_event_handler,
.receive_buf = cmux.cmux_receive_buf,
.receive_buf_size = sizeof(cmux.cmux_receive_buf),
.transmit_buf = cmux.cmux_transmit_buf,
.transmit_buf_size = sizeof(cmux.cmux_transmit_buf),
};

modem_cmux_init(&cmux.instance, &cmux_config);

for (size_t i = 0; i != ARRAY_SIZE(cmux.dlcis); ++i) {
init_dlci(i, sizeof(cmux.dlcis[i].receive_buf), cmux.dlcis[i].receive_buf);
}
}

#if defined(CONFIG_SLM_PPP)
void *slm_cmux_get_ppp_channel_pipe(void)
{
return cmux.dlcis[PPP_CHANNEL].pipe;
}
#endif

static int cmux_start(void)
{
int ret;
Expand All @@ -177,22 +205,6 @@ static int cmux_start(void)
return -ENODEV;
}
}
{
const struct modem_cmux_config cmux_config = {
.callback = cmux_event_handler,
.receive_buf = cmux.cmux_receive_buf,
.receive_buf_size = sizeof(cmux.cmux_receive_buf),
.transmit_buf = cmux.cmux_transmit_buf,
.transmit_buf_size = sizeof(cmux.cmux_transmit_buf),
};

modem_cmux_init(&cmux.instance, &cmux_config);
}
{
for (size_t i = 0; i != ARRAY_SIZE(cmux.dlcis); ++i) {
init_dlci(i, sizeof(cmux.dlcis[i].receive_buf), cmux.dlcis[i].receive_buf);
}
}

ret = modem_cmux_attach(&cmux.instance, cmux.uart_pipe);
if (ret) {
Expand Down
6 changes: 6 additions & 0 deletions applications/serial_lte_modem/src/slm_cmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#include <modem/at_cmd_parser.h>

void slm_cmux_init(void);

#if defined(CONFIG_SLM_PPP)
void *slm_cmux_get_ppp_channel_pipe(void);
#endif

int handle_at_cmux(enum at_cmd_type cmd_type);

#endif
Loading

0 comments on commit 5458ab1

Please sign in to comment.