usb-device: Check for USB product string if device match, remove detected_ prefix
This commit is contained in:
1 parent
d9e6d47f1b
commit
f059663164
2 files changed
+34
-6
No files matched your search
+32
-4
@@ -69,7 +69,7 @@ static void usb_flash_device_info_print(const struct usb_flash_device * dev) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device * dev) {
|
static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device * dev, char * product, size_t size) {
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char buf2[1024];
|
char buf2[1024];
|
||||||
@@ -82,6 +82,9 @@ static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device *
|
|||||||
PRINTF_LINE("USB device product string: %s", buf[0] ? buf : "(not detected)");
|
PRINTF_LINE("USB device product string: %s", buf[0] ? buf : "(not detected)");
|
||||||
PRINTF_END();
|
PRINTF_END();
|
||||||
|
|
||||||
|
if ( product && buf[0] )
|
||||||
|
strncpy(product, buf, size);
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
memset(buf2, 0, sizeof(buf2));
|
memset(buf2, 0, sizeof(buf2));
|
||||||
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, buf, sizeof(buf));
|
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, buf, sizeof(buf));
|
||||||
@@ -106,6 +109,7 @@ static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device *
|
|||||||
static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
|
static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
char product[1024];
|
||||||
struct usb_device_info * ret = NULL;
|
struct usb_device_info * ret = NULL;
|
||||||
|
|
||||||
for ( i = 0; usb_devices[i].vendor; ++i ) {
|
for ( i = 0; usb_devices[i].vendor; ++i ) {
|
||||||
@@ -125,7 +129,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_descriptor_info_print(udev, dev);
|
usb_descriptor_info_print(udev, dev, product, sizeof(product));
|
||||||
|
|
||||||
#if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
|
#if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
|
||||||
PRINTF_LINE("Detaching kernel from USB interface...");
|
PRINTF_LINE("Detaching kernel from USB interface...");
|
||||||
@@ -165,8 +169,32 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->detected_device = DEVICE_UNKNOWN;
|
if ( strstr(product, "N900") )
|
||||||
ret->detected_hwrev = -1;
|
ret->device = DEVICE_RX_51;
|
||||||
|
else
|
||||||
|
ret->device = DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
/* TODO: Autodetect more devices */
|
||||||
|
|
||||||
|
if ( device_to_string(ret->device) )
|
||||||
|
PRINTF_LINE("Detected USB device: %s", device_to_string(ret->device));
|
||||||
|
else
|
||||||
|
PRINTF_LINE("Detected USB device: (not detected)");
|
||||||
|
PRINTF_END();
|
||||||
|
|
||||||
|
if ( ret->device ) {
|
||||||
|
enum device * device;
|
||||||
|
for ( device = usb_devices[i].devices; *device; ++device )
|
||||||
|
if ( *device == ret->device )
|
||||||
|
break;
|
||||||
|
if ( ! *device ) {
|
||||||
|
ERROR("Device mishmash");
|
||||||
|
usb_close(udev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->hwrev = -1;
|
||||||
ret->flash_device = &usb_devices[i];
|
ret->flash_device = &usb_devices[i];
|
||||||
ret->udev = udev;
|
ret->udev = udev;
|
||||||
break;
|
break;
|
||||||
|
|||||||
+2
-2
@@ -43,8 +43,8 @@ struct usb_flash_device {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct usb_device_info {
|
struct usb_device_info {
|
||||||
enum device detected_device;
|
enum device device;
|
||||||
int16_t detected_hwrev;
|
int16_t hwrev;
|
||||||
const struct usb_flash_device * flash_device;
|
const struct usb_flash_device * flash_device;
|
||||||
usb_dev_handle * udev;
|
usb_dev_handle * udev;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user