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

Commit 89f83f0b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "gd HCI: Handle LE white list when cancel connecion"

parents 562667ed 6e1085f9
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -103,18 +103,6 @@ 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());
        }
      }
    }
  }

@@ -134,6 +122,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      return;
    } else {
      canceled_connections_.erase(remote_address);
      remove_device_from_white_list(remote_address);
    }

    if (status != ErrorCode::SUCCESS) {
@@ -181,6 +170,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      return;
    } else {
      canceled_connections_.erase(remote_address);
      remove_device_from_white_list(remote_address);
    }

    if (status != ErrorCode::SUCCESS) {
@@ -256,7 +246,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
  }

  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) {
@@ -325,10 +314,23 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    }
  }

  void cancel_connect(AddressWithType /* TODO: use this parameter for whitelist management */) {
    le_acl_connection_interface_->EnqueueCommand(
        LeCreateConnectionCancelBuilder::Create(),
        handler_->BindOnce(&check_command_complete<LeCreateConnectionCancelCompleteView>));
  void cancel_connect(AddressWithType address_with_type) {
    // the connection will be canceled by LeAddressManager.OnPause()
    remove_device_from_white_list(address_with_type);
  }

  void remove_device_from_white_list(AddressWithType address_with_type) {
    AddressType address_type = address_with_type.GetAddressType();
    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());
      }
    }
  }

  void set_privacy_policy_for_initiator_address(
+37 −0
Original line number Diff line number Diff line
@@ -641,6 +641,43 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) {
      0x0100, 0x0010, 0x0011, ClockAccuracy::PPM_30));
}

TEST_F(AclManagerTest, cancel_le_connection) {
  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();
  test_hci_layer_->GetCommandPacket(OpCode::LE_CREATE_CONNECTION);

  test_hci_layer_->SetCommandFuture();
  acl_manager_->CancelLeConnect(remote_with_type);
  auto packet = test_hci_layer_->GetCommandPacket(OpCode::LE_CREATE_CONNECTION_CANCEL);
  auto le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
  auto command_view = LeCreateConnectionCancelView::Create(le_connection_management_command_view);
  ASSERT_TRUE(command_view.IsValid());

  test_hci_layer_->IncomingEvent(LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
  test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
      ErrorCode::UNKNOWN_CONNECTION,
      0x123,
      Role::SLAVE,
      AddressType::PUBLIC_DEVICE_ADDRESS,
      remote,
      0x0100,
      0x0010,
      0x0011,
      ClockAccuracy::PPM_30));

  test_hci_layer_->SetCommandFuture();
  packet = test_hci_layer_->GetCommandPacket(OpCode::LE_REMOVE_DEVICE_FROM_WHITE_LIST);
  le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
  auto remove_command_view = LeRemoveDeviceFromWhiteListView::Create(le_connection_management_command_view);
  ASSERT_TRUE(remove_command_view.IsValid());

  test_hci_layer_->IncomingEvent(LeRemoveDeviceFromWhiteListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
}

TEST_F(AclManagerWithLeConnectionTest, acl_send_data_one_le_connection) {
  ASSERT_EQ(connection_->GetRemoteAddress(), remote_with_type_);
  ASSERT_EQ(connection_->GetHandle(), handle_);