blob: c3ef92afa74da2e629f4ae128eeaf84d66152387 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2008-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19/******************************************************************************
20 *
21 * This is the implementation for the audio/video registration module.
22 *
23 ******************************************************************************/
24
25#include <string.h>
Myles Watsonf355ef52016-11-09 13:04:33 -080026
The Android Open Source Project5738f832012-12-12 16:00:35 -080027#include "bta_ar_api.h"
28#include "bta_ar_int.h"
29
The Android Open Source Project5738f832012-12-12 16:00:35 -080030/* AV control block */
Myles Watsoncd1fd072016-11-09 13:17:43 -080031tBTA_AR_CB bta_ar_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -080032
33/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080034 *
35 * Function bta_ar_id
36 *
37 * Description This function maps sys_id to ar id mask.
38 *
39 * Returns void
40 *
41 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080042static uint8_t bta_ar_id(tBTA_SYS_ID sys_id) {
43 uint8_t mask = 0;
44 if (sys_id == BTA_ID_AV) {
45 mask = BTA_AR_AV_MASK;
46 } else if (sys_id == BTA_ID_AVK) {
47 mask = BTA_AR_AVK_MASK;
48 }
The Android Open Source Project5738f832012-12-12 16:00:35 -080049
Myles Watsoncd1fd072016-11-09 13:17:43 -080050 return mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -080051}
52
53/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080054 *
55 * Function bta_ar_init
56 *
57 * Description This function is called to register to AVDTP.
58 *
59 * Returns void
60 *
61 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080062void bta_ar_init(void) {
63 /* initialize control block */
64 memset(&bta_ar_cb, 0, sizeof(tBTA_AR_CB));
The Android Open Source Project5738f832012-12-12 16:00:35 -080065}
66
67/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080068 *
69 * Function bta_ar_reg_avdt
70 *
71 * Description This function is called to register to AVDTP.
72 *
73 * Returns void
74 *
75 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080076static void bta_ar_avdt_cback(uint8_t handle, BD_ADDR bd_addr, uint8_t event,
77 tAVDT_CTRL* p_data) {
78 /* route the AVDT registration callback to av or avk */
79 if (bta_ar_cb.p_av_conn_cback)
80 (*bta_ar_cb.p_av_conn_cback)(handle, bd_addr, event, p_data);
81 if (bta_ar_cb.p_avk_conn_cback)
82 (*bta_ar_cb.p_avk_conn_cback)(handle, bd_addr, event, p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -080083}
84
85/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080086 *
87 * Function bta_ar_reg_avdt
88 *
89 * Description AR module registration to AVDT.
90 *
91 * Returns void
92 *
93 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080094void bta_ar_reg_avdt(tAVDT_REG* p_reg, tAVDT_CTRL_CBACK* p_cback,
95 tBTA_SYS_ID sys_id) {
96 uint8_t mask = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -080097
Myles Watsoncd1fd072016-11-09 13:17:43 -080098 if (sys_id == BTA_ID_AV) {
99 bta_ar_cb.p_av_conn_cback = p_cback;
100 mask = BTA_AR_AV_MASK;
101 } else if (sys_id == BTA_ID_AVK) {
102 bta_ar_cb.p_avk_conn_cback = p_cback;
103 mask = BTA_AR_AVK_MASK;
104 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800105#if (BTA_AR_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800106 else {
107 APPL_TRACE_ERROR(
108 "bta_ar_reg_avdt: the registration is from wrong sys_id:%d", sys_id);
109 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800110#endif
111
Myles Watsoncd1fd072016-11-09 13:17:43 -0800112 if (mask) {
113 if (bta_ar_cb.avdt_registered == 0) {
114 AVDT_Register(p_reg, bta_ar_avdt_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800115 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800116 bta_ar_cb.avdt_registered |= mask;
117 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800118}
119
120/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800121 *
122 * Function bta_ar_dereg_avdt
123 *
124 * Description This function is called to de-register from AVDTP.
125 *
126 * Returns void
127 *
128 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800129void bta_ar_dereg_avdt(tBTA_SYS_ID sys_id) {
130 uint8_t mask = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131
Myles Watsoncd1fd072016-11-09 13:17:43 -0800132 if (sys_id == BTA_ID_AV) {
133 bta_ar_cb.p_av_conn_cback = NULL;
134 mask = BTA_AR_AV_MASK;
135 } else if (sys_id == BTA_ID_AVK) {
136 bta_ar_cb.p_avk_conn_cback = NULL;
137 mask = BTA_AR_AVK_MASK;
138 }
139 bta_ar_cb.avdt_registered &= ~mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800140
Myles Watsoncd1fd072016-11-09 13:17:43 -0800141 if (bta_ar_cb.avdt_registered == 0) AVDT_Deregister();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800142}
143
144/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800145 *
146 * Function bta_ar_avdt_conn
147 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800148 * Description This function is called to let ar know that some AVDTP
149 *profile
Myles Watson8af480e2016-11-09 10:40:23 -0800150 * is connected for this sys_id.
151 * If the other sys modules started a timer for PENDING_EVT,
152 * the timer can be stopped now.
153 *
154 * Returns void
155 *
156 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800157void bta_ar_avdt_conn(tBTA_SYS_ID sys_id, BD_ADDR bd_addr) {
158 uint8_t event = BTA_AR_AVDT_CONN_EVT;
159 tAVDT_CTRL data;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800160
Myles Watsoncd1fd072016-11-09 13:17:43 -0800161 if (sys_id == BTA_ID_AV) {
162 if (bta_ar_cb.p_avk_conn_cback) {
163 (*bta_ar_cb.p_avk_conn_cback)(0, bd_addr, event, &data);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800164 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800165 } else if (sys_id == BTA_ID_AVK) {
166 if (bta_ar_cb.p_av_conn_cback) {
167 (*bta_ar_cb.p_av_conn_cback)(0, bd_addr, event, &data);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800168 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800169 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800170}
171
172/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800173 *
174 * Function bta_ar_reg_avct
175 *
176 * Description This function is called to register to AVCTP.
177 *
178 * Returns void
179 *
180 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800181void bta_ar_reg_avct(uint16_t mtu, uint16_t mtu_br, uint8_t sec_mask,
182 tBTA_SYS_ID sys_id) {
183 uint8_t mask = bta_ar_id(sys_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800184
Myles Watsoncd1fd072016-11-09 13:17:43 -0800185 if (mask) {
186 if (bta_ar_cb.avct_registered == 0) {
187 AVCT_Register(mtu, mtu_br, sec_mask);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800188 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800189 bta_ar_cb.avct_registered |= mask;
190 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800191}
192
193/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800194 *
195 * Function bta_ar_dereg_avct
196 *
197 * Description This function is called to deregister from AVCTP.
198 *
199 * Returns void
200 *
201 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800202void bta_ar_dereg_avct(tBTA_SYS_ID sys_id) {
203 uint8_t mask = bta_ar_id(sys_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204
Myles Watsoncd1fd072016-11-09 13:17:43 -0800205 bta_ar_cb.avct_registered &= ~mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800206
Myles Watsoncd1fd072016-11-09 13:17:43 -0800207 if (bta_ar_cb.avct_registered == 0) AVCT_Deregister();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800208}
209
210/******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800211 *
212 * Function bta_ar_reg_avrc
213 *
214 * Description This function is called to register an SDP record for AVRCP.
215 *
216 * Returns void
217 *
218 *****************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800219void bta_ar_reg_avrc(uint16_t service_uuid, const char* service_name,
220 const char* provider_name, uint16_t categories,
Pavlin Radoslavovcc26bfc2016-10-14 12:17:08 -0700221 tBTA_SYS_ID sys_id, bool browse_supported,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800222 uint16_t profile_version) {
223 uint8_t mask = bta_ar_id(sys_id);
224 uint8_t temp[8], *p;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800225
Myles Watsoncd1fd072016-11-09 13:17:43 -0800226 if (!mask || !categories) return;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800227
Myles Watsoncd1fd072016-11-09 13:17:43 -0800228 if (service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET) {
229 if (bta_ar_cb.sdp_tg_handle == 0) {
230 bta_ar_cb.tg_registered = mask;
231 bta_ar_cb.sdp_tg_handle = SDP_CreateRecord();
232 AVRC_AddRecord(service_uuid, service_name, provider_name, categories,
233 bta_ar_cb.sdp_tg_handle, browse_supported,
234 profile_version);
235 bta_sys_add_uuid(service_uuid);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800236 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800237 /* only one TG is allowed (first-come, first-served).
238 * If sdp_tg_handle is non-0, ignore this request */
239 } else if ((service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL) ||
240 (service_uuid == UUID_SERVCLASS_AV_REM_CTRL_CONTROL)) {
241 bta_ar_cb.ct_categories[mask - 1] = categories;
242 categories = bta_ar_cb.ct_categories[0] | bta_ar_cb.ct_categories[1];
243 if (bta_ar_cb.sdp_ct_handle == 0) {
244 bta_ar_cb.sdp_ct_handle = SDP_CreateRecord();
245 AVRC_AddRecord(service_uuid, service_name, provider_name, categories,
246 bta_ar_cb.sdp_ct_handle, browse_supported,
247 profile_version);
248 bta_sys_add_uuid(service_uuid);
249 } else {
250 /* multiple CTs are allowed.
251 * Change supported categories on the second one */
252 p = temp;
253 UINT16_TO_BE_STREAM(p, categories);
254 SDP_AddAttribute(bta_ar_cb.sdp_ct_handle, ATTR_ID_SUPPORTED_FEATURES,
255 UINT_DESC_TYPE, (uint32_t)2, (uint8_t*)temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800256 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800257 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800258}
259
260/******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800261 *
262 * Function bta_ar_dereg_avrc
263 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800264 * Description This function is called to de-register/delete an SDP record
265 *for AVRCP.
Myles Watson8af480e2016-11-09 10:40:23 -0800266 *
267 * Returns void
268 *
269 *****************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800270void bta_ar_dereg_avrc(uint16_t service_uuid, tBTA_SYS_ID sys_id) {
271 uint8_t mask = bta_ar_id(sys_id);
272 uint16_t categories = 0;
273 uint8_t temp[8], *p;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800274
Myles Watsoncd1fd072016-11-09 13:17:43 -0800275 if (!mask) return;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800276
Myles Watsoncd1fd072016-11-09 13:17:43 -0800277 if (service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET) {
278 if (bta_ar_cb.sdp_tg_handle && mask == bta_ar_cb.tg_registered) {
279 bta_ar_cb.tg_registered = 0;
280 SDP_DeleteRecord(bta_ar_cb.sdp_tg_handle);
281 bta_ar_cb.sdp_tg_handle = 0;
282 bta_sys_remove_uuid(service_uuid);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800283 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800284 } else if (service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL) {
285 if (bta_ar_cb.sdp_ct_handle) {
286 bta_ar_cb.ct_categories[mask - 1] = 0;
287 categories = bta_ar_cb.ct_categories[0] | bta_ar_cb.ct_categories[1];
288 if (!categories) {
289 /* no CT is still registered - cleaup */
290 SDP_DeleteRecord(bta_ar_cb.sdp_ct_handle);
291 bta_ar_cb.sdp_ct_handle = 0;
292 bta_sys_remove_uuid(service_uuid);
293 } else {
294 /* change supported categories to the remaning one */
295 p = temp;
296 UINT16_TO_BE_STREAM(p, categories);
297 SDP_AddAttribute(bta_ar_cb.sdp_ct_handle, ATTR_ID_SUPPORTED_FEATURES,
298 UINT_DESC_TYPE, (uint32_t)2, (uint8_t*)temp);
299 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800300 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800301 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800302}