Huawei usb 3g modem reset – linux

A small memo to manage usb reset for Huawei usb 3g modem:

Get a persistant udev device:
Edit: /etc/udev/rules.d/99-usb-modem.rules

SUBSYSTEM=="tty", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003", SYMLINK+="usbmodem"

Reset the usb bus (quite rude but it is the only way i found to refresh the stack succesfully each time) and issue a ‘AT’ reset.


# Reset USB bus
for i in $(ls /sys/bus/pci/drivers/xhci_hcd/|grep :); do
 echo "$i" >/sys/bus/pci/drivers/xhci_hcd/unbind
 sleep 10
 echo "$i" >/sys/bus/pci/drivers/xhci_hcd/bind
sleep 10

# Reset modem
chat -t 1 -e "" '\pAT' OK AT+CFUN=1,1 '\pAT' OK >> /dev/usbmodem < /dev/usbmodem
sleep 20

Sleep timers are important.

I’m using huawei 3g modem for backup connections to my datacenters.
If the external network is detected down, the usb modem pops up, creates a ppp connection, and initiates a ssh forward service on a remote server (which owns a static IP on another network).

/usr/bin/ssh -o ServerAliveInterval=10 -o ServerAliveCountMax=2 \
        -o StrictHostKeyChecking=no -o ConnectTimeout=10 \
        -i <MY_SSH_KEY> \
        -C -g -R<MY_SSH_SERVICE_PORT>:localhost:22 \
        <LOGIN>@<HOST> sleep 3600;

Like this, i can access my network via a simple:


Leave a Reply

Your email address will not be published. Required fields are marked *