diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2017-12-26 16:37:22 -0800 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2017-12-26 16:37:22 -0800 |
commit | d8c1f7caa9f00496097037adc266bcdfbe866bda (patch) | |
tree | 37e392f32430e564675c0bc1a84149cf6ce57cd1 /examples | |
parent | ba86d27dca584db96378936a4d54c87c7b0bbfba (diff) | |
download | libusb-d8c1f7caa9f00496097037adc266bcdfbe866bda.tar.gz |
Examples: Improvements to xusb's support for Microsoft OS descriptors
As noted in issue #269, the current xusb implementation does not handle
Microsoft OS descriptors from devices whose vendor code is greater than
0x7F. This commit addresses this limitation by using
libusb_get_string_descriptor() instead of the ASCII variant and parsing
the descriptor separately. Note that this issue was addressed in PR #276,
but that approach was too cryptic to read.
Closes #269, Closes #276
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/xusb.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/examples/xusb.c b/examples/xusb.c index 565f5aa..1489bfc 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -96,6 +96,16 @@ static int perr(char const *format, ...) #define BOMS_RESET 0xFF #define BOMS_GET_MAX_LUN 0xFE +// Microsoft OS Descriptor +#define MS_OS_DESC_STRING_INDEX 0xEE +#define MS_OS_DESC_STRING_LENGTH 0x12 +#define MS_OS_DESC_VENDOR_CODE_OFFSET 0x10 +static const uint8_t ms_os_desc_string[] = { + MS_OS_DESC_STRING_LENGTH, + LIBUSB_DT_STRING, + 'M', 0, 'S', 0, 'F', 0, 'T', 0, '1', 0, '0', 0, '0', 0, +}; + // Section 5.1: Command Block Wrapper (CBW) struct command_block_wrapper { uint8_t dCBWSignature[4]; @@ -923,17 +933,16 @@ static int test_device(uint16_t vid, uint16_t pid) if (string_index[i] == 0) { continue; } - if (libusb_get_string_descriptor_ascii(handle, string_index[i], (unsigned char*)string, 128) >= 0) { + if (libusb_get_string_descriptor_ascii(handle, string_index[i], (unsigned char*)string, sizeof(string)) > 0) { printf(" String (0x%02X): \"%s\"\n", string_index[i], string); } } // Read the OS String Descriptor - if (libusb_get_string_descriptor_ascii(handle, 0xEE, (unsigned char*)string, 128) >= 0) { - printf(" String (0x%02X): \"%s\"\n", 0xEE, string); + r = libusb_get_string_descriptor(handle, MS_OS_DESC_STRING_INDEX, 0, (unsigned char*)string, MS_OS_DESC_STRING_LENGTH); + if (r == MS_OS_DESC_STRING_LENGTH && memcmp(ms_os_desc_string, string, sizeof(ms_os_desc_string)) == 0) { // If this is a Microsoft OS String Descriptor, // attempt to read the WinUSB extended Feature Descriptors - if (strncmp(string, "MSFT100", 7) == 0) - read_ms_winsub_feature_descriptors(handle, string[7], first_iface); + read_ms_winsub_feature_descriptors(handle, string[MS_OS_DESC_VENDOR_CODE_OFFSET], first_iface); } switch(test_mode) { |