Huawei E303 in fallback mode, OpenWRT: usb-mode.json explained

How I worked around usb-modeswitch issues with a Huawei E303s-2

If you need to use Huawei HiLink ™ devices on a router running OpenWRT, you most probably will want to use them as a dumb serial modem.


For the E303 this works as described here:
http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?f=4&t=1734

OpenWRT 15.05 has a different approach, since it’s mode switching database /etc/usb-mode.json contains the following:

“12d1:1f01”: {

“*”: {
“t_vendor”: 4817,
“t_product”: [ 5339, 5340 ],
“mode”: “HuaweiNew”,
“no_driver”: true,
“msg”: [  ]
}
},

4817 is the decimal representation of 12d1, the vendor id. 5339 is the product id 14db, 5340 is 14dc. This seems to represent the ethernet mode again – the one we don’t want to use because of NAT issues.

How does a modeswitch work?

You can easily test this on Linux (in my case Ubuntu 14.04 LTS):

Create the file /etc/usb_modeswitch.d/12d1:1f01 with the following content:

# Huawei Fallback Mode
DefaultVendor= 0x12d1
DefaultProduct=0x1f01
TargetVendor=0x12d1
TargetProductList=”14dc”
MessageContent=”55534243000000000000000000000011060000000000000000000000000000″
NeedResponse=1

CheckSuccess=20

Now plug your E303 to one of the USB ports.

run dmesg:

[46249.056189] usb 1-1.2: USB disconnect, device number 40
[46252.071841] usb 1-1.2: new high-speed USB device number 41 using ehci-pci
[46252.165380] usb 1-1.2: New USB device found, idVendor=12d1, idProduct=1001
[46252.165388] usb 1-1.2: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[46252.165392] usb 1-1.2: Product: HUAWEI HiLink
[46252.165395] usb 1-1.2: Manufacturer: HUAWEI
[46252.166130] option 1-1.2:1.0: GSM modem (1-port) converter detected
[46252.166704] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0
[46252.167042] option 1-1.2:1.1: GSM modem (1-port) converter detected
[46252.167221] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1
[46252.167381] option 1-1.2:1.2: GSM modem (1-port) converter detected
[46252.167521] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2

An output as above shows, that the modeswitch worked.

The above file with 12d1:1f01 will override the usb-modeswitch database and will send a certain configuration message to the modem.

Now how about usb-mode.json?
In usb-mode.json there is a set of available config messages at the top of the file.
They aren’t numbered, but they represent an array of such messages. A message is then represented by it’s decimal index – that is the position within that array.
In the example above, no message was sent to the modem. Only the target product id will change on the modeswitch. ‘udev’ may then recognize the modem and will load the corresponding drivers.
Message array in usb-mode.json:

{
“messages” : [                                                                                                                                           “555342431234567800000000000006d0000000000000000000000000000000”,                                                                  […]         “5553424398e2c4812400000080000bff524445564348473d43440000000000”                                                                     ],

If we want to use a dumb modem, we will have to adapt the lines above, to do what we did on our linux machine – so let’s edit the usb-mode.json db:

“12d1:1f01”:
{

“*”:            {
“t_vendor”: 4817,
“t_product”: [ 5340 ],
“msg”: [ 54 ]            }
},

The message we need, is to be inserted at line 58 of the original json db. Since these lines are on top of the file, their position won’t change. There is an offset of three lines before the the first message. So our message is at position(=index) 55, but the array starts with 0 i.e. we deduct 1; 55-1=54
If you just write a custom usb-mode.json it may look like this

{
“messages” : [
“55534243000000000000000000000011060000000000000000000000000000”
],
“devices” : {
“12d1:1f01”: {
“*”: {
“t_vendor”: 4817,
“t_product”: [ 4097, 5339, 5340, 7937 ],
“msg”: [ 0 ]
}
},
}
}

After saving the file, unplugging and replugging the E303 should be detected as a modem. The special devices /dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2 should now exist.
You will need to use /dev/ttyUSB2 to connect to your modem.

The mode switch isn’t a permanent thing. After unplugging, and replugging elsewhere the modem is in it’s default mode (usb ethernet mode) again.

A way to permanently switch the modem mode can be to supply an appropriate AT command on some models. Look for AT^U2DIAG at your own risk.

I ended up setting my E303 and another E220 to permanent serial mode with AT^U2DIAG=0.
I then removed /etc/usb-mode.json, but when I had to test a TP-LINK MA260, it couldn’t use it without the json. So I created a new /etc/usb-mode.json with the following content:

{
“messages”:[                                                                                                                                                                             “5553424312345678000000000000061b000000020000000000000000000000”
],    “devices” :

{
“2357:f000”:
{
“*”:        {
“t_vendor”: 9047,
“t_product”: [ 36864 ],
“msg”: [ 0 ],

}
},    }
}

You see, it follows always the same scheme.

And that’s the way it worked for me, too.

BTW: if you need to restore the file /etc/usb-mode.json on OpenWRT, that’s easy.
OpenWRT uses an overlay filesystem – so just delete the changes in the overlay an remount.

rm /overlay/upper/etc/usb-mode.json
mount -o remount /

Have fun!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s