15738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************
25738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
35738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Copyright (C) 2004-2012 Broadcom Corporation
45738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
55738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Licensed under the Apache License, Version 2.0 (the "License");
65738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  you may not use this file except in compliance with the License.
75738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  You may obtain a copy of the License at:
85738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
95738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  http://www.apache.org/licenses/LICENSE-2.0
105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  See the License for the specific language governing permissions and
155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  limitations under the License.
165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/
185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************
205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  This file contains action functions for advanced audio/video main state
225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  machine.
235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/
255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bt_target.h"
275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include <string.h>
305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_av_api.h"
315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_av_int.h"
325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "avdt_api.h"
335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bd.h"
345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "utl.h"
355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "l2c_api.h"
365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_ar_api.h"
385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*****************************************************************************
415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**  Constants
425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*****************************************************************************/
435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* the timer in milliseconds to wait for open req after setconfig for incoming connections */
445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#ifndef BTA_AV_SIG_TIME_VAL
455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_AV_SIG_TIME_VAL 8000
465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* In millisec to wait for signalling from SNK when it is initiated from SNK.   */
495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* If not, we will start signalling from SRC.                                   */
505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#ifndef BTA_AV_ACP_SIG_TIME_VAL
515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_AV_ACP_SIG_TIME_VAL 2000
525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle);
555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_get_rcb_by_shdl
595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      find the RCB associated with the given SCB handle.
615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          tBTA_AV_RCB
635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttBTA_AV_RCB * bta_av_get_rcb_by_shdl(UINT8 shdl)
665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB *p_rcb = NULL;
685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int         i;
695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for (i=0; i<BTA_AV_NUM_RCB; i++)
715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (bta_av_cb.rcb[i].shdl == shdl && bta_av_cb.rcb[i].handle != BTA_AV_RC_HANDLE_NONE)
735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb = &bta_av_cb.rcb[i];
755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return p_rcb;
795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_AV_STS_NO_RSP       0xFF    /* a number not used by tAVRC_STS */
815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_del_rc
855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      delete the given AVRC handle.
875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_del_rc(tBTA_AV_RCB *p_rcb)
925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB  *p_scb;
945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8        rc_handle;      /* connected AVRCP handle */
955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(p_rcb->handle != BTA_AV_RC_HANDLE_NONE)
975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_rcb->shdl)
995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1];
1015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_scb)
1025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
103e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG("bta_av_del_rc shdl:%d, srch:%d rc_handle:%d", p_rcb->shdl,
1045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                  p_scb->rc_handle, p_rcb->handle);
1055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(p_scb->rc_handle == p_rcb->handle)
1065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE;
1075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* just in case the RC timer is active
1085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(bta_av_cb.features & BTA_AV_FEAT_RCCT && p_scb->chnl == BTA_AV_CHNL_AUDIO) */
1095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_sys_stop_timer(&p_scb->timer);
1105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
1115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
1125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
113e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_EVENT("bta_av_del_rc  handle: %d status=0x%x, rc_acp_handle:%d, idx:%d",
1145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->handle, p_rcb->status, bta_av_cb.rc_acp_handle, bta_av_cb.rc_acp_idx);
1155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_handle = p_rcb->handle;
1165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(!(p_rcb->status & BTA_AV_RC_CONN_MASK) ||
1175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            ((p_rcb->status & BTA_AV_RC_ROLE_MASK) == BTA_AV_RC_ROLE_INT) )
1185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->status = 0;
1205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->handle = BTA_AV_RC_HANDLE_NONE;
1215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->shdl = 0;
1225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->lidx = 0;
1235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
1245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* else ACP && connected. do not clear the handle yet */
1255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        AVRC_Close(rc_handle);
1265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (rc_handle == bta_av_cb.rc_acp_handle)
1275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_cb.rc_acp_handle = BTA_AV_RC_HANDLE_NONE;
128e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_EVENT("end del_rc handle: %d status=0x%x, rc_acp_handle:%d, lidx:%d",
1295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->handle, p_rcb->status, bta_av_cb.rc_acp_handle, p_rcb->lidx);
1305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
1355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_close_all_rc
1375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      close the all AVRC handle.
1395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
1415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
1435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_close_all_rc(tBTA_AV_CB *p_cb)
1445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
1455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int i;
1465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(i=0; i<BTA_AV_NUM_RCB; i++)
1485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_cb->disabling == TRUE) || (bta_av_cb.rcb[i].shdl != 0))
1505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_del_rc(&bta_av_cb.rcb[i]);
1515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
1555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_del_sdp_rec
1575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      delete the given SDP record handle.
1595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
1615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
1635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_del_sdp_rec(UINT32 *p_sdp_handle)
1645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
1655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(*p_sdp_handle != 0)
1665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        SDP_DeleteRecord(*p_sdp_handle);
1685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        *p_sdp_handle = 0;
1695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_avrc_sdp_cback
1755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      AVRCP service discovery callback.
1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
1795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
1815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_avrc_sdp_cback(UINT16 status)
1825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
1835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BT_HDR *p_msg;
1845cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(status);
1855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
1875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_msg->event = BTA_AV_SDP_AVRC_DISC_EVT;
1895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_sys_sendmsg(p_msg);
1905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
1945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_ctrl_cback
1965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      AVRCP control callback.
1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_rc_ctrl_cback(UINT8 handle, UINT8 event, UINT16 result, BD_ADDR peer_addr)
2035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
2045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_CONN_CHG *p_msg;
2055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 msg_event = 0;
2065cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(result);
2075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if (defined(BTA_AV_MIN_DEBUG_TRACES) && BTA_AV_MIN_DEBUG_TRACES == TRUE)
209e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_EVENT("rc_ctrl handle: %d event=0x%x", handle, event);
2105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#else
211e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_EVENT("bta_av_rc_ctrl_cback handle: %d event=0x%x", handle, event);
2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (event == AVRC_OPEN_IND_EVT)
2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* save handle of opened connection
2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_av_cb.rc_handle = handle;*/
2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        msg_event = BTA_AV_AVRC_OPEN_EVT;
2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (event == AVRC_CLOSE_IND_EVT)
2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        msg_event = BTA_AV_AVRC_CLOSE_EVT;
2235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (msg_event)
2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_msg = (tBTA_AV_RC_CONN_CHG *) GKI_getbuf(sizeof(tBTA_AV_RC_CONN_CHG))) != NULL)
2285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_msg->hdr.event = msg_event;
2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_msg->handle    = handle;
2315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(peer_addr)
2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bdcpy(p_msg->peer_addr, peer_addr);
2335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_sys_sendmsg(p_msg);
2345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
2355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
2375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_msg_cback
2415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      AVRCP message callback.
2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_rc_msg_cback(UINT8 handle, UINT8 label, UINT8 opcode, tAVRC_MSG *p_msg)
2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_MSG  *p_buf;
2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8           *p_data = NULL;
2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8           **p_p_data = NULL;
2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16          data_len = 0;
2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if (defined(BTA_AV_MIN_DEBUG_TRACES) && BTA_AV_MIN_DEBUG_TRACES == TRUE)
255e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_ERROR("rc_msg handle: %d opcode=0x%x", handle, opcode);
2565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#else
257e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_EVENT("bta_av_rc_msg_cback handle: %d opcode=0x%x", handle, opcode);
2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* determine size of buffer we need */
2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (opcode == AVRC_OP_VENDOR && p_msg->vendor.p_vendor_data != NULL)
2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_data = p_msg->vendor.p_vendor_data;
2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_p_data = &p_msg->vendor.p_vendor_data;
2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        data_len = (UINT16) p_msg->vendor.vendor_len;
2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (opcode == AVRC_OP_PASS_THRU && p_msg->pass.p_pass_data != NULL)
2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_data = p_msg->pass.p_pass_data;
2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_p_data = &p_msg->pass.p_pass_data;
2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        data_len = (UINT16) p_msg->pass.pass_len;
2715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_buf = (tBTA_AV_RC_MSG *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_RC_MSG) + data_len))) != NULL)
2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->hdr.event = BTA_AV_AVRC_MSG_EVT;
2765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->handle = handle;
2775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->label = label;
2785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->opcode = opcode;
2795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memcpy(&p_buf->msg, p_msg, sizeof(tAVRC_MSG));
2805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_data != NULL)
2815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
2825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memcpy((UINT8 *)(p_buf + 1), p_data, data_len);
2835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            *p_p_data = (UINT8 *)(p_buf + 1);
2845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
2855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_sys_sendmsg(p_buf);
2865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
2885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
2905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_create
2925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      alloc RCB and call AVRC_Open
2945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          the created rc handle
2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8 bta_av_rc_create(tBTA_AV_CB *p_cb, UINT8 role, UINT8 shdl, UINT8 lidx)
2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tAVRC_CONN_CB ccb;
3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BD_ADDR_PTR   bda = (BD_ADDR_PTR)bd_addr_any;
3025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8         status = BTA_AV_RC_ROLE_ACP;
3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB  *p_scb = p_cb->p_scb[shdl - 1];
3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int i;
3055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   rc_handle;
3065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB *p_rcb;
3075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(role == AVCT_INT)
3095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bda = p_scb->peer_addr;
3115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        status = BTA_AV_RC_ROLE_INT;
3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_rcb = bta_av_get_rcb_by_shdl(shdl)) != NULL )
3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
317e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_ERROR("bta_av_rc_create ACP handle exist for shdl:%d", shdl);
3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return p_rcb->handle;
3195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ccb.p_ctrl_cback = bta_av_rc_ctrl_cback;
3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ccb.p_msg_cback = bta_av_rc_msg_cback;
3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ccb.company_id = p_bta_av_cfg->company_id;
3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ccb.conn = role;
3265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* note: BTA_AV_FEAT_RCTG = AVRC_CT_TARGET, BTA_AV_FEAT_RCCT = AVRC_CT_CONTROL */
3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ccb.control = p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_RCCT | AVRC_CT_PASSIVE);
3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (AVRC_Open(&rc_handle, &ccb, bda) != AVRC_SUCCESS)
3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return BTA_AV_RC_HANDLE_NONE;
3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    i = rc_handle;
3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rcb = &p_cb->rcb[i];
3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE)
3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
338e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_ERROR("bta_av_rc_create found duplicated handle:%d", rc_handle);
3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rcb->handle = rc_handle;
3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rcb->status = status;
3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rcb->shdl = shdl;
3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rcb->lidx = lidx;
3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rcb->peer_features = 0;
3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(lidx == (BTA_AV_NUM_LINKS + 1))
3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* this LIDX is reserved for the AVRCP ACP connection */
3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_cb->rc_acp_handle = p_rcb->handle;
3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_cb->rc_acp_idx = (i + 1);
351e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("rc_acp_handle:%d idx:%d", p_cb->rc_acp_handle, p_cb->rc_acp_idx);
3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
353e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("create %d, role: %d, shdl:%d, rc_handle:%d, lidx:%d, status:0x%x",
3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        i, role, shdl, p_rcb->handle, lidx, p_rcb->status);
3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return rc_handle;
3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_valid_group_navi_msg
3625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Check if it is Group Navigation Msg for Metadata
3645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          BTA_AV_RSP_ACCEPT or BTA_AV_RSP_NOT_IMPL.
3665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
368ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data, BOOLEAN is_inquiry)
3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CODE ret=BTA_AV_RSP_NOT_IMPL;
3715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8 *p_ptr = p_data;
3725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 u16;
3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT32 u32;
3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_bta_av_cfg->avrc_group && len == BTA_GROUP_NAVI_MSG_OP_DATA_LEN)
3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        BTA_AV_BE_STREAM_TO_CO_ID(u32, p_ptr);
3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        BE_STREAM_TO_UINT16(u16, p_ptr);
3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (u32 == AVRC_CO_METADATA)
3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
382ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (is_inquiry)
383ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
384ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                if (u16 <= AVRC_PDU_PREV_GROUP)
385ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    ret = BTA_AV_RSP_IMPL_STBL;
386ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
388ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
389ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                if (u16 <= AVRC_PDU_PREV_GROUP)
390ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    ret = BTA_AV_RSP_ACCEPT;
391ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                else
392ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    ret = BTA_AV_RSP_REJ;
393ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
3945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return ret;
3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_op_supported
4035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Check if remote control operation is supported.
4055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          BTA_AV_RSP_ACCEPT of supported, BTA_AV_RSP_NOT_IMPL if not.
4075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
409ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic tBTA_AV_CODE bta_av_op_supported(tBTA_AV_RC rc_id, BOOLEAN is_inquiry)
4105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
4115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CODE ret_code = BTA_AV_RSP_NOT_IMPL;
4125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_bta_av_rc_id)
4145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
415ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (is_inquiry)
4165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
417ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F)))
418ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
419ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                ret_code = BTA_AV_RSP_IMPL_STBL;
420ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
4215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
422ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        else
4235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
424ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F)))
425ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
426ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                ret_code = BTA_AV_RSP_ACCEPT;
427ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
428ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            else if ((p_bta_av_cfg->rc_pass_rsp == BTA_AV_RSP_INTERIM) && p_bta_av_rc_id_ac)
4295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
430ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                if (p_bta_av_rc_id_ac[rc_id >> 4] & (1 << (rc_id & 0x0F)))
431ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                {
432ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    ret_code = BTA_AV_RSP_INTERIM;
433ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                }
4345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
4355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
436ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
4375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return ret_code;
4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_find_lcb
4445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Given BD_addr, find the associated LCB.
4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          NULL, if not found.
4485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttBTA_AV_LCB * bta_av_find_lcb(BD_ADDR addr, UINT8 op)
4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int     xx;
4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   mask;
4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb = NULL;
4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(xx=0; xx<BTA_AV_NUM_LINKS; xx++)
4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
4595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        mask = 1 << xx; /* the used mask for this lcb */
4605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if((mask & p_cb->conn_lcb) && 0 ==( bdcmp(p_cb->lcb[xx].addr, addr)))
4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_lcb = &p_cb->lcb[xx];
4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(op == BTA_AV_LCB_FREE)
4645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
4655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_cb->conn_lcb &= ~mask; /* clear the connect mask */
466e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb);
4675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
4685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
4695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
4705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
4715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return p_lcb;
4725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_opened
4775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Set AVRCP state to opened.
4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_opened(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
4845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_OPEN rc_open;
4865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB     *p_scb;
4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int         i;
4885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       shdl = 0;
4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb;
4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB *p_rcb;
4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       tmp;
4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       disc = 0;
4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* find the SCB & stop the timer */
4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(i=0; i<BTA_AV_NUM_STRS; i++)
4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_scb = p_cb->p_scb[i];
4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_scb && bdcmp(p_scb->peer_addr, p_data->rc_conn_chg.peer_addr) == 0)
4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_scb->rc_handle = p_data->rc_conn_chg.handle;
501e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("bta_av_rc_opened shdl:%d, srch %d", i + 1, p_scb->rc_handle);
5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            shdl = i+1;
503e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_ERROR("use_rc:%d", p_scb->use_rc);
5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_sys_stop_timer(&p_scb->timer);
5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            disc = p_scb->hndl;
5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    i = p_data->rc_conn_chg.handle;
5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_cb->rcb[i].handle == BTA_AV_RC_HANDLE_NONE)
5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
513e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_ERROR("not a valid handle:%d any more", i);
5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
5155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_cb->rcb[i].lidx == (BTA_AV_NUM_LINKS + 1) && shdl != 0)
5195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* rc is opened on the RC only ACP channel, but is for a specific
5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project         * SCB -> need to switch RCBs */
5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_rcb = bta_av_get_rcb_by_shdl(shdl);
5235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_rcb)
5245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->shdl = p_cb->rcb[i].shdl;
5265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            tmp         = p_rcb->lidx;
5275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->lidx = p_cb->rcb[i].lidx;
5285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->rcb[i].lidx = tmp;
5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->rc_acp_handle = p_rcb->handle;
5305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->rc_acp_idx = (p_rcb - p_cb->rcb) + 1;
531e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("switching RCB rc_acp_handle:%d idx:%d",
5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                               p_cb->rc_acp_handle, p_cb->rc_acp_idx);
5335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_cb->rcb[i].shdl = shdl;
5375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    rc_open.rc_handle = i;
538e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_ERROR("bta_av_rc_opened rcb[%d] shdl:%d lidx:%d/%d",
5395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            i, shdl, p_cb->rcb[i].lidx, p_cb->lcb[BTA_AV_NUM_LINKS].lidx);
5405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_cb->rcb[i].status |= BTA_AV_RC_CONN_MASK;
5415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(!shdl && 0 == p_cb->lcb[BTA_AV_NUM_LINKS].lidx)
5435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* no associated SCB -> connected to an RC only device
5455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project         * update the index to the extra LCB */
5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_lcb = &p_cb->lcb[BTA_AV_NUM_LINKS];
5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bdcpy(p_lcb->addr, p_data->rc_conn_chg.peer_addr);
548e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("rc_only bd_addr:%02x-%02x-%02x-%02x-%02x-%02x",
5495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      p_lcb->addr[0], p_lcb->addr[1],
5505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      p_lcb->addr[2], p_lcb->addr[3],
5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      p_lcb->addr[4], p_lcb->addr[5]);
5525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_lcb->lidx = BTA_AV_NUM_LINKS + 1;
5535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->rcb[i].lidx = p_lcb->lidx;
5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_lcb->conn_msk = 1;
555e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_ERROR("rcb[%d].lidx=%d, lcb.conn_msk=x%x",
5565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            i, p_cb->rcb[i].lidx, p_lcb->conn_msk);
5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        disc = p_data->rc_conn_chg.handle|BTA_AV_CHNL_MSK;
5585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bdcpy(rc_open.peer_addr, p_data->rc_conn_chg.peer_addr);
5615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    rc_open.peer_features = p_cb->rcb[i].peer_features;
5625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    rc_open.status = BTA_AV_SUCCESS;
563e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("local features:x%x peer_features:x%x", p_cb->features,
5645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      rc_open.peer_features);
5655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(rc_open.peer_features == 0)
5665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* we have not done SDP on peer RC capabilities.
5685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project         * peer must have initiated the RC connection */
5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_open.peer_features = BTA_AV_FEAT_RCCT;
5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_av_rc_disc(disc);
5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, (tBTA_AV *) &rc_open);
5735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
5755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
5785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_remote_cmd
5805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Send an AVRCP remote control command.
5825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
5845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
5865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_remote_cmd(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
5875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
5885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB    *p_rcb;
5895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_cb->features & BTA_AV_FEAT_RCCT)
5905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_data->hdr.layer_specific < BTA_AV_NUM_RCB)
5925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
5945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_rcb->status & BTA_AV_RC_CONN_MASK)
5955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
5965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                AVRC_PassCmd(p_rcb->handle, p_data->api_remote_cmd.label,
5975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                     &p_data->api_remote_cmd.msg);
5985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
5995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_vendor_cmd
6065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Send an AVRCP vendor specific command.
6085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_vendor_cmd(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
6135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB    *p_rcb;
6155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ( (p_cb->features & (BTA_AV_FEAT_RCCT | BTA_AV_FEAT_VENDOR)) ==
6165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project         (BTA_AV_FEAT_RCCT | BTA_AV_FEAT_VENDOR))
6175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_data->hdr.layer_specific < BTA_AV_NUM_RCB)
6195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
6205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
6215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            AVRC_VendorCmd(p_rcb->handle, p_data->api_vendor.label, &p_data->api_vendor.msg);
6225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_vendor_rsp
6295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Send an AVRCP vendor specific response.
6315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_vendor_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
6365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB    *p_rcb;
6385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ( (p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_VENDOR)) ==
6395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project         (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_VENDOR))
6405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_data->hdr.layer_specific < BTA_AV_NUM_RCB)
6425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
6435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
6445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            AVRC_VendorRsp(p_rcb->handle, p_data->api_vendor.label, &p_data->api_vendor.msg);
6455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_meta_rsp
6525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Send an AVRCP metadata/advanced control command/response.
6545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_meta_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
6595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB *p_rcb;
6615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN         free = TRUE;
6625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_cb->features & BTA_AV_FEAT_METADATA) && (p_data->hdr.layer_specific < BTA_AV_NUM_RCB))
6645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_data->api_meta_rsp.is_rsp && (p_cb->features & BTA_AV_FEAT_RCTG)) ||
6665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            (!p_data->api_meta_rsp.is_rsp && (p_cb->features & BTA_AV_FEAT_RCCT)) )
6675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
6685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
66917b504d0b0b90de00f5f0c59a3601e7b7f444730Zhihai Xu            if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) {
67017b504d0b0b90de00f5f0c59a3601e7b7f444730Zhihai Xu                AVRC_MsgReq(p_rcb->handle, p_data->api_meta_rsp.label,
67117b504d0b0b90de00f5f0c59a3601e7b7f444730Zhihai Xu                            p_data->api_meta_rsp.rsp_code,
67217b504d0b0b90de00f5f0c59a3601e7b7f444730Zhihai Xu                            p_data->api_meta_rsp.p_pkt);
67317b504d0b0b90de00f5f0c59a3601e7b7f444730Zhihai Xu                free = FALSE;
67417b504d0b0b90de00f5f0c59a3601e7b7f444730Zhihai Xu            }
6755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (free)
6795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        GKI_freebuf (p_data->api_meta_rsp.p_pkt);
6805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_free_rsp
6855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      free an AVRCP metadata command buffer.
6875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_free_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
6925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6935cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_cb);
6945cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen
6955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GKI_freebuf (p_data->api_meta_rsp.p_pkt);
6965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_meta_req
7015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Send an AVRCP metadata command.
7035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
7055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
7075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_free_msg (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
7085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7095cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_cb);
7105cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_data);
7115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
7125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
7165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_chk_notif_evt_id
7185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      make sure the requested player id is valid.
7205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          BTA_AV_STS_NO_RSP, if no error
7225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
7245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic tAVRC_STS bta_av_chk_notif_evt_id(tAVRC_MSG_VENDOR *p_vendor)
7255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tAVRC_STS   status = BTA_AV_STS_NO_RSP;
7275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       xx;
7285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16      u16;
7295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       *p = p_vendor->p_vendor_data + 2;
7305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BE_STREAM_TO_UINT16 (u16, p);
7325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* double check the fixed length */
7335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((u16 != 5) || (p_vendor->vendor_len != 9))
7345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        status = AVRC_STS_INTERNAL_ERR;
7365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
7385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* make sure the player_id is valid */
7405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        for (xx=0; xx<p_bta_av_cfg->num_evt_ids; xx++)
7415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
7425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (*p == p_bta_av_cfg->p_meta_evt_ids[xx])
7435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
7445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
7455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
7465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (xx == p_bta_av_cfg->num_evt_ids)
7485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
7495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            status = AVRC_STS_BAD_PARAM;
7505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return status;
7545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
7555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
7575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_proc_meta_cmd
7595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Process an AVRCP metadata command from the peer.
7615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          TRUE to respond immediately
7635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
7655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE  *p_rc_rsp, tBTA_AV_RC_MSG *p_msg, UINT8 *p_ctype)
7665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_EVT evt = BTA_AV_META_MSG_EVT;
7685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       u8, pdu, *p;
7695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16      u16;
7705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tAVRC_MSG_VENDOR    *p_vendor = &p_msg->msg.vendor;
7715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7729adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#if (AVRC_METADATA_INCLUDED == TRUE)
7739adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan
7745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    pdu = *(p_vendor->p_vendor_data);
7755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_rc_rsp->pdu = pdu;
7765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    *p_ctype = AVRC_RSP_REJ;
7775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* Metadata messages only use PANEL sub-unit type */
7785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_vendor->hdr.subunit_type != AVRC_SUB_PANEL)
7795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
780e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("SUBUNIT must be PANEL");
7815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* reject it */
7825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        evt=0;
7835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_vendor->hdr.ctype = BTA_AV_RSP_NOT_IMPL;
7845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        AVRC_VendorRsp(p_msg->handle, p_msg->label, &p_msg->msg.vendor);
7855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7869adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    else if (!AVRC_IsValidAvcType(pdu, p_vendor->hdr.ctype) )
7879adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    {
788e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("Invalid pdu/ctype: 0x%x, %d", pdu, p_vendor->hdr.ctype);
7899adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        /* reject invalid message without reporting to app */
7909adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        evt = 0;
7919adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD;
7929adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    }
7935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
7945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        switch (pdu)
7965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
7975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case AVRC_PDU_GET_CAPABILITIES:
7985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* process GetCapabilities command without reporting the event to app */
7995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            evt = 0;
8005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            u8 = *(p_vendor->p_vendor_data + 4);
8015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p = p_vendor->p_vendor_data + 2;
8025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rc_rsp->get_caps.capability_id = u8;
8035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            BE_STREAM_TO_UINT16 (u16, p);
8045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((u16 != 1) || (p_vendor->vendor_len != 5))
8055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_rc_rsp->get_caps.status = AVRC_STS_INTERNAL_ERR;
8075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
8095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_rc_rsp->get_caps.status = AVRC_STS_NO_ERROR;
8115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (u8 == AVRC_CAP_COMPANY_ID)
8125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
8135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    *p_ctype = AVRC_RSP_IMPL_STBL;
8145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rc_rsp->get_caps.count = p_bta_av_cfg->num_co_ids;
8155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    memcpy(p_rc_rsp->get_caps.param.company_id, p_bta_av_cfg->p_meta_co_ids,
8165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                           (p_bta_av_cfg->num_co_ids << 2));
8175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
8185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else if (u8 == AVRC_CAP_EVENTS_SUPPORTED)
8195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
8205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    *p_ctype = AVRC_RSP_IMPL_STBL;
8215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rc_rsp->get_caps.count = p_bta_av_cfg->num_evt_ids;
8225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    memcpy(p_rc_rsp->get_caps.param.event_id, p_bta_av_cfg->p_meta_evt_ids,
8235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                           p_bta_av_cfg->num_evt_ids);
8245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
8255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else
8265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
827e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                    APPL_TRACE_DEBUG("Invalid capability ID: 0x%x", u8);
8285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* reject - unknown capability ID */
8295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rc_rsp->get_caps.status = AVRC_STS_BAD_PARAM;
8305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
8315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
8335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case AVRC_PDU_REGISTER_NOTIFICATION:
8365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* make sure the event_id is implemented */
8375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rc_rsp->rsp.status = bta_av_chk_notif_evt_id (p_vendor);
8385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_rc_rsp->rsp.status != BTA_AV_STS_NO_RSP)
8395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                evt = 0;
8405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
8415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
8435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
8449adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#else
845e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("AVRCP 1.3 Metadata not supporteed. Reject command.");
8469adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    /* reject invalid message without reporting to app */
8479adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    evt = 0;
8489adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD;
8499adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#endif
8505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return evt;
8525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
8535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
8565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_msg
8585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Process an AVRCP message from the peer.
8605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
8625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
8645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
8655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
8665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_EVT evt = 0;
8675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV     av;
8685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BT_HDR      *p_pkt = NULL;
8695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tAVRC_MSG_VENDOR    *p_vendor = &p_data->rc_msg.msg.vendor;
870ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    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);
8719adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#if (AVRC_METADATA_INCLUDED == TRUE)
8729adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    tAVRC_STS   res;
873bea4131cac3214e0ad26ea8258e270448f23f1f3Matthew Xie    UINT8       ctype = 0;
8749adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    tAVRC_RESPONSE  rc_rsp;
8759adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan
8769adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    rc_rsp.rsp.status = BTA_AV_STS_NO_RSP;
8779adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#endif
8785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_data->rc_msg.opcode == AVRC_OP_PASS_THRU)
8805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
8815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* if this is a pass thru command */
882ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_CTRL) ||
883ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) ||
884ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ)
885ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            )
8865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
8875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* check if operation is supported */
8885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_data->rc_msg.msg.pass.op_id == AVRC_ID_VENDOR)
8895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL;
8919adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#if (AVRC_METADATA_INCLUDED == TRUE)
8929adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                if (p_cb->features & BTA_AV_FEAT_METADATA)
8939adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                    p_data->rc_msg.msg.hdr.ctype =
8949adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                        bta_av_group_navi_supported(p_data->rc_msg.msg.pass.pass_len,
8959adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                        p_data->rc_msg.msg.pass.p_pass_data, is_inquiry);
8969adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#endif
8975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
8995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
900ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                p_data->rc_msg.msg.hdr.ctype = bta_av_op_supported(p_data->rc_msg.msg.pass.op_id, is_inquiry);
9015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
903e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("ctype %d",p_data->rc_msg.msg.hdr.ctype)
904ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
9055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* send response */
9065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_data->rc_msg.msg.hdr.ctype != BTA_AV_RSP_INTERIM)
9075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass);
9085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* set up for callback if supported */
9105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_data->rc_msg.msg.hdr.ctype == BTA_AV_RSP_ACCEPT || p_data->rc_msg.msg.hdr.ctype == BTA_AV_RSP_INTERIM)
9115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
9125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                evt = BTA_AV_REMOTE_CMD_EVT;
9135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                av.remote_cmd.rc_id = p_data->rc_msg.msg.pass.op_id;
9145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                av.remote_cmd.key_state = p_data->rc_msg.msg.pass.state;
9155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                av.remote_cmd.p_data = p_data->rc_msg.msg.pass.p_pass_data;
9165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                av.remote_cmd.len = p_data->rc_msg.msg.pass.pass_len;
9175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(&av.remote_cmd.hdr, &p_data->rc_msg.msg.hdr, sizeof (tAVRC_HDR));
9185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                av.remote_cmd.label = p_data->rc_msg.label;
9195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* else if this is a pass thru response */
9225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT)
9235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* set up for callback */
9255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            evt = BTA_AV_REMOTE_RSP_EVT;
9265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            av.remote_rsp.rc_id = p_data->rc_msg.msg.pass.op_id;
9275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            av.remote_rsp.key_state = p_data->rc_msg.msg.pass.state;
9285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            av.remote_rsp.rsp_code = p_data->rc_msg.msg.hdr.ctype;
9295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            av.remote_rsp.label = p_data->rc_msg.label;
9305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* must be a bad ctype -> reject*/
9325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
9335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_REJ;
9355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass);
9365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
9385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* else if this is a vendor specific command or response */
9395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (p_data->rc_msg.opcode == AVRC_OP_VENDOR)
9405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
9415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* set up for callback */
9425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        av.vendor_cmd.code = p_data->rc_msg.msg.hdr.ctype;
9435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        av.vendor_cmd.company_id = p_vendor->company_id;
9445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        av.vendor_cmd.label = p_data->rc_msg.label;
9455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        av.vendor_cmd.p_data = p_vendor->p_vendor_data;
9465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        av.vendor_cmd.len = p_vendor->vendor_len;
9475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* if configured to support vendor specific and it's a command */
9495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_cb->features & BTA_AV_FEAT_VENDOR)  &&
9505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ)
9515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9529adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#if (AVRC_METADATA_INCLUDED == TRUE)
9539adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            if ((p_cb->features & BTA_AV_FEAT_METADATA) &&
9549adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan               (p_vendor->company_id == AVRC_CO_METADATA))
9559adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            {
9569adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                av.meta_msg.p_msg = &p_data->rc_msg.msg;
9579adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                evt = bta_av_proc_meta_cmd (&rc_rsp, &p_data->rc_msg, &ctype);
9589adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            }
9599adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            else
9609adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#endif
9615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                evt = BTA_AV_VENDOR_CMD_EVT;
9625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* else if configured to support vendor specific and it's a response */
9645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if ((p_cb->features & BTA_AV_FEAT_VENDOR) &&
9655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT)
9665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9679adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#if (AVRC_METADATA_INCLUDED == TRUE)
9689adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            if ((p_cb->features & BTA_AV_FEAT_METADATA) &&
9699adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan               (p_vendor->company_id == AVRC_CO_METADATA))
9709adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            {
9719adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                av.meta_msg.p_msg = &p_data->rc_msg.msg;
9729adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan                evt = BTA_AV_META_MSG_EVT;
9739adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            }
9749adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            else
9759adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#endif
9765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                evt = BTA_AV_VENDOR_RSP_EVT;
9775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* else if not configured to support vendor specific and it's a command */
9805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (!(p_cb->features & BTA_AV_FEAT_VENDOR)  &&
9815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ)
9825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           if(p_data->rc_msg.msg.vendor.p_vendor_data[0] == AVRC_PDU_INVALID)
9845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           {
9855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           /* reject it */
9865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project              p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_REJ;
9875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project              p_data->rc_msg.msg.vendor.p_vendor_data[4] = AVRC_STS_BAD_CMD;
9885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           }
9895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           else
9905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project              p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL;
9915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           AVRC_VendorRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.vendor);
9925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
9949adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#if (AVRC_METADATA_INCLUDED == TRUE)
9959adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    if (evt == 0 && rc_rsp.rsp.status != BTA_AV_STS_NO_RSP)
9969adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    {
9979adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        if (!p_pkt)
9989adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        {
9999adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            rc_rsp.rsp.opcode = p_data->rc_msg.opcode;
10009adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            res = AVRC_BldResponse (0, &rc_rsp, &p_pkt);
10019adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        }
10029adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        if (p_pkt)
10039adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan            AVRC_MsgReq (p_data->rc_msg.handle, p_data->rc_msg.label, ctype, p_pkt);
10049adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    }
10059adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan#endif
10065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* call callback */
10085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (evt != 0)
10095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
10105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        av.remote_cmd.rc_handle = p_data->rc_msg.handle;
10115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_cb->p_cback)(evt, &av);
10125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_close
10185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      close the specified AVRC handle.
10205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
10225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
10245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_close (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
10255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 handle = p_data->hdr.layer_specific;
10275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB  *p_scb;
10285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB *p_rcb;
10295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(handle < BTA_AV_NUM_RCB)
10315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
10325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_rcb = &p_cb->rcb[handle];
10335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1034e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("bta_av_rc_close handle: %d, status=0x%x", p_rcb->handle, p_rcb->status);
10355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_rcb->handle != BTA_AV_RC_HANDLE_NONE)
10365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_rcb->shdl)
10385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1];
10405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(p_scb)
10415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
10425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* just in case the RC timer is active
10435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if(bta_av_cb.features & BTA_AV_FEAT_RCCT &&
10445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_scb->chnl == BTA_AV_CHNL_AUDIO) */
10455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_sys_stop_timer(&p_scb->timer);
10465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
10475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            AVRC_Close(p_rcb->handle);
10505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_get_shdl
10575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          The index to p_scb[]
10595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
10615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic UINT8 bta_av_get_shdl(tBTA_AV_SCB *p_scb)
10625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int     i;
10645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   shdl = 0;
10655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* find the SCB & stop the timer */
10665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(i=0; i<BTA_AV_NUM_STRS; i++)
10675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
10685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_scb == bta_av_cb.p_scb[i])
10695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            shdl = i+1;
10715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
10725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return shdl;
10755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_stream_chg
10805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      audio streaming status changed.
10825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
10845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
10865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_stream_chg(tBTA_AV_SCB *p_scb, BOOLEAN started)
10875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   started_msk;
10895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int     i;
10905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   *p_streams;
10915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN no_streams = FALSE;
10925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB *p_scbi;
10935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    started_msk = BTA_AV_HNDL_TO_MSK(p_scb->hdi);
1095e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG ("bta_av_stream_chg started:%d started_msk:x%x chnl:x%x", started,
10965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                                  started_msk, p_scb->chnl);
10975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (BTA_AV_CHNL_AUDIO == p_scb->chnl)
10985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_streams = &bta_av_cb.audio_streams;
10995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
11005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_streams = &bta_av_cb.video_streams;
11015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (started)
11035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* Let L2CAP know this channel is processed with high priority */
11055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        L2CA_SetAclPriority(p_scb->peer_addr, L2CAP_PRIORITY_HIGH);
11065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_streams) |= started_msk;
11075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
11095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_streams) &= ~started_msk;
11115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (!started)
11145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        i=0;
11165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (BTA_AV_CHNL_AUDIO == p_scb->chnl)
11175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (bta_av_cb.video_streams == 0)
11195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                no_streams = TRUE;
11205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
11225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            no_streams = TRUE;
11245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ( bta_av_cb.audio_streams )
11255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
11265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                for (; i<BTA_AV_NUM_STRS; i++)
11275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
11285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_scbi = bta_av_cb.p_scb[i];
11295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* scb is used and started */
11305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if ( p_scbi && (bta_av_cb.audio_streams & BTA_AV_HNDL_TO_MSK(i))
11315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        && bdcmp(p_scbi->peer_addr, p_scb->peer_addr) == 0)
11325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
11335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        no_streams = FALSE;
11345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        break;
11355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
11365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
11375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
11395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1141e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG ("no_streams:%d i:%d, audio_streams:x%x, video_streams:x%x", no_streams, i,
11425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                           bta_av_cb.audio_streams, bta_av_cb.video_streams);
11435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (no_streams)
11445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* Let L2CAP know this channel is processed with low priority */
11465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            L2CA_SetAclPriority(p_scb->peer_addr, L2CAP_PRIORITY_NORMAL);
11475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
11505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
11535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_conn_chg
11555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      connetion status changed.
11575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  Open an AVRCP acceptor channel, if new conn.
11585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
11605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
11625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_conn_chg(tBTA_AV_DATA *p_data)
11635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
11645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
11655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB     *p_scb;
11665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB     *p_scbi;
11675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   mask;
11685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   conn_msk;
11695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   old_msk;
11705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int i;
11715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int index = (p_data->hdr.layer_specific & BTA_AV_HNDL_MSK) - 1;
11725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb;
11735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb_rc;
11745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB *p_rcb, *p_rcb2;
11755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN     chk_restore = FALSE;
11765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_scb = p_cb->p_scb[index];
11785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    mask = BTA_AV_HNDL_TO_MSK(index);
11805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_lcb = bta_av_find_lcb(p_data->conn_chg.peer_addr, BTA_AV_LCB_FIND);
11815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    conn_msk = 1 << (index + 1);
11825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(p_data->conn_chg.is_up)
11835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* set the conned mask for this channel */
11855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_scb)
11865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_lcb)
11885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
11895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_lcb->conn_msk |= conn_msk;
11905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                for (i=0; i<BTA_AV_NUM_RCB; i++)
11915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
11925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (bta_av_cb.rcb[i].lidx == p_lcb->lidx)
11935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
11945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_av_cb.rcb[i].shdl = index + 1;
1195e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                        APPL_TRACE_DEBUG("conn_chg up[%d]: %d, status=0x%x, shdl:%d, lidx:%d", i,
11965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          bta_av_cb.rcb[i].handle, bta_av_cb.rcb[i].status,
11975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          bta_av_cb.rcb[i].shdl, bta_av_cb.rcb[i].lidx);
11985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        break;
11995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
12005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
12015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
12025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_scb->chnl == BTA_AV_CHNL_AUDIO)
12035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
12045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                old_msk = p_cb->conn_audio;
12055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_cb->conn_audio |= mask;
12065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
12075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
12085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
12095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                old_msk = p_cb->conn_video;
12105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_cb->conn_video |= mask;
12115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
12125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((old_msk & mask) == 0)
12145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
12155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* increase the audio open count, if not set yet */
12165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_av_cb.audio_open_cnt++;
12175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
12185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1220e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("rc_acp_handle:%d rc_acp_idx:%d", p_cb->rc_acp_handle, p_cb->rc_acp_idx);
12215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* check if the AVRCP ACP channel is already connected */
12225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_lcb && p_cb->rc_acp_handle != BTA_AV_RC_HANDLE_NONE && p_cb->rc_acp_idx)
12235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
12245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_lcb_rc = &p_cb->lcb[BTA_AV_NUM_LINKS];
1225e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG("rc_acp is connected && conn_chg on same addr p_lcb_rc->conn_msk:x%x",
12265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                  p_lcb_rc->conn_msk);
12275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* check if the RC is connected to the scb addr */
1228e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG ("p_lcb_rc->addr: %02x:%02x:%02x:%02x:%02x:%02x",
12295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_lcb_rc->addr[0], p_lcb_rc->addr[1], p_lcb_rc->addr[2], p_lcb_rc->addr[3],
12305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_lcb_rc->addr[4], p_lcb_rc->addr[5]);
1231e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG ("conn_chg.peer_addr: %02x:%02x:%02x:%02x:%02x:%02x",
12325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_data->conn_chg.peer_addr[0], p_data->conn_chg.peer_addr[1],
12335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_data->conn_chg.peer_addr[2],
12345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_data->conn_chg.peer_addr[3], p_data->conn_chg.peer_addr[4],
12355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_data->conn_chg.peer_addr[5]);
12365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_lcb_rc->conn_msk && bdcmp(p_lcb_rc->addr, p_data->conn_chg.peer_addr) == 0)
12375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
12385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* AVRCP is already connected.
12395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                     * need to update the association betwen SCB and RCB */
12405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_lcb_rc->conn_msk = 0; /* indicate RC ONLY is not connected */
12415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_lcb_rc->lidx = 0;
12425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_scb->rc_handle = p_cb->rc_acp_handle;
12435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rcb = &p_cb->rcb[p_cb->rc_acp_idx - 1];
12445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rcb->shdl = bta_av_get_shdl(p_scb);
1245e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                    APPL_TRACE_DEBUG("update rc_acp shdl:%d/%d srch:%d", index + 1, p_rcb->shdl,
12465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      p_scb->rc_handle );
12475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rcb2 = bta_av_get_rcb_by_shdl(p_rcb->shdl);
12495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (p_rcb2)
12505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
12515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        /* found the RCB that was created to associated with this SCB */
12525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_cb->rc_acp_handle = p_rcb2->handle;
12535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_cb->rc_acp_idx = (p_rcb2 - p_cb->rcb) + 1;
1254e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                        APPL_TRACE_DEBUG("new rc_acp_handle:%d, idx:%d", p_cb->rc_acp_handle,
12555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                           p_cb->rc_acp_idx);
12565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_rcb2->lidx = (BTA_AV_NUM_LINKS + 1);
1257e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                        APPL_TRACE_DEBUG("rc2 handle:%d lidx:%d/%d",p_rcb2->handle, p_rcb2->lidx,
12585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          p_cb->lcb[p_rcb2->lidx-1].lidx);
12595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
12605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_rcb->lidx = p_lcb->lidx;
1261e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                    APPL_TRACE_DEBUG("rc handle:%d lidx:%d/%d",p_rcb->handle, p_rcb->lidx,
12625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      p_cb->lcb[p_rcb->lidx-1].lidx);
12635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
12645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
12655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
12665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
12685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
12695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_cb->conn_audio & mask) && bta_av_cb.audio_open_cnt)
12705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
12715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* this channel is still marked as open. decrease the count */
12725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_cb.audio_open_cnt--;
12735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
12745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* clear the conned mask for this channel */
12765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_cb->conn_audio &= ~mask;
12775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_cb->conn_video &= ~mask;
12785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_scb)
12795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
12805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* the stream is closed.
12815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             * clear the peer address, so it would not mess up the AVRCP for the next round of operation */
12825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bdcpy(p_scb->peer_addr, bd_addr_null);
12835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_scb->chnl == BTA_AV_CHNL_AUDIO)
12845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
12855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(p_lcb)
12865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
12875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_lcb->conn_msk &= ~conn_msk;
12885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
12895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* audio channel is down. make sure the INT channel is down */
12905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* just in case the RC timer is active
12915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(p_cb->features & BTA_AV_FEAT_RCCT) */
12925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
12935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_sys_stop_timer(&p_scb->timer);
12945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
12955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* one audio channel goes down. check if we need to restore high priority */
12965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                chk_restore = TRUE;
12975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
12985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
12995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1300e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("bta_av_conn_chg shdl:%d", index + 1);
13015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        for (i=0; i<BTA_AV_NUM_RCB; i++)
13025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1303e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("conn_chg dn[%d]: %d, status=0x%x, shdl:%d, lidx:%d", i,
13045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              bta_av_cb.rcb[i].handle, bta_av_cb.rcb[i].status,
13055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              bta_av_cb.rcb[i].shdl, bta_av_cb.rcb[i].lidx);
13065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(bta_av_cb.rcb[i].shdl == index + 1)
13075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
13085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_av_del_rc(&bta_av_cb.rcb[i]);
13095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
13105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
13115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_cb->conn_audio == 0 && p_cb->conn_video == 0)
13145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* if both channels are not connected,
13165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             * close all RC channels */
13175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_close_all_rc(p_cb);
13185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* if the AVRCP is no longer listening, create the listening channel */
13215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (bta_av_cb.rc_acp_handle == BTA_AV_RC_HANDLE_NONE && bta_av_cb.features & BTA_AV_FEAT_RCTG)
13225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1);
13235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
13245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1325e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_conn_chg audio:%x video:%x up:%d conn_msk:0x%x chk_restore:%d audio_open_cnt:%d",
13265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_cb->conn_audio, p_cb->conn_video, p_data->conn_chg.is_up, conn_msk, chk_restore, p_cb->audio_open_cnt);
13275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (chk_restore)
13295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
13305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->audio_open_cnt == 1)
13315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* one audio channel goes down and there's one audio channel remains open.
13335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             * restore the switch role in default link policy */
13345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_sys_set_default_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH);
13355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* allow role switch, if this is the last connection */
13365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_restore_switch();
13375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->audio_open_cnt)
13395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* adjust flush timeout settings to longer period */
13415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            for (i=0; i<BTA_AV_NUM_STRS; i++)
13425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
13435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_scbi = bta_av_cb.p_scb[i];
13445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_scbi && p_scbi->chnl == BTA_AV_CHNL_AUDIO && p_scbi->co_started)
13455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
13465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* may need to update the flush timeout of this already started stream */
13475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (p_scbi->co_started != bta_av_cb.audio_open_cnt)
13485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
13495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_scbi->co_started = bta_av_cb.audio_open_cnt;
13505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        L2CA_SetFlushTimeout(p_scbi->peer_addr, p_bta_av_cfg->p_audio_flush_to[p_scbi->co_started - 1] );
13515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
13525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
13535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
13545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
13565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
13575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
13595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_disable
13615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      disable AV.
13635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
13655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
13675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_disable(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
13685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
13695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BT_HDR  hdr;
13705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16  xx;
13715cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_data);
13725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_cb->disabling = TRUE;
13745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_av_close_all_rc(p_cb);
13765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    utl_freebuf((void **) &p_cb->p_disc_db);
13785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* disable audio/video - de-register all channels,
13805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project     * expect BTA_AV_DEREG_COMP_EVT when deregister is complete */
13815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(xx=0; xx<BTA_AV_NUM_STRS; xx++)
13825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
13835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        hdr.layer_specific = xx + 1;
13845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_av_api_deregister((tBTA_AV_DATA *)&hdr);
13855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
13865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
13875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
13895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_api_disconnect
13915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      .
13935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
13955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
13975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_api_disconnect(tBTA_AV_DATA *p_data)
13985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
13995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    AVDT_DisconnectReq(p_data->api_discnt.bd_addr, bta_av_conn_cback);
14005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_sys_stop_timer(&bta_av_cb.sig_tmr);
14015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
14025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
14045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_sig_chg
14065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process AVDT signal channel up/down.
14085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
14105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
14125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_sig_chg(tBTA_AV_DATA *p_data)
14135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
14145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 event = p_data->str_msg.hdr.layer_specific;
14155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
14165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int     xx;
14175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   mask;
14185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb = NULL;
14195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1420e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_sig_chg event: %d", event);
14215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(event == AVDT_CONNECT_IND_EVT)
14225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
14235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_lcb = bta_av_find_lcb(p_data->str_msg.bd_addr, BTA_AV_LCB_FIND);
14245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(!p_lcb)
14255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
14265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* if the address does not have an LCB yet, alloc one */
14275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            for(xx=0; xx<BTA_AV_NUM_LINKS; xx++)
14285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
14295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                mask = 1 << xx;
1430e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb);
14315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1432ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                /* look for a p_lcb with its p_scb registered */
1433ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                if((!(mask & p_cb->conn_lcb)) && (p_cb->p_scb[xx] != NULL))
1434ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                {
14355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_lcb = &p_cb->lcb[xx];
14365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_lcb->lidx = xx + 1;
14375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bdcpy(p_lcb->addr, p_data->str_msg.bd_addr);
14385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_lcb->conn_msk = 0; /* clear the connect mask */
14395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* start listening when the signal channel is open */
14405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (p_cb->features & BTA_AV_FEAT_RCTG)
14415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
14425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_av_rc_create(p_cb, AVCT_ACP, 0, p_lcb->lidx);
14435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
14445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* this entry is not used yet. */
14455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_cb->conn_lcb |= mask;     /* mark it as used */
1446e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                    APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
14475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (p_data->hdr.offset == AVDT_ACP)
14485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
1449e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                        APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming", NULL);
14505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr);
14515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_cb->p_scb[xx]->use_rc = TRUE;     /* allowing RC for incoming connection */
14525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data);
14535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        /* The Pending Event should be sent as soon as the L2CAP signalling channel
14555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                         * is set up, which is NOW. Earlier this was done only after
14565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                         * BTA_AV_SIG_TIME_VAL milliseconds.
14575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                         * The following function shall send the event and start the recurring timer
14585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                         */
14595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_av_sig_timer(NULL);
14605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        /* Possible collision : need to avoid outgoing processing while the timer is running */
14625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_cb->p_scb[xx]->coll_mask = BTA_AV_COLL_INC_TMR;
14635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_cb->acp_sig_tmr.param = (UINT32)xx;
14655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_cb->acp_sig_tmr.p_cback = (TIMER_CBACK*)&bta_av_acp_sig_timer_cback;
14665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL);
14675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
14685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    break;
14695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
14705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
1471ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1472ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            /* check if we found something */
1473ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (xx == BTA_AV_NUM_LINKS)
1474ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
1475ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                /* We do not have scb for this avdt connection.     */
1476ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                /* Silently close the connection.                   */
1477e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_ERROR("av scb not available for avdt connection");
1478ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                AVDT_DisconnectReq (p_data->str_msg.bd_addr, NULL);
1479ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                return;
1480ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
14815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
14825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
14835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
14845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (event == BTA_AR_AVDT_CONN_EVT)
14855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
14865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_sys_stop_timer(&bta_av_cb.sig_tmr);
14875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
14885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
14895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
14905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
14915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* disconnected. */
14925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_lcb = bta_av_find_lcb(p_data->str_msg.bd_addr, BTA_AV_LCB_FREE);
14935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_lcb && p_lcb->conn_msk)
14945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1495e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("conn_msk: 0x%x", p_lcb->conn_msk);
14965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* clean up ssm  */
14975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            for(xx=0; xx < BTA_AV_NUM_STRS; xx++)
14985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
14995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                mask = 1 << (xx + 1);
15005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if ((mask & p_lcb->conn_msk) && (p_cb->p_scb[xx]) &&
15015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    (bdcmp(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr) == 0))
15025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
15035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_AVDT_DISCONNECT_EVT, NULL);
15045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
15055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
15065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
15075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1508e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb);
15095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
15105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
15125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_sig_timer
15145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process the signal channel timer. This timer is started
15165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  when the AVDTP signal channel is connected. If no profile
15175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  is connected, the timer goes off every BTA_AV_SIG_TIME_VAL
15185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
15205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
15225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_sig_timer(tBTA_AV_DATA *p_data)
15235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
15245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
15255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int     xx;
15265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   mask;
15275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb = NULL;
15285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_PEND pend;
15295cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_data);
15305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1531e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_sig_timer");
15325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(xx=0; xx<BTA_AV_NUM_LINKS; xx++)
15335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
15345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        mask = 1 << xx;
15355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(mask & p_cb->conn_lcb)
15365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
15375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* this entry is used. check if it is connected */
15385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_lcb = &p_cb->lcb[xx];
15395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(!p_lcb->conn_msk)
15405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
15415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_sys_start_timer(&p_cb->sig_tmr, BTA_AV_SIG_TIMER_EVT, BTA_AV_SIG_TIME_VAL);
15425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bdcpy(pend.bd_addr, p_lcb->addr);
15435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                (*p_cb->p_cback)(BTA_AV_PENDING_EVT, (tBTA_AV *) &pend);
15445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
15455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
15465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
15475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
15485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
15505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_acp_sig_timer_cback
15525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Process the timeout when SRC is accepting connection
15545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  and SNK did not start signalling.
15555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
15575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
15595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle)
15605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
15615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   inx = (UINT8)p_tle->param;
15625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB  *p_cb = &bta_av_cb;
15635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB *p_scb = p_cb->p_scb[inx];
15645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_API_OPEN  *p_buf;
15655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_scb)
15675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1568e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("bta_av_acp_sig_timer_cback, coll_mask = 0x%02X", p_scb->coll_mask);
15695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR)
15715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
15725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_scb->coll_mask &= ~BTA_AV_COLL_INC_TMR;
15735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (bta_av_is_scb_opening(p_scb))
15755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
15765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_scb->p_disc_db)
15775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
15785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* We are still doing SDP. Run the timer again. */
15795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_scb->coll_mask |= BTA_AV_COLL_INC_TMR;
15805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_cb->acp_sig_tmr.param = (UINT32)inx;
15825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_cb->acp_sig_tmr.p_cback = (TIMER_CBACK *)&bta_av_acp_sig_timer_cback;
15835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL);
15845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
15855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else
15865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
15875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* SNK did not start signalling, resume signalling process. */
15885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_av_discover_req (p_scb, NULL);
15895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
15905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
15915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if (bta_av_is_scb_incoming(p_scb))
15925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
15935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* Stay in incoming state if SNK does not start signalling */
15945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* API open was called right after SNK opened L2C connection. */
15965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_scb->coll_mask & BTA_AV_COLL_API_CALLED)
15975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
15985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_scb->coll_mask &= ~BTA_AV_COLL_API_CALLED;
15995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* BTA_AV_API_OPEN_EVT */
16015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if ((p_buf = (tBTA_AV_API_OPEN *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN))) != NULL)
16025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
16035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        memcpy(p_buf, &(p_scb->open_api), sizeof(tBTA_AV_API_OPEN));
16045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_sys_sendmsg(p_buf);
16055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
16065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
16075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
16085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
16095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
16105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
16115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
16135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_check_peer_features
16155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1616ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description      check supported features on the peer device from the SDP record
1617ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**                  and return the feature mask
16185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1619ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns          tBTA_AV_FEAT peer device feature mask
16205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
16225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttBTA_AV_FEAT bta_av_check_peer_features (UINT16 service_uuid)
16235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
16245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_FEAT peer_features = 0;
16255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
16265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tSDP_DISC_REC       *p_rec = NULL;
16275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tSDP_DISC_ATTR      *p_attr;
16285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              peer_rc_version=0;
16295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              categories = 0;
16305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1631e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_check_peer_features service_uuid:x%x", service_uuid);
16325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* loop through all records we found */
16335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    while (TRUE)
16345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
16355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* get next record; if none found, we're done */
16365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_rec = SDP_FindServiceInDb(p_cb->p_disc_db, service_uuid, p_rec)) == NULL)
16375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
16385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
16395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
16405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (( SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_CLASS_ID_LIST)) != NULL)
16425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
16435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* find peer features */
16445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (SDP_FindServiceInDb(p_cb->p_disc_db, UUID_SERVCLASS_AV_REMOTE_CONTROL, NULL))
16455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
16465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                peer_features |= BTA_AV_FEAT_RCCT;
16475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
16485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (SDP_FindServiceInDb(p_cb->p_disc_db, UUID_SERVCLASS_AV_REM_CTRL_TARGET, NULL))
16495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
16505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                peer_features |= BTA_AV_FEAT_RCTG;
16515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
16525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
16535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (( SDP_FindAttributeInRec(p_rec, ATTR_ID_BT_PROFILE_DESC_LIST)) != NULL)
16555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
16565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* get profile version (if failure, version parameter is not updated) */
16575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_AV_REMOTE_CONTROL, &peer_rc_version);
1658e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("peer_rc_version 0x%x", peer_rc_version);
16595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (peer_rc_version >= AVRC_REV_1_3)
16615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                peer_features |= (BTA_AV_FEAT_VENDOR | BTA_AV_FEAT_METADATA);
16625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (peer_rc_version >= AVRC_REV_1_4)
16645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
16655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                peer_features |= (BTA_AV_FEAT_ADV_CTRL);
16665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* get supported categories */
16675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if ((p_attr = SDP_FindAttributeInRec(p_rec,
16685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                ATTR_ID_SUPPORTED_FEATURES)) != NULL)
16695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
16705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    categories = p_attr->attr_value.v.u16;
16715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (categories & AVRC_SUPF_CT_BROWSE)
16725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        peer_features |= (BTA_AV_FEAT_BROWSE);
16735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
16745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
16755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
16765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1677e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("peer_features:x%x", peer_features);
16785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return peer_features;
16795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
16805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
16825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_disc_done
16845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Handle AVRCP service discovery results.  If matching
16865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  service found, open AVRCP connection.
16875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
16895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
16915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_disc_done(tBTA_AV_DATA *p_data)
16925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
16935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
16945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB  *p_scb = NULL;
16955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB  *p_lcb;
16965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_OPEN rc_open;
16975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_FEAT rc_feat;
16985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8               rc_handle;
16995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_FEAT        peer_features;  /* peer features mask */
17005cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen    UNUSED(p_data);
17015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1702e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_rc_disc_done disc:x%x", p_cb->disc);
17035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (!p_cb->disc)
17045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
17055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
17065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
17075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_cb->disc & BTA_AV_CHNL_MSK) == BTA_AV_CHNL_MSK)
17095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
17105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* this is the rc handle/index to tBTA_AV_RCB */
17115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_handle = p_cb->disc & (~BTA_AV_CHNL_MSK);
17125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
17135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
17145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
17155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_scb = p_cb->p_scb[(p_cb->disc & BTA_AV_HNDL_MSK) - 1];
17165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_scb)
17175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            rc_handle = p_scb->rc_handle;
17185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
17195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
17205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->disc = 0;
17215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return;
17225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
17235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
17245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1725e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("rc_handle %d", rc_handle);
1726ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* check peer version and whether support CT and TG role */
17275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    peer_features = bta_av_check_peer_features (UUID_SERVCLASS_AV_REMOTE_CONTROL);
17289adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    if ((p_cb->features & BTA_AV_FEAT_ADV_CTRL) && ((peer_features&BTA_AV_FEAT_ADV_CTRL) == 0))
17299adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    {
17309adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        /* if we support advance control and peer does not, check their support on TG role
17319adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan         * some implementation uses 1.3 on CT ans 1.4 on TG */
17329adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan        peer_features |= bta_av_check_peer_features (UUID_SERVCLASS_AV_REM_CTRL_TARGET);
17339adddf4965e9ddb01e339b934c343fcbd842a977Ravi Nagarajan    }
17345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_cb->disc = 0;
17365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    utl_freebuf((void **) &p_cb->p_disc_db);
17375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1738e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("peer_features 0x%x, features 0x%x", peer_features, p_cb->features);
17395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* if we have no rc connection */
17415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (rc_handle == BTA_AV_RC_HANDLE_NONE)
17425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
17435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_scb)
17445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
17455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* if peer remote control service matches ours and USE_RC is TRUE */
17465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((((p_cb->features & BTA_AV_FEAT_RCCT) && (peer_features & BTA_AV_FEAT_RCTG)) ||
17475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 ((p_cb->features & BTA_AV_FEAT_RCTG) && (peer_features & BTA_AV_FEAT_RCCT))) )
17485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
17495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_lcb = bta_av_find_lcb(p_scb->peer_addr, BTA_AV_LCB_FIND);
17505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(p_lcb)
17515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
17525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    rc_handle = bta_av_rc_create(p_cb, AVCT_INT, (UINT8)(p_scb->hdi + 1), p_lcb->lidx);
17535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_cb->rcb[rc_handle].peer_features = peer_features;
17545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
17555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if (BT_USE_TRACES == TRUE || BT_TRACE_APPL == TRUE)
17565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else
17575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
1758e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                    APPL_TRACE_ERROR("can not find LCB!!");
17595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
17605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
17615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
17625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if(p_scb->use_rc)
17635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
17645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* can not find AVRC on peer device. report failure */
17655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_scb->use_rc = FALSE;
17665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bdcpy(rc_open.peer_addr, p_scb->peer_addr);
17675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                rc_open.peer_features = 0;
17685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                rc_open.status = BTA_AV_FAIL_SDP;
17695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, (tBTA_AV *) &rc_open);
17705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
17715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
17725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
17735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
17745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
17755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_cb->rcb[rc_handle].peer_features = peer_features;
17765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_feat.rc_handle =  rc_handle;
17775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_feat.peer_features = peer_features;
17785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_cb->p_cback)(BTA_AV_RC_FEAT_EVT, (tBTA_AV *) &rc_feat);
17795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
17805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
17815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
17835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_closed
17855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Set AVRCP state to closed.
17875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
17895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
17915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_closed(tBTA_AV_DATA *p_data)
17925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
17935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
17945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_CLOSE rc_close;
17955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RC_CONN_CHG *p_msg = (tBTA_AV_RC_CONN_CHG *)p_data;
17965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_RCB    *p_rcb;
17975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB    *p_scb;
17985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    int i;
17995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN conn = FALSE;
18005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_LCB *p_lcb;
18015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    rc_close.rc_handle = BTA_AV_RC_HANDLE_NONE;
1803e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_rc_closed rc_handle:%d", p_msg->handle);
18045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for(i=0; i<BTA_AV_NUM_RCB; i++)
18055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
18065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_rcb = &p_cb->rcb[i];
1807e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("bta_av_rc_closed rcb[%d] rc_handle:%d, status=0x%x", i, p_rcb->handle, p_rcb->status);
18085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_rcb->handle == p_msg->handle)
18095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
18105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            rc_close.rc_handle = i;
18115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->status &= ~BTA_AV_RC_CONN_MASK;
18125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->peer_features = 0;
1813e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("       shdl:%d, lidx:%d", p_rcb->shdl, p_rcb->lidx);
18145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(p_rcb->shdl)
18155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
18165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1];
18175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if(p_scb)
18185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
18195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bdcpy(rc_close.peer_addr, p_scb->peer_addr);
18205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if(p_scb->rc_handle == p_rcb->handle)
18215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE;
1822e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                    APPL_TRACE_DEBUG("shdl:%d, srch:%d", p_rcb->shdl, p_scb->rc_handle);
18235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
18245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_rcb->shdl = 0;
18255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
18265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if(p_rcb->lidx == (BTA_AV_NUM_LINKS + 1) )
18275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
18285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* if the RCB uses the extra LCB, use the addr for event and clean it */
18295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_lcb = &p_cb->lcb[BTA_AV_NUM_LINKS];
18305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bdcpy(rc_close.peer_addr, p_msg->peer_addr);
1831e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG("rc_only closed bd_addr:%02x-%02x-%02x-%02x-%02x-%02x",
18325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              p_msg->peer_addr[0], p_msg->peer_addr[1],
18335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              p_msg->peer_addr[2], p_msg->peer_addr[3],
18345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              p_msg->peer_addr[4], p_msg->peer_addr[5]);
18355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_lcb->conn_msk = 0;
18365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_lcb->lidx = 0;
18375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
18385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rcb->lidx = 0;
18395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if((p_rcb->status & BTA_AV_RC_ROLE_MASK) == BTA_AV_RC_ROLE_INT)
18415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
18425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* AVCT CCB is deallocated */
18435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_rcb->handle = BTA_AV_RC_HANDLE_NONE;
18445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_rcb->status = 0;
18455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
18465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
18475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
18485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* AVCT CCB is still there. dealloc */
18495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_av_del_rc(p_rcb);
18505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* if the AVRCP is no longer listening, create the listening channel */
18525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (bta_av_cb.rc_acp_handle == BTA_AV_RC_HANDLE_NONE && bta_av_cb.features & BTA_AV_FEAT_RCTG)
18535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1);
18545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
18555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
18565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if((p_rcb->handle != BTA_AV_RC_HANDLE_NONE) && (p_rcb->status & BTA_AV_RC_CONN_MASK))
18575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
18585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* at least one channel is still connected */
18595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            conn = TRUE;
18605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
18615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(!conn)
18645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
18655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* no AVRC channels are connected, go back to INIT state */
18665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_av_sm_execute(p_cb, BTA_AV_AVRC_NONE_EVT, NULL);
18675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (rc_close.rc_handle == BTA_AV_RC_HANDLE_NONE)
18705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
18715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_close.rc_handle = p_msg->handle;
18725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bdcpy(rc_close.peer_addr, p_msg->peer_addr);
18735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    (*p_cb->p_cback)(BTA_AV_RC_CLOSE_EVT, (tBTA_AV *) &rc_close);
18755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
18765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
18785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_rc_disc
18805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      start AVRC SDP discovery.
18825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
18845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
18865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_rc_disc(UINT8 disc)
18875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
18885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
18895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tAVRC_SDP_DB_PARAMS db_params;
18905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project      UINT16              attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST,
18915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       ATTR_ID_BT_PROFILE_DESC_LIST,
18925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       ATTR_ID_SUPPORTED_FEATURES};
18935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       hdi;
18945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB *p_scb;
18955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       *p_addr = NULL;
18965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       rc_handle;
18975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1898e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    APPL_TRACE_DEBUG("bta_av_rc_disc 0x%x, %d", disc, bta_av_cb.disc);
18995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((bta_av_cb.disc != 0) || (disc == 0))
19005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
19015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((disc & BTA_AV_CHNL_MSK) == BTA_AV_CHNL_MSK)
19035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* this is the rc handle/index to tBTA_AV_RCB */
19055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rc_handle = disc & (~BTA_AV_CHNL_MSK);
19065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->rcb[rc_handle].lidx)
19075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
19085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_addr = p_cb->lcb[p_cb->rcb[rc_handle].lidx-1].addr;
19095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
19105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
19125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        hdi = (disc & BTA_AV_HNDL_MSK) - 1;
19145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_scb = p_cb->p_scb[hdi];
19155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_scb)
19175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1918e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            APPL_TRACE_DEBUG("rc_handle %d", p_scb->rc_handle);
19195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_addr = p_scb->peer_addr;
19205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
19215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_addr)
19245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* allocate discovery database */
19265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->p_disc_db == NULL)
19275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
19285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(BTA_AV_DISC_BUF_SIZE);
19295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
19305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->p_disc_db)
19325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
19335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* set up parameters */
19345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            db_params.db_len = BTA_AV_DISC_BUF_SIZE;
19355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            db_params.num_attr = 3;
19365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            db_params.p_db = p_cb->p_disc_db;
19375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            db_params.p_attrs = attr_list;
19385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* searching for UUID_SERVCLASS_AV_REMOTE_CONTROL gets both TG and CT */
19405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (AVRC_FindService(UUID_SERVCLASS_AV_REMOTE_CONTROL, p_addr, &db_params,
19415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            bta_av_avrc_sdp_cback) == AVRC_SUCCESS)
19425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
19435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_cb->disc = disc;
1944e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                APPL_TRACE_DEBUG("disc %d", p_cb->disc);
19455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
19465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
19475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
19495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
19515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_av_dereg_comp
19535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      deregister complete. free the stream control block.
19555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
19575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
19595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_av_dereg_comp(tBTA_AV_DATA *p_data)
19605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
19615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_CB   *p_cb = &bta_av_cb;
19625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_AV_SCB  *p_scb;
19635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_UTL_COD    cod;
19645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   mask;
19655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BT_HDR  *p_buf;
19665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* find the stream control block */
19685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific);
19695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if(p_scb)
19715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1972e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        APPL_TRACE_DEBUG("deregistered %d(h%d)", p_scb->chnl, p_scb->hndl);
19735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        mask = BTA_AV_HNDL_TO_MSK(p_scb->hdi);
19745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if(p_scb->chnl == BTA_AV_CHNL_AUDIO)
19755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
19765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->reg_audio  &= ~mask;
19775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((p_cb->conn_audio & mask) && bta_av_cb.audio_open_cnt)
19785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
19795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* this channel is still marked as open. decrease the count */
19805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_av_cb.audio_open_cnt--;
19815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
19825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->conn_audio &= ~mask;
19835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_scb->q_tag == BTA_AV_Q_TAG_STREAM)
19855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
19865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* make sure no buffers are in q_info.a2d */
19875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            while((p_buf = (BT_HDR*)GKI_dequeue (&p_scb->q_info.a2d)) != NULL)
19885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                GKI_freebuf(p_buf);
19895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
19905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* remove the A2DP SDP record, if no more audio stream is left */
19925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(!p_cb->reg_audio)
19935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
19945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
19955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_ar_dereg_avrc (UUID_SERVCLASS_AV_REMOTE_CONTROL, BTA_ID_AV);
19965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
19975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_av_del_sdp_rec(&p_cb->sdp_a2d_handle);
19985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SOURCE);
1999f7dd9f5779680da37dc89e5df2b26d436487818cHemant Gupta
20006718c6d9fcfe373a679a529aca003d32062f81dclungtsai_lin#if (BTA_AV_SINK_INCLUDED == TRUE)
2001f7dd9f5779680da37dc89e5df2b26d436487818cHemant Gupta                bta_av_del_sdp_rec(&p_cb->sdp_a2d_snk_handle);
2002f7dd9f5779680da37dc89e5df2b26d436487818cHemant Gupta                bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SINK);
2003f7dd9f5779680da37dc89e5df2b26d436487818cHemant Gupta#endif
20045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
20055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
20065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
20075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
20085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->reg_video  &= ~mask;
20095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* make sure that this channel is not connected */
20105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->conn_video &= ~mask;
20115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* remove the VDP SDP record, (only one video stream at most) */
20125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_av_del_sdp_rec(&p_cb->sdp_vdp_handle);
20135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_sys_remove_uuid(UUID_SERVCLASS_VIDEO_SOURCE);
20145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
20155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
20165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* make sure that the timer is not active */
20175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source P