コード例 #1
0
/*******************************************************************************
**
** Function         RFCOMM_ConfigCnf
**
** Description      This is a callback function called by L2CAP when
**                  L2CA_ConfigCnf received.  Save L2CAP handle and dispatch
**                  event to the FSM.
**
*******************************************************************************/
void RFCOMM_ConfigCnf (UINT16 lcid, tL2CAP_CFG_INFO *p_cfg)
{
    tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid);

    if (!p_mcb)
    {
        RFCOMM_TRACE_ERROR ("RFCOMM_ConfigCnf no MCB LCID:0x%x", lcid);
        return;
    }

    rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONF_CNF, (void *)p_cfg);
}
コード例 #2
0
ファイル: rfc_utils.c プロジェクト: danathughes/esp-idf
/*******************************************************************************
**
** Function         rfcomm_process_timeout
**
** Description      The function called every second to check RFCOMM timers
**
** Returns          void
**
*******************************************************************************/
void rfcomm_process_timeout (TIMER_LIST_ENT  *p_tle)
{
    switch (p_tle->event) {
    case BTU_TTYPE_RFCOMM_MFC:
        rfc_mx_sm_execute ((tRFC_MCB *)p_tle->param, RFC_EVENT_TIMEOUT, NULL);
        break;

    case BTU_TTYPE_RFCOMM_PORT:
        rfc_port_sm_execute ((tPORT *)p_tle->param, RFC_EVENT_TIMEOUT, NULL);
        break;

    default:
        break;
    }
}
コード例 #3
0
/*******************************************************************************
**
** Function         RFCOMM_DisconnectInd
**
** Description      This is a callback function called by L2CAP when
**                  L2CA_DisconnectInd received.  Dispatch event to the FSM.
**
*******************************************************************************/
void RFCOMM_DisconnectInd (UINT16 lcid, BOOLEAN is_conf_needed)
{
    tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid);

    if (is_conf_needed)
    {
        L2CA_DisconnectRsp (lcid);
    }

    if (!p_mcb)
    {
        RFCOMM_TRACE_WARNING ("RFCOMM_DisconnectInd LCID:0x%x", lcid);
        return;
    }

    rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_DISC_IND, NULL);
}
コード例 #4
0
/*******************************************************************************
**
** Function         RFCOMM_ConnectInd
**
** Description      This is a callback function called by L2CAP when
**                  L2CA_ConnectInd received.  Allocate multiplexer control block
**                  and dispatch the event to it.
**
*******************************************************************************/
void RFCOMM_ConnectInd (BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id)
{
    tRFC_MCB *p_mcb = rfc_alloc_multiplexer_channel(bd_addr, FALSE);
    UNUSED(psm);

    if ((p_mcb)&&(p_mcb->state != RFC_MX_STATE_IDLE))
    {
        /* if this is collision case */
        if ((p_mcb->is_initiator)&&(p_mcb->state == RFC_MX_STATE_WAIT_CONN_CNF))
        {
            p_mcb->pending_lcid = lcid;
            p_mcb->pending_id   = id;

            /* wait random timeout (2 - 12) to resolve collision */
            /* if peer gives up then local device rejects incoming connection and continues as initiator */
            /* if timeout, local device disconnects outgoing connection and continues as acceptor */
            RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectInd start timer for collision, initiator's LCID(0x%x), acceptor's LCID(0x%x)",
                                  p_mcb->lcid, p_mcb->pending_lcid);

            rfc_timer_start(p_mcb, (UINT16)(GKI_get_tick_count()%10 + 2));
            return;
        }
        else
        {
            /* we cannot accept connection request from peer at this state */
            /* don't update lcid */
            p_mcb = NULL;
        }
    }
    else
    {
        /* store mcb even if null */
        rfc_save_lcid_mcb (p_mcb, lcid);
    }

    if (p_mcb == NULL)
    {
        L2CA_ConnectRsp (bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0);
        return;
    }
    p_mcb->lcid     = lcid;

    rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &id);
}
コード例 #5
0
ファイル: rfc_utils.c プロジェクト: danathughes/esp-idf
/*******************************************************************************
**
** Function         rfc_check_mcb_active
**
** Description      Check if there are any opened ports on the MCB if not
**                  start MCB Inact timer.
**
** Returns          void
**
*******************************************************************************/
void rfc_check_mcb_active (tRFC_MCB *p_mcb)
{
    UINT16 i;

    for (i = 0; i < RFCOMM_MAX_DLCI; i++) {
        if (p_mcb->port_inx[i] != 0) {
            p_mcb->is_disc_initiator = FALSE;
            return;
        }
    }
    /* The last port was DISCed.  On the client side start disconnecting Mx */
    /* On the server side start inactivity timer */
    if (p_mcb->is_disc_initiator) {
        p_mcb->is_disc_initiator = FALSE;
        rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CLOSE_REQ, NULL);
    } else {
        rfc_timer_start (p_mcb, RFC_MCB_RELEASE_INACT_TIMER);
    }
}
コード例 #6
0
ファイル: rfc_port_if.c プロジェクト: Abocer/android-4.2_r1
/*******************************************************************************
**
** Function         RFCOMM_StartRsp
**
** Description      This function handles Start Response from the upper layer.
**                  Save upper layer handle and result of the Start Indication
**                  in the control block and dispatch event to the FSM.
**
*******************************************************************************/
void RFCOMM_StartRsp (tRFC_MCB *p_mcb, UINT16 result)
{
    rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_START_RSP, &result);
}
コード例 #7
0
ファイル: rfc_port_if.c プロジェクト: Abocer/android-4.2_r1
/*******************************************************************************
**
** Function         RFCOMM_StartReq
**
** Description      This function handles Start Request from the upper layer.
**                  If RFCOMM multiplexer channel can not be allocated
**                  send start not accepted confirmation.  Otherwise dispatch
**                  start event to the state machine.
**
*******************************************************************************/
void RFCOMM_StartReq (tRFC_MCB *p_mcb)
{
    rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_START_REQ, NULL);
}
コード例 #8
0
/*******************************************************************************
**
** Function         RFCOMM_BufDataInd
**
** Description      This is a callback function called by L2CAP when
**                  data RFCOMM frame is received.  Parse the frames, check
**                  the checksum and dispatch event to multiplexer or port
**                  state machine depending on the frame destination.
**
*******************************************************************************/
void RFCOMM_BufDataInd (UINT16 lcid, BT_HDR *p_buf)
{
    tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid);
    tPORT    *p_port;
    UINT8    event;


    if (!p_mcb)
    {
        RFCOMM_TRACE_WARNING ("RFCOMM_BufDataInd LCID:0x%x", lcid);
        GKI_freebuf (p_buf);
        return;
    }

    event = rfc_parse_data (p_mcb, &rfc_cb.rfc.rx_frame, p_buf);

    /* If the frame did not pass validation just ignore it */
    if (event == RFC_EVENT_BAD_FRAME)
    {
        GKI_freebuf (p_buf);
        return;
    }

    if (rfc_cb.rfc.rx_frame.dlci == RFCOMM_MX_DLCI)
    {
        /* Take special care of the Multiplexer Control Messages */
        if (event == RFC_EVENT_UIH)
        {
            rfc_process_mx_message (p_mcb, p_buf);
            return;
        }

        /* Other multiplexer events go to state machine */
        rfc_mx_sm_execute (p_mcb, event, NULL);
        GKI_freebuf (p_buf);
        return;
    }

    /* The frame was received on the data channel DLCI, verify that DLC exists */
    if (((p_port = port_find_mcb_dlci_port (p_mcb, rfc_cb.rfc.rx_frame.dlci)) == NULL)
     || (!p_port->rfc.p_mcb))
    {
        /* If this is a SABME on the new port, check if any appl is waiting for it */
        if (event != RFC_EVENT_SABME)
        {
            if (( p_mcb->is_initiator && !rfc_cb.rfc.rx_frame.cr)
             || (!p_mcb->is_initiator &&  rfc_cb.rfc.rx_frame.cr))
                rfc_send_dm (p_mcb, rfc_cb.rfc.rx_frame.dlci, rfc_cb.rfc.rx_frame.pf);
            GKI_freebuf (p_buf);
            return;
        }

        if ((p_port = port_find_dlci_port (rfc_cb.rfc.rx_frame.dlci)) == NULL)
        {
            rfc_send_dm (p_mcb, rfc_cb.rfc.rx_frame.dlci, TRUE);
            GKI_freebuf (p_buf);
            return;
        }
        p_mcb->port_inx[rfc_cb.rfc.rx_frame.dlci] = p_port->inx;
        p_port->rfc.p_mcb = p_mcb;
    }

    if (event == RFC_EVENT_UIH)
    {
        if (p_buf->len > 0)
            rfc_port_sm_execute (p_port, event, p_buf);
        else
            GKI_freebuf (p_buf);

        if (rfc_cb.rfc.rx_frame.credit != 0)
            rfc_inc_credit (p_port, rfc_cb.rfc.rx_frame.credit);

        return;
    }
    rfc_port_sm_execute (p_port, event,  NULL);
    GKI_freebuf (p_buf);
}
コード例 #9
0
/*******************************************************************************
**
** Function         RFCOMM_ConnectCnf
**
** Description      This is a callback function called by L2CAP when
**                  L2CA_ConnectCnf received.  Save L2CAP handle and dispatch
**                  event to the FSM.
**
*******************************************************************************/
void RFCOMM_ConnectCnf (UINT16 lcid, UINT16 result)
{
    tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid);

    if (!p_mcb)
    {
        RFCOMM_TRACE_ERROR ("RFCOMM_ConnectCnf LCID:0x%x", lcid);
        return;
    }

    if (p_mcb->pending_lcid)
    {
        /* if peer rejects our connect request but peer's connect request is pending */
        if (result != L2CAP_CONN_OK )
        {
            UINT16 i;
            UINT8  idx;

            RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectCnf retry as acceptor on pending LCID(0x%x)", p_mcb->pending_lcid);

            /* remove mcb from mapping table */
            rfc_save_lcid_mcb (NULL, p_mcb->lcid);

            p_mcb->lcid         = p_mcb->pending_lcid;
            p_mcb->is_initiator = FALSE;
            p_mcb->state        = RFC_MX_STATE_IDLE;

            /* store mcb into mapping table */
            rfc_save_lcid_mcb (p_mcb, p_mcb->lcid);

            /* update direction bit */
            for (i = 0; i < RFCOMM_MAX_DLCI; i += 2)
            {
                if ((idx = p_mcb->port_inx[i]) != 0)
                {
                    p_mcb->port_inx[i] = 0;
                    p_mcb->port_inx[i+1] = idx;
                    rfc_cb.port.port[idx - 1].dlci += 1;
                    RFCOMM_TRACE_DEBUG ("RFCOMM MX - DLCI:%d -> %d", i, rfc_cb.port.port[idx - 1].dlci);
                }
            }

            rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id));
            return;
        }
        else
        {
            RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectCnf peer gave up pending LCID(0x%x)", p_mcb->pending_lcid);

            /* Peer gave up his connection request, make sure cleaning up L2CAP channel */
            L2CA_ConnectRsp (p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, L2CAP_CONN_NO_RESOURCES, 0);

            p_mcb->pending_lcid = 0;
        }
    }

    /* Save LCID to be used in all consecutive calls to L2CAP */
    p_mcb->lcid         = lcid;

    rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_CNF, &result);
}
コード例 #10
0
ファイル: rfc_mx_fsm.c プロジェクト: Abocer/android-4.2_r1
/*******************************************************************************
**
** Function         rfc_mx_sm_state_wait_conn_cnf
**
** Description      This function handles events when the multiplexer is
**                  waiting for Connection Confirm from L2CAP.
**
** Returns          void
**
*******************************************************************************/
void rfc_mx_sm_state_wait_conn_cnf (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
{
    RFCOMM_TRACE_EVENT1 ("rfc_mx_sm_state_wait_conn_cnf - evt:%d", event);
    switch (event)
    {
    case RFC_MX_EVENT_START_REQ:
        RFCOMM_TRACE_ERROR2 ("Mx error state %d event %d", p_mcb->state, event);
        return;

    /* There is some new timing so that Config Ind comes before security is completed
       so we are still waiting fo the confirmation. */
    case RFC_MX_EVENT_CONF_IND:
        rfc_mx_conf_ind (p_mcb, (tL2CAP_CFG_INFO *)p_data);
        return;

    case RFC_MX_EVENT_CONN_CNF:
        if (*((UINT16 *)p_data) != L2CAP_SUCCESS)
        {
            p_mcb->state = RFC_MX_STATE_IDLE;

            PORT_StartCnf (p_mcb, *((UINT16 *)p_data));
            return;
        }
        p_mcb->state = RFC_MX_STATE_CONFIGURE;
        rfc_mx_send_config_req (p_mcb);
        return;

    case RFC_MX_EVENT_DISC_IND:
        p_mcb->state = RFC_MX_STATE_IDLE;
        PORT_CloseInd (p_mcb);
        return;

    case RFC_EVENT_TIMEOUT:
        p_mcb->state = RFC_MX_STATE_IDLE;
        L2CA_DisconnectReq (p_mcb->lcid);

        /* we gave up outgoing connection request then try peer's request */
        if (p_mcb->pending_lcid)
        {
            UINT16 i;
            UINT8  idx;

            RFCOMM_TRACE_DEBUG2 ("RFCOMM MX retry as acceptor in collision case - evt:%d in state:%d", event, p_mcb->state);

            rfc_save_lcid_mcb (NULL, p_mcb->lcid);
            p_mcb->lcid = p_mcb->pending_lcid;
            rfc_save_lcid_mcb (p_mcb, p_mcb->lcid);

            p_mcb->is_initiator = FALSE;

            /* update direction bit */
            for (i = 0; i < RFCOMM_MAX_DLCI; i += 2)
            {
                if ((idx = p_mcb->port_inx[i]) != 0)
                {
                    p_mcb->port_inx[i] = 0;
                    p_mcb->port_inx[i+1] = idx;
                    rfc_cb.port.port[idx - 1].dlci += 1;
                    RFCOMM_TRACE_DEBUG2 ("RFCOMM MX - DLCI:%d -> %d", i, rfc_cb.port.port[idx - 1].dlci);
                }
            }

            rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id));
        }
        else
        {
            PORT_CloseInd (p_mcb);
        }
        return;
    }
    RFCOMM_TRACE_EVENT2 ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
}