All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 15/19] tpm: add TPM2_GetCapability command support
Date: Thu, 29 Mar 2018 09:43:57 +0200	[thread overview]
Message-ID: <20180329074401.8691-16-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20180329074401.8691-1-miquel.raynal@bootlin.com>

Add support for the TPM2_GetCapability command.

Change the command file and the help accordingly.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 cmd/tpm.c     | 31 ++++++++++++++++++++-----------
 include/tpm.h | 14 +++++++-------
 lib/tpm.c     | 39 +++++++++++++++++++++++++++++++++++++--
 3 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/cmd/tpm.c b/cmd/tpm.c
index 6ee72b3032..eab914ce5f 100644
--- a/cmd/tpm.c
+++ b/cmd/tpm.c
@@ -433,21 +433,30 @@ static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t cap_area, sub_cap, rc;
-	void *cap;
+	u32 capability, property, rc;
+	u8 *data;
 	size_t count;
+	int i, j;
 
 	if (argc != 5)
 		return CMD_RET_USAGE;
-	cap_area = simple_strtoul(argv[1], NULL, 0);
-	sub_cap = simple_strtoul(argv[2], NULL, 0);
-	cap = (void *)simple_strtoul(argv[3], NULL, 0);
+	capability = simple_strtoul(argv[1], NULL, 0);
+	property = simple_strtoul(argv[2], NULL, 0);
+	data = (void *)simple_strtoul(argv[3], NULL, 0);
 	count = simple_strtoul(argv[4], NULL, 0);
 
-	rc = tpm_get_capability(cap_area, sub_cap, cap, count);
+	rc = tpm_get_capability(capability, property, data, count);
 	if (!rc) {
-		puts("capability information:\n");
-		print_byte_string(cap, count);
+		printf("Capabilities read from TPM:\n");
+		for (i = 0; i < count; i++) {
+			printf("Property 0x");
+			for (j = 0; j < 4; j++)
+				printf("%02x", data[(i * 8) + j]);
+			printf(": 0x");
+			for (j = 4; j < 8; j++)
+				printf("%02x", data[(i * 8) + j]);
+			printf("\n");
+		}
 	}
 
 	return report_return_code(rc);
@@ -998,9 +1007,9 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
 "  tsc_physical_presence flags\n"
 "    - Set TPM device's Physical Presence flags to <flags>.\n"
 "The Capability Commands:\n"
-"  get_capability cap_area sub_cap addr count\n"
-"    - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
-"      <sub_cap> to memory address <addr>.\n"
+"  get_capability <cap_area|capability> <sub_cap|property> <addr> <count>\n"
+"    - Read <count> bytes of TPM capability indexed by <cap_area|capability>\n"
+"      and <sub_cap|property> to memory address <addr>.\n"
 #if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
 "Resource management functions\n"
 #endif
diff --git a/include/tpm.h b/include/tpm.h
index 2df2ea3c5b..369119fc1b 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -628,17 +628,17 @@ uint32_t tpm_physical_set_deactivated(uint8_t state);
 
 /**
  * Issue a TPM_GetCapability command.  This implementation is limited
- * to query sub_cap index that is 4-byte wide.
+ * to query property index that is 4-byte wide.
  *
- * @param cap_area	partition of capabilities
- * @param sub_cap	further definition of capability, which is
+ * @param capability	partition of capabilities
+ * @param property	further definition of capability, which is
  *			limited to be 4-byte wide
- * @param cap		output buffer for capability information
- * @param count		size of ouput buffer
+ * @param buf		output buffer for capability information
+ * @param propertycount size of output buffer
  * @return return code of the operation
  */
-uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
-		void *cap, size_t count);
+int tpm_get_capability(u32 capability, u32 property, void *buf,
+		       size_t property_count);
 
 /**
  * Issue a TPM_FlushSpecific command for a AUTH ressource.
diff --git a/lib/tpm.c b/lib/tpm.c
index 589f9c1004..f15611ee92 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -789,8 +789,7 @@ uint32_t tpm_physical_set_deactivated(uint8_t state)
 	return tpm_sendrecv_command(buf, NULL, NULL);
 }
 
-uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
-		void *cap, size_t count)
+int tpm1_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count)
 {
 	const uint8_t command[22] = {
 		0x0, 0xc1,		/* TPM_TAG */
@@ -829,6 +828,42 @@ uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
 	return 0;
 }
 
+int tpm2_get_capability(u32 capability, u32 property, void *buf,
+			size_t property_count)
+{
+	u8 command_v2[COMMAND_BUFFER_SIZE] = {
+		U16_TO_ARRAY(TPM2_ST_NO_SESSIONS),	/* TAG */
+		U32_TO_ARRAY(22),			/* Length */
+		U32_TO_ARRAY(TPM2_CC_GET_CAPABILITY),	/* Command code */
+
+		U32_TO_ARRAY(capability),		/* Capability */
+		U32_TO_ARRAY(property),			/* Property */
+		U32_TO_ARRAY(property_count),		/* Property count */
+	};
+	u8 response[COMMAND_BUFFER_SIZE];
+	size_t response_len = COMMAND_BUFFER_SIZE;
+	int ret;
+
+	ret = tpm_sendrecv_command(command_v2, response, &response_len);
+	if (ret)
+		return ret;
+
+	memcpy(buf, &response[19], response_len - 19);
+
+	return 0;
+}
+
+int tpm_get_capability(u32 capability, u32 property, void *buf,
+		       size_t property_count)
+{
+	if (!is_tpmv2)
+		return tpm1_get_capability(capability, property, buf,
+					   property_count);
+	else
+		return tpm2_get_capability(capability, property, buf,
+					   property_count);
+}
+
 uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags)
 {
 	const uint8_t command[22] = {
-- 
2.14.1

  parent reply	other threads:[~2018-03-29  7:43 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29  7:43 [U-Boot] [PATCH v2 00/19] Introduce SPI TPM v2.0 support Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 01/19] tpm: add Revision ID field in the chip structure Miquel Raynal
2018-03-29 22:41   ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 02/19] tpm: rename tpm_tis_infineon in tpm_tis_infineon_i2c Miquel Raynal
2018-03-29 22:41   ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 03/19] tpm: add support for TPMv2 SPI modules Miquel Raynal
2018-03-29 22:41   ` Simon Glass
2018-04-24 13:02     ` Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 04/19] tpm: fix indentation in command list before adding more Miquel Raynal
2018-03-29 22:41   ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 05/19] tpm: prepare support for TPMv2 commands Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 06/19] tpm: add macros " Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 07/19] tpm: add possible traces to analyze buffers returned by the TPM Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-04-28 12:27     ` Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 08/19] tpm: handle different buffer sizes Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 09/19] tpm: add TPM2_Startup command support Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-04-27 13:45     ` Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 10/19] tpm: add TPM2_SelfTest " Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-04-24 12:53     ` Miquel Raynal
2018-04-26 14:40       ` Simon Glass
2018-04-28 13:10         ` Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 11/19] tpm: add TPM2_Clear " Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-04-24 13:17     ` Miquel Raynal
2018-04-26 14:40       ` Simon Glass
2018-04-27 13:39         ` Miquel Raynal
2018-05-03 19:01           ` Simon Glass
2018-03-29  7:43 ` [U-Boot] [PATCH v2 12/19] tpm: rename the _extend() function to be _pcr_event() Miquel Raynal
2018-03-29  9:44   ` Reinhard Pfau
2018-03-29  9:46     ` Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 13/19] tpm: add TPM2_PCR_Extend command support Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 14/19] tpm: add TPM2_PCR_Read " Miquel Raynal
2018-03-29  7:43 ` Miquel Raynal [this message]
2018-03-29  7:43 ` [U-Boot] [PATCH v2 16/19] tpm: add dictionary attack mitigation commands support Miquel Raynal
2018-03-29  7:43 ` [U-Boot] [PATCH v2 17/19] tpm: add TPM2_HierarchyChangeAuth command support Miquel Raynal
2018-03-29  7:44 ` [U-Boot] [PATCH v2 18/19] tpm: add PCR authentication commands support Miquel Raynal
2018-03-29 22:42   ` Simon Glass
2018-03-29  7:44 ` [U-Boot] [PATCH v2 19/19] test/py: add TPMv2.0 test suite Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180329074401.8691-16-miquel.raynal@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.