xpp: set EC firmware according to PRI settings:
authorOron Peled <oron.peled@xorcom.com>
Tue, 27 May 2014 13:50:21 +0000 (09:50 -0400)
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>
Sun, 29 Jun 2014 13:34:17 +0000 (16:34 +0300)
* Read first from modern configuration files
  (/etc/dahdi/span-types.conf)
  - Support either exact label match or complete '*' match in the
    configuration file.

* Fallback to legacy /etc/dahdi/xpp.conf

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

xpp/xpp_fxloader

index 076f0ec..b5173a4 100644 (file)
@@ -68,6 +68,7 @@ FIRMWARE_DIR="${FIRMWARE_DIR:-/usr/share/dahdi}"
 ASTRIBANK_HEXLOAD=${ASTRIBANK_HEXLOAD:-/usr/sbin/astribank_hexload}
 ASTRIBANK_TOOL=${ASTRIBANK_TOOL:-/usr/sbin/astribank_tool}
 XPP_CONFIG="${XPP_CONFIG:-/etc/dahdi/xpp.conf}"
+SPAN_TYPES_CONFIG="${SPAN_TYPES_CONFIG:-/etc/dahdi/span-types.conf}"
 XPP_UDEV_SLEEP_TIME="${XPP_UDEV_SLEEP_TIME:-15}"
 
 USB_RECOV="${USB_RECOV:-USB_RECOV.hex}"
@@ -270,6 +271,13 @@ usb_firmware_all_devices() {
        wait_renumeration $numdevs 'e4e4/11[3456]1/*' "usb_firmware_all_devices"
 }
 
+filter_span_types() {
+       #sed -n -e 's/#.*//' -e 's/[ \t]*$//' -e 's/^[ \t]*//' -e 's/^\*[ \t]\+\*://p' /etc/dahdi/span-types.conf
+       sed < "$SPAN_TYPES_CONFIG" 2>/dev/null \
+               -e 's/#.*//'    \
+               -e 's/[ \t]*$//'
+}
+
 load_fw_device() {
        dev="$1"
        fw="$2"
@@ -290,8 +298,35 @@ load_fw_device() {
                        3)      law="-A";;
                        4)
                                pri_protocol=''
-                               if [ -r "$XPP_CONFIG" ]; then
+                               dev_short=`echo "$dev" | sed -e 's,.*/usb/*,,' -e 's,/,:,'`
+                               # Try modern configuration
+                               if [ -r "$SPAN_TYPES_CONFIG" ]; then
+                                       # Try exact match by label
+                                       label=`lsusb -s "$dev_short" -v 2>/dev/null | awk '$1 == "iSerial" && $2 == 3 { print $3 }'`
+                                       if [ "$label" != '' ]; then
+                                               label="usb:$label"
+                                               debug "ECHO: checking device $dev_short [$label]"
+                                               pri_protocol=`filter_span_types | sed -n "s/^${label}[ \t]\+[0-9*]://p"`
+                                               if [ "$pri_protocol" != '' ]; then
+                                                       debug "ECHO: device $dev_short [$label] will be set to $pri_protocol"
+                                               fi
+                                       else
+                                               debug "ECHO: Device $dev_short without a label"
+                                       fi
+                                       # Fallback to wildcard match
+                                       if [ "$pri_protocol" = '' ]; then
+                                               pri_protocol=`filter_span_types | sed -n 's/^\*[ \t]\+\*://p'`
+                                               if [ "$pri_protocol" != '' ]; then
+                                                       debug "ECHO: device $dev_short will be set to $pri_protocol (wildcard match)"
+                                               fi
+                                       fi
+                               fi
+                               # Fallback to legacy xpp.conf
+                               if [ "$pri_protocol" = '' -a -r "$XPP_CONFIG" ]; then
                                        pri_protocol=`awk '/^pri_protocol/ {print $2}' $XPP_CONFIG`
+                                       if [ "$pri_protocol" != '' ]; then
+                                               debug "ECHO: device $dev_short will be set to $pri_protocol (legacy xpp.conf setting)"
+                                       fi
                                fi
                                # "E1" or empty (implied E1) means aLaw
                                if [ "$pri_protocol" != 'T1' ]; then