Pages

Thursday, August 16, 2018

D-Link DIR-505 with OpenWRT, Huawei 8221 & Huawei e3276

I have been fascinated with OpenWRT and have been using it since 15.05. Have never tried building my owner firmware and wanted to get my hands dirty on this. Recently I attempted to build a firmware for D-Link DIR-505 router which have been taking rest for past 2 years. I love this cute little box as it has all it needs to be a full fledged Router, NAS device, Hotspot and much more..
D-Link DIR-505

Have made significant progress on this project now. Below write up is result of hours spent on reading the instruction about configuring 3G/4G dongles with OpenWRT from the web and result of trial and error process as well. Thanks to all the original authors of these instructions posted on the web.

Had a spare Hawaii 8221 lying around. This is more than a dongle and they call it a Wiggle. It has Wi-Fi integrated as well and all you need to make it work is just a USB power port.

Making it work with a Router as a WAN interface is a different story all together. Through the course I learnt that 3G and 4G dongles emulate LAN interfaces on USB for higher through puts. PPP has its own limitation on max bandwidth it can support. Huawei 8221 implements RNDIS protocol for this purpose. This is supported in OpenWRT through "kmod-usb-net-cdc-ether" driver.

Below are the steps to get this Wiggle working with OpenWRT 17.01-SNAPSHOT. 


  1. Connect the Wiggle to a PC and configure the APN using the HiLink interface. This is a WebUI and will open automatically once the device is detected on windows. Test if you are able to successfully connect to the internet. 
  2. Install below modules using opkg command in case you are using release version from OpenWRT portal. You can download these modules individually from OpenWRT portal in case you can't get your router connected to internet. 
    1. kmod-usb-core
    2. kmod-usb2
    3. kmod-mii
    4. kmod-nls-base
    5. kmod-usb-net
    6. kmod-usb-net-cdc-ether
    7. libblobmsg-json
    8. librt
    9. libubox
    10. libusb-1.0
    11. libc
    12. wwan
  3. Connect the Wiggle to the usb port of the router. 
  4. Now the Wiggle should be detected as a cdc_ether device and LAN interface will be assigned. In my setup it was eth2.
  5. Through LuCI configure this interface as WAN interface and use dhcp as protocol. 
  6. Add the newly created interface into WAN firewall group. 
  7. You have successfully configured Huawei 8221 as the WAN link for the router. 

Huawei 8221 is a 3G Wiggle and I wanted to upgrade it to 4G to better utilize the bandwidth provided by the operator. My search for a 4G dongle ended with Huawei e3276-920 .. 


Huawei 8221


Ordered and received Huawei e3276-920 dongle. This device has specifications which suit providers in India. After receipt of the dongle realized that e3276-601 supports LTE Band 3 & 40 while e3276-920 only supports LTE Band 40. But this won't be a show stopper at this point though. 


Huawei e3276-920

source:
 4G Band 38/40 (TDD 2300/2600MHz)
* 3G DC-HSPA+ 900/2100MHz
* GSM 850/900/1800/1900MHz

Have also verified the same in the device through AT commands. 

AT^SYSCFGEX?

^SYSCFGEX: ("00","01","02","03"),((2000000400380,"GSM900/GSM1800/WCDMA900/WCDMA2100"),(280000,"GSM850/GSM1900"),(3fffffff,"All bands")),(0-2),(0-4),((a000000000,"LTE_B38/LTE_B40"),(7fffffffffffffff,"All bands"))

Will discuss more about the options a bit later.

This device works on NCM protocol and requires below modules in addition to above. 

  • kmod-usb-net-cdc-ncm
  • kmod-usb-net-huawei-cdc-ncm
  • usb-modeswitch 
Have also installed kmod-usb-serial-options module to have access to the Modem and PCUI ports of the dongle.

After installing the modules the device will get detected and below messages can be found in dmesg.

[   13.890047] usbcore: registered new interface driver cdc_ncm
[   13.946463] huawei_cdc_ncm 1-1:1.2: MAC-Address: 0c:5b:8f:27:9a:64
[   13.951207] huawei_cdc_ncm 1-1:1.2: setting rx_max = 16384
[   13.957079] huawei_cdc_ncm 1-1:1.2: setting tx_max = 16384
[   13.962448] huawei_cdc_ncm 1-1:1.2: NDP will be placed at end of frame for this device.
[   13.970508] huawei_cdc_ncm 1-1:1.2: cdc-wdm0: USB WDM device
[   13.977421] huawei_cdc_ncm 1-1:1.2 wwan0: register 'huawei_cdc_ncm' at usb-ehci-platform-1, Huawei CDC NCM device, 0c:5b:8f:27:9a:64
.
.
.
[   14.272584] usbcore: registered new interface driver option
[   14.276946] usbserial: USB Serial support registered for GSM modem (1-port)
[   14.284122] option 1-1:1.0: GSM modem (1-port) converter detected
[   14.290134] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[   14.296735] option 1-1:1.1: GSM modem (1-port) converter detected
[   14.303071] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1


Below is the content from /sys/kernel/debug/usb/devices file of OpenWRT post installing all the necessary drivers.

T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=480  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=12d1 ProdID=1506 Rev= 1.02
S:  Manufacturer=HUAWEI Technology
S:  Product=HUAWEI Mobile
C:* #Ifs= 5 Cfg#= 1 Atr=80 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=02 Prot=10 Driver=option
E:  Ad=81(I) Atr=03(Int.) MxPS=  64 Ivl=2ms
E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=4ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=02 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=4ms
I:  If#= 2 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=02 Prot=16 Driver=huawei_cdc_ncm
E:  Ad=84(I) Atr=03(Int.) MxPS=  64 Ivl=2ms
I:* If#= 2 Alt= 1 #EPs= 3 Cls=ff(vend.) Sub=02 Prot=16 Driver=huawei_cdc_ncm
E:  Ad=84(I) Atr=03(Int.) MxPS=  64 Ivl=2ms
E:  Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=4ms
I:* If#= 3 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=(none)
E:  Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 4 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=(none)
E:  Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms

LuCI on 17.01.5 doesn't support NCM protocol, interestingly its supported on 17.01 Master branch and also on 18.06. Tried compiling it from 17.01 Master source but wasn't successful and felt that's not a requirement as of now. Manual configuration is always handy here. 

Below is the configuration entries made in /etc/config/network file to get this module working. 

config interface 'wan_e3276'
        option ifname 'wwan0'
        option proto 'ncm'
        option device '/dev/cdc-wdm0'
        option apn 'airtelgprs.com'
        option delay '10'
        option auto '0'

Have set the auto option as '0', I am currently controlling the dongle connect and disconnect to internet through a shell script. 

Trouble-shooting: Speedtest upload failed with error - A socket error occurred during the Upload test.

Narrowed down the problem to the interference on the WiFi network. Moved the router and laptop to the same room and the issue got resolved.  Configured the dongle with LTE preferred mode as below. 


AT^SYSCFGEX?

^SYSCFGEX:"0302",2000000400380,1,2,A000000000

Just wanted to clean all the changes and hence opted for a fresh installation from release version of OpenWRT. This way I can download the ipk files from openwrt site directly rather than me compiling them each time.  Interestingly there was 17.01.6 release and went ahead in installing the same. By error I found that comgt & comgt-ncm are not actually required to have a ncm based dongle to work with OpenWRT as mentioned in may howto documentation on the web. Without these packages the only thing I missed was the AT commands logged into the logger. 

Will discuss about the scripts which I wrote for controlling the Internet connection and useful AT command set for Huawei e3276-920 in upcoming blogs.