Exemplo n.º 1
0
/*******************************************************************************
**
** Function         bta_ag_api_result
**
** Description      Handle an API result event.
**
**
** Returns          void
**
*******************************************************************************/
static void bta_ag_api_result(tBTA_AG_DATA *p_data)
{
    tBTA_AG_SCB     *p_scb;
    int             i;

    if (p_data->hdr.layer_specific != BTA_AG_HANDLE_ALL)
    {
        if ((p_scb = bta_ag_scb_by_idx(p_data->hdr.layer_specific)) != NULL)
        {
            APPL_TRACE_DEBUG("bta_ag_api_result: p_scb 0x%08x ", p_scb);
            bta_ag_sm_execute(p_scb, BTA_AG_API_RESULT_EVT, p_data);
        }
    }
    else
    {
        for (i = 0, p_scb = &bta_ag_cb.scb[0]; i < BTA_AG_NUM_SCB; i++, p_scb++)
        {
            if (p_scb->in_use && p_scb->svc_conn)
            {
                APPL_TRACE_DEBUG("bta_ag_api_result p_scb 0x%08x ", p_scb);
                bta_ag_sm_execute(p_scb, BTA_AG_API_RESULT_EVT, p_data);
            }
        }
    }
}
/*******************************************************************************
**
** Function         bta_ag_sdp_cback
**
** Description      SDP callback function.
**
**
** Returns          void
**
*******************************************************************************/
static void bta_ag_sdp_cback(UINT16 status, UINT8 idx)
{
    tBTA_AG_DISC_RESULT *p_buf;
    UINT16              event;
    tBTA_AG_SCB         *p_scb;

    APPL_TRACE_DEBUG1("bta_ag_sdp_cback status:0x%x", status);

    if ((p_scb = bta_ag_scb_by_idx(idx)) != NULL)
    {
        /* set event according to int/acp */
        if (p_scb->role == BTA_AG_ACP)
        {
            event = BTA_AG_DISC_ACP_RES_EVT;
        }
        else
        {
            event = BTA_AG_DISC_INT_RES_EVT;
        }

        if ((p_buf = (tBTA_AG_DISC_RESULT *) GKI_getbuf(sizeof(tBTA_AG_DISC_RESULT))) != NULL)
        {
            p_buf->hdr.event = event;
            p_buf->hdr.layer_specific = idx;
            p_buf->status = status;
            bta_sys_sendmsg(p_buf);
        }
    }
}
Exemplo n.º 3
0
/*******************************************************************************
**
** Function         bta_ag_collision_cback
**
** Description      Get notified about collision.
**
**
** Returns          void
**
*******************************************************************************/
void bta_ag_collision_cback (tBTA_SYS_CONN_STATUS status, UINT8 id,
                                    UINT8 app_id, BD_ADDR peer_addr)
{
    UINT16  handle;
    tBTA_AG_SCB *p_scb;
    UNUSED(status);
    UNUSED(app_id);

    /* Check if we have opening scb for the peer device. */
    handle = bta_ag_idx_by_bdaddr (peer_addr);
    p_scb = bta_ag_scb_by_idx (handle);

    if (p_scb && (p_scb->state == BTA_AG_OPENING_ST))
    {
        if (id == BTA_ID_SYS)   /* ACL collision */
        {
            APPL_TRACE_WARNING ("AG found collision (ACL) ...");
        }
        else if (id == BTA_ID_AG)   /* RFCOMM collision */
        {
            APPL_TRACE_WARNING ("AG found collision (RFCOMM) ...");
        }
        else
        {
            APPL_TRACE_WARNING ("AG found collision (\?\?\?) ...");
        }

        p_scb->state = BTA_AG_INIT_ST;

        /* Cancel SDP if it had been started. */
        if(p_scb->p_disc_db)
        {
            (void)SDP_CancelServiceSearch (p_scb->p_disc_db);
            bta_ag_free_db(p_scb, NULL);
        }

        /* reopen registered servers */
        /* Collision may be detected before or after we close servers. */
        if (bta_ag_is_server_closed (p_scb))
            bta_ag_start_servers(p_scb, p_scb->reg_services);

        /* Start timer to han */
        p_scb->colli_timer.p_cback = (TIMER_CBACK*)&bta_ag_colli_timer_cback;
        p_scb->colli_timer.param = (INT32)p_scb;
        bta_sys_start_timer(&p_scb->colli_timer, 0, BTA_AG_COLLISION_TIMER);
        p_scb->colli_tmr_on = TRUE;
    }

}
Exemplo n.º 4
0
/*******************************************************************************
**
** Function         bta_ag_hdl_event
**
** Description      Data gateway main event handling function.
**
**
** Returns          BOOLEAN
**
*******************************************************************************/
BOOLEAN bta_ag_hdl_event(BT_HDR *p_msg)
{
    tBTA_AG_SCB *p_scb;

    APPL_TRACE_DEBUG("bta_ag_hdl_event: Event 0x%04x ", p_msg->event);
    switch (p_msg->event)
    {
        /* handle enable event */
        case BTA_AG_API_ENABLE_EVT:
            bta_ag_api_enable((tBTA_AG_DATA *) p_msg);
            break;

        /* handle disable event */
        case BTA_AG_API_DISABLE_EVT:
            bta_ag_api_disable((tBTA_AG_DATA *) p_msg);
            break;

        /* handle register event */
        case BTA_AG_API_REGISTER_EVT:
            bta_ag_api_register((tBTA_AG_DATA *) p_msg);
            break;

        /* handle result event */
        case BTA_AG_API_RESULT_EVT:
            bta_ag_api_result((tBTA_AG_DATA *) p_msg);
            break;

        /* all others reference scb by handle */
        default:
            if ((p_scb = bta_ag_scb_by_idx(p_msg->layer_specific)) != NULL)
            {
                APPL_TRACE_DEBUG("bta_ag_hdl_event: p_scb 0x%08x ", p_scb);
                bta_ag_sm_execute(p_scb, p_msg->event, (tBTA_AG_DATA *) p_msg);
            }
            break;
    }
    return TRUE;
}
Exemplo n.º 5
0
/*******************************************************************************
**
** Function         bta_ag_api_result
**
** Description      Handle an API result event.
**
**
** Returns          void
**
*******************************************************************************/
static void bta_ag_api_result(tBTA_AG_DATA *p_data)
{
    tBTA_AG_SCB     *p_scb;
    int             i;

    if (p_data->hdr.layer_specific != BTA_AG_HANDLE_ALL)
    {
        if ((p_scb = bta_ag_scb_by_idx(p_data->hdr.layer_specific)) != NULL)
        {
            bta_ag_sm_execute(p_scb, BTA_AG_API_RESULT_EVT, p_data);
        }
    }
    else
    {
        for (i = 0, p_scb = &bta_ag_cb.scb[0]; i < BTA_AG_NUM_SCB; i++, p_scb++)
        {
            if (p_scb->in_use)
            {
                bta_ag_sm_execute(p_scb, BTA_AG_API_RESULT_EVT, p_data);
            }
        }
    }
}
Exemplo n.º 6
0
/*******************************************************************************
**
** Function         bta_ag_port_cback
**
** Description      RFCOMM Port callback
**
**
** Returns          void
**
*******************************************************************************/
static void bta_ag_port_cback(UINT32 code, UINT16 port_handle, UINT16 handle)
{
    BT_HDR      *p_buf;
    tBTA_AG_SCB *p_scb;
    UNUSED(code);

    if ((p_scb = bta_ag_scb_by_idx(handle)) != NULL)
    {
        /* ignore port events for port handles other than connected handle */
        if (port_handle != p_scb->conn_handle)
        {
            APPL_TRACE_DEBUG("ag_port_cback ignoring handle:%d conn_handle = %d other handle = %d",
                              port_handle, p_scb->conn_handle, handle);
            return;
        }

        if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
        {
            p_buf->event = BTA_AG_RFC_DATA_EVT;
            p_buf->layer_specific = handle;
            bta_sys_sendmsg(p_buf);
        }
    }
}
Exemplo n.º 7
0
/*******************************************************************************
**
** Function         bta_ag_mgmt_cback
**
** Description      RFCOMM management callback
**
**
** Returns          void
**
*******************************************************************************/
static void bta_ag_mgmt_cback(UINT32 code, UINT16 port_handle, UINT16 handle)
{
    tBTA_AG_RFC     *p_buf;
    tBTA_AG_SCB     *p_scb;
    UINT16          event;
    UINT8           i;
    BOOLEAN         found_handle = FALSE;

    APPL_TRACE_DEBUG("ag_mgmt_cback : code = %d, port_handle = %d, handle = %d",
                        code, port_handle, handle);

    if ((p_scb = bta_ag_scb_by_idx(handle)) != NULL)
    {
        /* ignore close event for port handles other than connected handle */
        if ((code != PORT_SUCCESS) && (port_handle != p_scb->conn_handle))
        {
            APPL_TRACE_DEBUG("ag_mgmt_cback ignoring handle:%d", port_handle);
            return;
        }

        if (code == PORT_SUCCESS)
        {
            if (p_scb->conn_handle)     /* Outgoing connection */
            {
                if (port_handle == p_scb->conn_handle)
                    found_handle = TRUE;
            }
            else                        /* Incoming connection */
            {
                for (i = 0; i < BTA_AG_NUM_IDX; i++)
                {
                    if (port_handle == p_scb->serv_handle[i])
                        found_handle = TRUE;
                }
            }

            if (!found_handle)
            {
                APPL_TRACE_ERROR ("bta_ag_mgmt_cback: PORT_SUCCESS, ignoring handle = %d", port_handle);
                return;
            }

            event = BTA_AG_RFC_OPEN_EVT;
        }
        /* distinguish server close events */
        else if (port_handle == p_scb->conn_handle)
        {
            event = BTA_AG_RFC_CLOSE_EVT;
        }
        else
        {
            event = BTA_AG_RFC_SRV_CLOSE_EVT;
        }

        if ((p_buf = (tBTA_AG_RFC *) GKI_getbuf(sizeof(tBTA_AG_RFC))) != NULL)
        {
            p_buf->hdr.event = event;
            p_buf->hdr.layer_specific = handle;
            p_buf->port_handle = port_handle;
            bta_sys_sendmsg(p_buf);
        }
    }
}