Skip to content

Commit

Permalink
Bluetooth: BAP: Fix issue with sink recv state notifications
Browse files Browse the repository at this point in the history
There was a bug in pa_decode_base that would would spent time
parsing incoming BASEs and also update the receive
states, which caused some tests to fail.

This commit adds a simply check to verify that the BASE is
different before spending parsing the content and updating
the receive states.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley committed Jan 21, 2025
1 parent e7151cf commit f7716ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
60 changes: 33 additions & 27 deletions subsys/bluetooth/audio/bap_broadcast_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,46 +649,51 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
const struct bt_bap_base *base = bt_bap_base_get_base_from_ad(data);
struct bt_bap_broadcast_sink_cb *listener;
int base_size;
int ret;

/* Base is NULL if the data does not contain a valid BASE */
if (base == NULL) {
return true;
}

if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_BIGINFO_RECEIVED)) {
ret = base_get_bis_count(base);

if (ret < 0) {
LOG_DBG("Invalid BASE: %d", ret);
return false;
} else if (ret != sink->biginfo_num_bis) {
LOG_DBG("BASE contains different amount of BIS (%u) than reported by "
"BIGInfo (%u)",
ret, sink->biginfo_num_bis);
return false;
}
}

/* We provide the BASE without the service data UUID */
base_size = bt_bap_base_get_size(base);
if (base_size != sink->base_size || memcmp(base, sink->base, base_size) != 0) {
/* New BASE, parse */

if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_BIGINFO_RECEIVED)) {
int ret;

/* Store newest BASE info until we are BIG synced */
if (sink->big == NULL) {
sink->qos_cfg.pd = bt_bap_base_get_pres_delay(base);
ret = base_get_bis_count(base);

sink->subgroup_count = 0;
sink->valid_indexes_bitfield = 0;
bt_bap_base_foreach_subgroup(base, base_decode_subgroup_cb, sink);
if (ret < 0) {
LOG_DBG("Invalid BASE: %d", ret);
return false;
} else if (ret != sink->biginfo_num_bis) {
LOG_DBG("BASE contains different amount of BIS (%u) than reported "
"by BIGInfo (%u)",
ret, sink->biginfo_num_bis);
return false;
}
}

LOG_DBG("Updating BASE for sink %p with %d subgroups\n", sink,
sink->subgroup_count);
/* Store newest BASE info until we are BIG synced */
if (sink->big == NULL) {
sink->qos_cfg.pd = bt_bap_base_get_pres_delay(base);

memcpy(sink->base, base, base_size);
}
sink->subgroup_count = 0;
sink->valid_indexes_bitfield = 0;
bt_bap_base_foreach_subgroup(base, base_decode_subgroup_cb, sink);

if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) {
update_recv_state_base(sink, base);
LOG_DBG("Updating BASE for sink %p with %d subgroups\n", sink,
sink->subgroup_count);

memcpy(sink->base, base, base_size);
sink->base_size = base_size;
}

if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) {
update_recv_state_base(sink, base);
}
}

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
Expand Down Expand Up @@ -726,6 +731,7 @@ static void pa_term_cb(struct bt_le_per_adv_sync *sync,

if (sink != NULL) {
sink->pa_sync = NULL;
sink->base_size = 0U;
}
}

Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/audio/bap_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct bt_bap_broadcast_sink {
struct bt_bap_qos_cfg qos_cfg;
struct bt_le_per_adv_sync *pa_sync;
struct bt_iso_big *big;
uint8_t base_size;
uint8_t base[BT_BASE_MAX_SIZE];
struct bt_bap_broadcast_sink_bis bis[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
struct bt_bap_broadcast_sink_subgroup subgroups[CONFIG_BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT];
Expand Down

0 comments on commit f7716ab

Please sign in to comment.