tlcl: support sending raw commands
authorAndrey Pronin <apronin@google.com>
Mon, 25 Jul 2016 23:28:39 +0000 (16:28 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Wed, 27 Jul 2016 06:54:31 +0000 (23:54 -0700)
Implement TlclSendReceive and TlclPacketSize required
for sending raw commands.

BRANCH=none
BUG=chrome-os-partner:55210
TEST=boot on kevin, verify that 'tpmc raw' works

Change-Id: Iba41b95dd7790a6b7a3a7af6cf5f897f45dce1e5
Reviewed-on: https://chromium-review.googlesource.com/363033
Commit-Ready: Andrey Pronin <apronin@chromium.org>
Tested-by: Andrey Pronin <apronin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
firmware/include/tpm2_marshaling.h
firmware/lib/tpm2_lite/marshaling.c
firmware/lib/tpm2_lite/tlcl.c

index 3d6fb8a..cbfded1 100644 (file)
@@ -47,6 +47,24 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
                                             int response_size);
 
 /**
+ * tpm_get_packet_size
+ *
+ * @packet: pointer to the start of the command or response packet.
+ *
+ * Returns the size of the tpm packet.
+ */
+uint32_t tpm_get_packet_size(const uint8_t *packet);
+
+/**
+ * tpm_get_packet_response_code
+ *
+ * @packet: pointer to the start of the response packet.
+ *
+ * Returns the response code.
+ */
+uint32_t tpm_get_packet_response_code(const uint8_t *packet);
+
+/**
  * tpm_set_ph_disabled
  *
  * Sets the flag that indicates if platform hierarchy is disabled.
index 037e696..fd94a51 100644 (file)
@@ -516,6 +516,23 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
        return &tpm2_resp;
 }
 
+uint32_t tpm_get_packet_size(const uint8_t *packet)
+{
+       /* 0: tag (16 bit)
+        * 2: size (32 bit)
+        */
+       return read_be32(packet + 2);
+}
+
+uint32_t tpm_get_packet_response_code(const uint8_t *packet)
+{
+       /* 0: tag (16 bit)
+        * 2: size (32 bit)
+        * 6: resp code (32 bit)
+        */
+       return read_be32(packet + 6);
+}
+
 void tpm_set_ph_disabled(int flag)
 {
        ph_disabled = flag;
index efc528d..d7d853b 100644 (file)
@@ -82,14 +82,18 @@ uint32_t TlclLibClose(void)
 uint32_t TlclSendReceive(const uint8_t *request, uint8_t *response,
                          int max_length)
 {
-        VBDEBUG(("%s called, NOT YET IMPLEMENTED\n", __func__));
-        return TPM_SUCCESS;
+       uint32_t rv, resp_size;
+
+       resp_size = max_length;
+       rv = VbExTpmSendReceive(request, tpm_get_packet_size(request),
+                               response, &resp_size);
+
+       return rv ? rv : tpm_get_packet_response_code(response);
 }
 
 int TlclPacketSize(const uint8_t *packet)
 {
-        VBDEBUG(("%s called, NOT YET IMPLEMENTED\n", __func__));
-        return 0;
+       return tpm_get_packet_size(packet);
 }
 
 uint32_t TlclStartup(void)