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