From 187708488678f20f5bf081dcb5572151656eef52 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 25 Sep 2020 15:18:09 -0700 Subject: [PATCH] L2CAP: Use ERTM info during registration, not conn req ERTM info is stored in p_ccb->p_rcb. Use that as the source of truth. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I78c3d65fdaf14addf80607ce5105221e52447a9e --- stack/l2cap/l2c_api.cc | 16 ---------------- stack/l2cap/l2c_fcr.cc | 28 ++++++++++++++-------------- stack/l2cap/l2c_utils.cc | 3 --- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index 82f4f1542..15980a9f0 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -398,14 +398,6 @@ uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr, /* Save registration info */ p_ccb->p_rcb = p_rcb; - if (p_ertm_info) { - p_ccb->ertm_info = *p_ertm_info; - - p_ccb->max_rx_mtu = - BT_DEFAULT_BUFFER_SIZE - - (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN); - } - /* If link is up, start the L2CAP connection */ if (p_lcb->link_state == LST_CONNECTED) { l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, nullptr); @@ -808,14 +800,6 @@ bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id, uint16_t lcid, return (false); } - if (p_ertm_info) { - p_ccb->ertm_info = *p_ertm_info; - - p_ccb->max_rx_mtu = - BT_DEFAULT_BUFFER_SIZE - - (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN); - } - if (result == L2CAP_CONN_OK) { l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL); } else { diff --git a/stack/l2cap/l2c_fcr.cc b/stack/l2cap/l2c_fcr.cc index 719fd592d..68c83246a 100644 --- a/stack/l2cap/l2c_fcr.cc +++ b/stack/l2cap/l2c_fcr.cc @@ -1596,10 +1596,10 @@ uint8_t l2c_fcr_chk_chan_modes(tL2C_CCB* p_ccb) { /* Remove nonbasic options that the peer does not support */ if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_ENH_RETRANS) && - p_ccb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE) { + p_ccb->p_rcb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE) { L2CAP_TRACE_WARNING( "L2CAP - Peer does not support our desired channel types"); - p_ccb->ertm_info.preferred_mode = 0; + p_ccb->p_rcb->ertm_info.preferred_mode = 0; return false; } return true; @@ -1621,19 +1621,19 @@ bool l2c_fcr_adj_our_req_options(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { tL2CAP_FCR_OPTS* p_fcr = &p_cfg->fcr; - if (p_fcr->mode != p_ccb->ertm_info.preferred_mode) { + if (p_fcr->mode != p_ccb->p_rcb->ertm_info.preferred_mode) { L2CAP_TRACE_WARNING( "l2c_fcr_adj_our_req_options - preferred_mode (%d), does not match " "mode (%d)", - p_ccb->ertm_info.preferred_mode, p_fcr->mode); + p_ccb->p_rcb->ertm_info.preferred_mode, p_fcr->mode); /* The preferred mode is passed in through tL2CAP_ERTM_INFO, so override * this one */ - p_fcr->mode = p_ccb->ertm_info.preferred_mode; + p_fcr->mode = p_ccb->p_rcb->ertm_info.preferred_mode; } /* If upper layer did not request eRTM mode, BASIC must be used */ - if (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { + if (p_ccb->p_rcb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { if (p_cfg->fcr_present && p_fcr->mode != L2CAP_FCR_BASIC_MODE) { L2CAP_TRACE_WARNING( "l2c_fcr_adj_our_req_options (mode %d): ERROR: No FCR options set " @@ -1657,7 +1657,7 @@ bool l2c_fcr_adj_our_req_options(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { } /* Basic is the only common channel mode between the two devices */ - else if (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { + else if (p_ccb->p_rcb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { /* We only want to try Basic, so bypass sending the FCR options entirely */ p_cfg->fcr_present = false; @@ -1673,7 +1673,7 @@ bool l2c_fcr_adj_our_req_options(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { /* If peer does not support ERTM, try BASIC (will support this if made it * here in the code) */ if (p_fcr->mode == L2CAP_FCR_ERTM_MODE && - !(p_ccb->ertm_info.preferred_mode & L2CAP_FCR_BASIC_MODE)) { + !(p_ccb->p_rcb->ertm_info.preferred_mode & L2CAP_FCR_BASIC_MODE)) { L2CAP_TRACE_DEBUG( "L2C CFG: mode is ERTM, but peer does not support; Try BASIC"); p_fcr->mode = L2CAP_FCR_BASIC_MODE; @@ -1835,7 +1835,7 @@ bool l2c_fcr_renegotiate_chan(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { switch (p_ccb->our_cfg.fcr.mode) { case L2CAP_FCR_ERTM_MODE: /* We can try basic for any other peer mode if we support it */ - if (p_ccb->ertm_info.preferred_mode & L2CAP_FCR_BASIC_MODE) { + if (p_ccb->p_rcb->ertm_info.preferred_mode & L2CAP_FCR_BASIC_MODE) { L2CAP_TRACE_DEBUG("%s(Trying Basic)", __func__); can_renegotiate = true; p_ccb->our_cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; @@ -1905,17 +1905,17 @@ uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { "l2c_fcr_process_peer_cfg_req() CFG fcr_present:%d fcr.mode:%d CCB FCR " "mode:%d preferred: %u", p_cfg->fcr_present, p_cfg->fcr.mode, p_ccb->our_cfg.fcr.mode, - p_ccb->ertm_info.preferred_mode); + p_ccb->p_rcb->ertm_info.preferred_mode); /* If Peer wants basic, we are done (accept it or disconnect) */ if (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE) { /* If we do not allow basic, disconnect */ - if (p_ccb->ertm_info.preferred_mode != L2CAP_FCR_BASIC_MODE) + if (p_ccb->p_rcb->ertm_info.preferred_mode != L2CAP_FCR_BASIC_MODE) fcr_ok = L2CAP_PEER_CFG_DISCONNECT; } /* Need to negotiate if our modes are not the same */ - else if (p_cfg->fcr.mode != p_ccb->ertm_info.preferred_mode) { + else if (p_cfg->fcr.mode != p_ccb->p_rcb->ertm_info.preferred_mode) { /* If peer wants a mode that we don't support then retry our mode (ex. *rtx/flc), OR ** If we want ERTM and they wanted streaming retry our mode. @@ -1923,7 +1923,7 @@ uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { ** from their EXF mask. */ if ((((1 << p_cfg->fcr.mode) & L2CAP_FCR_CHAN_OPT_ALL_MASK) == 0) || - (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE)) { + (p_ccb->p_rcb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE)) { p_cfg->fcr.mode = p_ccb->our_cfg.fcr.mode; p_cfg->fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz; p_cfg->fcr.max_transmit = p_ccb->our_cfg.fcr.max_transmit; @@ -1931,7 +1931,7 @@ uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { } /* If we wanted basic, then try to renegotiate it */ - else if (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { + else if (p_ccb->p_rcb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; p_cfg->fcr.max_transmit = p_cfg->fcr.tx_win_sz = 0; p_cfg->fcr.rtrans_tout = p_cfg->fcr.mon_tout = p_cfg->fcr.mps = 0; diff --git a/stack/l2cap/l2c_utils.cc b/stack/l2cap/l2c_utils.cc index 5ef27f856..56b12b853 100644 --- a/stack/l2cap/l2c_utils.cc +++ b/stack/l2cap/l2c_utils.cc @@ -1355,7 +1355,6 @@ tL2C_CCB* l2cu_allocate_ccb(tL2C_LCB* p_lcb, uint16_t cid) { p_ccb->our_cfg.qos.delay_variation = p_ccb->peer_cfg.qos.delay_variation = L2CAP_DEFAULT_DELAY; - memset(&p_ccb->ertm_info, 0, sizeof(tL2CAP_ERTM_INFO)); p_ccb->peer_cfg_already_rejected = false; p_ccb->fcr_cfg_tries = L2CAP_MAX_FCR_CFG_TRIES; @@ -1369,8 +1368,6 @@ tL2C_CCB* l2cu_allocate_ccb(tL2C_LCB* p_lcb, uint16_t cid) { alarm_free(p_ccb->fcrb.mon_retrans_timer); p_ccb->fcrb.mon_retrans_timer = alarm_new("l2c_fcrb.mon_retrans_timer"); - p_ccb->ertm_info.preferred_mode = - L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */ p_ccb->max_rx_mtu = L2CAP_MTU_SIZE; p_ccb->tx_mps = BT_DEFAULT_BUFFER_SIZE - 32; -- 2.11.0