Huawei E1552 Modem with Debian Linux

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:

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:

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😉