/******************************************************************************* ** ** 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_WARNING1 ("RFCOMM_DisconnectInd LCID:0x%x", lcid); return; } rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_DISC_IND, NULL); }
/******************************************************************************* ** ** Function rfc_check_send_cmd ** ** Description This function is called to send an RFCOMM command message ** or to handle the RFCOMM command message queue. ** ** Returns void ** *******************************************************************************/ void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf) { BT_HDR *p; /* if passed a buffer queue it */ if (p_buf != NULL) { if (p_mcb->cmd_q == NULL) { RFCOMM_TRACE_ERROR("%s: empty queue: p_mcb = %p p_mcb->lcid = %u cached p_mcb = %p", __func__, p_mcb, p_mcb->lcid, rfc_find_lcid_mcb(p_mcb->lcid)); } fixed_queue_enqueue(p_mcb->cmd_q, p_buf); } /* handle queue if L2CAP not congested */ while (p_mcb->l2cap_congested == FALSE) { if ((p = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q)) == NULL) { break; } L2CA_DataWrite (p_mcb->lcid, p); } }
/******************************************************************************* ** ** 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); }
/******************************************************************************* ** ** 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); }