OSDN Git Service

SMP: Assume L2cap tx completes immediately
authorHansong Zhang <hsz@google.com>
Fri, 2 Oct 2020 00:47:03 +0000 (17:47 -0700)
committerHansong Zhang <hsz@google.com>
Fri, 2 Oct 2020 22:50:58 +0000 (15:50 -0700)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I5bf5c5067f3ad3d48716fdc65f73920107d034cf

stack/smp/smp_l2c.cc
stack/smp/smp_utils.cc

index 2e0025c..f652c29 100644 (file)
@@ -208,24 +208,7 @@ static void smp_data_received(uint16_t channel, const RawAddress& bd_addr,
  * Description      SMP channel tx complete callback
  *
  ******************************************************************************/
-static void smp_tx_complete_callback(uint16_t cid, uint16_t num_pkt) {
-  tSMP_CB* p_cb = &smp_cb;
-
-  if (p_cb->total_tx_unacked >= num_pkt)
-    p_cb->total_tx_unacked -= num_pkt;
-  else
-    SMP_TRACE_ERROR("Unexpected %s: num_pkt = %d", __func__, num_pkt);
-
-  if (p_cb->total_tx_unacked == 0 && p_cb->wait_for_authorization_complete) {
-    tSMP_INT_DATA smp_int_data;
-    smp_int_data.status = SMP_SUCCESS;
-    if (cid == L2CAP_SMP_CID) {
-      smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
-    } else {
-      smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data);
-    }
-  }
-}
+static void smp_tx_complete_callback(uint16_t cid, uint16_t num_pkt) {}
 
 /*******************************************************************************
  *
index 9716468..43ae4ea 100644 (file)
@@ -340,18 +340,28 @@ bool smp_send_msg_to_L2CAP(const RawAddress& rem_bda, BT_HDR* p_toL2CAP) {
   }
 
   SMP_TRACE_EVENT("%s", __func__);
-  smp_cb.total_tx_unacked += 1;
 
   smp_log_metrics(rem_bda, true /* outgoing */,
                   p_toL2CAP->data + p_toL2CAP->offset, p_toL2CAP->len);
 
   l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP);
   if (l2cap_ret == L2CAP_DW_FAILED) {
-    smp_cb.total_tx_unacked -= 1;
     SMP_TRACE_ERROR("SMP failed to pass msg to L2CAP");
     return false;
-  } else
+  } else {
+    tSMP_CB* p_cb = &smp_cb;
+
+    if (p_cb->wait_for_authorization_complete) {
+      tSMP_INT_DATA smp_int_data;
+      smp_int_data.status = SMP_SUCCESS;
+      if (fixed_cid == L2CAP_SMP_CID) {
+        smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
+      } else {
+        smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &smp_int_data);
+      }
+    }
     return true;
+  }
 }
 
 /*******************************************************************************