From 01d89acd139e50470c41e5cd04df4acd49b635c6 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 21 Feb 2024 20:52:51 -0500 Subject: pctl: move types and results --- src/core/hle/service/pctl/pctl_module.cpp | 82 ++++++++++--------------------- src/core/hle/service/pctl/pctl_module.h | 13 +---- src/core/hle/service/pctl/pctl_results.h | 15 ++++++ src/core/hle/service/pctl/pctl_types.h | 43 ++++++++++++++++ 4 files changed, 86 insertions(+), 67 deletions(-) create mode 100644 src/core/hle/service/pctl/pctl_results.h create mode 100644 src/core/hle/service/pctl/pctl_types.h (limited to 'src/core/hle/service/pctl') diff --git a/src/core/hle/service/pctl/pctl_module.cpp b/src/core/hle/service/pctl/pctl_module.cpp index 6a7fd72bc..dab37cdc4 100644 --- a/src/core/hle/service/pctl/pctl_module.cpp +++ b/src/core/hle/service/pctl/pctl_module.cpp @@ -9,18 +9,28 @@ #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/pctl/pctl.h" #include "core/hle/service/pctl/pctl_module.h" +#include "core/hle/service/pctl/pctl_results.h" +#include "core/hle/service/pctl/pctl_types.h" #include "core/hle/service/server_manager.h" namespace Service::PCTL { -namespace Error { - -constexpr Result ResultNoFreeCommunication{ErrorModule::PCTL, 101}; -constexpr Result ResultStereoVisionRestricted{ErrorModule::PCTL, 104}; -constexpr Result ResultNoCapability{ErrorModule::PCTL, 131}; -constexpr Result ResultNoRestrictionEnabled{ErrorModule::PCTL, 181}; +struct States { + u64 current_tid{}; + ApplicationInfo application_info{}; + u64 tid_from_event{}; + bool launch_time_valid{}; + bool is_suspended{}; + bool temporary_unlocked{}; + bool free_communication{}; + bool stereo_vision{}; +}; -} // namespace Error +struct ParentalControlSettings { + bool is_stero_vision_restricted{}; + bool is_free_communication_default_on{}; + bool disabled{}; +}; class IParentalControlService final : public ServiceFramework { public: @@ -214,7 +224,7 @@ private: states.free_communication = false; states.stereo_vision = false; states.application_info = ApplicationInfo{ - .tid = tid, + .application_id = tid, .age_rating = control.first->GetRatingAge(), .parental_control_flag = control.first->GetParentalControlFlag(), .capability = capability, @@ -234,7 +244,7 @@ private: IPC::ResponseBuilder rb{ctx, 2}; if (!CheckFreeCommunicationPermissionImpl()) { - rb.Push(Error::ResultNoFreeCommunication); + rb.Push(ResultNoFreeCommunication); } else { rb.Push(ResultSuccess); } @@ -246,7 +256,7 @@ private: LOG_WARNING(Service_PCTL, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(Error::ResultNoFreeCommunication); + rb.Push(ResultNoFreeCommunication); } void IsRestrictionTemporaryUnlocked(HLERequestContext& ctx) { @@ -280,7 +290,7 @@ private: IPC::ResponseBuilder rb{ctx, 2}; if (!CheckFreeCommunicationPermissionImpl()) { - rb.Push(Error::ResultNoFreeCommunication); + rb.Push(ResultNoFreeCommunication); } else { rb.Push(ResultSuccess); } @@ -292,7 +302,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; if (False(capability & (Capability::Status | Capability::Recovery))) { LOG_ERROR(Service_PCTL, "Application does not have Status or Recovery capabilities!"); - rb.Push(Error::ResultNoCapability); + rb.Push(ResultNoCapability); rb.Push(false); return; } @@ -335,12 +345,12 @@ private: if (False(capability & Capability::StereoVision)) { LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(Error::ResultNoCapability); + rb.Push(ResultNoCapability); return; } if (pin_code[0] == '\0') { - rb.Push(Error::ResultNoRestrictionEnabled); + rb.Push(ResultNoRestrictionEnabled); return; } @@ -352,7 +362,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; if (!ConfirmStereoVisionPermissionImpl()) { - rb.Push(Error::ResultStereoVisionRestricted); + rb.Push(ResultStereoVisionRestricted); rb.Push(false); } else { rb.Push(ResultSuccess); @@ -423,7 +433,7 @@ private: IPC::ResponseBuilder rb{ctx, 2}; if (False(capability & Capability::StereoVision)) { LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(Error::ResultNoCapability); + rb.Push(ResultNoCapability); return; } @@ -437,7 +447,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; if (False(capability & Capability::StereoVision)) { LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(Error::ResultNoCapability); + rb.Push(ResultNoCapability); rb.Push(false); return; } @@ -455,44 +465,6 @@ private: rb.Push(ResultSuccess); } - struct ApplicationInfo { - u64 tid{}; - std::array age_rating{}; - u32 parental_control_flag{}; - Capability capability{}; - }; - - struct States { - u64 current_tid{}; - ApplicationInfo application_info{}; - u64 tid_from_event{}; - bool launch_time_valid{}; - bool is_suspended{}; - bool temporary_unlocked{}; - bool free_communication{}; - bool stereo_vision{}; - }; - - struct ParentalControlSettings { - bool is_stero_vision_restricted{}; - bool is_free_communication_default_on{}; - bool disabled{}; - }; - - // This is nn::pctl::RestrictionSettings - struct RestrictionSettings { - u8 rating_age; - bool sns_post_restriction; - bool free_communication_restriction; - }; - static_assert(sizeof(RestrictionSettings) == 0x3, "RestrictionSettings has incorrect size."); - - // This is nn::pctl::PlayTimerSettings - struct PlayTimerSettings { - std::array settings; - }; - static_assert(sizeof(PlayTimerSettings) == 0x34, "PlayTimerSettings has incorrect size."); - States states{}; ParentalControlSettings settings{}; RestrictionSettings restriction_settings{}; diff --git a/src/core/hle/service/pctl/pctl_module.h b/src/core/hle/service/pctl/pctl_module.h index dff0d3f08..715c05b20 100644 --- a/src/core/hle/service/pctl/pctl_module.h +++ b/src/core/hle/service/pctl/pctl_module.h @@ -3,7 +3,7 @@ #pragma once -#include "common/common_funcs.h" +#include "core/hle/service/pctl/pctl_types.h" #include "core/hle/service/service.h" namespace Core { @@ -12,17 +12,6 @@ class System; namespace Service::PCTL { -enum class Capability : u32 { - None = 0, - Application = 1 << 0, - SnsPost = 1 << 1, - Recovery = 1 << 6, - Status = 1 << 8, - StereoVision = 1 << 9, - System = 1 << 15, -}; -DECLARE_ENUM_FLAG_OPERATORS(Capability); - class Module final { public: class Interface : public ServiceFramework { diff --git a/src/core/hle/service/pctl/pctl_results.h b/src/core/hle/service/pctl/pctl_results.h new file mode 100644 index 000000000..1fc54727b --- /dev/null +++ b/src/core/hle/service/pctl/pctl_results.h @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/result.h" + +namespace Service::PCTL { + +constexpr Result ResultNoFreeCommunication{ErrorModule::PCTL, 101}; +constexpr Result ResultStereoVisionRestricted{ErrorModule::PCTL, 104}; +constexpr Result ResultNoCapability{ErrorModule::PCTL, 131}; +constexpr Result ResultNoRestrictionEnabled{ErrorModule::PCTL, 181}; + +} // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl_types.h b/src/core/hle/service/pctl/pctl_types.h new file mode 100644 index 000000000..daaecdf48 --- /dev/null +++ b/src/core/hle/service/pctl/pctl_types.h @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/common_funcs.h" + +namespace Service::PCTL { + +enum class Capability : u32 { + None = 0, + Application = 1 << 0, + SnsPost = 1 << 1, + Recovery = 1 << 6, + Status = 1 << 8, + StereoVision = 1 << 9, + System = 1 << 15, +}; +DECLARE_ENUM_FLAG_OPERATORS(Capability); + +struct ApplicationInfo { + u64 application_id{}; + std::array age_rating{}; + u32 parental_control_flag{}; + Capability capability{}; +}; +static_assert(sizeof(ApplicationInfo) == 0x30, "ApplicationInfo has incorrect size."); + +// This is nn::pctl::RestrictionSettings +struct RestrictionSettings { + u8 rating_age; + bool sns_post_restriction; + bool free_communication_restriction; +}; +static_assert(sizeof(RestrictionSettings) == 0x3, "RestrictionSettings has incorrect size."); + +// This is nn::pctl::PlayTimerSettings +struct PlayTimerSettings { + std::array settings; +}; +static_assert(sizeof(PlayTimerSettings) == 0x34, "PlayTimerSettings has incorrect size."); + +} // namespace Service::PCTL -- cgit v1.2.3 From a37bd0b9a706f63cf1eb4503549171c232bf4238 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 21 Feb 2024 20:59:33 -0500 Subject: pctl: move IParentalControlService --- .../hle/service/pctl/parental_control_service.cpp | 441 +++++++++++++++++++ .../hle/service/pctl/parental_control_service.h | 74 ++++ src/core/hle/service/pctl/pctl_module.cpp | 468 +-------------------- 3 files changed, 516 insertions(+), 467 deletions(-) create mode 100644 src/core/hle/service/pctl/parental_control_service.cpp create mode 100644 src/core/hle/service/pctl/parental_control_service.h (limited to 'src/core/hle/service/pctl') diff --git a/src/core/hle/service/pctl/parental_control_service.cpp b/src/core/hle/service/pctl/parental_control_service.cpp new file mode 100644 index 000000000..4248b0184 --- /dev/null +++ b/src/core/hle/service/pctl/parental_control_service.cpp @@ -0,0 +1,441 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core.h" +#include "core/file_sys/control_metadata.h" +#include "core/file_sys/patch_manager.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/pctl/parental_control_service.h" +#include "core/hle/service/pctl/pctl_results.h" + +namespace Service::PCTL { + +IParentalControlService::IParentalControlService(Core::System& system_, Capability capability_) + : ServiceFramework{system_, "IParentalControlService"}, capability{capability_}, + service_context{system_, "IParentalControlService"} { + // clang-format off + static const FunctionInfo functions[] = { + {1, &IParentalControlService::Initialize, "Initialize"}, + {1001, &IParentalControlService::CheckFreeCommunicationPermission, "CheckFreeCommunicationPermission"}, + {1002, nullptr, "ConfirmLaunchApplicationPermission"}, + {1003, nullptr, "ConfirmResumeApplicationPermission"}, + {1004, &IParentalControlService::ConfirmSnsPostPermission, "ConfirmSnsPostPermission"}, + {1005, nullptr, "ConfirmSystemSettingsPermission"}, + {1006, &IParentalControlService::IsRestrictionTemporaryUnlocked, "IsRestrictionTemporaryUnlocked"}, + {1007, nullptr, "RevertRestrictionTemporaryUnlocked"}, + {1008, nullptr, "EnterRestrictedSystemSettings"}, + {1009, nullptr, "LeaveRestrictedSystemSettings"}, + {1010, nullptr, "IsRestrictedSystemSettingsEntered"}, + {1011, nullptr, "RevertRestrictedSystemSettingsEntered"}, + {1012, nullptr, "GetRestrictedFeatures"}, + {1013, &IParentalControlService::ConfirmStereoVisionPermission, "ConfirmStereoVisionPermission"}, + {1014, nullptr, "ConfirmPlayableApplicationVideoOld"}, + {1015, nullptr, "ConfirmPlayableApplicationVideo"}, + {1016, nullptr, "ConfirmShowNewsPermission"}, + {1017, &IParentalControlService::EndFreeCommunication, "EndFreeCommunication"}, + {1018, &IParentalControlService::IsFreeCommunicationAvailable, "IsFreeCommunicationAvailable"}, + {1031, &IParentalControlService::IsRestrictionEnabled, "IsRestrictionEnabled"}, + {1032, &IParentalControlService::GetSafetyLevel, "GetSafetyLevel"}, + {1033, nullptr, "SetSafetyLevel"}, + {1034, nullptr, "GetSafetyLevelSettings"}, + {1035, &IParentalControlService::GetCurrentSettings, "GetCurrentSettings"}, + {1036, nullptr, "SetCustomSafetyLevelSettings"}, + {1037, nullptr, "GetDefaultRatingOrganization"}, + {1038, nullptr, "SetDefaultRatingOrganization"}, + {1039, &IParentalControlService::GetFreeCommunicationApplicationListCount, "GetFreeCommunicationApplicationListCount"}, + {1042, nullptr, "AddToFreeCommunicationApplicationList"}, + {1043, nullptr, "DeleteSettings"}, + {1044, nullptr, "GetFreeCommunicationApplicationList"}, + {1045, nullptr, "UpdateFreeCommunicationApplicationList"}, + {1046, nullptr, "DisableFeaturesForReset"}, + {1047, nullptr, "NotifyApplicationDownloadStarted"}, + {1048, nullptr, "NotifyNetworkProfileCreated"}, + {1049, nullptr, "ResetFreeCommunicationApplicationList"}, + {1061, &IParentalControlService::ConfirmStereoVisionRestrictionConfigurable, "ConfirmStereoVisionRestrictionConfigurable"}, + {1062, &IParentalControlService::GetStereoVisionRestriction, "GetStereoVisionRestriction"}, + {1063, &IParentalControlService::SetStereoVisionRestriction, "SetStereoVisionRestriction"}, + {1064, &IParentalControlService::ResetConfirmedStereoVisionPermission, "ResetConfirmedStereoVisionPermission"}, + {1065, &IParentalControlService::IsStereoVisionPermitted, "IsStereoVisionPermitted"}, + {1201, nullptr, "UnlockRestrictionTemporarily"}, + {1202, nullptr, "UnlockSystemSettingsRestriction"}, + {1203, nullptr, "SetPinCode"}, + {1204, nullptr, "GenerateInquiryCode"}, + {1205, nullptr, "CheckMasterKey"}, + {1206, nullptr, "GetPinCodeLength"}, + {1207, nullptr, "GetPinCodeChangedEvent"}, + {1208, nullptr, "GetPinCode"}, + {1403, &IParentalControlService::IsPairingActive, "IsPairingActive"}, + {1406, nullptr, "GetSettingsLastUpdated"}, + {1411, nullptr, "GetPairingAccountInfo"}, + {1421, nullptr, "GetAccountNickname"}, + {1424, nullptr, "GetAccountState"}, + {1425, nullptr, "RequestPostEvents"}, + {1426, nullptr, "GetPostEventInterval"}, + {1427, nullptr, "SetPostEventInterval"}, + {1432, &IParentalControlService::GetSynchronizationEvent, "GetSynchronizationEvent"}, + {1451, nullptr, "StartPlayTimer"}, + {1452, nullptr, "StopPlayTimer"}, + {1453, nullptr, "IsPlayTimerEnabled"}, + {1454, nullptr, "GetPlayTimerRemainingTime"}, + {1455, nullptr, "IsRestrictedByPlayTimer"}, + {1456, &IParentalControlService::GetPlayTimerSettings, "GetPlayTimerSettings"}, + {1457, &IParentalControlService::GetPlayTimerEventToRequestSuspension, "GetPlayTimerEventToRequestSuspension"}, + {1458, &IParentalControlService::IsPlayTimerAlarmDisabled, "IsPlayTimerAlarmDisabled"}, + {1471, nullptr, "NotifyWrongPinCodeInputManyTimes"}, + {1472, nullptr, "CancelNetworkRequest"}, + {1473, &IParentalControlService::GetUnlinkedEvent, "GetUnlinkedEvent"}, + {1474, nullptr, "ClearUnlinkedEvent"}, + {1601, nullptr, "DisableAllFeatures"}, + {1602, nullptr, "PostEnableAllFeatures"}, + {1603, nullptr, "IsAllFeaturesDisabled"}, + {1901, nullptr, "DeleteFromFreeCommunicationApplicationListForDebug"}, + {1902, nullptr, "ClearFreeCommunicationApplicationListForDebug"}, + {1903, nullptr, "GetExemptApplicationListCountForDebug"}, + {1904, nullptr, "GetExemptApplicationListForDebug"}, + {1905, nullptr, "UpdateExemptApplicationListForDebug"}, + {1906, nullptr, "AddToExemptApplicationListForDebug"}, + {1907, nullptr, "DeleteFromExemptApplicationListForDebug"}, + {1908, nullptr, "ClearExemptApplicationListForDebug"}, + {1941, nullptr, "DeletePairing"}, + {1951, nullptr, "SetPlayTimerSettingsForDebug"}, + {1952, nullptr, "GetPlayTimerSpentTimeForTest"}, + {1953, nullptr, "SetPlayTimerAlarmDisabledForDebug"}, + {2001, nullptr, "RequestPairingAsync"}, + {2002, nullptr, "FinishRequestPairing"}, + {2003, nullptr, "AuthorizePairingAsync"}, + {2004, nullptr, "FinishAuthorizePairing"}, + {2005, nullptr, "RetrievePairingInfoAsync"}, + {2006, nullptr, "FinishRetrievePairingInfo"}, + {2007, nullptr, "UnlinkPairingAsync"}, + {2008, nullptr, "FinishUnlinkPairing"}, + {2009, nullptr, "GetAccountMiiImageAsync"}, + {2010, nullptr, "FinishGetAccountMiiImage"}, + {2011, nullptr, "GetAccountMiiImageContentTypeAsync"}, + {2012, nullptr, "FinishGetAccountMiiImageContentType"}, + {2013, nullptr, "SynchronizeParentalControlSettingsAsync"}, + {2014, nullptr, "FinishSynchronizeParentalControlSettings"}, + {2015, nullptr, "FinishSynchronizeParentalControlSettingsWithLastUpdated"}, + {2016, nullptr, "RequestUpdateExemptionListAsync"}, + }; + // clang-format on + RegisterHandlers(functions); + + synchronization_event = + service_context.CreateEvent("IParentalControlService::SynchronizationEvent"); + unlinked_event = service_context.CreateEvent("IParentalControlService::UnlinkedEvent"); + request_suspension_event = + service_context.CreateEvent("IParentalControlService::RequestSuspensionEvent"); +} + +IParentalControlService::~IParentalControlService() { + service_context.CloseEvent(synchronization_event); + service_context.CloseEvent(unlinked_event); + service_context.CloseEvent(request_suspension_event); +} + +bool IParentalControlService::CheckFreeCommunicationPermissionImpl() const { + if (states.temporary_unlocked) { + return true; + } + if ((states.application_info.parental_control_flag & 1) == 0) { + return true; + } + if (pin_code[0] == '\0') { + return true; + } + if (!settings.is_free_communication_default_on) { + return true; + } + // TODO(ogniK): Check for blacklisted/exempted applications. Return false can happen here + // but as we don't have multiproceses support yet, we can just assume our application is + // valid for the time being + return true; +} + +bool IParentalControlService::ConfirmStereoVisionPermissionImpl() const { + if (states.temporary_unlocked) { + return true; + } + if (pin_code[0] == '\0') { + return true; + } + if (!settings.is_stero_vision_restricted) { + return false; + } + return true; +} + +void IParentalControlService::SetStereoVisionRestrictionImpl(bool is_restricted) { + if (settings.disabled) { + return; + } + + if (pin_code[0] == '\0') { + return; + } + settings.is_stero_vision_restricted = is_restricted; +} + +void IParentalControlService::Initialize(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + IPC::ResponseBuilder rb{ctx, 2}; + + if (False(capability & (Capability::Application | Capability::System))) { + LOG_ERROR(Service_PCTL, "Invalid capability! capability={:X}", capability); + return; + } + + // TODO(ogniK): Recovery flag initialization for pctl:r + + const auto tid = system.GetApplicationProcessProgramID(); + if (tid != 0) { + const FileSys::PatchManager pm{tid, system.GetFileSystemController(), + system.GetContentProvider()}; + const auto control = pm.GetControlMetadata(); + if (control.first) { + states.tid_from_event = 0; + states.launch_time_valid = false; + states.is_suspended = false; + states.free_communication = false; + states.stereo_vision = false; + states.application_info = ApplicationInfo{ + .application_id = tid, + .age_rating = control.first->GetRatingAge(), + .parental_control_flag = control.first->GetParentalControlFlag(), + .capability = capability, + }; + + if (False(capability & (Capability::System | Capability::Recovery))) { + // TODO(ogniK): Signal application launch event + } + } + } + + rb.Push(ResultSuccess); +} + +void IParentalControlService::CheckFreeCommunicationPermission(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2}; + if (!CheckFreeCommunicationPermissionImpl()) { + rb.Push(PCTL::ResultNoFreeCommunication); + } else { + rb.Push(ResultSuccess); + } + + states.free_communication = true; +} + +void IParentalControlService::ConfirmSnsPostPermission(HLERequestContext& ctx) { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(PCTL::ResultNoFreeCommunication); +} + +void IParentalControlService::IsRestrictionTemporaryUnlocked(HLERequestContext& ctx) { + const bool is_temporary_unlocked = false; + + LOG_WARNING(Service_PCTL, "(STUBBED) called, is_temporary_unlocked={}", is_temporary_unlocked); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(is_temporary_unlocked); +} + +void IParentalControlService::ConfirmStereoVisionPermission(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + states.stereo_vision = true; + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +void IParentalControlService::EndFreeCommunication(HLERequestContext& ctx) { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +void IParentalControlService::IsFreeCommunicationAvailable(HLERequestContext& ctx) { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + if (!CheckFreeCommunicationPermissionImpl()) { + rb.Push(PCTL::ResultNoFreeCommunication); + } else { + rb.Push(ResultSuccess); + } +} + +void IParentalControlService::IsRestrictionEnabled(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 3}; + if (False(capability & (Capability::Status | Capability::Recovery))) { + LOG_ERROR(Service_PCTL, "Application does not have Status or Recovery capabilities!"); + rb.Push(PCTL::ResultNoCapability); + rb.Push(false); + return; + } + + rb.Push(pin_code[0] != '\0'); +} + +void IParentalControlService::GetSafetyLevel(HLERequestContext& ctx) { + const u32 safety_level = 0; + + LOG_WARNING(Service_PCTL, "(STUBBED) called, safety_level={}", safety_level); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(safety_level); +} + +void IParentalControlService::GetCurrentSettings(HLERequestContext& ctx) { + LOG_INFO(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.PushRaw(restriction_settings); +} + +void IParentalControlService::GetFreeCommunicationApplicationListCount(HLERequestContext& ctx) { + const u32 count = 4; + + LOG_WARNING(Service_PCTL, "(STUBBED) called, count={}", count); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(count); +} + +void IParentalControlService::ConfirmStereoVisionRestrictionConfigurable(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2}; + + if (False(capability & Capability::StereoVision)) { + LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); + rb.Push(PCTL::ResultNoCapability); + return; + } + + if (pin_code[0] == '\0') { + rb.Push(PCTL::ResultNoRestrictionEnabled); + return; + } + + rb.Push(ResultSuccess); +} + +void IParentalControlService::IsStereoVisionPermitted(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 3}; + if (!ConfirmStereoVisionPermissionImpl()) { + rb.Push(PCTL::ResultStereoVisionRestricted); + rb.Push(false); + } else { + rb.Push(ResultSuccess); + rb.Push(true); + } +} + +void IParentalControlService::IsPairingActive(HLERequestContext& ctx) { + const bool is_pairing_active = false; + + LOG_WARNING(Service_PCTL, "(STUBBED) called, is_pairing_active={}", is_pairing_active); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(is_pairing_active); +} + +void IParentalControlService::GetSynchronizationEvent(HLERequestContext& ctx) { + LOG_INFO(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(synchronization_event->GetReadableEvent()); +} + +void IParentalControlService::GetPlayTimerSettings(HLERequestContext& ctx) { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + + const PlayTimerSettings timer_settings{}; + + IPC::ResponseBuilder rb{ctx, 15}; + rb.Push(ResultSuccess); + rb.PushRaw(timer_settings); +} + +void IParentalControlService::GetPlayTimerEventToRequestSuspension(HLERequestContext& ctx) { + LOG_INFO(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(request_suspension_event->GetReadableEvent()); +} + +void IParentalControlService::IsPlayTimerAlarmDisabled(HLERequestContext& ctx) { + const bool is_play_timer_alarm_disabled = false; + + LOG_INFO(Service_PCTL, "called, is_play_timer_alarm_disabled={}", is_play_timer_alarm_disabled); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(is_play_timer_alarm_disabled); +} + +void IParentalControlService::GetUnlinkedEvent(HLERequestContext& ctx) { + LOG_INFO(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(unlinked_event->GetReadableEvent()); +} + +void IParentalControlService::SetStereoVisionRestriction(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto can_use = rp.Pop(); + LOG_DEBUG(Service_PCTL, "called, can_use={}", can_use); + + IPC::ResponseBuilder rb{ctx, 2}; + if (False(capability & Capability::StereoVision)) { + LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); + rb.Push(PCTL::ResultNoCapability); + return; + } + + SetStereoVisionRestrictionImpl(can_use); + rb.Push(ResultSuccess); +} + +void IParentalControlService::GetStereoVisionRestriction(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 3}; + if (False(capability & Capability::StereoVision)) { + LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); + rb.Push(PCTL::ResultNoCapability); + rb.Push(false); + return; + } + + rb.Push(ResultSuccess); + rb.Push(settings.is_stero_vision_restricted); +} + +void IParentalControlService::ResetConfirmedStereoVisionPermission(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + states.stereo_vision = false; + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +} // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/parental_control_service.h b/src/core/hle/service/pctl/parental_control_service.h new file mode 100644 index 000000000..dcc357f65 --- /dev/null +++ b/src/core/hle/service/pctl/parental_control_service.h @@ -0,0 +1,74 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/kernel_helpers.h" +#include "core/hle/service/pctl/pctl_types.h" +#include "core/hle/service/service.h" + +namespace Service::PCTL { + +class IParentalControlService final : public ServiceFramework { +public: + explicit IParentalControlService(Core::System& system_, Capability capability_); + ~IParentalControlService() override; + +private: + bool CheckFreeCommunicationPermissionImpl() const; + bool ConfirmStereoVisionPermissionImpl() const; + void SetStereoVisionRestrictionImpl(bool is_restricted); + + void Initialize(HLERequestContext& ctx); + void CheckFreeCommunicationPermission(HLERequestContext& ctx); + void ConfirmSnsPostPermission(HLERequestContext& ctx); + void IsRestrictionTemporaryUnlocked(HLERequestContext& ctx); + void ConfirmStereoVisionPermission(HLERequestContext& ctx); + void EndFreeCommunication(HLERequestContext& ctx); + void IsFreeCommunicationAvailable(HLERequestContext& ctx); + void IsRestrictionEnabled(HLERequestContext& ctx); + void GetSafetyLevel(HLERequestContext& ctx); + void GetCurrentSettings(HLERequestContext& ctx); + void GetFreeCommunicationApplicationListCount(HLERequestContext& ctx); + void ConfirmStereoVisionRestrictionConfigurable(HLERequestContext& ctx); + void IsStereoVisionPermitted(HLERequestContext& ctx); + void IsPairingActive(HLERequestContext& ctx); + void GetSynchronizationEvent(HLERequestContext& ctx); + void GetPlayTimerSettings(HLERequestContext& ctx); + void GetPlayTimerEventToRequestSuspension(HLERequestContext& ctx); + void IsPlayTimerAlarmDisabled(HLERequestContext& ctx); + void GetUnlinkedEvent(HLERequestContext& ctx); + void SetStereoVisionRestriction(HLERequestContext& ctx); + void GetStereoVisionRestriction(HLERequestContext& ctx); + void ResetConfirmedStereoVisionPermission(HLERequestContext& ctx); + + struct States { + u64 current_tid{}; + ApplicationInfo application_info{}; + u64 tid_from_event{}; + bool launch_time_valid{}; + bool is_suspended{}; + bool temporary_unlocked{}; + bool free_communication{}; + bool stereo_vision{}; + }; + + struct ParentalControlSettings { + bool is_stero_vision_restricted{}; + bool is_free_communication_default_on{}; + bool disabled{}; + }; + + States states{}; + ParentalControlSettings settings{}; + RestrictionSettings restriction_settings{}; + std::array pin_code{}; + Capability capability{}; + + Kernel::KEvent* synchronization_event; + Kernel::KEvent* unlinked_event; + Kernel::KEvent* request_suspension_event; + KernelHelpers::ServiceContext service_context; +}; + +} // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl_module.cpp b/src/core/hle/service/pctl/pctl_module.cpp index dab37cdc4..118856574 100644 --- a/src/core/hle/service/pctl/pctl_module.cpp +++ b/src/core/hle/service/pctl/pctl_module.cpp @@ -2,481 +2,15 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/core.h" -#include "core/file_sys/control_metadata.h" -#include "core/file_sys/patch_manager.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" +#include "core/hle/service/pctl/parental_control_service.h" #include "core/hle/service/pctl/pctl.h" #include "core/hle/service/pctl/pctl_module.h" -#include "core/hle/service/pctl/pctl_results.h" -#include "core/hle/service/pctl/pctl_types.h" #include "core/hle/service/server_manager.h" namespace Service::PCTL { -struct States { - u64 current_tid{}; - ApplicationInfo application_info{}; - u64 tid_from_event{}; - bool launch_time_valid{}; - bool is_suspended{}; - bool temporary_unlocked{}; - bool free_communication{}; - bool stereo_vision{}; -}; - -struct ParentalControlSettings { - bool is_stero_vision_restricted{}; - bool is_free_communication_default_on{}; - bool disabled{}; -}; - -class IParentalControlService final : public ServiceFramework { -public: - explicit IParentalControlService(Core::System& system_, Capability capability_) - : ServiceFramework{system_, "IParentalControlService"}, capability{capability_}, - service_context{system_, "IParentalControlService"} { - // clang-format off - static const FunctionInfo functions[] = { - {1, &IParentalControlService::Initialize, "Initialize"}, - {1001, &IParentalControlService::CheckFreeCommunicationPermission, "CheckFreeCommunicationPermission"}, - {1002, nullptr, "ConfirmLaunchApplicationPermission"}, - {1003, nullptr, "ConfirmResumeApplicationPermission"}, - {1004, &IParentalControlService::ConfirmSnsPostPermission, "ConfirmSnsPostPermission"}, - {1005, nullptr, "ConfirmSystemSettingsPermission"}, - {1006, &IParentalControlService::IsRestrictionTemporaryUnlocked, "IsRestrictionTemporaryUnlocked"}, - {1007, nullptr, "RevertRestrictionTemporaryUnlocked"}, - {1008, nullptr, "EnterRestrictedSystemSettings"}, - {1009, nullptr, "LeaveRestrictedSystemSettings"}, - {1010, nullptr, "IsRestrictedSystemSettingsEntered"}, - {1011, nullptr, "RevertRestrictedSystemSettingsEntered"}, - {1012, nullptr, "GetRestrictedFeatures"}, - {1013, &IParentalControlService::ConfirmStereoVisionPermission, "ConfirmStereoVisionPermission"}, - {1014, nullptr, "ConfirmPlayableApplicationVideoOld"}, - {1015, nullptr, "ConfirmPlayableApplicationVideo"}, - {1016, nullptr, "ConfirmShowNewsPermission"}, - {1017, &IParentalControlService::EndFreeCommunication, "EndFreeCommunication"}, - {1018, &IParentalControlService::IsFreeCommunicationAvailable, "IsFreeCommunicationAvailable"}, - {1031, &IParentalControlService::IsRestrictionEnabled, "IsRestrictionEnabled"}, - {1032, &IParentalControlService::GetSafetyLevel, "GetSafetyLevel"}, - {1033, nullptr, "SetSafetyLevel"}, - {1034, nullptr, "GetSafetyLevelSettings"}, - {1035, &IParentalControlService::GetCurrentSettings, "GetCurrentSettings"}, - {1036, nullptr, "SetCustomSafetyLevelSettings"}, - {1037, nullptr, "GetDefaultRatingOrganization"}, - {1038, nullptr, "SetDefaultRatingOrganization"}, - {1039, &IParentalControlService::GetFreeCommunicationApplicationListCount, "GetFreeCommunicationApplicationListCount"}, - {1042, nullptr, "AddToFreeCommunicationApplicationList"}, - {1043, nullptr, "DeleteSettings"}, - {1044, nullptr, "GetFreeCommunicationApplicationList"}, - {1045, nullptr, "UpdateFreeCommunicationApplicationList"}, - {1046, nullptr, "DisableFeaturesForReset"}, - {1047, nullptr, "NotifyApplicationDownloadStarted"}, - {1048, nullptr, "NotifyNetworkProfileCreated"}, - {1049, nullptr, "ResetFreeCommunicationApplicationList"}, - {1061, &IParentalControlService::ConfirmStereoVisionRestrictionConfigurable, "ConfirmStereoVisionRestrictionConfigurable"}, - {1062, &IParentalControlService::GetStereoVisionRestriction, "GetStereoVisionRestriction"}, - {1063, &IParentalControlService::SetStereoVisionRestriction, "SetStereoVisionRestriction"}, - {1064, &IParentalControlService::ResetConfirmedStereoVisionPermission, "ResetConfirmedStereoVisionPermission"}, - {1065, &IParentalControlService::IsStereoVisionPermitted, "IsStereoVisionPermitted"}, - {1201, nullptr, "UnlockRestrictionTemporarily"}, - {1202, nullptr, "UnlockSystemSettingsRestriction"}, - {1203, nullptr, "SetPinCode"}, - {1204, nullptr, "GenerateInquiryCode"}, - {1205, nullptr, "CheckMasterKey"}, - {1206, nullptr, "GetPinCodeLength"}, - {1207, nullptr, "GetPinCodeChangedEvent"}, - {1208, nullptr, "GetPinCode"}, - {1403, &IParentalControlService::IsPairingActive, "IsPairingActive"}, - {1406, nullptr, "GetSettingsLastUpdated"}, - {1411, nullptr, "GetPairingAccountInfo"}, - {1421, nullptr, "GetAccountNickname"}, - {1424, nullptr, "GetAccountState"}, - {1425, nullptr, "RequestPostEvents"}, - {1426, nullptr, "GetPostEventInterval"}, - {1427, nullptr, "SetPostEventInterval"}, - {1432, &IParentalControlService::GetSynchronizationEvent, "GetSynchronizationEvent"}, - {1451, nullptr, "StartPlayTimer"}, - {1452, nullptr, "StopPlayTimer"}, - {1453, nullptr, "IsPlayTimerEnabled"}, - {1454, nullptr, "GetPlayTimerRemainingTime"}, - {1455, nullptr, "IsRestrictedByPlayTimer"}, - {1456, &IParentalControlService::GetPlayTimerSettings, "GetPlayTimerSettings"}, - {1457, &IParentalControlService::GetPlayTimerEventToRequestSuspension, "GetPlayTimerEventToRequestSuspension"}, - {1458, &IParentalControlService::IsPlayTimerAlarmDisabled, "IsPlayTimerAlarmDisabled"}, - {1471, nullptr, "NotifyWrongPinCodeInputManyTimes"}, - {1472, nullptr, "CancelNetworkRequest"}, - {1473, &IParentalControlService::GetUnlinkedEvent, "GetUnlinkedEvent"}, - {1474, nullptr, "ClearUnlinkedEvent"}, - {1601, nullptr, "DisableAllFeatures"}, - {1602, nullptr, "PostEnableAllFeatures"}, - {1603, nullptr, "IsAllFeaturesDisabled"}, - {1901, nullptr, "DeleteFromFreeCommunicationApplicationListForDebug"}, - {1902, nullptr, "ClearFreeCommunicationApplicationListForDebug"}, - {1903, nullptr, "GetExemptApplicationListCountForDebug"}, - {1904, nullptr, "GetExemptApplicationListForDebug"}, - {1905, nullptr, "UpdateExemptApplicationListForDebug"}, - {1906, nullptr, "AddToExemptApplicationListForDebug"}, - {1907, nullptr, "DeleteFromExemptApplicationListForDebug"}, - {1908, nullptr, "ClearExemptApplicationListForDebug"}, - {1941, nullptr, "DeletePairing"}, - {1951, nullptr, "SetPlayTimerSettingsForDebug"}, - {1952, nullptr, "GetPlayTimerSpentTimeForTest"}, - {1953, nullptr, "SetPlayTimerAlarmDisabledForDebug"}, - {2001, nullptr, "RequestPairingAsync"}, - {2002, nullptr, "FinishRequestPairing"}, - {2003, nullptr, "AuthorizePairingAsync"}, - {2004, nullptr, "FinishAuthorizePairing"}, - {2005, nullptr, "RetrievePairingInfoAsync"}, - {2006, nullptr, "FinishRetrievePairingInfo"}, - {2007, nullptr, "UnlinkPairingAsync"}, - {2008, nullptr, "FinishUnlinkPairing"}, - {2009, nullptr, "GetAccountMiiImageAsync"}, - {2010, nullptr, "FinishGetAccountMiiImage"}, - {2011, nullptr, "GetAccountMiiImageContentTypeAsync"}, - {2012, nullptr, "FinishGetAccountMiiImageContentType"}, - {2013, nullptr, "SynchronizeParentalControlSettingsAsync"}, - {2014, nullptr, "FinishSynchronizeParentalControlSettings"}, - {2015, nullptr, "FinishSynchronizeParentalControlSettingsWithLastUpdated"}, - {2016, nullptr, "RequestUpdateExemptionListAsync"}, - }; - // clang-format on - RegisterHandlers(functions); - - synchronization_event = - service_context.CreateEvent("IParentalControlService::SynchronizationEvent"); - unlinked_event = service_context.CreateEvent("IParentalControlService::UnlinkedEvent"); - request_suspension_event = - service_context.CreateEvent("IParentalControlService::RequestSuspensionEvent"); - } - - ~IParentalControlService() { - service_context.CloseEvent(synchronization_event); - service_context.CloseEvent(unlinked_event); - service_context.CloseEvent(request_suspension_event); - }; - -private: - bool CheckFreeCommunicationPermissionImpl() const { - if (states.temporary_unlocked) { - return true; - } - if ((states.application_info.parental_control_flag & 1) == 0) { - return true; - } - if (pin_code[0] == '\0') { - return true; - } - if (!settings.is_free_communication_default_on) { - return true; - } - // TODO(ogniK): Check for blacklisted/exempted applications. Return false can happen here - // but as we don't have multiproceses support yet, we can just assume our application is - // valid for the time being - return true; - } - - bool ConfirmStereoVisionPermissionImpl() const { - if (states.temporary_unlocked) { - return true; - } - if (pin_code[0] == '\0') { - return true; - } - if (!settings.is_stero_vision_restricted) { - return false; - } - return true; - } - - void SetStereoVisionRestrictionImpl(bool is_restricted) { - if (settings.disabled) { - return; - } - - if (pin_code[0] == '\0') { - return; - } - settings.is_stero_vision_restricted = is_restricted; - } - - void Initialize(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 2}; - - if (False(capability & (Capability::Application | Capability::System))) { - LOG_ERROR(Service_PCTL, "Invalid capability! capability={:X}", capability); - return; - } - - // TODO(ogniK): Recovery flag initialization for pctl:r - - const auto tid = system.GetApplicationProcessProgramID(); - if (tid != 0) { - const FileSys::PatchManager pm{tid, system.GetFileSystemController(), - system.GetContentProvider()}; - const auto control = pm.GetControlMetadata(); - if (control.first) { - states.tid_from_event = 0; - states.launch_time_valid = false; - states.is_suspended = false; - states.free_communication = false; - states.stereo_vision = false; - states.application_info = ApplicationInfo{ - .application_id = tid, - .age_rating = control.first->GetRatingAge(), - .parental_control_flag = control.first->GetParentalControlFlag(), - .capability = capability, - }; - - if (False(capability & (Capability::System | Capability::Recovery))) { - // TODO(ogniK): Signal application launch event - } - } - } - - rb.Push(ResultSuccess); - } - - void CheckFreeCommunicationPermission(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2}; - if (!CheckFreeCommunicationPermissionImpl()) { - rb.Push(ResultNoFreeCommunication); - } else { - rb.Push(ResultSuccess); - } - - states.free_communication = true; - } - - void ConfirmSnsPostPermission(HLERequestContext& ctx) { - LOG_WARNING(Service_PCTL, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultNoFreeCommunication); - } - - void IsRestrictionTemporaryUnlocked(HLERequestContext& ctx) { - const bool is_temporary_unlocked = false; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, is_temporary_unlocked={}", - is_temporary_unlocked); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_temporary_unlocked); - } - - void ConfirmStereoVisionPermission(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - states.stereo_vision = true; - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - } - - void EndFreeCommunication(HLERequestContext& ctx) { - LOG_WARNING(Service_PCTL, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - } - - void IsFreeCommunicationAvailable(HLERequestContext& ctx) { - LOG_WARNING(Service_PCTL, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - if (!CheckFreeCommunicationPermissionImpl()) { - rb.Push(ResultNoFreeCommunication); - } else { - rb.Push(ResultSuccess); - } - } - - void IsRestrictionEnabled(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 3}; - if (False(capability & (Capability::Status | Capability::Recovery))) { - LOG_ERROR(Service_PCTL, "Application does not have Status or Recovery capabilities!"); - rb.Push(ResultNoCapability); - rb.Push(false); - return; - } - - rb.Push(pin_code[0] != '\0'); - } - - void GetSafetyLevel(HLERequestContext& ctx) { - const u32 safety_level = 0; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, safety_level={}", safety_level); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(safety_level); - } - - void GetCurrentSettings(HLERequestContext& ctx) { - LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushRaw(restriction_settings); - } - - void GetFreeCommunicationApplicationListCount(HLERequestContext& ctx) { - const u32 count = 4; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, count={}", count); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(count); - } - - void ConfirmStereoVisionRestrictionConfigurable(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2}; - - if (False(capability & Capability::StereoVision)) { - LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(ResultNoCapability); - return; - } - - if (pin_code[0] == '\0') { - rb.Push(ResultNoRestrictionEnabled); - return; - } - - rb.Push(ResultSuccess); - } - - void IsStereoVisionPermitted(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 3}; - if (!ConfirmStereoVisionPermissionImpl()) { - rb.Push(ResultStereoVisionRestricted); - rb.Push(false); - } else { - rb.Push(ResultSuccess); - rb.Push(true); - } - } - - void IsPairingActive(HLERequestContext& ctx) { - const bool is_pairing_active = false; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, is_pairing_active={}", is_pairing_active); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_pairing_active); - } - - void GetSynchronizationEvent(HLERequestContext& ctx) { - LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(synchronization_event->GetReadableEvent()); - } - - void GetPlayTimerSettings(HLERequestContext& ctx) { - LOG_WARNING(Service_PCTL, "(STUBBED) called"); - - const PlayTimerSettings timer_settings{}; - - IPC::ResponseBuilder rb{ctx, 15}; - rb.Push(ResultSuccess); - rb.PushRaw(timer_settings); - } - - void GetPlayTimerEventToRequestSuspension(HLERequestContext& ctx) { - LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(request_suspension_event->GetReadableEvent()); - } - - void IsPlayTimerAlarmDisabled(HLERequestContext& ctx) { - const bool is_play_timer_alarm_disabled = false; - - LOG_INFO(Service_PCTL, "called, is_play_timer_alarm_disabled={}", - is_play_timer_alarm_disabled); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_play_timer_alarm_disabled); - } - - void GetUnlinkedEvent(HLERequestContext& ctx) { - LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(unlinked_event->GetReadableEvent()); - } - - void SetStereoVisionRestriction(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto can_use = rp.Pop(); - LOG_DEBUG(Service_PCTL, "called, can_use={}", can_use); - - IPC::ResponseBuilder rb{ctx, 2}; - if (False(capability & Capability::StereoVision)) { - LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(ResultNoCapability); - return; - } - - SetStereoVisionRestrictionImpl(can_use); - rb.Push(ResultSuccess); - } - - void GetStereoVisionRestriction(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 3}; - if (False(capability & Capability::StereoVision)) { - LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(ResultNoCapability); - rb.Push(false); - return; - } - - rb.Push(ResultSuccess); - rb.Push(settings.is_stero_vision_restricted); - } - - void ResetConfirmedStereoVisionPermission(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - states.stereo_vision = false; - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - } - - States states{}; - ParentalControlSettings settings{}; - RestrictionSettings restriction_settings{}; - std::array pin_code{}; - Capability capability{}; - - Kernel::KEvent* synchronization_event; - Kernel::KEvent* unlinked_event; - Kernel::KEvent* request_suspension_event; - KernelHelpers::ServiceContext service_context; -}; - void Module::Interface::CreateService(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); -- cgit v1.2.3 From 0e74204aadb1753e402b333692d36b1bc7221463 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 21 Feb 2024 21:05:30 -0500 Subject: pctl: move IParentalControlServiceFactory --- .../pctl/parental_control_service_factory.cpp | 35 ++++++++++++++ .../pctl/parental_control_service_factory.h | 30 ++++++++++++ src/core/hle/service/pctl/pctl.cpp | 27 +++++++---- src/core/hle/service/pctl/pctl.h | 9 +--- src/core/hle/service/pctl/pctl_module.cpp | 56 ---------------------- src/core/hle/service/pctl/pctl_module.h | 36 -------------- 6 files changed, 84 insertions(+), 109 deletions(-) create mode 100644 src/core/hle/service/pctl/parental_control_service_factory.cpp create mode 100644 src/core/hle/service/pctl/parental_control_service_factory.h delete mode 100644 src/core/hle/service/pctl/pctl_module.cpp delete mode 100644 src/core/hle/service/pctl/pctl_module.h (limited to 'src/core/hle/service/pctl') diff --git a/src/core/hle/service/pctl/parental_control_service_factory.cpp b/src/core/hle/service/pctl/parental_control_service_factory.cpp new file mode 100644 index 000000000..1427f5a96 --- /dev/null +++ b/src/core/hle/service/pctl/parental_control_service_factory.cpp @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/pctl/parental_control_service.h" +#include "core/hle/service/pctl/parental_control_service_factory.h" + +namespace Service::PCTL { + +IParentalControlServiceFactory::IParentalControlServiceFactory(Core::System& system_, + const char* name_, + Capability capability_) + : ServiceFramework{system_, name_}, capability{capability_} {} + +IParentalControlServiceFactory::~IParentalControlServiceFactory() = default; + +void IParentalControlServiceFactory::CreateService(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + rb.Push(ResultSuccess); + // TODO(ogniK): Get TID from process + + rb.PushIpcInterface(system, capability); +} + +void IParentalControlServiceFactory::CreateServiceWithoutInitialize(HLERequestContext& ctx) { + LOG_DEBUG(Service_PCTL, "called"); + + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + rb.Push(ResultSuccess); + rb.PushIpcInterface(system, capability); +} + +} // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/parental_control_service_factory.h b/src/core/hle/service/pctl/parental_control_service_factory.h new file mode 100644 index 000000000..19195aa38 --- /dev/null +++ b/src/core/hle/service/pctl/parental_control_service_factory.h @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/pctl/pctl_types.h" +#include "core/hle/service/service.h" + +namespace Core { +class System; +} + +namespace Service::PCTL { + +class IParentalControlServiceFactory : public ServiceFramework { +public: + explicit IParentalControlServiceFactory(Core::System& system_, const char* name_, + Capability capability_); + ~IParentalControlServiceFactory() override; + + void CreateService(HLERequestContext& ctx); + void CreateServiceWithoutInitialize(HLERequestContext& ctx); + +private: + Capability capability{}; +}; + +void LoopProcess(Core::System& system); + +} // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl.cpp b/src/core/hle/service/pctl/pctl.cpp index 3f47bf094..d92dbe216 100644 --- a/src/core/hle/service/pctl/pctl.cpp +++ b/src/core/hle/service/pctl/pctl.cpp @@ -1,19 +1,28 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/pctl/parental_control_service_factory.h" #include "core/hle/service/pctl/pctl.h" +#include "core/hle/service/server_manager.h" namespace Service::PCTL { -PCTL::PCTL(Core::System& system_, std::shared_ptr module_, const char* name, - Capability capability_) - : Interface{system_, std::move(module_), name, capability_} { - static const FunctionInfo functions[] = { - {0, &PCTL::CreateService, "CreateService"}, - {1, &PCTL::CreateServiceWithoutInitialize, "CreateServiceWithoutInitialize"}, - }; - RegisterHandlers(functions); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique(system); + + server_manager->RegisterNamedService("pctl", + std::make_shared( + system, "pctl", + Capability::Application | Capability::SnsPost | + Capability::Status | Capability::StereoVision)); + // TODO(ogniK): Implement remaining capabilities + server_manager->RegisterNamedService("pctl:a", std::make_shared( + system, "pctl:a", Capability::None)); + server_manager->RegisterNamedService("pctl:r", std::make_shared( + system, "pctl:r", Capability::None)); + server_manager->RegisterNamedService("pctl:s", std::make_shared( + system, "pctl:s", Capability::None)); + ServerManager::RunServer(std::move(server_manager)); } -PCTL::~PCTL() = default; } // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl.h b/src/core/hle/service/pctl/pctl.h index 87f93161e..5f9d03d4d 100644 --- a/src/core/hle/service/pctl/pctl.h +++ b/src/core/hle/service/pctl/pctl.h @@ -3,19 +3,12 @@ #pragma once -#include "core/hle/service/pctl/pctl_module.h" - namespace Core { class System; } namespace Service::PCTL { -class PCTL final : public Module::Interface { -public: - explicit PCTL(Core::System& system_, std::shared_ptr module_, const char* name, - Capability capability_); - ~PCTL() override; -}; +void LoopProcess(Core::System& system); } // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl_module.cpp b/src/core/hle/service/pctl/pctl_module.cpp deleted file mode 100644 index 118856574..000000000 --- a/src/core/hle/service/pctl/pctl_module.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "common/logging/log.h" -#include "core/hle/service/ipc_helpers.h" -#include "core/hle/service/kernel_helpers.h" -#include "core/hle/service/pctl/parental_control_service.h" -#include "core/hle/service/pctl/pctl.h" -#include "core/hle/service/pctl/pctl_module.h" -#include "core/hle/service/server_manager.h" - -namespace Service::PCTL { - -void Module::Interface::CreateService(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - // TODO(ogniK): Get TID from process - - rb.PushIpcInterface(system, capability); -} - -void Module::Interface::CreateServiceWithoutInitialize(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(system, capability); -} - -Module::Interface::Interface(Core::System& system_, std::shared_ptr module_, - const char* name_, Capability capability_) - : ServiceFramework{system_, name_}, module{std::move(module_)}, capability{capability_} {} - -Module::Interface::~Interface() = default; - -void LoopProcess(Core::System& system) { - auto server_manager = std::make_unique(system); - - auto module = std::make_shared(); - server_manager->RegisterNamedService( - "pctl", std::make_shared(system, module, "pctl", - Capability::Application | Capability::SnsPost | - Capability::Status | Capability::StereoVision)); - // TODO(ogniK): Implement remaining capabilities - server_manager->RegisterNamedService( - "pctl:a", std::make_shared(system, module, "pctl:a", Capability::None)); - server_manager->RegisterNamedService( - "pctl:r", std::make_shared(system, module, "pctl:r", Capability::None)); - server_manager->RegisterNamedService( - "pctl:s", std::make_shared(system, module, "pctl:s", Capability::None)); - ServerManager::RunServer(std::move(server_manager)); -} - -} // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl_module.h b/src/core/hle/service/pctl/pctl_module.h deleted file mode 100644 index 715c05b20..000000000 --- a/src/core/hle/service/pctl/pctl_module.h +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "core/hle/service/pctl/pctl_types.h" -#include "core/hle/service/service.h" - -namespace Core { -class System; -} - -namespace Service::PCTL { - -class Module final { -public: - class Interface : public ServiceFramework { - public: - explicit Interface(Core::System& system_, std::shared_ptr module_, - const char* name_, Capability capability_); - ~Interface() override; - - void CreateService(HLERequestContext& ctx); - void CreateServiceWithoutInitialize(HLERequestContext& ctx); - - protected: - std::shared_ptr module; - - private: - Capability capability{}; - }; -}; - -void LoopProcess(Core::System& system); - -} // namespace Service::PCTL -- cgit v1.2.3 From 5ab49c833d26b870ee250ef008e4aa1087b46f98 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 21 Feb 2024 21:10:49 -0500 Subject: pctl: rewrite IParentalControlServiceFactory --- .../pctl/parental_control_service_factory.cpp | 33 +++++++++++++--------- .../pctl/parental_control_service_factory.h | 13 +++++---- 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'src/core/hle/service/pctl') diff --git a/src/core/hle/service/pctl/parental_control_service_factory.cpp b/src/core/hle/service/pctl/parental_control_service_factory.cpp index 1427f5a96..7d8f361e9 100644 --- a/src/core/hle/service/pctl/parental_control_service_factory.cpp +++ b/src/core/hle/service/pctl/parental_control_service_factory.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/pctl/parental_control_service.h" #include "core/hle/service/pctl/parental_control_service_factory.h" @@ -10,26 +10,31 @@ namespace Service::PCTL { IParentalControlServiceFactory::IParentalControlServiceFactory(Core::System& system_, const char* name_, Capability capability_) - : ServiceFramework{system_, name_}, capability{capability_} {} + : ServiceFramework{system_, name_}, capability{capability_} { + static const FunctionInfo functions[] = { + {0, D<&IParentalControlServiceFactory::CreateService>, "CreateService"}, + {1, D<&IParentalControlServiceFactory::CreateServiceWithoutInitialize>, + "CreateServiceWithoutInitialize"}, + }; + RegisterHandlers(functions); +} IParentalControlServiceFactory::~IParentalControlServiceFactory() = default; -void IParentalControlServiceFactory::CreateService(HLERequestContext& ctx) { +Result IParentalControlServiceFactory::CreateService( + Out> out_service, ClientProcessId process_id) { LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - // TODO(ogniK): Get TID from process - - rb.PushIpcInterface(system, capability); + // TODO(ogniK): Get application id from process + *out_service = std::make_shared(system, capability); + R_SUCCEED(); } -void IParentalControlServiceFactory::CreateServiceWithoutInitialize(HLERequestContext& ctx) { +Result IParentalControlServiceFactory::CreateServiceWithoutInitialize( + Out> out_service, ClientProcessId process_id) { LOG_DEBUG(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(system, capability); + // TODO(ogniK): Get application id from process + *out_service = std::make_shared(system, capability); + R_SUCCEED(); } } // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/parental_control_service_factory.h b/src/core/hle/service/pctl/parental_control_service_factory.h index 19195aa38..362988add 100644 --- a/src/core/hle/service/pctl/parental_control_service_factory.h +++ b/src/core/hle/service/pctl/parental_control_service_factory.h @@ -3,23 +3,24 @@ #pragma once +#include "core/hle/service/cmif_types.h" #include "core/hle/service/pctl/pctl_types.h" #include "core/hle/service/service.h" -namespace Core { -class System; -} - namespace Service::PCTL { +class IParentalControlService; + class IParentalControlServiceFactory : public ServiceFramework { public: explicit IParentalControlServiceFactory(Core::System& system_, const char* name_, Capability capability_); ~IParentalControlServiceFactory() override; - void CreateService(HLERequestContext& ctx); - void CreateServiceWithoutInitialize(HLERequestContext& ctx); + Result CreateService(Out> out_service, + ClientProcessId process_id); + Result CreateServiceWithoutInitialize(Out> out_service, + ClientProcessId process_id); private: Capability capability{}; -- cgit v1.2.3 From 89c2fd3d2830d5b1e73c9e051e4af39772963036 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 21 Feb 2024 21:41:55 -0500 Subject: pctl: rewrite IParentalControlService --- .../hle/service/pctl/parental_control_service.cpp | 341 ++++++++++----------- .../hle/service/pctl/parental_control_service.h | 62 ++-- 2 files changed, 204 insertions(+), 199 deletions(-) (limited to 'src/core/hle/service/pctl') diff --git a/src/core/hle/service/pctl/parental_control_service.cpp b/src/core/hle/service/pctl/parental_control_service.cpp index 4248b0184..f57f2f157 100644 --- a/src/core/hle/service/pctl/parental_control_service.cpp +++ b/src/core/hle/service/pctl/parental_control_service.cpp @@ -4,7 +4,7 @@ #include "core/core.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/pctl/parental_control_service.h" #include "core/hle/service/pctl/pctl_results.h" @@ -12,37 +12,38 @@ namespace Service::PCTL { IParentalControlService::IParentalControlService(Core::System& system_, Capability capability_) : ServiceFramework{system_, "IParentalControlService"}, capability{capability_}, - service_context{system_, "IParentalControlService"} { + service_context{system_, "IParentalControlService"}, synchronization_event{service_context}, + unlinked_event{service_context}, request_suspension_event{service_context} { // clang-format off static const FunctionInfo functions[] = { - {1, &IParentalControlService::Initialize, "Initialize"}, - {1001, &IParentalControlService::CheckFreeCommunicationPermission, "CheckFreeCommunicationPermission"}, - {1002, nullptr, "ConfirmLaunchApplicationPermission"}, - {1003, nullptr, "ConfirmResumeApplicationPermission"}, - {1004, &IParentalControlService::ConfirmSnsPostPermission, "ConfirmSnsPostPermission"}, + {1, D<&IParentalControlService::Initialize>, "Initialize"}, + {1001, D<&IParentalControlService::CheckFreeCommunicationPermission>, "CheckFreeCommunicationPermission"}, + {1002, D<&IParentalControlService::ConfirmLaunchApplicationPermission>, "ConfirmLaunchApplicationPermission"}, + {1003, D<&IParentalControlService::ConfirmResumeApplicationPermission>, "ConfirmResumeApplicationPermission"}, + {1004, D<&IParentalControlService::ConfirmSnsPostPermission>, "ConfirmSnsPostPermission"}, {1005, nullptr, "ConfirmSystemSettingsPermission"}, - {1006, &IParentalControlService::IsRestrictionTemporaryUnlocked, "IsRestrictionTemporaryUnlocked"}, + {1006, D<&IParentalControlService::IsRestrictionTemporaryUnlocked>, "IsRestrictionTemporaryUnlocked"}, {1007, nullptr, "RevertRestrictionTemporaryUnlocked"}, {1008, nullptr, "EnterRestrictedSystemSettings"}, {1009, nullptr, "LeaveRestrictedSystemSettings"}, - {1010, nullptr, "IsRestrictedSystemSettingsEntered"}, + {1010, D<&IParentalControlService::IsRestrictedSystemSettingsEntered>, "IsRestrictedSystemSettingsEntered"}, {1011, nullptr, "RevertRestrictedSystemSettingsEntered"}, {1012, nullptr, "GetRestrictedFeatures"}, - {1013, &IParentalControlService::ConfirmStereoVisionPermission, "ConfirmStereoVisionPermission"}, + {1013, D<&IParentalControlService::ConfirmStereoVisionPermission>, "ConfirmStereoVisionPermission"}, {1014, nullptr, "ConfirmPlayableApplicationVideoOld"}, {1015, nullptr, "ConfirmPlayableApplicationVideo"}, {1016, nullptr, "ConfirmShowNewsPermission"}, - {1017, &IParentalControlService::EndFreeCommunication, "EndFreeCommunication"}, - {1018, &IParentalControlService::IsFreeCommunicationAvailable, "IsFreeCommunicationAvailable"}, - {1031, &IParentalControlService::IsRestrictionEnabled, "IsRestrictionEnabled"}, - {1032, &IParentalControlService::GetSafetyLevel, "GetSafetyLevel"}, + {1017, D<&IParentalControlService::EndFreeCommunication>, "EndFreeCommunication"}, + {1018, D<&IParentalControlService::IsFreeCommunicationAvailable>, "IsFreeCommunicationAvailable"}, + {1031, D<&IParentalControlService::IsRestrictionEnabled>, "IsRestrictionEnabled"}, + {1032, D<&IParentalControlService::GetSafetyLevel>, "GetSafetyLevel"}, {1033, nullptr, "SetSafetyLevel"}, {1034, nullptr, "GetSafetyLevelSettings"}, - {1035, &IParentalControlService::GetCurrentSettings, "GetCurrentSettings"}, + {1035, D<&IParentalControlService::GetCurrentSettings>, "GetCurrentSettings"}, {1036, nullptr, "SetCustomSafetyLevelSettings"}, {1037, nullptr, "GetDefaultRatingOrganization"}, {1038, nullptr, "SetDefaultRatingOrganization"}, - {1039, &IParentalControlService::GetFreeCommunicationApplicationListCount, "GetFreeCommunicationApplicationListCount"}, + {1039, D<&IParentalControlService::GetFreeCommunicationApplicationListCount>, "GetFreeCommunicationApplicationListCount"}, {1042, nullptr, "AddToFreeCommunicationApplicationList"}, {1043, nullptr, "DeleteSettings"}, {1044, nullptr, "GetFreeCommunicationApplicationList"}, @@ -51,20 +52,20 @@ IParentalControlService::IParentalControlService(Core::System& system_, Capabili {1047, nullptr, "NotifyApplicationDownloadStarted"}, {1048, nullptr, "NotifyNetworkProfileCreated"}, {1049, nullptr, "ResetFreeCommunicationApplicationList"}, - {1061, &IParentalControlService::ConfirmStereoVisionRestrictionConfigurable, "ConfirmStereoVisionRestrictionConfigurable"}, - {1062, &IParentalControlService::GetStereoVisionRestriction, "GetStereoVisionRestriction"}, - {1063, &IParentalControlService::SetStereoVisionRestriction, "SetStereoVisionRestriction"}, - {1064, &IParentalControlService::ResetConfirmedStereoVisionPermission, "ResetConfirmedStereoVisionPermission"}, - {1065, &IParentalControlService::IsStereoVisionPermitted, "IsStereoVisionPermitted"}, + {1061, D<&IParentalControlService::ConfirmStereoVisionRestrictionConfigurable>, "ConfirmStereoVisionRestrictionConfigurable"}, + {1062, D<&IParentalControlService::GetStereoVisionRestriction>, "GetStereoVisionRestriction"}, + {1063, D<&IParentalControlService::SetStereoVisionRestriction>, "SetStereoVisionRestriction"}, + {1064, D<&IParentalControlService::ResetConfirmedStereoVisionPermission>, "ResetConfirmedStereoVisionPermission"}, + {1065, D<&IParentalControlService::IsStereoVisionPermitted>, "IsStereoVisionPermitted"}, {1201, nullptr, "UnlockRestrictionTemporarily"}, {1202, nullptr, "UnlockSystemSettingsRestriction"}, {1203, nullptr, "SetPinCode"}, {1204, nullptr, "GenerateInquiryCode"}, {1205, nullptr, "CheckMasterKey"}, - {1206, nullptr, "GetPinCodeLength"}, + {1206, D<&IParentalControlService::GetPinCodeLength>, "GetPinCodeLength"}, {1207, nullptr, "GetPinCodeChangedEvent"}, {1208, nullptr, "GetPinCode"}, - {1403, &IParentalControlService::IsPairingActive, "IsPairingActive"}, + {1403, D<&IParentalControlService::IsPairingActive>, "IsPairingActive"}, {1406, nullptr, "GetSettingsLastUpdated"}, {1411, nullptr, "GetPairingAccountInfo"}, {1421, nullptr, "GetAccountNickname"}, @@ -72,18 +73,18 @@ IParentalControlService::IParentalControlService(Core::System& system_, Capabili {1425, nullptr, "RequestPostEvents"}, {1426, nullptr, "GetPostEventInterval"}, {1427, nullptr, "SetPostEventInterval"}, - {1432, &IParentalControlService::GetSynchronizationEvent, "GetSynchronizationEvent"}, - {1451, nullptr, "StartPlayTimer"}, - {1452, nullptr, "StopPlayTimer"}, - {1453, nullptr, "IsPlayTimerEnabled"}, + {1432, D<&IParentalControlService::GetSynchronizationEvent>, "GetSynchronizationEvent"}, + {1451, D<&IParentalControlService::StartPlayTimer>, "StartPlayTimer"}, + {1452, D<&IParentalControlService::StopPlayTimer>, "StopPlayTimer"}, + {1453, D<&IParentalControlService::IsPlayTimerEnabled>, "IsPlayTimerEnabled"}, {1454, nullptr, "GetPlayTimerRemainingTime"}, - {1455, nullptr, "IsRestrictedByPlayTimer"}, - {1456, &IParentalControlService::GetPlayTimerSettings, "GetPlayTimerSettings"}, - {1457, &IParentalControlService::GetPlayTimerEventToRequestSuspension, "GetPlayTimerEventToRequestSuspension"}, - {1458, &IParentalControlService::IsPlayTimerAlarmDisabled, "IsPlayTimerAlarmDisabled"}, + {1455, D<&IParentalControlService::IsRestrictedByPlayTimer>, "IsRestrictedByPlayTimer"}, + {1456, D<&IParentalControlService::GetPlayTimerSettings>, "GetPlayTimerSettings"}, + {1457, D<&IParentalControlService::GetPlayTimerEventToRequestSuspension>, "GetPlayTimerEventToRequestSuspension"}, + {1458, D<&IParentalControlService::IsPlayTimerAlarmDisabled>, "IsPlayTimerAlarmDisabled"}, {1471, nullptr, "NotifyWrongPinCodeInputManyTimes"}, {1472, nullptr, "CancelNetworkRequest"}, - {1473, &IParentalControlService::GetUnlinkedEvent, "GetUnlinkedEvent"}, + {1473, D<&IParentalControlService::GetUnlinkedEvent>, "GetUnlinkedEvent"}, {1474, nullptr, "ClearUnlinkedEvent"}, {1601, nullptr, "DisableAllFeatures"}, {1602, nullptr, "PostEnableAllFeatures"}, @@ -119,19 +120,9 @@ IParentalControlService::IParentalControlService(Core::System& system_, Capabili }; // clang-format on RegisterHandlers(functions); - - synchronization_event = - service_context.CreateEvent("IParentalControlService::SynchronizationEvent"); - unlinked_event = service_context.CreateEvent("IParentalControlService::UnlinkedEvent"); - request_suspension_event = - service_context.CreateEvent("IParentalControlService::RequestSuspensionEvent"); } -IParentalControlService::~IParentalControlService() { - service_context.CloseEvent(synchronization_event); - service_context.CloseEvent(unlinked_event); - service_context.CloseEvent(request_suspension_event); -} +IParentalControlService::~IParentalControlService() = default; bool IParentalControlService::CheckFreeCommunicationPermissionImpl() const { if (states.temporary_unlocked) { @@ -176,20 +167,19 @@ void IParentalControlService::SetStereoVisionRestrictionImpl(bool is_restricted) settings.is_stero_vision_restricted = is_restricted; } -void IParentalControlService::Initialize(HLERequestContext& ctx) { +Result IParentalControlService::Initialize() { LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 2}; if (False(capability & (Capability::Application | Capability::System))) { LOG_ERROR(Service_PCTL, "Invalid capability! capability={:X}", capability); - return; + R_THROW(PCTL::ResultNoCapability); } // TODO(ogniK): Recovery flag initialization for pctl:r - const auto tid = system.GetApplicationProcessProgramID(); - if (tid != 0) { - const FileSys::PatchManager pm{tid, system.GetFileSystemController(), + const auto program_id = system.GetApplicationProcessProgramID(); + if (program_id != 0) { + const FileSys::PatchManager pm{program_id, system.GetFileSystemController(), system.GetContentProvider()}; const auto control = pm.GetControlMetadata(); if (control.first) { @@ -199,7 +189,7 @@ void IParentalControlService::Initialize(HLERequestContext& ctx) { states.free_communication = false; states.stereo_vision = false; states.application_info = ApplicationInfo{ - .application_id = tid, + .application_id = program_id, .age_rating = control.first->GetRatingAge(), .parental_control_flag = control.first->GetParentalControlFlag(), .capability = capability, @@ -211,231 +201,234 @@ void IParentalControlService::Initialize(HLERequestContext& ctx) { } } - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IParentalControlService::CheckFreeCommunicationPermission(HLERequestContext& ctx) { +Result IParentalControlService::CheckFreeCommunicationPermission() { LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 2}; if (!CheckFreeCommunicationPermissionImpl()) { - rb.Push(PCTL::ResultNoFreeCommunication); + R_THROW(PCTL::ResultNoFreeCommunication); } else { - rb.Push(ResultSuccess); + states.free_communication = true; + R_SUCCEED(); } - - states.free_communication = true; } -void IParentalControlService::ConfirmSnsPostPermission(HLERequestContext& ctx) { - LOG_WARNING(Service_PCTL, "(STUBBED) called"); +Result IParentalControlService::ConfirmLaunchApplicationPermission( + InBuffer restriction_bitset, u64 nacp_flag, u64 application_id) { + LOG_WARNING(Service_PCTL, "(STUBBED) called, nacp_flag={:#x} application_id={:016X}", nacp_flag, + application_id); + R_SUCCEED(); +} - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(PCTL::ResultNoFreeCommunication); +Result IParentalControlService::ConfirmResumeApplicationPermission( + InBuffer restriction_bitset, u64 nacp_flag, u64 application_id) { + LOG_WARNING(Service_PCTL, "(STUBBED) called, nacp_flag={:#x} application_id={:016X}", nacp_flag, + application_id); + R_SUCCEED(); } -void IParentalControlService::IsRestrictionTemporaryUnlocked(HLERequestContext& ctx) { - const bool is_temporary_unlocked = false; +Result IParentalControlService::ConfirmSnsPostPermission() { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + R_THROW(PCTL::ResultNoFreeCommunication); +} - LOG_WARNING(Service_PCTL, "(STUBBED) called, is_temporary_unlocked={}", is_temporary_unlocked); +Result IParentalControlService::IsRestrictionTemporaryUnlocked( + Out out_is_temporary_unlocked) { + *out_is_temporary_unlocked = false; + LOG_WARNING(Service_PCTL, "(STUBBED) called, is_temporary_unlocked={}", + *out_is_temporary_unlocked); + R_SUCCEED(); +} - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_temporary_unlocked); +Result IParentalControlService::IsRestrictedSystemSettingsEntered( + Out out_is_restricted_system_settings_entered) { + *out_is_restricted_system_settings_entered = false; + LOG_WARNING(Service_PCTL, "(STUBBED) called, is_temporary_unlocked={}", + *out_is_restricted_system_settings_entered); + R_SUCCEED(); } -void IParentalControlService::ConfirmStereoVisionPermission(HLERequestContext& ctx) { +Result IParentalControlService::ConfirmStereoVisionPermission() { LOG_DEBUG(Service_PCTL, "called"); states.stereo_vision = true; - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IParentalControlService::EndFreeCommunication(HLERequestContext& ctx) { +Result IParentalControlService::EndFreeCommunication() { LOG_WARNING(Service_PCTL, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IParentalControlService::IsFreeCommunicationAvailable(HLERequestContext& ctx) { +Result IParentalControlService::IsFreeCommunicationAvailable() { LOG_WARNING(Service_PCTL, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2}; if (!CheckFreeCommunicationPermissionImpl()) { - rb.Push(PCTL::ResultNoFreeCommunication); + R_THROW(PCTL::ResultNoFreeCommunication); } else { - rb.Push(ResultSuccess); + R_SUCCEED(); } } -void IParentalControlService::IsRestrictionEnabled(HLERequestContext& ctx) { +Result IParentalControlService::IsRestrictionEnabled(Out out_restriction_enabled) { LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 3}; if (False(capability & (Capability::Status | Capability::Recovery))) { LOG_ERROR(Service_PCTL, "Application does not have Status or Recovery capabilities!"); - rb.Push(PCTL::ResultNoCapability); - rb.Push(false); - return; + *out_restriction_enabled = false; + R_THROW(PCTL::ResultNoCapability); } - rb.Push(pin_code[0] != '\0'); + *out_restriction_enabled = pin_code[0] != '\0'; + R_SUCCEED(); } -void IParentalControlService::GetSafetyLevel(HLERequestContext& ctx) { - const u32 safety_level = 0; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, safety_level={}", safety_level); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(safety_level); +Result IParentalControlService::GetSafetyLevel(Out out_safety_level) { + *out_safety_level = 0; + LOG_WARNING(Service_PCTL, "(STUBBED) called, safety_level={}", *out_safety_level); + R_SUCCEED(); } -void IParentalControlService::GetCurrentSettings(HLERequestContext& ctx) { +Result IParentalControlService::GetCurrentSettings(Out out_settings) { LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushRaw(restriction_settings); + *out_settings = restriction_settings; + R_SUCCEED(); } -void IParentalControlService::GetFreeCommunicationApplicationListCount(HLERequestContext& ctx) { - const u32 count = 4; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, count={}", count); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(count); +Result IParentalControlService::GetFreeCommunicationApplicationListCount(Out out_count) { + *out_count = 4; + LOG_WARNING(Service_PCTL, "(STUBBED) called, count={}", *out_count); + R_SUCCEED(); } -void IParentalControlService::ConfirmStereoVisionRestrictionConfigurable(HLERequestContext& ctx) { +Result IParentalControlService::ConfirmStereoVisionRestrictionConfigurable() { LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 2}; - if (False(capability & Capability::StereoVision)) { LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(PCTL::ResultNoCapability); - return; + R_THROW(PCTL::ResultNoCapability); } if (pin_code[0] == '\0') { - rb.Push(PCTL::ResultNoRestrictionEnabled); - return; + R_THROW(PCTL::ResultNoRestrictionEnabled); } - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IParentalControlService::IsStereoVisionPermitted(HLERequestContext& ctx) { +Result IParentalControlService::IsStereoVisionPermitted(Out out_is_permitted) { LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 3}; if (!ConfirmStereoVisionPermissionImpl()) { - rb.Push(PCTL::ResultStereoVisionRestricted); - rb.Push(false); + *out_is_permitted = false; + R_THROW(PCTL::ResultStereoVisionRestricted); } else { - rb.Push(ResultSuccess); - rb.Push(true); + *out_is_permitted = true; + R_SUCCEED(); } } -void IParentalControlService::IsPairingActive(HLERequestContext& ctx) { - const bool is_pairing_active = false; - - LOG_WARNING(Service_PCTL, "(STUBBED) called, is_pairing_active={}", is_pairing_active); +Result IParentalControlService::GetPinCodeLength(Out out_length) { + *out_length = 0; + LOG_WARNING(Service_PCTL, "(STUBBED) called, length={}", *out_length); + R_SUCCEED(); +} - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_pairing_active); +Result IParentalControlService::IsPairingActive(Out out_is_pairing_active) { + *out_is_pairing_active = false; + LOG_WARNING(Service_PCTL, "(STUBBED) called, is_pairing_active={}", *out_is_pairing_active); + R_SUCCEED(); } -void IParentalControlService::GetSynchronizationEvent(HLERequestContext& ctx) { +Result IParentalControlService::GetSynchronizationEvent( + OutCopyHandle out_event) { LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(synchronization_event->GetReadableEvent()); + *out_event = synchronization_event.GetHandle(); + R_SUCCEED(); } -void IParentalControlService::GetPlayTimerSettings(HLERequestContext& ctx) { +Result IParentalControlService::StartPlayTimer() { LOG_WARNING(Service_PCTL, "(STUBBED) called"); + R_SUCCEED(); +} - const PlayTimerSettings timer_settings{}; - - IPC::ResponseBuilder rb{ctx, 15}; - rb.Push(ResultSuccess); - rb.PushRaw(timer_settings); +Result IParentalControlService::StopPlayTimer() { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + R_SUCCEED(); } -void IParentalControlService::GetPlayTimerEventToRequestSuspension(HLERequestContext& ctx) { - LOG_INFO(Service_PCTL, "called"); +Result IParentalControlService::IsPlayTimerEnabled(Out out_is_play_timer_enabled) { + *out_is_play_timer_enabled = false; + LOG_WARNING(Service_PCTL, "(STUBBED) called, enabled={}", *out_is_play_timer_enabled); + R_SUCCEED(); +} - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(request_suspension_event->GetReadableEvent()); +Result IParentalControlService::IsRestrictedByPlayTimer(Out out_is_restricted_by_play_timer) { + *out_is_restricted_by_play_timer = false; + LOG_WARNING(Service_PCTL, "(STUBBED) called, restricted={}", *out_is_restricted_by_play_timer); + R_SUCCEED(); } -void IParentalControlService::IsPlayTimerAlarmDisabled(HLERequestContext& ctx) { - const bool is_play_timer_alarm_disabled = false; +Result IParentalControlService::GetPlayTimerSettings( + Out out_play_timer_settings) { + LOG_WARNING(Service_PCTL, "(STUBBED) called"); + *out_play_timer_settings = {}; + R_SUCCEED(); +} - LOG_INFO(Service_PCTL, "called, is_play_timer_alarm_disabled={}", is_play_timer_alarm_disabled); +Result IParentalControlService::GetPlayTimerEventToRequestSuspension( + OutCopyHandle out_event) { + LOG_INFO(Service_PCTL, "called"); + *out_event = request_suspension_event.GetHandle(); + R_SUCCEED(); +} - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(is_play_timer_alarm_disabled); +Result IParentalControlService::IsPlayTimerAlarmDisabled(Out out_play_timer_alarm_disabled) { + *out_play_timer_alarm_disabled = false; + LOG_INFO(Service_PCTL, "called, is_play_timer_alarm_disabled={}", + *out_play_timer_alarm_disabled); + R_SUCCEED(); } -void IParentalControlService::GetUnlinkedEvent(HLERequestContext& ctx) { +Result IParentalControlService::GetUnlinkedEvent(OutCopyHandle out_event) { LOG_INFO(Service_PCTL, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(unlinked_event->GetReadableEvent()); + *out_event = unlinked_event.GetHandle(); + R_SUCCEED(); } -void IParentalControlService::SetStereoVisionRestriction(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto can_use = rp.Pop(); - LOG_DEBUG(Service_PCTL, "called, can_use={}", can_use); +Result IParentalControlService::GetStereoVisionRestriction( + Out out_stereo_vision_restriction) { + LOG_DEBUG(Service_PCTL, "called"); - IPC::ResponseBuilder rb{ctx, 2}; if (False(capability & Capability::StereoVision)) { LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(PCTL::ResultNoCapability); - return; + *out_stereo_vision_restriction = false; + R_THROW(PCTL::ResultNoCapability); } - SetStereoVisionRestrictionImpl(can_use); - rb.Push(ResultSuccess); + *out_stereo_vision_restriction = settings.is_stero_vision_restricted; + R_SUCCEED(); } -void IParentalControlService::GetStereoVisionRestriction(HLERequestContext& ctx) { - LOG_DEBUG(Service_PCTL, "called"); +Result IParentalControlService::SetStereoVisionRestriction(bool stereo_vision_restriction) { + LOG_DEBUG(Service_PCTL, "called, can_use={}", stereo_vision_restriction); - IPC::ResponseBuilder rb{ctx, 3}; if (False(capability & Capability::StereoVision)) { LOG_ERROR(Service_PCTL, "Application does not have StereoVision capability!"); - rb.Push(PCTL::ResultNoCapability); - rb.Push(false); - return; + R_THROW(PCTL::ResultNoCapability); } - rb.Push(ResultSuccess); - rb.Push(settings.is_stero_vision_restricted); + SetStereoVisionRestrictionImpl(stereo_vision_restriction); + R_SUCCEED(); } -void IParentalControlService::ResetConfirmedStereoVisionPermission(HLERequestContext& ctx) { +Result IParentalControlService::ResetConfirmedStereoVisionPermission() { LOG_DEBUG(Service_PCTL, "called"); states.stereo_vision = false; - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } } // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/parental_control_service.h b/src/core/hle/service/pctl/parental_control_service.h index dcc357f65..03dbaa2e5 100644 --- a/src/core/hle/service/pctl/parental_control_service.h +++ b/src/core/hle/service/pctl/parental_control_service.h @@ -3,7 +3,9 @@ #pragma once +#include "core/hle/service/cmif_types.h" #include "core/hle/service/kernel_helpers.h" +#include "core/hle/service/os/event.h" #include "core/hle/service/pctl/pctl_types.h" #include "core/hle/service/service.h" @@ -19,28 +21,38 @@ private: bool ConfirmStereoVisionPermissionImpl() const; void SetStereoVisionRestrictionImpl(bool is_restricted); - void Initialize(HLERequestContext& ctx); - void CheckFreeCommunicationPermission(HLERequestContext& ctx); - void ConfirmSnsPostPermission(HLERequestContext& ctx); - void IsRestrictionTemporaryUnlocked(HLERequestContext& ctx); - void ConfirmStereoVisionPermission(HLERequestContext& ctx); - void EndFreeCommunication(HLERequestContext& ctx); - void IsFreeCommunicationAvailable(HLERequestContext& ctx); - void IsRestrictionEnabled(HLERequestContext& ctx); - void GetSafetyLevel(HLERequestContext& ctx); - void GetCurrentSettings(HLERequestContext& ctx); - void GetFreeCommunicationApplicationListCount(HLERequestContext& ctx); - void ConfirmStereoVisionRestrictionConfigurable(HLERequestContext& ctx); - void IsStereoVisionPermitted(HLERequestContext& ctx); - void IsPairingActive(HLERequestContext& ctx); - void GetSynchronizationEvent(HLERequestContext& ctx); - void GetPlayTimerSettings(HLERequestContext& ctx); - void GetPlayTimerEventToRequestSuspension(HLERequestContext& ctx); - void IsPlayTimerAlarmDisabled(HLERequestContext& ctx); - void GetUnlinkedEvent(HLERequestContext& ctx); - void SetStereoVisionRestriction(HLERequestContext& ctx); - void GetStereoVisionRestriction(HLERequestContext& ctx); - void ResetConfirmedStereoVisionPermission(HLERequestContext& ctx); + Result Initialize(); + Result CheckFreeCommunicationPermission(); + Result ConfirmLaunchApplicationPermission(InBuffer restriction_bitset, + u64 nacp_flag, u64 application_id); + Result ConfirmResumeApplicationPermission(InBuffer restriction_bitset, + u64 nacp_flag, u64 application_id); + Result ConfirmSnsPostPermission(); + Result IsRestrictionTemporaryUnlocked(Out out_is_temporary_unlocked); + Result IsRestrictedSystemSettingsEntered(Out out_is_restricted_system_settings_entered); + Result ConfirmStereoVisionPermission(); + Result EndFreeCommunication(); + Result IsFreeCommunicationAvailable(); + Result IsRestrictionEnabled(Out out_restriction_enabled); + Result GetSafetyLevel(Out out_safety_level); + Result GetCurrentSettings(Out out_settings); + Result GetFreeCommunicationApplicationListCount(Out out_count); + Result ConfirmStereoVisionRestrictionConfigurable(); + Result IsStereoVisionPermitted(Out out_is_permitted); + Result GetPinCodeLength(Out out_length); + Result IsPairingActive(Out out_is_pairing_active); + Result GetSynchronizationEvent(OutCopyHandle out_event); + Result StartPlayTimer(); + Result StopPlayTimer(); + Result IsPlayTimerEnabled(Out out_is_play_timer_enabled); + Result IsRestrictedByPlayTimer(Out out_is_restricted_by_play_timer); + Result GetPlayTimerSettings(Out out_play_timer_settings); + Result GetPlayTimerEventToRequestSuspension(OutCopyHandle out_event); + Result IsPlayTimerAlarmDisabled(Out out_play_timer_alarm_disabled); + Result GetUnlinkedEvent(OutCopyHandle out_event); + Result GetStereoVisionRestriction(Out out_stereo_vision_restriction); + Result SetStereoVisionRestriction(bool stereo_vision_restriction); + Result ResetConfirmedStereoVisionPermission(); struct States { u64 current_tid{}; @@ -65,10 +77,10 @@ private: std::array pin_code{}; Capability capability{}; - Kernel::KEvent* synchronization_event; - Kernel::KEvent* unlinked_event; - Kernel::KEvent* request_suspension_event; KernelHelpers::ServiceContext service_context; + Event synchronization_event; + Event unlinked_event; + Event request_suspension_event; }; } // namespace Service::PCTL -- cgit v1.2.3