Be bug compatible with other operating systems by allowing non-sequential

interface numbering for USB descriptors in userspace. Else certain USB
control requests using the interface number, won't be recognized by the
USB firmware.

Refer to section 9.2.3 in the USB 2.0 specification:
Interfaces are numbered from zero to one less than the number of concurrent interfaces
supported by the configuration.

PR:		251784
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
This commit is contained in:
Hans Petter Selasky 2020-12-14 11:56:16 +00:00
parent f32672272f
commit 1055793115

View File

@ -81,9 +81,10 @@ libusb20_parse_config_desc(const void *config_desc)
if (ptr[1] != LIBUSB20_DT_CONFIG) { if (ptr[1] != LIBUSB20_DT_CONFIG) {
return (NULL); /* not config descriptor */ return (NULL); /* not config descriptor */
} }
/* /*
* The first "bInterfaceNumber" should never have the value 0xff. * The first "bInterfaceNumber" cannot start at 0xFFFF
* Then it is corrupt. * because the field is 8-bit.
*/ */
niface_no_alt = 0; niface_no_alt = 0;
nendpoint = 0; nendpoint = 0;
@ -206,12 +207,15 @@ libusb20_parse_config_desc(const void *config_desc)
if (libusb20_me_decode(ptr, ptr[0], &last_if->desc)) { if (libusb20_me_decode(ptr, ptr[0], &last_if->desc)) {
/* ignore */ /* ignore */
} }
/*
* Sometimes USB devices have corrupt interface /* detect broken USB descriptors when USB debugging is enabled */
* descriptors and we need to overwrite the provided if (last_if->desc.bInterfaceNumber != (uint8_t)(niface - 1)) {
* interface number! const char *str = getenv("LIBUSB_DEBUG");
*/ if (str != NULL && str[0] != '\0' && str[0] != '0') {
last_if->desc.bInterfaceNumber = niface - 1; printf("LIBUSB_DEBUG: bInterfaceNumber(%u) is not sequential(%u)\n",
last_if->desc.bInterfaceNumber, niface - 1);
}
}
last_if->extra.ptr = LIBUSB20_ADD_BYTES(ptr, ptr[0]); last_if->extra.ptr = LIBUSB20_ADD_BYTES(ptr, ptr[0]);
last_if->extra.len = 0; last_if->extra.len = 0;
last_if->extra.type = LIBUSB20_ME_IS_RAW; last_if->extra.type = LIBUSB20_ME_IS_RAW;