Skip to content

Commit cde1a8a

Browse files
Swyterholtmann
authored andcommitted
Bluetooth: btusb: Fix and detect most of the Chinese Bluetooth controllers
For some reason they tend to squat on the very first CSR/ Cambridge Silicon Radio VID/PID instead of paying fees. This is an extremely common problem; the issue goes as back as 2013 and these devices are only getting more popular, even rebranded by reputable vendors and sold by retailers everywhere. So, at this point in time there are hundreds of modern dongles reusing the ID of what originally was an early Bluetooth 1.1 controller. Linux is the only place where they don't work due to spotty checks in our detection code. It only covered a minimum subset. So what's the big idea? Take advantage of the fact that all CSR chips report the same internal version as both the LMP sub-version and HCI revision number. It always matches, couple that with the manufacturer code, that rarely lies, and we now have a good idea of who is who. Additionally, by compiling a list of user-reported HCI/lsusb dumps, and searching around for legit CSR dongles in similar product ranges we can find what CSR BlueCore firmware supported which Bluetooth versions. That way we can narrow down ranges of fakes for each of them. e.g. Real CSR dongles with LMP subversion 0x73 are old enough that support BT 1.1 only; so it's a dead giveaway when some third-party BT 4.0 dongle reuses it. So, to sum things up; there are multiple classes of fake controllers reusing the same 0A12:0001 VID/PID. This has been broken for a while. Known 'fake' bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891 IC markings on 0x7558: FR3191AHAL 749H15143 (???) https://bugzilla.kernel.org/show_bug.cgi?id=60824 Fixes: 81cac64 (Deal with USB devices that are faking CSR vendor) Reported-by: Michał Wiśniewski <[email protected]> Tested-by: Mike Johnson <[email protected]> Tested-by: Ricardo Rodrigues <[email protected]> Tested-by: M.Hanny Sabbagh <[email protected]> Tested-by: Oussama BEN BRAHIM <[email protected]> Tested-by: Ismael Ferreras Morezuelas <[email protected]> Signed-off-by: Ismael Ferreras Morezuelas <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 339ddaa commit cde1a8a

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

drivers/bluetooth/btusb.c

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,7 @@ static int btusb_setup_csr(struct hci_dev *hdev)
17421742
{
17431743
struct hci_rp_read_local_version *rp;
17441744
struct sk_buff *skb;
1745+
bool is_fake = false;
17451746

17461747
BT_DBG("%s", hdev->name);
17471748

@@ -1761,18 +1762,69 @@ static int btusb_setup_csr(struct hci_dev *hdev)
17611762

17621763
rp = (struct hci_rp_read_local_version *)skb->data;
17631764

1764-
/* Detect controllers which aren't real CSR ones. */
1765+
/* Detect a wide host of Chinese controllers that aren't CSR.
1766+
*
1767+
* Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891
1768+
*
1769+
* The main thing they have in common is that these are really popular low-cost
1770+
* options that support newer Bluetooth versions but rely on heavy VID/PID
1771+
* squatting of this poor old Bluetooth 1.1 device. Even sold as such.
1772+
*
1773+
* We detect actual CSR devices by checking that the HCI manufacturer code
1774+
* is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and
1775+
* HCI rev values always match. As they both store the firmware number.
1776+
*/
17651777
if (le16_to_cpu(rp->manufacturer) != 10 ||
1766-
le16_to_cpu(rp->lmp_subver) == 0x0c5c) {
1778+
le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver))
1779+
is_fake = true;
1780+
1781+
/* Known legit CSR firmware build numbers and their supported BT versions:
1782+
* - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e
1783+
* - 1.2 (0x2) -> 0x04d9, 0x0529
1784+
* - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c
1785+
* - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External)
1786+
* - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb
1787+
*
1788+
* e.g. Real CSR dongles with LMP subversion 0x73 are old enough that
1789+
* support BT 1.1 only; so it's a dead giveaway when some
1790+
* third-party BT 4.0 dongle reuses it.
1791+
*/
1792+
else if (le16_to_cpu(rp->lmp_subver) <= 0x034e &&
1793+
le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1)
1794+
is_fake = true;
1795+
1796+
else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 &&
1797+
le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2)
1798+
is_fake = true;
1799+
1800+
else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c &&
1801+
le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0)
1802+
is_fake = true;
1803+
1804+
else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 &&
1805+
le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1)
1806+
is_fake = true;
1807+
1808+
else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb &&
1809+
le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0)
1810+
is_fake = true;
1811+
1812+
if (is_fake) {
1813+
bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds...");
1814+
1815+
/* Generally these clones have big discrepancies between
1816+
* advertised features and what's actually supported.
1817+
* Probably will need to be expanded in the future;
1818+
* without these the controller will lock up.
1819+
*/
1820+
set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
1821+
set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
1822+
17671823
/* Clear the reset quirk since this is not an actual
17681824
* early Bluetooth 1.1 device from CSR.
17691825
*/
17701826
clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
1771-
1772-
/* These fake CSR controllers have all a broken
1773-
* stored link key handling and so just disable it.
1774-
*/
1775-
set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
1827+
clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
17761828
}
17771829

17781830
kfree_skb(skb);
@@ -4070,11 +4122,13 @@ static int btusb_probe(struct usb_interface *intf,
40704122
if (bcdDevice < 0x117)
40714123
set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
40724124

4125+
/* This must be set first in case we disable it for fakes */
4126+
set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
4127+
40734128
/* Fake CSR devices with broken commands */
4074-
if (bcdDevice <= 0x100 || bcdDevice == 0x134)
4129+
if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 &&
4130+
le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
40754131
hdev->setup = btusb_setup_csr;
4076-
4077-
set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
40784132
}
40794133

40804134
if (id->driver_info & BTUSB_SNIFFER) {

include/net/bluetooth/bluetooth.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define BLUETOOTH_VER_1_1 1
4242
#define BLUETOOTH_VER_1_2 2
4343
#define BLUETOOTH_VER_2_0 3
44+
#define BLUETOOTH_VER_2_1 4
45+
#define BLUETOOTH_VER_4_0 6
4446

4547
/* Reserv for core and drivers use */
4648
#define BT_SKB_RESERVE 8

include/net/bluetooth/hci.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ enum {
227227
* supported.
228228
*/
229229
HCI_QUIRK_VALID_LE_STATES,
230+
231+
/* When this quirk is set, then erroneous data reporting
232+
* is ignored. This is mainly due to the fact that the HCI
233+
* Read Default Erroneous Data Reporting command is advertised,
234+
* but not supported; these controllers often reply with unknown
235+
* command and tend to lock up randomly. Needing a hard reset.
236+
*
237+
* This quirk can be set before hci_register_dev is called or
238+
* during the hdev->setup vendor callback.
239+
*/
240+
HCI_QUIRK_BROKEN_ERR_DATA_REPORTING,
230241
};
231242

232243
/* HCI device flags */

net/bluetooth/hci_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
605605
if (hdev->commands[8] & 0x01)
606606
hci_req_add(req, HCI_OP_READ_PAGE_SCAN_ACTIVITY, 0, NULL);
607607

608-
if (hdev->commands[18] & 0x04)
608+
if (hdev->commands[18] & 0x04 &&
609+
!test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks))
609610
hci_req_add(req, HCI_OP_READ_DEF_ERR_DATA_REPORTING, 0, NULL);
610611

611612
/* Some older Broadcom based Bluetooth 1.2 controllers do not
@@ -850,7 +851,8 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt)
850851
/* Set erroneous data reporting if supported to the wideband speech
851852
* setting value
852853
*/
853-
if (hdev->commands[18] & 0x08) {
854+
if (hdev->commands[18] & 0x08 &&
855+
!test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) {
854856
bool enabled = hci_dev_test_flag(hdev,
855857
HCI_WIDEBAND_SPEECH_ENABLED);
856858

0 commit comments

Comments
 (0)