+/* Returns true if the string descriptor indexed by str_index in device matches string */
+static bool string_descriptor_equal(usb_dev_handle *device, uint8_t str_index,
+ const char *string)
+{
+ int retval;
+ bool matched;
+ char desc_string[256+1]; /* Max size of string descriptor */
+
+ if (str_index == 0)
+ return false;
+
+ retval = usb_get_string_simple(device, str_index,
+ desc_string, sizeof(desc_string)-1);
+ if (retval < 0) {
+ LOG_ERROR("usb_get_string_simple() failed with %d", retval);
+ return false;
+ }
+
+ /* Null terminate descriptor string in case it needs to be logged. */
+ desc_string[sizeof(desc_string)-1] = '\0';
+
+ matched = strncmp(string, desc_string, sizeof(desc_string)) == 0;
+ if (!matched)
+ LOG_DEBUG("Device serial number '%s' doesn't match requested serial '%s'",
+ desc_string, string);
+ return matched;
+}
+