Skip to content

Commit ad383c2

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: hci_sync: Enable advertising when LL privacy is enabled
This enables advertising when LL privacy is enabled and changes the command sequence when resolving list is updated to also account for when advertising is enabled using the following sequence: If there are devices to scan: Disable Scanning -> Update Accept List -> use_ll_privacy((Disable Advertising) -> Disable Resolving List -> Update Resolving List -> Enable Resolving List -> (Enable Advertising)) -> Enable Scanning Otherwise: Disable Scanning Errors during the Update Accept List stage are handled gracefully by restoring any previous state (e.g. advertising) and disabling the use of accept list as either accept list or resolving list could not be updated. Tested with: mgmt-tester -s "LL Privacy" Test Summary ------------ LL Privacy - Add Device 1 (Add to WL) Passed LL Privacy - Add Device 2 (Add to RL) Passed LL Privacy - Add Device 3 (Enable RL) Passed LL Privacy - Add Device 4 (2 Devices to WL) Passed LL Privacy - Add Device 5 (2 Devices to RL) Passed LL Privacy - Add Device 6 (RL is full) Passed LL Privacy - Add Device 7 (WL is full) Passed LL Privacy - Add Device 8 (Disable Adv) Passed LL Privacy - Add Device 9 (Multi Adv) Passed LL Privacy - Add Device 10 (Multi Dev and Multi Adv) Passed LL Privacy - Remove Device 1 (Remove from WL) Passed LL Privacy - Remove Device 2 (Remove from RL) Passed LL Privacy - Remove Device 3 (Disable RL) Passed LL Privacy - Remove Device 4 (Disable Adv) Passed LL Privacy - Remove Device 5 (Multi Adv) Passed LL Privacy - Start Discovery 1 (Disable RL) Passed LL Privacy - Start Discovery 2 (Disable RL) Passed Total: 18, Passed: 18 (100.0%), Failed: 0, Not Run: 0 Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent e8907f7 commit ad383c2

File tree

6 files changed

+213
-130
lines changed

6 files changed

+213
-130
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,11 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
14651465
#define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
14661466
((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
14671467

1468+
#define ll_privacy_capable(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1469+
14681470
/* Use LL Privacy based address resolution if supported */
1469-
#define use_ll_privacy(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1471+
#define use_ll_privacy(dev) (ll_privacy_capable(dev) && \
1472+
hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))
14701473

14711474
/* Use enhanced synchronous connection if command is supported */
14721475
#define enhanced_sco_capable(dev) ((dev)->commands[29] & 0x08)

include/net/bluetooth/hci_sync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,
6565
int hci_disable_advertising_sync(struct hci_dev *hdev);
6666

6767
int hci_update_passive_scan_sync(struct hci_dev *hdev);
68+
int hci_update_passive_scan(struct hci_dev *hdev);

net/bluetooth/hci_event.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,9 +5501,7 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
55015501
le16_to_cpu(ev->latency),
55025502
le16_to_cpu(ev->supervision_timeout));
55035503

5504-
if (use_ll_privacy(hdev) &&
5505-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
5506-
hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
5504+
if (hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
55075505
hci_req_disable_address_resolution(hdev);
55085506
}
55095507

net/bluetooth/hci_request.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,7 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn)
511511
}
512512

513513
/* Disable address resolution */
514-
if (use_ll_privacy(hdev) &&
515-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
516-
hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
514+
if (hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
517515
__u8 enable = 0x00;
518516

519517
hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
@@ -532,8 +530,7 @@ static void del_from_accept_list(struct hci_request *req, bdaddr_t *bdaddr,
532530
cp.bdaddr_type);
533531
hci_req_add(req, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, sizeof(cp), &cp);
534532

535-
if (use_ll_privacy(req->hdev) &&
536-
hci_dev_test_flag(req->hdev, HCI_ENABLE_LL_PRIVACY)) {
533+
if (use_ll_privacy(req->hdev)) {
537534
struct smp_irk *irk;
538535

539536
irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type);
@@ -586,8 +583,7 @@ static int add_to_accept_list(struct hci_request *req,
586583
cp.bdaddr_type);
587584
hci_req_add(req, HCI_OP_LE_ADD_TO_ACCEPT_LIST, sizeof(cp), &cp);
588585

589-
if (use_ll_privacy(hdev) &&
590-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) {
586+
if (use_ll_privacy(hdev)) {
591587
struct smp_irk *irk;
592588

593589
irk = hci_find_irk_by_addr(hdev, &params->addr,
@@ -626,8 +622,7 @@ static u8 update_accept_list(struct hci_request *req)
626622
*/
627623
bool allow_rpa = hdev->suspended;
628624

629-
if (use_ll_privacy(hdev) &&
630-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY))
625+
if (use_ll_privacy(hdev))
631626
allow_rpa = true;
632627

633628
/* Go through the current accept list programmed into the
@@ -716,9 +711,7 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
716711
return;
717712
}
718713

719-
if (use_ll_privacy(hdev) &&
720-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
721-
addr_resolv) {
714+
if (use_ll_privacy(hdev) && addr_resolv) {
722715
u8 enable = 0x01;
723716

724717
hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
@@ -1480,8 +1473,7 @@ void hci_req_disable_address_resolution(struct hci_dev *hdev)
14801473
struct hci_request req;
14811474
__u8 enable = 0x00;
14821475

1483-
if (!use_ll_privacy(hdev) &&
1484-
!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
1476+
if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
14851477
return;
14861478

14871479
hci_req_init(&req, hdev);
@@ -1624,8 +1616,7 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
16241616
/* If Controller supports LL Privacy use own address type is
16251617
* 0x03
16261618
*/
1627-
if (use_ll_privacy(hdev) &&
1628-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY))
1619+
if (use_ll_privacy(hdev))
16291620
*own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
16301621
else
16311622
*own_addr_type = ADDR_LE_DEV_RANDOM;
@@ -2092,8 +2083,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
20922083
/* If Controller supports LL Privacy use own address type is
20932084
* 0x03
20942085
*/
2095-
if (use_ll_privacy(hdev) &&
2096-
hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY))
2086+
if (use_ll_privacy(hdev))
20972087
*own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
20982088
else
20992089
*own_addr_type = ADDR_LE_DEV_RANDOM;

0 commit comments

Comments
 (0)