Let’s assume that you need to install a multi-purpose firewall/server for your customer, but their ISP of choice is just too lazy to install their cabling to customer’s premises. Let’s also add that all you are left with is a Huawei E1552 Modem for HSPA/3G mobile packet data with a data plan SIM card. If so – here’s how I put it to use for persistent Internet uplink (this time with Debian squeeze) until the semi-decent ISP is ready.
Device
The E1552 is a member of Huawei packet modems family, which identify themselves differently on an USB bus, depending on circumstances. In an unprepared system one of these looks like:
# lsusb|grep 12d1 Bus 001 Device 013: ID 12d1:1446 Huawei Technologies Co., Ltd. E1552 (HSPA modem)
The kernel initializes it as USB storage. While it’s a neat feature to provide drivers for Windows world, Linux kernel could handle the device natively. The answer is that the device needs to have its mode switched. Luckily there is a piece software targeted at situations like this one: usb-modeswitch (or usb_modeswitch as the binary is named).
Luckily there’s a package for Debian squeeze, so just install it your favourite way, along with ppp tools:
# {apt-get,aptitude} install usb-modeswitch ppp wvdial
The package will install necessary udev rules, so the mode switching will happen automatically when the device is plugged in. Here’s an excerpt from logs:
Feb 28 14:55:24 pulp kernel: [862122.830661] usb 1-1.3: new high speed USB device using ehci_hcd and address 9 Feb 28 14:55:24 pulp kernel: [862122.925138] usb 1-1.3: New USB device found, idVendor=12d1, idProduct=1446 Feb 28 14:55:24 pulp kernel: [862122.925143] usb 1-1.3: New USB device strings: Mfr=3, Product=2, SerialNumber=0 Feb 28 14:55:24 pulp kernel: [862122.925147] usb 1-1.3: Product: HUAWEI Mobile Feb 28 14:55:24 pulp kernel: [862122.925149] usb 1-1.3: Manufacturer: HUAWEI Technology Feb 28 14:55:24 pulp kernel: [862122.925256] usb 1-1.3: configuration #1 chosen from 1 choice Feb 28 14:55:24 pulp kernel: [862122.927343] scsi31 : SCSI emulation for USB Mass Storage devices Feb 28 14:55:24 pulp kernel: [862122.927864] scsi32 : SCSI emulation for USB Mass Storage devices Feb 28 14:55:25 pulp usb_modeswitch: switching 12d1:1446 (HUAWEI Technology: HUAWEI Mobile) Feb 28 14:55:25 pulp kernel: [862123.655230] usb 1-1.3: USB disconnect, address 9 Feb 28 14:55:29 pulp kernel: [862127.438488] usb 1-1.3: new high speed USB device using ehci_hcd and address 10 Feb 28 14:55:29 pulp kernel: [862127.533042] usb 1-1.3: New USB device found, id Vendor=12d1, idProduct=1436 Feb 28 14:55:29 pulp kernel: [862127.533047] usb 1-1.3: New USB device strings: Mfr=4, Product=3, SerialNumber=0 Feb 28 14:55:29 pulp kernel: [862127.533051] usb 1-1.3: Product: HUAWEI Mobile Feb 28 14:55:29 pulp kernel: [862127.533054] usb 1-1.3: Manufacturer: HUAWEI Tec hnology Feb 28 14:55:29 pulp kernel: [862127.533146] usb 1-1.3: configuration #1 chosen from 1 choice Feb 28 14:55:29 pulp kernel: [862127.535986] option 1-1.3:1.0: GSM modem (1-port ) converter detected Feb 28 14:55:29 pulp kernel: [862127.536104] usb 1-1.3: GSM modem (1-port) conve rter now attached to ttyUSB1 Feb 28 14:55:29 pulp kernel: [862127.536694] option 1-1.3:1.3: GSM modem (1-port) converter detected Feb 28 14:55:29 pulp kernel: [862127.536783] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB2 Feb 28 14:55:29 pulp kernel: [862127.537015] option 1-1.3:1.4: GSM modem (1-port) converter detected Feb 28 14:55:29 pulp kernel: [862127.537110] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB3 Feb 28 14:55:29 pulp kernel: [862127.537609] scsi38 : SCSI emulation for USB Mass Storage devices Feb 28 14:55:29 pulp kernel: [862127.538238] scsi39 : SCSI emulation for USB Mass Storage devices Feb 28 14:55:34 pulp kernel: [862132.537641] scsi 38:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2 Feb 28 14:55:34 pulp kernel: [862132.539771] scsi 39:0:0:0: Direct-Access HUAWEI SD Storage 2.31 PQ: 0 ANSI: 2 Feb 28 14:55:34 pulp kernel: [862132.545634] sr1: scsi-1 drive Feb 28 14:55:34 pulp kernel: [862132.547349] sr 38:0:0:0: Attached scsi generic sg5 type 5 Feb 28 14:55:34 pulp kernel: [862132.548166] sd 39:0:0:0: Attached scsi generic sg6 type 0 Feb 28 14:55:34 pulp kernel: [862132.551390] sd 39:0:0:0: [sde] Attached SCSI removable disk
Aside from attaching as a storage it also provided /dev/ttyUSB{1,2,3} this time (on this system there’s also a /dev/ttyUSB0 provided by a different device for other purposes).
These serial devices are modems. Or at least the first one is. Various documentation on the web seems to vary on that subject, but I tried the first device and it works.
PPP
It is advisable to put these in /etc/ppp/options:
asyncmap 0 auth crtscts lock hide-password modem lcp-echo-interval 30 lcp-echo-failure 4 ipcp-max-failure 1000000000 noipx persist
Here’s an /etc/wvdial.conf for reference (works with Play P4 in Poland), using a /dev/serial/by-id modem path:
[Dialer Defaults] Phone = *99# Username = "blank" Password = "blank" Stupid Mode = 1 Carrier Check = No SetVolume = 0 Dial Command = ATDT FlowControl = NOFLOW [Dialer Defaults] Modem = /dev/serial/by-id/usb-HUAWEI_Technology_HUAWEI_Mobile-if00-port0 Baud = 460800 Init2 = ATZ Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 ISDN = 0 Modem Type = Analog Modem Init5 = AT+CGDCONT=1,"IP","internet"
To have it started at boot, remember add:
auto ppp0 iface ppp0 inet wvdial
to your /etc/network/interfaces file.
Caveats
This setup however has it’s issues and currently requires manual intervention at times. Fortunately this is not business critical in my case.
If anything breaks and a manual unplug-plug of the modem is done, it might be safe to have a watchdog cron job run every 1 minute to see if ppp0 is up, and do an ifdown/ifup dance if it’s not.
If you reboot the system remotely over this link with this setup, you will shoot yourself in the knee. The modem will be detected by Debian’s initramfs as a USB storage device, while it initializes storage for mounting rootfs. Unfortunately it will stay this way, and host system’s udev will not trigger usb_modeswitch. Manual unplug-plug cycle solves that.
I have played around and experimented with powering down the USB host controller where the device resides, but did not test it on that live system. Your mileage may vary, as USB power control has been deprecated in recent kernels. A PC-controlled electrical switchbox may help, but it’s just too “hackish” – get a decent modem or a better ISP, or…
There’s a more elegant option – hack the initramfs image so that it either does not initialize USB storage (a simple removal of usb-storage.ko could suffice, not tested), or put usb-modeswitch in it, along with udev rules or a manual invocation in the init scripts before switch root happens. You probably should build usb_modeswitch statically linked yourself to avoid libusb requirement (see ldd‘s output)
Next time when I’m on-site there I will test the initramfs approach and probably even share the results 😉
Good luck!
0 Responses to “Huawei E1552 Modem with Debian Linux”