]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/rc.d/rc.alcatelusb
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[people/pmueller/ipfire-2.x.git] / src / rc.d / rc.alcatelusb
diff --git a/src/rc.d/rc.alcatelusb b/src/rc.d/rc.alcatelusb
new file mode 100644 (file)
index 0000000..b19e049
--- /dev/null
@@ -0,0 +1,107 @@
+#!/bin/bash
+#
+# $Id: rc.alcatelusb,v 1.7.2.12 2005/07/07 20:11:57 franck78 Exp $
+#
+
+eval $(/usr/local/bin/readhash /var/ipcop/ppp/settings)
+
+# Debugging. Comment it out to stop logging
+DEBUG="yes"
+msg() {
+       if [ "z$DEBUG" != "z" ] ; then
+               /usr/bin/logger -t red "Speedtouch USB: $*"
+       fi
+       /bin/echo "$*"
+}
+
+function wait_for_iface()
+{
+       msg "Waiting for interface: $1"
+       COUNTER=10
+       FLREADY=0
+       TIMES=1
+       while [ $TIMES -le $COUNTER ]; do
+               /sbin/ifconfig $1> /dev/null 2>&1
+               if [ $? -eq 0 ]; then
+                       FLREADY=1
+                       break
+               fi
+               /bin/sleep 1
+               TIMES=$(expr $TIMES + 1)
+       done
+       if [ "$FLREADY" -eq 0 ]; then
+               msg "Interface not found: $1"
+               exit 1
+       fi
+}
+
+# See how we were called.
+case "$1" in
+  start)
+       if [ ! -f "/proc/bus/usb/devices" ]; then
+               msg "No USB enabled"
+               exit 1
+       fi
+       speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`
+       case "$speedtouch" in
+               '')
+                       msg "No Speedtouch found"
+                       exit 1
+               ;;
+               '0.00' | '0.01' | '2.00')
+                       modem='v0123'
+                       # Speedtouch 530 aka Rev 3.00 does not work actually
+               ;;
+               '4.00')
+                       modem='v4_b'
+               ;;
+                 *)
+                       msg "Unknown version or unsupported model Rev $speedtouch"
+                       exit 1
+               ;;
+       esac
+       if ( ! /bin/ps -ef | /bin/grep -q [m]odem_run ); then
+               rm -f /var/run/pppoa3-modem*.pid
+               msg "Uploading firmware to modem"
+               /usr/sbin/modem_run -v 1 -t 90 -n 4 -f /var/ipcop/alcatelusb/firmware.$modem.bin
+
+               # Check if Firmware uploaded ok. Reset USB if Failed
+               if [ $? -ne 0 ]; then
+                       msg "Firmware upload failed: Retrying"
+                       /usr/local/bin/resetusb
+                       /usr/sbin/modem_run -v 1 -t 90 -n 4 -f /var/ipcop/alcatelusb/firmware.$modem.bin
+                       if [ $? -ne 0 ]; then
+                               msg "Firmware upload failed: Exiting"
+                               exit 1
+                       fi
+               fi      
+       fi
+
+       # Alcatel USB PPPoE Mode
+       if [ "$PROTOCOL" = "RFC1483" ]; then
+               iface="tap0"
+               /sbin/modprobe tun
+               /usr/sbin/pppoa3 -b -c -m 1 -vpi $VPI -vci $VCI
+               wait_for_iface $iface
+               /sbin/ifconfig $iface up
+               exit $?
+       fi
+       exit 0
+       ;;
+  stop)
+       msg "stop"
+       /bin/killall pppoa3 2>/dev/null
+       /bin/sleep 1
+       /sbin/modprobe -r tun
+       ;;
+  cleanup)
+       msg "driver cleanup and USB Bus reset"
+       /usr/local/bin/resetusb
+       ;;
+  *)
+       /bin/echo "Usage: $0 {start|stop|cleanup}"
+       exit 1
+       ;;
+esac
+
+exit 0