/******************************************************************************* ** ** Function llcp_util_send_frmr ** ** Description Send FRMR PDU ** ** Returns tLLCP_STATUS ** *******************************************************************************/ tLLCP_STATUS llcp_util_send_frmr (tLLCP_DLCB *p_dlcb, UINT8 flags, UINT8 ptype, UINT8 sequence) { BT_HDR *p_msg; UINT8 *p; p_msg = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (p_msg) { p_msg->len = LLCP_PDU_FRMR_SIZE; p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; p = (UINT8 *) (p_msg + 1) + p_msg->offset; UINT16_TO_BE_STREAM (p, LLCP_GET_PDU_HEADER (p_dlcb->remote_sap, LLCP_PDU_FRMR_TYPE, p_dlcb->local_sap)); UINT8_TO_BE_STREAM (p, (flags << 4) | ptype); UINT8_TO_BE_STREAM (p, sequence); UINT8_TO_BE_STREAM (p, (p_dlcb->next_tx_seq << 4) | p_dlcb->next_rx_seq); UINT8_TO_BE_STREAM (p, (p_dlcb->rcvd_ack_seq << 4) | p_dlcb->sent_ack_seq); GKI_enqueue (&llcp_cb.lcb.sig_xmit_q, p_msg); llcp_link_check_send_data (); return LLCP_STATUS_SUCCESS; } else { LLCP_TRACE_ERROR0 ("llcp_util_send_frmr (): Out of resource"); return LLCP_STATUS_FAIL; } }
/******************************************************************************* ** ** Function llcp_util_send_connect ** ** Description Send CONNECT PDU ** ** Returns tLLCP_STATUS ** ******************************************************************************/ tLLCP_STATUS llcp_util_send_connect (tLLCP_DLCB *p_dlcb, tLLCP_CONNECTION_PARAMS *p_params) { BT_HDR *p_msg; UINT8 *p; UINT16 miu_len = 0, rw_len = 0, sn_len = 0; if (p_params->miu != LLCP_DEFAULT_MIU) { miu_len = 4; /* TYPE, LEN, 2 bytes MIU */ } if (p_params->rw != LLCP_DEFAULT_RW) { rw_len = 3; /* TYPE, LEN, 1 byte RW */ p_params->rw &= 0x0F; /* only 4 bits */ } if ((strlen (p_params->sn)) && (p_dlcb->remote_sap == LLCP_SAP_SDP)) { sn_len = (UINT16) (2 + strlen (p_params->sn)); /* TYPE, LEN, SN */ } p_msg = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (p_msg) { p_msg->len = LLCP_PDU_HEADER_SIZE + miu_len + rw_len + sn_len; p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; p = (UINT8 *) (p_msg + 1) + p_msg->offset; UINT16_TO_BE_STREAM (p, LLCP_GET_PDU_HEADER (p_dlcb->remote_sap, LLCP_PDU_CONNECT_TYPE, p_dlcb->local_sap)); if (miu_len) { UINT8_TO_BE_STREAM (p, LLCP_MIUX_TYPE); UINT8_TO_BE_STREAM (p, LLCP_MIUX_LEN); UINT16_TO_BE_STREAM (p, p_params->miu - LLCP_DEFAULT_MIU); } if (rw_len) { UINT8_TO_BE_STREAM (p, LLCP_RW_TYPE); UINT8_TO_BE_STREAM (p, LLCP_RW_LEN); UINT8_TO_BE_STREAM (p, p_params->rw); } if (sn_len) { UINT8_TO_BE_STREAM (p, LLCP_SN_TYPE); UINT8_TO_BE_STREAM (p, sn_len - 2); memcpy (p, p_params->sn, sn_len - 2); } GKI_enqueue (&llcp_cb.lcb.sig_xmit_q, p_msg); llcp_link_check_send_data (); return LLCP_STATUS_SUCCESS; } return LLCP_STATUS_FAIL; }
/******************************************************************************* ** ** Function llcp_util_send_ui ** ** Description Send UI PDU ** ** Returns tLLCP_STATUS ** *******************************************************************************/ tLLCP_STATUS llcp_util_send_ui (UINT8 ssap, UINT8 dsap, tLLCP_APP_CB *p_app_cb, BT_HDR *p_msg) { UINT8 *p; tLLCP_STATUS status = LLCP_STATUS_SUCCESS; p_msg->offset -= LLCP_PDU_HEADER_SIZE; p_msg->len += LLCP_PDU_HEADER_SIZE; p = (UINT8 *) (p_msg + 1) + p_msg->offset; UINT16_TO_BE_STREAM (p, LLCP_GET_PDU_HEADER (dsap, LLCP_PDU_UI_TYPE, ssap)); GKI_enqueue (&p_app_cb->ui_xmit_q, p_msg); llcp_cb.total_tx_ui_pdu++; llcp_link_check_send_data (); if ( (p_app_cb->is_ui_tx_congested) ||(p_app_cb->ui_xmit_q.count >= llcp_cb.ll_tx_congest_start) ||(llcp_cb.overall_tx_congested) ||(llcp_cb.total_tx_ui_pdu >= llcp_cb.max_num_ll_tx_buff) ) { /* set congested here so overall congestion check routine will not report event again, */ /* or notify uncongestion later */ p_app_cb->is_ui_tx_congested = TRUE; LLCP_TRACE_WARNING2 ("Logical link (SAP=0x%X) congested: ui_xmit_q.count=%d", ssap, p_app_cb->ui_xmit_q.count); status = LLCP_STATUS_CONGESTED; } return status; }
/******************************************************************************* ** ** Function llcp_process_timeout ** ** Description This function is called when an LLCP-related timeout occurs ** ** Returns void ** *******************************************************************************/ void llcp_process_timeout (TIMER_LIST_ENT *p_tle) { UINT8 reason; LLCP_TRACE_DEBUG1 ("llcp_process_timeout: event=%d", p_tle->event); switch (p_tle->event) { case NFC_TTYPE_LLCP_LINK_MANAGER: /* Link timeout or Symm timeout */ llcp_link_process_link_timeout (); break; case NFC_TTYPE_LLCP_LINK_INACT: /* inactivity timeout */ llcp_link_deactivate (LLCP_LINK_LOCAL_INITIATED); break; case NFC_TTYPE_LLCP_DATA_LINK: reason = LLCP_SAP_DISCONNECT_REASON_TIMEOUT; llcp_dlsm_execute ((tLLCP_DLCB *) (p_tle->param), LLCP_DLC_EVENT_TIMEOUT, &reason); break; case NFC_TTYPE_LLCP_DELAY_FIRST_PDU: llcp_link_check_send_data (); break; default: break; } }
/******************************************************************************* ** ** Function llcp_util_send_cc ** ** Description Send CC PDU ** ** Returns tLLCP_STATUS ** ******************************************************************************/ tLLCP_STATUS llcp_util_send_cc (tLLCP_DLCB *p_dlcb, tLLCP_CONNECTION_PARAMS *p_params) { BT_HDR *p_msg; UINT8 *p; UINT16 miu_len = 0, rw_len = 0; if (p_params->miu != LLCP_DEFAULT_MIU) { miu_len = 4; } if (p_params->rw != LLCP_DEFAULT_RW) { rw_len = 3; p_params->rw &= 0x0F; } p_msg = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (p_msg) { p_msg->len = LLCP_PDU_HEADER_SIZE + miu_len + rw_len; p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; p = (UINT8 *) (p_msg + 1) + p_msg->offset; UINT16_TO_BE_STREAM (p, LLCP_GET_PDU_HEADER (p_dlcb->remote_sap, LLCP_PDU_CC_TYPE, p_dlcb->local_sap)); if (miu_len) { UINT8_TO_BE_STREAM (p, LLCP_MIUX_TYPE); UINT8_TO_BE_STREAM (p, LLCP_MIUX_LEN); UINT16_TO_BE_STREAM (p, p_params->miu - LLCP_DEFAULT_MIU); } if (rw_len) { UINT8_TO_BE_STREAM (p, LLCP_RW_TYPE); UINT8_TO_BE_STREAM (p, LLCP_RW_LEN); UINT8_TO_BE_STREAM (p, p_params->rw); } GKI_enqueue (&llcp_cb.lcb.sig_xmit_q, p_msg); llcp_link_check_send_data (); return LLCP_STATUS_SUCCESS; } return LLCP_STATUS_FAIL; }
/******************************************************************************* ** ** Function llcp_util_send_disc ** ** Description Send DISC PDU ** ** Returns void ** *******************************************************************************/ void llcp_util_send_disc (UINT8 dsap, UINT8 ssap) { BT_HDR *p_msg; UINT8 *p; p_msg = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (p_msg) { p_msg->len = LLCP_PDU_DISC_SIZE; p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; p = (UINT8 *) (p_msg + 1) + p_msg->offset; UINT16_TO_BE_STREAM (p, LLCP_GET_PDU_HEADER (dsap, LLCP_PDU_DISC_TYPE, ssap)); GKI_enqueue (&llcp_cb.lcb.sig_xmit_q, p_msg); llcp_link_check_send_data (); } }
/******************************************************************************* ** ** Function llcp_sdp_send_sdres ** ** Description Send Service Discovery Response ** ** ** Returns LLCP_STATUS ** *******************************************************************************/ static tLLCP_STATUS llcp_sdp_send_sdres (UINT8 tid, UINT8 sap) { tLLCP_STATUS status; UINT16 available_bytes; LLCP_TRACE_DEBUG2 ("llcp_sdp_send_sdres (): tid=0x%x, SAP=0x%x", tid, sap); /* if there is no pending SNL */ if (!llcp_cb.sdp_cb.p_snl) { llcp_cb.sdp_cb.p_snl = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (llcp_cb.sdp_cb.p_snl) { llcp_cb.sdp_cb.p_snl->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + LLCP_PDU_HEADER_SIZE; llcp_cb.sdp_cb.p_snl->len = 0; } } if (llcp_cb.sdp_cb.p_snl) { available_bytes = GKI_get_buf_size (llcp_cb.sdp_cb.p_snl) - BT_HDR_SIZE - llcp_cb.sdp_cb.p_snl->offset - llcp_cb.sdp_cb.p_snl->len; /* if SDRES parameter can be added in SNL */ if ( (available_bytes >= 2 + LLCP_SDRES_LEN) &&(llcp_cb.sdp_cb.p_snl->len + 2 + LLCP_SDRES_LEN <= llcp_cb.lcb.effective_miu) ) { llcp_sdp_add_sdres (tid, sap); status = LLCP_STATUS_SUCCESS; } else { /* send pending SNL PDU to LM */ llcp_sdp_check_send_snl (); llcp_cb.sdp_cb.p_snl = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (llcp_cb.sdp_cb.p_snl) { llcp_cb.sdp_cb.p_snl->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + LLCP_PDU_HEADER_SIZE; llcp_cb.sdp_cb.p_snl->len = 0; llcp_sdp_add_sdres (tid, sap); status = LLCP_STATUS_SUCCESS; } else { status = LLCP_STATUS_FAIL; } } } else { status = LLCP_STATUS_FAIL; } /* if LM is waiting for PDUs from upper layer */ if ( (status == LLCP_STATUS_SUCCESS) &&(llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_LOCAL_XMIT_NEXT) ) { llcp_link_check_send_data (); } return status; }
/******************************************************************************* ** ** Function llcp_util_send_rr_rnr ** ** Description Send RR or RNR PDU ** ** Returns void ** *******************************************************************************/ void llcp_util_send_rr_rnr (tLLCP_DLCB *p_dlcb) { BT_HDR *p_msg; UINT8 *p; UINT8 pdu_type; UINT8 pdu_size; UINT8 rcv_seq; /* if no indication of change in local busy or rx congestion */ if ((p_dlcb->flags & LLCP_DATA_LINK_FLAG_PENDING_RR_RNR) == 0) { /* if all ack is sent */ if (p_dlcb->sent_ack_seq == p_dlcb->next_rx_seq) { /* we don't need to send RR/RNR */ return; } else { /* if rx flow off because of local busy or congestion */ if ( (p_dlcb->local_busy) ||(p_dlcb->is_rx_congested) ||(llcp_cb.overall_rx_congested) ) { /* don't send RR/RNR */ return; } } } if ( (p_dlcb->local_busy) ||(p_dlcb->is_rx_congested) ||(llcp_cb.overall_rx_congested) ) { LLCP_TRACE_DEBUG3 ("llcp_util_send_rr_rnr (): local_busy=%d,is_rx_congested=%d,overall_rx_congested=%d", p_dlcb->local_busy, p_dlcb->is_rx_congested, llcp_cb.overall_rx_congested); /* if local_busy or rx congested then do not update receive sequence number to flow off */ pdu_type = LLCP_PDU_RNR_TYPE; pdu_size = LLCP_PDU_RNR_SIZE; rcv_seq = p_dlcb->sent_ack_seq; } else { pdu_type = LLCP_PDU_RR_TYPE; pdu_size = LLCP_PDU_RR_SIZE; p_dlcb->sent_ack_seq = p_dlcb->next_rx_seq; rcv_seq = p_dlcb->sent_ack_seq; } p_msg = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID); if (p_msg) { p_dlcb->flags &= ~LLCP_DATA_LINK_FLAG_PENDING_RR_RNR; p_msg->len = pdu_size; p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; p = (UINT8 *) (p_msg + 1) + p_msg->offset; UINT16_TO_BE_STREAM (p, LLCP_GET_PDU_HEADER (p_dlcb->remote_sap, pdu_type, p_dlcb->local_sap)); UINT8_TO_BE_STREAM (p, rcv_seq); #if (BT_TRACE_VERBOSE == TRUE) LLCP_TRACE_DEBUG5 ("LLCP TX - N(S,R):(NA,%d) V(S,SA,R,RA):(%d,%d,%d,%d)", p_dlcb->next_rx_seq, p_dlcb->next_tx_seq, p_dlcb->rcvd_ack_seq, p_dlcb->next_rx_seq, p_dlcb->sent_ack_seq); #endif GKI_enqueue (&llcp_cb.lcb.sig_xmit_q, p_msg); llcp_link_check_send_data (); } else { LLCP_TRACE_ERROR0 ("llcp_util_send_rr_rnr (): Out of resource"); } }