2021-03-18 21:40:20 +01:00
|
|
|
|
using Ryujinx.Common.Memory;
|
|
|
|
|
using Ryujinx.Cpu;
|
|
|
|
|
using Ryujinx.HLE.Exceptions;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid;
|
2019-09-19 02:45:11 +02:00
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
|
|
|
|
|
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
using System;
|
2021-03-18 21:40:20 +01:00
|
|
|
|
using System.Buffers.Binary;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
|
|
|
|
{
|
|
|
|
|
class IUser : IpcService
|
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
private ulong _appletResourceUserId;
|
|
|
|
|
private ulong _mcuVersionData;
|
|
|
|
|
private byte[] _mcuData;
|
|
|
|
|
|
2019-06-28 13:08:23 +02:00
|
|
|
|
private State _state = State.NonInitialized;
|
|
|
|
|
|
|
|
|
|
private KEvent _availabilityChangeEvent;
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
private CancellationTokenSource _cancelTokenSource;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
public IUser() { }
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(0)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// Initialize(u64, u64, pid, buffer<unknown, 5>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
_appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
|
_mcuVersionData = context.RequestData.ReadUInt64();
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
|
|
|
|
long inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
|
long inputSize = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
_mcuData = new byte[inputSize];
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Memory.Read((ulong)inputPosition, _mcuData);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
// TODO: The mcuData buffer seems to contains entries with a size of 0x40 bytes each. Usage of the data needs to be determined.
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
// TODO: Handle this in a controller class directly.
|
|
|
|
|
// Every functions which use the Handle call nn::hid::system::GetXcdHandleForNpadWithNfc().
|
|
|
|
|
NfpDevice devicePlayer1 = new NfpDevice
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2020-04-03 02:10:02 +02:00
|
|
|
|
NpadIdType = NpadIdType.Player1,
|
|
|
|
|
Handle = HidUtils.GetIndexFromNpadIdType(NpadIdType.Player1),
|
2021-03-18 21:40:20 +01:00
|
|
|
|
State = NfpDeviceState.Initialized
|
2019-06-28 13:08:23 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Device.System.NfpDevices.Add(devicePlayer1);
|
|
|
|
|
|
|
|
|
|
// TODO: It mounts 0x8000000000000020 save data and stores a random generate value inside. Usage of the data needs to be determined.
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
|
|
|
|
_state = State.Initialized;
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(1)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// Finalize()
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode Finalize(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if (_state == State.Initialized)
|
|
|
|
|
{
|
|
|
|
|
if (_cancelTokenSource != null)
|
|
|
|
|
{
|
|
|
|
|
_cancelTokenSource.Cancel();
|
|
|
|
|
}
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
// NOTE: All events are destroyed here.
|
|
|
|
|
context.Device.System.NfpDevices.Clear();
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
_state = State.NonInitialized;
|
|
|
|
|
}
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(2)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// ListDevices() -> (u32, buffer<unknown, 0xa>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode ListDevices(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
|
|
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
return ResultCode.WrongArgument;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long outputPosition = context.Request.RecvListBuff[0].Position;
|
2021-03-18 21:40:20 +01:00
|
|
|
|
long outputSize = context.Request.RecvListBuff[0].Size;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.DeviceNotFound;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
|
|
|
|
|
|
|
|
|
if (CheckNfcIsEnabled() == ResultCode.Success)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
context.Memory.Write((ulong)(outputPosition + (i * sizeof(long))), (uint)context.Device.System.NfpDevices[i].Handle);
|
|
|
|
|
}
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.ResponseData.Write(context.Device.System.NfpDevices.Count);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(0);
|
|
|
|
|
}
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(3)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// StartDetection(bytes<8, 4>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode StartDetection(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
context.Device.System.NfpDevices[i].State = NfpDeviceState.SearchingForTag;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cancelTokenSource = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_cancelTokenSource.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagFound)
|
|
|
|
|
{
|
|
|
|
|
context.Device.System.NfpDevices[i].SignalActivate();
|
|
|
|
|
Thread.Sleep(50); // NOTE: Simulate amiibo scanning delay.
|
|
|
|
|
context.Device.System.NfpDevices[i].SignalDeactivate();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, _cancelTokenSource.Token);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(4)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// StopDetection(bytes<8, 4>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode StopDetection(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_cancelTokenSource != null)
|
|
|
|
|
{
|
|
|
|
|
_cancelTokenSource.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
context.Device.System.NfpDevices[i].State = NfpDeviceState.Initialized;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(5)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// Mount(bytes<8, 4>, u32, u32)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode Mount(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
UserManager.DeviceType deviceType = (UserManager.DeviceType)context.RequestData.ReadUInt32();
|
|
|
|
|
MountTarget mountTarget = (MountTarget)context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
if (deviceType != 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.WrongArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (((uint)mountTarget & 3) == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.WrongArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Found how the MountTarget is handled.
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagFound)
|
|
|
|
|
{
|
|
|
|
|
// NOTE: This mount the amiibo data, which isn't needed in our case.
|
|
|
|
|
|
|
|
|
|
context.Device.System.NfpDevices[i].State = NfpDeviceState.TagMounted;
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(6)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// Unmount(bytes<8, 4>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode Unmount(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// NOTE: This mount the amiibo data, which isn't needed in our case.
|
|
|
|
|
|
|
|
|
|
context.Device.System.NfpDevices[i].State = NfpDeviceState.TagFound;
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(7)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// OpenApplicationArea(bytes<8, 4>, u32)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode OpenApplicationArea(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint applicationAreaId = context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
bool isOpened = false;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
isOpened = VirtualAmiibo.OpenApplicationArea(context.Device.System.NfpDevices[i].AmiiboId, applicationAreaId);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isOpened)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.ApplicationAreaIsNull;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(8)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetApplicationArea(bytes<8, 4>) -> (u32, buffer<unknown, 6>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetApplicationArea(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long outputPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
long outputSize = context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
|
|
|
|
|
|
|
|
|
uint size = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
byte[] applicationArea = VirtualAmiibo.GetApplicationArea(context.Device.System.NfpDevices[i].AmiiboId);
|
|
|
|
|
|
|
|
|
|
context.Memory.Write((ulong)outputPosition, applicationArea);
|
|
|
|
|
|
|
|
|
|
size = (uint)applicationArea.Length;
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.ApplicationAreaIsNull;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(size);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(9)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// SetApplicationArea(bytes<8, 4>, buffer<unknown, 5>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode SetApplicationArea(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
|
long inputSize = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
|
|
|
|
byte[] applicationArea = new byte[inputSize];
|
|
|
|
|
|
|
|
|
|
context.Memory.Read((ulong)inputPosition, applicationArea);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
VirtualAmiibo.SetApplicationArea(context.Device.System.NfpDevices[i].AmiiboId, applicationArea);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(10)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// Flush(bytes<8, 4>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode Flush(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: Since we handle amiibo through VirtualAmiibo, we don't have to flush anything in our case.
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(11)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// Restore(bytes<8, 4>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode Restore(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(12)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// CreateApplicationArea(bytes<8, 4>, u32, buffer<unknown, 5>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode CreateApplicationArea(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint applicationAreaId = context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
long inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
|
long inputSize = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
|
|
|
|
byte[] applicationArea = new byte[inputSize];
|
|
|
|
|
|
|
|
|
|
context.Memory.Read((ulong)inputPosition, applicationArea);
|
|
|
|
|
|
|
|
|
|
bool isCreated = false;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
isCreated = VirtualAmiibo.CreateApplicationArea(context.Device.System.NfpDevices[i].AmiiboId, applicationAreaId, applicationArea);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isCreated)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.ApplicationAreaIsNull;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(13)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetTagInfo(bytes<8, 4>) -> buffer<unknown<0x58>, 0x1a>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetTagInfo(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.WrongArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long outputPosition = context.Request.RecvListBuff[0].Position;
|
|
|
|
|
|
|
|
|
|
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Marshal.SizeOf(typeof(TagInfo)));
|
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(TagInfo)));
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted || context.Device.System.NfpDevices[i].State == NfpDeviceState.TagFound)
|
|
|
|
|
{
|
|
|
|
|
byte[] Uuid = VirtualAmiibo.GenerateUuid(context.Device.System.NfpDevices[i].AmiiboId, context.Device.System.NfpDevices[i].UseRandomUuid);
|
|
|
|
|
|
|
|
|
|
if (Uuid.Length > AmiiboConstants.UuidMaxLength)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TagInfo tagInfo = new TagInfo
|
|
|
|
|
{
|
|
|
|
|
UuidLength = (byte)Uuid.Length,
|
|
|
|
|
Reserved1 = new Array21<byte>(),
|
|
|
|
|
Protocol = uint.MaxValue, // All Protocol
|
|
|
|
|
TagType = uint.MaxValue, // All Type
|
|
|
|
|
Reserved2 = new Array6<byte>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Uuid.CopyTo(tagInfo.Uuid.ToSpan());
|
|
|
|
|
|
|
|
|
|
context.Memory.Write((ulong)outputPosition, tagInfo);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(14)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetRegisterInfo(bytes<8, 4>) -> buffer<unknown<0x100>, 0x1a>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetRegisterInfo(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.WrongArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long outputPosition = context.Request.RecvListBuff[0].Position;
|
|
|
|
|
|
|
|
|
|
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Marshal.SizeOf(typeof(RegisterInfo)));
|
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(RegisterInfo)));
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
RegisterInfo registerInfo = VirtualAmiibo.GetRegisterInfo(context.Device.System.NfpDevices[i].AmiiboId);
|
|
|
|
|
|
|
|
|
|
context.Memory.Write((ulong)outputPosition, registerInfo);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(15)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetCommonInfo(bytes<8, 4>) -> buffer<unknown<0x40>, 0x1a>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetCommonInfo(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.WrongArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long outputPosition = context.Request.RecvListBuff[0].Position;
|
|
|
|
|
|
|
|
|
|
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Marshal.SizeOf(typeof(CommonInfo)));
|
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(CommonInfo)));
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
CommonInfo commonInfo = VirtualAmiibo.GetCommonInfo(context.Device.System.NfpDevices[i].AmiiboId);
|
|
|
|
|
|
|
|
|
|
context.Memory.Write((ulong)outputPosition, commonInfo);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(16)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetModelInfo(bytes<8, 4>) -> buffer<unknown<0x40>, 0x1a>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetModelInfo(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
ResultCode resultCode = CheckNfcIsEnabled();
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.WrongArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long outputPosition = context.Request.RecvListBuff[0].Position;
|
|
|
|
|
|
|
|
|
|
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Marshal.SizeOf(typeof(ModelInfo)));
|
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(ModelInfo)));
|
|
|
|
|
|
|
|
|
|
uint deviceHandle = (uint)context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
if (context.Device.System.NfpDevices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.DeviceNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].Handle == (PlayerIndex)deviceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagRemoved)
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.TagNotFound;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (context.Device.System.NfpDevices[i].State == NfpDeviceState.TagMounted)
|
|
|
|
|
{
|
|
|
|
|
ModelInfo modelInfo = new ModelInfo
|
|
|
|
|
{
|
|
|
|
|
Reserved = new Array57<byte>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
modelInfo.CharacterId = BinaryPrimitives.ReverseEndianness(ushort.Parse(context.Device.System.NfpDevices[i].AmiiboId.Substring(0, 4), NumberStyles.HexNumber));
|
|
|
|
|
modelInfo.CharacterVariant = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.Substring(4, 2), NumberStyles.HexNumber);
|
|
|
|
|
modelInfo.Series = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.Substring(12, 2), NumberStyles.HexNumber);
|
|
|
|
|
modelInfo.ModelNumber = ushort.Parse(context.Device.System.NfpDevices[i].AmiiboId.Substring(8, 4), NumberStyles.HexNumber);
|
|
|
|
|
modelInfo.Type = byte.Parse(context.Device.System.NfpDevices[i].AmiiboId.Substring(6, 2), NumberStyles.HexNumber);
|
|
|
|
|
|
|
|
|
|
context.Memory.Write((ulong)outputPosition, modelInfo);
|
|
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultCode = ResultCode.WrongDeviceState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCode;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(17)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// AttachActivateEvent(bytes<8, 4>) -> handle<copy>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode AttachActivateEvent(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
|
|
|
|
uint deviceHandle = context.RequestData.ReadUInt32();
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if ((uint)context.Device.System.NfpDevices[i].Handle == deviceHandle)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Device.System.NfpDevices[i].ActivateEvent = new KEvent(context.Device.System.KernelContext);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.NfpDevices[i].ActivateEvent.ReadableEvent, out int activateEventHandle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(activateEventHandle);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.DeviceNotFound;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(18)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// AttachDeactivateEvent(bytes<8, 4>) -> handle<copy>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode AttachDeactivateEvent(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
|
|
|
|
uint deviceHandle = context.RequestData.ReadUInt32();
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if ((uint)context.Device.System.NfpDevices[i].Handle == deviceHandle)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Device.System.NfpDevices[i].DeactivateEvent = new KEvent(context.Device.System.KernelContext);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.NfpDevices[i].DeactivateEvent.ReadableEvent, out int deactivateEventHandle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(deactivateEventHandle);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.DeviceNotFound;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(19)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetState() -> u32
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetState(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write((int)_state);
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(20)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetDeviceState(bytes<8, 4>) -> u32
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetDeviceState(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
|
|
|
|
uint deviceHandle = context.RequestData.ReadUInt32();
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if ((uint)context.Device.System.NfpDevices[i].Handle == deviceHandle)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if (context.Device.System.NfpDevices[i].State > NfpDeviceState.Finalized)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write((uint)context.Device.System.NfpDevices[i].State);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.ResponseData.Write((uint)NfpDeviceState.Unavailable);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.DeviceNotFound;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(21)]
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// GetNpadId(bytes<8, 4>) -> u32
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetNpadId(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
|
|
|
|
uint deviceHandle = context.RequestData.ReadUInt32();
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
for (int i = 0; i < context.Device.System.NfpDevices.Count; i++)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if ((uint)context.Device.System.NfpDevices[i].Handle == deviceHandle)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.ResponseData.Write((uint)HidUtils.GetNpadIdTypeFromIndex(context.Device.System.NfpDevices[i].Handle));
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.DeviceNotFound;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(22)]
|
2021-03-18 21:40:20 +01:00
|
|
|
|
// GetApplicationAreaSize() -> u32
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode GetApplicationAreaSize(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.ResponseData.Write(AmiiboConstants.ApplicationAreaSize);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(23)] // 3.0.0+
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// AttachAvailabilityChangeEvent() -> handle<copy>
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode AttachAvailabilityChangeEvent(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2021-03-18 21:40:20 +01:00
|
|
|
|
_availabilityChangeEvent = new KEvent(context.Device.System.KernelContext);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(_availabilityChangeEvent.ReadableEvent, out int availabilityChangeEventHandle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 21:40:20 +01:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(availabilityChangeEventHandle);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
|
return ResultCode.Success;
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
|
[Command(24)] // 3.0.0+
|
2019-06-28 13:08:23 +02:00
|
|
|
|
// RecreateApplicationArea(bytes<8, 4>, u32, buffer<unknown, 5>)
|
2019-07-14 21:04:38 +02:00
|
|
|
|
public ResultCode RecreateApplicationArea(ServiceCtx context)
|
2019-06-28 13:08:23 +02:00
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
2021-03-18 21:40:20 +01:00
|
|
|
|
|
|
|
|
|
private ResultCode CheckNfcIsEnabled()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Call nn::settings::detail::GetNfcEnableFlag when it will be implemented.
|
|
|
|
|
return true ? ResultCode.Success : ResultCode.NfcDisabled;
|
|
|
|
|
}
|
2019-06-28 13:08:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|