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