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

Commit 1849f699 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

GD: Pass initiator address between ACL manager and Security Manager

Test: gd/cert/run --host --test_filter=LeL2capTest
Bug: 152348535
Change-Id: I1b7628f93acef95540cc12e0054c967df69c745d
parent 3b18f281
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@
#include "hci/round_robin_scheduler.h"
#include "security/security_module.h"

using bluetooth::crypto_toolbox::Octet16;

namespace bluetooth {
namespace hci {

@@ -304,27 +306,29 @@ struct AclManager::impl : public security::ISecurityManagerListener {
    auto address = connection_complete.GetPeerAddress();
    auto peer_address_type = connection_complete.GetPeerAddressType();
    // TODO: find out which address and type was used to initiate the connection
    AddressWithType address_with_type(address, peer_address_type);
    on_common_le_connection_complete(address_with_type);
    AddressWithType remote_address(address, peer_address_type);
    AddressWithType local_address = le_initiator_address_;
    on_common_le_connection_complete(remote_address);
    if (status != ErrorCode::SUCCESS) {
      le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectFail,
                                                common::Unretained(le_client_callbacks_), address_with_type, status));
                                                common::Unretained(le_client_callbacks_), remote_address, status));
      return;
    }
    // TODO: Check and save other connection parameters
    uint16_t handle = connection_complete.GetConnectionHandle();
    ASSERT(acl_connections_.count(handle) == 0);
    acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle),
                             std::forward_as_tuple(address_with_type, handler_));
                             std::forward_as_tuple(remote_address, handler_));
    auto& connection = check_and_get_connection(handle);
    hci_layer_->GetHciHandler()->Post(
        common::BindOnce(&RoundRobinScheduler::Register, common::Unretained(round_robin_scheduler_),
                         RoundRobinScheduler::ConnectionType::LE, handle, connection.queue_->GetDownEnd()));
    auto role = connection_complete.GetRole();
    std::unique_ptr<LeAclConnection> connection_proxy(new LeAclConnection(
        &acl_manager_, connection.queue_->GetUpEnd(), le_acl_connection_interface_, handle, address_with_type, role));
    std::unique_ptr<LeAclConnection> connection_proxy(new LeAclConnection(&acl_manager_, connection.queue_->GetUpEnd(),
                                                                          le_acl_connection_interface_, handle,
                                                                          local_address, remote_address, role));
    le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess,
                                              common::Unretained(le_client_callbacks_), address_with_type,
                                              common::Unretained(le_client_callbacks_), remote_address,
                                              std::move(connection_proxy)));
  }

@@ -335,22 +339,22 @@ struct AclManager::impl : public security::ISecurityManagerListener {
    auto address = connection_complete.GetPeerAddress();
    auto peer_address_type = connection_complete.GetPeerAddressType();
    auto peer_resolvable_address = connection_complete.GetPeerResolvablePrivateAddress();
    AddressWithType reporting_address_with_type(address, peer_address_type);
    AddressWithType remote_address(address, peer_address_type);
    AddressWithType local_address = le_initiator_address_;
    if (!peer_resolvable_address.IsEmpty()) {
      reporting_address_with_type = AddressWithType(peer_resolvable_address, AddressType::RANDOM_DEVICE_ADDRESS);
      remote_address = AddressWithType(peer_resolvable_address, AddressType::RANDOM_DEVICE_ADDRESS);
    }
    on_common_le_connection_complete(reporting_address_with_type);
    on_common_le_connection_complete(remote_address);
    if (status != ErrorCode::SUCCESS) {
      le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectFail,
                                                common::Unretained(le_client_callbacks_), reporting_address_with_type,
                                                status));
                                                common::Unretained(le_client_callbacks_), remote_address, status));
      return;
    }
    // TODO: Check and save other connection parameters
    uint16_t handle = connection_complete.GetConnectionHandle();
    ASSERT(acl_connections_.count(handle) == 0);
    acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle),
                             std::forward_as_tuple(reporting_address_with_type, handler_));
                             std::forward_as_tuple(remote_address, handler_));
    auto& connection = check_and_get_connection(handle);
    hci_layer_->GetHciHandler()->Post(
        common::BindOnce(&RoundRobinScheduler::Register, common::Unretained(round_robin_scheduler_),
@@ -358,9 +362,9 @@ struct AclManager::impl : public security::ISecurityManagerListener {
    auto role = connection_complete.GetRole();
    std::unique_ptr<LeAclConnection> connection_proxy(new LeAclConnection(&acl_manager_, connection.queue_->GetUpEnd(),
                                                                          le_acl_connection_interface_, handle,
                                                                          reporting_address_with_type, role));
                                                                          local_address, remote_address, role));
    le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess,
                                              common::Unretained(le_client_callbacks_), reporting_address_with_type,
                                              common::Unretained(le_client_callbacks_), remote_address,
                                              std::move(connection_proxy)));
  }

+14 −7
Original line number Diff line number Diff line
@@ -191,10 +191,15 @@ class LeAclConnection : public AclConnection {
 public:
  LeAclConnection()
      : AclConnection(), le_acl_connection_interface_(nullptr),
        address_with_type_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS){};
        local_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS),
        remote_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS){};

  virtual AddressWithType GetAddressWithType() const {
    return address_with_type_;
  virtual AddressWithType GetLocalAddress() const {
    return local_address_;
  }

  virtual AddressWithType GetRemoteAddress() const {
    return remote_address_;
  }

  virtual void RegisterCallbacks(LeConnectionManagementCallbacks* callbacks, os::Handler* handler);
@@ -210,12 +215,14 @@ class LeAclConnection : public AclConnection {
 private:
  friend AclManager;
  LeAclConnection(const AclManager* acl_manager, QueueUpEnd* queue_up_end,
                  LeAclConnectionInterface* le_acl_connection_interface, uint16_t handle,
                  AddressWithType address_with_type, Role role)
                  LeAclConnectionInterface* le_acl_connection_interface, uint16_t handle, AddressWithType local_address,
                  AddressWithType remote_address, Role role)
      : AclConnection(acl_manager, queue_up_end, handle, role),
        le_acl_connection_interface_(le_acl_connection_interface), address_with_type_(address_with_type) {}
        le_acl_connection_interface_(le_acl_connection_interface), local_address_(local_address),
        remote_address_(remote_address) {}
  LeAclConnectionInterface* le_acl_connection_interface_;
  AddressWithType address_with_type_;
  AddressWithType local_address_;
  AddressWithType remote_address_;
  DISALLOW_COPY_AND_ASSIGN(LeAclConnection);
};

+2 −1
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ class MockClassicAclConnection : public ClassicAclConnection {

class MockLeAclConnection : public LeAclConnection {
 public:
  MOCK_METHOD(AddressWithType, GetAddressWithType, (), (const, override));
  MOCK_METHOD(AddressWithType, GetLocalAddress, (), (const, override));
  MOCK_METHOD(AddressWithType, GetRemoteAddress, (), (const, override));
  MOCK_METHOD(void, RegisterDisconnectCallback,
              (common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler), (override));
  MOCK_METHOD(bool, Disconnect, (DisconnectReason reason), (override));
+2 −2
Original line number Diff line number Diff line
@@ -534,7 +534,7 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_success
  ASSERT_EQ(first_connection_status, std::future_status::ready);

  auto connection = GetLastLeConnection();
  ASSERT_EQ(connection->GetAddressWithType(), remote_with_type);
  ASSERT_EQ(connection->GetRemoteAddress(), remote_with_type);
}

TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) {
@@ -582,7 +582,7 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_update_success)
  ASSERT_EQ(first_connection_status, std::future_status::ready);

  auto connection = GetLastLeConnection();
  ASSERT_EQ(connection->GetAddressWithType(), remote_with_type);
  ASSERT_EQ(connection->GetRemoteAddress(), remote_with_type);

  std::promise<ErrorCode> promise;
  auto future = promise.get_future();
+9 −9
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ TEST_F(L2capLeFixedChannelImplTest, get_device) {
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -78,7 +78,7 @@ TEST_F(L2capLeFixedChannelImplTest, close_triggers_callback) {
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -103,7 +103,7 @@ TEST_F(L2capLeFixedChannelImplTest, register_callback_after_close_should_call_im
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -128,7 +128,7 @@ TEST_F(L2capLeFixedChannelImplTest, close_twice_should_fail) {
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -156,7 +156,7 @@ TEST_F(L2capLeFixedChannelImplTest, multiple_registeration_should_fail) {
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -180,7 +180,7 @@ TEST_F(L2capLeFixedChannelImplTest, call_acquire_before_registeration_should_fai
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -193,7 +193,7 @@ TEST_F(L2capLeFixedChannelImplTest, call_release_before_registeration_should_fai
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -206,7 +206,7 @@ TEST_F(L2capLeFixedChannelImplTest, test_acquire_release_channel) {
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
@@ -238,7 +238,7 @@ TEST_F(L2capLeFixedChannelImplTest, test_acquire_after_close) {
  MockParameterProvider mock_parameter_provider;
  EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1);
  testing::MockLeAclConnection* mock_acl_connection = new testing::MockLeAclConnection();
  EXPECT_CALL(*mock_acl_connection, GetAddressWithType()).Times(1);
  EXPECT_CALL(*mock_acl_connection, GetRemoteAddress()).Times(1);
  MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider,
                        std::unique_ptr<testing::MockLeAclConnection>(mock_acl_connection));
  AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS};
Loading