Skip to content

Commit

Permalink
samples: bluetooth: Remove uses of auto name in advertising
Browse files Browse the repository at this point in the history
The adv options to automatically add the name in the advertising and
scan response data are deprecated.

Update the samples that used those options to explicitly include
the name in the advertising and scan response data.

Signed-off-by: Michał Grochala <michal.grochala@nordicsemi.no>
  • Loading branch information
grochu authored and rlubos committed May 27, 2024
1 parent 1e5f283 commit a11f7d1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
15 changes: 13 additions & 2 deletions samples/bluetooth/direction_finding_connectionless_tx/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
/* Number of CTE send in single periodic advertising train */
#define PER_ADV_EVENT_CTE_COUNT 5

static const struct bt_data ad[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static void adv_sent_cb(struct bt_le_ext_adv *adv,
struct bt_le_ext_adv_sent_info *info);

Expand All @@ -30,8 +34,7 @@ const static struct bt_le_ext_adv_cb adv_callbacks = {
static struct bt_le_ext_adv *adv_set;

const static struct bt_le_adv_param param =
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV |
BT_LE_ADV_OPT_USE_NAME,
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV,
BT_GAP_ADV_FAST_INT_MIN_2,
BT_GAP_ADV_FAST_INT_MAX_2,
NULL);
Expand Down Expand Up @@ -100,6 +103,14 @@ int main(void)
}
printk("success\n");

printk("Set advertising data...");
err = bt_le_ext_adv_set_data(adv_set, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("failed (err %d)\n", err);
return 0;
}
printk("success\n");

printk("Update CTE params...");
err = bt_df_set_adv_cte_tx_param(adv_set, &cte_params);
if (err) {
Expand Down
3 changes: 2 additions & 1 deletion samples/bluetooth/direction_finding_peripheral/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_LE_SUPPORTED_FEATURES, BT_LE_SUPP_FEAT_24_ENCODE(DF_FEAT_ENABLED)),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

/* Latency set to zero, to enforce PDU exchange every connection event */
Expand Down Expand Up @@ -97,7 +98,7 @@ static void bt_ready(void)

printk("Bluetooth initialized\n");

err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return;
Expand Down
13 changes: 12 additions & 1 deletion samples/bluetooth/iso_time_sync/src/bis_transmitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include "iso_time_sync.h"

static const struct bt_data ad[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

void bis_transmitter_start(uint8_t retransmission_number, uint16_t max_transport_latency_ms)
{
int err;
Expand All @@ -25,12 +29,19 @@ void bis_transmitter_start(uint8_t retransmission_number, uint16_t max_transport
iso_tx_init(retransmission_number, NULL);

/* Create a non-connectable non-scannable advertising set */
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &adv);
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, &adv);
if (err) {
printk("Failed to create advertising set (err %d)\n", err);
return;
}

/* Set the advertising data */
err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("failed to set advertising data (err %d)\n", err);
return 0;
}

/* Set periodic advertising parameters */
err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_PARAM(BT_GAP_PER_ADV_FAST_INT_MIN_2,
BT_GAP_PER_ADV_FAST_INT_MAX_2,
Expand Down
6 changes: 5 additions & 1 deletion samples/bluetooth/iso_time_sync/src/cis_peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

static bool configured_for_tx;

static const struct bt_data ad[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static void connected(struct bt_conn *conn, uint8_t err)
{
char addr[BT_ADDR_LE_STR_LEN];
Expand Down Expand Up @@ -93,7 +97,7 @@ void cis_peripheral_start(bool do_tx)
return;
}

err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, NULL, 0, NULL, 0);
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return;
Expand Down
3 changes: 2 additions & 1 deletion samples/bluetooth/mesh/common/smp_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static struct bt_le_adv_param adv_params = {
.id = BT_ID_DEFAULT,
.sid = 0,
.secondary_max_skip = 0,
.options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME,
.options = BT_LE_ADV_OPT_CONNECTABLE,
.interval_min = BT_GAP_ADV_SLOW_INT_MIN,
.interval_max = BT_GAP_ADV_SLOW_INT_MAX,
.peer = NULL
Expand All @@ -36,6 +36,7 @@ static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID128_ALL, 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86, 0xd3,
0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static void pending_adv_start(struct k_work *work)
Expand Down
10 changes: 6 additions & 4 deletions samples/bluetooth/multiple_adv_sets/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ static K_WORK_DEFINE(advertising_work, advertising_work_handle);

static struct bt_le_ext_adv *ext_adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET];
static const struct bt_le_adv_param *non_connectable_adv_param =
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME,
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_NONE,
0x140, /* 200 ms */
0x190, /* 250 ms */
NULL);

static const struct bt_le_adv_param *connectable_adv_param =
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME,
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE,
BT_GAP_ADV_FAST_INT_MIN_2, /* 100 ms */
BT_GAP_ADV_FAST_INT_MAX_2, /* 150 ms */
NULL);
Expand All @@ -47,12 +47,14 @@ static const struct bt_data non_connectable_data[] = {
0x17, /* UTF-8 code point for “https:” */
'/', '/', 'w', 'w', 'w', '.',
'n', 'o', 'r', 'd', 'i', 'c', 's', 'e', 'm', 'i', '.',
'c', 'o', 'm')
'c', 'o', 'm'),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static const struct bt_data connectable_data[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL))
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static void adv_connected_cb(struct bt_le_ext_adv *adv,
Expand Down
5 changes: 3 additions & 2 deletions samples/bluetooth/peripheral_cgms/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID16_ALL,
BT_UUID_16_ENCODE(BT_UUID_CGMS_VAL),
BT_UUID_16_ENCODE(BT_UUID_DIS_VAL))
BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static void connected(struct bt_conn *conn, uint8_t err)
Expand Down Expand Up @@ -148,7 +149,7 @@ int main(void)
return 0;
}

err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return 0;
Expand Down
8 changes: 5 additions & 3 deletions samples/bluetooth/peripheral_power_profiling/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static struct bt_conn *device_conn;

static const struct bt_data connectable_ad_data[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static const struct bt_data non_connectable_ad_data[] = {
Expand All @@ -87,17 +88,18 @@ static const struct bt_data non_connectable_ad_data[] = {
0x17, /* UTF-8 code point for “https:” */
'/', '/', 'w', 'w', 'w', '.',
'n', 'o', 'r', 'd', 'i', 'c', 's', 'e', 'm', 'i', '.',
'c', 'o', 'm')
'c', 'o', 'm'),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};

static const struct bt_le_adv_param *connectable_ad_params =
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME,
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE,
CONNECTABLE_ADV_INTERVAL_MIN,
CONNECTABLE_ADV_INTERVAL_MAX,
NULL);

static const struct bt_le_adv_param *non_connectable_ad_params =
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME,
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_NONE,
NON_CONNECTABLE_ADV_INTERVAL_MIN,
NON_CONNECTABLE_ADV_INTERVAL_MAX,
NULL);
Expand Down
5 changes: 3 additions & 2 deletions samples/bluetooth/peripheral_rscs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ static struct bt_conn_auth_info_cb conn_auth_info_callbacks;

static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_RSCS_VAL))
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_RSCS_VAL)),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1)
};

int main(void)
Expand Down Expand Up @@ -285,7 +286,7 @@ int main(void)
return 0;
}

err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return 0;
Expand Down

0 comments on commit a11f7d1

Please sign in to comment.