OSDN Git Service

L2CAP: Allowed mode is equivalent to preferred mode
authorHansong Zhang <hsz@google.com>
Thu, 24 Sep 2020 00:25:39 +0000 (17:25 -0700)
committerHansong Zhang <hsz@google.com>
Thu, 24 Sep 2020 02:14:16 +0000 (19:14 -0700)
In all use cases, we want one BASIC or ERTM exculsively, but we never
allow "both are ok" mode.

Remove allowed_mode.  Use preferred_mode to denote the desired mode.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I846eca1912fc9ea04dfa57c5698039d62e634186

btif/src/btif_sock_l2cap.cc
stack/avct/avct_api.cc
stack/avct/avct_bcb_act.cc
stack/avct/avct_l2c_br.cc
stack/gap/gap_conn.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc
stack/l2cap/l2c_fcr.cc
stack/l2cap/l2c_utils.cc

index 7f74a58..bd3cc85 100644 (file)
@@ -672,7 +672,6 @@ const tL2CAP_FCR_OPTS obex_l2c_fcr_opts_def = {
 };
 const tL2CAP_ERTM_INFO obex_l2c_etm_opt = {
     L2CAP_FCR_ERTM_MODE,     /* Mandatory for OBEX over l2cap */
-    L2CAP_FCR_CHAN_OPT_ERTM, /* Mandatory for OBEX over l2cap */
     OBX_USER_RX_BUF_SIZE,    OBX_USER_TX_BUF_SIZE,
     OBX_FCR_RX_BUF_SIZE,     OBX_FCR_TX_BUF_SIZE};
 
index f76093d..f620528 100644 (file)
@@ -70,7 +70,6 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
   /* Include the browsing channel which uses eFCR */
   tL2CAP_ERTM_INFO ertm_info;
   ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;
-  ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM;
   ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE;
   ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE;
   ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE;
index 2508f76..9f813ad 100644 (file)
@@ -107,7 +107,6 @@ void avct_bcb_chnl_open(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) {
 
   /* Set the FCR options: Browsing channel mandates ERTM */
   ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;
-  ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM;
   ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE;
   ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE;
   ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE;
index fb9234a..00b4557 100644 (file)
@@ -145,7 +145,6 @@ void avct_l2c_br_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,
 
   /* Set the FCR options: Browsing channel mandates ERTM */
   ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;
-  ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM;
   ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE;
   ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE;
   ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE;
index 6394c50..1f86adb 100644 (file)
@@ -259,12 +259,6 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
     }
   }
 
-  /* optional FCR channel modes */
-  if (ertm_info != NULL) {
-    p_ccb->ertm_info.allowed_modes =
-        (chan_mode_mask) ? chan_mode_mask : (uint8_t)L2CAP_FCR_CHAN_OPT_BASIC;
-  }
-
   if (is_server) {
     p_ccb->con_flags |=
         GAP_CCB_FLAGS_SEC_DONE; /* assume btm/l2cap would handle it */
index f22c8a2..a410c81 100644 (file)
@@ -259,7 +259,6 @@ typedef struct {
  */
 typedef struct {
   uint8_t preferred_mode;
-  uint8_t allowed_modes;
   uint16_t user_rx_buf_size;
   uint16_t user_tx_buf_size;
   uint16_t fcr_rx_buf_size;
index d599098..9033288 100644 (file)
@@ -352,8 +352,7 @@ uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr,
   }
 
   VLOG(1) << __func__ << "BDA " << p_bd_addr
-          << StringPrintf(" PSM: 0x%04x allowed:0x%x preferred:%d", psm,
-                          (p_ertm_info) ? p_ertm_info->allowed_modes : 0,
+          << StringPrintf(" PSM: 0x%04x preferred:%d", psm,
                           (p_ertm_info) ? p_ertm_info->preferred_mode : 0);
 
   /* Fail if we have not established communications with the controller */
index 5bc436c..4c6e90e 100644 (file)
@@ -1626,16 +1626,14 @@ uint8_t l2c_fcr_chk_chan_modes(tL2C_CCB* p_ccb) {
   CHECK(p_ccb != NULL);
 
   /* 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.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_ERTM;
-
-  /* At least one type needs to be set (Basic, ERTM, STM) to continue */
-  if (!p_ccb->ertm_info.allowed_modes) {
+  if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_ENH_RETRANS) &&
+      p_ccb->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;
+    return false;
   }
-
-  return (p_ccb->ertm_info.allowed_modes);
+  return true;
 }
 
 /*******************************************************************************
@@ -1666,7 +1664,7 @@ bool l2c_fcr_adj_our_req_options(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) {
   }
 
   /* If upper layer did not request eRTM mode, BASIC must be used */
-  if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC) {
+  if (p_ccb->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 "
@@ -1690,7 +1688,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.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC) {
+    else if (p_ccb->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;
@@ -1868,7 +1866,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.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC) {
+          if (p_ccb->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;
@@ -1936,14 +1934,14 @@ uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) {
 
   L2CAP_TRACE_EVENT(
       "l2c_fcr_process_peer_cfg_req() CFG fcr_present:%d fcr.mode:%d CCB FCR "
-      "mode:%d preferred: %u allowed:%u",
+      "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->ertm_info.allowed_modes);
+      p_ccb->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.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC))
+    if (p_ccb->ertm_info.preferred_mode != L2CAP_FCR_BASIC_MODE)
       fcr_ok = L2CAP_PEER_CFG_DISCONNECT;
   }
 
@@ -1973,12 +1971,10 @@ uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) {
       fcr_ok = L2CAP_PEER_CFG_UNACCEPTABLE;
     }
 
-    /* Only other valid case is if they want ERTM and we wanted STM which should
-       be
-       accepted if we support it; otherwise the channel should be disconnected
-       */
+    /* Only other valid case is if they want BASIC and we wanted ERTM
+     */
     else if ((p_cfg->fcr.mode != L2CAP_FCR_ERTM_MODE) ||
-             !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM)) {
+             (p_ccb->ertm_info.preferred_mode != L2CAP_FCR_ERTM_MODE)) {
       fcr_ok = L2CAP_PEER_CFG_DISCONNECT;
     }
   }
index 1e580c1..3078dc5 100644 (file)
@@ -1375,8 +1375,6 @@ tL2C_CCB* l2cu_allocate_ccb(tL2C_LCB* p_lcb, uint16_t cid) {
 
   p_ccb->ertm_info.preferred_mode =
       L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */
-  p_ccb->ertm_info.allowed_modes =
-      L2CAP_FCR_CHAN_OPT_BASIC; /* Default mode for channel is basic mode */
   p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
   p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE;
   p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE;