1 /** @file
2 * @brief Bluetooth Telephone and Media Audio Profile shell
3 *
4 */
5
6 /*
7 * Copyright (c) 2023 Nordic Semiconductor ASA
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11
12 #include <errno.h>
13 #include <stddef.h>
14 #include <stdint.h>
15
16 #include <zephyr/bluetooth/audio/tmap.h>
17 #include <zephyr/bluetooth/conn.h>
18 #include <zephyr/kernel.h>
19 #include <zephyr/shell/shell.h>
20 #include <zephyr/sys/util.h>
21
22 #include "host/shell/bt.h"
23
cmd_tmap_init(const struct shell * sh,size_t argc,char ** argv)24 static int cmd_tmap_init(const struct shell *sh, size_t argc, char **argv)
25 {
26 const enum bt_tmap_role role = (BT_TMAP_CG_SUPPORTED ? BT_TMAP_ROLE_CG : 0U) |
27 (BT_TMAP_CT_SUPPORTED ? BT_TMAP_ROLE_CT : 0U) |
28 (BT_TMAP_UMS_SUPPORTED ? BT_TMAP_ROLE_UMS : 0U) |
29 (BT_TMAP_UMR_SUPPORTED ? BT_TMAP_ROLE_UMR : 0U) |
30 (BT_TMAP_BMS_SUPPORTED ? BT_TMAP_ROLE_BMS : 0U) |
31 (BT_TMAP_BMR_SUPPORTED ? BT_TMAP_ROLE_BMR : 0U);
32 int err;
33
34 shell_info(sh, "Registering TMAS with role: 0x%04X", role);
35
36 err = bt_tmap_register(role);
37 if (err != 0) {
38 shell_error(sh, "bt_tmap_register (err %d)", err);
39
40 return -ENOEXEC;
41 }
42
43 return 0;
44 }
45
tmap_discover_cb(enum bt_tmap_role role,struct bt_conn * conn,int err)46 static void tmap_discover_cb(enum bt_tmap_role role, struct bt_conn *conn, int err)
47 {
48 if (err != 0) {
49 shell_error(ctx_shell, "tmap discovery (err %d)", err);
50 return;
51 }
52
53 shell_print(ctx_shell, "tmap discovered for conn %p: role 0x%04x", conn, role);
54 }
55
56 static const struct bt_tmap_cb tmap_cb = {
57 .discovery_complete = tmap_discover_cb,
58 };
59
cmd_tmap_discover(const struct shell * sh,size_t argc,char ** argv)60 static int cmd_tmap_discover(const struct shell *sh, size_t argc, char **argv)
61 {
62 int err;
63
64 if (default_conn == NULL) {
65 shell_error(sh, "Not connected");
66
67 return -ENOEXEC;
68 }
69
70 if (!ctx_shell) {
71 ctx_shell = sh;
72 }
73
74 err = bt_tmap_discover(default_conn, &tmap_cb);
75 if (err != 0) {
76 shell_error(sh, "bt_tmap_discover (err %d)", err);
77
78 return -ENOEXEC;
79 }
80
81 return err;
82 }
83
cmd_tmap(const struct shell * sh,size_t argc,char ** argv)84 static int cmd_tmap(const struct shell *sh, size_t argc, char **argv)
85 {
86 if (argc > 1) {
87 shell_error(sh, "%s unknown parameter: %s", argv[0], argv[1]);
88 } else {
89 shell_error(sh, "%s missing subcomand", argv[0]);
90 }
91
92 return -ENOEXEC;
93 }
94
95 SHELL_STATIC_SUBCMD_SET_CREATE(tmap_cmds,
96 SHELL_CMD_ARG(init, NULL, "Initialize and register the TMAS", cmd_tmap_init, 1, 0),
97 SHELL_CMD_ARG(discover, NULL, "Discover TMAS on remote device", cmd_tmap_discover, 1, 0),
98 SHELL_SUBCMD_SET_END
99 );
100
101 SHELL_CMD_ARG_REGISTER(tmap, &tmap_cmds, "Bluetooth tmap client shell commands", cmd_tmap, 1, 1);
102