Skip to content

Commit 8e53592

Browse files
Thalleykartben
authored andcommitted
Bluetooth: BAP: Fix issue with sink recv state notifications
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]>
1 parent ed5132d commit 8e53592

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

subsys/bluetooth/audio/bap_broadcast_sink.c

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -649,46 +649,51 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
649649
const struct bt_bap_base *base = bt_bap_base_get_base_from_ad(data);
650650
struct bt_bap_broadcast_sink_cb *listener;
651651
int base_size;
652-
int ret;
653652

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

659-
if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_BIGINFO_RECEIVED)) {
660-
ret = base_get_bis_count(base);
661-
662-
if (ret < 0) {
663-
LOG_DBG("Invalid BASE: %d", ret);
664-
return false;
665-
} else if (ret != sink->biginfo_num_bis) {
666-
LOG_DBG("BASE contains different amount of BIS (%u) than reported by "
667-
"BIGInfo (%u)",
668-
ret, sink->biginfo_num_bis);
669-
return false;
670-
}
671-
}
672-
673658
/* We provide the BASE without the service data UUID */
674659
base_size = bt_bap_base_get_size(base);
660+
if (base_size != sink->base_size || memcmp(base, sink->base, base_size) != 0) {
661+
/* New BASE, parse */
662+
663+
if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_BIGINFO_RECEIVED)) {
664+
int ret;
675665

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

680-
sink->subgroup_count = 0;
681-
sink->valid_indexes_bitfield = 0;
682-
bt_bap_base_foreach_subgroup(base, base_decode_subgroup_cb, sink);
668+
if (ret < 0) {
669+
LOG_DBG("Invalid BASE: %d", ret);
670+
return false;
671+
} else if (ret != sink->biginfo_num_bis) {
672+
LOG_DBG("BASE contains different amount of BIS (%u) than reported "
673+
"by BIGInfo (%u)",
674+
ret, sink->biginfo_num_bis);
675+
return false;
676+
}
677+
}
683678

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

687-
memcpy(sink->base, base, base_size);
688-
}
683+
sink->subgroup_count = 0;
684+
sink->valid_indexes_bitfield = 0;
685+
bt_bap_base_foreach_subgroup(base, base_decode_subgroup_cb, sink);
689686

690-
if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) {
691-
update_recv_state_base(sink, base);
687+
LOG_DBG("Updating BASE for sink %p with %d subgroups\n", sink,
688+
sink->subgroup_count);
689+
690+
memcpy(sink->base, base, base_size);
691+
sink->base_size = base_size;
692+
}
693+
694+
if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) {
695+
update_recv_state_base(sink, base);
696+
}
692697
}
693698

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

727732
if (sink != NULL) {
728733
sink->pa_sync = NULL;
734+
sink->base_size = 0U;
729735
}
730736
}
731737

subsys/bluetooth/audio/bap_endpoint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ struct bt_bap_broadcast_sink {
181181
struct bt_bap_qos_cfg qos_cfg;
182182
struct bt_le_per_adv_sync *pa_sync;
183183
struct bt_iso_big *big;
184+
uint8_t base_size;
184185
uint8_t base[BT_BASE_MAX_SIZE];
185186
struct bt_bap_broadcast_sink_bis bis[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
186187
struct bt_bap_broadcast_sink_subgroup subgroups[CONFIG_BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT];

0 commit comments

Comments
 (0)