Loading system/gd/hci/cert/cert.cc +2 −0 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "common/blocking_queue.h" #include "common/blocking_queue.h" #include "grpc/grpc_event_stream.h" #include "grpc/grpc_event_stream.h" #include "hci/cert/api.grpc.pb.h" #include "hci/cert/api.grpc.pb.h" #include "hci/classic_security_manager.h" #include "hci/controller.h" #include "hci/controller.h" #include "hci/hci_layer.h" #include "hci/hci_layer.h" #include "hci/hci_packets.h" #include "hci/hci_packets.h" Loading Loading @@ -321,6 +322,7 @@ void AclManagerCertModule::ListDependencies(ModuleList* list) { ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list); ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list); list->add<Controller>(); list->add<Controller>(); list->add<HciLayer>(); list->add<HciLayer>(); list->add<ClassicSecurityManager>(); } } void AclManagerCertModule::Start() { void AclManagerCertModule::Start() { Loading system/gd/hci/classic_security_manager.cc +19 −8 Original line number Original line Diff line number Diff line Loading @@ -39,10 +39,15 @@ struct ClassicSecurityManager::impl { hci_layer_ = classic_security_manager_.GetDependency<HciLayer>(); hci_layer_ = classic_security_manager_.GetDependency<HciLayer>(); handler_ = classic_security_manager_.GetHandler(); handler_ = classic_security_manager_.GetHandler(); hci_layer_->RegisterEventHandler(EventCode::IO_CAPABILITY_REQUEST, hci_layer_->RegisterEventHandler(EventCode::IO_CAPABILITY_REQUEST, Bind(&impl::on_io_capbility_request, common::Unretained(this)), handler_); Bind(&impl::on_request_event, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::AUTHENTICATION_COMPLETE, hci_layer_->RegisterEventHandler(EventCode::AUTHENTICATION_COMPLETE, Bind(&impl::on_authentication_complete, common::Unretained(this)), handler_); Bind(&impl::on_authentication_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::LINK_KEY_REQUEST, Bind(&impl::on_request_event, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::PIN_CODE_REQUEST, Bind(&impl::on_request_event, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE, Bind(&impl::on_complete_event, common::Unretained(this)), handler_); } } void Stop() { void Stop() { Loading Loading @@ -174,9 +179,8 @@ struct ClassicSecurityManager::impl { void refresh_encryption_key(uint16_t connection_handle) { void refresh_encryption_key(uint16_t connection_handle) { std::unique_ptr<RefreshEncryptionKeyBuilder> packet = RefreshEncryptionKeyBuilder::Create(connection_handle); std::unique_ptr<RefreshEncryptionKeyBuilder> packet = RefreshEncryptionKeyBuilder::Create(connection_handle); // TODO wait for CommandStatusView hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce([](CommandStatusView status) { /* TODO: check? */ }), hci_layer_->EnqueueCommand(std::move(packet), handler_); common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } } void read_simple_pairing_mode() { void read_simple_pairing_mode() { Loading Loading @@ -225,13 +229,20 @@ struct ClassicSecurityManager::impl { } } // TODO remove // TODO remove void on_io_capbility_request(EventPacketView packet) { void on_request_event(EventPacketView packet) { LOG_DEBUG("CYDBG on_io_capbility_request"); EventCode event_code = packet.GetEventCode(); LOG_DEBUG("receive request %d", (uint8_t)event_code); } // TODO remove void on_complete_event(EventPacketView packet) { EventCode event_code = packet.GetEventCode(); LOG_DEBUG("receive complete event %d", (uint8_t)event_code); } } // TODO remove // TODO remove void on_authentication_complete(EventPacketView packet) { void on_authentication_complete(EventPacketView packet) { LOG_DEBUG("CYDBG on_authentication_complete"); LOG_DEBUG("on_authentication_complete"); } } void on_command_complete(CommandCompleteView status) { void on_command_complete(CommandCompleteView status) { Loading system/gd/hci/classic_security_manager_test.cc +19 −1 Original line number Original line Diff line number Diff line Loading @@ -122,6 +122,9 @@ class ClassicSecurityManagerTest : public ::testing::Test, public ::bluetooth::h test_hci_layer_->RegisterEventHandler( test_hci_layer_->RegisterEventHandler( EventCode::COMMAND_COMPLETE, base::Bind(&ClassicSecurityManagerTest::ExpectCommand, common::Unretained(this)), EventCode::COMMAND_COMPLETE, base::Bind(&ClassicSecurityManagerTest::ExpectCommand, common::Unretained(this)), nullptr); nullptr); test_hci_layer_->RegisterEventHandler( EventCode::COMMAND_STATUS, base::Bind(&ClassicSecurityManagerTest::ExpectCommandStatus, common::Unretained(this)), nullptr); Address::FromString("A1:A2:A3:A4:A5:A6", remote); Address::FromString("A1:A2:A3:A4:A5:A6", remote); } } Loading Loading @@ -155,6 +158,21 @@ class ClassicSecurityManagerTest : public ::testing::Test, public ::bluetooth::h command_complete_ = true; command_complete_ = true; } } void ExpectCommandStatus(EventPacketView packet) { CommandStatusView command_status_view = CommandStatusView::Create(std::move(packet)); auto last_command_queue_entry = test_hci_layer_->GetLastCommand(); auto last_command = std::move(last_command_queue_entry->command); auto command_packet = GetPacketView(std::move(last_command)); CommandPacketView command_packet_view = CommandPacketView::Create(command_packet); // verify command complete event match last command opcode EXPECT_TRUE(command_packet_view.IsValid()); EXPECT_TRUE(command_status_view.IsValid()); EXPECT_EQ(command_packet_view.GetOpCode(), command_status_view.GetCommandOpCode()); command_complete_ = true; } void OnCommandComplete(CommandCompleteView status) override { void OnCommandComplete(CommandCompleteView status) override { callback_done.notify_one(); callback_done.notify_one(); } } Loading Loading @@ -332,7 +350,7 @@ TEST_F(ClassicSecurityManagerTest, send_refresh_encryption_key) { auto payload = std::make_unique<RawBuilder>(); auto payload = std::make_unique<RawBuilder>(); test_hci_layer_->IncomingEvent( test_hci_layer_->IncomingEvent( CommandCompleteBuilder::Create(0x01, OpCode::REFRESH_ENCRYPTION_KEY, std::move(payload))); CommandStatusBuilder::Create(ErrorCode::SUCCESS, 0x01, OpCode::REFRESH_ENCRYPTION_KEY, std::move(payload))); EXPECT_TRUE(command_complete_); EXPECT_TRUE(command_complete_); } } Loading Loading
system/gd/hci/cert/cert.cc +2 −0 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "common/blocking_queue.h" #include "common/blocking_queue.h" #include "grpc/grpc_event_stream.h" #include "grpc/grpc_event_stream.h" #include "hci/cert/api.grpc.pb.h" #include "hci/cert/api.grpc.pb.h" #include "hci/classic_security_manager.h" #include "hci/controller.h" #include "hci/controller.h" #include "hci/hci_layer.h" #include "hci/hci_layer.h" #include "hci/hci_packets.h" #include "hci/hci_packets.h" Loading Loading @@ -321,6 +322,7 @@ void AclManagerCertModule::ListDependencies(ModuleList* list) { ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list); ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list); list->add<Controller>(); list->add<Controller>(); list->add<HciLayer>(); list->add<HciLayer>(); list->add<ClassicSecurityManager>(); } } void AclManagerCertModule::Start() { void AclManagerCertModule::Start() { Loading
system/gd/hci/classic_security_manager.cc +19 −8 Original line number Original line Diff line number Diff line Loading @@ -39,10 +39,15 @@ struct ClassicSecurityManager::impl { hci_layer_ = classic_security_manager_.GetDependency<HciLayer>(); hci_layer_ = classic_security_manager_.GetDependency<HciLayer>(); handler_ = classic_security_manager_.GetHandler(); handler_ = classic_security_manager_.GetHandler(); hci_layer_->RegisterEventHandler(EventCode::IO_CAPABILITY_REQUEST, hci_layer_->RegisterEventHandler(EventCode::IO_CAPABILITY_REQUEST, Bind(&impl::on_io_capbility_request, common::Unretained(this)), handler_); Bind(&impl::on_request_event, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::AUTHENTICATION_COMPLETE, hci_layer_->RegisterEventHandler(EventCode::AUTHENTICATION_COMPLETE, Bind(&impl::on_authentication_complete, common::Unretained(this)), handler_); Bind(&impl::on_authentication_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::LINK_KEY_REQUEST, Bind(&impl::on_request_event, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::PIN_CODE_REQUEST, Bind(&impl::on_request_event, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE, Bind(&impl::on_complete_event, common::Unretained(this)), handler_); } } void Stop() { void Stop() { Loading Loading @@ -174,9 +179,8 @@ struct ClassicSecurityManager::impl { void refresh_encryption_key(uint16_t connection_handle) { void refresh_encryption_key(uint16_t connection_handle) { std::unique_ptr<RefreshEncryptionKeyBuilder> packet = RefreshEncryptionKeyBuilder::Create(connection_handle); std::unique_ptr<RefreshEncryptionKeyBuilder> packet = RefreshEncryptionKeyBuilder::Create(connection_handle); // TODO wait for CommandStatusView hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce([](CommandStatusView status) { /* TODO: check? */ }), hci_layer_->EnqueueCommand(std::move(packet), handler_); common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } } void read_simple_pairing_mode() { void read_simple_pairing_mode() { Loading Loading @@ -225,13 +229,20 @@ struct ClassicSecurityManager::impl { } } // TODO remove // TODO remove void on_io_capbility_request(EventPacketView packet) { void on_request_event(EventPacketView packet) { LOG_DEBUG("CYDBG on_io_capbility_request"); EventCode event_code = packet.GetEventCode(); LOG_DEBUG("receive request %d", (uint8_t)event_code); } // TODO remove void on_complete_event(EventPacketView packet) { EventCode event_code = packet.GetEventCode(); LOG_DEBUG("receive complete event %d", (uint8_t)event_code); } } // TODO remove // TODO remove void on_authentication_complete(EventPacketView packet) { void on_authentication_complete(EventPacketView packet) { LOG_DEBUG("CYDBG on_authentication_complete"); LOG_DEBUG("on_authentication_complete"); } } void on_command_complete(CommandCompleteView status) { void on_command_complete(CommandCompleteView status) { Loading
system/gd/hci/classic_security_manager_test.cc +19 −1 Original line number Original line Diff line number Diff line Loading @@ -122,6 +122,9 @@ class ClassicSecurityManagerTest : public ::testing::Test, public ::bluetooth::h test_hci_layer_->RegisterEventHandler( test_hci_layer_->RegisterEventHandler( EventCode::COMMAND_COMPLETE, base::Bind(&ClassicSecurityManagerTest::ExpectCommand, common::Unretained(this)), EventCode::COMMAND_COMPLETE, base::Bind(&ClassicSecurityManagerTest::ExpectCommand, common::Unretained(this)), nullptr); nullptr); test_hci_layer_->RegisterEventHandler( EventCode::COMMAND_STATUS, base::Bind(&ClassicSecurityManagerTest::ExpectCommandStatus, common::Unretained(this)), nullptr); Address::FromString("A1:A2:A3:A4:A5:A6", remote); Address::FromString("A1:A2:A3:A4:A5:A6", remote); } } Loading Loading @@ -155,6 +158,21 @@ class ClassicSecurityManagerTest : public ::testing::Test, public ::bluetooth::h command_complete_ = true; command_complete_ = true; } } void ExpectCommandStatus(EventPacketView packet) { CommandStatusView command_status_view = CommandStatusView::Create(std::move(packet)); auto last_command_queue_entry = test_hci_layer_->GetLastCommand(); auto last_command = std::move(last_command_queue_entry->command); auto command_packet = GetPacketView(std::move(last_command)); CommandPacketView command_packet_view = CommandPacketView::Create(command_packet); // verify command complete event match last command opcode EXPECT_TRUE(command_packet_view.IsValid()); EXPECT_TRUE(command_status_view.IsValid()); EXPECT_EQ(command_packet_view.GetOpCode(), command_status_view.GetCommandOpCode()); command_complete_ = true; } void OnCommandComplete(CommandCompleteView status) override { void OnCommandComplete(CommandCompleteView status) override { callback_done.notify_one(); callback_done.notify_one(); } } Loading Loading @@ -332,7 +350,7 @@ TEST_F(ClassicSecurityManagerTest, send_refresh_encryption_key) { auto payload = std::make_unique<RawBuilder>(); auto payload = std::make_unique<RawBuilder>(); test_hci_layer_->IncomingEvent( test_hci_layer_->IncomingEvent( CommandCompleteBuilder::Create(0x01, OpCode::REFRESH_ENCRYPTION_KEY, std::move(payload))); CommandStatusBuilder::Create(ErrorCode::SUCCESS, 0x01, OpCode::REFRESH_ENCRYPTION_KEY, std::move(payload))); EXPECT_TRUE(command_complete_); EXPECT_TRUE(command_complete_); } } Loading