// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include #include "common/logging.h" #include "common/settings.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/nfc.h" #include "core/hle/service/nfc/nfc_interface.h" #include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::NFC { class IUser final : public NfcInterface { public: explicit IUser(Core::System& system_) : NfcInterface(system_, "NFC::IUser", BackendType::Nfc) {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } static constexpr auto functions = CreateStaticMapWithClass( FunctionInfoTyped{0, &NfcInterface::Initialize, "InitializeOld"}, FunctionInfoTyped{1, &NfcInterface::Finalize, "FinalizeOld"}, FunctionInfoTyped{2, &NfcInterface::GetState, "GetStateOld"}, FunctionInfoTyped{3, &NfcInterface::IsNfcEnabled, "IsNfcEnabledOld"}, FunctionInfoTyped{400, &NfcInterface::Initialize, "Initialize"}, FunctionInfoTyped{401, &NfcInterface::Finalize, "Finalize"}, FunctionInfoTyped{402, &NfcInterface::GetState, "GetState"}, FunctionInfoTyped{403, &NfcInterface::IsNfcEnabled, "IsNfcEnabled"}, FunctionInfoTyped{404, &NfcInterface::ListDevices, "ListDevices"}, FunctionInfoTyped{405, &NfcInterface::GetDeviceState, "GetDeviceState"}, FunctionInfoTyped{406, &NfcInterface::GetNpadId, "GetNpadId"}, FunctionInfoTyped{407, &NfcInterface::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, FunctionInfoTyped{408, &NfcInterface::StartDetection, "StartDetection"}, FunctionInfoTyped{409, &NfcInterface::StopDetection, "StopDetection"}, FunctionInfoTyped{410, &NfcInterface::GetTagInfo, "GetTagInfo"}, FunctionInfoTyped{411, &NfcInterface::AttachActivateEvent, "AttachActivateEvent"}, FunctionInfoTyped{412, &NfcInterface::AttachDeactivateEvent, "AttachDeactivateEvent"}, FunctionInfoTyped{1000, &NfcInterface::ReadMifare, "ReadMifare"}, FunctionInfoTyped{1001, &NfcInterface::WriteMifare ,"WriteMifare"}, FunctionInfoTyped{1300, &NfcInterface::SendCommandByPassThrough, "SendCommandByPassThrough"}, FunctionInfoTyped{1301, nullptr, "KeepPassThroughSession"}, FunctionInfoTyped{1302, nullptr, "ReleasePassThroughSession"} ); }; class ISystem final : public NfcInterface { public: explicit ISystem(Core::System& system_) : NfcInterface{system_, "NFC::ISystem", BackendType::Nfc} {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } static constexpr auto functions = CreateStaticMapWithClass( FunctionInfoTyped{0, &NfcInterface::Initialize, "InitializeOld"}, FunctionInfoTyped{1, &NfcInterface::Finalize, "FinalizeOld"}, FunctionInfoTyped{2, &NfcInterface::GetState, "GetStateOld"}, FunctionInfoTyped{3, &NfcInterface::IsNfcEnabled, "IsNfcEnabledOld"}, FunctionInfoTyped{100, &NfcInterface::SetNfcEnabled, "SetNfcEnabledOld"}, FunctionInfoTyped{400, &NfcInterface::Initialize, "Initialize"}, FunctionInfoTyped{401, &NfcInterface::Finalize, "Finalize"}, FunctionInfoTyped{402, &NfcInterface::GetState, "GetState"}, FunctionInfoTyped{403, &NfcInterface::IsNfcEnabled, "IsNfcEnabled"}, FunctionInfoTyped{404, &NfcInterface::ListDevices, "ListDevices"}, FunctionInfoTyped{405, &NfcInterface::GetDeviceState, "GetDeviceState"}, FunctionInfoTyped{406, &NfcInterface::GetNpadId, "GetNpadId"}, FunctionInfoTyped{407, &NfcInterface::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, FunctionInfoTyped{408, &NfcInterface::StartDetection, "StartDetection"}, FunctionInfoTyped{409, &NfcInterface::StopDetection, "StopDetection"}, FunctionInfoTyped{410, &NfcInterface::GetTagInfo, "GetTagInfo"}, FunctionInfoTyped{411, &NfcInterface::AttachActivateEvent, "AttachActivateEvent"}, FunctionInfoTyped{412, &NfcInterface::AttachDeactivateEvent, "AttachDeactivateEvent"}, FunctionInfoTyped{500, &NfcInterface::SetNfcEnabled, "SetNfcEnabled"}, FunctionInfoTyped{510, nullptr, "OutputTestWave"}, FunctionInfoTyped{1000, &NfcInterface::ReadMifare, "ReadMifare"}, FunctionInfoTyped{1001, &NfcInterface::WriteMifare, "WriteMifare"}, FunctionInfoTyped{1300, &NfcInterface::SendCommandByPassThrough, "SendCommandByPassThrough"}, FunctionInfoTyped{1301, nullptr, "KeepPassThroughSession"}, FunctionInfoTyped{1302, nullptr, "ReleasePassThroughSession"} ); }; // MFInterface has an unique interface but it's identical to NfcInterface so we can keep the code // simpler using MFInterface = NfcInterface; class MFIUser final : public MFInterface { public: explicit MFIUser(Core::System& system_) : MFInterface{system_, "NFC::MFInterface", BackendType::Mifare} {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } static constexpr auto functions = CreateStaticMapWithClass( FunctionInfoTyped{0, &MFIUser::Initialize, "Initialize"}, FunctionInfoTyped{1, &MFIUser::Finalize, "Finalize"}, FunctionInfoTyped{2, &MFIUser::ListDevices, "ListDevices"}, FunctionInfoTyped{3, &MFIUser::StartDetection, "StartDetection"}, FunctionInfoTyped{4, &MFIUser::StopDetection, "StopDetection"}, FunctionInfoTyped{5, &MFIUser::ReadMifare, "Read"}, FunctionInfoTyped{6, &MFIUser::WriteMifare, "Write"}, FunctionInfoTyped{7, &MFIUser::GetTagInfo, "GetTagInfo"}, FunctionInfoTyped{8, &MFIUser::AttachActivateEvent, "GetActivateEventHandle"}, FunctionInfoTyped{9, &MFIUser::AttachDeactivateEvent, "GetDeactivateEventHandle"}, FunctionInfoTyped{10, &MFIUser::GetState, "GetState"}, FunctionInfoTyped{11, &MFIUser::GetDeviceState, "GetDeviceState"}, FunctionInfoTyped{12, &MFIUser::GetNpadId, "GetNpadId"}, FunctionInfoTyped{13, &MFIUser::AttachAvailabilityChangeEvent, "GetAvailabilityChangeEventHandle"} ); }; class IAm final : public ServiceFramework { public: explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} {} static constexpr auto functions = CreateStaticMap( FunctionInfo{0, nullptr, "Initialize"}, FunctionInfo{1, nullptr, "Finalize"}, FunctionInfo{2, nullptr, "NotifyForegroundApplet"} ); std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } }; class NFC_AM final : public ServiceFramework { public: explicit NFC_AM(Core::System& system_) : ServiceFramework{system_, "nfc:am"} {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } private: void CreateAmNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } static constexpr auto functions = CreateStaticMap( FunctionInfo{0, &NFC_AM::CreateAmNfcInterface, "CreateAmNfcInterface"} ); }; class NFC_MF_U final : public ServiceFramework { public: explicit NFC_MF_U(Core::System& system_) : ServiceFramework{system_, "nfc:mf:u"} {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } private: void CreateUserNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } static constexpr auto functions = CreateStaticMap( FunctionInfo{0, &NFC_MF_U::CreateUserNfcInterface, "CreateUserNfcInterface"} ); }; class NFC_U final : public ServiceFramework { public: explicit NFC_U(Core::System& system_) : ServiceFramework{system_, "nfc:user"} {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } private: void CreateUserNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } static constexpr auto functions = CreateStaticMap( FunctionInfo{0, &NFC_U::CreateUserNfcInterface, "CreateUserNfcInterface"} ); }; class NFC_SYS final : public ServiceFramework { public: explicit NFC_SYS(Core::System& system_) : ServiceFramework{system_, "nfc:sys"} {} std::optional FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, functions); } private: void CreateSystemNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } static constexpr auto functions = CreateStaticMap( FunctionInfo{0, &NFC_SYS::CreateSystemNfcInterface, "CreateSystemNfcInterface"} ); }; void LoopProcess(Core::System& system) { auto server_manager = std::make_unique(system); server_manager->RegisterNamedService("nfc:am", std::make_shared(system)); server_manager->RegisterNamedService("nfc:mf:u", std::make_shared(system)); server_manager->RegisterNamedService("nfc:user", std::make_shared(system)); server_manager->RegisterNamedService("nfc:sys", std::make_shared(system)); ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NFC