Skip to content

Commit

Permalink
bluetooth: tester: MICP Client tests
Browse files Browse the repository at this point in the history
Add support for MICP Client tests.

Signed-off-by: Piotr Narajowski <piotr.narajowski@codecoup.pl>
  • Loading branch information
piotrnarajowski committed Jul 25, 2023
1 parent df6f074 commit 9cba7b3
Show file tree
Hide file tree
Showing 13 changed files with 1,080 additions and 326 deletions.
33 changes: 3 additions & 30 deletions include/zephyr/bluetooth/audio/micp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include <stdint.h>
#include <../../subsys/bluetooth/audio/micp_internal.h>

#include <zephyr/bluetooth/audio/aics.h>

Expand All @@ -36,13 +37,14 @@ extern "C" {
/** Application error codes */
#define BT_MICP_ERR_MUTE_DISABLED 0x80
#define BT_MICP_ERR_VAL_OUT_OF_RANGE 0x81
#define BT_MICP_ERR_INVALID_COUNTER 0x82

/** Microphone Control Profile mute states */
#define BT_MICP_MUTE_UNMUTED 0x00
#define BT_MICP_MUTE_MUTED 0x01
#define BT_MICP_MUTE_DISABLED 0x02

/** @brief Opaque Microphone Controller instance. */
///** @brief Opaque Microphone Controller instance. */
struct bt_micp_mic_ctlr;

/** @brief Register parameters structure for Microphone Control Service */
Expand Down Expand Up @@ -272,35 +274,6 @@ int bt_micp_mic_ctlr_mute_get(struct bt_micp_mic_ctlr *mic_ctlr);
*/
int bt_micp_mic_ctlr_cb_register(struct bt_micp_mic_ctlr_cb *cb);

/**
* @brief Get the start handle and end handle a Microphone Controller instance
*
* @param mic_ctlr Microphone Controller instance pointer.
* @param mute_handle Mute characteristic handle.
*
* @return 0 if success, errno on failure.
*/
int bt_micp_mic_ctlr_chrc_get(const struct bt_micp_mic_ctlr *mic_ctlr, uint16_t *mute_handle);

/**
* @brief Get handles of each characteristic of AICS.
*
* @param micp_included Included Services containing array of pointers to AICS instances.
* @param state_handle state handle.
* @param gain_handle gain handle.
* @param type_handle type handle.
* @param status_handle status handle.
* @param control_handle control handle.
* @param desc_handle desc handle.
*
* @return 0 if success, errno on failure.
*/
int bt_micp_mic_ctlr_aics_chrc_get(const struct bt_micp_included micp_included,
uint16_t *state_handle, uint16_t *gain_handle,
uint16_t *type_handle,
uint16_t *status_handle, uint16_t *control_handle,
uint16_t *desc_handle);

#ifdef __cplusplus
}
#endif
Expand Down
35 changes: 35 additions & 0 deletions subsys/bluetooth/audio/micp_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @file
* @brief Internal APIs for Bluetooth MICP.
*/

/*
* Copyright (c) 2020 Bose Corporation
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICP_INTERNAL_
#define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICP_INTERNAL_
#include <zephyr/types.h>
#include <zephyr/bluetooth/gatt.h>

struct bt_micp_mic_ctlr {
uint16_t start_handle;
uint16_t end_handle;
uint16_t mute_handle;
struct bt_gatt_subscribe_params mute_sub_params;
struct bt_gatt_discover_params mute_sub_disc_params;

bool busy;
uint8_t mute_val_buf[1]; /* Mute value is a single octet */
struct bt_gatt_write_params write_params;
struct bt_gatt_read_params read_params;
struct bt_gatt_discover_params discover_params;
struct bt_conn *conn;

uint8_t aics_inst_cnt;
struct bt_aics *aics[CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT];
};

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MICP_INTERNAL_ */
62 changes: 2 additions & 60 deletions subsys/bluetooth/audio/micp_mic_ctlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/audio/micp.h>
#include <../../subsys/bluetooth/audio/aics_internal.h>

#include "micp_internal.h"

#include <zephyr/logging/log.h>

Expand All @@ -30,24 +31,6 @@ LOG_MODULE_REGISTER(bt_micp_mic_ctlr, CONFIG_BT_MICP_MIC_CTLR_LOG_LEVEL);
/* Callback functions */
static struct bt_micp_mic_ctlr_cb *micp_mic_ctlr_cb;

struct bt_micp_mic_ctlr {
uint16_t start_handle;
uint16_t end_handle;
uint16_t mute_handle;
struct bt_gatt_subscribe_params mute_sub_params;
struct bt_gatt_discover_params mute_sub_disc_params;

bool busy;
uint8_t mute_val_buf[1]; /* Mute value is a single octet */
struct bt_gatt_write_params write_params;
struct bt_gatt_read_params read_params;
struct bt_gatt_discover_params discover_params;
struct bt_conn *conn;

uint8_t aics_inst_cnt;
struct bt_aics *aics[CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST];
};

static struct bt_micp_mic_ctlr mic_ctlrs[CONFIG_BT_MAX_CONN];
static struct bt_uuid *mics_uuid = BT_UUID_MICS;

Expand Down Expand Up @@ -516,47 +499,6 @@ int bt_micp_mic_ctlr_conn_get(const struct bt_micp_mic_ctlr *mic_ctlr, struct bt
return 0;
}

int bt_micp_mic_ctlr_chrc_get(const struct bt_micp_mic_ctlr *mic_ctlr, uint16_t *mute_handle)
{
CHECKIF(mic_ctlr == NULL)
{
LOG_DBG("NULL mic_ctlr pointer");
return -EINVAL;
}

if (mic_ctlr->conn == NULL) {
LOG_DBG("mic_ctlr pointer not associated with a connection. "
"Do discovery first");
return -ENOTCONN;
}

*mute_handle = mic_ctlr->mute_handle;

return 0;
}

int bt_micp_mic_ctlr_aics_chrc_get(const struct bt_micp_included micp_included,
uint16_t *state_handle, uint16_t *gain_handle,
uint16_t *type_handle,
uint16_t *status_handle, uint16_t *control_handle,
uint16_t *desc_handle)
{
CHECKIF(micp_included.aics == NULL)
{
LOG_DBG("NULL AICS instance");
return -EINVAL;
}

*state_handle = micp_included.aics[0]->cli.state_handle;
*gain_handle = micp_included.aics[0]->cli.gain_handle;
*type_handle = micp_included.aics[0]->cli.type_handle;
*status_handle = micp_included.aics[0]->cli.status_handle;
*control_handle = micp_included.aics[0]->cli.control_handle;
*desc_handle = micp_included.aics[0]->cli.desc_handle;

return 0;
}

int bt_micp_mic_ctlr_mute_get(struct bt_micp_mic_ctlr *mic_ctlr)
{
int err;
Expand Down
5 changes: 5 additions & 0 deletions tests/bluetooth/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ endif()
if(CONFIG_BT_HAS)
target_sources(app PRIVATE src/btp_has.c)
endif()

if(CONFIG_BT_MICP_MIC_DEV)
target_sources(app PRIVATE src/btp_micp.c)
target_sources(app PRIVATE src/btp_aics.c)
endif()
4 changes: 4 additions & 0 deletions tests/bluetooth/tester/overlay-le-audio.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ CONFIG_BT_BUF_EVT_RX_COUNT=16
CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_CMD_TX_SIZE=255

# MICP
CONFIG_BT_MICP_MIC_DEV=y
CONFIG_BT_MICP_MIC_CTLR=y

# ASCS
CONFIG_BT_ASCS_ASE_SNK_COUNT=2
CONFIG_BT_ASCS_ASE_SRC_COUNT=2
Expand Down
5 changes: 4 additions & 1 deletion tests/bluetooth/tester/src/btp/btp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "btp_ascs.h"
#include "btp_bap.h"
#include "btp_has.h"
#include "btp_micp.h"

#define BTP_MTU 1024
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))
Expand All @@ -47,8 +48,10 @@
#define BTP_SERVICE_ID_ASCS 13
#define BTP_SERVICE_ID_BAP 14
#define BTP_SERVICE_ID_HAS 15
#define BTP_SERVICE_ID_MICP 16
#define BTP_SERVICE_ID_MICS 17

#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_HAS
#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_MICS

#define BTP_STATUS_SUCCESS 0x00
#define BTP_STATUS_FAILED 0x01
Expand Down
111 changes: 110 additions & 1 deletion tests/bluetooth/tester/src/btp/btp_aics.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,136 @@
#include <zephyr/sys/util.h>

/*AICS service */
struct btp_aics_instance {
/** Number of Audio Input Control Service instances */
uint8_t aics_cnt;
/** Array of pointers to Audio Input Control Service instances */
struct bt_aics **aics;
};

extern struct btp_aics_instance aics_instance;
void btp_send_aics_state_changed_ev(struct bt_conn *conn);
void btp_send_aics_state_ev(struct bt_conn *conn, int8_t gain, uint8_t mute, uint8_t mode);
void btp_send_gain_setting_properties_ev(struct bt_conn *conn, uint8_t units, int8_t minimum,
int8_t maximum);
void btp_send_aics_input_type_event(struct bt_conn *conn, uint8_t input_type);
void btp_aics_status_ev(struct bt_conn *conn, bool active);
void btp_aics_description_ev(struct bt_conn *conn, uint8_t data_len, char *description);

#define BTP_AICS_READ_SUPPORTED_COMMANDS 0x01
struct btp_aics_read_supported_commands_rp {
uint8_t data[0];
} __packed;

#define BTP_AICS_SET_GAIN 0x02
struct btp_aics_set_gain_cmd {
bt_addr_le_t address;
int8_t gain;
} __packed;

#define BTP_AICS_MUTE 0x03
struct btp_aics_mute_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_UNMUTE 0x04
struct btp_aics_unmute_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_MAN_GAIN 0x05
struct btp_aics_manual_gain_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_AUTO_GAIN 0x06
struct btp_aics_auto_gain_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_MAN_GAIN_ONLY 0x07
struct btp_aics_man_gain_only_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_AUTO_GAIN_ONLY 0x08
struct btp_aics_auto_gain_only_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_DESCRIPTION 0x09
#define BTP_AICS_DESCRIPTION_SET 0x09
struct btp_aics_audio_desc_cmd {
uint8_t desc_len;
uint8_t desc[0];
} __packed;

#define BTP_AICS_MUTE_DISABLE 0x0a
struct btp_aics_mute_disable_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_GAIN_SETTING_PROP 0x0b
struct btp_aics_gain_setting_prop_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_TYPE 0x0c
struct btp_aics_type_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_STATUS 0x0d
struct btp_aics_status_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_STATE 0x0e
struct btp_aics_state_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_DESCRIPTION 0x0f
struct btp_aics_desc_cmd {
bt_addr_le_t address;
} __packed;

/* AICS events */
#define BTP_AICS_STATE_EV 0x80
struct btp_aics_state_ev {
bt_addr_le_t address;
int8_t gain;
uint8_t mute;
uint8_t mode;
} __packed;

#define BTP_AICS_STATE_CHANGED_EV 0x81
struct btp_aics_state_changed_ev {
bt_addr_le_t address;
} __packed;

#define BTP_GAIN_SETTING_PROPERTIES_EV 0x82
struct btp_gain_setting_properties_ev {
bt_addr_le_t address;
uint8_t units;
int8_t minimum;
int8_t maximum;
} __packed;

#define BTP_AICS_INPUT_TYPE_EV 0x83
struct btp_aics_input_type_ev {
bt_addr_le_t address;
uint8_t input_type;
} __packed;

#define BTP_AICS_STATUS_EV 0x84
struct btp_aics_status_ev {
bt_addr_le_t address;
bool active;
} __packed;

#define BTP_AICS_DESCRIPTION_EV 0x85
struct btp_aics_description_ev {
bt_addr_le_t address;
uint8_t data_len;
char data[0];
} __packed;
Loading

0 comments on commit 9cba7b3

Please sign in to comment.