IManager.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.Exceptions;
  3. using Ryujinx.HLE.HOS.Services.Settings;
  4. using Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager;
  5. using System.Text;
  6. namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
  7. {
  8. [Service("nsd:a")] // Max sessions: 5
  9. [Service("nsd:u")] // Max sessions: 20
  10. class IManager : IpcService
  11. {
  12. private NsdSettings _nsdSettings;
  13. private FqdnResolver _fqdnResolver;
  14. private bool _isInitialized = false;
  15. public IManager(ServiceCtx context)
  16. {
  17. // TODO: Load nsd settings through the savedata 0x80000000000000B0 (nsdsave:/).
  18. NxSettings.Settings.TryGetValue("nsd!test_mode", out object testMode);
  19. _nsdSettings = new NsdSettings
  20. {
  21. Initialized = true,
  22. TestMode = (bool)testMode
  23. };
  24. _fqdnResolver = new FqdnResolver(_nsdSettings);
  25. _isInitialized = true;
  26. }
  27. [Command(10)]
  28. // GetSettingName() -> buffer<unknown<0x100>, 0x16>
  29. public ResultCode GetSettingName(ServiceCtx context)
  30. {
  31. (long outputPosition, long outputSize) = context.Request.GetBufferType0x22();
  32. ResultCode result = _fqdnResolver.GetSettingName(context, out string settingName);
  33. if (result == ResultCode.Success)
  34. {
  35. byte[] settingNameBuffer = Encoding.UTF8.GetBytes(settingName + '\0');
  36. context.Memory.Write((ulong)outputPosition, settingNameBuffer);
  37. }
  38. return result;
  39. }
  40. [Command(11)]
  41. // GetEnvironmentIdentifier() -> buffer<unknown<8>, 0x16>
  42. public ResultCode GetEnvironmentIdentifier(ServiceCtx context)
  43. {
  44. (long outputPosition, long outputSize) = context.Request.GetBufferType0x22();
  45. ResultCode result = _fqdnResolver.GetEnvironmentIdentifier(context, out string identifier);
  46. if (result == ResultCode.Success)
  47. {
  48. byte[] identifierBuffer = Encoding.UTF8.GetBytes(identifier + '\0');
  49. context.Memory.Write((ulong)outputPosition, identifierBuffer);
  50. }
  51. return result;
  52. }
  53. [Command(12)]
  54. // GetDeviceId() -> bytes<0x10, 1>
  55. public ResultCode GetDeviceId(ServiceCtx context)
  56. {
  57. // NOTE: Stubbed in system module.
  58. return ResultCode.Success;
  59. }
  60. [Command(13)]
  61. // DeleteSettings(u32)
  62. public ResultCode DeleteSettings(ServiceCtx context)
  63. {
  64. uint unknown = context.RequestData.ReadUInt32();
  65. if (!_isInitialized)
  66. {
  67. return ResultCode.ServiceNotInitialized;
  68. }
  69. if (unknown > 1)
  70. {
  71. return ResultCode.InvalidArgument;
  72. }
  73. if (unknown == 1)
  74. {
  75. NxSettings.Settings.TryGetValue("nsd!environment_identifier", out object environmentIdentifier);
  76. if ((string)environmentIdentifier == _nsdSettings.Environment)
  77. {
  78. // TODO: Call nn::fs::DeleteSystemFile() to delete the savedata file and return ResultCode.
  79. }
  80. else
  81. {
  82. // TODO: Mount the savedata file and return ResultCode.
  83. }
  84. }
  85. else
  86. {
  87. // TODO: Call nn::fs::DeleteSystemFile() to delete the savedata file and return ResultCode.
  88. }
  89. return ResultCode.Success;
  90. }
  91. [Command(14)]
  92. // ImportSettings(u32, buffer<unknown, 5>) -> buffer<unknown, 6>
  93. public ResultCode ImportSettings(ServiceCtx context)
  94. {
  95. throw new ServiceNotImplementedException(this, context);
  96. }
  97. [Command(15)]
  98. // Unknown(bytes<1>)
  99. public ResultCode Unknown(ServiceCtx context)
  100. {
  101. throw new ServiceNotImplementedException(this, context);
  102. }
  103. [Command(20)]
  104. // Resolve(buffer<unknown<0x100>, 0x15>) -> buffer<unknown<0x100>, 0x16>
  105. public ResultCode Resolve(ServiceCtx context)
  106. {
  107. (long outputPosition, long outputSize) = context.Request.GetBufferType0x22();
  108. ResultCode result = _fqdnResolver.ResolveEx(context, out ResultCode errorCode, out string resolvedAddress);
  109. byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress + '\0');
  110. context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer);
  111. return result;
  112. }
  113. [Command(21)]
  114. // ResolveEx(buffer<unknown<0x100>, 0x15>) -> (u32, buffer<unknown<0x100>, 0x16>)
  115. public ResultCode ResolveEx(ServiceCtx context)
  116. {
  117. (long outputPosition, long outputSize) = context.Request.GetBufferType0x22();
  118. ResultCode result = _fqdnResolver.ResolveEx(context, out ResultCode errorCode, out string resolvedAddress);
  119. byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress + '\0');
  120. context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer);
  121. context.ResponseData.Write((int)errorCode);
  122. return result;
  123. }
  124. [Command(30)]
  125. // GetNasServiceSetting(buffer<unknown<0x10>, 0x15>) -> buffer<unknown<0x108>, 0x16>
  126. public ResultCode GetNasServiceSetting(ServiceCtx context)
  127. {
  128. throw new ServiceNotImplementedException(this, context);
  129. }
  130. [Command(31)]
  131. // GetNasServiceSettingEx(buffer<unknown<0x10>, 0x15>) -> (u32, buffer<unknown<0x108>, 0x16>)
  132. public ResultCode GetNasServiceSettingEx(ServiceCtx context)
  133. {
  134. throw new ServiceNotImplementedException(this, context);
  135. }
  136. [Command(40)]
  137. // GetNasRequestFqdn() -> buffer<unknown<0x100>, 0x16>
  138. public ResultCode GetNasRequestFqdn(ServiceCtx context)
  139. {
  140. throw new ServiceNotImplementedException(this, context);
  141. }
  142. [Command(41)]
  143. // GetNasRequestFqdnEx() -> (u32, buffer<unknown<0x100>, 0x16>)
  144. public ResultCode GetNasRequestFqdnEx(ServiceCtx context)
  145. {
  146. throw new ServiceNotImplementedException(this, context);
  147. }
  148. [Command(42)]
  149. // GetNasApiFqdn() -> buffer<unknown<0x100>, 0x16>
  150. public ResultCode GetNasApiFqdn(ServiceCtx context)
  151. {
  152. throw new ServiceNotImplementedException(this, context);
  153. }
  154. [Command(43)]
  155. // GetNasApiFqdnEx() -> (u32, buffer<unknown<0x100>, 0x16>)
  156. public ResultCode GetNasApiFqdnEx(ServiceCtx context)
  157. {
  158. throw new ServiceNotImplementedException(this, context);
  159. }
  160. [Command(50)]
  161. // GetCurrentSetting() -> buffer<unknown<0x12bf0>, 0x16>
  162. public ResultCode GetCurrentSetting(ServiceCtx context)
  163. {
  164. throw new ServiceNotImplementedException(this, context);
  165. }
  166. [Command(60)]
  167. // ReadSaveDataFromFsForTest() -> buffer<unknown<0x12bf0>, 0x16>
  168. public ResultCode ReadSaveDataFromFsForTest(ServiceCtx context)
  169. {
  170. if (!_isInitialized)
  171. {
  172. return ResultCode.ServiceNotInitialized;
  173. }
  174. // TODO: Call nn::nsd::detail::fs::ReadSaveDataWithOffset() at offset 0 to write the
  175. // whole savedata inside the buffer.
  176. Logger.Stub?.PrintStub(LogClass.ServiceNsd);
  177. return ResultCode.Success;
  178. }
  179. [Command(61)]
  180. // WriteSaveDataToFsForTest(buffer<unknown<0x12bf0>, 0x15>)
  181. public ResultCode WriteSaveDataToFsForTest(ServiceCtx context)
  182. {
  183. // NOTE: Stubbed in system module.
  184. if (_isInitialized)
  185. {
  186. return ResultCode.NotImplemented;
  187. }
  188. else
  189. {
  190. return ResultCode.ServiceNotInitialized;
  191. }
  192. }
  193. [Command(62)]
  194. // DeleteSaveDataOfFsForTest()
  195. public ResultCode DeleteSaveDataOfFsForTest(ServiceCtx context)
  196. {
  197. // NOTE: Stubbed in system module.
  198. if (_isInitialized)
  199. {
  200. return ResultCode.NotImplemented;
  201. }
  202. else
  203. {
  204. return ResultCode.ServiceNotInitialized;
  205. }
  206. }
  207. [Command(63)]
  208. // IsChangeEnvironmentIdentifierDisabled() -> bytes<1>
  209. public ResultCode IsChangeEnvironmentIdentifierDisabled(ServiceCtx context)
  210. {
  211. throw new ServiceNotImplementedException(this, context);
  212. }
  213. }
  214. }