Skip to content

Commit 5b63d5d

Browse files
committed
samples: Bluetooth: Broadcast multiple legacy and extended advertising
Update broadcaster_multiple sample to start multiple advertising sets of type legacy and extended advertising. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent f3cffe8 commit 5b63d5d

File tree

9 files changed

+199
-54
lines changed

9 files changed

+199
-54
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Increased to 4 gives one each of legacy, 2M, 1M and Coded PHY advertising sets
2+
CONFIG_BT_EXT_ADV_MAX_ADV_SET=4
3+
4+
# Use Zephyr Bluetooth Low Energy Controller
5+
CONFIG_BT_LL_SW_SPLIT=y
6+
7+
# Enable Coded PHY support in Zephyr Controller, if testing 4 advertising sets
8+
CONFIG_BT_CTLR_PHY_CODED=y
9+
10+
# Zephyr Bluetooth LE Controller will need to use chain PDUs when AD data
11+
# length > 191 bytes
12+
# - 31 bytes will use 22 bytes for the default name in this sample plus 9 bytes
13+
# for manufacturer data
14+
# - 191 bytes will use 22 bytes for the default name in this sample plus 169
15+
# bytes for manufacturer data
16+
# - 277 bytes will use 22 bytes for the default name in this sample plus 255
17+
# bytes for manufacturer data
18+
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=192
19+
20+
# Increase Advertising PDU buffers to number of advertising sets times the
21+
# number of chain PDUs per advertising set when using Zephyr Bluetooth LE
22+
# Controller
23+
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
24+
CONFIG_BT_CTLR_ADV_RESERVE_MAX=n
25+
CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=6
26+
CONFIG_BT_CTLR_ADV_DATA_CHAIN=y
27+
28+
# Code size reduction
29+
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
30+
CONFIG_LTO=y
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
CONFIG_BT=y
22
CONFIG_BT_BROADCASTER=y
3-
CONFIG_BT_EXT_ADV=y
4-
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
53
CONFIG_BT_DEVICE_NAME="Broadcaster Multiple"
6-
74
CONFIG_LOG=y
85

9-
# Zephyr Bluetooth LE Controller will need to use chain PDUs when AD data
10-
# length > 191 bytes
11-
# - 31 bytes will use 22 bytes for the default name in this sample plus 9 bytes
12-
# for manufacturer data
13-
# - 191 bytes will use 22 bytes for the default name in this sample plus 169
14-
# bytes for manufacturer data
15-
# - 277 bytes will use 22 bytes for the default name in this sample plus 255
16-
# bytes for manufacturer data
17-
# CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=192
6+
# Require Bluetooth Advertising Extensions Feature
7+
CONFIG_BT_EXT_ADV=y
188

19-
# Increase Advertising PDU buffers to number of advertising sets times the
20-
# number of chain PDUs per advertising set when using Zephyr Bluetooth LE
21-
# Controller
22-
# CONFIG_BT_CTLR_ADVANCED_FEATURES=y
23-
# CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2
9+
# Increase to 4; gives one each of legacy, 2M, 1M and Coded PHY advertising sets, if supported by
10+
# Controller implementation
11+
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
sample:
22
name: Bluetooth Multiple Extended Advertising Broadcaster
33
tests:
4-
sample.bluetooth.multiple_broadcast:
4+
sample.bluetooth.broadcaster_multiple:
55
harness: bluetooth
6+
tags: bluetooth
67
platform_allow:
78
- qemu_cortex_m3
89
- qemu_x86
10+
integration_platforms:
11+
- qemu_cortex_m3
12+
sample.bluetooth.broadcaster_multiple.bt_ll_sw_split:
13+
harness: bluetooth
14+
tags: bluetooth
15+
extra_args:
16+
- EXTRA_CONF_FILE=overlay-bt_ll_sw_split.conf
17+
platform_allow:
918
- nrf51dk/nrf51822
1019
- nrf52_bsim
1120
- nrf52dk/nrf52832
12-
tags: bluetooth
21+
- nrf52840dk/nrf52840
1322
integration_platforms:
14-
- qemu_cortex_m3
23+
- nrf52dk/nrf52832
24+
- nrf52840dk/nrf52840

samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,44 +54,95 @@
5454
*/
5555
static uint8_t mfg_data[BT_MFG_DATA_LEN] = { 0xFF, 0xFF, };
5656

57-
static const struct bt_data ad[] = {
57+
static const struct bt_data ad_long[] = {
5858
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)),
5959
#if CONFIG_BT_CTLR_ADV_DATA_LEN_MAX > 255
6060
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)),
6161
#endif
6262
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
6363
};
6464

65+
static const struct bt_data ad_short[] = {
66+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
67+
};
68+
6569
static struct bt_le_ext_adv *adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET];
6670

6771
int broadcaster_multiple(void)
6872
{
69-
struct bt_le_adv_param adv_param = {
70-
.id = BT_ID_DEFAULT,
71-
.sid = 0U, /* Supply unique SID when creating advertising set */
72-
.secondary_max_skip = 0U,
73-
.options = BT_LE_ADV_OPT_EXT_ADV,
74-
.interval_min = BT_GAP_ADV_FAST_INT_MIN_2,
75-
.interval_max = BT_GAP_ADV_FAST_INT_MAX_2,
76-
.peer = NULL,
77-
};
7873
int err;
7974

75+
/* Create and start Advertising Sets */
8076
for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) {
77+
struct bt_le_adv_param adv_param = {
78+
.id = BT_ID_DEFAULT,
79+
.sid = 0U, /* Supply unique SID when creating advertising set */
80+
.secondary_max_skip = 0U,
81+
.options = BT_LE_ADV_OPT_EXT_ADV,
82+
.interval_min = BT_GAP_ADV_FAST_INT_MIN_2,
83+
.interval_max = BT_GAP_ADV_FAST_INT_MAX_2,
84+
.peer = NULL,
85+
};
86+
const struct adv_param_config {
87+
uint32_t options;
88+
const struct bt_data *ad;
89+
size_t ad_size;
90+
} param_config[] = {
91+
{ /* Use 1M legacy PDU */
92+
.options = BT_LE_ADV_OPT_NONE,
93+
.ad = ad_short,
94+
.ad_size = ARRAY_SIZE(ad_short),
95+
},
96+
{ /* Use 2M auxiliary PDU */
97+
.options = BT_LE_ADV_OPT_EXT_ADV,
98+
.ad = ad_long,
99+
.ad_size = ARRAY_SIZE(ad_long),
100+
},
101+
{ /* Use 1M auxiliary PDU */
102+
.options = BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_NO_2M,
103+
.ad = ad_long,
104+
.ad_size = ARRAY_SIZE(ad_long),
105+
},
106+
{ /* Use Coded PHY */
107+
.options = BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED,
108+
.ad = ad_long,
109+
.ad_size = ARRAY_SIZE(ad_long),
110+
}};
111+
const struct bt_data *ad;
112+
size_t ad_size;
113+
81114
/* Use advertising set instance index as SID */
82115
adv_param.sid = index;
83116

117+
/* Advertising set options, AD and AD array size */
118+
const struct adv_param_config *config =
119+
&param_config[index % ARRAY_SIZE(param_config)];
120+
121+
adv_param.options = config->options;
122+
ad = config->ad;
123+
ad_size = config->ad_size;
124+
125+
ext_adv_create_retry:
84126
/* Create a non-connectable advertising set */
85127
err = bt_le_ext_adv_create(&adv_param, NULL, &adv[index]);
86128
if (err) {
87-
printk("Failed to create advertising set %d (err %d)\n",
88-
index, err);
129+
/* Failed creating Coded PHY advertising set? */
130+
if ((adv_param.options & BT_LE_ADV_OPT_CODED) != 0U) {
131+
printk("Failed to create advertising set %d with Coded PHY "
132+
"(err %d), retry without...\n", index, err);
133+
134+
/* Retry with non-Coded PHY advertising set */
135+
adv_param.options &= ~BT_LE_ADV_OPT_CODED;
136+
137+
goto ext_adv_create_retry;
138+
}
139+
140+
printk("Failed to create advertising set %d (err %d)\n", index, err);
89141
return err;
90142
}
91143

92144
/* Set extended advertising data */
93-
err = bt_le_ext_adv_set_data(adv[index], ad, ARRAY_SIZE(ad),
94-
NULL, 0);
145+
err = bt_le_ext_adv_set_data(adv[index], ad, ad_size, NULL, 0);
95146
if (err) {
96147
printk("Failed to set advertising data for set %d "
97148
"(err %d)\n", index, err);

samples/bluetooth/observer/src/observer.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <zephyr/bluetooth/bluetooth.h>
1010
#include <zephyr/bluetooth/hci.h>
1111

12-
#define NAME_LEN 30
13-
1412
static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
1513
struct net_buf_simple *ad)
1614
{
@@ -22,6 +20,8 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
2220
}
2321

2422
#if defined(CONFIG_BT_EXT_ADV)
23+
#define NAME_LEN 30
24+
2525
static bool data_cb(struct bt_data *data, void *user_data)
2626
{
2727
char *name = user_data;
@@ -86,7 +86,7 @@ static struct bt_le_scan_cb scan_callbacks = {
8686
};
8787
#endif /* CONFIG_BT_EXT_ADV */
8888

89-
int observer_start(void)
89+
static int scan_start(void)
9090
{
9191
/* 30 ms continuous active scanning with duplicate filtering. */
9292
struct bt_le_scan_param scan_param = {
@@ -98,16 +98,45 @@ int observer_start(void)
9898
int err;
9999

100100
#if defined(CONFIG_BT_EXT_ADV)
101-
bt_le_scan_cb_register(&scan_callbacks);
102-
printk("Registered scan callbacks\n");
101+
scan_param.options |= BT_LE_SCAN_OPT_CODED;
103102
#endif /* CONFIG_BT_EXT_ADV */
104103

104+
scan_start_retry:
105+
printk("Starting scanning...\n");
105106
err = bt_le_scan_start(&scan_param, device_found);
106107
if (err) {
108+
if ((scan_param.options & BT_LE_SCAN_OPT_CODED) != 0U) {
109+
printk("Failed to start scanning with Coded PHY (err %d), retrying "
110+
"without...\n", err);
111+
112+
scan_param.options &= ~BT_LE_SCAN_OPT_CODED;
113+
114+
goto scan_start_retry;
115+
}
116+
107117
printk("Start scanning failed (err %d)\n", err);
118+
119+
return err;
120+
}
121+
122+
printk("success.\n");
123+
124+
return 0;
125+
}
126+
127+
int observer_start(void)
128+
{
129+
int err;
130+
131+
#if defined(CONFIG_BT_EXT_ADV)
132+
bt_le_scan_cb_register(&scan_callbacks);
133+
printk("Registered scan callbacks\n");
134+
#endif /* CONFIG_BT_EXT_ADV */
135+
136+
err = scan_start();
137+
if (err != 0) {
108138
return err;
109139
}
110-
printk("Started scanning...\n");
111140

112141
return 0;
113142
}

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,14 @@ void ull_adv_aux_lll_auxptr_fill(struct pdu_adv *pdu, struct lll_adv *adv)
31783178
}
31793179

31803180
#else /* !CONFIG_BT_TICKER_EXT_EXPIRE_INFO */
3181+
3182+
/* Maximum retries when ticks_current can change, example, when 3 extended advertising sets
3183+
* configured, and 1 advertising set is calculating the aux_offset, 2 other advertising sets and 2
3184+
* scanning instances can expire changing the ticks_current value while we are querying for
3185+
* aux_offset value.
3186+
*/
3187+
#define MAX_RETRY_TICKS_CURRENT_CHANGE ((CONFIG_BT_CTLR_ADV_AUX_SET) - 1U + 2U)
3188+
31813189
static void mfy_aux_offset_get(void *param)
31823190
{
31833191
struct pdu_adv_aux_ptr *aux_ptr;
@@ -3205,7 +3213,7 @@ static void mfy_aux_offset_get(void *param)
32053213
id = TICKER_NULL;
32063214
ticks_to_expire = 0U;
32073215
ticks_current = adv->ticks_at_expire;
3208-
retry = 4U; /* Assert on 2 other adv set ticks_current change, and 2 scanners expiring */
3216+
retry = MAX_RETRY_TICKS_CURRENT_CHANGE;
32093217
do {
32103218
uint32_t volatile ret_cb;
32113219
uint32_t ticks_previous;

tests/bsim/bluetooth/host/adv/chain/prj.conf

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
CONFIG_BT=y
2+
3+
# Broadcaster
24
CONFIG_BT_BROADCASTER=y
3-
CONFIG_BT_OBSERVER=y
45
CONFIG_BT_EXT_ADV=y
5-
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
6+
CONFIG_BT_EXT_ADV_MAX_ADV_SET=4
67
CONFIG_BT_DEVICE_NAME="Broadcaster Multiple"
78

89
# Enable Advertising Data chaining in Zephyr Bluetooth LE Controller
910
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
11+
CONFIG_BT_CTLR_ADV_RESERVE_MAX=n
1012
CONFIG_BT_CTLR_ADV_DATA_CHAIN=y
1113

1214
# Zephyr Bluetooth LE Controller will need to use chain PDUs when AD data
@@ -22,19 +24,36 @@ CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650
2224
# Increase Advertising PDU buffers to number of advertising sets times the
2325
# number of chain PDUs per advertising set when using Zephyr Bluetooth LE
2426
# Controller
25-
CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2
27+
CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=6
28+
29+
# Enable Coded PHY
30+
CONFIG_BT_CTLR_PHY_CODED=y
31+
32+
# Observer
33+
CONFIG_BT_OBSERVER=y
34+
CONFIG_BT_EXT_ADV=y
2635

2736
# Maximum Extended Scanning buffer size
2837
CONFIG_BT_EXT_SCAN_BUF_SIZE=1650
2938

30-
# Set maximum scan data length for Extended Scanning in Bluetooth LE Controller
31-
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650
32-
3339
# The Zephyr Controller does not combine all the 1650 bytes before
3440
# fragmenting into 8 HCI reports, if a PDU has 255 bytes,
3541
# it will generate 2 HCI reports and so we need to reserve 16 buffers
3642
CONFIG_BT_BUF_EVT_RX_COUNT=16
3743

44+
# Set maximum scan data length for Extended Scanning in Bluetooth LE Controller
45+
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650
46+
3847
# Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain
3948
# of PDUs
4049
CONFIG_BT_CTLR_RX_BUFFERS=9
50+
51+
# Enable scanning interleaved extended advertising in Zephyr Bluetooth LE
52+
# Controller
53+
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
54+
CONFIG_BT_CTLR_SCAN_AUX_SET=3
55+
CONFIG_BT_CTLR_LOW_LAT_ULL=y
56+
# CONFIG_BT_CTLR_SCAN_AUX_USE_CHAINS=y
57+
# CONFIG_BT_CTLR_SCAN_AUX_CHAIN_COUNT=3
58+
CONFIG_BT_CTLR_SCAN_UNRESERVED=y
59+
# CONFIG_BT_TICKER_EXT_EXPIRE_INFO=y

0 commit comments

Comments
 (0)