TPM: update description

This commit is contained in:
李通洲
2024-09-26 09:53:00 +08:00
committed by 李通洲
parent f496e6d965
commit 87f2e69162
4 changed files with 30 additions and 25 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
typedef struct FFTPMResult
{
FFstrbuf version;
FFstrbuf interfaceType;
FFstrbuf description;
} FFTPMResult;
const char* ffDetectTPM(FFTPMResult* result);
+11 -9
View File
@@ -1,22 +1,24 @@
#include "tpm.h"
#include "common/io/io.h"
const char* ffDetectTPM(FF_MAYBE_UNUSED FFTPMResult* result)
const char* ffDetectTPM(FFTPMResult* result)
{
if (!ffPathExists("/sys/class/tpm/tpm0", FF_PATHTYPE_DIRECTORY))
{
if (!ffPathExists("/sys/class/tpm", FF_PATHTYPE_DIRECTORY))
return "TPM is not supported by kernel";
return "TPM device is not found";
}
if (ffReadFileBuffer("/sys/class/tpm/tpm0/tpm_version_major", &result->version))
{
ffStrbufTrimRightSpace(&result->version);
if (ffStrbufEqualS(&result->version, "2"))
ffStrbufSetStatic(&result->version, "2.0");
return NULL;
}
if (ffPathExists("/sys/class/tpm/tpm0", FF_PATHTYPE_DIRECTORY))
{
ffStrbufSetStatic(&result->version, "unknown");
return NULL;
}
if (ffReadFileBuffer("/sys/class/tpm/tpm0/device/description", &result->description))
ffStrbufTrimRightSpace(&result->description);
return "TPM device is not found";
return NULL;
}
+5 -5
View File
@@ -60,19 +60,19 @@ const char* ffDetectTPM(FFTPMResult* result)
switch (deviceInfo.tpmInterfaceType)
{
case TPM_IFTYPE_1:
ffStrbufSetStatic(&result->interfaceType, "I/O-port or MMIO");
ffStrbufSetF(&result->description, "I/O-port or MMIO TPM %s", result->version.chars);
break;
case TPM_IFTYPE_TRUSTZONE:
ffStrbufSetStatic(&result->interfaceType, "Trustzone");
ffStrbufSetF(&result->description, "Trustzone TPM %s", result->version.chars);
break;
case TPM_IFTYPE_HW:
ffStrbufSetStatic(&result->interfaceType, "HW TPM");
ffStrbufSetF(&result->description, "HW TPM %s", result->version.chars);
break;
case TPM_IFTYPE_EMULATOR:
ffStrbufSetStatic(&result->interfaceType, "SW-emulator");
ffStrbufSetF(&result->description, "SW-emulator TPM %s", result->version.chars);
break;
case TPM_IFTYPE_SPB:
ffStrbufSetStatic(&result->interfaceType, "SPB attached");
ffStrbufSetF(&result->description, "SPB attached TPM %s", result->version.chars);
break;
default:
break;
+13 -10
View File
@@ -10,7 +10,7 @@ void ffPrintTPM(FFTPMOptions* options)
{
FFTPMResult result = {
.version = ffStrbufCreate(),
.interfaceType = ffStrbufCreate()
.description = ffStrbufCreate()
};
const char* error = ffDetectTPM(&result);
@@ -23,18 +23,21 @@ void ffPrintTPM(FFTPMOptions* options)
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_TPM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufPutTo(&result.version, stdout);
if (result.description.length > 0)
ffStrbufPutTo(&result.description, stdout);
else
ffStrbufPutTo(&result.version, stdout);
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_TPM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TPM_NUM_FORMAT_ARGS, ((FFformatarg[]){
FF_FORMAT_ARG(result.version, "version"),
FF_FORMAT_ARG(result.interfaceType, "interface-type"),
FF_FORMAT_ARG(result.description, "description"),
}));
}
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.interfaceType);
ffStrbufDestroy(&result.description);
}
bool ffParseTPMCommandOptions(FFTPMOptions* options, const char* key, const char* value)
@@ -76,7 +79,7 @@ void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_
{
FFTPMResult result = {
.version = ffStrbufCreate(),
.interfaceType = ffStrbufCreate()
.description = ffStrbufCreate()
};
const char* error = ffDetectTPM(&result);
@@ -88,17 +91,17 @@ void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
yyjson_mut_obj_add_strbuf(doc, obj, "interfaceType", &result.interfaceType);
yyjson_mut_obj_add_strbuf(doc, obj, "description", &result.description);
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.interfaceType);
ffStrbufDestroy(&result.description);
}
void ffPrintTPMHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TPM_MODULE_NAME, "{1} [{2}]", FF_TPM_NUM_FORMAT_ARGS, ((const char* []) {
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TPM_MODULE_NAME, "{2}", FF_TPM_NUM_FORMAT_ARGS, ((const char* []) {
"TPM device version - version",
"TPM interface type - interface-type",
"TPM general description - description",
}));
}
@@ -115,7 +118,7 @@ void ffInitTPMOptions(FFTPMOptions* options)
ffPrintTPMHelpFormat,
ffGenerateTPMJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "󰔎");
ffOptionInitModuleArg(&options->moduleArgs, "");
}
void ffDestroyTPMOptions(FFTPMOptions* options)