Installing 3G USB Modems On Linux

Photo of Greg Harvey
Wed, 2010-04-28 11:27By greg

So, last night I lost not inconsiderable amounts of time and sleep to a Vodafone Italy 3G USB key. Trying to get these things set up is supposed to be fairly straightforward, however the end-to-end process is not really documented anywhere, as far as I can tell. Maybe for individual devices, but not in any generic way.

Since this is the second time I've done this now, and in both cases it was a pain in the ass, I am documenting some generic steps so I don't forget what I need to do all over again!

This is written for Fedora, but the steps are pretty similar for any Linux distro. The basics are as follows:

First, some background: Vodafone have a small team of Python developers dedicated to a suite of Linux tools for mobile devices (obviously specifically Vodafone, but their overall package is generic enough to be useful). This work is based on a Vodafone-backed community site for mobile development called Betavine.

They piggy-back on some other excellent work from the wider Linux community. Whether you have a Vodafone card or not, it is worth going through the first steps of this tutorial, because they install the basic requirements for pretty much *all* USB 3G modems:

However, the software on that page is not necessarily the latest, so rather than downloading their tarball it is better to get the latest packages from here:

There are several distro-specific install help pages similar to this, for example the Ubuntu one is here:

You should be able to follow my Fedora instructions and "translate" them to your Linux distro. If you can't, you're probably not ready to be fiddling around with this stuff anyway!

Anyway, onwards with the Fedora install. In my case I downloaded the following packages from the Fedora section:


(Note, USB Modeswitch will never be the very latest version, but if you use the version Vodafone are recommending it should be stable with the other software they recommend you install.)

Before we start executing commands, we need to open a terminal window and switch to the root user:

$ su -

Now, repeating the steps from the Fedora tutorial on Betavine, we install the dependencies:

$ yum install wvdial redhat-lsb pyserial python-sqlite2 python-twisted pytz gnome-python2-libegg

Then we switch to the directory we downloaded the packages to and install USB Modeswitch and OZero CDOff (remember to put in the versions you downloaded, not necessarily this actual command):

$ rpm -i ~/Download/usb_modeswitch-0.9.7-1.fc10.i386.rpm
$ rpm -i ~/Download/ozerocdoff-0.4-1.fc10.i386.rpm

The problem with most USB 3G modems is they have two modes. In one mode they are a pen drive and in the other mode they are a modem. Typically they only ship with Windows drivers, sometimes Mac drivers as well. In any case, they seemingly seldom, if ever, ship with Linux drivers. What normally happens with Windows is the device starts up as a pen drive, the hardware drivers are installed and then they are responsible for "switching" the device in to modem mode so you can use it. This "switch" is done via some codes, specific to the device, which controlling software can pass as a command to switch from disk to modem mode.

That's where USB Modeswitch and OZero CDOff come in. The former manages the switch of mode from disk to modem, the latter disconnects any mounted disk containing software we don't care about that won't work anyway and, crucially, creates modem ports your NetworkManager/Vodafone Mobile Connect/whatever can use to start up a network connection. OZero CDOff is not really required in many cases, as there is an alternative way to create these modem ports, however it works and makes life easier, so use it. =)

Of course, when you first install it USB Modeswitch needs some help. It has no idea what the codes are for your specific device, so you need to tell it. You need to edit the config file:

$ gedit /etc/usb_modeswitch.conf

Scroll down a ways and you will start to come to device names, after all the documentation. If you're lucky, your device will already be there and you can just un-comment (delete the ';' characters at the start of the appropriate lines) the settings for your device. If you're not lucky (and this is far more likely) you'll need to go and find the specific configuration for your new device. Usually I Google for it and usually I find someone has already provided the details. Either on the Betavine forums (if it's a Vodafone device) or on the USB Modeswitch forums (for Vodafone + everything else). The two sites to search are: (Vodafone only) (all devices)

Now, my device is a Vodafone K3765 and I found this post on the USB Modeswitch forums (Josh, by the way, is the maintainer of the project):

Here's the configuration I pasted in to the top of usb_modeswitch.conf:

# Huawei K3765

DefaultVendor= 0x12d1
DefaultProduct= 0x1520

TargetVendor= 0x12d1
TargetProduct= 0x1465


Note, at any given time you may only have a single device "enabled" (e.g. uncommented) in your configuration file. If you have more than one device you may consider creating your own start-up scripts for each one, having a configuration file per device and starting usb_modeswitch something like this:

$ su -c "usb_modeswitch -c /path/to/device/config.conf"

If you're really unlucky, you might find you have a device no one has ever figured out the configuration for. In this case, either take it back to the shop and get one you know does work (hit the forums for reports of success and device/operator combinations that are known to work), wait patiently for someone else to provide a config file or do it yourself.

The latter is tricky, and I've never needed to, but it involves using a USB sniffer to snoop on the existing drivers and find out what the codes usb_modeswitch needs are. One Linux program called USB Sniff seems popular. Read up on that if you want/need to go that route.


Now, if you *do* have a Vodafone device, you should probably install the latest Vodafone Mobile Connect software too, as it has a useful GUI and contains specific support for your device (hopefully! Though development is a little behind the very latest models because it is a small team.)

I downloaded this version, again from the Forge site rather than the Download link on the Fedora instruction page:


And installed it:

$ rpm -i ~/Download/vodafone-mobile-connect-2.20.01-1.noarch.rpm

You'll now find a Vodafone icon in Applications -> Internet.

On with the show! Required again:

Before you continue, restart your computer with the 3G modem in a USB port. Here's what should happen:

On reboot usb_modeswitch and ozerocdoff should do their thing, switch the mode of the key from disk to modem and create the modem ports. When the system boots and you login, click on the NetworkManager in the task manager area, top right, and you should see "Auto Mobile Broadband (GSM) connection" as an option. If you click it, you should be prompted for the PIN of your SIM card inserted in the 3G key. After entering that, the key should simply connect to the Internet. And that's it! (I had to disconnect and reconnect once at first, to get Internet access, but after that it was fine.)

Alternatively, if you have a *Vodafone* mobile device and prefer to use it, open the Vodafone Mobile Connect application. Your device should be there to select on the start-up screen. Go through the initial set-up screens (I left everything default) and then there is a big green Connect button in the top left. You know what to do! (Again, you may have to try this a couple of times to actually get a connection to the Internet at first, but it should settle down and work after initial attempts. I had the same problem with Windows - it's just the way it is with a new key/contract, I think.)

Note, even if you do have a Vodafone device, you are not obliged to use the Vodafone Mobile Connect application. It will work through NetworkManager anyway, so VMC is always optional.

Now, what to do if it doesn't go so smoothly?

Firstly, you may need to un-mount any connected pen drive you don't want. If you notice a drive that you do not normally have, this is surely the 3G key:

$ umount /media/Name\ of\ odd\ device

Then we need to manually mode switch. First, we use lsusb to check the current settings. Here's my output:

$ lsusb
Bus 001 Device 004: ID 12d1:1465 Huawei Technologies Co., Ltd.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 003: ID 0b97:7762 O2 Micro, Inc. Oz776 SmartCard Reader
Bus 003 Device 002: ID 0b97:7761 O2 Micro, Inc. Oz776 1.1 Hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 413c:a005 Dell Computer Corp. Internal 2.0 Hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

The first device is actually my modem. Where it says ID those two numbers *should* correspond to the TargetVendor and TargetProduct values in your usb_modeswitch.conf file. If they correspond to the DefaultVendor and DefaultProduct values instead, mode switching has failed. Try it manually, like this:

$ usb_modeswitch -W

The "-W" is a sort of debug output, tells you everything. Afterwards do lsusb again. If the ID details are still wrong, you have a bigger problem. Time to hit the forums, my friend! Normally the problem is simply incorrect values in usb_modeswitch.conf, but you'll have to start Googling for a solution I'm afraid.

All being well though, mode switching occurred. Next we need to do the work of ozerocdoff manually. Here's how:

$ modprobe -a option
$ echo "0x12d1 0x1465" > /sys/bus/usb-serial/drivers/option1/new_id

The numbers after the echo, 0xXXXX, the XXXX should again correspond to the TargetVendor and TargetProduct numbers in the config file for usb_modeswitch.

If this is successful, you should be able to do something like this:

$ ls -l /dev/ttyUSB*
crw-rw---- 1 root uucp 188, 0 2010-04-28 10:55 /dev/ttyUSB0
crw-rw---- 1 root uucp 188, 1 2010-04-28 10:48 /dev/ttyUSB1
crw-rw---- 1 root uucp 188, 2 2010-04-28 10:48 /dev/ttyUSB2
crw-rw---- 1 root uucp 188, 3 2010-04-28 10:48 /dev/ttyUSB3
crw-rw---- 1 root uucp 188, 4 2010-04-28 10:55 /dev/ttyUSB4

If nothing is found, again, you have a bigger problem. It's forum time! Some devices have trouble "sticking" in modem mode and may require further tweaks to usb_modeswitch, but you'll have to investigate carefully. It may take some time.

Another issue I had, though only on my EEE PC 901, was VMC not "seeing" the device on initialisation. To resolve this I had to run this command (I found it on the Betavine forum) to make VMC "see" the 3G key. I don't understand why, but everything else seemed fine so I executed this command, as advised, removed the device, plugged it in again, started VMC and everything was fine:

$ eject sr0

As I say, I have no idea what or why, but it fixed things on my netbook. My Dell laptop did not have this problem. All that said, once things are installed and settled, as long as the key is inserted when the computer is booted you should have no problems.

Finally, what if the 3G key is *not* inserted when the computer is started? The following commands should sort it for you:

$ su -
$ usb_modeswitch
$ modprobe -a option
$ echo "0x12d1 0x1465" > /sys/bus/usb-serial/drivers/option1/new_id

That's all you need! Switch to root user, switch key mode to "modem" and create connection ports for the modem. Job done.

I hope this post has been helpful. It will certainly help jog my memory in future! =)