ohmu
·
2026-10-15
1#include "tpm.h"
2#include "common/library.h"
3
4#include <windef.h>
5#include <tbs.h>
6#include <winerror.h>
7
8const char* ffDetectTPM(FFTPMResult* result) {
9 FF_LIBRARY_LOAD_MESSAGE(tbs, "TBS" FF_LIBRARY_EXTENSION, -1)
10 FF_LIBRARY_LOAD_SYMBOL_MESSAGE(tbs, Tbsi_GetDeviceInfo)
11
12 TPM_DEVICE_INFO deviceInfo = {};
13 TBS_RESULT code = ffTbsi_GetDeviceInfo(sizeof(deviceInfo), &deviceInfo);
14 if (code != TBS_SUCCESS) {
15 return code == (TBS_RESULT) TBS_E_TPM_NOT_FOUND ? "TPM device is not found" : "Tbsi_GetDeviceInfo() failed";
16 }
17
18 switch (deviceInfo.tpmVersion) {
19 case TPM_VERSION_12:
20 ffStrbufSetStatic(&result->version, "1.2");
21 break;
22 case TPM_VERSION_20:
23 ffStrbufSetStatic(&result->version, "2.0");
24 break;
25 default:
26 ffStrbufSetStatic(&result->version, "unknown");
27 break;
28 }
29
30 switch (deviceInfo.tpmInterfaceType) {
31 case TPM_IFTYPE_1:
32 ffStrbufSetF(&result->description, "I/O-port or MMIO TPM %s", result->version.chars);
33 break;
34 case TPM_IFTYPE_TRUSTZONE:
35 ffStrbufSetF(&result->description, "Trustzone TPM %s", result->version.chars);
36 break;
37 case TPM_IFTYPE_HW:
38 ffStrbufSetF(&result->description, "HW TPM %s", result->version.chars);
39 break;
40 case TPM_IFTYPE_EMULATOR:
41 ffStrbufSetF(&result->description, "SW-emulator TPM %s", result->version.chars);
42 break;
43 case TPM_IFTYPE_SPB:
44 ffStrbufSetF(&result->description, "SPB attached TPM %s", result->version.chars);
45 break;
46 default:
47 break;
48 }
49
50 return nullptr;
51}