2023-02-07 11:58:26

by Tomasz Moń

[permalink] [raw]
Subject: [PATCH] Bluetooth: btusb: Do not require hardcoded interface numbers

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ń <[email protected]>
---
drivers/bluetooth/btusb.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

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;

--
2.39.1



2023-02-07 12:42:53

by bluez.test.bot

[permalink] [raw]
Subject: RE: Bluetooth: btusb: Do not require hardcoded interface numbers

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=719475

---Test result---

Test Summary:
CheckPatch PASS 0.92 seconds
GitLint PASS 0.33 seconds
SubjectPrefix PASS 0.11 seconds
BuildKernel PASS 30.90 seconds
CheckAllWarning PASS 33.91 seconds
CheckSparse PASS 38.08 seconds
CheckSmatch PASS 106.45 seconds
BuildKernel32 PASS 29.68 seconds
TestRunnerSetup PASS 428.94 seconds
TestRunner_l2cap-tester PASS 15.94 seconds
TestRunner_iso-tester PASS 16.64 seconds
TestRunner_bnep-tester PASS 5.43 seconds
TestRunner_mgmt-tester PASS 108.68 seconds
TestRunner_rfcomm-tester PASS 8.69 seconds
TestRunner_sco-tester PASS 7.99 seconds
TestRunner_ioctl-tester PASS 9.37 seconds
TestRunner_mesh-tester PASS 6.89 seconds
TestRunner_smp-tester PASS 7.89 seconds
TestRunner_userchan-tester PASS 5.68 seconds
IncrementalBuild PASS 27.68 seconds



---
Regards,
Linux Bluetooth

2023-02-09 21:33:05

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: Do not require hardcoded interface numbers

Hi Tomasz,

On Tue, Feb 7, 2023 at 3:58 AM Tomasz Moń <[email protected]> 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?

> Signed-off-by: Tomasz Moń <[email protected]>
> ---
> drivers/bluetooth/btusb.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> 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;
>
> --
> 2.39.1
>


--
Luiz Augusto von Dentz

2023-02-10 06:31:47

by Tomasz Moń

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: Do not require hardcoded interface numbers

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ń <[email protected]> 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.

--
Tomasz Moń | Senior Firmware Engineer
P +48 882 826 111 | Wrocław, Poland
nordicsemi.com | devzone.nordicsemi.com

2023-02-14 20:40:24

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: Do not require hardcoded interface numbers

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <[email protected]>:

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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html