1 /* 2 * The Initial Developer of the Original Code is International 3 * Business Machines Corporation. Portions created by IBM 4 * Corporation are Copyright (C) 2005 International Business 5 * Machines Corporation. All Rights Reserved. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the Common Public License as published by 9 * IBM Corporation; either version 1 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * Common Public License for more details. 16 * 17 * You should have received a copy of the Common Public License 18 * along with this program; if not, a copy can be viewed at 19 * http://www.opensource.org/licenses/cpl1.0.php. 20 */ 21 #include <sys/types.h> 22 #include <netinet/in.h> 23 #include <stdlib.h> //for def. exit 24 #include "tpm_tspi.h" 25 26 27 TSS_HCONTEXT hContext = 0; 28 29 int cmdVersion(const char *a_szCmd) 30 { 31 TSS_HTPM hTpm; 32 UINT32 uiSubCap; 33 BYTE *pSubCap; 34 UINT32 uiResultLen; 35 BYTE *pResult; 36 int iRc = -1; 37 38 if (contextCreate(&hContext) != TSS_SUCCESS) 39 goto out; 40 41 if (contextConnect(hContext) != TSS_SUCCESS) 42 goto out_close; 43 44 if (contextGetTpm(hContext, &hTpm) != TSS_SUCCESS) 45 goto out_close; 46 47 #ifdef TSS_LIB_IS_12 48 { 49 UINT64 offset; 50 TSS_RESULT uiResult; 51 TPM_CAP_VERSION_INFO versionInfo; 52 int tmpLogLevel = iLogLevel; 53 54 /* disable logging during this call. If we're on a 1.1 TPM, it'd throw an error */ 55 iLogLevel = LOG_LEVEL_NONE; 56 57 if ((uiResult = getCapability(hTpm, TSS_TPMCAP_VERSION_VAL, 0, NULL, &uiResultLen, 58 &pResult)) != TSS_SUCCESS) { 59 iLogLevel = tmpLogLevel; 60 if (uiResult == TPM_E_BAD_MODE) 61 goto print_cap_version; 62 else 63 goto out_close; 64 } 65 iLogLevel = tmpLogLevel; 66 67 offset = 0; 68 if ((uiResult = unloadVersionInfo(&offset, pResult, &versionInfo))) { 69 goto out_close; 70 } 71 72 logMsg(_(" TPM 1.2 Version Info:\n")); 73 logMsg(_(" Chip Version: %hhu.%hhu.%hhu.%hhu\n"), 74 versionInfo.version.major, versionInfo.version.minor, 75 versionInfo.version.revMajor, versionInfo.version.revMinor); 76 logMsg(_(" Spec Level: %hu\n"), versionInfo.specLevel); 77 logMsg(_(" Errata Revision: %hhu\n"), versionInfo.errataRev); 78 logMsg(_(" TPM Vendor ID: %c%c%c%c\n"), 79 versionInfo.tpmVendorID[0], versionInfo.tpmVendorID[1], 80 versionInfo.tpmVendorID[2], versionInfo.tpmVendorID[3]); 81 82 if (versionInfo.vendorSpecificSize) { 83 logMsg(_(" Vendor Specific data: ")); 84 logHex(versionInfo.vendorSpecificSize, versionInfo.vendorSpecific); 85 86 free(versionInfo.vendorSpecific); 87 } 88 } 89 90 print_cap_version: 91 #endif 92 if (getCapability(hTpm, TSS_TPMCAP_VERSION, 0, NULL, &uiResultLen, 93 &pResult) != TSS_SUCCESS) 94 goto out_close; 95 logMsg(_(" TPM Version: ")); 96 logHex(uiResultLen, pResult); 97 98 uiSubCap = TSS_TPMCAP_PROP_MANUFACTURER; 99 pSubCap = (BYTE *) & uiSubCap; 100 if (getCapability(hTpm, TSS_TPMCAP_PROPERTY, sizeof(uiSubCap), 101 pSubCap, &uiResultLen, &pResult) != TSS_SUCCESS) 102 goto out_close; 103 logMsg(_(" Manufacturer Info: ")); 104 logHex(uiResultLen, pResult); 105 106 iRc = 0; 107 logSuccess(a_szCmd); 108 109 out_close: 110 contextClose(hContext); 111 112 out: 113 return iRc; 114 } 115 116 117 int main(int argc, char *argv[]) 118 { 119 int rc; 120 121 initIntlSys(); 122 123 rc = genericOptHandler(argc, argv, "", NULL, 0, NULL, NULL); 124 if (rc) 125 exit(0); 126 127 rc = cmdVersion(argv[0]); 128 129 return rc; 130 } 131