diff --git a/subsys/bluetooth/audio/Kconfig.tmap b/subsys/bluetooth/audio/Kconfig.tmap index aa5dd7e727c66..bd450f3d1540c 100644 --- a/subsys/bluetooth/audio/Kconfig.tmap +++ b/subsys/bluetooth/audio/Kconfig.tmap @@ -4,6 +4,25 @@ # # SPDX-License-Identifier: Apache-2.0 # +config BT_TMAP_CG_SUPPORTED + def_bool (BT_CAP_INITIATOR && BT_CAP_COMMANDER && BT_BAP_UNICAST_CLIENT && BT_AUDIO_RX && \ + BT_AUDIO_TX && BT_VCP_VOL_CTLR && BT_TBS) + +config BT_TMAP_CT_SUPPORTED + def_bool BT_CAP_ACCEPTOR && BT_BAP_UNICAST_SERVER + +config BT_TMAP_UMS_SUPPORTED + def_bool (BT_CAP_INITIATOR && BT_CAP_COMMANDER && BT_BAP_UNICAST_CLIENT && BT_AUDIO_TX && \ + BT_VCP_VOL_CTLR && BT_MCS) + +config BT_TMAP_UMR_SUPPORTED + def_bool BT_CAP_ACCEPTOR && BT_BAP_UNICAST_SERVER && BT_VCP_VOL_REND + +config BT_TMAP_BMS_SUPPORTED + def_bool BT_CAP_INITIATOR && BT_BAP_BROADCAST_SOURCE + +config BT_TMAP_BMR_SUPPORTED + def_bool BT_CAP_ACCEPTOR && BT_BAP_BROADCAST_SINK && BT_VCP_VOL_REND config BT_TMAP bool "Telephony and Media Audio Profile" diff --git a/subsys/bluetooth/audio/tmap.c b/subsys/bluetooth/audio/tmap.c index 68926bd260395..157c6cb48ae47 100644 --- a/subsys/bluetooth/audio/tmap.c +++ b/subsys/bluetooth/audio/tmap.c @@ -1,5 +1,6 @@ /* * Copyright 2023 NXP + * Copyright (c) 2024 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,6 +23,8 @@ #include #include #include +#include +#include #include #include "audio_internal.h" @@ -29,7 +32,9 @@ LOG_MODULE_REGISTER(bt_tmap, CONFIG_BT_TMAP_LOG_LEVEL); /* Hex value if all TMAP role bits are set */ -#define TMAP_ALL_ROLES 0x3F +#define TMAP_ALL_ROLES \ + (BT_TMAP_ROLE_CG | BT_TMAP_ROLE_CT | BT_TMAP_ROLE_UMS | BT_TMAP_ROLE_UMR | \ + BT_TMAP_ROLE_BMS | BT_TMAP_ROLE_BMR) static uint16_t tmap_role; static const struct bt_tmap_cb *cb; @@ -155,10 +160,61 @@ static ssize_t read_role(struct bt_conn *conn, static struct bt_gatt_attr svc_attrs[] = { BT_TMAS_SERVICE_DEFINITION }; static struct bt_gatt_service tmas; +static bool valid_tmap_role(enum bt_tmap_role role) +{ + if (role == 0 || (role & TMAP_ALL_ROLES) != role) { + LOG_DBG("Invalid role %d", role); + } + + if ((role & BT_TMAP_ROLE_CG) != 0 && !IS_ENABLED(CONFIG_BT_TMAP_CG_SUPPORTED)) { + LOG_DBG("Device does not support the CG role"); + + return false; + } + + if ((role & BT_TMAP_ROLE_CT) != 0 && !IS_ENABLED(CONFIG_BT_TMAP_CT_SUPPORTED)) { + LOG_DBG("Device does not support the CT role"); + + return false; + } + + if ((role & BT_TMAP_ROLE_UMS) != 0 && !IS_ENABLED(CONFIG_BT_TMAP_UMS_SUPPORTED)) { + LOG_DBG("Device does not support the UMS role"); + + return false; + } + + if ((role & BT_TMAP_ROLE_UMR) != 0 && !IS_ENABLED(CONFIG_BT_TMAP_UMR_SUPPORTED)) { + LOG_DBG("Device does not support the UMR role"); + + return false; + } + + if ((role & BT_TMAP_ROLE_BMS) != 0 && !IS_ENABLED(CONFIG_BT_TMAP_BMS_SUPPORTED)) { + LOG_DBG("Device does not support the BMS role"); + + return false; + } + + if ((role & BT_TMAP_ROLE_BMR) != 0 && !IS_ENABLED(CONFIG_BT_TMAP_BMR_SUPPORTED)) { + LOG_DBG("Device does not support the BMR role"); + + return false; + } + + return true; +} + int bt_tmap_register(enum bt_tmap_role role) { int err; + CHECKIF(!valid_tmap_role(role)) { + LOG_DBG("Invalid role: %d", role); + + return -EINVAL; + } + tmas = (struct bt_gatt_service)BT_GATT_SERVICE(svc_attrs); err = bt_gatt_service_register(&tmas);