2012-10-07 19:35:46 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2012-10-07 21:12:36 +02:00
|
|
|
##
|
|
|
|
## This script is invoked by udev rules whenever USB device appears or
|
|
|
|
## changes. This happens in usbvm domain (or dom0 if USB controller
|
|
|
|
## drivers are in dom0). The script records information about available
|
|
|
|
## USB devices into XS directory, making it available to qvm-usb tool
|
|
|
|
## running in dom0.
|
|
|
|
##
|
|
|
|
|
2012-10-09 23:33:17 +02:00
|
|
|
# FIXME: Ignore USB hubs and other wierd devices (see also in usb_remove).
|
2012-10-23 05:44:37 +02:00
|
|
|
[ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0
|
2012-10-08 00:43:01 +02:00
|
|
|
[ "$DEVTYPE" != "usb_device" ] && exit 0
|
2012-10-07 19:35:46 +02:00
|
|
|
|
2012-10-23 05:42:39 +02:00
|
|
|
# xenstore doesn't allow dot in key name
|
2012-10-28 02:27:06 +01:00
|
|
|
XSNAME=`basename ${DEVPATH} | tr . _`
|
2012-10-24 22:02:55 +02:00
|
|
|
|
2012-10-07 23:16:04 +02:00
|
|
|
# FIXME: For some devices (my Cherry keyboard) ID_SERIAL does not
|
|
|
|
# contain proper human-readable name, should find better method to
|
|
|
|
# build devide description.
|
|
|
|
#DESC=`python -c "dev='%d-%d' % (int('${BUSNUM}'.lstrip('0')), (int('${DEVNUM}'.lstrip('0'))-1)); from xen.util import vusb_util; print vusb_util.get_usbdevice_info(dev);"`
|
|
|
|
DESC="${ID_VENDOR_ID}:${ID_MODEL_ID} ${ID_SERIAL}"
|
2012-10-24 22:00:27 +02:00
|
|
|
|
2012-10-28 02:24:17 +01:00
|
|
|
VERSION=`cat /sys/$DEVPATH/version`
|
2012-10-24 22:00:27 +02:00
|
|
|
if [ "${VERSION}" = " 1.00" -o "${VERSION}" = " 1.10" ] ; then
|
|
|
|
VERSION=1
|
|
|
|
elif [ "${VERSION}" = " 2.00" ] ; then
|
|
|
|
VERSION=2
|
|
|
|
else
|
|
|
|
# FIXME: silently ignoring devices with unexpected USB version
|
2012-10-24 22:05:57 +02:00
|
|
|
exit 0
|
2012-10-24 22:00:27 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
XS_KEY="qubes-usb-devices/$XSNAME"
|
2012-10-07 19:35:46 +02:00
|
|
|
|
|
|
|
xenstore-write "$XS_KEY/desc" "$DESC"
|
2012-10-26 23:09:36 +02:00
|
|
|
xenstore-write "$XS_KEY/usb-ver" "$VERSION"
|
2012-10-07 21:06:40 +02:00
|
|
|
|
2012-10-07 21:12:36 +02:00
|
|
|
# Make sure PVUSB backend driver is loaded.
|
2012-10-07 21:06:40 +02:00
|
|
|
/sbin/modprobe xen-usbback 2> /dev/null || /sbin/modprobe usbbk
|