OSDN Git Service

L2CAP: Add a "required_remote_mtu" and store it
authorHansong Zhang <hsz@google.com>
Fri, 25 Sep 2020 00:50:55 +0000 (17:50 -0700)
committerHansong Zhang <hsz@google.com>
Fri, 25 Sep 2020 17:07:39 +0000 (10:07 -0700)
For AVCT_BR and BNEP, we need a larger required remote mtu than minimal
L2CAP MTU.

So far we enforce this in profile service itself, but later we can let
L2CAP module enforce this for us.

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

13 files changed:
stack/avct/avct_api.cc
stack/avdt/avdt_api.cc
stack/bnep/bnep_main.cc
stack/gap/gap_conn.cc
stack/gatt/gatt_main.cc
stack/hid/hidd_conn.cc
stack/hid/hidh_conn.cc
stack/include/l2c_api.h
stack/l2cap/l2c_api.cc
stack/l2cap/l2c_int.h
stack/rfcomm/rfc_l2cap_if.cc
stack/sdp/sdp_main.cc
stack/test/common/mock_l2cap_layer.cc

index 8f1729b..ddbcab4 100644 (file)
@@ -61,7 +61,7 @@ void AVCT_Register() {
 
   /* register PSM with L2CAP */
   L2CA_Register2(AVCT_PSM, avct_l2c_appl, true /* enable_snoop */, nullptr,
-                 kAvrcMtu, BTA_SEC_AUTHENTICATE);
+                 kAvrcMtu, 0, BTA_SEC_AUTHENTICATE);
 
   /* Include the browsing channel which uses eFCR */
   tL2CAP_ERTM_INFO ertm_info;
@@ -72,7 +72,8 @@ void AVCT_Register() {
   ertm_info.fcr_tx_buf_size = BT_DEFAULT_BUFFER_SIZE;
 
   L2CA_Register2(AVCT_BR_PSM, avct_l2c_br_appl, true /*enable_snoop*/,
-                 &ertm_info, kAvrcBrMtu, BTA_SEC_AUTHENTICATE);
+                 &ertm_info, kAvrcBrMtu, AVCT_MIN_BROWSE_MTU,
+                 BTA_SEC_AUTHENTICATE);
 
 #if defined(AVCT_INITIAL_TRACE_LEVEL)
   avct_cb.trace_level = AVCT_INITIAL_TRACE_LEVEL;
index 539d474..3dcea1f 100644 (file)
@@ -93,7 +93,7 @@ void avdt_scb_transport_channel_timer_timeout(void* data) {
 void AVDT_Register(AvdtpRcb* p_reg, tAVDT_CTRL_CBACK* p_cback) {
   /* register PSM with L2CAP */
   L2CA_Register2(AVDT_PSM, avdt_l2c_appl, true /* enable_snoop */, nullptr,
-                 kAvdtpMtu, BTA_SEC_AUTHENTICATE);
+                 kAvdtpMtu, 0, BTA_SEC_AUTHENTICATE);
 
   /* initialize AVDTP data structures */
   avdt_scb_init();
index d2f5785..46287ea 100644 (file)
@@ -92,7 +92,7 @@ tBNEP_RESULT bnep_register_with_l2cap(void) {
 
   /* Now, register with L2CAP */
   if (!L2CA_Register2(BT_PSM_BNEP, bnep_cb.reg_info, false /* enable_snoop */,
-                      nullptr, BNEP_MTU_SIZE,
+                      nullptr, BNEP_MTU_SIZE, BNEP_MTU_SIZE,
                       BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     BNEP_TRACE_ERROR("BNEP - Registration failed");
     return BNEP_SECURITY_FAIL;
index 281d5fe..4d69f08 100644 (file)
@@ -241,7 +241,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
   if (transport == BT_TRANSPORT_BR_EDR) {
     p_ccb->psm =
         L2CA_Register2(psm, conn.reg_info, false /* enable_snoop */,
-                       &p_ccb->ertm_info, L2CAP_SDU_LENGTH_MAX, security);
+                       &p_ccb->ertm_info, L2CAP_SDU_LENGTH_MAX, 0, security);
     if (p_ccb->psm == 0) {
       LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__,
                                  psm);
index 9a0d68d..2a0f75e 100644 (file)
@@ -114,7 +114,7 @@ void gatt_init(void) {
 
   /* Now, register with L2CAP for ATT PSM over BR/EDR */
   if (!L2CA_Register2(BT_PSM_ATT, dyn_info, false /* enable_snoop */, nullptr,
-                      GATT_MAX_MTU_SIZE, BTM_SEC_NONE)) {
+                      GATT_MAX_MTU_SIZE, 0, BTM_SEC_NONE)) {
     LOG(ERROR) << "ATT Dynamic Registration failed";
   }
 
index 874ba33..e1480f0 100644 (file)
@@ -742,14 +742,14 @@ tHID_STATUS hidd_conn_reg(void) {
   hd_cb.l2cap_intr_cfg.mtu = HID_DEV_MTU_SIZE;
 
   if (!L2CA_Register2(HID_PSM_CONTROL, dev_reg_info, false /* enable_snoop */,
-                      nullptr, HID_DEV_MTU_SIZE,
+                      nullptr, HID_DEV_MTU_SIZE, 0,
                       BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     HIDD_TRACE_ERROR("HID Control (device) registration failed");
     return (HID_ERR_L2CAP_FAILED);
   }
 
   if (!L2CA_Register2(HID_PSM_INTERRUPT, dev_reg_info, false /* enable_snoop */,
-                      nullptr, HID_DEV_MTU_SIZE,
+                      nullptr, HID_DEV_MTU_SIZE, 0,
                       BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     L2CA_Deregister(HID_PSM_CONTROL);
     HIDD_TRACE_ERROR("HID Interrupt (device) registration failed");
index 6d9527e..a6d2c83 100644 (file)
@@ -92,7 +92,7 @@ tHID_STATUS hidh_conn_reg(void) {
 
   /* Now, register with L2CAP */
   if (!L2CA_Register2(HID_PSM_INTERRUPT, hst_reg_info, false /* enable_snoop */,
-                      nullptr, HID_HOST_MTU,
+                      nullptr, HID_HOST_MTU, 0,
                       BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
     L2CA_Deregister(HID_PSM_CONTROL);
     HIDH_TRACE_ERROR("HID-Host Interrupt Registration failed");
index a410c81..1a75312 100644 (file)
@@ -278,7 +278,8 @@ void l2c_free();
 // Also does security for you
 uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                         bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
-                        uint16_t required_mtu, uint16_t sec_level);
+                        uint16_t my_mtu, uint16_t required_remote_mtu,
+                        uint16_t sec_level);
 
 /*******************************************************************************
  *
@@ -296,7 +297,7 @@ uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
  ******************************************************************************/
 extern uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                               bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
-                              uint16_t required_mtu);
+                              uint16_t my_mtu, uint16_t required_remote_mtu);
 
 /*******************************************************************************
  *
index 9033288..d3bce82 100644 (file)
@@ -44,9 +44,10 @@ using base::StringPrintf;
 
 uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                         bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
-                        uint16_t required_mtu, uint16_t sec_level) {
-  auto ret =
-      L2CA_Register(psm, p_cb_info, enable_snoop, p_ertm_info, required_mtu);
+                        uint16_t my_mtu, uint16_t required_remote_mtu,
+                        uint16_t sec_level) {
+  auto ret = L2CA_Register(psm, p_cb_info, enable_snoop, p_ertm_info, my_mtu,
+                           required_remote_mtu);
   BTM_SetSecurityLevel(false, "", 0, sec_level, psm, 0, 0);
   return ret;
 }
@@ -67,10 +68,10 @@ uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
  ******************************************************************************/
 uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                        bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
-                       uint16_t required_mtu) {
+                       uint16_t my_mtu, uint16_t required_remote_mtu) {
   if (bluetooth::shim::is_gd_shim_enabled()) {
     return bluetooth::shim::L2CA_Register(psm, p_cb_info, enable_snoop,
-                                          p_ertm_info, required_mtu);
+                                          p_ertm_info, my_mtu);
   }
 
   tL2C_RCB* p_rcb;
@@ -122,7 +123,9 @@ uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
   p_rcb->api = p_cb_info;
   p_rcb->real_psm = psm;
   p_rcb->ertm_info = p_ertm_info == nullptr ? tL2CAP_ERTM_INFO{} : *p_ertm_info;
-  p_rcb->required_mtu = std::max<uint16_t>(required_mtu, L2CAP_DEFAULT_MTU);
+  p_rcb->my_mtu = my_mtu;
+  p_rcb->required_remote_mtu =
+      std::max<uint16_t>(required_remote_mtu, L2CAP_MIN_MTU);
 
   return (vpsm);
 }
index cd5f2d9..bcf1c23 100644 (file)
@@ -202,7 +202,8 @@ typedef struct {
                      /* this is the real PSM that we need to connect to */
   tL2CAP_APPL_INFO api;
   tL2CAP_ERTM_INFO ertm_info;
-  uint16_t required_mtu;
+  uint16_t my_mtu;
+  uint16_t required_remote_mtu;
 } tL2C_RCB;
 
 #define L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA 100
index e7bee29..4fdcdf2 100644 (file)
@@ -71,7 +71,7 @@ void rfcomm_l2cap_if_init(void) {
   p_l2c->pL2CA_TxComplete_Cb = NULL;
 
   L2CA_Register(BT_PSM_RFCOMM, rfc_cb.rfc.reg_info, true /* enable_snoop */,
-                nullptr, L2CAP_MTU_SIZE);
+                nullptr, L2CAP_MTU_SIZE, 0);
 }
 
 /*******************************************************************************
index 52fe345..3622a08 100644 (file)
@@ -90,7 +90,7 @@ void sdp_init(void) {
 
   /* Now, register with L2CAP */
   if (!L2CA_Register2(SDP_PSM, sdp_cb.reg_info, true /* enable_snoop */,
-                      nullptr, SDP_MTU_SIZE, BTM_SEC_NONE)) {
+                      nullptr, SDP_MTU_SIZE, 0, BTM_SEC_NONE)) {
     SDP_TRACE_ERROR("SDP Registration failed");
   }
 }
index a43a6ba..33e8643 100644 (file)
@@ -26,7 +26,7 @@ void bluetooth::l2cap::SetMockInterface(
 
 uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                        bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
-                       uint16_t required_mtu) {
+                       uint16_t my_mtu, uint16_t required_remote_mtu) {
   VLOG(1) << __func__ << ": psm=" << psm << ", enable_snoop=" << enable_snoop;
   return l2cap_interface->Register(psm, p_cb_info, enable_snoop, p_ertm_info);
 }