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

Commit 62d5ba41 authored by Martin Brabham's avatar Martin Brabham Committed by android-build-merger
Browse files

GD: Move Address and ClassOfDevice to hci am: 13606c9e am: 9f9219d2 am:...

GD: Move Address and ClassOfDevice to hci am: 13606c9e am: 9f9219d2 am: 584beaed am: 11caabac
am: 6e38249b

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


    // TODO: determine when we should reject connection
    // 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_ = hci_layer_->GetAclQueueEnd();
    hci_queue_end_->RegisterDequeue(
    hci_queue_end_->RegisterDequeue(
        handler_, common::Bind(&impl::dequeue_and_route_acl_packet_to_connection, common::Unretained(this)));
        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) {
  void on_incoming_connection(EventPacketView packet) {
    ConnectionRequestView request = ConnectionRequestView::Create(packet);
    ConnectionRequestView request = ConnectionRequestView::Create(packet);
    ASSERT(request.IsValid());
    ASSERT(request.IsValid());
    common::Address address = request.GetBdAddr();
    Address address = request.GetBdAddr();
    if (client_callbacks_ == nullptr) {
    if (client_callbacks_ == nullptr) {
      LOG_ERROR("No callbacks to call");
      LOG_ERROR("No callbacks to call");
      auto reason = RejectConnectionReason::LIMITED_RESOURCES;
      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?
    // TODO: Configure default connection parameters?
    uint16_t packet_type = 0x4408 /* DM 1,3,5 */ | 0x8810 /*DH 1,3,5 */;
    uint16_t packet_type = 0x4408 /* DM 1,3,5 */ | 0x8810 /*DH 1,3,5 */;
    PageScanRepetitionMode page_scan_repetition_mode = PageScanRepetitionMode::R1;
    PageScanRepetitionMode page_scan_repetition_mode = PageScanRepetitionMode::R1;
@@ -287,7 +287,7 @@ struct AclManager::impl {
                               handler_);
                               handler_);
  }
  }


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


  void accept_connection(common::Address address) {
  void accept_connection(Address address) {
    auto role = AcceptConnectionRequestRole::BECOME_MASTER;  // We prefer to be master
    auto role = AcceptConnectionRequestRole::BECOME_MASTER;  // We prefer to be master
    hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role),
    hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role),
                               common::BindOnce(&impl::on_accept_connection_status, common::Unretained(this), address),
                               common::BindOnce(&impl::on_accept_connection_status, common::Unretained(this), address),
@@ -323,7 +323,7 @@ struct AclManager::impl {
    acl_connections_.erase(handle);
    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);
    auto accept_status = AcceptConnectionRequestStatusView::Create(status);
    ASSERT(accept_status.IsValid());
    ASSERT(accept_status.IsValid());
    if (status.GetStatus() != ErrorCode::SUCCESS) {
    if (status.GetStatus() != ErrorCode::SUCCESS) {
@@ -398,8 +398,8 @@ struct AclManager::impl {
  os::Handler* client_handler_ = nullptr;
  os::Handler* client_handler_ = nullptr;
  common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* hci_queue_end_ = nullptr;
  common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* hci_queue_end_ = nullptr;
  std::map<uint16_t, AclManager::acl_connection> acl_connections_;
  std::map<uint16_t, AclManager::acl_connection> acl_connections_;
  std::set<common::Address> connecting_;
  std::set<Address> connecting_;
  common::Callback<bool(common::Address, common::ClassOfDevice)> should_accept_connection_;
  common::Callback<bool(Address, ClassOfDevice)> should_accept_connection_;
};
};


AclConnection::QueueUpEnd* AclConnection::GetAclQueueEnd() const {
AclConnection::QueueUpEnd* AclConnection::GetAclQueueEnd() const {
@@ -428,11 +428,11 @@ bool AclManager::RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler*
  return true;
  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));
  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));
  GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address));
}
}


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


#include <memory>
#include <memory>


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


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


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


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


 private:
 private:
  friend AclManager;
  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) {}
      : manager_(manager), handle_(handle), address_(address) {}
  AclManager* manager_;
  AclManager* manager_;
  uint16_t handle_;
  uint16_t handle_;
  common::Address address_;
  Address address_;
  DISALLOW_COPY_AND_ASSIGN(AclConnection);
  DISALLOW_COPY_AND_ASSIGN(AclConnection);
};
};


@@ -71,7 +71,7 @@ class ConnectionCallbacks {
  // Invoked when controller sends Connection Complete event with Success error code
  // Invoked when controller sends Connection Complete event with Success error code
  virtual void OnConnectSuccess(std::unique_ptr<AclConnection> /* , initiated_by_local ? */) = 0;
  virtual void OnConnectSuccess(std::unique_ptr<AclConnection> /* , initiated_by_local ? */) = 0;
  // Invoked when controller sends Connection Complete event with non-Success error code
  // 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 {
class AclManager : public Module {
@@ -88,11 +88,11 @@ class AclManager : public Module {
  virtual bool RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler* handler);
  virtual bool RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler* handler);


  // Generates OnConnectSuccess if connected, or OnConnectFail otherwise
  // 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
  // Generates OnConnectFail with error code "terminated by local host 0x16" if cancelled, or OnConnectSuccess if not
  // successfully cancelled and already connected
  // successfully cancelled and already connected
  virtual void CancelConnect(common::Address address);
  virtual void CancelConnect(Address address);


  static const ModuleFactory Factory;
  static const ModuleFactory Factory;


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


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


}  // namespace testing
}  // namespace testing
Loading