Skip to content

Commit e3ee414

Browse files
grochurlubos
authored andcommitted
samples: bluetooth: Remove uses of auto name in advertising
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> Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 09dfaba commit e3ee414

File tree

10 files changed

+63
-18
lines changed

10 files changed

+63
-18
lines changed

samples/bluetooth/direction_finding_connectionless_tx/src/main.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
/* Number of CTE send in single periodic advertising train */
2121
#define PER_ADV_EVENT_CTE_COUNT 5
2222

23+
static const struct bt_data ad[] = {
24+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
25+
};
26+
2327
static void adv_sent_cb(struct bt_le_ext_adv *adv,
2428
struct bt_le_ext_adv_sent_info *info);
2529

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

3236
const static struct bt_le_adv_param param =
33-
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV |
34-
BT_LE_ADV_OPT_USE_NAME,
37+
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV,
3538
BT_GAP_ADV_FAST_INT_MIN_2,
3639
BT_GAP_ADV_FAST_INT_MAX_2,
3740
NULL);
@@ -100,6 +103,14 @@ int main(void)
100103
}
101104
printk("success\n");
102105

106+
printk("Set advertising data...");
107+
err = bt_le_ext_adv_set_data(adv_set, ad, ARRAY_SIZE(ad), NULL, 0);
108+
if (err) {
109+
printk("failed (err %d)\n", err);
110+
return 0;
111+
}
112+
printk("success\n");
113+
103114
printk("Update CTE params...");
104115
err = bt_df_set_adv_cte_tx_param(adv_set, &cte_params);
105116
if (err) {

samples/bluetooth/direction_finding_peripheral/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
static const struct bt_data ad[] = {
2121
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
2222
BT_DATA_BYTES(BT_DATA_LE_SUPPORTED_FEATURES, BT_LE_SUPP_FEAT_24_ENCODE(DF_FEAT_ENABLED)),
23+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
2324
};
2425

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

9899
printk("Bluetooth initialized\n");
99100

100-
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
101+
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
101102
if (err) {
102103
printk("Advertising failed to start (err %d)\n", err);
103104
return;

samples/bluetooth/iso_combined_bis_and_cis/src/combined_bis_cis.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,30 @@ static void set_sdu_data_cb(struct net_buf *buf)
149149
}
150150
}
151151

152+
static const struct bt_data ad[] = {
153+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
154+
};
155+
152156
void bis_transmitter_start(void)
153157
{
154158
int err;
155159
struct bt_le_ext_adv *adv;
156160
struct bt_iso_big *big;
157161

158162
/* Create a non-connectable non-scannable advertising set */
159-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &adv);
163+
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, &adv);
160164
if (err) {
161165
LOG_INF("Failed to create advertising set (err %d)", err);
162166
return;
163167
}
164168

169+
/* Set the advertising data */
170+
err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
171+
if (err) {
172+
LOG_INF("failed to set advertising data (err %d)", err);
173+
return;
174+
}
175+
165176
/* Set periodic advertising parameters */
166177
err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_PARAM(PERIODIC_ADV_INTERVAL_BLE_UNITS,
167178
PERIODIC_ADV_INTERVAL_BLE_UNITS,

samples/bluetooth/iso_time_sync/src/bis_transmitter.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#include "iso_time_sync.h"
1818

19+
static const struct bt_data ad[] = {
20+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
21+
};
22+
1923
void bis_transmitter_start(uint8_t retransmission_number, uint16_t max_transport_latency_ms)
2024
{
2125
int err;
@@ -25,12 +29,19 @@ void bis_transmitter_start(uint8_t retransmission_number, uint16_t max_transport
2529
iso_tx_init(retransmission_number, NULL);
2630

2731
/* Create a non-connectable non-scannable advertising set */
28-
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &adv);
32+
err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, NULL, &adv);
2933
if (err) {
3034
printk("Failed to create advertising set (err %d)\n", err);
3135
return;
3236
}
3337

38+
/* Set the advertising data */
39+
err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
40+
if (err) {
41+
printk("failed to set advertising data (err %d)\n", err);
42+
return;
43+
}
44+
3445
/* Set periodic advertising parameters */
3546
err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_PARAM(BT_GAP_PER_ADV_FAST_INT_MIN_2,
3647
BT_GAP_PER_ADV_FAST_INT_MAX_2,

samples/bluetooth/iso_time_sync/src/cis_peripheral.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
static bool configured_for_tx;
2121

22+
static const struct bt_data ad[] = {
23+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
24+
};
25+
2226
static void connected(struct bt_conn *conn, uint8_t err)
2327
{
2428
char addr[BT_ADDR_LE_STR_LEN];
@@ -93,7 +97,7 @@ void cis_peripheral_start(bool do_tx)
9397
return;
9498
}
9599

96-
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, NULL, 0, NULL, 0);
100+
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
97101
if (err) {
98102
printk("Advertising failed to start (err %d)\n", err);
99103
return;

samples/bluetooth/mesh/common/smp_bt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static struct bt_le_adv_param adv_params = {
2626
.id = BT_ID_DEFAULT,
2727
.sid = 0,
2828
.secondary_max_skip = 0,
29-
.options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME,
29+
.options = BT_LE_ADV_OPT_CONNECTABLE,
3030
.interval_min = BT_GAP_ADV_SLOW_INT_MIN,
3131
.interval_max = BT_GAP_ADV_SLOW_INT_MAX,
3232
.peer = NULL
@@ -36,6 +36,7 @@ static const struct bt_data ad[] = {
3636
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
3737
BT_DATA_BYTES(BT_DATA_UUID128_ALL, 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86, 0xd3,
3838
0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
39+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
3940
};
4041

4142
static void pending_adv_start(struct k_work *work)

samples/bluetooth/multiple_adv_sets/src/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ static K_WORK_DEFINE(advertising_work, advertising_work_handle);
3030

3131
static struct bt_le_ext_adv *ext_adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET];
3232
static const struct bt_le_adv_param *non_connectable_adv_param =
33-
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME,
33+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_NONE,
3434
0x140, /* 200 ms */
3535
0x190, /* 250 ms */
3636
NULL);
3737

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

5354
static const struct bt_data connectable_data[] = {
5455
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
55-
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL))
56+
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
57+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
5658
};
5759

5860
static void adv_connected_cb(struct bt_le_ext_adv *adv,

samples/bluetooth/peripheral_cgms/src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static const struct bt_data ad[] = {
3131
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
3232
BT_DATA_BYTES(BT_DATA_UUID16_ALL,
3333
BT_UUID_16_ENCODE(BT_UUID_CGMS_VAL),
34-
BT_UUID_16_ENCODE(BT_UUID_DIS_VAL))
34+
BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
35+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
3536
};
3637

3738
static void connected(struct bt_conn *conn, uint8_t err)
@@ -148,7 +149,7 @@ int main(void)
148149
return 0;
149150
}
150151

151-
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
152+
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
152153
if (err) {
153154
printk("Advertising failed to start (err %d)\n", err);
154155
return 0;

samples/bluetooth/peripheral_power_profiling/src/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static struct bt_conn *device_conn;
7979

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

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

9395
static const struct bt_le_adv_param *connectable_ad_params =
94-
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME,
96+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE,
9597
CONNECTABLE_ADV_INTERVAL_MIN,
9698
CONNECTABLE_ADV_INTERVAL_MAX,
9799
NULL);
98100

99101
static const struct bt_le_adv_param *non_connectable_ad_params =
100-
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME,
102+
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_NONE,
101103
NON_CONNECTABLE_ADV_INTERVAL_MIN,
102104
NON_CONNECTABLE_ADV_INTERVAL_MAX,
103105
NULL);

samples/bluetooth/peripheral_rscs/src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ static struct bt_conn_auth_info_cb conn_auth_info_callbacks;
219219

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

225226
int main(void)
@@ -285,7 +286,7 @@ int main(void)
285286
return 0;
286287
}
287288

288-
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
289+
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
289290
if (err) {
290291
printk("Advertising failed to start (err %d)\n", err);
291292
return 0;

0 commit comments

Comments
 (0)