Files
fastfetch/src/detection/tpm/tpm_windows.c
T

52 lines
1.7 KiB
C
Raw Normal View History

2024-09-25 22:55:57 +08:00
#include "tpm.h"
2026-01-06 09:48:38 +08:00
#include "common/library.h"
2024-09-25 22:55:57 +08:00
2026-03-19 15:24:55 +08:00
#include <windef.h>
2024-10-17 09:20:17 +08:00
#include <tbs.h>
#include <winerror.h>
2024-09-25 22:55:57 +08:00
2026-03-29 09:28:49 +08:00
const char* ffDetectTPM(FFTPMResult* result) {
FF_LIBRARY_LOAD_MESSAGE(tbs, "TBS" FF_LIBRARY_EXTENSION, -1)
2024-09-25 22:55:57 +08:00
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(tbs, Tbsi_GetDeviceInfo)
TPM_DEVICE_INFO deviceInfo = {};
TBS_RESULT code = ffTbsi_GetDeviceInfo(sizeof(deviceInfo), &deviceInfo);
2026-03-29 09:28:49 +08:00
if (code != TBS_SUCCESS) {
2024-10-17 09:20:17 +08:00
return code == (TBS_RESULT) TBS_E_TPM_NOT_FOUND ? "TPM device is not found" : "Tbsi_GetDeviceInfo() failed";
2026-03-29 09:28:49 +08:00
}
2024-09-25 22:55:57 +08:00
2026-03-29 09:28:49 +08:00
switch (deviceInfo.tpmVersion) {
case TPM_VERSION_12:
ffStrbufSetStatic(&result->version, "1.2");
break;
case TPM_VERSION_20:
ffStrbufSetStatic(&result->version, "2.0");
break;
default:
ffStrbufSetStatic(&result->version, "unknown");
break;
2024-09-25 22:55:57 +08:00
}
2026-03-29 09:28:49 +08:00
switch (deviceInfo.tpmInterfaceType) {
case TPM_IFTYPE_1:
ffStrbufSetF(&result->description, "I/O-port or MMIO TPM %s", result->version.chars);
break;
case TPM_IFTYPE_TRUSTZONE:
ffStrbufSetF(&result->description, "Trustzone TPM %s", result->version.chars);
break;
case TPM_IFTYPE_HW:
ffStrbufSetF(&result->description, "HW TPM %s", result->version.chars);
break;
case TPM_IFTYPE_EMULATOR:
ffStrbufSetF(&result->description, "SW-emulator TPM %s", result->version.chars);
break;
case TPM_IFTYPE_SPB:
ffStrbufSetF(&result->description, "SPB attached TPM %s", result->version.chars);
break;
default:
break;
2024-09-25 22:55:57 +08:00
}
2026-07-10 18:08:04 +08:00
return nullptr;
2024-09-25 22:55:57 +08:00
}