]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Refactor function building TPM commands
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Thu, 12 Nov 2015 15:14:46 +0000 (10:14 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 19 Nov 2015 13:53:15 +0000 (08:53 -0500)
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>
src/tcgbios.c
src/tcgbios.h

index 2f6931893eb62dac4e49fc0db9ac7522e5411242..3e9560b9673fe8ba3518d82d5975c5592c7341f6 100644 (file)
@@ -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;
index b0c20ad8111c47bf17b98368c8e655d2fd34e3ea..2b0b65dbfeaf2f89bc3c9fb6a0112951f603d76a 100644 (file)
@@ -108,7 +108,7 @@ enum irq_ids {
 struct iovec
 {
     size_t length;
-    void   *data;
+    const void *data;
 };