Skip to content

Commit b800be3

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: BAP: Broadcast sync fail receive state bis sync value fixed
In the case that a broadcast sync fails for any reason, we need to set the BIS_Sync value for all subgroups to 0xFFFFFFFF (BT_BAP_BIS_SYNC_FAILED) as per the BAP spec. This commit adds a new define for this and modifies both the scan delegator and broadcast sink to support this. The change is validated by a modification to the broadcast assistant test that verifies that the value is set in the case of an invalid broadcast code (which indicates a failed BIG sync). Signed-off-by: Emil Gydesen <[email protected]>
1 parent 330abc4 commit b800be3

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

include/zephyr/bluetooth/audio/bap.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ enum bt_bap_bass_att_err {
9191
* Value indicating that the Broadcast Assistant has no preference to which BIS
9292
* the Scan Delegator syncs to
9393
*/
94-
#define BT_BAP_BIS_SYNC_NO_PREF 0xFFFFFFFF
94+
#define BT_BAP_BIS_SYNC_NO_PREF 0xFFFFFFFF
95+
/** BIS sync value indicating that the BIG sync has failed for any reason */
96+
#define BT_BAP_BIS_SYNC_FAILED 0xFFFFFFFF
9597

9698
/** Endpoint states */
9799
enum bt_bap_ep_state {
@@ -305,7 +307,11 @@ struct bt_bap_scan_delegator_recv_state {
305307
/** Number of subgroups */
306308
uint8_t num_subgroups;
307309

308-
/** Subgroup specific information */
310+
/** Subgroup specific information
311+
*
312+
* If the @ref bt_bap_bass_subgroup.bis_sync value is @ref BT_BAP_BIS_SYNC_FAILED then it
313+
* indicates that the BIG sync failed.
314+
*/
309315
struct bt_bap_bass_subgroup subgroups[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS];
310316
};
311317

@@ -2420,7 +2426,11 @@ struct bt_bap_broadcast_assistant_add_src_param {
24202426
/** Number of subgroups */
24212427
uint8_t num_subgroups;
24222428

2423-
/** Pointer to array of subgroups */
2429+
/** Pointer to array of subgroups
2430+
*
2431+
* The @ref bt_bap_bass_subgroup.bis_sync value can be set to BT_BAP_BIS_SYNC_NO_PREF to
2432+
* let the broadcast sink decide which BIS to synchronize to.
2433+
*/
24242434
struct bt_bap_bass_subgroup *subgroups;
24252435
};
24262436

subsys/bluetooth/audio/bap_broadcast_sink.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,13 @@ static void update_recv_state_big_cleared(const struct bt_bap_broadcast_sink *si
170170
mod_src_param.encrypt_state = recv_state->encrypt_state;
171171
}
172172

173-
/* BIS syncs will be automatically cleared since the mod_src_param
174-
* struct is 0-initialized
175-
*
176-
* Since the metadata_len is also 0, then the metadata won't be
177-
* modified by the operation either.
178-
*/
173+
if (reason != BT_HCI_ERR_LOCALHOST_TERM_CONN) {
174+
for (uint8_t i = 0U; i < recv_state->num_subgroups; i++) {
175+
mod_src_param.subgroups[i].bis_sync = BT_BAP_BIS_SYNC_FAILED;
176+
}
177+
}
178+
179+
/* Since the metadata_len is 0 then the metadata won't be modified by the operation either*/
179180

180181
/* Copy existing unchanged data */
181182
mod_src_param.num_subgroups = recv_state->num_subgroups;

subsys/bluetooth/audio/bap_scan_delegator.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,9 +1419,8 @@ static bool valid_bt_bap_scan_delegator_mod_src_param(
14191419
for (uint8_t i = 0U; i < param->num_subgroups; i++) {
14201420
const struct bt_bap_bass_subgroup *subgroup = &param->subgroups[i];
14211421

1422-
if (subgroup->bis_sync == BT_BAP_BIS_SYNC_NO_PREF ||
1423-
!bis_syncs_unique_or_no_pref(subgroup->bis_sync,
1424-
aggregated_bis_syncs)) {
1422+
if (subgroup->bis_sync != BT_BAP_BIS_SYNC_FAILED &&
1423+
!bis_syncs_unique_or_no_pref(subgroup->bis_sync, aggregated_bis_syncs)) {
14251424
LOG_DBG("Invalid BIS sync: %u", subgroup->bis_sync);
14261425

14271426
return false;
@@ -1483,7 +1482,8 @@ int bt_bap_scan_delegator_mod_src(const struct bt_bap_scan_delegator_mod_src_par
14831482
const uint32_t bis_sync = param->subgroups[i].bis_sync;
14841483
const uint32_t bis_sync_requested = internal_state->requested_bis_sync[i];
14851484

1486-
if (!bits_subset_of(bis_sync, bis_sync_requested)) {
1485+
if (bis_sync != BT_BAP_BIS_SYNC_FAILED &&
1486+
!bits_subset_of(bis_sync, bis_sync_requested)) {
14871487
LOG_DBG("Subgroup[%d] invalid bis_sync value %x for %x",
14881488
i, bis_sync, bis_sync_requested);
14891489

tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ static void bap_broadcast_assistant_recv_state_cb(
147147
FAIL("Bad code is not what we sent");
148148
return;
149149
}
150+
151+
for (uint8_t i = 0; i < state->num_subgroups; i++) {
152+
const struct bt_bap_bass_subgroup *subgroup = &state->subgroups[i];
153+
154+
if (subgroup->bis_sync != BT_BAP_BIS_SYNC_FAILED) {
155+
FAIL("Invalid BIS sync value 0x%08X for failed sync",
156+
subgroup->bis_sync);
157+
return;
158+
}
159+
}
150160
}
151161

152162
for (uint8_t i = 0; i < state->num_subgroups; i++) {

0 commit comments

Comments
 (0)