2013-03-20 05:27:32 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
##
|
|
|
|
## 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.
|
|
|
|
##
|
|
|
|
|
|
|
|
# FIXME: Ignore USB hubs and other wierd devices (see also in udev-usb-remove).
|
|
|
|
[ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0
|
|
|
|
[ "$DEVTYPE" != "usb_device" ] && exit 0
|
|
|
|
|
2013-06-07 03:21:41 +00:00
|
|
|
# qubesdb doesn't allow dot in key name
|
2013-03-20 05:27:32 +00:00
|
|
|
XSNAME=`basename ${DEVPATH} | tr . _`
|
|
|
|
|
|
|
|
# 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}"
|
|
|
|
|
2016-07-08 08:40:12 +00:00
|
|
|
VERSION=`cat /sys/$DEVPATH/version | tr -d ' '|cut -f 1 -d .`
|
2013-03-20 05:27:32 +00:00
|
|
|
|
2016-06-01 12:03:01 +00:00
|
|
|
# ignore usbip-connected devices, as most likely already passed through from
|
|
|
|
# another VM
|
|
|
|
if [ "`echo $DEVPATH | cut -d / -f 2-4`" = "devices/platform/vhci_hcd" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-06-07 03:21:41 +00:00
|
|
|
QDB_KEY="/qubes-usb-devices/$XSNAME"
|
2013-03-20 05:27:32 +00:00
|
|
|
|
2013-06-07 03:21:41 +00:00
|
|
|
qubesdb-write "$QDB_KEY/desc" "$DESC"
|
|
|
|
qubesdb-write "$QDB_KEY/usb-ver" "$VERSION"
|
|
|
|
qubesdb-write /qubes-usb-devices ''
|
2013-03-20 05:27:32 +00:00
|
|
|
|
|
|
|
# Make sure PVUSB backend driver is loaded.
|
2016-05-24 23:56:42 +00:00
|
|
|
/sbin/modprobe xen-usbback 2> /dev/null || true
|