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

Commit 40b80ada authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Change White list to Connect list"

parents 59e378c2 3cba2d8a
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -71,8 +71,9 @@ class SimpleHalTest(GdBaseTestClass):
        with EventStream(self.dut.hal.FetchHciEvent(empty_pb2.Empty())) as hci_event_stream:

            self.send_dut_hci_command(
                hci_packets.LeAddDeviceToWhiteListBuilder(hci_packets.WhiteListAddressType.RANDOM, '0C:05:04:03:02:01'))
            event = hci_packets.LeAddDeviceToWhiteListCompleteBuilder(1, hci_packets.ErrorCode.SUCCESS)
                hci_packets.LeAddDeviceToConnectListBuilder(hci_packets.ConnectListAddressType.RANDOM,
                                                            '0C:05:04:03:02:01'))
            event = hci_packets.LeAddDeviceToConnectListCompleteBuilder(1, hci_packets.ErrorCode.SUCCESS)

            assertThat(hci_event_stream).emits(lambda packet: bytes(event.Serialize()) in packet.payload)

@@ -81,7 +82,7 @@ class SimpleHalTest(GdBaseTestClass):

            self.send_dut_hci_command(hci_packets.WriteLoopbackModeBuilder(hci_packets.LoopbackMode.ENABLE_LOCAL))

            command = hci_packets.LeAddDeviceToWhiteListBuilder(hci_packets.WhiteListAddressType.RANDOM,
            command = hci_packets.LeAddDeviceToConnectListBuilder(hci_packets.ConnectListAddressType.RANDOM,
                                                                  '0C:05:04:03:02:01')
            self.send_dut_hci_command(command)

@@ -261,14 +262,15 @@ class SimpleHalTest(GdBaseTestClass):
            assertThat(cert_acl_data_stream).emits(lambda packet: b'SomeAclData' in packet.payload)
            assertThat(acl_data_stream).emits(lambda packet: b'SomeMoreAclData' in packet.payload)

    def test_le_white_list_connection_cert_advertises(self):
    def test_le_connect_list_connection_cert_advertises(self):
        with EventStream(self.dut.hal.FetchHciEvent(empty_pb2.Empty())) as hci_event_stream, \
            EventStream(self.cert.hal.FetchHciEvent(empty_pb2.Empty())) as cert_hci_event_stream:

            # DUT Connects
            self.send_dut_hci_command(hci_packets.LeSetRandomAddressBuilder('0D:05:04:03:02:01'))
            self.send_dut_hci_command(
                hci_packets.LeAddDeviceToWhiteListBuilder(hci_packets.WhiteListAddressType.RANDOM, '0C:05:04:03:02:01'))
                hci_packets.LeAddDeviceToConnectListBuilder(hci_packets.ConnectListAddressType.RANDOM,
                                                            '0C:05:04:03:02:01'))
            phy_scan_params = hci_packets.LeCreateConnPhyScanParameters()
            phy_scan_params.scan_interval = 0x60
            phy_scan_params.scan_window = 0x30
@@ -279,9 +281,10 @@ class SimpleHalTest(GdBaseTestClass):
            phy_scan_params.min_ce_length = 0
            phy_scan_params.max_ce_length = 0
            self.send_dut_hci_command(
                hci_packets.LeExtendedCreateConnectionBuilder(
                    hci_packets.InitiatorFilterPolicy.USE_WHITE_LIST, hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                    hci_packets.AddressType.RANDOM_DEVICE_ADDRESS, 'BA:D5:A4:A3:A2:A1', 1, [phy_scan_params]))
                hci_packets.LeExtendedCreateConnectionBuilder(hci_packets.InitiatorFilterPolicy.USE_CONNECT_LIST,
                                                              hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                                                              hci_packets.AddressType.RANDOM_DEVICE_ADDRESS,
                                                              'BA:D5:A4:A3:A2:A1', 1, [phy_scan_params]))

            # CERT Advertises
            advertising_handle = 1
+16 −14
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
        common::Bind(&le_impl::enqueue_command, common::Unretained(this)),
        handler_,
        controller->GetControllerMacAddress(),
        controller->GetControllerLeWhiteListSize(),
        controller->GetControllerLeConnectListSize(),
        controller->GetControllerLeResolvingListSize());
  }

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

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

    if (status != ErrorCode::SUCCESS) {
@@ -227,7 +227,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
        handler_->BindOnce(&LeAddressManager::OnCommandComplete, common::Unretained(le_address_manager_)));
  }

  void add_device_to_white_list(AddressWithType address_with_type) {
  void add_device_to_connect_list(AddressWithType address_with_type) {
    AddressType address_type = address_with_type.GetAddressType();
    if (!address_manager_registered) {
      le_address_manager_->Register(this);
@@ -237,20 +237,20 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    switch (address_type) {
      case AddressType::PUBLIC_DEVICE_ADDRESS:
      case AddressType::PUBLIC_IDENTITY_ADDRESS: {
        le_address_manager_->AddDeviceToWhiteList(WhiteListAddressType::PUBLIC, address_with_type.GetAddress());
        le_address_manager_->AddDeviceToConnectList(ConnectListAddressType::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());
        le_address_manager_->AddDeviceToConnectList(ConnectListAddressType::RANDOM, address_with_type.GetAddress());
      }
    }
  }

  void create_le_connection(AddressWithType address_with_type, bool add_to_white_list) {
  void create_le_connection(AddressWithType address_with_type, bool add_to_connect_list) {
    // TODO: Configure default LE connection parameters?

    if (add_to_white_list) {
      add_device_to_white_list(address_with_type);
    if (add_to_connect_list) {
      add_device_to_connect_list(address_with_type);
    }

    if (!address_manager_registered) {
@@ -271,7 +271,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_WHITE_LIST;
    InitiatorFilterPolicy initiator_filter_policy = InitiatorFilterPolicy::USE_CONNECT_LIST;
    OwnAddressType own_address_type =
        static_cast<OwnAddressType>(le_address_manager_->GetCurrentAddress().GetAddressType());
    uint16_t conn_interval_min = 0x0018;
@@ -317,19 +317,21 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {

  void cancel_connect(AddressWithType address_with_type) {
    // the connection will be canceled by LeAddressManager.OnPause()
    remove_device_from_white_list(address_with_type);
    remove_device_from_connect_list(address_with_type);
  }

  void remove_device_from_white_list(AddressWithType address_with_type) {
  void remove_device_from_connect_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());
        le_address_manager_->RemoveDeviceFromConnectList(
            ConnectListAddressType::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());
        le_address_manager_->RemoveDeviceFromConnectList(
            ConnectListAddressType::RANDOM, address_with_type.GetAddress());
      }
    }
  }
+11 −11
Original line number Diff line number Diff line
@@ -557,8 +557,8 @@ 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_->GetCommandPacket(OpCode::LE_ADD_DEVICE_TO_CONNECT_LIST);
    test_hci_layer_->IncomingEvent(LeAddDeviceToConnectListCompleteBuilder::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);
@@ -576,8 +576,8 @@ class AclManagerWithLeConnectionTest : public AclManagerTest {
        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));
    test_hci_layer_->GetCommandPacket(OpCode::LE_REMOVE_DEVICE_FROM_CONNECT_LIST);
    test_hci_layer_->IncomingEvent(LeRemoveDeviceFromConnectListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));

    auto first_connection_status = first_connection.wait_for(kTimeout);
    ASSERT_EQ(first_connection_status, std::future_status::ready);
@@ -622,8 +622,8 @@ 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_->GetCommandPacket(OpCode::LE_ADD_DEVICE_TO_CONNECT_LIST);
  test_hci_layer_->IncomingEvent(LeAddDeviceToConnectListCompleteBuilder::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);
@@ -645,8 +645,8 @@ 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_->GetCommandPacket(OpCode::LE_ADD_DEVICE_TO_CONNECT_LIST);
  test_hci_layer_->IncomingEvent(LeAddDeviceToConnectListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
  test_hci_layer_->SetCommandFuture();
  test_hci_layer_->GetCommandPacket(OpCode::LE_CREATE_CONNECTION);

@@ -670,12 +670,12 @@ TEST_F(AclManagerTest, cancel_le_connection) {
      ClockAccuracy::PPM_30));

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

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

TEST_F(AclManagerWithLeConnectionTest, acl_send_data_one_le_connection) {
+3 −3
Original line number Diff line number Diff line
@@ -253,16 +253,16 @@ class DirectHciTest(GdBaseTestClass):
        assertThat(self.dut_hci.get_raw_acl_stream()).emits(
            lambda packet: logging.debug(packet.data) or b'SomeMoreAclData' in packet.data)

    def test_le_white_list_connection_cert_advertises(self):
    def test_le_connect_list_connection_cert_advertises(self):
        self.dut_hci.register_for_le_events(hci_packets.SubeventCode.CONNECTION_COMPLETE)
        # DUT Connects
        self.dut_hci.send_command_with_complete(hci_packets.LeSetRandomAddressBuilder('0D:05:04:03:02:01'))
        self.dut_hci.send_command_with_complete(
            hci_packets.LeAddDeviceToWhiteListBuilder(hci_packets.WhiteListAddressType.RANDOM, '0C:05:04:03:02:01'))
            hci_packets.LeAddDeviceToConnectListBuilder(hci_packets.ConnectListAddressType.RANDOM, '0C:05:04:03:02:01'))
        phy_scan_params = DirectHciTest._create_phy_scan_params()
        self.dut_hci.send_command_with_status(
            hci_packets.LeExtendedCreateConnectionBuilder(
                hci_packets.InitiatorFilterPolicy.USE_WHITE_LIST, hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                hci_packets.InitiatorFilterPolicy.USE_CONNECT_LIST, hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                hci_packets.AddressType.RANDOM_DEVICE_ADDRESS, 'BA:D5:A4:A3:A2:A1', 1, [phy_scan_params]))

        # CERT Advertises
+12 −12
Original line number Diff line number Diff line
@@ -70,8 +70,8 @@ struct Controller::impl {
                         handler->BindOnceOn(this, &Controller::impl::le_read_supported_states_handler));

    hci_->EnqueueCommand(
        LeReadWhiteListSizeBuilder::Create(),
        handler->BindOnceOn(this, &Controller::impl::le_read_white_list_size_handler));
        LeReadConnectListSizeBuilder::Create(),
        handler->BindOnceOn(this, &Controller::impl::le_read_connect_list_size_handler));

    hci_->EnqueueCommand(
        LeReadResolvingListSizeBuilder::Create(),
@@ -253,12 +253,12 @@ struct Controller::impl {
    le_supported_states_ = complete_view.GetLeStates();
  }

  void le_read_white_list_size_handler(CommandCompleteView view) {
    auto complete_view = LeReadWhiteListSizeCompleteView::Create(view);
  void le_read_connect_list_size_handler(CommandCompleteView view) {
    auto complete_view = LeReadConnectListSizeCompleteView::Create(view);
    ASSERT(complete_view.IsValid());
    ErrorCode status = complete_view.GetStatus();
    ASSERT_LOG(status == ErrorCode::SUCCESS, "Status 0x%02hhx, %s", status, ErrorCodeText(status).c_str());
    le_white_list_size_ = complete_view.GetWhiteListSize();
    le_connect_list_size_ = complete_view.GetConnectListSize();
  }

  void le_read_resolving_list_size_handler(CommandCompleteView view) {
@@ -589,10 +589,10 @@ struct Controller::impl {
      OP_CODE_MAPPING(LE_SET_SCAN_ENABLE)
      OP_CODE_MAPPING(LE_CREATE_CONNECTION)
      OP_CODE_MAPPING(LE_CREATE_CONNECTION_CANCEL)
      OP_CODE_MAPPING(LE_READ_WHITE_LIST_SIZE)
      OP_CODE_MAPPING(LE_CLEAR_WHITE_LIST)
      OP_CODE_MAPPING(LE_ADD_DEVICE_TO_WHITE_LIST)
      OP_CODE_MAPPING(LE_REMOVE_DEVICE_FROM_WHITE_LIST)
      OP_CODE_MAPPING(LE_READ_CONNECT_LIST_SIZE)
      OP_CODE_MAPPING(LE_CLEAR_CONNECT_LIST)
      OP_CODE_MAPPING(LE_ADD_DEVICE_TO_CONNECT_LIST)
      OP_CODE_MAPPING(LE_REMOVE_DEVICE_FROM_CONNECT_LIST)
      OP_CODE_MAPPING(LE_CONNECTION_UPDATE)
      OP_CODE_MAPPING(LE_SET_HOST_CHANNEL_CLASSIFICATION)
      OP_CODE_MAPPING(LE_READ_CHANNEL_MAP)
@@ -745,7 +745,7 @@ struct Controller::impl {
  LeBufferSize le_buffer_size_;
  uint64_t le_local_supported_features_;
  uint64_t le_supported_states_;
  uint8_t le_white_list_size_;
  uint8_t le_connect_list_size_;
  uint8_t le_resolving_list_size_;
  LeMaximumDataLength le_maximum_data_length_;
  uint16_t le_maximum_advertising_data_length_;
@@ -898,8 +898,8 @@ uint64_t Controller::GetControllerLeSupportedStates() const {
  return impl_->le_supported_states_;
}

uint8_t Controller::GetControllerLeWhiteListSize() const {
  return impl_->le_white_list_size_;
uint8_t Controller::GetControllerLeConnectListSize() const {
  return impl_->le_connect_list_size_;
}

uint8_t Controller::GetControllerLeResolvingListSize() const {
Loading