aboutsummaryrefslogtreecommitdiff
path: root/src/tcgbios.c
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2015-11-12 10:14:46 -0500
committerKevin O'Connor <kevin@koconnor.net>2015-11-19 08:53:15 -0500
commitece25610aa69c0a3bc0b17cb934b7a9d95add060 (patch)
tree8731a4a655875e22918840a8d5c234f74510de45 /src/tcgbios.c
parent7fce1d9661b29e3dab05b862e95c6cd35d822536 (diff)
downloadseabios-hppa-ece25610aa69c0a3bc0b17cb934b7a9d95add060.zip
seabios-hppa-ece25610aa69c0a3bc0b17cb934b7a9d95add060.tar.gz
seabios-hppa-ece25610aa69c0a3bc0b17cb934b7a9d95add060.tar.bz2
tpm: Refactor function building TPM commands
Refactor the function building TPM commands to get rid of one of the buffers it uses for building a command. To do that, have it use the iovec also for the 'append' array that's being passed to the function. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'src/tcgbios.c')
-rw-r--r--src/tcgbios.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/tcgbios.c b/src/tcgbios.c
index 2f69318..3e9560b 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -330,47 +330,40 @@ build_and_send_cmd_od(u8 locty, u32 ordinal, const u8 *append, u32 append_size,
const u8 *otherdata, u32 otherdata_size,
enum tpmDurationType to_t)
{
-#define MAX_APPEND_SIZE sizeof(GetCapability_Timeouts)
-#define MAX_RESPONSE_SIZE sizeof(struct tpm_res_getcap_perm_flags)
u32 rc;
- u8 ibuffer[TPM_REQ_HEADER_SIZE + MAX_APPEND_SIZE];
- u8 obuffer[MAX_RESPONSE_SIZE];
- struct tpm_req_header *trqh = (struct tpm_req_header *)ibuffer;
+ u8 obuffer[64];
+ struct tpm_req_header trqh;
struct tpm_rsp_header *trsh = (struct tpm_rsp_header *)obuffer;
- struct iovec iovec[3];
+ struct iovec iovec[4] = {{ 0 }};
u32 obuffer_len = sizeof(obuffer);
u32 idx = 1;
- if (append_size > MAX_APPEND_SIZE ||
- return_size > MAX_RESPONSE_SIZE) {
- dprintf(DEBUG_tcg, "TCGBIOS: size of requested buffers too big.");
+ if (return_size > sizeof(obuffer)) {
+ dprintf(DEBUG_tcg, "TCGBIOS: size of requested response too big.");
return TCG_FIRMWARE_ERROR;
}
- iovec[0].data = trqh;
- iovec[0].length = TPM_REQ_HEADER_SIZE + append_size;
+ trqh.tag = cpu_to_be16(TPM_TAG_RQU_CMD);
+ trqh.totlen = cpu_to_be32(TPM_REQ_HEADER_SIZE + append_size +
+ otherdata_size);
+ trqh.ordinal = cpu_to_be32(ordinal);
- if (otherdata) {
- iovec[1].data = (void *)otherdata;
- iovec[1].length = otherdata_size;
+ iovec[0].data = &trqh;
+ iovec[0].length = TPM_REQ_HEADER_SIZE;
+
+ if (append_size) {
+ iovec[1].data = append;
+ iovec[1].length = append_size;
idx = 2;
}
- iovec[idx].data = NULL;
- iovec[idx].length = 0;
+ if (otherdata) {
+ iovec[idx].data = (void *)otherdata;
+ iovec[idx].length = otherdata_size;
+ }
- memset(ibuffer, 0x0, sizeof(ibuffer));
memset(obuffer, 0x0, sizeof(obuffer));
- trqh->tag = cpu_to_be16(TPM_TAG_RQU_CMD);
- trqh->totlen = cpu_to_be32(TPM_REQ_HEADER_SIZE + append_size +
- otherdata_size);
- trqh->ordinal = cpu_to_be32(ordinal);
-
- if (append_size)
- memcpy((char *)trqh + sizeof(*trqh),
- append, append_size);
-
rc = transmit(locty, iovec, obuffer, &obuffer_len, to_t);
if (rc)
return rc;