Skip to content

Commit

Permalink
tests: Bluetooth: tester: Add initial support for HAP
Browse files Browse the repository at this point in the history
This adds initial support for Hearing Aid Profile BTP service commands.

Signed-off-by: Mariusz Skamra <[email protected]>
  • Loading branch information
MariuszSkamra authored and carlescufi committed Jan 2, 2024
1 parent b79a341 commit 4a77bdb
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/bluetooth/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ endif()
if(CONFIG_BT_MCC OR CONFIG_BT_MCS)
target_sources(app PRIVATE src/btp_mcp.c)
endif()

if(CONFIG_BT_HAS)
target_sources(app PRIVATE src/btp_hap.c)
endif()
2 changes: 2 additions & 0 deletions tests/bluetooth/tester/overlay-le-audio.conf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ CONFIG_BT_HAS=y
CONFIG_BT_HAS_PRESET_COUNT=6
CONFIG_BT_HAS_PRESET_NAME_DYNAMIC=y

CONFIG_BT_HAS_CLIENT=y

# CSIS
CONFIG_BT_CSIP_SET_MEMBER=y

Expand Down
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 @@ -32,6 +32,7 @@
#include "btp_cas.h"
#include "btp_mcp.h"
#include "btp_mcs.h"
#include "btp_hap.h"

#define BTP_MTU 1024
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))
Expand Down Expand Up @@ -63,8 +64,9 @@
#define BTP_SERVICE_ID_CAS 21
#define BTP_SERVICE_ID_MCP 22
#define BTP_SERVICE_ID_GMCS 23
#define BTP_SERVICE_ID_HAP 24

#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_GMCS
#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_HAP

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

/*
* Copyright (c) 2023 Codecoup
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>

/* HAP commands */
#define BTP_HAP_READ_SUPPORTED_COMMANDS 0x01
struct btp_hap_read_supported_commands_rp {
uint8_t data[0];
} __packed;

#define BTP_HAP_HA_OPT_PRESETS_SYNC 0x01
#define BTP_HAP_HA_OPT_PRESETS_INDEPENDENT 0x02
#define BTP_HAP_HA_OPT_PRESETS_DYNAMIC 0x04
#define BTP_HAP_HA_OPT_PRESETS_WRITABLE 0x08

#define BTP_HAP_HA_INIT 0x02
struct btp_hap_ha_init_cmd {
uint8_t type;
uint16_t opts;
} __packed;

#define BTP_HAP_HARC_INIT 0x03
#define BTP_HAP_HAUC_INIT 0x04
#define BTP_HAP_IAC_INIT 0x05

#define BTP_HAP_IAC_DISCOVER 0x06
struct btp_hap_iac_discover_cmd {
bt_addr_le_t address;
} __packed;

#define BTP_HAP_IAC_SET_ALERT 0x07
struct btp_hap_iac_set_alert_cmd {
bt_addr_le_t address;
uint8_t alert;
} __packed;

#define BTP_HAP_HAUC_DISCOVER 0x08
struct btp_hap_hauc_discover_cmd {
bt_addr_le_t address;
} __packed;

/* HAP events */
#define BT_HAP_EV_IAC_DISCOVERY_COMPLETE 0x80
struct btp_hap_iac_discovery_complete_ev {
bt_addr_le_t address;
uint8_t status;
} __packed;

#define BT_HAP_EV_HAUC_DISCOVERY_COMPLETE 0x81
struct btp_hap_hauc_discovery_complete_ev {
bt_addr_le_t address;
uint8_t status;
uint16_t has_hearing_aid_features_handle;
uint16_t has_control_point_handle;
uint16_t has_active_preset_index_handle;
} __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 @@ -120,3 +120,6 @@ uint8_t tester_unregister_mcp(void);

uint8_t tester_init_mcs(void);
uint8_t tester_unregister_mcs(void);

uint8_t tester_init_hap(void);
uint8_t tester_unregister_hap(void);
13 changes: 13 additions & 0 deletions tests/bluetooth/tester/src/btp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ static uint8_t supported_services(const void *cmd, uint16_t cmd_len,
#if defined(CONFIG_BT_MCS)
tester_set_bit(rp->data, BTP_SERVICE_ID_GMCS);
#endif /* CONFIG_BT_MCS */
#if defined(CONFIG_BT_HAS)
tester_set_bit(rp->data, BTP_SERVICE_ID_HAP);
#endif /* CONFIG_BT_HAS */

*rsp_len = sizeof(*rp) + 2;

Expand Down Expand Up @@ -211,6 +214,11 @@ static uint8_t register_service(const void *cmd, uint16_t cmd_len,
status = tester_init_mcs();
break;
#endif /* CONFIG_BT_MCS */
#if defined(CONFIG_BT_HAS)
case BTP_SERVICE_ID_HAP:
status = tester_init_hap();
break;
#endif /* CONFIG_BT_HAS */
default:
LOG_WRN("unknown id: 0x%02x", cp->id);
status = BTP_STATUS_FAILED;
Expand Down Expand Up @@ -328,6 +336,11 @@ static uint8_t unregister_service(const void *cmd, uint16_t cmd_len,
status = tester_unregister_mcs();
break;
#endif /* CONFIG_BT_MCS */
#if defined(CONFIG_BT_HAS)
case BTP_SERVICE_ID_HAP:
status = tester_unregister_hap();
break;
#endif /* CONFIG_BT_HAS */
default:
LOG_WRN("unknown id: 0x%x", cp->id);
status = BTP_STATUS_FAILED;
Expand Down
Loading

0 comments on commit 4a77bdb

Please sign in to comment.