2018-03-29 18:06:51 -07:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-09-17 10:34:47 -07:00
|
|
|
#include <array>
|
2018-10-23 16:28:17 -07:00
|
|
|
#include <atomic>
|
|
|
|
|
2018-03-29 18:06:51 -07:00
|
|
|
#include "common/logging/log.h"
|
2018-09-25 14:14:19 -07:00
|
|
|
#include "core/core.h"
|
2021-06-16 20:09:38 -07:00
|
|
|
#include "core/hid/emulated_controller.h"
|
|
|
|
#include "core/hid/hid_core.h"
|
|
|
|
#include "core/hid/hid_types.h"
|
2018-03-29 18:06:51 -07:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2021-09-28 20:42:50 -07:00
|
|
|
#include "core/hle/kernel/k_event.h"
|
2022-03-17 00:48:31 -07:00
|
|
|
#include "core/hle/service/mii/mii_manager.h"
|
2018-03-29 18:06:51 -07:00
|
|
|
#include "core/hle/service/nfp/nfp.h"
|
|
|
|
#include "core/hle/service/nfp/nfp_user.h"
|
|
|
|
|
2018-04-19 18:41:44 -07:00
|
|
|
namespace Service::NFP {
|
2018-10-23 16:28:17 -07:00
|
|
|
namespace ErrCodes {
|
2021-06-16 20:09:38 -07:00
|
|
|
constexpr ResultCode DeviceNotFound(ErrorModule::NFP, 64);
|
|
|
|
constexpr ResultCode WrongDeviceState(ErrorModule::NFP, 73);
|
|
|
|
constexpr ResultCode ApplicationAreaIsNotInitialized(ErrorModule::NFP, 128);
|
|
|
|
constexpr ResultCode ApplicationAreaExist(ErrorModule::NFP, 168);
|
2019-01-03 18:22:25 -08:00
|
|
|
} // namespace ErrCodes
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
constexpr u32 ApplicationAreaSize = 0xD8;
|
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IUser::IUser(Module::Interface& nfp_interface_, Core::System& system_)
|
2021-06-16 20:09:38 -07:00
|
|
|
: ServiceFramework{system_, "NFP::IUser"}, service_context{system_, service_name},
|
|
|
|
nfp_interface{nfp_interface_} {
|
2021-06-15 23:03:56 -07:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &IUser::Initialize, "Initialize"},
|
|
|
|
{1, &IUser::Finalize, "Finalize"},
|
|
|
|
{2, &IUser::ListDevices, "ListDevices"},
|
|
|
|
{3, &IUser::StartDetection, "StartDetection"},
|
|
|
|
{4, &IUser::StopDetection, "StopDetection"},
|
|
|
|
{5, &IUser::Mount, "Mount"},
|
|
|
|
{6, &IUser::Unmount, "Unmount"},
|
|
|
|
{7, &IUser::OpenApplicationArea, "OpenApplicationArea"},
|
|
|
|
{8, &IUser::GetApplicationArea, "GetApplicationArea"},
|
2021-06-16 20:09:38 -07:00
|
|
|
{9, &IUser::SetApplicationArea, "SetApplicationArea"},
|
2021-06-15 23:03:56 -07:00
|
|
|
{10, nullptr, "Flush"},
|
|
|
|
{11, nullptr, "Restore"},
|
2021-06-16 20:09:38 -07:00
|
|
|
{12, &IUser::CreateApplicationArea, "CreateApplicationArea"},
|
2021-06-15 23:03:56 -07:00
|
|
|
{13, &IUser::GetTagInfo, "GetTagInfo"},
|
|
|
|
{14, &IUser::GetRegisterInfo, "GetRegisterInfo"},
|
|
|
|
{15, &IUser::GetCommonInfo, "GetCommonInfo"},
|
|
|
|
{16, &IUser::GetModelInfo, "GetModelInfo"},
|
|
|
|
{17, &IUser::AttachActivateEvent, "AttachActivateEvent"},
|
|
|
|
{18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"},
|
|
|
|
{19, &IUser::GetState, "GetState"},
|
|
|
|
{20, &IUser::GetDeviceState, "GetDeviceState"},
|
|
|
|
{21, &IUser::GetNpadId, "GetNpadId"},
|
|
|
|
{22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"},
|
|
|
|
{23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"},
|
|
|
|
{24, nullptr, "RecreateApplicationArea"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
2018-03-29 18:06:51 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
availability_change_event = service_context.CreateEvent("IUser:AvailabilityChangeEvent");
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2021-04-09 16:56:11 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::Initialize(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_INFO(Service_NFC, "called");
|
|
|
|
|
|
|
|
state = State::Initialized;
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
nfp_interface.Initialize();
|
2018-04-21 22:04:24 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
}
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::Finalize(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_INFO(Service_NFP, "called");
|
|
|
|
|
|
|
|
state = State::NonInitialized;
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
nfp_interface.Finalize();
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
}
|
2018-11-25 22:06:13 -08:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::ListDevices(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_INFO(Service_NFP, "called");
|
|
|
|
|
|
|
|
std::vector<u64> devices;
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
devices.push_back(nfp_interface.GetHandle());
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
ctx.WriteBuffer(devices);
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(ResultSuccess);
|
2022-02-08 14:53:53 -08:00
|
|
|
rb.Push(static_cast<s32>(devices.size()));
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-11-25 22:06:13 -08:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::StartDetection(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
const auto nfp_protocol{rp.Pop<s32>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}, nfp_protocol={}", device_handle, nfp_protocol);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
2022-02-08 12:09:30 -08:00
|
|
|
const auto result = nfp_interface.StartDetection(nfp_protocol);
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
2018-04-21 22:04:24 -07:00
|
|
|
}
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::StopDetection(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
const auto result = nfp_interface.StopDetection();
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
2018-06-04 02:27:32 -07:00
|
|
|
}
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::Mount(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
const auto model_type{rp.PopEnum<ModelType>()};
|
|
|
|
const auto mount_target{rp.PopEnum<MountTarget>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}, model_type={}, mount_target={}", device_handle,
|
|
|
|
model_type, mount_target);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
const auto result = nfp_interface.Mount();
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::Unmount(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
const auto result = nfp_interface.Unmount();
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
2018-11-25 22:06:13 -08:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::OpenApplicationArea(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
const auto access_id{rp.Pop<u32>()};
|
2022-02-08 14:53:53 -08:00
|
|
|
LOG_WARNING(Service_NFP, "(STUBBED) called, device_handle={}, access_id={}", device_handle,
|
|
|
|
access_id);
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
const auto result = nfp_interface.OpenApplicationArea(access_id);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
std::vector<u8> data{};
|
|
|
|
const auto result = nfp_interface.GetApplicationArea(data);
|
|
|
|
ctx.WriteBuffer(data);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(result);
|
2022-02-08 14:53:53 -08:00
|
|
|
rb.Push(static_cast<u32>(data.size()));
|
2021-06-16 20:09:38 -07:00
|
|
|
return;
|
|
|
|
}
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
const auto data{ctx.ReadBuffer()};
|
2022-02-08 14:53:53 -08:00
|
|
|
LOG_WARNING(Service_NFP, "(STUBBED) called, device_handle={}, data_size={}", device_handle,
|
|
|
|
data.size());
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
const auto result = nfp_interface.SetApplicationArea(data);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
const auto access_id{rp.Pop<u32>()};
|
|
|
|
const auto data{ctx.ReadBuffer()};
|
2022-02-08 14:53:53 -08:00
|
|
|
LOG_WARNING(Service_NFP, "(STUBBED) called, device_handle={}, data_size={}, access_id={}",
|
|
|
|
device_handle, access_id, data.size());
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
const auto result = nfp_interface.CreateApplicationArea(access_id, data);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetTagInfo(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
TagInfo tag_info{};
|
|
|
|
const auto result = nfp_interface.GetTagInfo(tag_info);
|
|
|
|
ctx.WriteBuffer(tag_info);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetRegisterInfo(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
RegisterInfo register_info{};
|
|
|
|
const auto result = nfp_interface.GetRegisterInfo(register_info);
|
|
|
|
ctx.WriteBuffer(register_info);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetCommonInfo(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
CommonInfo common_info{};
|
|
|
|
const auto result = nfp_interface.GetCommonInfo(common_info);
|
|
|
|
ctx.WriteBuffer(common_info);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetModelInfo(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
ModelInfo model_info{};
|
|
|
|
const auto result = nfp_interface.GetModelInfo(model_info);
|
|
|
|
ctx.WriteBuffer(model_info);
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2022-02-08 14:53:53 -08:00
|
|
|
rb.Push(result);
|
2021-06-16 20:09:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::AttachActivateEvent(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2021-06-16 20:09:38 -07:00
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
rb.PushCopyObjects(nfp_interface.GetActivateEvent());
|
|
|
|
return;
|
|
|
|
}
|
2018-06-04 02:27:32 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-06-04 07:51:52 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::AttachDeactivateEvent(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2021-06-16 20:09:38 -07:00
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
|
|
|
LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
rb.PushCopyObjects(nfp_interface.GetDeactivateEvent());
|
|
|
|
return;
|
|
|
|
}
|
2018-06-04 07:51:52 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetState(Kernel::HLERequestContext& ctx) {
|
2022-02-08 12:09:30 -08:00
|
|
|
LOG_DEBUG(Service_NFC, "called");
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3, 0};
|
|
|
|
rb.Push(ResultSuccess);
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.PushEnum(state);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetDeviceState(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
2022-02-08 12:09:30 -08:00
|
|
|
LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
rb.PushEnum(nfp_interface.GetCurrentState());
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetNpadId(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2021-06-16 20:09:38 -07:00
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
2022-02-08 12:09:30 -08:00
|
|
|
LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
rb.PushEnum(nfp_interface.GetNpadId());
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2021-06-15 21:58:08 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::GetApplicationAreaSize(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto device_handle{rp.Pop<u64>()};
|
2022-02-08 12:09:30 -08:00
|
|
|
LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
|
2021-06-16 20:09:38 -07:00
|
|
|
|
|
|
|
// TODO(german77): Loop through all interfaces
|
|
|
|
if (device_handle == nfp_interface.GetHandle()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(ResultSuccess);
|
|
|
|
rb.Push(ApplicationAreaSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Handle not found, device_handle={}", device_handle);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ErrCodes::DeviceNotFound);
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
void IUser::AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) {
|
2021-06-16 20:09:38 -07:00
|
|
|
LOG_DEBUG(Service_NFP, "(STUBBED) called");
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
|
|
rb.Push(ResultSuccess);
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.PushCopyObjects(availability_change_event->GetReadableEvent());
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,
|
|
|
|
const char* name)
|
2021-06-16 20:09:38 -07:00
|
|
|
: ServiceFramework{system_, name}, module{std::move(module_)},
|
|
|
|
npad_id{Core::HID::NpadIdType::Player1}, service_context{system_, service_name} {
|
|
|
|
activate_event = service_context.CreateEvent("IUser:NFPActivateEvent");
|
|
|
|
deactivate_event = service_context.CreateEvent("IUser:NFPDeactivateEvent");
|
2021-06-15 23:03:56 -07:00
|
|
|
}
|
2018-10-23 16:28:17 -07:00
|
|
|
|
2021-06-15 23:03:56 -07:00
|
|
|
Module::Interface::~Interface() = default;
|
2018-04-21 22:04:24 -07:00
|
|
|
|
2018-04-22 19:02:18 -07:00
|
|
|
void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) {
|
2018-07-02 09:13:26 -07:00
|
|
|
LOG_DEBUG(Service_NFP, "called");
|
2018-11-25 22:06:13 -08:00
|
|
|
|
2018-04-21 22:04:24 -07:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-20 22:05:04 -07:00
|
|
|
rb.Push(ResultSuccess);
|
2021-06-16 20:09:38 -07:00
|
|
|
rb.PushIpcInterface<IUser>(*this, system);
|
2018-10-23 16:28:17 -07:00
|
|
|
}
|
|
|
|
|
2018-10-24 06:37:29 -07:00
|
|
|
bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
|
2022-02-13 09:59:47 -08:00
|
|
|
if (device_state != DeviceState::SearchingForTag) {
|
|
|
|
LOG_ERROR(Service_NFP, "Game is not looking for amiibos, current state {}", device_state);
|
2018-10-24 06:37:29 -07:00
|
|
|
return false;
|
2018-10-23 16:28:17 -07:00
|
|
|
}
|
2018-10-24 06:37:29 -07:00
|
|
|
|
2022-02-13 09:59:47 -08:00
|
|
|
constexpr auto tag_size = sizeof(NTAG215File);
|
|
|
|
constexpr auto tag_size_without_password = sizeof(NTAG215File) - sizeof(NTAG215Password);
|
|
|
|
|
|
|
|
std::vector<u8> amiibo_buffer = buffer;
|
|
|
|
|
|
|
|
if (amiibo_buffer.size() < tag_size_without_password) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong file size {}", buffer.size());
|
2021-06-16 20:09:38 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-13 09:59:47 -08:00
|
|
|
// Ensure it has the correct size
|
|
|
|
if (amiibo_buffer.size() != tag_size) {
|
|
|
|
amiibo_buffer.resize(tag_size, 0);
|
|
|
|
}
|
|
|
|
|
2022-02-08 14:53:53 -08:00
|
|
|
LOG_INFO(Service_NFP, "Amiibo detected");
|
2022-02-13 09:59:47 -08:00
|
|
|
std::memcpy(&tag_data, buffer.data(), tag_size);
|
2022-02-08 12:09:30 -08:00
|
|
|
|
|
|
|
if (!IsAmiiboValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-10 08:58:37 -08:00
|
|
|
// This value can't be dumped from a tag. Generate it
|
2022-02-13 09:59:47 -08:00
|
|
|
tag_data.password.PWD = GetTagPassword(tag_data.uuid);
|
2022-02-10 08:58:37 -08:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
device_state = DeviceState::TagFound;
|
|
|
|
activate_event->GetWritableEvent().Signal();
|
2018-10-24 06:37:29 -07:00
|
|
|
return true;
|
2018-10-23 16:28:17 -07:00
|
|
|
}
|
2018-11-26 15:34:07 -08:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
void Module::Interface::CloseAmiibo() {
|
|
|
|
LOG_INFO(Service_NFP, "Remove amiibo");
|
|
|
|
device_state = DeviceState::TagRemoved;
|
|
|
|
is_application_area_initialized = false;
|
|
|
|
application_area_id = 0;
|
|
|
|
application_area_data.clear();
|
|
|
|
deactivate_event->GetWritableEvent().Signal();
|
|
|
|
}
|
|
|
|
|
2022-02-08 12:09:30 -08:00
|
|
|
bool Module::Interface::IsAmiiboValid() const {
|
2022-02-10 08:58:37 -08:00
|
|
|
const auto& amiibo_data = tag_data.user_memory;
|
|
|
|
LOG_DEBUG(Service_NFP, "uuid_lock=0x{0:x}", tag_data.lock_bytes);
|
|
|
|
LOG_DEBUG(Service_NFP, "compability_container=0x{0:x}", tag_data.compability_container);
|
|
|
|
LOG_DEBUG(Service_NFP, "crypto_init=0x{0:x}", amiibo_data.crypto_init);
|
|
|
|
LOG_DEBUG(Service_NFP, "write_count={}", amiibo_data.write_count);
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_NFP, "character_id=0x{0:x}", amiibo_data.model_info.character_id);
|
|
|
|
LOG_DEBUG(Service_NFP, "character_variant={}", amiibo_data.model_info.character_variant);
|
|
|
|
LOG_DEBUG(Service_NFP, "amiibo_type={}", amiibo_data.model_info.amiibo_type);
|
|
|
|
LOG_DEBUG(Service_NFP, "model_number=0x{0:x}", amiibo_data.model_info.model_number);
|
|
|
|
LOG_DEBUG(Service_NFP, "series={}", amiibo_data.model_info.series);
|
|
|
|
LOG_DEBUG(Service_NFP, "fixed_value=0x{0:x}", amiibo_data.model_info.fixed);
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_NFP, "tag_dynamic_lock=0x{0:x}", tag_data.dynamic_lock);
|
|
|
|
LOG_DEBUG(Service_NFP, "tag_CFG0=0x{0:x}", tag_data.CFG0);
|
|
|
|
LOG_DEBUG(Service_NFP, "tag_CFG1=0x{0:x}", tag_data.CFG1);
|
2022-02-08 12:09:30 -08:00
|
|
|
|
|
|
|
// Check against all know constants on an amiibo binary
|
2022-02-10 08:58:37 -08:00
|
|
|
if (tag_data.lock_bytes != 0xE00F) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 08:58:37 -08:00
|
|
|
if (tag_data.compability_container != 0xEEFF10F1U) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 08:58:37 -08:00
|
|
|
if ((amiibo_data.crypto_init & 0xFF) != 0xA5) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 08:58:37 -08:00
|
|
|
if (amiibo_data.model_info.fixed != 0x02) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 08:58:37 -08:00
|
|
|
if ((tag_data.dynamic_lock & 0xFFFFFF) != 0x0F0001) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 08:58:37 -08:00
|
|
|
if (tag_data.CFG0 != 0x04000000U) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 08:58:37 -08:00
|
|
|
if (tag_data.CFG1 != 0x5F) {
|
2022-02-08 12:09:30 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
Kernel::KReadableEvent& Module::Interface::GetActivateEvent() const {
|
|
|
|
return activate_event->GetReadableEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
Kernel::KReadableEvent& Module::Interface::GetDeactivateEvent() const {
|
|
|
|
return deactivate_event->GetReadableEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::Initialize() {
|
|
|
|
device_state = DeviceState::Initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::Finalize() {
|
|
|
|
device_state = DeviceState::Unaviable;
|
|
|
|
is_application_area_initialized = false;
|
|
|
|
application_area_id = 0;
|
|
|
|
application_area_data.clear();
|
|
|
|
}
|
|
|
|
|
2022-02-08 12:09:30 -08:00
|
|
|
ResultCode Module::Interface::StartDetection(s32 protocol_) {
|
2021-06-16 20:09:38 -07:00
|
|
|
auto npad_device = system.HIDCore().GetEmulatedController(npad_id);
|
|
|
|
|
|
|
|
// TODO(german77): Add callback for when nfc data is available
|
|
|
|
|
|
|
|
if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) {
|
|
|
|
npad_device->SetPollingMode(Common::Input::PollingMode::NFC);
|
|
|
|
device_state = DeviceState::SearchingForTag;
|
2022-02-08 12:09:30 -08:00
|
|
|
protocol = protocol_;
|
2021-06-16 20:09:38 -07:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::StopDetection() {
|
|
|
|
auto npad_device = system.HIDCore().GetEmulatedController(npad_id);
|
|
|
|
npad_device->SetPollingMode(Common::Input::PollingMode::Active);
|
|
|
|
|
|
|
|
if (device_state == DeviceState::TagFound || device_state == DeviceState::TagMounted) {
|
|
|
|
CloseAmiibo();
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
if (device_state == DeviceState::SearchingForTag || device_state == DeviceState::TagRemoved) {
|
|
|
|
device_state = DeviceState::Initialized;
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::Mount() {
|
|
|
|
if (device_state == DeviceState::TagFound) {
|
|
|
|
device_state = DeviceState::TagMounted;
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::Unmount() {
|
|
|
|
if (device_state == DeviceState::TagMounted) {
|
|
|
|
is_application_area_initialized = false;
|
|
|
|
application_area_id = 0;
|
|
|
|
application_area_data.clear();
|
|
|
|
device_state = DeviceState::TagFound;
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::GetTagInfo(TagInfo& tag_info) const {
|
|
|
|
if (device_state == DeviceState::TagFound || device_state == DeviceState::TagMounted) {
|
|
|
|
tag_info = {
|
2022-02-10 08:58:37 -08:00
|
|
|
.uuid = tag_data.uuid,
|
|
|
|
.uuid_length = static_cast<u8>(tag_data.uuid.size()),
|
2022-02-08 12:09:30 -08:00
|
|
|
.protocol = protocol,
|
2022-02-10 08:58:37 -08:00
|
|
|
.tag_type = static_cast<u32>(tag_data.user_memory.model_info.amiibo_type),
|
2021-06-16 20:09:38 -07:00
|
|
|
};
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::GetCommonInfo(CommonInfo& common_info) const {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read this data from the amiibo save file
|
|
|
|
common_info = {
|
|
|
|
.last_write_year = 2022,
|
|
|
|
.last_write_month = 2,
|
|
|
|
.last_write_day = 7,
|
2022-02-10 08:58:37 -08:00
|
|
|
.write_counter = tag_data.user_memory.write_count,
|
2021-06-16 20:09:38 -07:00
|
|
|
.version = 1,
|
|
|
|
.application_area_size = ApplicationAreaSize,
|
|
|
|
};
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::GetModelInfo(ModelInfo& model_info) const {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
2022-02-10 08:58:37 -08:00
|
|
|
model_info = tag_data.user_memory.model_info;
|
2021-06-16 20:09:38 -07:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::GetRegisterInfo(RegisterInfo& register_info) const {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
Service::Mii::MiiManager manager;
|
|
|
|
|
|
|
|
// Read this data from the amiibo save file
|
|
|
|
register_info = {
|
|
|
|
.mii_char_info = manager.BuildDefault(0),
|
|
|
|
.first_write_year = 2022,
|
|
|
|
.first_write_month = 2,
|
|
|
|
.first_write_day = 7,
|
|
|
|
.amiibo_name = {'Y', 'u', 'z', 'u', 'A', 'm', 'i', 'i', 'b', 'o', 0},
|
|
|
|
.unknown = {},
|
|
|
|
};
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::OpenApplicationArea(u32 access_id) {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
2022-02-08 12:09:30 -08:00
|
|
|
if (AmiiboApplicationDataExist(access_id)) {
|
|
|
|
application_area_data = LoadAmiiboApplicationData(access_id);
|
|
|
|
application_area_id = access_id;
|
|
|
|
is_application_area_initialized = true;
|
|
|
|
}
|
2021-06-16 20:09:38 -07:00
|
|
|
if (!is_application_area_initialized) {
|
2022-02-08 14:53:53 -08:00
|
|
|
LOG_WARNING(Service_NFP, "Application area is not initialized");
|
2021-06-16 20:09:38 -07:00
|
|
|
return ErrCodes::ApplicationAreaIsNotInitialized;
|
|
|
|
}
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::GetApplicationArea(std::vector<u8>& data) const {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
if (!is_application_area_initialized) {
|
|
|
|
LOG_ERROR(Service_NFP, "Application area is not initialized");
|
|
|
|
return ErrCodes::ApplicationAreaIsNotInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = application_area_data;
|
|
|
|
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::SetApplicationArea(const std::vector<u8>& data) {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
|
|
|
if (!is_application_area_initialized) {
|
|
|
|
LOG_ERROR(Service_NFP, "Application area is not initialized");
|
|
|
|
return ErrCodes::ApplicationAreaIsNotInitialized;
|
|
|
|
}
|
|
|
|
application_area_data = data;
|
2022-02-08 12:09:30 -08:00
|
|
|
SaveAmiiboApplicationData(application_area_id, application_area_data);
|
2021-06-16 20:09:38 -07:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode Module::Interface::CreateApplicationArea(u32 access_id, const std::vector<u8>& data) {
|
|
|
|
if (device_state != DeviceState::TagMounted) {
|
|
|
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
|
|
|
return ErrCodes::WrongDeviceState;
|
|
|
|
}
|
2022-02-08 12:09:30 -08:00
|
|
|
if (AmiiboApplicationDataExist(access_id)) {
|
|
|
|
LOG_ERROR(Service_NFP, "Application area already exist");
|
|
|
|
return ErrCodes::ApplicationAreaExist;
|
|
|
|
}
|
2021-06-16 20:09:38 -07:00
|
|
|
application_area_data = data;
|
|
|
|
application_area_id = access_id;
|
2022-02-08 12:09:30 -08:00
|
|
|
SaveAmiiboApplicationData(application_area_id, application_area_data);
|
2021-06-16 20:09:38 -07:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2022-02-08 12:09:30 -08:00
|
|
|
bool Module::Interface::AmiiboApplicationDataExist(u32 access_id) const {
|
|
|
|
// TODO(german77): Check if file exist
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-10 08:58:37 -08:00
|
|
|
std::vector<u8> Module::Interface::LoadAmiiboApplicationData(u32 access_id) const {
|
2022-02-08 12:09:30 -08:00
|
|
|
// TODO(german77): Read file
|
|
|
|
std::vector<u8> data(ApplicationAreaSize);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::SaveAmiiboApplicationData(u32 access_id,
|
|
|
|
const std::vector<u8>& data) const {
|
|
|
|
// TODO(german77): Save file
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
u64 Module::Interface::GetHandle() const {
|
|
|
|
// Generate a handle based of the npad id
|
|
|
|
return static_cast<u64>(npad_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceState Module::Interface::GetCurrentState() const {
|
|
|
|
return device_state;
|
2018-10-23 16:28:17 -07:00
|
|
|
}
|
2018-11-27 06:18:29 -08:00
|
|
|
|
2021-06-16 20:09:38 -07:00
|
|
|
Core::HID::NpadIdType Module::Interface::GetNpadId() const {
|
|
|
|
return npad_id;
|
2018-03-29 18:06:51 -07:00
|
|
|
}
|
|
|
|
|
2022-02-10 08:58:37 -08:00
|
|
|
u32 Module::Interface::GetTagPassword(const TagUuid& uuid) const {
|
|
|
|
// Verifiy that the generated password is correct
|
|
|
|
u32 password = 0xAA ^ (uuid[1] ^ uuid[3]);
|
|
|
|
password &= (0x55 ^ (uuid[2] ^ uuid[4])) << 8;
|
|
|
|
password &= (0xAA ^ (uuid[3] ^ uuid[5])) << 16;
|
|
|
|
password &= (0x55 ^ (uuid[4] ^ uuid[6])) << 24;
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
2019-09-21 02:03:20 -07:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
|
2018-03-29 18:06:51 -07:00
|
|
|
auto module = std::make_shared<Module>();
|
2019-09-21 02:03:20 -07:00
|
|
|
std::make_shared<NFP_User>(module, system)->InstallAsService(service_manager);
|
2018-03-29 18:06:51 -07:00
|
|
|
}
|
|
|
|
|
2018-04-19 18:41:44 -07:00
|
|
|
} // namespace Service::NFP
|