From 2a7e9b84ac69c374112a13fd16fbf7cb996b78bf Mon Sep 17 00:00:00 2001 From: Mattias Nissler Date: Mon, 10 Jul 2017 13:46:20 +0200 Subject: Implement tpmc getversion command. This command exposes the vendor and TPM firmware version. BRANCH=none BUG=chromium:728130 TEST=Builds and tpmc getversion prints plausible results. Change-Id: Iec556a298e025e10bda00121b40a25d8dc3839d1 Reviewed-on: https://chromium-review.googlesource.com/565287 Commit-Ready: Mattias Nissler Tested-by: Mattias Nissler Reviewed-by: Jorge Lucangeli Obes Reviewed-by: Andrey Pronin --- utility/tlcl_generator.c | 16 ++++++++++++++++ utility/tpmc.c | 14 ++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'utility') diff --git a/utility/tlcl_generator.c b/utility/tlcl_generator.c index 7ed1d6c3..70ce5fd9 100644 --- a/utility/tlcl_generator.c +++ b/utility/tlcl_generator.c @@ -389,6 +389,21 @@ Command* BuildGetRandomCommand(void) { return cmd; } +Command* BuildGetVersionValCommand(void) { + int size = (kTpmRequestHeaderLength + + sizeof(TPM_CAPABILITY_AREA) + /* capArea */ + sizeof(uint32_t)); /* subCapSize */ + + Command* cmd = newCommand(TPM_ORD_GetCapability, size); + cmd->name = "tpm_getversionval_cmd"; + AddInitializedField(cmd, kTpmRequestHeaderLength, + sizeof(TPM_CAPABILITY_AREA), TPM_CAP_GET_VERSION_VAL); + AddInitializedField(cmd, kTpmRequestHeaderLength + + sizeof(TPM_CAPABILITY_AREA), + sizeof(uint32_t), 0); + return cmd; +} + /* Output the fields of a structure. */ void OutputFields(Field* fld) { @@ -510,6 +525,7 @@ Command* (*builders[])(void) = { BuildGetOwnershipCommand, BuildGetRandomCommand, BuildExtendCommand, + BuildGetVersionValCommand, }; static void FreeFields(Field* fld) { diff --git a/utility/tpmc.c b/utility/tpmc.c index 1e4e3026..ae45ca1c 100644 --- a/utility/tpmc.c +++ b/utility/tpmc.c @@ -9,6 +9,7 @@ * for other errors. */ +#include #include #include #include @@ -456,6 +457,17 @@ static uint32_t HandlerSendRaw(void) { return result; } +static uint32_t HandlerGetVersion(void) { + uint32_t vendor; + uint64_t firmware_version; + uint32_t result = TlclGetVersion(&vendor, &firmware_version); + if (result == 0) { + printf("vendor %08x\nfirmware_version %016" PRIx64 "\n", + vendor, firmware_version); + } + return result; +} + #ifdef TPM2_MODE static uint32_t HandlerDoNothingForTPM2(void) { return 0; @@ -534,6 +546,8 @@ command_record command_table[] = { { "savestate", "save", "execute TPM_SaveState", TlclSaveState }, { "sendraw", "raw", "send a raw request and print raw response", HandlerSendRaw }, + { "getversion", "getver", "get TPM vendor and firmware version", + HandlerGetVersion }, }; static int n_commands = sizeof(command_table) / sizeof(command_table[0]); -- cgit v1.2.1