#!/bin/bash #set -x VID=6993 PIDS="b001 b700" DRIVER="yealink" IFCLASS="03" # hexadecimal: 03..HID if uname -r | grep -q '^2\.6\.28\>' ; then echo "WARNING: Your kernel version may suffer from kernel bug #12301, which" echo "prevents using the device after unbinding it! The bug is due to be" echo "fixed in kernel version 2.6.29." echo fi function attach() { local id dr id="$1" dr="$2" [ -f /sys/bus/usb/drivers/$dr/bind ] && \ echo -n "$d" > /sys/bus/usb/drivers/$dr/bind if [ $? = 0 ] then echo " successfully reattached driver '$dr'" else echo " could not reattach device to driver '$dr'" fi } find /sys/devices -name idVendor | \ while read v do if [ "`cat $v`" = "$VID" ] then base="${v%/*}" pid="`cat $base/idProduct`" #if "$pid" = "$PID" # use this for just one PID if echo $PIDS | grep -q "\\<$pid\\>" then cd "$base" devname=`cat product | sed 's/ *$//'` echo "Found device '$devname' at $base" find . -name bInterfaceClass | \ while read c do if [ "`cat $c`" = "$IFCLASS" ] then # this is the interface we are looking for d="${c%/*}" cd "$d" d="`pwd`" d="${d##*/}" echo " found interface at $d" if [ -e "driver/unbind" ] then drvr=`readlink driver` drvr=${drvr##*/} if [ "$drvr" = "$DRIVER" ] then echo " driver '$DRIVER' already attached - nothing to do" else echo -n "$d" > driver/unbind if [ $? = 0 ] then echo " successfully detached driver '$drvr'" sleep 1 attach "$d" "$DRIVER" else echo " could not detach driver '$drvr'" fi fi else attach "$d" "$DRIVER" fi fi done fi fi done