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

Commit bf2d36c9 authored by Chienyuan's avatar Chienyuan Committed by Myles Watson
Browse files

gd HCI: Split SetPrivacyPolicy from SetInitiatorAddress

Tag: #gd-refactor
Bug: 152348535
Test: gd/cert/run --host
Test: atest bluetooth_test_gd
Change-Id: Ia126dfffca2425b6767b542283997af969d72354
parent e34fc62a
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -221,14 +221,6 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
    le_address_rotator_->OnLeSetRandomAddressComplete(true);
  }

  std::chrono::milliseconds GetNextPrivateAddrressIntervalMs() {
    /* 7 minutes minimum, 15 minutes maximum for random address refreshing */
    const uint64_t interval_min_ms = (7 * 60 * 1000);
    const uint64_t interval_random_part_max_ms = (8 * 60 * 1000);

    return std::chrono::milliseconds(interval_min_ms + os::GenerateRandom() % interval_random_part_max_ms);
  }

  void SetRandomAddress(Address address) {
    hci_layer_->EnqueueCommand(
        hci::LeSetRandomAddressBuilder::Create(address),
+4 −4
Original line number Diff line number Diff line
@@ -315,11 +315,11 @@ class AclManagerNoCallbacksTest : public ::testing::Test {
    // Verify LE Set Random Address was sent during setup
    hci::AddressWithType address_with_type(hci::Address::kEmpty, hci::AddressType::RANDOM_DEVICE_ADDRESS);
    crypto_toolbox::Octet16 irk = {};
    auto interval_min_ms = std::chrono::milliseconds(7 * 60 * 1000);
    auto interval_random_part_max_ms = std::chrono::milliseconds(15 * 60 * 1000);
    auto minimum_rotation_time = std::chrono::milliseconds(7 * 60 * 1000);
    auto maximum_rotation_time = std::chrono::milliseconds(15 * 60 * 1000);
    acl_manager_->SetPrivacyPolicyForInitiatorAddress(LeAddressRotator::AddressPolicy::USE_RESOLVABLE_ADDRESS,
                                                      address_with_type, irk, interval_min_ms,
                                                      interval_random_part_max_ms);
                                                      address_with_type, irk, minimum_rotation_time,
                                                      maximum_rotation_time);

    auto set_random_address_packet = test_hci_layer_->GetLeSetRandomAddressPacket();
    EXPECT_TRUE(set_random_address_packet.IsValid());
+13 −0
Original line number Diff line number Diff line
@@ -38,6 +38,19 @@ class LeAclManagerTest(GdBaseTestClass):
                address=bytes(b'0D:05:04:03:02:01')),
            type=common.RANDOM_DEVICE_ADDRESS)
        self.dut.hci_le_acl_manager.SetInitiatorAddress(dut_address)
        private_policy = le_acl_manager_facade.PrivacyPolicy(
            address_policy=le_acl_manager_facade.AddressPolicy.
            USE_RESOLVABLE_ADDRESS,
            address_with_type=common.BluetoothAddressWithType(
                address=common.BluetoothAddress(
                    address=bytes(b'00:00:00:00:00:00')),
                type=common.RANDOM_DEVICE_ADDRESS),
            rotation_irk=
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
            minimum_rotation_time=(7 * 60 * 1000),
            maximum_rotation_time=(15 * 60 * 1000))
        self.dut.hci_le_acl_manager.SetPrivacyPolicyForInitiatorAddress(
            private_policy)

    def register_for_event(self, event_code):
        msg = hci_facade.EventCodeMsg(code=int(event_code))
+16 −6
Original line number Diff line number Diff line
@@ -122,13 +122,23 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC
    Address address;
    ASSERT(Address::FromString(request->address().address(), address));
    acl_manager_->SetLeInitiatorAddress(AddressWithType(address, static_cast<AddressType>(request->type())));
    AddressWithType address_with_type(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS);
    return ::grpc::Status::OK;
  }

  ::grpc::Status SetPrivacyPolicyForInitiatorAddress(::grpc::ServerContext* context, const PrivacyPolicy* request,
                                                     ::google::protobuf::Empty* writer) override {
    Address address;
    ASSERT(Address::FromString(request->address_with_type().address().address(), address));
    LeAddressRotator::AddressPolicy address_policy =
        static_cast<LeAddressRotator::AddressPolicy>(request->address_policy());
    AddressWithType address_with_type(address, static_cast<AddressType>(request->address_with_type().type()));
    std::vector<uint8_t> irk_data(request->rotation_irk().begin(), request->rotation_irk().end());
    crypto_toolbox::Octet16 irk = {};
    auto interval_min_ms = std::chrono::milliseconds(7 * 60 * 1000);
    auto interval_random_part_max_ms = std::chrono::milliseconds(15 * 60 * 1000);
    acl_manager_->SetPrivacyPolicyForInitiatorAddress(LeAddressRotator::AddressPolicy::USE_RESOLVABLE_ADDRESS,
                                                      address_with_type, irk, interval_min_ms,
                                                      interval_random_part_max_ms);
    std::copy_n(irk_data.begin(), crypto_toolbox::OCTET16_LEN, irk.begin());
    auto minimum_rotation_time = std::chrono::milliseconds(request->minimum_rotation_time());
    auto maximum_rotation_time = std::chrono::milliseconds(request->maximum_rotation_time());
    acl_manager_->SetPrivacyPolicyForInitiatorAddress(address_policy, address_with_type, irk, minimum_rotation_time,
                                                      maximum_rotation_time);
    return ::grpc::Status::OK;
  }

+17 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ service LeAclManagerFacade {
  rpc FetchAclData(google.protobuf.Empty) returns (stream LeAclData) {}
  rpc FetchIncomingConnection(google.protobuf.Empty) returns (stream LeConnectionEvent) {}
  rpc SetInitiatorAddress(bluetooth.facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {}
  rpc SetPrivacyPolicyForInitiatorAddress(PrivacyPolicy) returns (google.protobuf.Empty) {}
}

message LeHandleMsg {
@@ -32,3 +33,19 @@ message LeAclData {
  uint32 handle = 1;
  bytes payload = 2;
}

enum AddressPolicy {
  POLICY_NOT_SET = 0x00;
  USE_PUBLIC_ADDRESS = 0x01;
  USE_STATIC_ADDRESS = 0x02;
  USE_NON_RESOLVABLE_ADDRESS = 0x03;
  USE_RESOLVABLE_ADDRESS = 0x04;
}

message PrivacyPolicy {
  AddressPolicy address_policy = 1;
  facade.BluetoothAddressWithType address_with_type = 2;
  bytes rotation_irk = 3;
  uint64 minimum_rotation_time = 4;
  uint64 maximum_rotation_time = 5;
}
Loading