Skip to content

Commit 79a334b

Browse files
committed
tests: Bluetooth: Audio: Add common start_broadcast_adv
Add a common function, start_broadcast_adv, to start broadcast advertisement in the LE Audio BSIM tests. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent c40e77e commit 79a334b

File tree

5 files changed

+46
-71
lines changed

5 files changed

+46
-71
lines changed

tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,6 @@ static void setup_extended_adv_data(struct bt_cap_broadcast_source *source,
248248
}
249249
}
250250

251-
static void start_extended_adv(struct bt_le_ext_adv *adv)
252-
{
253-
int err;
254-
255-
/* Start extended advertising */
256-
err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
257-
if (err) {
258-
FAIL("Failed to start extended advertising: %d\n", err);
259-
return;
260-
}
261-
262-
/* Enable Periodic Advertising */
263-
err = bt_le_per_adv_start(adv);
264-
if (err) {
265-
FAIL("Failed to enable periodic advertising: %d\n", err);
266-
return;
267-
}
268-
}
269-
270251
static void stop_and_delete_extended_adv(struct bt_le_ext_adv *adv)
271252
{
272253
int err;
@@ -662,7 +643,7 @@ static void test_main_cap_initiator_broadcast(void)
662643

663644
setup_extended_adv_data(broadcast_source, adv);
664645

665-
start_extended_adv(adv);
646+
start_broadcast_adv(adv);
666647

667648
/* Wait for all to be started */
668649
printk("Waiting for broadcast_streams to be started\n");
@@ -708,7 +689,7 @@ static void test_main_cap_initiator_broadcast_inval(void)
708689

709690
setup_extended_adv_data(broadcast_source, adv);
710691

711-
start_extended_adv(adv);
692+
start_broadcast_adv(adv);
712693

713694
/* Wait for all to be started */
714695
printk("Waiting for broadcast_streams to be started\n");
@@ -754,7 +735,7 @@ static void test_main_cap_initiator_broadcast_update(void)
754735

755736
setup_extended_adv_data(broadcast_source, adv);
756737

757-
start_extended_adv(adv);
738+
start_broadcast_adv(adv);
758739

759740
/* Wait for all to be started */
760741
printk("Waiting for broadcast_streams to be started\n");
@@ -848,7 +829,7 @@ static int test_cap_initiator_ac(const struct cap_initiator_ac_param *param)
848829

849830
test_broadcast_audio_start(broadcast_source, adv);
850831
setup_extended_adv_data(broadcast_source, adv);
851-
start_extended_adv(adv);
832+
start_broadcast_adv(adv);
852833

853834
/* Wait for all to be started */
854835
printk("Waiting for broadcast_streams to be started\n");

tests/bsim/bluetooth/audio/src/common.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,45 @@ void setup_broadcast_adv(struct bt_le_ext_adv **adv)
247247
}
248248
}
249249

250+
void start_broadcast_adv(struct bt_le_ext_adv *adv)
251+
{
252+
char addr_str[BT_ADDR_LE_STR_LEN];
253+
struct bt_le_ext_adv_info info;
254+
int err;
255+
256+
err = bt_le_ext_adv_get_info(adv, &info);
257+
if (err != 0) {
258+
FAIL("Failed to get adv info: %d\n", err);
259+
return;
260+
}
261+
262+
if (info.per_adv_state == BT_LE_PER_ADV_STATE_NONE) {
263+
FAIL("Cannot start periodic advertising for non-periodic advertising set");
264+
return;
265+
}
266+
267+
if (info.ext_adv_state == BT_LE_EXT_ADV_STATE_CREATED) {
268+
/* Start extended advertising */
269+
err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
270+
if (err != 0) {
271+
FAIL("Failed to start extended advertising: %d\n", err);
272+
return;
273+
}
274+
}
275+
276+
if (info.per_adv_state == BT_LE_PER_ADV_STATE_CONFIGURED) {
277+
/* Enable Periodic Advertising */
278+
err = bt_le_per_adv_start(adv);
279+
if (err != 0) {
280+
FAIL("Failed to enable periodic advertising: %d\n", err);
281+
return;
282+
}
283+
}
284+
285+
bt_addr_le_to_str(info.addr, addr_str, sizeof(addr_str));
286+
printk("Started advertising with addr %s\n", addr_str);
287+
}
288+
250289
void test_tick(bs_time_t HW_device_time)
251290
{
252291
if (bst_result != Passed) {

tests/bsim/bluetooth/audio/src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ extern uint8_t csip_rsi[BT_CSIP_RSI_SIZE];
140140
void disconnected(struct bt_conn *conn, uint8_t reason);
141141
void setup_connectable_adv(struct bt_le_ext_adv **ext_adv);
142142
void setup_broadcast_adv(struct bt_le_ext_adv **adv);
143+
void start_broadcast_adv(struct bt_le_ext_adv *adv);
143144
void test_tick(bs_time_t HW_device_time);
144145
void test_init(void);
145146
uint16_t get_dev_cnt(void);

tests/bsim/bluetooth/audio/src/gmap_ugg_test.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,25 +1066,6 @@ static void setup_extended_adv_data(struct bt_cap_broadcast_source *source,
10661066
}
10671067
}
10681068

1069-
static void start_extended_adv(struct bt_le_ext_adv *adv)
1070-
{
1071-
int err;
1072-
1073-
/* Start extended advertising */
1074-
err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
1075-
if (err) {
1076-
FAIL("Failed to start extended advertising: %d\n", err);
1077-
return;
1078-
}
1079-
1080-
/* Enable Periodic Advertising */
1081-
err = bt_le_per_adv_start(adv);
1082-
if (err) {
1083-
FAIL("Failed to enable periodic advertising: %d\n", err);
1084-
return;
1085-
}
1086-
}
1087-
10881069
static void stop_and_delete_extended_adv(struct bt_le_ext_adv *adv)
10891070
{
10901071
int err;
@@ -1222,7 +1203,7 @@ static int test_gmap_ugg_broadcast_ac(const struct gmap_broadcast_ac_param *para
12221203

12231204
broadcast_audio_start(broadcast_source, adv);
12241205
setup_extended_adv_data(broadcast_source, adv);
1225-
start_extended_adv(adv);
1206+
start_broadcast_adv(adv);
12261207

12271208
/* Wait for all to be started */
12281209
printk("Waiting for broadcast_streams to be started\n");

tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,6 @@ static int setup_extended_adv_data(struct bt_cap_broadcast_source *source,
175175
return 0;
176176
}
177177

178-
static int start_extended_adv(struct bt_le_ext_adv *adv)
179-
{
180-
int err;
181-
182-
/* Start extended advertising */
183-
err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
184-
if (err) {
185-
printk("Failed to start extended advertising: %d\n", err);
186-
187-
return err;
188-
}
189-
190-
/* Enable Periodic Advertising */
191-
err = bt_le_per_adv_start(adv);
192-
if (err) {
193-
printk("Failed to enable periodic advertising: %d\n", err);
194-
195-
return err;
196-
}
197-
198-
return 0;
199-
}
200-
201178
static int stop_extended_adv(struct bt_le_ext_adv *adv)
202179
{
203180
int err;
@@ -289,11 +266,7 @@ static void test_main(void)
289266
FAIL("Public Broadcast source failed\n");
290267
}
291268

292-
err = start_extended_adv(adv);
293-
if (err != 0) {
294-
printk("Unable to start extended advertiser: %d\n", err);
295-
FAIL("Public Broadcast source failed\n");
296-
}
269+
start_broadcast_adv(adv);
297270

298271
k_sem_take(&sem_started, SEM_TIMEOUT);
299272

0 commit comments

Comments
 (0)