The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2004-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 file contains action functions for advanced audio/video main state |
| 22 | * machine. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame^] | 26 | #define LOG_TAG "bt_bta_av" |
| 27 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | #include "bt_target.h" |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 29 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) |
| 31 | |
| 32 | #include <string.h> |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 33 | |
| 34 | #include "avdt_api.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 35 | #include "bta_av_api.h" |
| 36 | #include "bta_av_int.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | #include "l2c_api.h" |
Sharvil Nanavati | 0f9b91e | 2015-03-12 15:42:50 -0700 | [diff] [blame] | 38 | #include "osi/include/list.h" |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 39 | #include "osi/include/osi.h" |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 40 | #include "utl.h" |
| 41 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) |
| 43 | #include "bta_ar_api.h" |
| 44 | #endif |
| 45 | |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 46 | #include "osi/include/log.h" |
| 47 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 48 | /***************************************************************************** |
| 49 | ** Constants |
| 50 | *****************************************************************************/ |
| 51 | /* the timer in milliseconds to wait for open req after setconfig for incoming connections */ |
| 52 | #ifndef BTA_AV_SIG_TIME_VAL |
| 53 | #define BTA_AV_SIG_TIME_VAL 8000 |
| 54 | #endif |
| 55 | |
| 56 | /* In millisec to wait for signalling from SNK when it is initiated from SNK. */ |
| 57 | /* If not, we will start signalling from SRC. */ |
| 58 | #ifndef BTA_AV_ACP_SIG_TIME_VAL |
| 59 | #define BTA_AV_ACP_SIG_TIME_VAL 2000 |
| 60 | #endif |
| 61 | |
| 62 | static void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle); |
| 63 | |
| 64 | /******************************************************************************* |
| 65 | ** |
| 66 | ** Function bta_av_get_rcb_by_shdl |
| 67 | ** |
| 68 | ** Description find the RCB associated with the given SCB handle. |
| 69 | ** |
| 70 | ** Returns tBTA_AV_RCB |
| 71 | ** |
| 72 | *******************************************************************************/ |
| 73 | tBTA_AV_RCB * bta_av_get_rcb_by_shdl(UINT8 shdl) |
| 74 | { |
| 75 | tBTA_AV_RCB *p_rcb = NULL; |
| 76 | int i; |
| 77 | |
| 78 | for (i=0; i<BTA_AV_NUM_RCB; i++) |
| 79 | { |
| 80 | if (bta_av_cb.rcb[i].shdl == shdl && bta_av_cb.rcb[i].handle != BTA_AV_RC_HANDLE_NONE) |
| 81 | { |
| 82 | p_rcb = &bta_av_cb.rcb[i]; |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | return p_rcb; |
| 87 | } |
| 88 | #define BTA_AV_STS_NO_RSP 0xFF /* a number not used by tAVRC_STS */ |
| 89 | |
| 90 | /******************************************************************************* |
| 91 | ** |
| 92 | ** Function bta_av_del_rc |
| 93 | ** |
| 94 | ** Description delete the given AVRC handle. |
| 95 | ** |
| 96 | ** Returns void |
| 97 | ** |
| 98 | *******************************************************************************/ |
| 99 | void bta_av_del_rc(tBTA_AV_RCB *p_rcb) |
| 100 | { |
| 101 | tBTA_AV_SCB *p_scb; |
| 102 | UINT8 rc_handle; /* connected AVRCP handle */ |
| 103 | |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 104 | p_scb = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | if(p_rcb->handle != BTA_AV_RC_HANDLE_NONE) |
| 106 | { |
| 107 | if(p_rcb->shdl) |
| 108 | { |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 109 | /* Validate array index*/ |
| 110 | if ((p_rcb->shdl - 1) < BTA_AV_NUM_STRS) |
| 111 | { |
| 112 | p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1]; |
| 113 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 114 | if(p_scb) |
| 115 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 116 | APPL_TRACE_DEBUG("bta_av_del_rc shdl:%d, srch:%d rc_handle:%d", p_rcb->shdl, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 117 | p_scb->rc_handle, p_rcb->handle); |
| 118 | if(p_scb->rc_handle == p_rcb->handle) |
| 119 | p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE; |
| 120 | /* just in case the RC timer is active |
| 121 | if(bta_av_cb.features & BTA_AV_FEAT_RCCT && p_scb->chnl == BTA_AV_CHNL_AUDIO) */ |
| 122 | bta_sys_stop_timer(&p_scb->timer); |
| 123 | } |
| 124 | } |
| 125 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 126 | APPL_TRACE_EVENT("bta_av_del_rc handle: %d status=0x%x, rc_acp_handle:%d, idx:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 127 | p_rcb->handle, p_rcb->status, bta_av_cb.rc_acp_handle, bta_av_cb.rc_acp_idx); |
| 128 | rc_handle = p_rcb->handle; |
| 129 | if(!(p_rcb->status & BTA_AV_RC_CONN_MASK) || |
| 130 | ((p_rcb->status & BTA_AV_RC_ROLE_MASK) == BTA_AV_RC_ROLE_INT) ) |
| 131 | { |
| 132 | p_rcb->status = 0; |
| 133 | p_rcb->handle = BTA_AV_RC_HANDLE_NONE; |
| 134 | p_rcb->shdl = 0; |
| 135 | p_rcb->lidx = 0; |
| 136 | } |
| 137 | /* else ACP && connected. do not clear the handle yet */ |
| 138 | AVRC_Close(rc_handle); |
| 139 | if (rc_handle == bta_av_cb.rc_acp_handle) |
| 140 | bta_av_cb.rc_acp_handle = BTA_AV_RC_HANDLE_NONE; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 141 | APPL_TRACE_EVENT("end del_rc handle: %d status=0x%x, rc_acp_handle:%d, lidx:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 142 | p_rcb->handle, p_rcb->status, bta_av_cb.rc_acp_handle, p_rcb->lidx); |
| 143 | } |
| 144 | } |
| 145 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 146 | /******************************************************************************* |
| 147 | ** |
| 148 | ** Function bta_av_close_all_rc |
| 149 | ** |
| 150 | ** Description close the all AVRC handle. |
| 151 | ** |
| 152 | ** Returns void |
| 153 | ** |
| 154 | *******************************************************************************/ |
| 155 | static void bta_av_close_all_rc(tBTA_AV_CB *p_cb) |
| 156 | { |
| 157 | int i; |
| 158 | |
| 159 | for(i=0; i<BTA_AV_NUM_RCB; i++) |
| 160 | { |
| 161 | if ((p_cb->disabling == TRUE) || (bta_av_cb.rcb[i].shdl != 0)) |
| 162 | bta_av_del_rc(&bta_av_cb.rcb[i]); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /******************************************************************************* |
| 167 | ** |
| 168 | ** Function bta_av_del_sdp_rec |
| 169 | ** |
| 170 | ** Description delete the given SDP record handle. |
| 171 | ** |
| 172 | ** Returns void |
| 173 | ** |
| 174 | *******************************************************************************/ |
| 175 | static void bta_av_del_sdp_rec(UINT32 *p_sdp_handle) |
| 176 | { |
| 177 | if(*p_sdp_handle != 0) |
| 178 | { |
| 179 | SDP_DeleteRecord(*p_sdp_handle); |
| 180 | *p_sdp_handle = 0; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /******************************************************************************* |
| 185 | ** |
| 186 | ** Function bta_av_avrc_sdp_cback |
| 187 | ** |
| 188 | ** Description AVRCP service discovery callback. |
| 189 | ** |
| 190 | ** Returns void |
| 191 | ** |
| 192 | *******************************************************************************/ |
| 193 | static void bta_av_avrc_sdp_cback(UINT16 status) |
| 194 | { |
| 195 | BT_HDR *p_msg; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 196 | UNUSED(status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 197 | |
| 198 | if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) |
| 199 | { |
| 200 | p_msg->event = BTA_AV_SDP_AVRC_DISC_EVT; |
| 201 | bta_sys_sendmsg(p_msg); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /******************************************************************************* |
| 206 | ** |
| 207 | ** Function bta_av_rc_ctrl_cback |
| 208 | ** |
| 209 | ** Description AVRCP control callback. |
| 210 | ** |
| 211 | ** Returns void |
| 212 | ** |
| 213 | *******************************************************************************/ |
| 214 | static void bta_av_rc_ctrl_cback(UINT8 handle, UINT8 event, UINT16 result, BD_ADDR peer_addr) |
| 215 | { |
| 216 | tBTA_AV_RC_CONN_CHG *p_msg; |
| 217 | UINT16 msg_event = 0; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 218 | UNUSED(result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 219 | |
| 220 | #if (defined(BTA_AV_MIN_DEBUG_TRACES) && BTA_AV_MIN_DEBUG_TRACES == TRUE) |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 221 | APPL_TRACE_EVENT("rc_ctrl handle: %d event=0x%x", handle, event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | #else |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 223 | APPL_TRACE_EVENT("bta_av_rc_ctrl_cback handle: %d event=0x%x", handle, event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 224 | #endif |
| 225 | if (event == AVRC_OPEN_IND_EVT) |
| 226 | { |
| 227 | /* save handle of opened connection |
| 228 | bta_av_cb.rc_handle = handle;*/ |
| 229 | |
| 230 | msg_event = BTA_AV_AVRC_OPEN_EVT; |
| 231 | } |
| 232 | else if (event == AVRC_CLOSE_IND_EVT) |
| 233 | { |
| 234 | msg_event = BTA_AV_AVRC_CLOSE_EVT; |
| 235 | } |
| 236 | |
| 237 | if (msg_event) |
| 238 | { |
| 239 | if ((p_msg = (tBTA_AV_RC_CONN_CHG *) GKI_getbuf(sizeof(tBTA_AV_RC_CONN_CHG))) != NULL) |
| 240 | { |
| 241 | p_msg->hdr.event = msg_event; |
| 242 | p_msg->handle = handle; |
| 243 | if(peer_addr) |
| 244 | bdcpy(p_msg->peer_addr, peer_addr); |
| 245 | bta_sys_sendmsg(p_msg); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /******************************************************************************* |
| 251 | ** |
| 252 | ** Function bta_av_rc_msg_cback |
| 253 | ** |
| 254 | ** Description AVRCP message callback. |
| 255 | ** |
| 256 | ** Returns void |
| 257 | ** |
| 258 | *******************************************************************************/ |
| 259 | static void bta_av_rc_msg_cback(UINT8 handle, UINT8 label, UINT8 opcode, tAVRC_MSG *p_msg) |
| 260 | { |
Pavlin Radoslavov | e4bd496 | 2015-05-04 18:28:52 -0700 | [diff] [blame] | 261 | UINT8 *p_data_src = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 262 | UINT16 data_len = 0; |
| 263 | |
Pavlin Radoslavov | e4bd496 | 2015-05-04 18:28:52 -0700 | [diff] [blame] | 264 | APPL_TRACE_DEBUG("%s handle: %u opcode=0x%x", __func__, handle, opcode); |
| 265 | |
| 266 | /* Determine the size of the buffer we need */ |
| 267 | if (opcode == AVRC_OP_VENDOR && p_msg->vendor.p_vendor_data != NULL) { |
| 268 | p_data_src = p_msg->vendor.p_vendor_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 269 | data_len = (UINT16) p_msg->vendor.vendor_len; |
Pavlin Radoslavov | e4bd496 | 2015-05-04 18:28:52 -0700 | [diff] [blame] | 270 | } else if (opcode == AVRC_OP_PASS_THRU && p_msg->pass.p_pass_data != NULL) { |
| 271 | p_data_src = p_msg->pass.p_pass_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 272 | data_len = (UINT16) p_msg->pass.pass_len; |
| 273 | } |
| 274 | |
Pavlin Radoslavov | e4bd496 | 2015-05-04 18:28:52 -0700 | [diff] [blame] | 275 | /* Create a copy of the message */ |
| 276 | tBTA_AV_RC_MSG *p_buf = |
| 277 | (tBTA_AV_RC_MSG *)GKI_getbuf((UINT16)(sizeof(tBTA_AV_RC_MSG) + data_len)); |
| 278 | if (p_buf != NULL) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 279 | p_buf->hdr.event = BTA_AV_AVRC_MSG_EVT; |
| 280 | p_buf->handle = handle; |
| 281 | p_buf->label = label; |
| 282 | p_buf->opcode = opcode; |
| 283 | memcpy(&p_buf->msg, p_msg, sizeof(tAVRC_MSG)); |
Pavlin Radoslavov | e4bd496 | 2015-05-04 18:28:52 -0700 | [diff] [blame] | 284 | /* Copy the data payload, and set the pointer to it */ |
| 285 | if (p_data_src != NULL) { |
| 286 | UINT8 *p_data_dst = (UINT8 *)(p_buf + 1); |
| 287 | memcpy(p_data_dst, p_data_src, data_len); |
| 288 | if (opcode == AVRC_OP_VENDOR) |
| 289 | p_buf->msg.vendor.p_vendor_data = p_data_dst; |
| 290 | else if (opcode == AVRC_OP_PASS_THRU) |
| 291 | p_buf->msg.pass.p_pass_data = p_data_dst; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 292 | } |
| 293 | bta_sys_sendmsg(p_buf); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /******************************************************************************* |
| 298 | ** |
| 299 | ** Function bta_av_rc_create |
| 300 | ** |
| 301 | ** Description alloc RCB and call AVRC_Open |
| 302 | ** |
| 303 | ** Returns the created rc handle |
| 304 | ** |
| 305 | *******************************************************************************/ |
| 306 | UINT8 bta_av_rc_create(tBTA_AV_CB *p_cb, UINT8 role, UINT8 shdl, UINT8 lidx) |
| 307 | { |
| 308 | tAVRC_CONN_CB ccb; |
| 309 | BD_ADDR_PTR bda = (BD_ADDR_PTR)bd_addr_any; |
| 310 | UINT8 status = BTA_AV_RC_ROLE_ACP; |
| 311 | tBTA_AV_SCB *p_scb = p_cb->p_scb[shdl - 1]; |
| 312 | int i; |
| 313 | UINT8 rc_handle; |
| 314 | tBTA_AV_RCB *p_rcb; |
| 315 | |
| 316 | if(role == AVCT_INT) |
| 317 | { |
| 318 | bda = p_scb->peer_addr; |
| 319 | status = BTA_AV_RC_ROLE_INT; |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | if ((p_rcb = bta_av_get_rcb_by_shdl(shdl)) != NULL ) |
| 324 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 325 | APPL_TRACE_ERROR("bta_av_rc_create ACP handle exist for shdl:%d", shdl); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 326 | return p_rcb->handle; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | ccb.p_ctrl_cback = bta_av_rc_ctrl_cback; |
| 331 | ccb.p_msg_cback = bta_av_rc_msg_cback; |
| 332 | ccb.company_id = p_bta_av_cfg->company_id; |
| 333 | ccb.conn = role; |
| 334 | /* note: BTA_AV_FEAT_RCTG = AVRC_CT_TARGET, BTA_AV_FEAT_RCCT = AVRC_CT_CONTROL */ |
| 335 | ccb.control = p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_RCCT | AVRC_CT_PASSIVE); |
| 336 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 337 | if (AVRC_Open(&rc_handle, &ccb, bda) != AVRC_SUCCESS) |
| 338 | return BTA_AV_RC_HANDLE_NONE; |
| 339 | |
| 340 | i = rc_handle; |
| 341 | p_rcb = &p_cb->rcb[i]; |
| 342 | |
| 343 | if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) |
| 344 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 345 | APPL_TRACE_ERROR("bta_av_rc_create found duplicated handle:%d", rc_handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | p_rcb->handle = rc_handle; |
| 349 | p_rcb->status = status; |
| 350 | p_rcb->shdl = shdl; |
| 351 | p_rcb->lidx = lidx; |
| 352 | p_rcb->peer_features = 0; |
| 353 | if(lidx == (BTA_AV_NUM_LINKS + 1)) |
| 354 | { |
| 355 | /* this LIDX is reserved for the AVRCP ACP connection */ |
| 356 | p_cb->rc_acp_handle = p_rcb->handle; |
| 357 | p_cb->rc_acp_idx = (i + 1); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 358 | APPL_TRACE_DEBUG("rc_acp_handle:%d idx:%d", p_cb->rc_acp_handle, p_cb->rc_acp_idx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 359 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 360 | APPL_TRACE_DEBUG("create %d, role: %d, shdl:%d, rc_handle:%d, lidx:%d, status:0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | i, role, shdl, p_rcb->handle, lidx, p_rcb->status); |
| 362 | |
| 363 | return rc_handle; |
| 364 | } |
| 365 | |
| 366 | /******************************************************************************* |
| 367 | ** |
| 368 | ** Function bta_av_valid_group_navi_msg |
| 369 | ** |
| 370 | ** Description Check if it is Group Navigation Msg for Metadata |
| 371 | ** |
| 372 | ** Returns BTA_AV_RSP_ACCEPT or BTA_AV_RSP_NOT_IMPL. |
| 373 | ** |
| 374 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 375 | static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data, BOOLEAN is_inquiry) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 376 | { |
| 377 | tBTA_AV_CODE ret=BTA_AV_RSP_NOT_IMPL; |
| 378 | UINT8 *p_ptr = p_data; |
| 379 | UINT16 u16; |
| 380 | UINT32 u32; |
| 381 | |
| 382 | if (p_bta_av_cfg->avrc_group && len == BTA_GROUP_NAVI_MSG_OP_DATA_LEN) |
| 383 | { |
| 384 | BTA_AV_BE_STREAM_TO_CO_ID(u32, p_ptr); |
| 385 | BE_STREAM_TO_UINT16(u16, p_ptr); |
| 386 | |
| 387 | if (u32 == AVRC_CO_METADATA) |
| 388 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 389 | if (is_inquiry) |
| 390 | { |
| 391 | if (u16 <= AVRC_PDU_PREV_GROUP) |
| 392 | ret = BTA_AV_RSP_IMPL_STBL; |
| 393 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 394 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 395 | { |
| 396 | if (u16 <= AVRC_PDU_PREV_GROUP) |
| 397 | ret = BTA_AV_RSP_ACCEPT; |
| 398 | else |
| 399 | ret = BTA_AV_RSP_REJ; |
| 400 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | return ret; |
| 405 | } |
| 406 | |
| 407 | /******************************************************************************* |
| 408 | ** |
| 409 | ** Function bta_av_op_supported |
| 410 | ** |
| 411 | ** Description Check if remote control operation is supported. |
| 412 | ** |
| 413 | ** Returns BTA_AV_RSP_ACCEPT of supported, BTA_AV_RSP_NOT_IMPL if not. |
| 414 | ** |
| 415 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 416 | static tBTA_AV_CODE bta_av_op_supported(tBTA_AV_RC rc_id, BOOLEAN is_inquiry) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 417 | { |
| 418 | tBTA_AV_CODE ret_code = BTA_AV_RSP_NOT_IMPL; |
| 419 | |
| 420 | if (p_bta_av_rc_id) |
| 421 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 422 | if (is_inquiry) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 423 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 424 | if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 425 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 426 | ret_code = BTA_AV_RSP_IMPL_STBL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 427 | } |
| 428 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 429 | else |
| 430 | { |
| 431 | if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F))) |
| 432 | { |
| 433 | ret_code = BTA_AV_RSP_ACCEPT; |
| 434 | } |
| 435 | else if ((p_bta_av_cfg->rc_pass_rsp == BTA_AV_RSP_INTERIM) && p_bta_av_rc_id_ac) |
| 436 | { |
| 437 | if (p_bta_av_rc_id_ac[rc_id >> 4] & (1 << (rc_id & 0x0F))) |
| 438 | { |
| 439 | ret_code = BTA_AV_RSP_INTERIM; |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 444 | } |
| 445 | return ret_code; |
| 446 | } |
| 447 | |
| 448 | /******************************************************************************* |
| 449 | ** |
| 450 | ** Function bta_av_find_lcb |
| 451 | ** |
| 452 | ** Description Given BD_addr, find the associated LCB. |
| 453 | ** |
| 454 | ** Returns NULL, if not found. |
| 455 | ** |
| 456 | *******************************************************************************/ |
| 457 | tBTA_AV_LCB * bta_av_find_lcb(BD_ADDR addr, UINT8 op) |
| 458 | { |
| 459 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 460 | int xx; |
| 461 | UINT8 mask; |
| 462 | tBTA_AV_LCB *p_lcb = NULL; |
| 463 | |
| 464 | for(xx=0; xx<BTA_AV_NUM_LINKS; xx++) |
| 465 | { |
| 466 | mask = 1 << xx; /* the used mask for this lcb */ |
| 467 | if((mask & p_cb->conn_lcb) && 0 ==( bdcmp(p_cb->lcb[xx].addr, addr))) |
| 468 | { |
| 469 | p_lcb = &p_cb->lcb[xx]; |
| 470 | if(op == BTA_AV_LCB_FREE) |
| 471 | { |
| 472 | p_cb->conn_lcb &= ~mask; /* clear the connect mask */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 473 | APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 474 | } |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | return p_lcb; |
| 479 | } |
| 480 | |
| 481 | /******************************************************************************* |
| 482 | ** |
| 483 | ** Function bta_av_rc_opened |
| 484 | ** |
| 485 | ** Description Set AVRCP state to opened. |
| 486 | ** |
| 487 | ** Returns void |
| 488 | ** |
| 489 | *******************************************************************************/ |
| 490 | void bta_av_rc_opened(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 491 | { |
| 492 | tBTA_AV_RC_OPEN rc_open; |
| 493 | tBTA_AV_SCB *p_scb; |
| 494 | int i; |
| 495 | UINT8 shdl = 0; |
| 496 | tBTA_AV_LCB *p_lcb; |
| 497 | tBTA_AV_RCB *p_rcb; |
| 498 | UINT8 tmp; |
| 499 | UINT8 disc = 0; |
| 500 | |
| 501 | /* find the SCB & stop the timer */ |
| 502 | for(i=0; i<BTA_AV_NUM_STRS; i++) |
| 503 | { |
| 504 | p_scb = p_cb->p_scb[i]; |
| 505 | if(p_scb && bdcmp(p_scb->peer_addr, p_data->rc_conn_chg.peer_addr) == 0) |
| 506 | { |
| 507 | p_scb->rc_handle = p_data->rc_conn_chg.handle; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 508 | APPL_TRACE_DEBUG("bta_av_rc_opened shdl:%d, srch %d", i + 1, p_scb->rc_handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 509 | shdl = i+1; |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 510 | LOG_INFO(LOG_TAG, "%s allow incoming AVRCP connections:%d", __func__, p_scb->use_rc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 511 | bta_sys_stop_timer(&p_scb->timer); |
| 512 | disc = p_scb->hndl; |
| 513 | break; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | i = p_data->rc_conn_chg.handle; |
| 518 | if (p_cb->rcb[i].handle == BTA_AV_RC_HANDLE_NONE) |
| 519 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 520 | APPL_TRACE_ERROR("not a valid handle:%d any more", i); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 521 | return; |
| 522 | } |
| 523 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 524 | if (p_cb->rcb[i].lidx == (BTA_AV_NUM_LINKS + 1) && shdl != 0) |
| 525 | { |
| 526 | /* rc is opened on the RC only ACP channel, but is for a specific |
| 527 | * SCB -> need to switch RCBs */ |
| 528 | p_rcb = bta_av_get_rcb_by_shdl(shdl); |
| 529 | if (p_rcb) |
| 530 | { |
| 531 | p_rcb->shdl = p_cb->rcb[i].shdl; |
| 532 | tmp = p_rcb->lidx; |
| 533 | p_rcb->lidx = p_cb->rcb[i].lidx; |
| 534 | p_cb->rcb[i].lidx = tmp; |
| 535 | p_cb->rc_acp_handle = p_rcb->handle; |
| 536 | p_cb->rc_acp_idx = (p_rcb - p_cb->rcb) + 1; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 537 | APPL_TRACE_DEBUG("switching RCB rc_acp_handle:%d idx:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 538 | p_cb->rc_acp_handle, p_cb->rc_acp_idx); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | p_cb->rcb[i].shdl = shdl; |
| 543 | rc_open.rc_handle = i; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 544 | APPL_TRACE_ERROR("bta_av_rc_opened rcb[%d] shdl:%d lidx:%d/%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 545 | i, shdl, p_cb->rcb[i].lidx, p_cb->lcb[BTA_AV_NUM_LINKS].lidx); |
| 546 | p_cb->rcb[i].status |= BTA_AV_RC_CONN_MASK; |
| 547 | |
| 548 | if(!shdl && 0 == p_cb->lcb[BTA_AV_NUM_LINKS].lidx) |
| 549 | { |
| 550 | /* no associated SCB -> connected to an RC only device |
| 551 | * update the index to the extra LCB */ |
| 552 | p_lcb = &p_cb->lcb[BTA_AV_NUM_LINKS]; |
| 553 | bdcpy(p_lcb->addr, p_data->rc_conn_chg.peer_addr); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 554 | APPL_TRACE_DEBUG("rc_only bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 555 | p_lcb->addr[0], p_lcb->addr[1], |
| 556 | p_lcb->addr[2], p_lcb->addr[3], |
| 557 | p_lcb->addr[4], p_lcb->addr[5]); |
| 558 | p_lcb->lidx = BTA_AV_NUM_LINKS + 1; |
| 559 | p_cb->rcb[i].lidx = p_lcb->lidx; |
| 560 | p_lcb->conn_msk = 1; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 561 | APPL_TRACE_ERROR("rcb[%d].lidx=%d, lcb.conn_msk=x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 562 | i, p_cb->rcb[i].lidx, p_lcb->conn_msk); |
| 563 | disc = p_data->rc_conn_chg.handle|BTA_AV_CHNL_MSK; |
| 564 | } |
| 565 | |
| 566 | bdcpy(rc_open.peer_addr, p_data->rc_conn_chg.peer_addr); |
| 567 | rc_open.peer_features = p_cb->rcb[i].peer_features; |
| 568 | rc_open.status = BTA_AV_SUCCESS; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 569 | APPL_TRACE_DEBUG("local features:x%x peer_features:x%x", p_cb->features, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 570 | rc_open.peer_features); |
| 571 | if(rc_open.peer_features == 0) |
| 572 | { |
| 573 | /* we have not done SDP on peer RC capabilities. |
| 574 | * peer must have initiated the RC connection */ |
| 575 | rc_open.peer_features = BTA_AV_FEAT_RCCT; |
| 576 | bta_av_rc_disc(disc); |
| 577 | } |
| 578 | (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, (tBTA_AV *) &rc_open); |
| 579 | |
| 580 | } |
| 581 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 582 | /******************************************************************************* |
| 583 | ** |
| 584 | ** Function bta_av_rc_remote_cmd |
| 585 | ** |
| 586 | ** Description Send an AVRCP remote control command. |
| 587 | ** |
| 588 | ** Returns void |
| 589 | ** |
| 590 | *******************************************************************************/ |
| 591 | void bta_av_rc_remote_cmd(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 592 | { |
| 593 | tBTA_AV_RCB *p_rcb; |
| 594 | if (p_cb->features & BTA_AV_FEAT_RCCT) |
| 595 | { |
| 596 | if(p_data->hdr.layer_specific < BTA_AV_NUM_RCB) |
| 597 | { |
| 598 | p_rcb = &p_cb->rcb[p_data->hdr.layer_specific]; |
| 599 | if(p_rcb->status & BTA_AV_RC_CONN_MASK) |
| 600 | { |
| 601 | AVRC_PassCmd(p_rcb->handle, p_data->api_remote_cmd.label, |
| 602 | &p_data->api_remote_cmd.msg); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | /******************************************************************************* |
| 609 | ** |
| 610 | ** Function bta_av_rc_vendor_cmd |
| 611 | ** |
| 612 | ** Description Send an AVRCP vendor specific command. |
| 613 | ** |
| 614 | ** Returns void |
| 615 | ** |
| 616 | *******************************************************************************/ |
| 617 | void bta_av_rc_vendor_cmd(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 618 | { |
| 619 | tBTA_AV_RCB *p_rcb; |
| 620 | if ( (p_cb->features & (BTA_AV_FEAT_RCCT | BTA_AV_FEAT_VENDOR)) == |
| 621 | (BTA_AV_FEAT_RCCT | BTA_AV_FEAT_VENDOR)) |
| 622 | { |
| 623 | if(p_data->hdr.layer_specific < BTA_AV_NUM_RCB) |
| 624 | { |
| 625 | p_rcb = &p_cb->rcb[p_data->hdr.layer_specific]; |
| 626 | AVRC_VendorCmd(p_rcb->handle, p_data->api_vendor.label, &p_data->api_vendor.msg); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | /******************************************************************************* |
| 632 | ** |
| 633 | ** Function bta_av_rc_vendor_rsp |
| 634 | ** |
| 635 | ** Description Send an AVRCP vendor specific response. |
| 636 | ** |
| 637 | ** Returns void |
| 638 | ** |
| 639 | *******************************************************************************/ |
| 640 | void bta_av_rc_vendor_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 641 | { |
| 642 | tBTA_AV_RCB *p_rcb; |
| 643 | if ( (p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_VENDOR)) == |
| 644 | (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_VENDOR)) |
| 645 | { |
| 646 | if(p_data->hdr.layer_specific < BTA_AV_NUM_RCB) |
| 647 | { |
| 648 | p_rcb = &p_cb->rcb[p_data->hdr.layer_specific]; |
| 649 | AVRC_VendorRsp(p_rcb->handle, p_data->api_vendor.label, &p_data->api_vendor.msg); |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /******************************************************************************* |
| 655 | ** |
| 656 | ** Function bta_av_rc_meta_rsp |
| 657 | ** |
| 658 | ** Description Send an AVRCP metadata/advanced control command/response. |
| 659 | ** |
| 660 | ** Returns void |
| 661 | ** |
| 662 | *******************************************************************************/ |
| 663 | void bta_av_rc_meta_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 664 | { |
| 665 | tBTA_AV_RCB *p_rcb; |
Pavlin Radoslavov | eae6166 | 2015-06-02 13:54:58 -0700 | [diff] [blame] | 666 | BOOLEAN do_free = TRUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 667 | |
| 668 | if ((p_cb->features & BTA_AV_FEAT_METADATA) && (p_data->hdr.layer_specific < BTA_AV_NUM_RCB)) |
| 669 | { |
| 670 | if ((p_data->api_meta_rsp.is_rsp && (p_cb->features & BTA_AV_FEAT_RCTG)) || |
| 671 | (!p_data->api_meta_rsp.is_rsp && (p_cb->features & BTA_AV_FEAT_RCCT)) ) |
| 672 | { |
| 673 | p_rcb = &p_cb->rcb[p_data->hdr.layer_specific]; |
Zhihai Xu | 17b504d | 2013-09-16 18:16:47 -0700 | [diff] [blame] | 674 | if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) { |
| 675 | AVRC_MsgReq(p_rcb->handle, p_data->api_meta_rsp.label, |
| 676 | p_data->api_meta_rsp.rsp_code, |
| 677 | p_data->api_meta_rsp.p_pkt); |
Pavlin Radoslavov | eae6166 | 2015-06-02 13:54:58 -0700 | [diff] [blame] | 678 | do_free = FALSE; |
Zhihai Xu | 17b504d | 2013-09-16 18:16:47 -0700 | [diff] [blame] | 679 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Pavlin Radoslavov | eae6166 | 2015-06-02 13:54:58 -0700 | [diff] [blame] | 683 | if (do_free) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 684 | GKI_freebuf (p_data->api_meta_rsp.p_pkt); |
| 685 | } |
| 686 | |
| 687 | /******************************************************************************* |
| 688 | ** |
| 689 | ** Function bta_av_rc_free_rsp |
| 690 | ** |
| 691 | ** Description free an AVRCP metadata command buffer. |
| 692 | ** |
| 693 | ** Returns void |
| 694 | ** |
| 695 | *******************************************************************************/ |
| 696 | void bta_av_rc_free_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 697 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 698 | UNUSED(p_cb); |
| 699 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 700 | GKI_freebuf (p_data->api_meta_rsp.p_pkt); |
| 701 | } |
| 702 | |
| 703 | /******************************************************************************* |
| 704 | ** |
| 705 | ** Function bta_av_rc_meta_req |
| 706 | ** |
| 707 | ** Description Send an AVRCP metadata command. |
| 708 | ** |
| 709 | ** Returns void |
| 710 | ** |
| 711 | *******************************************************************************/ |
| 712 | void bta_av_rc_free_msg (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 713 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 714 | UNUSED(p_cb); |
| 715 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 716 | } |
| 717 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 718 | /******************************************************************************* |
| 719 | ** |
| 720 | ** Function bta_av_chk_notif_evt_id |
| 721 | ** |
| 722 | ** Description make sure the requested player id is valid. |
| 723 | ** |
| 724 | ** Returns BTA_AV_STS_NO_RSP, if no error |
| 725 | ** |
| 726 | *******************************************************************************/ |
| 727 | static tAVRC_STS bta_av_chk_notif_evt_id(tAVRC_MSG_VENDOR *p_vendor) |
| 728 | { |
| 729 | tAVRC_STS status = BTA_AV_STS_NO_RSP; |
| 730 | UINT8 xx; |
| 731 | UINT16 u16; |
| 732 | UINT8 *p = p_vendor->p_vendor_data + 2; |
| 733 | |
| 734 | BE_STREAM_TO_UINT16 (u16, p); |
| 735 | /* double check the fixed length */ |
| 736 | if ((u16 != 5) || (p_vendor->vendor_len != 9)) |
| 737 | { |
| 738 | status = AVRC_STS_INTERNAL_ERR; |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | /* make sure the player_id is valid */ |
| 743 | for (xx=0; xx<p_bta_av_cfg->num_evt_ids; xx++) |
| 744 | { |
| 745 | if (*p == p_bta_av_cfg->p_meta_evt_ids[xx]) |
| 746 | { |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | if (xx == p_bta_av_cfg->num_evt_ids) |
| 751 | { |
| 752 | status = AVRC_STS_BAD_PARAM; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | return status; |
| 757 | } |
| 758 | |
| 759 | /******************************************************************************* |
| 760 | ** |
| 761 | ** Function bta_av_proc_meta_cmd |
| 762 | ** |
| 763 | ** Description Process an AVRCP metadata command from the peer. |
| 764 | ** |
| 765 | ** Returns TRUE to respond immediately |
| 766 | ** |
| 767 | *******************************************************************************/ |
| 768 | tBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE *p_rc_rsp, tBTA_AV_RC_MSG *p_msg, UINT8 *p_ctype) |
| 769 | { |
| 770 | tBTA_AV_EVT evt = BTA_AV_META_MSG_EVT; |
| 771 | UINT8 u8, pdu, *p; |
| 772 | UINT16 u16; |
| 773 | tAVRC_MSG_VENDOR *p_vendor = &p_msg->msg.vendor; |
| 774 | |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 775 | #if (AVRC_METADATA_INCLUDED == TRUE) |
| 776 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 777 | pdu = *(p_vendor->p_vendor_data); |
| 778 | p_rc_rsp->pdu = pdu; |
| 779 | *p_ctype = AVRC_RSP_REJ; |
| 780 | /* Metadata messages only use PANEL sub-unit type */ |
| 781 | if (p_vendor->hdr.subunit_type != AVRC_SUB_PANEL) |
| 782 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 783 | APPL_TRACE_DEBUG("SUBUNIT must be PANEL"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 784 | /* reject it */ |
| 785 | evt=0; |
| 786 | p_vendor->hdr.ctype = BTA_AV_RSP_NOT_IMPL; |
| 787 | AVRC_VendorRsp(p_msg->handle, p_msg->label, &p_msg->msg.vendor); |
| 788 | } |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 789 | else if (!AVRC_IsValidAvcType(pdu, p_vendor->hdr.ctype) ) |
| 790 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 791 | APPL_TRACE_DEBUG("Invalid pdu/ctype: 0x%x, %d", pdu, p_vendor->hdr.ctype); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 792 | /* reject invalid message without reporting to app */ |
| 793 | evt = 0; |
| 794 | p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD; |
| 795 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 796 | else |
| 797 | { |
| 798 | switch (pdu) |
| 799 | { |
| 800 | case AVRC_PDU_GET_CAPABILITIES: |
| 801 | /* process GetCapabilities command without reporting the event to app */ |
| 802 | evt = 0; |
| 803 | u8 = *(p_vendor->p_vendor_data + 4); |
| 804 | p = p_vendor->p_vendor_data + 2; |
| 805 | p_rc_rsp->get_caps.capability_id = u8; |
| 806 | BE_STREAM_TO_UINT16 (u16, p); |
| 807 | if ((u16 != 1) || (p_vendor->vendor_len != 5)) |
| 808 | { |
| 809 | p_rc_rsp->get_caps.status = AVRC_STS_INTERNAL_ERR; |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | p_rc_rsp->get_caps.status = AVRC_STS_NO_ERROR; |
| 814 | if (u8 == AVRC_CAP_COMPANY_ID) |
| 815 | { |
| 816 | *p_ctype = AVRC_RSP_IMPL_STBL; |
| 817 | p_rc_rsp->get_caps.count = p_bta_av_cfg->num_co_ids; |
| 818 | memcpy(p_rc_rsp->get_caps.param.company_id, p_bta_av_cfg->p_meta_co_ids, |
| 819 | (p_bta_av_cfg->num_co_ids << 2)); |
| 820 | } |
| 821 | else if (u8 == AVRC_CAP_EVENTS_SUPPORTED) |
| 822 | { |
| 823 | *p_ctype = AVRC_RSP_IMPL_STBL; |
| 824 | p_rc_rsp->get_caps.count = p_bta_av_cfg->num_evt_ids; |
| 825 | memcpy(p_rc_rsp->get_caps.param.event_id, p_bta_av_cfg->p_meta_evt_ids, |
| 826 | p_bta_av_cfg->num_evt_ids); |
| 827 | } |
| 828 | else |
| 829 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 830 | APPL_TRACE_DEBUG("Invalid capability ID: 0x%x", u8); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 831 | /* reject - unknown capability ID */ |
| 832 | p_rc_rsp->get_caps.status = AVRC_STS_BAD_PARAM; |
| 833 | } |
| 834 | } |
| 835 | break; |
| 836 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 837 | case AVRC_PDU_REGISTER_NOTIFICATION: |
| 838 | /* make sure the event_id is implemented */ |
| 839 | p_rc_rsp->rsp.status = bta_av_chk_notif_evt_id (p_vendor); |
| 840 | if (p_rc_rsp->rsp.status != BTA_AV_STS_NO_RSP) |
| 841 | evt = 0; |
| 842 | break; |
| 843 | |
| 844 | } |
| 845 | } |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 846 | #else |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 847 | APPL_TRACE_DEBUG("AVRCP 1.3 Metadata not supporteed. Reject command."); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 848 | /* reject invalid message without reporting to app */ |
| 849 | evt = 0; |
| 850 | p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD; |
| 851 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 852 | |
| 853 | return evt; |
| 854 | } |
| 855 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 856 | /******************************************************************************* |
| 857 | ** |
| 858 | ** Function bta_av_rc_msg |
| 859 | ** |
| 860 | ** Description Process an AVRCP message from the peer. |
| 861 | ** |
| 862 | ** Returns void |
| 863 | ** |
| 864 | *******************************************************************************/ |
| 865 | void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 866 | { |
| 867 | tBTA_AV_EVT evt = 0; |
| 868 | tBTA_AV av; |
| 869 | BT_HDR *p_pkt = NULL; |
| 870 | tAVRC_MSG_VENDOR *p_vendor = &p_data->rc_msg.msg.vendor; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 871 | BOOLEAN is_inquiry = ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) || p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 872 | #if (AVRC_METADATA_INCLUDED == TRUE) |
Matthew Xie | bea4131 | 2014-05-09 01:04:04 -0700 | [diff] [blame] | 873 | UINT8 ctype = 0; |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 874 | tAVRC_RESPONSE rc_rsp; |
| 875 | |
| 876 | rc_rsp.rsp.status = BTA_AV_STS_NO_RSP; |
| 877 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 878 | |
| 879 | if (p_data->rc_msg.opcode == AVRC_OP_PASS_THRU) |
| 880 | { |
| 881 | /* if this is a pass thru command */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 882 | if ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_CTRL) || |
| 883 | (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) || |
| 884 | (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ) |
| 885 | ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 886 | { |
| 887 | /* check if operation is supported */ |
| 888 | if (p_data->rc_msg.msg.pass.op_id == AVRC_ID_VENDOR) |
| 889 | { |
| 890 | p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL; |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 891 | #if (AVRC_METADATA_INCLUDED == TRUE) |
| 892 | if (p_cb->features & BTA_AV_FEAT_METADATA) |
| 893 | p_data->rc_msg.msg.hdr.ctype = |
| 894 | bta_av_group_navi_supported(p_data->rc_msg.msg.pass.pass_len, |
| 895 | p_data->rc_msg.msg.pass.p_pass_data, is_inquiry); |
| 896 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 897 | } |
| 898 | else |
| 899 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 900 | p_data->rc_msg.msg.hdr.ctype = bta_av_op_supported(p_data->rc_msg.msg.pass.op_id, is_inquiry); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 903 | APPL_TRACE_DEBUG("ctype %d",p_data->rc_msg.msg.hdr.ctype) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 904 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 905 | /* send response */ |
| 906 | if (p_data->rc_msg.msg.hdr.ctype != BTA_AV_RSP_INTERIM) |
| 907 | AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass); |
| 908 | |
| 909 | /* set up for callback if supported */ |
| 910 | if (p_data->rc_msg.msg.hdr.ctype == BTA_AV_RSP_ACCEPT || p_data->rc_msg.msg.hdr.ctype == BTA_AV_RSP_INTERIM) |
| 911 | { |
| 912 | evt = BTA_AV_REMOTE_CMD_EVT; |
| 913 | av.remote_cmd.rc_id = p_data->rc_msg.msg.pass.op_id; |
| 914 | av.remote_cmd.key_state = p_data->rc_msg.msg.pass.state; |
| 915 | av.remote_cmd.p_data = p_data->rc_msg.msg.pass.p_pass_data; |
| 916 | av.remote_cmd.len = p_data->rc_msg.msg.pass.pass_len; |
| 917 | memcpy(&av.remote_cmd.hdr, &p_data->rc_msg.msg.hdr, sizeof (tAVRC_HDR)); |
| 918 | av.remote_cmd.label = p_data->rc_msg.label; |
| 919 | } |
| 920 | } |
| 921 | /* else if this is a pass thru response */ |
| 922 | else if (p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT) |
| 923 | { |
| 924 | /* set up for callback */ |
| 925 | evt = BTA_AV_REMOTE_RSP_EVT; |
| 926 | av.remote_rsp.rc_id = p_data->rc_msg.msg.pass.op_id; |
| 927 | av.remote_rsp.key_state = p_data->rc_msg.msg.pass.state; |
| 928 | av.remote_rsp.rsp_code = p_data->rc_msg.msg.hdr.ctype; |
| 929 | av.remote_rsp.label = p_data->rc_msg.label; |
| 930 | } |
| 931 | /* must be a bad ctype -> reject*/ |
| 932 | else |
| 933 | { |
| 934 | p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_REJ; |
| 935 | AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass); |
| 936 | } |
| 937 | } |
| 938 | /* else if this is a vendor specific command or response */ |
| 939 | else if (p_data->rc_msg.opcode == AVRC_OP_VENDOR) |
| 940 | { |
| 941 | /* set up for callback */ |
| 942 | av.vendor_cmd.code = p_data->rc_msg.msg.hdr.ctype; |
| 943 | av.vendor_cmd.company_id = p_vendor->company_id; |
| 944 | av.vendor_cmd.label = p_data->rc_msg.label; |
| 945 | av.vendor_cmd.p_data = p_vendor->p_vendor_data; |
| 946 | av.vendor_cmd.len = p_vendor->vendor_len; |
| 947 | |
| 948 | /* if configured to support vendor specific and it's a command */ |
| 949 | if ((p_cb->features & BTA_AV_FEAT_VENDOR) && |
| 950 | p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ) |
| 951 | { |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 952 | #if (AVRC_METADATA_INCLUDED == TRUE) |
| 953 | if ((p_cb->features & BTA_AV_FEAT_METADATA) && |
| 954 | (p_vendor->company_id == AVRC_CO_METADATA)) |
| 955 | { |
| 956 | av.meta_msg.p_msg = &p_data->rc_msg.msg; |
| 957 | evt = bta_av_proc_meta_cmd (&rc_rsp, &p_data->rc_msg, &ctype); |
| 958 | } |
| 959 | else |
| 960 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 961 | evt = BTA_AV_VENDOR_CMD_EVT; |
| 962 | } |
| 963 | /* else if configured to support vendor specific and it's a response */ |
| 964 | else if ((p_cb->features & BTA_AV_FEAT_VENDOR) && |
| 965 | p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT) |
| 966 | { |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 967 | #if (AVRC_METADATA_INCLUDED == TRUE) |
| 968 | if ((p_cb->features & BTA_AV_FEAT_METADATA) && |
| 969 | (p_vendor->company_id == AVRC_CO_METADATA)) |
| 970 | { |
| 971 | av.meta_msg.p_msg = &p_data->rc_msg.msg; |
| 972 | evt = BTA_AV_META_MSG_EVT; |
| 973 | } |
| 974 | else |
| 975 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 976 | evt = BTA_AV_VENDOR_RSP_EVT; |
| 977 | |
| 978 | } |
| 979 | /* else if not configured to support vendor specific and it's a command */ |
| 980 | else if (!(p_cb->features & BTA_AV_FEAT_VENDOR) && |
| 981 | p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ) |
| 982 | { |
| 983 | if(p_data->rc_msg.msg.vendor.p_vendor_data[0] == AVRC_PDU_INVALID) |
| 984 | { |
| 985 | /* reject it */ |
| 986 | p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_REJ; |
| 987 | p_data->rc_msg.msg.vendor.p_vendor_data[4] = AVRC_STS_BAD_CMD; |
| 988 | } |
| 989 | else |
| 990 | p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL; |
| 991 | AVRC_VendorRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.vendor); |
| 992 | } |
| 993 | } |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 994 | #if (AVRC_METADATA_INCLUDED == TRUE) |
| 995 | if (evt == 0 && rc_rsp.rsp.status != BTA_AV_STS_NO_RSP) |
| 996 | { |
| 997 | if (!p_pkt) |
| 998 | { |
| 999 | rc_rsp.rsp.opcode = p_data->rc_msg.opcode; |
Sharvil Nanavati | f1c764f | 2015-02-23 17:31:48 -0800 | [diff] [blame] | 1000 | AVRC_BldResponse (0, &rc_rsp, &p_pkt); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 1001 | } |
| 1002 | if (p_pkt) |
| 1003 | AVRC_MsgReq (p_data->rc_msg.handle, p_data->rc_msg.label, ctype, p_pkt); |
| 1004 | } |
| 1005 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1006 | |
| 1007 | /* call callback */ |
| 1008 | if (evt != 0) |
| 1009 | { |
| 1010 | av.remote_cmd.rc_handle = p_data->rc_msg.handle; |
| 1011 | (*p_cb->p_cback)(evt, &av); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | /******************************************************************************* |
| 1016 | ** |
| 1017 | ** Function bta_av_rc_close |
| 1018 | ** |
| 1019 | ** Description close the specified AVRC handle. |
| 1020 | ** |
| 1021 | ** Returns void |
| 1022 | ** |
| 1023 | *******************************************************************************/ |
| 1024 | void bta_av_rc_close (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 1025 | { |
| 1026 | UINT16 handle = p_data->hdr.layer_specific; |
| 1027 | tBTA_AV_SCB *p_scb; |
| 1028 | tBTA_AV_RCB *p_rcb; |
| 1029 | |
| 1030 | if(handle < BTA_AV_NUM_RCB) |
| 1031 | { |
| 1032 | p_rcb = &p_cb->rcb[handle]; |
| 1033 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1034 | APPL_TRACE_DEBUG("bta_av_rc_close handle: %d, status=0x%x", p_rcb->handle, p_rcb->status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1035 | if(p_rcb->handle != BTA_AV_RC_HANDLE_NONE) |
| 1036 | { |
| 1037 | if(p_rcb->shdl) |
| 1038 | { |
| 1039 | p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1]; |
| 1040 | if(p_scb) |
| 1041 | { |
| 1042 | /* just in case the RC timer is active |
| 1043 | if(bta_av_cb.features & BTA_AV_FEAT_RCCT && |
| 1044 | p_scb->chnl == BTA_AV_CHNL_AUDIO) */ |
| 1045 | bta_sys_stop_timer(&p_scb->timer); |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | AVRC_Close(p_rcb->handle); |
| 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | /******************************************************************************* |
| 1055 | ** |
| 1056 | ** Function bta_av_get_shdl |
| 1057 | ** |
| 1058 | ** Returns The index to p_scb[] |
| 1059 | ** |
| 1060 | *******************************************************************************/ |
| 1061 | static UINT8 bta_av_get_shdl(tBTA_AV_SCB *p_scb) |
| 1062 | { |
| 1063 | int i; |
| 1064 | UINT8 shdl = 0; |
| 1065 | /* find the SCB & stop the timer */ |
| 1066 | for(i=0; i<BTA_AV_NUM_STRS; i++) |
| 1067 | { |
| 1068 | if(p_scb == bta_av_cb.p_scb[i]) |
| 1069 | { |
| 1070 | shdl = i+1; |
| 1071 | break; |
| 1072 | } |
| 1073 | } |
| 1074 | return shdl; |
| 1075 | } |
| 1076 | |
| 1077 | /******************************************************************************* |
| 1078 | ** |
| 1079 | ** Function bta_av_stream_chg |
| 1080 | ** |
| 1081 | ** Description audio streaming status changed. |
| 1082 | ** |
| 1083 | ** Returns void |
| 1084 | ** |
| 1085 | *******************************************************************************/ |
| 1086 | void bta_av_stream_chg(tBTA_AV_SCB *p_scb, BOOLEAN started) |
| 1087 | { |
| 1088 | UINT8 started_msk; |
| 1089 | int i; |
| 1090 | UINT8 *p_streams; |
| 1091 | BOOLEAN no_streams = FALSE; |
| 1092 | tBTA_AV_SCB *p_scbi; |
| 1093 | |
| 1094 | started_msk = BTA_AV_HNDL_TO_MSK(p_scb->hdi); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1095 | APPL_TRACE_DEBUG ("bta_av_stream_chg started:%d started_msk:x%x chnl:x%x", started, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1096 | started_msk, p_scb->chnl); |
| 1097 | if (BTA_AV_CHNL_AUDIO == p_scb->chnl) |
| 1098 | p_streams = &bta_av_cb.audio_streams; |
| 1099 | else |
| 1100 | p_streams = &bta_av_cb.video_streams; |
| 1101 | |
| 1102 | if (started) |
| 1103 | { |
| 1104 | /* Let L2CAP know this channel is processed with high priority */ |
| 1105 | L2CA_SetAclPriority(p_scb->peer_addr, L2CAP_PRIORITY_HIGH); |
| 1106 | (*p_streams) |= started_msk; |
| 1107 | } |
| 1108 | else |
| 1109 | { |
| 1110 | (*p_streams) &= ~started_msk; |
| 1111 | } |
| 1112 | |
| 1113 | if (!started) |
| 1114 | { |
| 1115 | i=0; |
| 1116 | if (BTA_AV_CHNL_AUDIO == p_scb->chnl) |
| 1117 | { |
| 1118 | if (bta_av_cb.video_streams == 0) |
| 1119 | no_streams = TRUE; |
| 1120 | } |
| 1121 | else |
| 1122 | { |
| 1123 | no_streams = TRUE; |
| 1124 | if ( bta_av_cb.audio_streams ) |
| 1125 | { |
| 1126 | for (; i<BTA_AV_NUM_STRS; i++) |
| 1127 | { |
| 1128 | p_scbi = bta_av_cb.p_scb[i]; |
| 1129 | /* scb is used and started */ |
| 1130 | if ( p_scbi && (bta_av_cb.audio_streams & BTA_AV_HNDL_TO_MSK(i)) |
| 1131 | && bdcmp(p_scbi->peer_addr, p_scb->peer_addr) == 0) |
| 1132 | { |
| 1133 | no_streams = FALSE; |
| 1134 | break; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | } |
| 1139 | } |
| 1140 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1141 | APPL_TRACE_DEBUG ("no_streams:%d i:%d, audio_streams:x%x, video_streams:x%x", no_streams, i, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1142 | bta_av_cb.audio_streams, bta_av_cb.video_streams); |
| 1143 | if (no_streams) |
| 1144 | { |
| 1145 | /* Let L2CAP know this channel is processed with low priority */ |
| 1146 | L2CA_SetAclPriority(p_scb->peer_addr, L2CAP_PRIORITY_NORMAL); |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1151 | /******************************************************************************* |
| 1152 | ** |
| 1153 | ** Function bta_av_conn_chg |
| 1154 | ** |
| 1155 | ** Description connetion status changed. |
| 1156 | ** Open an AVRCP acceptor channel, if new conn. |
| 1157 | ** |
| 1158 | ** Returns void |
| 1159 | ** |
| 1160 | *******************************************************************************/ |
| 1161 | void bta_av_conn_chg(tBTA_AV_DATA *p_data) |
| 1162 | { |
| 1163 | tBTA_AV_CB *p_cb = &bta_av_cb; |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1164 | tBTA_AV_SCB *p_scb = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1165 | tBTA_AV_SCB *p_scbi; |
| 1166 | UINT8 mask; |
| 1167 | UINT8 conn_msk; |
| 1168 | UINT8 old_msk; |
| 1169 | int i; |
| 1170 | int index = (p_data->hdr.layer_specific & BTA_AV_HNDL_MSK) - 1; |
| 1171 | tBTA_AV_LCB *p_lcb; |
| 1172 | tBTA_AV_LCB *p_lcb_rc; |
| 1173 | tBTA_AV_RCB *p_rcb, *p_rcb2; |
| 1174 | BOOLEAN chk_restore = FALSE; |
| 1175 | |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1176 | /* Validate array index*/ |
| 1177 | if (index < BTA_AV_NUM_STRS) |
| 1178 | { |
| 1179 | p_scb = p_cb->p_scb[index]; |
| 1180 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1181 | mask = BTA_AV_HNDL_TO_MSK(index); |
| 1182 | p_lcb = bta_av_find_lcb(p_data->conn_chg.peer_addr, BTA_AV_LCB_FIND); |
| 1183 | conn_msk = 1 << (index + 1); |
| 1184 | if(p_data->conn_chg.is_up) |
| 1185 | { |
| 1186 | /* set the conned mask for this channel */ |
| 1187 | if(p_scb) |
| 1188 | { |
| 1189 | if(p_lcb) |
| 1190 | { |
| 1191 | p_lcb->conn_msk |= conn_msk; |
| 1192 | for (i=0; i<BTA_AV_NUM_RCB; i++) |
| 1193 | { |
| 1194 | if (bta_av_cb.rcb[i].lidx == p_lcb->lidx) |
| 1195 | { |
| 1196 | bta_av_cb.rcb[i].shdl = index + 1; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1197 | APPL_TRACE_DEBUG("conn_chg up[%d]: %d, status=0x%x, shdl:%d, lidx:%d", i, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1198 | bta_av_cb.rcb[i].handle, bta_av_cb.rcb[i].status, |
| 1199 | bta_av_cb.rcb[i].shdl, bta_av_cb.rcb[i].lidx); |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | if (p_scb->chnl == BTA_AV_CHNL_AUDIO) |
| 1205 | { |
| 1206 | old_msk = p_cb->conn_audio; |
| 1207 | p_cb->conn_audio |= mask; |
| 1208 | } |
| 1209 | else |
| 1210 | { |
| 1211 | old_msk = p_cb->conn_video; |
| 1212 | p_cb->conn_video |= mask; |
| 1213 | } |
| 1214 | |
| 1215 | if ((old_msk & mask) == 0) |
| 1216 | { |
| 1217 | /* increase the audio open count, if not set yet */ |
| 1218 | bta_av_cb.audio_open_cnt++; |
| 1219 | } |
| 1220 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1221 | APPL_TRACE_DEBUG("rc_acp_handle:%d rc_acp_idx:%d", p_cb->rc_acp_handle, p_cb->rc_acp_idx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1222 | /* check if the AVRCP ACP channel is already connected */ |
| 1223 | if(p_lcb && p_cb->rc_acp_handle != BTA_AV_RC_HANDLE_NONE && p_cb->rc_acp_idx) |
| 1224 | { |
| 1225 | p_lcb_rc = &p_cb->lcb[BTA_AV_NUM_LINKS]; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1226 | APPL_TRACE_DEBUG("rc_acp is connected && conn_chg on same addr p_lcb_rc->conn_msk:x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1227 | p_lcb_rc->conn_msk); |
| 1228 | /* check if the RC is connected to the scb addr */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1229 | APPL_TRACE_DEBUG ("p_lcb_rc->addr: %02x:%02x:%02x:%02x:%02x:%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1230 | p_lcb_rc->addr[0], p_lcb_rc->addr[1], p_lcb_rc->addr[2], p_lcb_rc->addr[3], |
| 1231 | p_lcb_rc->addr[4], p_lcb_rc->addr[5]); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1232 | APPL_TRACE_DEBUG ("conn_chg.peer_addr: %02x:%02x:%02x:%02x:%02x:%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1233 | p_data->conn_chg.peer_addr[0], p_data->conn_chg.peer_addr[1], |
| 1234 | p_data->conn_chg.peer_addr[2], |
| 1235 | p_data->conn_chg.peer_addr[3], p_data->conn_chg.peer_addr[4], |
| 1236 | p_data->conn_chg.peer_addr[5]); |
| 1237 | if (p_lcb_rc->conn_msk && bdcmp(p_lcb_rc->addr, p_data->conn_chg.peer_addr) == 0) |
| 1238 | { |
| 1239 | /* AVRCP is already connected. |
| 1240 | * need to update the association betwen SCB and RCB */ |
| 1241 | p_lcb_rc->conn_msk = 0; /* indicate RC ONLY is not connected */ |
| 1242 | p_lcb_rc->lidx = 0; |
| 1243 | p_scb->rc_handle = p_cb->rc_acp_handle; |
| 1244 | p_rcb = &p_cb->rcb[p_cb->rc_acp_idx - 1]; |
| 1245 | p_rcb->shdl = bta_av_get_shdl(p_scb); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1246 | APPL_TRACE_DEBUG("update rc_acp shdl:%d/%d srch:%d", index + 1, p_rcb->shdl, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1247 | p_scb->rc_handle ); |
| 1248 | |
| 1249 | p_rcb2 = bta_av_get_rcb_by_shdl(p_rcb->shdl); |
| 1250 | if (p_rcb2) |
| 1251 | { |
| 1252 | /* found the RCB that was created to associated with this SCB */ |
| 1253 | p_cb->rc_acp_handle = p_rcb2->handle; |
| 1254 | p_cb->rc_acp_idx = (p_rcb2 - p_cb->rcb) + 1; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1255 | APPL_TRACE_DEBUG("new rc_acp_handle:%d, idx:%d", p_cb->rc_acp_handle, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1256 | p_cb->rc_acp_idx); |
| 1257 | p_rcb2->lidx = (BTA_AV_NUM_LINKS + 1); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1258 | APPL_TRACE_DEBUG("rc2 handle:%d lidx:%d/%d",p_rcb2->handle, p_rcb2->lidx, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1259 | p_cb->lcb[p_rcb2->lidx-1].lidx); |
| 1260 | } |
| 1261 | p_rcb->lidx = p_lcb->lidx; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1262 | APPL_TRACE_DEBUG("rc handle:%d lidx:%d/%d",p_rcb->handle, p_rcb->lidx, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1263 | p_cb->lcb[p_rcb->lidx-1].lidx); |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | else |
| 1269 | { |
| 1270 | if ((p_cb->conn_audio & mask) && bta_av_cb.audio_open_cnt) |
| 1271 | { |
| 1272 | /* this channel is still marked as open. decrease the count */ |
| 1273 | bta_av_cb.audio_open_cnt--; |
| 1274 | } |
| 1275 | |
| 1276 | /* clear the conned mask for this channel */ |
| 1277 | p_cb->conn_audio &= ~mask; |
| 1278 | p_cb->conn_video &= ~mask; |
| 1279 | if(p_scb) |
| 1280 | { |
| 1281 | /* the stream is closed. |
| 1282 | * clear the peer address, so it would not mess up the AVRCP for the next round of operation */ |
| 1283 | bdcpy(p_scb->peer_addr, bd_addr_null); |
| 1284 | if(p_scb->chnl == BTA_AV_CHNL_AUDIO) |
| 1285 | { |
| 1286 | if(p_lcb) |
| 1287 | { |
| 1288 | p_lcb->conn_msk &= ~conn_msk; |
| 1289 | } |
| 1290 | /* audio channel is down. make sure the INT channel is down */ |
| 1291 | /* just in case the RC timer is active |
| 1292 | if(p_cb->features & BTA_AV_FEAT_RCCT) */ |
| 1293 | { |
| 1294 | bta_sys_stop_timer(&p_scb->timer); |
| 1295 | } |
| 1296 | /* one audio channel goes down. check if we need to restore high priority */ |
| 1297 | chk_restore = TRUE; |
| 1298 | } |
| 1299 | } |
| 1300 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1301 | APPL_TRACE_DEBUG("bta_av_conn_chg shdl:%d", index + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1302 | for (i=0; i<BTA_AV_NUM_RCB; i++) |
| 1303 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1304 | APPL_TRACE_DEBUG("conn_chg dn[%d]: %d, status=0x%x, shdl:%d, lidx:%d", i, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1305 | bta_av_cb.rcb[i].handle, bta_av_cb.rcb[i].status, |
| 1306 | bta_av_cb.rcb[i].shdl, bta_av_cb.rcb[i].lidx); |
| 1307 | if(bta_av_cb.rcb[i].shdl == index + 1) |
| 1308 | { |
| 1309 | bta_av_del_rc(&bta_av_cb.rcb[i]); |
| 1310 | break; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | if(p_cb->conn_audio == 0 && p_cb->conn_video == 0) |
| 1315 | { |
| 1316 | /* if both channels are not connected, |
| 1317 | * close all RC channels */ |
| 1318 | bta_av_close_all_rc(p_cb); |
| 1319 | } |
| 1320 | |
| 1321 | /* if the AVRCP is no longer listening, create the listening channel */ |
| 1322 | if (bta_av_cb.rc_acp_handle == BTA_AV_RC_HANDLE_NONE && bta_av_cb.features & BTA_AV_FEAT_RCTG) |
| 1323 | bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1); |
| 1324 | } |
| 1325 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1326 | APPL_TRACE_DEBUG("bta_av_conn_chg audio:%x video:%x up:%d conn_msk:0x%x chk_restore:%d audio_open_cnt:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1327 | p_cb->conn_audio, p_cb->conn_video, p_data->conn_chg.is_up, conn_msk, chk_restore, p_cb->audio_open_cnt); |
| 1328 | |
| 1329 | if (chk_restore) |
| 1330 | { |
| 1331 | if (p_cb->audio_open_cnt == 1) |
| 1332 | { |
| 1333 | /* one audio channel goes down and there's one audio channel remains open. |
| 1334 | * restore the switch role in default link policy */ |
| 1335 | bta_sys_set_default_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH); |
| 1336 | /* allow role switch, if this is the last connection */ |
| 1337 | bta_av_restore_switch(); |
| 1338 | } |
| 1339 | if (p_cb->audio_open_cnt) |
| 1340 | { |
| 1341 | /* adjust flush timeout settings to longer period */ |
| 1342 | for (i=0; i<BTA_AV_NUM_STRS; i++) |
| 1343 | { |
| 1344 | p_scbi = bta_av_cb.p_scb[i]; |
| 1345 | if (p_scbi && p_scbi->chnl == BTA_AV_CHNL_AUDIO && p_scbi->co_started) |
| 1346 | { |
| 1347 | /* may need to update the flush timeout of this already started stream */ |
| 1348 | if (p_scbi->co_started != bta_av_cb.audio_open_cnt) |
| 1349 | { |
| 1350 | p_scbi->co_started = bta_av_cb.audio_open_cnt; |
| 1351 | L2CA_SetFlushTimeout(p_scbi->peer_addr, p_bta_av_cfg->p_audio_flush_to[p_scbi->co_started - 1] ); |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | /******************************************************************************* |
| 1360 | ** |
| 1361 | ** Function bta_av_disable |
| 1362 | ** |
| 1363 | ** Description disable AV. |
| 1364 | ** |
| 1365 | ** Returns void |
| 1366 | ** |
| 1367 | *******************************************************************************/ |
| 1368 | void bta_av_disable(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) |
| 1369 | { |
| 1370 | BT_HDR hdr; |
| 1371 | UINT16 xx; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1372 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1373 | |
| 1374 | p_cb->disabling = TRUE; |
| 1375 | |
| 1376 | bta_av_close_all_rc(p_cb); |
| 1377 | |
| 1378 | utl_freebuf((void **) &p_cb->p_disc_db); |
| 1379 | |
| 1380 | /* disable audio/video - de-register all channels, |
| 1381 | * expect BTA_AV_DEREG_COMP_EVT when deregister is complete */ |
| 1382 | for(xx=0; xx<BTA_AV_NUM_STRS; xx++) |
| 1383 | { |
| 1384 | hdr.layer_specific = xx + 1; |
| 1385 | bta_av_api_deregister((tBTA_AV_DATA *)&hdr); |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /******************************************************************************* |
| 1390 | ** |
| 1391 | ** Function bta_av_api_disconnect |
| 1392 | ** |
| 1393 | ** Description . |
| 1394 | ** |
| 1395 | ** Returns void |
| 1396 | ** |
| 1397 | *******************************************************************************/ |
| 1398 | void bta_av_api_disconnect(tBTA_AV_DATA *p_data) |
| 1399 | { |
| 1400 | AVDT_DisconnectReq(p_data->api_discnt.bd_addr, bta_av_conn_cback); |
| 1401 | bta_sys_stop_timer(&bta_av_cb.sig_tmr); |
| 1402 | } |
| 1403 | |
| 1404 | /******************************************************************************* |
| 1405 | ** |
| 1406 | ** Function bta_av_sig_chg |
| 1407 | ** |
| 1408 | ** Description process AVDT signal channel up/down. |
| 1409 | ** |
| 1410 | ** Returns void |
| 1411 | ** |
| 1412 | *******************************************************************************/ |
| 1413 | void bta_av_sig_chg(tBTA_AV_DATA *p_data) |
| 1414 | { |
| 1415 | UINT16 event = p_data->str_msg.hdr.layer_specific; |
| 1416 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1417 | int xx; |
| 1418 | UINT8 mask; |
| 1419 | tBTA_AV_LCB *p_lcb = NULL; |
| 1420 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1421 | APPL_TRACE_DEBUG("bta_av_sig_chg event: %d", event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1422 | if(event == AVDT_CONNECT_IND_EVT) |
| 1423 | { |
| 1424 | p_lcb = bta_av_find_lcb(p_data->str_msg.bd_addr, BTA_AV_LCB_FIND); |
| 1425 | if(!p_lcb) |
| 1426 | { |
| 1427 | /* if the address does not have an LCB yet, alloc one */ |
| 1428 | for(xx=0; xx<BTA_AV_NUM_LINKS; xx++) |
| 1429 | { |
| 1430 | mask = 1 << xx; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1431 | APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1432 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1433 | /* look for a p_lcb with its p_scb registered */ |
| 1434 | if((!(mask & p_cb->conn_lcb)) && (p_cb->p_scb[xx] != NULL)) |
| 1435 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1436 | p_lcb = &p_cb->lcb[xx]; |
| 1437 | p_lcb->lidx = xx + 1; |
| 1438 | bdcpy(p_lcb->addr, p_data->str_msg.bd_addr); |
| 1439 | p_lcb->conn_msk = 0; /* clear the connect mask */ |
| 1440 | /* start listening when the signal channel is open */ |
| 1441 | if (p_cb->features & BTA_AV_FEAT_RCTG) |
| 1442 | { |
| 1443 | bta_av_rc_create(p_cb, AVCT_ACP, 0, p_lcb->lidx); |
| 1444 | } |
| 1445 | /* this entry is not used yet. */ |
| 1446 | p_cb->conn_lcb |= mask; /* mark it as used */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1447 | APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1448 | if (p_data->hdr.offset == AVDT_ACP) |
| 1449 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1450 | APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming", NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1451 | bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr); |
| 1452 | p_cb->p_scb[xx]->use_rc = TRUE; /* allowing RC for incoming connection */ |
| 1453 | bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data); |
| 1454 | |
| 1455 | /* The Pending Event should be sent as soon as the L2CAP signalling channel |
| 1456 | * is set up, which is NOW. Earlier this was done only after |
| 1457 | * BTA_AV_SIG_TIME_VAL milliseconds. |
| 1458 | * The following function shall send the event and start the recurring timer |
| 1459 | */ |
| 1460 | bta_av_sig_timer(NULL); |
| 1461 | |
| 1462 | /* Possible collision : need to avoid outgoing processing while the timer is running */ |
| 1463 | p_cb->p_scb[xx]->coll_mask = BTA_AV_COLL_INC_TMR; |
| 1464 | |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 1465 | // TODO(armansito): Why is this variable called "xx" and |
| 1466 | // why is it a signed integer? The callback reinterprets |
| 1467 | // it as a UINT8 and then reassigns it as param that |
| 1468 | // way, so should this be unsigned? |
| 1469 | p_cb->acp_sig_tmr.param = INT_TO_PTR(xx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1470 | p_cb->acp_sig_tmr.p_cback = (TIMER_CBACK*)&bta_av_acp_sig_timer_cback; |
| 1471 | bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL); |
| 1472 | } |
| 1473 | break; |
| 1474 | } |
| 1475 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1476 | |
| 1477 | /* check if we found something */ |
| 1478 | if (xx == BTA_AV_NUM_LINKS) |
| 1479 | { |
| 1480 | /* We do not have scb for this avdt connection. */ |
| 1481 | /* Silently close the connection. */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1482 | APPL_TRACE_ERROR("av scb not available for avdt connection"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1483 | AVDT_DisconnectReq (p_data->str_msg.bd_addr, NULL); |
| 1484 | return; |
| 1485 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) |
| 1489 | else if (event == BTA_AR_AVDT_CONN_EVT) |
| 1490 | { |
| 1491 | bta_sys_stop_timer(&bta_av_cb.sig_tmr); |
| 1492 | } |
| 1493 | #endif |
| 1494 | else |
| 1495 | { |
| 1496 | /* disconnected. */ |
| 1497 | p_lcb = bta_av_find_lcb(p_data->str_msg.bd_addr, BTA_AV_LCB_FREE); |
| 1498 | if(p_lcb && p_lcb->conn_msk) |
| 1499 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1500 | APPL_TRACE_DEBUG("conn_msk: 0x%x", p_lcb->conn_msk); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1501 | /* clean up ssm */ |
| 1502 | for(xx=0; xx < BTA_AV_NUM_STRS; xx++) |
| 1503 | { |
| 1504 | mask = 1 << (xx + 1); |
| 1505 | if ((mask & p_lcb->conn_msk) && (p_cb->p_scb[xx]) && |
| 1506 | (bdcmp(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr) == 0)) |
| 1507 | { |
| 1508 | bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_AVDT_DISCONNECT_EVT, NULL); |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1513 | APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | /******************************************************************************* |
| 1517 | ** |
| 1518 | ** Function bta_av_sig_timer |
| 1519 | ** |
| 1520 | ** Description process the signal channel timer. This timer is started |
| 1521 | ** when the AVDTP signal channel is connected. If no profile |
| 1522 | ** is connected, the timer goes off every BTA_AV_SIG_TIME_VAL |
| 1523 | ** |
| 1524 | ** Returns void |
| 1525 | ** |
| 1526 | *******************************************************************************/ |
| 1527 | void bta_av_sig_timer(tBTA_AV_DATA *p_data) |
| 1528 | { |
| 1529 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1530 | int xx; |
| 1531 | UINT8 mask; |
| 1532 | tBTA_AV_LCB *p_lcb = NULL; |
| 1533 | tBTA_AV_PEND pend; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1534 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1535 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1536 | APPL_TRACE_DEBUG("bta_av_sig_timer"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1537 | for(xx=0; xx<BTA_AV_NUM_LINKS; xx++) |
| 1538 | { |
| 1539 | mask = 1 << xx; |
| 1540 | if(mask & p_cb->conn_lcb) |
| 1541 | { |
| 1542 | /* this entry is used. check if it is connected */ |
| 1543 | p_lcb = &p_cb->lcb[xx]; |
| 1544 | if(!p_lcb->conn_msk) |
| 1545 | { |
| 1546 | bta_sys_start_timer(&p_cb->sig_tmr, BTA_AV_SIG_TIMER_EVT, BTA_AV_SIG_TIME_VAL); |
| 1547 | bdcpy(pend.bd_addr, p_lcb->addr); |
| 1548 | (*p_cb->p_cback)(BTA_AV_PENDING_EVT, (tBTA_AV *) &pend); |
| 1549 | } |
| 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | /******************************************************************************* |
| 1555 | ** |
| 1556 | ** Function bta_av_acp_sig_timer_cback |
| 1557 | ** |
| 1558 | ** Description Process the timeout when SRC is accepting connection |
| 1559 | ** and SNK did not start signalling. |
| 1560 | ** |
| 1561 | ** Returns void |
| 1562 | ** |
| 1563 | *******************************************************************************/ |
| 1564 | static void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle) |
| 1565 | { |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 1566 | UINT8 inx = PTR_TO_UINT(p_tle->param); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1567 | tBTA_AV_CB *p_cb = &bta_av_cb; |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1568 | tBTA_AV_SCB *p_scb = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1569 | tBTA_AV_API_OPEN *p_buf; |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1570 | if (inx < BTA_AV_NUM_STRS) |
| 1571 | { |
| 1572 | p_scb = p_cb->p_scb[inx]; |
| 1573 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1574 | if (p_scb) |
| 1575 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1576 | APPL_TRACE_DEBUG("bta_av_acp_sig_timer_cback, coll_mask = 0x%02X", p_scb->coll_mask); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1577 | |
| 1578 | if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR) |
| 1579 | { |
| 1580 | p_scb->coll_mask &= ~BTA_AV_COLL_INC_TMR; |
| 1581 | |
| 1582 | if (bta_av_is_scb_opening(p_scb)) |
| 1583 | { |
| 1584 | if (p_scb->p_disc_db) |
| 1585 | { |
| 1586 | /* We are still doing SDP. Run the timer again. */ |
| 1587 | p_scb->coll_mask |= BTA_AV_COLL_INC_TMR; |
| 1588 | |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 1589 | p_cb->acp_sig_tmr.param = UINT_TO_PTR(inx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1590 | p_cb->acp_sig_tmr.p_cback = (TIMER_CBACK *)&bta_av_acp_sig_timer_cback; |
| 1591 | bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL); |
| 1592 | } |
| 1593 | else |
| 1594 | { |
| 1595 | /* SNK did not start signalling, resume signalling process. */ |
| 1596 | bta_av_discover_req (p_scb, NULL); |
| 1597 | } |
| 1598 | } |
| 1599 | else if (bta_av_is_scb_incoming(p_scb)) |
| 1600 | { |
| 1601 | /* Stay in incoming state if SNK does not start signalling */ |
| 1602 | |
| 1603 | /* API open was called right after SNK opened L2C connection. */ |
| 1604 | if (p_scb->coll_mask & BTA_AV_COLL_API_CALLED) |
| 1605 | { |
| 1606 | p_scb->coll_mask &= ~BTA_AV_COLL_API_CALLED; |
| 1607 | |
| 1608 | /* BTA_AV_API_OPEN_EVT */ |
| 1609 | if ((p_buf = (tBTA_AV_API_OPEN *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN))) != NULL) |
| 1610 | { |
| 1611 | memcpy(p_buf, &(p_scb->open_api), sizeof(tBTA_AV_API_OPEN)); |
| 1612 | bta_sys_sendmsg(p_buf); |
| 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | /******************************************************************************* |
| 1621 | ** |
| 1622 | ** Function bta_av_check_peer_features |
| 1623 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1624 | ** Description check supported features on the peer device from the SDP record |
| 1625 | ** and return the feature mask |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1626 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1627 | ** Returns tBTA_AV_FEAT peer device feature mask |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1628 | ** |
| 1629 | *******************************************************************************/ |
| 1630 | tBTA_AV_FEAT bta_av_check_peer_features (UINT16 service_uuid) |
| 1631 | { |
| 1632 | tBTA_AV_FEAT peer_features = 0; |
| 1633 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1634 | tSDP_DISC_REC *p_rec = NULL; |
| 1635 | tSDP_DISC_ATTR *p_attr; |
| 1636 | UINT16 peer_rc_version=0; |
| 1637 | UINT16 categories = 0; |
| 1638 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1639 | APPL_TRACE_DEBUG("bta_av_check_peer_features service_uuid:x%x", service_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1640 | /* loop through all records we found */ |
| 1641 | while (TRUE) |
| 1642 | { |
| 1643 | /* get next record; if none found, we're done */ |
| 1644 | if ((p_rec = SDP_FindServiceInDb(p_cb->p_disc_db, service_uuid, p_rec)) == NULL) |
| 1645 | { |
| 1646 | break; |
| 1647 | } |
| 1648 | |
| 1649 | if (( SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_CLASS_ID_LIST)) != NULL) |
| 1650 | { |
| 1651 | /* find peer features */ |
| 1652 | if (SDP_FindServiceInDb(p_cb->p_disc_db, UUID_SERVCLASS_AV_REMOTE_CONTROL, NULL)) |
| 1653 | { |
| 1654 | peer_features |= BTA_AV_FEAT_RCCT; |
| 1655 | } |
| 1656 | if (SDP_FindServiceInDb(p_cb->p_disc_db, UUID_SERVCLASS_AV_REM_CTRL_TARGET, NULL)) |
| 1657 | { |
| 1658 | peer_features |= BTA_AV_FEAT_RCTG; |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | if (( SDP_FindAttributeInRec(p_rec, ATTR_ID_BT_PROFILE_DESC_LIST)) != NULL) |
| 1663 | { |
| 1664 | /* get profile version (if failure, version parameter is not updated) */ |
| 1665 | SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_AV_REMOTE_CONTROL, &peer_rc_version); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1666 | APPL_TRACE_DEBUG("peer_rc_version 0x%x", peer_rc_version); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1667 | |
| 1668 | if (peer_rc_version >= AVRC_REV_1_3) |
| 1669 | peer_features |= (BTA_AV_FEAT_VENDOR | BTA_AV_FEAT_METADATA); |
| 1670 | |
| 1671 | if (peer_rc_version >= AVRC_REV_1_4) |
| 1672 | { |
| 1673 | peer_features |= (BTA_AV_FEAT_ADV_CTRL); |
| 1674 | /* get supported categories */ |
| 1675 | if ((p_attr = SDP_FindAttributeInRec(p_rec, |
| 1676 | ATTR_ID_SUPPORTED_FEATURES)) != NULL) |
| 1677 | { |
| 1678 | categories = p_attr->attr_value.v.u16; |
| 1679 | if (categories & AVRC_SUPF_CT_BROWSE) |
| 1680 | peer_features |= (BTA_AV_FEAT_BROWSE); |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1685 | APPL_TRACE_DEBUG("peer_features:x%x", peer_features); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1686 | return peer_features; |
| 1687 | } |
| 1688 | |
| 1689 | /******************************************************************************* |
| 1690 | ** |
| 1691 | ** Function bta_av_rc_disc_done |
| 1692 | ** |
| 1693 | ** Description Handle AVRCP service discovery results. If matching |
| 1694 | ** service found, open AVRCP connection. |
| 1695 | ** |
| 1696 | ** Returns void |
| 1697 | ** |
| 1698 | *******************************************************************************/ |
| 1699 | void bta_av_rc_disc_done(tBTA_AV_DATA *p_data) |
| 1700 | { |
| 1701 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1702 | tBTA_AV_SCB *p_scb = NULL; |
| 1703 | tBTA_AV_LCB *p_lcb; |
| 1704 | tBTA_AV_RC_OPEN rc_open; |
| 1705 | tBTA_AV_RC_FEAT rc_feat; |
| 1706 | UINT8 rc_handle; |
| 1707 | tBTA_AV_FEAT peer_features; /* peer features mask */ |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1708 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1709 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1710 | APPL_TRACE_DEBUG("bta_av_rc_disc_done disc:x%x", p_cb->disc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1711 | if (!p_cb->disc) |
| 1712 | { |
| 1713 | return; |
| 1714 | } |
| 1715 | |
| 1716 | if ((p_cb->disc & BTA_AV_CHNL_MSK) == BTA_AV_CHNL_MSK) |
| 1717 | { |
| 1718 | /* this is the rc handle/index to tBTA_AV_RCB */ |
| 1719 | rc_handle = p_cb->disc & (~BTA_AV_CHNL_MSK); |
| 1720 | } |
| 1721 | else |
| 1722 | { |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1723 | /* Validate array index*/ |
| 1724 | if (((p_cb->disc & BTA_AV_HNDL_MSK) - 1) < BTA_AV_NUM_STRS) |
| 1725 | { |
| 1726 | p_scb = p_cb->p_scb[(p_cb->disc & BTA_AV_HNDL_MSK) - 1]; |
| 1727 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1728 | if (p_scb) |
| 1729 | rc_handle = p_scb->rc_handle; |
| 1730 | else |
| 1731 | { |
| 1732 | p_cb->disc = 0; |
| 1733 | return; |
| 1734 | } |
| 1735 | } |
| 1736 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1737 | APPL_TRACE_DEBUG("rc_handle %d", rc_handle); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1738 | /* check peer version and whether support CT and TG role */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1739 | peer_features = bta_av_check_peer_features (UUID_SERVCLASS_AV_REMOTE_CONTROL); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 1740 | if ((p_cb->features & BTA_AV_FEAT_ADV_CTRL) && ((peer_features&BTA_AV_FEAT_ADV_CTRL) == 0)) |
| 1741 | { |
| 1742 | /* if we support advance control and peer does not, check their support on TG role |
| 1743 | * some implementation uses 1.3 on CT ans 1.4 on TG */ |
| 1744 | peer_features |= bta_av_check_peer_features (UUID_SERVCLASS_AV_REM_CTRL_TARGET); |
| 1745 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1746 | |
| 1747 | p_cb->disc = 0; |
| 1748 | utl_freebuf((void **) &p_cb->p_disc_db); |
| 1749 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1750 | APPL_TRACE_DEBUG("peer_features 0x%x, features 0x%x", peer_features, p_cb->features); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1751 | |
| 1752 | /* if we have no rc connection */ |
| 1753 | if (rc_handle == BTA_AV_RC_HANDLE_NONE) |
| 1754 | { |
| 1755 | if (p_scb) |
| 1756 | { |
| 1757 | /* if peer remote control service matches ours and USE_RC is TRUE */ |
| 1758 | if ((((p_cb->features & BTA_AV_FEAT_RCCT) && (peer_features & BTA_AV_FEAT_RCTG)) || |
| 1759 | ((p_cb->features & BTA_AV_FEAT_RCTG) && (peer_features & BTA_AV_FEAT_RCCT))) ) |
| 1760 | { |
| 1761 | p_lcb = bta_av_find_lcb(p_scb->peer_addr, BTA_AV_LCB_FIND); |
| 1762 | if(p_lcb) |
| 1763 | { |
| 1764 | rc_handle = bta_av_rc_create(p_cb, AVCT_INT, (UINT8)(p_scb->hdi + 1), p_lcb->lidx); |
| 1765 | p_cb->rcb[rc_handle].peer_features = peer_features; |
| 1766 | } |
| 1767 | #if (BT_USE_TRACES == TRUE || BT_TRACE_APPL == TRUE) |
| 1768 | else |
| 1769 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1770 | APPL_TRACE_ERROR("can not find LCB!!"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1771 | } |
| 1772 | #endif |
| 1773 | } |
| 1774 | else if(p_scb->use_rc) |
| 1775 | { |
| 1776 | /* can not find AVRC on peer device. report failure */ |
| 1777 | p_scb->use_rc = FALSE; |
| 1778 | bdcpy(rc_open.peer_addr, p_scb->peer_addr); |
| 1779 | rc_open.peer_features = 0; |
| 1780 | rc_open.status = BTA_AV_FAIL_SDP; |
| 1781 | (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, (tBTA_AV *) &rc_open); |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | else |
| 1786 | { |
| 1787 | p_cb->rcb[rc_handle].peer_features = peer_features; |
| 1788 | rc_feat.rc_handle = rc_handle; |
| 1789 | rc_feat.peer_features = peer_features; |
| 1790 | (*p_cb->p_cback)(BTA_AV_RC_FEAT_EVT, (tBTA_AV *) &rc_feat); |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | /******************************************************************************* |
| 1795 | ** |
| 1796 | ** Function bta_av_rc_closed |
| 1797 | ** |
| 1798 | ** Description Set AVRCP state to closed. |
| 1799 | ** |
| 1800 | ** Returns void |
| 1801 | ** |
| 1802 | *******************************************************************************/ |
| 1803 | void bta_av_rc_closed(tBTA_AV_DATA *p_data) |
| 1804 | { |
| 1805 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1806 | tBTA_AV_RC_CLOSE rc_close; |
| 1807 | tBTA_AV_RC_CONN_CHG *p_msg = (tBTA_AV_RC_CONN_CHG *)p_data; |
| 1808 | tBTA_AV_RCB *p_rcb; |
| 1809 | tBTA_AV_SCB *p_scb; |
| 1810 | int i; |
| 1811 | BOOLEAN conn = FALSE; |
| 1812 | tBTA_AV_LCB *p_lcb; |
| 1813 | |
| 1814 | rc_close.rc_handle = BTA_AV_RC_HANDLE_NONE; |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1815 | p_scb = NULL; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1816 | APPL_TRACE_DEBUG("bta_av_rc_closed rc_handle:%d", p_msg->handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1817 | for(i=0; i<BTA_AV_NUM_RCB; i++) |
| 1818 | { |
| 1819 | p_rcb = &p_cb->rcb[i]; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1820 | APPL_TRACE_DEBUG("bta_av_rc_closed rcb[%d] rc_handle:%d, status=0x%x", i, p_rcb->handle, p_rcb->status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1821 | if(p_rcb->handle == p_msg->handle) |
| 1822 | { |
| 1823 | rc_close.rc_handle = i; |
| 1824 | p_rcb->status &= ~BTA_AV_RC_CONN_MASK; |
| 1825 | p_rcb->peer_features = 0; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1826 | APPL_TRACE_DEBUG(" shdl:%d, lidx:%d", p_rcb->shdl, p_rcb->lidx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1827 | if(p_rcb->shdl) |
| 1828 | { |
Mallikarjuna GB | 4633fb8 | 2014-11-07 16:52:25 +0530 | [diff] [blame] | 1829 | if ((p_rcb->shdl - 1) < BTA_AV_NUM_STRS) |
| 1830 | { |
| 1831 | p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1]; |
| 1832 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1833 | if(p_scb) |
| 1834 | { |
| 1835 | bdcpy(rc_close.peer_addr, p_scb->peer_addr); |
| 1836 | if(p_scb->rc_handle == p_rcb->handle) |
| 1837 | p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1838 | APPL_TRACE_DEBUG("shdl:%d, srch:%d", p_rcb->shdl, p_scb->rc_handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1839 | } |
| 1840 | p_rcb->shdl = 0; |
| 1841 | } |
| 1842 | else if(p_rcb->lidx == (BTA_AV_NUM_LINKS + 1) ) |
| 1843 | { |
| 1844 | /* if the RCB uses the extra LCB, use the addr for event and clean it */ |
| 1845 | p_lcb = &p_cb->lcb[BTA_AV_NUM_LINKS]; |
| 1846 | bdcpy(rc_close.peer_addr, p_msg->peer_addr); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1847 | APPL_TRACE_DEBUG("rc_only closed bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1848 | p_msg->peer_addr[0], p_msg->peer_addr[1], |
| 1849 | p_msg->peer_addr[2], p_msg->peer_addr[3], |
| 1850 | p_msg->peer_addr[4], p_msg->peer_addr[5]); |
| 1851 | p_lcb->conn_msk = 0; |
| 1852 | p_lcb->lidx = 0; |
| 1853 | } |
| 1854 | p_rcb->lidx = 0; |
| 1855 | |
| 1856 | if((p_rcb->status & BTA_AV_RC_ROLE_MASK) == BTA_AV_RC_ROLE_INT) |
| 1857 | { |
| 1858 | /* AVCT CCB is deallocated */ |
| 1859 | p_rcb->handle = BTA_AV_RC_HANDLE_NONE; |
| 1860 | p_rcb->status = 0; |
| 1861 | } |
| 1862 | else |
| 1863 | { |
| 1864 | /* AVCT CCB is still there. dealloc */ |
| 1865 | bta_av_del_rc(p_rcb); |
| 1866 | |
| 1867 | /* if the AVRCP is no longer listening, create the listening channel */ |
| 1868 | if (bta_av_cb.rc_acp_handle == BTA_AV_RC_HANDLE_NONE && bta_av_cb.features & BTA_AV_FEAT_RCTG) |
| 1869 | bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1); |
| 1870 | } |
| 1871 | } |
| 1872 | else if((p_rcb->handle != BTA_AV_RC_HANDLE_NONE) && (p_rcb->status & BTA_AV_RC_CONN_MASK)) |
| 1873 | { |
| 1874 | /* at least one channel is still connected */ |
| 1875 | conn = TRUE; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | if(!conn) |
| 1880 | { |
| 1881 | /* no AVRC channels are connected, go back to INIT state */ |
| 1882 | bta_av_sm_execute(p_cb, BTA_AV_AVRC_NONE_EVT, NULL); |
| 1883 | } |
| 1884 | |
| 1885 | if (rc_close.rc_handle == BTA_AV_RC_HANDLE_NONE) |
| 1886 | { |
| 1887 | rc_close.rc_handle = p_msg->handle; |
| 1888 | bdcpy(rc_close.peer_addr, p_msg->peer_addr); |
| 1889 | } |
| 1890 | (*p_cb->p_cback)(BTA_AV_RC_CLOSE_EVT, (tBTA_AV *) &rc_close); |
| 1891 | } |
| 1892 | |
| 1893 | /******************************************************************************* |
| 1894 | ** |
| 1895 | ** Function bta_av_rc_disc |
| 1896 | ** |
| 1897 | ** Description start AVRC SDP discovery. |
| 1898 | ** |
| 1899 | ** Returns void |
| 1900 | ** |
| 1901 | *******************************************************************************/ |
| 1902 | void bta_av_rc_disc(UINT8 disc) |
| 1903 | { |
| 1904 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1905 | tAVRC_SDP_DB_PARAMS db_params; |
| 1906 | UINT16 attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, |
| 1907 | ATTR_ID_BT_PROFILE_DESC_LIST, |
| 1908 | ATTR_ID_SUPPORTED_FEATURES}; |
| 1909 | UINT8 hdi; |
| 1910 | tBTA_AV_SCB *p_scb; |
| 1911 | UINT8 *p_addr = NULL; |
| 1912 | UINT8 rc_handle; |
| 1913 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1914 | APPL_TRACE_DEBUG("bta_av_rc_disc 0x%x, %d", disc, bta_av_cb.disc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1915 | if ((bta_av_cb.disc != 0) || (disc == 0)) |
| 1916 | return; |
| 1917 | |
| 1918 | if ((disc & BTA_AV_CHNL_MSK) == BTA_AV_CHNL_MSK) |
| 1919 | { |
| 1920 | /* this is the rc handle/index to tBTA_AV_RCB */ |
| 1921 | rc_handle = disc & (~BTA_AV_CHNL_MSK); |
| 1922 | if (p_cb->rcb[rc_handle].lidx) |
| 1923 | { |
| 1924 | p_addr = p_cb->lcb[p_cb->rcb[rc_handle].lidx-1].addr; |
| 1925 | } |
| 1926 | } |
| 1927 | else |
| 1928 | { |
| 1929 | hdi = (disc & BTA_AV_HNDL_MSK) - 1; |
| 1930 | p_scb = p_cb->p_scb[hdi]; |
| 1931 | |
| 1932 | if (p_scb) |
| 1933 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1934 | APPL_TRACE_DEBUG("rc_handle %d", p_scb->rc_handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1935 | p_addr = p_scb->peer_addr; |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | if (p_addr) |
| 1940 | { |
| 1941 | /* allocate discovery database */ |
| 1942 | if (p_cb->p_disc_db == NULL) |
| 1943 | { |
| 1944 | p_cb->p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(BTA_AV_DISC_BUF_SIZE); |
| 1945 | } |
| 1946 | |
| 1947 | if (p_cb->p_disc_db) |
| 1948 | { |
| 1949 | /* set up parameters */ |
| 1950 | db_params.db_len = BTA_AV_DISC_BUF_SIZE; |
| 1951 | db_params.num_attr = 3; |
| 1952 | db_params.p_db = p_cb->p_disc_db; |
| 1953 | db_params.p_attrs = attr_list; |
| 1954 | |
| 1955 | /* searching for UUID_SERVCLASS_AV_REMOTE_CONTROL gets both TG and CT */ |
| 1956 | if (AVRC_FindService(UUID_SERVCLASS_AV_REMOTE_CONTROL, p_addr, &db_params, |
| 1957 | bta_av_avrc_sdp_cback) == AVRC_SUCCESS) |
| 1958 | { |
| 1959 | p_cb->disc = disc; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1960 | APPL_TRACE_DEBUG("disc %d", p_cb->disc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | /******************************************************************************* |
| 1967 | ** |
| 1968 | ** Function bta_av_dereg_comp |
| 1969 | ** |
| 1970 | ** Description deregister complete. free the stream control block. |
| 1971 | ** |
| 1972 | ** Returns void |
| 1973 | ** |
| 1974 | *******************************************************************************/ |
| 1975 | void bta_av_dereg_comp(tBTA_AV_DATA *p_data) |
| 1976 | { |
| 1977 | tBTA_AV_CB *p_cb = &bta_av_cb; |
| 1978 | tBTA_AV_SCB *p_scb; |
| 1979 | tBTA_UTL_COD cod; |
| 1980 | UINT8 mask; |
| 1981 | BT_HDR *p_buf; |
| 1982 | |
| 1983 | /* find the stream control block */ |
| 1984 | p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific); |
| 1985 | |
| 1986 | if(p_scb) |
| 1987 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1988 | APPL_TRACE_DEBUG("deregistered %d(h%d)", p_scb->chnl, p_scb->hndl); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1989 | mask = BTA_AV_HNDL_TO_MSK(p_scb->hdi); |
| 1990 | if(p_scb->chnl == BTA_AV_CHNL_AUDIO) |
| 1991 | { |
| 1992 | p_cb->reg_audio &= ~mask; |
| 1993 | if ((p_cb->conn_audio & mask) && bta_av_cb.audio_open_cnt) |
| 1994 | { |
| 1995 | /* this channel is still marked as open. decrease the count */ |
| 1996 | bta_av_cb.audio_open_cnt--; |
| 1997 | } |
| 1998 | p_cb->conn_audio &= ~mask; |
| 1999 | |
Chris Manton | d44d640 | 2015-03-06 14:41:32 -0800 | [diff] [blame] | 2000 | if (p_scb->q_tag == BTA_AV_Q_TAG_STREAM && p_scb->a2d_list) { |
| 2001 | /* make sure no buffers are in a2d_list */ |
| 2002 | while (!list_is_empty(p_scb->a2d_list)) { |
| 2003 | p_buf = (BT_HDR*)list_front(p_scb->a2d_list); |
| 2004 | list_remove(p_scb->a2d_list, p_buf); |
Chris Manton | 725278f | 2014-08-05 13:24:41 -0700 | [diff] [blame] | 2005 | GKI_freebuf(p_buf); |
| 2006 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | /* remove the A2DP SDP record, if no more audio stream is left */ |
| 2010 | if(!p_cb->reg_audio) |
| 2011 | { |
| 2012 | #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) |
| 2013 | bta_ar_dereg_avrc (UUID_SERVCLASS_AV_REMOTE_CONTROL, BTA_ID_AV); |
| 2014 | #endif |
| 2015 | bta_av_del_sdp_rec(&p_cb->sdp_a2d_handle); |
| 2016 | bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SOURCE); |
Hemant Gupta | f7dd9f5 | 2013-10-24 15:37:17 +0530 | [diff] [blame] | 2017 | |
lungtsai_lin | 6718c6d | 2014-07-02 20:39:02 +0800 | [diff] [blame] | 2018 | #if (BTA_AV_SINK_INCLUDED == TRUE) |
Hemant Gupta | f7dd9f5 | 2013-10-24 15:37:17 +0530 | [diff] [blame] | 2019 | bta_av_del_sdp_rec(&p_cb->sdp_a2d_snk_handle); |
| 2020 | bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SINK); |
| 2021 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | else |
| 2025 | { |
| 2026 | p_cb->reg_video &= ~mask; |
| 2027 | /* make sure that this channel is not connected */ |
| 2028 | p_cb->conn_video &= ~mask; |
| 2029 | /* remove the VDP SDP record, (only one video stream at most) */ |
| 2030 | bta_av_del_sdp_rec(&p_cb->sdp_vdp_handle); |
| 2031 | bta_sys_remove_uuid(UUID_SERVCLASS_VIDEO_SOURCE); |
| 2032 | } |
| 2033 | |
| 2034 | /* make sure that the timer is not active */ |
| 2035 | bta_sys_stop_timer(&p_scb->timer); |
| 2036 | utl_freebuf((void **)&p_cb->p_scb[p_scb->hdi]); |
| 2037 | } |
| 2038 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2039 | APPL_TRACE_DEBUG("audio 0x%x, video: 0x%x, disable:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2040 | p_cb->reg_audio, p_cb->reg_video, p_cb->disabling); |
| 2041 | /* if no stream control block is active */ |
| 2042 | if((p_cb->reg_audio + p_cb->reg_video) == 0) |
| 2043 | { |
| 2044 | #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) |
| 2045 | /* deregister from AVDT */ |
| 2046 | bta_ar_dereg_avdt(BTA_ID_AV); |
| 2047 | |
| 2048 | /* deregister from AVCT */ |
| 2049 | bta_ar_dereg_avrc (UUID_SERVCLASS_AV_REM_CTRL_TARGET, BTA_ID_AV); |
| 2050 | bta_ar_dereg_avct(BTA_ID_AV); |
| 2051 | #endif |
| 2052 | |
| 2053 | if(p_cb->disabling) |
| 2054 | { |
| 2055 | p_cb->disabling = FALSE; |
| 2056 | bta_av_cb.features = 0; |
| 2057 | } |
| 2058 | |
| 2059 | /* Clear the Capturing service class bit */ |
| 2060 | cod.service = BTM_COD_SERVICE_CAPTURING; |
| 2061 | utl_set_device_class(&cod, BTA_UTL_CLR_COD_SERVICE_CLASS); |
| 2062 | } |
| 2063 | } |
| 2064 | #endif /* BTA_AV_INCLUDED */ |