]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
SecurityPkg DxeTcgPhysicalPresenceLib: Enable Storage actions.
[mirror_edk2.git] / SecurityPkg / Library / DxeTcgPhysicalPresenceLib / DxeTcgPhysicalPresenceLib.c
1 /** @file
2
3 Execute pending TPM requests from OS or BIOS and Lock TPM.
4
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.
8
9 ExecutePendingTpmRequest() will receive untrusted input and do validation.
10
11 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
12 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
16
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19
20 **/
21
22 #include <PiDxe.h>
23
24 #include <Protocol/TcgService.h>
25 #include <Protocol/VariableLock.h>
26 #include <Library/DebugLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiRuntimeServicesTableLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/PrintLib.h>
34 #include <Library/HiiLib.h>
35 #include <Guid/EventGroup.h>
36 #include <Guid/PhysicalPresenceData.h>
37 #include <Library/TcgPpVendorLib.h>
38 #include <Library/TcgPhysicalPresenceStorageLib.h>
39
40 #define CONFIRM_BUFFER_SIZE 4096
41
42 EFI_HII_HANDLE mPpStringPackHandle;
43
44 /**
45 Get string by string id from HII Interface.
46
47 @param[in] Id String ID.
48
49 @retval CHAR16 * String from ID.
50 @retval NULL If error occurs.
51
52 **/
53 CHAR16 *
54 PhysicalPresenceGetStringById (
55 IN EFI_STRING_ID Id
56 )
57 {
58 return HiiGetString (mPpStringPackHandle, Id, NULL);
59 }
60
61 /**
62 Get TPM physical presence permanent flags.
63
64 @param[in] TcgProtocol EFI TCG Protocol instance.
65 @param[out] LifetimeLock physicalPresenceLifetimeLock permanent flag.
66 @param[out] CmdEnable physicalPresenceCMDEnable permanent flag.
67
68 @retval EFI_SUCCESS Flags were returns successfully.
69 @retval other Failed to locate EFI TCG Protocol.
70
71 **/
72 EFI_STATUS
73 GetTpmCapability (
74 IN EFI_TCG_PROTOCOL *TcgProtocol,
75 OUT BOOLEAN *LifetimeLock,
76 OUT BOOLEAN *CmdEnable
77 )
78 {
79 EFI_STATUS Status;
80 TPM_RQU_COMMAND_HDR *TpmRqu;
81 TPM_RSP_COMMAND_HDR *TpmRsp;
82 UINT32 *SendBufPtr;
83 UINT8 SendBuffer[sizeof (*TpmRqu) + sizeof (UINT32) * 3];
84 TPM_PERMANENT_FLAGS *TpmPermanentFlags;
85 UINT8 RecvBuffer[40];
86
87 //
88 // Fill request header
89 //
90 TpmRsp = (TPM_RSP_COMMAND_HDR*)RecvBuffer;
91 TpmRqu = (TPM_RQU_COMMAND_HDR*)SendBuffer;
92
93 TpmRqu->tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
94 TpmRqu->paramSize = SwapBytes32 (sizeof (SendBuffer));
95 TpmRqu->ordinal = SwapBytes32 (TPM_ORD_GetCapability);
96
97 //
98 // Set request parameter
99 //
100 SendBufPtr = (UINT32*)(TpmRqu + 1);
101 WriteUnaligned32 (SendBufPtr++, SwapBytes32 (TPM_CAP_FLAG));
102 WriteUnaligned32 (SendBufPtr++, SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT)));
103 WriteUnaligned32 (SendBufPtr, SwapBytes32 (TPM_CAP_FLAG_PERMANENT));
104
105 Status = TcgProtocol->PassThroughToTpm (
106 TcgProtocol,
107 sizeof (SendBuffer),
108 (UINT8*)TpmRqu,
109 sizeof (RecvBuffer),
110 (UINT8*)&RecvBuffer
111 );
112 ASSERT_EFI_ERROR (Status);
113 ASSERT (TpmRsp->tag == SwapBytes16 (TPM_TAG_RSP_COMMAND));
114 ASSERT (TpmRsp->returnCode == 0);
115
116 TpmPermanentFlags = (TPM_PERMANENT_FLAGS *)&RecvBuffer[sizeof (TPM_RSP_COMMAND_HDR) + sizeof (UINT32)];
117
118 if (LifetimeLock != NULL) {
119 *LifetimeLock = TpmPermanentFlags->physicalPresenceLifetimeLock;
120 }
121
122 if (CmdEnable != NULL) {
123 *CmdEnable = TpmPermanentFlags->physicalPresenceCMDEnable;
124 }
125
126 return Status;
127 }
128
129 /**
130 Issue TSC_PhysicalPresence command to TPM.
131
132 @param[in] TcgProtocol EFI TCG Protocol instance.
133 @param[in] PhysicalPresence The state to set the TPM's Physical Presence flags.
134
135 @retval EFI_SUCCESS TPM executed the command successfully.
136 @retval EFI_SECURITY_VIOLATION TPM returned error when executing the command.
137 @retval other Failed to locate EFI TCG Protocol.
138
139 **/
140 EFI_STATUS
141 TpmPhysicalPresence (
142 IN EFI_TCG_PROTOCOL *TcgProtocol,
143 IN TPM_PHYSICAL_PRESENCE PhysicalPresence
144 )
145 {
146 EFI_STATUS Status;
147 TPM_RQU_COMMAND_HDR *TpmRqu;
148 TPM_PHYSICAL_PRESENCE *TpmPp;
149 TPM_RSP_COMMAND_HDR TpmRsp;
150 UINT8 Buffer[sizeof (*TpmRqu) + sizeof (*TpmPp)];
151
152 TpmRqu = (TPM_RQU_COMMAND_HDR*)Buffer;
153 TpmPp = (TPM_PHYSICAL_PRESENCE*)(TpmRqu + 1);
154
155 TpmRqu->tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
156 TpmRqu->paramSize = SwapBytes32 (sizeof (Buffer));
157 TpmRqu->ordinal = SwapBytes32 (TSC_ORD_PhysicalPresence);
158 WriteUnaligned16 (TpmPp, (TPM_PHYSICAL_PRESENCE) SwapBytes16 (PhysicalPresence));
159
160 Status = TcgProtocol->PassThroughToTpm (
161 TcgProtocol,
162 sizeof (Buffer),
163 (UINT8*)TpmRqu,
164 sizeof (TpmRsp),
165 (UINT8*)&TpmRsp
166 );
167 ASSERT_EFI_ERROR (Status);
168 ASSERT (TpmRsp.tag == SwapBytes16 (TPM_TAG_RSP_COMMAND));
169 if (TpmRsp.returnCode != 0) {
170 //
171 // If it fails, some requirements may be needed for this command.
172 //
173 return EFI_SECURITY_VIOLATION;
174 }
175
176 return Status;
177 }
178
179 /**
180 Issue a TPM command for which no additional output data will be returned.
181
182 @param[in] TcgProtocol EFI TCG Protocol instance.
183 @param[in] Ordinal TPM command code.
184 @param[in] AdditionalParameterSize Additional parameter size.
185 @param[in] AdditionalParameters Pointer to the Additional paramaters.
186
187 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or
188 receiving response from TPM.
189 @retval Others Return code from the TPM device after command execution.
190
191 **/
192 UINT32
193 TpmCommandNoReturnData (
194 IN EFI_TCG_PROTOCOL *TcgProtocol,
195 IN TPM_COMMAND_CODE Ordinal,
196 IN UINTN AdditionalParameterSize,
197 IN VOID *AdditionalParameters
198 )
199 {
200 EFI_STATUS Status;
201 TPM_RQU_COMMAND_HDR *TpmRqu;
202 TPM_RSP_COMMAND_HDR TpmRsp;
203 UINT32 Size;
204
205 TpmRqu = (TPM_RQU_COMMAND_HDR*) AllocatePool (sizeof (*TpmRqu) + AdditionalParameterSize);
206 if (TpmRqu == NULL) {
207 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
208 }
209
210 TpmRqu->tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
211 Size = (UINT32)(sizeof (*TpmRqu) + AdditionalParameterSize);
212 TpmRqu->paramSize = SwapBytes32 (Size);
213 TpmRqu->ordinal = SwapBytes32 (Ordinal);
214 CopyMem (TpmRqu + 1, AdditionalParameters, AdditionalParameterSize);
215
216 Status = TcgProtocol->PassThroughToTpm (
217 TcgProtocol,
218 Size,
219 (UINT8*)TpmRqu,
220 (UINT32)sizeof (TpmRsp),
221 (UINT8*)&TpmRsp
222 );
223 FreePool (TpmRqu);
224 if (EFI_ERROR (Status) || (TpmRsp.tag != SwapBytes16 (TPM_TAG_RSP_COMMAND))) {
225 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
226 }
227 return SwapBytes32 (TpmRsp.returnCode);
228 }
229
230 /**
231 Execute physical presence operation requested by the OS.
232
233 @param[in] TcgProtocol EFI TCG Protocol instance.
234 @param[in] CommandCode Physical presence operation value.
235 @param[in, out] PpiFlags The physical presence interface flags.
236
237 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Unknown physical presence operation.
238 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or
239 receiving response from TPM.
240 @retval Others Return code from the TPM device after command execution.
241
242 **/
243 UINT32
244 ExecutePhysicalPresence (
245 IN EFI_TCG_PROTOCOL *TcgProtocol,
246 IN UINT32 CommandCode,
247 IN OUT EFI_PHYSICAL_PRESENCE_FLAGS *PpiFlags
248 )
249 {
250 BOOLEAN BoolVal;
251 UINT32 TpmResponse;
252 UINT32 InData[5];
253
254 switch (CommandCode) {
255 case PHYSICAL_PRESENCE_ENABLE:
256 return TpmCommandNoReturnData (
257 TcgProtocol,
258 TPM_ORD_PhysicalEnable,
259 0,
260 NULL
261 );
262
263 case PHYSICAL_PRESENCE_DISABLE:
264 return TpmCommandNoReturnData (
265 TcgProtocol,
266 TPM_ORD_PhysicalDisable,
267 0,
268 NULL
269 );
270
271 case PHYSICAL_PRESENCE_ACTIVATE:
272 BoolVal = FALSE;
273 return TpmCommandNoReturnData (
274 TcgProtocol,
275 TPM_ORD_PhysicalSetDeactivated,
276 sizeof (BoolVal),
277 &BoolVal
278 );
279
280 case PHYSICAL_PRESENCE_DEACTIVATE:
281 BoolVal = TRUE;
282 return TpmCommandNoReturnData (
283 TcgProtocol,
284 TPM_ORD_PhysicalSetDeactivated,
285 sizeof (BoolVal),
286 &BoolVal
287 );
288
289 case PHYSICAL_PRESENCE_CLEAR:
290 return TpmCommandNoReturnData (
291 TcgProtocol,
292 TPM_ORD_ForceClear,
293 0,
294 NULL
295 );
296
297 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:
298 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE, PpiFlags);
299 if (TpmResponse == 0) {
300 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ACTIVATE, PpiFlags);
301 }
302 return TpmResponse;
303
304 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:
305 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_DEACTIVATE, PpiFlags);
306 if (TpmResponse == 0) {
307 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_DISABLE, PpiFlags);
308 }
309 return TpmResponse;
310
311 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:
312 BoolVal = TRUE;
313 return TpmCommandNoReturnData (
314 TcgProtocol,
315 TPM_ORD_SetOwnerInstall,
316 sizeof (BoolVal),
317 &BoolVal
318 );
319
320 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:
321 BoolVal = FALSE;
322 return TpmCommandNoReturnData (
323 TcgProtocol,
324 TPM_ORD_SetOwnerInstall,
325 sizeof (BoolVal),
326 &BoolVal
327 );
328
329 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:
330 //
331 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
332 // PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE will be executed after reboot
333 //
334 if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) {
335 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags);
336 PpiFlags->PPFlags |= TCG_VENDOR_LIB_FLAG_RESET_TRACK;
337 } else {
338 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE, PpiFlags);
339 PpiFlags->PPFlags &= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;
340 }
341 return TpmResponse;
342
343 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:
344 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE, PpiFlags);
345 if (TpmResponse == 0) {
346 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_DEACTIVATE_DISABLE, PpiFlags);
347 }
348 return TpmResponse;
349
350 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:
351 InData[0] = SwapBytes32 (TPM_SET_STCLEAR_DATA); // CapabilityArea
352 InData[1] = SwapBytes32 (sizeof(UINT32)); // SubCapSize
353 InData[2] = SwapBytes32 (TPM_SD_DEFERREDPHYSICALPRESENCE); // SubCap
354 InData[3] = SwapBytes32 (sizeof(UINT32)); // SetValueSize
355 InData[4] = SwapBytes32 (1); // UnownedFieldUpgrade; bit0
356 return TpmCommandNoReturnData (
357 TcgProtocol,
358 TPM_ORD_SetCapability,
359 sizeof (UINT32) * 5,
360 InData
361 );
362
363 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:
364 //
365 // TPM_SetOperatorAuth
366 // This command requires UI to prompt user for Auth data
367 // Here it is NOT implemented
368 //
369 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
370
371 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:
372 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_CLEAR, PpiFlags);
373 if (TpmResponse == 0) {
374 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags);
375 }
376 return TpmResponse;
377
378 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:
379 PpiFlags->PPFlags &= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION;
380 return 0;
381
382 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:
383 PpiFlags->PPFlags |= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION;
384 return 0;
385
386 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:
387 PpiFlags->PPFlags &= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR;
388 return 0;
389
390 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:
391 PpiFlags->PPFlags |= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR;
392 return 0;
393
394 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:
395 PpiFlags->PPFlags &= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE;
396 return 0;
397
398 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:
399 PpiFlags->PPFlags |= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE;
400 return 0;
401
402 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:
403 //
404 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR
405 // PHYSICAL_PRESENCE_CLEAR will be executed after reboot.
406 //
407 if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) {
408 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags);
409 PpiFlags->PPFlags |= TCG_VENDOR_LIB_FLAG_RESET_TRACK;
410 } else {
411 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_CLEAR, PpiFlags);
412 PpiFlags->PPFlags &= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;
413 }
414 return TpmResponse;
415
416 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
417 //
418 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
419 // PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE will be executed after reboot.
420 //
421 if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) {
422 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags);
423 PpiFlags->PPFlags |= TCG_VENDOR_LIB_FLAG_RESET_TRACK;
424 } else {
425 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE, PpiFlags);
426 PpiFlags->PPFlags &= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;
427 }
428 return TpmResponse;
429
430 default:
431 ;
432 }
433 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
434 }
435
436
437 /**
438 Read the specified key for user confirmation.
439
440 @param[in] CautionKey If true, F12 is used as confirm key;
441 If false, F10 is used as confirm key.
442
443 @retval TRUE User confirmed the changes by input.
444 @retval FALSE User discarded the changes or device error.
445
446 **/
447 BOOLEAN
448 ReadUserKey (
449 IN BOOLEAN CautionKey
450 )
451 {
452 EFI_STATUS Status;
453 EFI_INPUT_KEY Key;
454 UINT16 InputKey;
455 UINTN Index;
456
457 InputKey = 0;
458 do {
459 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
460 if (Status == EFI_NOT_READY) {
461 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
462 continue;
463 }
464
465 if (Status == EFI_DEVICE_ERROR) {
466 return FALSE;
467 }
468
469 if (Key.ScanCode == SCAN_ESC) {
470 InputKey = Key.ScanCode;
471 }
472 if ((Key.ScanCode == SCAN_F10) && !CautionKey) {
473 InputKey = Key.ScanCode;
474 }
475 if ((Key.ScanCode == SCAN_F12) && CautionKey) {
476 InputKey = Key.ScanCode;
477 }
478 } while (InputKey == 0);
479
480 if (InputKey != SCAN_ESC) {
481 return TRUE;
482 }
483
484 return FALSE;
485 }
486
487 /**
488 The constructor function register UNI strings into imageHandle.
489
490 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
491
492 @param ImageHandle The firmware allocated handle for the EFI image.
493 @param SystemTable A pointer to the EFI System Table.
494
495 @retval EFI_SUCCESS The constructor successfully added string package.
496 @retval Other value The constructor can't add string package.
497
498 **/
499 EFI_STATUS
500 EFIAPI
501 TcgPhysicalPresenceLibConstructor (
502 IN EFI_HANDLE ImageHandle,
503 IN EFI_SYSTEM_TABLE *SystemTable
504 )
505 {
506 mPpStringPackHandle = HiiAddPackages (&gEfiPhysicalPresenceGuid, ImageHandle, DxeTcgPhysicalPresenceLibStrings, NULL);
507 ASSERT (mPpStringPackHandle != NULL);
508
509 return EFI_SUCCESS;
510 }
511
512 /**
513 Display the confirm text and get user confirmation.
514
515 @param[in] TpmPpCommand The requested TPM physical presence command.
516
517 @retval TRUE The user has confirmed the changes.
518 @retval FALSE The user doesn't confirm the changes.
519 **/
520 BOOLEAN
521 UserConfirm (
522 IN UINT32 TpmPpCommand
523 )
524 {
525 CHAR16 *ConfirmText;
526 CHAR16 *TmpStr1;
527 CHAR16 *TmpStr2;
528 UINTN BufSize;
529 BOOLEAN CautionKey;
530 UINT16 Index;
531 CHAR16 DstStr[81];
532
533 TmpStr2 = NULL;
534 CautionKey = FALSE;
535 BufSize = CONFIRM_BUFFER_SIZE;
536 ConfirmText = AllocateZeroPool (BufSize);
537 ASSERT (ConfirmText != NULL);
538
539 switch (TpmPpCommand) {
540 case PHYSICAL_PRESENCE_ENABLE:
541 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE));
542
543 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
544 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
545 FreePool (TmpStr1);
546
547 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
548 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
549 FreePool (TmpStr1);
550 break;
551
552 case PHYSICAL_PRESENCE_DISABLE:
553 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISABLE));
554
555 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
556 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
557 FreePool (TmpStr1);
558
559 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING));
560 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
561 FreePool (TmpStr1);
562
563 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
564 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
565 FreePool (TmpStr1);
566 break;
567
568 case PHYSICAL_PRESENCE_ACTIVATE:
569 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACTIVATE));
570
571 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
572 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
573 FreePool (TmpStr1);
574
575 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
576 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
577 FreePool (TmpStr1);
578 break;
579
580 case PHYSICAL_PRESENCE_DEACTIVATE:
581 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIVATE));
582
583 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
584 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
585 FreePool (TmpStr1);
586
587 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING));
588 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
589 FreePool (TmpStr1);
590
591 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
592 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
593 FreePool (TmpStr1);
594 break;
595
596 case PHYSICAL_PRESENCE_CLEAR:
597 CautionKey = TRUE;
598 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
599
600 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
601 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
602 FreePool (TmpStr1);
603
604 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
605 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
606 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
607 FreePool (TmpStr1);
608
609 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
610 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
611 FreePool (TmpStr1);
612 break;
613
614 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:
615 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_ACTIVATE));
616
617 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
618 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
619 FreePool (TmpStr1);
620
621 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON));
622 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
623 FreePool (TmpStr1);
624
625 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
626 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
627 FreePool (TmpStr1);
628 break;
629
630 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:
631 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIVATE_DISABLE));
632
633 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
634 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
635 FreePool (TmpStr1);
636
637 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OFF));
638 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
639 FreePool (TmpStr1);
640
641 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING));
642 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
643 FreePool (TmpStr1);
644
645 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
646 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
647 FreePool (TmpStr1);
648 break;
649
650 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:
651 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ALLOW_TAKE_OWNERSHIP));
652
653 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
654 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
655 FreePool (TmpStr1);
656
657 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
658 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
659 FreePool (TmpStr1);
660 break;
661
662 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:
663 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISALLOW_TAKE_OWNERSHIP));
664
665 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
666 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
667 FreePool (TmpStr1);
668
669 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
670 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
671 FreePool (TmpStr1);
672 break;
673
674 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:
675 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_ON));
676
677 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
678 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
679 FreePool (TmpStr1);
680
681 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON));
682 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
683 FreePool (TmpStr1);
684
685 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
686 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
687 FreePool (TmpStr1);
688 break;
689
690 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:
691 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_OFF));
692
693 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
694 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
695 FreePool (TmpStr1);
696
697 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OFF));
698 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
699 FreePool (TmpStr1);
700
701 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING));
702 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
703 FreePool (TmpStr1);
704
705 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
706 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
707 FreePool (TmpStr1);
708 break;
709
710 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:
711 CautionKey = TRUE;
712 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UNOWNED_FIELD_UPGRADE));
713
714 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UPGRADE_HEAD_STR));
715 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
716 FreePool (TmpStr1);
717
718 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_MAINTAIN));
719 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
720 FreePool (TmpStr1);
721
722 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
723 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
724 FreePool (TmpStr1);
725 break;
726
727 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:
728 //
729 // TPM_SetOperatorAuth
730 // This command requires UI to prompt user for Auth data
731 // Here it is NOT implemented
732 //
733 break;
734
735 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:
736 CautionKey = TRUE;
737 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR_TURN_ON));
738
739 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
740 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
741 FreePool (TmpStr1);
742
743 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON));
744 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
745 FreePool (TmpStr1);
746
747 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
748 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
749 FreePool (TmpStr1);
750
751 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR_CONT));
752 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
753 FreePool (TmpStr1);
754
755 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
756 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
757 FreePool (TmpStr1);
758 break;
759
760 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:
761 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_PROVISION));
762
763 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR));
764 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
765 FreePool (TmpStr1);
766
767 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
768 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
769 FreePool (TmpStr1);
770
771 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO));
772 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
773 FreePool (TmpStr1);
774 break;
775
776 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:
777 CautionKey = TRUE;
778 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
779
780 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR));
781 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
782 FreePool (TmpStr1);
783
784 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CLEAR));
785 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
786 FreePool (TmpStr1);
787
788 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
789 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
790 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
791 FreePool (TmpStr1);
792
793 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
794 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
795 FreePool (TmpStr1);
796
797 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO));
798 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
799 FreePool (TmpStr1);
800 break;
801
802 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:
803 CautionKey = TRUE;
804 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_MAINTAIN));
805
806 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR));
807 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
808 FreePool (TmpStr1);
809
810 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_MAINTAIN));
811 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
812 FreePool (TmpStr1);
813
814 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
815 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
816 FreePool (TmpStr1);
817
818 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO));
819 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
820 FreePool (TmpStr1);
821 break;
822
823 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:
824 CautionKey = TRUE;
825 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_ACTIVATE_CLEAR));
826
827 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
828 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
829 FreePool (TmpStr1);
830
831 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
832 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
833 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
834 FreePool (TmpStr1);
835
836 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
837 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
838 FreePool (TmpStr1);
839 break;
840
841 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
842 CautionKey = TRUE;
843 TmpStr2 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE));
844
845 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
846 UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
847 FreePool (TmpStr1);
848
849 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON));
850 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
851 FreePool (TmpStr1);
852
853 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
854 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
855 FreePool (TmpStr1);
856
857 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR_CONT));
858 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
859 FreePool (TmpStr1);
860
861 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY));
862 StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
863 FreePool (TmpStr1);
864 break;
865
866 default:
867 ;
868 }
869
870 if (TmpStr2 == NULL) {
871 FreePool (ConfirmText);
872 return FALSE;
873 }
874
875 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_REJECT_KEY));
876 BufSize -= StrSize (ConfirmText);
877 UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, TmpStr2);
878
879 DstStr[80] = L'\0';
880 for (Index = 0; Index < StrLen (ConfirmText); Index += 80) {
881 StrnCpyS(DstStr, sizeof (DstStr) / sizeof (CHAR16), ConfirmText + Index, sizeof (DstStr) / sizeof (CHAR16) - 1);
882 Print (DstStr);
883 }
884
885 FreePool (TmpStr1);
886 FreePool (TmpStr2);
887 FreePool (ConfirmText);
888
889 if (ReadUserKey (CautionKey)) {
890 return TRUE;
891 }
892
893 return FALSE;
894 }
895
896 /**
897 Check if there is a valid physical presence command request. Also updates parameter value
898 to whether the requested physical presence command already confirmed by user
899
900 @param[in] TcgPpData EFI TCG Physical Presence request data.
901 @param[in] Flags The physical presence interface flags.
902 @param[out] RequestConfirmed If the physical presence operation command required user confirm from UI.
903 True, it indicates the command doesn't require user confirm, or already confirmed
904 in last boot cycle by user.
905 False, it indicates the command need user confirm from UI.
906
907 @retval TRUE Physical Presence operation command is valid.
908 @retval FALSE Physical Presence operation command is invalid.
909
910 **/
911 BOOLEAN
912 HaveValidTpmRequest (
913 IN EFI_PHYSICAL_PRESENCE *TcgPpData,
914 IN EFI_PHYSICAL_PRESENCE_FLAGS Flags,
915 OUT BOOLEAN *RequestConfirmed
916 )
917 {
918 BOOLEAN IsRequestValid;
919
920 *RequestConfirmed = FALSE;
921
922 switch (TcgPpData->PPRequest) {
923 case PHYSICAL_PRESENCE_NO_ACTION:
924 *RequestConfirmed = TRUE;
925 return TRUE;
926 case PHYSICAL_PRESENCE_ENABLE:
927 case PHYSICAL_PRESENCE_DISABLE:
928 case PHYSICAL_PRESENCE_ACTIVATE:
929 case PHYSICAL_PRESENCE_DEACTIVATE:
930 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:
931 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:
932 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:
933 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:
934 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:
935 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:
936 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:
937 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) {
938 *RequestConfirmed = TRUE;
939 }
940 break;
941
942 case PHYSICAL_PRESENCE_CLEAR:
943 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:
944 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0) {
945 *RequestConfirmed = TRUE;
946 }
947 break;
948
949 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:
950 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE) != 0) {
951 *RequestConfirmed = TRUE;
952 }
953 break;
954
955 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:
956 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
957 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0 && (Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) {
958 *RequestConfirmed = TRUE;
959 }
960 break;
961
962 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:
963 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:
964 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:
965 *RequestConfirmed = TRUE;
966 break;
967
968 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:
969 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:
970 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:
971 break;
972
973 default:
974 if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
975 IsRequestValid = TcgPpVendorLibHasValidRequest (TcgPpData->PPRequest, Flags.PPFlags, RequestConfirmed);
976 if (!IsRequestValid) {
977 return FALSE;
978 } else {
979 break;
980 }
981 } else {
982 //
983 // Wrong Physical Presence command
984 //
985 return FALSE;
986 }
987 }
988
989 if ((Flags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) != 0) {
990 //
991 // It had been confirmed in last boot, it doesn't need confirm again.
992 //
993 *RequestConfirmed = TRUE;
994 }
995
996 //
997 // Physical Presence command is correct
998 //
999 return TRUE;
1000 }
1001
1002
1003 /**
1004 Check and execute the requested physical presence command.
1005
1006 Caution: This function may receive untrusted input.
1007 TcgPpData variable is external input, so this function will validate
1008 its data structure to be valid value.
1009
1010 @param[in] TcgProtocol EFI TCG Protocol instance.
1011 @param[in] TcgPpData Point to the physical presence NV variable.
1012 @param[in] Flags The physical presence interface flags.
1013
1014 **/
1015 VOID
1016 ExecutePendingTpmRequest (
1017 IN EFI_TCG_PROTOCOL *TcgProtocol,
1018 IN EFI_PHYSICAL_PRESENCE *TcgPpData,
1019 IN EFI_PHYSICAL_PRESENCE_FLAGS Flags
1020 )
1021 {
1022 EFI_STATUS Status;
1023 UINTN DataSize;
1024 BOOLEAN RequestConfirmed;
1025 EFI_PHYSICAL_PRESENCE_FLAGS NewFlags;
1026 BOOLEAN ResetRequired;
1027 UINT32 NewPPFlags;
1028
1029 if (!HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) {
1030 //
1031 // Invalid operation request.
1032 //
1033 TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
1034 TcgPpData->LastPPRequest = TcgPpData->PPRequest;
1035 TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION;
1036 DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
1037 Status = gRT->SetVariable (
1038 PHYSICAL_PRESENCE_VARIABLE,
1039 &gEfiPhysicalPresenceGuid,
1040 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1041 DataSize,
1042 TcgPpData
1043 );
1044 return;
1045 }
1046
1047 ResetRequired = FALSE;
1048 if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
1049 NewFlags = Flags;
1050 NewPPFlags = NewFlags.PPFlags;
1051 TcgPpData->PPResponse = TcgPpVendorLibExecutePendingRequest (TcgPpData->PPRequest, &NewPPFlags, &ResetRequired);
1052 NewFlags.PPFlags = (UINT8)NewPPFlags;
1053 } else {
1054 if (!RequestConfirmed) {
1055 //
1056 // Print confirm text and wait for approval.
1057 //
1058 RequestConfirmed = UserConfirm (TcgPpData->PPRequest);
1059 }
1060
1061 //
1062 // Execute requested physical presence command
1063 //
1064 TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_USER_ABORT;
1065 NewFlags = Flags;
1066 if (RequestConfirmed) {
1067 TcgPpData->PPResponse = ExecutePhysicalPresence (TcgProtocol, TcgPpData->PPRequest, &NewFlags);
1068 }
1069 }
1070
1071 //
1072 // Save the flags if it is updated.
1073 //
1074 if (CompareMem (&Flags, &NewFlags, sizeof(EFI_PHYSICAL_PRESENCE_FLAGS)) != 0) {
1075 Status = gRT->SetVariable (
1076 PHYSICAL_PRESENCE_FLAGS_VARIABLE,
1077 &gEfiPhysicalPresenceGuid,
1078 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1079 sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),
1080 &NewFlags
1081 );
1082 if (EFI_ERROR (Status)) {
1083 return;
1084 }
1085 }
1086
1087 //
1088 // Clear request
1089 //
1090 if ((NewFlags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) {
1091 TcgPpData->LastPPRequest = TcgPpData->PPRequest;
1092 TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION;
1093 }
1094
1095 //
1096 // Save changes
1097 //
1098 DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
1099 Status = gRT->SetVariable (
1100 PHYSICAL_PRESENCE_VARIABLE,
1101 &gEfiPhysicalPresenceGuid,
1102 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1103 DataSize,
1104 TcgPpData
1105 );
1106 if (EFI_ERROR (Status)) {
1107 return;
1108 }
1109
1110 if (TcgPpData->PPResponse == TCG_PP_OPERATION_RESPONSE_USER_ABORT) {
1111 return;
1112 }
1113
1114 //
1115 // Reset system to make new TPM settings in effect
1116 //
1117 switch (TcgPpData->LastPPRequest) {
1118 case PHYSICAL_PRESENCE_ACTIVATE:
1119 case PHYSICAL_PRESENCE_DEACTIVATE:
1120 case PHYSICAL_PRESENCE_CLEAR:
1121 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:
1122 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:
1123 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:
1124 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:
1125 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:
1126 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:
1127 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:
1128 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
1129 break;
1130 default:
1131 if (TcgPpData->LastPPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
1132 if (ResetRequired) {
1133 break;
1134 } else {
1135 return ;
1136 }
1137 }
1138 if (TcgPpData->PPRequest != PHYSICAL_PRESENCE_NO_ACTION) {
1139 break;
1140 }
1141 return;
1142 }
1143
1144 Print (L"Rebooting system to make TPM settings in effect\n");
1145 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1146 ASSERT (FALSE);
1147 }
1148
1149 /**
1150 Check and execute the pending TPM request and Lock TPM.
1151
1152 The TPM request may come from OS or BIOS. This API will display request information and wait
1153 for user confirmation if TPM request exists. The TPM request will be sent to TPM device after
1154 the TPM request is confirmed, and one or more reset may be required to make TPM request to
1155 take effect. At last, it will lock TPM to prevent TPM state change by malware.
1156
1157 This API should be invoked after console in and console out are all ready as they are required
1158 to display request information and get user input to confirm the request. This API should also
1159 be invoked as early as possible as TPM is locked in this function.
1160
1161 **/
1162 VOID
1163 EFIAPI
1164 TcgPhysicalPresenceLibProcessRequest (
1165 VOID
1166 )
1167 {
1168 EFI_STATUS Status;
1169 BOOLEAN LifetimeLock;
1170 BOOLEAN CmdEnable;
1171 UINTN DataSize;
1172 EFI_PHYSICAL_PRESENCE TcgPpData;
1173 EFI_TCG_PROTOCOL *TcgProtocol;
1174 EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol;
1175 EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;
1176
1177 //
1178 // Process the storage related action first.
1179 //
1180 TcgPhysicalPresenceStorageLibProcessRequest();
1181
1182 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol);
1183 if (EFI_ERROR (Status)) {
1184 return ;
1185 }
1186
1187 //
1188 // Initialize physical presence flags.
1189 //
1190 DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);
1191 Status = gRT->GetVariable (
1192 PHYSICAL_PRESENCE_FLAGS_VARIABLE,
1193 &gEfiPhysicalPresenceGuid,
1194 NULL,
1195 &DataSize,
1196 &PpiFlags
1197 );
1198 if (EFI_ERROR (Status)) {
1199 PpiFlags.PPFlags = TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION;
1200 Status = gRT->SetVariable (
1201 PHYSICAL_PRESENCE_FLAGS_VARIABLE,
1202 &gEfiPhysicalPresenceGuid,
1203 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1204 sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),
1205 &PpiFlags
1206 );
1207 if (EFI_ERROR (Status)) {
1208 DEBUG ((EFI_D_ERROR, "[TPM] Set physical presence flag failed, Status = %r\n", Status));
1209 return ;
1210 }
1211 }
1212 DEBUG ((EFI_D_INFO, "[TPM] PpiFlags = %x\n", PpiFlags.PPFlags));
1213
1214 //
1215 // This flags variable controls whether physical presence is required for TPM command.
1216 // It should be protected from malicious software. We set it as read-only variable here.
1217 //
1218 Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol);
1219 if (!EFI_ERROR (Status)) {
1220 Status = VariableLockProtocol->RequestToLock (
1221 VariableLockProtocol,
1222 PHYSICAL_PRESENCE_FLAGS_VARIABLE,
1223 &gEfiPhysicalPresenceGuid
1224 );
1225 if (EFI_ERROR (Status)) {
1226 DEBUG ((EFI_D_ERROR, "[TPM] Error when lock variable %s, Status = %r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status));
1227 ASSERT_EFI_ERROR (Status);
1228 }
1229 }
1230
1231 //
1232 // Initialize physical presence variable.
1233 //
1234 DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
1235 Status = gRT->GetVariable (
1236 PHYSICAL_PRESENCE_VARIABLE,
1237 &gEfiPhysicalPresenceGuid,
1238 NULL,
1239 &DataSize,
1240 &TcgPpData
1241 );
1242 if (EFI_ERROR (Status)) {
1243 ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData));
1244 DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
1245 Status = gRT->SetVariable (
1246 PHYSICAL_PRESENCE_VARIABLE,
1247 &gEfiPhysicalPresenceGuid,
1248 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1249 DataSize,
1250 &TcgPpData
1251 );
1252 if (EFI_ERROR (Status)) {
1253 DEBUG ((EFI_D_ERROR, "[TPM] Set physical presence variable failed, Status = %r\n", Status));
1254 return;
1255 }
1256 }
1257
1258 DEBUG ((EFI_D_INFO, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags.PPFlags, TcgPpData.PPRequest));
1259
1260 if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) {
1261 //
1262 // No operation request
1263 //
1264 return;
1265 }
1266
1267 Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);
1268 if (EFI_ERROR (Status)) {
1269 return ;
1270 }
1271
1272 if (!CmdEnable) {
1273 if (LifetimeLock) {
1274 //
1275 // physicalPresenceCMDEnable is locked, can't execute physical presence command.
1276 //
1277 return ;
1278 }
1279 Status = TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_CMD_ENABLE);
1280 if (EFI_ERROR (Status)) {
1281 return ;
1282 }
1283 }
1284
1285 //
1286 // Set operator physical presence flags
1287 //
1288 TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_PRESENT);
1289
1290 //
1291 // Execute pending TPM request.
1292 //
1293 ExecutePendingTpmRequest (TcgProtocol, &TcgPpData, PpiFlags);
1294 DEBUG ((EFI_D_INFO, "[TPM] PPResponse = %x\n", TcgPpData.PPResponse));
1295
1296 //
1297 // Lock physical presence.
1298 //
1299 TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_NOTPRESENT | TPM_PHYSICAL_PRESENCE_LOCK);
1300 }
1301
1302 /**
1303 Check if the pending TPM request needs user input to confirm.
1304
1305 The TPM request may come from OS. This API will check if TPM request exists and need user
1306 input to confirmation.
1307
1308 @retval TRUE TPM needs input to confirm user physical presence.
1309 @retval FALSE TPM doesn't need input to confirm user physical presence.
1310
1311 **/
1312 BOOLEAN
1313 EFIAPI
1314 TcgPhysicalPresenceLibNeedUserConfirm(
1315 VOID
1316 )
1317 {
1318 EFI_STATUS Status;
1319 EFI_PHYSICAL_PRESENCE TcgPpData;
1320 UINTN DataSize;
1321 BOOLEAN RequestConfirmed;
1322 BOOLEAN LifetimeLock;
1323 BOOLEAN CmdEnable;
1324 EFI_TCG_PROTOCOL *TcgProtocol;
1325 EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;
1326
1327 //
1328 // Process the storage related action first.
1329 // If confirm need user confirm, just return TRUE.
1330 // else continue check other actions.
1331 //
1332 if (TcgPhysicalPresenceStorageLibNeedUserConfirm()) {
1333 return TRUE;
1334 }
1335
1336 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol);
1337 if (EFI_ERROR (Status)) {
1338 return FALSE;
1339 }
1340
1341 //
1342 // Check Tpm requests
1343 //
1344 DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
1345 Status = gRT->GetVariable (
1346 PHYSICAL_PRESENCE_VARIABLE,
1347 &gEfiPhysicalPresenceGuid,
1348 NULL,
1349 &DataSize,
1350 &TcgPpData
1351 );
1352 if (EFI_ERROR (Status)) {
1353 return FALSE;
1354 }
1355
1356 DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);
1357 Status = gRT->GetVariable (
1358 PHYSICAL_PRESENCE_FLAGS_VARIABLE,
1359 &gEfiPhysicalPresenceGuid,
1360 NULL,
1361 &DataSize,
1362 &PpiFlags
1363 );
1364 if (EFI_ERROR (Status)) {
1365 return FALSE;
1366 }
1367
1368 if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) {
1369 //
1370 // No operation request
1371 //
1372 return FALSE;
1373 }
1374
1375 if (!HaveValidTpmRequest(&TcgPpData, PpiFlags, &RequestConfirmed)) {
1376 //
1377 // Invalid operation request.
1378 //
1379 return FALSE;
1380 }
1381
1382 //
1383 // Check Tpm Capability
1384 //
1385 Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);
1386 if (EFI_ERROR (Status)) {
1387 return FALSE;
1388 }
1389
1390 if (!CmdEnable) {
1391 if (LifetimeLock) {
1392 //
1393 // physicalPresenceCMDEnable is locked, can't execute physical presence command.
1394 //
1395 return FALSE;
1396 }
1397 }
1398
1399 if (!RequestConfirmed) {
1400 //
1401 // Need UI to confirm
1402 //
1403 return TRUE;
1404 }
1405
1406 return FALSE;
1407 }
1408