1 /** @file
2  *  @brief Internal APIs for Bluetooth MCP.
3  */
4 
5 /*
6  * Copyright (c) 2019 - 2021 Nordic Semiconductor ASA
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 
11 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCP_INTERNAL_
12 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCP_INTERNAL_
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 
17 #include <zephyr/autoconf.h>
18 #include <zephyr/bluetooth/audio/mcs.h>
19 #include <zephyr/bluetooth/conn.h>
20 #include <zephyr/bluetooth/gatt.h>
21 #include <zephyr/bluetooth/services/ots.h>
22 #include <zephyr/types.h>
23 
24 struct mcs_instance_t *lookup_inst_by_conn(struct bt_conn *conn);
25 
26 struct mcs_instance_t {
27 	struct bt_conn *conn;
28 	uint16_t start_handle;
29 	uint16_t end_handle;
30 	uint16_t player_name_handle;
31 #ifdef CONFIG_BT_MCC_OTS
32 	uint16_t icon_obj_id_handle;
33 #endif /* CONFIG_BT_MCC_OTS */
34 #if defined(CONFIG_BT_MCC_READ_MEDIA_PLAYER_ICON_URL)
35 	uint16_t icon_url_handle;
36 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_PLAYER_ICON_URL) */
37 	uint16_t track_changed_handle;
38 #if defined(CONFIG_BT_MCC_READ_TRACK_TITLE)
39 	uint16_t track_title_handle;
40 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_TITLE) */
41 #if defined(CONFIG_BT_MCC_READ_TRACK_DURATION)
42 	uint16_t track_duration_handle;
43 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_DURATION) */
44 #if defined(CONFIG_BT_MCC_READ_TRACK_POSITION) || defined(CONFIG_BT_MCC_SET_TRACK_POSITION)
45 	uint16_t track_position_handle;
46 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_POSITION) || defined(CONFIG_BT_MCC_SET_TRACK_POSITION) */
47 #if defined(CONFIG_BT_MCC_READ_PLAYBACK_SPEED) || defined(CONFIG_BT_MCC_SET_PLAYBACK_SPEED)
48 	uint16_t playback_speed_handle;
49 #endif /* defined (CONFIG_BT_MCC_READ_PLAYBACK_SPEED) || */
50        /* defined (CONFIG_BT_MCC_SET_PLAYBACK_SPEED) */
51 #if defined(CONFIG_BT_MCC_READ_SEEKING_SPEED)
52 	uint16_t seeking_speed_handle;
53 #endif /* defined (CONFIG_BT_MCC_READ_SEEKING_SPEED) */
54 #ifdef CONFIG_BT_MCC_OTS
55 	uint16_t segments_obj_id_handle;
56 	uint16_t current_track_obj_id_handle;
57 	uint16_t next_track_obj_id_handle;
58 	uint16_t current_group_obj_id_handle;
59 	uint16_t parent_group_obj_id_handle;
60 #endif /* CONFIG_BT_MCC_OTS */
61 #if defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) || defined(CONFIG_BT_MCC_SET_PLAYING_ORDER)
62 	uint16_t playing_order_handle;
63 #endif /* defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) || defined(CONFIG_BT_MCC_SET_PLAYING_ORDER) */
64 #if defined(CONFIG_BT_MCC_READ_PLAYING_ORDER_SUPPORTED)
65 	uint16_t playing_orders_supported_handle;
66 #endif /* defined(CONFIG_BT_MCC_READ_PLAYING_ORDER_SUPPORTED) */
67 #if defined(CONFIG_BT_MCC_READ_MEDIA_STATE)
68 	uint16_t media_state_handle;
69 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_STATE) */
70 	uint16_t cp_handle;
71 #if defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED)
72 	uint16_t opcodes_supported_handle;
73 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED) */
74 #ifdef CONFIG_BT_MCC_OTS
75 	uint16_t scp_handle;
76 	uint16_t search_results_obj_id_handle;
77 #endif /* CONFIG_BT_MCC_OTS */
78 #if defined(CONFIG_BT_MCC_READ_CONTENT_CONTROL_ID)
79 	uint16_t content_control_id_handle;
80 #endif /* defined(CONFIG_BT_MCC_READ_CONTENT_CONTROL_ID) */
81 
82 
83 	/* The write buffer is used for
84 	 * - track position    (4 octets)
85 	 * - playback speed    (1 octet)
86 	 * - playing order     (1 octet)
87 	 * - the control point (5 octets)
88 	 *                     (1 octet opcode + optionally 4 octet param)
89 	 *                     (mpl_cmd.opcode + mpl_cmd.param)
90 	 * If the object transfer client is included, it is also used for
91 	 * - object IDs (6 octets - BT_OTS_OBJ_ID_SIZE) and
92 	 * - the search control point (64 octets - SEARCH_LEN_MAX)
93 	 *
94 	 * If there is no OTC, the largest is control point
95 	 * If OTC is included, the largest is the search control point
96 	 */
97 #ifdef CONFIG_BT_MCC_OTS
98 	char write_buf[SEARCH_LEN_MAX];
99 #else
100 	/* Trick to be able to use sizeof on members of a struct type */
101 	/* TODO: Rewrite the mpl_cmd to have the "use_param" parameter */
102 	/* separately, and the opcode and param alone as a struct */
103 	char write_buf[sizeof(((struct mpl_cmd *)0)->opcode) +
104 		       sizeof(((struct mpl_cmd *)0)->param)];
105 #endif /* CONFIG_BT_MCC_OTS */
106 
107 	struct bt_gatt_discover_params  discover_params;
108 	struct bt_gatt_read_params      read_params;
109 	struct bt_gatt_write_params     write_params;
110 
111 /** Any fields below here cannot be memset as part of a reset */
112 	bool busy;
113 
114 	struct bt_gatt_subscribe_params player_name_sub_params;
115 	struct bt_gatt_subscribe_params track_changed_sub_params;
116 #if defined(CONFIG_BT_MCC_READ_TRACK_TITLE_ENABLE_SUBSCRIPTION)
117 	struct bt_gatt_subscribe_params track_title_sub_params;
118 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_TITLE_ENABLE_SUBSCRIPTION) */
119 #if defined(CONFIG_BT_MCC_READ_TRACK_DURATION)
120 	struct bt_gatt_subscribe_params track_duration_sub_params;
121 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_DURATION) */
122 #if defined(CONFIG_BT_MCC_READ_TRACK_POSITION)
123 	struct bt_gatt_subscribe_params track_position_sub_params;
124 #endif /* defined(CONFIG_BT_MCC_READ_TRACK_POSITION)*/
125 #if defined(CONFIG_BT_MCC_READ_PLAYBACK_SPEED)
126 	struct bt_gatt_subscribe_params playback_speed_sub_params;
127 #endif /* defined (CONFIG_BT_MCC_READ_PLAYBACK_SPEED) */
128 #if defined(CONFIG_BT_MCC_READ_SEEKING_SPEED)
129 	struct bt_gatt_subscribe_params seeking_speed_sub_params;
130 #endif /* defined (CONFIG_BT_MCC_READ_SEEKING_SPEED) */
131 #ifdef CONFIG_BT_MCC_OTS
132 	struct bt_gatt_subscribe_params current_track_obj_sub_params;
133 	struct bt_gatt_subscribe_params next_track_obj_sub_params;
134 	struct bt_gatt_subscribe_params parent_group_obj_sub_params;
135 	struct bt_gatt_subscribe_params current_group_obj_sub_params;
136 #endif /* CONFIG_BT_MCC_OTS */
137 #if defined(CONFIG_BT_MCC_READ_PLAYING_ORDER)
138 	struct bt_gatt_subscribe_params playing_order_sub_params;
139 #endif /* defined(CONFIG_BT_MCC_READ_PLAYING_ORDER) */
140 #if defined(CONFIG_BT_MCC_READ_MEDIA_STATE)
141 	struct bt_gatt_subscribe_params media_state_sub_params;
142 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_STATE) */
143 	struct bt_gatt_subscribe_params cp_sub_params;
144 #if defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED)
145 	struct bt_gatt_subscribe_params opcodes_supported_sub_params;
146 #endif /* defined(CONFIG_BT_MCC_READ_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED) */
147 #ifdef CONFIG_BT_MCC_OTS
148 	struct bt_gatt_subscribe_params scp_sub_params;
149 	struct bt_gatt_subscribe_params search_results_obj_sub_params;
150 #endif /* CONFIG_BT_MCC_OTS */
151 
152 #ifdef CONFIG_BT_MCC_OTS
153 	struct bt_ots_client otc;
154 #endif /* CONFIG_BT_MCC_OTS */
155 };
156 
157 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCP_INTERNAL_ */
158