Bluetooth: Add option to force using identity address for advertising

In some cases the app may want to force using the identity address
regardless of privacy support or what type of advertising is done.
Provide such an option in bt_le_adv_param.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-03-20 16:57:00 +02:00 committed by Johan Hedberg
commit 7d4514a8b0
2 changed files with 17 additions and 3 deletions

View file

@ -115,6 +115,12 @@ enum {
* occur.
*/
BT_LE_ADV_OPT_ONE_TIME = BIT(1),
/** Advertise using the identity address as the own address.
* @warning This will compromise the privacy of the device, so care
* must be taken when using this option.
*/
BT_LE_ADV_OPT_USE_IDENTITY = BIT(2),
};
/** LE Advertising Parameters. */

View file

@ -4697,7 +4697,8 @@ int bt_le_adv_start(const struct bt_le_adv_param *param,
set_param.channel_map = 0x07;
if (param->options & BT_LE_ADV_OPT_CONNECTABLE) {
if (IS_ENABLED(CONFIG_BT_PRIVACY)) {
if (IS_ENABLED(CONFIG_BT_PRIVACY) &&
!(param->options & BT_LE_ADV_OPT_USE_IDENTITY)) {
err = le_set_private_addr();
if (err) {
return err;
@ -4733,16 +4734,23 @@ int bt_le_adv_start(const struct bt_le_adv_param *param,
}
err = set_random_address(param->own_addr);
set_param.own_addr_type = BT_ADDR_LE_RANDOM;
} else if (param->options & BT_LE_ADV_OPT_USE_IDENTITY) {
if (atomic_test_bit(bt_dev.flags,
BT_DEV_ID_STATIC_RANDOM)) {
err = set_random_address(&bt_dev.id_addr.a);
}
set_param.own_addr_type = bt_dev.id_addr.type;
} else {
err = le_set_private_addr();
set_param.own_addr_type = BT_ADDR_LE_RANDOM;
}
if (err) {
return err;
}
set_param.own_addr_type = BT_ADDR_LE_RANDOM;
if (sd) {
set_param.type = BT_LE_ADV_SCAN_IND;
} else {