tpm2: Introduce TPM_HAVE_TPM2_DECLARATIONS to avoid re-declarations

Older gcc versions are unhappy that some types declared by TPM 1.2
headers are re-declared by TPM 2 headers. All of these types have
the same UINT32 datatype and we can avoid having the re-declared
by introducing TPM_HAVE_TPM2_DECLARATIONS and inlcuding the TPM2
headers first and then the TPM 1.2 headers where we then do not re-
declare those datatypes that are clashing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2018-10-05 19:00:50 -04:00 committed by Stefan Berger
parent 8df4b30270
commit 73cad883ba
13 changed files with 38 additions and 18 deletions

View File

@ -51,7 +51,9 @@ extern "C" {
#endif
/* 2.2.1 Basic data types rev 87 */
#if !defined(TPM_HAVE_TPM2_DECLARATIONS)
typedef unsigned char BYTE; /* Basic byte used to transmit all character fields. */
#endif
typedef unsigned char TPM_BOOL; /* TRUE/FALSE field. TRUE = 0x01, FALSE = 0x00 Use TPM_BOOL
because MS VC++ defines BOOL on Windows */
@ -97,8 +99,10 @@ typedef uint16_t TPM_PLATFORM_SPECIFIC; /* The platform specific spec to which
typedef uint32_t TPM_COMMAND_CODE; /* The command ordinal. */
typedef uint32_t TPM_CAPABILITY_AREA; /* Identifies a TPM capability area. */
typedef uint32_t TPM_KEY_FLAGS; /* Indicates information regarding a key. */
#if !defined(TPM_HAVE_TPM2_DECLARATIONS)
typedef uint32_t TPM_ALGORITHM_ID; /* Indicates the type of algorithm. */
typedef uint32_t TPM_MODIFIER_INDICATOR; /* The locality modifier */
#endif
typedef uint32_t TPM_ACTUAL_COUNT; /* The actual number of a counter. */
typedef uint32_t TPM_TRANSPORT_ATTRIBUTES; /* Attributes that define what options are in use
for a transport session */
@ -111,7 +115,9 @@ typedef uint32_t TPM_RESOURCE_TYPE; /* The types of resources that a TPM may ha
resources */
typedef uint32_t TPM_KEY_CONTROL; /* Allows for controlling of the key when loaded and how to
handle TPM_Startup issues */
#if !defined(TPM_HAVE_TPM2_DECLARATIONS)
typedef uint32_t TPM_NV_INDEX; /* The index into the NV storage area */
#endif
typedef uint32_t TPM_FAMILY_ID; /* The family ID. Families ID's are automatically assigned a
sequence number by the TPM. A trusted process can set the
FamilyID value in an individual row to zero, which
@ -129,7 +135,9 @@ typedef uint32_t TPM_CMK_DELEGATE; /* The restrictions placed on delegation of
typedef uint32_t TPM_COUNT_ID; /* The ID value of a monotonic counter */
typedef uint32_t TPM_REDIT_COMMAND; /* A command to execute */
typedef uint32_t TPM_TRANSHANDLE; /* A transport session handle */
#if !defined(TPM_HAVE_TPM2_DECLARATIONS)
typedef uint32_t TPM_HANDLE; /* A generic handle could be key, transport etc. */
#endif
typedef uint32_t TPM_FAMILY_OPERATION; /* What operation is happening */
/* Not in specification */

View File

@ -64,6 +64,10 @@
TPM command execution. */
#include "Tpm.h"
#include "ExecCommand_fp.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
/* Uncomment this next #include if doing static command/response buffer sizing */
// #include "CommandResponseSizes_fp.h"
// The function performs the following steps.

View File

@ -386,7 +386,6 @@
#define CONTEXT_ENCRYPT_ALGORITHM AES
#define NV_CLOCK_UPDATE_INTERVAL 12
#define NUM_POLICY_PCR 1
#include "tpm_library_intern.h"
#define MAX_COMMAND_SIZE TPM2_GetBufferSize()
#define MAX_RESPONSE_SIZE TPM2_GetBufferSize()
#define ORDERLY_BITS 8

View File

@ -43,6 +43,7 @@
#include "LibtpmsCallbacks.h"
#include "NVMarshal.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
#include "tpm_error.h"
#include "tpm_nvfilename.h"

View File

@ -63,8 +63,6 @@
#include "assert.h"
#include "tpm_library_intern.h"
#define SESSION_PROCESS_C
#define NV_C
#define OBJECT_C
@ -79,6 +77,9 @@
#include "TpmTcpProtocol.h"
#include "Simulator_fp.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
/*
* The TPM2 maintains a pcrAllocated shadow variable; the current active one is
* in gp.pcrAllocated and the one to be active after reboot is in NVRAM. So,

View File

@ -64,6 +64,9 @@
/* This file contains the functions that are used for accessing the TPM_CAP_TPM_PROPERTY values. */
/* 9.14.2 Includes */
#include "Tpm.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
/* 9.14.3 Functions */
/* 9.14.3.1 TPMPropertyIsDefined() */
/* This function accepts a property selection and, if so, sets value to the value of the

View File

@ -2,14 +2,15 @@
#include "config.h"
#include "StateMarshal.h"
#include "Volatile.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
#include "tpm_nvfilename.h"
#include "tpm_error.h"
#include "tpm_memory.h"
#include "StateMarshal.h"
#include "Volatile.h"
UINT16
VolatileSave(BYTE **buffer, INT32 *size)
{

View File

@ -70,6 +70,10 @@
does not use any of the structures in TpmTypes.h and only include it for the #defines of the
capabilities, properties, and command code values. */
#include "TpmTypes.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
/* 9.17.2 Typedefs */
/* These defines are used primarily for sizing of the local response buffer. */
typedef struct

View File

@ -73,6 +73,7 @@
#include "NVMarshal.h"
#include "Volatile.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
TPM_RC

View File

@ -64,7 +64,6 @@
#include "tpm_error.h"
#include "tpm_library.h"
#include "tpm_library_intern.h"
#include "tpm_memory.h"
#include "tpm_nvfilename.h"
static const struct tags_and_indices {

View File

@ -54,7 +54,6 @@
#include "tpm12/tpm_global.h"
#include "tpm12/tpm_permanent.h"
#include "tpm12/tpm_nvfile.h"
#include "tpm_memory.h"
TPM_RESULT TPM12_MainInit(void)
{

View File

@ -44,11 +44,6 @@
#include <stdlib.h>
#include <stdbool.h>
#include "tpm_error.h"
#include "tpm_memory.h"
#include "tpm_library_intern.h"
#include "tpm_nvfilename.h"
#ifndef LIB_EXPORT
#define LIB_EXPORT
#endif
@ -63,7 +58,12 @@
#include "tpm2/StateMarshal.h"
#include "tpm2/PlatformData.h"
#include "tpm2/Volatile.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm12/tpm_nvfile.h" // TPM_NVRAM_Loaddata()
#include "tpm_error.h"
#include "tpm_library_intern.h"
#include "tpm_nvfilename.h"
extern BOOL g_inFailureMode;

View File

@ -40,11 +40,7 @@
#include <stdint.h>
/* tpm2/TPM_Types.h gives type definition clashes with TPM 1.2 headers */
typedef uint32_t UINT32;
#include "tpm_library_intern.h"
#include "tpm_error.h"
#include "tpm2/TpmTypes.h"
#include "tpm2/TpmBuildSwitches.h"
#include "tpm2/_TPM_Hash_Start_fp.h"
#include "tpm2/_TPM_Hash_Data_fp.h"
@ -53,6 +49,10 @@ typedef uint32_t UINT32;
#include "tpm2/Platform_fp.h"
#include "tpm2/Simulator_fp.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h"
#include "tpm_error.h"
TPM_RESULT TPM2_IO_TpmEstablished_Get(TPM_BOOL *tpmEstablished)
{
*tpmEstablished = _rpc__Signal_GetTPMEstablished();