From 7bc63985af7e3f274ca4b09a325da0ce0892a826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Thu, 18 Apr 2024 14:32:20 +0200 Subject: [PATCH] Bluetooth: Samples: Remove uses of auto name in AD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The advertiser options to automatically add the name in the scan response and the advertising data will be deprecated. Update the samples that were using those options by explicitly adding the device name in the advertising data or the scan response data. Signed-off-by: Théo Battrel --- samples/bluetooth/broadcast_audio_sink/src/main.c | 4 +++- .../bluetooth/broadcast_audio_source/src/main.c | 12 +++++++++++- .../src/broadcaster_multiple.c | 3 ++- samples/bluetooth/direct_adv/src/main.c | 3 ++- .../direction_finding_connectionless_tx/src/main.c | 13 +++++++++++-- .../direction_finding_peripheral/src/main.c | 3 ++- samples/bluetooth/eddystone/src/main.c | 8 ++++++-- .../bluetooth/extended_adv/advertiser/src/main.c | 13 ++++++++++++- samples/bluetooth/hap_ha/src/main.c | 3 ++- samples/bluetooth/hci_pwr_ctrl/src/main.c | 8 ++++++-- samples/bluetooth/iso_broadcast/src/main.c | 13 ++++++++++++- .../iso_broadcast_benchmark/src/broadcaster.c | 13 ++++++++++++- .../bluetooth/iso_connected_benchmark/src/main.c | 10 ++++++---- .../peripheral/src/peripheral_mtu_update.c | 7 ++++--- samples/bluetooth/periodic_adv/src/main.c | 13 ++++++++++++- samples/bluetooth/periodic_adv_conn/src/main.c | 14 +++++++++++++- samples/bluetooth/periodic_sync_rsp/src/main.c | 10 ++++++---- samples/bluetooth/peripheral/src/main.c | 6 +++++- .../bluetooth/peripheral_accept_list/src/main.c | 5 +++-- samples/bluetooth/peripheral_csc/src/main.c | 6 +++++- samples/bluetooth/peripheral_dis/src/main.c | 6 +++++- samples/bluetooth/peripheral_esp/src/main.c | 6 +++++- .../src/peripheral_gatt_write.c | 6 +++++- samples/bluetooth/peripheral_hids/src/main.c | 6 +++++- samples/bluetooth/peripheral_hr/src/main.c | 6 +++++- samples/bluetooth/peripheral_ht/src/main.c | 6 +++++- .../peripheral_identity/src/peripheral_identity.c | 7 +++++-- samples/bluetooth/peripheral_iso/src/main.c | 6 +++++- samples/bluetooth/peripheral_past/src/main.c | 6 +++++- samples/bluetooth/peripheral_sc_only/src/main.c | 6 +++++- .../bluetooth/public_broadcast_source/src/main.c | 14 +++++++++++++- samples/bluetooth/tmap_bms/src/cap_initiator.c | 13 ++++++++++++- samples/bluetooth/tmap_peripheral/src/main.c | 3 ++- samples/bluetooth/unicast_audio_server/src/main.c | 3 ++- samples/boards/bbc_microbit/pong/src/ble.c | 8 ++++++-- samples/boards/reel_board/mesh_badge/src/main.c | 7 +++++-- samples/subsys/logging/ble_backend/src/main.c | 6 +++++- samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c | 6 +++++- 38 files changed, 235 insertions(+), 53 deletions(-) diff --git a/samples/bluetooth/broadcast_audio_sink/src/main.c b/samples/bluetooth/broadcast_audio_sink/src/main.c index d34a373a4b5..ae55ca13b12 100644 --- a/samples/bluetooth/broadcast_audio_sink/src/main.c +++ b/samples/bluetooth/broadcast_audio_sink/src/main.c @@ -1349,11 +1349,13 @@ static int start_adv(void) BT_UUID_16_ENCODE(BT_UUID_BASS_VAL), BT_UUID_16_ENCODE(BT_UUID_PACS_VAL)), BT_DATA_BYTES(BT_DATA_SVC_DATA16, BT_UUID_16_ENCODE(BT_UUID_BASS_VAL)), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, + sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; int err; /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, &ext_adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &ext_adv); if (err != 0) { printk("Failed to create advertising set (err %d)\n", err); diff --git a/samples/bluetooth/broadcast_audio_source/src/main.c b/samples/bluetooth/broadcast_audio_source/src/main.c index c63a1337992..dee7de02a8a 100644 --- a/samples/bluetooth/broadcast_audio_source/src/main.c +++ b/samples/bluetooth/broadcast_audio_source/src/main.c @@ -23,7 +23,7 @@ BUILD_ASSERT(strlen(CONFIG_BROADCAST_CODE) <= BT_AUDIO_BROADCAST_CODE_SIZE, * interval. */ #define BT_LE_EXT_ADV_CUSTOM \ - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_USE_NAME, 0x0080, 0x0080, NULL) + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, 0x0080, 0x0080, NULL) /* When BROADCAST_ENQUEUE_COUNT > 1 we can enqueue enough buffers to ensure that * the controller is never idle @@ -432,6 +432,10 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source) return 0; } +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + int main(void) { struct bt_le_ext_adv *adv; @@ -501,6 +505,12 @@ int main(void) return 0; } + 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_DEFAULT); if (err) { diff --git a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c index d4ce51c4f25..8da6984ee55 100644 --- a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c +++ b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c @@ -59,6 +59,7 @@ static const struct bt_data ad[] = { #if CONFIG_BT_CTLR_ADV_DATA_LEN_MAX > 255 BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), #endif + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; static struct bt_le_ext_adv *adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET]; @@ -69,7 +70,7 @@ int broadcaster_multiple(void) .id = BT_ID_DEFAULT, .sid = 0U, /* Supply unique SID when creating advertising set */ .secondary_max_skip = 0U, - .options = (BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_USE_NAME), + .options = BT_LE_ADV_OPT_EXT_ADV, .interval_min = BT_GAP_ADV_FAST_INT_MIN_2, .interval_max = BT_GAP_ADV_FAST_INT_MAX_2, .peer = NULL, diff --git a/samples/bluetooth/direct_adv/src/main.c b/samples/bluetooth/direct_adv/src/main.c index c8ebda0df9b..b277cd4205a 100644 --- a/samples/bluetooth/direct_adv/src/main.c +++ b/samples/bluetooth/direct_adv/src/main.c @@ -76,6 +76,7 @@ BT_GATT_SERVICE_DEFINE(primary_service, 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, BT_UUID_CUSTOM_SERVICE_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) @@ -127,7 +128,7 @@ static void bt_ready(void) adv_param.options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; err = bt_le_adv_start(&adv_param, NULL, 0, NULL, 0); } else { - 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) { diff --git a/samples/bluetooth/direction_finding_connectionless_tx/src/main.c b/samples/bluetooth/direction_finding_connectionless_tx/src/main.c index f00d42d5ab5..ef6a89b8852 100644 --- a/samples/bluetooth/direction_finding_connectionless_tx/src/main.c +++ b/samples/bluetooth/direction_finding_connectionless_tx/src/main.c @@ -31,8 +31,7 @@ static struct bt_le_ext_adv *adv_set; static struct bt_le_adv_param param = BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV | - BT_LE_ADV_OPT_USE_IDENTITY | - BT_LE_ADV_OPT_USE_NAME, + BT_LE_ADV_OPT_USE_IDENTITY, BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL); @@ -65,6 +64,10 @@ struct bt_df_adv_cte_tx_param cte_params = { .cte_len = CTE_LEN, #endif /* CONFIG_BT_DF_CTE_TX_AOD */ }; +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) { @@ -97,6 +100,12 @@ int main(void) } printk("success\n"); + 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("Update CTE params..."); err = bt_df_set_adv_cte_tx_param(adv_set, &cte_params); if (err) { diff --git a/samples/bluetooth/direction_finding_peripheral/src/main.c b/samples/bluetooth/direction_finding_peripheral/src/main.c index 3f921d21485..c122ae21a14 100644 --- a/samples/bluetooth/direction_finding_peripheral/src/main.c +++ b/samples/bluetooth/direction_finding_peripheral/src/main.c @@ -26,6 +26,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 */ @@ -99,7 +100,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; diff --git a/samples/bluetooth/eddystone/src/main.c b/samples/bluetooth/eddystone/src/main.c index 86a99aaac4c..b649e636ab6 100644 --- a/samples/bluetooth/eddystone/src/main.c +++ b/samples/bluetooth/eddystone/src/main.c @@ -38,6 +38,10 @@ static const struct bt_data ad[] = { 0xdf, 0x4b, 0xd3, 0x8e, 0x00, 0x75, 0xc8, 0xa3), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + /* Eddystone Service Variables */ /* Service UUID a3c87500-8ed3-4bdf-8a39-a01bebede295 */ static const struct bt_uuid_128 eds_uuid = BT_UUID_INIT_128( @@ -427,7 +431,7 @@ static int eds_slot_restart(struct eds_slot *slot, uint8_t type) addr = oob.addr; } - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), + err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0); } else { size_t count = 1; @@ -631,7 +635,7 @@ static void bt_ready(int err) printk("Bluetooth initialized\n"); /* Start advertising */ - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/extended_adv/advertiser/src/main.c b/samples/bluetooth/extended_adv/advertiser/src/main.c index 915e61b9366..be51694fd1a 100644 --- a/samples/bluetooth/extended_adv/advertiser/src/main.c +++ b/samples/bluetooth/extended_adv/advertiser/src/main.c @@ -84,6 +84,10 @@ static int start_advertising(struct bt_le_ext_adv *adv) return err; } +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + int main(void) { int err; @@ -99,12 +103,19 @@ int main(void) } /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, &adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); return err; } + /* Set advertising data to have complete local name set */ + 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; + } + err = start_advertising(adv); if (err) { return err; diff --git a/samples/bluetooth/hap_ha/src/main.c b/samples/bluetooth/hap_ha/src/main.c index 9c57bbefbcb..205feceb0b8 100644 --- a/samples/bluetooth/hap_ha/src/main.c +++ b/samples/bluetooth/hap_ha/src/main.c @@ -45,6 +45,7 @@ static const struct bt_data ad[] = { BT_DATA(BT_DATA_CSIS_RSI, csis_rsi_addata, ARRAY_SIZE(csis_rsi_addata)), #endif /* CONFIG_BT_CSIP_SET_MEMBER */ BT_DATA(BT_DATA_SVC_DATA16, unicast_server_addata, ARRAY_SIZE(unicast_server_addata)), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; static struct k_work_delayable adv_work; @@ -100,7 +101,7 @@ static void adv_work_handler(struct k_work *work) if (ext_adv == NULL) { /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, &adv_cb, &ext_adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, &adv_cb, &ext_adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); } diff --git a/samples/bluetooth/hci_pwr_ctrl/src/main.c b/samples/bluetooth/hci_pwr_ctrl/src/main.c index b18501016da..74318525753 100644 --- a/samples/bluetooth/hci_pwr_ctrl/src/main.c +++ b/samples/bluetooth/hci_pwr_ctrl/src/main.c @@ -29,6 +29,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_HRS_VAL)), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + #define DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) #define DEVICE_BEACON_TXPOWER_NUM 8 @@ -39,7 +43,7 @@ static K_THREAD_STACK_DEFINE(pwr_thread_stack, 512); static const int8_t txpower[DEVICE_BEACON_TXPOWER_NUM] = {4, 0, -3, -8, -15, -18, -23, -30}; static const struct bt_le_adv_param *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, 0x0020, 0x0020, NULL); static void read_conn_rssi(uint16_t handle, int8_t *rssi) @@ -206,7 +210,7 @@ static void bt_ready(int err) /* Start advertising */ err = bt_le_adv_start(param, ad, ARRAY_SIZE(ad), - NULL, 0); + sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/iso_broadcast/src/main.c b/samples/bluetooth/iso_broadcast/src/main.c index 1503dde2197..e0ff7dd306e 100644 --- a/samples/bluetooth/iso_broadcast/src/main.c +++ b/samples/bluetooth/iso_broadcast/src/main.c @@ -82,6 +82,10 @@ static struct bt_iso_big_create_param big_create_param = { .framing = 0, /* 0 - unframed, 1 - framed */ }; +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + int main(void) { uint32_t timeout_counter = INITIAL_TIMEOUT_COUNTER; @@ -102,12 +106,19 @@ int main(void) } /* 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 0; } + /* Set advertising data to have complete local name set */ + 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_DEFAULT); if (err) { diff --git a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c index 7ced3382fff..1040f0cd214 100644 --- a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c +++ b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c @@ -60,6 +60,10 @@ static struct bt_iso_big_create_param big_create_param = { #endif /* CONFIG_BT_ISO_TEST_PARAMS */ }; +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static void iso_connected(struct bt_iso_chan *chan) { LOG_INF("ISO Channel %p connected", chan); @@ -615,12 +619,19 @@ static int create_big(struct bt_le_ext_adv **adv, struct bt_iso_big **big) /* Create a non-connectable non-scannable advertising set */ LOG_INF("Creating Extended 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 != 0) { LOG_ERR("Failed to create advertising set (err %d)", err); return err; } + /* Set advertising data to have complete local name set */ + err = bt_le_ext_adv_set_data(*adv, ad, ARRAY_SIZE(ad), NULL, 0); + if (err) { + LOG_ERR("Failed to set advertising data (err %d)", err); + return 0; + } + LOG_INF("Setting Periodic Advertising parameters"); /* Set periodic advertising parameters */ err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); diff --git a/samples/bluetooth/iso_connected_benchmark/src/main.c b/samples/bluetooth/iso_connected_benchmark/src/main.c index a647421510e..9873a4c71f4 100644 --- a/samples/bluetooth/iso_connected_benchmark/src/main.c +++ b/samples/bluetooth/iso_connected_benchmark/src/main.c @@ -137,6 +137,10 @@ static struct bt_iso_cig_param cig_create_param = { #endif /* CONFIG_BT_ISO_TEST_PARAMS */ }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static enum benchmark_role device_role_select(void) { char role_char; @@ -1275,11 +1279,9 @@ static int run_peripheral(void) LOG_INF("Starting advertising"); err = bt_le_adv_start( - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_CONNECTABLE | - BT_LE_ADV_OPT_USE_NAME | - BT_LE_ADV_OPT_FORCE_NAME_IN_AD, + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_CONNECTABLE, BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL), - NULL, 0, NULL, 0); + NULL, 0, sd, ARRAY_SIZE(sd)); if (err != 0) { LOG_ERR("Advertising failed to start: %d", err); return err; diff --git a/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c b/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c index 66af1bf86b5..7e87dd5dfdf 100644 --- a/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c +++ b/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c @@ -23,7 +23,9 @@ static const struct bt_uuid_128 notify_characteristic_uuid = static const struct bt_data adv_ad_data[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID128_ALL, MTU_TEST_SERVICE_TYPE)}; + BT_DATA_BYTES(BT_DATA_UUID128_ALL, MTU_TEST_SERVICE_TYPE), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; static void ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { @@ -61,8 +63,7 @@ void run_peripheral_sample(uint8_t *notify_data, size_t notify_data_size, uint16 struct bt_gatt_attr *notify_crch = bt_gatt_find_by_uuid(mtu_test.attrs, 0xffff, ¬ify_characteristic_uuid.uuid); - /* Advertise. Auto include name in adv data. Connectable. */ - bt_le_adv_start(BT_LE_ADV_CONN_NAME, adv_ad_data, ARRAY_SIZE(adv_ad_data), NULL, 0); + bt_le_adv_start(BT_LE_ADV_CONN, adv_ad_data, ARRAY_SIZE(adv_ad_data), NULL, 0); bool infinite = seconds == 0; diff --git a/samples/bluetooth/periodic_adv/src/main.c b/samples/bluetooth/periodic_adv/src/main.c index bb009e62a44..6abee0c0812 100644 --- a/samples/bluetooth/periodic_adv/src/main.c +++ b/samples/bluetooth/periodic_adv/src/main.c @@ -12,6 +12,10 @@ static const struct bt_data ad[] = { BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + int main(void) { struct bt_le_ext_adv *adv; @@ -27,12 +31,19 @@ int main(void) } /* 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 0; } + /* Set advertising data to have complete local name set */ + err = bt_le_ext_adv_set_data(adv, NULL, 0, sd, ARRAY_SIZE(sd)); + 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_DEFAULT); if (err) { diff --git a/samples/bluetooth/periodic_adv_conn/src/main.c b/samples/bluetooth/periodic_adv_conn/src/main.c index 00464b43ead..63818ddbeea 100644 --- a/samples/bluetooth/periodic_adv_conn/src/main.c +++ b/samples/bluetooth/periodic_adv_conn/src/main.c @@ -160,6 +160,11 @@ static void init_bufs(void) } } +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + + int main(void) { int err; @@ -177,12 +182,19 @@ int main(void) } /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, &adv_cb, &pawr_adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN, &adv_cb, &pawr_adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); return 0; } + /* Set advertising data to have complete local name set */ + err = bt_le_ext_adv_set_data(pawr_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(pawr_adv, &per_adv_params); if (err) { diff --git a/samples/bluetooth/periodic_sync_rsp/src/main.c b/samples/bluetooth/periodic_sync_rsp/src/main.c index 24be636d8c9..8f8b1a61e6b 100644 --- a/samples/bluetooth/periodic_sync_rsp/src/main.c +++ b/samples/bluetooth/periodic_sync_rsp/src/main.c @@ -195,6 +195,10 @@ BT_CONN_CB_DEFINE(conn_cb) = { .disconnected = disconnected, }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + int main(void) { struct bt_le_per_adv_sync_transfer_param past_param; @@ -223,11 +227,9 @@ int main(void) do { err = bt_le_adv_start( - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_CONNECTABLE | - BT_LE_ADV_OPT_USE_NAME | - BT_LE_ADV_OPT_FORCE_NAME_IN_AD, + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_CONNECTABLE, BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL), - NULL, 0, NULL, 0); + NULL, 0, sd, ARRAY_SIZE(sd)); if (err && err != -EALREADY) { printk("Advertising failed to start (err %d)\n", err); diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index 7cd65636037..d0c62ec48e3 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -226,6 +226,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_CUSTOM_SERVICE_VAL), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + void mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) { printk("Updated MTU: TX: %d RX: %d bytes\n", tx, rx); @@ -287,7 +291,7 @@ static void bt_ready(void) settings_load(); } - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_accept_list/src/main.c b/samples/bluetooth/peripheral_accept_list/src/main.c index f185bfdd6c8..ddf390cb063 100644 --- a/samples/bluetooth/peripheral_accept_list/src/main.c +++ b/samples/bluetooth/peripheral_accept_list/src/main.c @@ -74,7 +74,8 @@ static const struct bt_data ad[] = { }; static const struct bt_data sd[] = { - BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_CUSTOM_SERVICE_VAL) + BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_CUSTOM_SERVICE_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) @@ -119,7 +120,7 @@ static void bt_ready(void) bond_count = 0; bt_foreach_bond(BT_ID_DEFAULT, add_bonded_addr_to_filter_list, NULL); - adv_param = *BT_LE_ADV_CONN_NAME; + adv_param = *BT_LE_ADV_CONN; /* If we have got at least one bond, activate the filter */ if (bond_count) { diff --git a/samples/bluetooth/peripheral_csc/src/main.c b/samples/bluetooth/peripheral_csc/src/main.c index d6a2f3d01e5..1a9970adb26 100644 --- a/samples/bluetooth/peripheral_csc/src/main.c +++ b/samples/bluetooth/peripheral_csc/src/main.c @@ -368,13 +368,17 @@ static const struct bt_data ad[] = { BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)) }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static void bt_ready(void) { int err; 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_dis/src/main.c b/samples/bluetooth/peripheral_dis/src/main.c index 922177ee57a..f17bbc7c51e 100644 --- a/samples/bluetooth/peripheral_dis/src/main.c +++ b/samples/bluetooth/peripheral_dis/src/main.c @@ -26,6 +26,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)), }; +static const struct bt_data sd[] = { + 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) { if (err) { @@ -96,7 +100,7 @@ int main(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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return 0; diff --git a/samples/bluetooth/peripheral_esp/src/main.c b/samples/bluetooth/peripheral_esp/src/main.c index 1375b130172..88ae192ce90 100644 --- a/samples/bluetooth/peripheral_esp/src/main.c +++ b/samples/bluetooth/peripheral_esp/src/main.c @@ -392,6 +392,10 @@ static const struct bt_data ad[] = { BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)), }; +static const struct bt_data sd[] = { + 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) { if (err) { @@ -417,7 +421,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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_gatt_write/src/peripheral_gatt_write.c b/samples/bluetooth/peripheral_gatt_write/src/peripheral_gatt_write.c index 7dcae853f01..019f8262cd6 100644 --- a/samples/bluetooth/peripheral_gatt_write/src/peripheral_gatt_write.c +++ b/samples/bluetooth/peripheral_gatt_write/src/peripheral_gatt_write.c @@ -20,6 +20,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static void mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) { printk("Updated MTU: TX: %d RX: %d bytes\n", tx, rx); @@ -62,7 +66,7 @@ uint32_t peripheral_gatt_write(uint32_t count) (void)bt_conn_auth_cb_register(&auth_callbacks); #endif /* CONFIG_BT_SMP */ - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return 0U; diff --git a/samples/bluetooth/peripheral_hids/src/main.c b/samples/bluetooth/peripheral_hids/src/main.c index 13109d40d94..ef743b7c57d 100644 --- a/samples/bluetooth/peripheral_hids/src/main.c +++ b/samples/bluetooth/peripheral_hids/src/main.c @@ -31,6 +31,10 @@ static const struct bt_data ad[] = { BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)), }; +static const struct bt_data sd[] = { + 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]; @@ -94,7 +98,7 @@ static void bt_ready(int err) settings_load(); } - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_hr/src/main.c b/samples/bluetooth/peripheral_hr/src/main.c index 135f41667e2..11b43586d53 100644 --- a/samples/bluetooth/peripheral_hr/src/main.c +++ b/samples/bluetooth/peripheral_hr/src/main.c @@ -32,6 +32,10 @@ static const struct bt_data ad[] = { BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)) }; +static const struct bt_data sd[] = { + 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) { if (err) { @@ -76,7 +80,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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_ht/src/main.c b/samples/bluetooth/peripheral_ht/src/main.c index 3f547652af6..197ee1cdaec 100644 --- a/samples/bluetooth/peripheral_ht/src/main.c +++ b/samples/bluetooth/peripheral_ht/src/main.c @@ -31,6 +31,10 @@ static const struct bt_data ad[] = { BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)), }; +static const struct bt_data sd[] = { + 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) { if (err) { @@ -58,7 +62,7 @@ static void bt_ready(void) hts_init(); - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_identity/src/peripheral_identity.c b/samples/bluetooth/peripheral_identity/src/peripheral_identity.c index ee35533b371..57956081fe3 100644 --- a/samples/bluetooth/peripheral_identity/src/peripheral_identity.c +++ b/samples/bluetooth/peripheral_identity/src/peripheral_identity.c @@ -22,6 +22,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static void adv_start(struct k_work *work) { struct bt_le_adv_param adv_param = { @@ -29,7 +33,6 @@ static void adv_start(struct k_work *work) .sid = 0, .secondary_max_skip = 0, .options = (BT_LE_ADV_OPT_CONNECTABLE | - BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_ONE_TIME), .interval_min = 0x0020, /* 20 ms */ .interval_max = 0x0020, /* 20 ms */ @@ -57,7 +60,7 @@ static void adv_start(struct k_work *work) printk("Using current id: %u\n", id_current); adv_param.id = id_current; - err = bt_le_adv_start(&adv_param, ad, ARRAY_SIZE(ad), NULL, 0); + err = bt_le_adv_start(&adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/bluetooth/peripheral_iso/src/main.c b/samples/bluetooth/peripheral_iso/src/main.c index 95f415e9503..e93b11bcf7f 100644 --- a/samples/bluetooth/peripheral_iso/src/main.c +++ b/samples/bluetooth/peripheral_iso/src/main.c @@ -22,6 +22,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), }; +static const struct bt_data sd[] = { + 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]; @@ -172,7 +176,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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return 0; diff --git a/samples/bluetooth/peripheral_past/src/main.c b/samples/bluetooth/peripheral_past/src/main.c index a3058af1755..398e691cf61 100644 --- a/samples/bluetooth/peripheral_past/src/main.c +++ b/samples/bluetooth/peripheral_past/src/main.c @@ -110,6 +110,10 @@ static struct bt_conn_cb conn_callbacks = { .disconnected = disconnected, }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + int main(void) { struct bt_le_per_adv_sync_transfer_param past_param; @@ -142,7 +146,7 @@ int main(void) return 0; } - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, NULL, 0, NULL, 0); + err = bt_le_adv_start(BT_LE_ADV_CONN, NULL, 0, sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return 0; diff --git a/samples/bluetooth/peripheral_sc_only/src/main.c b/samples/bluetooth/peripheral_sc_only/src/main.c index d9e8f646236..0b75d552427 100644 --- a/samples/bluetooth/peripheral_sc_only/src/main.c +++ b/samples/bluetooth/peripheral_sc_only/src/main.c @@ -24,6 +24,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), }; +static const struct bt_data sd[] = { + 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]; @@ -141,7 +145,7 @@ int main(void) bt_conn_auth_cb_register(&auth_cb_display); bt_conn_auth_info_cb_register(&auth_cb_info); - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return 0; diff --git a/samples/bluetooth/public_broadcast_source/src/main.c b/samples/bluetooth/public_broadcast_source/src/main.c index b9377e9f312..5ffb94d785f 100644 --- a/samples/bluetooth/public_broadcast_source/src/main.c +++ b/samples/bluetooth/public_broadcast_source/src/main.c @@ -49,6 +49,10 @@ static struct bt_bap_lc3_preset broadcast_preset_48_2_1 = BT_BAP_LC3_UNICAST_PRESET_48_2_1(BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_MEDIA); +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + struct bt_cap_initiator_broadcast_stream_param stream_params; struct bt_cap_initiator_broadcast_subgroup_param subgroup_param; struct bt_cap_initiator_broadcast_create_param create_param; @@ -124,13 +128,21 @@ static int setup_extended_adv(struct bt_le_ext_adv **adv) int err; /* 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 != 0) { printk("Unable to create extended advertising set: %d\n", err); return err; } + /* Set advertising data to have complete local name set */ + 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_DEFAULT); if (err) { diff --git a/samples/bluetooth/tmap_bms/src/cap_initiator.c b/samples/bluetooth/tmap_bms/src/cap_initiator.c index 249d31d49da..2c0019e234c 100644 --- a/samples/bluetooth/tmap_bms/src/cap_initiator.c +++ b/samples/bluetooth/tmap_bms/src/cap_initiator.c @@ -107,17 +107,28 @@ static struct bt_bap_stream_ops broadcast_stream_ops = { .sent = broadcast_sent_cb }; +static const struct bt_data ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static int setup_extended_adv(struct bt_le_ext_adv **adv) { int err; /* 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 != 0) { printk("Unable to create extended advertising set: %d\n", err); return err; } + /* Set advertising data to have complete local name set */ + 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_DEFAULT); if (err) { diff --git a/samples/bluetooth/tmap_peripheral/src/main.c b/samples/bluetooth/tmap_peripheral/src/main.c index 59aa8c70ef0..2a7ecc61759 100644 --- a/samples/bluetooth/tmap_peripheral/src/main.c +++ b/samples/bluetooth/tmap_peripheral/src/main.c @@ -62,6 +62,7 @@ static const struct bt_data ad[] = { BT_DATA(BT_DATA_SVC_DATA16, tmap_addata, ARRAY_SIZE(tmap_addata)), BT_DATA(BT_DATA_SVC_DATA16, cap_addata, ARRAY_SIZE(cap_addata)), BT_DATA(BT_DATA_SVC_DATA16, unicast_server_addata, ARRAY_SIZE(unicast_server_addata)), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; static K_SEM_DEFINE(sem_connected, 0, 1); @@ -243,7 +244,7 @@ int main(void) } printk("BAP initialized\n"); - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, &adv_cb, &adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, &adv_cb, &adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); return err; diff --git a/samples/bluetooth/unicast_audio_server/src/main.c b/samples/bluetooth/unicast_audio_server/src/main.c index 350f672b0c4..db2a76fbab6 100644 --- a/samples/bluetooth/unicast_audio_server/src/main.c +++ b/samples/bluetooth/unicast_audio_server/src/main.c @@ -67,6 +67,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_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL)), BT_DATA(BT_DATA_SVC_DATA16, unicast_server_addata, ARRAY_SIZE(unicast_server_addata)), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; #define AUDIO_DATA_TIMEOUT_US 1000000UL /* Send data every 1 second */ @@ -750,7 +751,7 @@ int main(void) } /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, &adv); + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN, NULL, &adv); if (err) { printk("Failed to create advertising set (err %d)\n", err); return 0; diff --git a/samples/boards/bbc_microbit/pong/src/ble.c b/samples/boards/bbc_microbit/pong/src/ble.c index 89f34f3585f..9f86a8e8712 100644 --- a/samples/boards/bbc_microbit/pong/src/ble.c +++ b/samples/boards/bbc_microbit/pong/src/ble.c @@ -42,6 +42,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_UUID128_ALL, PONG_SVC_UUID), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static struct bt_conn *default_conn; static const struct bt_gatt_attr *local_attr; @@ -467,8 +471,8 @@ static void ble_timeout(struct k_work *work) k_work_reschedule(&ble_work, K_NO_WAIT); break; case BLE_ADV_START: - 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), + sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/boards/reel_board/mesh_badge/src/main.c b/samples/boards/reel_board/mesh_badge/src/main.c index 49dd110ec0e..932e25f2d89 100644 --- a/samples/boards/reel_board/mesh_badge/src/main.c +++ b/samples/boards/reel_board/mesh_badge/src/main.c @@ -22,6 +22,10 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static ssize_t read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { @@ -176,8 +180,7 @@ static void bt_ready(int err) if (!mesh_is_initialized()) { /* Start advertising */ - 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), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; diff --git a/samples/subsys/logging/ble_backend/src/main.c b/samples/subsys/logging/ble_backend/src/main.c index 843ad366b51..bd11b987634 100644 --- a/samples/subsys/logging/ble_backend/src/main.c +++ b/samples/subsys/logging/ble_backend/src/main.c @@ -17,11 +17,15 @@ static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_UUID128_ALL, LOGGER_BACKEND_BLE_ADV_UUID_DATA) }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static void start_adv(void) { int err; - 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), sd, ARRAY_SIZE(sd)); if (err) { LOG_ERR("Advertising failed to start (err %d)", err); return; diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c b/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c index fa8e49ce351..7503c48a7fb 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c +++ b/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c @@ -23,13 +23,17 @@ static const struct bt_data ad[] = { 0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d), }; +static const struct bt_data sd[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), +}; + static void advertise(struct k_work *work) { int rc; bt_le_adv_stop(); - rc = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); + rc = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); if (rc) { LOG_ERR("Advertising failed to start (rc %d)", rc); return;