Hujambo!

snake-sugar
Alan volunteering with VSO in Tala, Kenya

Safaricom, Huawei e220, Linux and you!

I live next to nowhere in Kenya, so Internet access is pretty limited. I am able to access it at work, but it’s slow and only available during the day. Luckily Safaricom, one of the local cell phone companies, just rolled out 3G technology across Kenya. My cell phone isn’t very fancy so I picked up the USB modem instead. When the Safaricom employee asked if I had brought my laptop for them to configure I replied, “Um… no. I’ll do it myself…” So this is the culmination of my ensuing research.


Using a Huawei e220 With Safaricom Under Linux


Safaricom\'s Huawei e220The Huawei e220 is a USB HSDPA modem capable of some crazy speeds like 7.2 megabits per second, though Safaricom advertises the max on its network as being around 3.6. If you look around on the internet you’ll find a dearth of information about using the Huawei e220 under Linux, as lots of mobile phone companies all over the world have been providing these units for a few years. The software required to use these under Linux has changed a lot of the years, and it’s actually pretty easy to get working once you piece together the information from several blogs, forums, and man pages. If you also live in Kenya, use Linux, and have one of these modems, keep reading.

Requirements:
-Linux Kernel 2.6.20 or higher (I’ve used 2.6.24.x and the 2.6.25 prereleases)
-wvdial (which requires wvstreams from the same website)
-pppd

Make sure these are all installed and then keep reading!


Enable USB Serial Support in the Kernel


If you use Ubuntu or Fedora or whatever you may not have to do this step, but it’s here for reference. I use Zenwalk Linux and compile my own custom kernels, so I had to enable support for USB serial devices in the kernel’s menuconfig:

Device Drivers —>
   [*] USB support —>
      USB Serial Converter support —>
            <M> USB Serial Converter support
            [*] USB Generic Serial Driver
            <M> USB driver for GSM and CDMA modems

The “USB Generic Serial Driver” will be compiled as a module and will be called “usbserial” and the “USB Driver for GSM and CDMA modems” driver will be named “option”. Both of these drivers work with the e220, but it appears as if the option is the more appropriate one (the kernel’s drivers/usb/serial/option.c has some Huawei-specific notes whereas the generic driver is just generic). I’ve read of some speed differences between the two, but that may be only in Europe where you actually see speeds in excess of 10 or 30K/sec! After you compile your kernel with the new modules you should load the “option” module.

sudo modprobe option


Plug in the Modem!


In addition to three serial ports, the Huawei e220 also has a small memory containing some Safaricom software for Windows, so you may see some usb-storage notes in the system logs, but just ignore those. Look in the system log for some notes like below:

option 2-1:1.0: GSM modem (1-port) converter detected
usb 2-1: GSM modem (1-port) converter now attached to ttyUSB0
usb-storage: probe of 2-1:1.1 failed with error -5
option 2-1:1.1: GSM modem (1-port) converter detected
usb 2-1: GSM modem (1-port) converter now attached to ttyUSB1

If you don’t see anything about TTYs that’s ok, I usually don’t see them either! For some reason the e220 has a problem going into serial mode, so the serial ports do not show up until you prod the device a bit. If the modem is plugged in when the computer is boots up there seems to be no problem, but if you sleep the computer or unplug/replug the modem the only parts that show up are the partitions containing the Safaricom software.


Show Me Your Ports!


Some guy wrote a tool that switches the e220 to the correct mode for the serial ports to appear. You can download it here or here. Once it’s downloaded, compile it, run it, and then look at the system log for the TTYs!

[aorth@kenya: ~]$ cc huaweiAktBbo.c -lusb -o e220_fixer
[aorth@kenya: ~]$ ./e220_fixer
4 set feature request returned 0
Prepnute-OK, Mas ttyUSB0 ttyUSB1 (cez usbserial vendor=0×12d1 product=0×1003)
pozri /proc/bus/usb/devices

If the system log says the TTYs have been connected, you now need to figure out where the device nodes were created. We only need the first one, and on my system it is located at /dev/tts/USB0. I believe the default in recent kernels/udev versions is /dev/tts/USB0 or maybe /dev/ttyUSB0.


Creating Your wvdial.conf


Create a file to hold your wvdial configuration. When I compiled wvdial I told it to look for configuration files in /etc, and my /etc/wvdial.conf contains the following lines:

[Dialer Defaults]
Phone = *99#
Username = doesnt
Password = matter
Stupid Mode = 1
Dial Command = ATDT

[Dialer huawei]
Modem = /dev/tts/USB0
Baud = 3600000
Init2 = ATZ
Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = Analog Modem
Init4 = AT+CGDCONT=1,”IP”,”SAFARICOM”

If you haven’t tinkered with your SIM card yet you probably have to enter a PIN for the modem to be able to access the network. I disabled the PIN request by putting my modem’s SIM card in my phone and going to the Security settings. Otherwise, you can just enter your PIN manually and then dial the “huawei” section of your configuration:

[aorth@kenya: ~]$ sudo echo “AT+CPIN=xxxx” > /dev/tts/USB0
[aorth@kenya: ~]$ sudo wvdial huawei

After you dial you should see wvdial run through your configuration and then it will call Safaricom using pppd. It should hopefully look something like this:

CONNECT
–> Carrier detected. Starting PPP immediately.
–> Starting pppd at Thu Mar 27 08:29:45 2008
–> Pid of pppd: 4081
–> pppd: è7ö·Ðx[06][08]HÁ[06][08]
–> Using interface ppp0


–> local IP address 172.27.138.45
–> pppd: è7ö·Ðx[06][08]HÁ[06][08]
–> remote IP address 10.64.64.64
–> pppd: è7ö·Ðx[06][08]HÁ[06][08]
–> primary DNS address 10.11.12.13
–> pppd: è7ö·Ðx[06][08]HÁ[06][08]
–> secondary DNS address 10.11.12.14
–> pppd: è7ö·Ðx[06][08]HÁ[06][08]

It’s a bit ugly, but you should be dancing with joy when you see wvdial stop spitting crap out after the DNS servers! Take the two DNS server addresses and paste them into /etc/resolv.conf, commenting any others out. PPPd puts these DNS servers into /etc/ppp/resolv.conf but they didn’t won’t work there for me.

Hopefully you are able to browse the internet now… leave a comment if you need help!


Other Tools


Links

11 Comments so far

  1. Mom UNITED STATES March 28th, 2008 8:01 am

    Huh? What? and Wow!

  2. Erdost Ansal UNITED STATES March 28th, 2008 10:52 am

    You are the man Alan! Although I am an avid windows user, I would like to thank you on behalf of the unix community for this great post:) I can see that your unix skills are as sharp as before. Take good care of yourself.

  3. Ben UNITED STATES March 28th, 2008 12:42 pm

    Can you write a tutorial for the MAC, please?

  4. Sara UNITED STATES March 28th, 2008 2:54 pm

    SNL ;)

  5. bgm March 29th, 2008 3:52 am

    What’s the browsing experience like. From your about page it says you’re in Tala so the 3G is probably not there yet but have you been able to get the 3.6Mb/s advertised anywhere at all?

  6. bernie March 30th, 2008 12:56 pm

    Looks like a long shot for me….I use Ubuntu and use Vodafone Driver for linux (debian package) as detailed in this very easy tutorial here:
    http://www.howtoforge.com/vodafone_mobile_connect_card_driver_linux

    Mac users can get generic drivers here: http://www.huawei.com/mobileweb/en/doc/list.do?type=-1&id=736

    I’m quite sure you cannot get 3G speeds where you are. It wouldn’t make commercial sense for Safaricom to do so.

  7. Alan March 30th, 2008 2:30 pm

    Bernie,

    Yeah, the Vodafone Mobile Connect Driver is a sweet program (it’s really a hell of a lot more than a “driver” like its name suggests). The python setup on my system isn’t up to snuff, so it didn’t work… and as you know I live pretty remotely so I didn’t want to spend a whole bunch of time and bandwidth downloading extra python packages, etc.

    Besides, I kinda like doing it the manual way. ;)

    Thanks for stopping by!

    -Alan

  8. kinyanjui April 18th, 2008 8:46 am

    that an informative information. though your skills in linux are way below mine, it was a good trial.

  9. Mzururaji June 14th, 2008 12:51 am

    That bambanet color is sooo gay. Looks like a dildo/vibrator

  10. punchez June 28th, 2008 9:27 pm

    Cool work man…I have been looking for this information dearly..I’ll apply it to fedora8..keep it up!

  11. Peter Waa October 8th, 2008 12:08 pm

    Hi Allan,

    Many thanks for the script, which I was able to use to connect to the Internet on Safaricom’s GPRS service with my Nokia 6233. However I have tried to connect using the same phone on Safaricom’s 3G service but have not been able to…might you have experienced such a situation before? Can you find a workaround?

    Kind Regards,
    Peter.

Leave a reply