nfc/nfp: Implement ISystemManager and ISystem (#2381)

* nfc/nfp: Implement ISystemManager and ISystem

This PR add permission levels for `nfc` and `nfp` services:
- `nfc`: `CreateUserInterface` and `CreateSystemInterface` are implemented.
- `INfc`: `Initialize` and `IsNfcEnabled` calls are stubbed.
- `nfp`: `CreateDebugInterface` and `CreateSystemInterface` are implemented.
- `INfp`: `GetRegisterInfo2` for `IDebug` and `ISystem` are implemented.

* Addresses gdkchan feedback
This commit is contained in:
Ac_K 2021-06-24 01:05:40 +02:00 committed by GitHub
parent aea7a6631c
commit 55e0c71489
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 153 additions and 33 deletions

View file

@ -38,6 +38,7 @@ namespace Ryujinx.Common.Logging
ServiceLdr, ServiceLdr,
ServiceLm, ServiceLm,
ServiceMm, ServiceMm,
ServiceNfc,
ServiceNfp, ServiceNfp,
ServiceNgct, ServiceNgct,
ServiceNifm, ServiceNifm,

View file

@ -22,7 +22,7 @@ using Ryujinx.HLE.HOS.Services.Arp;
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer; using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
using Ryujinx.HLE.HOS.Services.Caps; using Ryujinx.HLE.HOS.Services.Caps;
using Ryujinx.HLE.HOS.Services.Mii; using Ryujinx.HLE.HOS.Services.Mii;
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager; using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
using Ryujinx.HLE.HOS.Services.Nv; using Ryujinx.HLE.HOS.Services.Nv;
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl; using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl;
using Ryujinx.HLE.HOS.Services.Pcv.Bpc; using Ryujinx.HLE.HOS.Services.Pcv.Bpc;

View file

@ -1,8 +1,19 @@
namespace Ryujinx.HLE.HOS.Services.Nfc using Ryujinx.HLE.HOS.Services.Nfc.NfcManager;
namespace Ryujinx.HLE.HOS.Services.Nfc
{ {
[Service("nfc:sys")] [Service("nfc:sys")]
class ISystemManager : IpcService class ISystemManager : IpcService
{ {
public ISystemManager(ServiceCtx context) { } public ISystemManager(ServiceCtx context) { }
[CommandHipc(0)]
// CreateSystemInterface() -> object<nn::nfc::detail::ISystem>
public ResultCode CreateSystemInterface(ServiceCtx context)
{
MakeObject(context, new INfc(NfcPermissionLevel.System));
return ResultCode.Success;
}
} }
} }

View file

@ -1,8 +1,19 @@
namespace Ryujinx.HLE.HOS.Services.Nfc using Ryujinx.HLE.HOS.Services.Nfc.NfcManager;
namespace Ryujinx.HLE.HOS.Services.Nfc
{ {
[Service("nfc:user")] [Service("nfc:user")]
class IUserManager : IpcService class IUserManager : IpcService
{ {
public IUserManager(ServiceCtx context) { } public IUserManager(ServiceCtx context) { }
[CommandHipc(0)]
// CreateUserInterface() -> object<nn::nfc::detail::IUser>
public ResultCode CreateUserInterface(ServiceCtx context)
{
MakeObject(context, new INfc(NfcPermissionLevel.User));
return ResultCode.Success;
}
} }
} }

View file

@ -0,0 +1,37 @@
using Ryujinx.Common.Logging;
namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager
{
class INfc : IpcService
{
private NfcPermissionLevel _permissionLevel;
public INfc(NfcPermissionLevel permissionLevel)
{
_permissionLevel = permissionLevel;
}
[CommandHipc(0)]
[CommandHipc(400)] // 4.0.0+
// Initialize()
public ResultCode Initialize(ServiceCtx context)
{
Logger.Stub?.PrintStub(LogClass.ServiceNfc, new { _permissionLevel });
return ResultCode.Success;
}
[CommandHipc(3)]
[CommandHipc(403)] // 4.0.0+
// IsNfcEnabled() -> b8
public ResultCode IsNfcEnabled(ServiceCtx context)
{
// NOTE: Write false value here could make nfp service not called.
context.ResponseData.Write(true);
Logger.Stub?.PrintStub(LogClass.ServiceNfc, new { _permissionLevel });
return ResultCode.Success;
}
}
}

View file

@ -0,0 +1,8 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager
{
enum NfcPermissionLevel
{
User,
System
}
}

View file

@ -1,8 +1,19 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{ {
[Service("nfp:dbg")] [Service("nfp:dbg")]
class IAmManager : IpcService class IAmManager : IpcService
{ {
public IAmManager(ServiceCtx context) { } public IAmManager(ServiceCtx context) { }
[CommandHipc(0)]
// CreateDebugInterface() -> object<nn::nfp::detail::IDebug>
public ResultCode CreateDebugInterface(ServiceCtx context)
{
MakeObject(context, new INfp(NfpPermissionLevel.Debug));
return ResultCode.Success;
}
} }
} }

View file

@ -1,8 +1,19 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{ {
[Service("nfp:sys")] [Service("nfp:sys")]
class ISystemManager : IpcService class ISystemManager : IpcService
{ {
public ISystemManager(ServiceCtx context) { } public ISystemManager(ServiceCtx context) { }
[CommandHipc(0)]
// CreateSystemInterface() -> object<nn::nfp::detail::ISystem>
public ResultCode CreateSystemInterface(ServiceCtx context)
{
MakeObject(context, new INfp(NfpPermissionLevel.System));
return ResultCode.Success;
}
} }
} }

View file

@ -1,4 +1,6 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{ {
[Service("nfp:user")] [Service("nfp:user")]
class IUserManager : IpcService class IUserManager : IpcService
@ -7,9 +9,9 @@
[CommandHipc(0)] [CommandHipc(0)]
// CreateUserInterface() -> object<nn::nfp::detail::IUser> // CreateUserInterface() -> object<nn::nfp::detail::IUser>
public ResultCode GetUserInterface(ServiceCtx context) public ResultCode CreateUserInterface(ServiceCtx context)
{ {
MakeObject(context, new IUser()); MakeObject(context, new INfp(NfpPermissionLevel.User));
return ResultCode.Success; return ResultCode.Success;
} }

View file

@ -6,7 +6,7 @@ using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Hid; using Ryujinx.HLE.HOS.Services.Hid;
using Ryujinx.HLE.HOS.Services.Hid.HidServer; using Ryujinx.HLE.HOS.Services.Hid.HidServer;
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager; using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
using System; using System;
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Globalization; using System.Globalization;
@ -16,7 +16,7 @@ using System.Threading.Tasks;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{ {
class IUser : IpcService class INfp : IpcService
{ {
private ulong _appletResourceUserId; private ulong _appletResourceUserId;
private ulong _mcuVersionData; private ulong _mcuVersionData;
@ -28,7 +28,12 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
private CancellationTokenSource _cancelTokenSource; private CancellationTokenSource _cancelTokenSource;
public IUser() { } private NfpPermissionLevel _permissionLevel;
public INfp(NfpPermissionLevel permissionLevel)
{
_permissionLevel = permissionLevel;
}
[CommandHipc(0)] [CommandHipc(0)]
// Initialize(u64, u64, pid, buffer<unknown, 5>) // Initialize(u64, u64, pid, buffer<unknown, 5>)
@ -214,7 +219,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
} }
uint deviceHandle = (uint)context.RequestData.ReadUInt64(); uint deviceHandle = (uint)context.RequestData.ReadUInt64();
UserManager.DeviceType deviceType = (UserManager.DeviceType)context.RequestData.ReadUInt32(); DeviceType deviceType = (DeviceType)context.RequestData.ReadUInt32();
MountTarget mountTarget = (MountTarget)context.RequestData.ReadUInt32(); MountTarget mountTarget = (MountTarget)context.RequestData.ReadUInt32();
if (deviceType != 0) if (deviceType != 0)
@ -969,6 +974,20 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
throw new ServiceNotImplementedException(this, context, false); throw new ServiceNotImplementedException(this, context, false);
} }
[CommandHipc(102)]
// GetRegisterInfo2(bytes<8, 4>) -> buffer<unknown<0x100>, 0x1a>
public ResultCode GetRegisterInfo2(ServiceCtx context)
{
// TODO: Find the differencies between IUser and ISystem/IDebug.
if (_permissionLevel == NfpPermissionLevel.Debug || _permissionLevel == NfpPermissionLevel.System)
{
return GetRegisterInfo(context);
}
return ResultCode.DeviceNotFound;
}
private ResultCode CheckNfcIsEnabled() private ResultCode CheckNfcIsEnabled()
{ {
// TODO: Call nn::settings::detail::GetNfcEnableFlag when it will be implemented. // TODO: Call nn::settings::detail::GetNfcEnableFlag when it will be implemented.

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
static class AmiiboConstants static class AmiiboConstants
{ {

View file

@ -1,7 +1,7 @@
using Ryujinx.Common.Memory; using Ryujinx.Common.Memory;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
[StructLayout(LayoutKind.Sequential, Size = 0x40)] [StructLayout(LayoutKind.Sequential, Size = 0x40)]
struct CommonInfo struct CommonInfo

View file

@ -0,0 +1,7 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{
enum DeviceType : uint
{
Amiibo
}
}

View file

@ -1,7 +1,7 @@
using Ryujinx.Common.Memory; using Ryujinx.Common.Memory;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
[StructLayout(LayoutKind.Sequential, Size = 0x40)] [StructLayout(LayoutKind.Sequential, Size = 0x40)]
struct ModelInfo struct ModelInfo

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
enum MountTarget : uint enum MountTarget : uint
{ {

View file

@ -1,7 +1,7 @@
using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Hid; using Ryujinx.HLE.HOS.Services.Hid;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
class NfpDevice class NfpDevice
{ {

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
enum NfpDeviceState enum NfpDeviceState
{ {

View file

@ -0,0 +1,9 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{
enum NfpPermissionLevel
{
Debug,
User,
System
}
}

View file

@ -2,7 +2,7 @@
using Ryujinx.HLE.HOS.Services.Mii.Types; using Ryujinx.HLE.HOS.Services.Mii.Types;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
[StructLayout(LayoutKind.Sequential, Size = 0x100)] [StructLayout(LayoutKind.Sequential, Size = 0x100)]
struct RegisterInfo struct RegisterInfo
@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager
public ushort FirstWriteYear; public ushort FirstWriteYear;
public byte FirstWriteMonth; public byte FirstWriteMonth;
public byte FirstWriteDay; public byte FirstWriteDay;
public Array11<byte> Nickname; public Array41<byte> Nickname;
public byte FontRegion; public byte FontRegion;
public Array64<byte> Reserved1; public Array64<byte> Reserved1;
public Array58<byte> Reserved2; public Array58<byte> Reserved2;

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
enum State enum State
{ {

View file

@ -1,7 +1,7 @@
using Ryujinx.Common.Memory; using Ryujinx.Common.Memory;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
[StructLayout(LayoutKind.Sequential, Size = 0x58)] [StructLayout(LayoutKind.Sequential, Size = 0x58)]
struct TagInfo struct TagInfo

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
{ {
struct VirtualAmiiboFile struct VirtualAmiiboFile
{ {

View file

@ -1,7 +0,0 @@
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager
{
enum DeviceType : uint
{
Amiibo
}
}

View file

@ -2,7 +2,7 @@
using Ryujinx.Common.Memory; using Ryujinx.Common.Memory;
using Ryujinx.HLE.HOS.Services.Mii; using Ryujinx.HLE.HOS.Services.Mii;
using Ryujinx.HLE.HOS.Services.Mii.Types; using Ryujinx.HLE.HOS.Services.Mii.Types;
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.UserManager; using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;