diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usb.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -27,6 +27,7 @@ int usb_open(struct context *context) { struct libusb_device_handle *handle; + int configuration; int rc; if (context == NULL) @@ -34,7 +35,7 @@ int usb_open(struct context *context) rc = libusb_init(NULL); if (rc < 0) { - fprintf(stderr, "Initializing libusb failed\n"); + fprintf(stderr, "Initializing USB failed\n"); return -1; } @@ -47,12 +48,20 @@ int usb_open(struct context *context) libusb_detach_kernel_driver(handle, USB_INTERFACE); - rc = libusb_set_configuration(handle, USB_CONFIGURATION); + rc = libusb_get_configuration(handle, &configuration); if (rc < 0) { - fprintf(stderr, "Setting USB configuration failed\n"); + fprintf(stderr, "Getting USB configuration failed\n"); goto error; } + if (configuration != USB_CONFIGURATION) { + rc = libusb_set_configuration(handle, USB_CONFIGURATION); + if (rc < 0) { + fprintf(stderr, "Setting USB configuration failed\n"); + goto error; + } + } + rc = libusb_claim_interface(handle, USB_INTERFACE); if (rc < 0) { fprintf(stderr, "Claiming USB interface failed\n"); |