/*******************************************************************************
**
** Function         bta_hd_hdl_event
**
** Description      HID device main event handling function.
**
** Returns          void
**
*******************************************************************************/
BOOLEAN bta_hd_hdl_event(BT_HDR *p_msg)
{
    tBTA_HD_CBACK_DATA  *p_data = (tBTA_HD_CBACK_DATA *) p_msg;

    APPL_TRACE_API("%s: p_msg->event=%d", __FUNCTION__, p_msg->event);

    switch (p_msg->event)
    {
        case BTA_HD_API_ENABLE_EVT:
            bta_hd_api_enable((tBTA_HD_DATA *) p_msg);
            break;

        case BTA_HD_API_DISABLE_EVT:
            if (bta_hd_cb.state == BTA_HD_CONN_ST)
            {
                APPL_TRACE_WARNING("%s: host connected, need to "
                    "disconnect before disabling", __FUNCTION__);

                // unregister (and disconnect)
                bta_hd_cb.disable_w4_close = TRUE;
                bta_hd_sm_execute(BTA_HD_API_UNREGISTER_APP_EVT,
                    (tBTA_HD_DATA *) p_msg);
            }
            else
            {
                bta_hd_api_disable();
            }
            break;

        default:
            bta_hd_sm_execute(p_msg->event, (tBTA_HD_DATA *) p_msg);
    }
    return (TRUE);
}
示例#2
0
/*******************************************************************************
**
** Function         BTA_HdRegisterApp
**
** Description      This function is called when application should be registered
**
** Returns          void
**
*******************************************************************************/
extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO *p_app_info, tBTA_HD_QOS_INFO *p_in_qos,
                                            tBTA_HD_QOS_INFO *p_out_qos)
{
    tBTA_HD_REGISTER_APP *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    if ((p_buf = (tBTA_HD_REGISTER_APP *) GKI_getbuf(sizeof(tBTA_HD_REGISTER_APP))) != NULL)
    {
        p_buf->hdr.event = BTA_HD_API_REGISTER_APP_EVT;

        if (p_app_info->p_name)
        {
            BCM_STRNCPY_S(p_buf->name, sizeof(p_buf->name),
                p_app_info->p_name, BTA_HD_APP_NAME_LEN);
            p_buf->name[BTA_HD_APP_NAME_LEN] = '\0';
        }
        else
        {
            p_buf->name[0]= '\0';
        }

        if (p_app_info->p_description)
        {
            BCM_STRNCPY_S(p_buf->description, sizeof(p_buf->description), p_app_info->p_description,
                BTA_HD_APP_DESCRIPTION_LEN);
            p_buf->description[BTA_HD_APP_DESCRIPTION_LEN] = '\0';
        }
        else
        {
            p_buf->description[0]= '\0';
        }

        if (p_app_info->p_provider)
        {
            BCM_STRNCPY_S(p_buf->provider, sizeof(p_buf->provider), p_app_info->p_provider,
                BTA_HD_APP_PROVIDER_LEN);
            p_buf->provider[BTA_HD_APP_PROVIDER_LEN] = '\0';
        }
        else
        {
            p_buf->provider[0]= '\0';
        }

        p_buf->subclass = p_app_info->subclass;

        p_buf->d_len = p_app_info->descriptor.dl_len;
        memcpy(p_buf->d_data, p_app_info->descriptor.dsc_list, p_app_info->descriptor.dl_len);

        // copy qos data as-is
        memcpy(&p_buf->in_qos, p_in_qos, sizeof(tBTA_HD_QOS_INFO));
        memcpy(&p_buf->out_qos, p_out_qos, sizeof(tBTA_HD_QOS_INFO));

        bta_sys_sendmsg(p_buf);
    }
}
示例#3
0
/*******************************************************************************
**
** Function         BTA_HdDisconnect
**
** Description      This function is called when host shall be disconnected
**
** Returns          void
**
*******************************************************************************/
extern void BTA_HdDisconnect(void)
{
    BT_HDR *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
    {
        p_buf->event = BTA_HD_API_DISCONNECT_EVT;

        bta_sys_sendmsg(p_buf);
    }
}
示例#4
0
/*******************************************************************************
**
** Function         BTA_HdVirtualCableUnplug
**
** Description      This function is called when VCU shall be sent
**
** Returns          void
**
*******************************************************************************/
extern void BTA_HdVirtualCableUnplug(void)
{
    BT_HDR *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
    {
        p_buf->event = BTA_HD_API_VC_UNPLUG_EVT;

        bta_sys_sendmsg(p_buf);
    }
}
示例#5
0
/*******************************************************************************
**
** Function         BTA_HdUnregisterApp
**
** Description      This function is called when application should be unregistered
**
** Returns          void
**
*******************************************************************************/
extern void BTA_HdUnregisterApp(void)
{
    BT_HDR *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
    {
        p_buf->event = BTA_HD_API_UNREGISTER_APP_EVT;

        bta_sys_sendmsg(p_buf);
    }
}
示例#6
0
/*******************************************************************************
**
** Function         BTA_HdDisable
**
** Description      Disables HID device.
**
** Returns          void
**
*******************************************************************************/
void BTA_HdDisable(void)
{
    BT_HDR  *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    bta_sys_deregister(BTA_ID_HD);

    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
    {
        p_buf->event = BTA_HD_API_DISABLE_EVT;
        bta_sys_sendmsg(p_buf);
    }
}
示例#7
0
/*******************************************************************************
**
** Function         BTA_HdReportError
**
** Description      This function is called when reporting error for set report
**
** Returns          void
**
*******************************************************************************/
extern void BTA_HdReportError(UINT8 error)
{
    tBTA_HD_REPORT_ERR *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    if ((p_buf = (tBTA_HD_REPORT_ERR *) GKI_getbuf(sizeof(tBTA_HD_REPORT_ERR))) != NULL)
    {
        p_buf->hdr.event = BTA_HD_API_REPORT_ERROR_EVT;
        p_buf->error = error;

        bta_sys_sendmsg(p_buf);
    }
}
示例#8
0
/*******************************************************************************
**
** Function         BTA_HdRemoveDevice
**
** Description      This function is called when a device is virtually uncabled
**
** Returns          void
**
*******************************************************************************/
extern void BTA_HdRemoveDevice(BD_ADDR addr)
{
    tBTA_HD_DEVICE_CTRL *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    if ((p_buf = (tBTA_HD_DEVICE_CTRL *) GKI_getbuf(sizeof(tBTA_HD_DEVICE_CTRL))) != NULL)
    {
        p_buf->hdr.event = BTA_HD_API_REMOVE_DEVICE_EVT;

        memcpy(p_buf->addr, addr, sizeof(BD_ADDR));

        bta_sys_sendmsg(p_buf);
    }
}
示例#9
0
/*******************************************************************************
**
** Function         BTA_SdpRemoveRecordByUser
**
** Description      This function is used to request a callback to remove a SDP
**                  record. The registered callback will be called with event
**                  BTA_SDP_REMOVE_RECORD_USER_EVT.
**
** Returns          BTA_SDP_SUCCESS, if the request is being processed.
**                  BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data)
{
    tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
    tBTA_SDP_API_RECORD_USER *p_msg;

    APPL_TRACE_API("%s\n", __FUNCTION__);
    if ((p_msg = (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
        p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
        p_msg->user_data = user_data;
        bta_sys_sendmsg(p_msg);
        ret = BTA_SDP_SUCCESS;
    }

    return (ret);
}
示例#10
0
/*******************************************************************************
**
** Function         BTA_SdpSearch
**
** Description      This function performs service discovery for a specific service
**                  on given peer device. When the operation is completed
**                  the tBTA_SDP_DM_CBACK callback function will be  called with
**                  a BTA_SDP_SEARCH_COMPLETE_EVT.
**
** Returns          BTA_SDP_SUCCESS, if the request is being processed.
**                  BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
{
    tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
    tBTA_SDP_API_SEARCH *p_msg;

    APPL_TRACE_API("%s\n", __FUNCTION__);
    if ((p_msg = (tBTA_SDP_API_SEARCH *)osi_malloc(sizeof(tBTA_SDP_API_SEARCH))) != NULL) {
        p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
        bdcpy(p_msg->bd_addr, bd_addr);
        //p_msg->uuid = uuid;
        memcpy(&(p_msg->uuid), uuid, sizeof(tSDP_UUID));
        bta_sys_sendmsg(p_msg);
        ret = BTA_SDP_SUCCESS;
    }

    return (ret);
}
示例#11
0
/*******************************************************************************
**
** Function         BTA_GATTC_SendIndConfirm
**
** Description      This function is called to send handle value confirmation.
**
** Parameters       conn_id - connection ID.
**                    p_char_id - characteristic ID to confirm.
**
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle)
{
    tBTA_GATTC_API_CONFIRM  *p_buf;

    APPL_TRACE_API("BTA_GATTC_SendIndConfirm conn_id=%d handle =0x%x",
                   conn_id, handle);

    if ((p_buf = (tBTA_GATTC_API_CONFIRM *) osi_malloc(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL) {
        memset(p_buf, 0, sizeof(tBTA_GATTC_API_CONFIRM));
        p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
        p_buf->hdr.layer_specific = conn_id;
        p_buf->handle = handle;

        bta_sys_sendmsg(p_buf);
    }
    return;

}
示例#12
0
/*******************************************************************************
**
** Function         BTA_HdEnable
**
** Description      Enables HID device
**
** Returns          void
**
*******************************************************************************/
void BTA_HdEnable(tBTA_HD_CBACK *p_cback)
{
    tBTA_HD_API_ENABLE *p_buf;

    APPL_TRACE_API("%s", __FUNCTION__);

    bta_sys_register(BTA_ID_HD, &bta_hd_reg);

    p_buf = (tBTA_HD_API_ENABLE *) GKI_getbuf((UINT16) sizeof(tBTA_HD_API_ENABLE));

    if (p_buf != NULL)
    {
        memset(p_buf, 0, sizeof(tBTA_HD_API_ENABLE));

        p_buf->hdr.event = BTA_HD_API_ENABLE_EVT;
        p_buf->p_cback = p_cback;

        bta_sys_sendmsg(p_buf);
    }
}
/*******************************************************************************
**
** Function         BTA_GATTC_SendIndConfirm
**
** Description      This function is called to send handle value confirmation.
**
** Parameters       conn_id - connection ID.
**                    p_char_id - characteristic ID to confirm.
**
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id)
{
    tBTA_GATTC_API_CONFIRM  *p_buf;

    APPL_TRACE_API("BTA_GATTC_SendIndConfirm conn_id=%d service uuid1=0x%x char uuid=0x%x",
                    conn_id, p_char_id->srvc_id.id.uuid.uu.uuid16, p_char_id->char_id.uuid.uu.uuid16);

    if ((p_buf = (tBTA_GATTC_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL)
    {
        memset(p_buf, 0, sizeof(tBTA_GATTC_API_CONFIRM));

        p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
        p_buf->hdr.layer_specific = conn_id;

        memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
        memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));

        bta_sys_sendmsg(p_buf);
    }
    return;

}
示例#14
0
/*******************************************************************************
**
** Function         BTA_SdpEnable
**
** Description      Enable the SDP search I/F service. When the enable
**                  operation is complete the callback function will be
**                  called with a BTA_SDP_ENABLE_EVT. This function must
**                  be called before other functions in the SDP search API are
**                  called.
**
** Returns          BTA_SDP_SUCCESS if successful.
**                  BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
{
    tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
    tBTA_SDP_API_ENABLE  *p_buf;

    APPL_TRACE_API("%s\n", __FUNCTION__);
    if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) {
        memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));

        /* register with BTA system manager */
        bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);

        if (p_cback &&
                (p_buf = (tBTA_SDP_API_ENABLE *) osi_malloc(sizeof(tBTA_SDP_API_ENABLE))) != NULL) {
            p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
            p_buf->p_cback = p_cback;
            bta_sys_sendmsg(p_buf);
            status = BTA_SDP_SUCCESS;
        }
    }
    return (status);
}
示例#15
0
/*******************************************************************************
**
** Function         bta_hf_client_create_sco
**
** Description
**
**
** Returns          void
**
*******************************************************************************/
static void bta_hf_client_sco_create(BOOLEAN is_orig)
{
    tBTM_STATUS       status;
    UINT8            *p_bd_addr = NULL;
    tBTM_ESCO_PARAMS params;

    APPL_TRACE_DEBUG("%s %d", __FUNCTION__, is_orig);

    /* Make sure this sco handle is not already in use */
    if (bta_hf_client_cb.scb.sco_idx != BTM_INVALID_SCO_INDEX)
    {
        APPL_TRACE_WARNING("%s: Index 0x%04x already in use", __FUNCTION__,
                            bta_hf_client_cb.scb.sco_idx);
        return;
    }

    params = bta_hf_client_esco_params[1];

    /* if initiating set current scb and peer bd addr */
    if (is_orig)
    {
        /* Attempt to use eSCO if remote host supports HFP >= 1.5 */
        if (bta_hf_client_cb.scb.peer_version >= HFP_VERSION_1_5 && !bta_hf_client_cb.scb.retry_with_sco_only)
        {
            BTM_SetEScoMode(BTM_LINK_TYPE_ESCO, &params);
            /* If ESCO or EDR ESCO, retry with SCO only in case of failure */
            if((params.packet_types & BTM_ESCO_LINK_ONLY_MASK)
               ||!((params.packet_types & ~(BTM_ESCO_LINK_ONLY_MASK | BTM_SCO_LINK_ONLY_MASK)) ^ BTA_HF_CLIENT_NO_EDR_ESCO))
            {
                bta_hf_client_cb.scb.retry_with_sco_only = TRUE;
                APPL_TRACE_API("Setting retry_with_sco_only to TRUE");
            }
        }
        else
        {
            if(bta_hf_client_cb.scb.retry_with_sco_only)
                APPL_TRACE_API("retrying with SCO only");
            bta_hf_client_cb.scb.retry_with_sco_only = FALSE;

            BTM_SetEScoMode(BTM_LINK_TYPE_SCO, &params);
        }

        /* tell sys to stop av if any */
        bta_sys_sco_use(BTA_ID_HS, 1, bta_hf_client_cb.scb.peer_addr);
    }
    else
    {
        bta_hf_client_cb.scb.retry_with_sco_only = FALSE;
    }

    p_bd_addr = bta_hf_client_cb.scb.peer_addr;

    status = BTM_CreateSco(p_bd_addr, is_orig, params.packet_types,
                           &bta_hf_client_cb.scb.sco_idx, bta_hf_client_sco_conn_cback,
                           bta_hf_client_sco_disc_cback);
    if (status == BTM_CMD_STARTED && !is_orig)
    {
        if(!BTM_RegForEScoEvts(bta_hf_client_cb.scb.sco_idx, bta_hf_client_esco_connreq_cback))
            APPL_TRACE_DEBUG("%s SCO registration success", __FUNCTION__);
    }

    APPL_TRACE_API("%s: orig %d, inx 0x%04x, status 0x%x, pkt types 0x%04x",
                      __FUNCTION__, is_orig, bta_hf_client_cb.scb.sco_idx,
                      status, params.packet_types);
}