The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 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 Watson | f355ef5 | 2016-11-09 13:04:33 -0800 | [diff] [blame] | 26 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 27 | #include "bta_ar_api.h" |
| 28 | #include "bta_ar_int.h" |
| 29 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | /* AV control block */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 31 | tBTA_AR_CB bta_ar_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 32 | |
| 33 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 34 | * |
| 35 | * Function bta_ar_id |
| 36 | * |
| 37 | * Description This function maps sys_id to ar id mask. |
| 38 | * |
| 39 | * Returns void |
| 40 | * |
| 41 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 42 | static 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 49 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 50 | return mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 54 | * |
| 55 | * Function bta_ar_init |
| 56 | * |
| 57 | * Description This function is called to register to AVDTP. |
| 58 | * |
| 59 | * Returns void |
| 60 | * |
| 61 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 62 | void bta_ar_init(void) { |
| 63 | /* initialize control block */ |
| 64 | memset(&bta_ar_cb, 0, sizeof(tBTA_AR_CB)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 68 | * |
| 69 | * Function bta_ar_reg_avdt |
| 70 | * |
| 71 | * Description This function is called to register to AVDTP. |
| 72 | * |
| 73 | * Returns void |
| 74 | * |
| 75 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 76 | static 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 86 | * |
| 87 | * Function bta_ar_reg_avdt |
| 88 | * |
| 89 | * Description AR module registration to AVDT. |
| 90 | * |
| 91 | * Returns void |
| 92 | * |
| 93 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 94 | void 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 97 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 98 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | #if (BTA_AR_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 106 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 110 | #endif |
| 111 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 112 | if (mask) { |
| 113 | if (bta_ar_cb.avdt_registered == 0) { |
| 114 | AVDT_Register(p_reg, bta_ar_avdt_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 115 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 116 | bta_ar_cb.avdt_registered |= mask; |
| 117 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 121 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 129 | void bta_ar_dereg_avdt(tBTA_SYS_ID sys_id) { |
| 130 | uint8_t mask = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 132 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 140 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 141 | if (bta_ar_cb.avdt_registered == 0) AVDT_Deregister(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 145 | * |
| 146 | * Function bta_ar_avdt_conn |
| 147 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 148 | * Description This function is called to let ar know that some AVDTP |
| 149 | *profile |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 150 | * 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 157 | void 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 160 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 161 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 164 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 165 | } 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 168 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 169 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 173 | * |
| 174 | * Function bta_ar_reg_avct |
| 175 | * |
| 176 | * Description This function is called to register to AVCTP. |
| 177 | * |
| 178 | * Returns void |
| 179 | * |
| 180 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 181 | void 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 184 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 185 | if (mask) { |
| 186 | if (bta_ar_cb.avct_registered == 0) { |
| 187 | AVCT_Register(mtu, mtu_br, sec_mask); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 188 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 189 | bta_ar_cb.avct_registered |= mask; |
| 190 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 194 | * |
| 195 | * Function bta_ar_dereg_avct |
| 196 | * |
| 197 | * Description This function is called to deregister from AVCTP. |
| 198 | * |
| 199 | * Returns void |
| 200 | * |
| 201 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 202 | void bta_ar_dereg_avct(tBTA_SYS_ID sys_id) { |
| 203 | uint8_t mask = bta_ar_id(sys_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 204 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 205 | bta_ar_cb.avct_registered &= ~mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 206 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 207 | if (bta_ar_cb.avct_registered == 0) AVCT_Deregister(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /****************************************************************************** |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 211 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 219 | void bta_ar_reg_avrc(uint16_t service_uuid, const char* service_name, |
| 220 | const char* provider_name, uint16_t categories, |
Pavlin Radoslavov | cc26bfc | 2016-10-14 12:17:08 -0700 | [diff] [blame] | 221 | tBTA_SYS_ID sys_id, bool browse_supported, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 222 | uint16_t profile_version) { |
| 223 | uint8_t mask = bta_ar_id(sys_id); |
| 224 | uint8_t temp[8], *p; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 225 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 226 | if (!mask || !categories) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 227 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 228 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 236 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 237 | /* 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 256 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 257 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /****************************************************************************** |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 261 | * |
| 262 | * Function bta_ar_dereg_avrc |
| 263 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 264 | * Description This function is called to de-register/delete an SDP record |
| 265 | *for AVRCP. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 266 | * |
| 267 | * Returns void |
| 268 | * |
| 269 | *****************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 270 | void 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 274 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 275 | if (!mask) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 276 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 277 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 283 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 284 | } 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 300 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame^] | 301 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 302 | } |