diff --git a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c index 2f03528093fb6e..4665eed3ca8709 100644 --- a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c +++ b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -86,7 +87,7 @@ static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason) chan, reason); connected_bis--; - if (connected_bis == big_create_param.num_bis) { + if (connected_bis == 0) { k_sem_give(&sem_big_term); } } @@ -681,7 +682,7 @@ static int create_big(struct bt_le_ext_adv **adv, struct bt_iso_big **big) 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; + return err; } LOG_INF("Setting Periodic Advertising parameters"); @@ -739,32 +740,41 @@ static int delete_big(struct bt_le_ext_adv **adv, struct bt_iso_big **big) { int err; - err = bt_iso_big_terminate(*big); - if (err != 0) { - LOG_ERR("Failed to terminate BIG (err %d)", err); - return err; + if (*big != NULL) { + err = bt_iso_big_terminate(*big); + if (err != 0) { + LOG_ERR("Failed to terminate BIG (err %d)", err); + return err; + } + err = k_sem_take(&sem_big_term, K_FOREVER); + if (err != 0) { + LOG_ERR("failed to take sem_big_term (err %d)", err); + return err; + } + *big = NULL; } - *big = NULL; - err = bt_le_per_adv_stop(*adv); - if (err != 0) { - LOG_ERR("Failed to stop periodic advertising (err %d)", err); - return err; - } + if (*adv != NULL) { + err = bt_le_per_adv_stop(*adv); + if (err != 0) { + LOG_ERR("Failed to stop periodic advertising (err %d)", err); + return err; + } - err = bt_le_ext_adv_stop(*adv); - if (err != 0) { - LOG_ERR("Failed to stop advertising (err %d)", err); - return err; - } + err = bt_le_ext_adv_stop(*adv); + if (err != 0) { + LOG_ERR("Failed to stop advertising (err %d)", err); + return err; + } - err = bt_le_ext_adv_delete(*adv); - if (err != 0) { - LOG_ERR("Failed to delete advertiser (err %d)", err); - return err; - } + err = bt_le_ext_adv_delete(*adv); + if (err != 0) { + LOG_ERR("Failed to delete advertiser (err %d)", err); + return err; + } - *adv = NULL; + *adv = NULL; + } return 0; } @@ -810,7 +820,15 @@ int test_run_broadcaster(void) err = create_big(&adv, &big); if (err) { + int del_err; + LOG_ERR("Could not create BIG: %d", err); + + del_err = delete_big(&adv, &big); + if (del_err) { + LOG_ERR("Could not delete BIG: %d", del_err); + } + return err; }