Skip to content

Commit

Permalink
Bluetooth: Audio: add babblesim tests for CAP distribute broadcastcode
Browse files Browse the repository at this point in the history
Adding a babblesim test for the distribute broadcastcode CAP procedure

Signed-off-by: Andries Kruithof <[email protected]>
  • Loading branch information
kruithofa committed Nov 13, 2024
1 parent b54a7ea commit 3123837
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/bsim/bluetooth/audio/src/cap_acceptor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,12 @@ static void base_wait_for_metadata_update(void)
backchannel_sync_send_all(); /* let others know we have received a metadata update */
}

static void wait_for_broadcast_code(void)
{
printk("Waiting for broadcast code\n");
WAIT_FOR_FLAG(flag_broadcast_code);
}

static void wait_for_streams_stop(int stream_count)
{
/* The order of PA sync lost and BIG Sync lost is irrelevant
Expand Down Expand Up @@ -1048,6 +1054,7 @@ static void test_cap_acceptor_broadcast_reception(void)

create_and_sync_sink(bap_streams, &stream_count);

wait_for_broadcast_code();
sink_wait_for_data();

/* Since we are re-using the BAP broadcast source test
Expand Down
31 changes: 31 additions & 0 deletions tests/bsim/bluetooth/audio/src/cap_commander_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

extern enum bst_result_t bst_result;

#define BROADCASTCODE "BroadcastCode"

static struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN];
static volatile size_t connected_conn_cnt;

Expand All @@ -51,6 +53,7 @@ static uint32_t broadcaster_broadcast_id;

static uint8_t received_base[UINT8_MAX];
static uint8_t received_base_size;
static uint8_t src_id[CONFIG_BT_MAX_CONN];

static struct k_sem sem_disconnected;
static struct k_sem sem_cas_discovered;
Expand Down Expand Up @@ -428,6 +431,7 @@ bap_broadcast_assistant_recv_state_cb(struct bt_conn *conn, int err,
{
char le_addr[BT_ADDR_LE_STR_LEN];
char bad_code[BT_ISO_BROADCAST_CODE_SIZE * 2 + 1];
size_t acceptor_count = get_dev_cnt() - 2;

if (err != 0) {
FAIL("BASS recv state read failed (%d)\n", err);
Expand All @@ -451,6 +455,12 @@ bap_broadcast_assistant_recv_state_cb(struct bt_conn *conn, int err,
return;
}

for (size_t index = 0; index < acceptor_count; index++) {
if (conn == connected_conns[index]) {
src_id[index] = state->src_id;
}
}

for (uint8_t i = 0; i < state->num_subgroups; i++) {
const struct bt_bap_bass_subgroup *subgroup = &state->subgroups[i];
struct net_buf_simple buf;
Expand Down Expand Up @@ -991,6 +1001,25 @@ static void test_broadcast_reception_stop(size_t acceptor_count)
}
}

static void test_distribute_broadcast_code(size_t acceptor_count)
{
struct bt_cap_commander_distribute_broadcast_code_param distribute_broadcast_code_param;
struct bt_cap_commander_distribute_broadcast_code_member_param param[CONFIG_BT_MAX_CONN] = {
0};

distribute_broadcast_code_param.type = BT_CAP_SET_TYPE_AD_HOC;
distribute_broadcast_code_param.param = param;
distribute_broadcast_code_param.count = acceptor_count;
memcpy(distribute_broadcast_code_param.broadcast_code, BROADCASTCODE,
sizeof(BROADCASTCODE));
for (size_t i = 0; i < acceptor_count; i++) {

distribute_broadcast_code_param.param[i].member.member = connected_conns[i];
distribute_broadcast_code_param.param[i].src_id = src_id[i];
}
bt_cap_commander_distribute_broadcast_code(&distribute_broadcast_code_param);
}

static void test_main_cap_commander_capture_and_render(void)
{
const size_t acceptor_cnt = get_dev_cnt() - 1; /* Assume all other devices are acceptors
Expand Down Expand Up @@ -1068,6 +1097,8 @@ static void test_main_cap_commander_broadcast_reception(void)

test_broadcast_reception_start(acceptor_count);

test_distribute_broadcast_code(acceptor_count);

backchannel_sync_wait_any(); /* wait for the acceptor to receive data */

backchannel_sync_wait_any(); /* wait for the acceptor to receive a metadata update
Expand Down

0 comments on commit 3123837

Please sign in to comment.