From 679e6c659c0fc8f2a1c69ae0c6dd7a41711f2fde Mon Sep 17 00:00:00 2001 From: nandhp Date: Sun, 30 Jul 2017 12:30:31 -0500 Subject: [PATCH 1/2] Fix Makefile build --- smc-command/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smc-command/Makefile b/smc-command/Makefile index c78db24..9d532d8 100644 --- a/smc-command/Makefile +++ b/smc-command/Makefile @@ -1,5 +1,6 @@ CC = gcc CFLAGS = -mmacosx-version-min=10.4 -Wall -g -framework IOKit +CPPFLAGS = -DCMD_TOOL_BUILD all: smc @@ -7,7 +8,7 @@ smc: smc.o $(CC) $(CFLAGS) -o smc smc.o smc.o: smc.h smc.c - $(CC) -c smc.c + $(CC) $(CPPFLAGS) -c smc.c clean: -rm -f smc smc.o From 757dd0083f4ed678c25faa93c4f77d6ec4564b03 Mon Sep 17 00:00:00 2001 From: nandhp Date: Sun, 30 Jul 2017 12:34:09 -0500 Subject: [PATCH 2/2] Add -t option to read temperatures --- smc-command/smc.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- smc-command/smc.h | 1 + 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/smc-command/smc.c b/smc-command/smc.c index 8da7d68..463a066 100755 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -549,12 +549,53 @@ kern_return_t SMCPrintFans(void) return kIOReturnSuccess; } +kern_return_t SMCPrintTemps(void) +{ + kern_return_t result; + SMCKeyData_t inputStructure; + SMCKeyData_t outputStructure; + + int totalKeys, i; + UInt32Char_t key; + SMCVal_t val; + + totalKeys = SMCReadIndexCount(); + for (i = 0; i < totalKeys; i++) + { + memset(&inputStructure, 0, sizeof(SMCKeyData_t)); + memset(&outputStructure, 0, sizeof(SMCKeyData_t)); + memset(&val, 0, sizeof(SMCVal_t)); + + inputStructure.data8 = SMC_CMD_READ_INDEX; + inputStructure.data32 = i; + + result = SMCCall(KERNEL_INDEX_SMC, &inputStructure, &outputStructure); + if (result != kIOReturnSuccess) + continue; + + _ultostr(key, outputStructure.key); + if ( key[0] != 'T' ) + continue; + + SMCReadKey(key, &val); + //printVal(val); + if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) { + printf("%-4s ", val.key); + printSP78(val); + printf("\n"); + } + } + + return kIOReturnSuccess; +} + void usage(char* prog) { printf("Apple System Management Control (SMC) tool %s\n", VERSION); printf("Usage:\n"); printf("%s [options]\n", prog); printf(" -f : fan info decoded\n"); + printf(" -t : list all temperatures\n"); printf(" -h : help\n"); printf(" -k : key to manipulate\n"); printf(" -l : list all keys and values\n"); @@ -595,13 +636,16 @@ int main(int argc, char *argv[]) UInt32Char_t key = { 0 }; SMCVal_t val; - while ((c = getopt(argc, argv, "fhk:lrw:v")) != -1) + while ((c = getopt(argc, argv, "fthk:lrw:v")) != -1) { switch(c) { case 'f': op = OP_READ_FAN; break; + case 't': + op = OP_READ_TEMPS; + break; case 'k': strncpy(key, optarg, sizeof(key)); //fix for buffer overflow key[sizeof(key) - 1] = '\0'; @@ -675,6 +719,11 @@ int main(int argc, char *argv[]) if (result != kIOReturnSuccess) printf("Error: SMCPrintFans() = %08x\n", result); break; + case OP_READ_TEMPS: + result = SMCPrintTemps(); + if (result != kIOReturnSuccess) + printf("Error: SMCPrintFans() = %08x\n", result); + break; case OP_WRITE: if (strlen(key) > 0) { diff --git a/smc-command/smc.h b/smc-command/smc.h index 5f086b4..4779abd 100755 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -30,6 +30,7 @@ #define OP_READ 2 #define OP_READ_FAN 3 #define OP_WRITE 4 +#define OP_READ_TEMPS 5 #define KERNEL_INDEX_SMC 2