Skip to content

Commit cead2e8

Browse files
committed
Bluetooth: host: Add RPA in directed advertisement support
In order to advertise directed to a privacy enabled central the initiator field of the directed adv packet needs to set to an RPA. To instruct the controller to use an RPA in the initiator field own address type should be set to either 0x02 or 0x03. Since it is not certain that a remote device supports address resolution of the initiator address we add an option to turn this on and give the application the responsibility to check if peer supports this. Fixes #14743 Signed-off-by: Joakim Andersson <[email protected]>
1 parent 12bf7e6 commit cead2e8

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

include/bluetooth/bluetooth.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ enum {
277277
* bt_conn_create_slave_le().
278278
*/
279279
BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY = BIT(4),
280+
281+
/** Enable use of Resolvable Private Address (RPA) as the target address
282+
* in directed advertisements when CONFIG_BT_PRIVACY is not enabled.
283+
* This is required if the remote device is privacy-enabled and
284+
* supports address resolution of the target address in directed
285+
* advertisement.
286+
* It is the responsibility of the application to check that the remote
287+
* device supports address resolution of directed advertisements by
288+
* reading its Central Address Resolution characteristic.
289+
*/
290+
BT_LE_ADV_OPT_DIR_ADDR_RPA = BIT(5),
280291
};
281292

282293
/** LE Advertising Parameters. */

include/bluetooth/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929
/* Special own address types for LL privacy (used in adv & scan parameters) */
3030
#define BT_HCI_OWN_ADDR_RPA_OR_PUBLIC 0x02
3131
#define BT_HCI_OWN_ADDR_RPA_OR_RANDOM 0x03
32+
#define BT_HCI_OWN_ADDR_RPA_MASK 0x02
3233

3334
/** Bluetooth Device Address */
3435
typedef struct {

subsys/bluetooth/host/hci_core.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,7 +3838,7 @@ static int le_set_event_mask(void)
38383838
mask |= BT_EVT_MASK_LE_ADVERTISING_REPORT;
38393839

38403840
if (IS_ENABLED(CONFIG_BT_CONN)) {
3841-
if (IS_ENABLED(CONFIG_BT_PRIVACY) &&
3841+
if (IS_ENABLED(CONFIG_BT_SMP) &&
38423842
BT_FEAT_LE_PRIVACY(bt_dev.le.features)) {
38433843
mask |= BT_EVT_MASK_LE_ENH_CONN_COMPLETE;
38443844
} else {
@@ -3982,8 +3982,7 @@ static int le_init(void)
39823982
}
39833983

39843984
#if defined(CONFIG_BT_SMP)
3985-
if (IS_ENABLED(CONFIG_BT_PRIVACY) &&
3986-
BT_FEAT_LE_PRIVACY(bt_dev.le.features)) {
3985+
if (BT_FEAT_LE_PRIVACY(bt_dev.le.features)) {
39873986
struct bt_hci_rp_le_read_rl_size *rp;
39883987

39893988
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_RL_SIZE, NULL,
@@ -5345,6 +5344,17 @@ int bt_le_adv_start_internal(const struct bt_le_adv_param *param,
53455344
}
53465345

53475346
bt_addr_le_copy(&set_param.direct_addr, peer);
5347+
5348+
if (IS_ENABLED(CONFIG_BT_SMP) &&
5349+
!IS_ENABLED(CONFIG_BT_PRIVACY) &&
5350+
BT_FEAT_LE_PRIVACY(bt_dev.le.features) &&
5351+
(param->options & BT_LE_ADV_OPT_DIR_ADDR_RPA)) {
5352+
/* This will not use RPA for our own address
5353+
* since we have set zeroed out the local IRK.
5354+
*/
5355+
set_param.own_addr_type |=
5356+
BT_HCI_OWN_ADDR_RPA_MASK;
5357+
}
53485358
} else {
53495359
set_param.type = BT_LE_ADV_IND;
53505360
}

0 commit comments

Comments
 (0)