Ticket #3341: 01-huawei

File 01-huawei, 2.0 KB (added by pieterp@…, 10 years ago)

very hackish hotplug script (for /etc/hotplug.d/usb) to automatically bring up th 3G upon device insertion. includes kill of pppd when the device is unplugged, and initial swith of to modem mode.

Line 
1#!/bin/sh
2
3# Copyright (C) 2008 Pieter Palmers
4
5#logger "USB: $ACTION for product:$PRODUCT type:$TYPE interface:$INTERFACE device:$DEVICE"
6#set > "/tmp/log$$"
7
8case "$ACTION" in
9        add)
10        # reset if necessary
11        if [ "x$PRODUCT" = "x12d1/1003/0" ] && [ "x$TYPE" = "x0/0/0" ] && [ "x$INTERFACE" = "x8/6/80" ]; then
12            logger "resetting huawei e220 device"
13            /usr/bin/huaweiAktBbo
14        fi
15               
16        if [ "x$PRODUCT" = "x12d1/1003/0" ] && [ "x$TYPE" = "x0/0/0" ] && [ "x$INTERFACE" = "x255/255/255" ]; then
17            logger "detected USB serial device add"
18            # if all 3 tty devices are present, bring up 3G
19            if [ -c /dev/usb/tts/0 ] && [ -c /dev/usb/tts/0 ] && [ -c /dev/usb/tts/0 ]; then
20                    logger "$$ can bring up 3G"
21                    echo $$ > /tmp/bringing_up_3g
22                    sleep 1
23                    BRINGUP_PID=$(cat /tmp/bringing_up_3g)
24                    ONLINE=$(grep wan /var/state/network | grep up | cut -d" " -f 4)
25                    if [ "x$$" = "x$BRINGUP_PID" ] && [ ! "x$ONLINE" = "x'1'" ]; then
26                        logger "It is I ($$) that will bring up 3G"
27                        # give it some time to settle
28                        sleep 1
29                        echo 1 | /sbin/ifup wan
30                    else
31                        logger "=> ($BRINGUP_PID) will bring up 3G"
32                    fi
33            else
34                    logger "skip 3G since not enough TTY's"
35            fi
36        fi
37        ;;
38
39        remove)
40        if [ "x$PRODUCT" = "x12d1/1003/0" ] && [ "x$TYPE" = "x0/0/0" ] && [ "x$INTERFACE" = "x8/6/80" ]; then
41            logger "removed huawei e220 device"
42            ONLINE=$(grep wan /var/state/network | grep up | cut -d" " -f 4)
43            if [ "x$ONLINE" = "x'1'" ]; then
44              logger "link was up"
45            fi
46            # bring the link down
47            /sbin/ifdown wan
48            /usr/bin/killall pppd
49        fi
50
51        if [ "x$PRODUCT" = "x12d1/1003/0" ] && [ "x$TYPE" = "x0/0/0" ] && [ "x$INTERFACE" = "x255/255/255" ]; then
52            logger "detected USB serial device removal"
53        fi
54esac
55