User Tools

Site Tools


docs:guide-user:network:wan:wwan:usb-modeswitching

USB mode switch

It's common for 3G/LTE dongles (and some smartphones) to show up as a virtual CD drive offering drivers and utilities to use them on Windows/Mac, then after you have dismissed this somehow then it will switch to the “useful” mode.
USB dongles also may or may not need to be switched to high-speed USB modem protocols to use their full potential.

The usb-modeswitch package includes usbmode tool with json-based configuration instead of classic usb_modeswitch binary, and a Procd service running to switch automatically all modems as soon as they are plugged in. The /etc/usb-mode.json configuration file looks partially like below.

{
	"messages" : [
		"555342431234567800000000000006d0000000000000000000000000000000",
		"5553424312345678000000000000061b004600000000000000000000000000",
],
"devices" : {
		"03f0:002a": {
			"*": {
				"t_class": 7,
				"msg": [ 0 ],
				"response": true
			}
		},
		"0408:f000": {
			"*": {
				"t_vendor": 1032,
				"t_product": [ 53257 ],
				"msg": [ 1 ]
			}
		},
	}
}

03f0:002a is default vendor and product in hexadecimal neotation, as it appears on executition of lsusb or kernel usb debug, while msg is the message content array. These messages issue the commands, that will either allow for media eject and/or eject the virtual CD-ROM, … in order to switch the device into 3G modem mode. t_vendor is target vendor in decimal notation, t_product is target product in decimal notation. Depending to the recognized vendor and product id, you may send one of the messages to the dongle by just using the message array index If you want to know more, look at the file /etc/usb-mode.json.

The above usbmode-json example will send this message code

"555342431234567800000000000006d0000000000000000000000000000000"

to the usb device with the vendor id 03f0 and product id 002a. After modeswitching, the usb device will stay with the same vendor id and product id, but with target device class number of 7.

In addition, it will send message code

"5553424312345678000000000000061b004600000000000000000000000000"

to the usb device with the vendor id and the product id of 0408:f000. After modeswitching, the usb device will switch to decimal vendor id and product id of 1032:53257, which you can convert to hexadecimal notation of 0408:D009 (You need decimal to hexadecimal converter such as your computer's calculator in 'programmer's mode'.). The device vendor id and product id after modeswitch as show on lsusb and /sys/kernel/debug/usb/devices is 0408:D009.

Note: the json file is generated automaticallly from ordinary usb_modeswitch data files during build process using perl script named convert-modeswitch.pl. For diagnostics purpose, you can create usb-mode-custom.json with defined message and devices part and launch the command

usbmode -l
usbmode -s -v -c /path/to/usb-mode-custom.json

Converting the standard usb-modeswitch file to json format can be done in a simple way. The standard usb-modeswitch file (0408:f000) content.

# Yota Router (Quanta 1QDLZZZ0ST2)
TargetVendor=0x0408
TargetProduct=0xd009
MessageContent="5553424312345678000000000000061b004600000000000000000000000000"

Target vendor (0x0408) is converted to decimal notation to fill t_vendor value (1032) and target product (0xd009) is converted to decimal notation to fill t_product (53257). There is only one message content, so the message index is zero (0). The resulting usb-mode-custom.json content is as follows.

{
	"messages" : [
		"5553424312345678000000000000061b004600000000000000000000000000",
],
"devices" : {
		"0408:f000": {
			"*": {
				"t_vendor": 1032,
				"t_product": [ 53257 ],
				"msg": [ 0 ]
			}
		},
	}
}

Based on this example, you can make another usb-mode-custom.json file to perform modeswitching on unsupported dongles for diagnostic purpose.

Also see this thread about 3g/4g USB dongle not showing up where you can see another example of troubleshooting and creating a new setup for usb-modeswitch.

sdparm method

This tool is no longer available in OpenWrt

This method uses sdparm to issue SCSI eject command to the emulated CDROM device. This is enough to put some modems into modem mode (tested on Ovation MC935D). Before you start, make note of your modem's vendor and product ID: <code> # cat /proc/bus/usb/devices … P: Vendor=1410 ProdID=5020 Rev= 0.00 S: Manufacturer=Novatel Wireless, Inc. … </code> First, find out your device address - in this example it's going to be sg0. Then issue the following: <code> sdparm –eject /dev/sg0 </code> For Attitude Adjustment try: <code> sdparm –command=eject /dev/sg0 </code> Then, check for changes of your product ID: <code> # cat /proc/bus/usb/devices … P: Vendor=1410 ProdID=7001 Rev= 0.00 S: Manufacturer=Novatel Wireless, Inc. S: Product=Qualcomm Configuration … I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none) … </code>

docs/guide-user/network/wan/wwan/usb-modeswitching.txt · Last modified: 2019/03/28 20:53 by tmomas