From 2a77e0389598adf98783d16ff7f92013c190f27e Mon Sep 17 00:00:00 2001 From: Andrey Pronin Date: Fri, 11 Nov 2016 19:49:50 -0800 Subject: tpmc: add 'tpmversion' command Add command for printing TPM version: 1.2 or 2.0. The command works even when trunksd/tcsd is running and /dev/tpm0 is busy, so it can be used to first determine which TPM we are dealing with, and then select the right name of the daemon to stop based on that. BUG=none BRANCH=none TEST=run 'tpmc tpmver' Change-Id: Ib8db81ff2af6dc6b0d5aecf30e2688a908b5c3d3 Reviewed-on: https://chromium-review.googlesource.com/410703 Commit-Ready: Andrey Pronin Tested-by: Andrey Pronin Reviewed-by: Vadim Bendebury --- utility/tpmc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utility/tpmc.c b/utility/tpmc.c index baddee65..1e4e3026 100644 --- a/utility/tpmc.c +++ b/utility/tpmc.c @@ -129,6 +129,11 @@ uint8_t ErrorCheck(uint32_t result, const char* cmd) { /* Handler functions. These wouldn't exist if C had closures. */ +static uint32_t HandlerTpmVersion(void) { + puts(TPM_MODE_STRING); + return 0; +} + /* TODO(apronin): stub for selected flags for TPM2 */ #ifdef TPM2_MODE static uint32_t HandlerGetFlags(void) { @@ -465,6 +470,8 @@ static uint32_t HandlerNotImplementedForTPM2(void) { /* Table of TPM commands. */ command_record command_table[] = { + { "tpmversion", "tpmver", "print TPM version: 1.2 or 2.0", + HandlerTpmVersion }, { "getflags", "getf", "read and print the value of selected flags", HandlerGetFlags }, { "startup", "sta", "issue a Startup command", TlclStartup }, @@ -559,6 +566,9 @@ int main(int argc, char* argv[]) { } return 0; } + if (!strcmp(cmd, "tpmversion") || !strcmp(cmd, "tpmver")) { + return HandlerTpmVersion(); + } result = TlclLibInit(); if (result) { -- cgit v1.2.1