Browse Source
Merge pull request #6472 from Morph1984/spl
Merge pull request #6472 from Morph1984/spl
service: spl: Implement general SPL servicence_cpp
committed by
GitHub
9 changed files with 493 additions and 78 deletions
-
3src/core/CMakeLists.txt
-
48src/core/file_sys/system_archive/system_version.cpp
-
38src/core/hle/api_version.h
-
2src/core/hle/service/spl/csrng.cpp
-
124src/core/hle/service/spl/module.cpp
-
13src/core/hle/service/spl/module.h
-
84src/core/hle/service/spl/spl.cpp
-
29src/core/hle/service/spl/spl_results.h
-
230src/core/hle/service/spl/spl_types.h
@ -0,0 +1,38 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#include "common/common_types.h" |
||||
|
|
||||
|
// This file contains yuzu's HLE API version constants. |
||||
|
|
||||
|
namespace HLE::ApiVersion { |
||||
|
|
||||
|
// Horizon OS version constants. |
||||
|
|
||||
|
constexpr u8 HOS_VERSION_MAJOR = 11; |
||||
|
constexpr u8 HOS_VERSION_MINOR = 0; |
||||
|
constexpr u8 HOS_VERSION_MICRO = 1; |
||||
|
|
||||
|
// NintendoSDK version constants. |
||||
|
|
||||
|
constexpr u8 SDK_REVISION_MAJOR = 1; |
||||
|
constexpr u8 SDK_REVISION_MINOR = 0; |
||||
|
|
||||
|
constexpr char PLATFORM_STRING[] = "NX"; |
||||
|
constexpr char VERSION_HASH[] = "69103fcb2004dace877094c2f8c29e6113be5dbf"; |
||||
|
constexpr char DISPLAY_VERSION[] = "11.0.1"; |
||||
|
constexpr char DISPLAY_TITLE[] = "NintendoSDK Firmware for NX 11.0.1-1.0"; |
||||
|
|
||||
|
// Atmosphere version constants. |
||||
|
|
||||
|
constexpr u8 ATMOSPHERE_RELEASE_VERSION_MAJOR = 0; |
||||
|
constexpr u8 ATMOSPHERE_RELEASE_VERSION_MINOR = 19; |
||||
|
constexpr u8 ATMOSPHERE_RELEASE_VERSION_MICRO = 4; |
||||
|
|
||||
|
constexpr u32 GetTargetFirmware() { |
||||
|
return u32{HOS_VERSION_MAJOR} << 24 | u32{HOS_VERSION_MINOR} << 16 | |
||||
|
u32{HOS_VERSION_MICRO} << 8 | 0U; |
||||
|
} |
||||
|
|
||||
|
} // namespace HLE::ApiVersion |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#include "core/hle/result.h" |
||||
|
|
||||
|
namespace Service::SPL { |
||||
|
|
||||
|
// Description 0 - 99 |
||||
|
constexpr ResultCode ResultSecureMonitorError{ErrorModule::SPL, 0}; |
||||
|
constexpr ResultCode ResultSecureMonitorNotImplemented{ErrorModule::SPL, 1}; |
||||
|
constexpr ResultCode ResultSecureMonitorInvalidArgument{ErrorModule::SPL, 2}; |
||||
|
constexpr ResultCode ResultSecureMonitorBusy{ErrorModule::SPL, 3}; |
||||
|
constexpr ResultCode ResultSecureMonitorNoAsyncOperation{ErrorModule::SPL, 4}; |
||||
|
constexpr ResultCode ResultSecureMonitorInvalidAsyncOperation{ErrorModule::SPL, 5}; |
||||
|
constexpr ResultCode ResultSecureMonitorNotPermitted{ErrorModule::SPL, 6}; |
||||
|
constexpr ResultCode ResultSecureMonitorNotInitialized{ErrorModule::SPL, 7}; |
||||
|
|
||||
|
constexpr ResultCode ResultInvalidSize{ErrorModule::SPL, 100}; |
||||
|
constexpr ResultCode ResultUnknownSecureMonitorError{ErrorModule::SPL, 101}; |
||||
|
constexpr ResultCode ResultDecryptionFailed{ErrorModule::SPL, 102}; |
||||
|
|
||||
|
constexpr ResultCode ResultOutOfKeySlots{ErrorModule::SPL, 104}; |
||||
|
constexpr ResultCode ResultInvalidKeySlot{ErrorModule::SPL, 105}; |
||||
|
constexpr ResultCode ResultBootReasonAlreadySet{ErrorModule::SPL, 106}; |
||||
|
constexpr ResultCode ResultBootReasonNotSet{ErrorModule::SPL, 107}; |
||||
|
constexpr ResultCode ResultInvalidArgument{ErrorModule::SPL, 108}; |
||||
|
|
||||
|
} // namespace Service::SPL |
||||
@ -0,0 +1,230 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#include <span> |
||||
|
|
||||
|
#include "common/bit_field.h" |
||||
|
#include "common/common_types.h" |
||||
|
|
||||
|
namespace Service::SPL { |
||||
|
|
||||
|
constexpr size_t AES_128_KEY_SIZE = 0x10; |
||||
|
|
||||
|
namespace Smc { |
||||
|
|
||||
|
enum class FunctionId : u32 { |
||||
|
SetConfig = 0xC3000401, |
||||
|
GetConfig = 0xC3000002, |
||||
|
GetResult = 0xC3000003, |
||||
|
GetResultData = 0xC3000404, |
||||
|
ModularExponentiate = 0xC3000E05, |
||||
|
GenerateRandomBytes = 0xC3000006, |
||||
|
GenerateAesKek = 0xC3000007, |
||||
|
LoadAesKey = 0xC3000008, |
||||
|
ComputeAes = 0xC3000009, |
||||
|
GenerateSpecificAesKey = 0xC300000A, |
||||
|
ComputeCmac = 0xC300040B, |
||||
|
ReencryptDeviceUniqueData = 0xC300D60C, |
||||
|
DecryptDeviceUniqueData = 0xC300100D, |
||||
|
|
||||
|
ModularExponentiateWithStorageKey = 0xC300060F, |
||||
|
PrepareEsDeviceUniqueKey = 0xC3000610, |
||||
|
LoadPreparedAesKey = 0xC3000011, |
||||
|
PrepareCommonEsTitleKey = 0xC3000012, |
||||
|
|
||||
|
// Deprecated functions. |
||||
|
LoadEsDeviceKey = 0xC300100C, |
||||
|
DecryptAndStoreGcKey = 0xC300100E, |
||||
|
|
||||
|
// Atmosphere functions. |
||||
|
AtmosphereIramCopy = 0xF0000201, |
||||
|
AtmosphereReadWriteRegister = 0xF0000002, |
||||
|
|
||||
|
AtmosphereGetEmummcConfig = 0xF0000404, |
||||
|
}; |
||||
|
|
||||
|
enum class CipherMode { |
||||
|
CbcEncrypt = 0, |
||||
|
CbcDecrypt = 1, |
||||
|
Ctr = 2, |
||||
|
}; |
||||
|
|
||||
|
enum class DeviceUniqueDataMode { |
||||
|
DecryptDeviceUniqueData = 0, |
||||
|
DecryptAndStoreGcKey = 1, |
||||
|
DecryptAndStoreEsDeviceKey = 2, |
||||
|
DecryptAndStoreSslKey = 3, |
||||
|
DecryptAndStoreDrmDeviceCertKey = 4, |
||||
|
}; |
||||
|
|
||||
|
enum class ModularExponentiateWithStorageKeyMode { |
||||
|
Gc = 0, |
||||
|
Ssl = 1, |
||||
|
DrmDeviceCert = 2, |
||||
|
}; |
||||
|
|
||||
|
enum class EsCommonKeyType { |
||||
|
TitleKey = 0, |
||||
|
ArchiveKey = 1, |
||||
|
}; |
||||
|
|
||||
|
struct AsyncOperationKey { |
||||
|
u64 value; |
||||
|
}; |
||||
|
|
||||
|
} // namespace Smc |
||||
|
|
||||
|
enum class HardwareType { |
||||
|
Icosa = 0, |
||||
|
Copper = 1, |
||||
|
Hoag = 2, |
||||
|
Iowa = 3, |
||||
|
Calcio = 4, |
||||
|
Aula = 5, |
||||
|
}; |
||||
|
|
||||
|
enum class SocType { |
||||
|
Erista = 0, |
||||
|
Mariko = 1, |
||||
|
}; |
||||
|
|
||||
|
enum class HardwareState { |
||||
|
Development = 0, |
||||
|
Production = 1, |
||||
|
}; |
||||
|
|
||||
|
enum class MemoryArrangement { |
||||
|
Standard = 0, |
||||
|
StandardForAppletDev = 1, |
||||
|
StandardForSystemDev = 2, |
||||
|
Expanded = 3, |
||||
|
ExpandedForAppletDev = 4, |
||||
|
|
||||
|
// Note: Dynamic is not official. |
||||
|
// Atmosphere uses it to maintain compatibility with firmwares prior to 6.0.0, |
||||
|
// which removed the explicit retrieval of memory arrangement from PM. |
||||
|
Dynamic = 5, |
||||
|
Count, |
||||
|
}; |
||||
|
|
||||
|
enum class BootReason { |
||||
|
Unknown = 0, |
||||
|
AcOk = 1, |
||||
|
OnKey = 2, |
||||
|
RtcAlarm1 = 3, |
||||
|
RtcAlarm2 = 4, |
||||
|
}; |
||||
|
|
||||
|
struct BootReasonValue { |
||||
|
union { |
||||
|
u32 value{}; |
||||
|
|
||||
|
BitField<0, 8, u32> power_intr; |
||||
|
BitField<8, 8, u32> rtc_intr; |
||||
|
BitField<16, 8, u32> nv_erc; |
||||
|
BitField<24, 8, u32> boot_reason; |
||||
|
}; |
||||
|
}; |
||||
|
static_assert(sizeof(BootReasonValue) == sizeof(u32), "BootReasonValue definition!"); |
||||
|
|
||||
|
struct AesKey { |
||||
|
std::array<u64, AES_128_KEY_SIZE / sizeof(u64)> data64{}; |
||||
|
|
||||
|
std::span<u8> AsBytes() { |
||||
|
return std::span{reinterpret_cast<u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
|
||||
|
std::span<const u8> AsBytes() const { |
||||
|
return std::span{reinterpret_cast<const u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
}; |
||||
|
static_assert(sizeof(AesKey) == AES_128_KEY_SIZE, "AesKey definition!"); |
||||
|
|
||||
|
struct IvCtr { |
||||
|
std::array<u64, AES_128_KEY_SIZE / sizeof(u64)> data64{}; |
||||
|
|
||||
|
std::span<u8> AsBytes() { |
||||
|
return std::span{reinterpret_cast<u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
|
||||
|
std::span<const u8> AsBytes() const { |
||||
|
return std::span{reinterpret_cast<const u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
}; |
||||
|
static_assert(sizeof(AesKey) == AES_128_KEY_SIZE, "IvCtr definition!"); |
||||
|
|
||||
|
struct Cmac { |
||||
|
std::array<u64, AES_128_KEY_SIZE / sizeof(u64)> data64{}; |
||||
|
|
||||
|
std::span<u8> AsBytes() { |
||||
|
return std::span{reinterpret_cast<u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
|
||||
|
std::span<const u8> AsBytes() const { |
||||
|
return std::span{reinterpret_cast<const u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
}; |
||||
|
static_assert(sizeof(AesKey) == AES_128_KEY_SIZE, "Cmac definition!"); |
||||
|
|
||||
|
struct AccessKey { |
||||
|
std::array<u64, AES_128_KEY_SIZE / sizeof(u64)> data64{}; |
||||
|
|
||||
|
std::span<u8> AsBytes() { |
||||
|
return std::span{reinterpret_cast<u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
|
||||
|
std::span<const u8> AsBytes() const { |
||||
|
return std::span{reinterpret_cast<const u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
}; |
||||
|
static_assert(sizeof(AesKey) == AES_128_KEY_SIZE, "AccessKey definition!"); |
||||
|
|
||||
|
struct KeySource { |
||||
|
std::array<u64, AES_128_KEY_SIZE / sizeof(u64)> data64{}; |
||||
|
|
||||
|
std::span<u8> AsBytes() { |
||||
|
return std::span{reinterpret_cast<u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
|
||||
|
std::span<const u8> AsBytes() const { |
||||
|
return std::span{reinterpret_cast<const u8*>(data64.data()), AES_128_KEY_SIZE}; |
||||
|
} |
||||
|
}; |
||||
|
static_assert(sizeof(AesKey) == AES_128_KEY_SIZE, "KeySource definition!"); |
||||
|
|
||||
|
enum class ConfigItem : u32 { |
||||
|
// Standard config items. |
||||
|
DisableProgramVerification = 1, |
||||
|
DramId = 2, |
||||
|
SecurityEngineInterruptNumber = 3, |
||||
|
FuseVersion = 4, |
||||
|
HardwareType = 5, |
||||
|
HardwareState = 6, |
||||
|
IsRecoveryBoot = 7, |
||||
|
DeviceId = 8, |
||||
|
BootReason = 9, |
||||
|
MemoryMode = 10, |
||||
|
IsDevelopmentFunctionEnabled = 11, |
||||
|
KernelConfiguration = 12, |
||||
|
IsChargerHiZModeEnabled = 13, |
||||
|
QuestState = 14, |
||||
|
RegulatorType = 15, |
||||
|
DeviceUniqueKeyGeneration = 16, |
||||
|
Package2Hash = 17, |
||||
|
|
||||
|
// Extension config items for exosphere. |
||||
|
ExosphereApiVersion = 65000, |
||||
|
ExosphereNeedsReboot = 65001, |
||||
|
ExosphereNeedsShutdown = 65002, |
||||
|
ExosphereGitCommitHash = 65003, |
||||
|
ExosphereHasRcmBugPatch = 65004, |
||||
|
ExosphereBlankProdInfo = 65005, |
||||
|
ExosphereAllowCalWrites = 65006, |
||||
|
ExosphereEmummcType = 65007, |
||||
|
ExospherePayloadAddress = 65008, |
||||
|
ExosphereLogConfiguration = 65009, |
||||
|
ExosphereForceEnableUsb30 = 65010, |
||||
|
}; |
||||
|
|
||||
|
} // namespace Service::SPL |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue