2 Utility functions used by TPM Dxe driver.
4 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <IndustryStandard/Tpm12.h>
16 #include <IndustryStandard/UefiTcgPlatform.h>
17 #include <Library/TpmCommLib.h>
18 #include <Library/BaseMemoryLib.h>
25 @param[in] TpmHandle TPM handle.
26 @param[in] DigestToExtend The 160 bit value representing the event to be recorded.
27 @param[in] PcrIndex The PCR to be updated.
28 @param[out] NewPcrValue New PCR value after extend.
30 @retval EFI_SUCCESS Operation completed successfully.
31 @retval EFI_DEVICE_ERROR The command was unsuccessful.
36 IN TIS_TPM_HANDLE TpmHandle
,
37 IN TPM_DIGEST
*DigestToExtend
,
38 IN TPM_PCRINDEX PcrIndex
,
39 OUT TPM_DIGEST
*NewPcrValue
44 TPM_RQU_COMMAND_HDR CmdHdr
;
45 TPM_RSP_COMMAND_HDR RspHdr
;
47 if (NewPcrValue
== NULL
) {
48 NewPcrValue
= &NewValue
;
51 CmdHdr
.tag
= TPM_TAG_RQU_COMMAND
;
53 sizeof (CmdHdr
) + sizeof (PcrIndex
) + sizeof (*DigestToExtend
);
54 CmdHdr
.ordinal
= TPM_ORD_Extend
;
55 Status
= TisPcExecute (
61 (UINTN
)sizeof (*DigestToExtend
),
64 (UINTN
)sizeof (*NewPcrValue
)
66 if (EFI_ERROR (Status
)) {
69 if (RspHdr
.returnCode
!= 0) {
70 return EFI_DEVICE_ERROR
;
76 Get TPM capability flags.
78 @param[in] TpmHandle TPM handle.
79 @param[in] FlagSubcap Flag subcap.
80 @param[out] FlagBuffer Pointer to the buffer for returned flag structure.
81 @param[in] FlagSize Size of the buffer.
83 @retval EFI_SUCCESS Operation completed successfully.
84 @retval EFI_DEVICE_ERROR The command was unsuccessful.
89 IN TIS_TPM_HANDLE TpmHandle
,
96 TPM_RQU_COMMAND_HDR CmdHdr
;
97 TPM_RSP_COMMAND_HDR RspHdr
;
100 CmdHdr
.tag
= TPM_TAG_RQU_COMMAND
;
101 CmdHdr
.paramSize
= sizeof (CmdHdr
) + sizeof (UINT32
) * 3;
102 CmdHdr
.ordinal
= TPM_ORD_GetCapability
;
104 Status
= TisPcExecute (
116 if (EFI_ERROR (Status
)) {
119 if (RspHdr
.returnCode
!= 0) {
120 return EFI_DEVICE_ERROR
;
126 Add a new entry to the Event Log.
128 @param[in, out] EventLogPtr Pointer to the Event Log data.
129 @param[in, out] LogSize Size of the Event Log.
130 @param[in] MaxSize Maximum size of the Event Log.
131 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
132 @param[in] NewEventData Pointer to the new event data.
134 @retval EFI_SUCCESS The new event log entry was added.
135 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
140 IN OUT UINT8
**EventLogPtr
,
141 IN OUT UINTN
*LogSize
,
143 IN TCG_PCR_EVENT_HDR
*NewEventHdr
,
144 IN UINT8
*NewEventData
150 // Prevent Event Overflow
152 if (NewEventHdr
->EventSize
> (UINTN
)(~0) - sizeof (*NewEventHdr
)) {
153 return EFI_OUT_OF_RESOURCES
;
156 NewLogSize
= sizeof (*NewEventHdr
) + NewEventHdr
->EventSize
;
157 if (NewLogSize
> MaxSize
- *LogSize
) {
158 return EFI_OUT_OF_RESOURCES
;
161 *EventLogPtr
+= *LogSize
;
162 *LogSize
+= NewLogSize
;
163 CopyMem (*EventLogPtr
, NewEventHdr
, sizeof (*NewEventHdr
));
165 *EventLogPtr
+ sizeof (*NewEventHdr
),
167 NewEventHdr
->EventSize