Beispiel #1
0
/*******************************************************************************
**
** Function         bta_hh_api_disable
**
** Description      Perform necessary operations to disable HID host.
**
**
** Returns          void
**
*******************************************************************************/
void bta_hh_api_disable(void)
{
    UINT8 xx;

    /* service is not enabled */
    if (bta_hh_cb.p_cback == NULL)
        return;

    /* no live connection, signal DISC_CMPL_EVT directly */
    if (!bta_hh_cb.cnt_num)
    {
        bta_hh_disc_cmpl();
    }
    else /* otherwise, disconnect all live connections */
    {
        bta_hh_cb.w4_disable = TRUE;

        for(xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
        {
            /* send API_CLOSE event to every connected device */
            if ( bta_hh_cb.kdev[xx].state == BTA_HH_CONN_ST )
            {
                /* disconnect all connected devices */
                bta_hh_sm_execute(&bta_hh_cb.kdev[xx],
                                BTA_HH_API_CLOSE_EVT,
                                NULL);
            }
        }
    }

    return;
}
Beispiel #2
0
/*******************************************************************************
**
** Function         bta_hh_hdl_event
**
** Description      HID host main event handling function.
**
**
** Returns          void
**
*******************************************************************************/
BOOLEAN bta_hh_hdl_event(BT_HDR *p_msg)
{
    UINT8           index = BTA_HH_IDX_INVALID;
    tBTA_HH_DEV_CB *p_cb = NULL;

    switch (p_msg->event) {
    case BTA_HH_API_ENABLE_EVT:
        bta_hh_api_enable((tBTA_HH_DATA *) p_msg);
        break;

    case BTA_HH_API_DISABLE_EVT:
        bta_hh_api_disable();
        break;

    case BTA_HH_DISC_CMPL_EVT:          /* disable complete */
        bta_hh_disc_cmpl();
        break;

    default:
        /* all events processed in state machine need to find corresponding
            CB before proceed */
        if (p_msg->event == BTA_HH_API_OPEN_EVT) {
            index = bta_hh_find_cb(((tBTA_HH_API_CONN *)p_msg)->bd_addr);
        } else if (p_msg->event == BTA_HH_API_MAINT_DEV_EVT) {
            /* if add device */
            if (((tBTA_HH_MAINT_DEV *)p_msg)->sub_event == BTA_HH_ADD_DEV_EVT) {
                index = bta_hh_find_cb(((tBTA_HH_MAINT_DEV *)p_msg)->bda);
            } else { /* else remove device by handle */
                index = bta_hh_dev_handle_to_cb_idx((UINT8)p_msg->layer_specific);
// btla-specific ++
                /* If BT disable is done while the HID device is connected and Link_Key uses unauthenticated combination
                  * then we can get into a situation where remove_bonding is called with the index set to 0 (without getting
                  * cleaned up). Only when VIRTUAL_UNPLUG is called do we cleanup the index and make it MAX_KNOWN.
                  * So if REMOVE_DEVICE is called and in_use is FALSE then we should treat this as a NULL p_cb. Hence we
                  * force the index to be IDX_INVALID
                  */
                if ((index != BTA_HH_IDX_INVALID) &&
                        (bta_hh_cb.kdev[index].in_use == FALSE)) {
                    index = BTA_HH_IDX_INVALID;
                }
// btla-specific --
            }
        } else if (p_msg->event == BTA_HH_INT_OPEN_EVT) {
            index = bta_hh_find_cb(((tBTA_HH_CBACK_DATA *)p_msg)->addr);
        } else {
            index = bta_hh_dev_handle_to_cb_idx((UINT8)p_msg->layer_specific);
        }

        if (index != BTA_HH_IDX_INVALID) {
            p_cb = &bta_hh_cb.kdev[index];
        }

#if BTA_HH_DEBUG
        APPL_TRACE_DEBUG("bta_hh_hdl_event:: handle = %d dev_cb[%d] ", p_msg->layer_specific, index);
#endif
        bta_hh_sm_execute(p_cb, p_msg->event, (tBTA_HH_DATA *) p_msg);
    }
    return (TRUE);
}