3 Execute pending TPM requests from OS or BIOS and Lock TPM.
5 Caution: This module requires additional review when modified.
6 This driver will have external input - variable.
7 This external input must be validated carefully to avoid security issue.
9 ExecutePendingTpmRequest() will receive untrusted input and do validation.
11 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
12 SPDX-License-Identifier: BSD-2-Clause-Patent
18 #include <Protocol/TcgService.h>
19 #include <Protocol/VariableLock.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/UefiRuntimeServicesTableLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/PrintLib.h>
28 #include <Library/HiiLib.h>
29 #include <Guid/EventGroup.h>
30 #include <Guid/PhysicalPresenceData.h>
31 #include <Library/TcgPpVendorLib.h>
33 #define CONFIRM_BUFFER_SIZE 4096
35 EFI_HII_HANDLE mPpStringPackHandle
;
38 Get string by string id from HII Interface.
40 @param[in] Id String ID.
42 @retval CHAR16 * String from ID.
43 @retval NULL If error occurs.
47 PhysicalPresenceGetStringById (
51 return HiiGetString (mPpStringPackHandle
, Id
, NULL
);
55 Get TPM physical presence permanent flags.
57 @param[in] TcgProtocol EFI TCG Protocol instance.
58 @param[out] LifetimeLock physicalPresenceLifetimeLock permanent flag.
59 @param[out] CmdEnable physicalPresenceCMDEnable permanent flag.
61 @retval EFI_SUCCESS Flags were returns successfully.
62 @retval other Failed to locate EFI TCG Protocol.
67 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
68 OUT BOOLEAN
*LifetimeLock
,
69 OUT BOOLEAN
*CmdEnable
73 TPM_RQU_COMMAND_HDR
*TpmRqu
;
74 TPM_RSP_COMMAND_HDR
*TpmRsp
;
76 UINT8 SendBuffer
[sizeof (*TpmRqu
) + sizeof (UINT32
) * 3];
77 TPM_PERMANENT_FLAGS
*TpmPermanentFlags
;
81 // Fill request header
83 TpmRsp
= (TPM_RSP_COMMAND_HDR
*)RecvBuffer
;
84 TpmRqu
= (TPM_RQU_COMMAND_HDR
*)SendBuffer
;
86 TpmRqu
->tag
= SwapBytes16 (TPM_TAG_RQU_COMMAND
);
87 TpmRqu
->paramSize
= SwapBytes32 (sizeof (SendBuffer
));
88 TpmRqu
->ordinal
= SwapBytes32 (TPM_ORD_GetCapability
);
91 // Set request parameter
93 SendBufPtr
= (UINT32
*)(TpmRqu
+ 1);
94 WriteUnaligned32 (SendBufPtr
++, SwapBytes32 (TPM_CAP_FLAG
));
95 WriteUnaligned32 (SendBufPtr
++, SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT
)));
96 WriteUnaligned32 (SendBufPtr
, SwapBytes32 (TPM_CAP_FLAG_PERMANENT
));
98 Status
= TcgProtocol
->PassThroughToTpm (
105 ASSERT_EFI_ERROR (Status
);
106 ASSERT (TpmRsp
->tag
== SwapBytes16 (TPM_TAG_RSP_COMMAND
));
107 ASSERT (TpmRsp
->returnCode
== 0);
109 TpmPermanentFlags
= (TPM_PERMANENT_FLAGS
*)&RecvBuffer
[sizeof (TPM_RSP_COMMAND_HDR
) + sizeof (UINT32
)];
111 if (LifetimeLock
!= NULL
) {
112 *LifetimeLock
= TpmPermanentFlags
->physicalPresenceLifetimeLock
;
115 if (CmdEnable
!= NULL
) {
116 *CmdEnable
= TpmPermanentFlags
->physicalPresenceCMDEnable
;
123 Issue TSC_PhysicalPresence command to TPM.
125 @param[in] TcgProtocol EFI TCG Protocol instance.
126 @param[in] PhysicalPresence The state to set the TPM's Physical Presence flags.
128 @retval EFI_SUCCESS TPM executed the command successfully.
129 @retval EFI_SECURITY_VIOLATION TPM returned error when executing the command.
130 @retval other Failed to locate EFI TCG Protocol.
134 TpmPhysicalPresence (
135 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
136 IN TPM_PHYSICAL_PRESENCE PhysicalPresence
140 TPM_RQU_COMMAND_HDR
*TpmRqu
;
141 TPM_PHYSICAL_PRESENCE
*TpmPp
;
142 TPM_RSP_COMMAND_HDR TpmRsp
;
143 UINT8 Buffer
[sizeof (*TpmRqu
) + sizeof (*TpmPp
)];
145 TpmRqu
= (TPM_RQU_COMMAND_HDR
*)Buffer
;
146 TpmPp
= (TPM_PHYSICAL_PRESENCE
*)(TpmRqu
+ 1);
148 TpmRqu
->tag
= SwapBytes16 (TPM_TAG_RQU_COMMAND
);
149 TpmRqu
->paramSize
= SwapBytes32 (sizeof (Buffer
));
150 TpmRqu
->ordinal
= SwapBytes32 (TSC_ORD_PhysicalPresence
);
151 WriteUnaligned16 (TpmPp
, (TPM_PHYSICAL_PRESENCE
) SwapBytes16 (PhysicalPresence
));
153 Status
= TcgProtocol
->PassThroughToTpm (
160 ASSERT_EFI_ERROR (Status
);
161 ASSERT (TpmRsp
.tag
== SwapBytes16 (TPM_TAG_RSP_COMMAND
));
162 if (TpmRsp
.returnCode
!= 0) {
164 // If it fails, some requirements may be needed for this command.
166 return EFI_SECURITY_VIOLATION
;
173 Issue a TPM command for which no additional output data will be returned.
175 @param[in] TcgProtocol EFI TCG Protocol instance.
176 @param[in] Ordinal TPM command code.
177 @param[in] AdditionalParameterSize Additional parameter size.
178 @param[in] AdditionalParameters Pointer to the Additional paramaters.
180 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or
181 receiving response from TPM.
182 @retval Others Return code from the TPM device after command execution.
186 TpmCommandNoReturnData (
187 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
188 IN TPM_COMMAND_CODE Ordinal
,
189 IN UINTN AdditionalParameterSize
,
190 IN VOID
*AdditionalParameters
194 TPM_RQU_COMMAND_HDR
*TpmRqu
;
195 TPM_RSP_COMMAND_HDR TpmRsp
;
198 TpmRqu
= (TPM_RQU_COMMAND_HDR
*) AllocatePool (sizeof (*TpmRqu
) + AdditionalParameterSize
);
199 if (TpmRqu
== NULL
) {
200 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE
;
203 TpmRqu
->tag
= SwapBytes16 (TPM_TAG_RQU_COMMAND
);
204 Size
= (UINT32
)(sizeof (*TpmRqu
) + AdditionalParameterSize
);
205 TpmRqu
->paramSize
= SwapBytes32 (Size
);
206 TpmRqu
->ordinal
= SwapBytes32 (Ordinal
);
207 CopyMem (TpmRqu
+ 1, AdditionalParameters
, AdditionalParameterSize
);
209 Status
= TcgProtocol
->PassThroughToTpm (
213 (UINT32
)sizeof (TpmRsp
),
217 if (EFI_ERROR (Status
) || (TpmRsp
.tag
!= SwapBytes16 (TPM_TAG_RSP_COMMAND
))) {
218 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE
;
220 return SwapBytes32 (TpmRsp
.returnCode
);
224 Execute physical presence operation requested by the OS.
226 @param[in] TcgProtocol EFI TCG Protocol instance.
227 @param[in] CommandCode Physical presence operation value.
228 @param[in, out] PpiFlags The physical presence interface flags.
230 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Unknown physical presence operation.
231 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or
232 receiving response from TPM.
233 @retval Others Return code from the TPM device after command execution.
237 ExecutePhysicalPresence (
238 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
239 IN UINT32 CommandCode
,
240 IN OUT EFI_PHYSICAL_PRESENCE_FLAGS
*PpiFlags
247 switch (CommandCode
) {
248 case PHYSICAL_PRESENCE_ENABLE
:
249 return TpmCommandNoReturnData (
251 TPM_ORD_PhysicalEnable
,
256 case PHYSICAL_PRESENCE_DISABLE
:
257 return TpmCommandNoReturnData (
259 TPM_ORD_PhysicalDisable
,
264 case PHYSICAL_PRESENCE_ACTIVATE
:
266 return TpmCommandNoReturnData (
268 TPM_ORD_PhysicalSetDeactivated
,
273 case PHYSICAL_PRESENCE_DEACTIVATE
:
275 return TpmCommandNoReturnData (
277 TPM_ORD_PhysicalSetDeactivated
,
282 case PHYSICAL_PRESENCE_CLEAR
:
283 return TpmCommandNoReturnData (
290 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE
:
291 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_ENABLE
, PpiFlags
);
292 if (TpmResponse
== 0) {
293 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_ACTIVATE
, PpiFlags
);
297 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
:
298 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_DEACTIVATE
, PpiFlags
);
299 if (TpmResponse
== 0) {
300 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_DISABLE
, PpiFlags
);
304 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
:
306 return TpmCommandNoReturnData (
308 TPM_ORD_SetOwnerInstall
,
313 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE
:
315 return TpmCommandNoReturnData (
317 TPM_ORD_SetOwnerInstall
,
322 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE
:
324 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
325 // PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE will be executed after reboot
327 if ((PpiFlags
->PPFlags
& TCG_VENDOR_LIB_FLAG_RESET_TRACK
) == 0) {
328 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_ENABLE_ACTIVATE
, PpiFlags
);
329 PpiFlags
->PPFlags
|= TCG_VENDOR_LIB_FLAG_RESET_TRACK
;
331 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
, PpiFlags
);
332 PpiFlags
->PPFlags
&= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK
;
336 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE
:
337 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE
, PpiFlags
);
338 if (TpmResponse
== 0) {
339 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
, PpiFlags
);
343 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE
:
344 InData
[0] = SwapBytes32 (TPM_SET_STCLEAR_DATA
); // CapabilityArea
345 InData
[1] = SwapBytes32 (sizeof(UINT32
)); // SubCapSize
346 InData
[2] = SwapBytes32 (TPM_SD_DEFERREDPHYSICALPRESENCE
); // SubCap
347 InData
[3] = SwapBytes32 (sizeof(UINT32
)); // SetValueSize
348 InData
[4] = SwapBytes32 (1); // UnownedFieldUpgrade; bit0
349 return TpmCommandNoReturnData (
351 TPM_ORD_SetCapability
,
356 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
:
358 // TPM_SetOperatorAuth
359 // This command requires UI to prompt user for Auth data
360 // Here it is NOT implemented
362 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE
;
364 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
:
365 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_CLEAR
, PpiFlags
);
366 if (TpmResponse
== 0) {
367 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_ENABLE_ACTIVATE
, PpiFlags
);
371 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE
:
372 PpiFlags
->PPFlags
&= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION
;
375 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE
:
376 PpiFlags
->PPFlags
|= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION
;
379 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE
:
380 PpiFlags
->PPFlags
&= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR
;
383 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE
:
384 PpiFlags
->PPFlags
|= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR
;
387 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE
:
388 PpiFlags
->PPFlags
&= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE
;
391 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE
:
392 PpiFlags
->PPFlags
|= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE
;
395 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR
:
397 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR
398 // PHYSICAL_PRESENCE_CLEAR will be executed after reboot.
400 if ((PpiFlags
->PPFlags
& TCG_VENDOR_LIB_FLAG_RESET_TRACK
) == 0) {
401 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_ENABLE_ACTIVATE
, PpiFlags
);
402 PpiFlags
->PPFlags
|= TCG_VENDOR_LIB_FLAG_RESET_TRACK
;
404 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_CLEAR
, PpiFlags
);
405 PpiFlags
->PPFlags
&= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK
;
409 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
:
411 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
412 // PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE will be executed after reboot.
414 if ((PpiFlags
->PPFlags
& TCG_VENDOR_LIB_FLAG_RESET_TRACK
) == 0) {
415 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_ENABLE_ACTIVATE
, PpiFlags
);
416 PpiFlags
->PPFlags
|= TCG_VENDOR_LIB_FLAG_RESET_TRACK
;
418 TpmResponse
= ExecutePhysicalPresence (TcgProtocol
, PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
, PpiFlags
);
419 PpiFlags
->PPFlags
&= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK
;
426 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE
;
431 Read the specified key for user confirmation.
433 @param[in] CautionKey If true, F12 is used as confirm key;
434 If false, F10 is used as confirm key.
436 @retval TRUE User confirmed the changes by input.
437 @retval FALSE User discarded the changes or device error.
442 IN BOOLEAN CautionKey
452 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
453 if (Status
== EFI_NOT_READY
) {
454 gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &Index
);
458 if (Status
== EFI_DEVICE_ERROR
) {
462 if (Key
.ScanCode
== SCAN_ESC
) {
463 InputKey
= Key
.ScanCode
;
465 if ((Key
.ScanCode
== SCAN_F10
) && !CautionKey
) {
466 InputKey
= Key
.ScanCode
;
468 if ((Key
.ScanCode
== SCAN_F12
) && CautionKey
) {
469 InputKey
= Key
.ScanCode
;
471 } while (InputKey
== 0);
473 if (InputKey
!= SCAN_ESC
) {
481 The constructor function register UNI strings into imageHandle.
483 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
485 @param ImageHandle The firmware allocated handle for the EFI image.
486 @param SystemTable A pointer to the EFI System Table.
488 @retval EFI_SUCCESS The constructor successfully added string package.
489 @retval Other value The constructor can't add string package.
494 TcgPhysicalPresenceLibConstructor (
495 IN EFI_HANDLE ImageHandle
,
496 IN EFI_SYSTEM_TABLE
*SystemTable
499 mPpStringPackHandle
= HiiAddPackages (&gEfiPhysicalPresenceGuid
, ImageHandle
, DxeTcgPhysicalPresenceLibStrings
, NULL
);
500 ASSERT (mPpStringPackHandle
!= NULL
);
506 Display the confirm text and get user confirmation.
508 @param[in] TpmPpCommand The requested TPM physical presence command.
510 @retval TRUE The user has confirmed the changes.
511 @retval FALSE The user doesn't confirm the changes.
515 IN UINT32 TpmPpCommand
528 BufSize
= CONFIRM_BUFFER_SIZE
;
529 ConfirmText
= AllocateZeroPool (BufSize
);
530 ASSERT (ConfirmText
!= NULL
);
532 switch (TpmPpCommand
) {
533 case PHYSICAL_PRESENCE_ENABLE
:
534 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE
));
536 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
537 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
540 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
541 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
545 case PHYSICAL_PRESENCE_DISABLE
:
546 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISABLE
));
548 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
549 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
552 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING
));
553 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
556 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
557 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
561 case PHYSICAL_PRESENCE_ACTIVATE
:
562 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACTIVATE
));
564 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
565 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
568 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
569 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
573 case PHYSICAL_PRESENCE_DEACTIVATE
:
574 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIVATE
));
576 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
577 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
580 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING
));
581 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
584 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
585 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
589 case PHYSICAL_PRESENCE_CLEAR
:
591 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR
));
593 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
594 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
597 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR
));
598 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
599 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), L
" \n\n", (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
602 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
603 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
607 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE
:
608 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_ACTIVATE
));
610 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
611 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
614 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON
));
615 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
618 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
619 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
623 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
:
624 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIVATE_DISABLE
));
626 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
627 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
630 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OFF
));
631 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
634 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING
));
635 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
638 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
639 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
643 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
:
644 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ALLOW_TAKE_OWNERSHIP
));
646 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
647 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
650 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
651 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
655 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE
:
656 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISALLOW_TAKE_OWNERSHIP
));
658 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
659 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
662 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
663 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
667 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE
:
668 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_ON
));
670 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
671 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
674 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON
));
675 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
678 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
679 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
683 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE
:
684 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_OFF
));
686 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
687 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
690 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OFF
));
691 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
694 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING
));
695 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
698 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
699 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
703 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE
:
705 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UNOWNED_FIELD_UPGRADE
));
707 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UPGRADE_HEAD_STR
));
708 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
711 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_MAINTAIN
));
712 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
715 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
716 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
720 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
:
722 // TPM_SetOperatorAuth
723 // This command requires UI to prompt user for Auth data
724 // Here it is NOT implemented
728 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
:
730 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR_TURN_ON
));
732 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
733 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
736 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON
));
737 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
740 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR
));
741 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
744 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR_CONT
));
745 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
748 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
749 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
753 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE
:
754 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_PROVISION
));
756 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR
));
757 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
760 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY
));
761 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
764 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO
));
765 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
769 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE
:
771 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR
));
773 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR
));
774 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
777 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CLEAR
));
778 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
781 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR
));
782 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
783 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), L
" \n\n", (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
786 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
787 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
790 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO
));
791 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
795 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE
:
797 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_MAINTAIN
));
799 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR
));
800 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
803 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_MAINTAIN
));
804 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
807 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
808 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
811 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO
));
812 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
816 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR
:
818 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_ACTIVATE_CLEAR
));
820 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
821 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
824 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR
));
825 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
826 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), L
" \n\n", (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
829 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
830 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
834 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
:
836 TmpStr2
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
));
838 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR
));
839 UnicodeSPrint (ConfirmText
, BufSize
, TmpStr1
, TmpStr2
);
842 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON
));
843 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
846 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR
));
847 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
850 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR_CONT
));
851 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
854 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY
));
855 StrnCatS (ConfirmText
, BufSize
/ sizeof (CHAR16
), TmpStr1
, (BufSize
/ sizeof (CHAR16
)) - StrLen (ConfirmText
) - 1);
863 if (TmpStr2
== NULL
) {
864 FreePool (ConfirmText
);
868 TmpStr1
= PhysicalPresenceGetStringById (STRING_TOKEN (TPM_REJECT_KEY
));
869 BufSize
-= StrSize (ConfirmText
);
870 UnicodeSPrint (ConfirmText
+ StrLen (ConfirmText
), BufSize
, TmpStr1
, TmpStr2
);
873 for (Index
= 0; Index
< StrLen (ConfirmText
); Index
+= 80) {
874 StrnCpyS(DstStr
, sizeof (DstStr
) / sizeof (CHAR16
), ConfirmText
+ Index
, sizeof (DstStr
) / sizeof (CHAR16
) - 1);
880 FreePool (ConfirmText
);
882 if (ReadUserKey (CautionKey
)) {
890 Check if there is a valid physical presence command request. Also updates parameter value
891 to whether the requested physical presence command already confirmed by user
893 @param[in] TcgPpData EFI TCG Physical Presence request data.
894 @param[in] Flags The physical presence interface flags.
895 @param[out] RequestConfirmed If the physical presence operation command required user confirm from UI.
896 True, it indicates the command doesn't require user confirm, or already confirmed
897 in last boot cycle by user.
898 False, it indicates the command need user confirm from UI.
900 @retval TRUE Physical Presence operation command is valid.
901 @retval FALSE Physical Presence operation command is invalid.
905 HaveValidTpmRequest (
906 IN EFI_PHYSICAL_PRESENCE
*TcgPpData
,
907 IN EFI_PHYSICAL_PRESENCE_FLAGS Flags
,
908 OUT BOOLEAN
*RequestConfirmed
911 BOOLEAN IsRequestValid
;
913 *RequestConfirmed
= FALSE
;
915 switch (TcgPpData
->PPRequest
) {
916 case PHYSICAL_PRESENCE_NO_ACTION
:
917 *RequestConfirmed
= TRUE
;
919 case PHYSICAL_PRESENCE_ENABLE
:
920 case PHYSICAL_PRESENCE_DISABLE
:
921 case PHYSICAL_PRESENCE_ACTIVATE
:
922 case PHYSICAL_PRESENCE_DEACTIVATE
:
923 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE
:
924 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
:
925 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
:
926 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE
:
927 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE
:
928 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE
:
929 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
:
930 if ((Flags
.PPFlags
& TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION
) != 0) {
931 *RequestConfirmed
= TRUE
;
935 case PHYSICAL_PRESENCE_CLEAR
:
936 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR
:
937 if ((Flags
.PPFlags
& TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR
) != 0) {
938 *RequestConfirmed
= TRUE
;
942 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE
:
943 if ((Flags
.PPFlags
& TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE
) != 0) {
944 *RequestConfirmed
= TRUE
;
948 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
:
949 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
:
950 if ((Flags
.PPFlags
& TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR
) != 0 && (Flags
.PPFlags
& TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION
) != 0) {
951 *RequestConfirmed
= TRUE
;
955 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE
:
956 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE
:
957 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE
:
958 *RequestConfirmed
= TRUE
;
961 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE
:
962 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE
:
963 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE
:
967 if (TcgPpData
->PPRequest
>= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) {
968 IsRequestValid
= TcgPpVendorLibHasValidRequest (TcgPpData
->PPRequest
, Flags
.PPFlags
, RequestConfirmed
);
969 if (!IsRequestValid
) {
976 // Wrong Physical Presence command
982 if ((Flags
.PPFlags
& TCG_VENDOR_LIB_FLAG_RESET_TRACK
) != 0) {
984 // It had been confirmed in last boot, it doesn't need confirm again.
986 *RequestConfirmed
= TRUE
;
990 // Physical Presence command is correct
997 Check and execute the requested physical presence command.
999 Caution: This function may receive untrusted input.
1000 TcgPpData variable is external input, so this function will validate
1001 its data structure to be valid value.
1003 @param[in] TcgProtocol EFI TCG Protocol instance.
1004 @param[in] TcgPpData Point to the physical presence NV variable.
1005 @param[in] Flags The physical presence interface flags.
1009 ExecutePendingTpmRequest (
1010 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
1011 IN EFI_PHYSICAL_PRESENCE
*TcgPpData
,
1012 IN EFI_PHYSICAL_PRESENCE_FLAGS Flags
1017 BOOLEAN RequestConfirmed
;
1018 EFI_PHYSICAL_PRESENCE_FLAGS NewFlags
;
1019 BOOLEAN ResetRequired
;
1022 if (!HaveValidTpmRequest(TcgPpData
, Flags
, &RequestConfirmed
)) {
1024 // Invalid operation request.
1026 TcgPpData
->PPResponse
= TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE
;
1027 TcgPpData
->LastPPRequest
= TcgPpData
->PPRequest
;
1028 TcgPpData
->PPRequest
= PHYSICAL_PRESENCE_NO_ACTION
;
1029 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
1030 Status
= gRT
->SetVariable (
1031 PHYSICAL_PRESENCE_VARIABLE
,
1032 &gEfiPhysicalPresenceGuid
,
1033 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1040 ResetRequired
= FALSE
;
1041 if (TcgPpData
->PPRequest
>= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) {
1043 NewPPFlags
= NewFlags
.PPFlags
;
1044 TcgPpData
->PPResponse
= TcgPpVendorLibExecutePendingRequest (TcgPpData
->PPRequest
, &NewPPFlags
, &ResetRequired
);
1045 NewFlags
.PPFlags
= (UINT8
)NewPPFlags
;
1047 if (!RequestConfirmed
) {
1049 // Print confirm text and wait for approval.
1051 RequestConfirmed
= UserConfirm (TcgPpData
->PPRequest
);
1055 // Execute requested physical presence command
1057 TcgPpData
->PPResponse
= TCG_PP_OPERATION_RESPONSE_USER_ABORT
;
1059 if (RequestConfirmed
) {
1060 TcgPpData
->PPResponse
= ExecutePhysicalPresence (TcgProtocol
, TcgPpData
->PPRequest
, &NewFlags
);
1065 // Save the flags if it is updated.
1067 if (CompareMem (&Flags
, &NewFlags
, sizeof(EFI_PHYSICAL_PRESENCE_FLAGS
)) != 0) {
1068 Status
= gRT
->SetVariable (
1069 PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
1070 &gEfiPhysicalPresenceGuid
,
1071 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1072 sizeof (EFI_PHYSICAL_PRESENCE_FLAGS
),
1075 if (EFI_ERROR (Status
)) {
1083 if ((NewFlags
.PPFlags
& TCG_VENDOR_LIB_FLAG_RESET_TRACK
) == 0) {
1084 TcgPpData
->LastPPRequest
= TcgPpData
->PPRequest
;
1085 TcgPpData
->PPRequest
= PHYSICAL_PRESENCE_NO_ACTION
;
1091 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
1092 Status
= gRT
->SetVariable (
1093 PHYSICAL_PRESENCE_VARIABLE
,
1094 &gEfiPhysicalPresenceGuid
,
1095 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1099 if (EFI_ERROR (Status
)) {
1103 if (TcgPpData
->PPResponse
== TCG_PP_OPERATION_RESPONSE_USER_ABORT
) {
1108 // Reset system to make new TPM settings in effect
1110 switch (TcgPpData
->LastPPRequest
) {
1111 case PHYSICAL_PRESENCE_ACTIVATE
:
1112 case PHYSICAL_PRESENCE_DEACTIVATE
:
1113 case PHYSICAL_PRESENCE_CLEAR
:
1114 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE
:
1115 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
:
1116 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE
:
1117 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE
:
1118 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE
:
1119 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
:
1120 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR
:
1121 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
:
1124 if (TcgPpData
->LastPPRequest
>= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) {
1125 if (ResetRequired
) {
1131 if (TcgPpData
->PPRequest
!= PHYSICAL_PRESENCE_NO_ACTION
) {
1137 Print (L
"Rebooting system to make TPM settings in effect\n");
1138 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
1143 Check and execute the pending TPM request and Lock TPM.
1145 The TPM request may come from OS or BIOS. This API will display request information and wait
1146 for user confirmation if TPM request exists. The TPM request will be sent to TPM device after
1147 the TPM request is confirmed, and one or more reset may be required to make TPM request to
1148 take effect. At last, it will lock TPM to prevent TPM state change by malware.
1150 This API should be invoked after console in and console out are all ready as they are required
1151 to display request information and get user input to confirm the request. This API should also
1152 be invoked as early as possible as TPM is locked in this function.
1157 TcgPhysicalPresenceLibProcessRequest (
1162 BOOLEAN LifetimeLock
;
1165 EFI_PHYSICAL_PRESENCE TcgPpData
;
1166 EFI_TCG_PROTOCOL
*TcgProtocol
;
1167 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLockProtocol
;
1168 EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags
;
1170 Status
= gBS
->LocateProtocol (&gEfiTcgProtocolGuid
, NULL
, (VOID
**)&TcgProtocol
);
1171 if (EFI_ERROR (Status
)) {
1176 // Initialize physical presence flags.
1178 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE_FLAGS
);
1179 Status
= gRT
->GetVariable (
1180 PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
1181 &gEfiPhysicalPresenceGuid
,
1186 if (EFI_ERROR (Status
)) {
1187 PpiFlags
.PPFlags
= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION
;
1188 Status
= gRT
->SetVariable (
1189 PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
1190 &gEfiPhysicalPresenceGuid
,
1191 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1192 sizeof (EFI_PHYSICAL_PRESENCE_FLAGS
),
1195 if (EFI_ERROR (Status
)) {
1196 DEBUG ((EFI_D_ERROR
, "[TPM] Set physical presence flag failed, Status = %r\n", Status
));
1200 DEBUG ((EFI_D_INFO
, "[TPM] PpiFlags = %x\n", PpiFlags
.PPFlags
));
1203 // This flags variable controls whether physical presence is required for TPM command.
1204 // It should be protected from malicious software. We set it as read-only variable here.
1206 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**)&VariableLockProtocol
);
1207 if (!EFI_ERROR (Status
)) {
1208 Status
= VariableLockProtocol
->RequestToLock (
1209 VariableLockProtocol
,
1210 PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
1211 &gEfiPhysicalPresenceGuid
1213 if (EFI_ERROR (Status
)) {
1214 DEBUG ((EFI_D_ERROR
, "[TPM] Error when lock variable %s, Status = %r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE
, Status
));
1215 ASSERT_EFI_ERROR (Status
);
1220 // Initialize physical presence variable.
1222 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
1223 Status
= gRT
->GetVariable (
1224 PHYSICAL_PRESENCE_VARIABLE
,
1225 &gEfiPhysicalPresenceGuid
,
1230 if (EFI_ERROR (Status
)) {
1231 ZeroMem ((VOID
*)&TcgPpData
, sizeof (TcgPpData
));
1232 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
1233 Status
= gRT
->SetVariable (
1234 PHYSICAL_PRESENCE_VARIABLE
,
1235 &gEfiPhysicalPresenceGuid
,
1236 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1240 if (EFI_ERROR (Status
)) {
1241 DEBUG ((EFI_D_ERROR
, "[TPM] Set physical presence variable failed, Status = %r\n", Status
));
1246 DEBUG ((EFI_D_INFO
, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags
.PPFlags
, TcgPpData
.PPRequest
));
1248 if (TcgPpData
.PPRequest
== PHYSICAL_PRESENCE_NO_ACTION
) {
1250 // No operation request
1255 Status
= GetTpmCapability (TcgProtocol
, &LifetimeLock
, &CmdEnable
);
1256 if (EFI_ERROR (Status
)) {
1263 // physicalPresenceCMDEnable is locked, can't execute physical presence command.
1267 Status
= TpmPhysicalPresence (TcgProtocol
, TPM_PHYSICAL_PRESENCE_CMD_ENABLE
);
1268 if (EFI_ERROR (Status
)) {
1274 // Set operator physical presence flags
1276 TpmPhysicalPresence (TcgProtocol
, TPM_PHYSICAL_PRESENCE_PRESENT
);
1279 // Execute pending TPM request.
1281 ExecutePendingTpmRequest (TcgProtocol
, &TcgPpData
, PpiFlags
);
1282 DEBUG ((EFI_D_INFO
, "[TPM] PPResponse = %x\n", TcgPpData
.PPResponse
));
1285 // Lock physical presence.
1287 TpmPhysicalPresence (TcgProtocol
, TPM_PHYSICAL_PRESENCE_NOTPRESENT
| TPM_PHYSICAL_PRESENCE_LOCK
);
1291 Check if the pending TPM request needs user input to confirm.
1293 The TPM request may come from OS. This API will check if TPM request exists and need user
1294 input to confirmation.
1296 @retval TRUE TPM needs input to confirm user physical presence.
1297 @retval FALSE TPM doesn't need input to confirm user physical presence.
1302 TcgPhysicalPresenceLibNeedUserConfirm(
1307 EFI_PHYSICAL_PRESENCE TcgPpData
;
1309 BOOLEAN RequestConfirmed
;
1310 BOOLEAN LifetimeLock
;
1312 EFI_TCG_PROTOCOL
*TcgProtocol
;
1313 EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags
;
1315 Status
= gBS
->LocateProtocol (&gEfiTcgProtocolGuid
, NULL
, (VOID
**)&TcgProtocol
);
1316 if (EFI_ERROR (Status
)) {
1321 // Check Tpm requests
1323 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
1324 Status
= gRT
->GetVariable (
1325 PHYSICAL_PRESENCE_VARIABLE
,
1326 &gEfiPhysicalPresenceGuid
,
1331 if (EFI_ERROR (Status
)) {
1335 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE_FLAGS
);
1336 Status
= gRT
->GetVariable (
1337 PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
1338 &gEfiPhysicalPresenceGuid
,
1343 if (EFI_ERROR (Status
)) {
1347 if (TcgPpData
.PPRequest
== PHYSICAL_PRESENCE_NO_ACTION
) {
1349 // No operation request
1354 if (!HaveValidTpmRequest(&TcgPpData
, PpiFlags
, &RequestConfirmed
)) {
1356 // Invalid operation request.
1362 // Check Tpm Capability
1364 Status
= GetTpmCapability (TcgProtocol
, &LifetimeLock
, &CmdEnable
);
1365 if (EFI_ERROR (Status
)) {
1372 // physicalPresenceCMDEnable is locked, can't execute physical presence command.
1378 if (!RequestConfirmed
) {
1380 // Need UI to confirm