Skip to content

Commit

Permalink
Bluetooth: TMAP: Add TMAP shell module
Browse files Browse the repository at this point in the history
Add simple TMAP shell module that supports the TMAP
discovery.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley authored and carlescufi committed Jun 30, 2023
1 parent 43ef100 commit 49a70aa
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/connectivity/bluetooth/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Bluetooth APIs
shell/csip.rst
shell/iso.rst
shell/mcp.rst
shell/tmap.rst
22 changes: 22 additions & 0 deletions doc/connectivity/bluetooth/api/shell/tmap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Bluetooth: Telephone and Media Audio Profile Shell
##################################################

This document describes how to run the Telephone and Media Audio Profile functionality.
Unlike most other low-layer profiles, TMAP is a profile that exists and has a service (TMAS) on all
devices. Thus both the initiator and acceptor (or central and peripheral) should do a discovery of
the remote device's TMAS to see what TMAP roles they support.

Using the TMAP Shell
********************

When the Bluetooth stack has been initialized (:code:`bt init`), the TMAS can be registered by
by calling :code:`tmap init`.

.. code-block:: console
tmap --help
tmap - Bluetooth TMAP shell commands
Subcommands:
init :Initialize and register the TMAS
discover :Discover TMAS on remote device
4 changes: 4 additions & 0 deletions subsys/bluetooth/audio/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ zephyr_library_sources_ifdef(
CONFIG_BT_HAS_CLIENT
has_client.c
)
zephyr_library_sources_ifdef(
CONFIG_BT_TMAP
tmap.c
)
# We use BT_BAP_STREAM as a common ground for audio, as that is set whenever
# any audio stream functionality is enabled.
zephyr_library_sources_ifdef(
Expand Down
121 changes: 121 additions & 0 deletions subsys/bluetooth/audio/shell/tmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/** @file
* @brief Bluetooth Telephone and Media Audio Profile shell
*
*/

/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/bluetooth/audio/tmap.h>
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#include <zephyr/sys/util.h>

#include "shell/bt.h"

#define TMAP_CG_SUPPORTED \
(IS_ENABLED(CONFIG_BT_CAP_INITIATOR) && IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && \
IS_ENABLED(CONFIG_BT_TBS) && IS_ENABLED(CONFIG_BT_VCP_VOL_CTLR))

#define TMAP_CT_SUPPORTED \
(IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR) && IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) && \
IS_ENABLED(CONFIG_BT_TBS_CLIENT) && \
(IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK) && \
IS_ENABLED(CONFIG_BT_VCP_VOL_REND) == IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)))

#define TMAP_UMS_SUPPORTED \
(IS_ENABLED(CONFIG_BT_CAP_INITIATOR) && \
IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK) && IS_ENABLED(CONFIG_BT_VCP_VOL_CTLR) && \
IS_ENABLED(CONFIG_BT_MCS))

#define TMAP_UMR_SUPPORTED \
(IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR) && IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK) && \
IS_ENABLED(CONFIG_BT_VCP_VOL_REND))

#define TMAP_BMS_SUPPORTED \
(IS_ENABLED(CONFIG_BT_CAP_INITIATOR) && IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE))

#define TMAP_BMR_SUPPORTED \
(IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR) && IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK))

static int cmd_tmap_init(const struct shell *sh, size_t argc, char **argv)
{
const enum bt_tmap_role role = (TMAP_CG_SUPPORTED ? BT_TMAP_ROLE_CG : 0U) |
(TMAP_CT_SUPPORTED ? BT_TMAP_ROLE_CT : 0U) |
(TMAP_UMS_SUPPORTED ? BT_TMAP_ROLE_UMS : 0U) |
(TMAP_UMR_SUPPORTED ? BT_TMAP_ROLE_UMR : 0U) |
(TMAP_BMS_SUPPORTED ? BT_TMAP_ROLE_BMS : 0U) |
(TMAP_BMR_SUPPORTED ? BT_TMAP_ROLE_BMR : 0U);
int err;

shell_info(sh, "Registering TMAS with role: %u", role);

err = bt_tmap_register(role);
if (err != 0) {
shell_error(sh, "bt_tmap_register (err %d)", err);

return -ENOEXEC;
}

return 0;
}

static void tmap_discover_cb(enum bt_tmap_role role, struct bt_conn *conn, int err)
{
if (err != 0) {
shell_error(ctx_shell, "tmap discovery (err %d)", err);
return;
}

shell_print(ctx_shell, "tmap discovered for conn %p: role 0x%02x", conn, role);
}

static const struct bt_tmap_cb tmap_cb = {
.discovery_complete = tmap_discover_cb,
};

static int cmd_tmap_discover(const struct shell *sh, size_t argc, char **argv)
{
int err;

if (default_conn == NULL) {
shell_error(sh, "Not connected");

return -ENOEXEC;
}

if (!ctx_shell) {
ctx_shell = sh;
}

err = bt_tmap_discover(default_conn, &tmap_cb);
if (err != 0) {
shell_error(sh, "bt_tmap_discover (err %d)", err);

return -ENOEXEC;
}

return err;
}

static int cmd_tmap(const struct shell *sh, size_t argc, char **argv)
{
if (argc > 1) {
shell_error(sh, "%s unknown parameter: %s", argv[0], argv[1]);
} else {
shell_error(sh, "%s missing subcomand", argv[0]);
}

return -ENOEXEC;
}

SHELL_STATIC_SUBCMD_SET_CREATE(tmap_cmds,
SHELL_CMD_ARG(init, NULL, "Initialize and register the TMAS", cmd_tmap_init, 1, 0),
SHELL_CMD_ARG(discover, NULL, "Discover TMAS on remote device", cmd_tmap_discover, 1, 0),
SHELL_SUBCMD_SET_END
);

SHELL_CMD_ARG_REGISTER(tmap, &tmap_cmds, "Bluetooth tmap client shell commands", cmd_tmap, 1, 1);
6 changes: 6 additions & 0 deletions tests/bluetooth/shell/audio.conf
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ CONFIG_BT_CAP_ACCEPTOR=y
CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER=y
CONFIG_BT_CAP_INITIATOR=y

# Telephone and Media Audio Profile
CONFIG_BT_TMAP=y

# DEBUGGING
CONFIG_LOG=y
CONFIG_BT_AUDIO_LOG_LEVEL_DBG=y
Expand Down Expand Up @@ -186,3 +189,6 @@ CONFIG_BT_BAP_ISO_LOG_LEVEL_DBG=y
CONFIG_BT_AUDIO_CODEC_LOG_LEVEL_DBG=y
CONFIG_BT_CSIP_SET_COORDINATOR_LOG_LEVEL_DBG=y
CONFIG_BT_CSIP_SET_MEMBER_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_ACCEPTOR_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_INITIATOR_LOG_LEVEL_DBG=y
CONFIG_BT_TMAP_LOG_LEVEL_DBG=y

0 comments on commit 49a70aa

Please sign in to comment.