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

Commit 8b325fec authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2cap shim: Implement L2CA_GetBleConnRole

Note: We haven't routed LE link property callbacks yet.

Test: cert/run
Tag: #gd-refactor
Bug: 141555841
Change-Id: I987fbcede2e8e9e133418c72cb2d99dda0253b40
parent 986face4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ class LinkPropertyListener {
  /**
   * Invoked when an ACL link is connected.
   */
  virtual void OnLinkConnected(hci::AddressWithType remote, uint16_t handle) {}
  virtual void OnLinkConnected(hci::AddressWithType remote, uint16_t handle, hci::Role my_role) {}

  /**
   * Invoked when an ACL link is disconnected.
+13 −1
Original line number Diff line number Diff line
@@ -484,9 +484,12 @@ bluetooth::l2cap::classic::SecurityInterface* security_interface_ = nullptr;
struct LeLinkPropertyListenerShim
    : public bluetooth::l2cap::le::LinkPropertyListener {
  std::unordered_map<hci::AddressWithType, uint16_t> address_to_handle_;
  std::unordered_map<hci::AddressWithType, hci::Role> address_to_role_;

  void OnLinkConnected(hci::AddressWithType remote, uint16_t handle) override {
  void OnLinkConnected(hci::AddressWithType remote, uint16_t handle,
                       hci::Role role) override {
    address_to_handle_[remote] = handle;
    address_to_role_[remote] = role;
  }

  void OnLinkDisconnected(hci::AddressWithType remote) override {
@@ -1042,6 +1045,15 @@ bool L2CA_IsLeLink(uint16_t acl_handle) {
  return false;
}

hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr) {
  auto remote = ToAddressWithType(bd_addr, Btm::GetAddressType(bd_addr));
  if (le_link_property_listener_shim_.address_to_role_.count(remote) == 0) {
    return HCI_ROLE_UNKNOWN;
  }
  return static_cast<hci_role_t>(
      le_link_property_listener_shim_.address_to_role_[remote]);
}

void L2CA_ConnectForSecurity(const RawAddress& bd_addr) {
  security_interface_->InitiateConnectionForSecurity(
      bluetooth::ToGdAddress(bd_addr));
+1 −0
Original line number Diff line number Diff line
@@ -394,6 +394,7 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,
bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda);

uint16_t L2CA_GetLeHandle(uint16_t cid, const RawAddress& rem_bda);
hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr);

void L2CA_LeConnectionUpdate(const RawAddress& rem_bda, uint16_t min_int,
                             uint16_t max_int, uint16_t latency,
+4 −0
Original line number Diff line number Diff line
@@ -162,6 +162,10 @@ bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable) {
}

hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr) {
  if (bluetooth::shim::is_gd_l2cap_enabled()) {
    return bluetooth::shim::L2CA_GetBleConnRole(bd_addr);
  }

  tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE);
  if (p_lcb == nullptr) {
    return HCI_ROLE_UNKNOWN;