Vous êtes ici

Linux and 4G USB sticks

tuxIn latest versions of Linux, 4G USB sticks are well supported. But it may happen that either you don't run a recent version, or the stick is still uknown to Linux. In those cases, what to do?

One beauty of Linux is that it is open. Consequently, you know that you'll always be able to find information about its inner workings. This can be sometimes time consuming, but at least you have the opportunity to do it. Recently, I happened to use several different 3G and 4G USB sticks. One of them was not supported yet by Linux version I was using. So, I had to look at under the hood. This article summarizes what I discovered. It is written for Linux Mint 15, based on Ubuntu 13.04. This is the most recent version of Linux Mint, but information below should apply to most (not too old) distributions based on Debian...

Key detection

So, what happens when you insert a 4G USB stick into a USB connector? This action is detected by udev, a generic device manager which runs as a daemon. Udev performs actions depending on device attributes and on a predefined set of rules. You can find those rules in folders /etc/udev/rules.d/ and /lib/udev/rules.d/.

So, which rule is called? Here enters another piece of software, named USB_ModeSwitch. USB_ModeSwitch provides udev with a specific rule, 40-usb_modeswitch.rules (in /lib/udev/rules.d/).

CD or modem?

What's the aim of USB_ModeSwitch? For some years now, wireless "modem" USB sticks have been delivered without any accompanying CD (lower cost, smaller box!). Software driver that Windows requires are on the stick itself. First time the stick is connected to a PC, it is seen by Windows as an external USB drive. The "modem" driver is automatically installed from this drive. Once installed, the driver "switches" the stick into its modem configuration. Next time the stick is connected to Windows, the driver will again switch it into its modem configuration.

For Linux, USB_ModeSwitch performs the right switch operation for a given stick. Why "right"? Because, of course, almost every stick has a different way to be switched... To send the right command to the stick, USB_ModeSwitch uses a set of predefined configuration files. Those files are stored inside /usr/share/usb_modeswitch/configPack.tar.gz. Each file is named according to vendor id and product id declared in the stick.

Once the key is switched into its modem configuration, one or more ttyUSB devices are created. Starting from there, the stick is seen as a normal (serial) modem, that can be controlled through device /dev/ttyUSB0 (or another number).

Network Manager

Network Manager is a service which is started automatically at system boot. Additionally, when you are the first user to log in, related applet should be displayed somewhere on your desktop environment.

As soon as the USB stick is seen as an usual modem, Network Manager is informed about it. If you decide to activate wireless network connectivity (or if Network Manager decides it), ModemManager handles the connectivity request.

To perform the connection, it first sends required AT commands to the stick, using device ttyUSB0. Then, a PPP session is activated.

If it does not work...

This was the theory. Now, what to do if, when you insert the brand new 4G USB stick you just received, nothing happens?

One good method is to switch various applications to debug mode:

  • for udev:
    • stop the service: sudo service udev stop
    • run udevd in the foreground and in debug mode: sudo udevd --debug
  • for USB_ModeSwitch, open file /etc/usb_modeswitch.conf, and set EnableLogging to 1. Starting from now, USB_ModeSwitch will log trace messages to /var/log/usb_modeswitch.log.
  • for Network Manager and ModemManager:
    • from a terminal, stop Network Manager with command: sudo service network-manager stop. This should stop ModemManager process as well.
    • restart ModemManager in debug mode: 
      sudo su
      modem-manager --debug
    • from another terminal, restart Network Manager in debug mode as well:
      sudo su
      export NM_PPP_DEBUG=1

      export NM_SERIAL_DEBUG=1
      NetworkManager --no-daemon
    • starting from now, you will get trace messages displayed, including all AT commands sent to the modem device.

Once everything is configured, insert the USB stick. You'll get plenty of traces, that will show where the problem is: udev rule not executed, no configuration file for USB_ModeSwitch, etc.

If you want to send a specific configuration file to a USB stick, you can use the following command:

sudo usb_modeswitch -W -c <configurationFile>

To disable debugging, simply perform above steps in reverse order (using sudo service xxxx start to start stopped services).