2018-07-27 14:32:39 -04:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2018-07-27 15:12:04 -04:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
2018-07-27 14:32:39 -04:00
|
|
|
#include "core/hle/service/nfc/nfc.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
2018-10-23 19:28:17 -04:00
|
|
|
#include "core/settings.h"
|
2018-07-27 14:32:39 -04:00
|
|
|
|
|
|
|
namespace Service::NFC {
|
|
|
|
|
|
|
|
class IAm final : public ServiceFramework<IAm> {
|
|
|
|
public:
|
2018-10-23 19:28:17 -04:00
|
|
|
explicit IAm() : ServiceFramework{"NFC::IAm"} {
|
2018-07-27 14:32:39 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "Initialize"},
|
|
|
|
{1, nullptr, "Finalize"},
|
|
|
|
{2, nullptr, "NotifyForegroundApplet"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NFC_AM final : public ServiceFramework<NFC_AM> {
|
|
|
|
public:
|
|
|
|
explicit NFC_AM() : ServiceFramework{"nfc:am"} {
|
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-07-27 15:12:04 -04:00
|
|
|
{0, &NFC_AM::CreateAmInterface, "CreateAmInterface"},
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-07-27 15:12:04 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CreateAmInterface(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NFC, "called");
|
|
|
|
|
2018-07-27 15:12:04 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IAm>();
|
|
|
|
}
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class MFIUser final : public ServiceFramework<MFIUser> {
|
|
|
|
public:
|
2018-10-23 19:28:17 -04:00
|
|
|
explicit MFIUser() : ServiceFramework{"NFC::MFIUser"} {
|
2018-07-27 14:32:39 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "Initialize"},
|
|
|
|
{1, nullptr, "Finalize"},
|
|
|
|
{2, nullptr, "ListDevices"},
|
|
|
|
{3, nullptr, "StartDetection"},
|
|
|
|
{4, nullptr, "StopDetection"},
|
|
|
|
{5, nullptr, "Read"},
|
|
|
|
{6, nullptr, "Write"},
|
|
|
|
{7, nullptr, "GetTagInfo"},
|
|
|
|
{8, nullptr, "GetActivateEventHandle"},
|
|
|
|
{9, nullptr, "GetDeactivateEventHandle"},
|
|
|
|
{10, nullptr, "GetState"},
|
|
|
|
{11, nullptr, "GetDeviceState"},
|
|
|
|
{12, nullptr, "GetNpadId"},
|
|
|
|
{13, nullptr, "GetAvailabilityChangeEventHandle"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NFC_MF_U final : public ServiceFramework<NFC_MF_U> {
|
|
|
|
public:
|
|
|
|
explicit NFC_MF_U() : ServiceFramework{"nfc:mf:u"} {
|
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-07-27 15:12:04 -04:00
|
|
|
{0, &NFC_MF_U::CreateUserInterface, "CreateUserInterface"},
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-07-27 15:12:04 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CreateUserInterface(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NFC, "called");
|
|
|
|
|
2018-07-27 15:12:04 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<MFIUser>();
|
|
|
|
}
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class IUser final : public ServiceFramework<IUser> {
|
|
|
|
public:
|
2018-10-23 19:28:17 -04:00
|
|
|
explicit IUser() : ServiceFramework{"NFC::IUser"} {
|
2018-07-27 14:32:39 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-10-23 19:28:17 -04:00
|
|
|
{0, &IUser::InitializeOld, "InitializeOld"},
|
|
|
|
{1, &IUser::FinalizeOld, "FinalizeOld"},
|
|
|
|
{2, &IUser::GetStateOld, "GetStateOld"},
|
|
|
|
{3, &IUser::IsNfcEnabledOld, "IsNfcEnabledOld"},
|
2018-07-27 14:32:39 -04:00
|
|
|
{400, nullptr, "Initialize"},
|
|
|
|
{401, nullptr, "Finalize"},
|
|
|
|
{402, nullptr, "GetState"},
|
|
|
|
{403, nullptr, "IsNfcEnabled"},
|
|
|
|
{404, nullptr, "ListDevices"},
|
|
|
|
{405, nullptr, "GetDeviceState"},
|
|
|
|
{406, nullptr, "GetNpadId"},
|
|
|
|
{407, nullptr, "AttachAvailabilityChangeEvent"},
|
|
|
|
{408, nullptr, "StartDetection"},
|
|
|
|
{409, nullptr, "StopDetection"},
|
|
|
|
{410, nullptr, "GetTagInfo"},
|
|
|
|
{411, nullptr, "AttachActivateEvent"},
|
|
|
|
{412, nullptr, "AttachDeactivateEvent"},
|
|
|
|
{1000, nullptr, "ReadMifare"},
|
|
|
|
{1001, nullptr, "WriteMifare"},
|
|
|
|
{1300, nullptr, "SendCommandByPassThrough"},
|
|
|
|
{1301, nullptr, "KeepPassThroughSession"},
|
|
|
|
{1302, nullptr, "ReleasePassThroughSession"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-10-23 19:28:17 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum class NfcStates : u32 {
|
|
|
|
Finalized = 6,
|
|
|
|
};
|
|
|
|
|
|
|
|
void InitializeOld(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NFC, "called");
|
|
|
|
|
2018-10-23 19:28:17 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
// We don't deal with hardware initialization so we can just stub this.
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsNfcEnabledOld(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NFC, "IsNfcEnabledOld");
|
|
|
|
|
2018-10-23 19:28:17 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-03-28 18:01:52 -04:00
|
|
|
rb.PushRaw<u8>(true);
|
2018-10-23 19:28:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetStateOld(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushEnum(NfcStates::Finalized); // TODO(ogniK): Figure out if this matches nfp
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinalizeOld(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_WARNING(Service_NFC, "(STUBBED) called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class NFC_U final : public ServiceFramework<NFC_U> {
|
|
|
|
public:
|
2018-10-23 19:28:17 -04:00
|
|
|
explicit NFC_U() : ServiceFramework{"nfc:user"} {
|
2018-07-27 14:32:39 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-07-27 15:12:04 -04:00
|
|
|
{0, &NFC_U::CreateUserInterface, "CreateUserInterface"},
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-07-27 15:12:04 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CreateUserInterface(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NFC, "called");
|
|
|
|
|
2018-07-27 15:12:04 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IUser>();
|
|
|
|
}
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ISystem final : public ServiceFramework<ISystem> {
|
|
|
|
public:
|
|
|
|
explicit ISystem() : ServiceFramework{"ISystem"} {
|
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "Initialize"},
|
|
|
|
{1, nullptr, "Finalize"},
|
|
|
|
{2, nullptr, "GetState"},
|
|
|
|
{3, nullptr, "IsNfcEnabled"},
|
|
|
|
{100, nullptr, "SetNfcEnabled"},
|
|
|
|
{400, nullptr, "InitializeSystem"},
|
|
|
|
{401, nullptr, "FinalizeSystem"},
|
|
|
|
{402, nullptr, "GetState"},
|
|
|
|
{403, nullptr, "IsNfcEnabled"},
|
|
|
|
{404, nullptr, "ListDevices"},
|
|
|
|
{405, nullptr, "GetDeviceState"},
|
|
|
|
{406, nullptr, "GetNpadId"},
|
|
|
|
{407, nullptr, "AttachAvailabilityChangeEvent"},
|
|
|
|
{408, nullptr, "StartDetection"},
|
|
|
|
{409, nullptr, "StopDetection"},
|
|
|
|
{410, nullptr, "GetTagInfo"},
|
|
|
|
{411, nullptr, "AttachActivateEvent"},
|
|
|
|
{412, nullptr, "AttachDeactivateEvent"},
|
|
|
|
{500, nullptr, "SetNfcEnabled"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{510, nullptr, "OutputTestWave"},
|
2018-07-27 14:32:39 -04:00
|
|
|
{1000, nullptr, "ReadMifare"},
|
|
|
|
{1001, nullptr, "WriteMifare"},
|
|
|
|
{1300, nullptr, "SendCommandByPassThrough"},
|
|
|
|
{1301, nullptr, "KeepPassThroughSession"},
|
|
|
|
{1302, nullptr, "ReleasePassThroughSession"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NFC_SYS final : public ServiceFramework<NFC_SYS> {
|
|
|
|
public:
|
|
|
|
explicit NFC_SYS() : ServiceFramework{"nfc:sys"} {
|
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-07-27 15:12:04 -04:00
|
|
|
{0, &NFC_SYS::CreateSystemInterface, "CreateSystemInterface"},
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-07-27 15:12:04 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CreateSystemInterface(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NFC, "called");
|
|
|
|
|
2018-07-27 15:12:04 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<ISystem>();
|
|
|
|
}
|
2018-07-27 14:32:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void InstallInterfaces(SM::ServiceManager& sm) {
|
|
|
|
std::make_shared<NFC_AM>()->InstallAsService(sm);
|
|
|
|
std::make_shared<NFC_MF_U>()->InstallAsService(sm);
|
|
|
|
std::make_shared<NFC_U>()->InstallAsService(sm);
|
|
|
|
std::make_shared<NFC_SYS>()->InstallAsService(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::NFC
|