Bluetooth: Add BT_LE_ADV_OPT_USE_NAME

This introduces a new advertising flag BT_LE_ADV_OPT_USE_NAME which can
be used by applications to make the stack automatically include the
Bluetooth Device Name in the Scan Response.

The name is also updated in case there is already an advertising
instance using it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2018-07-10 10:14:23 +03:00 committed by Johan Hedberg
commit acc3e5129e
3 changed files with 37 additions and 0 deletions

View file

@ -154,6 +154,9 @@ enum {
* must be taken when using this option.
*/
BT_LE_ADV_OPT_USE_IDENTITY = BIT(2),
/* Advertise using GAP device name */
BT_LE_ADV_OPT_USE_NAME = BIT(3),
};
/** LE Advertising Parameters. */

View file

@ -4754,6 +4754,20 @@ int bt_set_name(const char *name)
strncpy(bt_dev.name, name, sizeof(bt_dev.name));
/* Update advertising name if in use */
if (atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING_NAME)) {
struct bt_data sd[] = { BT_DATA(BT_DATA_NAME_COMPLETE, name,
strlen(name)) };
set_ad(BT_HCI_OP_LE_SET_SCAN_RSP_DATA, sd, ARRAY_SIZE(sd));
/* Make sure the new name is set */
if (atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) {
set_advertise_enable(false);
set_advertise_enable(true);
}
}
return 0;
#else
return -ENOMEM;
@ -4844,6 +4858,21 @@ int bt_le_adv_start(const struct bt_le_adv_param *param,
return err;
}
if (param->options & BT_LE_ADV_OPT_USE_NAME) {
const char *name;
/* Cannot use name if sd is set */
if (sd) {
return -EINVAL;
}
name = bt_get_name();
sd = (&(struct bt_data)BT_DATA(BT_DATA_NAME_COMPLETE, name,
strlen(name)));
sd_len = 1;
}
/*
* We need to set SCAN_RSP when enabling advertising type that allows
* for Scan Requests.
@ -4941,6 +4970,10 @@ int bt_le_adv_start(const struct bt_le_adv_param *param,
atomic_set_bit(bt_dev.flags, BT_DEV_KEEP_ADVERTISING);
}
if (param->options & BT_LE_ADV_OPT_USE_NAME) {
atomic_set_bit(bt_dev.flags, BT_DEV_ADVERTISING_NAME);
}
return 0;
}

View file

@ -36,6 +36,7 @@ enum {
BT_DEV_PUB_KEY_BUSY,
BT_DEV_ADVERTISING,
BT_DEV_ADVERTISING_NAME,
BT_DEV_KEEP_ADVERTISING,
BT_DEV_SCANNING,
BT_DEV_EXPLICIT_SCAN,