From 5ac059b6b95ef0efb38b93a115f9cd28a9a96ef8 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 27 Nov 2016 21:07:11 +0200 Subject: [PATCH] Bluetooth: Extend advertising parameters with optional own address Applications may want finer control of the NRPA used for non-connectable beacons, and provide it up-front rather than letting the stack generate one. Change-Id: I84d459372cc85ed09a8f9cde16dbb9b98dec2a43 Signed-off-by: Johan Hedberg --- include/bluetooth/bluetooth.h | 6 ++++++ subsys/bluetooth/host/hci_core.c | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) 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;