Date: Mon, 28 Dec 2020 12:38:55 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 1952bc128c99 - stable/11 - MFC r368632: 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. Message-ID: <202012281238.0BSCctJ8091083@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/11 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=1952bc128c9903a1a2985063685268522e995c14 commit 1952bc128c9903a1a2985063685268522e995c14 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2020-12-14 11:56:16 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2020-12-28 12:38:06 +0000 MFC r368632: 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 Sponsored by: Mellanox Technologies // NVIDIA Networking --- lib/libusb/libusb20_desc.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/libusb/libusb20_desc.c b/lib/libusb/libusb20_desc.c index c285193664ab..ce3aaab84b08 100644 --- a/lib/libusb/libusb20_desc.c +++ b/lib/libusb/libusb20_desc.c @@ -79,9 +79,10 @@ libusb20_parse_config_desc(const void *config_desc) if (ptr[1] != LIBUSB20_DT_CONFIG) { return (NULL); /* not config descriptor */ } + /* - * The first "bInterfaceNumber" should never have the value 0xff. - * Then it is corrupt. + * The first "bInterfaceNumber" cannot start at 0xFFFF + * because the field is 8-bit. */ niface_no_alt = 0; nendpoint = 0; @@ -204,12 +205,15 @@ libusb20_parse_config_desc(const void *config_desc) if (libusb20_me_decode(ptr, ptr[0], &last_if->desc)) { /* ignore */ } - /* - * Sometimes USB devices have corrupt interface - * descriptors and we need to overwrite the provided - * interface number! - */ - last_if->desc.bInterfaceNumber = niface - 1; + + /* detect broken USB descriptors when USB debugging is enabled */ + if (last_if->desc.bInterfaceNumber != (uint8_t)(niface - 1)) { + const char *str = getenv("LIBUSB_DEBUG"); + if (str != NULL && str[0] != '\0' && str[0] != '0') { + 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.len = 0; last_if->extra.type = LIBUSB20_ME_IS_RAW;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012281238.0BSCctJ8091083>