Files
gronodandDevin <158243242+devin-ai-integration[bot]@users.noreply.github.com> acf5d03277 fix(smc): correct IOKit service name and SMCKeyData_t layout (fixes #32)
Two latent bugs kept all SMC telemetry dead:
- IOServiceMatching("AppleSMCClient") never matched — the kernel service
  is AppleSMC, so openWithError always failed and every SMC-gated provider
  (thermal, fan, component, power) reported unavailable.
- #pragma pack(1) shrank SMCKeyData_t to 74 bytes; the SMC user client
  requires the canonical 80-byte layout and rejected every
  IOConnectCallStructMethod with kIOReturnBadArgument. Verified live on
  Intel hardware: unpacked calls succeed and return key data.

Also sources the alert engine's batteryLevel from the SMC-independent
batteryHealth path (currentCapacity/maxCapacity), falling back to the
power provider.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 15:14:41 +01:00

76 lines
1.6 KiB
Objective-C

#ifndef MMSMCDefines_h
#define MMSMCDefines_h
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
#define KERNEL_INDEX_SMC 2
// SMC Call Selectors
#define kSMCUserClientOpen 0
#define kSMCUserClientClose 1
#define kSMCHandleYPCEvent 2
#define kSMCReadKey 5
#define kSMCWriteKey 6
#define kSMCGetKeyFromIndex 8
#define kSMCGetKeyInfo 9
typedef struct {
unsigned char major;
unsigned char minor;
unsigned char build;
unsigned char reserved[1];
unsigned short release;
} SMCVersion;
typedef struct {
uint16_t version;
uint16_t length;
uint32_t cpuPLimit;
uint32_t gpuPLimit;
uint32_t memPLimit;
} SMCPLimitData;
typedef struct {
IOByteCount dataSize;
UInt32 dataType;
UInt8 dataAttributes;
} SMCKeyInfoData;
typedef struct {
UInt32 key;
SMCVersion vers;
SMCPLimitData pLimitData;
SMCKeyInfoData keyInfo;
UInt8 result;
UInt8 status;
UInt8 data8;
UInt32 data32;
UInt8 bytes[32];
} SMCKeyData_t;
typedef struct {
char key[5];
UInt32 dataSize;
char dataType[5];
UInt8 bytes[32];
} SMCVal_t;
static inline UInt32 MMSMCToFourCharCode(const char * _Nonnull str) {
UInt32 code = 0;
for (int i = 0; i < 4 && str[i] != '\0'; i++) {
code = (code << 8) | (UInt8)str[i];
}
return code;
}
static inline void MMSMCFromFourCharCode(UInt32 code, char * _Nonnull outStr) {
outStr[0] = (char)((code >> 24) & 0xFF);
outStr[1] = (char)((code >> 16) & 0xFF);
outStr[2] = (char)((code >> 8) & 0xFF);
outStr[3] = (char)(code & 0xFF);
outStr[4] = '\0';
}
#endif /* MMSMCDefines_h */