From 66c8f9cd928b2791ac6a4e0656b06893d7086d15 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 11 Nov 2024 15:35:55 +0100 Subject: [PATCH] samples: Bluetooth: Handle shutdown of iso broadcast benchmark 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 4d60f0a51b5883cb060625af512dad378d52f9e3) Original-Signed-off-by: Emil Gydesen GitOrigin-RevId: 4d60f0a51b5883cb060625af512dad378d52f9e3 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) Commit-Queue: ChromeOS Prod (Robot) Tested-by: ChromeOS Prod (Robot) --- .../iso_broadcast_benchmark/src/broadcaster.c | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c b/samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c index 2f03528093f..4665eed3ca8 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; }