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