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