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