Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc691bc8 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

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
parent b5c07eeb
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -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;
  }

  /* 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 */
+4 −21
Original line number Diff line number Diff line
@@ -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;
  }
  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) {
+9 −4
Original line number Diff line number Diff line
@@ -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<uint16_t>(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;
    }
  }