IRequest.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using System;
  6. namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
  7. {
  8. class IRequest : IpcService
  9. {
  10. private enum RequestState
  11. {
  12. Error = 1,
  13. OnHold = 2,
  14. Available = 3
  15. }
  16. private KEvent _event0;
  17. private KEvent _event1;
  18. private int _event0Handle;
  19. private int _event1Handle;
  20. private uint _version;
  21. public IRequest(Horizon system, uint version)
  22. {
  23. _event0 = new KEvent(system.KernelContext);
  24. _event1 = new KEvent(system.KernelContext);
  25. _version = version;
  26. }
  27. [CommandHipc(0)]
  28. // GetRequestState() -> u32
  29. public ResultCode GetRequestState(ServiceCtx context)
  30. {
  31. RequestState requestState = context.Device.Configuration.EnableInternetAccess
  32. ? RequestState.Available
  33. : RequestState.Error;
  34. context.ResponseData.Write((int)requestState);
  35. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  36. return ResultCode.Success;
  37. }
  38. [CommandHipc(1)]
  39. // GetResult()
  40. public ResultCode GetResult(ServiceCtx context)
  41. {
  42. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  43. return GetResultImpl();
  44. }
  45. private ResultCode GetResultImpl()
  46. {
  47. return ResultCode.Success;
  48. }
  49. [CommandHipc(2)]
  50. // GetSystemEventReadableHandles() -> (handle<copy>, handle<copy>)
  51. public ResultCode GetSystemEventReadableHandles(ServiceCtx context)
  52. {
  53. if (_event0Handle == 0)
  54. {
  55. if (context.Process.HandleTable.GenerateHandle(_event0.ReadableEvent, out _event0Handle) != KernelResult.Success)
  56. {
  57. throw new InvalidOperationException("Out of handles!");
  58. }
  59. }
  60. if (_event1Handle == 0)
  61. {
  62. if (context.Process.HandleTable.GenerateHandle(_event1.ReadableEvent, out _event1Handle) != KernelResult.Success)
  63. {
  64. throw new InvalidOperationException("Out of handles!");
  65. }
  66. }
  67. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_event0Handle, _event1Handle);
  68. return ResultCode.Success;
  69. }
  70. [CommandHipc(3)]
  71. // Cancel()
  72. public ResultCode Cancel(ServiceCtx context)
  73. {
  74. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  75. return ResultCode.Success;
  76. }
  77. [CommandHipc(4)]
  78. // Submit()
  79. public ResultCode Submit(ServiceCtx context)
  80. {
  81. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  82. return ResultCode.Success;
  83. }
  84. [CommandHipc(11)]
  85. // SetConnectionConfirmationOption(i8)
  86. public ResultCode SetConnectionConfirmationOption(ServiceCtx context)
  87. {
  88. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  89. return ResultCode.Success;
  90. }
  91. [CommandHipc(21)]
  92. // GetAppletInfo(u32) -> (u32, u32, u32, buffer<bytes, 6>)
  93. public ResultCode GetAppletInfo(ServiceCtx context)
  94. {
  95. uint themeColor = context.RequestData.ReadUInt32();
  96. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  97. ResultCode result = GetResultImpl();
  98. if (result == ResultCode.Success || (ResultCode)((int)result & 0x3fffff) == ResultCode.Unknown112)
  99. {
  100. return ResultCode.Unknown180;
  101. }
  102. // Returns appletId, libraryAppletMode, outSize and a buffer.
  103. // Returned applet ids- (0x19, 0xf, 0xe)
  104. // libraryAppletMode seems to be 0 for all applets supported.
  105. // TODO: check order
  106. context.ResponseData.Write(0xe); // Use error applet as default for now
  107. context.ResponseData.Write(0); // libraryAppletMode
  108. context.ResponseData.Write(0); // outSize
  109. return ResultCode.Success;
  110. }
  111. }
  112. }