From 7102fa910e3a05ec0a87608abdf0b8545f978545 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 9 Jul 2020 14:28:26 +0100 Subject: [PATCH] Implement nfp services --- app/CMakeLists.txt | 2 ++ .../main/cpp/skyline/services/base_service.h | 3 +++ .../main/cpp/skyline/services/nfp/IUser.cpp | 13 +++++++++++ app/src/main/cpp/skyline/services/nfp/IUser.h | 22 +++++++++++++++++++ .../cpp/skyline/services/nfp/IUserManager.cpp | 15 +++++++++++++ .../cpp/skyline/services/nfp/IUserManager.h | 22 +++++++++++++++++++ .../main/cpp/skyline/services/serviceman.cpp | 4 ++++ 7 files changed, 81 insertions(+) create mode 100644 app/src/main/cpp/skyline/services/nfp/IUser.cpp create mode 100644 app/src/main/cpp/skyline/services/nfp/IUser.h create mode 100644 app/src/main/cpp/skyline/services/nfp/IUserManager.cpp create mode 100644 app/src/main/cpp/skyline/services/nfp/IUserManager.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 156185ab..431295e8 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -117,6 +117,8 @@ add_library(skyline SHARED ${source_DIR}/skyline/services/account/IManagerForApplication.cpp ${source_DIR}/skyline/services/friends/IServiceCreator.cpp ${source_DIR}/skyline/services/friends/IFriendService.cpp + ${source_DIR}/skyline/services/nfp/IUserManager.cpp + ${source_DIR}/skyline/services/nfp/IUser.cpp ${source_DIR}/skyline/vfs/partition_filesystem.cpp ${source_DIR}/skyline/vfs/rom_filesystem.cpp ${source_DIR}/skyline/vfs/os_backing.cpp diff --git a/app/src/main/cpp/skyline/services/base_service.h b/app/src/main/cpp/skyline/services/base_service.h index 8120d3db..cc3b5ce7 100644 --- a/app/src/main/cpp/skyline/services/base_service.h +++ b/app/src/main/cpp/skyline/services/base_service.h @@ -73,6 +73,8 @@ namespace skyline::service { account_IManagerForApplication, friends_IServiceCreator, friends_IFriendService, + nfp_IUserManager, + nfp_IUser, }; /** @@ -108,6 +110,7 @@ namespace skyline::service { {"lm", Service::lm_ILogService}, {"acc:u0", Service::account_IAccountServiceForApplication}, {"friend:u", Service::friends_IServiceCreator}, + {"nfp:user", Service::nfp_IUserManager}, }; class ServiceManager; diff --git a/app/src/main/cpp/skyline/services/nfp/IUser.cpp b/app/src/main/cpp/skyline/services/nfp/IUser.cpp new file mode 100644 index 00000000..152d2eb5 --- /dev/null +++ b/app/src/main/cpp/skyline/services/nfp/IUser.cpp @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "IUser.h" +#include "IUserManager.h" + +namespace skyline::service::nfp { + IUser::IUser(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::nfp_IUser, "nfp:IUser", { + {0x0, SFUNC(IUser::Initialize)} + }) {} + + void IUser::Initialize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {} +} diff --git a/app/src/main/cpp/skyline/services/nfp/IUser.h b/app/src/main/cpp/skyline/services/nfp/IUser.h new file mode 100644 index 00000000..f89d03a9 --- /dev/null +++ b/app/src/main/cpp/skyline/services/nfp/IUser.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include + +namespace skyline::service::nfp { + /** + * @brief IUser is used by applications to access NFC devices (https://switchbrew.org/wiki/NFC_services#IUser) + */ + class IUser : public BaseService { + public: + IUser(const DeviceState &state, ServiceManager &manager); + + /** + * @brief This initializes an NFP session + */ + void Initialize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + }; +} diff --git a/app/src/main/cpp/skyline/services/nfp/IUserManager.cpp b/app/src/main/cpp/skyline/services/nfp/IUserManager.cpp new file mode 100644 index 00000000..5f1de14f --- /dev/null +++ b/app/src/main/cpp/skyline/services/nfp/IUserManager.cpp @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "IUser.h" +#include "IUserManager.h" + +namespace skyline::service::nfp { + IUserManager::IUserManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::nfp_IUserManager, "nfp:IUserManager", { + {0x0, SFUNC(IUserManager::CreateUserInterface)} + }) {} + + void IUserManager::CreateUserInterface(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + manager.RegisterService(SRVREG(IUser), session, response); + } +} diff --git a/app/src/main/cpp/skyline/services/nfp/IUserManager.h b/app/src/main/cpp/skyline/services/nfp/IUserManager.h new file mode 100644 index 00000000..cc4e4adc --- /dev/null +++ b/app/src/main/cpp/skyline/services/nfp/IUserManager.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include + +namespace skyline::service::nfp { + /** + * @brief IUserManager or nfp:user is used by applications to open an IUser instance for accessing NFC devices (https://switchbrew.org/wiki/NFC_services#nfp:user) + */ + class IUserManager : public BaseService { + public: + IUserManager(const DeviceState &state, ServiceManager &manager); + + /** + * @brief This opens an IUser that can be used by applications to access NFC devices + */ + void CreateUserInterface(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + }; +} diff --git a/app/src/main/cpp/skyline/services/serviceman.cpp b/app/src/main/cpp/skyline/services/serviceman.cpp index d8c3ca81..f2e354c5 100644 --- a/app/src/main/cpp/skyline/services/serviceman.cpp +++ b/app/src/main/cpp/skyline/services/serviceman.cpp @@ -22,6 +22,7 @@ #include "lm/ILogService.h" #include "account/IAccountServiceForApplication.h" #include "friends/IServiceCreator.h" +#include "nfp/IUserManager.h" #include "serviceman.h" namespace skyline::service { @@ -94,6 +95,9 @@ namespace skyline::service { case Service::friends_IServiceCreator: serviceObj = std::make_shared(state, *this); break; + case Service::nfp_IUserManager: + serviceObj = std::make_shared(state, *this); + break; default: throw exception("CreateService called on missing object, type: {}", serviceType); }