Skip to content

Commit

Permalink
bluetooth: tester: MICS Server tests
Browse files Browse the repository at this point in the history
Add support for MICS Server tests

Signed-off-by: Piotr Narajowski <[email protected]>
  • Loading branch information
piotrnarajowski authored and nashif committed Sep 11, 2023
1 parent 08130f0 commit a2f92ba
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/bluetooth/tester/src/btp/btp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "btp_has.h"
#include "btp_csis.h"
#include "btp_micp.h"
#include "btp_mics.h"

#define BTP_MTU 1024
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))
Expand All @@ -51,8 +52,9 @@
#define BTP_SERVICE_ID_HAS 15
#define BTP_SERVICE_ID_MICP 16
#define BTP_SERVICE_ID_CSIS 17
#define BTP_SERVICE_ID_MICS 18

#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_CSIS
#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_MICS

#define BTP_STATUS_SUCCESS 0x00
#define BTP_STATUS_FAILED 0x01
Expand Down
23 changes: 23 additions & 0 deletions tests/bluetooth/tester/src/btp/btp_mics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* btp_mics.h - Bluetooth tester headers */

/*
* Copyright (c) 2023 Codecoup
*
* SPDX-License-Identifier: Apache-2.0
*/

/* MICS commands */
#define BTP_MICS_READ_SUPPORTED_COMMANDS 0x01
struct btp_mics_read_supported_commands_rp {
uint8_t data[0];
} __packed;

#define BTP_MICS_DEV_MUTE_DISABLE 0x02
#define BTP_MICS_DEV_MUTE_READ 0x03
#define BTP_MICS_DEV_MUTE 0x04
#define BTP_MICS_DEV_UNMUTE 0x05

#define BTP_MICS_MUTE_STATE_EV 0x80
struct btp_mics_mute_state_ev {
uint8_t mute;
} __packed;
3 changes: 3 additions & 0 deletions tests/bluetooth/tester/src/btp/bttester.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ uint8_t tester_unregister_csis(void);

uint8_t tester_init_micp(void);
uint8_t tester_unregister_micp(void);

uint8_t tester_init_mics(void);
uint8_t tester_unregister_mics(void);
9 changes: 7 additions & 2 deletions tests/bluetooth/tester/src/btp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,15 @@ static uint8_t register_service(const void *cmd, uint16_t cmd_len,
case BTP_SERVICE_ID_BAP:
status = tester_init_bap();
break;
case BTP_SERVICE_ID_MICP:
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT or CONFIG_BT_BAP_UNICAST_SERVER */
#if defined(CONFIG_BT_MICP_MIC_DEV) || defined(CONFIG_BT_MICP_MIC_CTLR)
case BTP_SERVICE_ID_MICP:
status = tester_init_micp();
break;
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT or CONFIG_BT_BAP_UNICAST_SERVER */
case BTP_SERVICE_ID_MICS:
status = tester_init_mics();
break;
#endif /* CONFIG_BT_MICP_MIC_DEV or CONFIG_BT_MICP_MIC_CTLR */
#if defined(CONFIG_BT_HAS)
case BTP_SERVICE_ID_HAS:
status = tester_init_has();
Expand Down
216 changes: 215 additions & 1 deletion tests/bluetooth/tester/src/btp_micp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stddef.h>
#include <errno.h>
#include <stdio.h>

#include <zephyr/types.h>
#include <zephyr/kernel.h>
Expand All @@ -30,6 +31,7 @@
LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL);

static struct bt_micp_mic_ctlr *mic_ctlr;
static struct bt_micp_mic_dev_register_param mic_dev_register_param;

#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
static struct bt_micp_included micp_included;
Expand All @@ -47,6 +49,7 @@ extern struct btp_aics_instance aics_client_instance;
extern struct bt_aics_cb aics_client_cb;
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */

/* Microphone Control Profile */
static void btp_send_micp_found_ev(struct bt_conn *conn, const struct chrc_handles *micp_handles)
{
struct btp_micp_discovered_ev ev;
Expand Down Expand Up @@ -237,7 +240,7 @@ static const struct btp_handler micp_handlers[] = {
.opcode = BTP_MICP_CTLR_MUTE,
.expect_len = sizeof(struct btp_micp_mute_cmd),
.func = micp_mute,
}
},
};

uint8_t tester_init_micp(void)
Expand All @@ -262,3 +265,214 @@ uint8_t tester_unregister_micp(void)
(void)bt_micp_mic_ctlr_cb_register(NULL);
return BTP_STATUS_SUCCESS;
}

/* Microphone Control Service */
static uint8_t mics_supported_commands(const void *cmd, uint16_t cmd_len, void *rsp,
uint16_t *rsp_len)
{
struct btp_mics_read_supported_commands_rp *rp = rsp;

/* octet 0 */
tester_set_bit(rp->data, BTP_MICS_READ_SUPPORTED_COMMANDS);
tester_set_bit(rp->data, BTP_MICS_DEV_MUTE_DISABLE);
tester_set_bit(rp->data, BTP_MICS_DEV_MUTE_READ);
tester_set_bit(rp->data, BTP_MICS_DEV_MUTE);
tester_set_bit(rp->data, BTP_MICS_DEV_UNMUTE);

*rsp_len = sizeof(*rp) + 1;

return BTP_STATUS_SUCCESS;
}

static uint8_t mics_mute_disable(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
{
int err;

LOG_DBG("MICP Mute disable");

err = bt_micp_mic_dev_mute_disable();
if (err) {
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}

static uint8_t mics_mute_read(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
{
int err;

LOG_DBG("MICS Mute state read");

err = bt_micp_mic_dev_mute_get();
if (err) {
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}

static uint8_t mics_mute(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
{
int err;

LOG_DBG("MICS Mute");

err = bt_micp_mic_dev_mute();
if (err) {
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}

static uint8_t mics_unmute(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
{
int err;

LOG_DBG("MICS Mute");

err = bt_micp_mic_dev_unmute();
if (err) {
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}

static void btp_send_mics_mute_state_ev(uint8_t mute)
{
struct btp_mics_mute_state_ev ev;

ev.mute = mute;

tester_event(BTP_SERVICE_ID_MICS, BTP_MICS_MUTE_STATE_EV, &ev, sizeof(ev));
}

static void mic_dev_mute_cb(uint8_t mute)
{
LOG_DBG("Microphone Device Mute cb");

btp_send_mics_mute_state_ev(mute);
}

static struct bt_micp_mic_dev_cb mic_dev_cb = {
.mute = mic_dev_mute_cb,
};

#if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain,
uint8_t mute, uint8_t mode)
{
LOG_DBG("AICS state callback (%d)", err);
}

static void aics_gain_setting_cb(struct bt_aics *inst, int err, uint8_t units,
int8_t minimum, int8_t maximum)
{
LOG_DBG("AICS gain setting callback (%d)", err);
}

static void aics_input_type_cb(struct bt_aics *inst, int err,
uint8_t input_type)
{
LOG_DBG("AICS input type callback (%d)", err);
}

static void aics_status_cb(struct bt_aics *inst, int err, bool active)
{
LOG_DBG("AICS status callback (%d)", err);
}

static void aics_description_cb(struct bt_aics *inst, int err,
char *description)
{
LOG_DBG("AICS description callback (%d)", err);
}

struct bt_aics_cb aics_mic_dev_cb = {
.state = aics_state_cb,
.gain_setting = aics_gain_setting_cb,
.type = aics_input_type_cb,
.status = aics_status_cb,
.description = aics_description_cb,
};
#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */

static const struct btp_handler mics_handlers[] = {
{
.opcode = BTP_MICS_READ_SUPPORTED_COMMANDS,
.index = BTP_INDEX_NONE,
.expect_len = 0,
.func = mics_supported_commands,
},
{
.opcode = BTP_MICS_DEV_MUTE_DISABLE,
.expect_len = 0,
.func = mics_mute_disable,
},
{
.opcode = BTP_MICS_DEV_MUTE_READ,
.expect_len = 0,
.func = mics_mute_read,
},
{
.opcode = BTP_MICS_DEV_MUTE,
.expect_len = 0,
.func = mics_mute,
},
{
.opcode = BTP_MICS_DEV_UNMUTE,
.expect_len = 0,
.func = mics_unmute,
},
};

uint8_t tester_init_mics(void)
{
int err;

memset(&mic_dev_register_param, 0, sizeof(mic_dev_register_param));

#if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
char input_desc[CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT][16];

for (size_t i = 0; i < ARRAY_SIZE(mic_dev_register_param.aics_param); i++) {
mic_dev_register_param.aics_param[i].desc_writable = true;
snprintf(input_desc[i], sizeof(input_desc[i]),
"Input %zu", i + 1);
mic_dev_register_param.aics_param[i].description = input_desc[i];
mic_dev_register_param.aics_param[i].type = BT_AICS_INPUT_TYPE_DIGITAL;
mic_dev_register_param.aics_param[i].status = 1;
mic_dev_register_param.aics_param[i].gain_mode = BT_AICS_MODE_MANUAL;
mic_dev_register_param.aics_param[i].units = 1;
mic_dev_register_param.aics_param[i].min_gain = 0;
mic_dev_register_param.aics_param[i].max_gain = 100;
mic_dev_register_param.aics_param[i].cb = &aics_mic_dev_cb;
}
#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */

mic_dev_register_param.cb = &mic_dev_cb;

err = bt_micp_mic_dev_register(&mic_dev_register_param);
if (err) {
return BTP_STATUS_FAILED;
}

#if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
err = bt_micp_mic_dev_included_get(&micp_included);
if (err) {
return BTP_STATUS_FAILED;
}
#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */

tester_register_command_handlers(BTP_SERVICE_ID_MICS, mics_handlers,
ARRAY_SIZE(mics_handlers));

return BTP_STATUS_SUCCESS;
}

uint8_t tester_unregister_mics(void)
{
return BTP_STATUS_SUCCESS;
}

0 comments on commit a2f92ba

Please sign in to comment.