1 /**
2  * @file
3  * @brief Header for Bluetooth TMAP.
4  *
5  * Copyright 2023 NXP
6  * Copyright (c) 2024 Nordic Semiconductor ASA
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 
11 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_TMAP_
12 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_TMAP_
13 
14 /**
15  * @brief Telephone and Media Audio Profile (TMAP)
16  *
17  * @defgroup bt_tmap Telephone and Media Audio Profile (TMAP)
18  *
19  * @since 3.4
20  * @version 0.8.0
21  *
22  * @ingroup bluetooth
23  * @{
24  *
25  * The Telephone and Media Audio Profile (TMAP) uses a collection of Bluetooth features and profiles
26  * to enable interoperability between devices for telephony and media audio.
27  */
28 
29 #include <zephyr/autoconf.h>
30 #include <zephyr/bluetooth/conn.h>
31 #include <zephyr/sys/util.h>
32 #include <zephyr/sys/util_macro.h>
33 
34 /** Call Gateway (CG) supported */
35 #define BT_TMAP_CG_SUPPORTED                                                                       \
36 	(IS_ENABLED(CONFIG_BT_CAP_INITIATOR) && IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) &&        \
37 	 IS_ENABLED(CONFIG_BT_TBS) && IS_ENABLED(CONFIG_BT_VCP_VOL_CTLR))
38 
39 /** Call Terminal (CT) supported */
40 #define BT_TMAP_CT_SUPPORTED                                                                       \
41 	(IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR) && IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) &&         \
42 	 IS_ENABLED(CONFIG_BT_TBS_CLIENT) &&                                                       \
43 	 (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK) &&                                                    \
44 	  IS_ENABLED(CONFIG_BT_VCP_VOL_REND) == IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)))
45 
46 /** Unicast Media Sender (UMS) supported */
47 #define BT_TMAP_UMS_SUPPORTED                                                                      \
48 	(IS_ENABLED(CONFIG_BT_CAP_INITIATOR) &&                                                    \
49 	 IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK) && IS_ENABLED(CONFIG_BT_VCP_VOL_CTLR) && \
50 	 IS_ENABLED(CONFIG_BT_MCS))
51 
52 /** Unicast Media Receiver (UMR) supported */
53 #define BT_TMAP_UMR_SUPPORTED                                                                      \
54 	(IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR) && IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK) &&               \
55 	 IS_ENABLED(CONFIG_BT_VCP_VOL_REND))
56 
57 /** Broadcast Media Sender (BMS) supported */
58 #define BT_TMAP_BMS_SUPPORTED                                                                      \
59 	(IS_ENABLED(CONFIG_BT_CAP_INITIATOR) && IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE))
60 
61 /** Broadcast Media Receiver (BMR) supported */
62 #define BT_TMAP_BMR_SUPPORTED                                                                      \
63 	(IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR) && IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK))
64 
65 /** @brief TMAP Role characteristic */
66 enum bt_tmap_role {
67 	/**
68 	 * @brief TMAP Call Gateway role
69 	 *
70 	 * This role is defined to telephone and VoIP applications using the Call Control Profile
71 	 * to control calls on a remote TMAP Call Terminal.
72 	 * Audio streams in this role are typically bi-directional.
73 	 */
74 	BT_TMAP_ROLE_CG = BIT(0),
75 	/**
76 	 * @brief TMAP Call Terminal role
77 	 *
78 	 * This role is defined to telephone and VoIP applications using the Call Control Profile
79 	 * to expose calls to remote TMAP Call Gateways.
80 	 * Audio streams in this role are typically bi-directional.
81 	 */
82 	BT_TMAP_ROLE_CT = BIT(1),
83 	/**
84 	 * @brief TMAP Unicast Media Sender role
85 	 *
86 	 * This role is defined send media audio to TMAP Unicast Media Receivers.
87 	 * Audio streams in this role are typically uni-directional.
88 	 */
89 	BT_TMAP_ROLE_UMS = BIT(2),
90 	/**
91 	 * @brief TMAP Unicast Media Receiver role
92 	 *
93 	 * This role is defined receive media audio to TMAP Unicast Media Senders.
94 	 * Audio streams in this role are typically uni-directional.
95 	 */
96 	BT_TMAP_ROLE_UMR = BIT(3),
97 	/**
98 	 * @brief TMAP Broadcast Media Sender role
99 	 *
100 	 * This role is defined send media audio to TMAP Broadcast Media Receivers.
101 	 * Audio streams in this role are always uni-directional.
102 	 */
103 	BT_TMAP_ROLE_BMS = BIT(4),
104 	/**
105 	 * @brief TMAP Broadcast Media Receiver role
106 	 *
107 	 * This role is defined send media audio to TMAP Broadcast Media Senders.
108 	 * Audio streams in this role are always uni-directional.
109 	 */
110 	BT_TMAP_ROLE_BMR = BIT(5),
111 };
112 
113 /** @brief TMAP callback structure. */
114 struct bt_tmap_cb {
115 	/**
116 	 * @brief TMAP discovery complete callback
117 	 *
118 	 * This callback notifies the application about the value of the
119 	 * TMAP Role characteristic on the peer.
120 	 *
121 	 * @param role	   Peer TMAP role(s).
122 	 * @param conn     Pointer to the connection
123 	 * @param err      0 if success, ATT error received from server otherwise.
124 	 */
125 	void (*discovery_complete)(enum bt_tmap_role role, struct bt_conn *conn, int err);
126 };
127 
128 /**
129  * @brief Adds TMAS instance to database and sets the received TMAP role(s).
130  *
131  * @param role TMAP role(s) of the device (one or multiple).
132  *
133  * @return 0 on success or negative error value on failure.
134  */
135 int bt_tmap_register(enum bt_tmap_role role);
136 
137 /**
138  * @brief Perform service discovery as TMAP Client
139  *
140  * @param conn     Pointer to the connection.
141  * @param tmap_cb  Pointer to struct of TMAP callbacks.
142  *
143  * @return 0 on success or negative error value on failure.
144  */
145 int bt_tmap_discover(struct bt_conn *conn, const struct bt_tmap_cb *tmap_cb);
146 
147 /**
148  * @brief Set one or multiple TMAP roles dynamically.
149  *        Previously registered value will be overwritten.
150  *
151  * @param role     TMAP role(s).
152  *
153  */
154 void bt_tmap_set_role(enum bt_tmap_role role);
155 
156 /**
157  * @}
158  */
159 
160 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_TMAP_ */
161