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

Commit 432050b4 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2cap shim namespace clean up

Tag: #gd-refactor
Bug: 141555841
Test: cert/run --host
Change-Id: Id1b152a6f679b5141c1ae80eab0696d6dafe6087
parent 320bcc1e
Loading
Loading
Loading
Loading
+19 −23
Original line number Original line Diff line number Diff line
@@ -33,6 +33,9 @@
#include "stack/include/acl_hci_link_interface.h"
#include "stack/include/acl_hci_link_interface.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_api.h"


using bluetooth::hci::AddressWithType;
using namespace bluetooth::l2cap;

static bluetooth::shim::legacy::L2cap shim_l2cap;
static bluetooth::shim::legacy::L2cap shim_l2cap;


// Helper: L2cap security enforcement shim
// Helper: L2cap security enforcement shim
@@ -409,32 +412,24 @@ bool bluetooth::shim::L2CA_GetPeerFeatures(const RawAddress& bd_addr,
  return false;
  return false;
}
}


using bluetooth::hci::AddressWithType;
using bluetooth::l2cap::le::DynamicChannel;
using bluetooth::l2cap::le::DynamicChannelManager;
using bluetooth::l2cap::le::DynamicChannelService;
using bluetooth::l2cap::le::FixedChannel;
using bluetooth::l2cap::le::FixedChannelManager;
using bluetooth::l2cap::le::FixedChannelService;

static constexpr uint16_t kAttCid = 4;
static constexpr uint16_t kAttCid = 4;
static constexpr uint16_t kSmpCid = 6;


struct LeFixedChannelHelper {
struct LeFixedChannelHelper {
  LeFixedChannelHelper(uint16_t cid) : cid_(cid) {}
  LeFixedChannelHelper(uint16_t cid) : cid_(cid) {}


  uint16_t cid_;
  uint16_t cid_;


  void on_registration_complete(FixedChannelManager::RegistrationResult result,
  void on_registration_complete(
                                std::unique_ptr<FixedChannelService> service) {
      le::FixedChannelManager::RegistrationResult result,
    if (result != FixedChannelManager::RegistrationResult::SUCCESS) {
      std::unique_ptr<le::FixedChannelService> service) {
    if (result != le::FixedChannelManager::RegistrationResult::SUCCESS) {
      LOG(ERROR) << "Channel is not registered. cid=" << +cid_;
      LOG(ERROR) << "Channel is not registered. cid=" << +cid_;
      return;
      return;
    }
    }
    channel_service_ = std::move(service);
    channel_service_ = std::move(service);
  }
  }


  std::unique_ptr<FixedChannelService> channel_service_ = nullptr;
  std::unique_ptr<le::FixedChannelService> channel_service_ = nullptr;


  void on_channel_close(bluetooth::hci::AddressWithType device,
  void on_channel_close(bluetooth::hci::AddressWithType device,
                        bluetooth::hci::ErrorCode error_code) {
                        bluetooth::hci::ErrorCode error_code) {
@@ -445,7 +440,7 @@ struct LeFixedChannelHelper {
    (freg_.pL2CA_FixedConn_Cb)(cid_, address, true, 0, 2);
    (freg_.pL2CA_FixedConn_Cb)(cid_, address, true, 0, 2);
  }
  }


  void on_channel_open(std::unique_ptr<FixedChannel> channel) {
  void on_channel_open(std::unique_ptr<le::FixedChannel> channel) {
    auto device = channel->GetDevice();
    auto device = channel->GetDevice();
    channel->RegisterOnCloseCallback(
    channel->RegisterOnCloseCallback(
        bluetooth::shim::GetGdShimHandler(),
        bluetooth::shim::GetGdShimHandler(),
@@ -486,7 +481,7 @@ struct LeFixedChannelHelper {
  }
  }


  void on_outgoing_connection_fail(
  void on_outgoing_connection_fail(
      RawAddress remote, FixedChannelManager::ConnectionResult result) {
      RawAddress remote, le::FixedChannelManager::ConnectionResult result) {
    LOG(ERROR) << "Outgoing connection failed";
    LOG(ERROR) << "Outgoing connection failed";
    freg_.pL2CA_FixedConn_Cb(cid_, remote, true, 0, BT_TRANSPORT_LE);
    freg_.pL2CA_FixedConn_Cb(cid_, remote, true, 0, BT_TRANSPORT_LE);
  }
  }
@@ -503,7 +498,8 @@ struct LeFixedChannelHelper {
    return true;
    return true;
  }
  }


  std::unordered_map<AddressWithType, std::unique_ptr<FixedChannel>> channels_;
  std::unordered_map<AddressWithType, std::unique_ptr<le::FixedChannel>>
      channels_;
  std::unordered_map<AddressWithType,
  std::unordered_map<AddressWithType,
                     std::unique_ptr<bluetooth::os::EnqueueBuffer<
                     std::unique_ptr<bluetooth::os::EnqueueBuffer<
                         bluetooth::packet::BasePacketBuilder>>>
                         bluetooth::packet::BasePacketBuilder>>>
@@ -704,16 +700,16 @@ struct LeDynamicChannelHelper {
  }
  }


  void on_registration_complete(
  void on_registration_complete(
      DynamicChannelManager::RegistrationResult result,
      le::DynamicChannelManager::RegistrationResult result,
      std::unique_ptr<DynamicChannelService> service) {
      std::unique_ptr<le::DynamicChannelService> service) {
    if (result != DynamicChannelManager::RegistrationResult::SUCCESS) {
    if (result != le::DynamicChannelManager::RegistrationResult::SUCCESS) {
      LOG(ERROR) << "Channel is not registered. psm=" << +psm_ << (int)result;
      LOG(ERROR) << "Channel is not registered. psm=" << +psm_ << (int)result;
      return;
      return;
    }
    }
    channel_service_ = std::move(service);
    channel_service_ = std::move(service);
  }
  }


  std::unique_ptr<DynamicChannelService> channel_service_ = nullptr;
  std::unique_ptr<le::DynamicChannelService> channel_service_ = nullptr;


  void Connect(bluetooth::hci::AddressWithType device) {
  void Connect(bluetooth::hci::AddressWithType device) {
    if (channel_service_ == nullptr) {
    if (channel_service_ == nullptr) {
@@ -776,7 +772,7 @@ struct LeDynamicChannelHelper {
    }
    }
  }
  }


  void on_channel_open(std::unique_ptr<DynamicChannel> channel) {
  void on_channel_open(std::unique_ptr<le::DynamicChannel> channel) {
    auto device = channel->GetDevice();
    auto device = channel->GetDevice();
    channel->RegisterOnCloseCallback(
    channel->RegisterOnCloseCallback(
        bluetooth::shim::GetGdShimHandler()->BindOnceOn(
        bluetooth::shim::GetGdShimHandler()->BindOnceOn(
@@ -822,7 +818,7 @@ struct LeDynamicChannelHelper {
  }
  }


  void on_outgoing_connection_fail(
  void on_outgoing_connection_fail(
      DynamicChannelManager::ConnectionResult result) {
      le::DynamicChannelManager::ConnectionResult result) {
    LOG(ERROR) << "Outgoing connection failed";
    LOG(ERROR) << "Outgoing connection failed";
  }
  }


@@ -845,7 +841,7 @@ struct LeDynamicChannelHelper {
    return static_cast<uint16_t>(channels_[remote]->GetMtu());
    return static_cast<uint16_t>(channels_[remote]->GetMtu());
  }
  }


  std::unordered_map<AddressWithType, std::unique_ptr<DynamicChannel>>
  std::unordered_map<AddressWithType, std::unique_ptr<le::DynamicChannel>>
      channels_;
      channels_;
  std::unordered_map<AddressWithType,
  std::unordered_map<AddressWithType,
                     std::unique_ptr<bluetooth::os::EnqueueBuffer<
                     std::unique_ptr<bluetooth::os::EnqueueBuffer<