No ads - but links to sites I deem valuable and important:
stop-overpopulation.org - Life could be so good if there'd be fewer of us ...
metabunk.org - Remove the bunk from scary claims

This site is powered by green energy; for details see the provider's page

 

USB_ModeSwitch - Handling Mode-Switching USB Devices on Linux

 
If you don't like the text column width, adjust your browser window

Introduction

USB_ModeSwitch is (surprise!) a mode switching tool for controlling 'multi-mode' USB devices.

More and more USB devices (especially high-speed WAN stuff, based on cell phone chipsets which are able to change their USB connection mode) have their MS Windows drivers onboard; when plugged in for the first time they act like a flash storage and start installing the driver from there. After installation (and on every consecutive plugging) the driver switches the mode internally, the storage device vanishes (in most cases), and a new device (like an USB modem) shows up. Modem maker "Option" calls that feature "ZeroCD (TM)" since it eliminates the need for shipping a separate driver carrier.

In the beginning, nothing of this was documented in any form and there was hardly any Linux support available.
On the good side, most of the known devices do work in both modes with the available Linux drivers like "usb-storage" or "option" (an optimized serial driver, the Linux standard for high-speed 3G modems).
That leaves only the problem of the mode switching from storage to modem or whatever the thing is supposed to do.

Fortunately there are things like human reason, USB sniffing programs and "libusb". It is possible to eavesdrop the communication of the MS Windows driver, to isolate the command or action that triggers the mode switching and to reproduce the same thing under the rule of Linux or the BSD variants.

USB_ModeSwitch makes this process easy to handle by taking the important parameters from a configuration file and doing all the initialization and communication stuff, with heavy help from "libusb".
It is mainly used automatically - via udev events and rules - to do the switch without any user interaction. But it can also be run as a command line tool, usually when trying to make unknown devices work with it.

This tool is part of most major distributions; you should not be having to install from the source packages here unless you run into problems and need the latest version.

 

Please read the information on this page carefully before you go around posting questions! If you encounter a new device, it really helps to understand the principle of what is happening, which in turn makes it easier to find out about the switching command and to add a new config entry.

For hints about doing your own sniffing see paragraph Contribute below.

Download

Important: For a working installation you need both program and data package !

Changes and updates to the configuration data may happen more often than new program releases; most of the knowledge about devices is contained in these files. That's why it is provided separately.

If you have an Android Tablet with USB host port and at least Android version 2.2, you can try the "PPP Widget", available only on Google Play. It includes USB_ModeSwitch and PPPD, making it relatively easy to go online with your modem stick or your phone, even on WiFi-only devices.

If you are a system integrator (package maintainer) you can use this XML file to check for new releases:
usb-modeswitch-versions.xml.

The maintainer of the USB_ModeSwitch Debian package has set up a PPA providing the most recent release; see his posting in the forum for the link.

How to install

If you have an earlier version installed, de-installation is recommended ("make uninstall"). Several file locations changed in 1.1.0, old ones might be orphaned if not taken care of. If you have a version after 1.1.0 you can just update and overwrite all existing files.

Unpack the source file of the program (who might have thought!). In the newly created directory run as root or superuser:

# make install
This installs a small shell script for udev, the larger wrapper script, a config file, the man page and the freshly compiled binary.
Important: if you install this way, you will need the "tcl" package for the large dispatcher script. There are more ways to install which do not depend on that package. Refer to the included README for further install options !

Now do the same procedure for the data package. It will install the config files in "/usr/share/usb_modeswitch" and the udev rule file in "/lib/udev/rules.d". The earlier "/etc/usb_modeswitch.d" is now reserved for custom config files (new or changed).
You are set already; if your device is known, you should be able to just plug it and use it. If it doesn't work right away we'll find out why.

For manual use just install the program. Work with the command line interface or use a custom config file. The "device_reference" file (see "Download") is a good starting point to create your own configuration. It is heavily commented and should tell you what to do.
Your custom config file can have any name and place; just tell usb_modeswitch how to find it with the -c parameter.

Manual use is intended for testing and analyzing. See next paragraph.

How to use

In most cases, you will be able to use your device without any interaction except plugging it in.

If you think your device is supported, but things are not working out as they should, turn on logging first as described in Troubleshooting.

For testing, debugging and taming new devices from the wild, you can use the binary part of USB_ModeSwitch in manual mode.
There are two ways for that: using a config file or using the command line.

Run "usb-modeswitch -h" to list the command line parameters. If any of them except -W, -D, -I and -q are used, a config file given with -c is ignored and all mandatory parameters have to be provided on the command line. See also the included man page.

To work with a config file, use one of the little files in "/usr/share/usb_modeswitch" or create one yourself. Then give the path and file name to usb_modeswitch with the -c option. You also can have a look into the device_reference.txt for hints about model families and an explanation of the parameters.

Important: USB_ModeSwitch - like all programs using libusb - has to be run as root (or with "sudo") when calling it manually. Otherwise strange error messages turn up and things won't work. When trying out switching commands and strategies, it's probably easier to work at a root shell for a while ("sudo bash" or "su -").

The automatic approach consists of several components working together, listed in the logical order of usage:

After switching and driver-loading, it is the responsibility of the system to discover the new (mostly serial) device.

Current releases of NetworkManager (or its ModemManager component) are usually quite good at making use of wireless modems. Even newer models that don't use PPP interfaces anymore are recognized and integrated seamlessly.
There may be issues with older versions of these programs which may run into touble when trying to auto-detect USB modems and how to use them.
If you are stuck with an older system, try disabling NM and MM. Good results were reported by working with wvdial, UMTSmon and several tools providing a user interface to PPP like kppp; some of these programs may require a bit of basic knowledge though.

Starting from version 1.1.2, usb_modeswitch will add a symbolic link to the correct port with interrupt transfer if the device provides standard serial ports. The link will have the name /dev/gsmmodem, with a number appended if more than one device is attached.
You can use this name with connection helpers like wvdial. Note that in many cases you may have to edit the configuration file manually.

If you managed to get a new or badly supported device to switch correctly in manual mode, you can add a udev rule and a config file yourself. But please report it back to share it !!

See Contribute.

Known working hardware

Very important note:
Personally, I could not test the vast majority of supported devices; the list here - as well as the necessary data - relies on reports from third parties (people, that is). So it may happen that you hit sudden obstacles even with your device listed here.
That said, the user base of this little tool has grown considerably, so that any data related problems are generally surfacing quite soon.

There are hitherto three known methods for initiating the switching process:

  1. sending a rarely used or seemingly weird standard storage command (equivalent to those of SCSI) to the storage device ("eject" for example)
  2. sending one or more vendor-specific control messages to the device
  3. actively removing (detaching) the storage driver from the device (only some early devices)

Again, if you don't find the name of your device in the list, it may still be supported.
The important thing is that you find your device's USB ID in the config file folder. Have a look into the latest data package (See Download).

Here is the list of devices, together with the respective contributors:
device_reference.txt.

Troubleshooting

Note: if you still need support after having followed the advice on this page, please use the forum!
E-mail may be used for device/config contributions only - no support questions!

Known issues:

For debugging of the automated system integration, edit (as root or su) /etc/usb_modeswitch.conf in a text editor and change the line

 EnableLogging=0
to
 EnableLogging=1
This gives you a verbose output of the hotplug activity to /var/log/usb_modeswitch_<device>.

If you're next to certain that you have the right values for your device, followed all the hints (see Known working hardware), and USB_ModeSwitch seems to do something run after run but to no effect, there are most likely system issues involved.

The first suspects are existing system rules for modems which handle things not quite correctly.
If you own a device with the unswitched ID of 05c6:1000, it may get a wrong switching command in older systems. There are four different types of switching devices, all with that same ID; in the big distributions they were all treated alike as a model from "Option" (the manufacturer) which is wrong in four out of five cases. There are even cell phones with that ID which wrongly get the same treatment when connected to an USB port.

To fix problems like that you can try to remove rules files from "/lib/udev/rules.d" which contain calls to "modem-modeswitch".
USB_ModeSwitch will do additional checks beside the USB ID and treat all known ambiguous devices in the right way. For example, it will leave unknown devices with the 05c6:1000 ID alone.

Annother notorious candidate is again 19d2:2000. It may be switched O.K. by an existing rule, but there is no driver loading if your model is new and its ID is not yet added to the "option" module.
Disable the rule running "eject" and the ID will be handled by usb_modeswitch.

Kernel related issues

In some newer kernels, certain devices (some Option, some Huawei, some ZTE as mentioned above) get a special treatment in the usb-storage code to enable switching right away. You would not need USB_ModeSwitch anymore for these specific devices; on the other hand you have no choice of accessing the "CD-ROM" part of your device. Plus, there were cases when the special treatment brought no results and furthermore prevented USB_ModeSwitch to work properly afterwards (happened with ZTE devices, error "-2").

In case of trouble, look into "unusual_devs.h" in the "drivers/usb/storage" folder of your kernel source. If your default ID (vendor and product ID of the storage part) can be found there and you get errors when running USB_ModeSwitch, try first to blacklist "usb-storage".
If that helps, you should consider rebuilding your kernel with the entry in "unusual_devs.h" deactivated. The only thing that will happen is that usb-storage works in the default way afterwards.
I found a tip in the Russian Gentoo wiki to do exactly what I just suggested for the ZTE MF626.
By the way, at one point there was an agreement among USB developers to keep all future mode switching code out of the kernel drivers if the neccessary steps can be taken in "user space".

Annother way of influencing the kernel behaviour is the parameter "delay_use" of "usb-storage" which sets the time in seconds after plugging when the storage device will actually be used (and probably automounted). The default value is 5; this might affect the switching result under certain conditions.
To change the default add in /etc/modprobe.conf:

 options usb-storage delay_use=1 (or 10, or other)

Old systems (e.g. CentOS 5 or Xandros 6)

If you are running a not-quite-fresh system (with a kernel below 2.6.27), you may run into incompatibilities between versions of "udev", the device manager. If you get no indication of the usb_modeswitch components doing anything at all (no log files), follow these steps:

Contribute

USB_ModeSwitch comes quite handy for experimenting with your own hardware if not supported yet.
The first step would be to try widely used switching methods from known devices, like the "eject" sequence found in the BandLuxe configuration "1a8d:1000". If you have a hint that your device may be made by Huawei originally, try the sequence from "12d1:1446".
Don't worry, it's almost impossible to break anything by experimenting with possibly wrong sequences. Just make sure you re-plug your device after each attempt!

If all this has no effect you can try this approach:
Note the device's Vendor and Product ID from /proc/bus/usb/devices (or from the output of "lsusb"); the assigned driver is usually "usb-storage". Then spy out the USB communication to the device with the same ID inside M$ Windoze, with the on-board driver installed. The device must be switched there too, and you want to log that moment.
I recommend this tool: "SniffUSB" ( http://www.pcausa.com/Utilities/UsbSnoop/default.htm).

This is the short version. There is a very good case example from Mark A. Ziesemer here:
Alltel UM175AL USB EVDO under Ubuntu Hardy Heron

Please post any improvements, new device information and/or bug reports to the ModeSwitchForum !
If you don't need support you can also send me an old-fashioned - and at your demand confidential - e-mail (see below).

Whodunit

Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Please use only the forum for support questions! For other messages like tested new device configurations or personal/confidential stuff you can mail me directly.

Other contributors

Command line parsing, decent usage/config output and handling, bugfixes added by: TargetClass parameter implementation to support new Option devices/firmware: Created with initial help from: Config file parsing stuff borrowed from: Hexstr2bin function borrowed from: A special "Thank You" goes to who tirelessly traces and collects new device configurations from around the electronic universe, then lists them for me to make updates and corrections so much easier !!

Code, ideas and other input from:

More contributors (device specific) are listed in the device_reference.txt. Thanks to everyone at the forum too! Sometimes it takes a considerable reservoir of patience on the road to success ...

History

See the ChangeLog of the program package or the ChangeLog of the data package which includes the names of supported device models.

Legal

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details:
http://www.gnu.org/licenses/gpl.txt

Page last revised: 2014-11-03