aboutsummaryrefslogtreecommitdiff
path: root/hw/tpm/tpm_util.c
diff options
context:
space:
mode:
authorAmarnath Valluri <amarnath.valluri@intel.com>2017-09-29 14:10:19 +0300
committerStefan Berger <stefanb@linux.vnet.ibm.com>2017-10-13 07:34:33 -0400
commit4a3d80980ebf71d8faf9d0ce2e2e23bdda5728df (patch)
tree8f6ae0639592b55879c5748adb78eb3fbff138a2 /hw/tpm/tpm_util.c
parentd0c519bdffa303d141727369e55b157c45b03147 (diff)
tpm-passthrough: move reusable code to utils
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'hw/tpm/tpm_util.c')
-rw-r--r--hw/tpm/tpm_util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
index 44842075b9..73d77965fd 100644
--- a/hw/tpm/tpm_util.c
+++ b/hw/tpm/tpm_util.c
@@ -24,6 +24,31 @@
#include "tpm_int.h"
/*
+ * Write an error message in the given output buffer.
+ */
+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len)
+{
+ if (out_len >= sizeof(struct tpm_resp_hdr)) {
+ struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;
+
+ resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);
+ resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));
+ resp->errcode = cpu_to_be32(TPM_FAIL);
+ }
+}
+
+bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len)
+{
+ struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;
+
+ if (in_len >= sizeof(*hdr)) {
+ return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest);
+ }
+
+ return false;
+}
+
+/*
* A basic test of a TPM device. We expect a well formatted response header
* (error response is fine) within one second.
*/