~vcs-imports/ipfire/ipfire-2.x

« back to all changes in this revision

Viewing changes to src/rc.d/rc.alcatelusb

  • Committer: ipfire
  • Date: 2006-02-15 21:15:54 UTC
  • Revision ID: git-v1:cd1a2927226c734d96478e12bb768256fb64a06a


git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# $Id: rc.alcatelusb,v 1.7.2.12 2005/07/07 20:11:57 franck78 Exp $
 
4
#
 
5
 
 
6
eval $(/usr/local/bin/readhash /var/ipcop/ppp/settings)
 
7
 
 
8
# Debugging. Comment it out to stop logging
 
9
DEBUG="yes"
 
10
msg() {
 
11
        if [ "z$DEBUG" != "z" ] ; then
 
12
                /usr/bin/logger -t red "Speedtouch USB: $*"
 
13
        fi
 
14
        /bin/echo "$*"
 
15
}
 
16
 
 
17
function wait_for_iface()
 
18
{
 
19
        msg "Waiting for interface: $1"
 
20
        COUNTER=10
 
21
        FLREADY=0
 
22
        TIMES=1
 
23
        while [ $TIMES -le $COUNTER ]; do
 
24
                /sbin/ifconfig $1> /dev/null 2>&1
 
25
                if [ $? -eq 0 ]; then
 
26
                        FLREADY=1
 
27
                        break
 
28
                fi
 
29
                /bin/sleep 1
 
30
                TIMES=$(expr $TIMES + 1)
 
31
        done
 
32
        if [ "$FLREADY" -eq 0 ]; then
 
33
                msg "Interface not found: $1"
 
34
                exit 1
 
35
        fi
 
36
}
 
37
 
 
38
# See how we were called.
 
39
case "$1" in
 
40
  start)
 
41
        if [ ! -f "/proc/bus/usb/devices" ]; then
 
42
                msg "No USB enabled"
 
43
                exit 1
 
44
        fi
 
45
        speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`
 
46
        case "$speedtouch" in
 
47
                '')
 
48
                        msg "No Speedtouch found"
 
49
                        exit 1
 
50
                ;;
 
51
                '0.00' | '0.01' | '2.00')
 
52
                        modem='v0123'
 
53
                        # Speedtouch 530 aka Rev 3.00 does not work actually
 
54
                ;;
 
55
                '4.00')
 
56
                        modem='v4_b'
 
57
                ;;
 
58
                  *)
 
59
                        msg "Unknown version or unsupported model Rev $speedtouch"
 
60
                        exit 1
 
61
                ;;
 
62
        esac
 
63
        if ( ! /bin/ps -ef | /bin/grep -q [m]odem_run ); then
 
64
                rm -f /var/run/pppoa3-modem*.pid
 
65
                msg "Uploading firmware to modem"
 
66
                /usr/sbin/modem_run -v 1 -t 90 -n 4 -f /var/ipcop/alcatelusb/firmware.$modem.bin
 
67
 
 
68
                # Check if Firmware uploaded ok. Reset USB if Failed
 
69
                if [ $? -ne 0 ]; then
 
70
                        msg "Firmware upload failed: Retrying"
 
71
                        /usr/local/bin/resetusb
 
72
                        /usr/sbin/modem_run -v 1 -t 90 -n 4 -f /var/ipcop/alcatelusb/firmware.$modem.bin
 
73
                        if [ $? -ne 0 ]; then
 
74
                                msg "Firmware upload failed: Exiting"
 
75
                                exit 1
 
76
                        fi
 
77
                fi      
 
78
        fi
 
79
 
 
80
        # Alcatel USB PPPoE Mode
 
81
        if [ "$PROTOCOL" = "RFC1483" ]; then
 
82
                iface="tap0"
 
83
                /sbin/modprobe tun
 
84
                /usr/sbin/pppoa3 -b -c -m 1 -vpi $VPI -vci $VCI
 
85
                wait_for_iface $iface
 
86
                /sbin/ifconfig $iface up
 
87
                exit $?
 
88
        fi
 
89
        exit 0
 
90
        ;;
 
91
  stop)
 
92
        msg "stop"
 
93
        /bin/killall pppoa3 2>/dev/null
 
94
        /bin/sleep 1
 
95
        /sbin/modprobe -r tun
 
96
        ;;
 
97
  cleanup)
 
98
        msg "driver cleanup and USB Bus reset"
 
99
        /usr/local/bin/resetusb
 
100
        ;;
 
101
  *)
 
102
        /bin/echo "Usage: $0 {start|stop|cleanup}"
 
103
        exit 1
 
104
        ;;
 
105
esac
 
106
 
 
107
exit 0