tests: Bluetooth: Add test for incorrect bcode as assistant
Add a bsim test that verifies the behavior when the assistant provides an incorrect code to the broadcast sink. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
c49a058b9b
commit
34fa014682
3 changed files with 141 additions and 17 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include <zephyr/bluetooth/gap.h>
|
#include <zephyr/bluetooth/gap.h>
|
||||||
#include <zephyr/bluetooth/gatt.h>
|
#include <zephyr/bluetooth/gatt.h>
|
||||||
#include <zephyr/bluetooth/hci.h>
|
#include <zephyr/bluetooth/hci.h>
|
||||||
|
#include <zephyr/bluetooth/iso.h>
|
||||||
#include <zephyr/bluetooth/uuid.h>
|
#include <zephyr/bluetooth/uuid.h>
|
||||||
#include <zephyr/net/buf.h>
|
#include <zephyr/net/buf.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
@ -47,6 +48,8 @@ CREATE_FLAG(flag_recv_state_read);
|
||||||
CREATE_FLAG(flag_recv_state_updated);
|
CREATE_FLAG(flag_recv_state_updated);
|
||||||
CREATE_FLAG(flag_recv_state_updated_with_bis_sync);
|
CREATE_FLAG(flag_recv_state_updated_with_bis_sync);
|
||||||
CREATE_FLAG(flag_recv_state_removed);
|
CREATE_FLAG(flag_recv_state_removed);
|
||||||
|
CREATE_FLAG(flag_broadcast_code_requested);
|
||||||
|
CREATE_FLAG(flag_incorrect_broadcast_code);
|
||||||
|
|
||||||
/* Broadcaster variables */
|
/* Broadcaster variables */
|
||||||
static bt_addr_le_t g_broadcaster_addr;
|
static bt_addr_le_t g_broadcaster_addr;
|
||||||
|
@ -98,7 +101,7 @@ static void bap_broadcast_assistant_scan_cb(const struct bt_le_scan_recv_info *i
|
||||||
|
|
||||||
static bool metadata_entry(struct bt_data *data, void *user_data)
|
static bool metadata_entry(struct bt_data *data, void *user_data)
|
||||||
{
|
{
|
||||||
char metadata[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE];
|
char metadata[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE] = {0};
|
||||||
|
|
||||||
(void)bin2hex(data->data, data->data_len, metadata, sizeof(metadata));
|
(void)bin2hex(data->data, data->data_len, metadata, sizeof(metadata));
|
||||||
|
|
||||||
|
@ -130,14 +133,15 @@ static void bap_broadcast_assistant_recv_state_cb(
|
||||||
bt_addr_le_to_str(&state->addr, le_addr, sizeof(le_addr));
|
bt_addr_le_to_str(&state->addr, le_addr, sizeof(le_addr));
|
||||||
(void)bin2hex(state->bad_code, BT_AUDIO_BROADCAST_CODE_SIZE, bad_code,
|
(void)bin2hex(state->bad_code, BT_AUDIO_BROADCAST_CODE_SIZE, bad_code,
|
||||||
sizeof(bad_code));
|
sizeof(bad_code));
|
||||||
printk("BASS recv state: src_id %u, addr %s, sid %u, sync_state %u, "
|
printk("BASS recv state: src_id %u, addr %s, sid %u, sync_state %u, encrypt_state %u%s%s\n",
|
||||||
"encrypt_state %u%s%s\n", state->src_id, le_addr, state->adv_sid,
|
state->src_id, le_addr, state->adv_sid, state->pa_sync_state, state->encrypt_state,
|
||||||
state->pa_sync_state, state->encrypt_state,
|
state->encrypt_state == BT_BAP_BIG_ENC_STATE_BAD_CODE ? ", bad code: " : "",
|
||||||
state->encrypt_state == BT_BAP_BIG_ENC_STATE_BAD_CODE ? ", bad code" : "",
|
|
||||||
bad_code);
|
bad_code);
|
||||||
|
|
||||||
if (state->encrypt_state == BT_BAP_BIG_ENC_STATE_BAD_CODE) {
|
if (state->encrypt_state == BT_BAP_BIG_ENC_STATE_BCODE_REQ) {
|
||||||
FAIL("Encryption state is BT_BAP_BIG_ENC_STATE_BAD_CODE");
|
SET_FLAG(flag_broadcast_code_requested);
|
||||||
|
} else if (state->encrypt_state == BT_BAP_BIG_ENC_STATE_BAD_CODE) {
|
||||||
|
SET_FLAG(flag_incorrect_broadcast_code);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,15 +503,10 @@ static void test_bass_mod_source_long_meta(void)
|
||||||
printk("Server PA synced\n");
|
printk("Server PA synced\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_bass_broadcast_code(void)
|
static void test_bass_broadcast_code(const uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE])
|
||||||
{
|
{
|
||||||
uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE];
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(broadcast_code); i++) {
|
|
||||||
broadcast_code[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
printk("Adding broadcast code\n");
|
printk("Adding broadcast code\n");
|
||||||
UNSET_FLAG(flag_write_complete);
|
UNSET_FLAG(flag_write_complete);
|
||||||
err = bt_bap_broadcast_assistant_set_broadcast_code(default_conn, g_src_id, broadcast_code);
|
err = bt_bap_broadcast_assistant_set_broadcast_code(default_conn, g_src_id, broadcast_code);
|
||||||
|
@ -588,7 +587,7 @@ static void test_main_client_sync(void)
|
||||||
test_bass_add_source();
|
test_bass_add_source();
|
||||||
test_bass_mod_source();
|
test_bass_mod_source();
|
||||||
test_bass_mod_source_long_meta();
|
test_bass_mod_source_long_meta();
|
||||||
test_bass_broadcast_code();
|
test_bass_broadcast_code(BROADCAST_CODE);
|
||||||
|
|
||||||
printk("Waiting for receive state with BIS sync\n");
|
printk("Waiting for receive state with BIS sync\n");
|
||||||
WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync);
|
WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync);
|
||||||
|
@ -598,6 +597,30 @@ static void test_main_client_sync(void)
|
||||||
PASS("BAP Broadcast Assistant Client Sync Passed\n");
|
PASS("BAP Broadcast Assistant Client Sync Passed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_main_client_sync_incorrect_code(void)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = common_init();
|
||||||
|
if (err != 0) {
|
||||||
|
FAIL("Bluetooth enable failed (err %d)\n", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
test_bass_scan_start();
|
||||||
|
test_bass_scan_stop();
|
||||||
|
test_bass_create_pa_sync();
|
||||||
|
test_bass_add_source();
|
||||||
|
test_bass_mod_source();
|
||||||
|
WAIT_FOR_FLAG(flag_broadcast_code_requested);
|
||||||
|
test_bass_broadcast_code(INCORRECT_BROADCAST_CODE);
|
||||||
|
WAIT_FOR_FLAG(flag_incorrect_broadcast_code);
|
||||||
|
|
||||||
|
test_bass_remove_source();
|
||||||
|
|
||||||
|
PASS("BAP Broadcast Assistant Client Sync Passed\n");
|
||||||
|
}
|
||||||
|
|
||||||
static void test_main_server_sync_client_rem(void)
|
static void test_main_server_sync_client_rem(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -610,7 +633,7 @@ static void test_main_server_sync_client_rem(void)
|
||||||
|
|
||||||
WAIT_FOR_FLAG(flag_recv_state_updated);
|
WAIT_FOR_FLAG(flag_recv_state_updated);
|
||||||
|
|
||||||
test_bass_broadcast_code();
|
test_bass_broadcast_code(BROADCAST_CODE);
|
||||||
|
|
||||||
printk("Waiting for receive state with BIS sync\n");
|
printk("Waiting for receive state with BIS sync\n");
|
||||||
WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync);
|
WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync);
|
||||||
|
@ -632,7 +655,7 @@ static void test_main_server_sync_server_rem(void)
|
||||||
|
|
||||||
WAIT_FOR_FLAG(flag_recv_state_updated);
|
WAIT_FOR_FLAG(flag_recv_state_updated);
|
||||||
|
|
||||||
test_bass_broadcast_code();
|
test_bass_broadcast_code(BROADCAST_CODE);
|
||||||
|
|
||||||
printk("Waiting for receive state with BIS sync\n");
|
printk("Waiting for receive state with BIS sync\n");
|
||||||
WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync);
|
WAIT_FOR_FLAG(flag_recv_state_updated_with_bis_sync);
|
||||||
|
@ -649,6 +672,12 @@ static const struct bst_test_instance test_bass[] = {
|
||||||
.test_tick_f = test_tick,
|
.test_tick_f = test_tick,
|
||||||
.test_main_f = test_main_client_sync,
|
.test_main_f = test_main_client_sync,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.test_id = "bap_broadcast_assistant_client_sync_incorrect_code",
|
||||||
|
.test_pre_init_f = test_init,
|
||||||
|
.test_tick_f = test_tick,
|
||||||
|
.test_main_f = test_main_client_sync_incorrect_code,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.test_id = "bap_broadcast_assistant_server_sync_client_rem",
|
.test_id = "bap_broadcast_assistant_server_sync_client_rem",
|
||||||
.test_pre_init_f = test_init,
|
.test_pre_init_f = test_init,
|
||||||
|
@ -661,7 +690,7 @@ static const struct bst_test_instance test_bass[] = {
|
||||||
.test_tick_f = test_tick,
|
.test_tick_f = test_tick,
|
||||||
.test_main_f = test_main_server_sync_server_rem,
|
.test_main_f = test_main_server_sync_server_rem,
|
||||||
},
|
},
|
||||||
BSTEST_END_MARKER
|
BSTEST_END_MARKER,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bst_test_list *test_bap_broadcast_assistant_install(struct bst_test_list *tests)
|
struct bst_test_list *test_bap_broadcast_assistant_install(struct bst_test_list *tests)
|
||||||
|
|
|
@ -59,6 +59,7 @@ static struct bt_bap_stream *streams[ARRAY_SIZE(broadcast_sink_streams)];
|
||||||
static uint32_t requested_bis_sync;
|
static uint32_t requested_bis_sync;
|
||||||
static struct bt_le_ext_adv *ext_adv;
|
static struct bt_le_ext_adv *ext_adv;
|
||||||
static const struct bt_bap_scan_delegator_recv_state *req_recv_state;
|
static const struct bt_bap_scan_delegator_recv_state *req_recv_state;
|
||||||
|
static uint8_t recv_state_broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE];
|
||||||
|
|
||||||
#define SUPPORTED_CHAN_COUNTS BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1, 2)
|
#define SUPPORTED_CHAN_COUNTS BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1, 2)
|
||||||
#define SUPPORTED_MIN_OCTETS_PER_FRAME 30
|
#define SUPPORTED_MIN_OCTETS_PER_FRAME 30
|
||||||
|
@ -385,6 +386,8 @@ static int bis_sync_req_cb(struct bt_conn *conn,
|
||||||
const struct bt_bap_scan_delegator_recv_state *recv_state,
|
const struct bt_bap_scan_delegator_recv_state *recv_state,
|
||||||
const uint32_t bis_sync_req[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS])
|
const uint32_t bis_sync_req[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS])
|
||||||
{
|
{
|
||||||
|
req_recv_state = recv_state;
|
||||||
|
|
||||||
printk("BIS sync request received for %p: 0x%08x\n", recv_state, bis_sync_req[0]);
|
printk("BIS sync request received for %p: 0x%08x\n", recv_state, bis_sync_req[0]);
|
||||||
/* We only care about a single subgroup in this test */
|
/* We only care about a single subgroup in this test */
|
||||||
requested_bis_sync = bis_sync_req[0];
|
requested_bis_sync = bis_sync_req[0];
|
||||||
|
@ -398,10 +401,20 @@ static int bis_sync_req_cb(struct bt_conn *conn,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void broadcast_code_cb(struct bt_conn *conn,
|
||||||
|
const struct bt_bap_scan_delegator_recv_state *recv_state,
|
||||||
|
const uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE])
|
||||||
|
{
|
||||||
|
req_recv_state = recv_state;
|
||||||
|
|
||||||
|
memcpy(recv_state_broadcast_code, broadcast_code, BT_AUDIO_BROADCAST_CODE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
static struct bt_bap_scan_delegator_cb scan_delegator_cbs = {
|
static struct bt_bap_scan_delegator_cb scan_delegator_cbs = {
|
||||||
.pa_sync_req = pa_sync_req_cb,
|
.pa_sync_req = pa_sync_req_cb,
|
||||||
.pa_sync_term_req = pa_sync_term_req_cb,
|
.pa_sync_term_req = pa_sync_term_req_cb,
|
||||||
.bis_sync_req = bis_sync_req_cb,
|
.bis_sync_req = bis_sync_req_cb,
|
||||||
|
.broadcast_code = broadcast_code_cb,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
|
static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
|
||||||
|
@ -1138,6 +1151,50 @@ static void broadcast_sink_with_assistant(void)
|
||||||
PASS("Broadcast sink with assistant passed\n");
|
PASS("Broadcast sink with assistant passed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void broadcast_sink_with_assistant_incorrect_code(void)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = init();
|
||||||
|
if (err) {
|
||||||
|
FAIL("Init failed (err %d)\n", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
test_start_adv();
|
||||||
|
WAIT_FOR_FLAG(flag_connected);
|
||||||
|
|
||||||
|
printk("Waiting for PA sync request\n");
|
||||||
|
WAIT_FOR_FLAG(flag_pa_request);
|
||||||
|
|
||||||
|
test_scan_and_pa_sync();
|
||||||
|
test_broadcast_sink_create();
|
||||||
|
|
||||||
|
printk("Broadcast source PA synced, waiting for BASE\n");
|
||||||
|
WAIT_FOR_FLAG(flag_base_received);
|
||||||
|
printk("BASE received\n");
|
||||||
|
|
||||||
|
printk("Waiting for BIG syncable\n");
|
||||||
|
WAIT_FOR_FLAG(flag_syncable);
|
||||||
|
|
||||||
|
printk("Waiting for BIG sync request\n");
|
||||||
|
WAIT_FOR_FLAG(flag_bis_sync_requested);
|
||||||
|
test_broadcast_sync(recv_state_broadcast_code);
|
||||||
|
/* Wait for MIC failure */
|
||||||
|
WAIT_FOR_FLAG(flag_big_sync_mic_failure);
|
||||||
|
|
||||||
|
backchannel_sync_send_all(); /* let other devices know we have received data */
|
||||||
|
|
||||||
|
printk("Waiting for PA sync terminate request\n");
|
||||||
|
WAIT_FOR_UNSET_FLAG(flag_pa_request);
|
||||||
|
test_pa_sync_delete();
|
||||||
|
test_broadcast_delete();
|
||||||
|
|
||||||
|
backchannel_sync_send_all(); /* let the broadcast source know it can stop */
|
||||||
|
|
||||||
|
PASS("Broadcast sink with assistant and incorrect code passed\n");
|
||||||
|
}
|
||||||
|
|
||||||
static const struct bst_test_instance test_broadcast_sink[] = {
|
static const struct bst_test_instance test_broadcast_sink[] = {
|
||||||
{
|
{
|
||||||
.test_id = "broadcast_sink",
|
.test_id = "broadcast_sink",
|
||||||
|
@ -1169,6 +1226,12 @@ static const struct bst_test_instance test_broadcast_sink[] = {
|
||||||
.test_tick_f = test_tick,
|
.test_tick_f = test_tick,
|
||||||
.test_main_f = broadcast_sink_with_assistant,
|
.test_main_f = broadcast_sink_with_assistant,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.test_id = "broadcast_sink_with_assistant_incorrect_code",
|
||||||
|
.test_pre_init_f = test_init,
|
||||||
|
.test_tick_f = test_tick,
|
||||||
|
.test_main_f = broadcast_sink_with_assistant_incorrect_code,
|
||||||
|
},
|
||||||
BSTEST_END_MARKER,
|
BSTEST_END_MARKER,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Copyright (c) 2020-2022 Nordic Semiconductor ASA
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
SIMULATION_ID="bap_broadcast_audio_assistant_incorrect_code"
|
||||||
|
VERBOSITY_LEVEL=2
|
||||||
|
|
||||||
|
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
|
||||||
|
|
||||||
|
cd ${BSIM_OUT_PATH}/bin
|
||||||
|
|
||||||
|
printf "\n\n======== Running BAP Broadcast audio assistant incorrect code =========\n\n"
|
||||||
|
|
||||||
|
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
|
||||||
|
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -RealEncryption=1 \
|
||||||
|
-testid=broadcast_sink_with_assistant_incorrect_code -rs=24 -D=3
|
||||||
|
|
||||||
|
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
|
||||||
|
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -RealEncryption=1 \
|
||||||
|
-testid=bap_broadcast_assistant_client_sync_incorrect_code -rs=46 -D=3
|
||||||
|
|
||||||
|
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
|
||||||
|
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -RealEncryption=1 \
|
||||||
|
-testid=broadcast_source_encrypted -rs=69 -D=3
|
||||||
|
|
||||||
|
# Simulation time should be larger than the WAIT_TIME in common.h
|
||||||
|
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -D=3 \
|
||||||
|
-sim_length=60e6 $@
|
||||||
|
|
||||||
|
wait_for_background_jobs
|
Loading…
Add table
Add a link
Reference in a new issue