Skip to content

Commit

Permalink
samples: Bluetooth: Handle shutdown of iso broadcast benchmark
Browse files Browse the repository at this point in the history
The sample did not properly handle ending the broadcast and setting
it up for a new broadcast, due to missing wait for sem_big_term and
a bad check in iso_disconnected.

Furthermore if any did not work when setting up the BIG,
the error handling did not properly clean up for a retry.

(cherry picked from commit 4d60f0a)

Original-Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
GitOrigin-RevId: 4d60f0a
Cr-Build-Id: 8726634528781615073
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8726634528781615073
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I86f7258145fa80a6330ba9b8cf73c0b529f2d030
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6145195
Bot-Commit: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
  • Loading branch information
Emil Gydesen authored and Chromeos LUCI committed Jan 5, 2025
1 parent bcbe501 commit 66c8f9c
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zephyr/console/console.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/byteorder.h>

#include <zephyr/logging/log.h>
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 66c8f9c

Please sign in to comment.