2021-03-13 00:48:05

by Sonny Sasaka

[permalink] [raw]
Subject: [PATCH] Bluetooth: Cancel le_scan_restart work when stopping discovery

Not cancelling it has caused a bug where passive background scanning is
disabled out of the blue, preventing BLE keyboards/mice to reconnect.
Here is how it happens:
After hci_req_stop_discovery, there is still le_scan_restart_work
scheduled. Invocation of le_scan_restart_work causes a harmful
le_scan_disable_work to be scheduled. This le_scan_disable_work will
eventually disable passive scanning when the timer fires.

Sample btmon trace:

< HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
Type: Passive (0x00)
Interval: 367.500 msec (0x024c)
Window: 37.500 msec (0x003c)
Own address type: Public (0x00)
Filter policy: Accept all advertisement (0x00)
> HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Parameters (0x08|0x000b) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
Scanning: Enabled (0x01)
Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 2
Status: Success (0x00)
...
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
Scanning: Disabled (0x00)
Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 2
Status: Success (0x00)
// Background scanning is not working here onwards.

Reviewed-by: Abhishek Pandit-Subedi <[email protected]>
Signed-off-by: Sonny Sasaka <[email protected]>

---
net/bluetooth/hci_request.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index d7639c4b63104..c64b4a06de708 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -2710,6 +2710,7 @@ bool hci_req_stop_discovery(struct hci_request *req)

if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
cancel_delayed_work(&hdev->le_scan_disable);
+ cancel_delayed_work(&hdev->le_scan_restart);
hci_req_add_le_scan_disable(req);
}

--
2.29.2


2021-03-13 11:03:54

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: Cancel le_scan_restart work when stopping discovery

Hi Sonny,

> Not cancelling it has caused a bug where passive background scanning is
> disabled out of the blue, preventing BLE keyboards/mice to reconnect.
> Here is how it happens:
> After hci_req_stop_discovery, there is still le_scan_restart_work
> scheduled. Invocation of le_scan_restart_work causes a harmful
> le_scan_disable_work to be scheduled. This le_scan_disable_work will
> eventually disable passive scanning when the timer fires.
>
> Sample btmon trace:
>
> < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
> Type: Passive (0x00)
> Interval: 367.500 msec (0x024c)
> Window: 37.500 msec (0x003c)
> Own address type: Public (0x00)
> Filter policy: Accept all advertisement (0x00)
>> HCI Event: Command Complete (0x0e) plen 4
> LE Set Scan Parameters (0x08|0x000b) ncmd 1
> Status: Success (0x00)
> < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
> Scanning: Enabled (0x01)
> Filter duplicates: Disabled (0x00)
>> HCI Event: Command Complete (0x0e) plen 4
> LE Set Scan Enable (0x08|0x000c) ncmd 2
> Status: Success (0x00)
> ...
> < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
> Scanning: Disabled (0x00)
> Filter duplicates: Disabled (0x00)
>> HCI Event: Command Complete (0x0e) plen 4
> LE Set Scan Enable (0x08|0x000c) ncmd 2
> Status: Success (0x00)
> // Background scanning is not working here onwards.
>
> Reviewed-by: Abhishek Pandit-Subedi <[email protected]>
> Signed-off-by: Sonny Sasaka <[email protected]>
>
> ---
> net/bluetooth/hci_request.c | 1 +
> 1 file changed, 1 insertion(+)

I can apply this cleanly to bluetooth-next tree. Please double-check and rebase if it is still needed.

Regards

Marcel

2021-03-15 20:05:00

by Sonny Sasaka

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: Cancel le_scan_restart work when stopping discovery

Hi Marcel,

I have just sent a v2 which is rebased on bluetooth-next/master. PTAL. Thanks.


On Sat, Mar 13, 2021 at 3:00 AM Marcel Holtmann <[email protected]> wrote:
>
> Hi Sonny,
>
> > Not cancelling it has caused a bug where passive background scanning is
> > disabled out of the blue, preventing BLE keyboards/mice to reconnect.
> > Here is how it happens:
> > After hci_req_stop_discovery, there is still le_scan_restart_work
> > scheduled. Invocation of le_scan_restart_work causes a harmful
> > le_scan_disable_work to be scheduled. This le_scan_disable_work will
> > eventually disable passive scanning when the timer fires.
> >
> > Sample btmon trace:
> >
> > < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
> > Type: Passive (0x00)
> > Interval: 367.500 msec (0x024c)
> > Window: 37.500 msec (0x003c)
> > Own address type: Public (0x00)
> > Filter policy: Accept all advertisement (0x00)
> >> HCI Event: Command Complete (0x0e) plen 4
> > LE Set Scan Parameters (0x08|0x000b) ncmd 1
> > Status: Success (0x00)
> > < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
> > Scanning: Enabled (0x01)
> > Filter duplicates: Disabled (0x00)
> >> HCI Event: Command Complete (0x0e) plen 4
> > LE Set Scan Enable (0x08|0x000c) ncmd 2
> > Status: Success (0x00)
> > ...
> > < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
> > Scanning: Disabled (0x00)
> > Filter duplicates: Disabled (0x00)
> >> HCI Event: Command Complete (0x0e) plen 4
> > LE Set Scan Enable (0x08|0x000c) ncmd 2
> > Status: Success (0x00)
> > // Background scanning is not working here onwards.
> >
> > Reviewed-by: Abhishek Pandit-Subedi <[email protected]>
> > Signed-off-by: Sonny Sasaka <[email protected]>
> >
> > ---
> > net/bluetooth/hci_request.c | 1 +
> > 1 file changed, 1 insertion(+)
>
> I can apply this cleanly to bluetooth-next tree. Please double-check and rebase if it is still needed.
>
> Regards
>
> Marcel
>