Revision: 6321
          http://ipcop.svn.sourceforge.net/ipcop/?rev=6321&view=rev
Author:   owes
Date:     2012-02-05 18:13:39 +0000 (Sun, 05 Feb 2012)
Log Message:
-----------
Proper device detection

Modified Paths:
--------------
    ipcop/trunk/src/rc.d/rc.fritzdsl

Modified: ipcop/trunk/src/rc.d/rc.fritzdsl
===================================================================
--- ipcop/trunk/src/rc.d/rc.fritzdsl    2012-02-05 17:32:05 UTC (rev 6320)
+++ ipcop/trunk/src/rc.d/rc.fritzdsl    2012-02-05 18:13:39 UTC (rev 6321)
@@ -34,42 +34,72 @@
 }
 
 
-# TODO: find device IDs, /proc/pci is gone
+# Borrowed from Gentoo ebuild, detect fcdsl card
+# should work with 'Card DSL', 'Card DSL v2.0', 'Card DSL SL', 'Card DSL USB', 
'Card DSL SL USB', etc.
+FCDSL_MODULES=("fcdsl" "fcdsl2" "fcdslsl" "fcdslusb" "fcdslslusb" "fcdslusba" 
"fcdslusb2")
+FCDSL_NAMES=("AVM FRITZ!Card DSL" "AVM FRITZ!Card DSL v2.0"
+    "AVM FRITZ!Card DSL SL" "AVM FRITZ!Card DSL USB" "AVM FRITZ!Card DSL SL 
USB"
+    "AVM Fritz!Card DSL USB analog" "AVM Fritz!Card DSL USB v2.0")
+FCDSL_BUSTYPES=("pci" "pci" "pci" "usb" "usb" "usb" "usb")
+FCDSL_IDS=("1131:5402" "1244:2900" "1244:2700" "057c:2300" "057c:3500" 
"057c:3000" "057c:3600")
 
-
-# ID borrowed from Gentoo ebuild,
-# should work with 'Card DSL','Card DSL v2.0', 'Card DSL SL', 'Card DSL 
USB','Card DSL SL USB'
-# pcmcia card not compiled
-if ( /bin/grep "1244:2700" -q /proc/pci ); then
-    FCDSLMODEM='sl'
-elif ( /bin/grep "1244:2900" -q /proc/pci ); then
-    FCDSLMODEM='2'
-elif ( /bin/grep "1131:5402" -q /proc/pci ); then
-    FCDSLMODEM=''
-elif ( /bin/grep "Vendor=057c ProdID=2300" -q /proc/bus/usb/devices ); then
-    FCDSLMODEM='usb'
-elif ( /bin/grep "Vendor=057c ProdID=3500" -q /proc/bus/usb/devices ); then
-    FCDSLMODEM='slusb'
-else 
-    FCDSLMODEM='none'
+PCI_IDS=""
+USB_IDS=""
+if [ -d /sys/bus ]; then
+    if [ -d /sys/bus/pci/devices ]; then
+        cd /sys/bus/pci/devices
+        for PCI_DEVICE in *; do
+            vendor="$(< ${PCI_DEVICE}/vendor)"
+            device="$(< ${PCI_DEVICE}/device)"
+            PCI_IDS="${PCI_IDS}${vendor:2}:${device:2} "
+        done
+    fi
+# We do not currently support fcdsl USB!
+#    if [ -d /sys/bus/usb/devices ]; then
+#        cd /sys/bus/usb/devices
+#        for USB_DEVICE in [0-9]*; do
+#            if [ -f ${USB_DEVICE}/idVendor ]; then
+#                USB_IDS="${USB_IDS}$(< ${USB_DEVICE}/idVendor):$(< 
${USB_DEVICE}/idProduct) "
+#            fi
+#        done
+#    fi
 fi
 
+FCDSL_MODULE=""
+for ((CARD=0; CARD < ${#FCDSL_IDS[*]}; CARD++)); do
+    BUS_IDS=""
+    if [ "${FCDSL_BUSTYPES[CARD]}" == "pci" ]; then
+        BUS_IDS="${PCI_IDS}"
+    else
+        BUS_IDS="${USB_IDS}"
+    fi
+    for BUS_ID in ${BUS_IDS}; do
+        if [ "${BUS_ID}" == "${FCDSL_IDS[CARD]}" ]; then
+            FCDSL_FIRMWARE=${FCDSL_FIRMWARES[CARD]}
+            FCDSL_MODULE=${FCDSL_MODULES[CARD]}
+            msg "Found: ${FCDSL_NAMES[CARD]}, uses module: ${FCDSL_MODULE}"
+        fi
+    done
+done
+
+
 # See how we were called.
 case "$1" in
 start)
+    # TODO: really exit if already loaded? Maybe reload?
     if ( /bin/grep -q "fcdsl" /proc/modules >/dev/null ); then
         exit 0;
     fi
-    if [ "$FCDSLMODEM" = 'none' ]; then
-        msg "No supported modem found"
+    if [ "${FCDSL_MODULE}" == "" ]; then
+        msg "No AVM FRITZ!Card DSL found!"
         exit 1
     fi
-    if [ ! -f "/lib/modules/`/bin/uname -r`/extra/fcdsl$FCDSLMODEM.ko.gz" ]; 
then
+    if [ ! -f "/lib/modules/`/bin/uname -r`/extra/${FCDSL_MODULE}.ko.gz" ]; 
then
         msg "Driver not uploaded"
         exit 1
     else
         # should use drdsl and drdsl.ini for parameters autoconfiguration or 
use pppsetup.cgi?
-        /usr/sbin/capiinit -c "/etc/fcdsl/fcdsl$FCDSLMODEM.conf" start
+        /usr/sbin/capiinit -c "/etc/fcdsl/${FCDSL_MODULE}.conf" start
     fi
     ;;
 stop)
@@ -77,14 +107,8 @@
     ;;
 cleanup)
     msg "driver cleanup"
-    if [ "$FCDSLMODEM" = 'none' ]; then
-        FCDSLMODEM=''
-    fi
     /sbin/modprobe -r fcdslusb fcdslslusb
-    /usr/sbin/capiinit -c "/etc/fcdsl/fcdsl$FCDSLMODEM.conf" stop
-    if [ "$FCDSLMODEM" = 'slusb' -o "$FCDSLMODEM" = 'usb' ]; then
-        /usr/local/bin/resetusb
-    fi
+    /usr/sbin/capiinit -c "/etc/fcdsl/${FCDSL_MODULE}.conf" stop
     ;;
 *)
     /bin/echo "Usage: $0 {start|stop|cleanup}"

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to