X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fusb.c;h=96df219fd734fa168d6347bfeeddad0d2e331f03;hb=47bbc4b531eb8e491115b0dbcb686d23c78235fb;hp=f53119a6aab181b08c2faf338777da9db9db0712;hpb=176d785d33a28a1bb24f2ee483595ec54f7b52b6;p=libsigrok.git diff --git a/src/usb.c b/src/usb.c index f53119a6..96df219f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -329,8 +329,7 @@ SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn) if ((mstr = g_match_info_fetch(match, 2))) pid = strtoul(mstr, NULL, 16); g_free(mstr); - sr_dbg("Trying to find USB device with VID:PID = %04x:%04x.", - vid, pid); + /* Trying to find USB device via VID:PID. */ } else { g_match_info_unref(match); g_regex_unref(reg); @@ -343,8 +342,7 @@ SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn) if ((mstr = g_match_info_fetch(match, 2))) addr = strtoul(mstr, NULL, 10); g_free(mstr); - sr_dbg("Trying to find USB device with bus.address = " - "%d.%d.", bus, addr); + /* Trying to find USB device via bus.address. */ } } g_match_info_unref(match); @@ -392,7 +390,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)); + /* No log message for #devices found (caller will log that). */ return devices; } @@ -510,3 +508,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; +}