From bc4aeefab5c80308ef96ea33e3085c72094b622b Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Tue, 18 Nov 2014 23:51:04 +0100 Subject: usb-device: Do not claim USB interface in raw disk mode --- src/usb-device.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/usb-device.c') diff --git a/src/usb-device.c b/src/usb-device.c index 0ef55b4..1f9b403 100644 --- a/src/usb-device.c +++ b/src/usb-device.c @@ -42,9 +42,9 @@ static struct usb_flash_device usb_devices[] = { { 0x0421, 0x0105, 2, 1, -1, FLASH_NOLO, { DEVICE_SU_18, DEVICE_RX_44, DEVICE_RX_48, DEVICE_RX_51, 0 } }, { 0x0421, 0x0106, 0, -1, -1, FLASH_COLD, { DEVICE_RX_51, 0 } }, - { 0x0421, 0x01c7, 0, -1, -1, FLASH_DISK, { DEVICE_RX_51, 0 } }, + { 0x0421, 0x01c7, -1, -1, -1, FLASH_DISK, { DEVICE_RX_51, 0 } }, { 0x0421, 0x01c8, 1, 1, -1, FLASH_MKII, { DEVICE_RX_51, 0 } }, - { 0x0421, 0x0431, 0, -1, -1, FLASH_DISK, { DEVICE_SU_18, DEVICE_RX_34, 0 } }, + { 0x0421, 0x0431, -1, -1, -1, FLASH_DISK, { DEVICE_SU_18, DEVICE_RX_34, 0 } }, { 0x0421, 0x3f00, 2, 1, -1, FLASH_NOLO, { DEVICE_RX_34, 0 } }, }; @@ -90,6 +90,9 @@ static void usb_reattach_kernel_driver(usb_dev_handle * udev, int interface) { .data = NULL, }; + if ( interface < 0 ) + return; + usb_release_interface(udev, interface); ioctl(*((int *)udev), _IOWR('U', 18, command), &command); #endif @@ -159,18 +162,22 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { usb_descriptor_info_print(udev, dev, product, sizeof(product)); + if ( usb_devices[i].interface >= 0 ) { + #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP - PRINTF_LINE("Detaching kernel from USB interface..."); - usb_detach_kernel_driver_np(udev, usb_devices[i].interface); + PRINTF_LINE("Detaching kernel from USB interface..."); + usb_detach_kernel_driver_np(udev, usb_devices[i].interface); #endif - PRINTF_LINE("Claiming USB interface..."); - if ( usb_claim_interface(udev, usb_devices[i].interface) < 0 ) { - PRINTF_ERROR("usb_claim_interface failed"); - fprintf(stderr, "\n"); - usb_reattach_kernel_driver(udev, usb_devices[i].interface); - usb_close(udev); - return NULL; + PRINTF_LINE("Claiming USB interface..."); + if ( usb_claim_interface(udev, usb_devices[i].interface) < 0 ) { + PRINTF_ERROR("usb_claim_interface failed"); + fprintf(stderr, "\n"); + usb_reattach_kernel_driver(udev, usb_devices[i].interface); + usb_close(udev); + return NULL; + } + } if ( usb_devices[i].alternate >= 0 ) { -- cgit v1.2.3