Loading flags/hci.aconfig +7 −0 Original line number Original line Diff line number Diff line Loading @@ -10,3 +10,10 @@ flag { purpose: PURPOSE_BUGFIX purpose: PURPOSE_BUGFIX } } } } flag { name: "encryption_change_v2" namespace: "bluetooth" description: "Enable encryption change V2 event" bug: "366018699" } system/gd/hci/controller.cc +11 −0 Original line number Original line Diff line number Diff line Loading @@ -56,6 +56,10 @@ struct Controller::impl { handler->BindOn(this, &Controller::impl::NumberOfCompletedPackets)); handler->BindOn(this, &Controller::impl::NumberOfCompletedPackets)); set_event_mask(kDefaultEventMask); set_event_mask(kDefaultEventMask); if (com::android::bluetooth::flags::encryption_change_v2()) { set_event_mask_page_2(kDefaultEventMaskPage2); } write_le_host_support(Enable::ENABLED, Enable::DISABLED); write_le_host_support(Enable::ENABLED, Enable::DISABLED); hci_->EnqueueCommand( hci_->EnqueueCommand( ReadLocalNameBuilder::Create(), ReadLocalNameBuilder::Create(), Loading Loading @@ -766,6 +770,13 @@ struct Controller::impl { module_.GetHandler()->BindOnce(check_complete<SetEventMaskCompleteView>)); module_.GetHandler()->BindOnce(check_complete<SetEventMaskCompleteView>)); } } void set_event_mask_page_2(uint64_t event_mask_page_2) { std::unique_ptr<SetEventMaskPage2Builder> packet = SetEventMaskPage2Builder::Create(event_mask_page_2); hci_->EnqueueCommand(std::move(packet), module_.GetHandler()->BindOnce( check_complete<SetEventMaskPage2CompleteView>)); } void write_le_host_support(Enable enable, Enable deprecated_host_bit) { void write_le_host_support(Enable enable, Enable deprecated_host_bit) { if (deprecated_host_bit == Enable::ENABLED) { if (deprecated_host_bit == Enable::ENABLED) { // Since Bluetooth Core Spec 4.1, this bit should be 0 // Since Bluetooth Core Spec 4.1, this bit should be 0 Loading system/gd/hci/controller.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -202,6 +202,7 @@ public: static const ModuleFactory Factory; static const ModuleFactory Factory; static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff; static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff; static constexpr uint64_t kDefaultEventMaskPage2 = 0x2000000; static constexpr uint64_t kDefaultLeEventMask = 0x000000074d02fe7f; static constexpr uint64_t kDefaultLeEventMask = 0x000000074d02fe7f; static constexpr uint64_t kLeCSEventMask = 0x0007f80000000000; static constexpr uint64_t kLeCSEventMask = 0x0007f80000000000; Loading system/gd/hci/security_interface.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,7 @@ constexpr hci::EventCode SecurityEvents[] = { hci::EventCode::KEYPRESS_NOTIFICATION, hci::EventCode::KEYPRESS_NOTIFICATION, hci::EventCode::USER_CONFIRMATION_REQUEST, hci::EventCode::USER_CONFIRMATION_REQUEST, hci::EventCode::USER_PASSKEY_REQUEST, hci::EventCode::USER_PASSKEY_REQUEST, hci::EventCode::ENCRYPTION_CHANGE_V2, }; }; typedef CommandInterface<SecurityCommandBuilder> SecurityInterface; typedef CommandInterface<SecurityCommandBuilder> SecurityInterface; Loading system/gd/security/channel/security_manager_channel_unittest.cc +16 −0 Original line number Original line Diff line number Diff line Loading @@ -82,6 +82,7 @@ public: bool receivedUserPasskeyRequest = false; bool receivedUserPasskeyRequest = false; bool receivedKeypressNotification = false; bool receivedKeypressNotification = false; bool receivedUserConfirmationRequest = false; bool receivedUserConfirmationRequest = false; bool receivedEncryptionChangeV2 = false; void OnReceive(hci::AddressWithType device, hci::ChangeConnectionLinkKeyCompleteView packet) { void OnReceive(hci::AddressWithType device, hci::ChangeConnectionLinkKeyCompleteView packet) { ASSERT_TRUE(packet.IsValid()); ASSERT_TRUE(packet.IsValid()); Loading Loading @@ -147,6 +148,10 @@ public: ASSERT_TRUE(packet.IsValid()); ASSERT_TRUE(packet.IsValid()); receivedUserPasskeyRequest = true; receivedUserPasskeyRequest = true; } } void OnReceive(hci::AddressWithType device, hci::EncryptionChangeV2View packet) { ASSERT_TRUE(packet.IsValid()); receivedEncryptionChangeV2 = true; } void OnHciEventReceived(EventView packet) override { void OnHciEventReceived(EventView packet) override { auto event = EventView::Create(packet); auto event = EventView::Create(packet); Loading Loading @@ -201,6 +206,9 @@ public: case hci::EventCode::USER_PASSKEY_REQUEST: case hci::EventCode::USER_PASSKEY_REQUEST: OnReceive(hci::AddressWithType(), hci::UserPasskeyRequestView::Create(event)); OnReceive(hci::AddressWithType(), hci::UserPasskeyRequestView::Create(event)); break; break; case hci::EventCode::ENCRYPTION_CHANGE_V2: OnReceive(hci::AddressWithType(), hci::EncryptionChangeV2View::Create(event)); break; default: default: log::fatal("Cannot handle received packet: {}", hci::EventCodeText(code)); log::fatal("Cannot handle received packet: {}", hci::EventCodeText(code)); break; break; Loading Loading @@ -584,6 +592,14 @@ TEST_F(SecurityManagerChannelTest, recv_encryption_change) { ASSERT_TRUE(callback_->receivedEncryptionChange); ASSERT_TRUE(callback_->receivedEncryptionChange); } } TEST_F(SecurityManagerChannelTest, recv_encryption_change_v2) { uint16_t connection_handle = 0x0; hci_layer_->IncomingEvent(hci::EncryptionChangeV2Builder::Create( hci::ErrorCode::SUCCESS, connection_handle, hci::EncryptionEnabled::ON, 0x10)); synchronize(); ASSERT_TRUE(callback_->receivedEncryptionChangeV2); } TEST_F(SecurityManagerChannelTest, recv_encryption_key_refresh) { TEST_F(SecurityManagerChannelTest, recv_encryption_key_refresh) { uint16_t connection_handle = 0x0; uint16_t connection_handle = 0x0; hci_layer_->IncomingEvent(hci::EncryptionKeyRefreshCompleteBuilder::Create( hci_layer_->IncomingEvent(hci::EncryptionKeyRefreshCompleteBuilder::Create( Loading Loading
flags/hci.aconfig +7 −0 Original line number Original line Diff line number Diff line Loading @@ -10,3 +10,10 @@ flag { purpose: PURPOSE_BUGFIX purpose: PURPOSE_BUGFIX } } } } flag { name: "encryption_change_v2" namespace: "bluetooth" description: "Enable encryption change V2 event" bug: "366018699" }
system/gd/hci/controller.cc +11 −0 Original line number Original line Diff line number Diff line Loading @@ -56,6 +56,10 @@ struct Controller::impl { handler->BindOn(this, &Controller::impl::NumberOfCompletedPackets)); handler->BindOn(this, &Controller::impl::NumberOfCompletedPackets)); set_event_mask(kDefaultEventMask); set_event_mask(kDefaultEventMask); if (com::android::bluetooth::flags::encryption_change_v2()) { set_event_mask_page_2(kDefaultEventMaskPage2); } write_le_host_support(Enable::ENABLED, Enable::DISABLED); write_le_host_support(Enable::ENABLED, Enable::DISABLED); hci_->EnqueueCommand( hci_->EnqueueCommand( ReadLocalNameBuilder::Create(), ReadLocalNameBuilder::Create(), Loading Loading @@ -766,6 +770,13 @@ struct Controller::impl { module_.GetHandler()->BindOnce(check_complete<SetEventMaskCompleteView>)); module_.GetHandler()->BindOnce(check_complete<SetEventMaskCompleteView>)); } } void set_event_mask_page_2(uint64_t event_mask_page_2) { std::unique_ptr<SetEventMaskPage2Builder> packet = SetEventMaskPage2Builder::Create(event_mask_page_2); hci_->EnqueueCommand(std::move(packet), module_.GetHandler()->BindOnce( check_complete<SetEventMaskPage2CompleteView>)); } void write_le_host_support(Enable enable, Enable deprecated_host_bit) { void write_le_host_support(Enable enable, Enable deprecated_host_bit) { if (deprecated_host_bit == Enable::ENABLED) { if (deprecated_host_bit == Enable::ENABLED) { // Since Bluetooth Core Spec 4.1, this bit should be 0 // Since Bluetooth Core Spec 4.1, this bit should be 0 Loading
system/gd/hci/controller.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -202,6 +202,7 @@ public: static const ModuleFactory Factory; static const ModuleFactory Factory; static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff; static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff; static constexpr uint64_t kDefaultEventMaskPage2 = 0x2000000; static constexpr uint64_t kDefaultLeEventMask = 0x000000074d02fe7f; static constexpr uint64_t kDefaultLeEventMask = 0x000000074d02fe7f; static constexpr uint64_t kLeCSEventMask = 0x0007f80000000000; static constexpr uint64_t kLeCSEventMask = 0x0007f80000000000; Loading
system/gd/hci/security_interface.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,7 @@ constexpr hci::EventCode SecurityEvents[] = { hci::EventCode::KEYPRESS_NOTIFICATION, hci::EventCode::KEYPRESS_NOTIFICATION, hci::EventCode::USER_CONFIRMATION_REQUEST, hci::EventCode::USER_CONFIRMATION_REQUEST, hci::EventCode::USER_PASSKEY_REQUEST, hci::EventCode::USER_PASSKEY_REQUEST, hci::EventCode::ENCRYPTION_CHANGE_V2, }; }; typedef CommandInterface<SecurityCommandBuilder> SecurityInterface; typedef CommandInterface<SecurityCommandBuilder> SecurityInterface; Loading
system/gd/security/channel/security_manager_channel_unittest.cc +16 −0 Original line number Original line Diff line number Diff line Loading @@ -82,6 +82,7 @@ public: bool receivedUserPasskeyRequest = false; bool receivedUserPasskeyRequest = false; bool receivedKeypressNotification = false; bool receivedKeypressNotification = false; bool receivedUserConfirmationRequest = false; bool receivedUserConfirmationRequest = false; bool receivedEncryptionChangeV2 = false; void OnReceive(hci::AddressWithType device, hci::ChangeConnectionLinkKeyCompleteView packet) { void OnReceive(hci::AddressWithType device, hci::ChangeConnectionLinkKeyCompleteView packet) { ASSERT_TRUE(packet.IsValid()); ASSERT_TRUE(packet.IsValid()); Loading Loading @@ -147,6 +148,10 @@ public: ASSERT_TRUE(packet.IsValid()); ASSERT_TRUE(packet.IsValid()); receivedUserPasskeyRequest = true; receivedUserPasskeyRequest = true; } } void OnReceive(hci::AddressWithType device, hci::EncryptionChangeV2View packet) { ASSERT_TRUE(packet.IsValid()); receivedEncryptionChangeV2 = true; } void OnHciEventReceived(EventView packet) override { void OnHciEventReceived(EventView packet) override { auto event = EventView::Create(packet); auto event = EventView::Create(packet); Loading Loading @@ -201,6 +206,9 @@ public: case hci::EventCode::USER_PASSKEY_REQUEST: case hci::EventCode::USER_PASSKEY_REQUEST: OnReceive(hci::AddressWithType(), hci::UserPasskeyRequestView::Create(event)); OnReceive(hci::AddressWithType(), hci::UserPasskeyRequestView::Create(event)); break; break; case hci::EventCode::ENCRYPTION_CHANGE_V2: OnReceive(hci::AddressWithType(), hci::EncryptionChangeV2View::Create(event)); break; default: default: log::fatal("Cannot handle received packet: {}", hci::EventCodeText(code)); log::fatal("Cannot handle received packet: {}", hci::EventCodeText(code)); break; break; Loading Loading @@ -584,6 +592,14 @@ TEST_F(SecurityManagerChannelTest, recv_encryption_change) { ASSERT_TRUE(callback_->receivedEncryptionChange); ASSERT_TRUE(callback_->receivedEncryptionChange); } } TEST_F(SecurityManagerChannelTest, recv_encryption_change_v2) { uint16_t connection_handle = 0x0; hci_layer_->IncomingEvent(hci::EncryptionChangeV2Builder::Create( hci::ErrorCode::SUCCESS, connection_handle, hci::EncryptionEnabled::ON, 0x10)); synchronize(); ASSERT_TRUE(callback_->receivedEncryptionChangeV2); } TEST_F(SecurityManagerChannelTest, recv_encryption_key_refresh) { TEST_F(SecurityManagerChannelTest, recv_encryption_key_refresh) { uint16_t connection_handle = 0x0; uint16_t connection_handle = 0x0; hci_layer_->IncomingEvent(hci::EncryptionKeyRefreshCompleteBuilder::Create( hci_layer_->IncomingEvent(hci::EncryptionKeyRefreshCompleteBuilder::Create( Loading