Kenya, Miscellaneous

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=0x12d1 product=0x1003)
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

41 Comments to “Safaricom, Huawei e220, Linux and you!”

  1. Erdost Ansal

    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.

  2. bgm

    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?

  3. Alan Author

    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

  4. Peter Waa

    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.

  5. KENNETH ORWA

    I bought a new Bamba Net modem of 3G capacity of Safaricom but it keeps on droping each and everytime.Even connecting it is a problem,yet my town of Migori there are limited Internet connectivity yet we need to have one so the only solution left is just the safaricom.
    We just have to use that even if it is not stable coz its the thing we have at hand.

  6. Sheila Ommeh

    Dear Alan,

    Thank you very much for this information which is quite timely. I have a safcom bambanet and I have been tying to get it work in UBUNTU Hardy Heron LTS.

    Now I have the following problem:

    When I use the following configuration
    [Dialer Defaults]
    Init1 = ATZ
    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Init4 = AT+CGDCONT=1,”IP”,”www.dialogsl.com”
    Password = bar
    Phone = *99***1#
    Modem Type = Analog Modem
    Stupid Mode = yes
    Baud = 9600
    Dial Command = ATDT
    Modem = /dev/ttyUSB0
    ISDN = 0
    Username = foo

    I get connected BUT I am not able to surf the internet i.e. no connection. I tried using your configuration and it was not working.
    What can you advise?

    Regards,
    Sheila

    What

  7. Sheila Ommeh

    Hi Alan,

    I managed to solve the problem by modifying the configuration above as below:

    [Dialer Defaults]
    Init1 = ATZ
    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Init4 = AT+CGDCONT=1,”IP”,”SAFARICOM”
    Password = bar
    Phone = *99***1#
    Modem Type = Analog Modem
    Stupid Mode = yes
    Baud = 9600
    Dial Command = ATDT
    Modem = /dev/ttyUSB0
    ISDN = 0
    Username = foo

    Since I use Mozilla, I also unchecked the work offline mode in the file menu.

    Everything is working fine with internet but I am not able to connect to a remote server :(

    I will post this once sorted out.

    Best regards,
    Sheila

    1. Alan Author

      Sheila,

      Make sure you have DNS entries in your /etc/resolv.conf when you connect the modem. Those are really important for resolving human-readable names like “apple.com” to the IP addresses (numbers) which computers need!

      Also, I’m wondering if your bamba net is the default connection. Maybe try to make sure the any Ethernet and/or Wireless cards are disabled.

      Good luck!

  8. Mubarak

    Hi,
    JUst came across you website and installing the 3G modem on Linux. My Scenario: Asus Eee Netbook running Linux, Huawei e160 3G Modem. Will your solution work on this hardware?
    Many thanks.

  9. Jason Hopkins

    SWEET!! I’m in Nairobi and the only linux user I know. I use Ubuntu – though I used LFS before. I followed your instructions.

    The modem was plugged in when I booted so I saw the TTY stuff no problem – at least this time.

    I copied your wvdial.conf then changed:
    Modem = /dev/ttyUSB0

    Also, when copy/paste I had to replace the ” with the straight kind. Pretty obvious if you know what your looking at otherwise it may drive you crazy!

    I’m curious, why is this called an analog modem and not a USB modem?

    Thanks for the help. I was worried when I couldn’t get it working in VirtualBox I was going to have to dual boot again!!

    I use Zain for my phone, any idea how to top up without having to put the SIM in my phone?

    1. Alan Author

      Jason,

      Glad it worked for you. I don’t know any other hardcore Linux users in Nairobi… good to know you’re out there! As for topping up the credit… I use Safaricom, but it should be the same. Instead of putting the SIM in your phone, just top up your phone and then sambaza (“spread”) the credit to your modem’s phone number. I’ve never used Zain/Celtel, but I know there’s a way to send credit to other numbers.

      Good luck!

    2. Alan Author

      Jason,

      I re-read your comment… you use Zain for your phone, haha. No, I don’t know a way to sambaza credit to your Safaricom line! I realized I had read your comment wrong when I looked in the comment log and your IP was the same as mine (so I thought, “Shit, he’s using Safaricom”).

      Haha, Actually, you should just buy a data bundle. I just bought one last month. 1000 bob and your rate per megabyte goes down to 3.3 shillings. It’s much better than topping up with 50 bob here and there.

      To get the bundle just make sure your phone has 1000 bob credit and then send an SMS with “activate” to 446. Then you can check your remaining data by SMSing “balance” to 450. I’ve been using mine for almost three weeks now.

      I hope that helps…

  10. Jeff

    Hi Alan, I’ve just bought a modem with the 300MB preloaded. Now the literature I’ve seen says that to activate one should send a text to 446. I have a Zain SIM on my phone. Do I send the text from a Safaricom line or do I insert the SIM that came with the Bambanet?

    1. Alan Author

      Jeff,

      If the 300 megs is preloaded I doubt you have to “activate” it. To check, what you can do is put the Bambanet SIM in your phone and SMS “Balance” to the number 450, it will tell you how many megs you remain with.

      As far as I know the “activation” is only used when you want to purchase a new bundle. What you do then is top up so you have 1000, 2000, or however many shillings the data bundle costs, and then you SMS the word “activate” to the appropriate number (446 for 300 MB, 447 for 700 MB, etc).

      Hope that helps.

  11. the bambanet (Safaricom’s internet access product) is pretty fascinating, though every once in a while it does get its flaws.

    and about it and linux, Ubuntu 8.10 Intrepid is wonderful. it auto-picks the modem and gives u a GUI step-by-step guide to setting it up. :)

    A few pointers to note of, or you’d like to contribute to, check out GotIssuez.com | Bambanet

    1. Alan Author

      With Safaricom the rates are 8 Kenyan shillings per megabyte. They also sell several bundles 300 MB, 700 MB, etc. For a 300 meg bundle you pay 1000 shillings, which is like 3.3 shillings per megabyte. So you can see it’s pretty affordable if you buy the bundles and ration yourself (no youtube!) :)

  12. george

    Hello Allan. thanks very much for this post. really helped me alot. however could be by any chance be having the wvdial setting for Yu network.

    1. Alan Author

      George,

      Where I live there is Yu voice only, so I haven’t had a chance to test data yet. I was in Nairobi the other day and I used Yu’s EDGE without much trouble at all on my Nokia 5320. The configuration was fairly simple, and not nearly as complex as the Yu website wants it to be. For the record, I didn’t need any of the proxy settings they were talking about. I’m not even sure the APN matters (Yu’s website lists an APN of “internet” but I was successful with “yu” and I’m sure others will work).

      I don’t have a Huawei modem anymore, and like I said there is no Yu internet here in Kangundo yet, but one thing to consider is that Safaricom has network locked the modem. It’s a shame if they have…

      Good luck.

  13. mike

    hi i know it must be like a gazillion years since you wrote this article, but its still useful since i used it to get the huawei e220 working in my opensuse 11.2 installation. would be nice to note im in an area with 3G and the speed is :)~! , dop dead gorgeous

  14. Linda

    I would really appreciate if you took me on step to step help on how I would use the safaricom modem from when I am at the network preferences and click on network connection to whhere I select my provider and insert my username and password coz what u have given me is doing jerk for me. I just don’t get it. please help.

    1. Carlos

      I’m replying to my own post :-)

      After some extra configuration in Slackware 13 using pppsetup, it worked perfectly.

      Thanks a lot for this blog!

        1. mike

          Alan:
          well its a nice thing he was able to do that, but slackware 13 was the easiest for me along with opensuse 11.2 in connecting the e220 modem, im however having real trouble with fedora 12 and debian lenny. the so called “friendlier” distros

  15. Carlos

    Hi, do anyone have experience connecting to Orange?

    I am able to connect but the IP address that I get seem to be wrong. For example:

    ATZ
    OK
    –> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    OK
    –> Sending: AT+CGDCONT=1,”IP”,”bew.orange.co.ke”
    AT+CGDCONT=1,”IP”,”bew.orange.co.ke”
    OK
    –> Modem initialized.
    –> Sending: ATDT*99#
    –> Waiting for carrier.
    ATDT*99#
    CONNECT
    –> Carrier detected. Starting PPP immediately.
    –> Starting pppd at Mon Feb 1 14:59:26 2010
    –> Pid of pppd: 15754
    –> Using interface ppp0
    –> pppd: (â[06][08][08]ã[06][08]
    –> pppd: (â[06][08][08]ã[06][08]
    –> pppd: (â[06][08][08]ã[06][08]
    –> pppd: (â[06][08][08]ã[06][08]
    –> pppd: (â[06][08][08]ã[06][08]
    –> pppd: (â[06][08][08]ã[06][08]
    –> local IP address 10.53.0.196
    –> pppd: (â[06][08][08]ã[06][08]
    –> remote IP address 10.64.64.64
    –> pppd: (â[06][08][08]ã[06][08]
    –> primary DNS address 212.49.70.22
    –> pppd: (â[06][08][08]ã[06][08]
    –> secondary DNS address 212.49.70.23
    –> pppd: (â[06][08][08]ã[06][08]

    Now, I am not able to reach any of the DNS, not browse the internet.

    Many thanks.

  16. Chris

    Hi Carlos,
    If I got you right, you have NOT yet figured it out, am I correct? I would also like to use Orange’s CDMA services, as they are much cheaper than Safaricom. The ZTE modem is not picked by Linux (I am running Linux Mint Helena), but their Huawei is. Yet, it does not connect. Any ideas or past experiences? Thanks a lot!

  17. peter

    Mike,
    works fine by me. I’m using Debian Lenny. I installed wvdial, modified /etc/wvdial.conf and voila I was up and running.

  18. Samuel

    Hi allan,
    My sister wants a system like mine, linux mint, because she doesn’t want to deal anymore with windows xp virus. I think of sending her Linux mint isadora (ubuntu 10.04 LTS) but not sure of how it behaves with the safaricon dongle. With Ubuntu 9.04 it worked very well (the last time I was in kenya). What about PClinuxOS 2010, has anyone there tried it on any kenyan usb modem internet providers?

  19. Tony

    Hi
    I am running ubuntu 10.04 on laptop. I copied the wvdial settings that you have posted here to my /etc/wvdial.conf file so as to connect to the net using my safcom Huawei E220 dongle. I got the error ‘bad init string’ after the first run. I then removed the line ” Init4 = AT+CGDCONT=1,”IP”,”SAFARICOM” ” from the /etc/wvdial.conf settings. I am currently getting the error below:

    No Carrier! Trying again.
    –> Sending: ATDT*99#
    –> Waiting for carrier.
    ATDT*99#
    NO CARRIER
    –> No Carrier! Trying again.

    I would really appreciate any help I can get.

    1. Alan Author

      Tony,

      Hey, if you’re on Ubuntu 10.04 it should work without wvdial. Try to plug in the modem and then right click the network menu, go to “Edit connections” and then set up a new “Mobile Broadband.”

      I’ve been meaning to update this post to mention that wvdial isn’t strictly necessary anymore!

  20. Safri Dzal

    Wow, your post was 2008 but it just fit to what I want..Now I’m using LinuxMint11, no problem on connecting, but I cannot send/recieve SMS. Your post was a great help to me..thanks a lot.

  21. Dennis Mungai

    Got a solution to a small problem with the ZTE MF192 HSPA modem on Fedora 17 from a post made in 2008. Unbelievable. Yet it works since I’m using wvdial to connect to the internet.

    Thanks man!

Comments are closed.