nim.cpp 15 KB

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