mPCIe Modem QMI Interface Internet Connection Setup #2

As discussed in the previous QMI section the new generation of LTE mPCIE modems provide both HSDPA/3G and LTE/4G wireless connectivity, these modems by default use the newer QMI interface as the primary connection method, as opposed to PPP over serial or Direct IP as with earlier modems in the range, and are currently best supported by Raspbian Jessie OS or above as this has support for the libqmi interface tools.

The lastest generaton models have dropped the support for 802.3 framing data format in favor of the raw-ip format, the result of this means the qmi connection methods previosuly used for earilier generation modems no longer work and we need to modify the connection scripts accordingly

You'll know if the modem you have doesn't support 802.3 mode if you try setting the link method to 802-3 (as per the steps in the previous QMI help document) and the setting does not change

In this example we'll use a Sierra Wireless MC7455 modem and start by installing the udev rule (20-modem-7304.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 :

MyPi Industrial Raspberry Pi Sierra Wireless MC7455 4G Modem QMI Internet Connection Configuration Step 3

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:

MyPi Industrial Raspberry Pi Sierra Wireless MC7304 3G Modem QMI Internet Connection Configuration Step 4

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
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.

We can still take advantage of the qmi-network helper script, but before we can do that we must modify it to use the new raw ip settings as shown above. The below shows the changes you need to make, we have created a new version with all the edits done along with the usual connection montioring scripts and wwan0 interfaces file (see download link at bottom of page).

Here's the commands used and the edits done to the original files, note that this has changed slightly on Raspbian Stretch as the OS introduces a newer version of the qmi-network script with an additional bug so for Stretch additonal lines need changing (see link for more information).

cp /usr/bin/qmi-network /usr/local/bin/qmi-network-raw
vim /usr/local/bin/qmi-network-raw

Raspbian Jessie Edit

MyPi Industrial Raspberry Pi Sierra Wireless MC7455 4G Modem qmi-network raw-ip mode modification

 

Raspbian Stretch/Buster

Raspberry Pi QMI Raw IP Buster Stretch qmi-network modification needed

 

Next we need to setup the SIM APN configuration by creating and then adding a line to /etc/qmi-network.conf - Consult your carrier for the correct APN name and insert it into the configuration file as shown below :

echo "APN=your.sim.apn.name.here" >/etc/qmi-network.conf

So now we can use the below commands to manually start and stop the network connection

 # To start connection
 ifconfig wwan0 down
 ifconfig wwan1 down  # Only needed for Sierra Wireless modems
 qmi-network-raw /dev/cdc-wdm0 start
 udhcpc -i wwan0

 # To stop connection
 qmi-network-raw /dev/cdc-wdm0 stop
 ifconfig wwan0 down

With regards to enabling Raw IP mode note that at startup wwan interfaces are usually enabled but in a disconnected state (usually with a 169.254.x.x. address) and before you can alter the /sys/class/net/wwan0/qmi/raw_ip setting, which needs doing at each bootup as it isn't persistent, all of the modem wwan interfaces need to be brought down (hence the ifconfig wwanx down statements).

As with most Linux related tasks however there is more than one method of achiving something, in this case a neater but more involved method to document would be installing the sysfsutils package and placing this setting in /etc/sysfs.conf, so is worth investigating.

The modemAT serial interface can still be used as normal to interact with the modem or send SMS messages even when connected to the internet.

The above sequence of steps can be automated by creating the configuration file /etc/network/interfaces.d/wwan0 with lines below:

iface wwan0 inet manual
     pre-up ifconfig wwan0 down
     pre-up ifconfig wwan1 down # only needed if the modem presents two wwan interfaces
     pre-up for _ in $(seq 1 10); do /usr/bin/test -c /dev/cdc-wdm0 && break; /bin/sleep 1; done
     pre-up for _ in $(seq 1 10); do /usr/bin/qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength && break; /bin/sleep 1; done
     pre-up /usr/local/bin/qmi-network-raw /dev/cdc-wdm0 start
     pre-up udhcpc -i wwan0
     post-down /usr/local/bin/qmi-network-raw /dev/cdc-wdm0 stop

With this in place wwan0 will attempt to make a cellular connection at each ifup wwan0 event, depending on how long the DHCP process takes you the interface may take a while to get a usable IP address for network useage.

See below finshed example

Sierra Wireless Modem QMI Dialout demo 1

 

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

 

To help the process of getting and maintaining a connection we have create an example script set that can be run as part of the boot process to automate and supervise the modem connection, download these using the link below

Modem QMI Supervisor Script Set -- Raw IP Edition Jessie OS

[ wget --no-check-certificate 'https://drive.google.com/uc?export=download&id=1J1sjJmOYR45O5m51uFlJIhjHpg-LbP-S' -O modemcomms-scripts-rawip.tar.gz ]

Modem QMI Supervisor Script Set -- Raw IP Edition Stretch OS

[ wget --no-check-certificate 'https://drive.google.com/uc?export=download&id=1gdrS4S2Msi36JKiPZnHcBgDEGRyiL-2D' -O modemcomms-scripts-rawip.tar.gz ]

Modem QMI Supervisor Script Set -- Raw IP Edition Buster OS

[ wget --no-check-certificate 'https://drive.google.com/uc?export=download&id=1qE63FmCVEk4sUEsr9ybAkFR23PQWjRut' -O modemcomms-scripts-rawip.tar.gz ]

 

It is worth reading through the section on modem troubleshooting as this covers the more common issues with establishing and maintaining a network connection

Contact us now to discuss your project

Ready to order, contact us today for pricing or samples

Contact Us