416. Mobile broadband
This page is for anyone who wants to get online through a mobile (cellular) data connection: a built-in WWAN (wireless wide-area network) card, a USB modem, or a phone that offers dial-up networking over Bluetooth. Three programs share the work:
- ModemManager finds and drives the modem;
- NetworkManager makes the connection;
mmcli, ModemManager’s command-line client, shows the modem’s state, unlocks its SIM and reads its text messages.
Mobile broadband is built but has not been connected on hardware, so no step on this page has been seen to unlock a SIM, register with a network or connect. What has been checked, on a machine with no modem, is that the service starts with ModemManager holding its bus name, what mmcli answers when there is no modem, and that each profile below can be created.
Installation
| Port | Provides |
|---|---|
| modemmanager | ModemManager, mmcli and libmm-glib |
| libmbim, libqmi, libqrtr-glib | The MBIM, QMI and QRTR protocols ModemManager speaks to a modem; a modem that speaks none of them is driven with AT commands |
| mobile-broadband-provider-info | The carriers’ APN database, /usr/share/mobile-broadband-provider-info/serviceproviders.xml |
| ppp | pppd, for a modem that connects over a serial line |
| networkmanager | The gsm connection type, built with -Dmodem_manager=true and, for a phone, -Dbluez5_dun=true |
All of them are in the network shelf’s list of 41_system, so every image ships them. The kernel drivers for MBIM and QMI USB modems and for PCIe WWAN cards are modules of the linux port, loaded when the device appears.
/etc/init.d/42_modemmanager.sh starts ModemManager at boot on every machine, enabled on the live medium and on an installed system alike. It sorts after 41_polkitd and before 42_networkmanager.
Configuration
The service script
. /etc/init.d/service_helper
# STARTED HERE AND NEVER BY D-BUS ACTIVATION, for the reason polkitd is:
# activating a root service hangs off the setuid launch helper, and a modem
# that is present and never managed says nothing anywhere. The port ships no
# activation file. With one, NetworkManager's call to the name as it starts
# would make the bus run a second ModemManager outside the supervisor; the
# supervised one would lose the name, exit and be started again every five
# seconds, never getting it.
#
# AFTER polkitd (41) AND BEFORE NetworkManager (42_networkmanager, which sorts
# after this name), and `wait_bus_name` holds the boot until the name is
# owned. NetworkManager's WWAN and Bluetooth DUN devices are ModemManager's
# modems; a NetworkManager that found the name unowned would stop asking for
# it and wait for it to appear. fwupd's modem plugin reads the same daemon.
NAME="ModemManager"
DAEMON="/usr/sbin/ModemManager"
case "$1" in
start)
if [ ! -x "$DAEMON" ]; then
echo "[SKIP] $NAME: $DAEMON not found"
exit 0
fi
echo "[KDOS] Starting $NAME..."
# Foreground by default. Left to its own syslog writer it opens the
# log with no ident and copies each line to stderr, which the
# supervisor logs again: every line twice, once untagged. On stdout
# the supervisor logs it once, tagged ModemManager.
supervise "$NAME" "$DAEMON" --log-file=/dev/stdout
wait_bus_name org.freedesktop.ModemManager1
;;
stop)
stop_service "$NAME"
;;
status)
check_status "$NAME"
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
fs/etc/init.d/42_modemmanager.sh
ModemManager is started here rather than by the bus, for the reason given in How polkit and ModemManager are started. It writes its log to standard output (--log-file=/dev/stdout), so the supervisor keeps it in /run/kdos-svc.ModemManager.log and the system log, /var/log/messages, under the tag ModemManager; the script’s own output is in /run/kdos-init.modemmanager.log. Its name for service is modemmanager, and service status modemmanager reports the process as ModemManager.
The supervised ModemManager is the only one. The port’s build.sh deletes the D-Bus activation file ModemManager’s build installs, so the system bus never starts a ModemManager of its own, and the script returns only once the daemon holds org.freedesktop.ModemManager1 (wait_bus_name, from Services), so NetworkManager, which asks for that name as it starts, finds it taken.
The deleted file is what keeps the supervised copy alive. With it, NetworkManager’s call would make the bus start a second ModemManager beside the supervised one. ModemManager exits with status 0 when it cannot take its name, and the supervisor counts an exit 0 within five seconds of the start as a failed start, so the supervised copy would be restarted every five seconds, never get the name, and service status modemmanager would answer [FAIL] (Services). On a working system pgrep -a ModemManager prints one process, a child of the supervisor, and NetworkManager logs modem-manager: ModemManager available.
Who may drive the modem
ModemManager asks polkit before it unlocks a SIM, enables a modem or reads its messages. KDOS builds it with its strict polkit policy, so the person in the active session at the machine does all three with mmcli, or from the network applet, after typing their own password; polkit keeps that answer for a few minutes. KDOS’s rule file adds no rule for these actions. An SSH login, or a session that has been switched away from, is refused, and needs sudo. NetworkManager itself needs no rule, because it runs as root.
The connection profile
A mobile broadband connection is a NetworkManager profile of type gsm, saved under /etc/NetworkManager/system-connections/ like every other; see NetworkManager. Its settings, gsm.apn, gsm.username, gsm.password, gsm.pin and the rest, are listed in nm-settings-nmcli(5).
Usage
Finding the modem
List the modems ModemManager has found:
mmcli -LShow one in full.
anystands for the only modem, or the first:mmcli -m anyThe output gives the modem’s state (
locked,disabled,registered,connectedand so on), its SIM, its signal and the operator it has registered with.
With none found, mmcli -L prints No modems were found and mmcli -m any prints error: couldn't find modem. A modem missing from mmcli -L is either absent from the kernel too (see Troubleshooting) or a USB stick still showing its storage side.
Unlocking the SIM
When mmcli -m any reports the modem locked, give the SIM its PIN:
mmcli -i any --pin=<PIN>
If you skip this, NetworkManager asks for the PIN when it first connects, through the networks applet’s password dialog in a desktop session (see The system tray).
Connecting
Create the profile with your carrier’s APN:
nmcli connection add type gsm ifname '*' con-name mobile apn <apn>ifname '*'lets the profile use whichever modem is present. Addgsm.usernameandgsm.passwordwhen the carrier asks for them.nmtui’s Mobile Broadband entry, under Edit a connection, creates the same profile.Bring it up, and down:
nmcli connection up mobile nmcli connection down mobile
Connecting through a phone over Bluetooth
A phone that offers only dial-up networking over Bluetooth is a modem to ModemManager.
Pair the phone in the Bluetooth applet; see Bluetooth.
Create a Bluetooth profile of the
dunkind, with the phone’s address and the carrier’s APN:nmcli connection add type bluetooth bt-type dun bluetooth.bdaddr <phone> gsm.apn <apn>Bring it up with
nmcli connection upand the profile’s name, whichnmcli connection showlists.
A phone that shares its connection as a network (PAN) needs no modem at all; that is the panu kind, on the NetworkManager page.
Text messages
mmcli -m any --messaging-list-sms # the messages, each with a path or an index
mmcli -s <index> # one message in full
A carrier’s data-limit warnings arrive this way.
On the live medium and on an installed system
The two behave the same. On the live medium a profile lasts until the next reboot unless the medium has a persistence store; see Live persistence.
Tips
- If you do not know the APN, set
gsm.auto-config yeson the profile:nmcli connection modify mobile gsm.auto-config yes. NetworkManager then looks the APN up in the provider database by the network the modem has registered with. mmcli -m any --3gpp-scan --timeout=300lists the operators in range, which shows whether the modem can see a network at all. A scan can take minutes;--timeoutkeepsmmcliwaiting for it.mmcli -m any --enableand--disableswitch the modem’s radio on and off without NetworkManager.- Each option of
mmcliis inmmcli(1);mmcli --help-allprints them grouped.
Troubleshooting
mmcli -L lists no modem. Check that the kernel sees one: dmesg | grep -iE 'mbim|qmi|wwan' shows the driver binding to it, and ls /sys/class/net then lists its network interface. A USB stick that shows up as a small read-only disk is in its storage mode, and nothing on KDOS switches it; see Known gaps. If the kernel has the device and ModemManager does not, check that ModemManager is running and holds the bus name (service status modemmanager, then mmcli -L, which answers error: couldn’t find the ModemManager process in the bus when nothing owns it; see The service script) and read the system log.
mmcli refuses to unlock or enable the modem, or to list its messages. ModemManager lets only the active session at the machine do these, after that person types their own password (see Who may drive the modem). An SSH login, or a session that has been switched away from, is refused outright. Run the command with sudo, or from the desktop session in front of you.
The modem is registered and the connection fails. The APN is the usual cause. Compare the profile’s with the carrier’s (nmcli -f gsm connection show mobile), or turn on gsm.auto-config. NetworkManager’s reason is in the system log: sudo grep NetworkManager /var/log/messages.
More detail is needed. sudo mmcli -G DEBUG raises ModemManager’s log level (it answers Successfully set logging level), and sudo tail -f /var/log/messages then shows what it says to the modem. The level holds until ModemManager exits; sudo service restart modemmanager sets it back to the default.
Known gaps
See also
- Networking: mobile broadband and the other connection types
- How polkit and ModemManager are started
- What 50-kdos.rules changes
- NetworkManager, DNS
- Bluetooth, sudo, PAM and polkit