From 48cbf2ac37d52a82f4e9b3008c7737eab42c9925 Mon Sep 17 00:00:00 2001 From: Perceval F Date: Mon, 30 Mar 2015 15:43:04 +0200 Subject: [PATCH 01/11] Now includes its header --- SMCWrapper/SMCWrapper.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index 30ece75..52aec14 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -30,7 +30,7 @@ #include #include #include - +#include "SMCWrapper.h" #include "smc.h" //#define STRIP_COMPATIBILIY From 9f6741b37d15be296a70bca823c4f7a165dabd47 Mon Sep 17 00:00:00 2001 From: Perceval F Date: Mon, 30 Mar 2015 15:45:51 +0200 Subject: [PATCH 02/11] Stripped useless "key values", added SMCState_t enum --- SMCWrapper/SMCWrapper.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SMCWrapper/SMCWrapper.h b/SMCWrapper/SMCWrapper.h index 53ef0cf..15bb3cf 100644 --- a/SMCWrapper/SMCWrapper.h +++ b/SMCWrapper/SMCWrapper.h @@ -72,14 +72,6 @@ #define DATATYPE_FLAG "flag" #define DATATYPE_CHARSTAR "ch8*" -// key values -#define SMC_KEY_CPU_TEMP "TC0P" -#define SMC_KEY_FAN_SPEED "F%dAc" -#define SMC_KEY_FAN_NUM "FNum" -#define SMC_KEY_BATTERY_TEMP "TB0T" - - - typedef struct SMCKeyData_vers_t { char major; char minor; @@ -131,6 +123,14 @@ typedef struct { SMCBytes_t bytes; } SMCVal_t; +typedef enum { + SUCCESS = 0, + FAILURE_IOServiceGetMatchingServices = 1, + FAILURE_NO_SMC_FOUND = 2, + FAILURE_IOServiceOpen = 3, + FAILURE_CALLING_STRUCT_METHOD = 4 +} SMCState_t; + @interface SMCWrapper : NSObject +(SMCWrapper *)sharedWrapper; -(id) init; From 8a48880f06414557d0e2d79ae0f79e725a4aa7f5 Mon Sep 17 00:00:00 2001 From: Perceval F Date: Mon, 30 Mar 2015 15:49:35 +0200 Subject: [PATCH 03/11] Reordered typedefs, normalised carriage returns --- SMCWrapper/SMCWrapper.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/SMCWrapper/SMCWrapper.h b/SMCWrapper/SMCWrapper.h index 15bb3cf..702a256 100644 --- a/SMCWrapper/SMCWrapper.h +++ b/SMCWrapper/SMCWrapper.h @@ -30,7 +30,6 @@ #endif #define KERNEL_INDEX_SMC 2 - #define SMC_CMD_READ_BYTES 5 #define SMC_CMD_WRITE_BYTES 6 #define SMC_CMD_READ_INDEX 8 @@ -69,9 +68,16 @@ #define DATATYPE_PWM "{pwm" #define DATATYPE_LSO "{lso" #define DATATYPE_ALA "{ala" + #define DATATYPE_FLAG "flag" #define DATATYPE_CHARSTAR "ch8*" +typedef char SMCBytes_t[32]; +typedef char UInt32Char_t[5]; +typedef char Flag[1]; +typedef UInt flag; +typedef UInt16 PWMValue; + typedef struct SMCKeyData_vers_t { char major; char minor; @@ -94,8 +100,6 @@ typedef struct { char dataAttributes; } SMCKeyData_keyInfo_t; -typedef char SMCBytes_t[32]; - typedef struct { UInt32 key; SMCKeyData_vers_t vers; @@ -108,14 +112,6 @@ typedef struct { SMCBytes_t bytes; } SMCKeyData_t; -typedef char UInt32Char_t[5]; - -typedef char Flag[1]; -typedef UInt8 flag; - - -typedef UInt16 PWMValue; - typedef struct { UInt32Char_t key; UInt32 dataSize; @@ -131,6 +127,7 @@ typedef enum { FAILURE_CALLING_STRUCT_METHOD = 4 } SMCState_t; + @interface SMCWrapper : NSObject +(SMCWrapper *)sharedWrapper; -(id) init; From ec7f61940889ee2158c3036adb53fd6c81e1cd8c Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Mon, 30 Mar 2015 16:00:41 +0200 Subject: [PATCH 04/11] Removed useless SMC.h And moved #includes to header --- SMCWrapper/SMCWrapper.h | 7 +++ SMCWrapper/SMCWrapper.m | 9 +--- SMCWrapper/smc.h | 113 ---------------------------------------- 3 files changed, 8 insertions(+), 121 deletions(-) delete mode 100644 SMCWrapper/smc.h diff --git a/SMCWrapper/SMCWrapper.h b/SMCWrapper/SMCWrapper.h index 702a256..71841cc 100644 --- a/SMCWrapper/SMCWrapper.h +++ b/SMCWrapper/SMCWrapper.h @@ -24,6 +24,13 @@ */ #include #include +#include +#include +#include +#include +#include +#include +#include #ifndef __SMC_H__ #define __SMC_H__ diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index 52aec14..8590bc4 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -23,15 +23,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include -#include -#include -#include -#include -#include -#include #include "SMCWrapper.h" -#include "smc.h" + //#define STRIP_COMPATIBILIY // AppleSMC IOService connection diff --git a/SMCWrapper/smc.h b/SMCWrapper/smc.h deleted file mode 100644 index 2f1892c..0000000 --- a/SMCWrapper/smc.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Based on the work included in the Apple System Management Control (SMC) Tool, - * the Apple SMC Tool is Copyright (C) 2006 devnull. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef SMCInfo_smc_h -#define SMCInfo_smc_h - -#define KERNEL_INDEX_SMC 2 - -#define SMC_CMD_READ_BYTES 5 -#define SMC_CMD_WRITE_BYTES 6 -#define SMC_CMD_READ_INDEX 8 -#define SMC_CMD_READ_KEYINFO 9 -#define SMC_CMD_READ_PLIMIT 11 -#define SMC_CMD_READ_VERS 12 - -#define DATATYPE_FP1F "fp1f" -#define DATATYPE_FP4C "fp4c" -#define DATATYPE_FP5B "fp5b" -#define DATATYPE_FP6A "fp6a" -#define DATATYPE_FP79 "fp79" -#define DATATYPE_FP88 "fp88" -#define DATATYPE_FPA6 "fpa6" -#define DATATYPE_FPC4 "fpc4" -#define DATATYPE_FPE2 "fpe2" - -#define DATATYPE_SP1E "sp1e" -#define DATATYPE_SP3C "sp3c" -#define DATATYPE_SP4B "sp4b" -#define DATATYPE_SP5A "sp5a" -#define DATATYPE_SP69 "sp69" -#define DATATYPE_SP78 "sp78" -#define DATATYPE_SP87 "sp87" -#define DATATYPE_SP96 "sp96" -#define DATATYPE_SPB4 "spb4" -#define DATATYPE_SPF0 "spf0" - -#define DATATYPE_UINT8 "ui8 " -#define DATATYPE_UINT16 "ui16" -#define DATATYPE_UINT32 "ui32" - -#define DATATYPE_SI8 "si8 " -#define DATATYPE_SI16 "si16" - -#define DATATYPE_FLAG "flag" -#define DATATYPE_CHARSTAR "ch8*" -#define DATATYPE_PWM "{pwm" - -// @todo: document these structures/types and work out -// where they're utilised. - -typedef struct SMCKeyData_vers_t{ //used to identify SMC firmware version - char major; - char minor; - char build; - char reserved[1]; - UInt16 release; -} SMCKeyData_vers_t; - -typedef struct { - UInt16 version; - UInt16 length; - UInt32 cpuPLimit; - UInt32 gpuPLimit; - UInt32 memPLimit; -} SMCKeyData_pLimitData_t; - -typedef struct { - UInt32 dataSize; - UInt32 dataType; - char dataAttributes; -} SMCKeyData_keyInfo_t; - -typedef char SMCBytes_t[32]; - -typedef struct { - UInt32 key; - SMCKeyData_vers_t vers; - SMCKeyData_pLimitData_t pLimitData; - SMCKeyData_keyInfo_t keyInfo; - char result; - char status; - char data8; - UInt32 data32; - SMCBytes_t bytes; -} SMCKeyData_t; - -typedef char UInt32Char_t[5]; - -typedef struct { - UInt32Char_t key; - UInt32 dataSize; - UInt32Char_t dataType; - SMCBytes_t bytes; -} SMCVal_t; - - -#endif From af0e45a9282a0c803e6c0e020f83844a1fbfb20a Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Mon, 30 Mar 2015 17:00:08 +0200 Subject: [PATCH 05/11] Fixed typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I SPENT ONE FUCKING HOUR TRYING TO UNDERSTAND WHY MY CODE SEGFAULTED. Someone will be hung for that… :rage: --- SMCWrapper/SMCWrapper.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index 8590bc4..44c49d8 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -505,7 +505,7 @@ -(BOOL) readKey:(NSString *)key intoString:(NSString **)str // Mac OS X means rubbish FourCC style data type referencing [self stringRepresentationForBytes:val.bytes - withSize:val.dataType + withSize:val.dataSize ofType:val.dataType inBuffer:&cStr[0]]; From 804d263606ac184309844f86ba82bca716b2ad96 Mon Sep 17 00:00:00 2001 From: Perceval F Date: Wed, 1 Apr 2015 19:04:16 +0200 Subject: [PATCH 06/11] Fixed indentation in stringRepresentationForBytes:withSize:ofType:inBuffer --- SMCWrapper/SMCWrapper.m | 122 ++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index 44c49d8..d9dd49b 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -310,68 +310,68 @@ -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes inBuffer: (char *)str { if (dataSize > 0) { - if ((strcmp(dataType, DATATYPE_UINT8) == 0) || - (strcmp(dataType, DATATYPE_UINT16) == 0) || - (strcmp(dataType, DATATYPE_UINT32) == 0)) { - UInt32 uint= [self _strtoul:bytes forSize:dataSize inBase:10]; - snprintf(str, 15, "%u ", (unsigned int)uint); - } - else if (strcmp(dataType, DATATYPE_FP1F) == 0 && dataSize == 2) - snprintf(str, 15, "%.5f ", ntohs(*(UInt16*)bytes) / 32768.0); - else if (strcmp(dataType, DATATYPE_FP4C) == 0 && dataSize == 2) - snprintf(str, 15, "%.5f ", ntohs(*(UInt16*)bytes) / 4096.0); - else if (strcmp(dataType, DATATYPE_FP5B) == 0 && dataSize == 2) - snprintf(str, 15, "%.5f ", ntohs(*(UInt16*)bytes) / 2048.0); - else if (strcmp(dataType, DATATYPE_FP6A) == 0 && dataSize == 2) - snprintf(str, 15, "%.4f ", ntohs(*(UInt16*)bytes) / 1024.0); - else if (strcmp(dataType, DATATYPE_FP79) == 0 && dataSize == 2) - snprintf(str, 15, "%.4f ", ntohs(*(UInt16*)bytes) / 512.0); - else if (strcmp(dataType, DATATYPE_FP88) == 0 && dataSize == 2) - snprintf(str, 15, "%.3f ", ntohs(*(UInt16*)bytes) / 256.0); - else if (strcmp(dataType, DATATYPE_FPA6) == 0 && dataSize == 2) - snprintf(str, 15, "%.2f ", ntohs(*(UInt16*)bytes) / 64.0); - else if (strcmp(dataType, DATATYPE_FPC4) == 0 && dataSize == 2) - snprintf(str, 15, "%.2f ", ntohs(*(UInt16*)bytes) / 16.0); - else if (strcmp(dataType, DATATYPE_FPE2) == 0 && dataSize == 2) - snprintf(str, 15, "%.2f ", ntohs(*(UInt16*)bytes) / 4.0); - else if (strcmp(dataType, DATATYPE_SP1E) == 0 && dataSize == 2) - snprintf(str, 15, "%.5f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 16384.0); - else if (strcmp(dataType, DATATYPE_SP3C) == 0 && dataSize == 2) - snprintf(str, 15, "%.5f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 4096.0); - else if (strcmp(dataType, DATATYPE_SP4B) == 0 && dataSize == 2) - snprintf(str, 15, "%.4f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 2048.0); - else if (strcmp(dataType, DATATYPE_SP5A) == 0 && dataSize == 2) - snprintf(str, 15, "%.4f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 1024.0); - else if (strcmp(dataType, DATATYPE_SP69) == 0 && dataSize == 2) - snprintf(str, 15, "%.3f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 512.0); - else if (strcmp(dataType, DATATYPE_SP78) == 0 && dataSize == 2) - snprintf(str, 15, "%.3f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 256.0); - else if (strcmp(dataType, DATATYPE_SP87) == 0 && dataSize == 2) - snprintf(str, 15, "%.3f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 128.0); - else if (strcmp(dataType, DATATYPE_SP96) == 0 && dataSize == 2) - snprintf(str, 15, "%.2f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 64.0); - else if (strcmp(dataType, DATATYPE_SPB4) == 0 && dataSize == 2) - snprintf(str, 15, "%.2f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 16.0); - else if (strcmp(dataType, DATATYPE_SPF0) == 0 && dataSize == 2) - snprintf(str, 15, "%.0f ", (float)ntohs(*(UInt16*)bytes)); - else if (strcmp(dataType, DATATYPE_SI16) == 0 && dataSize == 2) - snprintf(str, 15, "%d ", ntohs(*(SInt16*)bytes)); - else if (strcmp(dataType, DATATYPE_SI8) == 0 && dataSize == 1) - snprintf(str, 15, "%d ", (signed char)*bytes); - else if (strcmp(dataType, DATATYPE_PWM) == 0 && dataSize == 2) - snprintf(str, 15, "%.1f%% ", ntohs(*(UInt16*)bytes) * 100 / 65536.0); - else if (strcmp(dataType, DATATYPE_CHARSTAR) == 0) - snprintf(str, 15, "%s ", bytes); - else if (strcmp(dataType, DATATYPE_FLAG) == 0) - snprintf(str, 15, "%s ", bytes[0] ? "TRUE" : "FALSE"); - else { - int i; - char tempAb[64]; - for (i = 0; i < dataSize; i++) { - snprintf(tempAb+strlen(tempAb), 8, "%02x ", (unsigned char) bytes[i]); + if ((strcmp(dataType, DATATYPE_UINT8) == 0) || + (strcmp(dataType, DATATYPE_UINT16) == 0) || + (strcmp(dataType, DATATYPE_UINT32) == 0)) { + UInt32 uint= [self _strtoul:bytes forSize:dataSize inBase:10]; + snprintf(str, 15, "%u ", (unsigned int)uint); + } + else if (strcmp(dataType, DATATYPE_FP1F) == 0 && dataSize == 2) + snprintf(str, 15, "%.5f ", ntohs(*(UInt16*)bytes) / 32768.0); + else if (strcmp(dataType, DATATYPE_FP4C) == 0 && dataSize == 2) + snprintf(str, 15, "%.5f ", ntohs(*(UInt16*)bytes) / 4096.0); + else if (strcmp(dataType, DATATYPE_FP5B) == 0 && dataSize == 2) + snprintf(str, 15, "%.5f ", ntohs(*(UInt16*)bytes) / 2048.0); + else if (strcmp(dataType, DATATYPE_FP6A) == 0 && dataSize == 2) + snprintf(str, 15, "%.4f ", ntohs(*(UInt16*)bytes) / 1024.0); + else if (strcmp(dataType, DATATYPE_FP79) == 0 && dataSize == 2) + snprintf(str, 15, "%.4f ", ntohs(*(UInt16*)bytes) / 512.0); + else if (strcmp(dataType, DATATYPE_FP88) == 0 && dataSize == 2) + snprintf(str, 15, "%.3f ", ntohs(*(UInt16*)bytes) / 256.0); + else if (strcmp(dataType, DATATYPE_FPA6) == 0 && dataSize == 2) + snprintf(str, 15, "%.2f ", ntohs(*(UInt16*)bytes) / 64.0); + else if (strcmp(dataType, DATATYPE_FPC4) == 0 && dataSize == 2) + snprintf(str, 15, "%.2f ", ntohs(*(UInt16*)bytes) / 16.0); + else if (strcmp(dataType, DATATYPE_FPE2) == 0 && dataSize == 2) + snprintf(str, 15, "%.2f ", ntohs(*(UInt16*)bytes) / 4.0); + else if (strcmp(dataType, DATATYPE_SP1E) == 0 && dataSize == 2) + snprintf(str, 15, "%.5f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 16384.0); + else if (strcmp(dataType, DATATYPE_SP3C) == 0 && dataSize == 2) + snprintf(str, 15, "%.5f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 4096.0); + else if (strcmp(dataType, DATATYPE_SP4B) == 0 && dataSize == 2) + snprintf(str, 15, "%.4f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 2048.0); + else if (strcmp(dataType, DATATYPE_SP5A) == 0 && dataSize == 2) + snprintf(str, 15, "%.4f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 1024.0); + else if (strcmp(dataType, DATATYPE_SP69) == 0 && dataSize == 2) + snprintf(str, 15, "%.3f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 512.0); + else if (strcmp(dataType, DATATYPE_SP78) == 0/* && dataSize == 2*/) + snprintf(str, 15, "%.3f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 256.0); + else if (strcmp(dataType, DATATYPE_SP87) == 0 && dataSize == 2) + snprintf(str, 15, "%.3f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 128.0); + else if (strcmp(dataType, DATATYPE_SP96) == 0 && dataSize == 2) + snprintf(str, 15, "%.2f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 64.0); + else if (strcmp(dataType, DATATYPE_SPB4) == 0 && dataSize == 2) + snprintf(str, 15, "%.2f ", ((SInt16)ntohs(*(UInt16*)bytes)) / 16.0); + else if (strcmp(dataType, DATATYPE_SPF0) == 0 && dataSize == 2) + snprintf(str, 15, "%.0f ", (float)ntohs(*(UInt16*)bytes)); + else if (strcmp(dataType, DATATYPE_SI16) == 0 && dataSize == 2) + snprintf(str, 15, "%d ", ntohs(*(SInt16*)bytes)); + else if (strcmp(dataType, DATATYPE_SI8) == 0 && dataSize == 1) + snprintf(str, 15, "%d ", (signed char)*bytes); + else if (strcmp(dataType, DATATYPE_PWM) == 0 && dataSize == 2) + snprintf(str, 15, "%.1f%% ", ntohs(*(UInt16*)bytes) * 100 / 65536.0); + else if (strcmp(dataType, DATATYPE_CHARSTAR) == 0) + snprintf(str, 15, "%s ", bytes); + else if (strcmp(dataType, DATATYPE_FLAG) == 0) + snprintf(str, 15, "%s ", bytes[0] ? "TRUE" : "FALSE"); + else { + int i; + char tempAb[64]; + for (i = 0; i < dataSize; i++) { + snprintf(tempAb+strlen(tempAb), 8, "%02x ", (unsigned char) bytes[i]); + } + snprintf(str, 15, "%s ", tempAb); } - snprintf(str, 15, "%s ", tempAb); - } return TRUE; } return FALSE; From d75bdc1b2905184acb6f4ea1d2bb355a20f9a3e9 Mon Sep 17 00:00:00 2001 From: Perceval F Date: Wed, 1 Apr 2015 19:05:16 +0200 Subject: [PATCH 07/11] stringRepresentationForBytes: Returns true --- SMCWrapper/SMCWrapper.m | 1 + 1 file changed, 1 insertion(+) diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index d9dd49b..a95dd64 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -448,6 +448,7 @@ -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes } *abri = [[NSString alloc] initWithFormat:@"%s", tempAb]; } + return TRUE; } else { return TRUE; } From f06f166f6aa884b4808b6979e74915b0131192c1 Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Wed, 1 Apr 2015 19:15:28 +0200 Subject: [PATCH 08/11] Raw representation for SMCVals * stringRawRepresentationForBytes:withSize:ofType:toNSString * stringRawRepresentationForBytes:withSize:ofType:inBuffer * stringRawRepresentationOfVal:inBuffer * stringRawRepresentationOfVal:toNSString Also added comments for readKey:intoVal --- SMCWrapper/SMCWrapper.h | 12 ++++++++ SMCWrapper/SMCWrapper.m | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/SMCWrapper/SMCWrapper.h b/SMCWrapper/SMCWrapper.h index 71841cc..5344f11 100644 --- a/SMCWrapper/SMCWrapper.h +++ b/SMCWrapper/SMCWrapper.h @@ -146,10 +146,22 @@ typedef enum { withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType toNSString: (NSString**)abri; +-(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes + withSize: (UInt32)dataSize + ofType: (UInt32Char_t)dataType + toNSString: (NSString**)abri; +-(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes + withSize: (UInt32)dataSize + ofType: (UInt32Char_t)dataType + inBuffer: (char *)str; -(BOOL) stringRepresentationOfVal:(SMCVal_t)val inBuffer: (char *)str; -(BOOL) stringRepresentationOfVal:(SMCVal_t)val toNSString:(NSString**)abri; +-(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val + inBuffer:(char *)str; +-(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val + toNSString:(NSString**)abri; #ifndef STRIP_COMPATIBILITY -(BOOL) getStringRepresentation: (SMCBytes_t)bytes forSize: (UInt32)dataSize diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index a95dd64..d686ca9 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -455,6 +455,50 @@ -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes return FALSE; } +/** + * stringRawRepresentationForBytes:withSize:ofType:toNSString - Retrieves a NSString raw (hex bytes) + * representation of the given values ; returns a bool to indicate success or failure. + */ +-(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes + withSize: (UInt32)dataSize + ofType: (UInt32Char_t)dataType + toNSString: (NSString**)abri +{ + if (dataSize > 0) { + int i; + char tempAb[64]; + for (i = 0; i < dataSize; i++) { + snprintf(tempAb+strlen(tempAb), 8, "%02x ", (unsigned char) bytes[i]); + } + *abri = [[NSString alloc] initWithFormat:@"%s", tempAb]; + return TRUE; + } else { + return TRUE; + } + return FALSE; +} + +/** + * stringRawRepresentationForBytes:withSize:ofType:inBuffer - Retrieves a CString raw (hex bytes) + * representation of the given values ; returns a bool to indicate success or failure. + */ +-(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes + withSize: (UInt32)dataSize + ofType: (UInt32Char_t)dataType + inBuffer: (char *)str +{ + if (dataSize > 0) { + int i; + char tempAb[64]; + for (i = 0; i < dataSize; i++) { + snprintf(tempAb+strlen(tempAb), 8, "%02x ", (unsigned char) bytes[i]); + } + snprintf(str, 15, "%s ", tempAb); + return TRUE; + } + return FALSE; +} + /** * stringRepresentationOfVal:inBuffer: - Retrieves a CString representation * of the given SMCVal_t ; returns a bool to indicate success or failure. @@ -475,6 +519,30 @@ -(BOOL) stringRepresentationOfVal:(SMCVal_t)val return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType toNSString:abri]; } +/** + * stringRawRepresentationOfVal:inBuffer: - Retrieves a NSString representation + * of the given SMCVal_t raw value (hex bytes); returns a bool to indicate success or failure. + */ +-(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val + inBuffer:(char *)str +{ + return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType inBuffer:str]; +} + +/** + * stringRawRepresentationOfVal:toNSString: - Retrieves a NSString representation + * of the given SMCVal_t raw value (hex bytes); returns a bool to indicate success or failure. + */ +-(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val + toNSString:(NSString**)abri +{ + return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType toNSString:abri]; +} + +/** + * readKey:intoVal - Wrapper for the internal _smcReadKey that fills the given SMCVal_t, + * taking a NSString (not a CString) as the key name; returns a bool to indicate success or failure. + */ -(BOOL) readKey:(NSString *)key intoVal:(SMCVal_t *)val { kern_return_t result; From 745cd42275a9f529b664a690fb5762878f416688 Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Wed, 1 Apr 2015 19:31:20 +0200 Subject: [PATCH 09/11] FAILURE_REPRESENTING_STRUCT in SMCState --- SMCWrapper/SMCWrapper.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SMCWrapper/SMCWrapper.h b/SMCWrapper/SMCWrapper.h index 5344f11..45f26f3 100644 --- a/SMCWrapper/SMCWrapper.h +++ b/SMCWrapper/SMCWrapper.h @@ -131,7 +131,8 @@ typedef enum { FAILURE_IOServiceGetMatchingServices = 1, FAILURE_NO_SMC_FOUND = 2, FAILURE_IOServiceOpen = 3, - FAILURE_CALLING_STRUCT_METHOD = 4 + FAILURE_CALLING_STRUCT_METHOD = 4, + FAILURE_REPRESENTING_STRUCT = 5 } SMCState_t; From b15417d2ce4301069aa098587af15730aa2fc621 Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Thu, 2 Apr 2015 18:46:28 +0200 Subject: [PATCH 10/11] Cleaned again, added typeOfVal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Standardised argument for NSStrings passed ‘by reference’ Added -(BOOL) typeOfVal:(SMCVal_t)val intoString:(NSString **)str; stringRep methods now properly return true/false values (made a mistake yesterday) --- SMCWrapper/SMCWrapper.h | 9 ++++--- SMCWrapper/SMCWrapper.m | 55 ++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/SMCWrapper/SMCWrapper.h b/SMCWrapper/SMCWrapper.h index 45f26f3..28794cb 100644 --- a/SMCWrapper/SMCWrapper.h +++ b/SMCWrapper/SMCWrapper.h @@ -146,11 +146,11 @@ typedef enum { -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType - toNSString: (NSString**)abri; + intoString: (NSString**)abri; -(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType - toNSString: (NSString**)abri; + intoString: (NSString**)abri; -(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType @@ -158,11 +158,11 @@ typedef enum { -(BOOL) stringRepresentationOfVal:(SMCVal_t)val inBuffer: (char *)str; -(BOOL) stringRepresentationOfVal:(SMCVal_t)val - toNSString:(NSString**)abri; + intoString:(NSString**)abri; -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val inBuffer:(char *)str; -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val - toNSString:(NSString**)abri; + intoString:(NSString**)abri; #ifndef STRIP_COMPATIBILITY -(BOOL) getStringRepresentation: (SMCBytes_t)bytes forSize: (UInt32)dataSize @@ -178,5 +178,6 @@ __deprecated_msg("Use readKey:intoString: instead."); -(BOOL) readKey:(NSString *)key intoVal:(SMCVal_t *)val; -(BOOL) readKey:(NSString *)key intoString:(NSString **)str; -(BOOL) readKey:(NSString *)key intoNumber:(NSNumber **)value; +-(BOOL) typeOfVal:(SMCVal_t)val intoString:(NSString **)str; -(void) dealloc; @end diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index d686ca9..16140cc 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -168,8 +168,8 @@ -(void) _ultostr:(char *)str * IOConnectCallStructMethod - which is responsible for IOService calls. */ -(kern_return_t) _smcCall:(int)index - forKeyData:(SMCKeyData_t *)inputStructure - toKeyData:(SMCKeyData_t *)outputStructure + forKeyData:(SMCKeyData_t *)inputStructure + toKeyData:(SMCKeyData_t *)outputStructure { size_t structureInputSize; size_t structureOutputSize; @@ -202,8 +202,8 @@ -(kern_return_t) _smcReadKey:(UInt32Char_t)key toValue:(SMCVal_t*)val inputStructure.data8 = SMC_CMD_READ_KEYINFO; result = [self _smcCall: KERNEL_INDEX_SMC - forKeyData: &inputStructure - toKeyData: &outputStructure]; + forKeyData: &inputStructure + toKeyData: &outputStructure]; if (result != kIOReturnSuccess) return result; @@ -307,7 +307,7 @@ -(SMCVal_t) createEmptyValue { -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType - inBuffer: (char *)str + inBuffer: (char *)str { if (dataSize > 0) { if ((strcmp(dataType, DATATYPE_UINT8) == 0) || @@ -378,13 +378,13 @@ -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes } /** - * stringRepresentationForBytes:withSize:ofType:toNSString - Retrieves a NSString + * stringRepresentationForBytes:withSize:ofType:intoString - Retrieves a NSString * representation of the given values ; returns a bool to indicate success or failure. */ -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType - toNSString: (NSString**)abri + intoString: (NSString**)abri { if (dataSize > 0) { if ((strcmp(dataType, DATATYPE_UINT8) == 0) || @@ -449,20 +449,18 @@ -(BOOL) stringRepresentationForBytes: (SMCBytes_t)bytes *abri = [[NSString alloc] initWithFormat:@"%s", tempAb]; } return TRUE; - } else { - return TRUE; } return FALSE; } /** - * stringRawRepresentationForBytes:withSize:ofType:toNSString - Retrieves a NSString raw (hex bytes) + * stringRawRepresentationForBytes:withSize:ofType:intoString - Retrieves a NSString raw (hex bytes) * representation of the given values ; returns a bool to indicate success or failure. */ -(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes withSize: (UInt32)dataSize ofType: (UInt32Char_t)dataType - toNSString: (NSString**)abri + intoString: (NSString**)abri { if (dataSize > 0) { int i; @@ -472,8 +470,6 @@ -(BOOL) stringRawRepresentationForBytes: (SMCBytes_t)bytes } *abri = [[NSString alloc] initWithFormat:@"%s", tempAb]; return TRUE; - } else { - return TRUE; } return FALSE; } @@ -510,13 +506,13 @@ -(BOOL) stringRepresentationOfVal:(SMCVal_t)val } /** - * stringRepresentationOfVal:toNSString: - Retrieves a NSString representation + * stringRepresentationOfVal:intoString: - Retrieves a NSString representation * of the given SMCVal_t ; returns a bool to indicate success or failure. */ -(BOOL) stringRepresentationOfVal:(SMCVal_t)val - toNSString:(NSString**)abri + intoString:(NSString**)abri { - return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType toNSString:abri]; + return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType intoString:abri]; } /** @@ -530,13 +526,26 @@ -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val } /** - * stringRawRepresentationOfVal:toNSString: - Retrieves a NSString representation + * stringRawRepresentationOfVal:intoString: - Retrieves a NSString representation * of the given SMCVal_t raw value (hex bytes); returns a bool to indicate success or failure. */ -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val - toNSString:(NSString**)abri + intoString:(NSString**)abri +{ + return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType intoString:abri]; +} + +/** + * stringRawRepresentationOfVal:intoString: - Retrieves a NSString representation + * of the given SMCVal_t raw value (hex bytes); returns a bool to indicate success or failure. + */ +-(BOOL) typeOfVal:(SMCVal_t)val intoString:(NSString **)str { - return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType toNSString:abri]; + if (val.dataType) { //check if belongs to type array + *str = [[NSString alloc] initWithCString:val.dataType encoding:NSUTF8StringEncoding]; + return TRUE; + } + return FALSE; } /** @@ -546,7 +555,7 @@ -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val -(BOOL) readKey:(NSString *)key intoVal:(SMCVal_t *)val { kern_return_t result; - result = [self _smcReadKey:[key UTF8String] toValue: val]; + result = [self _smcReadKey:(char*)[key UTF8String] toValue: val]; // Do value checking on val. if (result != kIOReturnSuccess) { return NO; @@ -564,7 +573,7 @@ -(BOOL) readKey:(NSString *)key intoString:(NSString **)str SMCVal_t val; kern_return_t result; - result = [self _smcReadKey:[key UTF8String] toValue: &val]; + result = [self _smcReadKey:(char*)[key UTF8String] toValue: &val]; // Do value checking on val. if (result != kIOReturnSuccess) { @@ -637,8 +646,8 @@ -(BOOL) dumpToValueDict:(NSMutableDictionary**)valDict andTypeDict:(NSMutableDic result = [self _smcReadKey:key toValue:&val]; //reads key (by its name, see above) stringKey = [NSString stringWithFormat:@"%s" , key]; - [self stringRepresentationOfVal:val toNSString:&valueKey]; - + [self stringRepresentationOfVal:val intoString:&valueKey]; + typeKey = [NSString stringWithFormat:@"%-4s",val.dataType]; [*valDict setObject:valueKey forKey:stringKey]; [*typeDict setObject:typeKey forKey:stringKey]; From f057f533efa428c3c35bdaf0ea08a3ab9de75905 Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Sat, 4 Apr 2015 08:32:43 +0200 Subject: [PATCH 11/11] Fixed typo in function name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was calling stringRep… instead of stringRawRep --- SMCWrapper/SMCWrapper.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SMCWrapper/SMCWrapper.m b/SMCWrapper/SMCWrapper.m index 16140cc..dfd856f 100644 --- a/SMCWrapper/SMCWrapper.m +++ b/SMCWrapper/SMCWrapper.m @@ -522,7 +522,7 @@ -(BOOL) stringRepresentationOfVal:(SMCVal_t)val -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val inBuffer:(char *)str { - return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType inBuffer:str]; + return [self stringRawRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType inBuffer:str]; } /** @@ -532,7 +532,7 @@ -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val -(BOOL) stringRawRepresentationOfVal:(SMCVal_t)val intoString:(NSString**)abri { - return [self stringRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType intoString:abri]; + return [self stringRawRepresentationForBytes:val.bytes withSize:val.dataSize ofType:val.dataType intoString:abri]; } /**