Loading system/gd/hci/acl_manager/le_impl.h +8 −1 Original line number Diff line number Diff line Loading @@ -141,7 +141,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { le_address_manager_ = new LeAddressManager( common::Bind(&le_impl::enqueue_command, common::Unretained(this)), handler_, controller->GetMacAddress(), controller->GetLeFilterAcceptListSize(), controller->GetLeResolvingListSize()); controller->GetLeResolvingListSize(), controller_); } ~le_impl() { Loading Loading @@ -857,6 +857,13 @@ public: address_with_type = AddressWithType(); } if (com::android::bluetooth::flags::rpa_offload_to_bt_controller() && controller_->IsSupported(OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2) && own_address_type != OwnAddressType::PUBLIC_DEVICE_ADDRESS) { log::info("Support RPA offload, set own address type RESOLVABLE_OR_RANDOM_ADDRESS"); own_address_type = OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS; } if (controller_->IsSupported(OpCode::LE_EXTENDED_CREATE_CONNECTION)) { bool only_init_1m_phy = os::GetSystemPropertyBool(kPropertyEnableBleOnlyInit1mPhy, kEnableBleOnlyInit1mPhy); Loading system/gd/hci/controller.cc +1 −0 Original line number Diff line number Diff line Loading @@ -1092,6 +1092,7 @@ struct Controller::impl { OP_CODE_MAPPING(LE_READ_LOCAL_RESOLVABLE_ADDRESS) OP_CODE_MAPPING(LE_SET_ADDRESS_RESOLUTION_ENABLE) OP_CODE_MAPPING(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT) OP_CODE_MAPPING(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2) OP_CODE_MAPPING(LE_READ_MAXIMUM_DATA_LENGTH) OP_CODE_MAPPING(LE_READ_PHY) OP_CODE_MAPPING(LE_SET_DEFAULT_PHY) Loading system/gd/hci/le_address_manager.cc +52 −13 Original line number Diff line number Diff line Loading @@ -21,10 +21,13 @@ #include <ctime> #include "hci/controller.h" #include "hci/octets.h" #include "include/macros.h" #include "os/rand.h" // TODO(b/378143579) For peer address not in resolving list // TODO(b/369381361) Enfore -Wmissing-prototypes #pragma GCC diagnostic ignored "-Wmissing-prototypes" Loading Loading @@ -64,12 +67,13 @@ std::string AddressPolicyText(const LeAddressManager::AddressPolicy policy) { LeAddressManager::LeAddressManager( common::Callback<void(std::unique_ptr<CommandBuilder>)> enqueue_command, os::Handler* handler, Address public_address, uint8_t accept_list_size, uint8_t resolving_list_size) uint8_t resolving_list_size, Controller* controller) : enqueue_command_(enqueue_command), handler_(handler), public_address_(public_address), accept_list_size_(accept_list_size), resolving_list_size_(resolving_list_size) {} resolving_list_size_(resolving_list_size), controller_(controller) {} LeAddressManager::~LeAddressManager() { if (address_rotation_wake_alarm_ != nullptr) { Loading Loading @@ -153,12 +157,26 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddress( log::info("minimum_rotation_time_={}ms, maximum_rotation_time_={}ms", minimum_rotation_time_.count(), maximum_rotation_time_.count()); } if (com::android::bluetooth::flags::rpa_offload_to_bt_controller() && controller_->IsSupported(hci::OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2)) { auto min_seconds = std::chrono::duration_cast<std::chrono::seconds>(minimum_rotation_time_); auto max_seconds = std::chrono::duration_cast<std::chrono::seconds>(maximum_rotation_time_); log::info( "Support RPA offload, set min_seconds={}s, max_seconds={}s", min_seconds.count(), max_seconds.count()); /* Default to 7 minutes minimum, 15 minutes maximum for random address refreshing; * device can override. */ auto packet = hci::LeSetResolvablePrivateAddressTimeoutV2Builder::Create( min_seconds.count(), max_seconds.count()); enqueue_command_.Run(std::move(packet)); } else { if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) { address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true); address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false); } else { address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_); } } set_random_address(); break; case AddressPolicy::POLICY_NOT_SET: Loading Loading @@ -205,6 +223,19 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddressForTest( maximum_rotation_time_ = maximum_rotation_time; log::info("minimum_rotation_time_={}ms, maximum_rotation_time_={}ms", minimum_rotation_time_.count(), maximum_rotation_time_.count()); if (com::android::bluetooth::flags::rpa_offload_to_bt_controller() && controller_->IsSupported(hci::OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2)) { auto min_seconds = std::chrono::duration_cast<std::chrono::seconds>(minimum_rotation_time_); auto max_seconds = std::chrono::duration_cast<std::chrono::seconds>(maximum_rotation_time_); log::info( "Support RPA offload, set min_seconds={}s, max_seconds={}s", min_seconds.count(), max_seconds.count()); /* Default to 7 minutes minimum, 15 minutes maximum for random address refreshing; * device can override. */ auto packet = hci::LeSetResolvablePrivateAddressTimeoutV2Builder::Create( min_seconds.count(), max_seconds.count()); enqueue_command_.Run(std::move(packet)); } else { if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) { address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true); address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false); Loading @@ -212,6 +243,7 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddressForTest( address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_); } set_random_address(); } break; case AddressPolicy::POLICY_NOT_SET: log::fatal("invalid parameters"); Loading @@ -237,10 +269,13 @@ void LeAddressManager::register_client(LeAddressManagerCallback* callback) { } else if (address_policy_ == AddressPolicy::USE_RESOLVABLE_ADDRESS || address_policy_ == AddressPolicy::USE_NON_RESOLVABLE_ADDRESS) { if (registered_clients_.size() == 1) { if (!com::android::bluetooth::flags::rpa_offload_to_bt_controller() || !controller_->IsSupported(hci::OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2)) { schedule_rotate_random_address(); log::info("Scheduled address rotation for first client registered"); } } } log::info("Client registered"); } Loading Loading @@ -817,6 +852,10 @@ void LeAddressManager::OnCommandComplete(bluetooth::hci::CommandCompleteView vie on_command_complete<LeClearFilterAcceptListCompleteView>(view); break; case OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2: on_command_complete<LeSetResolvablePrivateAddressTimeoutV2CompleteView>(view); break; default: log::error("Received UNSUPPORTED command {} complete", hci::OpCodeText(op_code)); break; Loading system/gd/hci/le_address_manager.h +4 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include "common/callback.h" #include "hci/address_with_type.h" #include "hci/controller.h" #include "hci/octets.h" #include "os/alarm.h" Loading @@ -47,7 +48,7 @@ class LeAddressManager { public: LeAddressManager(common::Callback<void(std::unique_ptr<CommandBuilder>)> enqueue_command, os::Handler* handler, Address public_address, uint8_t accept_list_size, uint8_t resolving_list_size); uint8_t resolving_list_size, Controller* controller); virtual ~LeAddressManager(); enum AddressPolicy { Loading Loading @@ -186,6 +187,8 @@ private: // Only used for logging error in address rotation time. std::optional<std::chrono::time_point<std::chrono::system_clock>> address_rotation_interval_min; std::optional<std::chrono::time_point<std::chrono::system_clock>> address_rotation_interval_max; Controller* controller_; }; } // namespace hci Loading system/gd/hci/le_address_manager_test.cc +39 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "hci/hci_layer_fake.h" #include "hci/octets.h" #include "hci/controller.h" #include "packet/raw_builder.h" using ::bluetooth::hci::Octet16; Loading @@ -34,6 +35,39 @@ using packet::kLittleEndian; using packet::PacketView; using packet::RawBuilder; class TestController : public Controller { public: bool IsSupported(OpCode op_code) const override { return supported_opcodes_.count(op_code) == 1; } void AddSupported(OpCode op_code) { supported_opcodes_.insert(op_code); } uint8_t GetLeNumberOfSupportedAdverisingSets() const override { return num_advertisers_; } uint16_t GetLeMaximumAdvertisingDataLength() const override { return 0x0672; } bool SupportsBlePeriodicAdvertising() const override { return true; } bool SupportsBleExtendedAdvertising() const override { return support_ble_extended_advertising_; } void SetBleExtendedAdvertisingSupport(bool support) { support_ble_extended_advertising_ = support; } VendorCapabilities GetVendorCapabilities() const override { return vendor_capabilities_; } uint8_t num_advertisers_{0}; VendorCapabilities vendor_capabilities_; protected: void Start() override {} void Stop() override {} void ListDependencies(ModuleList* /* list */) const {} private: std::set<OpCode> supported_opcodes_{}; bool support_ble_extended_advertising_ = false; }; class RotatorClient : public LeAddressManagerCallback { public: RotatorClient(LeAddressManager* le_address_manager, size_t id) Loading Loading @@ -76,9 +110,10 @@ public: handler_ = new Handler(thread_); hci_layer_ = new HciLayerFake(); Address address({0x01, 0x02, 0x03, 0x04, 0x05, 0x06}); controller_ = new TestController; le_address_manager_ = new LeAddressManager( common::Bind(&LeAddressManagerTest::enqueue_command, common::Unretained(this)), handler_, address, 0x3F, 0x3F); handler_, address, 0x3F, 0x3F, controller_); AllocateClients(1); } Loading Loading @@ -115,6 +150,7 @@ public: Thread* thread_; Handler* handler_; HciLayerFake* hci_layer_ = nullptr; TestController* controller_ = nullptr; LeAddressManager* le_address_manager_; std::vector<std::unique_ptr<RotatorClient>> clients; }; Loading Loading @@ -194,10 +230,11 @@ public: handler_ = new Handler(thread_); hci_layer_ = new HciLayerFake(); Address address({0x01, 0x02, 0x03, 0x04, 0x05, 0x06}); controller_ = new TestController; le_address_manager_ = new LeAddressManager( common::Bind(&LeAddressManagerWithSingleClientTest::enqueue_command, common::Unretained(this)), handler_, address, 0x3F, 0x3F); handler_, address, 0x3F, 0x3F, controller_); AllocateClients(1); Octet16 irk = {0xec, 0x02, 0x34, 0xa3, 0x57, 0xc8, 0xad, 0x05, Loading Loading
system/gd/hci/acl_manager/le_impl.h +8 −1 Original line number Diff line number Diff line Loading @@ -141,7 +141,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { le_address_manager_ = new LeAddressManager( common::Bind(&le_impl::enqueue_command, common::Unretained(this)), handler_, controller->GetMacAddress(), controller->GetLeFilterAcceptListSize(), controller->GetLeResolvingListSize()); controller->GetLeResolvingListSize(), controller_); } ~le_impl() { Loading Loading @@ -857,6 +857,13 @@ public: address_with_type = AddressWithType(); } if (com::android::bluetooth::flags::rpa_offload_to_bt_controller() && controller_->IsSupported(OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2) && own_address_type != OwnAddressType::PUBLIC_DEVICE_ADDRESS) { log::info("Support RPA offload, set own address type RESOLVABLE_OR_RANDOM_ADDRESS"); own_address_type = OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS; } if (controller_->IsSupported(OpCode::LE_EXTENDED_CREATE_CONNECTION)) { bool only_init_1m_phy = os::GetSystemPropertyBool(kPropertyEnableBleOnlyInit1mPhy, kEnableBleOnlyInit1mPhy); Loading
system/gd/hci/controller.cc +1 −0 Original line number Diff line number Diff line Loading @@ -1092,6 +1092,7 @@ struct Controller::impl { OP_CODE_MAPPING(LE_READ_LOCAL_RESOLVABLE_ADDRESS) OP_CODE_MAPPING(LE_SET_ADDRESS_RESOLUTION_ENABLE) OP_CODE_MAPPING(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT) OP_CODE_MAPPING(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2) OP_CODE_MAPPING(LE_READ_MAXIMUM_DATA_LENGTH) OP_CODE_MAPPING(LE_READ_PHY) OP_CODE_MAPPING(LE_SET_DEFAULT_PHY) Loading
system/gd/hci/le_address_manager.cc +52 −13 Original line number Diff line number Diff line Loading @@ -21,10 +21,13 @@ #include <ctime> #include "hci/controller.h" #include "hci/octets.h" #include "include/macros.h" #include "os/rand.h" // TODO(b/378143579) For peer address not in resolving list // TODO(b/369381361) Enfore -Wmissing-prototypes #pragma GCC diagnostic ignored "-Wmissing-prototypes" Loading Loading @@ -64,12 +67,13 @@ std::string AddressPolicyText(const LeAddressManager::AddressPolicy policy) { LeAddressManager::LeAddressManager( common::Callback<void(std::unique_ptr<CommandBuilder>)> enqueue_command, os::Handler* handler, Address public_address, uint8_t accept_list_size, uint8_t resolving_list_size) uint8_t resolving_list_size, Controller* controller) : enqueue_command_(enqueue_command), handler_(handler), public_address_(public_address), accept_list_size_(accept_list_size), resolving_list_size_(resolving_list_size) {} resolving_list_size_(resolving_list_size), controller_(controller) {} LeAddressManager::~LeAddressManager() { if (address_rotation_wake_alarm_ != nullptr) { Loading Loading @@ -153,12 +157,26 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddress( log::info("minimum_rotation_time_={}ms, maximum_rotation_time_={}ms", minimum_rotation_time_.count(), maximum_rotation_time_.count()); } if (com::android::bluetooth::flags::rpa_offload_to_bt_controller() && controller_->IsSupported(hci::OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2)) { auto min_seconds = std::chrono::duration_cast<std::chrono::seconds>(minimum_rotation_time_); auto max_seconds = std::chrono::duration_cast<std::chrono::seconds>(maximum_rotation_time_); log::info( "Support RPA offload, set min_seconds={}s, max_seconds={}s", min_seconds.count(), max_seconds.count()); /* Default to 7 minutes minimum, 15 minutes maximum for random address refreshing; * device can override. */ auto packet = hci::LeSetResolvablePrivateAddressTimeoutV2Builder::Create( min_seconds.count(), max_seconds.count()); enqueue_command_.Run(std::move(packet)); } else { if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) { address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true); address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false); } else { address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_); } } set_random_address(); break; case AddressPolicy::POLICY_NOT_SET: Loading Loading @@ -205,6 +223,19 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddressForTest( maximum_rotation_time_ = maximum_rotation_time; log::info("minimum_rotation_time_={}ms, maximum_rotation_time_={}ms", minimum_rotation_time_.count(), maximum_rotation_time_.count()); if (com::android::bluetooth::flags::rpa_offload_to_bt_controller() && controller_->IsSupported(hci::OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2)) { auto min_seconds = std::chrono::duration_cast<std::chrono::seconds>(minimum_rotation_time_); auto max_seconds = std::chrono::duration_cast<std::chrono::seconds>(maximum_rotation_time_); log::info( "Support RPA offload, set min_seconds={}s, max_seconds={}s", min_seconds.count(), max_seconds.count()); /* Default to 7 minutes minimum, 15 minutes maximum for random address refreshing; * device can override. */ auto packet = hci::LeSetResolvablePrivateAddressTimeoutV2Builder::Create( min_seconds.count(), max_seconds.count()); enqueue_command_.Run(std::move(packet)); } else { if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) { address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true); address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false); Loading @@ -212,6 +243,7 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddressForTest( address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_); } set_random_address(); } break; case AddressPolicy::POLICY_NOT_SET: log::fatal("invalid parameters"); Loading @@ -237,10 +269,13 @@ void LeAddressManager::register_client(LeAddressManagerCallback* callback) { } else if (address_policy_ == AddressPolicy::USE_RESOLVABLE_ADDRESS || address_policy_ == AddressPolicy::USE_NON_RESOLVABLE_ADDRESS) { if (registered_clients_.size() == 1) { if (!com::android::bluetooth::flags::rpa_offload_to_bt_controller() || !controller_->IsSupported(hci::OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2)) { schedule_rotate_random_address(); log::info("Scheduled address rotation for first client registered"); } } } log::info("Client registered"); } Loading Loading @@ -817,6 +852,10 @@ void LeAddressManager::OnCommandComplete(bluetooth::hci::CommandCompleteView vie on_command_complete<LeClearFilterAcceptListCompleteView>(view); break; case OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_V2: on_command_complete<LeSetResolvablePrivateAddressTimeoutV2CompleteView>(view); break; default: log::error("Received UNSUPPORTED command {} complete", hci::OpCodeText(op_code)); break; Loading
system/gd/hci/le_address_manager.h +4 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include "common/callback.h" #include "hci/address_with_type.h" #include "hci/controller.h" #include "hci/octets.h" #include "os/alarm.h" Loading @@ -47,7 +48,7 @@ class LeAddressManager { public: LeAddressManager(common::Callback<void(std::unique_ptr<CommandBuilder>)> enqueue_command, os::Handler* handler, Address public_address, uint8_t accept_list_size, uint8_t resolving_list_size); uint8_t resolving_list_size, Controller* controller); virtual ~LeAddressManager(); enum AddressPolicy { Loading Loading @@ -186,6 +187,8 @@ private: // Only used for logging error in address rotation time. std::optional<std::chrono::time_point<std::chrono::system_clock>> address_rotation_interval_min; std::optional<std::chrono::time_point<std::chrono::system_clock>> address_rotation_interval_max; Controller* controller_; }; } // namespace hci Loading
system/gd/hci/le_address_manager_test.cc +39 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "hci/hci_layer_fake.h" #include "hci/octets.h" #include "hci/controller.h" #include "packet/raw_builder.h" using ::bluetooth::hci::Octet16; Loading @@ -34,6 +35,39 @@ using packet::kLittleEndian; using packet::PacketView; using packet::RawBuilder; class TestController : public Controller { public: bool IsSupported(OpCode op_code) const override { return supported_opcodes_.count(op_code) == 1; } void AddSupported(OpCode op_code) { supported_opcodes_.insert(op_code); } uint8_t GetLeNumberOfSupportedAdverisingSets() const override { return num_advertisers_; } uint16_t GetLeMaximumAdvertisingDataLength() const override { return 0x0672; } bool SupportsBlePeriodicAdvertising() const override { return true; } bool SupportsBleExtendedAdvertising() const override { return support_ble_extended_advertising_; } void SetBleExtendedAdvertisingSupport(bool support) { support_ble_extended_advertising_ = support; } VendorCapabilities GetVendorCapabilities() const override { return vendor_capabilities_; } uint8_t num_advertisers_{0}; VendorCapabilities vendor_capabilities_; protected: void Start() override {} void Stop() override {} void ListDependencies(ModuleList* /* list */) const {} private: std::set<OpCode> supported_opcodes_{}; bool support_ble_extended_advertising_ = false; }; class RotatorClient : public LeAddressManagerCallback { public: RotatorClient(LeAddressManager* le_address_manager, size_t id) Loading Loading @@ -76,9 +110,10 @@ public: handler_ = new Handler(thread_); hci_layer_ = new HciLayerFake(); Address address({0x01, 0x02, 0x03, 0x04, 0x05, 0x06}); controller_ = new TestController; le_address_manager_ = new LeAddressManager( common::Bind(&LeAddressManagerTest::enqueue_command, common::Unretained(this)), handler_, address, 0x3F, 0x3F); handler_, address, 0x3F, 0x3F, controller_); AllocateClients(1); } Loading Loading @@ -115,6 +150,7 @@ public: Thread* thread_; Handler* handler_; HciLayerFake* hci_layer_ = nullptr; TestController* controller_ = nullptr; LeAddressManager* le_address_manager_; std::vector<std::unique_ptr<RotatorClient>> clients; }; Loading Loading @@ -194,10 +230,11 @@ public: handler_ = new Handler(thread_); hci_layer_ = new HciLayerFake(); Address address({0x01, 0x02, 0x03, 0x04, 0x05, 0x06}); controller_ = new TestController; le_address_manager_ = new LeAddressManager( common::Bind(&LeAddressManagerWithSingleClientTest::enqueue_command, common::Unretained(this)), handler_, address, 0x3F, 0x3F); handler_, address, 0x3F, 0x3F, controller_); AllocateClients(1); Octet16 irk = {0xec, 0x02, 0x34, 0xa3, 0x57, 0xc8, 0xad, 0x05, Loading