master ohmu/fastfetch-openbsd / src / detection / tpm / tpm_linux.c
ohmu  ·  2026-10-15
 1#include "tpm.h"
 2#include "common/debug.h"
 3#include "common/io.h"
 4
 5const char* ffDetectTPM(FFTPMResult* result) {
 6    if (!ffPathExists("/sys/class/tpm/tpm0/", FF_PATHTYPE_DIRECTORY)) {
 7        if (!ffPathExists("/sys/class/tpm/", FF_PATHTYPE_DIRECTORY)) {
 8            FF_DEBUG("/sys/class/tpm/ does not exist, the kernel has no TPM support");
 9            return "TPM is not supported by kernel";
10        }
11        FF_DEBUG("/sys/class/tpm/ exists but /sys/class/tpm/tpm0/ does not");
12        return "TPM device is not found";
13    }
14
15    if (ffReadFileBuffer("/sys/class/tpm/tpm0/tpm_version_major", &result->version)) {
16        ffStrbufTrimRightSpace(&result->version);
17        if (ffStrbufEqualS(&result->version, "2")) {
18            ffStrbufSetStatic(&result->version, "2.0");
19        }
20    }
21
22    if (ffReadFileBuffer("/sys/class/tpm/tpm0/device/description", &result->description)) {
23        ffStrbufTrimRightSpace(&result->description);
24    }
25
26    return nullptr;
27}