From 00d76fc5f5276b74f4c14edda579981831808d35 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Fri, 14 Apr 2023 17:55:13 -0600 Subject: [PATCH] service: nfc: Create mifare interface --- .../{mifare_user.cpp => mifare_interface.cpp} | 58 +++++++------------ .../nfc/{mifare_user.h => mifare_interface.h} | 18 +++--- src/core/hle/service/nfc/nfc.cpp | 32 +++++++++- 3 files changed, 58 insertions(+), 50 deletions(-) rename src/core/hle/service/nfc/{mifare_user.cpp => mifare_interface.cpp} (83%) rename src/core/hle/service/nfc/{mifare_user.h => mifare_interface.h} (90%) diff --git a/src/core/hle/service/nfc/mifare_user.cpp b/src/core/hle/service/nfc/mifare_interface.cpp similarity index 83% rename from src/core/hle/service/nfc/mifare_user.cpp rename to src/core/hle/service/nfc/mifare_interface.cpp index e0bbd46e1..7e6635ba2 100644 --- a/src/core/hle/service/nfc/mifare_user.cpp +++ b/src/core/hle/service/nfc/mifare_interface.cpp @@ -6,33 +6,15 @@ #include "core/hid/hid_types.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/ipc_helpers.h" -#include "core/hle/service/nfc/mifare_user.h" +#include "core/hle/service/nfc/mifare_interface.h" #include "core/hle/service/nfc/nfc_device.h" #include "core/hle/service/nfc/nfc_result.h" namespace Service::NFC { -MFIUser::MFIUser(Core::System& system_) - : ServiceFramework{system_, "NFC::MFIUser"}, service_context{system_, service_name} { - static const FunctionInfo functions[] = { - {0, &MFIUser::Initialize, "Initialize"}, - {1, &MFIUser::Finalize, "Finalize"}, - {2, &MFIUser::ListDevices, "ListDevices"}, - {3, &MFIUser::StartDetection, "StartDetection"}, - {4, &MFIUser::StopDetection, "StopDetection"}, - {5, &MFIUser::Read, "Read"}, - {6, &MFIUser::Write, "Write"}, - {7, &MFIUser::GetTagInfo, "GetTagInfo"}, - {8, &MFIUser::GetActivateEventHandle, "GetActivateEventHandle"}, - {9, &MFIUser::GetDeactivateEventHandle, "GetDeactivateEventHandle"}, - {10, &MFIUser::GetState, "GetState"}, - {11, &MFIUser::GetDeviceState, "GetDeviceState"}, - {12, &MFIUser::GetNpadId, "GetNpadId"}, - {13, &MFIUser::GetAvailabilityChangeEventHandle, "GetAvailabilityChangeEventHandle"}, - }; - RegisterHandlers(functions); - - availability_change_event = service_context.CreateEvent("MFIUser:AvailabilityChangeEvent"); +MFInterface::MFInterface(Core::System& system_, const char* name) + : ServiceFramework{system_, name}, service_context{system_, service_name} { + availability_change_event = service_context.CreateEvent("MFInterface:AvailabilityChangeEvent"); for (u32 device_index = 0; device_index < 10; device_index++) { devices[device_index] = @@ -41,11 +23,11 @@ MFIUser::MFIUser(Core::System& system_) } } -MFIUser ::~MFIUser() { +MFInterface ::~MFInterface() { availability_change_event->Close(); } -void MFIUser::Initialize(HLERequestContext& ctx) { +void MFInterface::Initialize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::Initialized; @@ -58,7 +40,7 @@ void MFIUser::Initialize(HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void MFIUser::Finalize(HLERequestContext& ctx) { +void MFInterface::Finalize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::NonInitialized; @@ -71,7 +53,7 @@ void MFIUser::Finalize(HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void MFIUser::ListDevices(HLERequestContext& ctx) { +void MFInterface::ListDevices(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -117,7 +99,7 @@ void MFIUser::ListDevices(HLERequestContext& ctx) { rb.Push(static_cast(nfp_devices.size())); } -void MFIUser::StartDetection(HLERequestContext& ctx) { +void MFInterface::StartDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -141,7 +123,7 @@ void MFIUser::StartDetection(HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::StopDetection(HLERequestContext& ctx) { +void MFInterface::StopDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -165,7 +147,7 @@ void MFIUser::StopDetection(HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::Read(HLERequestContext& ctx) { +void MFInterface::Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto buffer{ctx.ReadBuffer()}; @@ -206,7 +188,7 @@ void MFIUser::Read(HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::Write(HLERequestContext& ctx) { +void MFInterface::Write(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto buffer{ctx.ReadBuffer()}; @@ -250,7 +232,7 @@ void MFIUser::Write(HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::GetTagInfo(HLERequestContext& ctx) { +void MFInterface::GetTagInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -276,7 +258,7 @@ void MFIUser::GetTagInfo(HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) { +void MFInterface::GetActivateEventHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -300,7 +282,7 @@ void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetActivateEvent()); } -void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) { +void MFInterface::GetDeactivateEventHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -324,7 +306,7 @@ void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetDeactivateEvent()); } -void MFIUser::GetState(HLERequestContext& ctx) { +void MFInterface::GetState(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -332,7 +314,7 @@ void MFIUser::GetState(HLERequestContext& ctx) { rb.PushEnum(state); } -void MFIUser::GetDeviceState(HLERequestContext& ctx) { +void MFInterface::GetDeviceState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -350,7 +332,7 @@ void MFIUser::GetDeviceState(HLERequestContext& ctx) { rb.PushEnum(device.value()->GetCurrentState()); } -void MFIUser::GetNpadId(HLERequestContext& ctx) { +void MFInterface::GetNpadId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -374,7 +356,7 @@ void MFIUser::GetNpadId(HLERequestContext& ctx) { rb.PushEnum(device.value()->GetNpadId()); } -void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { +void MFInterface::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -388,7 +370,7 @@ void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { rb.PushCopyObjects(availability_change_event->GetReadableEvent()); } -std::optional> MFIUser::GetNfcDevice(u64 handle) { +std::optional> MFInterface::GetNfcDevice(u64 handle) { for (auto& device : devices) { if (device->GetHandle() == handle) { return device; diff --git a/src/core/hle/service/nfc/mifare_user.h b/src/core/hle/service/nfc/mifare_interface.h similarity index 90% rename from src/core/hle/service/nfc/mifare_user.h rename to src/core/hle/service/nfc/mifare_interface.h index 9701f1d7f..698c8a6b6 100644 --- a/src/core/hle/service/nfc/mifare_user.h +++ b/src/core/hle/service/nfc/mifare_interface.h @@ -13,16 +13,10 @@ namespace Service::NFC { class NfcDevice; -class MFIUser final : public ServiceFramework { +class MFInterface : public ServiceFramework { public: - explicit MFIUser(Core::System& system_); - ~MFIUser(); - -private: - enum class State : u32 { - NonInitialized, - Initialized, - }; + explicit MFInterface(Core::System& system_, const char* name); + ~MFInterface(); void Initialize(HLERequestContext& ctx); void Finalize(HLERequestContext& ctx); @@ -39,6 +33,12 @@ private: void GetNpadId(HLERequestContext& ctx); void GetAvailabilityChangeEventHandle(HLERequestContext& ctx); +private: + enum class State : u32 { + NonInitialized, + Initialized, + }; + std::optional> GetNfcDevice(u64 handle); KernelHelpers::ServiceContext service_context; diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index 7a8f59725..444d65f07 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp @@ -6,7 +6,7 @@ #include "common/logging/log.h" #include "common/settings.h" #include "core/hle/service/ipc_helpers.h" -#include "core/hle/service/nfc/mifare_user.h" +#include "core/hle/service/nfc/mifare_interface.h" #include "core/hle/service/nfc/nfc.h" #include "core/hle/service/nfc/nfc_interface.h" #include "core/hle/service/server_manager.h" @@ -16,7 +16,7 @@ namespace Service::NFC { class IUser final : public Interface { public: - explicit IUser(Core::System& system_) : Interface(system_, "IUser") { + explicit IUser(Core::System& system_) : Interface(system_, "NFC::IUser") { // clang-format off static const FunctionInfo functions[] = { {0, &Interface::Initialize, "InitializeOld"}, @@ -50,7 +50,7 @@ public: class ISystem final : public Interface { public: - explicit ISystem(Core::System& system_) : Interface{system_, "ISystem"} { + explicit ISystem(Core::System& system_) : Interface{system_, "NFC::ISystem"} { // clang-format off static const FunctionInfo functions[] = { {0, &Interface::Initialize, "InitializeOld"}, @@ -85,6 +85,32 @@ public: } }; +class MFIUser final : public MFInterface { +public: + explicit MFIUser(Core::System& system_) : MFInterface{system_, "NFC::MFInterface"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, &MFIUser::Initialize, "Initialize"}, + {1, &MFIUser::Finalize, "Finalize"}, + {2, &MFIUser::ListDevices, "ListDevices"}, + {3, &MFIUser::StartDetection, "StartDetection"}, + {4, &MFIUser::StopDetection, "StopDetection"}, + {5, &MFIUser::Read, "Read"}, + {6, &MFIUser::Write, "Write"}, + {7, &MFIUser::GetTagInfo, "GetTagInfo"}, + {8, &MFIUser::GetActivateEventHandle, "GetActivateEventHandle"}, + {9, &MFIUser::GetDeactivateEventHandle, "GetDeactivateEventHandle"}, + {10, &MFIUser::GetState, "GetState"}, + {11, &MFIUser::GetDeviceState, "GetDeviceState"}, + {12, &MFIUser::GetNpadId, "GetNpadId"}, + {13, &MFIUser::GetAvailabilityChangeEventHandle, "GetAvailabilityChangeEventHandle"}, + }; + // clang-format on + + RegisterHandlers(functions); + } +}; + class IAm final : public ServiceFramework { public: explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} {