OpenWRT 4G WAN configuration

This step by step tutorial will show you how to configure a 4G mPCIe cellular modem, and use it as the main internet connection in OpenWRT. 

Please note this article assumes that you have OpenWRT already installed. If that's not the case, please start by installing OpenWRT on your router.

4G hardware compatible with OpenWRT

The first thing you need to do it to have compatible hardware. There are many 3G, 4G and LTE modems on the market, but not all of them work well with OpenWRT. Some modems aren't compatible with some motherboards.  

In this tutorial, we are using Quectel EC25-E LTE modem with APU4D4 motherboard. This hardware combination works very well in our experience.

If you are also using PC Engines APU3 or APU4, please make sure to connect the SIM card to SIM1 slot, and your modem to the middle mPCIe slot. If your operating system is installed on an SD card or USB thumb drive, you can also use the first mPCIe slot that is usually occupied by the mSATA SSD drive. In that case, you should connect the SIM card to SIM2 slot. 

Please refer to the image below for details.


4G LTE speed

The popular mobile modems available on the market are Category 4. Category 4 modems can get a theoretical maximum of 150Mbps download speed and 50Mbps upload speed. Please note that these speeds are theoretical, and in practice, the speed of 100Mbit/s is often maximum achievable. The actual speed depends on a variety of factors such as distance to the nearest base station, capabilities of the base station, antennas used, time of day or even weather conditions.

Configuring QMI interface 

There are many different proprietary cellular communication protocols and it may be a little overwhelming to know which ones work well, which ones your modem supports and how to get the modem working properly. There are PPP, QMI, MBIM, NCM and a few others. Each one is configured slightly differently and has a different level of support in OpenWRT. That's a mess worth its own article.

In this article, we are using the Quectel modem so we will use the QMI protocol. This protocol is well supported in OpenWRT and is able to deliver a good performance.

Step 1: Install QMI software packages

Go to Software -> Update list -> search for QMI -> install the following packages.

qmi-utils luci-proto-qmi

Now you need to reboot the router. If you don't reboot, the next step won't work.

Step 2: Create the QMI interface

Go to Network => Interfaces => click "Add new interface"

You can input any name you like. In this example, I named my interface "4G". 

In the protocol field choose "QMI". If you don't see QMI on the list, you have not installed the right packages or haven't rebooted the router.

 

Click "create interface" to go to the next step. 

This is the main configuration screen for your LTE connection. The important configuration fields here are "APN" and "Modem device". 

Step 3: APN configuration

APN stands for Access Point Name and it's the name your modem will try to connect to gain access to the public internet. It's similar to SSID in WiFi networks. If you don't know what to input here, google for "APN + your provider name". 

Select "/dev/cdc-wdm0" in the "Modem device" dropdown. If you don't see this device in the dropdown, your modem is not detected. Go to the troubleshooting section.

​​​​​​​Input the other fields as you see on the screenshot. If your SIM card has a PIN number, make sure to enter that.

click save.

After a minute, your interfaces should look like on the screenshot below. 

Please note that two interfaces showed up. One called "4G" and another one "Virtual dynamic interface (DHCP client)" called "4G_4".

The "_4" means that the interface has an IPv4 IP address. This is based on the "PDP Type" selected in the previous step. If your carrier supports IPv6, you can use that as well (not recommended).  

If you see a valid IPv4 address, like on the screenshot, it means that your connection has been established successfully, and the last thing to do is to configure the 4G interface as a default WAN. 

If you see "NETWORK_REGISTRATION_FAILED", power off the router, wait a couple of seconds and power it back on. A soft reboot may not work, do a full shutdown. If this did not help, go to the troubleshooting section. 

Step 4: Set the 4G interface as default WAN

Note, on the previous screenshot there's a wired WAN interface on eth0. We will need to delete this interface and configure the 4G interface as WAN.

Click the "Delete" button next to "WAN" and confirm the deletion.

Now click "Edit" on the 4G interface => go to Firewall settings tab => Assign firewall zone => Select WAN => Save.

 

The result should look similar to the screenshot below. At this point, you should have a working 4G router.

You can verify the speed with http://www.bredbandskollen.se/ 

The speeds I have seen are highly dependent on the time of day. With this configuration, I have seen speeds between 50Mbit/s to a little over 100Mbit/s. Typically around 70-80Mbit/s. 

Troubleshooting

If you run into some problems, here are a few commands to help you diagnose the problem. You need an ssh session or a serial console connection to type these commands.

Check the connection status

Here's how it should look like when the modem is connected and disconnected

root@OpenWrt:/# uqmi -d /dev/cdc-wdm0 --get-data-status
"disconnected"
    
root@OpenWrt:/# uqmi -d /dev/cdc-wdm0 --get-data-status
"connected"

uqmi commands hang

If you type any uqmi command and get no output, you may need to edit the qmi.sh script to fix it.

The file is located in /lib/netifd/proto/qmi.sh

Locate the line that looks like this:

while uqmi -s -d "$device" --get-pin-status | grep '"UIM uninitialized"' > /dev/null; do

On OpenWRT 19.7 it's on line 83. It might be on a different line if you have a newer or older OS version.

Add the following 3 lines before the line above.

uqmi -s -d "$device" --get-pin-status &
sleep 3
killall uqmi || echo "UQMI now works fine!"

This fix is currently necessary for SIM7600G-H card.

Check SIM status

With SIM not detected it looks like this:

root@OpenWrt:/# qmicli --device=/dev/cdc-wdm0 --device-open-proxy --uim-get-card-status
[/dev/cdc-wdm0] Successfully got card status
Provisioning applications:
        Primary GW:   session doesn't exist
        Primary 1X:   session doesn't exist
        Secondary GW: session doesn't exist
        Secondary 1X: session doesn't exist
Slot [1]:
        Card state: 'error: no-atr-received (3)'
        UPIN state: 'not-initialized'
                UPIN retries: '0'
                UPUK retries: '0'

With SIM detected, it should look similar to this:

root@OpenWrt:/# qmicli --device=/dev/cdc-wdm0 --device-open-proxy --uim-get-card-status
[/dev/cdc-wdm0] Successfully got card status
Provisioning applications:
        Primary GW:   slot '1', application '1'
        Primary 1X:   session doesn't exist
        Secondary GW: session doesn't exist
        Secondary 1X: session doesn't exist
Slot [1]:
        Card state: 'present'
        UPIN state: 'not-initialized'
                UPIN retries: '0'
                UPUK retries: '0'
        Application [1]:
                Application type:  'usim (2)'
                Application state: 'ready'
                Application ID:
                        A0:00:00:00:87:10:02:FF:44:FF:FF:89:06:00:00:FF
                Personalization state: 'ready'
                UPIN replaces PIN1: 'no'
                PIN1 state: 'disabled'
                        PIN1 retries: '3'
                        PUK1 retries: '10'
                PIN2 state: 'enabled-not-verified'
                        PIN2 retries: '3'
                        PUK2 retries: '10'

Note, on APU routers you must turn off the device, pull the power cable, and plug it back in for SIM to be detected. Hot-swapping, or even regular rebooting won't work.

Signal status

Weak signal, with antenna disconnected.

root@OpenWrt:/# uqmi -d /dev/cdc-wdm0 --get-signal-info
{
        "type": "lte",
        "rssi": -90,
        "rsrq": -9,
        "rsrp": -125,
        "snr": 34
}

And here's what strong signal should look like when one antenna is connected properly.


root@OpenWrt:/# uqmi -d /dev/cdc-wdm0 --get-signal-info
{
        "type": "lte",
        "rssi": -66,
        "rsrq": -8,
        "rsrp": -97,
        "snr": 186
}

connection settings

root@OpenWrt:/# uqmi -d /dev/cdc-wdm0 --get-current-settings
{
        "pdp-type": "ipv4-or-ipv6",
        "ip-family": "ipv4",
        "mtu": 1500,
        "ipv4": {
                "ip": "100.68.0.195",
                "dns1": "80.251.201.177",
                "dns2": "80.251.201.178",
                "gateway": "100.68.0.196",
                "subnet": "255.255.255.248"
        },
        "ipv6": {

        },
        "domain-names": {

        }
}

Good luck!