udev-usb-add-change 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. ##
  3. ## This script is invoked by udev rules whenever USB device appears or
  4. ## changes. This happens in usbvm domain (or dom0 if USB controller
  5. ## drivers are in dom0). The script records information about available
  6. ## USB devices into XS directory, making it available to qvm-usb tool
  7. ## running in dom0.
  8. ##
  9. # FIXME: Ignore USB hubs and other wierd devices (see also in udev-usb-remove).
  10. [ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0
  11. [ "$DEVTYPE" != "usb_device" ] && exit 0
  12. # xenstore doesn't allow dot in key name
  13. XSNAME=`basename ${DEVPATH} | tr . _`
  14. # FIXME: For some devices (my Cherry keyboard) ID_SERIAL does not
  15. # contain proper human-readable name, should find better method to
  16. # build devide description.
  17. #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);"`
  18. DESC="${ID_VENDOR_ID}:${ID_MODEL_ID} ${ID_SERIAL}"
  19. VERSION=`cat /sys/$DEVPATH/version`
  20. if [ "${VERSION}" = " 1.00" -o "${VERSION}" = " 1.10" ] ; then
  21. VERSION=1
  22. elif [ "${VERSION}" = " 2.00" ] ; then
  23. VERSION=2
  24. else
  25. # FIXME: silently ignoring devices with unexpected USB version
  26. exit 0
  27. fi
  28. XS_KEY="qubes-usb-devices/$XSNAME"
  29. xenstore-write "$XS_KEY/desc" "$DESC"
  30. xenstore-write "$XS_KEY/usb-ver" "$VERSION"
  31. # Make sure PVUSB backend driver is loaded.
  32. /sbin/modprobe xen-usbback 2> /dev/null || /sbin/modprobe usbbk