Bluetooth: audio: Add initial Hearing Access Service implementation

This adds bare minimum implementation of Hearing Access Service.
The GATT HAS service contains one Hearing Aid Features mandatory
characteristic.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2022-03-14 14:15:32 +01:00 committed by Carles Cufí
commit 7c99e67b94
5 changed files with 148 additions and 0 deletions

View file

@ -50,3 +50,4 @@ zephyr_library_sources_ifdef(CONFIG_BT_AUDIO_BROADCAST_SOURCE broadcast_source.c
zephyr_library_sources_ifdef(CONFIG_BT_AUDIO_BROADCAST_SINK broadcast_sink.c) zephyr_library_sources_ifdef(CONFIG_BT_AUDIO_BROADCAST_SINK broadcast_sink.c)
zephyr_library_sources_ifdef(CONFIG_BT_BASS bass.c) zephyr_library_sources_ifdef(CONFIG_BT_BASS bass.c)
zephyr_library_sources_ifdef(CONFIG_BT_BASS_CLIENT bass_client.c) zephyr_library_sources_ifdef(CONFIG_BT_BASS_CLIENT bass_client.c)
zephyr_library_sources_ifdef(CONFIG_BT_HAS has.c)

View file

@ -33,5 +33,6 @@ rsource "Kconfig.mics"
rsource "Kconfig.csis" rsource "Kconfig.csis"
rsource "Kconfig.mcs" rsource "Kconfig.mcs"
rsource "Kconfig.bass" rsource "Kconfig.bass"
rsource "Kconfig.has"
endif # BT_AUDIO endif # BT_AUDIO

View file

@ -0,0 +1,63 @@
# Bluetooth Audio - Hearing Access Service options
#
# Copyright (c) 2022 Codecoup
#
# SPDX-License-Identifier: Apache-2.0
config BT_HAS
bool "Hearing Access Service support [EXPERIMENTAL]"
select EXPERIMENTAL
help
This option enables support for Hearing Access Service.
if BT_HAS
choice BT_HAS_HEARING_AID_TYPE_CHOICE
prompt "Hearing Aid Type selection"
help
Select the Hearing Aid Type to compile.
config BT_HAS_HEARING_AID_MONAURAL
bool "Monaural Hearing Aid"
config BT_HAS_HEARING_AID_BINAURAL
depends on BT_CSIS
bool "Binaural Hearing Aid"
config BT_HAS_HEARING_AID_BANDED
bool "Banded Hearing Aid"
endchoice # BT_HAS_HEARING_AID_TYPE_CHOICE
if BT_HAS_HEARING_AID_MONAURAL || BT_HAS_HEARING_AID_BINAURAL
choice BT_HAS_HEARING_AID_LOCATION
prompt "Hearing Aid Device Location"
help
Select the Hearing Aid Device location.
config BT_HAS_HEARING_AID_LEFT
bool "Left Ear"
config BT_HAS_HEARING_AID_RIGHT
bool "Right Ear"
endchoice # BT_HAS_HEARING_AID_LOCATION
endif # BT_HAS_HEARING_AID_MONAURAL || BT_HAS_HEARING_AID_BINAURAL
config BT_HAS_HEARING_AID_TYPE
int # hidden
range 0 2
default 0 if BT_HAS_HEARING_AID_BINAURAL
default 1 if BT_HAS_HEARING_AID_MONAURAL
default 2 if BT_HAS_HEARING_AID_BANDED
help
The value shall be one of 3 defined by the HAS 1.0 specification table 3.2
config BT_DEBUG_HAS
bool "Hearing Access Service debug"
help
This option enables enables Hearing Access Service debug logs.
endif # BT_HAS

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2022 Codecoup
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/gatt.h>
#include <bluetooth/audio/audio.h>
#include <bluetooth/audio/capabilities.h>
#include "has_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HAS)
#define LOG_MODULE_NAME bt_has
#include "common/log.h"
static struct bt_has has;
static ssize_t read_features(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset)
{
BT_DBG("conn %p attr %p offset %d", conn, attr, offset);
if (offset > sizeof(has.features)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}
return bt_gatt_attr_read(conn, attr, buf, len, offset, &has.features,
sizeof(has.features));
}
/* Hearing Access Service GATT Attributes */
BT_GATT_SERVICE_DEFINE(has_svc,
BT_GATT_PRIMARY_SERVICE(BT_UUID_HAS),
BT_GATT_CHARACTERISTIC(BT_UUID_HAS_HEARING_AID_FEATURES, BT_GATT_CHRC_READ,
BT_GATT_PERM_READ_ENCRYPT, read_features, NULL, NULL),
);
static int has_init(const struct device *dev)
{
ARG_UNUSED(dev);
/* Initialize the supported features characteristic value */
has.features = CONFIG_BT_HAS_HEARING_AID_TYPE & BT_HAS_FEAT_HEARING_AID_TYPE_MASK;
if (IS_ENABLED(CONFIG_BT_HAS_HEARING_AID_BANDED)) {
/* HAP_d1.0r00; 3.7 BAP Unicast Server role requirements
* A Banded Hearing Aid in the HA role shall set the Front Left and the Front
* Right bits to a value of 0b1 in the Sink Audio Locations characteristic value.
*/
bt_audio_capability_set_location(BT_AUDIO_SINK, BT_AUDIO_LOCATION_FRONT_LEFT |
BT_AUDIO_LOCATION_FRONT_RIGHT);
} else if (IS_ENABLED(CONFIG_BT_HAS_HEARING_AID_LEFT)) {
bt_audio_capability_set_location(BT_AUDIO_SINK, BT_AUDIO_LOCATION_FRONT_LEFT);
} else {
bt_audio_capability_set_location(BT_AUDIO_SINK, BT_AUDIO_LOCATION_FRONT_RIGHT);
}
return 0;
}
SYS_INIT(has_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

View file

@ -0,0 +1,16 @@
/** @file
* @brief Internal APIs for Bluetooth Hearing Access Profile.
*/
/*
* Copyright (c) 2022 Codecoup
*
* SPDX-License-Identifier: Apache-2.0
*/
#define BT_HAS_FEAT_HEARING_AID_TYPE_MASK 0x03
struct bt_has {
/** Hearing Aid Features value */
uint8_t features;
};