diff --git a/lib/usb.c b/lib/usb.c index 07475da..625c74f 100644 --- a/lib/usb.c +++ b/lib/usb.c @@ -26,6 +26,10 @@ usb_dev_handle *open_usb(uint16_t default_vendor, uint16_t default_product) { const struct usb_bus *bus; struct usb_device *dev; + usb_dev_handle *handle; +#ifdef DO_FULL_USB_BUREAUCRACY + int res; +#endif usb_init(); usb_find_busses(); @@ -39,7 +43,30 @@ usb_dev_handle *open_usb(uint16_t default_vendor, uint16_t default_product) if (dev->descriptor.idProduct != product ? product : default_product) continue; - return usb_open(dev); + handle = usb_open(dev); +#ifdef DO_FULL_USB_BUREAUCRACY + if (!handle) + return NULL; + res = usb_set_configuration(handle, 1); + if (res < 0) { + fprintf(stderr, "usb_set_configuration: %d\n", + res); + return NULL; + } + res = usb_claim_interface(handle, 0); + if (res < 0) { + fprintf(stderr, "usb_claim_interface: %d\n", + res); + return NULL; + } + res = usb_set_altinterface(handle, 0); + if (res < 0) { + fprintf(stderr, "usb_set_altinterface: %d\n", + res); + return NULL; + } +#endif + return handle; } return NULL; }