Skip to content

Commit

Permalink
[nrf fromlist] tests: bluetooth: tester: refactor CSIP btp command
Browse files Browse the repository at this point in the history
Refactor CSIP btp commands by removing the 'count' parameter from
set_coordinator_lock and set_coordinator_release functions.
If we want to support lock/release procedure on subset of set members
in the future, 'count' param doesn't indicate a specific set member.
Instead, introduce 'address_count' and 'addr' array params, although their
usage is not yet implemented.

Upstream PR: zephyrproject-rtos/zephyr#71059

Signed-off-by: Piotr Narajowski <[email protected]>
  • Loading branch information
piotrnarajowski authored and carlescufi committed Aug 30, 2024
1 parent 425e40b commit cde1b1d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
6 changes: 4 additions & 2 deletions tests/bluetooth/tester/src/btp/btp_csip.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ struct btp_csip_start_ordered_access_cmd {

#define BTP_CSIP_SET_COORDINATOR_LOCK 0x04
struct btp_csip_set_coordinator_lock_cmd {
uint8_t count;
uint8_t addr_cnt;
bt_addr_le_t addr[];
} __packed;

#define BTP_CSIP_SET_COORDINATOR_RELEASE 0x05
struct btp_csip_set_coordinator_release_cmd {
uint8_t count;
uint8_t addr_cnt;
bt_addr_le_t addr[];
} __packed;

/* CSIP Events */
Expand Down
57 changes: 54 additions & 3 deletions tests/bluetooth/tester/src/btp_csip.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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 members_count;

static uint8_t btp_csip_supported_commands(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
Expand Down Expand Up @@ -189,15 +190,53 @@ static uint8_t btp_csip_discover(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_VAL(err);
}

static int get_available_members(const struct bt_csip_set_coordinator_set_member **members)
{
members_count = 0;

if (cur_csis_inst == NULL) {
LOG_ERR("No CISP instance available");
return BTP_STATUS_FAILED;
}

for (size_t i = 0; i < (size_t)ARRAY_SIZE(btp_csip_set_members); i++) {
if (btp_csip_set_members[i] == NULL) {
continue;
}

members[members_count++] = btp_csip_set_members[i];
}

if (members_count == 0) {
LOG_ERR("No set members available");
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}

static uint8_t btp_csip_set_coordinator_lock(const void *cmd, uint16_t cmd_len, void *rsp,
uint16_t *rsp_len)
{
const struct bt_csip_set_coordinator_set_member *members[ARRAY_SIZE(btp_csip_set_members)];
const struct btp_csip_set_coordinator_lock_cmd *cp = cmd;
int err;
int rc;

LOG_DBG("");

err = bt_csip_set_coordinator_lock(btp_csip_set_members, cp->count, &cur_csis_inst->info);
if (cp->addr_cnt != 0) {
/* TODO: add support for lock request procedure on subset of set members */
return BTP_STATUS_FAILED;
}

rc = get_available_members(members);

if (rc) {
return BTP_STATUS_FAILED;
}

err = bt_csip_set_coordinator_lock(members, members_count, &cur_csis_inst->info);

if (err) {
LOG_DBG("Failed to lock set members");
Expand All @@ -210,13 +249,25 @@ static uint8_t btp_csip_set_coordinator_lock(const void *cmd, uint16_t cmd_len,
static uint8_t btp_csip_set_coordinator_release(const void *cmd, uint16_t cmd_len, void *rsp,
uint16_t *rsp_len)
{
const struct bt_csip_set_coordinator_set_member *members[ARRAY_SIZE(btp_csip_set_members)];
const struct btp_csip_set_coordinator_release_cmd *cp = cmd;
int err;
int rc;

LOG_DBG("");

err = bt_csip_set_coordinator_release(btp_csip_set_members, cp->count,
&cur_csis_inst->info);
if (cp->addr_cnt != 0) {
/* TODO: add support for lock release procedure on subset of set members */
return BTP_STATUS_FAILED;
}

rc = get_available_members(members);

if (rc) {
return BTP_STATUS_FAILED;
}

err = bt_csip_set_coordinator_release(members, members_count, &cur_csis_inst->info);

if (err) {
LOG_DBG("Failed to release set members");
Expand Down

0 comments on commit cde1b1d

Please sign in to comment.