Skip to content

Commit 3c44a43

Browse files
Zhengping JiangVudentz
authored andcommitted
Bluetooth: hci_sync: Resume adv with no RPA when active scan
The address resolution should be disabled during the active scan, so all the advertisements can reach the host. The advertising has to be paused before disabling the address resolution, because the advertising will prevent any changes to the resolving list and the address resolution status. Skipping this will cause the hci error and the discovery failure. According to the bluetooth specification: "7.8.44 LE Set Address Resolution Enable command This command shall not be used when: - Advertising (other than periodic advertising) is enabled, - Scanning is enabled, or - an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding." If the host is using RPA, the controller needs to generate RPA for the advertising, so the advertising must remain paused during the active scan. If the host is not using RPA, the advertising can be resumed after disabling the address resolution. Fixes: 9afc675 ("Bluetooth: hci_sync: allow advertise when scan without RPA") Signed-off-by: Zhengping Jiang <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent bb765a7 commit 3c44a43

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

net/bluetooth/hci_sync.c

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,45 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev)
23672367
return err;
23682368
}
23692369

2370+
static int hci_pause_addr_resolution(struct hci_dev *hdev)
2371+
{
2372+
int err;
2373+
2374+
if (!use_ll_privacy(hdev))
2375+
return 0;
2376+
2377+
if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
2378+
return 0;
2379+
2380+
/* Cannot disable addr resolution if scanning is enabled or
2381+
* when initiating an LE connection.
2382+
*/
2383+
if (hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
2384+
hci_lookup_le_connect(hdev)) {
2385+
bt_dev_err(hdev, "Command not allowed when scan/LE connect");
2386+
return -EPERM;
2387+
}
2388+
2389+
/* Cannot disable addr resolution if advertising is enabled. */
2390+
err = hci_pause_advertising_sync(hdev);
2391+
if (err) {
2392+
bt_dev_err(hdev, "Pause advertising failed: %d", err);
2393+
return err;
2394+
}
2395+
2396+
err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00);
2397+
if (err)
2398+
bt_dev_err(hdev, "Unable to disable Address Resolution: %d",
2399+
err);
2400+
2401+
/* Return if address resolution is disabled and RPA is not used. */
2402+
if (!err && scan_use_rpa(hdev))
2403+
return err;
2404+
2405+
hci_resume_advertising_sync(hdev);
2406+
return err;
2407+
}
2408+
23702409
struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev,
23712410
bool extended, struct sock *sk)
23722411
{
@@ -2402,7 +2441,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
24022441
u8 filter_policy;
24032442
int err;
24042443

2405-
/* Pause advertising if resolving list can be used as controllers are
2444+
/* Pause advertising if resolving list can be used as controllers
24062445
* cannot accept resolving list modifications while advertising.
24072446
*/
24082447
if (use_ll_privacy(hdev)) {
@@ -5394,27 +5433,12 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)
53945433

53955434
cancel_interleave_scan(hdev);
53965435

5397-
/* Pause advertising since active scanning disables address resolution
5398-
* which advertising depend on in order to generate its RPAs.
5399-
*/
5400-
if (use_ll_privacy(hdev) && hci_dev_test_flag(hdev, HCI_PRIVACY)) {
5401-
err = hci_pause_advertising_sync(hdev);
5402-
if (err) {
5403-
bt_dev_err(hdev, "pause advertising failed: %d", err);
5404-
goto failed;
5405-
}
5406-
}
5407-
5408-
/* Disable address resolution while doing active scanning since the
5409-
* accept list shall not be used and all reports shall reach the host
5410-
* anyway.
5436+
/* Pause address resolution for active scan and stop advertising if
5437+
* privacy is enabled.
54115438
*/
5412-
err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00);
5413-
if (err) {
5414-
bt_dev_err(hdev, "Unable to disable Address Resolution: %d",
5415-
err);
5439+
err = hci_pause_addr_resolution(hdev);
5440+
if (err)
54165441
goto failed;
5417-
}
54185442

54195443
/* All active scans will be done with either a resolvable private
54205444
* address (when privacy feature has been enabled) or non-resolvable

0 commit comments

Comments
 (0)