From ab57f2275ac0055a303b0b2a9c89467eecec6ccd Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 26 Mar 2024 14:41:56 +0100 Subject: [PATCH] Bluetooth: BAP: Shell: Fix state lookup with PAST When a PA is synced via PAST, the receive state does not have a PA sync object, and the address and SID must be used. Signed-off-by: Emil Gydesen --- .../audio/shell/bap_scan_delegator.c | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/shell/bap_scan_delegator.c b/subsys/bluetooth/audio/shell/bap_scan_delegator.c index 79676875554..a2067301c8d 100644 --- a/subsys/bluetooth/audio/shell/bap_scan_delegator.c +++ b/subsys/bluetooth/audio/shell/bap_scan_delegator.c @@ -77,6 +77,21 @@ static struct sync_state *sync_state_get_by_pa(struct bt_le_per_adv_sync *sync) return NULL; } +static struct sync_state * +sync_state_get_by_sync_info(const struct bt_le_per_adv_sync_synced_info *info) +{ + for (size_t i = 0U; i < ARRAY_SIZE(sync_states); i++) { + if (sync_states[i].recv_state != NULL && + bt_addr_le_eq(info->addr, &sync_states[i].recv_state->addr) && + info->sid == sync_states[i].recv_state->adv_sid) { + + return &sync_states[i]; + } + } + + return NULL; +} + static struct sync_state *sync_state_new(void) { for (size_t i = 0U; i < ARRAY_SIZE(sync_states); i++) { @@ -337,7 +352,13 @@ static void pa_synced_cb(struct bt_le_per_adv_sync *sync, shell_info(ctx_shell, "PA %p synced", sync); - state = sync_state_get_by_pa(sync); + if (info->conn == NULL) { + state = sync_state_get_by_pa(sync); + } else { + /* In case of PAST we need to use the addr instead */ + state = sync_state_get_by_sync_info(info); + } + if (state == NULL) { shell_info(ctx_shell, "Could not get sync state from PA sync %p",