Connect cellular module in QMI mode with libqmi

Start a data connection on a Quectel or Telit module in QMI mode with qmicli and the in-kernel qmi_wwan driver, get an IP address with udhcpc, test and stop it.

Modules with a Qualcomm chipset have a QMI interface. qmicli from libqmi starts the data connection through the in-kernel qmi_wwan driver, and udhcpc gives the interface its IP address.

Requirements

Finish the quickstart of the board first: Get started with Base HAT, Get started with 4G/LTE Cellular Modem Kit or Get started with Jetson Nano Cellular Modem Kit.

Required

Hardware

  • Base HAT, 4G/LTE Cellular Modem Kit or Jetson Nano Cellular Modem KitAssembled as in the quickstart of the Base HAT, the 4G/LTE kit or the Jetson Nano kit, with the USB cable connected.
  • A module with a QMI interfaceFor example Quectel EC25, EG25-G, EC21 or UC20-G, or Telit LE910C1 or LE910C4.

SIM

  • SIM card with data serviceIts APN, and a username and password if the operator uses them. The Sixfab SIM and the KORE Super SIM (formerly Twilio Super SIM) use the APN super, without username or password.

Software

Stop ModemManager

  1. Stop and disable ModemManager

    On Raspberry Pi OS Bookworm and later, ModemManager is installed by default and can take over the module. Stop and disable it, or remove it with sudo apt purge modemmanager -y:

    sudo systemctl stop ModemManager.service
    sudo systemctl disable ModemManager.service

Check driver and module mode

  1. Check driver

    lsusb -t

    One interface of the module uses the qmi_wwan driver. This page needs qmi_wwan; libqmi does not work with Qualcomm’s GobiNet driver.

    |__ Port 4: Dev 6, If 4, Class=Vendor Specific Class, Driver=qmi_wwan, 480M

    If the module has no network driver, see the driver guide of the module manufacturer, linked in the Base HAT troubleshooting.

  2. Check that module is in QMI mode

    Send the AT commands of your module, as in Send AT commands:

Install libqmi

  1. Install libqmi-utils and udhcpc

    sudo apt update && sudo apt install libqmi-utils udhcpc

    libqmi-utils installs qmicli, which talks to the module (man qmicli), and the qmi-network helper script; udhcpc sets the IP address. The commands below use the control device /dev/cdc-wdm0 and the interface wwan0; with more than one modem, sudo qmicli -d /dev/cdc-wdm0 --get-wwan-iface prints the interface of a control device.

Start data connection

  1. Check that module is online

    sudo qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode

    The answer includes Mode: 'online'. If it does not, set it:

    sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
  2. Set interface to raw IP

    sudo ip link set wwan0 down
    echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
    sudo ip link set wwan0 up

    To check the data format of the module:

    sudo qmicli -d /dev/cdc-wdm0 --wda-get-data-format
  3. Connect to network

    Replace the APN, username and password with those of your SIM and operator; without a username and password, delete those two parameters:

    sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='YOUR_APN',username='YOUR_USERNAME',password='YOUR_PASSWORD',ip-type=4" --client-no-release-cid

    With the Sixfab SIM or the KORE Super SIM:

    sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='super',ip-type=4" --client-no-release-cid

    The answer says Network started and gives the packet data handle and the client ID (CID) that --client-no-release-cid keeps open. Note both: they stop the connection.

  4. Get IP address and default route

    sudo udhcpc -q -f -i wwan0

    The answer ends with the lease, for example udhcpc: lease of 100.67.114.164 obtained, lease time 7200. With -q, udhcpc exits once it has the lease.

Verify

  1. Check interface address

    ip addr show wwan0
    Result: wwan0 has the address of the lease.
  2. Ping through cellular interface

    ping -I wwan0 -c 5 sixfab.com
    $ ping -I wwan0 -c 5 sixfab.com
    PING sixfab.com (172.67.75.126) from 100.67.114.164 wwan0: 56(84) bytes of data.
    64 bytes from 172.67.75.126 (172.67.75.126): icmp_seq=1 ttl=29 time=247 ms
    64 bytes from 172.67.75.126 (172.67.75.126): icmp_seq=2 ttl=29 time=205 ms
    64 bytes from 172.67.75.126 (172.67.75.126): icmp_seq=3 ttl=29 time=207 ms
    64 bytes from 172.67.75.126 (172.67.75.126): icmp_seq=4 ttl=29 time=204 ms
    64 bytes from 172.67.75.126 (172.67.75.126): icmp_seq=5 ttl=29 time=216 ms
    --- sixfab.com ping statistics ---
    5 packets transmitted, 5 received, 0% packet loss, time 8ms
    rtt min/avg/max/mdev = 204.050/215.839/247.004/16.201 ms

    Five replies and 0% packet loss mean the connection works; addresses and times differ by network.

Details

Stop connection

Use the packet data handle and the CID from the start command:

sudo qmicli -p -d /dev/cdc-wdm0 --wds-stop-network=PACKET_DATA_HANDLE --client-cid=CID

Troubleshooting

The module is not in QMI mode, or qmi_wwan is not loaded: see Check driver and module mode.

Check the SIM (AT+CPIN?), the registration (AT+CREG?) and the APN, username and password.

Check that /sys/class/net/wwan0/qmi/raw_ip is Y, and that ModemManager is stopped.

Power, SIM, antenna and USB checks are in the Base HAT troubleshooting.

Next steps