[RFC PATCH 1/2] Bluetooth: hci_sync: latch broken ext scan on Command Disallowed

Kamil Serwus <[email protected]>
Newsgroups dev.linux.lists.regressions,org.kernel.vger.linux-bluetooth,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
HCI_QUIRK_BROKEN_EXT_SCAN exists for controllers that "erroneously claim
to support extended scanning". Today every user of it has to be
recognised up front - by chip id or USB id - which means a controller is
only handled once somebody has owned one, hit the bug and sent a patch.

Recognising them by behaviour instead is both simpler and complete: a
controller that advertises the extended scan commands in its supported
commands bitmap but answers Command Disallowed is exactly the class of
device the quirk describes, and it says so itself on the first attempt.

Latch the quirk there, so every later scan uses the legacy commands.
The cost for an affected controller is one rejected scan round per power
cycle instead of a permanent stream of failures; for everyone else
nothing changes.

Signed-off-by: Kamil Serwus <[email protected]>
---
 include/net/bluetooth/hci.h |  4 ++--
 net/bluetooth/hci_sync.c    | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 50f0eef71..5cee010f2 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -276,8 +276,8 @@ enum {
 	 * disabled. This is required for some Broadcom controllers which
 	 * erroneously claim to support extended scanning.
 	 *
-	 * This quirk can be set before hci_register_dev is called or
-	 * during the hdev->setup vendor callback.
+	 * This quirk can be set before hci_register_dev is called, during the
+	 * hdev->setup vendor callback, or at runtime on Command Disallowed.
 	 */
 	HCI_QUIRK_BROKEN_EXT_SCAN,
 
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index c8d14128c..eb711f454 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -2265,6 +2265,7 @@ static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val,
 					   u8 filter_dup)
 {
 	struct hci_cp_le_set_ext_scan_enable cp;
+	int err;
 
 	memset(&cp, 0, sizeof(cp));
 	cp.enable = val;
@@ -2274,8 +2275,18 @@ static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val,
 	else
 		cp.filter_dup = filter_dup;
 
-	return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE,
-				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+	err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE,
+				    sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+
+	/* The controller claims extended scan support but rejects it. Latch
+	 * the quirk so that every later scan uses the legacy commands.
+	 */
+	if (err == -EBUSY) {
+		bt_dev_warn(hdev, "extended scan rejected, using legacy scan");
+		hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_SCAN);
+	}
+
+	return err;
 }
 
 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val,
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.