bluetooth: tester: CSIP tests

Adding support for CSIP client role tests.

Signed-off-by: Piotr Narajowski <piotr.narajowski@codecoup.pl>
This commit is contained in:
Piotr Narajowski 2024-02-06 11:05:08 +01:00 committed by Alberto Escolar
parent 8cdcb2c167
commit 4c9d644680
5 changed files with 143 additions and 3 deletions

View File

@ -1,5 +1,6 @@
# Apply this overlay at tester build, not hci_ipc build
CONFIG_BT_MAX_CONN=3
# Those have to be the same as in the controller (hci_ipc)
CONFIG_BT_MAX_CONN=2
CONFIG_BT_BUF_EVT_RX_COUNT=16
CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_CMD_TX_SIZE=255

View File

@ -4,3 +4,4 @@ CONFIG_BT_CTLR_DATA_LENGTH_MAX=100
CONFIG_BT_BUF_ACL_RX_SIZE=100
CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START=y
CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y
CONFIG_BT_MAX_CONN=3

View File

@ -11,7 +11,8 @@ CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE=22
CONFIG_RING_BUFFER=y
# These have to be the same as in the controller (hci_ipc)
CONFIG_BT_MAX_CONN=2
CONFIG_BT_MAX_CONN=3
CONFIG_BT_MAX_PAIRED=3
CONFIG_BT_BUF_EVT_RX_COUNT=16
CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_CMD_TX_SIZE=255
@ -102,6 +103,7 @@ CONFIG_BT_CSIP_SET_MEMBER=y
# CSIP
CONFIG_BT_CSIP_SET_COORDINATOR=y
CONFIG_BT_CSIP_SET_COORDINATOR_MAX_CSIS_INSTANCES=3
# CCP
CONFIG_BT_ATT_TX_COUNT=12

View File

@ -22,3 +22,35 @@ struct btp_csip_discover_cmd {
struct btp_csip_start_ordered_access_cmd {
uint8_t flags;
} __packed;
#define BTP_CSIP_SET_COORDINATOR_LOCK 0x04
struct btp_csip_set_coordinator_lock_cmd {
uint8_t count;
} __packed;
#define BTP_CSIP_SET_COORDINATOR_RELEASE 0x05
struct btp_csip_set_coordinator_release_cmd {
uint8_t count;
} __packed;
/* CSIP Events */
#define BTP_CSIP_DISCOVERED_EV 0x80
struct btp_csip_discovered_ev {
bt_addr_le_t address;
uint8_t status;
uint16_t sirk_handle;
uint16_t size_handle;
uint16_t lock_handle;
uint16_t rank_handle;
} __packed;
#define BTP_CSIP_SIRK_EV 0x81
struct btp_csip_sirk_ev {
bt_addr_le_t address;
uint8_t sirk[BT_CSIP_SET_SIRK_SIZE];
} __packed;
#define BTP_CSIP_LOCK_EV 0x82
struct btp_csip_lock_ev {
uint8_t status;
} __packed;

View File

@ -8,12 +8,14 @@
#include "btp/btp.h"
#include <zephyr/bluetooth/audio/csip.h>
#include "../bluetooth/audio/csip_internal.h"
#include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bttester_csip
LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL);
const struct bt_csip_set_coordinator_set_member *btp_csip_set_members[CONFIG_BT_MAX_CONN];
static const struct bt_csip_set_coordinator_csis_inst *cur_csis_inst;
static struct bt_csip_set_coordinator_svc_inst *csip_inst;
static uint8_t btp_csip_supported_commands(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
@ -22,21 +24,65 @@ static uint8_t btp_csip_supported_commands(const void *cmd, uint16_t cmd_len,
/* octet 0 */
tester_set_bit(rp->data, BTP_CSIP_READ_SUPPORTED_COMMANDS);
tester_set_bit(rp->data, BTP_CSIP_DISCOVER);
tester_set_bit(rp->data, BTP_CSIP_START_ORDERED_ACCESS);
tester_set_bit(rp->data, BTP_CSIP_SET_COORDINATOR_LOCK);
tester_set_bit(rp->data, BTP_CSIP_SET_COORDINATOR_RELEASE);
*rsp_len = sizeof(*rp) + 1;
return BTP_STATUS_SUCCESS;
}
static void btp_send_csip_discovered_ev(struct bt_conn *conn, uint16_t sirk_handle,
uint16_t size_handle, uint16_t lock_handle,
uint16_t rank_handle, uint8_t status)
{
struct btp_csip_discovered_ev ev;
bt_addr_le_copy(&ev.address, bt_conn_get_dst(conn));
ev.status = status;
ev.sirk_handle = sys_cpu_to_le16(sirk_handle);
ev.size_handle = sys_cpu_to_le16(size_handle);
ev.lock_handle = sys_cpu_to_le16(lock_handle);
ev.rank_handle = sys_cpu_to_le16(rank_handle);
tester_event(BTP_SERVICE_ID_CSIP, BTP_CSIP_DISCOVERED_EV, &ev, sizeof(ev));
}
static void btp_send_csip_sirk_ev(struct bt_conn *conn, uint8_t *sirk, size_t sirk_size)
{
struct btp_csip_sirk_ev ev;
bt_addr_le_copy(&ev.address, bt_conn_get_dst(conn));
memcpy(ev.sirk, sirk, sirk_size);
tester_event(BTP_SERVICE_ID_CSIP, BTP_CSIP_SIRK_EV, &ev, sizeof(ev));
}
static void btp_send_csip_lock_ev(int err)
{
struct btp_csip_lock_ev ev;
ev.status = err;
tester_event(BTP_SERVICE_ID_CSIP, BTP_CSIP_LOCK_EV, &ev, sizeof(ev));
}
static void csip_set_coordinator_lock_set_cb(int err)
{
LOG_DBG("");
btp_send_csip_lock_ev(err);
}
static void csip_set_coordinator_lock_release_cb(int err)
{
LOG_DBG("");
btp_send_csip_lock_ev(err);
}
static void csip_discover_cb(struct bt_conn *conn,
@ -45,6 +91,8 @@ static void csip_discover_cb(struct bt_conn *conn,
{
LOG_DBG("");
uint8_t sirk[BT_CSIP_SET_SIRK_SIZE];
size_t sirk_size = ARRAY_SIZE(sirk);
uint8_t conn_index;
if (err != 0) {
@ -61,6 +109,12 @@ static void csip_discover_cb(struct bt_conn *conn,
LOG_DBG("Found %zu sets on member[%u]", set_count, conn_index);
cur_csis_inst = &member->insts[0];
memcpy(sirk, cur_csis_inst->info.set_sirk, sizeof(cur_csis_inst->info.set_sirk));
btp_send_csip_sirk_ev(conn, sirk, sirk_size);
for (size_t i = 0U; i < set_count; i++) {
LOG_DBG("CSIS[%zu]: %p", i, &member->insts[i]);
LOG_DBG("Rank: %u", member->insts[i].info.rank);
@ -68,8 +122,11 @@ static void csip_discover_cb(struct bt_conn *conn,
LOG_DBG("Lockable: %u", member->insts[i].info.lockable);
}
cur_csis_inst = &member->insts[0];
btp_csip_set_members[conn_index] = member;
csip_inst = bt_csip_set_coordinator_lookup_instance_by_index(conn, conn_index);
btp_send_csip_discovered_ev(conn, csip_inst->set_sirk_handle, csip_inst->set_size_handle,
csip_inst->set_lock_handle, csip_inst->rank_handle, err);
}
static void csip_lock_changed_cb(struct bt_csip_set_coordinator_csis_inst *inst,
@ -132,6 +189,43 @@ static uint8_t btp_csip_discover(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_VAL(err);
}
static uint8_t btp_csip_set_coordinator_lock(const void *cmd, uint16_t cmd_len, void *rsp,
uint16_t *rsp_len)
{
const struct btp_csip_set_coordinator_lock_cmd *cp = cmd;
int err;
LOG_DBG("");
err = bt_csip_set_coordinator_lock(btp_csip_set_members, cp->count, &cur_csis_inst->info);
if (err) {
LOG_DBG("Failed to lock set members");
return BTP_STATUS_FAILED;
}
return BTP_STATUS_SUCCESS;
}
static uint8_t btp_csip_set_coordinator_release(const void *cmd, uint16_t cmd_len, void *rsp,
uint16_t *rsp_len)
{
const struct btp_csip_set_coordinator_release_cmd *cp = cmd;
int err;
LOG_DBG("");
err = bt_csip_set_coordinator_release(btp_csip_set_members, cp->count,
&cur_csis_inst->info);
if (err) {
LOG_DBG("Failed to release set members");
return BTP_STATUS_FAILED;
}
return BTP_STATUS_SUCCESS;
}
static uint8_t btp_csip_start_ordered_access(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
{
@ -186,6 +280,16 @@ static const struct btp_handler csip_handlers[] = {
.expect_len = sizeof(struct btp_csip_start_ordered_access_cmd),
.func = btp_csip_start_ordered_access
},
{
.opcode = BTP_CSIP_SET_COORDINATOR_LOCK,
.expect_len = sizeof(struct btp_csip_set_coordinator_lock_cmd),
.func = btp_csip_set_coordinator_lock,
},
{
.opcode = BTP_CSIP_SET_COORDINATOR_RELEASE,
.expect_len = sizeof(struct btp_csip_set_coordinator_release_cmd),
.func = btp_csip_set_coordinator_release,
},
};
uint8_t tester_init_csip(void)