Example #1
0
/*******************************************************************************
**
** Function         bta_ag_sm_execute
**
** Description      State machine event handling function for AG
**
**
** Returns          void
**
*******************************************************************************/
void bta_ag_sm_execute(tBTA_AG_SCB *p_scb, UINT16 event, tBTA_AG_DATA *p_data)
{
    tBTA_AG_ST_TBL      state_table;
    UINT8               action;
    int                 i;

#if BTA_AG_DEBUG == TRUE
    UINT16  in_event = event;
    UINT8   in_state = p_scb->state;

    /* Ignore displaying of AT results when not connected (Ignored in state machine) */
    if (in_event != BTA_AG_API_RESULT_EVT || p_scb->state == BTA_AG_OPEN_ST)
    {
        APPL_TRACE_EVENT5("AG evt (hdl 0x%04x): State %d (%s), Event 0x%04x (%s)",
                           bta_ag_scb_to_idx(p_scb),
                           p_scb->state, bta_ag_state_str(p_scb->state),
                           event, bta_ag_evt_str(event, p_data->api_result.result));
    }
#else
    APPL_TRACE_EVENT3("AG evt (hdl 0x%04x): State %d, Event 0x%04x",
                      bta_ag_scb_to_idx(p_scb), p_scb->state, event);
#endif

    event &= 0x00FF;
    if (event >= (BTA_AG_MAX_EVT & 0x00FF))
    {
        APPL_TRACE_ERROR0("AG evt out of range, ignoring...");
        return;
    }

    /* look up the state table for the current state */
    state_table = bta_ag_st_tbl[p_scb->state];

    /* set next state */
    p_scb->state = state_table[event][BTA_AG_NEXT_STATE];

    /* execute action functions */
    for (i = 0; i < BTA_AG_ACTIONS; i++)
    {
        if ((action = state_table[event][i]) != BTA_AG_IGNORE)
        {
            (*bta_ag_action[action])(p_scb, p_data);
        }
        else
        {
            break;
        }
    }
#if BTA_AG_DEBUG == TRUE
    if (p_scb->state != in_state)
    {
        APPL_TRACE_EVENT3("BTA AG State Change: [%s] -> [%s] after Event [%s]",
                      bta_ag_state_str(in_state),
                      bta_ag_state_str(p_scb->state),
                      bta_ag_evt_str(in_event, p_data->api_result.result));
    }
#endif
}
/*******************************************************************************
**
** Function         bta_pan_sm_execute
**
** Description      State machine event handling function for PAN
**
**
** Returns          void
**
*******************************************************************************/
static void bta_pan_sm_execute(tBTA_PAN_SCB *p_scb, UINT16 event, tBTA_PAN_DATA *p_data)
{
    tBTA_PAN_ST_TBL      state_table;
    UINT8               action;
    int                 i;

    APPL_TRACE_EVENT3("PAN scb=%d event=0x%x state=%d", bta_pan_scb_to_idx(p_scb), event, p_scb->state);

    /* look up the state table for the current state */
    state_table = bta_pan_st_tbl[p_scb->state];

    event &= 0x00FF;

    /* set next state */
    p_scb->state = state_table[event][BTA_PAN_NEXT_STATE];

    /* execute action functions */
    for (i = 0; i < BTA_PAN_ACTIONS; i++)
    {
        if ((action = state_table[event][i]) != BTA_PAN_IGNORE)
        {
            (*bta_pan_action[action])(p_scb, p_data);
        }
        else
        {
            break;
        }
    }
}
/*******************************************************************************
**
** Function         bta_ma_get_body_length
**
** Description      Returns the combined length in characters of the message
**                      content.
**
** Parameters       p_body - pointer to bBody structure.
**
** Returns          Length of the body message text.
**
*******************************************************************************/
UINT32 bta_ma_get_body_length(tBTA_MA_BMSG_BODY * p_body)
{
    UINT32 length = 0, len=0;
    tBTA_MA_BMSG_CONTENT * p_content;
    char * p_text;

    APPL_TRACE_EVENT0("bta_ma_get_body_length");

    p_content = BTA_MaBmsgGetContentFromBody(p_body);

    while ( p_content )
    {
        p_text= BTA_MaBmsgGetMsgContent(p_content);

        while ( p_text )
        {
            len = strlen(p_text);
            length += len;

            APPL_TRACE_EVENT3("total=%d len=%d text=%s",length, len, p_text);

            p_text = BTA_MaBmsgGetNextMsgContent(p_content);
        }

        p_content = BTA_MaBmsgGetNextContent(p_content);
    }

    APPL_TRACE_EVENT1("bta_ma_get_body_length len=%d", length);
    return( length );


}
Example #4
0
/*******************************************************************************
**
** Function         bta_hd_sm_execute
**
** Description      State machine event handling function for HID Device
**
** Returns          void
**
*******************************************************************************/
void bta_hd_sm_execute(UINT16 event, tBTA_HD_DATA * p_data)
{
    tBTA_HD_ST_TBL  state_table;
    tBTA_HD_STATE   prev_state;
    UINT8           action;
    tBTA_HD         cback_data;
    tBTA_HD_EVT     cback_event = 0;

    APPL_TRACE_EVENT5("%s: state=%s (%d) event=%s (%d)", __FUNCTION__,
        bta_hd_state_code(bta_hd_cb.state), bta_hd_cb.state,
        bta_hd_evt_code(event), event);

    prev_state = bta_hd_cb.state;

    memset(&cback_data, 0, sizeof(tBTA_HD));

    state_table = bta_hd_st_tbl[bta_hd_cb.state];

    event &= 0xff;

    if ((action = state_table[event][BTA_HD_ACTION]) != BTA_HD_IGNORE)
    {
        (*bta_hd_action[action])(p_data);
    }

    bta_hd_cb.state = state_table[event][BTA_HD_NEXT_STATE] ;

    if (bta_hd_cb.state != prev_state)
    {
        APPL_TRACE_EVENT3("%s: [new] state=%s (%d)", __FUNCTION__,
            bta_hd_state_code(bta_hd_cb.state), bta_hd_cb.state);
    }

    return;
}
Example #5
0
/*******************************************************************************
**
** Function         bta_hh_sdp_cback
**
** Description      SDP callback function.
**
** Returns          void
**
*******************************************************************************/
static void bta_hh_sdp_cback(UINT16 result, UINT16 attr_mask,
                                  tHID_DEV_SDP_INFO *sdp_rec )
{
    tBTA_HH_DEV_CB     *p_cb = bta_hh_cb.p_cur;
    UINT8              hdl;
    tBTA_HH_STATUS    status = BTA_HH_ERR_SDP;

    /* make sure sdp succeeded and hh has not been disabled */
    if ((result == SDP_SUCCESS) && (p_cb != NULL))
    {
        /* security is required for the connection, add attr_mask bit*/
        if (p_cb->sec_mask)
            attr_mask |= HID_SEC_REQUIRED;

#if BTA_HH_DEBUG
        APPL_TRACE_EVENT3("bta_hh_sdp_cback: p_cb: %d result 0x%02x, \
                            attr_mask 0x%02x", \
                            p_cb, result, attr_mask);
#endif

        /* check to see type of device is supported , and should not been added before */
        if (bta_hh_tod_spt(p_cb, sdp_rec->sub_class))
        {
            /* if not added before */
            if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
            {
                /*  add device/update attr_mask information */
                if(HID_HostAddDev (p_cb->addr, attr_mask, &hdl) == HID_SUCCESS)
                {
                    status = BTA_HH_OK;
                    /* update cb_index[] map */
                    bta_hh_cb.cb_index[hdl] = p_cb->index;
                }
                else
                {
                    p_cb->app_id = 0;
                }
            }
            /* else : incoming connection after SDP should update the SDP information as well */

            if (p_cb->app_id != 0)
            {
                /* update cb information with attr_mask, dscp_info etc. */
                bta_hh_add_device_to_list(p_cb,  hdl, attr_mask,
                                            &sdp_rec->dscp_info,
                                            sdp_rec->sub_class,
                                            sdp_rec->ssr_max_latency,
                                            sdp_rec->ssr_min_tout,
                                            p_cb->app_id);

                p_cb->dscp_info.ctry_code = sdp_rec->ctry_code;

                status = BTA_HH_OK;
            }

        }
        else /* type of device is not supported */
            status = BTA_HH_ERR_TOD_UNSPT;
    }

    /* free disc_db when SDP is completed */
    utl_freebuf((void **)&bta_hh_cb.p_disc_db);


    /* send SDP_CMPL_EVT into state machine */
    bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);

    return;
}
/*******************************************************************************
**
** Function         bta_hh_sm_execute
**
** Description      State machine event handling function for HID Host
**
**
** Returns          void
**
*******************************************************************************/
void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data)
{
    tBTA_HH_ST_TBL  state_table;
    UINT8           action;
    tBTA_HH         cback_data;
    tBTA_HH_EVT     cback_event = 0;
#if BTA_HH_DEBUG == TRUE
    tBTA_HH_STATE   in_state ;
    UINT16          debug_event = event;
#endif

    memset(&cback_data, 0, sizeof(tBTA_HH));

    /* handle exception, no valid control block was found */
    if (!p_cb)
    {
        /* BTA HH enabled already? otherwise ignore the event although it's bad*/
        if (bta_hh_cb.p_cback != NULL)
        {
            switch (event)
            {
            /* no control block available for new connection */
            case BTA_HH_API_OPEN_EVT:
                cback_event = BTA_HH_OPEN_EVT;
                /* build cback data */
                bdcpy(cback_data.conn.bda, ((tBTA_HH_API_CONN *)p_data)->bd_addr);
                cback_data.conn.status  = BTA_HH_ERR_DB_FULL;
                cback_data.conn.handle  = BTA_HH_INVALID_HANDLE;
                break;
            /* DB full, BTA_HhAddDev */
            case BTA_HH_API_MAINT_DEV_EVT:
                cback_event = p_data->api_maintdev.sub_event;

                if (p_data->api_maintdev.sub_event == BTA_HH_ADD_DEV_EVT)
                {
                    bdcpy(cback_data.dev_info.bda, p_data->api_maintdev.bda);
                    cback_data.dev_info.status    = BTA_HH_ERR_DB_FULL;
                    cback_data.dev_info.handle    = BTA_HH_INVALID_HANDLE;
                }
                else
                {
                    cback_data.dev_info.status    = BTA_HH_ERR_HDL;
                    cback_data.dev_info.handle    = (UINT8)p_data->api_maintdev.hdr.layer_specific;
                }
                break;
            case BTA_HH_API_WRITE_DEV_EVT:
                cback_event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) +
                        BTA_HH_FST_TRANS_CB_EVT;
                if (p_data->api_sndcmd.p_data != NULL)
                {
                    GKI_freebuf(p_data->api_sndcmd.p_data);
                }
                if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL ||
                    p_data->api_sndcmd.t_type == HID_TRANS_SET_REPORT ||
                    p_data->api_sndcmd.t_type == HID_TRANS_SET_IDLE)
                {
                    cback_data.dev_status.status = BTA_HH_ERR_HDL;
                    cback_data.dev_status.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific;
                }
                else if (p_data->api_sndcmd.t_type != HID_TRANS_DATA &&
                    p_data->api_sndcmd.t_type != HID_TRANS_CONTROL)
                {
                    cback_data.hs_data.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific;
                    cback_data.hs_data.status = BTA_HH_ERR_HDL;
                    /* hs_data.rsp_data will be all zero, which is not valid value */
                }
                else if (p_data->api_sndcmd.t_type == HID_TRANS_CONTROL &&
                         p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
                {
                    cback_data.status = BTA_HH_ERR_HDL;
                    cback_event = BTA_HH_VC_UNPLUG_EVT;
                }
                else
                    cback_event = 0;
                break;

            case BTA_HH_API_CLOSE_EVT:
                cback_event = BTA_HH_CLOSE_EVT;

                cback_data.dev_status.status = BTA_HH_ERR_HDL;
                cback_data.dev_status.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific;
                break;

            default:
                /* invalid handle, call bad API event */
                APPL_TRACE_ERROR1("wrong device handle: [%d]", p_data->hdr.layer_specific);
                break;
            }
           if (cback_event)
               (* bta_hh_cb.p_cback)(cback_event, &cback_data);
        }
    }
    /* corresponding CB is found, go to state machine */
    else
    {
#if BTA_HH_DEBUG == TRUE
        in_state = p_cb->state;
        APPL_TRACE_EVENT3("bta_hh_sm_execute: State 0x%02x [%s], Event [%s]",
                          in_state, bta_hh_state_code(in_state),
                          bta_hh_evt_code(debug_event));
#endif

        if ((p_cb->state == BTA_HH_NULL_ST) || (p_cb->state >= BTA_HH_INVALID_ST))
        {
            APPL_TRACE_ERROR2("bta_hh_sm_execute: Invalid state State = 0x%x, Event = %d",
                              p_cb->state,event);
            return;
        }
        state_table = bta_hh_st_tbl[p_cb->state - 1];

        event &= 0xff;

        p_cb->state = state_table[event][BTA_HH_NEXT_STATE] ;

        if ((action = state_table[event][BTA_HH_ACTION]) != BTA_HH_IGNORE)
        {
            (*bta_hh_action[action])(p_cb, p_data);
        }

#if BTA_HH_DEBUG == TRUE
        if (in_state != p_cb->state)
        {
            APPL_TRACE_DEBUG3("HH State Change: [%s] -> [%s] after Event [%s]",
                          bta_hh_state_code(in_state),
                          bta_hh_state_code(p_cb->state),
                          bta_hh_evt_code(debug_event));
        }
#endif
    }

    return;
}