2018-07-26 02:17:15 -04:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
#include <chrono>
|
|
|
|
#include <ctime>
|
2018-09-25 17:14:19 -04:00
|
|
|
#include "core/core.h"
|
2018-09-20 01:14:07 -04:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2018-11-26 18:34:07 -05:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/kernel/readable_event.h"
|
|
|
|
#include "core/hle/kernel/writable_event.h"
|
2018-07-26 02:17:15 -04:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-19 03:46:01 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-26 02:17:15 -04:00
|
|
|
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"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{503, nullptr, "RequestSyncTicket"},
|
|
|
|
{504, nullptr, "RequestDownloadTicketForPrepurchasedContents2"},
|
2018-07-26 02:17:15 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
class IEnsureNetworkClockAvailabilityService final
|
|
|
|
: public ServiceFramework<IEnsureNetworkClockAvailabilityService> {
|
|
|
|
public:
|
2019-09-22 02:41:34 -04:00
|
|
|
explicit IEnsureNetworkClockAvailabilityService(Core::System& system)
|
2018-09-20 01:14:07 -04:00
|
|
|
: 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);
|
|
|
|
|
2019-09-21 05:11:52 -04:00
|
|
|
auto& kernel = system.Kernel();
|
2018-11-27 09:18:29 -05:00
|
|
|
finished_event = Kernel::WritableEvent::CreateEventPair(
|
2019-11-03 04:10:12 -05:00
|
|
|
kernel, "IEnsureNetworkClockAvailabilityService:FinishEvent");
|
2018-09-20 01:14:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-11-27 09:18:29 -05:00
|
|
|
Kernel::EventPair finished_event;
|
2018-09-20 01:14:07 -04:00
|
|
|
|
|
|
|
void StartTask(Kernel::HLERequestContext& ctx) {
|
|
|
|
// No need to connect to the internet, just finish the task straight away.
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
2018-11-27 09:18:29 -05:00
|
|
|
finished_event.writable->Signal();
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetFinishNotificationEvent(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-11-27 09:18:29 -05:00
|
|
|
rb.PushCopyObjects(finished_event.readable);
|
2018-09-20 01:14:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetResult(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
2018-11-27 09:18:29 -05:00
|
|
|
finished_event.writable->Clear();
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsProcessing(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushRaw<u32>(0); // We instantly process the request
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetServerTime(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-26 02:17:15 -04:00
|
|
|
class NTC final : public ServiceFramework<NTC> {
|
|
|
|
public:
|
2019-09-21 05:11:52 -04:00
|
|
|
explicit NTC(Core::System& system) : ServiceFramework{"ntc"}, system(system) {
|
2018-07-26 02:17:15 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-09-20 01:14:07 -04:00
|
|
|
{0, &NTC::OpenEnsureNetworkClockAvailabilityService, "OpenEnsureNetworkClockAvailabilityService"},
|
|
|
|
{100, &NTC::SuspendAutonomicTimeCorrection, "SuspendAutonomicTimeCorrection"},
|
|
|
|
{101, &NTC::ResumeAutonomicTimeCorrection, "ResumeAutonomicTimeCorrection"},
|
2018-07-26 02:17:15 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-09-20 01:14:07 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void OpenEnsureNetworkClockAvailabilityService(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_NIM, "called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-09-21 05:11:52 -04:00
|
|
|
rb.PushIpcInterface<IEnsureNetworkClockAvailabilityService>(system);
|
2018-09-20 01:14:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(ogniK): Do we need these?
|
|
|
|
void SuspendAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_NIM, "(STUBBED) called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResumeAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_NIM, "(STUBBED) called");
|
|
|
|
|
2018-09-20 01:14:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2019-09-21 05:11:52 -04:00
|
|
|
Core::System& system;
|
2018-07-26 02:17:15 -04:00
|
|
|
};
|
|
|
|
|
2019-09-21 05:11:52 -04:00
|
|
|
void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
|
2018-07-26 02:17:15 -04:00
|
|
|
std::make_shared<NIM>()->InstallAsService(sm);
|
2018-10-19 03:46:01 -04:00
|
|
|
std::make_shared<NIM_ECA>()->InstallAsService(sm);
|
2018-07-26 02:17:15 -04:00
|
|
|
std::make_shared<NIM_SHP>()->InstallAsService(sm);
|
2019-09-21 05:11:52 -04:00
|
|
|
std::make_shared<NTC>(system)->InstallAsService(sm);
|
2018-07-26 02:17:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::NIM
|