DxeTcgPhysicalPresenceLib.c 50 KB

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