mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 21:07:52 +00:00
service: nfc: Create mifare interface
This commit is contained in:
parent
a3fa64fcc4
commit
00d76fc5f5
3 changed files with 58 additions and 50 deletions
|
@ -6,33 +6,15 @@
|
||||||
#include "core/hid/hid_types.h"
|
#include "core/hid/hid_types.h"
|
||||||
#include "core/hle/kernel/k_event.h"
|
#include "core/hle/kernel/k_event.h"
|
||||||
#include "core/hle/service/ipc_helpers.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_device.h"
|
||||||
#include "core/hle/service/nfc/nfc_result.h"
|
#include "core/hle/service/nfc/nfc_result.h"
|
||||||
|
|
||||||
namespace Service::NFC {
|
namespace Service::NFC {
|
||||||
|
|
||||||
MFIUser::MFIUser(Core::System& system_)
|
MFInterface::MFInterface(Core::System& system_, const char* name)
|
||||||
: ServiceFramework{system_, "NFC::MFIUser"}, service_context{system_, service_name} {
|
: ServiceFramework{system_, name}, service_context{system_, service_name} {
|
||||||
static const FunctionInfo functions[] = {
|
availability_change_event = service_context.CreateEvent("MFInterface:AvailabilityChangeEvent");
|
||||||
{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");
|
|
||||||
|
|
||||||
for (u32 device_index = 0; device_index < 10; device_index++) {
|
for (u32 device_index = 0; device_index < 10; device_index++) {
|
||||||
devices[device_index] =
|
devices[device_index] =
|
||||||
|
@ -41,11 +23,11 @@ MFIUser::MFIUser(Core::System& system_)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MFIUser ::~MFIUser() {
|
MFInterface ::~MFInterface() {
|
||||||
availability_change_event->Close();
|
availability_change_event->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::Initialize(HLERequestContext& ctx) {
|
void MFInterface::Initialize(HLERequestContext& ctx) {
|
||||||
LOG_INFO(Service_NFC, "called");
|
LOG_INFO(Service_NFC, "called");
|
||||||
|
|
||||||
state = State::Initialized;
|
state = State::Initialized;
|
||||||
|
@ -58,7 +40,7 @@ void MFIUser::Initialize(HLERequestContext& ctx) {
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::Finalize(HLERequestContext& ctx) {
|
void MFInterface::Finalize(HLERequestContext& ctx) {
|
||||||
LOG_INFO(Service_NFC, "called");
|
LOG_INFO(Service_NFC, "called");
|
||||||
|
|
||||||
state = State::NonInitialized;
|
state = State::NonInitialized;
|
||||||
|
@ -71,7 +53,7 @@ void MFIUser::Finalize(HLERequestContext& ctx) {
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::ListDevices(HLERequestContext& ctx) {
|
void MFInterface::ListDevices(HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_NFC, "called");
|
LOG_DEBUG(Service_NFC, "called");
|
||||||
|
|
||||||
if (state == State::NonInitialized) {
|
if (state == State::NonInitialized) {
|
||||||
|
@ -117,7 +99,7 @@ void MFIUser::ListDevices(HLERequestContext& ctx) {
|
||||||
rb.Push(static_cast<s32>(nfp_devices.size()));
|
rb.Push(static_cast<s32>(nfp_devices.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::StartDetection(HLERequestContext& ctx) {
|
void MFInterface::StartDetection(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_INFO(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_INFO(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -141,7 +123,7 @@ void MFIUser::StartDetection(HLERequestContext& ctx) {
|
||||||
rb.Push(result);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::StopDetection(HLERequestContext& ctx) {
|
void MFInterface::StopDetection(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_INFO(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_INFO(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -165,7 +147,7 @@ void MFIUser::StopDetection(HLERequestContext& ctx) {
|
||||||
rb.Push(result);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::Read(HLERequestContext& ctx) {
|
void MFInterface::Read(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
const auto buffer{ctx.ReadBuffer()};
|
const auto buffer{ctx.ReadBuffer()};
|
||||||
|
@ -206,7 +188,7 @@ void MFIUser::Read(HLERequestContext& ctx) {
|
||||||
rb.Push(result);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::Write(HLERequestContext& ctx) {
|
void MFInterface::Write(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
const auto buffer{ctx.ReadBuffer()};
|
const auto buffer{ctx.ReadBuffer()};
|
||||||
|
@ -250,7 +232,7 @@ void MFIUser::Write(HLERequestContext& ctx) {
|
||||||
rb.Push(result);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetTagInfo(HLERequestContext& ctx) {
|
void MFInterface::GetTagInfo(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_INFO(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_INFO(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -276,7 +258,7 @@ void MFIUser::GetTagInfo(HLERequestContext& ctx) {
|
||||||
rb.Push(result);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) {
|
void MFInterface::GetActivateEventHandle(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -300,7 +282,7 @@ void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) {
|
||||||
rb.PushCopyObjects(device.value()->GetActivateEvent());
|
rb.PushCopyObjects(device.value()->GetActivateEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) {
|
void MFInterface::GetDeactivateEventHandle(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -324,7 +306,7 @@ void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) {
|
||||||
rb.PushCopyObjects(device.value()->GetDeactivateEvent());
|
rb.PushCopyObjects(device.value()->GetDeactivateEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetState(HLERequestContext& ctx) {
|
void MFInterface::GetState(HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_NFC, "called");
|
LOG_DEBUG(Service_NFC, "called");
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 3};
|
IPC::ResponseBuilder rb{ctx, 3};
|
||||||
|
@ -332,7 +314,7 @@ void MFIUser::GetState(HLERequestContext& ctx) {
|
||||||
rb.PushEnum(state);
|
rb.PushEnum(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetDeviceState(HLERequestContext& ctx) {
|
void MFInterface::GetDeviceState(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -350,7 +332,7 @@ void MFIUser::GetDeviceState(HLERequestContext& ctx) {
|
||||||
rb.PushEnum(device.value()->GetCurrentState());
|
rb.PushEnum(device.value()->GetCurrentState());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetNpadId(HLERequestContext& ctx) {
|
void MFInterface::GetNpadId(HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle);
|
||||||
|
@ -374,7 +356,7 @@ void MFIUser::GetNpadId(HLERequestContext& ctx) {
|
||||||
rb.PushEnum(device.value()->GetNpadId());
|
rb.PushEnum(device.value()->GetNpadId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) {
|
void MFInterface::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) {
|
||||||
LOG_INFO(Service_NFC, "called");
|
LOG_INFO(Service_NFC, "called");
|
||||||
|
|
||||||
if (state == State::NonInitialized) {
|
if (state == State::NonInitialized) {
|
||||||
|
@ -388,7 +370,7 @@ void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) {
|
||||||
rb.PushCopyObjects(availability_change_event->GetReadableEvent());
|
rb.PushCopyObjects(availability_change_event->GetReadableEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::shared_ptr<NfcDevice>> MFIUser::GetNfcDevice(u64 handle) {
|
std::optional<std::shared_ptr<NfcDevice>> MFInterface::GetNfcDevice(u64 handle) {
|
||||||
for (auto& device : devices) {
|
for (auto& device : devices) {
|
||||||
if (device->GetHandle() == handle) {
|
if (device->GetHandle() == handle) {
|
||||||
return device;
|
return device;
|
|
@ -13,16 +13,10 @@
|
||||||
namespace Service::NFC {
|
namespace Service::NFC {
|
||||||
class NfcDevice;
|
class NfcDevice;
|
||||||
|
|
||||||
class MFIUser final : public ServiceFramework<MFIUser> {
|
class MFInterface : public ServiceFramework<MFInterface> {
|
||||||
public:
|
public:
|
||||||
explicit MFIUser(Core::System& system_);
|
explicit MFInterface(Core::System& system_, const char* name);
|
||||||
~MFIUser();
|
~MFInterface();
|
||||||
|
|
||||||
private:
|
|
||||||
enum class State : u32 {
|
|
||||||
NonInitialized,
|
|
||||||
Initialized,
|
|
||||||
};
|
|
||||||
|
|
||||||
void Initialize(HLERequestContext& ctx);
|
void Initialize(HLERequestContext& ctx);
|
||||||
void Finalize(HLERequestContext& ctx);
|
void Finalize(HLERequestContext& ctx);
|
||||||
|
@ -39,6 +33,12 @@ private:
|
||||||
void GetNpadId(HLERequestContext& ctx);
|
void GetNpadId(HLERequestContext& ctx);
|
||||||
void GetAvailabilityChangeEventHandle(HLERequestContext& ctx);
|
void GetAvailabilityChangeEventHandle(HLERequestContext& ctx);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class State : u32 {
|
||||||
|
NonInitialized,
|
||||||
|
Initialized,
|
||||||
|
};
|
||||||
|
|
||||||
std::optional<std::shared_ptr<NfcDevice>> GetNfcDevice(u64 handle);
|
std::optional<std::shared_ptr<NfcDevice>> GetNfcDevice(u64 handle);
|
||||||
|
|
||||||
KernelHelpers::ServiceContext service_context;
|
KernelHelpers::ServiceContext service_context;
|
|
@ -6,7 +6,7 @@
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "core/hle/service/ipc_helpers.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.h"
|
||||||
#include "core/hle/service/nfc/nfc_interface.h"
|
#include "core/hle/service/nfc/nfc_interface.h"
|
||||||
#include "core/hle/service/server_manager.h"
|
#include "core/hle/service/server_manager.h"
|
||||||
|
@ -16,7 +16,7 @@ namespace Service::NFC {
|
||||||
|
|
||||||
class IUser final : public Interface {
|
class IUser final : public Interface {
|
||||||
public:
|
public:
|
||||||
explicit IUser(Core::System& system_) : Interface(system_, "IUser") {
|
explicit IUser(Core::System& system_) : Interface(system_, "NFC::IUser") {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &Interface::Initialize, "InitializeOld"},
|
{0, &Interface::Initialize, "InitializeOld"},
|
||||||
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
class ISystem final : public Interface {
|
class ISystem final : public Interface {
|
||||||
public:
|
public:
|
||||||
explicit ISystem(Core::System& system_) : Interface{system_, "ISystem"} {
|
explicit ISystem(Core::System& system_) : Interface{system_, "NFC::ISystem"} {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &Interface::Initialize, "InitializeOld"},
|
{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<IAm> {
|
class IAm final : public ServiceFramework<IAm> {
|
||||||
public:
|
public:
|
||||||
explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} {
|
explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} {
|
||||||
|
|
Loading…
Reference in a new issue