Huawei E160

3G USB sticks for networking are used to provide mobile internet access. My ISP gave me a model manufactured by HUAWEI, with a product code "HUAWEI Mobile Connect, Model: E160E HSDPA USB stick". The instructions below work with this stick (E160) in the network elisa.fi but other ISPs and similar HUAWEI sticks can probably connected by similar methods.

These instructions were written in January 2010. I'm using kernel 2.6.31-gentoo-r6 with baselayout-2.0.1 and OpenRC 0.4.3-r3.

=Choose your connection method= I know of three different methods how to connect this stick:
 * 1) NetworkManager
 * 2) wvdial
 * 3) /etc/conf.d/net script

NetworkManager method works well in GNOME, if you are happy to connect after you log in to the GNOME desktop. wvdial can be used to connect from the command-line. The /etc/conf.d/net script is supposed to do everything "automatically" the Gentoo way. If you already use NetworkManager, I recommend using method 1. Otherwise, for me method 3 works best.

=Requirements for all methods=

Kernel options
Enable the following kernel options for USB networking and for PPP protocol (NOTE: Could we indicate weather this is as build-in or module?):

 Device Drivers > Network Device Support > PPP support Device Drivers > Network Device Support > PPP support > PPP support for async serial ports Device Drivers > Network Device Support > PPP support > PPP support for sync tty ports Device Drivers > Network Device Support > PPP support > PPP Deflate compression Device Drivers > Network Device Support > PPP support > PPP BSD-Compression Device Drivers > USB support > USB Modem (CDC ACM) support Device Drivers > USB support > USB serial converter support Device Drivers > USB support > USB serial converter support > USB Generic serial driver Device Drivers > USB support > USB serial converter support > USB driver for GSM and CDMA modems 

(Recompile the kernel and reboot, if anything wasn't enabled yet.)

Packages
Emerge the following packages:

net-dialup/ppp (for all methods) net-misc/networkmanager (only for method 1) net-dialup/wvdial (only for method 2)

Necessary information
Plug in the device and wait a while. Check that the node /dev/ttyUSB0 appears. If your device node is different, you have to modify the instructions below accordingly.

If you are already using ppp0</tt> for something, find the next free number and use that in the instructions below, for example ppp2</tt>

Information from your ISP
You need the following information from your ISP:
 * Telephone number (for me it is *99#</tt>).
 * PIN code for the SIM card in the USB stick (in the example below, 1234).
 * Name of access point. In the example below, "IP","internet"</tt>

You may have to modify the instructions below so that they work with your ISP.

=Configuring the setup files= This process depends on which method you want to use.

Method 1: NetworkManager
For me this worked basically out of the box. Log in to your desktop and connect the USB stick. After a while, NetworkManager shows the device as available when you right-click on the NetworkManager icon. Now you need to change a few options: PIN, dial number, and DNS servers.

If you don't need a PIN, leave the PIN space blank, otherwise enter your PIN. The dial number for elisa.fi</tt> is *99#</tt> - ask your ISP if you don't know which one you have to use. You may need to change the inputs on "internet"</tt> and "IP"</tt> as well - again ask your ISP for the correct values. Also, for some reason the DNS servers that are autodetected by NetworkManager are very slow. It is recommended to provide specific DNS servers in the option for DNS. For example, use server addresses from OpenDNS.

You can check the box to automatically connect this connection whenever you plug in the stick.

Method 2: wvdial
wvdial</tt> requires a config script in /etc/wvdial.conf</tt>. If this file does not exist, create it. Then edit it and add the following lines.

 [Dialer pin] Modem = /dev/ttyUSB0 Baud = 460800 Init1 =ATZ Init2 =AT+Cpin=1234 Dial Attempts = 1 [Dialer connect] Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 +FCLASS=0 Init3 = AT+CGDCONT=1,"IP","internet" Abort on No Dialtone = off Password = irrelevant Check Def Route = on Phone = *99# Modem Type = Analog Modem Stupid Mode = 1 SetVolume = 0 Baud = 460800 Dial Command = ATDT Dial Attempts = 3 Modem = /dev/ttyUSB0 ISDN = 0 Username = irrelevant </tt>
 * 1) Replace 1234 with your PIN in the next line

Save the file. Make it root-readable only by, if you do not want other users to read your PIN code.

To connect, plug in the USB stick and wait a while. Open a terminal window. Then, if your SIM card requires a PIN, issue the command. This sends the pin. Next, issue the command. The connection stays connected until you close this command with CTRL+C</tt>.

Method 3: /etc/conf.d/net</tt> script
For this method, you add the information about the USB 3G stick to the script in /etc/conf.d/net</tt>. If the file does not exist, you can create it. Open this file and add the following (somewhere, say at the bottom of the file). Make sure to change the phone number, PIN code and where it says IP</tt> and internet</tt>, if your ISP requires different information.

<tt> dns_servers_ppp0=" '208.67.222.222' '208.67.220.220' " config_ppp0="ppp" link_ppp0="/dev/ttyUSB0" plugins_ppp0="" username_ppp0="nobody" password_ppp0="nothing" pppd_ppp0="lock defaultroute noipdefault noauth usepeerdns 460800" phone_number_ppp0="*99#" chat_ppp0=" 	'ABORT' 'BUSY' 	'ABORT' 'ERROR' 	'ABORT' 'NO ANSWER' 	'ABORT' 'NO CARRIER' 	'ABORT' 'NO DIALTONE' 	'ABORT' 'Invalid Login' 	'ABORT' 'Login incorrect' 	'TIMEOUT' '10' 	 'ATZ' 	'OK' 'AT+CPIN?' 	'READY-AT+CPIN=1234\r\n\d\d\d\d\d-OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' 	'OK' 'AT+CGDCONT=1,\\\"IP\\\",\\\"internet\\\"' 	'OK' 'ATDT\T' 	'CONNECT'  	'~--' '' " </tt>
 * 1) DNS servers line is only needed if your default servers are slow
 * 2) These servers below are from OpenDNS

If you do not need a PIN code, then delete the first line that contain <tt>CPIN</tt> and change the <tt>READY-AT+CPIN...</tt> phrase below it to <tt>OK</tt>.

Save the file. Next, create a symlink as follows.

You can now start and stop the USB stick with  and.

If you want to avoid typing the  commands and want to autostart the connection whenever the stick is plugged in, you have to tell the <tt>udev</tt> daemon that this USB stick should trigger <tt>net.ppp0</tt>. To achieve this, edit the file <tt>/etc/udev/rules.d/10-local.rules</tt> (or create a new file if it does not exist yet). Add the following lines to the file:

<tt> KERNEL=="ttyUSB0", ACTION=="add|change", RUN+="/usr/bin/rc-config start net.ppp0" KERNEL=="ttyUSB0", ACTION=="remove", RUN+="/usr/bin/rc-config stop net.ppp0" </tt>

Save the file. These changes will take effect when the <tt>udev</tt> daemon is restarted. You can do this manually by, but I recommend that you reboot instead, because many programs rely on a running <tt>udev</tt>.

=Things that could be improved=
 * Method 3 sometimes doesn't autoconnect the stick if it was plugged in when the computer is switched on. Just unplug the stick and plug it again.
 * Method 1 never autoconnects the stick if it was plugged in when you log in to the desktop. Just unplug the stick and plug it again.
 * Method 3 is slower compared to the other methods.
 * Method 3 exposes the PIN code in the <tt>/etc/conf.d/net</tt> file, which is readable by all users.
 * The "USB memory stick" function of the device does not work on my machine. Maybe I need to enable other drivers for that.

=Notes=
 * The device requires that the PIN is sent the first time the connection is attempted. If you send the PIN twice (e.g. the connection was lost and you reconnect), the device gives an ERROR in the chat part. Therefore, I did not list  in the chat part of method 3.
 * Meaning of the lights on the device
 * No lights on: The device is not connected to USB.
 * Green light flashing twice: Device is powered up but has not detected a network in the air. This may indicate that you need to enter your PIN.
 * Green light flashing once: Found only 2G networks, not connected to them.
 * Green constant light: Device is connected to the network, but the connection is very slow (2G).
 * Blue flashing light: 3G networks are around but the stick has not established connection.
 * Blue constant light: Device is connected to a 3G network.
 * If you cannot get it to work on your machine, look for debugging information in <tt>/var/log/syslog</tt> and <tt>/var/log/daemon.log</tt>

=Hardware information= ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem