spl_module.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <algorithm>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <vector>
  7. #include "common/logging/log.h"
  8. #include "common/settings.h"
  9. #include "core/hle/api_version.h"
  10. #include "core/hle/ipc_helpers.h"
  11. #include "core/hle/service/spl/csrng.h"
  12. #include "core/hle/service/spl/spl.h"
  13. #include "core/hle/service/spl/spl_module.h"
  14. namespace Service::SPL {
  15. Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> module_,
  16. const char* name)
  17. : ServiceFramework{system_, name}, module{std::move(module_)},
  18. rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr))) {}
  19. Module::Interface::~Interface() = default;
  20. void Module::Interface::GetConfig(Kernel::HLERequestContext& ctx) {
  21. IPC::RequestParser rp{ctx};
  22. const auto config_item = rp.PopEnum<ConfigItem>();
  23. // This should call svcCallSecureMonitor with the appropriate args.
  24. // Since we do not have it implemented yet, we will use this for now.
  25. const auto smc_result = GetConfigImpl(config_item);
  26. const auto result_code = smc_result.Code();
  27. if (smc_result.Failed()) {
  28. LOG_ERROR(Service_SPL, "called, config_item={}, result_code={}", config_item,
  29. result_code.raw);
  30. IPC::ResponseBuilder rb{ctx, 2};
  31. rb.Push(result_code);
  32. }
  33. LOG_DEBUG(Service_SPL, "called, config_item={}, result_code={}, smc_result={}", config_item,
  34. result_code.raw, *smc_result);
  35. IPC::ResponseBuilder rb{ctx, 4};
  36. rb.Push(result_code);
  37. rb.Push(*smc_result);
  38. }
  39. void Module::Interface::ModularExponentiate(Kernel::HLERequestContext& ctx) {
  40. UNIMPLEMENTED_MSG("ModularExponentiate is not implemented!");
  41. IPC::ResponseBuilder rb{ctx, 2};
  42. rb.Push(ResultSecureMonitorNotImplemented);
  43. }
  44. void Module::Interface::SetConfig(Kernel::HLERequestContext& ctx) {
  45. UNIMPLEMENTED_MSG("SetConfig is not implemented!");
  46. IPC::ResponseBuilder rb{ctx, 2};
  47. rb.Push(ResultSecureMonitorNotImplemented);
  48. }
  49. void Module::Interface::GenerateRandomBytes(Kernel::HLERequestContext& ctx) {
  50. LOG_DEBUG(Service_SPL, "called");
  51. const std::size_t size = ctx.GetWriteBufferSize();
  52. std::uniform_int_distribution<u16> distribution(0, std::numeric_limits<u8>::max());
  53. std::vector<u8> data(size);
  54. std::generate(data.begin(), data.end(), [&] { return static_cast<u8>(distribution(rng)); });
  55. ctx.WriteBuffer(data);
  56. IPC::ResponseBuilder rb{ctx, 2};
  57. rb.Push(ResultSuccess);
  58. }
  59. void Module::Interface::IsDevelopment(Kernel::HLERequestContext& ctx) {
  60. UNIMPLEMENTED_MSG("IsDevelopment is not implemented!");
  61. IPC::ResponseBuilder rb{ctx, 2};
  62. rb.Push(ResultSecureMonitorNotImplemented);
  63. }
  64. void Module::Interface::SetBootReason(Kernel::HLERequestContext& ctx) {
  65. UNIMPLEMENTED_MSG("SetBootReason is not implemented!");
  66. IPC::ResponseBuilder rb{ctx, 2};
  67. rb.Push(ResultSecureMonitorNotImplemented);
  68. }
  69. void Module::Interface::GetBootReason(Kernel::HLERequestContext& ctx) {
  70. UNIMPLEMENTED_MSG("GetBootReason is not implemented!");
  71. IPC::ResponseBuilder rb{ctx, 2};
  72. rb.Push(ResultSecureMonitorNotImplemented);
  73. }
  74. ResultVal<u64> Module::Interface::GetConfigImpl(ConfigItem config_item) const {
  75. switch (config_item) {
  76. case ConfigItem::DisableProgramVerification:
  77. case ConfigItem::DramId:
  78. case ConfigItem::SecurityEngineInterruptNumber:
  79. case ConfigItem::FuseVersion:
  80. case ConfigItem::HardwareType:
  81. case ConfigItem::HardwareState:
  82. case ConfigItem::IsRecoveryBoot:
  83. case ConfigItem::DeviceId:
  84. case ConfigItem::BootReason:
  85. case ConfigItem::MemoryMode:
  86. case ConfigItem::IsDevelopmentFunctionEnabled:
  87. case ConfigItem::KernelConfiguration:
  88. case ConfigItem::IsChargerHiZModeEnabled:
  89. case ConfigItem::QuestState:
  90. case ConfigItem::RegulatorType:
  91. case ConfigItem::DeviceUniqueKeyGeneration:
  92. case ConfigItem::Package2Hash:
  93. return ResultSecureMonitorNotImplemented;
  94. case ConfigItem::ExosphereApiVersion:
  95. // Get information about the current exosphere version.
  96. return (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MAJOR} << 56) |
  97. (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MINOR} << 48) |
  98. (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MICRO} << 40) |
  99. (static_cast<u64>(HLE::ApiVersion::GetTargetFirmware()));
  100. case ConfigItem::ExosphereNeedsReboot:
  101. // We are executing, so we aren't in the process of rebooting.
  102. return u64{0};
  103. case ConfigItem::ExosphereNeedsShutdown:
  104. // We are executing, so we aren't in the process of shutting down.
  105. return u64{0};
  106. case ConfigItem::ExosphereGitCommitHash:
  107. // Get information about the current exosphere git commit hash.
  108. return u64{0};
  109. case ConfigItem::ExosphereHasRcmBugPatch:
  110. // Get information about whether this unit has the RCM bug patched.
  111. return u64{0};
  112. case ConfigItem::ExosphereBlankProdInfo:
  113. // Get whether this unit should simulate a "blanked" PRODINFO.
  114. return u64{0};
  115. case ConfigItem::ExosphereAllowCalWrites:
  116. // Get whether this unit should allow writing to the calibration partition.
  117. return u64{0};
  118. case ConfigItem::ExosphereEmummcType:
  119. // Get what kind of emummc this unit has active.
  120. return u64{0};
  121. case ConfigItem::ExospherePayloadAddress:
  122. // Gets the physical address of the reboot payload buffer, if one exists.
  123. return ResultSecureMonitorNotInitialized;
  124. case ConfigItem::ExosphereLogConfiguration:
  125. // Get the log configuration.
  126. return u64{0};
  127. case ConfigItem::ExosphereForceEnableUsb30:
  128. // Get whether usb 3.0 should be force-enabled.
  129. return u64{0};
  130. default:
  131. return ResultSecureMonitorInvalidArgument;
  132. }
  133. }
  134. void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
  135. auto module = std::make_shared<Module>();
  136. std::make_shared<CSRNG>(system, module)->InstallAsService(service_manager);
  137. std::make_shared<SPL>(system, module)->InstallAsService(service_manager);
  138. std::make_shared<SPL_MIG>(system, module)->InstallAsService(service_manager);
  139. std::make_shared<SPL_FS>(system, module)->InstallAsService(service_manager);
  140. std::make_shared<SPL_SSL>(system, module)->InstallAsService(service_manager);
  141. std::make_shared<SPL_ES>(system, module)->InstallAsService(service_manager);
  142. std::make_shared<SPL_MANU>(system, module)->InstallAsService(service_manager);
  143. }
  144. } // namespace Service::SPL