Skip to content

Commit bf6a4e3

Browse files
howardchunggholtmann
authored andcommitted
Bluetooth: disable advertisement filters during suspend
This adds logic to disable and reenable advertisement filters during suspend and resume. After this patch, we would only receive packets from devices in allow list during suspend. Signed-off-by: Howard Chung <[email protected]> Reviewed-by: Abhishek Pandit-Subedi <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 58ceb1e commit bf6a4e3

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ enum suspend_tasks {
105105
SUSPEND_POWERING_DOWN,
106106

107107
SUSPEND_PREPARE_NOTIFIER,
108+
109+
SUSPEND_SET_ADV_FILTER,
108110
__SUSPEND_NUM_TASKS
109111
};
110112

net/bluetooth/hci_request.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "smp.h"
3131
#include "hci_request.h"
32+
#include "msft.h"
3233

3334
#define HCI_REQ_DONE 0
3435
#define HCI_REQ_PEND 1
@@ -1242,6 +1243,29 @@ static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode)
12421243
clear_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks);
12431244
wake_up(&hdev->suspend_wait_q);
12441245
}
1246+
1247+
if (test_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks)) {
1248+
clear_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks);
1249+
wake_up(&hdev->suspend_wait_q);
1250+
}
1251+
}
1252+
1253+
static void hci_req_add_set_adv_filter_enable(struct hci_request *req,
1254+
bool enable)
1255+
{
1256+
struct hci_dev *hdev = req->hdev;
1257+
1258+
switch (hci_get_adv_monitor_offload_ext(hdev)) {
1259+
case HCI_ADV_MONITOR_EXT_MSFT:
1260+
msft_req_add_set_filter_enable(req, enable);
1261+
break;
1262+
default:
1263+
return;
1264+
}
1265+
1266+
/* No need to block when enabling since it's on resume path */
1267+
if (hdev->suspended && !enable)
1268+
set_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks);
12451269
}
12461270

12471271
/* Call with hci_dev_lock */
@@ -1301,6 +1325,9 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next)
13011325
hci_req_add_le_scan_disable(&req, false);
13021326
}
13031327

1328+
/* Disable advertisement filters */
1329+
hci_req_add_set_adv_filter_enable(&req, false);
1330+
13041331
/* Mark task needing completion */
13051332
set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks);
13061333

@@ -1340,6 +1367,8 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next)
13401367
hci_req_clear_event_filter(&req);
13411368
/* Reset passive/background scanning to normal */
13421369
__hci_update_background_scan(&req);
1370+
/* Enable all of the advertisement filters */
1371+
hci_req_add_set_adv_filter_enable(&req, true);
13431372

13441373
/* Unpause directed advertising */
13451374
hdev->advertising_paused = false;

net/bluetooth/msft.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,21 +579,28 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,
579579
return err;
580580
}
581581

582-
int msft_set_filter_enable(struct hci_dev *hdev, bool enable)
582+
void msft_req_add_set_filter_enable(struct hci_request *req, bool enable)
583583
{
584+
struct hci_dev *hdev = req->hdev;
584585
struct msft_cp_le_set_advertisement_filter_enable cp;
586+
587+
cp.sub_opcode = MSFT_OP_LE_SET_ADVERTISEMENT_FILTER_ENABLE;
588+
cp.enable = enable;
589+
590+
hci_req_add(req, hdev->msft_opcode, sizeof(cp), &cp);
591+
}
592+
593+
int msft_set_filter_enable(struct hci_dev *hdev, bool enable)
594+
{
585595
struct hci_request req;
586596
struct msft_data *msft = hdev->msft_data;
587597
int err;
588598

589599
if (!msft)
590600
return -EOPNOTSUPP;
591601

592-
cp.sub_opcode = MSFT_OP_LE_SET_ADVERTISEMENT_FILTER_ENABLE;
593-
cp.enable = enable;
594-
595602
hci_req_init(&req, hdev);
596-
hci_req_add(&req, hdev->msft_opcode, sizeof(cp), &cp);
603+
msft_req_add_set_filter_enable(&req, enable);
597604
err = hci_req_run_skb(&req, msft_le_set_advertisement_filter_enable_cb);
598605

599606
return err;

net/bluetooth/msft.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ __u64 msft_get_features(struct hci_dev *hdev);
2020
int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor);
2121
int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,
2222
u16 handle);
23+
void msft_req_add_set_filter_enable(struct hci_request *req, bool enable);
2324
int msft_set_filter_enable(struct hci_dev *hdev, bool enable);
2425

2526
#else
@@ -46,6 +47,8 @@ static inline int msft_remove_monitor(struct hci_dev *hdev,
4647
return -EOPNOTSUPP;
4748
}
4849

50+
static inline void msft_req_add_set_filter_enable(struct hci_request *req,
51+
bool enable) {}
4952
static inline int msft_set_filter_enable(struct hci_dev *hdev, bool enable)
5053
{
5154
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)