Skip to content

Commit dd7e77b

Browse files
Thalleyaescolar
authored andcommitted
Bluetooth: BAP: Shell: Fix bad PA sync ref for sink auto scan
When creating a broadcast sink using the auto scan feature, the call to bt_le_per_adv_sync_create would use a local PA sync pointer, instead of one from the per_adv_syncs array, making it impossible to stop the PA sync afterwards. This commit modifed the auto_scan so that it properly uses the per_adv_syncs array, while still assigning the PA sync in the shell broadcast sink struct. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 24f0a83 commit dd7e77b

File tree

1 file changed

+13
-6
lines changed
  • subsys/bluetooth/audio/shell

1 file changed

+13
-6
lines changed

subsys/bluetooth/audio/shell/bap.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,7 @@ static int cmd_preset(const struct shell *sh, size_t argc, char *argv[])
21502150
static struct broadcast_sink_auto_scan {
21512151
struct broadcast_sink *broadcast_sink;
21522152
uint32_t broadcast_id;
2153+
struct bt_le_per_adv_sync **out_sync;
21532154
} auto_scan = {
21542155
.broadcast_id = INVALID_BROADCAST_ID,
21552156
};
@@ -2204,8 +2205,10 @@ static bool scan_check_and_sync_broadcast(struct bt_data *data, void *user_data)
22042205

22052206
bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
22062207

2207-
shell_print(ctx_shell, "Found broadcaster with ID 0x%06X and addr %s and sid 0x%02X",
2208-
broadcast_id, le_addr, info->sid);
2208+
shell_print(ctx_shell,
2209+
"Found broadcaster with ID 0x%06X and addr %s and sid 0x%02X (looking for "
2210+
"0x%06X)",
2211+
broadcast_id, le_addr, info->sid, auto_scan.broadcast_id);
22092212

22102213
if (auto_scan.broadcast_id == broadcast_id && auto_scan.broadcast_sink != NULL &&
22112214
auto_scan.broadcast_sink->pa_sync == NULL) {
@@ -2224,9 +2227,11 @@ static bool scan_check_and_sync_broadcast(struct bt_data *data, void *user_data)
22242227
create_params.timeout = interval_to_sync_timeout(info->interval);
22252228

22262229
shell_print(ctx_shell, "Attempting to PA sync to the broadcaster");
2227-
err = bt_le_per_adv_sync_create(&create_params, &auto_scan.broadcast_sink->pa_sync);
2230+
err = bt_le_per_adv_sync_create(&create_params, auto_scan.out_sync);
22282231
if (err != 0) {
22292232
shell_error(ctx_shell, "Could not create Broadcast PA sync: %d", err);
2233+
} else {
2234+
auto_scan.broadcast_sink->pa_sync = *auto_scan.out_sync;
22302235
}
22312236
}
22322237

@@ -2271,12 +2276,13 @@ static void syncable(struct bt_bap_broadcast_sink *sink, const struct bt_iso_big
22712276
static void bap_pa_sync_synced_cb(struct bt_le_per_adv_sync *sync,
22722277
struct bt_le_per_adv_sync_synced_info *info)
22732278
{
2274-
if (auto_scan.broadcast_sink != NULL && sync == auto_scan.broadcast_sink->pa_sync) {
2279+
if (auto_scan.broadcast_sink != NULL && auto_scan.out_sync != NULL &&
2280+
sync == *auto_scan.out_sync) {
22752281
shell_print(ctx_shell, "PA synced to broadcast with broadcast ID 0x%06x",
22762282
auto_scan.broadcast_id);
22772283

22782284
if (auto_scan.broadcast_sink->bap_sink == NULL) {
2279-
shell_print(ctx_shell, "Attempting to sync to the BIG");
2285+
shell_print(ctx_shell, "Attempting to create the sink");
22802286
int err;
22812287

22822288
err = bt_bap_broadcast_sink_create(sync, auto_scan.broadcast_id,
@@ -2285,7 +2291,7 @@ static void bap_pa_sync_synced_cb(struct bt_le_per_adv_sync *sync,
22852291
shell_error(ctx_shell, "Could not create broadcast sink: %d", err);
22862292
}
22872293
} else {
2288-
shell_print(ctx_shell, "BIG is already synced");
2294+
shell_print(ctx_shell, "Sink is already created");
22892295
}
22902296
}
22912297

@@ -2822,6 +2828,7 @@ static int cmd_create_broadcast_sink(const struct shell *sh, size_t argc, char *
28222828

28232829
auto_scan.broadcast_sink = &default_broadcast_sink;
28242830
auto_scan.broadcast_id = broadcast_id;
2831+
auto_scan.out_sync = &per_adv_syncs[selected_per_adv_sync];
28252832
} else {
28262833
shell_print(sh, "Creating broadcast sink with broadcast ID 0x%06X",
28272834
(uint32_t)broadcast_id);

0 commit comments

Comments
 (0)