X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fusb.c;h=c4d5567399de247148e4fd7a289e575686073129;hb=e7eb29685cac9332f4137201a6759130e700165d;hp=35a3e80ed58cc7d340317b1aeea116ba4d1f2d83;hpb=039a2fd78a61ad8c6e9159be9ba06b605a456155;p=libsigrok.git diff --git a/src/usb.c b/src/usb.c index 35a3e80e..c4d55673 100644 --- a/src/usb.c +++ b/src/usb.c @@ -393,7 +393,7 @@ SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn) libusb_free_device_list(devlist, 1); sr_dbg("Found %d device(s).", g_slist_length(devices)); - + return devices; } @@ -510,3 +510,47 @@ SR_PRIV int usb_get_port_path(libusb_device *dev, char *path, int path_len) return SR_OK; } + +/** + * Check the USB configuration to determine if this device has a given + * manufacturer and product string. + * + * @return TRUE if the device's configuration profile strings + * configuration, FALSE otherwise. + */ +SR_PRIV gboolean usb_match_manuf_prod(libusb_device *dev, + const char *manufacturer, const char *product) +{ + struct libusb_device_descriptor des; + struct libusb_device_handle *hdl; + gboolean ret; + unsigned char strdesc[64]; + + hdl = NULL; + ret = FALSE; + while (!ret) { + /* Assume the FW has not been loaded, unless proven wrong. */ + libusb_get_device_descriptor(dev, &des); + + if (libusb_open(dev, &hdl) != 0) + break; + + if (libusb_get_string_descriptor_ascii(hdl, + des.iManufacturer, strdesc, sizeof(strdesc)) < 0) + break; + if (strcmp((const char *)strdesc, manufacturer)) + break; + + if (libusb_get_string_descriptor_ascii(hdl, + des.iProduct, strdesc, sizeof(strdesc)) < 0) + break; + if (strcmp((const char *)strdesc, product)) + break; + + ret = TRUE; + } + if (hdl) + libusb_close(hdl); + + return ret; +}