* [PATCH 1/2] Bluetooth: MSFT: Record the filter state on Command Disallowed
2026-11-20 1:13 [PATCH 0/2] Bluetooth: MSFT: Only enable the advertisement filter with monitors Thomas de Gruijter via B4 Relay
@ 2026-11-20 1:13 ` Thomas de Gruijter via B4 Relay
2026-11-20 4:51 ` Bluetooth: MSFT: Only enable the advertisement filter with monitors bluez.test.bot
2026-11-20 1:13 ` [PATCH 2/2] " Thomas de Gruijter via B4 Relay
2026-11-20 17:20 ` [PATCH 0/2] " patchwork-bot+bluetooth
2 siblings, 1 reply; 5+ messages in thread
From: Thomas de Gruijter via B4 Relay @ 2026-11-20 1:13 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Brian Gix, Yun-Hao Chung,
Miao-chen Chou, Archie Pusaka
Cc: Luiz Augusto von Dentz, linux-bluetooth, linux-kernel,
Thomas de Gruijter
From: Thomas de Gruijter <thomasdegruijter@pm.me>
msft_le_set_advertisement_filter_enable_cb() treats status 0x0C (Command
Disallowed) as success: a controller returns it when the advertisement
filter is already in the requested state, and some controllers start
with the filter enabled.
Since commit 493ea69970e2 ("Bluetooth: Convert MSFT filter HCI cmd to
hci_sync") the callback is passed the return value of
__hci_cmd_sync_status() instead of the HCI status. That function reports
Command Disallowed as -EBUSY, so the 0x0C branch is never taken and
msft->filter_enabled keeps its old value whenever the filter was already
in the requested state. msft_set_filter_enable() also always returns 0,
hiding real errors from its callers.
Pass the error code to the callback, treat -EBUSY as the filter already
being in the requested state, and return real errors from
msft_set_filter_enable(). Nothing reads msft->filter_enabled yet, but
the next patch relies on it to decide when to change the filter state.
The problem was found, with the help of an AI coding assistant
(Claude Code with Claude Opus 5.5).
Fixes: 493ea69970e2 ("Bluetooth: Convert MSFT filter HCI cmd to hci_sync")
Signed-off-by: Thomas de Gruijter <thomasdegruijter@pm.me>
---
net/bluetooth/msft.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c
index 7a06c2b8974b..f372df9a9831 100644
--- a/net/bluetooth/msft.c
+++ b/net/bluetooth/msft.c
@@ -1142,26 +1142,27 @@ __u64 msft_get_features(struct hci_dev *hdev)
static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev,
void *user_data,
- u8 status)
+ int err)
{
struct msft_cp_le_set_advertisement_filter_enable *cp = user_data;
struct msft_data *msft = hdev->msft_data;
- /* Error 0x0C would be returned if the filter enabled status is
+ /* Error 0x0C (Command Disallowed), which __hci_cmd_sync_status()
+ * reports as -EBUSY, would be returned if the filter enabled status is
* already set to whatever we were trying to set.
* Although the default state should be disabled, some controller set
* the initial value to enabled. Because there is no way to know the
* actual initial value before sending this command, here we also treat
* error 0x0C as success.
*/
- if (status != 0x00 && status != 0x0C)
+ if (err && err != -EBUSY)
return;
hci_dev_lock(hdev);
msft->filter_enabled = cp->enable;
- if (status == 0x0C)
+ if (err == -EBUSY)
bt_dev_warn(hdev, "MSFT filter_enable is already %s",
cp->enable ? "on" : "off");
@@ -1212,7 +1213,7 @@ int msft_set_filter_enable(struct hci_dev *hdev, bool enable)
msft_le_set_advertisement_filter_enable_cb(hdev, &cp, err);
- return 0;
+ return err == -EBUSY ? 0 : err;
}
bool msft_curve_validity(struct hci_dev *hdev)
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] Bluetooth: MSFT: Only enable the advertisement filter with monitors
2026-11-20 1:13 [PATCH 0/2] Bluetooth: MSFT: Only enable the advertisement filter with monitors Thomas de Gruijter via B4 Relay
2026-11-20 1:13 ` [PATCH 1/2] Bluetooth: MSFT: Record the filter state on Command Disallowed Thomas de Gruijter via B4 Relay
@ 2026-11-20 1:13 ` Thomas de Gruijter via B4 Relay
2026-11-20 17:20 ` [PATCH 0/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 5+ messages in thread
From: Thomas de Gruijter via B4 Relay @ 2026-11-20 1:13 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Brian Gix, Yun-Hao Chung,
Miao-chen Chou, Archie Pusaka
Cc: Luiz Augusto von Dentz, linux-bluetooth, linux-kernel,
Thomas de Gruijter
From: Thomas de Gruijter <thomasdegruijter@pm.me>
msft_do_open() unconditionally enables the MSFT LE advertisement filter
on every power on, whether or not any advertisement monitor is
registered.
On MediaTek MT7922 (USB 0e8d:0616, firmware build 20260724) the
controller then drops every LE advertisement: LE Set Extended Scan
Enable succeeds, but no LE Extended Advertising Report is ever
delivered, so LE discovery and passive scanning find nothing. BR/EDR
inquiry is not affected. Sending LE Set Advertisement Filter Enable with
Enable set to 0x00 restores reporting immediately. The Microsoft HCI
extension specification defines the filter as disabled by default and
does not specify what a controller reports while the filter is enabled
without any monitor condition.
Only enable the filter while at least one monitor is offloaded to the
controller, and update it after a monitor is added or removed and after
the monitors are re-registered on power on and resume. Like the
monitors, the filter state does not survive a power off, so reset the
tracked state in msft_do_close() instead of sending a redundant disable
on power on. A command is only sent when the wanted state differs from
msft->filter_enabled, so this depends on the previous patch keeping
that state accurate when the controller reports the filter as already
being in the requested state.
Fixes: 394566bf1e37 ("Bluetooth: advmon offload MSFT handle filter enablement")
Signed-off-by: Thomas de Gruijter <thomasdegruijter@pm.me>
---
net/bluetooth/msft.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c
index f372df9a9831..db7b40ab5fc1 100644
--- a/net/bluetooth/msft.c
+++ b/net/bluetooth/msft.c
@@ -468,6 +468,30 @@ static int msft_remove_monitor_sync(struct hci_dev *hdev,
return err;
}
+/* Keep the advertisement filter enabled only while at least one monitor is
+ * offloaded to the controller. With the filter enabled and no monitors, some
+ * controllers (e.g. MediaTek MT7922) drop every advertisement, which breaks
+ * LE discovery and passive scanning entirely.
+ *
+ * This function requires the caller holds hci_req_sync_lock
+ */
+static void msft_update_filter_enable(struct hci_dev *hdev)
+{
+ struct msft_data *msft = hdev->msft_data;
+ bool enable, update;
+
+ if (!msft)
+ return;
+
+ hci_dev_lock(hdev);
+ enable = !list_empty(&msft->handle_map);
+ update = enable != msft->filter_enabled;
+ hci_dev_unlock(hdev);
+
+ if (update)
+ msft_set_filter_enable(hdev, enable);
+}
+
/* This function requires the caller holds hci_req_sync_lock */
int msft_suspend_sync(struct hci_dev *hdev)
{
@@ -493,6 +517,8 @@ int msft_suspend_sync(struct hci_dev *hdev)
/* All monitors have been removed */
msft->suspending = false;
+ msft_update_filter_enable(hdev);
+
return 0;
}
@@ -633,6 +659,7 @@ int msft_resume_sync(struct hci_dev *hdev)
hci_dev_unlock(hdev);
reregister_monitor(hdev);
+ msft_update_filter_enable(hdev);
return 0;
}
@@ -670,11 +697,11 @@ void msft_do_open(struct hci_dev *hdev)
if (msft_monitor_supported(hdev)) {
msft->resuming = true;
- msft_set_filter_enable(hdev, true);
/* Monitors get removed on power off, so we need to explicitly
* tell the controller to re-monitor.
*/
reregister_monitor(hdev);
+ msft_update_filter_enable(hdev);
}
}
@@ -706,6 +733,11 @@ void msft_do_close(struct hci_dev *hdev)
kfree(handle_data);
}
+ /* The advertisement filter is back to its default, disabled state
+ * after power off as well.
+ */
+ msft->filter_enabled = false;
+
hci_dev_unlock(hdev);
mutex_lock(&msft->filter_lock);
@@ -1173,6 +1205,7 @@ static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev,
int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor)
{
struct msft_data *msft = hdev->msft_data;
+ int err;
if (!msft)
return -EOPNOTSUPP;
@@ -1180,13 +1213,17 @@ int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor)
if (msft->resuming || msft->suspending)
return -EBUSY;
- return msft_add_monitor_sync(hdev, monitor);
+ err = msft_add_monitor_sync(hdev, monitor);
+ msft_update_filter_enable(hdev);
+
+ return err;
}
/* This function requires the caller holds hci_req_sync_lock */
int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
{
struct msft_data *msft = hdev->msft_data;
+ int err;
if (!msft)
return -EOPNOTSUPP;
@@ -1194,7 +1231,10 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
if (msft->resuming || msft->suspending)
return -EBUSY;
- return msft_remove_monitor_sync(hdev, monitor);
+ err = msft_remove_monitor_sync(hdev, monitor);
+ msft_update_filter_enable(hdev);
+
+ return err;
}
int msft_set_filter_enable(struct hci_dev *hdev, bool enable)
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 0/2] Bluetooth: MSFT: Only enable the advertisement filter with monitors
2026-11-20 1:13 [PATCH 0/2] Bluetooth: MSFT: Only enable the advertisement filter with monitors Thomas de Gruijter via B4 Relay
2026-11-20 1:13 ` [PATCH 1/2] Bluetooth: MSFT: Record the filter state on Command Disallowed Thomas de Gruijter via B4 Relay
2026-11-20 1:13 ` [PATCH 2/2] " Thomas de Gruijter via B4 Relay
@ 2026-11-20 17:20 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2026-11-20 17:20 UTC (permalink / raw)
To: Thomas de Gruijter
Cc: marcel, luiz.dentz, brian.gix, howardchung, mcchou, apusaka,
luiz.von.dentz, linux-bluetooth, linux-kernel
Hello:
This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 20 Nov 2026 02:13:34 +0100 you wrote:
> On MediaTek MT7922 (USB 0e8d:0616, BT firmware build 20260724) LE
> discovery and passive scanning find nothing, because msft_do_open()
> enables the MSFT advertisement filter on every power on even when no
> advertisement monitor is registered, and this controller then drops
> every advertisement.
>
> Patch 2 only enables the filter while at least one monitor is offloaded.
> It is the first user of msft->filter_enabled, which does not follow the
> controller when it reports the filter as already being in the requested
> state, so patch 1 fixes that first.
>
> [...]
Here is the summary with links:
- [1/2] Bluetooth: MSFT: Record the filter state on Command Disallowed
https://git.kernel.org/bluetooth/bluetooth-next/c/75d6b9d82c35
- [2/2] Bluetooth: MSFT: Only enable the advertisement filter with monitors
https://git.kernel.org/bluetooth/bluetooth-next/c/4a8f9b7fb4f5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread