Home | History | Annotate | Download | only in l2cap

Lines Matching refs:p_ccb

89 static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word);
90 static void process_s_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word);
91 static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, BOOLEAN delay_ack);
92 static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq);
93 static void prepare_I_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, BOOLEAN is_retransmission);
94 static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf);
95 static BOOLEAN do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word);
98 static BOOLEAN l2c_corrupt_the_fcr_packet (tL2C_CCB *p_ccb, BT_HDR *p_buf,
100 static BOOLEAN l2c_bypass_sframe_packet (tL2C_CCB *p_ccb);
104 static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, UINT8 num_bufs_acked);
175 void l2c_fcr_start_timer (tL2C_CCB *p_ccb)
180 if (p_ccb->fcrb.wait_ack)
182 tout = (UINT32)p_ccb->our_cfg.fcr.mon_tout;
186 tout = (UINT32)p_ccb->our_cfg.fcr.rtrans_tout;
190 tout, p_ccb->timer_entry.in_use, p_ccb->fcrb.wait_ack, p_ccb->fcrb.waiting_for_ack_q.count);
193 if (p_ccb->fcrb.mon_retrans_timer.in_use == 0)
194 btu_start_quick_timer (&p_ccb->fcrb.mon_retrans_timer, BTU_TTYPE_L2CAP_CHNL, tout*QUICK_TIMER_TICKS_PER_SEC/1000);
206 void l2c_fcr_stop_timer (tL2C_CCB *p_ccb)
208 if (p_ccb->fcrb.mon_retrans_timer.in_use)
212 p_ccb->fcrb.wait_ack, p_ccb->fcrb.waiting_for_ack_q.count);
214 btu_stop_quick_timer (&p_ccb->fcrb.mon_retrans_timer);
227 void l2c_fcr_cleanup (tL2C_CCB *p_ccb)
229 tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
231 l2c_fcr_stop_timer (p_ccb);
246 btu_stop_quick_timer (&p_ccb->fcrb.mon_retrans_timer);
249 if ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) )
251 UINT32 dur = GKI_get_os_tick_count() - p_ccb->fcrb.connect_tick_count;
258 "--- L2CAP ERTM Stats for CID: 0x%04x Duration: %08ums", p_ccb->local_cid, dur);
261 p_ccb->fcrb.pkts_retransmitted, p_ccb->fcrb.xmit_window_closed, p_ccb->fcrb.retrans_touts, p_ccb->fcrb.xmit_ack_touts);
263 "Times there is less than 2 packets in controller when flow controlled:%08u", p_ccb->fcrb.controller_idle);
265 "max_held_acks:%08u, in_cfg.fcr.tx_win_sz:%08u", p_ccb->fcrb.max_held_acks, p_ccb->peer_cfg.fcr.tx_win_sz );
269 p_ccb->fcrb.ertm_pkt_counts[0], p_ccb->fcrb.ertm_byte_counts[0],
270 (dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[0] * 100) / (dur / 10) : 0),
271 p_ccb->fcrb.s_frames_sent[0], p_ccb->fcrb.s_frames_sent[1], p_ccb->fcrb.s_frames_sent[2], p_ccb->fcrb.s_frames_sent[3]);
276 p_ccb->fcrb.ertm_pkt_counts[1], p_ccb->fcrb.ertm_byte_counts[1],
277 (dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[1] * 100) / (dur / 10) : 0),
278 p_ccb->fcrb.s_frames_rcvd[0], p_ccb->fcrb.s_frames_rcvd[1], p_ccb->fcrb.s_frames_rcvd[2], p_ccb->fcrb.s_frames_rcvd[3]);
288 if (i == p_ccb->fcrb.ack_delay_avg_index )
296 i, p_ccb->fcrb.throughput[i],
297 p_ccb->fcrb.ack_delay_avg[i], p_ccb->fcrb.ack_delay_min[i], p_ccb->fcrb.ack_delay_max[i],
298 p_ccb->fcrb.ack_q_count_avg[i], p_ccb->fcrb.ack_q_count_min[i], p_ccb->fcrb.ack_q_count_max[i] );
302 throughput_avg += p_ccb->fcrb.throughput[i];
303 ack_delay_avg += p_ccb->fcrb.ack_delay_avg[i];
304 ack_q_count_avg += p_ccb->fcrb.ack_q_count_avg[i];
387 BOOLEAN l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb)
389 if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)
392 if ( (p_ccb->fcrb.remote_busy == TRUE)
393 || (p_ccb->fcrb.waiting_for_ack_q.count >= p_ccb->peer_cfg.fcr.tx_win_sz) )
396 if (p_ccb->xmit_hold_q.count != 0)
398 p_ccb->fcrb.xmit_window_closed++;
400 if ((p_ccb->p_lcb->sent_not_acked < 2)&&(l2cb.controller_xmit_window > 0))
401 p_ccb->fcrb.controller_idle++;
421 static void prepare_I_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, BOOLEAN is_retransmission)
423 tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
449 if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)
456 p_fcrb->last_ack_sent = p_ccb->fcrb.next_seq_expected;
458 if (p_ccb->fcrb.ack_timer.in_use)
459 btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
468 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
489 p_ccb->local_cid, p_buf->len,
498 p_ccb->local_cid, p_buf->len,
507 if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)
508 l2c_fcr_start_timer (p_ccb);
520 void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, UINT16 function_code, UINT16 pf_bit)
529 if (l2c_bypass_sframe_packet (p_ccb))
533 if ((!p_ccb->in_use) || (p_ccb->chnl_state != CST_OPEN))
537 p_ccb->fcrb.s_frames_sent[function_code]++;
542 p_ccb->fcrb.wait_ack = TRUE;
544 l2c_fcr_stop_timer (p_ccb); /* Restart the monitor timer */
545 l2c_fcr_start_timer (p_ccb);
550 ctrl_word |= (p_ccb->fcrb.next_seq_expected << L2CAP_FCR_REQ_SEQ_BITS_SHIFT);
563 UINT16_TO_STREAM (p, p_ccb->remote_cid);
567 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
582 if (l2c_corrupt_the_fcr_packet (p_ccb, p_buf, FALSE, ctrl_word))
587 l2cu_set_acl_hci_header (p_buf, p_ccb);
594 p_ccb->local_cid, ctrl_word,
604 p_ccb->local_cid, ctrl_word,
613 l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf);
615 p_ccb->fcrb.last_ack_sent = p_ccb->fcrb.next_seq_expected;
617 if (p_ccb->fcrb.ack_timer.in_use)
618 btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
623 p_ccb->local_cid, function_code);
638 void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf)
646 min_pdu_len = (p_ccb->bypass_fcs == L2CAP_BYPASS_FCS) ?
651 L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x Len too short: %u", p_ccb->local_cid, p_buf->len);
656 if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_STREAM_MODE)
658 process_stream_frame (p_ccb, p_buf);
674 p_ccb->local_cid, p_buf->len,
683 p_ccb->local_cid, p_buf->len,
693 p_ccb->local_cid, p_buf->len,
701 p_ccb->fcrb.next_tx_seq, p_ccb->fcrb.last_rx_ack, p_ccb->fcrb.next_seq_expected,
702 p_ccb->fcrb.last_ack_sent, p_ccb->fcrb.waiting_for_ack_q.count, p_ccb->fcrb.num_tries);
711 if (l2c_corrupt_the_fcr_packet (p_ccb, p_buf, TRUE, ctrl_word))
716 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
726 L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x BAD FCS", p_ccb->local_cid);
741 if (p_ccb->fcrb.wait_ack)
748 if (p_ccb->fcrb.srej_sent)
749 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, L2CAP_FCR_F_BIT);
750 else if (p_ccb->fcrb.local_busy)
751 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_F_BIT);
753 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_F_BIT);
759 btu_start_quick_timer (&p_ccb->fcrb.mon_retrans_timer, BTU_TTYPE_L2CAP_CHNL, QUICK_TIMER_TICKS_PER_SEC);
765 p_ccb->fcrb.wait_ack = FALSE;
771 if (p_ccb->fcrb.waiting_for_ack_q.count == 0)
772 p_ccb->fcrb.num_tries = 0;
774 l2c_fcr_stop_timer (p_ccb);
783 if (!process_reqseq (p_ccb, ctrl_word))
791 process_s_frame (p_ccb, p_buf, ctrl_word);
793 process_i_frame (p_ccb, p_buf, ctrl_word, FALSE);
796 if ( (!p_ccb->in_use) || (p_ccb->chnl_state != CST_OPEN) )
800 if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.srej_sent) && (p_ccb->fcrb.srej_rcv_hold_q.count > 0) )
802 BUFFER_Q temp_q = p_ccb->fcrb.srej_rcv_hold_q;
804 GKI_init_q (&p_ccb->fcrb.srej_rcv_hold_q);
808 if (p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN))
816 p_ccb->local_cid, (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT,
817 p_ccb->fcrb.next_seq_expected);
820 process_i_frame (p_ccb, p_buf, ctrl_word, TRUE);
826 if (p_ccb->fcrb.rej_after_srej)
828 p_ccb->fcrb.rej_after_srej = FALSE;
829 p_ccb->fcrb.rej_sent = TRUE;
831 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_REJ, 0);
836 if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.rej_sent) && (!p_ccb->fcrb.srej_sent)
837 && (p_ccb->fcrb.next_seq_expected != p_ccb->fcrb.last_ack_sent) )
838 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, 0);
842 p_ccb->local_cid, p_ccb->fcrb.local_busy, p_ccb->fcrb.rej_sent, p_ccb->fcrb.srej_sent, p_ccb->fcrb.next_seq_expected,
843 p_ccb->fcrb.last_ack_sent);
848 if ( (p_ccb->fcrb.retrans_q.count || p_ccb->xmit_hold_q.count)
849 && (p_ccb->fcrb.wait_ack == FALSE)
850 && (l2c_fcr_is_flow_controlled (p_ccb) == FALSE) )
852 l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
865 void l2c_fcr_proc_tout (tL2C_CCB *p_ccb)
868 p_ccb->local_cid, p_ccb->fcrb.num_tries, p_ccb->peer_cfg.fcr.max_transmit,
869 p_ccb->fcrb.wait_ack, p_ccb->fcrb.waiting_for_ack_q.count);
872 p_ccb->fcrb.retrans_touts++;
875 if ( (p_ccb->peer_cfg.fcr.max_transmit != 0) && (++p_ccb->fcrb.num_tries > p_ccb->peer_cfg.fcr.max_transmit) )
877 l2cu_disconnect_chnl (p_ccb);
881 if (!p_ccb->fcrb.srej_sent && !p_ccb->fcrb.rej_sent)
883 if (p_ccb->fcrb.local_busy)
884 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_P_BIT);
886 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_P_BIT);
901 void l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb)
903 L2CAP_TRACE_DEBUG ("l2c_fcr_proc_ack_tout: CID: 0x%04x State: %u Wack:%u Rq:%d Acked:%d", p_ccb->local_cid,
904 p_ccb->chnl_state, p_ccb->fcrb.wait_ack, p_ccb->fcrb.next_seq_expected, p_ccb->fcrb.last_ack_sent);
906 if ( (p_ccb->chnl_state == CST_OPEN) && (!p_ccb->fcrb.wait_ack)
907 && (p_ccb->fcrb.last_ack_sent != p_ccb->fcrb.next_seq_expected) )
910 p_ccb->fcrb.xmit_ack_touts++;
912 if (p_ccb->fcrb.local_busy)
913 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0);
915 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, 0);
929 static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word)
931 tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
943 l2c_fcr_start_timer (p_ccb);
960 l2cu_disconnect_chnl (p_ccb);
977 l2c_fcr_collect_ack_delay (p_ccb, num_bufs_acked);
991 if (!p_ccb->fcrb.wait_ack)
992 l2c_fcr_stop_timer (p_ccb);
995 if ( (p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && (full_sdus_xmitted) )
998 if ( (p_fcrb->waiting_for_ack_q.count == 0) && (p_ccb->xmit_hold_q.count == 0) )
1001 (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, full_sdus_xmitted);
1007 l2c_fcr_start_timer (p_ccb);
1022 static void process_s_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word)
1024 tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
1037 p_ccb->fcrb.s_frames_rcvd[s_frame_type]++;
1053 all_ok = retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS);
1058 all_ok = retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS);
1063 l2c_fcr_stop_timer (p_ccb);
1068 all_ok = retransmit_i_frames (p_ccb, (UINT8)((ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT));
1078 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, L2CAP_FCR_F_BIT);
1080 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_F_BIT);
1082 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_F_BIT);
1105 static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, BOOLEAN delay_ack)
1107 tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
1113 if (!retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS))
1121 p_ccb->fcrb.ertm_pkt_counts[1]++;
1122 p_ccb->fcrb.ertm_byte_counts[1] += p_buf->len;
1132 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0);
1139 if (GKI_poolfreecount (p_ccb->ertm_info.user_rx_pool_id) == 0)
1142 p_ccb->local_cid, tx_seq, p_ccb->ertm_info.user_rx_pool_id,
1143 GKI_poolcount (p_ccb->ertm_info.user_rx_pool_id));
1154 if (num_lost >= p_ccb->our_cfg.fcr.tx_win_sz)
1163 p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent, p_fcrb->srej_sent);
1170 if ( (tx_seq == next_srej) && (p_fcrb->srej_rcv_hold_q.count < p_ccb->our_cfg.fcr.tx_win_sz) )
1173 if (p_ccb->ertm_info.fcr_rx_pool_id != HCI_ACL_POOL_ID)
1181 p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len, p_ccb->ertm_info.fcr_rx_pool_id);
1200 p_ccb->local_cid, next_srej, p_fcrb->srej_rcv_hold_q.count, p_ccb->our_cfg.fcr.tx_win_sz);
1209 p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->srej_sent);
1217 p_ccb->local_cid, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent);
1224 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_REJ, 0);
1231 p_ccb->local_cid, tx_seq, p_fcrb->srej_rcv_hold_q.count);
1236 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, 0);
1238 btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
1252 if (!do_sar_reassembly (p_ccb, p_buf, ctrl_word))
1254 L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x reassembly failed", p_ccb->local_cid);
1255 l2cu_disconnect_chnl (p_ccb);
1262 if ( (num_to_ack < p_ccb->fcrb.max_held_acks) && (!p_fcrb->local_busy) )
1266 if ((num_to_ack != 0) && p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN))
1272 if (!p_ccb->fcrb.ack_timer.in_use)
1274 btu_start_quick_timer (&p_ccb->fcrb.ack_timer, BTU_TTYPE_L2CAP_FCR_ACK,
1278 else if ( ((p_ccb->xmit_hold_q.count == 0) || (l2c_fcr_is_flow_controlled (p_ccb)))
1279 && (p_ccb->fcrb.srej_rcv_hold_q.count == 0) )
1282 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0);
1284 l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, 0);
1299 static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf)
1307 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
1317 L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x BAD FCS", p_ccb->local_cid);
1334 L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x BAD S-frame in streaming mode ctrl_word: 0x%04x", p_ccb->local_cid, ctrl_word);
1341 p_ccb->local_cid, p_buf->len,
1352 if (tx_seq != p_ccb->fcrb.next_seq_expected)
1355 p_ccb->local_cid, p_ccb->fcrb.next_seq_expected, tx_seq, p_ccb->fcrb.p_rx_sdu);
1358 if (p_ccb->fcrb.p_rx_sdu != NULL)
1360 GKI_freebuf (p_ccb->fcrb.p_rx_sdu);
1361 p_ccb->fcrb.p_rx_sdu = NULL;
1365 p_ccb->fcrb.next_seq_expected = (tx_seq + 1) & L2CAP_FCR_SEQ_MODULO;
1367 if (!do_sar_reassembly (p_ccb, p_buf, ctrl_word))
1370 if (p_ccb->fcrb.p_rx_sdu != NULL)
1372 GKI_freebuf (p_ccb->fcrb.p_rx_sdu);
1373 p_ccb->fcrb.p_rx_sdu = NULL;
1388 static BOOLEAN do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word)
1390 tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
1433 if (p_fcrb->rx_sdu_len > p_ccb->max_rx_mtu)
1438 else if ((p_fcrb->p_rx_sdu = (BT_HDR *)GKI_getpoolbuf (p_ccb->ertm_info.user_rx_pool_id)) == NULL)
1440 L2CAP_TRACE_ERROR ("SAR - no buffer for SDU start user_rx_pool_id:%d", p_ccb->ertm_info.user_rx_pool_id);
1489 if (p_ccb->local_cid < L2CAP_BASE_APPL_CID &&
1490 (p_ccb->local_cid >= L2CAP_FIRST_FIXED_CHNL && p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL))
1492 if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)
1493 (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)(p_ccb->p_lcb->remote_bd_addr, p_buf);
1497 l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DATA, p_buf);
1513 static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq)
1520 if ( (p_ccb->fcrb.waiting_for_ack_q.p_first)
1521 && (p_ccb->peer_cfg.fcr.max_transmit != 0)
1522 && (p_ccb->fcrb.num_tries >= p_ccb->peer_cfg.fcr.max_transmit) )
1525 p_ccb->fcrb.last_rx_ack, p_ccb->local_cid, p_ccb->fcrb.num_tries, p_ccb->peer_cfg.fcr.max_transmit,
1526 p_ccb->fcrb.waiting_for_ack_q.count);
1528 l2cu_disconnect_chnl (p_ccb);
1537 for (p_buf = (BT_HDR *)p_ccb->fcrb.waiting_for_ack_q.p_first; p_buf; p_buf = (BT_HDR *)GKI_getnext (p_buf))
1554 L2CAP_TRACE_ERROR ("retransmit_i_frames() UNKNOWN seq: %u q_count: %u", tx_seq, p_ccb->fcrb.waiting_for_ack_q.count);
1562 p_buf = (BT_HDR *)p_ccb->p_lcb->link_xmit_data_q.p_first;
1567 if ( (p_buf->layer_specific == 0) && (p_buf->event == p_ccb->local_cid) )
1572 GKI_remove_from_queue (&p_ccb->p_lcb->link_xmit_data_q, p_buf2);
1580 while (p_ccb->fcrb.retrans_q.p_first)
1581 GKI_freebuf (GKI_dequeue (&p_ccb->fcrb.retrans_q));
1583 p_buf = (BT_HDR *)p_ccb->fcrb.waiting_for_ack_q.p_first;
1588 p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len, p_ccb->ertm_info.fcr_tx_pool_id);
1594 GKI_enqueue (&p_ccb->fcrb.retrans_q, p_buf2);
1603 l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL);
1605 if (p_ccb->fcrb.waiting_for_ack_q.count)
1607 p_ccb->fcrb.num_tries++;
1608 l2c_fcr_start_timer (p_ccb);
1624 BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length)
1632 UINT16 max_pdu = p_ccb->tx_mps /* Needed? - L2CAP_MAX_HEADER_FCS*/;
1636 if (p_ccb->fcrb.retrans_q.p_first)
1638 p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->fcrb.retrans_q);
1641 prepare_I_frame (p_ccb, p_buf, TRUE);
1643 p_buf->event = p_ccb->local_cid;
1651 if (l2c_corrupt_the_fcr_packet (p_ccb, p_buf, FALSE, sdu_len))
1656 p_ccb->fcrb.pkts_retransmitted++;
1657 p_ccb->fcrb.ertm_pkt_counts[0]++;
1658 p_ccb->fcrb.ertm_byte_counts[0] += (p_buf->len - 8);
1671 p_buf = (BT_HDR *)p_ccb->xmit_hold_q.p_first;
1687 max_pdu, p_ccb->ertm_info.fcr_tx_pool_id);
1691 p_buf->event = p_ccb->local_cid;
1692 p_xmit->event = p_ccb->local_cid;
1702 L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer, for segmentation, pool: %u", p_ccb->ertm_info.fcr_tx_pool_id);
1708 p_xmit = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_hold_q);
1713 p_xmit->event = p_ccb->local_cid;
1734 UINT16_TO_STREAM (p, p_ccb->remote_cid);
1755 prepare_I_frame (p_ccb, p_xmit, FALSE);
1757 if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)
1759 BT_HDR *p_wack = l2c_fcr_clone_buf (p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len, p_ccb->ertm_info.fcr_tx_pool_id);
1764 p_ccb->local_cid, p_ccb->ertm_info.fcr_tx_pool_id, GKI_poolfreecount(p_ccb->ertm_info.fcr_tx_pool_id));
1767 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
1771 GKI_enqueue (&p_ccb->fcrb.waiting_for_ack_q, p_xmit);
1782 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
1786 GKI_enqueue (&p_ccb->fcrb.waiting_for_ack_q, p_wack);
1796 if (l2c_corrupt_the_fcr_packet (p_ccb, p_xmit, FALSE, ctrl_word))
1801 p_ccb->fcrb.ertm_pkt_counts[0]++;
1802 p_ccb->fcrb.ertm_byte_counts[0] += (p_xmit->len - 8);
1831 UINT8 l2c_fcr_chk_chan_modes (tL2C_CCB *p_ccb)
1834 if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_ENH_RETRANS))
1835 p_ccb->ertm_info.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_ERTM;
1837 if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_STREAM_MODE))
1838 p_ccb->ertm_info.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_STREAM;
1841 if (!p_ccb->ertm_info.allowed_modes)
1846 return (p_ccb->ertm_info.allowed_modes);
1859 BOOLEAN l2c_fcr_adj_our_req_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg)
1863 if (p_fcr->mode != p_ccb->ertm_info.preferred_mode)
1866 p_ccb->ertm_info.preferred_mode, p_fcr->mode);
1869 p_fcr->mode = p_ccb->ertm_info.preferred_mode;
1873 if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC)
1885 if (p_cfg->fcr_present && !(p_ccb->config_done & RECONFIG_FLAG))
1888 if (!l2c_fcr_chk_chan_modes(p_ccb))
1891 l2cu_disconnect_chnl (p_ccb);
1896 else if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC)
1910 if (p_fcr->mode == L2CAP_FCR_STREAM_MODE && !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_STREAM))
1917 if (p_fcr->mode == L2CAP_FCR_ERTM_MODE && !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM))
1927 if ( (p_cfg->mtu_present) && (p_cfg->mtu > p_ccb->max_rx_mtu) )
1929 L2CAP_TRACE_WARNING ("L2CAP - MTU: %u larger than buf size: %u", p_cfg->mtu, p_ccb->max_rx_mtu);
1939 else if (p_fcr->mps > p_ccb->max_rx_mtu)
1941 L2CAP_TRACE_WARNING ("L2CAP - MPS %u invalid MTU: %u", p_fcr->mps, p_ccb->max_rx_mtu);
1955 p_ccb->our_cfg.fcr = *p_fcr;
1959 p_ccb->our_cfg.fcr_present = FALSE;
1975 void l2c_fcr_adj_monitor_retran_timeout (tL2C_CCB *p_ccb)
1978 if (p_ccb->out_cfg_fcr_present)
1984 if ((p_ccb->our_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)
1985 ||(p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE))
1988 p_ccb->our_cfg.fcr.mon_tout = L2CAP_MIN_MONITOR_TOUT;
1989 p_ccb->our_cfg.fcr.rtrans_tout = L2CAP_MIN_RETRANS_TOUT;
1993 p_ccb->our_cfg.fcr.mon_tout = 0;
1994 p_ccb->our_cfg.fcr.rtrans_tout = 0;
1998 p_ccb->our_cfg.fcr.mon_tout, p_ccb->our_cfg.fcr.rtrans_tout);
2012 void l2c_fcr_adj_our_rsp_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg)
2015 l2c_fcr_adj_monitor_retran_timeout(p_ccb);
2017 p_cfg->fcr_present = p_ccb->out_cfg_fcr_present;
2025 if (p_ccb->peer_cfg.fcr.tx_win_sz > p_ccb->our_cfg.fcr.tx_win_sz)
2027 L2CAP_TRACE_DEBUG ("%s: adjusting requested tx_win_sz from %i to %i", __FUNCTION__, p_ccb->peer_cfg.fcr.tx_win_sz, p_ccb->our_cfg.fcr.tx_win_sz);
2028 p_ccb->peer_cfg.fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz;
2032 p_cfg->fcr.mode = p_ccb->peer_cfg.fcr.mode;
2033 p_cfg->fcr.tx_win_sz = p_ccb->peer_cfg.fcr.tx_win_sz;
2034 p_cfg->fcr.max_transmit = p_ccb->peer_cfg.fcr.max_transmit;
2035 p_cfg->fcr.mps = p_ccb->peer_cfg.fcr.mps;
2036 p_cfg->fcr.rtrans_tout = p_ccb->our_cfg.fcr.rtrans_tout;
2037 p_cfg->fcr.mon_tout = p_ccb->our_cfg.fcr.mon_tout;
2053 BOOLEAN l2c_fcr_renegotiate_chan(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg)
2055 UINT8 peer_mode = p_ccb->our_cfg.fcr.mode;
2059 if (!p_cfg->fcr_present || (p_ccb->config_done & RECONFIG_FLAG))
2067 if (p_ccb->our_cfg.fcr.mode != peer_mode)
2070 if ((--p_ccb->fcr_cfg_tries) == 0)
2079 switch (p_ccb->our_cfg.fcr.mode)
2084 if ( (peer_mode == L2CAP_FCR_ERTM_MODE) && (p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM) )
2087 p_ccb->our_cfg.fcr.mode = L2CAP_FCR_ERTM_MODE;
2095 if (p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC)
2099 p_ccb->our_cfg.fcr.mode = L2CAP_FCR_BASIC_MODE;
2111 p_ccb->our_cfg.fcr_present = TRUE;
2113 if (p_ccb->our_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE)
2115 p_ccb->our_cfg.fcs_present = FALSE;
2116 p_ccb->our_cfg.ext_flow_spec_present = FALSE;
2126 l2cu_process_our_cfg_req (p_ccb, &p_ccb->our_cfg);
2127 l2cu_send_peer_config_req (p_ccb, &p_ccb->our_cfg);
2128 btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
2135 if (p_ccb->our_cfg.fcr.mode != peer_mode)
2138 p_ccb->our_cfg.fcr.mode, peer_mode);
2139 l2cu_disconnect_chnl (p_ccb);
2157 UINT8 l2c_fcr_process_peer_cfg_req(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg)
2162 p_ccb->p_lcb->w4_info_rsp = FALSE; /* Handles T61x SonyEricsson Bug in Info Request */
2165 p_cfg->fcr_present, p_cfg->fcr.mode, p_ccb->our_cfg.fcr.mode, p_ccb->ertm_info.preferred_mode,
2166 p_ccb->ertm_info.allowed_modes);
2172 if ( !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC) )
2177 else if (p_cfg->fcr.mode != p_ccb->ertm_info.preferred_mode)
2185 || (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE) )
2187 p_cfg->fcr.mode = p_ccb->our_cfg.fcr.mode;
2188 p_cfg->fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz;
2189 p_cfg->fcr.max_transmit = p_ccb->our_cfg.fcr.max_transmit;
2194 else if (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE)
2199 p_ccb->our_cfg.fcr.rtrans_tout = p_ccb->our_cfg.fcr.mon_tout = p_ccb->our_cfg.fcr.mps = 0;
2206 || !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM) )
2216 p_ccb->out_cfg_fcr_present = FALSE;
2224 p_ccb->peer_cfg.fcs = p_cfg->fcs;
2225 p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FCS;
2227 p_ccb->bypass_fcs |= L2CAP_CFG_FCS_PEER;
2230 max_retrans_size = GKI_get_pool_bufsize (p_ccb->ertm_info.fcr_tx_pool_id) - sizeof(BT_HDR)
2234 if ( (p_cfg->fcr.mps == 0) || (p_cfg->fcr.mps > p_ccb->peer_cfg.mtu) )
2236 p_cfg->fcr.mps = p_ccb->peer_cfg.mtu;
2237 p_ccb->out_cfg_fcr_present = TRUE;
2246 p_ccb->out_cfg_fcr_present = TRUE;
2252 p_ccb->out_cfg_fcr_present = TRUE;
2257 p_ccb->peer_cfg.fcr = p_cfg->fcr;
2260 p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FCR;
2265 if (p_ccb->peer_cfg_already_rejected)
2268 p_ccb->peer_cfg_already_rejected = TRUE;
2297 static BOOLEAN l2c_corrupt_the_fcr_packet (tL2C_CCB *p_ccb, BT_HDR *p_buf,
2306 if (!p_ccb || !p_ccb->fcrb.test_cb.cfg.in_use)
2315 p_cfg = &p_ccb->fcrb.test_cb.cfg;
2338 p_ccb->fcrb.test_cb.cfg.in_use = FALSE;
2383 if (!is_rx || p_ccb->bypass_fcs == L2CAP_BYPASS_FCS)
2427 tL2C_CCB *p_ccb = NULL;
2441 p_ccb = p_temp_ccb;
2448 p_ccb = l2cu_find_ccb_by_cid (NULL, cid);
2450 if (!p_ccb || type == L2CAP_FCR_TTYPE_GET_CID)
2459 p_test_cb = &p_ccb->fcrb.test_cb;
2522 tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid (NULL, cid);
2524 if (p_ccb && (sup_type == L2CAP_FCR_SUP_RR || sup_type == L2CAP_FCR_SUP_RNR))
2526 l2c_fcr_send_S_frame (p_ccb, sup_type, L2CAP_FCR_P_BIT);
2530 L2CAP_TRACE_ERROR ("L2CA_SendPolledSFrame(ERROR): sup_type %u, p_ccb 0x%07x",
2531 sup_type, (UINT32)p_ccb);
2545 static BOOLEAN l2c_bypass_sframe_packet (tL2C_CCB *p_ccb)
2547 if (p_ccb && p_ccb->fcrb.test_cb.cfm.in_use)
2549 if (p_ccb->fcrb.test_cb.cfm.skip_sframe_count > 0)
2552 p_ccb->fcrb.test_cb.cfm.skip_sframe_count);
2554 if (--p_ccb->fcrb.test_cb.cfm.skip_sframe_count == 0)
2555 p_ccb->fcrb.test_cb.cfm.in_use = FALSE;
2561 p_ccb->fcrb.test_cb.cfm.in_use = FALSE;
2584 tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid (NULL, cid);
2587 if (!p_ccb)
2589 L2CAP_TRACE_WARNING ("L2CA_BypassSFrame(ERROR): no p_ccb (0x%07x)", (UINT32)p_ccb);
2593 p_test_cb = &p_ccb->fcrb.test_cb.cfm;
2622 static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, UINT8 num_bufs_acked)
2631 index = p_ccb->fcrb.ack_delay_avg_index;
2634 p_ccb->fcrb.ack_q_count_avg[index] += p_ccb->fcrb.waiting_for_ack_q.count;
2636 if ( p_ccb->fcrb.waiting_for_ack_q.count > p_ccb->fcrb.ack_q_count_max[index] )
2637 p_ccb->fcrb.ack_q_count_max[index] = p_ccb->fcrb.waiting_for_ack_q.count;
2639 if ( p_ccb->fcrb.waiting_for_ack_q.count < p_ccb->fcrb.ack_q_count_min[index] )
2640 p_ccb->fcrb.ack_q_count_min[index] = p_ccb->fcrb.waiting_for_ack_q.count;
2643 p_buf = (BT_HDR *)(p_ccb->fcrb.waiting_for_ack_q.p_first);
2647 p_ccb->fcrb.throughput[index] += p_buf->len - 8;
2653 if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
2661 p_ccb->fcrb.ack_delay_avg[index] += delay;
2662 if ( delay > p_ccb->fcrb.ack_delay_max[index] )
2663 p_ccb->fcrb.ack_delay_max[index] = delay;
2664 if ( delay < p_ccb->fcrb.ack_delay_min[index] )
2665 p_ccb->fcrb.ack_delay_min[index] = delay;
2671 p_ccb->fcrb.ack_delay_avg_count++;
2674 if (p_ccb->fcrb.ack_delay_avg_count > L2CAP_ERTM_STATS_AVG_NUM_SAMPLES)
2676 p_ccb->fcrb.ack_delay_avg_count = 0;
2678 p_ccb->fcrb.ack_q_count_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES;
2679 p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES;
2683 if (timestamp - p_ccb->fcrb.throughput_start > 0 )
2684 p_ccb->fcrb.throughput[index] /= (timestamp - p_ccb->fcrb.throughput_start);
2686 p_ccb->fcrb.throughput_start = timestamp;
2689 index, p_ccb->fcrb.throughput[index],
2690 p_ccb->fcrb.ack_delay_avg[index], p_ccb->fcrb.ack_delay_min[index], p_ccb->fcrb.ack_delay_max[index],
2691 p_ccb->fcrb.ack_q_count_avg[index], p_ccb->fcrb.ack_q_count_min[index], p_ccb->fcrb.ack_q_count_max[index] );
2696 p_ccb->fcrb.ack_delay_avg_index = index;
2698 p_ccb->fcrb.ack_q_count_max[index] = 0;
2699 p_ccb->fcrb.ack_q_count_min[index] = 0xFFFFFFFF;
2700 p_ccb->fcrb.ack_q_count_avg[index] = 0;
2703 p_ccb->fcrb.ack_delay_max[index] = 0;
2704 p_ccb->fcrb.ack_delay_min[index] = 0xFFFFFFFF;
2705 p_ccb->fcrb.ack_delay_avg[index] = 0;
2707 p_ccb->fcrb.throughput[index] = 0;