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

Commit 9619a5c0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "gd HCI: Manage LE white list for LE connection"

parents 1ee7faf5 c9d89929
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ void AclManager::CreateConnection(Address address) {

void AclManager::CreateLeConnection(AddressWithType address_with_type) {
  GetHandler()->Post(
      common::BindOnce(&le_impl::create_le_connection, common::Unretained(pimpl_->le_impl_), address_with_type));
      common::BindOnce(&le_impl::create_le_connection, common::Unretained(pimpl_->le_impl_), address_with_type, true));
}

void AclManager::SetPrivacyPolicyForInitiatorAddress(
+40 −4
Original line number Diff line number Diff line
@@ -103,6 +103,18 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      LOG_WARN("No prior connection request for %s", address_with_type.ToString().c_str());
    } else {
      connecting_le_.erase(connecting_addr_with_type);
      AddressType address_type = address_with_type.GetAddressType();
      pause_connection = true;
      switch (address_type) {
        case AddressType::PUBLIC_DEVICE_ADDRESS:
        case AddressType::PUBLIC_IDENTITY_ADDRESS: {
          le_address_manager_->RemoveDeviceFromWhiteList(WhiteListAddressType::PUBLIC, address_with_type.GetAddress());
        } break;
        case AddressType::RANDOM_DEVICE_ADDRESS:
        case AddressType::RANDOM_IDENTITY_ADDRESS: {
          le_address_manager_->RemoveDeviceFromWhiteList(WhiteListAddressType::RANDOM, address_with_type.GetAddress());
        }
      }
    }
  }

@@ -224,9 +236,33 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
        handler_->BindOnce(&LeAddressManager::OnCommandComplete, common::Unretained(le_address_manager_)));
  }

  void create_le_connection(AddressWithType address_with_type) {
  void add_device_to_white_list(AddressWithType address_with_type) {
    AddressType address_type = address_with_type.GetAddressType();
    if (!address_manager_registered) {
      le_address_manager_->Register(this);
      address_manager_registered = true;
    }
    pause_connection = true;
    switch (address_type) {
      case AddressType::PUBLIC_DEVICE_ADDRESS:
      case AddressType::PUBLIC_IDENTITY_ADDRESS: {
        le_address_manager_->AddDeviceToWhiteList(WhiteListAddressType::PUBLIC, address_with_type.GetAddress());
      } break;
      case AddressType::RANDOM_DEVICE_ADDRESS:
      case AddressType::RANDOM_IDENTITY_ADDRESS: {
        le_address_manager_->AddDeviceToWhiteList(WhiteListAddressType::RANDOM, address_with_type.GetAddress());
      }
    }
  }

  void create_le_connection(AddressWithType address_with_type, bool add_to_white_list) {
    // TODO: Add white list handling.
    // TODO: Configure default LE connection parameters?

    if (add_to_white_list) {
      add_device_to_white_list(address_with_type);
    }

    if (!address_manager_registered) {
      auto policy = le_address_manager_->Register(this);
      address_manager_registered = true;
@@ -245,7 +281,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {

    uint16_t le_scan_interval = 0x0060;
    uint16_t le_scan_window = 0x0030;
    InitiatorFilterPolicy initiator_filter_policy = InitiatorFilterPolicy::USE_PEER_ADDRESS;
    InitiatorFilterPolicy initiator_filter_policy = InitiatorFilterPolicy::USE_WHITE_LIST;
    OwnAddressType own_address_type =
        static_cast<OwnAddressType>(le_address_manager_->GetCurrentAddress().GetAddressType());
    uint16_t conn_interval_min = 0x0018;
@@ -348,8 +384,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {

  void OnResume() override {
    pause_connection = false;
    for (auto address_with_type : canceled_connections_) {
      create_le_connection(address_with_type);
    if (!canceled_connections_.empty()) {
      create_le_connection(*canceled_connections_.begin(), false);
    }
    canceled_connections_.clear();
    le_address_manager_->AckResume(this);
+10 −1
Original line number Diff line number Diff line
@@ -557,7 +557,9 @@ class AclManagerWithLeConnectionTest : public AclManagerTest {
    remote_with_type_ = AddressWithType(remote, AddressType::PUBLIC_DEVICE_ADDRESS);
    test_hci_layer_->SetCommandFuture();
    acl_manager_->CreateLeConnection(remote_with_type_);

    test_hci_layer_->GetCommandPacket(OpCode::LE_ADD_DEVICE_TO_WHITE_LIST);
    test_hci_layer_->IncomingEvent(LeAddDeviceToWhiteListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
    test_hci_layer_->SetCommandFuture();
    auto packet = test_hci_layer_->GetCommandPacket(OpCode::LE_CREATE_CONNECTION);
    auto le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
    auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view);
@@ -573,6 +575,10 @@ class AclManagerWithLeConnectionTest : public AclManagerTest {
        ErrorCode::SUCCESS, handle_, Role::SLAVE, AddressType::PUBLIC_DEVICE_ADDRESS, remote, 0x0100, 0x0010, 0x0011,
        ClockAccuracy::PPM_30));

    test_hci_layer_->SetCommandFuture();
    test_hci_layer_->GetCommandPacket(OpCode::LE_REMOVE_DEVICE_FROM_WHITE_LIST);
    test_hci_layer_->IncomingEvent(LeRemoveDeviceFromWhiteListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));

    auto first_connection_status = first_connection.wait_for(kTimeout);
    ASSERT_EQ(first_connection_status, std::future_status::ready);

@@ -616,6 +622,9 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) {
  AddressWithType remote_with_type(remote, AddressType::PUBLIC_DEVICE_ADDRESS);
  test_hci_layer_->SetCommandFuture();
  acl_manager_->CreateLeConnection(remote_with_type);
  test_hci_layer_->GetCommandPacket(OpCode::LE_ADD_DEVICE_TO_WHITE_LIST);
  test_hci_layer_->IncomingEvent(LeAddDeviceToWhiteListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
  test_hci_layer_->SetCommandFuture();
  auto packet = test_hci_layer_->GetCommandPacket(OpCode::LE_CREATE_CONNECTION);
  auto le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
  auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view);
+8 −1
Original line number Diff line number Diff line
@@ -335,7 +335,14 @@ void LeAddressManager::OnCommandComplete(bluetooth::hci::CommandCompleteView vie
    return;
  }
  std::string op_code = OpCodeText(view.GetCommandOpCode());
  LOG_ERROR("Received command complete with op_code %s", op_code.c_str());
  LOG_DEBUG("Received command complete with op_code %s", op_code.c_str());

  // The command was sent before any client registered, we can make sure all the clients paused when command complete.
  if (view.GetCommandOpCode() == OpCode::LE_SET_RANDOM_ADDRESS &&
      address_policy_ == AddressPolicy::USE_STATIC_ADDRESS) {
    LOG_DEBUG("Received LE_SET_RANDOM_ADDRESS complete and Address policy is USE_STATIC_ADDRESS, return");
    return;
  }

  if (cached_commands_.empty()) {
    handler_->BindOnceOn(this, &LeAddressManager::resume_registered_clients).Invoke();