get_modem_alternate_device 2.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. #Barry Kauler 2010 LGPL
  3. #Find another candidate for USB modem, for device in argument 1.
  4. DEVM=$1
  5. DEVMALT=""
  6. if [ "`echo "$DEVM" | grep -E 'ttyACM[0-9]|ttyHS[0-9]|ttyUSB[0-9]|rfcomm[0-9]'`" != "" ];then
  7. INTERRUPTLIST="`grep -H -s 'Interrupt' /sys/bus/usb/devices/*-*:*.*/ep_??/type | cut -f 1-6 -d /`"
  8. DEVLISTACM="`ls -1 -d /sys/bus/usb/devices/*-*:*.*/tty/tty????* 2>/dev/null | sed 's/ /\n/g' | grep -F "$INTERRUPTLIST" | cut -f 8 -d / | sed 's/\(tty...\)\([0-9]$\)/\10\2/' | sort | sed 's/\(tty...\)\(0\)/\1/'`"
  9. DEVLISTHS="`grep -l -s 'Modem' /sys/class/tty/ttyHS?*/hsotype | cut -f 5 -d / | sort -u`"
  10. DEVLISTUSB="`ls -1 -d /sys/bus/usb/devices/*-*:*.*/tty????* 2>/dev/null | sed 's/ /\n/g' | grep -F "$INTERRUPTLIST" | cut -f 7 -d / | sed 's/\(tty...\)\([0-9]$\)/\10\2/' | sort | sed 's/\(tty...\)\(0\)/\1/'`"
  11. DEVMLIST="`grep -s 'converter now attached' /var/log/messages | grep ' modem ' | grep -o 'ttyUSB[0-9][0-9]*' | sort -u`"
  12. [ "$DEVMLIST" != "" ] && DEVLISTUSB="`echo "$DEVLISTUSB" | grep -F "$DEVMLIST"`"
  13. #Prepend any bluetooth modems to list...
  14. DUNRFCLIST=""
  15. if which rfcomm >/dev/null && which sdptool >/dev/null;then
  16. DUNPATTERN="`sdptool search DUN | sed -n -e '/^Searching/h' -e '/^ Channel:/{H;x}' -e 's/Searching for DUN on //' -e 's/ ...\n Channel://p'`"
  17. [ "$DUNPATTERN" != "" ] \
  18. && DUNRFCLIST="`rfcomm -a | grep ' connected' | sed -e 's/ channel//' | grep -F "$DUNPATTERN" | cut -f 1 -d :`"
  19. echo "Modemtest/probe: DUNPATTERN: $DUNPATTERN DUNRFCLIST: $DUNRFCLIST" >> /tmp/udevtrace-modem.log #DEBUG
  20. fi
  21. DEVLISTALL="`echo "$DUNRFCLIST $DEVLISTACM $DEVLISTHS $DEVLISTUSB" | tr ' ' '\n' | sed /^$/d`"
  22. SEDSCRIPT1="/${DEVM}/"'{n;p;q}'
  23. DEVMALT="`echo "$DEVLISTALL" | sed -n "$SEDSCRIPT1"`"
  24. [ "$DEVMALT" = "" ] \
  25. && SEDSCRIPT2="/${DEVM}/"'!{p;q}' \
  26. && DEVMALT="`echo "$DEVLISTALL" | sed -n "$SEDSCRIPT2"`"
  27. echo -e "Modemtest/probe: DEVM: $DEVM DEVMALT: $DEVMALT DEVLISTALL:\n$DEVLISTALL" >> /tmp/udevtrace-modem.log #DEBUG
  28. fi
  29. echo "$DEVMALT"
  30. exit 0
  31. ###END###