User Tools

Site Tools


doc:recipes:ethernetoverusb_ncm

Use NCM USB Dongle for WAN connection

NCM (Network Control Model) is ethernet over USB protocol used by some fast speed USB modems/dongles.

For more information about different protocols used:

Modem Preparation

You need to switch modem to provide native NCM interface instead of Modem interface.

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

Router Preparation

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.

Required Packages

To make use of NCM protocol, package kmod-usb-net-huawei-cdc-ncm and comgt-ncm are needed.

  • usb-modeswitch - It will automatically issue a "special" command to the modem for switching it into the "Working" state

opkg update
opkg install comgt-ncm kmod-usb-net-huawei-cdc-ncm usb-modeswitch

Optional Packages

1. Add support for PC Interface (ttyUSB0)

  • kmod-usb-serial
  • kmod-usb-serial-option
  • kmod-usb-serial-wwan

opkg update
opkg install kmod-usb-serial kmod-usb-serial-option kmod-usb-serial-wwan

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

Installation

1. Install all the needed packages

opkg update
opkg install comgt-ncm kmod-usb-net-huawei-cdc-ncm usb-modeswitch

:!: If your have not enough space on your device - think of installing Rootfs on External Storage (extroot)

:!: Another option is Hardware memory upgrade. Refer to your router Forum thread for possibility and instructions.

2. Reboot the router

reboot

3. Check that everything is OK and you got new device:

ls -l /dev/cdc-wdm0

crw-r--r--    1 root     root      180, 176 Oct  1 12:03 /dev/cdc-wdm0

If you have no such device - try to find out what went wrong:

try dmesg to read kernel logs on USB init

dmesg
or look info about USB devices and interfaces present in the system:
cat /sys/kernel/debug/usb/devices

FIXME

See Troubleshooting Section of this page for more information.

Configuration

Protocol Configuration

UCI is supporting NCM network protocol configuration. The detailed explanation about NCM network configuration is explained here.

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

Network configuration

Now you should add new Interface to /etc/config/network

config interface 'wwan'
        option proto 'ncm'
        option ifname 'wwan0'
        option device '/dev/cdc-wdm0'
        option apn 'internet'
        option mode 'preferlte'
        option pincode '0000'
        option delay '5'

You can do this using the vi text editor, but if you're not comfortable with that, point your browser to 192.168.1.1 again, choose Network → Interfaces and click Add new interface.

Write wwan as the name of the interface and make it cover the wwan0 interface. Choose ncm as the protocol.

FIXME Insert a screenshot of LUCI add Interface.

Firewall configuration

The only thing that is left - Add wwan interface to WAN zone

Using LUCI:

  • go to Network → Firewall, scroll down to wan and click the Edit button
  • add a checkmark to the wwan box under Covered networks heading, click Save & Apply

FIXME Insert a Screen Shot from LUCI.

Additional Info

Some providers of the cellular internet use redirection to their pages for access activation, when you are connected first time. I.e. YOTA in Russia.

Normally this would be blocked by dnsmasq:

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

You have 2 options:

  • Allow rebind responses RFC1918 (In LUCI goto NetworkDHCP and DNS and uncheck Rebind protection checkmark)
  • Add Yota.ru domain to Whitelist (In LUCI goto NetworkDHCP and DNS and type in "yota.ru" without quotes to the Domain whitelist field.

Save & apply

Troubleshooting

My router is not detecting the dongle. What should I do?

Try the following commands:

usbmode -l
It should respond with a message about your USB device is detected. If it does, issue the next command. If it doesn't, you might want to get help from the forum.
usbmode -s
Then wait for the dongle to get issued an IP from your ISP.

I have to issue usbmode -l and usbmode -s every time I reboot my router to detect my USB device. How can I automate it?

Include the following codes into /etc/rc.local just before exit 0:

/sbin/usbmode -l
/bin/sleep 2
/sbin/usbmode -s

I am using 'huawei_cdc_ncm' module and the /dev/cdc-wdm0 does not respond. What do I do?

This is probably related to ticket #18673 (https://dev.openwrt.org/ticket/18673). You should be able to use the modem by starting ndis 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 loosing 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

doc/recipes/ethernetoverusb_ncm.txt · Last modified: 2017/04/16 23:51 by tmomas