diff mbox series

Bluetooth: btusb: Do not require hardcoded interface numbers

Message ID 20230207115741.122854-1-tomasz.mon@nordicsemi.no
State Accepted
Commit dbf27f4a6adb530999726340bd133a22f57779c9
Headers show
Series Bluetooth: btusb: Do not require hardcoded interface numbers | expand

Commit Message

Tomasz Moń Feb. 7, 2023, 11:57 a.m. UTC
Remove hardcoded interface number check because Bluetooth specification
since version 4.0 only recommends and no longer requires specific
interface numbers.

While earlier Bluetooth versions, i.e. 2.1 + EDR and 3.0 + HS, contain
required configuration table in Volume 4 - Host Controller Interface
Part B - USB Transport Layer, Bluetooth Core Specification Addendum 2
changes the table from required to recommended configuration.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
---
 drivers/bluetooth/btusb.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Tomasz Moń Feb. 10, 2023, 6:31 a.m. UTC | #1
On Thu, 2023-02-09 at 13:32 -0800, Luiz Augusto von Dentz wrote:
> On Tue, Feb 7, 2023 at 3:58 AM Tomasz Moń <tomasz.mon@nordicsemi.no> wrote:
> > Remove hardcoded interface number check because Bluetooth specification
> > since version 4.0 only recommends and no longer requires specific
> > interface numbers.
> > 
> > While earlier Bluetooth versions, i.e. 2.1 + EDR and 3.0 + HS, contain
> > required configuration table in Volume 4 - Host Controller Interface
> > Part B - USB Transport Layer, Bluetooth Core Specification Addendum 2
> > changes the table from required to recommended configuration.
> 
> Can you give it a little more context, is this supposed to be the case
> for LE only controllers? I assume this shouldn't cause any regressions
> for other controllers right?

Why do you think it is the case for LE only controllers? The Bluetooth
Host Controller interface is not limited to LE.

I believe this doesn't cause any regressions for other controllers.
Because I don't know anything nor have access to the Apple-specific
(Broadcom) devices that have BTUSB_IFNUM_2 flag set, I left the
BTUSB_IFNUM_2 check intact. It might be that the BTUSB_IFNUM_2 is not
necessary after all (and was only added because of this no longer
necessary hardcoded interface check), but you really need the actual
hardware to tell.

Note that this patch is merely removing the no longer necessary check
and otherwise leaving the communication intact. The hardcoded interface
check is preventing btusb from attaching to Bluetooth HCI controller in
a composite device that have some other interface under the number 0.

The composite devices that previously failed due to check do work with
this patch, because the specification (Bluetooth Core Specification
Version 5.3 Vol 4, Part B 2.2.2 Controller function in a composite
device) says host **should** address control packets to Interface (and
not Device) while at the same time the specification explicitly says
that the device **shall** recognize the HCI command packets directed to
Device.

Because **should** equals to recommended and **shall** is mandatory
requirement, the btusb driver is actually compliant even if it always
directs the control transfers to Device.
patchwork-bot+bluetooth@kernel.org Feb. 14, 2023, 8:40 p.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue, 7 Feb 2023 12:57:41 +0100 you wrote:
> Remove hardcoded interface number check because Bluetooth specification
> since version 4.0 only recommends and no longer requires specific
> interface numbers.
> 
> While earlier Bluetooth versions, i.e. 2.1 + EDR and 3.0 + HS, contain
> required configuration table in Volume 4 - Host Controller Interface
> Part B - USB Transport Layer, Bluetooth Core Specification Addendum 2
> changes the table from required to recommended configuration.
> 
> [...]

Here is the summary with links:
  - Bluetooth: btusb: Do not require hardcoded interface numbers
    https://git.kernel.org/bluetooth/bluetooth-next/c/dbf27f4a6adb

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 2ad4efdd9e40..5110d26cff7a 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -3830,13 +3830,9 @@  static int btusb_probe(struct usb_interface *intf,
 
 	BT_DBG("intf %p id %p", intf, id);
 
-	/* interface numbers are hardcoded in the spec */
-	if (intf->cur_altsetting->desc.bInterfaceNumber != 0) {
-		if (!(id->driver_info & BTUSB_IFNUM_2))
-			return -ENODEV;
-		if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
-			return -ENODEV;
-	}
+	if ((id->driver_info & BTUSB_IFNUM_2) &&
+	    (intf->cur_altsetting->desc.bInterfaceNumber != 2))
+		return -ENODEV;
 
 	ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber;