Home | History | Annotate | Download | only in Protocol
      1 /** @file
      2   TPM2 Protocol as defined in TCG PC Client Platform EFI Protocol Specification Family "2.0".
      3   See http://trustedcomputinggroup.org for the latest specification
      4 
      5 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions of the BSD License
      8 which accompanies this distribution.  The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #ifndef __TCG2_PROTOCOL_H__
     17 #define __TCG2_PROTOCOL_H__
     18 
     19 #include <IndustryStandard/UefiTcgPlatform.h>
     20 #include <IndustryStandard/Tpm20.h>
     21 
     22 #define EFI_TCG2_PROTOCOL_GUID \
     23   {0x607f766c, 0x7455, 0x42be, { 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }}
     24 
     25 typedef struct tdEFI_TCG2_PROTOCOL EFI_TCG2_PROTOCOL;
     26 
     27 typedef struct tdEFI_TCG2_VERSION {
     28   UINT8 Major;
     29   UINT8 Minor;
     30 } EFI_TCG2_VERSION;
     31 
     32 typedef UINT32 EFI_TCG2_EVENT_LOG_BITMAP;
     33 typedef UINT32 EFI_TCG2_EVENT_LOG_FORMAT;
     34 typedef UINT32 EFI_TCG2_EVENT_ALGORITHM_BITMAP;
     35 
     36 #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2       0x00000001
     37 #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2         0x00000002
     38 
     39 typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY {
     40   //
     41   // Allocated size of the structure
     42   //
     43   UINT8                            Size;
     44   //
     45   // Version of the EFI_TCG2_BOOT_SERVICE_CAPABILITY structure itself.
     46   // For this version of the protocol, the Major version shall be set to 1
     47   // and the Minor version shall be set to 1.
     48   //
     49   EFI_TCG2_VERSION                 StructureVersion;
     50   //
     51   // Version of the EFI TCG2 protocol.
     52   // For this version of the protocol, the Major version shall be set to 1
     53   // and the Minor version shall be set to 1.
     54   //
     55   EFI_TCG2_VERSION                 ProtocolVersion;
     56   //
     57   // Supported hash algorithms (this bitmap is determined by the supported PCR
     58   // banks in the TPM and the hashing algorithms supported by the firmware)
     59   //
     60   EFI_TCG2_EVENT_ALGORITHM_BITMAP  HashAlgorithmBitmap;
     61   //
     62   // Bitmap of supported event log formats
     63   //
     64   EFI_TCG2_EVENT_LOG_BITMAP        SupportedEventLogs;
     65   //
     66   // False = TPM not present
     67   //
     68   BOOLEAN                          TPMPresentFlag;
     69   //
     70   // Max size (in bytes) of a command that can be sent to the TPM
     71   //
     72   UINT16                           MaxCommandSize;
     73   //
     74   // Max size (in bytes) of a response that can be provided by the TPM
     75   //
     76   UINT16                           MaxResponseSize;
     77   //
     78   // 4-byte Vendor ID
     79   // (see TCG Vendor ID registry, Section "TPM Capabilities Vendor ID")
     80   //
     81   UINT32                           ManufacturerID;
     82   //
     83   // Maximum number of PCR banks (hashing algorithms) supported.
     84   // No granularity is provided to support a specific set of algorithms.
     85   // Minimum value is 1.
     86   //
     87   UINT32                           NumberOfPCRBanks;
     88   //
     89   // A bitmap of currently active PCR banks (hashing algorithms).
     90   // This is a subset of the supported hashing algorithms reported in HashAlgorithmBitMap.
     91   // NumberOfPcrBanks defines the number of bits that are set.
     92   //
     93   EFI_TCG2_EVENT_ALGORITHM_BITMAP  ActivePcrBanks;
     94 } EFI_TCG2_BOOT_SERVICE_CAPABILITY;
     95 
     96 #define EFI_TCG2_BOOT_HASH_ALG_SHA1    0x00000001
     97 #define EFI_TCG2_BOOT_HASH_ALG_SHA256  0x00000002
     98 #define EFI_TCG2_BOOT_HASH_ALG_SHA384  0x00000004
     99 #define EFI_TCG2_BOOT_HASH_ALG_SHA512  0x00000008
    100 #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010
    101 
    102 //
    103 // This bit is shall be set when an event shall be extended but not logged.
    104 //
    105 #define EFI_TCG2_EXTEND_ONLY  0x0000000000000001
    106 //
    107 // This bit shall be set when the intent is to measure a PE/COFF image.
    108 //
    109 #define PE_COFF_IMAGE     0x0000000000000010
    110 
    111 #define MAX_PCR_INDEX  23
    112 
    113 #pragma pack(1)
    114 
    115 #define EFI_TCG2_EVENT_HEADER_VERSION  1
    116 
    117 typedef struct {
    118   //
    119   // Size of the event header itself (sizeof(EFI_TCG2_EVENT_HEADER)).
    120   //
    121   UINT32            HeaderSize;
    122   //
    123   // Header version. For this version of this specification, the value shall be 1.
    124   //
    125   UINT16            HeaderVersion;
    126   //
    127   // Index of the PCR that shall be extended (0 - 23).
    128   //
    129   TCG_PCRINDEX      PCRIndex;
    130   //
    131   // Type of the event that shall be extended (and optionally logged).
    132   //
    133   TCG_EVENTTYPE     EventType;
    134 } EFI_TCG2_EVENT_HEADER;
    135 
    136 typedef struct tdEFI_TCG2_EVENT {
    137   //
    138   // Total size of the event including the Size component, the header and the Event data.
    139   //
    140   UINT32                Size;
    141   EFI_TCG2_EVENT_HEADER Header;
    142   UINT8                 Event[1];
    143 } EFI_TCG2_EVENT;
    144 
    145 #pragma pack()
    146 
    147 /**
    148   The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
    149   capability information and state information.
    150 
    151   @param[in]      This               Indicates the calling context
    152   @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
    153                                      structure and sets the size field to the size of the structure allocated.
    154                                      The callee fills in the fields with the EFI protocol capability information
    155                                      and the current EFI TCG2 state information up to the number of fields which
    156                                      fit within the size of the structure passed in.
    157 
    158   @retval EFI_SUCCESS            Operation completed successfully.
    159   @retval EFI_DEVICE_ERROR       The command was unsuccessful.
    160                                  The ProtocolCapability variable will not be populated.
    161   @retval EFI_INVALID_PARAMETER  One or more of the parameters are incorrect.
    162                                  The ProtocolCapability variable will not be populated.
    163   @retval EFI_BUFFER_TOO_SMALL   The ProtocolCapability variable is too small to hold the full response.
    164                                  It will be partially populated (required Size field will be set).
    165 **/
    166 typedef
    167 EFI_STATUS
    168 (EFIAPI *EFI_TCG2_GET_CAPABILITY) (
    169   IN EFI_TCG2_PROTOCOL                    *This,
    170   IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability
    171   );
    172 
    173 /**
    174   The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
    175   retrieve the address of a given event log and its last entry.
    176 
    177   @param[in]  This               Indicates the calling context
    178   @param[in]  EventLogFormat     The type of the event log for which the information is requested.
    179   @param[out] EventLogLocation   A pointer to the memory address of the event log.
    180   @param[out] EventLogLastEntry  If the Event Log contains more than one entry, this is a pointer to the
    181                                  address of the start of the last entry in the event log in memory.
    182   @param[out] EventLogTruncated  If the Event Log is missing at least one entry because an event would
    183                                  have exceeded the area allocated for events, this value is set to TRUE.
    184                                  Otherwise, the value will be FALSE and the Event Log will be complete.
    185 
    186   @retval EFI_SUCCESS            Operation completed successfully.
    187   @retval EFI_INVALID_PARAMETER  One or more of the parameters are incorrect
    188                                  (e.g. asking for an event log whose format is not supported).
    189 **/
    190 typedef
    191 EFI_STATUS
    192 (EFIAPI *EFI_TCG2_GET_EVENT_LOG) (
    193   IN EFI_TCG2_PROTOCOL         *This,
    194   IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat,
    195   OUT EFI_PHYSICAL_ADDRESS     *EventLogLocation,
    196   OUT EFI_PHYSICAL_ADDRESS     *EventLogLastEntry,
    197   OUT BOOLEAN                  *EventLogTruncated
    198   );
    199 
    200 /**
    201   The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
    202   an opportunity to extend and optionally log events without requiring
    203   knowledge of actual TPM commands.
    204   The extend operation will occur even if this function cannot create an event
    205   log entry (e.g. due to the event log being full).
    206 
    207   @param[in]  This               Indicates the calling context
    208   @param[in]  Flags              Bitmap providing additional information.
    209   @param[in]  DataToHash         Physical address of the start of the data buffer to be hashed.
    210   @param[in]  DataToHashLen      The length in bytes of the buffer referenced by DataToHash.
    211   @param[in]  EfiTcgEvent        Pointer to data buffer containing information about the event.
    212 
    213   @retval EFI_SUCCESS            Operation completed successfully.
    214   @retval EFI_DEVICE_ERROR       The command was unsuccessful.
    215   @retval EFI_VOLUME_FULL        The extend operation occurred, but the event could not be written to one or more event logs.
    216   @retval EFI_INVALID_PARAMETER  One or more of the parameters are incorrect.
    217   @retval EFI_UNSUPPORTED        The PE/COFF image type is not supported.
    218 **/
    219 typedef
    220 EFI_STATUS
    221 (EFIAPI * EFI_TCG2_HASH_LOG_EXTEND_EVENT) (
    222   IN EFI_TCG2_PROTOCOL    *This,
    223   IN UINT64               Flags,
    224   IN EFI_PHYSICAL_ADDRESS DataToHash,
    225   IN UINT64               DataToHashLen,
    226   IN EFI_TCG2_EVENT       *EfiTcgEvent
    227   );
    228 
    229 /**
    230   This service enables the sending of commands to the TPM.
    231 
    232   @param[in]  This                     Indicates the calling context
    233   @param[in]  InputParameterBlockSize  Size of the TPM input parameter block.
    234   @param[in]  InputParameterBlock      Pointer to the TPM input parameter block.
    235   @param[in]  OutputParameterBlockSize Size of the TPM output parameter block.
    236   @param[in]  OutputParameterBlock     Pointer to the TPM output parameter block.
    237 
    238   @retval EFI_SUCCESS            The command byte stream was successfully sent to the device and a response was successfully received.
    239   @retval EFI_DEVICE_ERROR       The command was not successfully sent to the device or a response was not successfully received from the device.
    240   @retval EFI_INVALID_PARAMETER  One or more of the parameters are incorrect.
    241   @retval EFI_BUFFER_TOO_SMALL   The output parameter block is too small.
    242 **/
    243 typedef
    244 EFI_STATUS
    245 (EFIAPI *EFI_TCG2_SUBMIT_COMMAND) (
    246   IN EFI_TCG2_PROTOCOL *This,
    247   IN UINT32            InputParameterBlockSize,
    248   IN UINT8             *InputParameterBlock,
    249   IN UINT32            OutputParameterBlockSize,
    250   IN UINT8             *OutputParameterBlock
    251   );
    252 
    253 /**
    254   This service returns the currently active PCR banks.
    255 
    256   @param[in]  This            Indicates the calling context
    257   @param[out] ActivePcrBanks  Pointer to the variable receiving the bitmap of currently active PCR banks.
    258 
    259   @retval EFI_SUCCESS           The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
    260   @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
    261 **/
    262 typedef
    263 EFI_STATUS
    264 (EFIAPI *EFI_TCG2_GET_ACTIVE_PCR_BANKS) (
    265   IN  EFI_TCG2_PROTOCOL *This,
    266   OUT UINT32            *ActivePcrBanks
    267   );
    268 
    269 /**
    270   This service sets the currently active PCR banks.
    271 
    272   @param[in]  This            Indicates the calling context
    273   @param[in]  ActivePcrBanks  Bitmap of the requested active PCR banks. At least one bit SHALL be set.
    274 
    275   @retval EFI_SUCCESS           The bitmap in ActivePcrBank parameter is already active.
    276   @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
    277 **/
    278 typedef
    279 EFI_STATUS
    280 (EFIAPI *EFI_TCG2_SET_ACTIVE_PCR_BANKS) (
    281   IN EFI_TCG2_PROTOCOL *This,
    282   IN UINT32            ActivePcrBanks
    283   );
    284 
    285 /**
    286   This service retrieves the result of a previous invocation of SetActivePcrBanks.
    287 
    288   @param[in]  This              Indicates the calling context
    289   @param[out] OperationPresent  Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
    290   @param[out] Response          The response from the SetActivePcrBank request.
    291 
    292   @retval EFI_SUCCESS           The result value could be returned.
    293   @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
    294 **/
    295 typedef
    296 EFI_STATUS
    297 (EFIAPI *EFI_TCG2_GET_RESULT_OF_SET_ACTIVE_PCR_BANKS) (
    298   IN  EFI_TCG2_PROTOCOL  *This,
    299   OUT UINT32             *OperationPresent,
    300   OUT UINT32             *Response
    301   );
    302 
    303 struct tdEFI_TCG2_PROTOCOL {
    304   EFI_TCG2_GET_CAPABILITY                     GetCapability;
    305   EFI_TCG2_GET_EVENT_LOG                      GetEventLog;
    306   EFI_TCG2_HASH_LOG_EXTEND_EVENT              HashLogExtendEvent;
    307   EFI_TCG2_SUBMIT_COMMAND                     SubmitCommand;
    308   EFI_TCG2_GET_ACTIVE_PCR_BANKS               GetActivePcrBanks;
    309   EFI_TCG2_SET_ACTIVE_PCR_BANKS               SetActivePcrBanks;
    310   EFI_TCG2_GET_RESULT_OF_SET_ACTIVE_PCR_BANKS GetResultOfSetActivePcrBanks;
    311 };
    312 
    313 extern EFI_GUID gEfiTcg2ProtocolGuid;
    314 
    315 //
    316 // Log entries after Get Event Log service
    317 //
    318 
    319 #define EFI_TCG2_FINAL_EVENTS_TABLE_GUID \
    320   {0x1e2ed096, 0x30e2, 0x4254, { 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25 }}
    321 
    322 extern EFI_GUID gEfiTcg2FinalEventsTableGuid;
    323 
    324 typedef struct tdEFI_TCG2_FINAL_EVENTS_TABLE {
    325   //
    326   // The version of this structure.
    327   //
    328   UINT64                  Version;
    329   //
    330   // Number of events recorded after invocation of GetEventLog API
    331   //
    332   UINT64                  NumberOfEvents;
    333   //
    334   // List of events of type TCG_PCR_EVENT2.
    335   //
    336 //TCG_PCR_EVENT2          Event[1];
    337 } EFI_TCG2_FINAL_EVENTS_TABLE;
    338 
    339 #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION   1
    340 
    341 #endif
    342