nim.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <chrono>
  5. #include <ctime>
  6. #include "core/core.h"
  7. #include "core/hle/ipc_helpers.h"
  8. #include "core/hle/kernel/k_event.h"
  9. #include "core/hle/kernel/k_readable_event.h"
  10. #include "core/hle/kernel/k_writable_event.h"
  11. #include "core/hle/kernel/kernel.h"
  12. #include "core/hle/service/nim/nim.h"
  13. #include "core/hle/service/service.h"
  14. #include "core/hle/service/sm/sm.h"
  15. namespace Service::NIM {
  16. class IShopServiceAsync final : public ServiceFramework<IShopServiceAsync> {
  17. public:
  18. explicit IShopServiceAsync(Core::System& system_)
  19. : ServiceFramework{system_, "IShopServiceAsync"} {
  20. // clang-format off
  21. static const FunctionInfo functions[] = {
  22. {0, nullptr, "Cancel"},
  23. {1, nullptr, "GetSize"},
  24. {2, nullptr, "Read"},
  25. {3, nullptr, "GetErrorCode"},
  26. {4, nullptr, "Request"},
  27. {5, nullptr, "Prepare"},
  28. };
  29. // clang-format on
  30. RegisterHandlers(functions);
  31. }
  32. };
  33. class IShopServiceAccessor final : public ServiceFramework<IShopServiceAccessor> {
  34. public:
  35. explicit IShopServiceAccessor(Core::System& system_)
  36. : ServiceFramework{system_, "IShopServiceAccessor"} {
  37. // clang-format off
  38. static const FunctionInfo functions[] = {
  39. {0, &IShopServiceAccessor::CreateAsyncInterface, "CreateAsyncInterface"},
  40. };
  41. // clang-format on
  42. RegisterHandlers(functions);
  43. }
  44. private:
  45. void CreateAsyncInterface(Kernel::HLERequestContext& ctx) {
  46. LOG_WARNING(Service_NIM, "(STUBBED) called");
  47. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  48. rb.Push(RESULT_SUCCESS);
  49. rb.PushIpcInterface<IShopServiceAsync>(system);
  50. }
  51. };
  52. class IShopServiceAccessServer final : public ServiceFramework<IShopServiceAccessServer> {
  53. public:
  54. explicit IShopServiceAccessServer(Core::System& system_)
  55. : ServiceFramework{system_, "IShopServiceAccessServer"} {
  56. // clang-format off
  57. static const FunctionInfo functions[] = {
  58. {0, &IShopServiceAccessServer::CreateAccessorInterface, "CreateAccessorInterface"},
  59. };
  60. // clang-format on
  61. RegisterHandlers(functions);
  62. }
  63. private:
  64. void CreateAccessorInterface(Kernel::HLERequestContext& ctx) {
  65. LOG_WARNING(Service_NIM, "(STUBBED) called");
  66. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  67. rb.Push(RESULT_SUCCESS);
  68. rb.PushIpcInterface<IShopServiceAccessor>(system);
  69. }
  70. };
  71. class NIM final : public ServiceFramework<NIM> {
  72. public:
  73. explicit NIM(Core::System& system_) : ServiceFramework{system_, "nim"} {
  74. // clang-format off
  75. static const FunctionInfo functions[] = {
  76. {0, nullptr, "CreateSystemUpdateTask"},
  77. {1, nullptr, "DestroySystemUpdateTask"},
  78. {2, nullptr, "ListSystemUpdateTask"},
  79. {3, nullptr, "RequestSystemUpdateTaskRun"},
  80. {4, nullptr, "GetSystemUpdateTaskInfo"},
  81. {5, nullptr, "CommitSystemUpdateTask"},
  82. {6, nullptr, "CreateNetworkInstallTask"},
  83. {7, nullptr, "DestroyNetworkInstallTask"},
  84. {8, nullptr, "ListNetworkInstallTask"},
  85. {9, nullptr, "RequestNetworkInstallTaskRun"},
  86. {10, nullptr, "GetNetworkInstallTaskInfo"},
  87. {11, nullptr, "CommitNetworkInstallTask"},
  88. {12, nullptr, "RequestLatestSystemUpdateMeta"},
  89. {14, nullptr, "ListApplicationNetworkInstallTask"},
  90. {15, nullptr, "ListNetworkInstallTaskContentMeta"},
  91. {16, nullptr, "RequestLatestVersion"},
  92. {17, nullptr, "SetNetworkInstallTaskAttribute"},
  93. {18, nullptr, "AddNetworkInstallTaskContentMeta"},
  94. {19, nullptr, "GetDownloadedSystemDataPath"},
  95. {20, nullptr, "CalculateNetworkInstallTaskRequiredSize"},
  96. {21, nullptr, "IsExFatDriverIncluded"},
  97. {22, nullptr, "GetBackgroundDownloadStressTaskInfo"},
  98. {23, nullptr, "RequestDeviceAuthenticationToken"},
  99. {24, nullptr, "RequestGameCardRegistrationStatus"},
  100. {25, nullptr, "RequestRegisterGameCard"},
  101. {26, nullptr, "RequestRegisterNotificationToken"},
  102. {27, nullptr, "RequestDownloadTaskList"},
  103. {28, nullptr, "RequestApplicationControl"},
  104. {29, nullptr, "RequestLatestApplicationControl"},
  105. {30, nullptr, "RequestVersionList"},
  106. {31, nullptr, "CreateApplyDeltaTask"},
  107. {32, nullptr, "DestroyApplyDeltaTask"},
  108. {33, nullptr, "ListApplicationApplyDeltaTask"},
  109. {34, nullptr, "RequestApplyDeltaTaskRun"},
  110. {35, nullptr, "GetApplyDeltaTaskInfo"},
  111. {36, nullptr, "ListApplyDeltaTask"},
  112. {37, nullptr, "CommitApplyDeltaTask"},
  113. {38, nullptr, "CalculateApplyDeltaTaskRequiredSize"},
  114. {39, nullptr, "PrepareShutdown"},
  115. {40, nullptr, "ListApplyDeltaTask"},
  116. {41, nullptr, "ClearNotEnoughSpaceStateOfApplyDeltaTask"},
  117. {42, nullptr, "CreateApplyDeltaTaskFromDownloadTask"},
  118. {43, nullptr, "GetBackgroundApplyDeltaStressTaskInfo"},
  119. {44, nullptr, "GetApplyDeltaTaskRequiredStorage"},
  120. {45, nullptr, "CalculateNetworkInstallTaskContentsSize"},
  121. {46, nullptr, "PrepareShutdownForSystemUpdate"},
  122. {47, nullptr, "FindMaxRequiredApplicationVersionOfTask"},
  123. {48, nullptr, "CommitNetworkInstallTaskPartially"},
  124. {49, nullptr, "ListNetworkInstallTaskCommittedContentMeta"},
  125. {50, nullptr, "ListNetworkInstallTaskNotCommittedContentMeta"},
  126. {51, nullptr, "FindMaxRequiredSystemVersionOfTask"},
  127. {52, nullptr, "GetNetworkInstallTaskErrorContext"},
  128. {53, nullptr, "CreateLocalCommunicationReceiveApplicationTask"},
  129. {54, nullptr, "DestroyLocalCommunicationReceiveApplicationTask"},
  130. {55, nullptr, "ListLocalCommunicationReceiveApplicationTask"},
  131. {56, nullptr, "RequestLocalCommunicationReceiveApplicationTaskRun"},
  132. {57, nullptr, "GetLocalCommunicationReceiveApplicationTaskInfo"},
  133. {58, nullptr, "CommitLocalCommunicationReceiveApplicationTask"},
  134. {59, nullptr, "ListLocalCommunicationReceiveApplicationTaskContentMeta"},
  135. {60, nullptr, "CreateLocalCommunicationSendApplicationTask"},
  136. {61, nullptr, "RequestLocalCommunicationSendApplicationTaskRun"},
  137. {62, nullptr, "GetLocalCommunicationReceiveApplicationTaskErrorContext"},
  138. {63, nullptr, "GetLocalCommunicationSendApplicationTaskInfo"},
  139. {64, nullptr, "DestroyLocalCommunicationSendApplicationTask"},
  140. {65, nullptr, "GetLocalCommunicationSendApplicationTaskErrorContext"},
  141. {66, nullptr, "CalculateLocalCommunicationReceiveApplicationTaskRequiredSize"},
  142. {67, nullptr, "ListApplicationLocalCommunicationReceiveApplicationTask"},
  143. {68, nullptr, "ListApplicationLocalCommunicationSendApplicationTask"},
  144. {69, nullptr, "CreateLocalCommunicationReceiveSystemUpdateTask"},
  145. {70, nullptr, "DestroyLocalCommunicationReceiveSystemUpdateTask"},
  146. {71, nullptr, "ListLocalCommunicationReceiveSystemUpdateTask"},
  147. {72, nullptr, "RequestLocalCommunicationReceiveSystemUpdateTaskRun"},
  148. {73, nullptr, "GetLocalCommunicationReceiveSystemUpdateTaskInfo"},
  149. {74, nullptr, "CommitLocalCommunicationReceiveSystemUpdateTask"},
  150. {75, nullptr, "GetLocalCommunicationReceiveSystemUpdateTaskErrorContext"},
  151. {76, nullptr, "CreateLocalCommunicationSendSystemUpdateTask"},
  152. {77, nullptr, "RequestLocalCommunicationSendSystemUpdateTaskRun"},
  153. {78, nullptr, "GetLocalCommunicationSendSystemUpdateTaskInfo"},
  154. {79, nullptr, "DestroyLocalCommunicationSendSystemUpdateTask"},
  155. {80, nullptr, "GetLocalCommunicationSendSystemUpdateTaskErrorContext"},
  156. {81, nullptr, "ListLocalCommunicationSendSystemUpdateTask"},
  157. {82, nullptr, "GetReceivedSystemDataPath"},
  158. {83, nullptr, "CalculateApplyDeltaTaskOccupiedSize"},
  159. {84, nullptr, "Unknown84"},
  160. {85, nullptr, "ListNetworkInstallTaskContentMetaFromInstallMeta"},
  161. {86, nullptr, "ListNetworkInstallTaskOccupiedSize"},
  162. {87, nullptr, "Unknown87"},
  163. {88, nullptr, "Unknown88"},
  164. {89, nullptr, "Unknown89"},
  165. {90, nullptr, "Unknown90"},
  166. {91, nullptr, "Unknown91"},
  167. {92, nullptr, "Unknown92"},
  168. {93, nullptr, "Unknown93"},
  169. {94, nullptr, "Unknown94"},
  170. {95, nullptr, "Unknown95"},
  171. {96, nullptr, "Unknown96"},
  172. {97, nullptr, "Unknown97"},
  173. {98, nullptr, "Unknown98"},
  174. {99, nullptr, "Unknown99"},
  175. {100, nullptr, "Unknown100"},
  176. {101, nullptr, "Unknown101"},
  177. {102, nullptr, "Unknown102"},
  178. {103, nullptr, "Unknown103"},
  179. {104, nullptr, "Unknown104"},
  180. {105, nullptr, "Unknown105"},
  181. {106, nullptr, "Unknown106"},
  182. {107, nullptr, "Unknown107"},
  183. {108, nullptr, "Unknown108"},
  184. {109, nullptr, "Unknown109"},
  185. {110, nullptr, "Unknown110"},
  186. {111, nullptr, "Unknown111"},
  187. {112, nullptr, "Unknown112"},
  188. {113, nullptr, "Unknown113"},
  189. {114, nullptr, "Unknown114"},
  190. {115, nullptr, "Unknown115"},
  191. {116, nullptr, "Unknown116"},
  192. {117, nullptr, "Unknown117"},
  193. {118, nullptr, "Unknown118"},
  194. {119, nullptr, "Unknown119"},
  195. {120, nullptr, "Unknown120"},
  196. {121, nullptr, "Unknown121"},
  197. {122, nullptr, "Unknown122"},
  198. {123, nullptr, "Unknown123"},
  199. {124, nullptr, "Unknown124"},
  200. {125, nullptr, "Unknown125"},
  201. {126, nullptr, "Unknown126"},
  202. {127, nullptr, "Unknown127"},
  203. {128, nullptr, "Unknown128"},
  204. {129, nullptr, "Unknown129"},
  205. };
  206. // clang-format on
  207. RegisterHandlers(functions);
  208. }
  209. };
  210. class NIM_ECA final : public ServiceFramework<NIM_ECA> {
  211. public:
  212. explicit NIM_ECA(Core::System& system_) : ServiceFramework{system_, "nim:eca"} {
  213. // clang-format off
  214. static const FunctionInfo functions[] = {
  215. {0, &NIM_ECA::CreateServerInterface, "CreateServerInterface"},
  216. {1, nullptr, "RefreshDebugAvailability"},
  217. {2, nullptr, "ClearDebugResponse"},
  218. {3, nullptr, "RegisterDebugResponse"},
  219. {4, &NIM_ECA::IsLargeResourceAvailable, "IsLargeResourceAvailable"},
  220. };
  221. // clang-format on
  222. RegisterHandlers(functions);
  223. }
  224. private:
  225. void CreateServerInterface(Kernel::HLERequestContext& ctx) {
  226. LOG_WARNING(Service_NIM, "(STUBBED) called");
  227. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  228. rb.Push(RESULT_SUCCESS);
  229. rb.PushIpcInterface<IShopServiceAccessServer>(system);
  230. }
  231. void IsLargeResourceAvailable(Kernel::HLERequestContext& ctx) {
  232. IPC::RequestParser rp{ctx};
  233. const auto unknown{rp.Pop<u64>()};
  234. LOG_INFO(Service_NIM, "(STUBBED) called, unknown={}", unknown);
  235. IPC::ResponseBuilder rb{ctx, 3};
  236. rb.Push(RESULT_SUCCESS);
  237. rb.Push(false);
  238. }
  239. };
  240. class NIM_SHP final : public ServiceFramework<NIM_SHP> {
  241. public:
  242. explicit NIM_SHP(Core::System& system_) : ServiceFramework{system_, "nim:shp"} {
  243. // clang-format off
  244. static const FunctionInfo functions[] = {
  245. {0, nullptr, "RequestDeviceAuthenticationToken"},
  246. {1, nullptr, "RequestCachedDeviceAuthenticationToken"},
  247. {2, nullptr, "RequestEdgeToken"},
  248. {3, nullptr, "RequestCachedEdgeToken"},
  249. {100, nullptr, "RequestRegisterDeviceAccount"},
  250. {101, nullptr, "RequestUnregisterDeviceAccount"},
  251. {102, nullptr, "RequestDeviceAccountStatus"},
  252. {103, nullptr, "GetDeviceAccountInfo"},
  253. {104, nullptr, "RequestDeviceRegistrationInfo"},
  254. {105, nullptr, "RequestTransferDeviceAccount"},
  255. {106, nullptr, "RequestSyncRegistration"},
  256. {107, nullptr, "IsOwnDeviceId"},
  257. {200, nullptr, "RequestRegisterNotificationToken"},
  258. {300, nullptr, "RequestUnlinkDevice"},
  259. {301, nullptr, "RequestUnlinkDeviceIntegrated"},
  260. {302, nullptr, "RequestLinkDevice"},
  261. {303, nullptr, "HasDeviceLink"},
  262. {304, nullptr, "RequestUnlinkDeviceAll"},
  263. {305, nullptr, "RequestCreateVirtualAccount"},
  264. {306, nullptr, "RequestDeviceLinkStatus"},
  265. {400, nullptr, "GetAccountByVirtualAccount"},
  266. {401, nullptr, "GetVirtualAccount"},
  267. {500, nullptr, "RequestSyncTicketLegacy"},
  268. {501, nullptr, "RequestDownloadTicket"},
  269. {502, nullptr, "RequestDownloadTicketForPrepurchasedContents"},
  270. {503, nullptr, "RequestSyncTicket"},
  271. {504, nullptr, "RequestDownloadTicketForPrepurchasedContents2"},
  272. };
  273. // clang-format on
  274. RegisterHandlers(functions);
  275. }
  276. };
  277. class IEnsureNetworkClockAvailabilityService final
  278. : public ServiceFramework<IEnsureNetworkClockAvailabilityService> {
  279. public:
  280. explicit IEnsureNetworkClockAvailabilityService(Core::System& system_)
  281. : ServiceFramework{system_, "IEnsureNetworkClockAvailabilityService"},
  282. finished_event{system.Kernel()} {
  283. static const FunctionInfo functions[] = {
  284. {0, &IEnsureNetworkClockAvailabilityService::StartTask, "StartTask"},
  285. {1, &IEnsureNetworkClockAvailabilityService::GetFinishNotificationEvent,
  286. "GetFinishNotificationEvent"},
  287. {2, &IEnsureNetworkClockAvailabilityService::GetResult, "GetResult"},
  288. {3, &IEnsureNetworkClockAvailabilityService::Cancel, "Cancel"},
  289. {4, &IEnsureNetworkClockAvailabilityService::IsProcessing, "IsProcessing"},
  290. {5, &IEnsureNetworkClockAvailabilityService::GetServerTime, "GetServerTime"},
  291. };
  292. RegisterHandlers(functions);
  293. Kernel::KAutoObject::Create(std::addressof(finished_event));
  294. finished_event.Initialize("IEnsureNetworkClockAvailabilityService:FinishEvent");
  295. }
  296. private:
  297. Kernel::KEvent finished_event;
  298. void StartTask(Kernel::HLERequestContext& ctx) {
  299. // No need to connect to the internet, just finish the task straight away.
  300. LOG_DEBUG(Service_NIM, "called");
  301. finished_event.GetWritableEvent().Signal();
  302. IPC::ResponseBuilder rb{ctx, 2};
  303. rb.Push(RESULT_SUCCESS);
  304. }
  305. void GetFinishNotificationEvent(Kernel::HLERequestContext& ctx) {
  306. LOG_DEBUG(Service_NIM, "called");
  307. IPC::ResponseBuilder rb{ctx, 2, 1};
  308. rb.Push(RESULT_SUCCESS);
  309. rb.PushCopyObjects(finished_event.GetReadableEvent());
  310. }
  311. void GetResult(Kernel::HLERequestContext& ctx) {
  312. LOG_DEBUG(Service_NIM, "called");
  313. IPC::ResponseBuilder rb{ctx, 2};
  314. rb.Push(RESULT_SUCCESS);
  315. }
  316. void Cancel(Kernel::HLERequestContext& ctx) {
  317. LOG_DEBUG(Service_NIM, "called");
  318. finished_event.GetWritableEvent().Clear();
  319. IPC::ResponseBuilder rb{ctx, 2};
  320. rb.Push(RESULT_SUCCESS);
  321. }
  322. void IsProcessing(Kernel::HLERequestContext& ctx) {
  323. LOG_DEBUG(Service_NIM, "called");
  324. IPC::ResponseBuilder rb{ctx, 3};
  325. rb.Push(RESULT_SUCCESS);
  326. rb.PushRaw<u32>(0); // We instantly process the request
  327. }
  328. void GetServerTime(Kernel::HLERequestContext& ctx) {
  329. LOG_DEBUG(Service_NIM, "called");
  330. const s64 server_time{std::chrono::duration_cast<std::chrono::seconds>(
  331. std::chrono::system_clock::now().time_since_epoch())
  332. .count()};
  333. IPC::ResponseBuilder rb{ctx, 4};
  334. rb.Push(RESULT_SUCCESS);
  335. rb.PushRaw<s64>(server_time);
  336. }
  337. };
  338. class NTC final : public ServiceFramework<NTC> {
  339. public:
  340. explicit NTC(Core::System& system_) : ServiceFramework{system_, "ntc"} {
  341. // clang-format off
  342. static const FunctionInfo functions[] = {
  343. {0, &NTC::OpenEnsureNetworkClockAvailabilityService, "OpenEnsureNetworkClockAvailabilityService"},
  344. {100, &NTC::SuspendAutonomicTimeCorrection, "SuspendAutonomicTimeCorrection"},
  345. {101, &NTC::ResumeAutonomicTimeCorrection, "ResumeAutonomicTimeCorrection"},
  346. };
  347. // clang-format on
  348. RegisterHandlers(functions);
  349. }
  350. private:
  351. void OpenEnsureNetworkClockAvailabilityService(Kernel::HLERequestContext& ctx) {
  352. LOG_DEBUG(Service_NIM, "called");
  353. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  354. rb.Push(RESULT_SUCCESS);
  355. rb.PushIpcInterface<IEnsureNetworkClockAvailabilityService>(system);
  356. }
  357. // TODO(ogniK): Do we need these?
  358. void SuspendAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) {
  359. LOG_WARNING(Service_NIM, "(STUBBED) called");
  360. IPC::ResponseBuilder rb{ctx, 2};
  361. rb.Push(RESULT_SUCCESS);
  362. }
  363. void ResumeAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) {
  364. LOG_WARNING(Service_NIM, "(STUBBED) called");
  365. IPC::ResponseBuilder rb{ctx, 2};
  366. rb.Push(RESULT_SUCCESS);
  367. }
  368. };
  369. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  370. std::make_shared<NIM>(system)->InstallAsService(sm);
  371. std::make_shared<NIM_ECA>(system)->InstallAsService(sm);
  372. std::make_shared<NIM_SHP>(system)->InstallAsService(sm);
  373. std::make_shared<NTC>(system)->InstallAsService(sm);
  374. }
  375. } // namespace Service::NIM