Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8410d0b6 authored by Archie Pusaka's avatar Archie Pusaka
Browse files

Fix SMP total_tx_unacked counting

total_tx_unacked needs to be incremented before L2CA_SendFixedChnlData
is called, because it is possible to call smp_tx_complete_callback
immediately, in which we should decrement the value but we can't since
it is still zero.

If this happens, we will be stuck with total_tx_unacked = 1 after the
SMP transaction is done, and we don't actually detect it as complete.

Bug: 319027651
Bug: 314819704
Test: m -j
Test: Pair with LE device, and run LE pairing tests.
Change-Id: I1fd32297f77f5d61ccd80f41f87639c1b3b3df56
parent ed670559
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -370,22 +370,29 @@ bool smp_send_msg_to_L2CAP(const RawAddress& rem_bda, BT_HDR* p_toL2CAP) {
                  p_toL2CAP->data + p_toL2CAP->offset, p_toL2CAP->len,
                  smp_cb.smp_over_br /* is_over_br */);

  l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP);
  if (l2cap_ret == L2CAP_DW_FAILED) {
    LOG_ERROR("SMP failed to pass msg to L2CAP");
    return false;
  } else {
#ifdef TARGET_FLOSS
  if (true)
#else
  if (IS_FLAG_ENABLED(l2cap_tx_complete_cb_info))
#endif
  {
      LOG_VERBOSE("l2cap_tx_complete_cb_info is enabled, exit here");
      smp_cb.total_tx_unacked += 1;
    /* Unacked needs to be incremented before calling SendFixedChnlData */
    smp_cb.total_tx_unacked++;
    l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP);
    if (l2cap_ret == L2CAP_DW_FAILED) {
      smp_cb.total_tx_unacked--;
      LOG_ERROR("SMP failed to pass msg to L2CAP");
      return false;
    }
    LOG_VERBOSE("l2cap_tx_complete_cb_info is enabled");
    return true;
  }

  l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP);
  if (l2cap_ret == L2CAP_DW_FAILED) {
    LOG_ERROR("SMP failed to pass msg to L2CAP");
    return false;
  } else {
    tSMP_CB* p_cb = &smp_cb;

    LOG_VERBOSE("l2cap_tx_complete_cb_info is disabled");