Difference between revisions of "Huawei E220"

From ArchWiki
Jump to: navigation, search
m (categorized)
(Big sloppy edit/update. Feel free to correct many stuff.)
Line 1: Line 1:
 
[[Category:Communication and network (English)]]
 
[[Category:Communication and network (English)]]
  
Huawei E220 it's a 3G HSDPA modem.
+
= Introduction =
 +
Marketed by various telecommunications companies in several countries, the [http://en.wikipedia.org/wiki/Huawei_E220|Huawei E220] is a 3.5G HSDPA USB modem used mainly for wireless Internet access via mobile telephony networks. Technically it is a modem, USB and (due to the CDFS format) CD-ROM device. With a kernel version older than 2.6.20, getting Linux to recognize the device as a modem and accessing its functions requires a workaround.
  
== Make it work ==
+
''"Linux kernel versions prior to 2.6.20 have some problems with it, as the SCSI CDROM fakevolume with drivers for Microsoft systems gets automounted by usbstorage.ko module, preventing serial device /dev/ttyUSB0 from working properly."''
When you plug the modem to the computer you should see 3 usb serials ports of it, normally, /dev/ttyUSB0, /dev/ttyUSB1 and /dev/ttyUSB2.
+
  
If when you connect the modem only one usbserial port shows up (i.e. ttyUSB0) you should run the program below.
+
However, as support for it was added in 2.6.20 via modules ''usb-storage'' and ''usbserial'', getting it to work is as simple as plugging it in and dialling up (the above statement is of no concern to us as we can load and unload modules at will, it was probably meant for pre-packaged GNU and Linux distributions). In fact, using the modem under Linux proves to be more reliable as there are no uncalled-for disconnections. This is probably due to the fact that we are communicating directly with the modem, whereas in Windows or Mac OS X drivers are installed on first run (that is what the storage portion is for) and connection is achieved through a thick software layer every time, leaving room for possible interferences and conflicts.
  
/* Huawei E220 3G HSDPA modem mode activator
+
= Plugging In =
  * 
+
Archers do not use old stuff, let alone use old kernels. That is, however, not enough reason to explain why in some cases the modem still needs the workaround. Thus, you have to see for yourself if you are one of the lucky ones. It almost seems as if the "support" in kernels > 2.6.20 is a myth, although I may be entirely incorrect (maybe it is how Arch developers package the vanilla kernels in which case we have only [http://www.archlinux.org/developers/ phrakkkture and gang] to thank).
  * Copyright (C) 2006 bobovsky bobovsky_at_kanoistika.sk  GPL
+
  * This program is free software; you can redistribute it and/or modify
+
  *  it under the terms of the GNU General Public License 2.
+
  *
+
  * Changes from the original at:
+
  * http://www.kanoistika.sk/bobovsky/archiv/umts/huaweiAktBbo.c
+
  * by raca, vh.dev.linux_at_gmail.com
+
  *
+
  * Compile:
+
  * gcc -lusb h_e220_mma.c -o h_e220_mma
+
  */
+
+
#include <stdio.h>
+
#include <usb.h> //libusb
+
+
//Find a specific usb device and return its usb_device
+
struct usb_device *find_device(int vendor, int product) {
+
struct usb_bus *bus;
+
struct usb_device *dev;
+
+
for (bus = usb_get_busses(); bus; bus = bus->next) {
+
for (dev = bus->devices; dev; dev = dev->next) {
+
if (dev->descriptor.idVendor == vendor
+
&& dev->descriptor.idProduct == product)
+
return dev;
+
}
+
}
+
return NULL;
+
}
+
+
int main(int argc, char **argv){
+
int ret, vendor, product;
+
struct usb_device *usbdev;
+
struct usb_dev_handle *usbdev_h;
+
char *data;
+
+
usb_init(); //init de libusb library
+
usb_find_busses(); // fill the busses info for the library
+
usb_find_devices(); // fill the devices info for the library
+
+
vendor = 0x12d1; //Huawei
+
product = 0x1003; //E220
+
usbdev = find_device(vendor, product);
+
if(usbdev==NULL){
+
fprintf(stderr, "Couldn't find the device, terminating.\n");
+
return 0;
+
}
+
+
usbdev_h = usb_open(usbdev);
+
if(usbdev_h==NULL){
+
fprintf(stderr, "Couldn't open the device, terminating.\n");
+
return 0;
+
}
+
+
ret=usb_control_msg(usbdev_h, USB_TYPE_STANDARD + USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, 1, 0, data, 0, 1000);
+
if(ret==0){
+
fprintf(stdout, "Message to activate modem mode send successfully.\n");
+
} else {
+
fprintf(stdout, "Message to activate modem mode send unsuccessfully, terminating.\n");
+
return 0;
+
}
+
+
fprintf(stdout, "Everything done. You can use the usbtty now.\n");
+
return 0;
+
}
+
Compile with gcc -lusb h_e220_mma.c -o h_e220_mma<br>
+
And run as root the program.
+
  
The usb serial ports:
+
The magic (trick) lies in the kernel modules; unloading, blacklisting, reloading and loading things will get it done.
* ttyUSB0 - Don't know what's for.
+
* ttyUSB1 - Used for modem communication.
+
* ttyUSB2 - Should even show up, isn't used. It has some to do with the emulated scsi cdrom of the modem.
+
  
To check if everything is running ok, use minicom. (If you don't have it just to the usal pacman -Sy minicom)<br>
+
== Quick Start ==
  $ minicom -s
+
After hooking up to the USB port (some say an upright position is best; let it hang over the edge of the desk), check to make sure it is detected.
Change the serial port to /dev/ttyUSB1 and exit (not exit from minicom), this will open minicom.<br>
+
$ cat /proc/bus/usb/devices
If minicom initialize the modem and when you send the command 'AT' the answer is 'OK', the modem is working well on that port.
+
You should see '''Huawei''' somewhere there. If not, you are on your own. The ''usb-storage'' and/or ''usbserial'' modules must be loaded, whether manually or by ''HAL'' is up to you and/or your system.
 +
  # modprobe usb-storage
 +
# modprobe usbserial
 +
$ sleep 6 # the modem may take a while to initialize
 +
$ ls /dev/ttyUSB*
 +
You should see three renditions of '''ttyUSB'''. If not, we will get to that later. This ''is'' a "Quick Start" after all, no? The ports:
 +
* ttyUSB0 - Modem
 +
* ttyUSB1 - USB?
 +
* ttyUSB2 - Nothing
 +
Now you need a dialler. Most convenient of all would be ''wvdial'', so install it. You should have ''ppp'' already, if not just pull them both in.
 +
# pacman -Sy wvdial ppp
 +
Most SIM and data services provided together with the device do not require special settings and work with similar configuration to get connected. They are almost "Plug n' Play", a special trait of Linux. Edit ''/etc/wvdial.conf'' and use something like the following:
 +
[Dialer hsdpa]
 +
Phone = *99***16#
 +
Username = 65
 +
Password = user123
 +
Stupid Mode = 1
 +
Dial Command = ATDT
 +
Modem = /dev/ttyUSB0
 +
Baud = 460800
 +
Init2 = ATZ
 +
Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
 +
ISDN = 0
 +
Modem Type = Analog Modem
 +
There is an example [http://www.insync.za.net/3g_docs/wvdial.conf here] by a "Linux Guru". Then load the PPP module.
 +
# modprobe ppp-generic
 +
You can now connect immediately, but probably only as root, which is '''not''' a disadvantage.
 +
# wvdial hsdpa
  
 +
== Slow Start ==
 +
So why then? Well, for some reason those of us on newer kernels still have to ride the old ways. In some cases, all that is needed to be done is to remove the ''usb-storage'' module first, then load ''usbserial'' with the device IDs. The first ''cat'' command on this page will have that information, while ''lsusb'' is an alternative. Anyhow, the IDs are the same for almost all E220s, so you can copy wholesale.
 +
# modprobe -r usb-storage
 +
# modprobe usbserial vendor=0x12d1 product=0x1003
 +
When you cannot salvage anything from this either, you have to ''go Gentoo'' and compile something. Do not worry, it is only a script and we do things like this almost everyday, albeit in ''bash''.
 +
$ mkdir ~/huawei-e220 && cd ~/huawei-e220
 +
$ wget http://www.kanoistika.sk/bobovsky/archiv/umts/huaweiAktBbo.c
 +
$ gcc -o e220 *.c
 +
# ./e220
 +
This gets around the kernel to recognize the modem functionalities of the device. You can now carry on and connect using the above methods. If you had to follow this step, you will always need the script unless you set ''udev'' rules and such (package link below). So move it to a global ''PATH''.
 +
$ cd ~/huawei-e220
 +
# mv e220 /usr/bin/e220
 +
Now it is easier.
  
== Using it ==
+
= Extras =
 +
''Note: It seems some people get it to work using ttyUSB1, which should not be the case, but rest assured that at least on recent kernels and systems ttyUSB0 is the correct port to dial with.''
  
Now you just have to configure it according to you network provider and set up the scripts do connect.
+
== Port Testing ==
Here,http://thewinningmove.blogspot.com/ , you can find a program do check the modem status and a package which has the wvdial scripts. I haven't been able to make the program to work.
+
To check if the device is functioning alright on a particular serial port, there is a program for probing serial devices.
 +
# pacman -S minicom
 +
Now run it.
 +
# minicom -s
 +
Change the serial port to ''/dev/ttyUSB1'' and exit from the page, this will open the main program. When it initializes the modem, issue the command ''AT''. The answer should be ''OK'', which means the modem is working well on that port.
 +
 
 +
== Packages ==
 +
For an "automated" workaround, there is [http://aur.archlinux.org/packages.php?do_Details=1&ID=14413&O=0&L=0&C=0&K=e220&SB=n&SO=a&PP=25&do_MyPackages=0&do_Orphans=0&SeB=nd huawei-e220] in [[AUR]].
 +
 
 +
For ''Vodafone'' brands of this device, you can use [http://aur.archlinux.org/packages.php?do_Details=1&ID=14414&O=0&L=0&C=0&K=vodafone&SB=n&SO=a&PP=25&do_MyPackages=0&do_Orphans=0&SeB=nd vodafone-mccd] which is the [http://forge.vodafonebetavine.net/projects/vodafonemobilec/ Vodafone Mobile Connect Card Driver for Linux]. The official name is very long, yes.
 +
 
 +
= Links =
 +
http://wwwu.uni-klu.ac.at/agebhard/HuaweiE220/<br>
 +
http://oozie.fm.interia.pl/pro/huawei-e220/<br>
 +
http://mybroadband.co.za/vb/showthread.php?t=21726

Revision as of 08:21, 1 January 2008


Introduction

Marketed by various telecommunications companies in several countries, the E220 is a 3.5G HSDPA USB modem used mainly for wireless Internet access via mobile telephony networks. Technically it is a modem, USB and (due to the CDFS format) CD-ROM device. With a kernel version older than 2.6.20, getting Linux to recognize the device as a modem and accessing its functions requires a workaround.

"Linux kernel versions prior to 2.6.20 have some problems with it, as the SCSI CDROM fakevolume with drivers for Microsoft systems gets automounted by usbstorage.ko module, preventing serial device /dev/ttyUSB0 from working properly."

However, as support for it was added in 2.6.20 via modules usb-storage and usbserial, getting it to work is as simple as plugging it in and dialling up (the above statement is of no concern to us as we can load and unload modules at will, it was probably meant for pre-packaged GNU and Linux distributions). In fact, using the modem under Linux proves to be more reliable as there are no uncalled-for disconnections. This is probably due to the fact that we are communicating directly with the modem, whereas in Windows or Mac OS X drivers are installed on first run (that is what the storage portion is for) and connection is achieved through a thick software layer every time, leaving room for possible interferences and conflicts.

Plugging In

Archers do not use old stuff, let alone use old kernels. That is, however, not enough reason to explain why in some cases the modem still needs the workaround. Thus, you have to see for yourself if you are one of the lucky ones. It almost seems as if the "support" in kernels > 2.6.20 is a myth, although I may be entirely incorrect (maybe it is how Arch developers package the vanilla kernels in which case we have only phrakkkture and gang to thank).

The magic (trick) lies in the kernel modules; unloading, blacklisting, reloading and loading things will get it done.

Quick Start

After hooking up to the USB port (some say an upright position is best; let it hang over the edge of the desk), check to make sure it is detected.

$ cat /proc/bus/usb/devices

You should see Huawei somewhere there. If not, you are on your own. The usb-storage and/or usbserial modules must be loaded, whether manually or by HAL is up to you and/or your system.

# modprobe usb-storage
# modprobe usbserial
$ sleep 6 # the modem may take a while to initialize
$ ls /dev/ttyUSB*

You should see three renditions of ttyUSB. If not, we will get to that later. This is a "Quick Start" after all, no? The ports:

  • ttyUSB0 - Modem
  • ttyUSB1 - USB?
  • ttyUSB2 - Nothing

Now you need a dialler. Most convenient of all would be wvdial, so install it. You should have ppp already, if not just pull them both in.

# pacman -Sy wvdial ppp

Most SIM and data services provided together with the device do not require special settings and work with similar configuration to get connected. They are almost "Plug n' Play", a special trait of Linux. Edit /etc/wvdial.conf and use something like the following:

[Dialer hsdpa]
Phone = *99***16#
Username = 65
Password = user123
Stupid Mode = 1
Dial Command = ATDT
Modem = /dev/ttyUSB0
Baud = 460800
Init2 = ATZ
Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = Analog Modem

There is an example here by a "Linux Guru". Then load the PPP module.

# modprobe ppp-generic

You can now connect immediately, but probably only as root, which is not a disadvantage.

# wvdial hsdpa

Slow Start

So why then? Well, for some reason those of us on newer kernels still have to ride the old ways. In some cases, all that is needed to be done is to remove the usb-storage module first, then load usbserial with the device IDs. The first cat command on this page will have that information, while lsusb is an alternative. Anyhow, the IDs are the same for almost all E220s, so you can copy wholesale.

# modprobe -r usb-storage
# modprobe usbserial vendor=0x12d1 product=0x1003

When you cannot salvage anything from this either, you have to go Gentoo and compile something. Do not worry, it is only a script and we do things like this almost everyday, albeit in bash.

$ mkdir ~/huawei-e220 && cd ~/huawei-e220
$ wget http://www.kanoistika.sk/bobovsky/archiv/umts/huaweiAktBbo.c
$ gcc -o e220 *.c
# ./e220

This gets around the kernel to recognize the modem functionalities of the device. You can now carry on and connect using the above methods. If you had to follow this step, you will always need the script unless you set udev rules and such (package link below). So move it to a global PATH.

$ cd ~/huawei-e220
# mv e220 /usr/bin/e220

Now it is easier.

Extras

Note: It seems some people get it to work using ttyUSB1, which should not be the case, but rest assured that at least on recent kernels and systems ttyUSB0 is the correct port to dial with.

Port Testing

To check if the device is functioning alright on a particular serial port, there is a program for probing serial devices.

# pacman -S minicom

Now run it.

# minicom -s

Change the serial port to /dev/ttyUSB1 and exit from the page, this will open the main program. When it initializes the modem, issue the command AT. The answer should be OK, which means the modem is working well on that port.

Packages

For an "automated" workaround, there is huawei-e220 in AUR.

For Vodafone brands of this device, you can use vodafone-mccd which is the Vodafone Mobile Connect Card Driver for Linux. The official name is very long, yes.

Links

http://wwwu.uni-klu.ac.at/agebhard/HuaweiE220/
http://oozie.fm.interia.pl/pro/huawei-e220/
http://mybroadband.co.za/vb/showthread.php?t=21726