Browse Source

Bluetooth: TMAP: Add role validation for bt_tmap_register

Add validation that the device supports the role
set by bt_tmap_register.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
pull/83425/head
Emil Gydesen 8 months ago committed by Benjamin Cabé
parent
commit
8c38d1b9a3
  1. 19
      subsys/bluetooth/audio/Kconfig.tmap
  2. 58
      subsys/bluetooth/audio/tmap.c

19
subsys/bluetooth/audio/Kconfig.tmap

@ -4,6 +4,25 @@ @@ -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"

58
subsys/bluetooth/audio/tmap.c

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
/*
* Copyright 2023 NXP
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -22,6 +23,8 @@ @@ -22,6 +23,8 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/check.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/types.h>
#include "audio_internal.h"
@ -29,7 +32,9 @@ @@ -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, @@ -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);

Loading…
Cancel
Save