TianoCore EDK2 master
Loading...
Searching...
No Matches
Tcg2Dxe.c File Reference

Go to the source code of this file.

Data Structures

struct  VARIABLE_TYPE
 
struct  TCG2_EVENT_INFO_STRUCT
 
struct  TCG_EVENT_LOG_AREA_STRUCT
 
struct  _TCG_DXE_DATA
 

Macros

#define PERF_ID_TCG2_DXE   0x3120
 
#define TCG2_DEFAULT_MAX_COMMAND_SIZE   0x1000
 
#define TCG2_DEFAULT_MAX_RESPONSE_SIZE   0x1000
 
#define TCG_EVENT_LOG_AREA_COUNT_MAX   2
 
#define COLUME_SIZE   (16 * 2)
 

Typedefs

typedef struct _TCG_DXE_DATA TCG_DXE_DATA
 

Functions

EFI_STATUS MeasurePeImageAndExtend (IN UINT32 PCRIndex, IN EFI_PHYSICAL_ADDRESS ImageAddress, IN UINTN ImageSize, OUT TPML_DIGEST_VALUES *DigestList)
 
VOID InternalDumpData (IN UINT8 *Data, IN UINTN Size)
 
VOID InitNoActionEvent (IN OUT TCG_PCR_EVENT2_HDR *NoActionEvent, IN UINT32 EventSize)
 
VOID InternalDumpHex (IN UINT8 *Data, IN UINTN Size)
 
EFI_STATUS GetProcessorsCpuLocation (OUT EFI_CPU_PHYSICAL_LOCATION **LocationBuf, OUT UINTN *Num)
 
EFI_STATUS EFIAPI Tcg2GetCapability (IN EFI_TCG2_PROTOCOL *This, IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability)
 
VOID DumpEvent (IN TCG_PCR_EVENT_HDR *EventHdr)
 
VOID DumpTcgEfiSpecIdEventStruct (IN TCG_EfiSpecIDEventStruct *TcgEfiSpecIdEventStruct)
 
UINTN GetTcgEfiSpecIdEventStructSize (IN TCG_EfiSpecIDEventStruct *TcgEfiSpecIdEventStruct)
 
VOID DumpEvent2 (IN TCG_PCR_EVENT2 *TcgPcrEvent2)
 
UINTN GetPcrEvent2Size (IN TCG_PCR_EVENT2 *TcgPcrEvent2)
 
VOID DumpEventLog (IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat, IN EFI_PHYSICAL_ADDRESS EventLogLocation, IN EFI_PHYSICAL_ADDRESS EventLogLastEntry, IN EFI_TCG2_FINAL_EVENTS_TABLE *FinalEventsTable)
 
EFI_STATUS EFIAPI Tcg2GetEventLog (IN EFI_TCG2_PROTOCOL *This, IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat, OUT EFI_PHYSICAL_ADDRESS *EventLogLocation, OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry, OUT BOOLEAN *EventLogTruncated)
 
BOOLEAN Is800155Event (IN VOID *NewEventHdr, IN UINT32 NewEventHdrSize, IN UINT8 *NewEventData, IN UINT32 NewEventSize)
 
EFI_STATUS TcgCommLogEvent (IN OUT TCG_EVENT_LOG_AREA_STRUCT *EventLogAreaStruct, IN VOID *NewEventHdr, IN UINT32 NewEventHdrSize, IN UINT8 *NewEventData, IN UINT32 NewEventSize)
 
EFI_STATUS TcgDxeLogEvent (IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat, IN VOID *NewEventHdr, IN UINT32 NewEventHdrSize, IN UINT8 *NewEventData, IN UINT32 NewEventSize)
 
UINT32 GetDigestListBinSize (IN VOID *DigestListBin)
 
VOID * CopyDigestListBinToBuffer (IN OUT VOID *Buffer, IN VOID *DigestListBin, IN UINT32 HashAlgorithmMask, OUT UINT32 *HashAlgorithmMaskCopied)
 
EFI_STATUS TcgDxeLogHashEvent (IN TPML_DIGEST_VALUES *DigestList, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
 
EFI_STATUS TcgDxeHashLogExtendEvent (IN UINT64 Flags, IN UINT8 *HashData, IN UINT64 HashDataLen, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
 
EFI_STATUS EFIAPI Tcg2HashLogExtendEvent (IN EFI_TCG2_PROTOCOL *This, IN UINT64 Flags, IN EFI_PHYSICAL_ADDRESS DataToHash, IN UINT64 DataToHashLen, IN EFI_TCG2_EVENT *Event)
 
EFI_STATUS EFIAPI Tcg2SubmitCommand (IN EFI_TCG2_PROTOCOL *This, IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN UINT32 OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
 
EFI_STATUS EFIAPI Tcg2GetActivePCRBanks (IN EFI_TCG2_PROTOCOL *This, OUT UINT32 *ActivePcrBanks)
 
EFI_STATUS EFIAPI Tcg2SetActivePCRBanks (IN EFI_TCG2_PROTOCOL *This, IN UINT32 ActivePcrBanks)
 
EFI_STATUS EFIAPI Tcg2GetResultOfSetActivePcrBanks (IN EFI_TCG2_PROTOCOL *This, OUT UINT32 *OperationPresent, OUT UINT32 *Response)
 
EFI_STATUS SetupEventLog (VOID)
 
EFI_STATUS TcgMeasureAction (IN TPM_PCRINDEX PCRIndex, IN CHAR8 *String)
 
EFI_STATUS MeasureHandoffTables (VOID)
 
EFI_STATUS MeasureSeparatorEvent (IN TPM_PCRINDEX PCRIndex)
 
EFI_STATUS MeasureVariable (IN TPM_PCRINDEX PCRIndex, IN TCG_EVENTTYPE EventType, IN CHAR16 *VarName, IN EFI_GUID *VendorGuid, IN VOID *VarData, IN UINTN VarSize)
 
EFI_STATUS ReadAndMeasureVariable (IN TPM_PCRINDEX PCRIndex, IN TCG_EVENTTYPE EventType, IN CHAR16 *VarName, IN EFI_GUID *VendorGuid, OUT UINTN *VarSize, OUT VOID **VarData)
 
EFI_STATUS ReadAndMeasureBootVariable (IN CHAR16 *VarName, IN EFI_GUID *VendorGuid, OUT UINTN *VarSize, OUT VOID **VarData)
 
EFI_STATUS ReadAndMeasureSecureVariable (IN CHAR16 *VarName, IN EFI_GUID *VendorGuid, OUT UINTN *VarSize, OUT VOID **VarData)
 
EFI_STATUS MeasureAllBootVariables (VOID)
 
EFI_STATUS MeasureAllSecureVariables (VOID)
 
EFI_STATUS MeasureLaunchOfFirmwareDebugger (VOID)
 
VOID EFIAPI MeasureSecureBootPolicy (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI OnReadyToBoot (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI OnExitBootServices (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI OnExitBootServicesFailed (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI ShutdownTpmOnReset (IN EFI_RESET_TYPE ResetType, IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN VOID *ResetData OPTIONAL)
 
VOID EFIAPI OnResetNotificationInstall (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_STATUS InstallTcg2 (VOID)
 
EFI_STATUS EFIAPI DriverEntry (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

TCG2_EVENT_INFO_STRUCT mTcg2EventInfo []
 
TCG_DXE_DATA mTcgDxeData
 
UINTN mBootAttempts = 0
 
CHAR16 mBootVarName [] = L"BootOrder"
 
VARIABLE_TYPE mVariableType []
 
EFI_HANDLE mImageHandle
 
EFI_TCG2_PROTOCOL mTcg2Protocol
 

Detailed Description

This module implements Tcg2 Protocol.

Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Tcg2Dxe.c.

Macro Definition Documentation

◆ PERF_ID_TCG2_DXE

#define PERF_ID_TCG2_DXE   0x3120

Definition at line 49 of file Tcg2Dxe.c.

◆ TCG2_DEFAULT_MAX_COMMAND_SIZE

#define TCG2_DEFAULT_MAX_COMMAND_SIZE   0x1000

Definition at line 56 of file Tcg2Dxe.c.

◆ TCG2_DEFAULT_MAX_RESPONSE_SIZE

#define TCG2_DEFAULT_MAX_RESPONSE_SIZE   0x1000

Definition at line 57 of file Tcg2Dxe.c.

◆ TCG_EVENT_LOG_AREA_COUNT_MAX

#define TCG_EVENT_LOG_AREA_COUNT_MAX   2

Definition at line 69 of file Tcg2Dxe.c.

Function Documentation

◆ CopyDigestListBinToBuffer()

VOID * CopyDigestListBinToBuffer ( IN OUT VOID *  Buffer,
IN VOID *  DigestListBin,
IN UINT32  HashAlgorithmMask,
OUT UINT32 *  HashAlgorithmMaskCopied 
)

Copy TPML_DIGEST_VALUES compact binary into a buffer

Parameters
[in,out]BufferBuffer to hold copied TPML_DIGEST_VALUES compact binary.
[in]DigestListBinTPML_DIGEST_VALUES compact binary buffer.
[in]HashAlgorithmMaskHASH bits corresponding to the desired digests to copy.
[out]HashAlgorithmMaskCopiedPointer to HASH bits corresponding to the digests copied.
Returns
The end of buffer to hold TPML_DIGEST_VALUES compact binary.

Definition at line 1065 of file Tcg2Dxe.c.

◆ DriverEntry()

EFI_STATUS EFIAPI DriverEntry ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

The driver's entry point. It publishes EFI Tcg2 Protocol.

Parameters
[in]ImageHandleThe firmware allocated handle for the EFI image.
[in]SystemTableA pointer to the EFI System Table.
Return values
EFI_SUCCESSThe entry point is executed successfully.
otherSome error occurs when executing this entry point.

Definition at line 2736 of file Tcg2Dxe.c.

◆ DumpEvent()

VOID DumpEvent ( IN TCG_PCR_EVENT_HDR EventHdr)

This function dump PCR event.

Parameters
[in]EventHdrTCG PCR event structure.

Definition at line 428 of file Tcg2Dxe.c.

◆ DumpEvent2()

VOID DumpEvent2 ( IN TCG_PCR_EVENT2 TcgPcrEvent2)

This function dump PCR event 2.

Parameters
[in]TcgPcrEvent2TCG PCR event 2 structure.

Definition at line 522 of file Tcg2Dxe.c.

◆ DumpEventLog()

VOID DumpEventLog ( IN EFI_TCG2_EVENT_LOG_FORMAT  EventLogFormat,
IN EFI_PHYSICAL_ADDRESS  EventLogLocation,
IN EFI_PHYSICAL_ADDRESS  EventLogLastEntry,
IN EFI_TCG2_FINAL_EVENTS_TABLE FinalEventsTable 
)

This function dump event log.

Parameters
[in]EventLogFormatThe type of the event log for which the information is requested.
[in]EventLogLocationA pointer to the memory address of the event log.
[in]EventLogLastEntryIf the Event Log contains more than one entry, this is a pointer to the address of the start of the last entry in the event log in memory.
[in]FinalEventsTableA pointer to the memory address of the final event table.

Definition at line 619 of file Tcg2Dxe.c.

◆ DumpTcgEfiSpecIdEventStruct()

VOID DumpTcgEfiSpecIdEventStruct ( IN TCG_EfiSpecIDEventStruct TcgEfiSpecIdEventStruct)

This function dump TCG_EfiSpecIDEventStruct.

Parameters
[in]TcgEfiSpecIdEventStructA pointer to TCG_EfiSpecIDEventStruct.

Definition at line 453 of file Tcg2Dxe.c.

◆ GetDigestListBinSize()

UINT32 GetDigestListBinSize ( IN VOID *  DigestListBin)

Get TPML_DIGEST_VALUES compact binary buffer size.

Parameters
[in]DigestListBinTPML_DIGEST_VALUES compact binary buffer.
Returns
TPML_DIGEST_VALUES compact binary buffer size.

Definition at line 1028 of file Tcg2Dxe.c.

◆ GetPcrEvent2Size()

UINTN GetPcrEvent2Size ( IN TCG_PCR_EVENT2 TcgPcrEvent2)

This function returns size of TCG PCR event 2.

Parameters
[in]TcgPcrEvent2TCG PCR event 2 structure.
Returns
size of TCG PCR event 2.

Definition at line 577 of file Tcg2Dxe.c.

◆ GetProcessorsCpuLocation()

EFI_STATUS GetProcessorsCpuLocation ( OUT EFI_CPU_PHYSICAL_LOCATION **  LocationBuf,
OUT UINTN Num 
)

Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function Caller is responsible to free LocationBuf.

Parameters
[out]LocationBufReturns Processor Location Buffer.
[out]NumReturns processor number.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_UNSUPPORTEDMpService protocol not found.

Definition at line 290 of file Tcg2Dxe.c.

◆ GetTcgEfiSpecIdEventStructSize()

UINTN GetTcgEfiSpecIdEventStructSize ( IN TCG_EfiSpecIDEventStruct TcgEfiSpecIdEventStruct)

This function get size of TCG_EfiSpecIDEventStruct.

Parameters
[in]TcgEfiSpecIdEventStructA pointer to TCG_EfiSpecIDEventStruct.

Definition at line 501 of file Tcg2Dxe.c.

◆ InitNoActionEvent()

VOID InitNoActionEvent ( IN OUT TCG_PCR_EVENT2_HDR NoActionEvent,
IN UINT32  EventSize 
)

This function initialize TCG_PCR_EVENT2_HDR for EV_NO_ACTION Event Type other than EFI Specification ID event The behavior is defined by TCG PC Client PFP Spec. Section 9.3.4 EV_NO_ACTION Event Types

Parameters
[in,out]NoActionEventEvent Header of EV_NO_ACTION Event
[in]EventSizeEvent Size of the EV_NO_ACTION Event

Definition at line 177 of file Tcg2Dxe.c.

◆ InstallTcg2()

EFI_STATUS InstallTcg2 ( VOID  )

The function install Tcg2 protocol.

Return values
EFI_SUCCESSTcg2 protocol is installed.
otherSome error occurs.

Definition at line 2708 of file Tcg2Dxe.c.

◆ InternalDumpData()

VOID InternalDumpData ( IN UINT8 *  Data,
IN UINTN  Size 
)

This function dump raw data.

Parameters
Dataraw data
Sizeraw data size

Definition at line 155 of file Tcg2Dxe.c.

◆ InternalDumpHex()

VOID InternalDumpHex ( IN UINT8 *  Data,
IN UINTN  Size 
)

This function dump raw data with colume format.

Parameters
Dataraw data
Sizeraw data size

Definition at line 252 of file Tcg2Dxe.c.

◆ Is800155Event()

BOOLEAN Is800155Event ( IN VOID *  NewEventHdr,
IN UINT32  NewEventHdrSize,
IN UINT8 *  NewEventData,
IN UINT32  NewEventSize 
)

Return if this is a Tcg800155PlatformIdEvent.

Parameters
[in]NewEventHdrPointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
[in]NewEventHdrSizeNew event header size.
[in]NewEventDataPointer to the new event data.
[in]NewEventSizeNew event data size.
Return values
TRUEThis is a Tcg800155PlatformIdEvent.
FALSEThis is NOT a Tcg800155PlatformIdEvent.

Definition at line 806 of file Tcg2Dxe.c.

◆ MeasureAllBootVariables()

EFI_STATUS MeasureAllBootVariables ( VOID  )

Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.

The EFI boot variables are BootOrder and Boot#### variables.

Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2243 of file Tcg2Dxe.c.

◆ MeasureAllSecureVariables()

EFI_STATUS MeasureAllSecureVariables ( VOID  )

Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.

The EFI boot variables are BootOrder and Boot#### variables.

Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2301 of file Tcg2Dxe.c.

◆ MeasureHandoffTables()

EFI_STATUS MeasureHandoffTables ( VOID  )

Measure and log EFI handoff tables, and extend the measurement result into PCR[1].

Return values
EFI_SUCCESSOperation completed successfully.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 1950 of file Tcg2Dxe.c.

◆ MeasureLaunchOfFirmwareDebugger()

EFI_STATUS MeasureLaunchOfFirmwareDebugger ( VOID  )

Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.

Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2386 of file Tcg2Dxe.c.

◆ MeasurePeImageAndExtend()

EFI_STATUS MeasurePeImageAndExtend ( IN UINT32  PCRIndex,
IN EFI_PHYSICAL_ADDRESS  ImageAddress,
IN UINTN  ImageSize,
OUT TPML_DIGEST_VALUES DigestList 
)

Measure PE image into TPM log based on the authenticode image hashing in PE/COFF Specification 8.0 Appendix A.

Caution: This function may receive untrusted input. PE/COFF image is external input, so this function will validate its data structure within this image buffer before use.

Notes: PE/COFF image is checked by BasePeCoffLib PeCoffLoaderGetImageInfo().

Parameters
[in]PCRIndexTPM PCR index
[in]ImageAddressStart address of image buffer.
[in]ImageSizeImage size
[out]DigestListDigest list of this image.
Return values
EFI_SUCCESSSuccessfully measure image.
EFI_OUT_OF_RESOURCESNo enough resource to measure image.
othererror value

Measure PE image into TPM log based on the authenticode image hashing in PE/COFF Specification 8.0 Appendix A.

Caution: This function may receive untrusted input. PE/COFF image is external input, so this function will validate its data structure within this image buffer before use.

Notes: PE/COFF image is checked by BasePeCoffLib PeCoffLoaderGetImageInfo().

Parameters
[in]RtmrIndexRtmr index
[in]ImageAddressStart address of image buffer.
[in]ImageSizeImage size
[out]DigestListDigest list of this image.
Return values
EFI_SUCCESSSuccessfully measure image.
EFI_OUT_OF_RESOURCESNo enough resource to measure image.
othererror value

Definition at line 95 of file MeasureBootPeCoff.c.

◆ MeasureSecureBootPolicy()

VOID EFIAPI MeasureSecureBootPolicy ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.

Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)

  • The contents of the SecureBoot variable
  • The contents of the PK variable
  • The contents of the KEK variable
  • The contents of the EFI_IMAGE_SECURITY_DATABASE variable
  • The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
  • Separator
  • Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path

NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE, EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].

Parameters
[in]EventEvent whose notification function is being invoked
[in]ContextPointer to the notification function's context

Definition at line 2424 of file Tcg2Dxe.c.

◆ MeasureSeparatorEvent()

EFI_STATUS MeasureSeparatorEvent ( IN TPM_PCRINDEX  PCRIndex)

Measure and log Separator event, and extend the measurement result into a specific PCR.

Parameters
[in]PCRIndexPCR index.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2004 of file Tcg2Dxe.c.

◆ MeasureVariable()

EFI_STATUS MeasureVariable ( IN TPM_PCRINDEX  PCRIndex,
IN TCG_EVENTTYPE  EventType,
IN CHAR16 *  VarName,
IN EFI_GUID VendorGuid,
IN VOID *  VarData,
IN UINTN  VarSize 
)

Measure and log an EFI variable, and extend the measurement result into a specific PCR.

Parameters
[in]PCRIndexPCR Index.
[in]EventTypeEvent type.
[in]VarNameA Null-terminated string that is the name of the vendor's variable.
[in]VendorGuidA unique identifier for the vendor.
[in]VarDataThe content of the variable data.
[in]VarSizeThe size of the variable data.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2042 of file Tcg2Dxe.c.

◆ OnExitBootServices()

VOID EFIAPI OnExitBootServices ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Exit Boot Services Event notification handler.

Measure invocation and success of ExitBootServices.

Parameters
[in]EventEvent whose notification function is being invoked
[in]ContextPointer to the notification function's context

Definition at line 2570 of file Tcg2Dxe.c.

◆ OnExitBootServicesFailed()

VOID EFIAPI OnExitBootServicesFailed ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Exit Boot Services Failed Event notification handler.

Measure Failure of ExitBootServices.

Parameters
[in]EventEvent whose notification function is being invoked
[in]ContextPointer to the notification function's context

Definition at line 2611 of file Tcg2Dxe.c.

◆ OnReadyToBoot()

VOID EFIAPI OnReadyToBoot ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Ready to Boot Event notification handler.

Sequence of OS boot events is measured in this event notification handler.

Parameters
[in]EventEvent whose notification function is being invoked
[in]ContextPointer to the notification function's context

Definition at line 2467 of file Tcg2Dxe.c.

◆ OnResetNotificationInstall()

VOID EFIAPI OnResetNotificationInstall ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Hook the system reset to properly shutdown TPM. It follow chapter "12.2.3 Startup State" in Trusted Platform Module Library Part 1: Architecture, Revision 01.16.

Parameters
[in]EventEvent whose notification function is being invoked
[in]ContextPointer to the notification function's context

Definition at line 2683 of file Tcg2Dxe.c.

◆ ReadAndMeasureBootVariable()

EFI_STATUS ReadAndMeasureBootVariable ( IN CHAR16 *  VarName,
IN EFI_GUID VendorGuid,
OUT UINTN VarSize,
OUT VOID **  VarData 
)

Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[1]. according to TCG PC Client PFP spec 0021 Section 2.4.4.2

Parameters
[in]VarNameA Null-terminated string that is the name of the vendor's variable.
[in]VendorGuidA unique identifier for the vendor.
[out]VarSizeThe size of the variable data.
[out]VarDataPointer to the content of the variable.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2184 of file Tcg2Dxe.c.

◆ ReadAndMeasureSecureVariable()

EFI_STATUS ReadAndMeasureSecureVariable ( IN CHAR16 *  VarName,
IN EFI_GUID VendorGuid,
OUT UINTN VarSize,
OUT VOID **  VarData 
)

Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].

Parameters
[in]VarNameA Null-terminated string that is the name of the vendor's variable.
[in]VendorGuidA unique identifier for the vendor.
[out]VarSizeThe size of the variable data.
[out]VarDataPointer to the content of the variable.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2215 of file Tcg2Dxe.c.

◆ ReadAndMeasureVariable()

EFI_STATUS ReadAndMeasureVariable ( IN TPM_PCRINDEX  PCRIndex,
IN TCG_EVENTTYPE  EventType,
IN CHAR16 *  VarName,
IN EFI_GUID VendorGuid,
OUT UINTN VarSize,
OUT VOID **  VarData 
)

Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.

Parameters
[in]PCRIndexPCR Index.
[in]EventTypeEvent type.
[in]VarNameA Null-terminated string that is the name of the vendor's variable.
[in]VendorGuidA unique identifier for the vendor.
[out]VarSizeThe size of the variable data.
[out]VarDataPointer to the content of the variable.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 2129 of file Tcg2Dxe.c.

◆ SetupEventLog()

EFI_STATUS SetupEventLog ( VOID  )

Initialize the Event Log and log events passed from the PEI phase.

Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESOut of memory.

Definition at line 1567 of file Tcg2Dxe.c.

◆ ShutdownTpmOnReset()

VOID EFIAPI ShutdownTpmOnReset ( IN EFI_RESET_TYPE  ResetType,
IN EFI_STATUS  ResetStatus,
IN UINTN  DataSize,
IN VOID *ResetData  OPTIONAL 
)

This routine is called to properly shutdown the TPM before system reset. It follow chapter "12.2.3 Startup State" in Trusted Platform Module Library Part 1: Architecture, Revision 01.16.

Parameters
[in]ResetTypeThe type of reset to perform.
[in]ResetStatusThe status code for the reset.
[in]DataSizeThe size, in bytes, of ResetData.
[in]ResetDataFor a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown the data buffer starts with a Null-terminated string, optionally followed by additional binary data. The string is a description that the caller may use to further indicate the reason for the system reset. For a ResetType of EfiResetPlatformSpecific the data buffer also starts with a Null-terminated string that is followed by an EFI_GUID that describes the specific type of reset to perform.

Definition at line 2660 of file Tcg2Dxe.c.

◆ Tcg2GetActivePCRBanks()

EFI_STATUS EFIAPI Tcg2GetActivePCRBanks ( IN EFI_TCG2_PROTOCOL This,
OUT UINT32 *  ActivePcrBanks 
)

This service returns the currently active PCR banks.

Parameters
[in]ThisIndicates the calling context
[out]ActivePcrBanksPointer to the variable receiving the bitmap of currently active PCR banks.
Return values
EFI_SUCCESSThe bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect.

Definition at line 1451 of file Tcg2Dxe.c.

◆ Tcg2GetCapability()

EFI_STATUS EFIAPI Tcg2GetCapability ( IN EFI_TCG2_PROTOCOL This,
IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY ProtocolCapability 
)

The EFI_TCG2_PROTOCOL GetCapability function call provides protocol capability information and state information.

Parameters
[in]ThisIndicates the calling context
[in,out]ProtocolCapabilityThe caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY structure and sets the size field to the size of the structure allocated. The callee fills in the fields with the EFI protocol capability information and the current EFI TCG2 state information up to the number of fields which fit within the size of the structure passed in.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_DEVICE_ERRORThe command was unsuccessful. The ProtocolCapability variable will not be populated.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect. The ProtocolCapability variable will not be populated.
EFI_BUFFER_TOO_SMALLThe ProtocolCapability variable is too small to hold the full response. It will be partially populated (required Size field will be set).

Definition at line 380 of file Tcg2Dxe.c.

◆ Tcg2GetEventLog()

EFI_STATUS EFIAPI Tcg2GetEventLog ( IN EFI_TCG2_PROTOCOL This,
IN EFI_TCG2_EVENT_LOG_FORMAT  EventLogFormat,
OUT EFI_PHYSICAL_ADDRESS EventLogLocation,
OUT EFI_PHYSICAL_ADDRESS EventLogLastEntry,
OUT BOOLEAN *  EventLogTruncated 
)

The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to retrieve the address of a given event log and its last entry.

Parameters
[in]ThisIndicates the calling context
[in]EventLogFormatThe type of the event log for which the information is requested.
[out]EventLogLocationA pointer to the memory address of the event log.
[out]EventLogLastEntryIf the Event Log contains more than one entry, this is a pointer to the address of the start of the last entry in the event log in memory.
[out]EventLogTruncatedIf the Event Log is missing at least one entry because an event would have exceeded the area allocated for events, this value is set to TRUE. Otherwise, the value will be FALSE and the Event Log will be complete.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect (e.g. asking for an event log whose format is not supported).

Definition at line 711 of file Tcg2Dxe.c.

◆ Tcg2GetResultOfSetActivePcrBanks()

EFI_STATUS EFIAPI Tcg2GetResultOfSetActivePcrBanks ( IN EFI_TCG2_PROTOCOL This,
OUT UINT32 *  OperationPresent,
OUT UINT32 *  Response 
)

This service retrieves the result of a previous invocation of SetActivePcrBanks.

Parameters
[in]ThisIndicates the calling context
[out]OperationPresentNon-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
[out]ResponseThe response from the SetActivePcrBank request.
Return values
EFI_SUCCESSThe result value could be returned.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect.

Definition at line 1529 of file Tcg2Dxe.c.

◆ Tcg2HashLogExtendEvent()

EFI_STATUS EFIAPI Tcg2HashLogExtendEvent ( IN EFI_TCG2_PROTOCOL This,
IN UINT64  Flags,
IN EFI_PHYSICAL_ADDRESS  DataToHash,
IN UINT64  DataToHashLen,
IN EFI_TCG2_EVENT Event 
)

The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with an opportunity to extend and optionally log events without requiring knowledge of actual TPM commands. The extend operation will occur even if this function cannot create an event log entry (e.g. due to the event log being full).

Parameters
[in]ThisIndicates the calling context
[in]FlagsBitmap providing additional information.
[in]DataToHashPhysical address of the start of the data buffer to be hashed.
[in]DataToHashLenThe length in bytes of the buffer referenced by DataToHash.
[in]EventPointer to data buffer containing information about the event.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_DEVICE_ERRORThe command was unsuccessful.
EFI_VOLUME_FULLThe extend operation occurred, but the event could not be written to one or more event logs.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect.
EFI_UNSUPPORTEDThe PE/COFF image type is not supported.

Definition at line 1308 of file Tcg2Dxe.c.

◆ Tcg2SetActivePCRBanks()

EFI_STATUS EFIAPI Tcg2SetActivePCRBanks ( IN EFI_TCG2_PROTOCOL This,
IN UINT32  ActivePcrBanks 
)

This service sets the currently active PCR banks.

Parameters
[in]ThisIndicates the calling context
[in]ActivePcrBanksBitmap of the requested active PCR banks. At least one bit SHALL be set.
Return values
EFI_SUCCESSThe bitmap in ActivePcrBank parameter is already active.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect.

Definition at line 1475 of file Tcg2Dxe.c.

◆ Tcg2SubmitCommand()

EFI_STATUS EFIAPI Tcg2SubmitCommand ( IN EFI_TCG2_PROTOCOL This,
IN UINT32  InputParameterBlockSize,
IN UINT8 *  InputParameterBlock,
IN UINT32  OutputParameterBlockSize,
IN UINT8 *  OutputParameterBlock 
)

This service enables the sending of commands to the TPM.

Parameters
[in]ThisIndicates the calling context
[in]InputParameterBlockSizeSize of the TPM input parameter block.
[in]InputParameterBlockPointer to the TPM input parameter block.
[in]OutputParameterBlockSizeSize of the TPM output parameter block.
[in]OutputParameterBlockPointer to the TPM output parameter block.
Return values
EFI_SUCCESSThe command byte stream was successfully sent to the device and a response was successfully received.
EFI_DEVICE_ERRORThe command was not successfully sent to the device or a response was not successfully received from the device.
EFI_INVALID_PARAMETEROne or more of the parameters are incorrect.
EFI_BUFFER_TOO_SMALLThe output parameter block is too small.

Definition at line 1399 of file Tcg2Dxe.c.

◆ TcgCommLogEvent()

EFI_STATUS TcgCommLogEvent ( IN OUT TCG_EVENT_LOG_AREA_STRUCT EventLogAreaStruct,
IN VOID *  NewEventHdr,
IN UINT32  NewEventHdrSize,
IN UINT8 *  NewEventData,
IN UINT32  NewEventSize 
)

Add a new entry to the Event Log.

Parameters
[in,out]EventLogAreaStructThe event log area data structure
[in]NewEventHdrPointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
[in]NewEventHdrSizeNew event header size.
[in]NewEventDataPointer to the new event data.
[in]NewEventSizeNew event data size.
Return values
EFI_SUCCESSThe new event log entry was added.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.

Definition at line 846 of file Tcg2Dxe.c.

◆ TcgDxeHashLogExtendEvent()

EFI_STATUS TcgDxeHashLogExtendEvent ( IN UINT64  Flags,
IN UINT8 *  HashData,
IN UINT64  HashDataLen,
IN OUT TCG_PCR_EVENT_HDR NewEventHdr,
IN UINT8 *  NewEventData 
)

Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and add an entry to the Event Log.

Parameters
[in]FlagsBitmap providing additional information.
[in]HashDataPhysical address of the start of the data buffer to be hashed, extended, and logged.
[in]HashDataLenThe length, in bytes, of the buffer referenced by HashData
[in,out]NewEventHdrPointer to a TCG_PCR_EVENT_HDR data structure.
[in]NewEventDataPointer to the new event data.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Definition at line 1219 of file Tcg2Dxe.c.

◆ TcgDxeLogEvent()

EFI_STATUS TcgDxeLogEvent ( IN EFI_TCG2_EVENT_LOG_FORMAT  EventLogFormat,
IN VOID *  NewEventHdr,
IN UINT32  NewEventHdrSize,
IN UINT8 *  NewEventData,
IN UINT32  NewEventSize 
)

Add a new entry to the Event Log.

Parameters
[in]EventLogFormatThe type of the event log for which the information is requested.
[in]NewEventHdrPointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
[in]NewEventHdrSizeNew event header size.
[in]NewEventDataPointer to the new event data.
[in]NewEventSizeNew event data size.
Return values
EFI_SUCCESSThe new event log entry was added.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.

Definition at line 933 of file Tcg2Dxe.c.

◆ TcgDxeLogHashEvent()

EFI_STATUS TcgDxeLogHashEvent ( IN TPML_DIGEST_VALUES DigestList,
IN OUT TCG_PCR_EVENT_HDR NewEventHdr,
IN UINT8 *  NewEventData 
)

Add a new entry to the Event Log.

Parameters
[in]DigestListA list of digest.
[in,out]NewEventHdrPointer to a TCG_PCR_EVENT_HDR data structure.
[in]NewEventDataPointer to the new event data.
Return values
EFI_SUCCESSThe new event log entry was added.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.

Definition at line 1121 of file Tcg2Dxe.c.

◆ TcgMeasureAction()

EFI_STATUS TcgMeasureAction ( IN TPM_PCRINDEX  PCRIndex,
IN CHAR8 *  String 
)

Measure and log an action string, and extend the measurement result into PCR[PCRIndex].

Parameters
[in]PCRIndexPCRIndex to extend
[in]StringA specific string that indicates an Action event.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 1923 of file Tcg2Dxe.c.

Variable Documentation

◆ mBootAttempts

UINTN mBootAttempts = 0

Definition at line 106 of file Tcg2Dxe.c.

◆ mBootVarName

CHAR16 mBootVarName[] = L"BootOrder"

Definition at line 107 of file Tcg2Dxe.c.

◆ mImageHandle

EFI_HANDLE mImageHandle

Definition at line 117 of file Tcg2Dxe.c.

◆ mTcg2EventInfo

TCG2_EVENT_INFO_STRUCT mTcg2EventInfo[]
Initial value:
= {
{ &gTcgEventEntryHobGuid, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 },
{ &gTcgEvent2EntryHobGuid, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 },
}

Definition at line 64 of file Tcg2Dxe.c.

◆ mTcg2Protocol

EFI_TCG2_PROTOCOL mTcg2Protocol
Initial value:
= {
}
EFI_STATUS EFIAPI Tcg2SetActivePCRBanks(IN EFI_TCG2_PROTOCOL *This, IN UINT32 ActivePcrBanks)
Definition: Tcg2Dxe.c:1475
EFI_STATUS EFIAPI Tcg2HashLogExtendEvent(IN EFI_TCG2_PROTOCOL *This, IN UINT64 Flags, IN EFI_PHYSICAL_ADDRESS DataToHash, IN UINT64 DataToHashLen, IN EFI_TCG2_EVENT *Event)
Definition: Tcg2Dxe.c:1308
EFI_STATUS EFIAPI Tcg2GetActivePCRBanks(IN EFI_TCG2_PROTOCOL *This, OUT UINT32 *ActivePcrBanks)
Definition: Tcg2Dxe.c:1451
EFI_STATUS EFIAPI Tcg2GetCapability(IN EFI_TCG2_PROTOCOL *This, IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability)
Definition: Tcg2Dxe.c:380
EFI_STATUS EFIAPI Tcg2SubmitCommand(IN EFI_TCG2_PROTOCOL *This, IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN UINT32 OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
Definition: Tcg2Dxe.c:1399
EFI_STATUS EFIAPI Tcg2GetEventLog(IN EFI_TCG2_PROTOCOL *This, IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat, OUT EFI_PHYSICAL_ADDRESS *EventLogLocation, OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry, OUT BOOLEAN *EventLogTruncated)
Definition: Tcg2Dxe.c:711
EFI_STATUS EFIAPI Tcg2GetResultOfSetActivePcrBanks(IN EFI_TCG2_PROTOCOL *This, OUT UINT32 *OperationPresent, OUT UINT32 *Response)
Definition: Tcg2Dxe.c:1529

Definition at line 1549 of file Tcg2Dxe.c.

◆ mTcgDxeData

TCG_DXE_DATA mTcgDxeData
Initial value:
= {
{
{ 1, 1 },
{ 1, 1 },
EFI_TCG2_BOOT_HASH_ALG_SHA1,
EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2,
TRUE,
TCG2_DEFAULT_MAX_COMMAND_SIZE,
TCG2_DEFAULT_MAX_RESPONSE_SIZE,
0,
0,
0,
},
}
#define TRUE
Definition: Base.h:301

Definition at line 90 of file Tcg2Dxe.c.

◆ mVariableType

VARIABLE_TYPE mVariableType[]
Initial value:
= {
{ EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid },
{ EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid },
{ EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid },
{ EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid },
{ EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid },
}
#define EFI_KEY_EXCHANGE_KEY_NAME
#define EFI_PLATFORM_KEY_NAME
#define EFI_SECURE_BOOT_MODE_NAME
#define EFI_IMAGE_SECURITY_DATABASE1
#define EFI_IMAGE_SECURITY_DATABASE

Definition at line 109 of file Tcg2Dxe.c.