Use USB CDC-NCM capable dongles for WWAN connection

USB CDC-NCM (Network Control Model) is an USB device class for Ethernet over USB function (alternative to the older and simpler CDC-ECM (Ethernet Control Model).

The same applies to modems connected to external USB ports or internal USB-capable M.2(NGFF) or miniPCIe slots.

For more information about other protocols commonly used:

You may need to switch your modem to provide a native NCM interface instead of serial Modem interface. Dongles usually supports many different modes, even in parallel. If yours have also older ECM native mode, make sure to understand how to actually use NCM instead. In Linux, there are separate drivers for CDC-ECM and CDC-NCM; uninstalling the CDC-ECM driver (cdc-ether) avoids the older ECM interface from appearing as an available interface even if the dongle is exposing one.

:!: Please read about AT commands for your modem.

Once you've done - you can disconnect modem from the PC and connect it to the router.

1. Install OpenWrt

2. Complete steps OpenWrt Configuration

Router should be turned on and connected to the Internet to get the needed packages. Please refer to: Internet Connection.

To make use of NCM protocol, package comgt-ncm is needed along with NCM drivers kmod-usb-net-cdc-ncm (and kmod-usb-net-huawei-cdc-ncmfor Huawei modems).

To access the PC-side modem interface (AT serial command port), package kmod-usb-serial-option is typically needed. Some modems may also need kmod-usb-acm driver for their serial command port.

1. Install usb-modeswitch only if that is needed for switching the modem into a “working” state. More about: USB mode switch

2. A terminal program like picocom will be needed to manually send AT commands.

3. Add support for FlashCard of your dongle - refer to: USB Storage

1. Install all the needed packages either in Luci → System → Software or via command line:

  • For generic NCM modems (via LuCI):
root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install luci-proto-ncm picocom

The luci-proto-ncm package will also install comgt-ncm which in turn installs other commonly needed drivers including kmod-usb-net-cdc-ncm, kmod-usb-net-huawei-cdc-ncm and kmod-usb-serial-option.

  • For Huawei modems:

You will need kmod-usb-net-huawei-cdc-ncm. Make sure it is installed (either directly or as luci-proto-ncm/comgt-ncm dependency.

root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install kmod-usb-net-huawei-cdc-ncm
  • For modems requiring ACM for serial control interface:

Other modems like Mikrotik exposes the serial control interface via an ACM driver, you will also need kmod-usb-acm:

root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install kmod-usb-acm

Additional packages will be automatically installed as dependencies.

You can also add the necessary packages when building a new image with Firmware Selector.

:!: If your have not enough space on your device - think about upgrading your hardware or installing Rootfs on External Storage (extroot). Refer to your router wiki page or forum thread for possibility and instructions.

2. Reboot the router by executing reboot on the console.

3. Check if you got a new interface:

root@OpenWrt:~# ifconfig -a
usb0: ...

If there is no such device found, there is a possibility that completely different name is in use by the device driver, like eth1. Try to get more details:

  • Open System Log from Luci web interface and see what it shows regarding newly discovered USB device(s)
  • execute dmesg on the console and see if any relevant information about new USB NCM is present in the kernel log
  • check the details about USB devices detected by the system by running cat /sys/kernel/debug/usb/devices on the console:
[...]
T:  Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=480  MxCh= 0
D:  Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=12d1 ProdID=1506 Rev= 1.02
S:  Manufacturer=HUAWEI_MOBILE
S:  Product=HUAWEI_MOBILE
C:* #Ifs= 5 Cfg#= 1 Atr=80 MxPwr=  2mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=03 Prot=10 Driver=(none)
E:  Ad=82(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=03 Prot=12 Driver=option
E:  Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:  If#= 2 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=03 Prot=16 Driver=huawei_cdc_ncm
E:  Ad=85(I) Atr=03(Int.) MxPS=  16 Ivl=2ms
I:* If#= 2 Alt= 1 #EPs= 3 Cls=ff(vend.) Sub=03 Prot=16 Driver=huawei_cdc_ncm
E:  Ad=85(I) Atr=03(Int.) MxPS=  16 Ivl=2ms
E:  Ad=84(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 3 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E:  Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=125us
I:* If#= 4 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E:  Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=125us

See Troubleshooting Section of this page for more information.

UCI is supporting NCM network protocol configuration.

Name Type Required Default Description
device file path yes (none) NCM device node, usually /dev/ttyUSBx or /dev/ttyACMx; acts as a control interface
apn string yes (none) APN to use
pincode number no (none) PIN code to unlock SIM card
username string no (none) Username for PAP/CHAP authentication
password string no (none) Password for PAP/CHAP authentication
auth string no (none) Authentication type: pap, chap, both, none
mode string no (modem default) Used network mode, not every device support every mode: preferlte, preferumts, lte, umts, gsm, auto
pdptype string no IP PDP Context Type, IP (for IPv4), IPV6 (for IPv6) or IPV4V6 (for dual-stack)
profile number no 1 PDP Context Identifier
ifname string no (none) Data interface name
delay number no 0 Seconds to wait before trying to interact with the modem (some modems require up to 30 s.)

You can configure the interface manually using uci command line or text editor or with Luci package luci-proto-ncm.

:!: If option “mode” is set, the corresponding AT command is sent to the modem on every connection attempt. Most of modems (at least all Huawei models) store this setting in internal flash. So on each connection OpenWrt writes to modem flash. It is recommended to not use this option after the required mode is set once.

Using Luci web interface: navigate to Network → Interfaces → Add new interface… → Protocol : NCM, Interface: “ttyUSB1”

The interface selected above is the “AT Command Port” or “PCUI” in Huawei terms, ttyUSB1 is shown here as an example only, different modems have different port assignments like /dev/ttyUSBx or /dev/ttyACMx. The data interface (like usb0) and corresponding device will be discovered by the connection script automatically.

Enter your APN and select the 'IP Protocol' as instructed by the carrier.

Assign the firewall zone (wan) on 'Firewall Settings' tab.

Alternatively you can edit the configuration files with any text editor like vi or nano:

  • add a new Interface in /etc/config/network:
config interface 'wwan'
        option proto 'ncm'
        option device '/dev/ttyUSB1'
        option pdptype 'IP'
        option apn 'internet'
  • add the same interface name to the “wan” firewall zone in /etc/config/firewall:
config zone
    option name 'wan'
    [...]
    list network 'wwan'

Some providers of mobile Internet use Web redirection to their service pages for access activation, modem configuration, etc. If a private (rfc1918) IP address is used in redirection (example: YOTA in Russia), name resolution will be blocked by dnsmasq by default:

Jan 18 14:36:49 OpenWrt daemon.warn dnsmasq[1325]: possible DNS-rebind attack detected: my.yota.ru

To overcome this issue add the required domain to a whitelist: navigate in LuCI to “Network” → “DHCP and DNS” → “Filter” tab and type “yota.ru” without quotes in the “Domain whitelist” field then click on “+” next to it. Save & apply.

Get the information about USB devices with cat /sys/kernel/debug/usb/devices

Find a section for your device, look for “Manufacturer” and/or “Product” lines corresponding to your modem, for example:

S:  Manufacturer=HUAWEI_MOBILE
S:  Product=HUAWEI_MOBILE

See if necessary drivers are loaded for your device:

I:* If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=03 Prot=12 Driver=option
[...]
I:  If#= 2 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=03 Prot=16 Driver=huawei_cdc_ncm

If the drivers are missing, install the missing packages and/or change the operating mode of the modem to expose the necessary interfaces.

Finally, ask in the forum.

This script GitHub oilervoss will check the connection pinging a public IP and, under failure, it will send AT commands to the serial interface of the modem restarting it.

To achieve continuous monitoring of the connection, it must be called recurrently through a cron job as:

#/etc/crontabs/root
#min    h   day  mon  week  command
*/20    *    *    *    *    /etc/init.d/ncm-fix start

This is probably related to ticket #18673 (https://dev.openwrt.org/ticket/18673). You should be able to use the modem by starting ndis dialup manually by sending the following to /dev/ttyUSB1

AT^NDISDUP=1,1,"your_apn_address"

It is possible to automate this task using hotplug. Below are some scripts fetched from http://forum.ixbt.com/post.cgi?id=print:14:59307&page=4. Do not forget to modify them to your needs. The scripts are for Huawei modems obviously.

/etc/init.d/ncm-network:

#!/bin/sh /etc/rc.common

#
DEVICE='/dev/ttyUSB1'
# Interface name from /etc/config/network
IFNAME='WWAN'
# Your APN:
APN='your_apn_here'

START=70
STOP=90

start() {
        if [ -e ${DEVICE} ]; then
                echo -ne "AT^NDISDUP=1,0\r\n" > ${DEVICE}
                sleep 3
                echo -ne "AT^NDISDUP=1,1,\"${APN}\"\r\n" > ${DEVICE}
                sleep 3
                ifup $IFNAME
        else
                echo "No such device ${DEVICE}" | logger -t "ncm-network[$$]" -p info
        fi
}

stop() {
        if [ -e ${DEVICE} ]; then
                ifdown $IFNAME
                sleep 3
                echo -ne "AT^NDISDUP=1,0\r\n" > ${DEVICE}
        else
                echo "No such device ${DEVICE}" | logger -t "ncm-network[$$]" -p info
        fi
}

/etc/hotplug.d/usb/70-ncm-network

#!/bin/sh

# Uncomment set line below and check your modalias I from tmp file
MODEM_ID='usb:v12D1p1506d0102dc00dsc00dp00ic08isc06ip50in05'
PAUSE=10
PAUSE_FOR_HOTPLUG=5

#set >> /tmp/ncm-network.debug

if [ "${MODALIAS}" != "${MODEM_ID}" ]; then
        exit 0
fi

case "$ACTION" in
        add)
                SYSTEM_UPTIME=$(cat /proc/uptime | awk -F"\." '{ print $1 }')
                if [ "${SYSTEM_UPTIME}" -gt 60 ]; then
                        PAUSE=$PAUSE_FOR_HOTPLUG
                fi
                {
                sleep ${PAUSE} && \
                echo "Start modem ${MODEM_ID}" | logger -t "hotplug[$$]" -p info && \
                /etc/init.d/ncm-network start
                } &
                ;;
        remove)
                echo "Stop modem ${MODEM_ID}" | logger -t "hotplug[$$]" -p info
                /etc/init.d/ncm-network stop
                ;;
esac

Some modems does not reconnect after losing connection. Here is a connection check sh script which checks if it can ping remote servers with time intervals. If all pings fail, it tries to start the network by executing /etc/init.d/ncm-network start

#!/bin/sh

# Enter the FQDNs you want to check with ping (space separated)
# Script does nothing if any tries to any FQDN succeeds
FQDN="www.google.com"
FQDN="$FQDN www.amd.com"
FQDN="$FQDN www.juniper.net"

# Sleep between ping checks of a FQDN (seconds between pings)
SLEEP=3                         # Sleep time between each retry
RETRY=3                         # Retry each FQDN $RETRY times
SLEEP_MAIN=60                   # Main loop sleep time

check_connection()
{
  for NAME in $FQDN; do
    for i in $(seq 1 $RETRY); do
      ping -c 1 $NAME > /dev/null 2>&1
      if [ $? -eq 0 ]; then
        return 0
      fi
      sleep $SLEEP
    done
  done
  # If we are here, it means all failed
  return 1
}

while true; do
  check_connection
  if [ $? -ne 0 ]; then
    /etc/init.d/ncm-network start
  fi
  sleep $SLEEP_MAIN
done

If your SIM receives a voice call. It will downgrade to CS network which means you will downgrade into 3G mode. To avoid this, set the stick to use only PS network by creating `/etc/hotplug.d/iface/99-ifupwwan` file with following code. Make sure to modify it to use correct serial interface and correct AT command for your device.

[ "$ACTION" = "ifup" -a "$INTERFACE" = "wwan" ] && {
    logger "iface wwan up detected..."
    # We need to set this to stop the card from receiving phone calls
    # This is for EC-25
    #echo -ne "\r\nAT+QCFG=\"servicedomain\",1,1\r\n" > /dev/ttyUSB2
    # This is for Huawei
    echo -ne "\r\nAT^SYSCFGEX=\"00\",3FFFFFFF,1,1,7FFFFFFFFFFFFFFF,,\r\n" > /dev/ttyUSB2
}
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2026/04/19 17:55
  • by lukepicci