From 5b72be88c31e86af72fffd67ff5e5232bba63497 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 16 Oct 2022 17:55:04 +0100 Subject: [PATCH] Stub ldn:u service --- app/CMakeLists.txt | 2 + .../ldn/IUserLocalCommunicationService.cpp | 35 ++++++++++++ .../ldn/IUserLocalCommunicationService.h | 57 +++++++++++++++++++ .../services/ldn/IUserServiceCreator.cpp | 14 +++++ .../services/ldn/IUserServiceCreator.h | 23 ++++++++ .../main/cpp/skyline/services/serviceman.cpp | 2 + 6 files changed, 133 insertions(+) create mode 100644 app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.cpp create mode 100644 app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.h create mode 100644 app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.cpp create mode 100644 app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index ceb00df4..26e00b0a 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -335,6 +335,8 @@ add_library(skyline SHARED ${source_DIR}/skyline/services/pctl/IParentalControlService.cpp ${source_DIR}/skyline/services/lm/ILogService.cpp ${source_DIR}/skyline/services/lm/ILogger.cpp + ${source_DIR}/skyline/services/ldn/IUserServiceCreator.cpp + ${source_DIR}/skyline/services/ldn/IUserLocalCommunicationService.cpp ${source_DIR}/skyline/services/account/IAccountServiceForApplication.cpp ${source_DIR}/skyline/services/account/IManagerForApplication.cpp ${source_DIR}/skyline/services/account/IProfile.cpp diff --git a/app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.cpp b/app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.cpp new file mode 100644 index 00000000..4b118c69 --- /dev/null +++ b/app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.cpp @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "IUserLocalCommunicationService.h" + +namespace skyline::service::ldn { + IUserLocalCommunicationService::IUserLocalCommunicationService(const DeviceState &state, ServiceManager &manager) + : BaseService(state, manager), + event{std::make_shared(state, false)} {} + + Result IUserLocalCommunicationService::GetState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + static constexpr u32 StateNone{0x0}; + response.Push(StateNone); + return {}; + } + + Result IUserLocalCommunicationService::AttachStateChangeEvent(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + auto handle{state.process->InsertItem(event)}; + Logger::Debug("LDN State Change Event Handle: 0x{:X}", handle); + response.copyHandles.push_back(handle); + return {}; + } + + Result IUserLocalCommunicationService::InitializeSystem(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + return result::DeviceDisabled; + } + + Result IUserLocalCommunicationService::FinalizeSystem(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + return {}; + } + + Result IUserLocalCommunicationService::InitializeSystem2(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + return result::DeviceDisabled; + } +} diff --git a/app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.h b/app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.h new file mode 100644 index 00000000..fcedb2fe --- /dev/null +++ b/app/src/main/cpp/skyline/services/ldn/IUserLocalCommunicationService.h @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include + +namespace skyline::service::ldn { + namespace result { + static constexpr Result DeviceDisabled{203, 22}; + } + + /** + * @brief IUserLocalCommunicationService is used by applications to manage LDN sessions + * @url https://switchbrew.org/wiki/LDN_services#IUserLocalCommunicationService + */ + class IUserLocalCommunicationService : public BaseService { + private: + std::shared_ptr event; //!< The KEvent that is signalled on state changes + + public: + IUserLocalCommunicationService(const DeviceState &state, ServiceManager &manager); + + /** + * @url https://switchbrew.org/wiki/LDN_services#GetState + */ + Result GetState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @url https://switchbrew.org/wiki/LDN_services#AttachStateChangeEvent + */ + Result AttachStateChangeEvent(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @url https://switchbrew.org/wiki/LDN_services#InitializeSystem + */ + Result InitializeSystem(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @url https://switchbrew.org/wiki/LDN_services#FinalizeSystem + */ + Result FinalizeSystem(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @url https://switchbrew.org/wiki/LDN_services#InitializeSystem2 + */ + Result InitializeSystem2(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + SERVICE_DECL( + SFUNC(0x0, IUserLocalCommunicationService, GetState), + SFUNC(0x64, IUserLocalCommunicationService, AttachStateChangeEvent), + SFUNC(0x190, IUserLocalCommunicationService, InitializeSystem), + SFUNC(0x191, IUserLocalCommunicationService, FinalizeSystem), + SFUNC(0x192, IUserLocalCommunicationService, InitializeSystem2), + ) + }; +} diff --git a/app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.cpp b/app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.cpp new file mode 100644 index 00000000..01ba40b2 --- /dev/null +++ b/app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.cpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "IUserLocalCommunicationService.h" +#include "IUserServiceCreator.h" + +namespace skyline::service::ldn { + IUserServiceCreator::IUserServiceCreator(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager) {} + + Result IUserServiceCreator::CreateUserLocalCommunicationService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + manager.RegisterService(SRVREG(IUserLocalCommunicationService), session, response); + return {}; + } +} diff --git a/app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.h b/app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.h new file mode 100644 index 00000000..8ac541f6 --- /dev/null +++ b/app/src/main/cpp/skyline/services/ldn/IUserServiceCreator.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include + +namespace skyline::service::ldn { + /** + * @brief IUserServiceCreator or ldn:u is used by applications to open a channel to manage LDN sessions + * @url https://switchbrew.org/wiki/LDN_services#CreateUserLocalCommunicationService + */ + class IUserServiceCreator : public BaseService { + public: + IUserServiceCreator(const DeviceState &state, ServiceManager &manager); + + Result CreateUserLocalCommunicationService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + SERVICE_DECL( + SFUNC(0x0, IUserServiceCreator, CreateUserLocalCommunicationService) + ) + }; +} diff --git a/app/src/main/cpp/skyline/services/serviceman.cpp b/app/src/main/cpp/skyline/services/serviceman.cpp index ff9f950b..96b62e9f 100644 --- a/app/src/main/cpp/skyline/services/serviceman.cpp +++ b/app/src/main/cpp/skyline/services/serviceman.cpp @@ -34,6 +34,7 @@ #include "aocsrv/IAddOnContentManager.h" #include "pctl/IParentalControlServiceFactory.h" #include "lm/ILogService.h" +#include "ldn/IUserServiceCreator.h" #include "account/IAccountServiceForApplication.h" #include "friends/IServiceCreator.h" #include "nfp/IUserManager.h" @@ -106,6 +107,7 @@ namespace skyline::service { SERVICE_CASE(pctl::IParentalControlServiceFactory, "pctl:s") SERVICE_CASE(pctl::IParentalControlServiceFactory, "pctl:r") SERVICE_CASE(lm::ILogService, "lm") + SERVICE_CASE(ldn::IUserServiceCreator, "ldn:u") SERVICE_CASE(account::IAccountServiceForApplication, "acc:u0") SERVICE_CASE(friends::IServiceCreator, "friend:u") SERVICE_CASE(nfp::IUserManager, "nfp:user")