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

Commit aa5b19c8 authored by Chris Manton's avatar Chris Manton
Browse files

gd_acl: Add shim disconnect

Bug: 166280067
Tag: #refactor
Test: gd/cert/run --host

Change-Id: I8bf1358024ab61c5ed8377424c52e9aa219a75d5
parent 6cd20ed5
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -150,6 +150,8 @@ class ShimAclConnection {
    TRY_POSTING_ON_MAIN(send_data_upwards_, p_buf);
  }

  virtual void InitiateDisconnect(hci::DisconnectReason reason) = 0;

 protected:
  const uint16_t handle_{kInvalidHciHandle};
  os::Handler* handler_;
@@ -340,6 +342,10 @@ class ClassicShimAclConnection

  hci::Address GetRemoteAddress() const { return connection_->GetAddress(); }

  void InitiateDisconnect(hci::DisconnectReason reason) override {
    connection_->Disconnect(reason);
  }

 private:
  OnDisconnect on_disconnect_;
  const shim::legacy::acl_classic_link_interface_t interface_;
@@ -400,6 +406,10 @@ class LeShimAclConnection
    return connection_->GetRemoteAddress();
  }

  void InitiateDisconnect(hci::DisconnectReason reason) override {
    connection_->Disconnect(reason);
  }

 private:
  OnDisconnect on_disconnect_;
  const shim::legacy::acl_le_link_interface_t interface_;
@@ -761,3 +771,38 @@ void bluetooth::shim::legacy::Acl::ConfigureLePrivacy(
      address_policy, empty_address_with_type, rotation_irk,
      minimum_rotation_time, maximum_rotation_time);
}

void bluetooth::shim::legacy::Acl::DisconnectClassic(uint16_t handle,
                                                     tHCI_STATUS reason) {
  auto connection = pimpl_->handle_to_classic_connection_map_.find(handle);
  if (connection != pimpl_->handle_to_classic_connection_map_.end()) {
    auto remote_address = connection->second->GetRemoteAddress();
    connection->second->InitiateDisconnect(
        ToDisconnectReasonFromLegacy(reason));
    LOG_DEBUG("Disconnection initiated classic remote:%s handle:%hu",
              PRIVATE_ADDRESS(remote_address), handle);
    btm_cb.history_->Push("%-32s: %s classic", "Disconnection initiated",
                          PRIVATE_ADDRESS(remote_address));
  } else {
    LOG_WARN("Unable to disconnect unknown classic connection handle:0x%04x",
             handle);
  }
}

void bluetooth::shim::legacy::Acl::DisconnectLe(uint16_t handle,
                                                tHCI_STATUS reason) {
  auto connection = pimpl_->handle_to_le_connection_map_.find(handle);
  if (connection != pimpl_->handle_to_le_connection_map_.end()) {
    auto remote_address_with_type =
        connection->second->GetRemoteAddressWithType();
    connection->second->InitiateDisconnect(
        ToDisconnectReasonFromLegacy(reason));
    LOG_DEBUG("Disconnection initiated le remote:%s handle:%hu",
              PRIVATE_ADDRESS(remote_address_with_type), handle);
    btm_cb.history_->Push("%-32s: %s le", "Disconnection initiated",
                          PRIVATE_ADDRESS(remote_address_with_type));
  } else {
    LOG_WARN("Unable to disconnect unknown le connection handle:0x%04x",
             handle);
  }
}
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ class Acl : public hci::acl_manager::ConnectionCallbacks,

  void ConfigureLePrivacy(bool is_le_privacy_enabled);

  void DisconnectClassic(uint16_t handle, tHCI_STATUS reason);
  void DisconnectLe(uint16_t handle, tHCI_STATUS reason);

  void Dump(int fd) const;

 protected:
+7 −0
Original line number Diff line number Diff line
@@ -51,3 +51,10 @@ void bluetooth::shim::ACL_WriteData(uint16_t handle, const BT_HDR* p_buf) {
void bluetooth::shim::ACL_ConfigureLePrivacy(bool is_le_privacy_enabled) {
  Stack::GetInstance()->GetAcl()->ConfigureLePrivacy(is_le_privacy_enabled);
}

void bluetooth::shim::ACL_Disconnect(uint16_t handle, bool is_classic,
                                     tHCI_STATUS reason) {
  (is_classic)
      ? Stack::GetInstance()->GetAcl()->DisconnectClassic(handle, reason)
      : Stack::GetInstance()->GetAcl()->DisconnectLe(handle, reason);
}
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include "stack/include/bt_types.h"
#include "stack/include/hci_error_code.h"
#include "types/ble_address_with_type.h"
#include "types/raw_address.h"

@@ -27,6 +28,7 @@ void ACL_CancelClassicConnection(const RawAddress& raw_address);
void ACL_CancelLeConnection(const tBLE_BD_ADDR& legacy_address_with_type);
void ACL_CreateClassicConnection(const RawAddress& raw_address);
void ACL_CreateLeConnection(const tBLE_BD_ADDR& legacy_address_with_type);
void ACL_Disconnect(uint16_t handle, bool is_classic, tHCI_STATUS reason);
void ACL_WriteData(uint16_t handle, const BT_HDR* p_buf);
void ACL_ConfigureLePrivacy(bool is_le_privacy_enabled);