X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fusb.c;h=c4d5567399de247148e4fd7a289e575686073129;hb=adcb9951f8a52852e65f99d45083a3e6b9a1981a;hp=02510caed4edca7293410788156521d35be81e61;hpb=e4ce146fefe7cfd475b9d8fdec1101b188b746db;p=libsigrok.git diff --git a/src/usb.c b/src/usb.c index 02510cae..c4d55673 100644 --- a/src/usb.c +++ b/src/usb.c @@ -28,7 +28,7 @@ #include "libsigrok-internal.h" /* SR_CONF_CONN takes one of these: */ -#define CONN_USB_VIDPID "^([0-9a-z]{4})\\.([0-9a-z]{4})$" +#define CONN_USB_VIDPID "^([0-9a-fA-F]{4})\\.([0-9a-fA-F]{4})$" #define CONN_USB_BUSADDR "^(\\d+)\\.(\\d+)$" #define LOG_PREFIX "usb" @@ -134,10 +134,6 @@ static gboolean usb_source_dispatch(GSource *source, pollfd = g_ptr_array_index(usource->pollfds, i); revents |= pollfd->revents; } - if (revents != 0) - sr_spew("%s: revents 0x%.2X", __func__, revents); - else - sr_spew("%s: timed out", __func__); if (!callback) { sr_err("Callback not set, cannot dispatch event."); @@ -397,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; } @@ -514,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; +}