Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1def2552 authored by Ganesh Ganapathi Batta's avatar Ganesh Ganapathi Batta Committed by Matthew Xie
Browse files

Initial version of BLE support for Bluedroid

Change-Id: I9825a5cef9be2559c34c2a529b211b7d471147cf
parent bf927c3c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -434,6 +434,7 @@ void *GKI_getbuf (UINT16 size)

    GKI_enable();

    GKI_exception (GKI_ERROR_OUT_OF_BUFFERS, "getbuf: out of buffers");
    return (NULL);
}

@@ -460,7 +461,10 @@ void *GKI_getpoolbuf (UINT8 pool_id)
    tGKI_COM_CB *p_cb = &gki_cb.com;

    if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS)
    {
        GKI_exception(GKI_ERROR_GETPOOLBUF_BAD_QID, "getpoolbuf bad pool");
        return (NULL);
    }

    /* Make sure the buffers aren't disturbed til finished with allocation */
    GKI_disable();
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@
#define GKI_ERROR_BUF_SIZE_TOOBIG       0xFFF7
#define GKI_ERROR_BUF_SIZE_ZERO         0xFFF6
#define GKI_ERROR_ADDR_NOT_IN_BUF       0xFFF5
#define GKI_ERROR_OUT_OF_BUFFERS        0xFFF4
#define GKI_ERROR_GETPOOLBUF_BAD_QID    0xFFF3


/********************************************************************
+111 −20
Original line number Diff line number Diff line
@@ -394,6 +394,16 @@ void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CT
            /* copy config params to event message buffer */
            switch (event)
            {
            case AVDT_RECONFIG_CFM_EVT:
            APPL_TRACE_DEBUG4("reconfig cfm event codec info = 0x%06x-%06x-%06x-%02x",
                (p_msg->msg.reconfig_cfm.p_cfg->codec_info[0]<<16)+(p_msg->msg.reconfig_cfm.p_cfg->codec_info[1]<<8)+p_msg->msg.reconfig_cfm.p_cfg->codec_info[2],
                (p_msg->msg.reconfig_cfm.p_cfg->codec_info[3]<<16)+(p_msg->msg.reconfig_cfm.p_cfg->codec_info[4]<<8)+p_msg->msg.reconfig_cfm.p_cfg->codec_info[5],
                (p_msg->msg.reconfig_cfm.p_cfg->codec_info[6]<<16)+(p_msg->msg.reconfig_cfm.p_cfg->codec_info[7]<<8)+p_msg->msg.reconfig_cfm.p_cfg->codec_info[8],
                p_msg->msg.reconfig_cfm.p_cfg->codec_info[9]);
            break;



            case AVDT_CONFIG_IND_EVT:
            /* We might have 2 SEP signallings(A2DP + VDP) with one peer device on one L2CAP.
             * If we already have a signalling connection with the bd_addr and the streaming
@@ -461,17 +471,16 @@ void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CT
        if (event == AVDT_SUSPEND_CFM_EVT)
            p_msg->initiator = TRUE;

        APPL_TRACE_EVENT1("hndl:x%x", p_scb->hndl);
        APPL_TRACE_VERBOSE1("hndl:x%x", p_scb->hndl);
        p_msg->hdr.layer_specific = p_scb->hndl;
        p_msg->handle   = handle;
        p_msg->avdt_event = event;
        bta_sys_sendmsg(p_msg);
    }

/* coverity[var_deref_model]: Variable "p_data" tracked as NULL was passed to function "bta_av_conn_cback" that dereferences it.
 * false-positive: bta_av_conn_cback only processes AVDT_CONNECT_IND_EVT and AVDT_DISCONNECT_IND_EVT event
 *                 these 2 events always have associated p_data
 */
/* coverity[var_deref_model] */
/* false-positive: bta_av_conn_cback only processes AVDT_CONNECT_IND_EVT and AVDT_DISCONNECT_IND_EVT event
 *                 these 2 events always have associated p_data */
    bta_av_conn_cback(handle, bd_addr, event, p_data);
}

@@ -486,7 +495,7 @@ void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CT
*******************************************************************************/
static void bta_av_stream0_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
{
    APPL_TRACE_EVENT2("bta_av_stream0_cback avdt_handle: %d event=0x%x", handle, event);
    APPL_TRACE_VERBOSE2("bta_av_stream0_cback avdt_handle: %d event=0x%x", handle, event);
    bta_av_proc_stream_evt(handle, bd_addr, event, p_data, 0);
}

@@ -1570,10 +1579,47 @@ void bta_av_cco_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
*******************************************************************************/
void bta_av_open_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
{

    BOOLEAN is_av_opened = FALSE;
    tBTA_AV_SCB * p_opened_scb = NULL;
    UINT8 idx;
    tBTA_AV_OPEN    open;

    APPL_TRACE_DEBUG0("bta_av_open_failed");
    p_scb->open_status = BTA_AV_FAIL_STREAM;
    bta_av_cco_close(p_scb, p_data);

    /* check whether there is already an opened audio or video connection with the same device */
    for (idx = 0; (idx < BTA_AV_NUM_STRS) && (is_av_opened == FALSE); idx++ )
    {
        p_opened_scb = bta_av_cb.p_scb[idx];
        if (p_opened_scb && (p_opened_scb->state == BTA_AV_OPEN_SST) && (!bdcmp(p_opened_scb->peer_addr,p_scb->peer_addr )) )
            is_av_opened = TRUE;

    }

    /* if there is already an active AV connnection with the same bd_addr,
       don't send disconnect req, just report the open event with BTA_AV_FAIL_GET_CAP status */
    if (is_av_opened == TRUE)
    {
        bdcpy(open.bd_addr, p_scb->peer_addr);
        open.chnl   = p_scb->chnl;
        open.hndl   = p_scb->hndl;
        open.status = BTA_AV_FAIL_GET_CAP;
        open.starting = bta_av_chk_start(p_scb);
        open.edr    = 0;
        /* set the state back to initial state */
        bta_av_set_scb_sst_init(p_scb);

        (*bta_av_cb.p_cback)(BTA_AV_OPEN_EVT, (tBTA_AV *) &open);

    }
    else
    {
        AVDT_DisconnectReq(p_scb->peer_addr, bta_av_dt_cback[p_scb->hdi]);
    }
}


/*******************************************************************************
**
@@ -1798,7 +1844,8 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
            AVDT_SuspendReq(&p_scb->avdt_handle, 1);
        }

        if(sus_evt)
        /* send SUSPEND_EVT event only if not in reconfiguring state and sus_evt is TRUE*/
        if ((sus_evt)&&(p_scb->state != BTA_AV_RCFG_SST))
        {
            suspend_rsp.status = BTA_AV_SUCCESS;
            suspend_rsp.initiator = TRUE;
@@ -1811,9 +1858,13 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        suspend_rsp.initiator = TRUE;
        APPL_TRACE_EVENT1("bta_av_str_stopped status %d", suspend_rsp.status);

        /* send STOP_EVT event only if not in reconfiguring state */
        if (p_scb->state != BTA_AV_RCFG_SST)
        {
            (*bta_av_cb.p_cback)(BTA_AV_STOP_EVT, (tBTA_AV *) &suspend_rsp);
        }
    }
}

/*******************************************************************************
**
@@ -1916,6 +1967,7 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    UINT32  timestamp;
    BOOLEAN new_buf = FALSE;
    UINT8   m_pt = 0x60 | p_scb->codec_type;
    tAVDT_DATA_OPT_MASK     opt;

    if (!p_scb->cong)
    {
@@ -1958,7 +2010,15 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
                /*
                APPL_TRACE_ERROR1("qw: %d", p_scb->l2c_bufs);
                */
                AVDT_WriteReq(p_scb->avdt_handle, p_buf, timestamp, m_pt);

                /* opt is a bit mask, it could have several options set */
                opt = AVDT_DATA_OPT_NONE;
                if (p_scb->no_rtp_hdr)
                {
                    opt |= AVDT_DATA_OPT_NO_RTP;
                }

                AVDT_WriteReqOpt(p_scb->avdt_handle, p_buf, timestamp, m_pt, opt);
                p_scb->cong = TRUE;
            }
            else
@@ -2008,6 +2068,8 @@ void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    UINT16          flush_to;
    UINT8           new_role = p_scb->role;
    BT_HDR          hdr;
    UINT8           policy = HCI_ENABLE_SNIFF_MODE;
    UINT8           cur_role;

    APPL_TRACE_DEBUG2("bta_av_start_ok wait:x%x, role:x%x", p_scb->wait, p_scb->role);

@@ -2111,11 +2173,27 @@ void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    }

    {
        /* If sink starts stream, disable sniff mode here */
        if (!initiator)
        {
             /* If souce is the master role, disable role switch during streaming.
             * Otherwise allow role switch, if source is slave.
             * Because it would not hurt source, if the peer device wants source to be master */
            if ((BTM_GetRole (p_scb->peer_addr, &cur_role) == BTM_SUCCESS) &&
                (cur_role == BTM_ROLE_MASTER) )
            {
                policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
            }

            bta_sys_clear_policy(BTA_ID_AV, policy, p_scb->peer_addr);
        }

        p_scb->role = new_role;
        p_scb->role &= ~BTA_AV_ROLE_AD_ACP;
        p_scb->role &= ~BTA_AV_ROLE_SUSPEND_OPT;

        p_scb->p_cos->start(p_scb->hndl, p_scb->codec_type);
        p_scb->no_rtp_hdr = FALSE;
        p_scb->p_cos->start(p_scb->hndl, p_scb->codec_type, p_scb->cfg.codec_info, &p_scb->no_rtp_hdr);
        p_scb->co_started = TRUE;

        APPL_TRACE_DEBUG3("bta_av_start_ok suspending: %d, role:x%x, init %d",
@@ -2270,8 +2348,12 @@ void bta_av_suspend_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)

    suspend_rsp.status = BTA_AV_SUCCESS;
    if (err_code)
    {
         /* Disable suspend feature only with explicit rejection(not with timeout) */
        if (err_code != AVDT_ERR_TIMEOUT)
        {
            p_scb->suspend_sup = FALSE;
        }
        suspend_rsp.status = BTA_AV_FAIL;

        APPL_TRACE_ERROR0 ("bta_av_suspend_cfm: suspend failed, closing connection");
@@ -2472,8 +2554,11 @@ void bta_av_suspend_cont (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        else
        {
            APPL_TRACE_ERROR0("suspend rejected, try close");
             /* Disable suspend feature only with explicit rejection(not with timeout) */
            if (err_code != AVDT_ERR_TIMEOUT)
            {
                p_scb->suspend_sup = FALSE;

            }
            /* drop the buffers queued in L2CAP */
            L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);

@@ -2510,7 +2595,11 @@ void bta_av_rcfg_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    if (err_code)
    {
        APPL_TRACE_ERROR0("reconfig rejected, try close");
         /* Disable reconfiguration feature only with explicit rejection(not with timeout) */
        if (err_code != AVDT_ERR_TIMEOUT)
        {
            p_scb->recfg_sup = FALSE;
        }
        /* started flag is FALSE when reconfigure command is sent */
        /* drop the buffers queued in L2CAP */
        L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
@@ -2518,6 +2607,8 @@ void bta_av_rcfg_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    }
    else
    {
        /* update the codec info after rcfg cfm */
        memcpy(p_scb->cfg.codec_info,p_data->str_msg.msg.reconfig_cfm.p_cfg->codec_info,AVDT_CODEC_SIZE);
        /* take the SSM back to OPEN state */
        bta_av_ssm_execute(p_scb, BTA_AV_STR_OPEN_OK_EVT, NULL);
    }
+55 −30
Original line number Diff line number Diff line
@@ -363,7 +363,7 @@ UINT8 bta_av_rc_create(tBTA_AV_CB *p_cb, UINT8 role, UINT8 shdl, UINT8 lidx)
** Returns          BTA_AV_RSP_ACCEPT or BTA_AV_RSP_NOT_IMPL.
**
*******************************************************************************/
static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data)
static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data, BOOLEAN is_inquiry)
{
    tBTA_AV_CODE ret=BTA_AV_RSP_NOT_IMPL;
    UINT8 *p_ptr = p_data;
@@ -376,6 +376,13 @@ static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data)
        BE_STREAM_TO_UINT16(u16, p_ptr);

        if (u32 == AVRC_CO_METADATA)
        {
            if (is_inquiry)
            {
                if (u16 <= AVRC_PDU_PREV_GROUP)
                    ret = BTA_AV_RSP_IMPL_STBL;
            }
            else
            {
                if (u16 <= AVRC_PDU_PREV_GROUP)
                    ret = BTA_AV_RSP_ACCEPT;
@@ -383,6 +390,7 @@ static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data)
                    ret = BTA_AV_RSP_REJ;
            }
        }
    }

    return ret;
}
@@ -396,11 +404,20 @@ static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data)
** Returns          BTA_AV_RSP_ACCEPT of supported, BTA_AV_RSP_NOT_IMPL if not.
**
*******************************************************************************/
static tBTA_AV_CODE bta_av_op_supported(tBTA_AV_RC rc_id)
static tBTA_AV_CODE bta_av_op_supported(tBTA_AV_RC rc_id, BOOLEAN is_inquiry)
{
    tBTA_AV_CODE ret_code = BTA_AV_RSP_NOT_IMPL;

    if (p_bta_av_rc_id)
    {
        if (is_inquiry)
        {
            if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F)))
            {
                ret_code = BTA_AV_RSP_IMPL_STBL;
            }
        }
        else
        {
            if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F)))
            {
@@ -414,6 +431,8 @@ static tBTA_AV_CODE bta_av_op_supported(tBTA_AV_RC rc_id)
                }
            }
        }

    }
    return ret_code;
}

@@ -824,11 +843,15 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
    tBTA_AV     av;
    BT_HDR      *p_pkt = NULL;
    tAVRC_MSG_VENDOR    *p_vendor = &p_data->rc_msg.msg.vendor;
    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);

    if (p_data->rc_msg.opcode == AVRC_OP_PASS_THRU)
    {
    /* if this is a pass thru command */
        if (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_CTRL)
        if ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_CTRL) ||
            (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) ||
            (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ)
            )
        {
        /* check if operation is supported */
            if (p_data->rc_msg.msg.pass.op_id == AVRC_ID_VENDOR)
@@ -837,9 +860,11 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
            }
            else
            {
                p_data->rc_msg.msg.hdr.ctype = bta_av_op_supported(p_data->rc_msg.msg.pass.op_id);
                p_data->rc_msg.msg.hdr.ctype = bta_av_op_supported(p_data->rc_msg.msg.pass.op_id, is_inquiry);
            }

            APPL_TRACE_DEBUG1("ctype %d",p_data->rc_msg.msg.hdr.ctype)

            /* send response */
            if (p_data->rc_msg.msg.hdr.ctype != BTA_AV_RSP_INTERIM)
                AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass);
@@ -1335,17 +1360,10 @@ void bta_av_sig_chg(tBTA_AV_DATA *p_data)
            {
                mask = 1 << xx;
                APPL_TRACE_DEBUG1("conn_lcb: 0x%x", p_cb->conn_lcb);
                if(!(mask & p_cb->conn_lcb))
                {
                    if (!p_cb->p_scb[xx])
                    {
                        /* We do not have scb for this avdt connection.     */
                        /* Silently close the connection.                   */
                        APPL_TRACE_ERROR0("av scb not available for avdt connection");
                        AVDT_DisconnectReq (p_data->str_msg.bd_addr, NULL);
                        return;
                    }

                /* look for a p_lcb with its p_scb registered */
                if((!(mask & p_cb->conn_lcb)) && (p_cb->p_scb[xx] != NULL))
                {
                    p_lcb = &p_cb->lcb[xx];
                    p_lcb->lidx = xx + 1;
                    bdcpy(p_lcb->addr, p_data->str_msg.bd_addr);
@@ -1382,6 +1400,16 @@ void bta_av_sig_chg(tBTA_AV_DATA *p_data)
                    break;
                }
            }

            /* check if we found something */
            if (xx == BTA_AV_NUM_LINKS)
            {
                /* We do not have scb for this avdt connection.     */
                /* Silently close the connection.                   */
                APPL_TRACE_ERROR0("av scb not available for avdt connection");
                AVDT_DisconnectReq (p_data->str_msg.bd_addr, NULL);
                return;
            }
        }
    }
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
@@ -1516,9 +1544,10 @@ static void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle)
**
** Function         bta_av_check_peer_features
**
** Description      checks
** Description      check supported features on the peer device from the SDP record
**                  and return the feature mask
**
** Returns          void
** Returns          tBTA_AV_FEAT peer device feature mask
**
*******************************************************************************/
tBTA_AV_FEAT bta_av_check_peer_features (UINT16 service_uuid)
@@ -1624,13 +1653,9 @@ void bta_av_rc_disc_done(tBTA_AV_DATA *p_data)
    }

    APPL_TRACE_DEBUG1("rc_handle %d", rc_handle);
    /* check peer version and whether support CT and TG role */
    peer_features = bta_av_check_peer_features (UUID_SERVCLASS_AV_REMOTE_CONTROL);
    if ((p_cb->features & BTA_AV_FEAT_ADV_CTRL) && ((peer_features&BTA_AV_FEAT_ADV_CTRL) == 0))
    {
        /* if we support advance control and peer does not, check their support on TG role
         * some implementation uses 1.3 on CT ans 1.4 on TG */
    peer_features |= bta_av_check_peer_features (UUID_SERVCLASS_AV_REM_CTRL_TARGET);
    }

    p_cb->disc = 0;
    utl_freebuf((void **) &p_cb->p_disc_db);
+0 −33
Original line number Diff line number Diff line
@@ -78,39 +78,6 @@ const UINT8 bta_av_meta_caps_evt_ids[] = {
#define BTA_AV_NUM_RC_EVT_IDS   (sizeof(bta_av_meta_caps_evt_ids) / sizeof(bta_av_meta_caps_evt_ids[0]))
#endif /* BTA_AV_NUM_RC_EVT_IDS */


#else /* !ANDROID_APP_INCLUDED */

/* Note: if AVRC_SUPF_TG_GROUP_NAVI is set, bta_av_cfg.avrc_group should be TRUE */
#define BTA_AV_RC_SUPF_TG       (AVRC_SUPF_TG_CAT1)

const UINT16  bta_av_audio_flush_to[] = {
    120, /* 1 stream  */
    100, /* 2 streams */
     80, /* 3 streams */
     60, /* 4 streams */
     40  /* 5 streams */
};     /* AVDTP audio transport channel flush timeout */


/*
 * If the number of event IDs is changed in this array, BTA_AV_ NUM_RC_EVT_IDS   also needs to be changed.
 */
const UINT8  bta_av_meta_caps_evt_ids[] = {
    AVRC_EVT_PLAY_STATUS_CHANGE,
    AVRC_EVT_TRACK_CHANGE,
    AVRC_EVT_TRACK_REACHED_END,
    AVRC_EVT_TRACK_REACHED_START,
    AVRC_EVT_PLAY_POS_CHANGED,
    AVRC_EVT_BATTERY_STATUS_CHANGE,
    AVRC_EVT_SYSTEM_STATUS_CHANGE,
    AVRC_EVT_APP_SETTING_CHANGE,
};

#ifndef BTA_AV_NUM_RC_EVT_IDS
#define BTA_AV_NUM_RC_EVT_IDS   8
#endif

#endif /* ANDROID_APP_INCLUDED */

/* the MTU for the AVRCP browsing channel */
Loading