]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Avoid macro expansion of tpm request / response structs
authorKevin O'Connor <kevin@koconnor.net>
Sat, 28 Nov 2015 13:08:57 +0000 (08:08 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 29 Dec 2015 17:21:17 +0000 (12:21 -0500)
Avoid macros and use regular struct definitions for the request and
response headers.  This simplifies the header and reduces the need for
casts in the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/std/tcg.h
src/tcgbios.c

index d7b3fc498f55f579eb20dc29cd41b0ed13569ad5..70daa41e6fe2ea040d131bea28ca039678abce0b 100644 (file)
@@ -227,41 +227,35 @@ struct pcctes_romex
 } PACKED;
 
 
-#define TPM_REQ_HEADER \
-    u16    tag; \
-    u32    totlen; \
-    u32    ordinal;
-
-#define TPM_RSP_HEADER \
-    u16    tag; \
-    u32    totlen; \
-    u32    errcode;
-
 struct tpm_req_header {
-    TPM_REQ_HEADER;
+    u16    tag;
+    u32    totlen;
+    u32    ordinal;
 } PACKED;
 
 
 struct tpm_rsp_header {
-    TPM_RSP_HEADER;
+    u16    tag;
+    u32    totlen;
+    u32    errcode;
 } PACKED;
 
 
 struct tpm_req_extend {
-    TPM_REQ_HEADER
+    struct tpm_req_header hdr;
     u32    pcrindex;
     u8     digest[SHA1_BUFSIZE];
 } PACKED;
 
 
 struct tpm_rsp_extend {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u8     digest[SHA1_BUFSIZE];
 } PACKED;
 
 
 struct tpm_req_getcap_perm_flags {
-    TPM_REQ_HEADER
+    struct tpm_req_header hdr;
     u32    capArea;
     u32    subCapSize;
     u32    subCap;
@@ -287,13 +281,13 @@ enum permFlagsIndex {
 
 
 struct tpm_res_getcap_perm_flags {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u32    size;
     struct tpm_permanent_flags perm_flags;
 } PACKED;
 
 struct tpm_req_getcap_stclear_flags {
-    TPM_REQ_HEADER
+    struct tpm_req_header hdr;
     u32    capArea;
     u32    subCapSize;
     u32    subCap;
@@ -311,40 +305,40 @@ struct tpm_stclear_flags {
 #define STCLEAR_FLAG_IDX_GLOBAL_LOCK 4
 
 struct tpm_res_getcap_stclear_flags {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u32    size;
     struct tpm_stclear_flags stclear_flags;
 } PACKED;
 
 struct tpm_res_getcap_ownerauth {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u32    size;
     u8     flag;
 } PACKED;
 
 
 struct tpm_res_getcap_timeouts {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u32    size;
     u32    timeouts[4];
 } PACKED;
 
 
 struct tpm_res_getcap_durations {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u32    size;
     u32    durations[3];
 } PACKED;
 
 
 struct tpm_res_sha1start {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u32    max_num_bytes;
 } PACKED;
 
 
 struct tpm_res_sha1complete {
-    TPM_RSP_HEADER
+    struct tpm_rsp_header hdr;
     u8     hash[20];
 } PACKED;
 
index 4f78c4223c91fad27b1ee53a668d6616ef3af3f2..55e38a958843bc12bd43c1aef5913800cc322d6d 100644 (file)
@@ -472,17 +472,16 @@ tpm_log_extend_event(struct pcpes *pcpes, const void *event)
         return TCG_INVALID_INPUT_PARA;
 
     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(pcpes->pcrindex),
+        .hdr.tag     = cpu_to_be16(TPM_TAG_RQU_CMD),
+        .hdr.totlen  = cpu_to_be32(sizeof(tre)),
+        .hdr.ordinal = cpu_to_be32(TPM_ORD_Extend),
+        .pcrindex    = cpu_to_be32(pcpes->pcrindex),
     };
     memcpy(tre.digest, pcpes->digest, sizeof(tre.digest));
 
     struct tpm_rsp_extend rsp;
     u32 resp_length = sizeof(rsp);
-    u32 rc = transmit(0, (void*)&tre, &rsp, &resp_length,
-                      TPM_DURATION_TYPE_SHORT);
+    u32 rc = transmit(0, &tre.hdr, &rsp, &resp_length, TPM_DURATION_TYPE_SHORT);
     if (rc || resp_length != sizeof(rsp)) {
         tpm_set_failure();
         return rc;