Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bluetooth: tester: MICP Client tests #60045

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions subsys/bluetooth/audio/micp_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @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_ */
21 changes: 2 additions & 19 deletions subsys/bluetooth/audio/micp_mic_ctlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,17 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/audio/micp.h>

#include <zephyr/logging/log.h>

#include "micp_internal.h"

LOG_MODULE_REGISTER(bt_micp_mic_ctlr, CONFIG_BT_MICP_MIC_CTLR_LOG_LEVEL);

#include "common/bt_str.h"

/* 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];
};
MariuszSkamra marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
8 changes: 8 additions & 0 deletions tests/bluetooth/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ endif()
if (CONFIG_BT_CSIP_SET_MEMBER)
target_sources(app PRIVATE src/btp_csis.c)
endif()

if(CONFIG_BT_MICP_MIC_DEV)
target_sources(app PRIVATE src/btp_micp.c)
endif()

if(CONFIG_BT_AICS)
target_sources(app PRIVATE src/btp_aics.c)
endif()
6 changes: 6 additions & 0 deletions tests/bluetooth/tester/overlay-le-audio.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ CONFIG_BT_BUF_CMD_TX_SIZE=255
# were freed too slow. The bt_bap_stream_ops.configured callback comes earlier.
CONFIG_BT_L2CAP_TX_BUF_COUNT=4

# MICP
CONFIG_BT_MICP_MIC_DEV=y
CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT=1
CONFIG_BT_MICP_MIC_CTLR=y
CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST=1

# ASCS
CONFIG_BT_ASCS_ASE_SNK_COUNT=2
CONFIG_BT_ASCS_ASE_SRC_COUNT=2
Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/tester/src/btp/btp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "btp_bap.h"
#include "btp_has.h"
#include "btp_csis.h"
#include "btp_micp.h"

#define BTP_MTU 1024
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))
Expand All @@ -48,6 +49,7 @@
#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_CSIS 17

#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_CSIS
Expand Down
106 changes: 101 additions & 5 deletions tests/bluetooth/tester/src/btp/btp_aics.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,125 @@
*/

#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/conn.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 bt_aics_cb aics_client_cb;
extern struct btp_aics_instance aics_client_instance;
extern struct btp_aics_instance aics_server_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_send_aics_status_ev(struct bt_conn *conn, bool active);
void btp_send_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;

/* AICS client/server commands */
#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
#define BTP_AICS_MAN_GAIN 0x05
#define BTP_AICS_AUTO_GAIN 0x06
#define BTP_AICS_MAN_GAIN_ONLY 0x07
#define BTP_AICS_AUTO_GAIN_ONLY 0x08
struct btp_aics_unmute_cmd {
bt_addr_le_t address;
} __packed;

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

#define BTP_AICS_DESCRIPTION 0x09
#define BTP_AICS_AUTO_GAIN_SET 0x06
struct btp_aics_auto_gain_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_AICS_SET_MAN_GAIN_ONLY 0x07
#define BTP_AICS_SET_AUTO_GAIN_ONLY 0x08
#define BTP_AICS_AUDIO_DESCRIPTION_SET 0x09
struct btp_aics_audio_desc_cmd {
uint8_t desc_len;
uint8_t desc[0];
} __packed;

#define BTP_AICS_MUTE_DISABLE 0x0a
#define BTP_AICS_GAIN_SETTING_PROP_GET 0x0b
struct btp_aics_gain_setting_prop_cmd {
bt_addr_le_t address;
} __packed;

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

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

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

#define BTP_AICS_DESCRIPTION_GET 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_GAIN_SETTING_PROPERTIES_EV 0x81
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 0x82
struct btp_aics_input_type_ev {
bt_addr_le_t address;
uint8_t input_type;
} __packed;

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

#define BTP_AICS_DESCRIPTION_EV 0x84
struct btp_aics_description_ev {
bt_addr_le_t address;
uint8_t data_len;
char data[0];
} __packed;
47 changes: 47 additions & 0 deletions tests/bluetooth/tester/src/btp/btp_micp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* btp_micp.h - Bluetooth tester headers */

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

/* MICP commands */
#define BTP_MICP_READ_SUPPORTED_COMMANDS 0x01
struct btp_micp_read_supported_commands_rp {
uint8_t data[0];
} __packed;

#define BTP_MICP_CTLR_DISCOVER 0x02
struct btp_micp_discover_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_MICP_CTLR_MUTE_READ 0x03
struct btp_micp_mute_read_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_MICP_CTLR_MUTE 0x04
struct btp_micp_mute_cmd {
bt_addr_le_t address;
} __packed;

/* MICP events */
#define BTP_MICP_DISCOVERED_EV 0x80
struct btp_micp_discovered_ev {
bt_addr_le_t address;
uint16_t mute_handle;
uint16_t state_handle;
uint16_t gain_handle;
uint16_t type_handle;
uint16_t status_handle;
uint16_t control_handle;
uint16_t desc_handle;
} __packed;

#define BTP_MICP_MUTE_STATE_EV 0x81
struct btp_micp_mute_state_ev {
bt_addr_le_t address;
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 @@ -92,3 +92,6 @@ uint8_t tester_unregister_has(void);

uint8_t tester_init_csis(void);
uint8_t tester_unregister_csis(void);

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