Guest User

rebind.sh

a guest
Dec 12th, 2010
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.17 KB | None | 0 0
  1. #!/bin/bash
  2. #set -x
  3.  
  4. VID=6993
  5. PIDS="b001 b700"
  6. DRIVER="yealink"
  7. IFCLASS="03"     # hexadecimal: 03..HID
  8.  
  9. if uname -r | grep -q '^2\.6\.28\>' ; then
  10.   echo "WARNING: Your kernel version may suffer from kernel bug #12301, which"
  11.   echo "prevents using the device after unbinding it! The bug is due to be"
  12.   echo "fixed in kernel version 2.6.29."
  13.   echo
  14. fi
  15.  
  16. function attach() {
  17.   local id dr
  18.   id="$1"
  19.   dr="$2"
  20.   [ -f /sys/bus/usb/drivers/$dr/bind ] && \
  21.     echo -n "$d" > /sys/bus/usb/drivers/$dr/bind
  22.   if [ $? = 0 ]
  23.   then
  24.     echo "  successfully reattached driver '$dr'"
  25.   else
  26.     echo "  could not reattach device to driver '$dr'"
  27.   fi
  28. }
  29.  
  30. find /sys/devices -name idVendor | \
  31.   while read v
  32.   do
  33.     if [ "`cat $v`" = "$VID" ]
  34.     then
  35.       base="${v%/*}"
  36.       pid="`cat $base/idProduct`"
  37.       #if "$pid" = "$PID"    # use this for just one PID
  38.       if echo $PIDS | grep -q "\\<$pid\\>"
  39.       then
  40.         cd "$base"
  41.         devname=`cat product | sed 's/ *$//'`
  42.         echo "Found device '$devname' at $base"
  43.         find . -name bInterfaceClass | \
  44.           while read c
  45.           do
  46.             if [ "`cat $c`" = "$IFCLASS" ]
  47.             then
  48.               # this is the interface we are looking for
  49.               d="${c%/*}"
  50.               cd "$d"
  51.               d="`pwd`"
  52.               d="${d##*/}"
  53.               echo "  found interface at $d"
  54.               if [ -e "driver/unbind" ]
  55.               then
  56.                 drvr=`readlink driver`
  57.                 drvr=${drvr##*/}
  58.                 if [ "$drvr" = "$DRIVER" ]
  59.                 then
  60.                   echo "  driver '$DRIVER' already attached - nothing to do"
  61.                 else
  62.                   echo -n "$d" > driver/unbind
  63.                   if [ $? = 0 ]
  64.                   then
  65.                     echo "  successfully detached driver '$drvr'"
  66.                     sleep 1
  67.                     attach "$d" "$DRIVER"
  68.                   else
  69.                     echo "  could not detach driver '$drvr'"
  70.                   fi
  71.                 fi
  72.               else
  73.                 attach "$d" "$DRIVER"
  74.               fi
  75.             fi
  76.           done
  77.       fi
  78.     fi
  79.   done
Advertisement
Add Comment
Please, Sign In to add comment