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.
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
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.
16 #include "Tcg2ConfigImpl.h"
17 #include <Library/PcdLib.h>
18 #include <Library/Tpm2CommandLib.h>
19 #include <Guid/TpmInstance.h>
21 #define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
23 TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1] = TPM_INSTANCE_ID_LIST
;
25 TCG2_CONFIG_PRIVATE_DATA
*mTcg2ConfigPrivateDate
;
26 TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate
= {
27 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE
,
35 HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath
= {
41 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
42 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
45 TCG2_CONFIG_FORM_SET_GUID
49 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
51 (UINT8
) (END_DEVICE_PATH_LENGTH
),
52 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
57 UINT8 mCurrentPpRequest
;
60 This function allows a caller to extract the current configuration for one
61 or more named elements from the target driver.
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
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.
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
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
94 if (Progress
== NULL
|| Results
== NULL
) {
95 return EFI_INVALID_PARAMETER
;
103 Save TPM request to variable space.
105 @param[in] PpRequest Physical Presence request command.
107 @retval EFI_SUCCESS The operation is finished successfully.
108 @retval Others Other errors as indicated.
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
;
128 Status
= EFI_DEVICE_ERROR
;
135 Save TPM request to variable space.
137 @param[in] PpRequestParameter Physical Presence request parameter.
139 @retval EFI_SUCCESS The operation is finished successfully.
140 @retval Others Other errors as indicated.
144 SaveTcg2PpRequestParameter (
145 IN UINT32 PpRequestParameter
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
;
159 Status
= EFI_DEVICE_ERROR
;
166 Save Tcg2 PCR Banks request request to variable space.
168 @param[in] PCRBankIndex PCR Bank Index.
169 @param[in] Enable Enable or disable this PCR Bank.
171 @retval EFI_SUCCESS The operation is finished successfully.
172 @retval Others Other errors as indicated.
176 SaveTcg2PCRBanksRequest (
177 IN UINTN PCRBankIndex
,
185 mTcg2ConfigPrivateDate
->PCRBanksDesired
|= (0x1 << PCRBankIndex
);
187 mTcg2ConfigPrivateDate
->PCRBanksDesired
&= ~(0x1 << PCRBankIndex
);
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
;
198 Status
= EFI_DEVICE_ERROR
;
205 This function processes the results of changes in configuration.
207 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
208 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
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.
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
225 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
226 IN CONST EFI_STRING Configuration
,
227 OUT EFI_STRING
*Progress
230 if (Configuration
== NULL
|| Progress
== NULL
) {
231 return EFI_INVALID_PARAMETER
;
234 return EFI_NOT_FOUND
;
238 This function processes the results of changes in configuration.
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
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
248 @param[out] ActionRequest On return, points to the action requested by the
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
262 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
263 IN EFI_BROWSER_ACTION Action
,
264 IN EFI_QUESTION_ID QuestionId
,
266 IN EFI_IFR_TYPE_VALUE
*Value
,
267 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
270 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
271 return EFI_INVALID_PARAMETER
;
274 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
275 if (QuestionId
== KEY_TPM_DEVICE
) {
278 if (QuestionId
== KEY_TPM2_OPERATION
) {
279 return SaveTcg2PpRequest (Value
->u8
);
281 if (QuestionId
== KEY_TPM2_OPERATION_PARAMETER
) {
282 return SaveTcg2PpRequestParameter (Value
->u32
);
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
);
289 return EFI_UNSUPPORTED
;
293 Append Buffer With TpmAlgHash.
295 @param[in] Buffer Buffer to be appended.
296 @param[in] BufferSize Size of buffer.
297 @param[in] TpmAlgHash TpmAlgHash.
301 AppendBufferWithTpmAlgHash (
307 switch (TpmAlgHash
) {
309 if (Buffer
[0] != 0) {
310 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
312 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
315 if (Buffer
[0] != 0) {
316 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
318 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
321 if (Buffer
[0] != 0) {
322 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
324 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
327 if (Buffer
[0] != 0) {
328 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
330 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
332 case TPM_ALG_SM3_256
:
333 if (Buffer
[0] != 0) {
334 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
336 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
342 Fill Buffer With BootHashAlg.
344 @param[in] Buffer Buffer to be filled.
345 @param[in] BufferSize Size of buffer.
346 @param[in] BootHashAlg BootHashAlg.
350 FillBufferWithBootHashAlg (
353 IN UINT32 BootHashAlg
357 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
358 if (Buffer
[0] != 0) {
359 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
361 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
363 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
364 if (Buffer
[0] != 0) {
365 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
367 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
369 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
370 if (Buffer
[0] != 0) {
371 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
373 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
375 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
376 if (Buffer
[0] != 0) {
377 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
379 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
381 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
382 if (Buffer
[0] != 0) {
383 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
385 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
390 Set ConfigInfo according to TpmAlgHash.
392 @param[in,out] Tcg2ConfigInfo TCG2 config info.
393 @param[in] TpmAlgHash TpmAlgHash.
398 IN OUT TCG2_CONFIGURATION_INFO
*Tcg2ConfigInfo
,
402 switch (TpmAlgHash
) {
404 Tcg2ConfigInfo
->Sha1Supported
= TRUE
;
407 Tcg2ConfigInfo
->Sha256Supported
= TRUE
;
410 Tcg2ConfigInfo
->Sha384Supported
= TRUE
;
413 Tcg2ConfigInfo
->Sha512Supported
= TRUE
;
415 case TPM_ALG_SM3_256
:
416 Tcg2ConfigInfo
->Sm3Supported
= TRUE
;
422 Fill Buffer With TCG2EventLogFormat.
424 @param[in] Buffer Buffer to be filled.
425 @param[in] BufferSize Size of buffer.
426 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
430 FillBufferWithTCG2EventLogFormat (
433 IN UINT32 TCG2EventLogFormat
437 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
438 if (Buffer
[0] != 0) {
439 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
441 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_1_2");
443 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
444 if (Buffer
[0] != 0) {
445 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
447 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_2");
449 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
450 if (Buffer
[0] != 0) {
451 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
453 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"UNKNOWN");
458 Check if buffer is all zero.
460 @param[in] Buffer Buffer to be checked.
461 @param[in] BufferSize Size of buffer to be checked.
463 @retval TRUE Buffer is all zero.
464 @retval FALSE Buffer is not all zero.
476 for (Index
= 0; Index
< BufferSize
; Index
++) {
477 if (BufferData
[Index
] != 0) {
485 This function publish the TCG2 configuration Form for TPM device.
487 @param[in, out] PrivateData Points to TCG2 configuration private data.
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.
495 InstallTcg2ConfigForm (
496 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
500 EFI_HII_HANDLE HiiHandle
;
501 EFI_HANDLE DriverHandle
;
502 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
504 TPML_PCR_SELECTION Pcrs
;
505 CHAR16 TempBuffer
[1024];
506 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo
;
509 ConfigAccess
= &PrivateData
->ConfigAccess
;
510 Status
= gBS
->InstallMultipleProtocolInterfaces (
512 &gEfiDevicePathProtocolGuid
,
513 &mTcg2HiiVendorDevicePath
,
514 &gEfiHiiConfigAccessProtocolGuid
,
518 if (EFI_ERROR (Status
)) {
522 PrivateData
->DriverHandle
= DriverHandle
;
525 // Publish the HII package list
527 HiiHandle
= HiiAddPackages (
528 &gTcg2ConfigFormSetGuid
,
530 Tcg2ConfigDxeStrings
,
534 if (HiiHandle
== NULL
) {
535 gBS
->UninstallMultipleProtocolInterfaces (
537 &gEfiDevicePathProtocolGuid
,
538 &mTcg2HiiVendorDevicePath
,
539 &gEfiHiiConfigAccessProtocolGuid
,
544 return EFI_OUT_OF_RESOURCES
;
547 PrivateData
->HiiHandle
= HiiHandle
;
550 // Update static data
552 switch (PrivateData
->TpmDeviceDetected
) {
553 case TPM_DEVICE_NULL
:
554 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
557 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
559 case TPM_DEVICE_2_0_DTPM
:
560 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0 (DTPM)", NULL
);
563 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
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
);
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
);
579 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
582 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
583 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
584 SetConfigInfo (&Tcg2ConfigInfo
, Pcrs
.pcrSelections
[Index
].hash
);
586 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
589 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
590 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
595 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
596 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
598 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
599 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
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
);
604 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
605 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
608 // Set ConfigInfo, to control the check box.
610 Status
= gRT
->SetVariable (
611 TCG2_STORAGE_INFO_NAME
,
612 &gTcg2ConfigFormSetGuid
,
613 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
614 sizeof(Tcg2ConfigInfo
),
617 if (EFI_ERROR (Status
)) {
618 DEBUG ((EFI_D_ERROR
, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
624 This function removes TCG2 configuration Form.
626 @param[in, out] PrivateData Points to TCG2 configuration private data.
630 UninstallTcg2ConfigForm (
631 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
635 // Uninstall HII package list
637 if (PrivateData
->HiiHandle
!= NULL
) {
638 HiiRemovePackages (PrivateData
->HiiHandle
);
639 PrivateData
->HiiHandle
= NULL
;
643 // Uninstall HII Config Access Protocol
645 if (PrivateData
->DriverHandle
!= NULL
) {
646 gBS
->UninstallMultipleProtocolInterfaces (
647 PrivateData
->DriverHandle
,
648 &gEfiDevicePathProtocolGuid
,
649 &mTcg2HiiVendorDevicePath
,
650 &gEfiHiiConfigAccessProtocolGuid
,
651 &PrivateData
->ConfigAccess
,
654 PrivateData
->DriverHandle
= NULL
;
657 FreePool (PrivateData
);