From ded36b86887a3f8d727af6d3d30d069da871b475 Mon Sep 17 00:00:00 2001
From: Morph <39850852+Morph1984@users.noreply.github.com>
Date: Tue, 15 Jun 2021 02:36:52 -0400
Subject: [PATCH] spl: Add the general SPL interface

---
 src/core/hle/service/spl/csrng.cpp  |  2 +-
 src/core/hle/service/spl/module.cpp | 14 ++++-
 src/core/hle/service/spl/module.h   |  9 +++-
 src/core/hle/service/spl/spl.cpp    | 84 ++++++++++++++---------------
 4 files changed, 64 insertions(+), 45 deletions(-)

diff --git a/src/core/hle/service/spl/csrng.cpp b/src/core/hle/service/spl/csrng.cpp
index 1beca417c6..9c7f894758 100644
--- a/src/core/hle/service/spl/csrng.cpp
+++ b/src/core/hle/service/spl/csrng.cpp
@@ -9,7 +9,7 @@ namespace Service::SPL {
 CSRNG::CSRNG(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "csrng") {
     static const FunctionInfo functions[] = {
-        {0, &CSRNG::GetRandomBytes, "GetRandomBytes"},
+        {0, &CSRNG::GenerateRandomBytes, "GenerateRandomBytes"},
     };
     RegisterHandlers(functions);
 }
diff --git a/src/core/hle/service/spl/module.cpp b/src/core/hle/service/spl/module.cpp
index 0b5e2b7c3a..eabf2e3194 100644
--- a/src/core/hle/service/spl/module.cpp
+++ b/src/core/hle/service/spl/module.cpp
@@ -24,7 +24,13 @@ Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> modu
 
 Module::Interface::~Interface() = default;
 
-void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) {
+void Module::Interface::GetConfig(Kernel::HLERequestContext& ctx) {}
+
+void Module::Interface::ModularExponentiate(Kernel::HLERequestContext& ctx) {}
+
+void Module::Interface::SetConfig(Kernel::HLERequestContext& ctx) {}
+
+void Module::Interface::GenerateRandomBytes(Kernel::HLERequestContext& ctx) {
     LOG_DEBUG(Service_SPL, "called");
 
     const std::size_t size = ctx.GetWriteBufferSize();
@@ -39,6 +45,12 @@ void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) {
     rb.Push(ResultSuccess);
 }
 
+void Module::Interface::IsDevelopment(Kernel::HLERequestContext& ctx) {}
+
+void Module::Interface::SetBootReason(Kernel::HLERequestContext& ctx) {}
+
+void Module::Interface::GetBootReason(Kernel::HLERequestContext& ctx) {}
+
 void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
     auto module = std::make_shared<Module>();
     std::make_shared<CSRNG>(system, module)->InstallAsService(service_manager);
diff --git a/src/core/hle/service/spl/module.h b/src/core/hle/service/spl/module.h
index 71855c1bfd..67f7657e9d 100644
--- a/src/core/hle/service/spl/module.h
+++ b/src/core/hle/service/spl/module.h
@@ -21,7 +21,14 @@ public:
                            const char* name);
         ~Interface() override;
 
-        void GetRandomBytes(Kernel::HLERequestContext& ctx);
+        // General
+        void GetConfig(Kernel::HLERequestContext& ctx);
+        void ModularExponentiate(Kernel::HLERequestContext& ctx);
+        void SetConfig(Kernel::HLERequestContext& ctx);
+        void GenerateRandomBytes(Kernel::HLERequestContext& ctx);
+        void IsDevelopment(Kernel::HLERequestContext& ctx);
+        void SetBootReason(Kernel::HLERequestContext& ctx);
+        void GetBootReason(Kernel::HLERequestContext& ctx);
 
     protected:
         std::shared_ptr<Module> module;
diff --git a/src/core/hle/service/spl/spl.cpp b/src/core/hle/service/spl/spl.cpp
index fff3f3c42e..20384042f0 100644
--- a/src/core/hle/service/spl/spl.cpp
+++ b/src/core/hle/service/spl/spl.cpp
@@ -10,13 +10,13 @@ SPL::SPL(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "spl:") {
     // clang-format off
     static const FunctionInfo functions[] = {
-        {0, nullptr, "GetConfig"},
-        {1, nullptr, "ModularExponentiate"},
-        {5, nullptr, "SetConfig"},
-        {7, &SPL::GetRandomBytes, "GetRandomBytes"},
-        {11, nullptr, "IsDevelopment"},
-        {24, nullptr, "SetBootReason"},
-        {25, nullptr, "GetBootReason"},
+        {0, &SPL::GetConfig, "GetConfig"},
+        {1, &SPL::ModularExponentiate, "ModularExponentiate"},
+        {5, &SPL::SetConfig, "SetConfig"},
+        {7, &SPL::GenerateRandomBytes, "GenerateRandomBytes"},
+        {11, &SPL::IsDevelopment, "IsDevelopment"},
+        {24, &SPL::SetBootReason, "SetBootReason"},
+        {25, &SPL::GetBootReason, "GetBootReason"},
     };
     // clang-format on
 
@@ -27,22 +27,22 @@ SPL_MIG::SPL_MIG(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "spl:mig") {
     // clang-format off
     static const FunctionInfo functions[] = {
-        {0, nullptr, "GetConfig"},
-        {1, nullptr, "ModularExponentiate"},
+        {0, &SPL::GetConfig, "GetConfig"},
+        {1, &SPL::ModularExponentiate, "ModularExponentiate"},
         {2, nullptr, "GenerateAesKek"},
         {3, nullptr, "LoadAesKey"},
         {4, nullptr, "GenerateAesKey"},
-        {5, nullptr, "SetConfig"},
-        {7, &SPL::GetRandomBytes, "GenerateRandomBytes"},
-        {11, nullptr, "IsDevelopment"},
+        {5, &SPL::SetConfig, "SetConfig"},
+        {7, &SPL::GenerateRandomBytes, "GenerateRandomBytes"},
+        {11, &SPL::IsDevelopment, "IsDevelopment"},
         {14, nullptr, "DecryptAesKey"},
         {15, nullptr, "CryptAesCtr"},
         {16, nullptr, "ComputeCmac"},
         {21, nullptr, "AllocateAesKeyslot"},
         {22, nullptr, "DeallocateAesKeySlot"},
         {23, nullptr, "GetAesKeyslotAvailableEvent"},
-        {24, nullptr, "SetBootReason"},
-        {25, nullptr, "GetBootReason"},
+        {24, &SPL::SetBootReason, "SetBootReason"},
+        {25, &SPL::GetBootReason, "GetBootReason"},
     };
     // clang-format on
 
@@ -53,16 +53,16 @@ SPL_FS::SPL_FS(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "spl:fs") {
     // clang-format off
     static const FunctionInfo functions[] = {
-        {0, nullptr, "GetConfig"},
-        {1, nullptr, "ModularExponentiate"},
+        {0, &SPL::GetConfig, "GetConfig"},
+        {1, &SPL::ModularExponentiate, "ModularExponentiate"},
         {2, nullptr, "GenerateAesKek"},
         {3, nullptr, "LoadAesKey"},
         {4, nullptr, "GenerateAesKey"},
-        {5, nullptr, "SetConfig"},
-        {7, &SPL::GetRandomBytes, "GenerateRandomBytes"},
+        {5, &SPL::SetConfig, "SetConfig"},
+        {7, &SPL::GenerateRandomBytes, "GenerateRandomBytes"},
         {9, nullptr, "ImportLotusKey"},
         {10, nullptr, "DecryptLotusMessage"},
-        {11, nullptr, "IsDevelopment"},
+        {11, &SPL::IsDevelopment, "IsDevelopment"},
         {12, nullptr, "GenerateSpecificAesKey"},
         {14, nullptr, "DecryptAesKey"},
         {15, nullptr, "CryptAesCtr"},
@@ -71,8 +71,8 @@ SPL_FS::SPL_FS(Core::System& system_, std::shared_ptr<Module> module_)
         {21, nullptr, "AllocateAesKeyslot"},
         {22, nullptr, "DeallocateAesKeySlot"},
         {23, nullptr, "GetAesKeyslotAvailableEvent"},
-        {24, nullptr, "SetBootReason"},
-        {25, nullptr, "GetBootReason"},
+        {24, &SPL::SetBootReason, "SetBootReason"},
+        {25, &SPL::GetBootReason, "GetBootReason"},
         {31, nullptr, "GetPackage2Hash"},
     };
     // clang-format on
@@ -84,14 +84,14 @@ SPL_SSL::SPL_SSL(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "spl:ssl") {
     // clang-format off
     static const FunctionInfo functions[] = {
-        {0, nullptr, "GetConfig"},
-        {1, nullptr, "ModularExponentiate"},
+        {0, &SPL::GetConfig, "GetConfig"},
+        {1, &SPL::ModularExponentiate, "ModularExponentiate"},
         {2, nullptr, "GenerateAesKek"},
         {3, nullptr, "LoadAesKey"},
         {4, nullptr, "GenerateAesKey"},
-        {5, nullptr, "SetConfig"},
-        {7, &SPL::GetRandomBytes, "GetRandomBytes"},
-        {11, nullptr, "IsDevelopment"},
+        {5, &SPL::SetConfig, "SetConfig"},
+        {7, &SPL::GenerateRandomBytes, "GenerateRandomBytes"},
+        {11, &SPL::IsDevelopment, "IsDevelopment"},
         {13, nullptr, "DecryptDeviceUniqueData"},
         {14, nullptr, "DecryptAesKey"},
         {15, nullptr, "CryptAesCtr"},
@@ -99,8 +99,8 @@ SPL_SSL::SPL_SSL(Core::System& system_, std::shared_ptr<Module> module_)
         {21, nullptr, "AllocateAesKeyslot"},
         {22, nullptr, "DeallocateAesKeySlot"},
         {23, nullptr, "GetAesKeyslotAvailableEvent"},
-        {24, nullptr, "SetBootReason"},
-        {25, nullptr, "GetBootReason"},
+        {24, &SPL::SetBootReason, "SetBootReason"},
+        {25, &SPL::GetBootReason, "GetBootReason"},
         {26, nullptr, "DecryptAndStoreSslClientCertKey"},
         {27, nullptr, "ModularExponentiateWithSslClientCertKey"},
     };
@@ -113,14 +113,14 @@ SPL_ES::SPL_ES(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "spl:es") {
     // clang-format off
     static const FunctionInfo functions[] = {
-        {0, nullptr, "GetConfig"},
-        {1, nullptr, "ModularExponentiate"},
+        {0, &SPL::GetConfig, "GetConfig"},
+        {1, &SPL::ModularExponentiate, "ModularExponentiate"},
         {2, nullptr, "GenerateAesKek"},
         {3, nullptr, "LoadAesKey"},
         {4, nullptr, "GenerateAesKey"},
-        {5, nullptr, "SetConfig"},
-        {7, &SPL::GetRandomBytes, "GenerateRandomBytes"},
-        {11, nullptr, "IsDevelopment"},
+        {5, &SPL::SetConfig, "SetConfig"},
+        {7, &SPL::GenerateRandomBytes, "GenerateRandomBytes"},
+        {11, &SPL::IsDevelopment, "IsDevelopment"},
         {13, nullptr, "DecryptDeviceUniqueData"},
         {14, nullptr, "DecryptAesKey"},
         {15, nullptr, "CryptAesCtr"},
@@ -131,8 +131,8 @@ SPL_ES::SPL_ES(Core::System& system_, std::shared_ptr<Module> module_)
         {21, nullptr, "AllocateAesKeyslot"},
         {22, nullptr, "DeallocateAesKeySlot"},
         {23, nullptr, "GetAesKeyslotAvailableEvent"},
-        {24, nullptr, "SetBootReason"},
-        {25, nullptr, "GetBootReason"},
+        {24, &SPL::SetBootReason, "SetBootReason"},
+        {25, &SPL::GetBootReason, "GetBootReason"},
         {28, nullptr, "DecryptAndStoreDrmDeviceCertKey"},
         {29, nullptr, "ModularExponentiateWithDrmDeviceCertKey"},
         {31, nullptr, "PrepareEsArchiveKey"},
@@ -147,14 +147,14 @@ SPL_MANU::SPL_MANU(Core::System& system_, std::shared_ptr<Module> module_)
     : Interface(system_, std::move(module_), "spl:manu") {
     // clang-format off
     static const FunctionInfo functions[] = {
-        {0, nullptr, "GetConfig"},
-        {1, nullptr, "ModularExponentiate"},
+        {0, &SPL::GetConfig, "GetConfig"},
+        {1, &SPL::ModularExponentiate, "ModularExponentiate"},
         {2, nullptr, "GenerateAesKek"},
         {3, nullptr, "LoadAesKey"},
         {4, nullptr, "GenerateAesKey"},
-        {5, nullptr, "SetConfig"},
-        {7, &SPL::GetRandomBytes, "GetRandomBytes"},
-        {11, nullptr, "IsDevelopment"},
+        {5, &SPL::SetConfig, "SetConfig"},
+        {7, &SPL::GenerateRandomBytes, "GenerateRandomBytes"},
+        {11, &SPL::IsDevelopment, "IsDevelopment"},
         {13, nullptr, "DecryptDeviceUniqueData"},
         {14, nullptr, "DecryptAesKey"},
         {15, nullptr, "CryptAesCtr"},
@@ -162,8 +162,8 @@ SPL_MANU::SPL_MANU(Core::System& system_, std::shared_ptr<Module> module_)
         {21, nullptr, "AllocateAesKeyslot"},
         {22, nullptr, "DeallocateAesKeySlot"},
         {23, nullptr, "GetAesKeyslotAvailableEvent"},
-        {24, nullptr, "SetBootReason"},
-        {25, nullptr, "GetBootReason"},
+        {24, &SPL::SetBootReason, "SetBootReason"},
+        {25, &SPL::GetBootReason, "GetBootReason"},
         {30, nullptr, "ReencryptDeviceUniqueData"},
     };
     // clang-format on