// 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) {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, &NfcInterface::Initialize, "InitializeOld"}, FunctionInfo{1, &NfcInterface::Finalize, "FinalizeOld"}, FunctionInfo{2, &NfcInterface::GetState, "GetStateOld"}, FunctionInfo{3, &NfcInterface::IsNfcEnabled, "IsNfcEnabledOld"}, FunctionInfo{400, &NfcInterface::Initialize, "Initialize"}, FunctionInfo{401, &NfcInterface::Finalize, "Finalize"}, FunctionInfo{402, &NfcInterface::GetState, "GetState"}, FunctionInfo{403, &NfcInterface::IsNfcEnabled, "IsNfcEnabled"}, FunctionInfo{404, &NfcInterface::ListDevices, "ListDevices"}, FunctionInfo{405, &NfcInterface::GetDeviceState, "GetDeviceState"}, FunctionInfo{406, &NfcInterface::GetNpadId, "GetNpadId"}, FunctionInfo{407, &NfcInterface::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, FunctionInfo{408, &NfcInterface::StartDetection, "StartDetection"}, FunctionInfo{409, &NfcInterface::StopDetection, "StopDetection"}, FunctionInfo{410, &NfcInterface::GetTagInfo, "GetTagInfo"}, FunctionInfo{411, &NfcInterface::AttachActivateEvent, "AttachActivateEvent"}, FunctionInfo{412, &NfcInterface::AttachDeactivateEvent, "AttachDeactivateEvent"}, FunctionInfo{1000, &NfcInterface::ReadMifare, "ReadMifare"}, FunctionInfo{1001, &NfcInterface::WriteMifare ,"WriteMifare"}, FunctionInfo{1300, &NfcInterface::SendCommandByPassThrough, "SendCommandByPassThrough"}, FunctionInfo{1301, nullptr, "KeepPassThroughSession"}, FunctionInfo{1302, nullptr, "ReleasePassThroughSession"} ); } }; class ISystem final : public NfcInterface { public: explicit ISystem(Core::System& system_) : NfcInterface{system_, "NFC::ISystem", BackendType::Nfc} {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, &NfcInterface::Initialize, "InitializeOld"}, FunctionInfo{1, &NfcInterface::Finalize, "FinalizeOld"}, FunctionInfo{2, &NfcInterface::GetState, "GetStateOld"}, FunctionInfo{3, &NfcInterface::IsNfcEnabled, "IsNfcEnabledOld"}, FunctionInfo{100, &NfcInterface::SetNfcEnabled, "SetNfcEnabledOld"}, FunctionInfo{400, &NfcInterface::Initialize, "Initialize"}, FunctionInfo{401, &NfcInterface::Finalize, "Finalize"}, FunctionInfo{402, &NfcInterface::GetState, "GetState"}, FunctionInfo{403, &NfcInterface::IsNfcEnabled, "IsNfcEnabled"}, FunctionInfo{404, &NfcInterface::ListDevices, "ListDevices"}, FunctionInfo{405, &NfcInterface::GetDeviceState, "GetDeviceState"}, FunctionInfo{406, &NfcInterface::GetNpadId, "GetNpadId"}, FunctionInfo{407, &NfcInterface::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, FunctionInfo{408, &NfcInterface::StartDetection, "StartDetection"}, FunctionInfo{409, &NfcInterface::StopDetection, "StopDetection"}, FunctionInfo{410, &NfcInterface::GetTagInfo, "GetTagInfo"}, FunctionInfo{411, &NfcInterface::AttachActivateEvent, "AttachActivateEvent"}, FunctionInfo{412, &NfcInterface::AttachDeactivateEvent, "AttachDeactivateEvent"}, FunctionInfo{500, &NfcInterface::SetNfcEnabled, "SetNfcEnabled"}, FunctionInfo{510, nullptr, "OutputTestWave"}, FunctionInfo{1000, &NfcInterface::ReadMifare, "ReadMifare"}, FunctionInfo{1001, &NfcInterface::WriteMifare, "WriteMifare"}, FunctionInfo{1300, &NfcInterface::SendCommandByPassThrough, "SendCommandByPassThrough"}, FunctionInfo{1301, nullptr, "KeepPassThroughSession"}, FunctionInfo{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} { // clang-format off static const FunctionInfoTyped functions[] = { FunctionInfo{0, &MFIUser::Initialize, "Initialize"}, FunctionInfo{1, &MFIUser::Finalize, "Finalize"}, FunctionInfo{2, &MFIUser::ListDevices, "ListDevices"}, FunctionInfo{3, &MFIUser::StartDetection, "StartDetection"}, FunctionInfo{4, &MFIUser::StopDetection, "StopDetection"}, FunctionInfo{5, &MFIUser::ReadMifare, "Read"}, FunctionInfo{6, &MFIUser::WriteMifare, "Write"}, FunctionInfo{7, &MFIUser::GetTagInfo, "GetTagInfo"}, FunctionInfo{8, &MFIUser::AttachActivateEvent, "GetActivateEventHandle"}, FunctionInfo{9, &MFIUser::AttachDeactivateEvent, "GetDeactivateEventHandle"}, FunctionInfo{10, &MFIUser::GetState, "GetState"}, FunctionInfo{11, &MFIUser::GetDeviceState, "GetDeviceState"}, FunctionInfo{12, &MFIUser::GetNpadId, "GetNpadId"}, FunctionInfo{13, &MFIUser::AttachAvailabilityChangeEvent, "GetAvailabilityChangeEventHandle"} ); } }; class IAm final : public ServiceFramework { public: explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, nullptr, "Initialize"}, FunctionInfo{1, nullptr, "Finalize"}, FunctionInfo{2, nullptr, "NotifyForegroundApplet"} ); } }; class NFC_AM final : public ServiceFramework { public: explicit NFC_AM(Core::System& system_) : ServiceFramework{system_, "nfc:am"} {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, &NFC_AM::CreateAmNfcInterface, "CreateAmNfcInterface"} ); } private: void CreateAmNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } }; class NFC_MF_U final : public ServiceFramework { public: explicit NFC_MF_U(Core::System& system_) : ServiceFramework{system_, "nfc:mf:u"} {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, &NFC_MF_U::CreateUserNfcInterface, "CreateUserNfcInterface"} ); } private: void CreateUserNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } }; class NFC_U final : public ServiceFramework { public: explicit NFC_U(Core::System& system_) : ServiceFramework{system_, "nfc:user"} {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, &NFC_U::CreateUserNfcInterface, "CreateUserNfcInterface"} ); } private: void CreateUserNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } }; class NFC_SYS final : public ServiceFramework { public: explicit NFC_SYS(Core::System& system_) : ServiceFramework{system_, "nfc:sys"} {} FunctionInfoBase const* FindRequest(u32 key) override { return HandlerTableGenerateWithFind(key, FunctionInfo{0, &NFC_SYS::CreateSystemNfcInterface, "CreateSystemNfcInterface"} ); } private: void CreateSystemNfcInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface(ctx, system); } }; 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