]> git.ipfire.org Git - ipfire-2.x.git/blob - src/rc.d/rc.eciadsl
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[ipfire-2.x.git] / src / rc.d / rc.eciadsl
1 #!/bin/bash
2 #
3 # $Id: rc.eciadsl,v 1.4.2.14 2005/07/28 16:47:43 gespinasse Exp $
4 #
5
6 eval $(/usr/local/bin/readhash CONFIG_ROOT/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 "ECI USB: $*"
13 fi
14 /bin/echo "$*"
15 }
16
17 # Function to wait for interface to become ready
18 # Borrowed from eciadsl startmodem script
19 function wait_for_iface()
20 {
21 msg "Waiting for interface: $1"
22 COUNTER=10
23 FLREADY=0
24 TIMES=1
25 while [ $TIMES -le $COUNTER ]; do
26 /sbin/ifconfig $1> /dev/null 2>&1
27 if [ $? -eq 0 ]; then
28 FLREADY=1
29 break
30 fi
31 /bin/sleep 1
32 TIMES=$(expr $TIMES + 1)
33 done
34 if [ "$FLREADY" -eq 0 ]; then
35 msg "Interface not found: $1"
36 exit 1
37 fi
38 }
39
40 # See how we were called.
41 case "$1" in
42 start)
43 if [ ! -f "CONFIG_ROOT/eciadsl/synch.bin" ]; then
44 msg "Synch.bin not uploaded"
45 exit 1
46 fi
47
48 if [ ! -f "/proc/bus/usb/devices" ]; then
49 msg "No USB enabled"
50 exit 1
51 fi
52
53 VID1="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 2)"
54 PID1="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 3)"
55 VID2="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 4)"
56 PID2="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 5)"
57 CHIP="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 6)"
58 ALTS="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 7)"
59 ALTP="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 8)"
60
61 if [ "$CHIP" = '' ]; then
62 msg "error in modems.db reading for $MODEM no CHIP found"
63 exit 1
64 fi
65
66 # Firmware
67 if [ "$CHIP" = 'GS7070' ]; then
68 if ( /bin/grep -q "^P: Vendor=$VID1 ProdID=$PID1" /proc/bus/usb/devices ); then
69 /bin/rm -f /var/ipcop/red/eciadsl-synch-done
70 /bin/sleep 2
71 msg "Loading Firmware for $MODEM"
72 /usr/sbin/eciadsl-firmware 0x$VID1 0x$PID1 0x$VID2 0x$PID2 /etc/eciadsl/firmware00.bin
73 RET=$?
74 if [ "$RET" -ne "0" ]; then
75 msg "$MODEM failed to load firmware, reason: $RET"
76 exit 1
77 fi
78 /bin/sleep 2
79 fi
80 fi
81
82 if ( ! /bin/grep -q "^P: Vendor=$VID2 ProdID=$PID2" /proc/bus/usb/devices ); then
83 msg "$MODEM modem not found ready"
84 exit 1
85 fi
86
87 # Modem synch
88 if [ ! -e "CONFIG_ROOT/red/eciadsl-synch-done" ]; then
89 /usr/sbin/eciadsl-synch -alt $ALTS -mc $CHIP 0x$VID2 0x$PID2 CONFIG_ROOT/eciadsl/synch.bin
90 RET=$?
91 if [ "$RET" -ne "0" ]; then
92 msg "$MODEM failed to get synchronization, reason:$RET"
93 exit 1
94 else
95 /bin/touch CONFIG_ROOT/red/eciadsl-synch-done
96 fi
97 fi
98
99 if [ "$PROTOCOL" = "RFC1483" ]; then
100 case "$ENCAP" in
101 0) ECIMODE="LLC_SNAP_RFC1483_BRIDGED_ETH_NO_FCS"
102 ;;
103 1) ECIMODE="VCM_RFC_1483_BRIDGED_ETH"
104 ;;
105 2) ECIMODE="LLC_RFC1483_ROUTED_IP"
106 ;;
107 3) ECIMODE="VCM_RFC1483_ROUTED_IP"
108 ;;
109 *) msg "Unknown encapsulation: $ENCAP"
110 exit 1
111 ;;
112 esac
113
114 # Start pppoeci
115 if [ "$ENCAP" = "0" -o "$ENCAP" = "1" ]; then
116 ECIIF="tap0"
117 else
118 ECIIF="tun0"
119 fi
120 /sbin/modprobe tun
121 /usr/sbin/eciadsl-pppoeci -alt $ALTP -vpi $VPI -vci $VCI -vendor 0x$VID2 -product 0x$PID2 -mode $ECIMODE
122 wait_for_iface $ECIIF
123 /sbin/ifconfig $ECIIF up
124 exit $?
125 fi
126 exit 0
127 ;;
128 stop)
129 msg "stop"
130 # Avoid possibility of multiple 'rc.eciadsl start' as only one prog can claim interface at a time
131 # and time for the full eci-load2 loop may be too long for the user to wait until to try once again
132 RCECIADSLSTART=`/bin/ps ax | /bin/grep '[r]c.eciadsl start' | /usr/bin/cut -f1 -d ' '`
133 [ "$RCECIADSLSTART" != '' ] && /bin/kill "$RCECIADSLSTART"
134
135 # -KILL is necessary because pppoeci ignores sigint
136 /bin/killall -KILL eciadsl-pppoeci eciadsl-firmware eciadsl-synch 2> /dev/null
137 /bin/sleep 1
138 /sbin/modprobe -r tun
139 ;;
140 cleanup)
141 msg "driver cleanup and USB Bus reset"
142 /usr/local/bin/resetusb
143 /bin/rm -f CONFIG_ROOT/red/eciadsl-synch-done
144 ;;
145 *)
146 /bin/echo "Usage: $0 {start|stop|cleanup}"
147 exit 1
148 ;;
149 esac
150
151 exit 0