From owner-svn-src-head@freebsd.org Mon Dec 14 11:56:17 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5429D4B7707; Mon, 14 Dec 2020 11:56:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CvfxF1y9Fz4mXJ; Mon, 14 Dec 2020 11:56:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 35DE320F5B; Mon, 14 Dec 2020 11:56:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BEBuHPl069273; Mon, 14 Dec 2020 11:56:17 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BEBuHLU069272; Mon, 14 Dec 2020 11:56:17 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202012141156.0BEBuHLU069272@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 14 Dec 2020 11:56:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368632 - head/lib/libusb X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/lib/libusb X-SVN-Commit-Revision: 368632 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2020 11:56:17 -0000 Author: hselasky Date: Mon Dec 14 11:56:16 2020 New Revision: 368632 URL: https://svnweb.freebsd.org/changeset/base/368632 Log: 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 Modified: head/lib/libusb/libusb20_desc.c Modified: head/lib/libusb/libusb20_desc.c ============================================================================== --- head/lib/libusb/libusb20_desc.c Mon Dec 14 11:09:07 2020 (r368631) +++ head/lib/libusb/libusb20_desc.c Mon Dec 14 11:56:16 2020 (r368632) @@ -81,9 +81,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; @@ -206,12 +207,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;