BaseTools: fix the bug for Mixed Pcd display in the report
[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
518b6f65 5Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
1abfa4ce
JY
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
518b6f65 19#include <Library/IoLib.h>\r
1abfa4ce
JY
20#include <Guid/TpmInstance.h>\r
21\r
518b6f65
JY
22#include <IndustryStandard/TpmPtp.h>\r
23\r
1abfa4ce
JY
24#define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)\r
25\r
26TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;\r
27\r
28TCG2_CONFIG_PRIVATE_DATA *mTcg2ConfigPrivateDate;\r
29TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate = {\r
30 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE,\r
31 {\r
32 Tcg2ExtractConfig,\r
33 Tcg2RouteConfig,\r
34 Tcg2Callback\r
35 }\r
36};\r
37\r
38HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath = {\r
39 {\r
40 {\r
41 HARDWARE_DEVICE_PATH,\r
42 HW_VENDOR_DP,\r
43 {\r
44 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
45 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
46 }\r
47 },\r
48 TCG2_CONFIG_FORM_SET_GUID\r
49 },\r
50 {\r
51 END_DEVICE_PATH_TYPE,\r
52 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
53 { \r
54 (UINT8) (END_DEVICE_PATH_LENGTH),\r
55 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
56 }\r
57 }\r
58};\r
59\r
60UINT8 mCurrentPpRequest;\r
61\r
518b6f65
JY
62/**\r
63 Return PTP interface type.\r
64\r
65 @param[in] Register Pointer to PTP register.\r
66\r
67 @return PTP interface type.\r
68**/\r
69UINT8\r
70GetPtpInterface (\r
71 IN VOID *Register\r
72 )\r
73{\r
74 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
75 PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;\r
76\r
77 //\r
78 // Check interface id\r
79 //\r
80 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
81 InterfaceCapability.Uint32 = MmioRead32 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->InterfaceCapability);\r
82\r
83 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&\r
84 (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&\r
85 (InterfaceId.Bits.CapCRB != 0)) {\r
86 return TPM_DEVICE_INTERFACE_PTP_CRB;\r
87 }\r
88 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO) &&\r
89 (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO) &&\r
90 (InterfaceId.Bits.CapFIFO != 0) &&\r
91 (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP)) {\r
92 return TPM_DEVICE_INTERFACE_PTP_FIFO;\r
93 }\r
94 return TPM_DEVICE_INTERFACE_TIS;\r
95}\r
96\r
97/**\r
98 Return if PTP CRB is supported.\r
99\r
100 @param[in] Register Pointer to PTP register.\r
101 \r
102 @retval TRUE PTP CRB is supported.\r
103 @retval FALSE PTP CRB is unsupported.\r
104**/\r
105BOOLEAN\r
106IsPtpCrbSupported (\r
107 IN VOID *Register\r
108 )\r
109{\r
110 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
111\r
112 //\r
113 // Check interface id\r
114 //\r
115 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
116\r
117 if (((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) ||\r
118 (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO)) &&\r
119 (InterfaceId.Bits.CapCRB != 0)) {\r
120 return TRUE;\r
121 }\r
122 return FALSE;\r
123}\r
124\r
125/**\r
126 Return if PTP FIFO is supported.\r
127\r
128 @param[in] Register Pointer to PTP register.\r
129 \r
130 @retval TRUE PTP FIFO is supported.\r
131 @retval FALSE PTP FIFO is unsupported.\r
132**/\r
133BOOLEAN\r
134IsPtpFifoSupported (\r
135 IN VOID *Register\r
136 )\r
137{\r
138 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
139\r
140 //\r
141 // Check interface id\r
142 //\r
143 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
144\r
145 if (((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) ||\r
146 (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO)) &&\r
147 (InterfaceId.Bits.CapFIFO != 0)) {\r
148 return TRUE;\r
149 }\r
150 return FALSE;\r
151}\r
152\r
153/**\r
154 Set PTP interface type.\r
155\r
156 @param[in] Register Pointer to PTP register.\r
157 @param[in] PtpInterface PTP interface type.\r
158 \r
159 @retval EFI_SUCCESS PTP interface type is set.\r
160 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.\r
161 @retval EFI_UNSUPPORTED PTP interface type is unsupported.\r
162 @retval EFI_WRITE_PROTECTED PTP interface is locked.\r
163**/\r
164EFI_STATUS\r
165SetPtpInterface (\r
166 IN VOID *Register,\r
167 IN UINT8 PtpInterface\r
168 )\r
169{\r
170 UINT8 PtpInterfaceCurrent;\r
171 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
172\r
173 PtpInterfaceCurrent = GetPtpInterface (Register);\r
174 if ((PtpInterfaceCurrent != TPM_DEVICE_INTERFACE_PTP_FIFO) && \r
175 (PtpInterfaceCurrent != TPM_DEVICE_INTERFACE_PTP_CRB)) {\r
176 return EFI_UNSUPPORTED;\r
177 }\r
178 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
179 if (InterfaceId.Bits.IntfSelLock != 0) {\r
180 return EFI_WRITE_PROTECTED;\r
181 }\r
182\r
183 switch (PtpInterface) {\r
184 case TPM_DEVICE_INTERFACE_PTP_FIFO:\r
185 if (InterfaceId.Bits.CapFIFO == 0) {\r
186 return EFI_UNSUPPORTED;\r
187 }\r
188 InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO;\r
189 MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);\r
190 return EFI_SUCCESS;\r
191 case TPM_DEVICE_INTERFACE_PTP_CRB:\r
192 if (InterfaceId.Bits.CapCRB == 0) {\r
193 return EFI_UNSUPPORTED;\r
194 }\r
195 InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB;\r
196 MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);\r
197 return EFI_SUCCESS;\r
198 default:\r
199 return EFI_INVALID_PARAMETER;\r
200 }\r
201}\r
202\r
1abfa4ce
JY
203/**\r
204 This function allows a caller to extract the current configuration for one\r
205 or more named elements from the target driver.\r
206\r
207 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
208 @param[in] Request A null-terminated Unicode string in\r
209 <ConfigRequest> format.\r
210 @param[out] Progress On return, points to a character in the Request\r
211 string. Points to the string's null terminator if\r
212 request was successful. Points to the most recent\r
213 '&' before the first failing name/value pair (or\r
214 the beginning of the string if the failure is in\r
215 the first name/value pair) if the request was not\r
216 successful.\r
217 @param[out] Results A null-terminated Unicode string in\r
218 <ConfigAltResp> format which has all values filled\r
219 in for the names in the Request string. String to\r
220 be allocated by the called function.\r
221\r
222 @retval EFI_SUCCESS The Results is filled with the requested values.\r
223 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
224 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
225 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
226 driver.\r
227\r
228**/\r
229EFI_STATUS\r
230EFIAPI\r
231Tcg2ExtractConfig (\r
232 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
233 IN CONST EFI_STRING Request,\r
234 OUT EFI_STRING *Progress,\r
235 OUT EFI_STRING *Results\r
236 )\r
237{\r
238 if (Progress == NULL || Results == NULL) {\r
239 return EFI_INVALID_PARAMETER;\r
240 }\r
241\r
242 *Progress = Request;\r
243 return EFI_NOT_FOUND;\r
244}\r
245\r
246/**\r
247 Save TPM request to variable space.\r
248\r
249 @param[in] PpRequest Physical Presence request command.\r
250\r
251 @retval EFI_SUCCESS The operation is finished successfully.\r
252 @retval Others Other errors as indicated.\r
253\r
254**/\r
255EFI_STATUS\r
256SaveTcg2PpRequest (\r
257 IN UINT8 PpRequest\r
258 )\r
259{\r
260 UINT32 ReturnCode;\r
261 EFI_STATUS Status;\r
262\r
263 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest, 0);\r
264 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
265 mCurrentPpRequest = PpRequest;\r
266 Status = EFI_SUCCESS;\r
267 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
268 Status = EFI_OUT_OF_RESOURCES;\r
269 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
270 Status = EFI_UNSUPPORTED;\r
271 } else {\r
272 Status = EFI_DEVICE_ERROR;\r
273 }\r
274\r
275 return Status;\r
276}\r
277\r
278/**\r
279 Save TPM request to variable space.\r
280\r
281 @param[in] PpRequestParameter Physical Presence request parameter.\r
282\r
283 @retval EFI_SUCCESS The operation is finished successfully.\r
284 @retval Others Other errors as indicated.\r
285\r
286**/\r
287EFI_STATUS\r
288SaveTcg2PpRequestParameter (\r
289 IN UINT32 PpRequestParameter\r
290 )\r
291{\r
292 UINT32 ReturnCode;\r
293 EFI_STATUS Status;\r
294\r
295 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest, PpRequestParameter);\r
296 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
297 Status = EFI_SUCCESS;\r
298 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
299 Status = EFI_OUT_OF_RESOURCES;\r
300 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
301 Status = EFI_UNSUPPORTED;\r
302 } else {\r
303 Status = EFI_DEVICE_ERROR;\r
304 }\r
305\r
306 return Status;\r
307}\r
308\r
309/**\r
310 Save Tcg2 PCR Banks request request to variable space.\r
311\r
312 @param[in] PCRBankIndex PCR Bank Index.\r
313 @param[in] Enable Enable or disable this PCR Bank.\r
314\r
315 @retval EFI_SUCCESS The operation is finished successfully.\r
316 @retval Others Other errors as indicated.\r
317\r
318**/\r
319EFI_STATUS\r
320SaveTcg2PCRBanksRequest (\r
321 IN UINTN PCRBankIndex,\r
322 IN BOOLEAN Enable\r
323 )\r
324{\r
325 UINT32 ReturnCode;\r
326 EFI_STATUS Status;\r
327\r
328 if (Enable) {\r
329 mTcg2ConfigPrivateDate->PCRBanksDesired |= (0x1 << PCRBankIndex);\r
330 } else {\r
331 mTcg2ConfigPrivateDate->PCRBanksDesired &= ~(0x1 << PCRBankIndex);\r
332 }\r
333 \r
334 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS, mTcg2ConfigPrivateDate->PCRBanksDesired);\r
335 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
336 Status = EFI_SUCCESS;\r
337 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
338 Status = EFI_OUT_OF_RESOURCES;\r
339 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
340 Status = EFI_UNSUPPORTED;\r
341 } else {\r
342 Status = EFI_DEVICE_ERROR;\r
343 }\r
344\r
345 return Status;\r
346}\r
347\r
348/**\r
349 This function processes the results of changes in configuration.\r
350\r
351 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
352 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
353 format.\r
354 @param[out] Progress A pointer to a string filled in with the offset of\r
355 the most recent '&' before the first failing\r
356 name/value pair (or the beginning of the string if\r
357 the failure is in the first name/value pair) or\r
358 the terminating NULL if all was successful.\r
359\r
360 @retval EFI_SUCCESS The Results is processed successfully.\r
361 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
362 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
363 driver.\r
364\r
365**/\r
366EFI_STATUS\r
367EFIAPI\r
368Tcg2RouteConfig (\r
369 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
370 IN CONST EFI_STRING Configuration,\r
371 OUT EFI_STRING *Progress\r
372 )\r
373{\r
374 if (Configuration == NULL || Progress == NULL) {\r
375 return EFI_INVALID_PARAMETER;\r
376 }\r
377\r
378 return EFI_NOT_FOUND;\r
379}\r
380\r
381/**\r
382 This function processes the results of changes in configuration.\r
383\r
384 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
385 @param[in] Action Specifies the type of action taken by the browser.\r
386 @param[in] QuestionId A unique value which is sent to the original\r
387 exporting driver so that it can identify the type\r
388 of data to expect.\r
389 @param[in] Type The type of value for the question.\r
390 @param[in] Value A pointer to the data being sent to the original\r
391 exporting driver.\r
392 @param[out] ActionRequest On return, points to the action requested by the\r
393 callback function.\r
394\r
395 @retval EFI_SUCCESS The callback successfully handled the action.\r
396 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
397 variable and its data.\r
398 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
399 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
400 callback.\r
401\r
402**/\r
403EFI_STATUS\r
404EFIAPI\r
405Tcg2Callback (\r
406 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
407 IN EFI_BROWSER_ACTION Action,\r
408 IN EFI_QUESTION_ID QuestionId,\r
409 IN UINT8 Type,\r
410 IN EFI_IFR_TYPE_VALUE *Value,\r
411 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
412 )\r
413{\r
518b6f65
JY
414 EFI_INPUT_KEY Key;\r
415\r
1abfa4ce
JY
416 if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
417 return EFI_INVALID_PARAMETER;\r
418 }\r
518b6f65
JY
419\r
420 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
421 if (QuestionId == KEY_TPM_DEVICE_INTERFACE) {\r
422 EFI_STATUS Status;\r
423 Status = SetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress), Value->u8);\r
424 if (EFI_ERROR (Status)) {\r
425 CreatePopUp (\r
426 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
427 &Key,\r
428 L"Error: Fail to set PTP interface!",\r
429 NULL\r
430 );\r
431 return EFI_DEVICE_ERROR;\r
432 }\r
433 }\r
434 }\r
1abfa4ce
JY
435 \r
436 if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
437 if (QuestionId == KEY_TPM_DEVICE) {\r
438 return EFI_SUCCESS;\r
439 }\r
440 if (QuestionId == KEY_TPM2_OPERATION) {\r
441 return SaveTcg2PpRequest (Value->u8);\r
442 }\r
443 if (QuestionId == KEY_TPM2_OPERATION_PARAMETER) {\r
444 return SaveTcg2PpRequestParameter (Value->u32);\r
445 }\r
446 if ((QuestionId >= KEY_TPM2_PCR_BANKS_REQUEST_0) && (QuestionId <= KEY_TPM2_PCR_BANKS_REQUEST_4)) {\r
447 SaveTcg2PCRBanksRequest (QuestionId - KEY_TPM2_PCR_BANKS_REQUEST_0, Value->b);\r
448 }\r
449 }\r
450\r
451 return EFI_UNSUPPORTED;\r
452}\r
453\r
454/**\r
455 Append Buffer With TpmAlgHash.\r
456\r
457 @param[in] Buffer Buffer to be appended.\r
458 @param[in] BufferSize Size of buffer.\r
459 @param[in] TpmAlgHash TpmAlgHash.\r
460\r
461**/\r
462VOID\r
463AppendBufferWithTpmAlgHash (\r
464 IN UINT16 *Buffer,\r
465 IN UINTN BufferSize,\r
466 IN UINT32 TpmAlgHash\r
467 )\r
468{\r
469 switch (TpmAlgHash) {\r
470 case TPM_ALG_SHA1:\r
471 if (Buffer[0] != 0) {\r
d2e8af97 472 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 473 }\r
d2e8af97 474 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");\r
1abfa4ce
JY
475 break;\r
476 case TPM_ALG_SHA256:\r
477 if (Buffer[0] != 0) {\r
d2e8af97 478 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 479 }\r
d2e8af97 480 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");\r
1abfa4ce
JY
481 break;\r
482 case TPM_ALG_SHA384:\r
483 if (Buffer[0] != 0) {\r
d2e8af97 484 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 485 }\r
d2e8af97 486 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");\r
1abfa4ce
JY
487 break;\r
488 case TPM_ALG_SHA512:\r
489 if (Buffer[0] != 0) {\r
d2e8af97 490 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 491 }\r
d2e8af97 492 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");\r
1abfa4ce
JY
493 break;\r
494 case TPM_ALG_SM3_256:\r
495 if (Buffer[0] != 0) {\r
d2e8af97 496 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 497 }\r
d2e8af97 498 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");\r
1abfa4ce
JY
499 break;\r
500 }\r
501}\r
502\r
503/**\r
504 Fill Buffer With BootHashAlg.\r
505\r
506 @param[in] Buffer Buffer to be filled.\r
507 @param[in] BufferSize Size of buffer.\r
508 @param[in] BootHashAlg BootHashAlg.\r
509\r
510**/\r
511VOID\r
512FillBufferWithBootHashAlg (\r
513 IN UINT16 *Buffer,\r
514 IN UINTN BufferSize,\r
515 IN UINT32 BootHashAlg\r
516 )\r
517{\r
518 Buffer[0] = 0;\r
519 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) {\r
520 if (Buffer[0] != 0) {\r
d2e8af97 521 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 522 }\r
d2e8af97 523 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");\r
1abfa4ce
JY
524 }\r
525 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) {\r
526 if (Buffer[0] != 0) {\r
d2e8af97 527 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 528 }\r
d2e8af97 529 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");\r
1abfa4ce
JY
530 }\r
531 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) {\r
532 if (Buffer[0] != 0) {\r
d2e8af97 533 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 534 }\r
d2e8af97 535 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");\r
1abfa4ce
JY
536 }\r
537 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) {\r
538 if (Buffer[0] != 0) {\r
d2e8af97 539 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 540 }\r
d2e8af97 541 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");\r
1abfa4ce
JY
542 }\r
543 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SM3_256) != 0) {\r
544 if (Buffer[0] != 0) {\r
d2e8af97 545 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 546 }\r
d2e8af97 547 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");\r
1abfa4ce
JY
548 }\r
549}\r
550\r
c41eeb44
JY
551/**\r
552 Set ConfigInfo according to TpmAlgHash.\r
553\r
554 @param[in,out] Tcg2ConfigInfo TCG2 config info.\r
555 @param[in] TpmAlgHash TpmAlgHash.\r
556\r
557**/\r
558VOID\r
559SetConfigInfo (\r
560 IN OUT TCG2_CONFIGURATION_INFO *Tcg2ConfigInfo,\r
561 IN UINT32 TpmAlgHash\r
562 )\r
563{\r
564 switch (TpmAlgHash) {\r
565 case TPM_ALG_SHA1:\r
566 Tcg2ConfigInfo->Sha1Supported = TRUE;\r
567 break;\r
568 case TPM_ALG_SHA256:\r
569 Tcg2ConfigInfo->Sha256Supported = TRUE;\r
570 break;\r
571 case TPM_ALG_SHA384:\r
572 Tcg2ConfigInfo->Sha384Supported = TRUE;\r
573 break;\r
574 case TPM_ALG_SHA512:\r
575 Tcg2ConfigInfo->Sha512Supported = TRUE;\r
576 break;\r
577 case TPM_ALG_SM3_256:\r
578 Tcg2ConfigInfo->Sm3Supported = TRUE;\r
579 break;\r
580 }\r
581}\r
582\r
1abfa4ce
JY
583/**\r
584 Fill Buffer With TCG2EventLogFormat.\r
585\r
586 @param[in] Buffer Buffer to be filled.\r
587 @param[in] BufferSize Size of buffer.\r
588 @param[in] TCG2EventLogFormat TCG2EventLogFormat.\r
589\r
590**/\r
591VOID\r
592FillBufferWithTCG2EventLogFormat (\r
593 IN UINT16 *Buffer,\r
594 IN UINTN BufferSize,\r
595 IN UINT32 TCG2EventLogFormat\r
596 )\r
597{\r
598 Buffer[0] = 0;\r
599 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2) != 0) {\r
600 if (Buffer[0] != 0) {\r
d2e8af97 601 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 602 }\r
d2e8af97 603 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_1_2");\r
1abfa4ce
JY
604 }\r
605 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) != 0) {\r
606 if (Buffer[0] != 0) {\r
d2e8af97 607 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 608 }\r
d2e8af97 609 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_2");\r
1abfa4ce
JY
610 }\r
611 if ((TCG2EventLogFormat & (~EFI_TCG2_EVENT_LOG_FORMAT_ALL)) != 0) {\r
612 if (Buffer[0] != 0) {\r
d2e8af97 613 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 614 }\r
d2e8af97 615 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"UNKNOWN");\r
1abfa4ce
JY
616 }\r
617}\r
618\r
1abfa4ce
JY
619/**\r
620 This function publish the TCG2 configuration Form for TPM device.\r
621\r
622 @param[in, out] PrivateData Points to TCG2 configuration private data.\r
623\r
624 @retval EFI_SUCCESS HII Form is installed for this network device.\r
625 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
626 @retval Others Other errors as indicated.\r
627\r
628**/\r
629EFI_STATUS\r
630InstallTcg2ConfigForm (\r
631 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData\r
632 )\r
633{\r
634 EFI_STATUS Status;\r
635 EFI_HII_HANDLE HiiHandle;\r
636 EFI_HANDLE DriverHandle;\r
637 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
638 UINTN Index;\r
639 TPML_PCR_SELECTION Pcrs;\r
640 CHAR16 TempBuffer[1024];\r
c41eeb44 641 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo;\r
518b6f65 642 UINT8 TpmDeviceInterfaceDetected;\r
1abfa4ce
JY
643\r
644 DriverHandle = NULL;\r
645 ConfigAccess = &PrivateData->ConfigAccess;\r
646 Status = gBS->InstallMultipleProtocolInterfaces (\r
647 &DriverHandle,\r
648 &gEfiDevicePathProtocolGuid,\r
649 &mTcg2HiiVendorDevicePath,\r
650 &gEfiHiiConfigAccessProtocolGuid,\r
651 ConfigAccess,\r
652 NULL\r
653 );\r
654 if (EFI_ERROR (Status)) {\r
655 return Status;\r
656 }\r
657\r
658 PrivateData->DriverHandle = DriverHandle;\r
659\r
660 //\r
661 // Publish the HII package list\r
662 //\r
663 HiiHandle = HiiAddPackages (\r
664 &gTcg2ConfigFormSetGuid,\r
665 DriverHandle,\r
666 Tcg2ConfigDxeStrings,\r
667 Tcg2ConfigBin,\r
668 NULL\r
669 );\r
670 if (HiiHandle == NULL) {\r
671 gBS->UninstallMultipleProtocolInterfaces (\r
672 DriverHandle,\r
673 &gEfiDevicePathProtocolGuid,\r
674 &mTcg2HiiVendorDevicePath,\r
675 &gEfiHiiConfigAccessProtocolGuid,\r
676 ConfigAccess,\r
677 NULL\r
678 ); \r
679\r
680 return EFI_OUT_OF_RESOURCES;\r
681 }\r
682 \r
683 PrivateData->HiiHandle = HiiHandle;\r
684\r
685 //\r
686 // Update static data\r
687 //\r
688 switch (PrivateData->TpmDeviceDetected) {\r
689 case TPM_DEVICE_NULL:\r
690 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Not Found", NULL);\r
691 break;\r
692 case TPM_DEVICE_1_2:\r
693 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);\r
694 break;\r
695 case TPM_DEVICE_2_0_DTPM:\r
518b6f65 696 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 2.0", NULL);\r
1abfa4ce
JY
697 break;\r
698 default:\r
699 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Unknown", NULL);\r
700 break;\r
701 }\r
702\r
c41eeb44 703 ZeroMem (&Tcg2ConfigInfo, sizeof(Tcg2ConfigInfo));\r
1abfa4ce
JY
704 Status = Tpm2GetCapabilityPcrs (&Pcrs);\r
705 if (EFI_ERROR (Status)) {\r
706 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), L"[Unknown]", NULL);\r
707 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), L"[Unknown]", NULL);\r
708 } else {\r
709 TempBuffer[0] = 0;\r
710 for (Index = 0; Index < Pcrs.count; Index++) {\r
72388f9c 711 if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {\r
1abfa4ce
JY
712 AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);\r
713 }\r
714 }\r
715 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
716\r
717 TempBuffer[0] = 0;\r
718 for (Index = 0; Index < Pcrs.count; Index++) {\r
719 AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);\r
c41eeb44 720 SetConfigInfo (&Tcg2ConfigInfo, Pcrs.pcrSelections[Index].hash);\r
1abfa4ce
JY
721 }\r
722 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
723 }\r
724\r
725 FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PcdGet32 (PcdTcg2HashAlgorithmBitmap));\r
726 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
727\r
728 //\r
729 // Tcg2 Capability\r
730 //\r
731 FillBufferWithTCG2EventLogFormat (TempBuffer, sizeof(TempBuffer), PrivateData->ProtocolCapability.SupportedEventLogs);\r
732 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT), TempBuffer, NULL);\r
733\r
734 FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PrivateData->ProtocolCapability.HashAlgorithmBitmap);\r
735 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT), TempBuffer, NULL);\r
736\r
737 UnicodeSPrint (TempBuffer, sizeof (TempBuffer), L"%d", PrivateData->ProtocolCapability.NumberOfPCRBanks);\r
738 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT), TempBuffer, NULL);\r
739\r
740 FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PrivateData->ProtocolCapability.ActivePcrBanks);\r
741 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT), TempBuffer, NULL);\r
742\r
518b6f65
JY
743 //\r
744 // Update TPM device interface type\r
745 //\r
746 if (PrivateData->TpmDeviceDetected == TPM_DEVICE_2_0_DTPM) {\r
747 TpmDeviceInterfaceDetected = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
748 switch (TpmDeviceInterfaceDetected) {\r
749 case TPM_DEVICE_INTERFACE_TIS:\r
750 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"TIS", NULL);\r
751 break;\r
752 case TPM_DEVICE_INTERFACE_PTP_FIFO:\r
753 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP FIFO", NULL);\r
754 break;\r
755 case TPM_DEVICE_INTERFACE_PTP_CRB:\r
756 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP CRB", NULL);\r
757 break;\r
758 default:\r
759 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"Unknown", NULL);\r
760 break;\r
761 }\r
762\r
763 Tcg2ConfigInfo.TpmDeviceInterfaceAttempt = TpmDeviceInterfaceDetected;\r
764 switch (TpmDeviceInterfaceDetected) {\r
765 case TPM_DEVICE_INTERFACE_TIS:\r
766 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;\r
767 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = FALSE;\r
768 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"TIS", NULL);\r
769 break;\r
770 case TPM_DEVICE_INTERFACE_PTP_FIFO:\r
771 case TPM_DEVICE_INTERFACE_PTP_CRB:\r
772 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = IsPtpFifoSupported((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
773 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = IsPtpCrbSupported((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
774 TempBuffer[0] = 0;\r
775 if (Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported) {\r
776 if (TempBuffer[0] != 0) {\r
777 StrCatS (TempBuffer, sizeof(TempBuffer) / sizeof (CHAR16), L", ");\r
778 }\r
779 StrCatS (TempBuffer, sizeof(TempBuffer) / sizeof (CHAR16), L"PTP FIFO");\r
780 }\r
781 if (Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported) {\r
782 if (TempBuffer[0] != 0) {\r
783 StrCatS (TempBuffer, sizeof(TempBuffer) / sizeof (CHAR16), L", ");\r
784 }\r
785 StrCatS (TempBuffer, sizeof(TempBuffer) / sizeof (CHAR16), L"PTP CRB");\r
786 }\r
787 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), TempBuffer, NULL);\r
788 break;\r
789 default:\r
790 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;\r
791 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = FALSE;\r
792 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"Unknown", NULL);\r
793 break;\r
794 }\r
795 }\r
796\r
c41eeb44
JY
797 //\r
798 // Set ConfigInfo, to control the check box.\r
799 //\r
800 Status = gRT->SetVariable (\r
801 TCG2_STORAGE_INFO_NAME,\r
802 &gTcg2ConfigFormSetGuid,\r
803 EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
804 sizeof(Tcg2ConfigInfo),\r
805 &Tcg2ConfigInfo\r
806 );\r
807 if (EFI_ERROR (Status)) {\r
808 DEBUG ((EFI_D_ERROR, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));\r
809 }\r
1abfa4ce
JY
810 return EFI_SUCCESS; \r
811}\r
812\r
813/**\r
814 This function removes TCG2 configuration Form.\r
815\r
816 @param[in, out] PrivateData Points to TCG2 configuration private data.\r
817\r
818**/\r
819VOID\r
820UninstallTcg2ConfigForm (\r
821 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData\r
822 )\r
823{\r
824 //\r
825 // Uninstall HII package list\r
826 //\r
827 if (PrivateData->HiiHandle != NULL) {\r
828 HiiRemovePackages (PrivateData->HiiHandle);\r
829 PrivateData->HiiHandle = NULL;\r
830 }\r
831\r
832 //\r
833 // Uninstall HII Config Access Protocol\r
834 //\r
835 if (PrivateData->DriverHandle != NULL) {\r
836 gBS->UninstallMultipleProtocolInterfaces (\r
837 PrivateData->DriverHandle,\r
838 &gEfiDevicePathProtocolGuid,\r
839 &mTcg2HiiVendorDevicePath,\r
840 &gEfiHiiConfigAccessProtocolGuid,\r
841 &PrivateData->ConfigAccess,\r
842 NULL\r
843 );\r
844 PrivateData->DriverHandle = NULL;\r
845 }\r
846 \r
847 FreePool (PrivateData);\r
848}\r