Skip to content

Commit 7722d6f

Browse files
arkqVudentz
authored andcommitted
Bluetooth: btusb: Check for unexpected bytes when defragmenting HCI frames
Some Barrot based USB Bluetooth dongles erroneously send one extra random byte for the HCI_OP_READ_LOCAL_EXT_FEATURES command. The consequence of that is that the next HCI transfer is misaligned by one byte causing undefined behavior. In most cases the response event for the next command fails with random error code. Since the HCI_OP_READ_LOCAL_EXT_FEATURES command is used during HCI controller initialization, the initialization fails rendering the USB dongle not usable. > [59.464099] usb 1-1.3: new full-speed USB device number 11 using xhci_hcd > [59.561617] usb 1-1.3: New USB device found, idVendor=33fa, idProduct=0012, bcdDevice=88.91 > [59.561642] usb 1-1.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0 > [59.561656] usb 1-1.3: Product: UGREEN BT6.0 Adapter > [61.720116] Bluetooth: hci1: command 0x1005 tx timeout > [61.720167] Bluetooth: hci1: Opcode 0x1005 failed: -110 This patch was tested with the 33fa:0012 device. The info from the /sys/kernel/debug/usb/devices is shown below: T: Bus=01 Lev=02 Prnt=02 Port=02 Cnt=01 Dev#= 12 Spd=12 MxCh= 0 D: Ver= 2.00 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=33fa ProdID=0012 Rev=88.91 S: Product=UGREEN BT6.0 Adapter C:* #Ifs= 2 Cfg#= 1 Atr=c0 MxPwr=100mA I:* If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=1ms E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms I:* If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 0 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 0 Ivl=1ms I: If#= 1 Alt= 1 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 9 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 9 Ivl=1ms I: If#= 1 Alt= 2 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 17 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 17 Ivl=1ms I: If#= 1 Alt= 3 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 25 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 25 Ivl=1ms I: If#= 1 Alt= 4 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 33 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 33 Ivl=1ms I: If#= 1 Alt= 5 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb E: Ad=03(O) Atr=01(Isoc) MxPS= 49 Ivl=1ms E: Ad=83(I) Atr=01(Isoc) MxPS= 49 Ivl=1ms Now the device is initialized properly: > [43.329852] usb 1-1.4: new full-speed USB device number 4 using dwc_otg > [43.446790] usb 1-1.4: New USB device found, idVendor=33fa, idProduct=0012, bcdDevice=88.91 > [43.446813] usb 1-1.4: New USB device strings: Mfr=0, Product=2, SerialNumber=0 > [43.446821] usb 1-1.4: Product: UGREEN BT6.0 Adapter > [43.582024] Bluetooth: hci1: Unexpected continuation: 1 bytes > [43.703025] Bluetooth: hci1: Unexpected continuation: 1 bytes > [43.750141] Bluetooth: MGMT ver 1.23 Link: bluez/bluez#1326 Signed-off-by: Arkadiusz Bokowy <[email protected]> Tested-by: Arkadiusz Bokowy <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 48a258b commit 7722d6f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/bluetooth/btusb.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static struct usb_driver btusb_driver;
6666
#define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25)
6767
#define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26)
6868
#define BTUSB_ACTIONS_SEMI BIT(27)
69+
#define BTUSB_BARROT BIT(28)
6970

7071
static const struct usb_device_id btusb_table[] = {
7172
/* Generic Bluetooth USB device */
@@ -812,6 +813,10 @@ static const struct usb_device_id quirks_table[] = {
812813
{ USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK |
813814
BTUSB_WIDEBAND_SPEECH },
814815

816+
/* Barrot Technology Bluetooth devices */
817+
{ USB_DEVICE(0x33fa, 0x0010), .driver_info = BTUSB_BARROT },
818+
{ USB_DEVICE(0x33fa, 0x0012), .driver_info = BTUSB_BARROT },
819+
815820
/* Actions Semiconductor ATS2851 based devices */
816821
{ USB_DEVICE(0x10d7, 0xb012), .driver_info = BTUSB_ACTIONS_SEMI },
817822

@@ -1194,6 +1199,18 @@ static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
11941199
}
11951200

11961201
if (!hci_skb_expect(skb)) {
1202+
/* Each chunk should correspond to at least 1 or more
1203+
* events so if there are still bytes left that doesn't
1204+
* constitute a new event this is likely a bug in the
1205+
* controller.
1206+
*/
1207+
if (count && count < HCI_EVENT_HDR_SIZE) {
1208+
bt_dev_warn(data->hdev,
1209+
"Unexpected continuation: %d bytes",
1210+
count);
1211+
count = 0;
1212+
}
1213+
11971214
/* Complete frame */
11981215
btusb_recv_event(data, skb);
11991216
skb = NULL;

0 commit comments

Comments
 (0)