Loading system/gd/hci/acl_manager.cc +168 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,8 @@ struct AclManager::impl { hci_layer_->RegisterEventHandler(EventCode::CONNECTION_PACKET_TYPE_CHANGED, Bind(&impl::on_connection_packet_type_changed, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::MASTER_LINK_KEY_COMPLETE, Bind(&impl::on_master_link_key_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::AUTHENTICATION_COMPLETE, Bind(&impl::on_authentication_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ENCRYPTION_CHANGE, Loading @@ -94,6 +96,8 @@ struct AclManager::impl { handler_); hci_layer_->RegisterEventHandler(EventCode::QOS_SETUP_COMPLETE, Bind(&impl::on_qos_setup_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ROLE_CHANGE, Bind(&impl::on_role_change, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::FLOW_SPECIFICATION_COMPLETE, Bind(&impl::on_flow_specification_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::FLUSH_OCCURRED, Loading Loading @@ -366,6 +370,26 @@ struct AclManager::impl { } } void on_master_link_key_complete(EventPacketView packet) { MasterLinkKeyCompleteView complete_view = MasterLinkKeyCompleteView::Create(packet); if (!complete_view.IsValid()) { LOG_ERROR("Received on_master_link_key_complete with invalid packet"); return; } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) { auto status = complete_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_master_link_key_complete with error code %s", error_code.c_str()); return; } if (acl_manager_client_callbacks_ != nullptr) { uint16_t connection_handle = complete_view.GetConnectionHandle(); KeyFlag key_flag = complete_view.GetKeyFlag(); acl_manager_client_handler_->Post(common::BindOnce(&AclManagerCallbacks::OnMasterLinkKeyComplete, common::Unretained(acl_manager_client_callbacks_), connection_handle, key_flag)); } } void on_authentication_complete(EventPacketView packet) { AuthenticationCompleteView authentication_complete = AuthenticationCompleteView::Create(packet); if (!authentication_complete.IsValid()) { Loading Loading @@ -496,6 +520,25 @@ struct AclManager::impl { } } void on_role_change(EventPacketView packet) { RoleChangeView role_change_view = RoleChangeView::Create(packet); if (!role_change_view.IsValid()) { LOG_ERROR("Received on_role_change with invalid packet"); return; } else if (role_change_view.GetStatus() != ErrorCode::SUCCESS) { auto status = role_change_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_role_change with error code %s", error_code.c_str()); return; } if (acl_manager_client_callbacks_ != nullptr) { Address bd_addr = role_change_view.GetBdAddr(); Role new_role = role_change_view.GetNewRole(); acl_manager_client_handler_->Post(common::BindOnce( &AclManagerCallbacks::OnRoleChange, common::Unretained(acl_manager_client_callbacks_), bd_addr, new_role)); } } void on_flow_specification_complete(EventPacketView packet) { FlowSpecificationCompleteView complete_view = FlowSpecificationCompleteView::Create(packet); if (!complete_view.IsValid()) { Loading Loading @@ -580,6 +623,25 @@ struct AclManager::impl { } } void on_read_default_link_policy_settings_complete(CommandCompleteView view) { auto complete_view = ReadDefaultLinkPolicySettingsCompleteView::Create(view); if (!complete_view.IsValid()) { LOG_ERROR("Received on_read_link_policy_settings_complete with invalid packet"); return; } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) { auto status = complete_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_read_link_policy_settings_complete with error code %s", error_code.c_str()); return; } if (acl_manager_client_callbacks_ != nullptr) { uint16_t default_link_policy_settings = complete_view.GetDefaultLinkPolicySettings(); acl_manager_client_handler_->Post(common::BindOnce(&AclManagerCallbacks::OnReadDefaultLinkPolicySettingsComplete, common::Unretained(acl_manager_client_callbacks_), default_link_policy_settings)); } } void on_read_automatic_flush_timeout_complete(CommandCompleteView view) { auto complete_view = ReadAutomaticFlushTimeoutCompleteView::Create(view); if (!complete_view.IsValid()) { Loading Loading @@ -685,6 +747,28 @@ struct AclManager::impl { } } void on_read_afh_channel_map_complete(CommandCompleteView view) { auto complete_view = ReadAfhChannelMapCompleteView::Create(view); if (!complete_view.IsValid()) { LOG_ERROR("Received on_read_afh_channel_map_complete with invalid packet"); return; } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) { auto status = complete_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_read_afh_channel_map_complete with error code %s", error_code.c_str()); return; } uint16_t handle = complete_view.GetConnectionHandle(); auto& acl_connection = acl_connections_.find(handle)->second; if (acl_connection.command_complete_handler_ != nullptr) { AfhMode afh_mode = complete_view.GetAfhMode(); std::array<uint8_t, 10> afh_channel_map = complete_view.GetAfhChannelMap(); acl_connection.command_complete_handler_->Post( common::BindOnce(&ConnectionManagementCallbacks::OnReadAfhChannelMapComplete, common::Unretained(acl_connection.command_complete_callbacks_), afh_mode, afh_channel_map)); } } void on_read_rssi_complete(CommandCompleteView view) { auto complete_view = ReadRssiCompleteView::Create(view); if (!complete_view.IsValid()) { Loading Loading @@ -788,6 +872,37 @@ struct AclManager::impl { handler_); } void master_link_key(KeyFlag key_flag) { std::unique_ptr<MasterLinkKeyBuilder> packet = MasterLinkKeyBuilder::Create(key_flag); hci_layer_->EnqueueCommand( std::move(packet), common::BindOnce(&impl::check_command_status<MasterLinkKeyStatusView>, common::Unretained(this)), handler_); } void switch_role(Address address, Role role) { std::unique_ptr<SwitchRoleBuilder> packet = SwitchRoleBuilder::Create(address, role); hci_layer_->EnqueueCommand( std::move(packet), common::BindOnce(&impl::check_command_status<SwitchRoleStatusView>, common::Unretained(this)), handler_); } void read_default_link_policy_settings() { std::unique_ptr<ReadDefaultLinkPolicySettingsBuilder> packet = ReadDefaultLinkPolicySettingsBuilder::Create(); hci_layer_->EnqueueCommand( std::move(packet), common::BindOnce(&impl::on_read_default_link_policy_settings_complete, common::Unretained(this)), handler_); } void write_default_link_policy_settings(uint16_t default_link_policy_settings) { std::unique_ptr<WriteDefaultLinkPolicySettingsBuilder> packet = WriteDefaultLinkPolicySettingsBuilder::Create(default_link_policy_settings); hci_layer_->EnqueueCommand( std::move(packet), BindOnce(&AclManager::impl::check_command_complete<WriteDefaultLinkPolicySettingsCompleteView>, common::Unretained(this)), handler_); } void accept_connection(Address address) { auto role = AcceptConnectionRequestRole::BECOME_MASTER; // We prefer to be master hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role), Loading Loading @@ -986,6 +1101,13 @@ struct AclManager::impl { std::move(packet), common::BindOnce(&impl::on_read_link_quality_complete, common::Unretained(this)), handler_); } void handle_afh_channel_map(uint16_t handle) { std::unique_ptr<ReadAfhChannelMapBuilder> packet = ReadAfhChannelMapBuilder::Create(handle); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_read_afh_channel_map_complete, common::Unretained(this)), handler_); } void handle_read_rssi(uint16_t handle) { std::unique_ptr<ReadRssiBuilder> packet = ReadRssiBuilder::Create(handle); hci_layer_->EnqueueCommand(std::move(packet), Loading Loading @@ -1069,6 +1191,13 @@ struct AclManager::impl { le_client_handler_ = handler; } void handle_register_acl_manager_callbacks(AclManagerCallbacks* callbacks, os::Handler* handler) { ASSERT(acl_manager_client_callbacks_ == nullptr); ASSERT(acl_manager_client_handler_ == nullptr); acl_manager_client_callbacks_ = callbacks; acl_manager_client_handler_ = handler; } acl_connection& check_and_get_connection(uint16_t handle) { auto connection = acl_connections_.find(handle); ASSERT(connection != acl_connections_.end()); Loading Loading @@ -1347,6 +1476,16 @@ struct AclManager::impl { return true; } bool ReadAfhChannelMap(uint16_t handle) { auto& connection = check_and_get_connection(handle); if (connection.is_disconnected_) { LOG_INFO("Already disconnected"); return false; } handler_->Post(BindOnce(&impl::handle_afh_channel_map, common::Unretained(this), handle)); return true; } bool ReadRssi(uint16_t handle) { auto& connection = check_and_get_connection(handle); if (connection.is_disconnected_) { Loading Loading @@ -1390,6 +1529,8 @@ struct AclManager::impl { os::Handler* client_handler_ = nullptr; LeConnectionCallbacks* le_client_callbacks_ = nullptr; os::Handler* le_client_handler_ = nullptr; AclManagerCallbacks* acl_manager_client_callbacks_ = nullptr; os::Handler* acl_manager_client_handler_ = nullptr; common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* hci_queue_end_ = nullptr; std::map<uint16_t, AclManager::acl_connection> acl_connections_; std::set<Address> connecting_; Loading Loading @@ -1509,6 +1650,10 @@ bool AclConnection::ReadLinkQuality() { return manager_->pimpl_->ReadLinkQuality(handle_); } bool AclConnection::ReadAfhChannelMap() { return manager_->pimpl_->ReadAfhChannelMap(handle_); } bool AclConnection::ReadRssi() { return manager_->pimpl_->ReadRssi(handle_); } Loading @@ -1535,6 +1680,12 @@ void AclManager::RegisterLeCallbacks(LeConnectionCallbacks* callbacks, os::Handl common::Unretained(callbacks), common::Unretained(handler))); } void AclManager::RegisterAclManagerCallbacks(AclManagerCallbacks* callbacks, os::Handler* handler) { ASSERT(callbacks != nullptr && handler != nullptr); GetHandler()->Post(common::BindOnce(&impl::handle_register_acl_manager_callbacks, common::Unretained(pimpl_.get()), common::Unretained(callbacks), common::Unretained(handler))); } void AclManager::CreateConnection(Address address) { GetHandler()->Post(common::BindOnce(&impl::create_connection, common::Unretained(pimpl_.get()), address)); } Loading @@ -1548,6 +1699,23 @@ void AclManager::CancelConnect(Address address) { GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address)); } void AclManager::MasterLinkKey(KeyFlag key_flag) { GetHandler()->Post(BindOnce(&impl::master_link_key, common::Unretained(pimpl_.get()), key_flag)); } void AclManager::SwitchRole(Address address, Role role) { GetHandler()->Post(BindOnce(&impl::switch_role, common::Unretained(pimpl_.get()), address, role)); } void AclManager::ReadDefaultLinkPolicySettings() { GetHandler()->Post(BindOnce(&impl::read_default_link_policy_settings, common::Unretained(pimpl_.get()))); } void AclManager::WriteDefaultLinkPolicySettings(uint16_t default_link_policy_settings) { GetHandler()->Post(BindOnce(&impl::write_default_link_policy_settings, common::Unretained(pimpl_.get()), default_link_policy_settings)); } void AclManager::ListDependencies(ModuleList* list) { list->add<HciLayer>(); list->add<Controller>(); Loading system/gd/hci/acl_manager.h +23 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class ConnectionManagementCallbacks { virtual void OnReadFailedContactCounterComplete(uint16_t failed_contact_counter) = 0; // Invoked when controller sends Command Complete event for Read Link Quality command with Success error code virtual void OnReadLinkQualityComplete(uint8_t link_quality) = 0; // Invoked when controller sends Command Complete event for Read AFH Channel Map command with Success error code virtual void OnReadAfhChannelMapComplete(AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map) = 0; // Invoked when controller sends Command Complete event for Read RSSI command with Success error code virtual void OnReadRssiComplete(uint8_t rssi) = 0; // Invoked when controller sends Command Complete event for Read Clock command with Success error code Loading Loading @@ -124,6 +126,7 @@ class AclConnection { virtual bool ReadFailedContactCounter(); virtual bool ResetFailedContactCounter(); virtual bool ReadLinkQuality(); virtual bool ReadAfhChannelMap(); virtual bool ReadRssi(); virtual bool ReadClock(WhichClock which_clock); Loading Loading @@ -160,6 +163,18 @@ class LeConnectionCallbacks { virtual void OnLeConnectFail(Address, AddressType, ErrorCode reason) = 0; }; class AclManagerCallbacks { public: virtual ~AclManagerCallbacks() = default; // Invoked when controller sends Master Link Key Complete event with Success error code virtual void OnMasterLinkKeyComplete(uint16_t connection_handle, KeyFlag key_flag) = 0; // Invoked when controller sends Role Change event with Success error code virtual void OnRoleChange(Address bd_addr, Role new_role) = 0; // Invoked when controller sends Command Complete event for Read Default Link Policy Settings command with Success // error code virtual void OnReadDefaultLinkPolicySettingsComplete(uint16_t default_link_policy_settings) = 0; }; class AclManager : public Module { public: AclManager(); Loading @@ -176,6 +191,9 @@ class AclManager : public Module { // Should register only once when user module starts. virtual void RegisterLeCallbacks(LeConnectionCallbacks* callbacks, os::Handler* handler); // Should register only once when user module starts. virtual void RegisterAclManagerCallbacks(AclManagerCallbacks* callbacks, os::Handler* handler); // Generates OnConnectSuccess if connected, or OnConnectFail otherwise virtual void CreateConnection(Address address); Loading @@ -186,6 +204,11 @@ class AclManager : public Module { // successfully cancelled and already connected virtual void CancelConnect(Address address); virtual void MasterLinkKey(KeyFlag key_flag); virtual void SwitchRole(Address address, Role role); virtual void ReadDefaultLinkPolicySettings(); virtual void WriteDefaultLinkPolicySettings(uint16_t default_link_policy_settings); static const ModuleFactory Factory; protected: Loading system/gd/hci/acl_manager_test.cc +71 −2 Original line number Diff line number Diff line Loading @@ -125,8 +125,7 @@ class TestHciLayer : public HciLayer { std::chrono::milliseconds time = std::chrono::milliseconds(3000); ASSERT(not_empty_.wait_for(lock, time) != std::cv_status::timeout); auto packet = GetLastCommand(); auto packet_view = GetPacketView(std::move(packet)); auto packet_view = GetPacketView(GetLastCommand()); CommandPacketView command_packet_view = CommandPacketView::Create(packet_view); ConnectionManagementCommandView command = ConnectionManagementCommandView::Create(command_packet_view); ASSERT(command.IsValid()); Loading Loading @@ -280,6 +279,13 @@ class AclManagerNoCallbacksTest : public ::testing::Test { std::list<std::shared_ptr<AclConnection>> connections_; std::unique_ptr<std::promise<void>> connection_promise_; } mock_connection_callback_; class MockAclManagerCallbacks : public AclManagerCallbacks { public: MOCK_METHOD2(OnMasterLinkKeyComplete, void(uint16_t connection_handle, KeyFlag key_flag)); MOCK_METHOD2(OnRoleChange, void(Address bd_addr, Role new_role)); MOCK_METHOD1(OnReadDefaultLinkPolicySettingsComplete, void(uint16_t default_link_policy_settings)); } mock_acl_manager_callbacks_; }; class AclManagerTest : public AclManagerNoCallbacksTest { Loading @@ -287,6 +293,7 @@ class AclManagerTest : public AclManagerNoCallbacksTest { void SetUp() override { AclManagerNoCallbacksTest::SetUp(); acl_manager_->RegisterCallbacks(&mock_connection_callback_, client_handler_); acl_manager_->RegisterAclManagerCallbacks(&mock_acl_manager_callbacks_, client_handler_); } }; Loading Loading @@ -342,6 +349,7 @@ class AclManagerWithConnectionTest : public AclManagerTest { MOCK_METHOD1(OnReadLinkSupervisionTimeoutComplete, void(uint16_t link_supervision_timeout)); MOCK_METHOD1(OnReadFailedContactCounterComplete, void(uint16_t failed_contact_counter)); MOCK_METHOD1(OnReadLinkQualityComplete, void(uint8_t link_quality)); MOCK_METHOD2(OnReadAfhChannelMapComplete, void(AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map)); MOCK_METHOD1(OnReadRssiComplete, void(uint8_t rssi)); MOCK_METHOD2(OnReadClockComplete, void(uint32_t clock, uint16_t accuracy)); } mock_connection_management_callbacks_; Loading Loading @@ -579,6 +587,53 @@ TEST_F(AclManagerTest, acl_send_data_credits) { connection->Disconnect(DisconnectReason::AUTHENTICATION_FAILURE); } TEST_F(AclManagerWithConnectionTest, send_master_link_key) { acl_manager_->MasterLinkKey(KeyFlag::TEMPORARY); auto packet = test_hci_layer_->GetCommandPacket(OpCode::MASTER_LINK_KEY); auto command_view = MasterLinkKeyView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_EQ(command_view.GetKeyFlag(), KeyFlag::TEMPORARY); EXPECT_CALL(mock_acl_manager_callbacks_, OnMasterLinkKeyComplete(0x123, KeyFlag::TEMPORARY)); test_hci_layer_->IncomingEvent(MasterLinkKeyCompleteBuilder::Create(ErrorCode::SUCCESS, 0x123, KeyFlag::TEMPORARY)); } TEST_F(AclManagerWithConnectionTest, send_switch_role) { acl_manager_->SwitchRole(connection_->GetAddress(), Role::SLAVE); auto packet = test_hci_layer_->GetCommandPacket(OpCode::SWITCH_ROLE); auto command_view = SwitchRoleView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_EQ(command_view.GetBdAddr(), connection_->GetAddress()); EXPECT_EQ(command_view.GetRole(), Role::SLAVE); EXPECT_CALL(mock_acl_manager_callbacks_, OnRoleChange(connection_->GetAddress(), Role::SLAVE)); test_hci_layer_->IncomingEvent(RoleChangeBuilder::Create(ErrorCode::SUCCESS, connection_->GetAddress(), Role::SLAVE)); } TEST_F(AclManagerWithConnectionTest, send_read_default_link_policy_settings) { acl_manager_->ReadDefaultLinkPolicySettings(); auto packet = test_hci_layer_->GetCommandPacket(OpCode::READ_DEFAULT_LINK_POLICY_SETTINGS); auto command_view = ReadDefaultLinkPolicySettingsView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_CALL(mock_acl_manager_callbacks_, OnReadDefaultLinkPolicySettingsComplete(0x07)); uint8_t num_packets = 1; test_hci_layer_->IncomingEvent( ReadDefaultLinkPolicySettingsCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, 0x07)); } TEST_F(AclManagerWithConnectionTest, send_write_default_link_policy_settings) { acl_manager_->WriteDefaultLinkPolicySettings(0x05); auto packet = test_hci_layer_->GetCommandPacket(OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS); auto command_view = WriteDefaultLinkPolicySettingsView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_EQ(command_view.GetDefaultLinkPolicySettings(), 0x05); uint8_t num_packets = 1; test_hci_layer_->IncomingEvent( WriteDefaultLinkPolicySettingsCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS)); } TEST_F(AclManagerWithConnectionTest, send_change_connection_packet_type) { connection_->ChangeConnectionPacketType(0xEE1C); auto packet = test_hci_layer_->GetCommandPacket(OpCode::CHANGE_CONNECTION_PACKET_TYPE); Loading Loading @@ -861,6 +916,20 @@ TEST_F(AclManagerWithConnectionTest, send_read_link_quality) { ReadLinkQualityCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, handle_, 0xa9)); } TEST_F(AclManagerWithConnectionTest, send_read_afh_channel_map) { connection_->ReadAfhChannelMap(); auto packet = test_hci_layer_->GetCommandPacket(OpCode::READ_AFH_CHANNEL_MAP); auto command_view = ReadAfhChannelMapView::Create(packet); ASSERT(command_view.IsValid()); std::array<uint8_t, 10> afh_channel_map = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; EXPECT_CALL(mock_connection_management_callbacks_, OnReadAfhChannelMapComplete(AfhMode::AFH_ENABLED, afh_channel_map)); uint8_t num_packets = 1; test_hci_layer_->IncomingEvent(ReadAfhChannelMapCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, handle_, AfhMode::AFH_ENABLED, afh_channel_map)); } TEST_F(AclManagerWithConnectionTest, send_read_rssi) { connection_->ReadRssi(); auto packet = test_hci_layer_->GetCommandPacket(OpCode::READ_RSSI); Loading system/gd/hci/cert/cert.cc +5 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ class AclManagerCertService : public AclManagerCert::Service { hci_layer_->RegisterEventHandler(EventCode::QOS_SETUP_COMPLETE, Bind(&AclManagerCertService::on_qos_setup_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ROLE_CHANGE, Bind(&AclManagerCertService::on_role_change, common::Unretained(this)), handler_); controller_->RegisterCompletedAclPacketsCallback(common::Bind([](uint16_t, uint16_t) { /* TODO check */ }), handler_); Loading Loading @@ -152,6 +154,9 @@ class AclManagerCertService : public AclManagerCert::Service { void on_qos_setup_complete(EventPacketView packet) { /*TODO*/ } void on_role_change(EventPacketView packet) { /*TODO*/ } using EventStream = ::bluetooth::grpc::GrpcEventStream<AclData, AclPacketView>; ::grpc::Status SetPageScanMode(::grpc::ServerContext* context, const ::bluetooth::hci::cert::PageScanMode* request, Loading system/gd/hci/facade.cc +25 −1 Original line number Diff line number Diff line Loading @@ -43,12 +43,14 @@ namespace hci { class AclManagerFacadeService : public AclManagerFacade::Service, public ::bluetooth::hci::ConnectionCallbacks, public ::bluetooth::hci::ConnectionManagementCallbacks { public ::bluetooth::hci::ConnectionManagementCallbacks, public ::bluetooth::hci::AclManagerCallbacks { public: AclManagerFacadeService(AclManager* acl_manager, Controller* controller, HciLayer* hci_layer, ::bluetooth::os::Handler* facade_handler) : acl_manager_(acl_manager), controller_(controller), hci_layer_(hci_layer), facade_handler_(facade_handler) { acl_manager_->RegisterCallbacks(this, facade_handler_); acl_manager_->RegisterAclManagerCallbacks(this, facade_handler_); } using EventStream = ::bluetooth::grpc::GrpcEventStream<AclData, AclPacketView>; Loading Loading @@ -202,6 +204,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, connection->second->ReadFailedContactCounter(); connection->second->ResetFailedContactCounter(); connection->second->ReadLinkQuality(); connection->second->ReadAfhChannelMap(); connection->second->ReadRssi(); connection->second->ReadClock(WhichClock::LOCAL); connection->second->ReadClock(WhichClock::PICONET); Loading @@ -217,6 +220,11 @@ class AclManagerFacadeService : public AclManagerFacade::Service, connection->second->FlowSpecification(FlowDirection::OUTGOING_FLOW, ServiceType::BEST_EFFORT, 0x1234, 0x1233, 0x1232, 0x1231); connection->second->Flush(); acl_manager_->MasterLinkKey(KeyFlag::TEMPORARY); acl_manager_->SwitchRole(peer, Role::MASTER); acl_manager_->WriteDefaultLinkPolicySettings(0x07); acl_manager_->ReadDefaultLinkPolicySettings(); return ::grpc::Status::OK; } } Loading Loading @@ -249,6 +257,18 @@ class AclManagerFacadeService : public AclManagerFacade::Service, connection_complete_stream_.OnIncomingEvent(shared_connection); } void OnMasterLinkKeyComplete(uint16_t connection_handle, KeyFlag key_flag) override { LOG_DEBUG("OnMasterLinkKeyComplete connection_handle:%d", connection_handle); } void OnRoleChange(Address bd_addr, Role new_role) override { LOG_DEBUG("OnRoleChange bd_addr:%s, new_role:%d", bd_addr.ToString().c_str(), (uint8_t)new_role); } void OnReadDefaultLinkPolicySettingsComplete(uint16_t default_link_policy_settings) override { LOG_DEBUG("OnReadDefaultLinkPolicySettingsComplete default_link_policy_settings:%d", default_link_policy_settings); } void on_disconnect(std::string address, ErrorCode code) { acl_connections_.erase(address); DisconnectionEvent event; Loading Loading @@ -341,6 +361,10 @@ class AclManagerFacadeService : public AclManagerFacade::Service, LOG_DEBUG("OnReadLinkQualityComplete link_quality:%d", link_quality); } void OnReadAfhChannelMapComplete(AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map) { LOG_DEBUG("OnReadAfhChannelMapComplete afh_mode:%d", (uint8_t)afh_mode); } void OnReadRssiComplete(uint8_t rssi) override { LOG_DEBUG("OnReadRssiComplete rssi:%d", rssi); } Loading Loading
system/gd/hci/acl_manager.cc +168 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,8 @@ struct AclManager::impl { hci_layer_->RegisterEventHandler(EventCode::CONNECTION_PACKET_TYPE_CHANGED, Bind(&impl::on_connection_packet_type_changed, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::MASTER_LINK_KEY_COMPLETE, Bind(&impl::on_master_link_key_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::AUTHENTICATION_COMPLETE, Bind(&impl::on_authentication_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ENCRYPTION_CHANGE, Loading @@ -94,6 +96,8 @@ struct AclManager::impl { handler_); hci_layer_->RegisterEventHandler(EventCode::QOS_SETUP_COMPLETE, Bind(&impl::on_qos_setup_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ROLE_CHANGE, Bind(&impl::on_role_change, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::FLOW_SPECIFICATION_COMPLETE, Bind(&impl::on_flow_specification_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::FLUSH_OCCURRED, Loading Loading @@ -366,6 +370,26 @@ struct AclManager::impl { } } void on_master_link_key_complete(EventPacketView packet) { MasterLinkKeyCompleteView complete_view = MasterLinkKeyCompleteView::Create(packet); if (!complete_view.IsValid()) { LOG_ERROR("Received on_master_link_key_complete with invalid packet"); return; } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) { auto status = complete_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_master_link_key_complete with error code %s", error_code.c_str()); return; } if (acl_manager_client_callbacks_ != nullptr) { uint16_t connection_handle = complete_view.GetConnectionHandle(); KeyFlag key_flag = complete_view.GetKeyFlag(); acl_manager_client_handler_->Post(common::BindOnce(&AclManagerCallbacks::OnMasterLinkKeyComplete, common::Unretained(acl_manager_client_callbacks_), connection_handle, key_flag)); } } void on_authentication_complete(EventPacketView packet) { AuthenticationCompleteView authentication_complete = AuthenticationCompleteView::Create(packet); if (!authentication_complete.IsValid()) { Loading Loading @@ -496,6 +520,25 @@ struct AclManager::impl { } } void on_role_change(EventPacketView packet) { RoleChangeView role_change_view = RoleChangeView::Create(packet); if (!role_change_view.IsValid()) { LOG_ERROR("Received on_role_change with invalid packet"); return; } else if (role_change_view.GetStatus() != ErrorCode::SUCCESS) { auto status = role_change_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_role_change with error code %s", error_code.c_str()); return; } if (acl_manager_client_callbacks_ != nullptr) { Address bd_addr = role_change_view.GetBdAddr(); Role new_role = role_change_view.GetNewRole(); acl_manager_client_handler_->Post(common::BindOnce( &AclManagerCallbacks::OnRoleChange, common::Unretained(acl_manager_client_callbacks_), bd_addr, new_role)); } } void on_flow_specification_complete(EventPacketView packet) { FlowSpecificationCompleteView complete_view = FlowSpecificationCompleteView::Create(packet); if (!complete_view.IsValid()) { Loading Loading @@ -580,6 +623,25 @@ struct AclManager::impl { } } void on_read_default_link_policy_settings_complete(CommandCompleteView view) { auto complete_view = ReadDefaultLinkPolicySettingsCompleteView::Create(view); if (!complete_view.IsValid()) { LOG_ERROR("Received on_read_link_policy_settings_complete with invalid packet"); return; } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) { auto status = complete_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_read_link_policy_settings_complete with error code %s", error_code.c_str()); return; } if (acl_manager_client_callbacks_ != nullptr) { uint16_t default_link_policy_settings = complete_view.GetDefaultLinkPolicySettings(); acl_manager_client_handler_->Post(common::BindOnce(&AclManagerCallbacks::OnReadDefaultLinkPolicySettingsComplete, common::Unretained(acl_manager_client_callbacks_), default_link_policy_settings)); } } void on_read_automatic_flush_timeout_complete(CommandCompleteView view) { auto complete_view = ReadAutomaticFlushTimeoutCompleteView::Create(view); if (!complete_view.IsValid()) { Loading Loading @@ -685,6 +747,28 @@ struct AclManager::impl { } } void on_read_afh_channel_map_complete(CommandCompleteView view) { auto complete_view = ReadAfhChannelMapCompleteView::Create(view); if (!complete_view.IsValid()) { LOG_ERROR("Received on_read_afh_channel_map_complete with invalid packet"); return; } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) { auto status = complete_view.GetStatus(); std::string error_code = ErrorCodeText(status); LOG_ERROR("Received on_read_afh_channel_map_complete with error code %s", error_code.c_str()); return; } uint16_t handle = complete_view.GetConnectionHandle(); auto& acl_connection = acl_connections_.find(handle)->second; if (acl_connection.command_complete_handler_ != nullptr) { AfhMode afh_mode = complete_view.GetAfhMode(); std::array<uint8_t, 10> afh_channel_map = complete_view.GetAfhChannelMap(); acl_connection.command_complete_handler_->Post( common::BindOnce(&ConnectionManagementCallbacks::OnReadAfhChannelMapComplete, common::Unretained(acl_connection.command_complete_callbacks_), afh_mode, afh_channel_map)); } } void on_read_rssi_complete(CommandCompleteView view) { auto complete_view = ReadRssiCompleteView::Create(view); if (!complete_view.IsValid()) { Loading Loading @@ -788,6 +872,37 @@ struct AclManager::impl { handler_); } void master_link_key(KeyFlag key_flag) { std::unique_ptr<MasterLinkKeyBuilder> packet = MasterLinkKeyBuilder::Create(key_flag); hci_layer_->EnqueueCommand( std::move(packet), common::BindOnce(&impl::check_command_status<MasterLinkKeyStatusView>, common::Unretained(this)), handler_); } void switch_role(Address address, Role role) { std::unique_ptr<SwitchRoleBuilder> packet = SwitchRoleBuilder::Create(address, role); hci_layer_->EnqueueCommand( std::move(packet), common::BindOnce(&impl::check_command_status<SwitchRoleStatusView>, common::Unretained(this)), handler_); } void read_default_link_policy_settings() { std::unique_ptr<ReadDefaultLinkPolicySettingsBuilder> packet = ReadDefaultLinkPolicySettingsBuilder::Create(); hci_layer_->EnqueueCommand( std::move(packet), common::BindOnce(&impl::on_read_default_link_policy_settings_complete, common::Unretained(this)), handler_); } void write_default_link_policy_settings(uint16_t default_link_policy_settings) { std::unique_ptr<WriteDefaultLinkPolicySettingsBuilder> packet = WriteDefaultLinkPolicySettingsBuilder::Create(default_link_policy_settings); hci_layer_->EnqueueCommand( std::move(packet), BindOnce(&AclManager::impl::check_command_complete<WriteDefaultLinkPolicySettingsCompleteView>, common::Unretained(this)), handler_); } void accept_connection(Address address) { auto role = AcceptConnectionRequestRole::BECOME_MASTER; // We prefer to be master hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role), Loading Loading @@ -986,6 +1101,13 @@ struct AclManager::impl { std::move(packet), common::BindOnce(&impl::on_read_link_quality_complete, common::Unretained(this)), handler_); } void handle_afh_channel_map(uint16_t handle) { std::unique_ptr<ReadAfhChannelMapBuilder> packet = ReadAfhChannelMapBuilder::Create(handle); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_read_afh_channel_map_complete, common::Unretained(this)), handler_); } void handle_read_rssi(uint16_t handle) { std::unique_ptr<ReadRssiBuilder> packet = ReadRssiBuilder::Create(handle); hci_layer_->EnqueueCommand(std::move(packet), Loading Loading @@ -1069,6 +1191,13 @@ struct AclManager::impl { le_client_handler_ = handler; } void handle_register_acl_manager_callbacks(AclManagerCallbacks* callbacks, os::Handler* handler) { ASSERT(acl_manager_client_callbacks_ == nullptr); ASSERT(acl_manager_client_handler_ == nullptr); acl_manager_client_callbacks_ = callbacks; acl_manager_client_handler_ = handler; } acl_connection& check_and_get_connection(uint16_t handle) { auto connection = acl_connections_.find(handle); ASSERT(connection != acl_connections_.end()); Loading Loading @@ -1347,6 +1476,16 @@ struct AclManager::impl { return true; } bool ReadAfhChannelMap(uint16_t handle) { auto& connection = check_and_get_connection(handle); if (connection.is_disconnected_) { LOG_INFO("Already disconnected"); return false; } handler_->Post(BindOnce(&impl::handle_afh_channel_map, common::Unretained(this), handle)); return true; } bool ReadRssi(uint16_t handle) { auto& connection = check_and_get_connection(handle); if (connection.is_disconnected_) { Loading Loading @@ -1390,6 +1529,8 @@ struct AclManager::impl { os::Handler* client_handler_ = nullptr; LeConnectionCallbacks* le_client_callbacks_ = nullptr; os::Handler* le_client_handler_ = nullptr; AclManagerCallbacks* acl_manager_client_callbacks_ = nullptr; os::Handler* acl_manager_client_handler_ = nullptr; common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* hci_queue_end_ = nullptr; std::map<uint16_t, AclManager::acl_connection> acl_connections_; std::set<Address> connecting_; Loading Loading @@ -1509,6 +1650,10 @@ bool AclConnection::ReadLinkQuality() { return manager_->pimpl_->ReadLinkQuality(handle_); } bool AclConnection::ReadAfhChannelMap() { return manager_->pimpl_->ReadAfhChannelMap(handle_); } bool AclConnection::ReadRssi() { return manager_->pimpl_->ReadRssi(handle_); } Loading @@ -1535,6 +1680,12 @@ void AclManager::RegisterLeCallbacks(LeConnectionCallbacks* callbacks, os::Handl common::Unretained(callbacks), common::Unretained(handler))); } void AclManager::RegisterAclManagerCallbacks(AclManagerCallbacks* callbacks, os::Handler* handler) { ASSERT(callbacks != nullptr && handler != nullptr); GetHandler()->Post(common::BindOnce(&impl::handle_register_acl_manager_callbacks, common::Unretained(pimpl_.get()), common::Unretained(callbacks), common::Unretained(handler))); } void AclManager::CreateConnection(Address address) { GetHandler()->Post(common::BindOnce(&impl::create_connection, common::Unretained(pimpl_.get()), address)); } Loading @@ -1548,6 +1699,23 @@ void AclManager::CancelConnect(Address address) { GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address)); } void AclManager::MasterLinkKey(KeyFlag key_flag) { GetHandler()->Post(BindOnce(&impl::master_link_key, common::Unretained(pimpl_.get()), key_flag)); } void AclManager::SwitchRole(Address address, Role role) { GetHandler()->Post(BindOnce(&impl::switch_role, common::Unretained(pimpl_.get()), address, role)); } void AclManager::ReadDefaultLinkPolicySettings() { GetHandler()->Post(BindOnce(&impl::read_default_link_policy_settings, common::Unretained(pimpl_.get()))); } void AclManager::WriteDefaultLinkPolicySettings(uint16_t default_link_policy_settings) { GetHandler()->Post(BindOnce(&impl::write_default_link_policy_settings, common::Unretained(pimpl_.get()), default_link_policy_settings)); } void AclManager::ListDependencies(ModuleList* list) { list->add<HciLayer>(); list->add<Controller>(); Loading
system/gd/hci/acl_manager.h +23 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class ConnectionManagementCallbacks { virtual void OnReadFailedContactCounterComplete(uint16_t failed_contact_counter) = 0; // Invoked when controller sends Command Complete event for Read Link Quality command with Success error code virtual void OnReadLinkQualityComplete(uint8_t link_quality) = 0; // Invoked when controller sends Command Complete event for Read AFH Channel Map command with Success error code virtual void OnReadAfhChannelMapComplete(AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map) = 0; // Invoked when controller sends Command Complete event for Read RSSI command with Success error code virtual void OnReadRssiComplete(uint8_t rssi) = 0; // Invoked when controller sends Command Complete event for Read Clock command with Success error code Loading Loading @@ -124,6 +126,7 @@ class AclConnection { virtual bool ReadFailedContactCounter(); virtual bool ResetFailedContactCounter(); virtual bool ReadLinkQuality(); virtual bool ReadAfhChannelMap(); virtual bool ReadRssi(); virtual bool ReadClock(WhichClock which_clock); Loading Loading @@ -160,6 +163,18 @@ class LeConnectionCallbacks { virtual void OnLeConnectFail(Address, AddressType, ErrorCode reason) = 0; }; class AclManagerCallbacks { public: virtual ~AclManagerCallbacks() = default; // Invoked when controller sends Master Link Key Complete event with Success error code virtual void OnMasterLinkKeyComplete(uint16_t connection_handle, KeyFlag key_flag) = 0; // Invoked when controller sends Role Change event with Success error code virtual void OnRoleChange(Address bd_addr, Role new_role) = 0; // Invoked when controller sends Command Complete event for Read Default Link Policy Settings command with Success // error code virtual void OnReadDefaultLinkPolicySettingsComplete(uint16_t default_link_policy_settings) = 0; }; class AclManager : public Module { public: AclManager(); Loading @@ -176,6 +191,9 @@ class AclManager : public Module { // Should register only once when user module starts. virtual void RegisterLeCallbacks(LeConnectionCallbacks* callbacks, os::Handler* handler); // Should register only once when user module starts. virtual void RegisterAclManagerCallbacks(AclManagerCallbacks* callbacks, os::Handler* handler); // Generates OnConnectSuccess if connected, or OnConnectFail otherwise virtual void CreateConnection(Address address); Loading @@ -186,6 +204,11 @@ class AclManager : public Module { // successfully cancelled and already connected virtual void CancelConnect(Address address); virtual void MasterLinkKey(KeyFlag key_flag); virtual void SwitchRole(Address address, Role role); virtual void ReadDefaultLinkPolicySettings(); virtual void WriteDefaultLinkPolicySettings(uint16_t default_link_policy_settings); static const ModuleFactory Factory; protected: Loading
system/gd/hci/acl_manager_test.cc +71 −2 Original line number Diff line number Diff line Loading @@ -125,8 +125,7 @@ class TestHciLayer : public HciLayer { std::chrono::milliseconds time = std::chrono::milliseconds(3000); ASSERT(not_empty_.wait_for(lock, time) != std::cv_status::timeout); auto packet = GetLastCommand(); auto packet_view = GetPacketView(std::move(packet)); auto packet_view = GetPacketView(GetLastCommand()); CommandPacketView command_packet_view = CommandPacketView::Create(packet_view); ConnectionManagementCommandView command = ConnectionManagementCommandView::Create(command_packet_view); ASSERT(command.IsValid()); Loading Loading @@ -280,6 +279,13 @@ class AclManagerNoCallbacksTest : public ::testing::Test { std::list<std::shared_ptr<AclConnection>> connections_; std::unique_ptr<std::promise<void>> connection_promise_; } mock_connection_callback_; class MockAclManagerCallbacks : public AclManagerCallbacks { public: MOCK_METHOD2(OnMasterLinkKeyComplete, void(uint16_t connection_handle, KeyFlag key_flag)); MOCK_METHOD2(OnRoleChange, void(Address bd_addr, Role new_role)); MOCK_METHOD1(OnReadDefaultLinkPolicySettingsComplete, void(uint16_t default_link_policy_settings)); } mock_acl_manager_callbacks_; }; class AclManagerTest : public AclManagerNoCallbacksTest { Loading @@ -287,6 +293,7 @@ class AclManagerTest : public AclManagerNoCallbacksTest { void SetUp() override { AclManagerNoCallbacksTest::SetUp(); acl_manager_->RegisterCallbacks(&mock_connection_callback_, client_handler_); acl_manager_->RegisterAclManagerCallbacks(&mock_acl_manager_callbacks_, client_handler_); } }; Loading Loading @@ -342,6 +349,7 @@ class AclManagerWithConnectionTest : public AclManagerTest { MOCK_METHOD1(OnReadLinkSupervisionTimeoutComplete, void(uint16_t link_supervision_timeout)); MOCK_METHOD1(OnReadFailedContactCounterComplete, void(uint16_t failed_contact_counter)); MOCK_METHOD1(OnReadLinkQualityComplete, void(uint8_t link_quality)); MOCK_METHOD2(OnReadAfhChannelMapComplete, void(AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map)); MOCK_METHOD1(OnReadRssiComplete, void(uint8_t rssi)); MOCK_METHOD2(OnReadClockComplete, void(uint32_t clock, uint16_t accuracy)); } mock_connection_management_callbacks_; Loading Loading @@ -579,6 +587,53 @@ TEST_F(AclManagerTest, acl_send_data_credits) { connection->Disconnect(DisconnectReason::AUTHENTICATION_FAILURE); } TEST_F(AclManagerWithConnectionTest, send_master_link_key) { acl_manager_->MasterLinkKey(KeyFlag::TEMPORARY); auto packet = test_hci_layer_->GetCommandPacket(OpCode::MASTER_LINK_KEY); auto command_view = MasterLinkKeyView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_EQ(command_view.GetKeyFlag(), KeyFlag::TEMPORARY); EXPECT_CALL(mock_acl_manager_callbacks_, OnMasterLinkKeyComplete(0x123, KeyFlag::TEMPORARY)); test_hci_layer_->IncomingEvent(MasterLinkKeyCompleteBuilder::Create(ErrorCode::SUCCESS, 0x123, KeyFlag::TEMPORARY)); } TEST_F(AclManagerWithConnectionTest, send_switch_role) { acl_manager_->SwitchRole(connection_->GetAddress(), Role::SLAVE); auto packet = test_hci_layer_->GetCommandPacket(OpCode::SWITCH_ROLE); auto command_view = SwitchRoleView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_EQ(command_view.GetBdAddr(), connection_->GetAddress()); EXPECT_EQ(command_view.GetRole(), Role::SLAVE); EXPECT_CALL(mock_acl_manager_callbacks_, OnRoleChange(connection_->GetAddress(), Role::SLAVE)); test_hci_layer_->IncomingEvent(RoleChangeBuilder::Create(ErrorCode::SUCCESS, connection_->GetAddress(), Role::SLAVE)); } TEST_F(AclManagerWithConnectionTest, send_read_default_link_policy_settings) { acl_manager_->ReadDefaultLinkPolicySettings(); auto packet = test_hci_layer_->GetCommandPacket(OpCode::READ_DEFAULT_LINK_POLICY_SETTINGS); auto command_view = ReadDefaultLinkPolicySettingsView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_CALL(mock_acl_manager_callbacks_, OnReadDefaultLinkPolicySettingsComplete(0x07)); uint8_t num_packets = 1; test_hci_layer_->IncomingEvent( ReadDefaultLinkPolicySettingsCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, 0x07)); } TEST_F(AclManagerWithConnectionTest, send_write_default_link_policy_settings) { acl_manager_->WriteDefaultLinkPolicySettings(0x05); auto packet = test_hci_layer_->GetCommandPacket(OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS); auto command_view = WriteDefaultLinkPolicySettingsView::Create(packet); ASSERT(command_view.IsValid()); EXPECT_EQ(command_view.GetDefaultLinkPolicySettings(), 0x05); uint8_t num_packets = 1; test_hci_layer_->IncomingEvent( WriteDefaultLinkPolicySettingsCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS)); } TEST_F(AclManagerWithConnectionTest, send_change_connection_packet_type) { connection_->ChangeConnectionPacketType(0xEE1C); auto packet = test_hci_layer_->GetCommandPacket(OpCode::CHANGE_CONNECTION_PACKET_TYPE); Loading Loading @@ -861,6 +916,20 @@ TEST_F(AclManagerWithConnectionTest, send_read_link_quality) { ReadLinkQualityCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, handle_, 0xa9)); } TEST_F(AclManagerWithConnectionTest, send_read_afh_channel_map) { connection_->ReadAfhChannelMap(); auto packet = test_hci_layer_->GetCommandPacket(OpCode::READ_AFH_CHANNEL_MAP); auto command_view = ReadAfhChannelMapView::Create(packet); ASSERT(command_view.IsValid()); std::array<uint8_t, 10> afh_channel_map = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; EXPECT_CALL(mock_connection_management_callbacks_, OnReadAfhChannelMapComplete(AfhMode::AFH_ENABLED, afh_channel_map)); uint8_t num_packets = 1; test_hci_layer_->IncomingEvent(ReadAfhChannelMapCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, handle_, AfhMode::AFH_ENABLED, afh_channel_map)); } TEST_F(AclManagerWithConnectionTest, send_read_rssi) { connection_->ReadRssi(); auto packet = test_hci_layer_->GetCommandPacket(OpCode::READ_RSSI); Loading
system/gd/hci/cert/cert.cc +5 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ class AclManagerCertService : public AclManagerCert::Service { hci_layer_->RegisterEventHandler(EventCode::QOS_SETUP_COMPLETE, Bind(&AclManagerCertService::on_qos_setup_complete, common::Unretained(this)), handler_); hci_layer_->RegisterEventHandler(EventCode::ROLE_CHANGE, Bind(&AclManagerCertService::on_role_change, common::Unretained(this)), handler_); controller_->RegisterCompletedAclPacketsCallback(common::Bind([](uint16_t, uint16_t) { /* TODO check */ }), handler_); Loading Loading @@ -152,6 +154,9 @@ class AclManagerCertService : public AclManagerCert::Service { void on_qos_setup_complete(EventPacketView packet) { /*TODO*/ } void on_role_change(EventPacketView packet) { /*TODO*/ } using EventStream = ::bluetooth::grpc::GrpcEventStream<AclData, AclPacketView>; ::grpc::Status SetPageScanMode(::grpc::ServerContext* context, const ::bluetooth::hci::cert::PageScanMode* request, Loading
system/gd/hci/facade.cc +25 −1 Original line number Diff line number Diff line Loading @@ -43,12 +43,14 @@ namespace hci { class AclManagerFacadeService : public AclManagerFacade::Service, public ::bluetooth::hci::ConnectionCallbacks, public ::bluetooth::hci::ConnectionManagementCallbacks { public ::bluetooth::hci::ConnectionManagementCallbacks, public ::bluetooth::hci::AclManagerCallbacks { public: AclManagerFacadeService(AclManager* acl_manager, Controller* controller, HciLayer* hci_layer, ::bluetooth::os::Handler* facade_handler) : acl_manager_(acl_manager), controller_(controller), hci_layer_(hci_layer), facade_handler_(facade_handler) { acl_manager_->RegisterCallbacks(this, facade_handler_); acl_manager_->RegisterAclManagerCallbacks(this, facade_handler_); } using EventStream = ::bluetooth::grpc::GrpcEventStream<AclData, AclPacketView>; Loading Loading @@ -202,6 +204,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, connection->second->ReadFailedContactCounter(); connection->second->ResetFailedContactCounter(); connection->second->ReadLinkQuality(); connection->second->ReadAfhChannelMap(); connection->second->ReadRssi(); connection->second->ReadClock(WhichClock::LOCAL); connection->second->ReadClock(WhichClock::PICONET); Loading @@ -217,6 +220,11 @@ class AclManagerFacadeService : public AclManagerFacade::Service, connection->second->FlowSpecification(FlowDirection::OUTGOING_FLOW, ServiceType::BEST_EFFORT, 0x1234, 0x1233, 0x1232, 0x1231); connection->second->Flush(); acl_manager_->MasterLinkKey(KeyFlag::TEMPORARY); acl_manager_->SwitchRole(peer, Role::MASTER); acl_manager_->WriteDefaultLinkPolicySettings(0x07); acl_manager_->ReadDefaultLinkPolicySettings(); return ::grpc::Status::OK; } } Loading Loading @@ -249,6 +257,18 @@ class AclManagerFacadeService : public AclManagerFacade::Service, connection_complete_stream_.OnIncomingEvent(shared_connection); } void OnMasterLinkKeyComplete(uint16_t connection_handle, KeyFlag key_flag) override { LOG_DEBUG("OnMasterLinkKeyComplete connection_handle:%d", connection_handle); } void OnRoleChange(Address bd_addr, Role new_role) override { LOG_DEBUG("OnRoleChange bd_addr:%s, new_role:%d", bd_addr.ToString().c_str(), (uint8_t)new_role); } void OnReadDefaultLinkPolicySettingsComplete(uint16_t default_link_policy_settings) override { LOG_DEBUG("OnReadDefaultLinkPolicySettingsComplete default_link_policy_settings:%d", default_link_policy_settings); } void on_disconnect(std::string address, ErrorCode code) { acl_connections_.erase(address); DisconnectionEvent event; Loading Loading @@ -341,6 +361,10 @@ class AclManagerFacadeService : public AclManagerFacade::Service, LOG_DEBUG("OnReadLinkQualityComplete link_quality:%d", link_quality); } void OnReadAfhChannelMapComplete(AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map) { LOG_DEBUG("OnReadAfhChannelMapComplete afh_mode:%d", (uint8_t)afh_mode); } void OnReadRssiComplete(uint8_t rssi) override { LOG_DEBUG("OnReadRssiComplete rssi:%d", rssi); } Loading