This is an automated email from Gerrit. Scott Tsai ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/2343
-- gerrit commit befed0aa741478c60369462ec2632d777a2ef0cc Author: Scott Tsai <[email protected]> Date: Mon Oct 13 13:25:52 2014 -0700 libusb1_common: fix reading non-ASCII characters in device serial numbers libusb1's libusb_get_string_descriptor_ascii() replaces non ASCII characters with '?' (0x3f). Non ASCII characters in USB serials are found in the wild on ST-Link/V2 dongles and STM32 Discovery boards, which have serials like "Q\377j\006I\207PS(H\t\207". This patch uses libusb_get_string_descritor() to read the non ASCII characters properly. Change-Id: I5fd7b626342dba5811fe81ab581ec22584a5e6d5 Signed-off-by: Scott Tsai <[email protected]> diff --git a/src/jtag/drivers/libusb1_common.c b/src/jtag/drivers/libusb1_common.c index bda91ff..b8a95ef 100644 --- a/src/jtag/drivers/libusb1_common.c +++ b/src/jtag/drivers/libusb1_common.c @@ -44,22 +44,50 @@ static bool jtag_libusb_match(struct libusb_device_descriptor *dev_desc, static bool string_descriptor_equal(libusb_device_handle *device, uint8_t str_index, const char *string) { - int retval; + int retval, i; bool matched; + char desc_string_utf16[256*2+1]; /* Max size of string descriptor */ char desc_string[256+1]; /* Max size of string descriptor */ + uint16_t langid; if (str_index == 0) return false; - retval = libusb_get_string_descriptor_ascii(device, str_index, - (unsigned char *)desc_string, sizeof(desc_string)-1); - if (retval < 0) { - LOG_ERROR("libusb_get_string_descriptor_ascii() failed with %d", retval); + /* Asking for the zero'th index is special - it returns a string + descriptor that contains all the language IDs supported by the device. + Typically there aren't many - often only one. The language IDs are 16 + bit numbers, and they start at the third byte in the descriptor. See + USB 2.0 specification section 9.6.7 for more information. + Note from libusb 1.0 sources (descriptor.c) */ + + retval = libusb_get_descriptor(device, LIBUSB_DT_STRING, str_index, + (unsigned char*)desc_string, sizeof(desc_string)-1); + if (retval < 4) { + LOG_ERROR("libusb_get_descriptor() failed with %d", retval); + return false; + } + + langid = desc_string[2] | (desc_string[3] << 8); + + /* libusb1's libusb_get_string_descriptor_ascii() replaces non ASCII + * characters with '?' (0x3f). So use libusb_get_string_descritor() instead. + * Non ASCII characters in USB serials are found in the wild on + * ST-Link and STM32 Discovery boards, which have serials like + * "Q\377j\006I\207PS(H\t\207". + * */ + + memset(desc_string, 0, sizeof(desc_string_utf16)); + retval = libusb_get_string_descriptor(device, str_index, langid, + (unsigned char*)desc_string_utf16, sizeof(desc_string)-1); + if (retval < 3) { + LOG_ERROR("libusb_get_string_descriptor() failed with %d", retval); return false; } /* Null terminate descriptor string in case it needs to be logged. */ - desc_string[sizeof(desc_string)-1] = '\0'; + memset(desc_string, 0, sizeof(desc_string)); + for (i=0; i<(int)sizeof(desc_string); i++) + desc_string[i] = desc_string_utf16[2 + i*2]; matched = strncmp(string, desc_string, sizeof(desc_string)) == 0; if (!matched) -- ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
