SecurityPkg: Add TPM PTP detection in TPM12 device lib.
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Config / Tcg2ConfigImpl.c
CommitLineData
1abfa4ce
JY
1/** @file\r
2 HII Config Access protocol implementation of TCG2 configuration module.\r
3 NOTE: This module is only for reference only, each platform should have its own setup page.\r
4\r
5Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials \r
7are licensed and made available under the terms and conditions of the BSD License \r
8which accompanies this distribution. The full text of the license may be found at \r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "Tcg2ConfigImpl.h"\r
17#include <Library/PcdLib.h>\r
18#include <Library/Tpm2CommandLib.h>\r
19#include <Guid/TpmInstance.h>\r
20\r
21#define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)\r
22\r
23TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;\r
24\r
25TCG2_CONFIG_PRIVATE_DATA *mTcg2ConfigPrivateDate;\r
26TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate = {\r
27 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE,\r
28 {\r
29 Tcg2ExtractConfig,\r
30 Tcg2RouteConfig,\r
31 Tcg2Callback\r
32 }\r
33};\r
34\r
35HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath = {\r
36 {\r
37 {\r
38 HARDWARE_DEVICE_PATH,\r
39 HW_VENDOR_DP,\r
40 {\r
41 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
42 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
43 }\r
44 },\r
45 TCG2_CONFIG_FORM_SET_GUID\r
46 },\r
47 {\r
48 END_DEVICE_PATH_TYPE,\r
49 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
50 { \r
51 (UINT8) (END_DEVICE_PATH_LENGTH),\r
52 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
53 }\r
54 }\r
55};\r
56\r
57UINT8 mCurrentPpRequest;\r
58\r
59/**\r
60 This function allows a caller to extract the current configuration for one\r
61 or more named elements from the target driver.\r
62\r
63 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
64 @param[in] Request A null-terminated Unicode string in\r
65 <ConfigRequest> format.\r
66 @param[out] Progress On return, points to a character in the Request\r
67 string. Points to the string's null terminator if\r
68 request was successful. Points to the most recent\r
69 '&' before the first failing name/value pair (or\r
70 the beginning of the string if the failure is in\r
71 the first name/value pair) if the request was not\r
72 successful.\r
73 @param[out] Results A null-terminated Unicode string in\r
74 <ConfigAltResp> format which has all values filled\r
75 in for the names in the Request string. String to\r
76 be allocated by the called function.\r
77\r
78 @retval EFI_SUCCESS The Results is filled with the requested values.\r
79 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
80 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
81 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
82 driver.\r
83\r
84**/\r
85EFI_STATUS\r
86EFIAPI\r
87Tcg2ExtractConfig (\r
88 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
89 IN CONST EFI_STRING Request,\r
90 OUT EFI_STRING *Progress,\r
91 OUT EFI_STRING *Results\r
92 )\r
93{\r
94 if (Progress == NULL || Results == NULL) {\r
95 return EFI_INVALID_PARAMETER;\r
96 }\r
97\r
98 *Progress = Request;\r
99 return EFI_NOT_FOUND;\r
100}\r
101\r
102/**\r
103 Save TPM request to variable space.\r
104\r
105 @param[in] PpRequest Physical Presence request command.\r
106\r
107 @retval EFI_SUCCESS The operation is finished successfully.\r
108 @retval Others Other errors as indicated.\r
109\r
110**/\r
111EFI_STATUS\r
112SaveTcg2PpRequest (\r
113 IN UINT8 PpRequest\r
114 )\r
115{\r
116 UINT32 ReturnCode;\r
117 EFI_STATUS Status;\r
118\r
119 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest, 0);\r
120 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
121 mCurrentPpRequest = PpRequest;\r
122 Status = EFI_SUCCESS;\r
123 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
124 Status = EFI_OUT_OF_RESOURCES;\r
125 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
126 Status = EFI_UNSUPPORTED;\r
127 } else {\r
128 Status = EFI_DEVICE_ERROR;\r
129 }\r
130\r
131 return Status;\r
132}\r
133\r
134/**\r
135 Save TPM request to variable space.\r
136\r
137 @param[in] PpRequestParameter Physical Presence request parameter.\r
138\r
139 @retval EFI_SUCCESS The operation is finished successfully.\r
140 @retval Others Other errors as indicated.\r
141\r
142**/\r
143EFI_STATUS\r
144SaveTcg2PpRequestParameter (\r
145 IN UINT32 PpRequestParameter\r
146 )\r
147{\r
148 UINT32 ReturnCode;\r
149 EFI_STATUS Status;\r
150\r
151 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest, PpRequestParameter);\r
152 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
153 Status = EFI_SUCCESS;\r
154 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
155 Status = EFI_OUT_OF_RESOURCES;\r
156 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
157 Status = EFI_UNSUPPORTED;\r
158 } else {\r
159 Status = EFI_DEVICE_ERROR;\r
160 }\r
161\r
162 return Status;\r
163}\r
164\r
165/**\r
166 Save Tcg2 PCR Banks request request to variable space.\r
167\r
168 @param[in] PCRBankIndex PCR Bank Index.\r
169 @param[in] Enable Enable or disable this PCR Bank.\r
170\r
171 @retval EFI_SUCCESS The operation is finished successfully.\r
172 @retval Others Other errors as indicated.\r
173\r
174**/\r
175EFI_STATUS\r
176SaveTcg2PCRBanksRequest (\r
177 IN UINTN PCRBankIndex,\r
178 IN BOOLEAN Enable\r
179 )\r
180{\r
181 UINT32 ReturnCode;\r
182 EFI_STATUS Status;\r
183\r
184 if (Enable) {\r
185 mTcg2ConfigPrivateDate->PCRBanksDesired |= (0x1 << PCRBankIndex);\r
186 } else {\r
187 mTcg2ConfigPrivateDate->PCRBanksDesired &= ~(0x1 << PCRBankIndex);\r
188 }\r
189 \r
190 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS, mTcg2ConfigPrivateDate->PCRBanksDesired);\r
191 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
192 Status = EFI_SUCCESS;\r
193 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
194 Status = EFI_OUT_OF_RESOURCES;\r
195 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
196 Status = EFI_UNSUPPORTED;\r
197 } else {\r
198 Status = EFI_DEVICE_ERROR;\r
199 }\r
200\r
201 return Status;\r
202}\r
203\r
204/**\r
205 This function processes the results of changes in configuration.\r
206\r
207 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
208 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
209 format.\r
210 @param[out] Progress A pointer to a string filled in with the offset of\r
211 the most recent '&' before the first failing\r
212 name/value pair (or the beginning of the string if\r
213 the failure is in the first name/value pair) or\r
214 the terminating NULL if all was successful.\r
215\r
216 @retval EFI_SUCCESS The Results is processed successfully.\r
217 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
218 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
219 driver.\r
220\r
221**/\r
222EFI_STATUS\r
223EFIAPI\r
224Tcg2RouteConfig (\r
225 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
226 IN CONST EFI_STRING Configuration,\r
227 OUT EFI_STRING *Progress\r
228 )\r
229{\r
230 if (Configuration == NULL || Progress == NULL) {\r
231 return EFI_INVALID_PARAMETER;\r
232 }\r
233\r
234 return EFI_NOT_FOUND;\r
235}\r
236\r
237/**\r
238 This function processes the results of changes in configuration.\r
239\r
240 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
241 @param[in] Action Specifies the type of action taken by the browser.\r
242 @param[in] QuestionId A unique value which is sent to the original\r
243 exporting driver so that it can identify the type\r
244 of data to expect.\r
245 @param[in] Type The type of value for the question.\r
246 @param[in] Value A pointer to the data being sent to the original\r
247 exporting driver.\r
248 @param[out] ActionRequest On return, points to the action requested by the\r
249 callback function.\r
250\r
251 @retval EFI_SUCCESS The callback successfully handled the action.\r
252 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
253 variable and its data.\r
254 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
255 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
256 callback.\r
257\r
258**/\r
259EFI_STATUS\r
260EFIAPI\r
261Tcg2Callback (\r
262 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
263 IN EFI_BROWSER_ACTION Action,\r
264 IN EFI_QUESTION_ID QuestionId,\r
265 IN UINT8 Type,\r
266 IN EFI_IFR_TYPE_VALUE *Value,\r
267 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
268 )\r
269{\r
270 if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
271 return EFI_INVALID_PARAMETER;\r
272 }\r
273 \r
274 if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
275 if (QuestionId == KEY_TPM_DEVICE) {\r
276 return EFI_SUCCESS;\r
277 }\r
278 if (QuestionId == KEY_TPM2_OPERATION) {\r
279 return SaveTcg2PpRequest (Value->u8);\r
280 }\r
281 if (QuestionId == KEY_TPM2_OPERATION_PARAMETER) {\r
282 return SaveTcg2PpRequestParameter (Value->u32);\r
283 }\r
284 if ((QuestionId >= KEY_TPM2_PCR_BANKS_REQUEST_0) && (QuestionId <= KEY_TPM2_PCR_BANKS_REQUEST_4)) {\r
285 SaveTcg2PCRBanksRequest (QuestionId - KEY_TPM2_PCR_BANKS_REQUEST_0, Value->b);\r
286 }\r
287 }\r
288\r
289 return EFI_UNSUPPORTED;\r
290}\r
291\r
292/**\r
293 Append Buffer With TpmAlgHash.\r
294\r
295 @param[in] Buffer Buffer to be appended.\r
296 @param[in] BufferSize Size of buffer.\r
297 @param[in] TpmAlgHash TpmAlgHash.\r
298\r
299**/\r
300VOID\r
301AppendBufferWithTpmAlgHash (\r
302 IN UINT16 *Buffer,\r
303 IN UINTN BufferSize,\r
304 IN UINT32 TpmAlgHash\r
305 )\r
306{\r
307 switch (TpmAlgHash) {\r
308 case TPM_ALG_SHA1:\r
309 if (Buffer[0] != 0) {\r
d2e8af97 310 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 311 }\r
d2e8af97 312 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");\r
1abfa4ce
JY
313 break;\r
314 case TPM_ALG_SHA256:\r
315 if (Buffer[0] != 0) {\r
d2e8af97 316 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 317 }\r
d2e8af97 318 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");\r
1abfa4ce
JY
319 break;\r
320 case TPM_ALG_SHA384:\r
321 if (Buffer[0] != 0) {\r
d2e8af97 322 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 323 }\r
d2e8af97 324 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");\r
1abfa4ce
JY
325 break;\r
326 case TPM_ALG_SHA512:\r
327 if (Buffer[0] != 0) {\r
d2e8af97 328 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 329 }\r
d2e8af97 330 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");\r
1abfa4ce
JY
331 break;\r
332 case TPM_ALG_SM3_256:\r
333 if (Buffer[0] != 0) {\r
d2e8af97 334 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 335 }\r
d2e8af97 336 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");\r
1abfa4ce
JY
337 break;\r
338 }\r
339}\r
340\r
341/**\r
342 Fill Buffer With BootHashAlg.\r
343\r
344 @param[in] Buffer Buffer to be filled.\r
345 @param[in] BufferSize Size of buffer.\r
346 @param[in] BootHashAlg BootHashAlg.\r
347\r
348**/\r
349VOID\r
350FillBufferWithBootHashAlg (\r
351 IN UINT16 *Buffer,\r
352 IN UINTN BufferSize,\r
353 IN UINT32 BootHashAlg\r
354 )\r
355{\r
356 Buffer[0] = 0;\r
357 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) {\r
358 if (Buffer[0] != 0) {\r
d2e8af97 359 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 360 }\r
d2e8af97 361 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");\r
1abfa4ce
JY
362 }\r
363 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) {\r
364 if (Buffer[0] != 0) {\r
d2e8af97 365 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 366 }\r
d2e8af97 367 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");\r
1abfa4ce
JY
368 }\r
369 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) {\r
370 if (Buffer[0] != 0) {\r
d2e8af97 371 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 372 }\r
d2e8af97 373 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");\r
1abfa4ce
JY
374 }\r
375 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) {\r
376 if (Buffer[0] != 0) {\r
d2e8af97 377 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 378 }\r
d2e8af97 379 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");\r
1abfa4ce
JY
380 }\r
381 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SM3_256) != 0) {\r
382 if (Buffer[0] != 0) {\r
d2e8af97 383 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 384 }\r
d2e8af97 385 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");\r
1abfa4ce
JY
386 }\r
387}\r
388\r
c41eeb44
JY
389/**\r
390 Set ConfigInfo according to TpmAlgHash.\r
391\r
392 @param[in,out] Tcg2ConfigInfo TCG2 config info.\r
393 @param[in] TpmAlgHash TpmAlgHash.\r
394\r
395**/\r
396VOID\r
397SetConfigInfo (\r
398 IN OUT TCG2_CONFIGURATION_INFO *Tcg2ConfigInfo,\r
399 IN UINT32 TpmAlgHash\r
400 )\r
401{\r
402 switch (TpmAlgHash) {\r
403 case TPM_ALG_SHA1:\r
404 Tcg2ConfigInfo->Sha1Supported = TRUE;\r
405 break;\r
406 case TPM_ALG_SHA256:\r
407 Tcg2ConfigInfo->Sha256Supported = TRUE;\r
408 break;\r
409 case TPM_ALG_SHA384:\r
410 Tcg2ConfigInfo->Sha384Supported = TRUE;\r
411 break;\r
412 case TPM_ALG_SHA512:\r
413 Tcg2ConfigInfo->Sha512Supported = TRUE;\r
414 break;\r
415 case TPM_ALG_SM3_256:\r
416 Tcg2ConfigInfo->Sm3Supported = TRUE;\r
417 break;\r
418 }\r
419}\r
420\r
1abfa4ce
JY
421/**\r
422 Fill Buffer With TCG2EventLogFormat.\r
423\r
424 @param[in] Buffer Buffer to be filled.\r
425 @param[in] BufferSize Size of buffer.\r
426 @param[in] TCG2EventLogFormat TCG2EventLogFormat.\r
427\r
428**/\r
429VOID\r
430FillBufferWithTCG2EventLogFormat (\r
431 IN UINT16 *Buffer,\r
432 IN UINTN BufferSize,\r
433 IN UINT32 TCG2EventLogFormat\r
434 )\r
435{\r
436 Buffer[0] = 0;\r
437 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2) != 0) {\r
438 if (Buffer[0] != 0) {\r
d2e8af97 439 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 440 }\r
d2e8af97 441 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_1_2");\r
1abfa4ce
JY
442 }\r
443 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) != 0) {\r
444 if (Buffer[0] != 0) {\r
d2e8af97 445 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 446 }\r
d2e8af97 447 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_2");\r
1abfa4ce
JY
448 }\r
449 if ((TCG2EventLogFormat & (~EFI_TCG2_EVENT_LOG_FORMAT_ALL)) != 0) {\r
450 if (Buffer[0] != 0) {\r
d2e8af97 451 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 452 }\r
d2e8af97 453 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"UNKNOWN");\r
1abfa4ce
JY
454 }\r
455}\r
456\r
457/**\r
458 Check if buffer is all zero.\r
459\r
460 @param[in] Buffer Buffer to be checked.\r
461 @param[in] BufferSize Size of buffer to be checked.\r
462\r
463 @retval TRUE Buffer is all zero.\r
464 @retval FALSE Buffer is not all zero.\r
465**/\r
466BOOLEAN\r
467IsZeroBuffer (\r
468 IN VOID *Buffer,\r
469 IN UINTN BufferSize\r
470 )\r
471{\r
472 UINT8 *BufferData;\r
473 UINTN Index;\r
474\r
475 BufferData = Buffer;\r
476 for (Index = 0; Index < BufferSize; Index++) {\r
477 if (BufferData[Index] != 0) {\r
478 return FALSE;\r
479 }\r
480 }\r
481 return TRUE;\r
482}\r
483\r
484/**\r
485 This function publish the TCG2 configuration Form for TPM device.\r
486\r
487 @param[in, out] PrivateData Points to TCG2 configuration private data.\r
488\r
489 @retval EFI_SUCCESS HII Form is installed for this network device.\r
490 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
491 @retval Others Other errors as indicated.\r
492\r
493**/\r
494EFI_STATUS\r
495InstallTcg2ConfigForm (\r
496 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData\r
497 )\r
498{\r
499 EFI_STATUS Status;\r
500 EFI_HII_HANDLE HiiHandle;\r
501 EFI_HANDLE DriverHandle;\r
502 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
503 UINTN Index;\r
504 TPML_PCR_SELECTION Pcrs;\r
505 CHAR16 TempBuffer[1024];\r
c41eeb44 506 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo;\r
1abfa4ce
JY
507\r
508 DriverHandle = NULL;\r
509 ConfigAccess = &PrivateData->ConfigAccess;\r
510 Status = gBS->InstallMultipleProtocolInterfaces (\r
511 &DriverHandle,\r
512 &gEfiDevicePathProtocolGuid,\r
513 &mTcg2HiiVendorDevicePath,\r
514 &gEfiHiiConfigAccessProtocolGuid,\r
515 ConfigAccess,\r
516 NULL\r
517 );\r
518 if (EFI_ERROR (Status)) {\r
519 return Status;\r
520 }\r
521\r
522 PrivateData->DriverHandle = DriverHandle;\r
523\r
524 //\r
525 // Publish the HII package list\r
526 //\r
527 HiiHandle = HiiAddPackages (\r
528 &gTcg2ConfigFormSetGuid,\r
529 DriverHandle,\r
530 Tcg2ConfigDxeStrings,\r
531 Tcg2ConfigBin,\r
532 NULL\r
533 );\r
534 if (HiiHandle == NULL) {\r
535 gBS->UninstallMultipleProtocolInterfaces (\r
536 DriverHandle,\r
537 &gEfiDevicePathProtocolGuid,\r
538 &mTcg2HiiVendorDevicePath,\r
539 &gEfiHiiConfigAccessProtocolGuid,\r
540 ConfigAccess,\r
541 NULL\r
542 ); \r
543\r
544 return EFI_OUT_OF_RESOURCES;\r
545 }\r
546 \r
547 PrivateData->HiiHandle = HiiHandle;\r
548\r
549 //\r
550 // Update static data\r
551 //\r
552 switch (PrivateData->TpmDeviceDetected) {\r
553 case TPM_DEVICE_NULL:\r
554 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Not Found", NULL);\r
555 break;\r
556 case TPM_DEVICE_1_2:\r
557 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);\r
558 break;\r
559 case TPM_DEVICE_2_0_DTPM:\r
560 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 2.0 (DTPM)", NULL);\r
561 break;\r
562 default:\r
563 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Unknown", NULL);\r
564 break;\r
565 }\r
566\r
c41eeb44 567 ZeroMem (&Tcg2ConfigInfo, sizeof(Tcg2ConfigInfo));\r
1abfa4ce
JY
568 Status = Tpm2GetCapabilityPcrs (&Pcrs);\r
569 if (EFI_ERROR (Status)) {\r
570 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), L"[Unknown]", NULL);\r
571 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), L"[Unknown]", NULL);\r
572 } else {\r
573 TempBuffer[0] = 0;\r
574 for (Index = 0; Index < Pcrs.count; Index++) {\r
575 if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {\r
576 AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);\r
577 }\r
578 }\r
579 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
580\r
581 TempBuffer[0] = 0;\r
582 for (Index = 0; Index < Pcrs.count; Index++) {\r
583 AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);\r
c41eeb44 584 SetConfigInfo (&Tcg2ConfigInfo, Pcrs.pcrSelections[Index].hash);\r
1abfa4ce
JY
585 }\r
586 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
587 }\r
588\r
589 FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PcdGet32 (PcdTcg2HashAlgorithmBitmap));\r
590 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
591\r
592 //\r
593 // Tcg2 Capability\r
594 //\r
595 FillBufferWithTCG2EventLogFormat (TempBuffer, sizeof(TempBuffer), PrivateData->ProtocolCapability.SupportedEventLogs);\r
596 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT), TempBuffer, NULL);\r
597\r
598 FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PrivateData->ProtocolCapability.HashAlgorithmBitmap);\r
599 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT), TempBuffer, NULL);\r
600\r
601 UnicodeSPrint (TempBuffer, sizeof (TempBuffer), L"%d", PrivateData->ProtocolCapability.NumberOfPCRBanks);\r
602 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT), TempBuffer, NULL);\r
603\r
604 FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PrivateData->ProtocolCapability.ActivePcrBanks);\r
605 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT), TempBuffer, NULL);\r
606\r
c41eeb44
JY
607 //\r
608 // Set ConfigInfo, to control the check box.\r
609 //\r
610 Status = gRT->SetVariable (\r
611 TCG2_STORAGE_INFO_NAME,\r
612 &gTcg2ConfigFormSetGuid,\r
613 EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
614 sizeof(Tcg2ConfigInfo),\r
615 &Tcg2ConfigInfo\r
616 );\r
617 if (EFI_ERROR (Status)) {\r
618 DEBUG ((EFI_D_ERROR, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));\r
619 }\r
1abfa4ce
JY
620 return EFI_SUCCESS; \r
621}\r
622\r
623/**\r
624 This function removes TCG2 configuration Form.\r
625\r
626 @param[in, out] PrivateData Points to TCG2 configuration private data.\r
627\r
628**/\r
629VOID\r
630UninstallTcg2ConfigForm (\r
631 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData\r
632 )\r
633{\r
634 //\r
635 // Uninstall HII package list\r
636 //\r
637 if (PrivateData->HiiHandle != NULL) {\r
638 HiiRemovePackages (PrivateData->HiiHandle);\r
639 PrivateData->HiiHandle = NULL;\r
640 }\r
641\r
642 //\r
643 // Uninstall HII Config Access Protocol\r
644 //\r
645 if (PrivateData->DriverHandle != NULL) {\r
646 gBS->UninstallMultipleProtocolInterfaces (\r
647 PrivateData->DriverHandle,\r
648 &gEfiDevicePathProtocolGuid,\r
649 &mTcg2HiiVendorDevicePath,\r
650 &gEfiHiiConfigAccessProtocolGuid,\r
651 &PrivateData->ConfigAccess,\r
652 NULL\r
653 );\r
654 PrivateData->DriverHandle = NULL;\r
655 }\r
656 \r
657 FreePool (PrivateData);\r
658}\r