Using The T-Mobile 3G USB Stick Under Linux
Background
This page is an update to my earlier pages on 3G under Linux.
As the first 12 months of my T-Mobile contract had finished, in March 2008 I was able to upgrade free of charge to a new USB stick 3G device. The one supplied by T-Mobile UK is a little larger than a USB memory stick. It is black and pink with T-Mobile branding, but it is really a HUAWEI E220 device, made in China.
Compared to the old Cardbus PCMCIA card, the USB stick is much easier to set up under Windows and MacOsX, as it doubles as a read-only memory stick containing the setup programs for Windows and MacOsX, which are mercifully smaller and less fiddly than the ones shipped with the device I'd used earlier. So, under Windows and MacOsX, the device is really quick to set up: just plug in the stick and let the autorun programs do their job. Really very handy if a colleague wants to borrow your 3G to quickly look something up on the web.
Inserting the 3G USB stick into my Dell D620 laptop running Linux (Kubuntu/Ubuntu Feisty Fawn), there was a little more fiddling to do, as detailed below. Basically in most cases it should just work (the thing is autodetected as a USB serial port), but in my case there was a small amount of messing required in order to avoid a clash with a built-in 3G card that I didn't want to use.
Costs
By agreeing to a 24-month contract, the cost (for up to 3 GB per month) comes down to 15 pounds per month (or half that if you are lucky enough to know someone who can give you a friends and family employee discount).
Getting 3G working Under Linux
Note for Ubuntu 7.10 "Gutsy Gibbon" Linux (tested on a Thinkpad T41): You need to enter the following commands after plugging in the USB stick, in order for /dev/ttyUSB0 and /dev/ttyUSB1 to be created:
sudo modprobe -r uhci_hcd sudo modprobe uhci_hcd
The remainder of these notes apply to Kubuntu/Ubuntu 7.04 "Feisty Fawn" Linux on a Dell Latitude D620. Your mileage may vary on other Linux versions on other hardware.
Plug in the 3G USB stick and you should see this:-
cat /proc/bus/usb/devices !! This command does not work on Gutsy Gibbon !! ... P: Vendor=12d1 ProdID=1003 Rev= 0.00 S: Manufacturer=HUAWEI Technologies S: Product=HUAWEI Mobile
Similarly if you run 'sudo lsusb' you should see (even on Gutsy):
Bus 004 Device 024: ID 12d1:1003
Now, on my machine, there was already an internal 3G modem that I no longer wished to use, as I wanted to keep the SIM card in the USB stick for portability. But the effect of the internal modem was to autoload the 'option' kernel module, which in turn would autoload the 'usbserial' module with the wrong parameters, creating a /dev/ttyUSB0 device pointing to the wrong hardware. Your mileage may vary, but on my machine the solution was as follows...
1. Edit /etc/modprobe.d/blacklist and add a line saying:
blacklist optionto stop the kernel module loading for the old hardware made by Option Inc.
2. Create /etc/modprobe.d/usb3g containing this line:
install usb3g modprobe usbserial vendor=0x12d1 product=0x1003This creates a placeholder called 'usb3g' which is a shorthand for loading the usbserial module with the right arguments.
Now, to test this by hand... Execute the following commands as root..
rmmod option rmmod usbserial modprobe usb3gThis unloads the old option 3G module and the usbserial module from the kernel memory, then it loads the usbserial module with the right parameters (just a shorthand for 'modprobe usbserial vendor=0x413c product=0x8116'). If you type ls -l /dev/ttyU* you should now see:-
crw-rw---- 1 root dialout 188, 0 2008-03-07 21:40 /dev/ttyUSB0 crw-rw---- 1 root dialout 188, 1 2008-03-07 21:40 /dev/ttyUSB1 crw-rw---- 1 root dialout 188, 2 2008-03-07 21:40 /dev/ttyUSB2
In order to connect to the Internet, we just need to invoke 'kppp' and tell it to dial '*99#' using device /dev/ttyUSB0 (see below).
The fiddly bit was getting the three /dev/ttyUSB devices created correctly each time. You will probably find that it will be simpler on your machine: you can probably just add the line 'usb3g' to /etc/modules (to get the module loaded correctly at boot time). In my case that didn't work, because it was too late when that happened: the usbserial module had already been loaded with the wrong parameters (for my old modem I think), so the /dev/ttyUSB0 entry pointed to the wrong device. So I frigged it using a combination of /etc/sudoers and the KPPP pre-flight command execution option as detailed below....
Using 3G with KPPP
Using the KPPP utility from the Kubuntu desktop ("K" / "Internet" / "KPPP Internet Dial-Up Tool"), I created a new PPP dialup connection.
- Start KPPP and press 'Configure...'.
- Under 'Accounts', press 'New' and create a name for the 3G/GPRS connection: say T-MobileUSB.
- Enter the telephone number to dial as *99#
- Under 'Modems', add a new modem (say T-MobileUSBModem). In the modem Device tab, set the port to be /dev/ttyUSB0 from the drop-down menu.
- Username and password don't seem to matter, but I set them to web/web.
- The dirty frig for my machine (which most people won't need) goes like this:
- Under the 'Execute' tab for the 3G/GPRS connection, I entered the 'Before Connect' command: 'sudo /usr/local/sbin/go3gusb' (without the quotes).
- I created a shell script called /usr/local/sbin/go3gusb containing the lines:
/sbin/rmmod usbserial sleep 2 /sbin/modprobe usb3g sleep 2
- Now, the sudo command would normally prompt for your password in order to gain the root privileges that are needed for all this.
But you can't enter your password in the middle of KPPP, so what you need to do is arrange for the 'go3gusb' script to invoke the sudo
command without a password. You can do this by adding the line: 'fred ALL = NOPASSWD: /usr/local/sbin/go3gusb' to your /etc/sudoers file,
where 'fred' is your login name.
This trick worked under Feisty Fawn on the D620, but it didn't work under Gutsy Gibbon on the Thinkpad (where I needed to unload and reload the uhci_hcd module). Gutsy's KPPP daemon seems to check that the serial device exists before starting the 'Before Connect' command, so it doesn't seem to be possible to use that command to create the device. So on Gutsy I just run the script by hand after plugging in the 3G stick.
- Under the 'Execute' tab for the 3G/GPRS connection, I entered the 'Before Connect' command: 'sudo /usr/local/sbin/go3gusb' (without the quotes).
Interestingly, there did not seem to be any need to set up the APN, the 'novj' command, or the MTU. So the procedure seems a little simpler than before in some regards.
I hope this helps someone. I would be interested to hear if there is some way to make usbserial load correctly at boot time, to avoid the need to unload it and reload it with the right arguments from KPPP, which seems dirty on account of the sudoers hack.