OSDN Git Service

L2cap shim: Add mtu requirement to config option
authorHansong Zhang <hsz@google.com>
Tue, 29 Sep 2020 04:56:13 +0000 (21:56 -0700)
committerHansong Zhang <hsz@google.com>
Tue, 29 Sep 2020 17:09:35 +0000 (10:09 -0700)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ib0da747b905df5edfc1f03518a565f1ed914a148

gd/shim/l2cap.cc
gd/shim/l2cap.h
gd/shim/l2cap_test.cc
main/shim/l2c_api.cc
main/shim/l2c_api.h
main/shim/l2cap.cc
main/shim/l2cap.h
stack/l2cap/l2c_api.cc

index e3954bd..2a88e7e 100644 (file)
@@ -611,6 +611,7 @@ void L2cap::RegisterClassicService(
     uint16_t raw_psm,
     bool use_ertm,
     uint16_t mtu,
+    uint16_t required_remote_mtu,
     ConnectionCompleteCallback on_complete,
     RegisterServicePromise register_promise) {
   l2cap::Psm psm{raw_psm};
@@ -620,6 +621,7 @@ void L2cap::RegisterClassicService(
         l2cap::classic::DynamicChannelConfigurationOption::RetransmissionAndFlowControlMode::ENHANCED_RETRANSMISSION;
   }
   option.incoming_mtu = mtu;
+  option.minimal_remote_mtu = required_remote_mtu;
   GetHandler()->Post(common::BindOnce(
       &L2cap::impl::RegisterService,
       common::Unretained(pimpl_.get()),
index 206b0a9..8686de7 100644 (file)
@@ -41,6 +41,7 @@ class L2cap : public bluetooth::Module {
       uint16_t psm,
       bool use_ertm,
       uint16_t mtu,
+      uint16_t required_remote_mtu,
       ConnectionCompleteCallback on_complete,
       RegisterServicePromise register_promise);
   void UnregisterClassicService(uint16_t psm, UnregisterServicePromise unregister_promise);
index 9f9e41f..ef6d82c 100644 (file)
@@ -401,6 +401,7 @@ TEST_F(ShimL2capTest, RegisterService_Success) {
       kPsm,
       kNoUseErtm,
       kMtu,
+      kMtu,
       std::bind(
           &bluetooth::shim::ShimL2capTest::OnConnectionComplete,
           this,
@@ -432,6 +433,7 @@ TEST_F(ShimL2capTest, RegisterService_Duplicate) {
       kPsm,
       kNoUseErtm,
       kMtu,
+      kMtu,
       std::bind(
           &bluetooth::shim::ShimL2capTest::OnConnectionComplete,
           this,
@@ -464,6 +466,7 @@ TEST_F(ShimL2capTest, RegisterService_Invalid) {
       kPsm,
       kNoUseErtm,
       kMtu,
+      kMtu,
       std::bind(
           &bluetooth::shim::ShimL2capTest::OnConnectionComplete,
           this,
index 1719960..3e41194 100644 (file)
@@ -35,7 +35,8 @@ uint16_t bluetooth::shim::L2CA_Register(uint16_t client_psm,
                                         const tL2CAP_APPL_INFO& callbacks,
                                         bool enable_snoop,
                                         tL2CAP_ERTM_INFO* p_ertm_info,
-                                        uint16_t required_mtu) {
+                                        uint16_t my_mtu,
+                                        uint16_t required_remote_mtu) {
   if (L2C_INVALID_PSM(client_psm)) {
     LOG_ERROR("%s Invalid classic psm:%hd", __func__, client_psm);
     return 0;
@@ -63,9 +64,10 @@ uint16_t bluetooth::shim::L2CA_Register(uint16_t client_psm,
     return 0;
   }
   LOG_INFO("%s classic client_psm:%hd psm:%hd", __func__, client_psm, psm);
-
+  // Minimum acceptable MTU is 48 bytes
+  required_remote_mtu = std::max<uint16_t>(required_remote_mtu, 48);
   return shim_l2cap.RegisterService(psm, callbacks, enable_snoop, p_ertm_info,
-                                    required_mtu);
+                                    my_mtu, required_remote_mtu);
 }
 
 void bluetooth::shim::L2CA_Deregister(uint16_t client_psm) {
index d261191..b67f539 100644 (file)
@@ -40,7 +40,7 @@ namespace shim {
  ******************************************************************************/
 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 8b4eb42..15e2b4d 100644 (file)
@@ -161,7 +161,8 @@ uint16_t bluetooth::shim::legacy::L2cap::GetNextDynamicClassicPsm() {
 
 uint16_t bluetooth::shim::legacy::L2cap::RegisterService(
     uint16_t psm, const tL2CAP_APPL_INFO& callbacks, bool enable_snoop,
-    tL2CAP_ERTM_INFO* p_ertm_info, uint16_t required_mtu) {
+    tL2CAP_ERTM_INFO* p_ertm_info, uint16_t my_mtu,
+    uint16_t required_remote_mtu) {
   if (Classic().IsPsmRegistered(psm)) {
     LOG_WARN("Service is already registered psm:%hd", psm);
     return 0;
@@ -179,7 +180,7 @@ uint16_t bluetooth::shim::legacy::L2cap::RegisterService(
     use_ertm = true;
   }
   bluetooth::shim::GetL2cap()->RegisterClassicService(
-      psm, use_ertm, required_mtu,
+      psm, use_ertm, my_mtu, required_remote_mtu,
       std::bind(
           &bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated,
           this, std::placeholders::_1, std::placeholders::_2,
index 581c35f..ea8400b 100644 (file)
@@ -60,7 +60,7 @@ class L2cap {
  public:
   uint16_t RegisterService(uint16_t psm, const tL2CAP_APPL_INFO& callbacks,
                            bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
-                           uint16_t required_mtu);
+                           uint16_t my_mtu, uint16_t required_remote_mtu);
   void UnregisterService(uint16_t psm);
 
   uint16_t CreateConnection(uint16_t psm, const RawAddress& raw_address);
index 0087a8c..5e92ce9 100644 (file)
@@ -70,8 +70,8 @@ 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 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, my_mtu);
+    return bluetooth::shim::L2CA_Register(
+        psm, p_cb_info, enable_snoop, p_ertm_info, my_mtu, required_remote_mtu);
   }
 
   tL2C_RCB* p_rcb;