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

Commit 13606c9e authored by Martin Brabham's avatar Martin Brabham
Browse files

GD: Move Address and ClassOfDevice to hci

Bug: 139135297
Test: atest --host -t bluetooth_test_gd
Change-Id: I64c3ccbb3543a22a24f1b6b8a99f32e3d8aa3e24
parent 8bcb5bf3
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
filegroup {
    name: "BluetoothCommonSources",
    srcs: [
        "address.cc",
        "class_of_device.cc",
        "link_key.cc",
    ],
}
@@ -10,9 +8,7 @@ filegroup {
filegroup {
    name: "BluetoothCommonTestSources",
    srcs: [
        "address_unittest.cc",
        "blocking_queue_unittest.cc",
        "class_of_device_unittest.cc",
        "bidi_queue_unittest.cc",
        "observer_registry_test.cc",
        "link_key_unittest.cc",
+4 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ filegroup {
        "acl_manager.cc",
        "classic_security_manager.cc",
        "controller.cc",
        "address.cc",
        "class_of_device.cc",
        "hci_layer.cc",
    ],
}
@@ -15,6 +17,8 @@ filegroup {
        "acl_manager_test.cc",
        "classic_security_manager_test.cc",
        "controller_test.cc",
        "address_unittest.cc",
        "class_of_device_unittest.cc",
        "hci_layer_test.cc",
    ],
}
+10 −10
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ struct AclManager::impl {
        common::Bind(&impl::incoming_acl_credits, common::Unretained(this)), handler_);

    // TODO: determine when we should reject connection
    should_accept_connection_ = common::Bind([](common::Address, common::ClassOfDevice) { return true; });
    should_accept_connection_ = common::Bind([](Address, ClassOfDevice) { return true; });
    hci_queue_end_ = hci_layer_->GetAclQueueEnd();
    hci_queue_end_->RegisterDequeue(
        handler_, common::Bind(&impl::dequeue_and_route_acl_packet_to_connection, common::Unretained(this)));
@@ -204,7 +204,7 @@ struct AclManager::impl {
  void on_incoming_connection(EventPacketView packet) {
    ConnectionRequestView request = ConnectionRequestView::Create(packet);
    ASSERT(request.IsValid());
    common::Address address = request.GetBdAddr();
    Address address = request.GetBdAddr();
    if (client_callbacks_ == nullptr) {
      LOG_ERROR("No callbacks to call");
      auto reason = RejectConnectionReason::LIMITED_RESOURCES;
@@ -267,7 +267,7 @@ struct AclManager::impl {
    }
  }

  void create_connection(common::Address address) {
  void create_connection(Address address) {
    // TODO: Configure default connection parameters?
    uint16_t packet_type = 0x4408 /* DM 1,3,5 */ | 0x8810 /*DH 1,3,5 */;
    PageScanRepetitionMode page_scan_repetition_mode = PageScanRepetitionMode::R1;
@@ -287,7 +287,7 @@ struct AclManager::impl {
                               handler_);
  }

  void cancel_connect(common::Address address) {
  void cancel_connect(Address address) {
    auto connecting_addr = connecting_.find(address);
    if (connecting_addr == connecting_.end()) {
      LOG_INFO("Cannot cancel non-existent connection to %s", address.ToString().c_str());
@@ -299,7 +299,7 @@ struct AclManager::impl {
                               handler_);
  }

  void accept_connection(common::Address address) {
  void accept_connection(Address address) {
    auto role = AcceptConnectionRequestRole::BECOME_MASTER;  // We prefer to be master
    hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role),
                               common::BindOnce(&impl::on_accept_connection_status, common::Unretained(this), address),
@@ -323,7 +323,7 @@ struct AclManager::impl {
    acl_connections_.erase(handle);
  }

  void on_accept_connection_status(common::Address address, CommandStatusView status) {
  void on_accept_connection_status(Address address, CommandStatusView status) {
    auto accept_status = AcceptConnectionRequestStatusView::Create(status);
    ASSERT(accept_status.IsValid());
    if (status.GetStatus() != ErrorCode::SUCCESS) {
@@ -398,8 +398,8 @@ struct AclManager::impl {
  os::Handler* client_handler_ = nullptr;
  common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* hci_queue_end_ = nullptr;
  std::map<uint16_t, AclManager::acl_connection> acl_connections_;
  std::set<common::Address> connecting_;
  common::Callback<bool(common::Address, common::ClassOfDevice)> should_accept_connection_;
  std::set<Address> connecting_;
  common::Callback<bool(Address, ClassOfDevice)> should_accept_connection_;
};

AclConnection::QueueUpEnd* AclConnection::GetAclQueueEnd() const {
@@ -428,11 +428,11 @@ bool AclManager::RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler*
  return true;
}

void AclManager::CreateConnection(common::Address address) {
void AclManager::CreateConnection(Address address) {
  GetHandler()->Post(common::BindOnce(&impl::create_connection, common::Unretained(pimpl_.get()), address));
}

void AclManager::CancelConnect(common::Address address) {
void AclManager::CancelConnect(Address address) {
  GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address));
}

+8 −8
Original line number Diff line number Diff line
@@ -18,9 +18,9 @@

#include <memory>

#include "common/address.h"
#include "common/bidi_queue.h"
#include "common/callback.h"
#include "hci/address.h"
#include "hci/hci_layer.h"
#include "hci/hci_packets.h"
#include "module.h"
@@ -33,10 +33,10 @@ class AclManager;

class AclConnection {
 public:
  AclConnection() : manager_(nullptr), handle_(0), address_(common::Address::kEmpty){};
  AclConnection() : manager_(nullptr), handle_(0), address_(Address::kEmpty){};
  virtual ~AclConnection() = default;

  virtual common::Address GetAddress() const {
  virtual Address GetAddress() const {
    return address_;
  }

@@ -57,11 +57,11 @@ class AclConnection {

 private:
  friend AclManager;
  AclConnection(AclManager* manager, uint16_t handle, common::Address address)
  AclConnection(AclManager* manager, uint16_t handle, Address address)
      : manager_(manager), handle_(handle), address_(address) {}
  AclManager* manager_;
  uint16_t handle_;
  common::Address address_;
  Address address_;
  DISALLOW_COPY_AND_ASSIGN(AclConnection);
};

@@ -71,7 +71,7 @@ class ConnectionCallbacks {
  // Invoked when controller sends Connection Complete event with Success error code
  virtual void OnConnectSuccess(std::unique_ptr<AclConnection> /* , initiated_by_local ? */) = 0;
  // Invoked when controller sends Connection Complete event with non-Success error code
  virtual void OnConnectFail(common::Address, ErrorCode reason) = 0;
  virtual void OnConnectFail(Address, ErrorCode reason) = 0;
};

class AclManager : public Module {
@@ -88,11 +88,11 @@ class AclManager : public Module {
  virtual bool RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler* handler);

  // Generates OnConnectSuccess if connected, or OnConnectFail otherwise
  virtual void CreateConnection(common::Address address);
  virtual void CreateConnection(Address address);

  // Generates OnConnectFail with error code "terminated by local host 0x16" if cancelled, or OnConnectSuccess if not
  // successfully cancelled and already connected
  virtual void CancelConnect(common::Address address);
  virtual void CancelConnect(Address address);

  static const ModuleFactory Factory;

+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ namespace testing {

class MockAclConnection : public AclConnection {
 public:
  MOCK_METHOD(common::Address, GetAddress, (), (const, override));
  MOCK_METHOD(Address, GetAddress, (), (const, override));
  MOCK_METHOD(void, RegisterDisconnectCallback,
              (common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler), (override));
  MOCK_METHOD(bool, Disconnect, (DisconnectReason reason), (override));
@@ -37,8 +37,8 @@ class MockAclConnection : public AclConnection {
class MockAclManager : public AclManager {
 public:
  MOCK_METHOD(bool, RegisterCallbacks, (ConnectionCallbacks * callbacks, os::Handler* handler), (override));
  MOCK_METHOD(void, CreateConnection, (common::Address address), (override));
  MOCK_METHOD(void, CancelConnect, (common::Address address), (override));
  MOCK_METHOD(void, CreateConnection, (Address address), (override));
  MOCK_METHOD(void, CancelConnect, (Address address), (override));
};

}  // namespace testing
Loading