OSDN Git Service

L2cap shim clean up
authorHansong Zhang <hsz@google.com>
Sun, 27 Sep 2020 22:18:57 +0000 (15:18 -0700)
committerHansong Zhang <hsz@google.com>
Mon, 28 Sep 2020 18:55:20 +0000 (11:55 -0700)
Now we send ConfigReq and ConfigRsp automatically, we need to send
callbacks automatically.

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

main/shim/l2c_api.cc
main/shim/l2c_api.h
main/shim/l2cap.cc
main/shim/l2cap.h

index 34dd015..7cbc751 100644 (file)
@@ -109,22 +109,10 @@ bool bluetooth::shim::L2CA_ConnectRsp(const RawAddress& p_bd_addr, uint8_t id,
   return shim_l2cap.ConnectResponse(p_bd_addr, id, lcid, result, status);
 }
 
-bool bluetooth::shim::L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* cfg_info) {
-  return shim_l2cap.ConfigRequest(cid, cfg_info);
-}
-
-bool bluetooth::shim::L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* cfg_info) {
-  return shim_l2cap.ConfigResponse(cid, cfg_info);
-}
-
 bool bluetooth::shim::L2CA_DisconnectReq(uint16_t cid) {
   return shim_l2cap.DisconnectRequest(cid);
 }
 
-bool bluetooth::shim::L2CA_DisconnectRsp(uint16_t cid) {
-  return shim_l2cap.DisconnectResponse(cid);
-}
-
 /**
  * Le Connection Oriented Channel APIs
  */
index 5fae24f..2432166 100644 (file)
@@ -189,29 +189,6 @@ bool L2CA_GetPeerLECocConfig(uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg);
 
 /*******************************************************************************
  *
- * Function         L2CA_ConfigReq
- *
- * Description      Higher layers call this function to send configuration.
- *
- * Returns          true if configuration sent, else false
- *
- ******************************************************************************/
-bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);
-
-/*******************************************************************************
- *
- * Function         L2CA_ConfigRsp
- *
- * Description      Higher layers call this function to send a configuration
- *                  response.
- *
- * Returns          true if configuration response sent, else false
- *
- ******************************************************************************/
-bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);
-
-/*******************************************************************************
- *
  * Function         L2CA_DisconnectReq
  *
  * Description      Higher layers call this function to disconnect a channel.
@@ -223,18 +200,6 @@ bool L2CA_DisconnectReq(uint16_t cid);
 
 /*******************************************************************************
  *
- * Function         L2CA_DisconnectRsp
- *
- * Description      Higher layers call this function to acknowledge the
- *                  disconnection of a channel.
- *
- * Returns          void
- *
- ******************************************************************************/
-bool L2CA_DisconnectRsp(uint16_t cid);
-
-/*******************************************************************************
- *
  * Function         L2CA_DataWrite
  *
  * Description      Higher layers call this function to write data.
index 09ba5bc..006bd23 100644 (file)
@@ -267,6 +267,15 @@ void bluetooth::shim::legacy::L2cap::OnLocalInitiatedConnectionCreated(
         FROM_HERE,
         base::Bind(classic_.Callbacks(psm).pL2CA_ConnectCfm_Cb, cid,
                    connected ? (kConnectionSuccess) : (kConnectionFail)));
+    tL2CAP_CFG_INFO cfg_info{};
+    do_in_main_thread(
+        FROM_HERE,
+        base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigInd_Cb, cid,
+                   base::Unretained(&cfg_info)));
+    do_in_main_thread(
+        FROM_HERE,
+        base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigCfm_Cb, cid,
+                   L2CAP_CFG_OK));
 
   } else {
     LOG_DEBUG("Connection Closed before presentation to upper layer");
@@ -298,6 +307,15 @@ void bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated(
       FROM_HERE,
       base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConnectInd_Cb,
                  raw_address, cid, psm, kUnusedId));
+  tL2CAP_CFG_INFO cfg_info{};
+  do_in_main_thread(
+      FROM_HERE,
+      base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigInd_Cb, cid,
+                 base::Unretained(&cfg_info)));
+  do_in_main_thread(
+      FROM_HERE,
+      base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigCfm_Cb, cid,
+                 L2CAP_CFG_OK));
 }
 
 bool bluetooth::shim::legacy::L2cap::Write(uint16_t cid, BT_HDR* bt_hdr) {
@@ -358,46 +376,6 @@ bool bluetooth::shim::legacy::L2cap::ConnectResponse(
   return true;
 }
 
-bool bluetooth::shim::legacy::L2cap::ConfigRequest(
-    uint16_t cid, const tL2CAP_CFG_INFO* config_info) {
-  LOG_INFO("Received config request from upper layer cid:%hd", cid);
-  CHECK(ConnectionExists(cid));
-
-  bluetooth::shim::GetL2cap()->SendLoopbackResponse([this, cid]() {
-    CHECK(ConnectionExists(cid));
-    tL2CAP_CFG_INFO cfg_info{
-        .result = L2CAP_CFG_OK,
-        .mtu_present = false,
-        .qos_present = false,
-        .flush_to_present = false,
-        .fcr_present = false,
-        .fcs_present = false,
-        .ext_flow_spec_present = false,
-        .flags = 0,
-    };
-    LOG(INFO) << __func__ << "Rcvd config request";
-    do_in_main_thread(
-        FROM_HERE,
-        base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigInd_Cb, cid,
-                   base::Unretained(&cfg_info)));
-    do_in_main_thread(
-        FROM_HERE,
-        base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigCfm_Cb, cid,
-                   L2CAP_CFG_OK));
-  });
-  return true;
-}
-
-bool bluetooth::shim::legacy::L2cap::ConfigResponse(
-    uint16_t cid, const tL2CAP_CFG_INFO* config_info) {
-  CHECK(ConnectionExists(cid));
-  LOG_DEBUG(
-
-      "%s Silently dropping client config response as channel is already open",
-      __func__);
-  return true;
-}
-
 bool bluetooth::shim::legacy::L2cap::DisconnectRequest(uint16_t cid) {
   CHECK(ConnectionExists(cid));
   if (cid_closing_set_.find(cid) != cid_closing_set_.end()) {
@@ -410,14 +388,6 @@ bool bluetooth::shim::legacy::L2cap::DisconnectRequest(uint16_t cid) {
   return true;
 }
 
-bool bluetooth::shim::legacy::L2cap::DisconnectResponse(uint16_t cid) {
-  LOG_DEBUG(
-      "%s Silently dropping client disconnect response as channel is "
-      "already disconnected",
-      __func__);
-  return true;
-}
-
 void bluetooth::shim::legacy::L2cap::Dump(int fd) {
   if (cid_to_psm_map_.empty()) {
     dprintf(fd, "%s No active l2cap channels\n", kModuleName);
index c710a97..4821f99 100644 (file)
@@ -85,10 +85,8 @@ class L2cap {
   // Legacy API entry points
   bool ConnectResponse(const RawAddress& raw_address, uint8_t signal_id,
                        uint16_t cid, uint16_t result, uint16_t status);
-  bool ConfigRequest(uint16_t cid, const tL2CAP_CFG_INFO* config_info);
-  bool ConfigResponse(uint16_t cid, const tL2CAP_CFG_INFO* config_info);
+
   bool DisconnectRequest(uint16_t cid);
-  bool DisconnectResponse(uint16_t cid);
 
   bool GetRemoteCid(uint16_t cid, uint16_t* remote_cid);