From: Hansong Zhang Date: Fri, 25 Sep 2020 02:57:01 +0000 (-0700) Subject: Enforce remote MTU requirement in L2CAP directly X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=679dfc5152fa78182bc8b579faff9e0d8092a83c;p=android-x86%2Fsystem-bt.git Enforce remote MTU requirement in L2CAP directly AVCT_BR and BNEP don't need to enforce it locally. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I090d4e31b76e0098fc77e707ebd2eacf4cd78b7b --- diff --git a/stack/avct/avct_l2c_br.cc b/stack/avct/avct_l2c_br.cc index 9bbaf5708..96fb81dab 100644 --- a/stack/avct/avct_l2c_br.cc +++ b/stack/avct/avct_l2c_br.cc @@ -287,21 +287,11 @@ void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { AVCT_TRACE_DEBUG("%s peer_mtu:%d use:%d", __func__, p_lcb->peer_mtu, max_mtu); - if (p_lcb->peer_mtu >= AVCT_MIN_BROWSE_MTU) - p_cfg->result = L2CAP_CFG_OK; - else { - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - p_cfg->mtu_present = true; - p_cfg->mtu = AVCT_MIN_BROWSE_MTU; - } + p_cfg->result = L2CAP_CFG_OK; /* send L2CAP configure response */ L2CA_ConfigRsp(lcid, p_cfg); - if (p_cfg->result != L2CAP_CFG_OK) { - return; - } - /* if first config ind */ if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) { /* update flags */ diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc index 46287eab2..892fc888a 100644 --- a/stack/bnep/bnep_main.cc +++ b/stack/bnep/bnep_main.cc @@ -205,7 +205,6 @@ static void bnep_connect_cfm(uint16_t l2cap_cid, uint16_t result) { ******************************************************************************/ static void bnep_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { tBNEP_CONN* p_bcb; - uint16_t result, mtu = 0; /* Find CCB based on CID */ p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); @@ -217,29 +216,13 @@ static void bnep_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { BNEP_TRACE_EVENT("BNEP - Rcvd cfg ind, CID: 0x%x", l2cap_cid); - /* Remember the remote MTU size */ - if ((!p_cfg->mtu_present) || (p_cfg->mtu < BNEP_MTU_SIZE)) { - mtu = p_cfg->mtu; - p_cfg->flush_to_present = false; - p_cfg->mtu_present = true; - p_cfg->mtu = BNEP_MTU_SIZE; - p_cfg->result = result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - } else { - - /* For now, always accept configuration from the other side */ - p_cfg->flush_to_present = false; - p_cfg->mtu_present = false; - p_cfg->result = result = L2CAP_CFG_OK; - } + /* For now, always accept configuration from the other side */ + p_cfg->flush_to_present = false; + p_cfg->mtu_present = false; + p_cfg->result = L2CAP_CFG_OK; L2CA_ConfigRsp(l2cap_cid, p_cfg); - if (result != L2CAP_CFG_OK) { - BNEP_TRACE_EVENT("BNEP - Rcvd cfg ind with bad MTU %d, CID: 0x%x", mtu, - l2cap_cid); - return; - } - p_bcb->con_flags |= BNEP_FLAGS_HIS_CFG_DONE; if (p_bcb->con_flags & BNEP_FLAGS_MY_CFG_DONE) { diff --git a/stack/l2cap/l2c_utils.cc b/stack/l2cap/l2c_utils.cc index 3d64cc6db..55626d1a5 100644 --- a/stack/l2cap/l2c_utils.cc +++ b/stack/l2cap/l2c_utils.cc @@ -1752,14 +1752,19 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { bool flush_to_ok = true; bool fcr_ok = true; uint8_t fcr_status; + uint16_t required_remote_mtu = + std::max(L2CAP_MIN_MTU, p_ccb->p_rcb->required_remote_mtu); /* Ignore FCR parameters for basic mode */ if (!p_cfg->fcr_present) p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; - /* Save the MTU that our peer can receive */ - if (p_cfg->mtu_present) { + if (!p_cfg->mtu_present && required_remote_mtu > L2CAP_DEFAULT_MTU) { + // We reject if we have a MTU requirement higher than default MTU + p_cfg->mtu = required_remote_mtu; + mtu_ok = false; + } else if (p_cfg->mtu_present) { /* Make sure MTU is at least the minimum */ - if (p_cfg->mtu >= L2CAP_MIN_MTU) { + if (p_cfg->mtu >= required_remote_mtu) { /* In basic mode, limit the MTU to our buffer size */ if ((!p_cfg->fcr_present) && (p_cfg->mtu > L2CAP_MTU_SIZE)) p_cfg->mtu = L2CAP_MTU_SIZE; @@ -1769,7 +1774,7 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { p_ccb->peer_cfg.mtu_present = true; } else /* Illegal MTU value */ { - p_cfg->mtu = L2CAP_MIN_MTU; + p_cfg->mtu = required_remote_mtu; mtu_ok = false; } }