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

Commit 36762115 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Race condition with channel closure"

parents fbea9d63 db32dc8a
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -312,10 +312,17 @@ bool bluetooth::legacy::shim::L2cap::SetCallbacks(
  bluetooth::shim::GetL2cap()->SetConnectionClosedCallback(
      cid, [this](uint16_t cid, int error_code) {
        LOG_DEBUG(LOG_TAG, "OnChannel closed callback cid:%hd", cid);
        CHECK(cid_to_callback_map_.find(cid) != cid_to_callback_map_.end());
        if (cid_to_callback_map_.find(cid) != cid_to_callback_map_.end()) {
          cid_to_callback_map_[cid]->pL2CA_DisconnectInd_Cb(
              cid, kDisconnectResponseRequired);
          cid_to_callback_map_.erase(cid);
        } else if (cid_closing_set_.count(cid) == 1) {
          cid_closing_set_.erase(cid);
        } else {
          LOG_WARN(LOG_TAG, "%s Unexpected channel closure cid:%hd", __func__,
                   cid);
        }
        CHECK(cid_to_psm_map_.find(cid) != cid_to_psm_map_.end());
        cid_to_psm_map_.erase(cid);
      });
  return true;
@@ -369,8 +376,10 @@ bool bluetooth::legacy::shim::L2cap::ConfigResponse(

bool bluetooth::legacy::shim::L2cap::DisconnectRequest(uint16_t cid) {
  CHECK(ConnectionExists(cid));
  cid_to_callback_map_.erase(cid);
  LOG_DEBUG(LOG_TAG, "%s cid:%hu", __func__, cid);
  bluetooth::shim::GetL2cap()->CloseConnection(cid);
  cid_to_callback_map_.erase(cid);
  cid_closing_set_.insert(cid);
  return true;
}

+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <cstdint>
#include <set>
#include <unordered_map>

#include "stack/include/l2c_api.h"
@@ -103,6 +104,8 @@ class L2cap {
  std::unordered_map<uint16_t,
                     std::function<void(std::function<void(uint16_t c)>)>>
      cid_to_postable_map_;
  std::set<uint16_t> cid_closing_set_;

  std::unordered_map<uint16_t, uint16_t> cid_to_psm_map_;
  std::unordered_map<uint16_t, uint16_t> client_psm_to_real_psm_map_;
  std::unordered_map<uint16_t, const tL2CAP_APPL_INFO*> cid_to_callback_map_;