From e8d4a68f8e6e3452a94d1ea016f8d6d50ff54b47 Mon Sep 17 00:00:00 2001 From: Piotr Narajowski Date: Wed, 27 Mar 2024 11:39:36 +0100 Subject: [PATCH] bluetooth: tester: Add CSIS btp command This commit adds CSIS command to change type of SIRK. This is needed for CSIS/SR/SP/BV-05-C test case. Signed-off-by: Piotr Narajowski --- tests/bluetooth/tester/overlay-le-audio.conf | 1 + tests/bluetooth/tester/src/btp/btp_csis.h | 5 +++ tests/bluetooth/tester/src/btp_csis.c | 41 +++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/overlay-le-audio.conf b/tests/bluetooth/tester/overlay-le-audio.conf index 12a237a720..ba1b6a4e55 100644 --- a/tests/bluetooth/tester/overlay-le-audio.conf +++ b/tests/bluetooth/tester/overlay-le-audio.conf @@ -100,6 +100,7 @@ CONFIG_BT_HAS_CLIENT=y # CSIS CONFIG_BT_CSIP_SET_MEMBER=y +CONFIG_BT_CSIP_SET_MEMBER_ENC_SIRK_SUPPORT=y # CSIP CONFIG_BT_CSIP_SET_COORDINATOR=y diff --git a/tests/bluetooth/tester/src/btp/btp_csis.h b/tests/bluetooth/tester/src/btp/btp_csis.h index 3c155acb6d..1a9d34221a 100644 --- a/tests/bluetooth/tester/src/btp/btp_csis.h +++ b/tests/bluetooth/tester/src/btp/btp_csis.h @@ -28,3 +28,8 @@ struct btp_csis_get_member_rsi_cmd { struct btp_csis_get_member_rsi_rp { uint8_t rsi[BT_CSIP_RSI_SIZE]; } __packed; + +#define BTP_CSIS_ENC_SIRK_TYPE 0x04 +struct btp_csis_set_sirk_type_cmd { + uint8_t encrypted; +} __packed; diff --git a/tests/bluetooth/tester/src/btp_csis.c b/tests/bluetooth/tester/src/btp_csis.c index 08e9b05723..f0d14f114f 100644 --- a/tests/bluetooth/tester/src/btp_csis.c +++ b/tests/bluetooth/tester/src/btp_csis.c @@ -17,6 +17,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL); #define BTP_STATUS_VAL(err) (err) ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS static struct bt_csip_set_member_svc_inst *csis_svc_inst; +static bool enc_sirk; static uint8_t csis_supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -27,6 +28,7 @@ static uint8_t csis_supported_commands(const void *cmd, uint16_t cmd_len, tester_set_bit(rp->data, BTP_CSIS_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_CSIS_SET_MEMBER_LOCK); tester_set_bit(rp->data, BTP_CSIS_GET_MEMBER_RSI); + tester_set_bit(rp->data, BTP_CSIS_ENC_SIRK_TYPE); *rsp_len = sizeof(*rp) + 1; @@ -61,6 +63,18 @@ static uint8_t csis_get_member_rsi(const void *cmd, uint16_t cmd_len, return BTP_STATUS_VAL(err); } +static uint8_t csis_set_sirk_type(const void *cmd, uint16_t cmd_len, void *rsp, + uint16_t *rsp_len) +{ + const struct btp_csis_set_sirk_type_cmd *cp = cmd; + + enc_sirk = cp->encrypted != 0U; + + LOG_DBG("Set SIRK type: %s", enc_sirk ? "encrypted" : "plain text"); + + return BTP_STATUS_SUCCESS; +} + static const struct btp_handler csis_handlers[] = { { .opcode = BTP_CSIS_READ_SUPPORTED_COMMANDS, @@ -77,7 +91,32 @@ static const struct btp_handler csis_handlers[] = { .opcode = BTP_CSIS_GET_MEMBER_RSI, .expect_len = sizeof(struct btp_csis_get_member_rsi_cmd), .func = csis_get_member_rsi + }, + { + .opcode = BTP_CSIS_ENC_SIRK_TYPE, + .expect_len = sizeof(struct btp_csis_set_sirk_type_cmd), + .func = csis_set_sirk_type, + }, +}; + +static void lock_changed_cb(struct bt_conn *conn, struct bt_csip_set_member_svc_inst *svc_inst, + bool locked) +{ + LOG_DBG("%s", locked ? "locked" : "unlocked"); +} + +static uint8_t sirk_read_cb(struct bt_conn *conn, struct bt_csip_set_member_svc_inst *svc_inst) +{ + if (enc_sirk) { + return BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT_ENC; + } else { + return BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT; } +} + +static struct bt_csip_set_member_cb csis_cb = { + .lock_changed = lock_changed_cb, + .sirk_read_req = sirk_read_cb, }; uint8_t tester_init_csis(void) @@ -88,7 +127,7 @@ uint8_t tester_init_csis(void) 0x5A, 0x41, 0xF1, 0x53, 0x05, 0x68, 0x8E, 0x83 }, .lockable = true, .rank = 1, - .cb = NULL + .cb = &csis_cb, }; int err = bt_csip_set_member_register(®ister_params, &csis_svc_inst);