Cellular modem
This section applies to models with a cellular modem, such as the WL830S.
Security
Warning
An ssh server listening on wwan0 or ppp0 and accepting a weak or default password is an easy target. It can be broken into within seconds after the modem connects to the Internet.
We strongly recommend protecting your system with a firewall and review services and ports before enabling the cellular connection. While your office firewall or home router may protect a weak default password, a public IP address leaves your Kvaser Edge open to connections so make sure you understand this topic well.
Add a table modem_wan to /etc/nftables.conf.
On wwan0, ppp0 and qmimux*, it accepts only replies to the unit's own traffic, and IPv6 router advertisements on ppp0; other interfaces are not filtered.
Keep all rules in this file: flush ruleset at the top removes every rule that is not in it.
#!/usr/sbin/nft -f
flush ruleset
# The modem gives the container a public address, reachable from the
# internet. Accept only replies to the container's own traffic on the cellular
# interfaces, and IPv6 router advertisements on ppp0. Other interfaces are not
# filtered here.
table inet modem_wan {
chain input {
type filter hook input priority filter; policy accept;
iifname != { "wwan0", "ppp0" } iifname != "qmimux*" accept
ct state established,related accept
# ppp0 gets its IPv6 address from these. Hop limit 255: sent on the link
iifname "ppp0" icmpv6 type nd-router-advert ip6 hoplimit 255 accept
counter drop comment "wan-drop"
}
chain forward {
type filter hook forward priority filter; policy accept;
iifname { "wwan0", "ppp0" } counter drop comment "wan-forward-drop"
iifname "qmimux*" counter drop comment "wan-forward-drop"
}
}
Enable nftables at boot:
systemctl enable --now nftables
If it was already enabled when you saved nftables.conf, reload it instead:
systemctl reload nftables
Devices in the container
The built-in modem connects the Kvaser Edge unit to a cellular (mobile) network using a factory installed SIM card. The container gets full access to the modem, including its device files and network interfaces. The following sections show how to configure it.
The container has these devices for the modem:
| Device | Use |
|---|---|
/dev/modem |
AT commands |
/dev/cdc-wdm0 |
QMI control |
/dev/ppp |
Kernel PPP device |
wwan0 |
Network interface (ModemManager) |
ppp0 |
Network interface (created when PPP is used) |
wwan0 and ppp0 need no entry in container-config.yaml.
Note
The modem takes time to start. After a cold start or wakeup, it answers AT commands after about 20 seconds and attaches to the network after about 50 seconds. Before that, it cannot connect.
SIM
PIN
Remember that your SIM either needs PIN code disabled or you need to provide it in your configuration for your chosen software.
eSIM
If your Kvaser Edge is equipped with an eSIM type SIM, you can manage its
profiles with lpac, built with QMI
support. Download lpac-linux-aarch64-with-qmi.zip from its
releases.
export LPAC_APDU=qmi
export LPAC_HTTP=curl
export LPAC_APDU_QMI_DEVICE=/dev/cdc-wdm0
export LPAC_APDU_QMI_UIM_SLOT="${LPAC_APDU_QMI_UIM_SLOT:-${UIM_SLOT:-1}}"
lpac chip info
Warning
Switching profile disables the current one and interrupts the cellular bearer, so keep another way into the unit.
To switch profile, enable it and reset the modem so ModemManager picks up the new SIM:
lpac profile enable ICCID-REPLACE-ME
mmcli -m any --reset
Downloading a profile needs a working Internet connection and an activation code from the profile provider. Treat activation and confirmation codes as secrets: keep them out of shell history, logs and support requests.
lpac profile download -a 'LPA:1$sm-dp-plus.example$ACTIVATION_CODE'
Choose client software
ModemManager
If you use ModemManager, it needs a few
changes to run in the container. This drop-in makes it read the modem's ports
from /host/modem/kernel-events, since there is no udev in the container, and
lets it release its QMI clients when it stops:
# ModemManager in the KEOS user container
[Unit]
# The stock unit skips containers
ConditionVirtualization=
# Stop before D-Bus. ModemManager exits as soon as it loses the bus, before it
# has disabled the modem and released its QMI clients, which leak in the modem
# until it fails with "Couldn't peek client for service 'nas'".
After=dbus.service
[Service]
# There is no udev in the container: read the modem's ports from the host
ExecStart=
ExecStart=/usr/sbin/ModemManager --test-no-udev --no-auto-scan --initial-kernel-events=/host/modem/kernel-events
# Stop ModemManager alone and let it stop its qmi-proxy, so that it can
# release its QMI clients. Backport of upstream commit 225e66fe ("service:
# don't SIGTERM the QMI/MBIM proxies together with the daemon"); remove once
# the container's ModemManager has it.
KillMode=mixed
This rule file tells ModemManager which of the modem's ports are AT and QCDM, and gives the AT port up to 60 seconds to answer. Without udev, ModemManager reads it itself:
# Telit FN920 port types. ModemManager reads this file itself when it runs
# without udev. The name must start with one of 77-mm- to 80-mm- for that.
ACTION!="add|change|move|bind", GOTO="mm_kvaser_fn920_end"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="10a0", GOTO="mm_kvaser_fn920"
GOTO="mm_kvaser_fn920_end"
LABEL="mm_kvaser_fn920"
SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}"
ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="10a0", ENV{.MM_USBIFNUM}=="02", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1"
# Up to 20 AT tries of 3 s instead of 6. ModemManager's own parser takes one
# assignment per line.
ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="10a0", ENV{.MM_USBIFNUM}=="02", SUBSYSTEM=="tty", ENV{ID_MM_TTY_AT_PROBE_TRIES}="20"
ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="10a0", ENV{.MM_USBIFNUM}=="03", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_QCDM}="1"
LABEL="mm_kvaser_fn920_end"
Bring up the connection on wwan0 with, for example,
NetworkManager. Limit it to the modem, so
that it leaves the other interfaces alone, and keep it down without the
firewall rules:
# NetworkManager handles only the modem and leaves the other interfaces alone
[main]
no-auto-default=*
[keyfile]
unmanaged-devices=*,except:interface-name:cdc-wdm*,except:interface-name:wwan0,except:interface-name:qmimux*
# Do not bring up the cellular connection without its firewall
[Unit]
Requires=nftables.service
After=nftables.service
Load the new configuration:
systemctl daemon-reload
systemctl restart ModemManager NetworkManager
Then create a connection for the modem. Leave the APN empty for the network's
default one, or give yours; without gsm.apn, nmcli sets internet:
nmcli connection add type gsm ifname '*' con-name modem gsm.apn '' \
connection.autoconnect-retries 0 ipv4.route-metric 2000 ipv6.route-metric 2000
With autoconnect-retries 0, NetworkManager keeps trying while the modem
starts. The route metric is above systemd-networkd's default of 1024, so a LAN
route is preferred over the cellular one.
For IPv6, if your network offers it, also set the modem's stored default
profile to IPv4 and IPv6. Use the same APN as the connection; without apn=,
mmcli clears it:
mmcli -m any --3gpp-profile-manager-set="profile-id=1,apn=,ip-type=ipv4v6"
PPP
Instead of ModemManager, you can connect with pppd.
Create a configuration file for the pppd call command:
/dev/modem
115200
# The network does not authenticate itself
noauth
# Ignore DCD; with "modem" the call hangs up after PAP
local
nocrtscts
noipdefault
usepeerdns
+ipv6
defaultroute
# Hang up after 30 s without replies, such as when the data session dies
lcp-echo-interval 10
lcp-echo-failure 3
connect "/usr/sbin/chat -v -f /etc/chatscripts/modem"
Also, create an associated chat script controls the connection process:
# Dials the modem for pppd, see /etc/ppp/peers/modem.
ABORT "ERROR"
ABORT "NO CARRIER"
# Stop at once if the modem has not attached to the network yet, since
# dialing before that fails
ABORT "+CGATT: 0"
TIMEOUT 20
"" "AT+CGATT?"
# \c sends nothing: just wait for the attach state
"+CGATT: 1" "\c"
# IPV4V6 for IPv6. The modem stores this context, also for ModemManager.
# Your APN between the empty quotes, or empty for the network's default one
"OK" "AT+CGDCONT=1,\"IPV4V6\",\"\""
"OK" "ATD*99***1#"
"CONNECT" ""
With +ipv6, ppp0 gets its IPv6 address from router advertisements, which
the firewall above accepts. Keep accept_ra on for ppp0, or 2 if the
container forwards traffic.
Debian's usepeerdns hook does nothing when systemd-resolved runs. This hook
hands the network's DNS servers to systemd-resolved instead:
#!/bin/sh -eu
# Hand the DNS servers the network gave pppd to systemd-resolved
[ -n "${IFNAME:-}" ] || exit 0
servers=
for server in "${DNS1:-}" "${DNS2:-}"; do
[ -n "$server" ] && servers="${servers}${servers:+ }$server"
done
[ -n "$servers" ] || exit 0
# shellcheck disable=SC2086 # one argument per server
resolvectl dns "$IFNAME" $servers
resolvectl domain "$IFNAME" '~.'
Make it executable:
chmod +x /etc/ppp/ip-up.d/90-resolved
Create a service that starts pppd after nftables.service is successfully started:
[Unit]
Description=Connect the modem with pppd
# Do not bring up the cellular connection without its firewall
Requires=nftables.service
After=nftables.service
# Both use the modem's AT port
Conflicts=ModemManager.service
[Service]
# Wait for the modem's AT port, which is missing until the modem has started
ExecStartPre=/bin/sh -c 'until [ -e /dev/modem ]; do sleep 1; done'
ExecStart=/usr/sbin/pppd call modem nodetach
# Dial again if the modem was not attached yet or went away, such as on suspend
Restart=always
RestartSec=5
# pppd's exit status when stopped
SuccessExitStatus=5
[Install]
WantedBy=multi-user.target
Enable and start ppp:
systemctl enable --now modem-ppp
If ModemManager is installed, for example because NetworkManager recommends it,
disable it, so that only modem-ppp starts at boot:
systemctl disable --now ModemManager
Troubleshooting
ModemManager
The modem does not register. Check the SIM, or the enabled eSIM profile,
and its subscription before the APN. The reject cause is in
journalctl -u ModemManager.
The modem is failed with unknown-capabilities. If
journalctl -u ModemManager shows Couldn't peek client for service 'nas',
the modem has run out of QMI clients. Restarting ModemManager does not help;
mmcli -m any --reset does.
AT commands. mmcli --command needs ModemManager with --debug.
Otherwise stop ModemManager and use /dev/modem.
PPP
chat fails with ERROR after ATD*99***1#. A previous call is still
open, for example after dialing by hand. +++ and ATH do not end it. If
ATO on /dev/modem returns CONNECT, run pppd on that call and stop it,
which ends the call:
pppd call modem connect '/usr/sbin/chat -v "" AT OK ATO CONNECT'
pppd gets no IP address. If pppd logs
IPCP: timeout sending Config-Requests after authentication, restart the unit.