EFI config backup

This commit is contained in:
2022-03-29 10:26:33 +03:00
parent 03b8035141
commit 24449516c0
96 changed files with 33899 additions and 0 deletions

View File

@ -0,0 +1,431 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>20G417</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>VirtualSMC</string>
<key>CFBundleIdentifier</key>
<string>as.vit9696.VirtualSMC</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>VirtualSMC</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>1.2.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1.2.9</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>12E507</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>11.3</string>
<key>DTSDKBuild</key>
<string>20E214</string>
<key>DTSDKName</key>
<string>macosx11.3</string>
<key>DTXcode</key>
<string>1251</string>
<key>DTXcodeBuild</key>
<string>12E507</string>
<key>IOKitPersonalities</key>
<dict>
<key>as.vit9696.VirtualSMC</key>
<dict>
<key>CFBundleIdentifier</key>
<string>as.vit9696.VirtualSMC</string>
<key>IOClass</key>
<string>VirtualSMC</string>
<key>IODeviceMemory</key>
<array>
<array>
<dict>
<key>address</key>
<integer>768</integer>
<key>length</key>
<integer>32</integer>
</dict>
</array>
<array>
<dict>
<key>address</key>
<integer>4277141504</integer>
<key>length</key>
<integer>65536</integer>
</dict>
</array>
</array>
<key>IOInterruptControllers</key>
<array>
<string>io-apic-0</string>
</array>
<key>IOInterruptSpecifiers</key>
<array>
<data>
BgAAAAAAAAA=
</data>
</array>
<key>IOMatchCategory</key>
<string>IOACPIPlatformDevice</string>
<key>IOName</key>
<string>SMC</string>
<key>IOProbeScore</key>
<integer>60000</integer>
<key>IOProviderClass</key>
<string>AppleACPIPlatformExpert</string>
<key>Keystore</key>
<dict>
<key>Generic</key>
<array>
<dict>
<key>attr</key>
<data>
iA==
</data>
<key>comment</key>
<string>Total fan number, this should be put to a plugin</string>
<key>name</key>
<data>
Rk51bQ==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>CPU plimit</string>
<key>name</key>
<data>
TVNUYw==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>FAN plimit (supposedly)</string>
<key>name</key>
<data>
TVNUZg==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>Memory plimit</string>
<key>name</key>
<data>
TVNUbQ==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>This should be 1 on laptops, and is overriden by sensors</string>
<key>name</key>
<data>
QkFUUA==
</data>
<key>type</key>
<data>
ZmxhZw==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>Only MacPros have custom illumination controllers</string>
<key>name</key>
<data>
THNOTQ==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
</array>
<key>GenericDesktopV1</key>
<array/>
<key>GenericDesktopV2</key>
<array/>
<key>GenericLaptopV1</key>
<array/>
<key>GenericLaptopV2</key>
<array/>
<key>GenericV1</key>
<array>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>GPU plimit</string>
<key>name</key>
<data>
TVNUZw==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
</array>
<key>GenericV2</key>
<array>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>E plimit (???)</string>
<key>name</key>
<data>
TVNUZQ==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>I plimit (???)</string>
<key>name</key>
<data>
TVNUaQ==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
<dict>
<key>attr</key>
<data>
gA==
</data>
<key>comment</key>
<string>J plimit (???)</string>
<key>name</key>
<data>
TVNUag==
</data>
<key>type</key>
<data>
dWk4IA==
</data>
<key>value</key>
<data>
AA==
</data>
</dict>
</array>
</dict>
<key>ModelInfo</key>
<dict>
<key>GenericV1</key>
<dict>
<key>branch</key>
<data>
ajUyAAAAAAA=
</data>
<key>hwname</key>
<data>
c21jLXBpa2V0b24A
</data>
<key>platform</key>
<data>
ajUyAAAAAAA=
</data>
<key>rev</key>
<data>
AXQPAAAE
</data>
<key>revfb</key>
<data>
AXQPAAAE
</data>
<key>revfu</key>
<data>
AXQPAAAE
</data>
</dict>
<key>GenericV2</key>
<dict>
<key>branch</key>
<data>
ajUyAAAAAAA=
</data>
<key>hwname</key>
<data>
c21jLWh1cm9ucml2ZXIA
</data>
<key>platform</key>
<data>
ajUyAAAAAAA=
</data>
<key>rev</key>
<data>
AigPAAAH
</data>
<key>revfb</key>
<data>
AigPAAAH
</data>
<key>revfu</key>
<data>
AigPAAAH
</data>
</dict>
<key>GenericV3</key>
<dict>
<key>hwname</key>
<data>
c21jLWh1cm9ucml2ZXIA
</data>
<key>platform</key>
<data>
ajUyAAAAAAA=
</data>
</dict>
</dict>
<key>_STA</key>
<integer>11</integer>
<key>name</key>
<data>
QVBQMDAwMQA=
</data>
</dict>
</dict>
<key>LSMinimumSystemVersion</key>
<string>10.6</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 vit9696. All rights reserved.</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0</string>
<key>OSBundleLibraries</key>
<dict>
<key>as.vit9696.Lilu</key>
<string>1.2.0</string>
<key>com.apple.iokit.IOACPIFamily</key>
<string>1.0.0d1</string>
<key>com.apple.kernel.6.0</key>
<string>7.9.9</string>
<key>com.apple.kpi.bsd</key>
<string>8.0.0</string>
<key>com.apple.kpi.iokit</key>
<string>8.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
<key>com.apple.kpi.unsupported</key>
<string>8.0.0</string>
</dict>
<key>OSBundleLibraries_x86_64</key>
<dict>
<key>as.vit9696.Lilu</key>
<string>1.2.0</string>
<key>com.apple.iokit.IOACPIFamily</key>
<string>1.0.0d1</string>
<key>com.apple.kpi.bsd</key>
<string>10.0.0</string>
<key>com.apple.kpi.iokit</key>
<string>10.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>10.0.0</string>
<key>com.apple.kpi.mach</key>
<string>10.0.0</string>
<key>com.apple.kpi.unsupported</key>
<string>10.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Root</string>
</dict>
</plist>

Binary file not shown.

View File

@ -0,0 +1,437 @@
/** @file
Copyright (C) 2014 - 2016, Download-Fritz. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef APPLE_SMC_H
#define APPLE_SMC_H
//
// SMC uses Big Endian byte order to store keys.
// For some reason AppleSmcIo protocol in UEFI takes little endian keys.
// As this header is used by both UEFI and Kernel VirtualSMC parts,
// we define SMC_MAKE_IDENTIFIER to produce Little Endian keys in UEFI (EFIAPI),
// and Big Endian keys in all other places.
//
// NB: This code assumes Little Endian host byte order, which so far is the
// only supported byte order in UEFI.
//
#ifdef EFIAPI
#define SMC_MAKE_IDENTIFIER(A, B, C, D) \
((UINT32)(((UINT32)(A) << 24U) | ((UINT32)(B) << 16U) | ((UINT32)(C) << 8U) | (UINT32)(D)))
#else
#define SMC_MAKE_IDENTIFIER(A, B, C, D) \
((UINT32)(((UINT32)(D) << 24U) | ((UINT32)(C) << 16U) | ((UINT32)(B) << 8U) | (UINT32)(A)))
#endif
// PMIO
#define SMC_PORT_BASE 0x0300
#define SMC_PORT_LENGTH 0x0020
#define SMC_PORT_OFFSET_DATA 0x00
#define SMC_PORT_OFFSET_COMMAND 0x04
#define SMC_PORT_OFFSET_STATUS SMC_PORT_OFFSET_COMMAND
#define SMC_PORT_OFFSET_RESULT 0x1E
#define SMC_PORT_OFFSET_EVENT 0x1F
// MMIO
#define SMC_MMIO_BASE_ADDRESS 0xFEF00000
#define SMC_MMIO_LENGTH 0x00010000
#define SMC_MMIO_DATA_VARIABLE 0x00
#define SMC_MMIO_DATA_FIXED 0x78
// MMIO offsets
#define SMC_MMIO_OFFSET_KEY 0x00
#define SMC_MMIO_OFFSET_KEY_TYPE SMC_MMIO_OFFSET_KEY
#define SMC_MMIO_OFFSET_SMC_MODE SMC_MMIO_OFFSET_KEY
#define SMC_MMIO_OFFSET_DATA_SIZE 0x05
#define SMC_MMIO_OFFSET_KEY_ATTRIBUTES 0x06
#define SMC_MMIO_OFFSET_COMMAND 0x07
#define SMC_MMIO_OFFSET_RESULT SMC_MMIO_OFFSET_COMMAND
#define SMC_MMIO_OFFSET_LOG 0x08
// Read addresses
#define SMC_MMIO_READ_KEY \
(SMC_MMIO_DATA_VARIABLE + SMC_MMIO_OFFSET_KEY)
#define SMC_MMIO_READ_KEY_TYPE \
(SMC_MMIO_DATA_VARIABLE + SMC_MMIO_OFFSET_KEY_TYPE)
#define SMC_MMIO_READ_DATA_SIZE \
(SMC_MMIO_DATA_VARIABLE + SMC_MMIO_OFFSET_DATA_SIZE)
#define SMC_MMIO_READ_KEY_ATTRIBUTES \
(SMC_MMIO_DATA_VARIABLE + SMC_MMIO_OFFSET_KEY_ATTRIBUTES)
#define SMC_MMIO_READ_LOG \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_LOG)
#define SMC_MMIO_READ_RESULT \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_RESULT)
#define SMC_MMIO_READ_EVENT_STATUS 0x4000
#define SMC_MMIO_READ_UNKNOWN1 0x4004
#define SMC_MMIO_READ_KEY_STATUS 0x4005
// Write addresses
#define SMC_MMIO_WRITE_MODE \
(SMC_MMIO_DATA_VARIABLE + SMC_MMIO_OFFSET_SMC_MODE)
#define SMC_MMIO_WRITE_KEY \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_KEY)
#define SMC_MMIO_WRITE_INDEX \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_KEY_TYPE)
#define SMC_MMIO_WRITE_DATA_SIZE \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_DATA_SIZE)
#define SMC_MMIO_WRITE_KEY_ATTRIBUTES \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_KEY_ATTRIBUTES)
#define SMC_MMIO_WRITE_COMMAND \
(SMC_MMIO_DATA_FIXED + SMC_MMIO_OFFSET_COMMAND)
typedef UINT32 SMC_ADDRESS;
// Modes
#define SMC_MODE_APPCODE 'A'
#define SMC_MODE_UPDATE 'U'
#define SMC_MODE_BASE 'B'
// SMC_MODE
typedef CHAR8 *SMC_MODE;
enum {
SmcResetModeMaster = 0,
SmcResetModeAppCode = 1,
SmcResetModeUpdate = 2,
SmcResetModeBase = 3
};
typedef UINT8 SMC_RESET_MODE;
enum {
SmcFlashTypeAppCode = 1,
SmcFlashTypeBase = 2,
SmcFlashTypeUpdate = 3,
SmcFlashTypeEpm = 4
};
typedef UINT8 SMC_FLASH_TYPE;
enum {
SmcFlashModeAppCode = SmcResetModeMaster,
SmcFlashModeUpdate = SmcResetModeBase,
SmcFlashModeBase = SmcResetModeUpdate,
SmcFlashModeEpm = SmcResetModeMaster
};
typedef UINT8 SMC_FLASH_MODE;
// Commands
enum {
SmcCmdReadValue = 0x10,
SmcCmdWriteValue = 0x11,
SmcCmdGetKeyFromIndex = 0x12,
SmcCmdGetKeyInfo = 0x13,
SmcCmdReset = 0x14,
SmcCmdWriteValueAtIndex = 0x15,
SmcCmdReadValueAtIndex = 0x16,
SmcCmdGetSramAddress = 0x17,
SmcCmdReadPKey = 0x20, // response based on payload submitted
SmcCmdUnknown1 = 0x77,
SmcCmdFlashWrite = 0xF1,
SmcCmdFlashAuth = 0xF2,
SmcCmdFlashType = 0xF4,
SmcCmdFlashWriteMoreData = 0xF5, // write more data than available at once
SmcCmdFlashAuthMoreData = 0xF6 // auth more data than available at once
};
typedef UINT8 SMC_COMMAND;
// Reports
#define SMC_STATUS_AWAITING_DATA BIT0 ///< Ready to read data.
#define SMC_STATUS_IB_CLOSED BIT1 /// A write is pending.
#define SMC_STATUS_BUSY BIT2 ///< Busy processing a command.
#define SMC_STATUS_GOT_COMMAND BIT3 ///< The last input was a command.
#define SMC_STATUS_UKN_0x16 BIT4
#define SMC_STATUS_KEY_DONE BIT5
#define SMC_STATUS_READY BIT6 // Ready to work
#define SMC_STATUS_UKN_0x80 BIT7 // error
// SMC_STATUS
typedef UINT8 SMC_STATUS;
enum {
SmcSuccess = 0,
SmcError = 1,
SmcCommCollision = 128,
SmcSpuriousData = 129,
SmcBadCommand = 130,
SmcBadParameter = 131,
SmcNotFound = 132,
SmcNotReadable = 133,
SmcNotWritable = 134,
SmcKeySizeMismatch = 135,
SmcFramingError = 136,
SmcBadArgumentError = 137,
SmcTimeoutError = 183,
SmcKeyIndexRangeError = 184,
SmcBadFunctionParameter = 192,
SmcEventBufferWrongOrder = 196,
SmcEventBufferReadError = 197,
SmcDeviceAccessError = 199,
SmcUnsupportedFeature = 203,
SmcSmbAccessError = 204,
SmcInvalidSize = 206
};
#define SMC_ERROR(a) (((UINTN)(a)) > 0)
#define EFI_STATUS_FROM_SMC_RESULT(x) \
((((UINTN)(x)) == SmcSuccess) ? EFI_SUCCESS : EFIERR ((UINTN)(x)))
#define EFI_SMC_SUCCESS SmcSuccess
#define EFI_SMC_ERROR EFIERR (SmcError)
#define EFI_SMC_COMM_COLLISION EFIERR (SmcCommCollision)
#define EFI_SMC_SPURIOUS_DATA EFIERR (SmcSpuriousData)
#define EFI_SMC_BAD_COMMAND EFIERR (SmcBadCommand)
#define EFI_SMC_BAD_PARAMETER EFIERR (SmcBadParameter)
#define EFI_SMC_NOT_FOUND EFIERR (SmcNotFound)
#define EFI_SMC_NOT_READABLE EFIERR (SmcNotReadable)
#define EFI_SMC_NOT_WRITABLE EFIERR (SmcNotWritable)
#define EFI_SMC_KEY_MISMATCH EFIERR (SmcKeySizeMismatch)
#define EFI_SMC_FRAMING_ERROR EFIERR (SmcFramingError)
#define EFI_SMC_BAD_ARGUMENT_ERROR EFIERR (SmcBadArgumentError)
#define EFI_SMC_TIMEOUT_ERROR EFIERR (SmcTimeoutError)
#define EFI_SMC_KEY_INDEX_RANGE_ERROR EFIERR (SmcKeyIndexRangeError)
#define EFI_SMC_BAD_FUNCTION_PARAMETER EFIERR (SmcBadFunctionParameter)
#define EFI_SMC_EVENT_BUFFER_WRONG_ORDER EFIERR (SmcEventBufferWrongOrder)
#define EFI_SMC_EVENT_BUFFER_READ_ERROR EFIERR (SmcEventBufferReadError)
#define EFI_SMC_DEVICE_ACCESS_ERROR EFIERR (SmcDeviceAccessError)
#define EFI_SMC_UNSUPPORTED_FEATURE EFIERR (SmcUnsupportedFeature)
#define EFI_SMB_ACCESS_ERROR EFIERR (SmcSmbAccessError)
#define EFI_SMC_INVALID_SIZE EFIERR (SmcInvalidSize)
// SMC_RESULT
typedef UINT8 SMC_RESULT;
// Key Types
#define SMC_MAKE_KEY_TYPE(A, B, C, D) SMC_MAKE_IDENTIFIER ((A), (B), (C), (D))
enum {
SmcKeyTypeCh8s = SMC_MAKE_KEY_TYPE ('c', 'h', '8', '*'),
SmcKeyTypeChar = SMC_MAKE_KEY_TYPE ('c', 'h', 'a', 'r'),
SmcKeyTypeFloat = SMC_MAKE_KEY_TYPE ('f', 'l', 't', ' '),
SmcKeyTypeFlag = SMC_MAKE_KEY_TYPE ('f', 'l', 'a', 'g'),
SmcKeyTypeFp1f = SMC_MAKE_KEY_TYPE ('f', 'p', '1', 'f'),
SmcKeyTypeFp2e = SMC_MAKE_KEY_TYPE ('f', 'p', '2', 'e'),
SmcKeyTypeFp3d = SMC_MAKE_KEY_TYPE ('f', 'p', '3', 'd'),
SmcKeyTypeFp4c = SMC_MAKE_KEY_TYPE ('f', 'p', '4', 'c'),
SmcKeyTypeFp5b = SMC_MAKE_KEY_TYPE ('f', 'p', '5', 'b'),
SmcKeyTypeFp6a = SMC_MAKE_KEY_TYPE ('f', 'p', '6', 'a'),
SmcKeyTypeFp79 = SMC_MAKE_KEY_TYPE ('f', 'p', '7', '9'),
SmcKeyTypeFp88 = SMC_MAKE_KEY_TYPE ('f', 'p', '8', '8'),
SmcKeyTypeFp97 = SMC_MAKE_KEY_TYPE ('f', 'p', '9', '7'),
SmcKeyTypeFpa6 = SMC_MAKE_KEY_TYPE ('f', 'p', 'a', '6'),
SmcKeyTypeFpb5 = SMC_MAKE_KEY_TYPE ('f', 'p', 'b', '5'),
SmcKeyTypeFpc4 = SMC_MAKE_KEY_TYPE ('f', 'p', 'c', '4'),
SmcKeyTypeFpd3 = SMC_MAKE_KEY_TYPE ('f', 'p', 'd', '3'),
SmcKeyTypeFpe2 = SMC_MAKE_KEY_TYPE ('f', 'p', 'e', '2'),
SmcKeyTypeFpf1 = SMC_MAKE_KEY_TYPE ('f', 'p', 'f', '1'),
SmcKeyTypeHex = SMC_MAKE_KEY_TYPE ('h', 'e', 'x', '_'),
SmcKeyTypeIoft = SMC_MAKE_KEY_TYPE ('i', 'o', 'f', 't'),
SmcKeyTypeSint8 = SMC_MAKE_KEY_TYPE ('s', 'i', '8', ' '),
SmcKeyTypeSint16 = SMC_MAKE_KEY_TYPE ('s', 'i', '1', '6'),
SmcKeyTypeSint32 = SMC_MAKE_KEY_TYPE ('s', 'i', '3', '2'),
SmcKeyTypeSint64 = SMC_MAKE_KEY_TYPE ('s', 'i', '6', '4'),
SmcKeyTypeSp1e = SMC_MAKE_KEY_TYPE ('s', 'p', '1', 'e'),
SmcKeyTypeSp2d = SMC_MAKE_KEY_TYPE ('s', 'p', '2', 'd'),
SmcKeyTypeSp3c = SMC_MAKE_KEY_TYPE ('s', 'p', '3', 'c'),
SmcKeyTypeSp4b = SMC_MAKE_KEY_TYPE ('s', 'p', '4', 'b'),
SmcKeyTypeSp5a = SMC_MAKE_KEY_TYPE ('s', 'p', '5', 'a'),
SmcKeyTypeSp69 = SMC_MAKE_KEY_TYPE ('s', 'p', '6', '9'),
SmcKeyTypeSp78 = SMC_MAKE_KEY_TYPE ('s', 'p', '7', '8'),
SmcKeyTypeSp87 = SMC_MAKE_KEY_TYPE ('s', 'p', '8', '7'),
SmcKeyTypeSp96 = SMC_MAKE_KEY_TYPE ('s', 'p', '9', '6'),
SmcKeyTypeSpa5 = SMC_MAKE_KEY_TYPE ('s', 'p', 'a', '5'),
SmcKeyTypeSpb4 = SMC_MAKE_KEY_TYPE ('s', 'p', 'b', '4'),
SmcKeyTypeSpc3 = SMC_MAKE_KEY_TYPE ('s', 'p', 'c', '3'),
SmcKeyTypeSpd2 = SMC_MAKE_KEY_TYPE ('s', 'p', 'd', '2'),
SmcKeyTypeSpe1 = SMC_MAKE_KEY_TYPE ('s', 'p', 'e', '1'),
SmcKeyTypeSpf0 = SMC_MAKE_KEY_TYPE ('s', 'p', 'f', '0'),
SmcKeyTypeUint8z = SMC_MAKE_KEY_TYPE ('u', 'i', '8', '\0'),
SmcKeyTypeUint8 = SMC_MAKE_KEY_TYPE ('u', 'i', '8', ' '),
SmcKeyTypeUint8s = SMC_MAKE_KEY_TYPE ('u', 'i', '8', '*'),
SmcKeyTypeUint16 = SMC_MAKE_KEY_TYPE ('u', 'i', '1', '6'),
SmcKeyTypeUint32 = SMC_MAKE_KEY_TYPE ('u', 'i', '3', '2'),
SmcKeyTypeUint64 = SMC_MAKE_KEY_TYPE ('u', 'i', '6', '4'),
SmcKeyTypeAla = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 'a'),
SmcKeyTypeAlc = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 'c'),
SmcKeyTypeAli = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 'i'),
SmcKeyTypeAlp = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 'p'),
SmcKeyTypeAlr = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 'r'),
SmcKeyTypeAlt = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 't'),
SmcKeyTypeAlv = SMC_MAKE_KEY_TYPE ('{', 'a', 'l', 'v'),
SmcKeyTypeClc = SMC_MAKE_KEY_TYPE ('{', 'c', 'l', 'c'),
SmcKeyTypeClh = SMC_MAKE_KEY_TYPE ('{', 'c', 'l', 'h'),
SmcKeyTypeFds = SMC_MAKE_KEY_TYPE ('{', 'f', 'd', 's'),
SmcKeyTypeHdi = SMC_MAKE_KEY_TYPE ('{', 'h', 'd', 'i'),
SmcKeyTypeJst = SMC_MAKE_KEY_TYPE ('{', 'j', 's', 't'),
SmcKeyTypeLia = SMC_MAKE_KEY_TYPE ('{', 'l', 'i', 'a'),
SmcKeyTypeLic = SMC_MAKE_KEY_TYPE ('{', 'l', 'i', 'c'),
SmcKeyTypeLim = SMC_MAKE_KEY_TYPE ('{', 'l', 'i', 'm'),
SmcKeyTypeLkb = SMC_MAKE_KEY_TYPE ('{', 'l', 'k', 'b'),
SmcKeyTypeLks = SMC_MAKE_KEY_TYPE ('{', 'l', 'k', 's'),
SmcKeyTypeLsc = SMC_MAKE_KEY_TYPE ('{', 'l', 's', 'c'),
SmcKeyTypeLsd = SMC_MAKE_KEY_TYPE ('{', 'l', 's', 'd'),
SmcKeyTypeLsf = SMC_MAKE_KEY_TYPE ('{', 'l', 's', 'f'),
SmcKeyTypeLso = SMC_MAKE_KEY_TYPE ('{', 'l', 's', 'o'),
SmcKeyTypeMss = SMC_MAKE_KEY_TYPE ('{', 'm', 's', 's'),
SmcKeyTypePwm = SMC_MAKE_KEY_TYPE ('{', 'p', 'w', 'm'),
SmcKeyTypeRev = SMC_MAKE_KEY_TYPE ('{', 'r', 'e', 'v')
};
// SMC_KEY_TYPE
typedef UINT32 SMC_KEY_TYPE;
// Key Attributes
#define SMC_KEY_ATTRIBUTE_PRIVATE_WRITE BIT0
#define SMC_KEY_ATTRIBUTE_PRIVATE_READ BIT1
#define SMC_KEY_ATTRIBUTE_ATOMIC BIT2
#define SMC_KEY_ATTRIBUTE_CONST BIT3
#define SMC_KEY_ATTRIBUTE_FUNCTION BIT4
#define SMC_KEY_ATTRIBUTE_UKN_0x20 BIT5
#define SMC_KEY_ATTRIBUTE_WRITE BIT6
#define SMC_KEY_ATTRIBUTE_READ BIT7
// SMC_KEY_ATTRIBUTES
typedef UINT8 SMC_KEY_ATTRIBUTES;
// Data
#define SMC_MAX_DATA_SIZE (SMC_MMIO_DATA_FIXED - SMC_MMIO_DATA_VARIABLE)
typedef UINT8 SMC_DATA;
typedef UINT8 SMC_DATA_SIZE;
// Keys
// SMC_KEY_IS_VALID_CHAR
#define SMC_KEY_IS_VALID_CHAR(x) (((x) >= 0x20) && ((x) <= 0x7E))
// SMC_MAKE_KEY
#define SMC_MAKE_KEY(A, B, C, D) SMC_MAKE_IDENTIFIER ((A), (B), (C), (D))
#define SMC_KEY_NUM SMC_MAKE_KEY ('$', 'N', 'u', 'm')
#define SMC_KEY_ADR SMC_MAKE_KEY ('$', 'A', 'd', 'r')
#define SMC_KEY_LDKN SMC_MAKE_KEY ('L', 'D', 'K', 'N')
#define SMC_KEY_HBKP SMC_MAKE_KEY ('H', 'B', 'K', 'P')
#define SMC_KEY_KEY SMC_MAKE_KEY ('#', 'K', 'E', 'Y')
#define SMC_KEY_RMde SMC_MAKE_KEY ('R', 'M', 'd', 'e')
#define SMC_KEY_BRSC SMC_MAKE_KEY ('B', 'R', 'S', 'C')
#define SMC_KEY_MSLD SMC_MAKE_KEY ('M', 'S', 'L', 'D')
#define SMC_KEY_BATP SMC_MAKE_KEY ('B', 'A', 'T', 'P')
#define SMC_KEY_BBIN SMC_MAKE_KEY ('B', 'B', 'I', 'N')
typedef UINT32 SMC_KEY;
typedef UINT32 SMC_KEY_INDEX;
typedef UINT8 SMC_DEVICE_INDEX;
// Flash data
// SMC_FLASH_SIZE_MAX
#define SMC_FLASH_SIZE_MAX 0x0800
// SMC_FLASH_SIZE
typedef UINT16 SMC_FLASH_SIZE;
// Events
enum {
SmcEventALSChange = 0x2A,
SmcEventShutdownImminent = 0x40,
SmcEventBridgeOSPanic = 0x41,
SmcEventLogMessage = 0x4C,
SmcEventKeyDone = 0x4B,
SmcEventPThermalLevelChanged = 0x54,
SmcEventCallPlatformFunction = 0x55,
SmcEventSMSDrop = 0x60,
SmcEventUnknown6A = 0x6A, // Bug??
SmcEventSMSOrientation = 0x69,
SmcEventSMSShock = 0x6F,
SmcEventSystemStateNotify = 0x70,
SmcEventPowerStateNotify = 0x71,
SmcEventHidEventNotify = 0x72,
SmcEventPLimitChange = 0x80,
SmcEventPCIeReady = 0x83, // Not certain
};
// SmcEventSystemStateNotify subtypes, not always certain
// Mostly from bridgeOS kernelcache and ramrod.
// Check SMCRegisterForSubTypeNotification in libSMC.dylib.
enum {
SmcSystemStateNotifyMacOsPanicCause = 4, // Name unclear
SmcSystemStateNotifyPrepareForS0 = 6,
SmcSystemStateNotifyMacOsPanicDone = 10,
SmcSystemStateNotifyRestart = 15,
SmcSystemStateNotifyMacEfiFirmwareUpdated = 16,
SmcSystemStateNotifyQuiesceDevices = 17,
SmcSystemStateNotifyResumeDevices = 18,
SmcSystemStateNotifyGPUPanelPowerOn = 19,
};
// SmcSystemStateNotifyMacOsPanicCause values, received after PanicDone
enum {
SmcSystemStateNotifyPanicUnknown = 0,
SmcSystemStateNotifyPanicMacOSPanic = 1,
SmcSystemStateNotifyPanicMacOSWatchdog = 2,
SmcSystemStateNotifyPanicX86StraightS5Shutdown = 3,
SmcSystemStateNotifyPanicX86GlobalReset = 4,
SmcSystemStateNotifyPanicX86CpuCATERR = 5,
SmcSystemStateNotifyPanicACPIPanic = 6,
};
// SMC_EVENT_CODE
typedef UINT8 SMC_EVENT_CODE;
// Log
#define SMC_MAX_LOG_SIZE 0x80
typedef UINT8 SMC_LOG;
typedef UINT8 SMC_LOG_SIZE;
// Hard drive encryption
#define SMC_HBKP_SIZE 0x20
#endif // APPLE_SMC_H

View File

@ -0,0 +1,31 @@
//
// AppleSmcBridge.hpp
// AppleSmcBridge
//
// Copyright © 2017 vit9696. All rights reserved.
//
#ifndef AppleSmcBridge_hpp
#define AppleSmcBridge_hpp
#include <stdint.h>
using CHAR8 = char;
using UINT8 = uint8_t;
using UINT16 = uint16_t;
using UINT32 = uint32_t;
static constexpr uint8_t BIT0 = 0b00000001;
static constexpr uint8_t BIT1 = 0b00000010;
static constexpr uint8_t BIT2 = 0b00000100;
static constexpr uint8_t BIT3 = 0b00001000;
static constexpr uint8_t BIT4 = 0b00010000;
static constexpr uint8_t BIT5 = 0b00100000;
static constexpr uint8_t BIT6 = 0b01000000;
static constexpr uint8_t BIT7 = 0b10000000;
extern "C" {
#include "AppleSmc.h"
}
#endif /* AppleSmcBridge_hpp */

View File

@ -0,0 +1,125 @@
//
// kern_keyvalue.hpp
// VirtualSMC
//
// Copyright © 2017 vit9696. All rights reserved.
//
#ifndef kern_keyvalue_hpp
#define kern_keyvalue_hpp
#include <stdatomic.h>
#include <VirtualSMCSDK/AppleSmcBridge.hpp>
#include <VirtualSMCSDK/kern_value.hpp>
struct VirtualSMCKeyValue {
/**
* Key name
*/
SMC_KEY key;
/**
* Key value
*/
_Atomic(VirtualSMCValue *) value = ATOMIC_VAR_INIT(nullptr);
/**
* Original value
*/
_Atomic(VirtualSMCValue *) backup = nullptr;
/**
* Should key value pair be serialisable
*
* @param confidential confidential serialisation stores are allowed
*
* @return true if should be saved
*/
bool serializable(bool confidential) const;
/**
* Get serialized size (normally key, size, key data)
*
* @return size in bytes
*/
size_t serializedSize() const;
/**
* Write serialized data to the buffer
*
* @param dst serialization buffer reference of at least serializedSize()
*/
void serialize(uint8_t *&dst) const;
/**
* Read serialized data
*
* @param src serialization buffer reference (increased)
* @param size serialization buffer size (decreased)
* @param name read key name
* @param out read key data (must be preallocated)
* @param outsz key data size
*
* @return true on succesful read
*/
static bool deserialize(const uint8_t *&src, uint32_t &size, SMC_KEY &name, SMC_DATA *out, SMC_DATA_SIZE &outsz);
/**
* Create key/value pair for storage
*
* @param k key name
* @param v key value
*
* @return key/value pair
*/
static VirtualSMCKeyValue create(SMC_KEY k, VirtualSMCValue *v) {
VirtualSMCKeyValue kv {k};
atomic_init(&kv.value, v);
atomic_init(&kv.backup, nullptr);
return kv;
}
/**
* Key/value deleter responsible for freeing value dynamic memory
*
* @param kv key/value pair
*/
static void deleter(VirtualSMCKeyValue &kv) {
// This is just an old compiler crash workaround, no need for atomicity here!
auto v = atomic_load_explicit(&kv.value, memory_order_relaxed);
auto b = atomic_load_explicit(&kv.backup, memory_order_relaxed);
if (v) VirtualSMCValue::deleter(v);
if (b) VirtualSMCValue::deleter(b);
}
/**
* Key comparator for sorting
*
* @param a first key
* @param b second key
*
* @return like qsort (<0 if a goes before b)
*/
static int compare(const SMC_KEY a, const SMC_KEY b) {
if (a == b)
return 0;
else if (OSSwapInt32(a) < OSSwapInt32(b))
return -1;
return 1;
}
/**
* Key value comparator for sorting
*
* @param a opaque k/v pointer
* @param b opaque k/v pointer
*
* @return like qsort (<0 if a goes before b)
*/
static int compare(const void *a, const void *b) {
return compare(static_cast<const VirtualSMCKeyValue *>(a)->key, static_cast<const VirtualSMCKeyValue *>(b)->key);
}
};
#endif /* kern_keyvalue_hpp */

View File

@ -0,0 +1,256 @@
//
// kern_smcinfo.hpp
// VirtualSMC
//
// Copyright © 2017 vit9696. All rights reserved.
//
#ifndef kern_smcinfo_h
#define kern_smcinfo_h
#include <Headers/kern_util.hpp>
#include <VirtualSMCSDK/AppleSmcBridge.hpp>
class SMCInfo {
/**
* Device-specific reproducible random state
*/
uint64_t generatorState {};
public:
/**
* Size in bytes for SmcKeyTypeRev keys
*/
static constexpr SMC_DATA_SIZE RevisionSize = 6;
/**
* Size in bytes for branch keys (usually ch8*)
*/
static constexpr SMC_DATA_SIZE BranchSize = 8;
/**
* Size in bytes for hardware model name
*/
static constexpr SMC_DATA_SIZE ModelSize = 64;
/**
* Size in bytes for MAC value
*/
static constexpr SMC_DATA_SIZE MacSize = 6;
/**
* Size in bytes for Serial value
*/
static constexpr SMC_DATA_SIZE SerialSize = 16;
/**
* Size in bytes for Motherboard Serial value
*/
static constexpr SMC_DATA_SIZE MotherboardSerialSize = 17;
/**
* Device generation:
* - V1 is Big Endian Hitachi
* - V2 is Little Endian ARM
* - Unspecified is used for autodetection code
*/
enum class Generation {
Unspecified = 0,
V1 = 1,
V2 = 2,
V3 = 3
};
/**
* Device memory layout information
*/
struct Memory {
mach_vm_address_t start;
mach_vm_size_t size;
vm_prot_t prot;
};
/**
* Buffers describing device version information
*/
enum class Buffer {
RevMain,
RevFlasherBase,
RevFlasherUpdate,
Branch,
Platform,
HardwareModel,
MacAddress,
Serial,
MotherboardSerial
};
/**
* Corresponds to REV key contents
*/
SMC_DATA main[RevisionSize] {};
/**
* Corresponds to RVBF key contents
*/
SMC_DATA flasherBase[RevisionSize] {};
/**
* Corresponds to RVUF key contents
*/
SMC_DATA flasherUpdate[RevisionSize] {};
/**
* Corresponds to RBr key contents
*/
SMC_DATA branch[BranchSize] {};
/**
* Corresponds to RPlt key contents
*/
SMC_DATA platform[BranchSize] {};
/**
* Corresponds to SMC hardware model (aka compatible key)
*/
SMC_DATA hardwareModel[ModelSize] {};
/**
* Corresponds to RMAC key contents
*/
SMC_DATA macAddress[MacSize] {};
/**
* Corresponds to RSSN key contents
*/
SMC_DATA serial[SerialSize] {};
/**
* Corresponds to RSSN key contents
*/
SMC_DATA motherboardSerial[MotherboardSerialSize] {};
/**
* Get device generation based on obtained buffers
*
* @return device generation
*/
Generation getGeneration() const {
if (main[0] == 1)
return Generation::V1;
else if (main[0] == 2)
return Generation::V2;
else if (main[0] == 3 || main[0] == 0)
return Generation::V3;
DBGLOG("smcinfo", "invalid generation %X, defaulting to V2", main[0]);
return Generation::V2;
}
/**
* Initialise reproducible pseudo-random number generator with device info
*/
void generatorSeed() {
union {
uint8_t arr[8];
uint64_t raw;
} seed;
seed.arr[0] = main[0];
seed.arr[1] = main[1];
seed.arr[2] = main[3];
seed.arr[3] = main[5];
seed.arr[4] = branch[0];
seed.arr[5] = branch[1];
seed.arr[6] = branch[2];
seed.arr[7] = branch[4];
generatorState = seed.raw ^ 0x106689D45497FDB5;
}
/**
* Get next reproducible pseudo-random number based on device info
* generatorSeed must be called before using this function
*
* @return pseudo-random number
*/
uint64_t generatorRand() {
uint64_t x = generatorState;
x ^= x >> 12; // a
x ^= x << 25; // b
x ^= x >> 27; // c
generatorState = x;
return x * 0x2545F4914F6CDD1D;
}
/**
* Get device information buffer
*
* @param id buffer id
*
* @return pointer to the buffer
*/
SMC_DATA *getBuffer(Buffer id) {
switch (id) {
case Buffer::RevMain:
return main;
case Buffer::RevFlasherBase:
return flasherBase;
case Buffer::RevFlasherUpdate:
return flasherUpdate;
case Buffer::Branch:
return branch;
case Buffer::Platform:
return platform;
case Buffer::HardwareModel:
return hardwareModel;
case Buffer::MacAddress:
return macAddress;
case Buffer::Serial:
return serial;
case Buffer::MotherboardSerial:
return motherboardSerial;
}
}
/**
* Get device information buffer size
*
* @param id buffer id
*
* @return buffer size
*/
SMC_DATA_SIZE getBufferSize(Buffer id) {
switch (id) {
case Buffer::RevMain:
case Buffer::RevFlasherBase:
case Buffer::RevFlasherUpdate:
return RevisionSize;
case Buffer::Branch:
case Buffer::Platform:
return BranchSize;
case Buffer::HardwareModel:
return ModelSize;
case Buffer::MacAddress:
return MacSize;
case Buffer::Serial:
return SerialSize;
case Buffer::MotherboardSerial:
return MotherboardSerialSize;
}
}
/**
* Check if the necessary buffer information was supplied previously
*
* @return true if version info is ok
*/
bool isValid() const {
// Note, we do not check mac/serial validity, as they are optional!
// Everything but platform was also removed by T2!
return platform[0] && hardwareModel[0];
}
};
#endif /* kern_smcinfo_h */

View File

@ -0,0 +1,149 @@
//
// kern_keyvalue.hpp
// VirtualSMC
//
// Copyright © 2018 vit9696. All rights reserved.
//
#ifndef kern_value_hpp
#define kern_value_hpp
#include <Headers/kern_util.hpp>
#include <libkern/c++/OSData.h>
#include <VirtualSMCSDK/AppleSmcBridge.hpp>
/**
* Serialization level determining external value storage necessity
*/
enum class EXPORT SerializeLevel {
None,
Normal,
Confidential,
Default = Confidential
};
class VirtualSMCKeystore;
class VirtualSMCKeyValue;
class EXPORT VirtualSMCValue {
friend VirtualSMCKeystore;
friend VirtualSMCKeyValue;
protected:
/**
* Value contents retrieved by other protocols
*/
SMC_DATA data[SMC_MAX_DATA_SIZE] {};
/**
* Actual value contents size (could be less than SMC_MAX_DATA_SIZE)
*/
SMC_DATA_SIZE size {};
/**
* One of the enum types defined in AppleSmc.h specifying value type
*/
SMC_KEY_TYPE type {};
/**
* Bitmask of key attributes defined in AppleSmc.h defining value abilities
*/
SMC_KEY_ATTRIBUTES attr {};
/**
* Serialization level defining the necessity to serialize values on power events
*/
SerializeLevel serializeLevel {SerializeLevel::None};
/**
* On read access, update the data if needed, and perform custom access control.
* For base value, always allow the access if keystore allowed it.
*
* @return SmcSuccess if allowed
*/
virtual SMC_RESULT readAccess() {
return SmcSuccess;
}
/**
* On write access, update the data if needed, and perform custom access control.
* For base value, always allow the access if keystore allowed it.
*
* @return SmcSuccess if allowed
*/
virtual SMC_RESULT writeAccess() {
return SmcSuccess;
}
public:
/**
* Initialises a value with existing data.
*
* @param data Initial data, must be at least size bytes
* @param size Amount of data bytes used, at most SMC_MAX_DATA_SIZE
* @param type Value type
* @param attr Value attributes
* @param level Serialization necessity
*
* @return true on success
*/
EXPORT bool init(const SMC_DATA *data, SMC_DATA_SIZE size, SMC_KEY_TYPE type, SMC_KEY_ATTRIBUTES attr, SerializeLevel level = SerializeLevel::None);
/**
* Initialises a value with an OSDictionary.
* Dictionary keys are described in VirtualKeystore::merge(const OSArray *) method.
*
* @param dict An OSDictionary that describes the value
*
* @return true on success
*/
EXPORT bool init(const OSDictionary *dict);
/**
* Obtain value contents
*
* @param size Amount of used bytes
*
* @return Pointer to the value data buffer.
*
* The buffer shall never be modified externally.
*/
const SMC_DATA *get(SMC_DATA_SIZE &size) const;
/**
* Update the internal buffer, assuming the same
* amount of bytes is used for this value.
*
* @param src new contents
*/
virtual SMC_RESULT update(const SMC_DATA *src);
/**
* Checks serialization necessity
*
* @param confidential confidential information storage is allowed
*
* @retrurn true if the value needs to be serialized
*/
bool serializable(bool confidential) const {
return serializeLevel == SerializeLevel::Normal ||
(serializeLevel == SerializeLevel::Confidential && confidential);
}
/**
* It is not recommended to free created values but you can if you need
*/
virtual ~VirtualSMCValue() = default;
/**
* Used for storing values in evector
*
* @param inst value to be freed
*/
static void deleter(VirtualSMCValue *inst) {
delete inst;
}
};
#endif /* kern_value_hpp */

View File

@ -0,0 +1,328 @@
//
// kern_vsmcapi.hpp
// VirtualSMC
//
// Copyright © 2018 vit9696. All rights reserved.
//
#ifndef kern_vsmcapi_hpp
#define kern_vsmcapi_hpp
#include <Headers/kern_util.hpp>
#include <VirtualSMCSDK/kern_smcinfo.hpp>
#include <VirtualSMCSDK/kern_keyvalue.hpp>
#include <IOKit/IOService.h>
namespace VirtualSMCAPI {
/**
* SMC device service name. Please be aware that the same name is used for any (including physical) SMC device.
*/
static constexpr const char *ServiceName = "APP0001";
/**
* Main communication platform function interface.
* Takes plugin IOService and VirtualSMCPlugin as arguments. No modifications to struct contents are allowed once it is submitted.
* Virtual key functions may be invoked asynchronously from inside IOSimpleLock context, so they should be designed
* with the help of lock-free algorithms.
*/
static constexpr const char *SubmitPlugin = "VirtualSMCSubmitPlugin";
/**
* A total maximum of allowed plugins for installation.
*/
static constexpr size_t PluginMax = 16;
/**
* Accepted plugin API (and ABI) compatibility
*/
static constexpr size_t Version = 1;
/**
* Sorted key storage containing pairs of keys and values.
*/
using KeyStorage = evector<VirtualSMCKeyValue&, VirtualSMCKeyValue::deleter>;
/**
* Main description structure submitted by a plugin. Must be unchanged and never deallocated after submission.
*/
struct Plugin {
const char *product; // Product name (e.g. xStringify(PRODUCT_NAME))
size_t version; // Product version (e.g. parseModuleVersion(xStringify(MODULE_VERSION)))
size_t apiver; // Product API compatibility (i.e. VirtualSMCAPIVersion)
// Please note, that storage vectors MUST be sorted. Otherwise the behaviour is undefined.
KeyStorage data, dataHidden;
};
/**
* Register plugin handler for plugin loading
*
* @param handler function to handle the notification
* @param context function context
*
* @result notifier (must be released) or nullptr
*/
EXPORT IONotifier *registerHandler(IOServiceMatchingNotificationHandler handler, void *context);
/**
* Asynchronous event poster, which may be used for submitting plugin events.
* Note, this may only be used after SubmitPlugin.
*
* @param code event code to post
* @param data data to include in the interrupt
* @param dataSize size of the supplied data
*
* @return true on success
*/
EXPORT bool postInterrupt(SMC_EVENT_CODE code, const void *data=nullptr, uint32_t dataSize=0);
/**
* Obtain emulated SMC device info to determine used keys and their format.
* Note, this may only be used within SubmitPlugin or afterwards.
*
* @param info device info object to be copied to
*
* @return true on success
*/
EXPORT bool getDeviceInfo(SMCInfo &info);
/**
* Adds a key with given value to a key storage.
* Does nothing if given value is nullptr.
*
* @param key an SMC key
* @param data a key storage to add the key to
* @param val an SMC value for the given key
*
* @return true on success
*/
EXPORT bool addKey(SMC_KEY key, KeyStorage &data, VirtualSMCValue *val);
/**
* Initializes the given value with the appropriate data. Creates new value if nullptr passed as thisValue.
*
* @param smcData a pointer to SMC_DATA to be used for the value.
* @param smcDataSize a size of given SMC_DATA. Cannot be 0.
* @param smcKeyType a key type to init value with.
* @param thisValue a pointer to VirtualSMCValue. Must always be heap-based, don't use address take operator (&). If nullptr passed an instance of VirtualSMCValue will be created for you. Defaults to nullptr.
* @param smcKeyAttrs a key attributes as SMC_KEY_ATTRIBUTES flags. Defaults to SMC_KEY_ATTRIBUTE_READ.
* @param serializeLevel a serialize level needed. Defaults to SerializeLevel::None.
*
* @return thisValue either passed or created new on success, nullptr if something went wrong.
*/
EXPORT VirtualSMCValue *valueWithData(const SMC_DATA *smcData, SMC_DATA_SIZE smcDataSize, SMC_KEY_TYPE smcKeyType, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None);
/**
* Decode Apple SP signed fixed point fractional format
*
* @param type encoding type, e.g. SmcKeyTypeSp78
* @param value value as it is read from SMC_DATA field
*
* @return floating point value
*/
EXPORT double decodeSp(uint32_t type, uint16_t value);
/**
* Encode Apple SP signed fixed point fractional format
*
* @param type encoding type, e.g. SmcKeyTypeSp78
* @param value source value
*
* @return value as it is to be written to SMC_DATA field
*/
EXPORT uint16_t encodeSp(uint32_t type, double value);
/**
* Decode Apple FP unsigned fixed point fractional format
*
* @param type encoding type, e.g. SmcKeyTypeFp88
* @param value value as it is read from SMC_DATA field
*
* @return floating point value
*/
EXPORT double decodeFp(uint32_t type, uint16_t value);
/**
* Encode Apple FP unsigned fixed point fractional format
*
* @param type encoding type, e.g. SmcKeyTypeFp88
* @param value source value
*
* @return value as it is to be written to SMC_DATA field
*/
EXPORT uint16_t encodeFp(uint32_t type, double value);
/**
* Decode Apple FP signed integral number
*
* @param type encoding type, e.g. SmcKeyTypeSp78
* @param value value as it is read from SMC_DATA field
*
* @return floating point value
*/
EXPORT int16_t decodeIntSp(uint32_t type, uint16_t value);
/**
* Encode Apple FP signed integral number
*
* @param type encoding type, e.g. SmcKeyTypeSp78
* @param value source value
*
* @return value as it is to be written to SMC_DATA field
*/
EXPORT uint16_t encodeIntSp(uint32_t type, int16_t value);
/**
* Decode Apple FP unsigned integral number
*
* @param type encoding type, e.g. SmcKeyTypeFpe2
* @param value value as it is read from SMC_DATA field
*
* @return floating point value
*/
EXPORT uint16_t decodeIntFp(uint32_t type, uint16_t value);
/**
* Encode Apple FP unsigned integral number
*
* @param type encoding type, e.g. SmcKeyTypeFpe2
* @param value source value
*
* @return value as it is to be written to SMC_DATA field
*/
EXPORT uint16_t encodeIntFp(uint32_t type, uint16_t value);
/**
* Decode Apple float fractional format
*
* @param value value as it is read from SMC_DATA field
*
* @return floating point value
*/
inline float decodeFlt(uint32_t value) {
union { uint32_t u32; float f; } v {value};
return v.f;
}
/**
* Encode Apple float fractional format
*
* @param value source value
*
* @return value as it is to be written to SMC_DATA field
*/
inline uint32_t encodeFlt(float value) {
union { float f; uint32_t u32; } v {value};
return v.u32;
}
/**
* A convenient method for initializing flag type key value.
*
* @param flagValue a boolean true or false.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithFlag(bool flagValue, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
return valueWithData(reinterpret_cast<const SMC_DATA *>(&flagValue), sizeof(bool), SmcKeyTypeFlag, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing Uint8 type key value.
*
* @param uint8Value an integer of 0..255 range.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithUint8(uint8_t uint8Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
return valueWithData(reinterpret_cast<const SMC_DATA *>(&uint8Value), sizeof(uint8_t), SmcKeyTypeUint8, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing Sint8 type key value.
*
* @param sint8Value an integer of -128..127 range.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithSint8(int8_t sint8Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
return valueWithData(reinterpret_cast<const SMC_DATA *>(&sint8Value), sizeof(uint8_t), SmcKeyTypeSint8, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing Sint16 type key value.
*
* @param int16Value an integer of -32767..32768 range.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithSint16(int16_t int16Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
int16_t t = OSSwapHostToBigInt16(int16Value);
return valueWithData(reinterpret_cast<const SMC_DATA *>(&t), sizeof(int16_t), SmcKeyTypeSint16, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing Uint16 type key value.
*
* @param uint16Value an integer of 0..65535 range.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithUint16(uint16_t uint16Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
uint16_t t = OSSwapHostToBigInt16(uint16Value);
return valueWithData(reinterpret_cast<const SMC_DATA *>(&t), sizeof(uint16_t), SmcKeyTypeUint16, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing Sint32 type key value.
*
* @param int32Value an integer of 2147483648..2147483647 range.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithSint32(int32_t int32Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
int32_t t = OSSwapHostToBigInt32(int32Value);
return valueWithData(reinterpret_cast<const SMC_DATA *>(&t), sizeof(int32_t), SmcKeyTypeSint32, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing uint32_t type key value.
*
* @param uint32Value an integer of 0..4294967295 range.
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithUint32(uint32_t uint32Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
uint32_t t = OSSwapHostToBigInt32(uint32Value);
return valueWithData(reinterpret_cast<const SMC_DATA *>(&t), sizeof(uint32_t), SmcKeyTypeUint32, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing spXX key value
*
* @param value floating point value
* @param type Apple sp type (see encodeSp)
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithSp(double value, SMC_KEY_TYPE spType, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
auto e = encodeSp(spType, value);
return valueWithData(reinterpret_cast<SMC_DATA *>(&e), sizeof(e), spType, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing fpXX key value
*
* @param value floating point value
* @param type Apple fp type (see encodeFp)
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithFp(double value, SMC_KEY_TYPE fpType, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
auto e = encodeFp(fpType, value);
return valueWithData(reinterpret_cast<SMC_DATA *>(&e), sizeof(e), fpType, thisValue, smcKeyAttrs, serializeLevel);
}
/**
* A convenient method for initializing flt key value
*
* @param value floating point value
* @see VirtualSMCAPI::valueWithData
*/
inline VirtualSMCValue *valueWithFlt(float value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) {
auto e = encodeFlt(value);
return valueWithData(reinterpret_cast<SMC_DATA *>(&e), sizeof(e), SmcKeyTypeFloat, thisValue, smcKeyAttrs, serializeLevel);
}
}
#endif /* kern_vsmcapi_hpp */