1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/bluetooth/bluetooth.h>
9 #include <zephyr/bluetooth/hci.h>
10 
11 #include <zephyr/ztest.h>
12 
13 #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
14 #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
15 
16 #define TIMEOUT_MS 300000 /* 5 minutes */
17 
18 static const struct bt_data ad[] = {
19 	BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
20 };
21 
22 /* Set Scan Response data */
23 static const struct bt_data sd[] = {
24 	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
25 };
26 
27 ZTEST_SUITE(adv_tests, NULL, NULL, NULL, NULL, NULL);
28 
ZTEST(adv_tests,test_adv_fast_ad_data_update)29 ZTEST(adv_tests, test_adv_fast_ad_data_update)
30 {
31 	int err;
32 
33 	printk("Starting Beacon Demo\n");
34 
35 	/* Initialize the Bluetooth Subsystem */
36 	err = bt_enable(NULL);
37 	zassert_equal(err, 0, "Bluetooth init failed (err %d)\n", err);
38 
39 	printk("Bluetooth initialized\n");
40 
41 	/* Start advertising */
42 	err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad),
43 			      sd, ARRAY_SIZE(sd));
44 	zassert_equal(err, 0, "Advertising failed to start (err %d)\n", err);
45 
46 	printk("Advertising started\n");
47 
48 	while (k_uptime_get() < TIMEOUT_MS) {
49 		err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad),
50 					    sd, ARRAY_SIZE(sd));
51 		zassert_equal(err, 0, "Update adv data failed (err %d)\n", err);
52 	}
53 }
54