mPCIe Modem QMI Interface Internet Connection Setup
Modern LTE mPCIE modems offer 4G wireless connectivity, primarily using the QMI interface for connections. This is a departure from older modems that relied on PPP over serial or Direct IP methods. These newer modems are optimally supported by Raspbian Jessie OS or later versions, which include the necessary libqmi interface tools.
A key development in recent modem generations is the shift away from 802.3 framing for cellular data transmission. Instead, these modems now utilize the raw-ip format, necessitating updates to connection scripts and methods.
In this example we'll use a Quectel modem and start by installing the udev rule (20-modem-ec2x.rules) in /etc/udev/rules.d from the modem rule pack. This sets up shortcut references to allow us to consistently identify which of the ttyUSBx ports do which functions
To start we need to install the software support packages via the command below:
apt-get install libqmi-utils udhcpc
This installs two main utilities (qmi-cli tool and qmi-network helper script) these are used for interaction with the modem and udhcp package (which supports raw-ip mode) and makes configuring the OS networking post connection easier.
Having checked we've registered on the network and have good signal let's push on and connect to the network :
There are essentially 4 steps here:
1. Set the QMI kernel driver to work in raw-ip mode
2. Ensure the wwan0 network interface is ready
3. Connect to the cellular network
4. Run a raw-ip supporting DHCP client to configure the network interface and routing/DNS
So let's step through a sample connection here:
ifconfig wwan0 down ifconfig wwan1 down # Only needed for Sierra Wireless modems # Enable OS Raw IP Mode setting (not persistent) echo Y > /sys/class/net/wwan0/qmi/raw_ip ifconfig wwan0 up # Next line for Jessie OS -- Change APN Name! qmicli -d /dev/cdc-wdm0 --device-open-net="net-raw-ip|net-no-qos-header" --wds-start-network=your.sim.apn.name.here --client-no-release-cid # Next line for Stretch/Buster OS -- Change APN Name! qmicli -d /dev/cdc-wdm0 --device-open-net="net-raw-ip|net-no-qos-header" --wds-start-network="apn='your.sim.apn.name.here',ip-type=4" --client-no-release-cid udhcpc -i wwan0 # Stop Connection qmicli -d /dev/cdc-wdm0 --wds-stop-network='2267205232' --client-cid='20' # Uses the ID numbers from the start command ifconfig wwan0 down
You'll see that once the network connection is made the network interface just needs to be configured via the udhcp client, this has the bonus of automatically configuring routing and DNS.
Note that once the network connection is disconnected the interface will need to be brought down (by using ifconfig wwan0 down to correct the routing/DNS configuration.
Other commands of interest are shown below, for more information see man qmicli
qmicli -d /dev/cdc-wdm0 --nas-get-signal-info qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength qmicli -d /dev/cdc-wdm0 --nas-get-home-network qmicli -d /dev/cdc-wdm0 --nas-get-serving-system qmicli -d /dev/cdc-wdm0 --dms-uim-verify-pin=PIN,0000 qmi-network /dev/cdc-wdm0 status qmicli -d /dev/cdc-wdm0 --wds-get-packet-service-status
It is worth reading through the section on modem troubleshooting as this covers the more common issues with establishing and maintaining a network connection
Modem Connection Manager
We have created a management script you can download to provide connection managment and checking, see link below
Connection Manager Github Repo