Mar 1, 2012

Troubleshooting USB mobile internet in Ubuntu

Most mobile broadband USB sticks come with two partitions; one with the installer and the other with the actual connection device. When you plug in the USB, the operating system will first mount the installer partition (which usually contains the installers for Windows and Mac). The installer will insert code that will automatically switch the USB to skip the installer and mount the connection device directly. Unfortunately most manufacturers don't support Linux, so new USB devices won't work straight away.

This guide will provide some tips to get your troublesome USB broadband stick working. This guide will focus on Ubuntu (11.04 in particular), however most of this guide should be applicable to other distro's as well (as long as it has usb_modeswitch installed). The particular device I will be configuring is the Huawei Technologies K3771 USB device given by Vodafone Australia.

First we will go through some troubleshooting tips for those new to the game, and by step 3 we will begin applying our fix.


  1. Plug-in your device, open up a terminal (or command prompt) and type in the following command:

    nm-tool

    This will open up a list of internet devices; eth stands for ethernet and is usually your wired/wireless connections. We are looking for entries with wwan, GSM, 3G or Mobile Broadband in this list. If your device is detected here but does not work then it is a software issue that is outside the scope of this guide.
     
  2. Now we need to see if your device is even detected by the system. Unplug your device, wait a second and in the terminal type in:

    lsusb > ~/usb1.txt

    When the command finishes plug the device back in, wait ALOT of seconds (wait until LEDs start flashing) and type in:

    lsusb > ~/usb2.txt

    Now to see if anything changed. Type in the command:

    diff ~/usb1.txt ~/usb2.txt

    You should now see something like:

    6a7> Bus 002 Device 008: ID 12d1:14c4 Huawei Technologies Co., Ltd

    If nothing pops up on the terminal, then either you jumped the gun too early with the second lsusb OR your device simply isn't playing nice. This is outside the scope of this guide and I suggest you hit up the guys at libusb or kernel developers to track this problem down. But before you do just cross your fingers and try:

    sudo /usr/sbin/update-usbids

    This will update the id list of USB devices your system will support; hopefully it will be in there!!
     
  3. So now the hard part starts. The line we got from lsusb gives us some useful information about the device. The ID of a device can be split into two parts; the first part (12d1) is the vendor code, and the second part (14c4) is the product code. Unfortunately, in this case the product code points to the installer partition of the device. We need to manually tell the system to switch over to the mobile broadband part (this is what the installer does automatically for Windows and Mac). To do this we run the following command:

    sudo gedit /lib/udev/rules.d/40-usb_modeswitch.rules

    This will bring up a text editor with a list of all the USB devices that the system will automatically switch. We now need to add our device to this list. Either add to the end of the file or do a search to find similar devices and add:

    # This is just a comment. Replace this text with information of your device
    ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="14c4", RUN+="usb_modeswitch '%b/%k'"

    Replace the vendor and product id's with whatever lsusb produced. It should look like:

    # Vodafone (Huawei) K3771
    ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="14c4", RUN+="usb_modeswitch '%b/%k'"

    Ok, so now we are telling the system to switch our device.... switch to what? Remember, no matter how fancy they get computers are always very, very stupid machines. The mobile broadband device has it's own product id that we must link to the installer id. This is where it gets tricky; you need to figure out what this id is and at this stage I have no other advice other than to Google and pray. Luckily for me I know that my device id is 12d1:14ca. Now we need to create a custom usb_modeswitch rule.....
     
  4. Navigate to the directory /usr/share/usb_modeswitch/ by running the following command in a terminal:

    cd /usr/share/usb_modeswitch/

    If you perform an ls you will see that this directory contains a file called configPack.tar.gz. This file contains all the switching rules; we need to edit it to add our device. First back up the file through:

    sudo cp configPack.tar.gz configPack-ORIGINAL.tar.gz

    Now we will extract the scripts through running:

    sudo mkdir configPack/; sudo tar xzf configPack.tar.gz -C configPack/

    Run the command to open a text file for our new rule (replace the 12d1:14c4 part with the id of your device):

    sudo gedit configPack/12d1\:14c4

    This will open a completely blank document. Add the following text (remember to customise for your particular device!):

    ##########################################
    # Vodafone (Huawei) K3771 (again, this is just a comment)
    #
    # Our settings discovered by lsusb (the '0x' part just
    # tells the system how to interpret the number
    DefaultVendor= 0x12d1
    DefaultProduct=0x14c4
    #
    # Our target product that we will switch to
    TargetVendor= 0x12d1
    TargetProduct= 0x14ca
    #
    # Some misc values that I don't really understand and am
    # not game enough to change...
    CheckSuccess=20
    MessageContent="55534243123456780000000000000011062000000100000000000000000000"

    Now we need to repack the rules and clean up our mess:

    cd configPack/; sudo tar -czf ../configPack.tar.gz *; cd ../; sudo rm -rf configPack/

    You can check the contents of the file by running the following command:

    sudo file-roller configPack.tar.gz
     
  5. Now restart your machine and, fingers crossed, the system will now correctly detect your device!

References

Some useful links for those who want to trace something more specific:

No comments:

Post a Comment

Thanks for contributing!! Try to keep on topic and please avoid flame wars!!