diff --git a/include/bluetooth/bluetooth.h b/include/bluetooth/bluetooth.h index 7190d3ac9d3..fd2862b37c4 100644 --- a/include/bluetooth/bluetooth.h +++ b/include/bluetooth/bluetooth.h @@ -126,6 +126,12 @@ struct bt_le_adv_param { /** Maximum Advertising Interval (N * 0.625) */ uint16_t interval_max; + + /** Optional pre-defined (random) own address. Currently + * the only permitted use of this is for NRPA with + * non-connectable advertising. + */ + const bt_addr_t *own_addr; }; /** Helper to declare advertising parameters inline diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index e5ac1e82293..8a3c718657a 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3844,11 +3844,21 @@ int bt_le_adv_start(const struct bt_le_adv_param *param, #endif /* CONFIG_BLUETOOTH_PRIVACY */ set_param->type = BT_LE_ADV_IND; } else { + if (param->own_addr) { + /* Only NRPA is allowed */ + if (!BT_ADDR_IS_NRPA(param->own_addr)) { + return -EINVAL; + } + + err = set_random_address(param->own_addr); + } else { #if defined(CONFIG_BLUETOOTH_PRIVACY) - err = le_set_rpa(); + err = le_set_rpa(); #else - err = le_set_nrpa(); + err = le_set_nrpa(); #endif /* CONFIG_BLUETOOTH_PRIVACY */ + } + if (err) { net_buf_unref(buf); return err;