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 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
312 StrnCat (Buffer
, L
"SHA1", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
315 if (Buffer
[0] != 0) {
316 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
318 StrnCat (Buffer
, L
"SHA256", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
321 if (Buffer
[0] != 0) {
322 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
324 StrnCat (Buffer
, L
"SHA384", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
327 if (Buffer
[0] != 0) {
328 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
330 StrnCat (Buffer
, L
"SHA512", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
332 case TPM_ALG_SM3_256
:
333 if (Buffer
[0] != 0) {
334 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
336 StrnCat (Buffer
, L
"SM3_256", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
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 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
361 StrnCat (Buffer
, L
"SHA1", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
363 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
364 if (Buffer
[0] != 0) {
365 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
367 StrnCat (Buffer
, L
"SHA256", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
369 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
370 if (Buffer
[0] != 0) {
371 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
373 StrnCat (Buffer
, L
"SHA384", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
375 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
376 if (Buffer
[0] != 0) {
377 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
379 StrnCat (Buffer
, L
"SHA512", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
381 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
382 if (Buffer
[0] != 0) {
383 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
385 StrnCat (Buffer
, L
"SM3_256", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
390 Fill Buffer With TCG2EventLogFormat.
392 @param[in] Buffer Buffer to be filled.
393 @param[in] BufferSize Size of buffer.
394 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
398 FillBufferWithTCG2EventLogFormat (
401 IN UINT32 TCG2EventLogFormat
405 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
406 if (Buffer
[0] != 0) {
407 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
409 StrnCat (Buffer
, L
"TCG_1_2", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
411 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
412 if (Buffer
[0] != 0) {
413 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
415 StrnCat (Buffer
, L
"TCG_2", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
417 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
418 if (Buffer
[0] != 0) {
419 StrnCat (Buffer
, L
", ", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
421 StrnCat (Buffer
, L
"UNKNOWN", (BufferSize
/ sizeof (CHAR16
)) - StrLen (Buffer
) - 1);
426 Check if buffer is all zero.
428 @param[in] Buffer Buffer to be checked.
429 @param[in] BufferSize Size of buffer to be checked.
431 @retval TRUE Buffer is all zero.
432 @retval FALSE Buffer is not all zero.
444 for (Index
= 0; Index
< BufferSize
; Index
++) {
445 if (BufferData
[Index
] != 0) {
453 This function publish the TCG2 configuration Form for TPM device.
455 @param[in, out] PrivateData Points to TCG2 configuration private data.
457 @retval EFI_SUCCESS HII Form is installed for this network device.
458 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
459 @retval Others Other errors as indicated.
463 InstallTcg2ConfigForm (
464 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
468 EFI_HII_HANDLE HiiHandle
;
469 EFI_HANDLE DriverHandle
;
470 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
472 TPML_PCR_SELECTION Pcrs
;
473 CHAR16 TempBuffer
[1024];
476 ConfigAccess
= &PrivateData
->ConfigAccess
;
477 Status
= gBS
->InstallMultipleProtocolInterfaces (
479 &gEfiDevicePathProtocolGuid
,
480 &mTcg2HiiVendorDevicePath
,
481 &gEfiHiiConfigAccessProtocolGuid
,
485 if (EFI_ERROR (Status
)) {
489 PrivateData
->DriverHandle
= DriverHandle
;
492 // Publish the HII package list
494 HiiHandle
= HiiAddPackages (
495 &gTcg2ConfigFormSetGuid
,
497 Tcg2ConfigDxeStrings
,
501 if (HiiHandle
== NULL
) {
502 gBS
->UninstallMultipleProtocolInterfaces (
504 &gEfiDevicePathProtocolGuid
,
505 &mTcg2HiiVendorDevicePath
,
506 &gEfiHiiConfigAccessProtocolGuid
,
511 return EFI_OUT_OF_RESOURCES
;
514 PrivateData
->HiiHandle
= HiiHandle
;
517 // Update static data
519 switch (PrivateData
->TpmDeviceDetected
) {
520 case TPM_DEVICE_NULL
:
521 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
524 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
526 case TPM_DEVICE_2_0_DTPM
:
527 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0 (DTPM)", NULL
);
530 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
534 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
535 if (EFI_ERROR (Status
)) {
536 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
537 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
540 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
541 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
542 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
545 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
548 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
549 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
551 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
554 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
555 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
560 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
561 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
563 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
564 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
566 UnicodeSPrint (TempBuffer
, sizeof (TempBuffer
), L
"%d", PrivateData
->ProtocolCapability
.NumberOfPCRBanks
);
567 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
569 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
570 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
576 This function removes TCG2 configuration Form.
578 @param[in, out] PrivateData Points to TCG2 configuration private data.
582 UninstallTcg2ConfigForm (
583 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
587 // Uninstall HII package list
589 if (PrivateData
->HiiHandle
!= NULL
) {
590 HiiRemovePackages (PrivateData
->HiiHandle
);
591 PrivateData
->HiiHandle
= NULL
;
595 // Uninstall HII Config Access Protocol
597 if (PrivateData
->DriverHandle
!= NULL
) {
598 gBS
->UninstallMultipleProtocolInterfaces (
599 PrivateData
->DriverHandle
,
600 &gEfiDevicePathProtocolGuid
,
601 &mTcg2HiiVendorDevicePath
,
602 &gEfiHiiConfigAccessProtocolGuid
,
603 &PrivateData
->ConfigAccess
,
606 PrivateData
->DriverHandle
= NULL
;
609 FreePool (PrivateData
);