nim.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 NIM final : public ServiceFramework<NIM> {
  16. public:
  17. explicit NIM() : ServiceFramework{"nim"} {
  18. // clang-format off
  19. static const FunctionInfo functions[] = {
  20. {0, nullptr, "CreateSystemUpdateTask"},
  21. {1, nullptr, "DestroySystemUpdateTask"},
  22. {2, nullptr, "ListSystemUpdateTask"},
  23. {3, nullptr, "RequestSystemUpdateTaskRun"},
  24. {4, nullptr, "GetSystemUpdateTaskInfo"},
  25. {5, nullptr, "CommitSystemUpdateTask"},
  26. {6, nullptr, "CreateNetworkInstallTask"},
  27. {7, nullptr, "DestroyNetworkInstallTask"},
  28. {8, nullptr, "ListNetworkInstallTask"},
  29. {9, nullptr, "RequestNetworkInstallTaskRun"},
  30. {10, nullptr, "GetNetworkInstallTaskInfo"},
  31. {11, nullptr, "CommitNetworkInstallTask"},
  32. {12, nullptr, "RequestLatestSystemUpdateMeta"},
  33. {14, nullptr, "ListApplicationNetworkInstallTask"},
  34. {15, nullptr, "ListNetworkInstallTaskContentMeta"},
  35. {16, nullptr, "RequestLatestVersion"},
  36. {17, nullptr, "SetNetworkInstallTaskAttribute"},
  37. {18, nullptr, "AddNetworkInstallTaskContentMeta"},
  38. {19, nullptr, "GetDownloadedSystemDataPath"},
  39. {20, nullptr, "CalculateNetworkInstallTaskRequiredSize"},
  40. {21, nullptr, "IsExFatDriverIncluded"},
  41. {22, nullptr, "GetBackgroundDownloadStressTaskInfo"},
  42. {23, nullptr, "RequestDeviceAuthenticationToken"},
  43. {24, nullptr, "RequestGameCardRegistrationStatus"},
  44. {25, nullptr, "RequestRegisterGameCard"},
  45. {26, nullptr, "RequestRegisterNotificationToken"},
  46. {27, nullptr, "RequestDownloadTaskList"},
  47. {28, nullptr, "RequestApplicationControl"},
  48. {29, nullptr, "RequestLatestApplicationControl"},
  49. {30, nullptr, "RequestVersionList"},
  50. {31, nullptr, "CreateApplyDeltaTask"},
  51. {32, nullptr, "DestroyApplyDeltaTask"},
  52. {33, nullptr, "ListApplicationApplyDeltaTask"},
  53. {34, nullptr, "RequestApplyDeltaTaskRun"},
  54. {35, nullptr, "GetApplyDeltaTaskInfo"},
  55. {36, nullptr, "ListApplyDeltaTask"},
  56. {37, nullptr, "CommitApplyDeltaTask"},
  57. {38, nullptr, "CalculateApplyDeltaTaskRequiredSize"},
  58. {39, nullptr, "PrepareShutdown"},
  59. {40, nullptr, "ListApplyDeltaTask"},
  60. {41, nullptr, "ClearNotEnoughSpaceStateOfApplyDeltaTask"},
  61. {42, nullptr, "Unknown1"},
  62. {43, nullptr, "Unknown2"},
  63. {44, nullptr, "Unknown3"},
  64. {45, nullptr, "Unknown4"},
  65. {46, nullptr, "Unknown5"},
  66. };
  67. // clang-format on
  68. RegisterHandlers(functions);
  69. }
  70. };
  71. class NIM_ECA final : public ServiceFramework<NIM_ECA> {
  72. public:
  73. explicit NIM_ECA() : ServiceFramework{"nim:eca"} {
  74. // clang-format off
  75. static const FunctionInfo functions[] = {
  76. {0, nullptr, "CreateServerInterface"},
  77. {1, nullptr, "RefreshDebugAvailability"},
  78. {2, nullptr, "ClearDebugResponse"},
  79. {3, nullptr, "RegisterDebugResponse"},
  80. };
  81. // clang-format on
  82. RegisterHandlers(functions);
  83. }
  84. };
  85. class NIM_SHP final : public ServiceFramework<NIM_SHP> {
  86. public:
  87. explicit NIM_SHP() : ServiceFramework{"nim:shp"} {
  88. // clang-format off
  89. static const FunctionInfo functions[] = {
  90. {0, nullptr, "RequestDeviceAuthenticationToken"},
  91. {1, nullptr, "RequestCachedDeviceAuthenticationToken"},
  92. {100, nullptr, "RequestRegisterDeviceAccount"},
  93. {101, nullptr, "RequestUnregisterDeviceAccount"},
  94. {102, nullptr, "RequestDeviceAccountStatus"},
  95. {103, nullptr, "GetDeviceAccountInfo"},
  96. {104, nullptr, "RequestDeviceRegistrationInfo"},
  97. {105, nullptr, "RequestTransferDeviceAccount"},
  98. {106, nullptr, "RequestSyncRegistration"},
  99. {107, nullptr, "IsOwnDeviceId"},
  100. {200, nullptr, "RequestRegisterNotificationToken"},
  101. {300, nullptr, "RequestUnlinkDevice"},
  102. {301, nullptr, "RequestUnlinkDeviceIntegrated"},
  103. {302, nullptr, "RequestLinkDevice"},
  104. {303, nullptr, "HasDeviceLink"},
  105. {304, nullptr, "RequestUnlinkDeviceAll"},
  106. {305, nullptr, "RequestCreateVirtualAccount"},
  107. {306, nullptr, "RequestDeviceLinkStatus"},
  108. {400, nullptr, "GetAccountByVirtualAccount"},
  109. {500, nullptr, "RequestSyncTicket"},
  110. {501, nullptr, "RequestDownloadTicket"},
  111. {502, nullptr, "RequestDownloadTicketForPrepurchasedContents"},
  112. };
  113. // clang-format on
  114. RegisterHandlers(functions);
  115. }
  116. };
  117. class IEnsureNetworkClockAvailabilityService final
  118. : public ServiceFramework<IEnsureNetworkClockAvailabilityService> {
  119. public:
  120. IEnsureNetworkClockAvailabilityService()
  121. : ServiceFramework("IEnsureNetworkClockAvailabilityService") {
  122. static const FunctionInfo functions[] = {
  123. {0, &IEnsureNetworkClockAvailabilityService::StartTask, "StartTask"},
  124. {1, &IEnsureNetworkClockAvailabilityService::GetFinishNotificationEvent,
  125. "GetFinishNotificationEvent"},
  126. {2, &IEnsureNetworkClockAvailabilityService::GetResult, "GetResult"},
  127. {3, &IEnsureNetworkClockAvailabilityService::Cancel, "Cancel"},
  128. {4, &IEnsureNetworkClockAvailabilityService::IsProcessing, "IsProcessing"},
  129. {5, &IEnsureNetworkClockAvailabilityService::GetServerTime, "GetServerTime"},
  130. };
  131. RegisterHandlers(functions);
  132. auto& kernel = Core::System::GetInstance().Kernel();
  133. finished_event = Kernel::WritableEvent::CreateEventPair(
  134. kernel, Kernel::ResetType::OneShot,
  135. "IEnsureNetworkClockAvailabilityService:FinishEvent");
  136. }
  137. private:
  138. Kernel::EventPair finished_event;
  139. void StartTask(Kernel::HLERequestContext& ctx) {
  140. // No need to connect to the internet, just finish the task straight away.
  141. LOG_DEBUG(Service_NIM, "called");
  142. finished_event.writable->Signal();
  143. IPC::ResponseBuilder rb{ctx, 2};
  144. rb.Push(RESULT_SUCCESS);
  145. }
  146. void GetFinishNotificationEvent(Kernel::HLERequestContext& ctx) {
  147. LOG_DEBUG(Service_NIM, "called");
  148. IPC::ResponseBuilder rb{ctx, 2, 1};
  149. rb.Push(RESULT_SUCCESS);
  150. rb.PushCopyObjects(finished_event.readable);
  151. }
  152. void GetResult(Kernel::HLERequestContext& ctx) {
  153. LOG_DEBUG(Service_NIM, "called");
  154. IPC::ResponseBuilder rb{ctx, 2};
  155. rb.Push(RESULT_SUCCESS);
  156. }
  157. void Cancel(Kernel::HLERequestContext& ctx) {
  158. LOG_DEBUG(Service_NIM, "called");
  159. finished_event.writable->Clear();
  160. IPC::ResponseBuilder rb{ctx, 2};
  161. rb.Push(RESULT_SUCCESS);
  162. }
  163. void IsProcessing(Kernel::HLERequestContext& ctx) {
  164. LOG_DEBUG(Service_NIM, "called");
  165. IPC::ResponseBuilder rb{ctx, 3};
  166. rb.Push(RESULT_SUCCESS);
  167. rb.PushRaw<u32>(0); // We instantly process the request
  168. }
  169. void GetServerTime(Kernel::HLERequestContext& ctx) {
  170. LOG_DEBUG(Service_NIM, "called");
  171. const s64 server_time{std::chrono::duration_cast<std::chrono::seconds>(
  172. std::chrono::system_clock::now().time_since_epoch())
  173. .count()};
  174. IPC::ResponseBuilder rb{ctx, 4};
  175. rb.Push(RESULT_SUCCESS);
  176. rb.PushRaw<s64>(server_time);
  177. }
  178. };
  179. class NTC final : public ServiceFramework<NTC> {
  180. public:
  181. explicit NTC() : ServiceFramework{"ntc"} {
  182. // clang-format off
  183. static const FunctionInfo functions[] = {
  184. {0, &NTC::OpenEnsureNetworkClockAvailabilityService, "OpenEnsureNetworkClockAvailabilityService"},
  185. {100, &NTC::SuspendAutonomicTimeCorrection, "SuspendAutonomicTimeCorrection"},
  186. {101, &NTC::ResumeAutonomicTimeCorrection, "ResumeAutonomicTimeCorrection"},
  187. };
  188. // clang-format on
  189. RegisterHandlers(functions);
  190. }
  191. private:
  192. void OpenEnsureNetworkClockAvailabilityService(Kernel::HLERequestContext& ctx) {
  193. LOG_DEBUG(Service_NIM, "called");
  194. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  195. rb.Push(RESULT_SUCCESS);
  196. rb.PushIpcInterface<IEnsureNetworkClockAvailabilityService>();
  197. }
  198. // TODO(ogniK): Do we need these?
  199. void SuspendAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) {
  200. LOG_WARNING(Service_NIM, "(STUBBED) called");
  201. IPC::ResponseBuilder rb{ctx, 2};
  202. rb.Push(RESULT_SUCCESS);
  203. }
  204. void ResumeAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) {
  205. LOG_WARNING(Service_NIM, "(STUBBED) called");
  206. IPC::ResponseBuilder rb{ctx, 2};
  207. rb.Push(RESULT_SUCCESS);
  208. }
  209. };
  210. void InstallInterfaces(SM::ServiceManager& sm) {
  211. std::make_shared<NIM>()->InstallAsService(sm);
  212. std::make_shared<NIM_ECA>()->InstallAsService(sm);
  213. std::make_shared<NIM_SHP>()->InstallAsService(sm);
  214. std::make_shared<NTC>()->InstallAsService(sm);
  215. }
  216. } // namespace Service::NIM