[PATCH] Bluetooth: hci_sync: Fix BLE devices were unable to disable the wakeup function

clancy_shang@163.com posted 1 patch 1 year, 11 months ago
net/bluetooth/hci_sync.c | 10 ++++++++++
1 file changed, 10 insertions(+)
[PATCH] Bluetooth: hci_sync: Fix BLE devices were unable to disable the wakeup function
Posted by clancy_shang@163.com 1 year, 11 months ago
From: Clancy Shang <clancy.shang@quectel.com>

when BLE master enter suspend,  it does not delete the peripheral that
in acceptlist. so if disable the wakeup function, the BLE master scans with
basic filter next time, the peripheral can be scanned which is unexpected

Signed-off-by: Clancy Shang <clancy.shang@quectel.com>
---
 net/bluetooth/hci_sync.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index d85a7091a116..abc7f614da5f 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -2533,6 +2533,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
 	struct bdaddr_list *b, *t;
 	u8 num_entries = 0;
 	bool pend_conn, pend_report;
+	struct hci_conn_params *conn_params;
 	u8 filter_policy;
 	size_t i, n;
 	int err;
@@ -2585,6 +2586,15 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
 			continue;
 		}
 
+		conn_params = hci_conn_params_lookup(hdev, &b->bdaddr, b->bdaddr_type);
+		/* During suspend, only wakeable devices can be in acceptlist */
+		if (conn_params && hdev->suspended &&
+		    !(conn_params->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) {
+			hci_le_del_accept_list_sync(hdev, &b->bdaddr,
+						    b->bdaddr_type);
+			continue;
+		}
+
 		num_entries++;
 	}
 
-- 
2.25.1
Re: [PATCH] Bluetooth: hci_sync: Fix BLE devices were unable to disable the wakeup function
Posted by Luiz Augusto von Dentz 1 year, 11 months ago
Hi Clancy,

On Thu, Jan 4, 2024 at 9:56 PM <clancy_shang@163.com> wrote:
>
> From: Clancy Shang <clancy.shang@quectel.com>
>
> when BLE master enter suspend,  it does not delete the peripheral that
> in acceptlist. so if disable the wakeup function, the BLE master scans with
> basic filter next time, the peripheral can be scanned which is unexpected
>
> Signed-off-by: Clancy Shang <clancy.shang@quectel.com>
> ---
>  net/bluetooth/hci_sync.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
> index d85a7091a116..abc7f614da5f 100644
> --- a/net/bluetooth/hci_sync.c
> +++ b/net/bluetooth/hci_sync.c
> @@ -2533,6 +2533,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
>         struct bdaddr_list *b, *t;
>         u8 num_entries = 0;
>         bool pend_conn, pend_report;
> +       struct hci_conn_params *conn_params;
>         u8 filter_policy;
>         size_t i, n;
>         int err;
> @@ -2585,6 +2586,15 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
>                         continue;
>                 }
>
> +               conn_params = hci_conn_params_lookup(hdev, &b->bdaddr, b->bdaddr_type);
> +               /* During suspend, only wakeable devices can be in acceptlist */
> +               if (conn_params && hdev->suspended &&
> +                   !(conn_params->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) {
> +                       hci_le_del_accept_list_sync(hdev, &b->bdaddr,
> +                                                   b->bdaddr_type);
> +                       continue;
> +               }

This might require a lock since that is not a copy of the conn_params
which can be updated concurrently, so perhaps something like the
following is might be safer:

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index b3141e3f9cf6..eeb73a54fd26 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -2206,8 +2206,11 @@ static int hci_le_add_accept_list_sync(struct
hci_dev *hdev,

        /* During suspend, only wakeable devices can be in acceptlist */
        if (hdev->suspended &&
-           !(params->flags & HCI_CONN_FLAG_REMOTE_WAKEUP))
+           !(params->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) {
+               hci_le_del_accept_list_sync(hdev, &params->bdaddr,
+                                           params->bdaddr_type);
                return 0;
+       }

        /* Select filter policy to accept all advertising */
        if (*num_entries >= hdev->le_accept_list_size)

>                 num_entries++;
>         }
>
> --
> 2.25.1
>


-- 
Luiz Augusto von Dentz