aboutsummaryrefslogtreecommitdiff
path: root/src/tcgbios.c
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2015-11-21 14:54:43 -0500
committerKevin O'Connor <kevin@koconnor.net>2015-11-22 10:12:35 -0500
commitfbc231b2e838e021f287fb5e057fab1d7b956bee (patch)
tree1db2949388df37c2dfe5bfa80abc24b3357a2d34 /src/tcgbios.c
parent60bb9e9778324f0b7cbbbc11d66ef0c59017be40 (diff)
downloadseabios-hppa-fbc231b2e838e021f287fb5e057fab1d7b956bee.zip
seabios-hppa-fbc231b2e838e021f287fb5e057fab1d7b956bee.tar.gz
seabios-hppa-fbc231b2e838e021f287fb5e057fab1d7b956bee.tar.bz2
tpm: Refactor pass_through_to_tpm
Refactor the signature of the pass_through_to_tpm function to take individual pointers as parameters and introduce pass_through_to_tpm_int as a function to be called with the parameters passed from the BIOS interrupt. Refactor existing callers that now do not have to build up the data structure expected by the BIOS interface. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'src/tcgbios.c')
-rw-r--r--src/tcgbios.c82
1 files changed, 37 insertions, 45 deletions
diff --git a/src/tcgbios.c b/src/tcgbios.c
index 018c580..7a60138 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -666,24 +666,34 @@ shutdown_preboot_interface(void)
return rc;
}
-
-static void
-tpm_shutdown(void)
+static u32
+pass_through_to_tpm(u8 locty, const u8 *cmd, u32 cmd_length,
+ u8 *resp, u32 *resp_length)
{
- reset_acpi_log();
- shutdown_preboot_interface();
-}
+ struct iovec iovec[2] = {{ 0 }};
+ const u32 *tmp;
+
+ if (cmd_length < TPM_REQ_HEADER_SIZE)
+ return TCG_INVALID_INPUT_PARA;
+
+ iovec[0].data = cmd;
+ tmp = (const u32 *)&((u8 *)iovec[0].data)[2];
+ iovec[0].length = cpu_to_be32(*tmp);
+
+ if (cmd_length != iovec[0].length)
+ return TCG_INVALID_INPUT_PARA;
+
+ return transmit(locty, iovec, resp, resp_length,
+ TPM_DURATION_TYPE_LONG /* worst case */);
+}
static u32
-pass_through_to_tpm(struct pttti *pttti, struct pttto *pttto)
+pass_through_to_tpm_int(struct pttti *pttti, struct pttto *pttto)
{
u32 rc = 0;
u32 resbuflen = 0;
struct tpm_req_header *trh;
- u8 locty = 0;
- struct iovec iovec[2];
- const u32 *tmp;
if (is_preboot_if_shutdown()) {
rc = TCG_INTERFACE_SHUTDOWN;
@@ -701,15 +711,10 @@ pass_through_to_tpm(struct pttti *pttti, struct pttto *pttto)
resbuflen = pttti->opblength - offsetof(struct pttto, tpmopout);
- iovec[0].data = pttti->tpmopin;
- tmp = (const u32 *)&((u8 *)iovec[0].data)[2];
- iovec[0].length = cpu_to_be32(*tmp);
-
- iovec[1].data = NULL;
- iovec[1].length = 0;
+ rc = pass_through_to_tpm(0, pttti->tpmopin,
+ pttti->ipblength - offsetof(struct pttti, tpmopin),
+ pttto->tpmopout, &resbuflen);
- rc = transmit(locty, iovec, pttto->tpmopout, &resbuflen,
- TPM_DURATION_TYPE_LONG /* worst case */);
if (rc)
goto err_exit;
@@ -730,35 +735,22 @@ static u32
tpm_extend(u8 *hash, u32 pcrindex)
{
u32 rc;
- struct pttto_extend pttto;
- struct pttti_extend pttti = {
- .pttti = {
- .ipblength = sizeof(struct pttti_extend),
- .opblength = sizeof(struct pttto_extend),
- },
- .req = {
- .tag = cpu_to_be16(0xc1),
- .totlen = cpu_to_be32(sizeof(pttti.req)),
- .ordinal = cpu_to_be32(TPM_ORD_Extend),
- .pcrindex = cpu_to_be32(pcrindex),
- },
+ struct tpm_req_extend tre = {
+ .tag = cpu_to_be16(TPM_TAG_RQU_CMD),
+ .totlen = cpu_to_be32(sizeof(tre)),
+ .ordinal = cpu_to_be32(TPM_ORD_Extend),
+ .pcrindex = cpu_to_be32(pcrindex),
};
+ struct tpm_rsp_extend rsp;
+ u32 resp_length = sizeof(rsp);
- memcpy(pttti.req.digest, hash, sizeof(pttti.req.digest));
-
- rc = pass_through_to_tpm(&pttti.pttti, &pttto.pttto);
+ memcpy(tre.digest, hash, sizeof(tre.digest));
- if (rc == 0) {
- if (pttto.pttto.opblength < TPM_RSP_HEADER_SIZE ||
- pttto.pttto.opblength !=
- sizeof(struct pttto) + be32_to_cpu(pttto.rsp.totlen) ||
- be16_to_cpu(pttto.rsp.tag) != 0xc4) {
- rc = TCG_FATAL_COM_ERROR;
- }
- }
+ rc = pass_through_to_tpm(0, (u8 *)&tre, sizeof(tre),
+ (u8 *)&rsp, &resp_length);
- if (rc)
- tpm_shutdown();
+ if (rc || resp_length != sizeof(rsp))
+ tpm_set_failure();
return rc;
}
@@ -1014,8 +1006,8 @@ tpm_interrupt_handler32(struct bregs *regs)
case TCG_PassThroughToTPM:
regs->eax =
- pass_through_to_tpm((struct pttti *)input_buf32(regs),
- (struct pttto *)output_buf32(regs));
+ pass_through_to_tpm_int((struct pttti *)input_buf32(regs),
+ (struct pttto *)output_buf32(regs));
break;
case TCG_ShutdownPreBootInterface: