Skip to content

Commit

Permalink
Bluetooth: GMAP: Add GMAP BSIM test
Browse files Browse the repository at this point in the history
Add BSIM testing of GMAP, with all spec-specified audio
configuration combinations added and tested.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
  • Loading branch information
Thalley committed Oct 23, 2023
1 parent 732b09f commit 798632c
Show file tree
Hide file tree
Showing 26 changed files with 2,433 additions and 113 deletions.
31 changes: 25 additions & 6 deletions tests/bsim/bluetooth/audio/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ CONFIG_BT_MAX_PAIRED=3
CONFIG_BT_EXT_ADV_MAX_ADV_SET=3
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_SMP=y
CONFIG_BT_L2CAP_TX_MTU=100
CONFIG_BT_BUF_ACL_TX_SIZE=104
CONFIG_BT_BUF_ACL_RX_SIZE=104
CONFIG_BT_L2CAP_TX_MTU=128
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251

CONFIG_BT_AUDIO=y
CONFIG_BT_BAP_UNICAST_SERVER=y
Expand Down Expand Up @@ -144,6 +144,9 @@ CONFIG_BT_PAC_SNK_LOC_WRITEABLE=y
CONFIG_BT_PAC_SRC_LOC_WRITEABLE=y
CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y

# Gaming Audio Profile
CONFIG_BT_GMAP=y

# DEBUGGING
CONFIG_LOG=y
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y
Expand Down Expand Up @@ -182,20 +185,34 @@ CONFIG_BT_HAS_LOG_LEVEL_DBG=y
CONFIG_BT_HAS_CLIENT_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_ACCEPTOR_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_INITIATOR_LOG_LEVEL_DBG=y
CONFIG_BT_GMAP_LOG_LEVEL_DBG=y

# LOGGING
CONFIG_LOG_MODE_IMMEDIATE=y

# Controller Broadcast ISO configs
# Controller Settings
CONFIG_BT_LL_SW_SPLIT=y
CONFIG_BT_CTLR_PHY_CODED=y
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y
CONFIG_BT_CTLR_ADV_SYNC_PDU_BACK2BACK=y
CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=6
CONFIG_BT_CTLR_ADV_RESERVE_MAX=n
CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n
CONFIG_BT_CTLR_SCAN_UNRESERVED=y
CONFIG_BT_CTLR_ADV_ISO=y
CONFIG_BT_CTLR_SYNC_ISO=y
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=255
CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=251
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191
CONFIG_BT_CTLR_ISO_TX_BUFFERS=8
CONFIG_BT_CTLR_ISO_RX_BUFFERS=1

# Controller ISO Broadcast Settings
CONFIG_BT_CTLR_SYNC_ISO=y
CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=1
CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=1

# Controller Connected ISO configs
# Controller ISO Unicast Settings
CONFIG_BT_CTLR_CENTRAL_ISO=y
CONFIG_BT_CTLR_PERIPHERAL_ISO=y
CONFIG_BT_CTLR_ISOAL_SOURCES=2
Expand All @@ -213,3 +230,5 @@ CONFIG_BT_CTLR_SCAN_UNRESERVED=y
CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y
CONFIG_BT_TICKER_EXT=y
CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD=y
CONFIG_BT_CTLR_CONN_ISO_STREAMS=2
CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/byteorder.h>

#include "common.h"
#include "bap_unicast_common.h"
#include "bap_common.h"

void print_hex(const uint8_t *ptr, size_t len)
{
Expand Down Expand Up @@ -79,6 +81,42 @@ void print_qos(const struct bt_audio_codec_qos *qos)
{
printk("QoS: interval %u framing 0x%02x phy 0x%02x sdu %u "
"rtn %u latency %u pd %u\n",
qos->interval, qos->framing, qos->phy, qos->sdu,
qos->rtn, qos->latency, qos->pd);
qos->interval, qos->framing, qos->phy, qos->sdu, qos->rtn, qos->latency, qos->pd);
}

int set_chan_alloc(enum bt_audio_location loc, struct bt_audio_codec_cfg *codec_cfg)
{
for (size_t i = 0U; i < codec_cfg->data_len;) {
const uint8_t len = codec_cfg->data[i++];
uint8_t value_len;
uint8_t *value;
uint8_t type;

if (len == 0 || len > codec_cfg->data_len - i) {
/* Invalid len field */
return false;
}

type = codec_cfg->data[i++];
value = &codec_cfg->data[i];
value_len = len - sizeof(type);

if (type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
const uint32_t loc_32 = loc;

sys_put_le32(loc_32, value);

return 0;
}
i += value_len;
}

return -ENODATA;
}

void copy_unicast_stream_preset(struct unicast_stream *stream,
const struct named_lc3_preset *named_preset)
{
memcpy(&stream->qos, &named_preset->preset.qos, sizeof(stream->qos));
memcpy(&stream->codec_cfg, &named_preset->preset.codec_cfg, sizeof(stream->codec_cfg));
}
98 changes: 98 additions & 0 deletions tests/bsim/bluetooth/audio/src/bap_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Common functions and helpers for audio BSIM audio tests
*
* Copyright (c) 2021-2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_COMMON_
#define ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_COMMON_

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
#include <zephyr/bluetooth/audio/cap.h>

#define LONG_META 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, \
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, \
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, \
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, \
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, \
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, \
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, \
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f

#define LONG_META_LEN (sizeof((uint8_t []){LONG_META}) + 1U) /* Size of data + type */

struct unicast_stream {
struct bt_cap_stream stream;
struct bt_audio_codec_cfg codec_cfg;
struct bt_audio_codec_qos qos;
};

struct named_lc3_preset {
const char *name;
struct bt_bap_lc3_preset preset;
};

void print_hex(const uint8_t *ptr, size_t len);
void print_codec_cap(const struct bt_audio_codec_cap *codec_cap);
void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg);
void print_qos(const struct bt_audio_codec_qos *qos);
int set_chan_alloc(enum bt_audio_location loc, struct bt_audio_codec_cfg *codec_cfg);
void copy_unicast_stream_preset(struct unicast_stream *stream,
const struct named_lc3_preset *named_preset);

static inline bool valid_metadata_type(uint8_t type, uint8_t len)
{
switch (type) {
case BT_AUDIO_METADATA_TYPE_PREF_CONTEXT:
case BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT:
if (len != 2) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_STREAM_LANG:
if (len != 3) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_PARENTAL_RATING:
if (len != 1) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
if (len < 1) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_CCID_LIST: /* 2 - 254 octets */
if (len < 2) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO: /* 0 - 255 octets */
case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI: /* 0 - 255 octets */
return true;
default:
return false;
}
}

#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_COMMON_ */
2 changes: 1 addition & 1 deletion tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
#include <zephyr/bluetooth/audio/pacs.h>
#include "common.h"
#include "bap_unicast_common.h"
#include "bap_common.h"

#define BAP_STREAM_RETRY_WAIT K_MSEC(100)

Expand Down
39 changes: 0 additions & 39 deletions tests/bsim/bluetooth/audio/src/bap_unicast_common.h

This file was deleted.

2 changes: 1 addition & 1 deletion tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/pacs.h>
#include "common.h"
#include "bap_unicast_common.h"
#include "bap_common.h"

extern enum bst_result_t bst_result;

Expand Down
40 changes: 1 addition & 39 deletions tests/bsim/bluetooth/audio/src/cap_acceptor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <zephyr/bluetooth/audio/pacs.h>
#include <zephyr/sys/byteorder.h>
#include "common.h"
#include "bap_unicast_common.h"
#include "bap_common.h"

extern enum bst_result_t bst_result;

Expand Down Expand Up @@ -62,44 +62,6 @@ static struct bt_cap_stream unicast_streams[CONFIG_BT_ASCS_ASE_SNK_COUNT +

CREATE_FLAG(flag_unicast_stream_configured);

static bool valid_metadata_type(uint8_t type, uint8_t len)
{
switch (type) {
case BT_AUDIO_METADATA_TYPE_PREF_CONTEXT:
case BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT:
if (len != 2) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_STREAM_LANG:
if (len != 3) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_PARENTAL_RATING:
if (len != 1) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
if (len < 2) {
return false;
}

return true;
case BT_AUDIO_METADATA_TYPE_CCID_LIST:
case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO: /* 0 - 255 octets */
case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI: /* 0 - 255 octets */
return true;
default:
return false;
}
}

static bool subgroup_data_func_cb(struct bt_data *data, void *user_data)
{
bool *stream_context_found = (bool *)user_data;
Expand Down
26 changes: 3 additions & 23 deletions tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/sys/byteorder.h>
#include "common.h"
#include "bap_unicast_common.h"
#include "bap_common.h"

#define UNICAST_SINK_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0)
#define UNICAST_SRC_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0)
Expand All @@ -27,17 +27,6 @@
#define CONTEXT (BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED)
#define LOCATION (BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT)

struct unicast_stream {
struct bt_cap_stream stream;
struct bt_audio_codec_cfg codec_cfg;
struct bt_audio_codec_qos qos;
};

struct named_lc3_preset {
const char *name;
struct bt_bap_lc3_preset preset;
};

struct cap_initiator_ac_param {
char *name;
size_t conn_cnt;
Expand All @@ -64,8 +53,8 @@ static struct bt_bap_ep
static struct unicast_stream unicast_streams[CAP_AC_MAX_STREAM];
static struct bt_conn *connected_conns[CAP_AC_MAX_CONN];
static size_t connected_conn_cnt;
const struct named_lc3_preset *snk_named_preset;
const struct named_lc3_preset *src_named_preset;
static const struct named_lc3_preset *snk_named_preset;
static const struct named_lc3_preset *src_named_preset;

CREATE_FLAG(flag_discovered);
CREATE_FLAG(flag_codec_found);
Expand Down Expand Up @@ -940,15 +929,6 @@ const struct named_lc3_preset *cap_get_named_preset(const char *preset_arg)
return NULL;
}

static inline void copy_unicast_stream_preset(struct unicast_stream *stream,
const struct named_lc3_preset *named_preset)
{
printk("stream %p\n", stream);
printk("named_preset %p\n", named_preset);
memcpy(&stream->qos, &named_preset->preset.qos, sizeof(stream->qos));
memcpy(&stream->codec_cfg, &named_preset->preset.codec_cfg, sizeof(stream->codec_cfg));
}

static int cap_initiator_ac_create_unicast_group(const struct cap_initiator_ac_param *param,
struct unicast_stream *snk_uni_streams[],
size_t snk_cnt,
Expand Down

0 comments on commit 798632c

Please sign in to comment.