spl_module.cpp 6.7 KB

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