#!/bin/bash # # $Id: rc.eciadsl,v 1.4.2.14 2005/07/28 16:47:43 gespinasse Exp $ # eval $(/usr/local/bin/readhash CONFIG_ROOT/ppp/settings) # Debugging. Comment it out to stop logging DEBUG="yes" msg() { if [ "z$DEBUG" != "z" ] ; then /usr/bin/logger -t red "ECI USB: $*" fi /bin/echo "$*" } # Function to wait for interface to become ready # Borrowed from eciadsl startmodem script 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 "CONFIG_ROOT/eciadsl/synch.bin" ]; then msg "Synch.bin not uploaded" exit 1 fi if [ ! -f "/proc/bus/usb/devices" ]; then msg "No USB enabled" exit 1 fi VID1="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 2)" PID1="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 3)" VID2="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 4)" PID2="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 5)" CHIP="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 6)" ALTS="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 7)" ALTP="$(/bin/grep "$MODEM " "/etc/eciadsl/modems.db" | /usr/bin/tr -s "\t" "|" | /usr/bin/cut -d '|' -f 8)" if [ "$CHIP" = '' ]; then msg "error in modems.db reading for $MODEM no CHIP found" exit 1 fi # Firmware if [ "$CHIP" = 'GS7070' ]; then if ( /bin/grep -q "^P: Vendor=$VID1 ProdID=$PID1" /proc/bus/usb/devices ); then /bin/rm -f /var/ipfire/red/eciadsl-synch-done /bin/sleep 2 msg "Loading Firmware for $MODEM" /usr/sbin/eciadsl-firmware 0x$VID1 0x$PID1 0x$VID2 0x$PID2 /etc/eciadsl/firmware00.bin RET=$? if [ "$RET" -ne "0" ]; then msg "$MODEM failed to load firmware, reason: $RET" exit 1 fi /bin/sleep 2 fi fi if ( ! /bin/grep -q "^P: Vendor=$VID2 ProdID=$PID2" /proc/bus/usb/devices ); then msg "$MODEM modem not found ready" exit 1 fi # Modem synch if [ ! -e "CONFIG_ROOT/red/eciadsl-synch-done" ]; then /usr/sbin/eciadsl-synch -alt $ALTS -mc $CHIP 0x$VID2 0x$PID2 CONFIG_ROOT/eciadsl/synch.bin RET=$? if [ "$RET" -ne "0" ]; then msg "$MODEM failed to get synchronization, reason:$RET" exit 1 else /bin/touch CONFIG_ROOT/red/eciadsl-synch-done fi fi if [ "$PROTOCOL" = "RFC1483" ]; then case "$ENCAP" in 0) ECIMODE="LLC_SNAP_RFC1483_BRIDGED_ETH_NO_FCS" ;; 1) ECIMODE="VCM_RFC_1483_BRIDGED_ETH" ;; 2) ECIMODE="LLC_RFC1483_ROUTED_IP" ;; 3) ECIMODE="VCM_RFC1483_ROUTED_IP" ;; *) msg "Unknown encapsulation: $ENCAP" exit 1 ;; esac # Start pppoeci if [ "$ENCAP" = "0" -o "$ENCAP" = "1" ]; then ECIIF="tap0" else ECIIF="tun0" fi /sbin/modprobe tun /usr/sbin/eciadsl-pppoeci -alt $ALTP -vpi $VPI -vci $VCI -vendor 0x$VID2 -product 0x$PID2 -mode $ECIMODE wait_for_iface $ECIIF /sbin/ifconfig $ECIIF up exit $? fi exit 0 ;; stop) msg "stop" # Avoid possibility of multiple 'rc.eciadsl start' as only one prog can claim interface at a time # and time for the full eci-load2 loop may be too long for the user to wait until to try once again RCECIADSLSTART=`/bin/ps ax | /bin/grep '[r]c.eciadsl start' | /usr/bin/cut -f1 -d ' '` [ "$RCECIADSLSTART" != '' ] && /bin/kill "$RCECIADSLSTART" # -KILL is necessary because pppoeci ignores sigint /bin/killall -KILL eciadsl-pppoeci eciadsl-firmware eciadsl-synch 2> /dev/null /bin/sleep 1 /sbin/modprobe -r tun ;; cleanup) msg "driver cleanup and USB Bus reset" /usr/local/bin/resetusb /bin/rm -f CONFIG_ROOT/red/eciadsl-synch-done ;; *) /bin/echo "Usage: $0 {start|stop|cleanup}" exit 1 ;; esac exit 0