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>
This commit is contained in:
Amarnath Valluri 2017-09-29 14:10:19 +03:00 committed by Stefan Berger
parent d0c519bdff
commit 4a3d80980e
3 changed files with 34 additions and 59 deletions

View file

@ -23,6 +23,31 @@
#include "tpm_util.h"
#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.