2 HII Config Access protocol implementation of TCG configuration module.
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "TcgConfigImpl.h"
17 EFI_GUID mTcgFormSetGuid
= TCG_CONFIG_PRIVATE_GUID
;
18 CHAR16 mTcgStorageName
[] = L
"TCG_CONFIGURATION";
20 TCG_CONFIG_PRIVATE_DATA mTcgConfigPrivateDateTemplate
= {
21 TCG_CONFIG_PRIVATE_DATA_SIGNATURE
,
29 HII_VENDOR_DEVICE_PATH mTcgHiiVendorDevicePath
= {
35 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
36 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
39 TCG_CONFIG_PRIVATE_GUID
43 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
45 (UINT8
) (END_DEVICE_PATH_LENGTH
),
46 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
52 Get current state of TPM device.
54 @param[in] TcgProtocol Point to EFI_TCG_PROTOCOL instance.
55 @param[out] TpmEnable Flag to indicate TPM is enabled or not.
56 @param[out] TpmActivate Flag to indicate TPM is activated or not.
58 @retval EFI_SUCCESS State is successfully returned.
59 @retval EFI_DEVICE_ERROR Failed to get TPM response.
60 @retval Others Other errors as indicated.
65 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
66 OUT BOOLEAN
*TpmEnable
, OPTIONAL
67 OUT BOOLEAN
*TpmActivate OPTIONAL
71 TPM_RSP_COMMAND_HDR
*TpmRsp
;
73 TPM_PERMANENT_FLAGS
*TpmPermanentFlags
;
76 ASSERT (TcgProtocol
!= NULL
);
79 // Get TPM Permanent flags (TpmEnable, TpmActivate)
81 if ((TpmEnable
!= NULL
) || (TpmActivate
!= NULL
)) {
82 TpmSendSize
= sizeof (TPM_RQU_COMMAND_HDR
) + sizeof (UINT32
) * 3;
83 *(UINT16
*)&CmdBuf
[0] = H2NS (TPM_TAG_RQU_COMMAND
);
84 *(UINT32
*)&CmdBuf
[2] = H2NL (TpmSendSize
);
85 *(UINT32
*)&CmdBuf
[6] = H2NL (TPM_ORD_GetCapability
);
87 *(UINT32
*)&CmdBuf
[10] = H2NL (TPM_CAP_FLAG
);
88 *(UINT32
*)&CmdBuf
[14] = H2NL (sizeof (TPM_CAP_FLAG_PERMANENT
));
89 *(UINT32
*)&CmdBuf
[18] = H2NL (TPM_CAP_FLAG_PERMANENT
);
91 Status
= TcgProtocol
->PassThroughToTpm (
98 TpmRsp
= (TPM_RSP_COMMAND_HDR
*) &CmdBuf
[0];
99 if (EFI_ERROR (Status
) || (TpmRsp
->tag
!= H2NS (TPM_TAG_RSP_COMMAND
)) || (TpmRsp
->returnCode
!= 0)) {
100 return EFI_DEVICE_ERROR
;
103 TpmPermanentFlags
= (TPM_PERMANENT_FLAGS
*) &CmdBuf
[sizeof (TPM_RSP_COMMAND_HDR
) + sizeof (UINT32
)];
105 if (TpmEnable
!= NULL
) {
106 *TpmEnable
= (BOOLEAN
) !TpmPermanentFlags
->disable
;
109 if (TpmActivate
!= NULL
) {
110 *TpmActivate
= (BOOLEAN
) !TpmPermanentFlags
->deactivated
;
118 This function allows a caller to extract the current configuration for one
119 or more named elements from the target driver.
121 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
122 @param[in] Request A null-terminated Unicode string in
123 <ConfigRequest> format.
124 @param[out] Progress On return, points to a character in the Request
125 string. Points to the string's null terminator if
126 request was successful. Points to the most recent
127 '&' before the first failing name/value pair (or
128 the beginning of the string if the failure is in
129 the first name/value pair) if the request was not
131 @param[out] Results A null-terminated Unicode string in
132 <ConfigAltResp> format which has all values filled
133 in for the names in the Request string. String to
134 be allocated by the called function.
136 @retval EFI_SUCCESS The Results is filled with the requested values.
137 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
138 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
139 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
146 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
147 IN CONST EFI_STRING Request
,
148 OUT EFI_STRING
*Progress
,
149 OUT EFI_STRING
*Results
154 TCG_CONFIGURATION Configuration
;
155 TCG_CONFIG_PRIVATE_DATA
*PrivateData
;
156 EFI_STRING ConfigRequestHdr
;
157 EFI_STRING ConfigRequest
;
158 BOOLEAN AllocatedRequest
;
164 if (Progress
== NULL
|| Results
== NULL
) {
165 return EFI_INVALID_PARAMETER
;
169 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &mTcgFormSetGuid
, mTcgStorageName
)) {
170 return EFI_NOT_FOUND
;
173 ConfigRequestHdr
= NULL
;
174 ConfigRequest
= NULL
;
175 AllocatedRequest
= FALSE
;
178 PrivateData
= TCG_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
181 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
183 ZeroMem (&Configuration
, sizeof (TCG_CONFIGURATION
));
185 Configuration
.MorState
= PcdGetBool (PcdMorEnable
);
186 Configuration
.TpmOperation
= ENABLE
;
187 Configuration
.HideTpm
= (BOOLEAN
) (PcdGetBool (PcdHideTpmSupport
) && PcdGetBool (PcdHideTpm
));
189 // Read the original value of HideTpm from PrivateData which won't be changed by Setup in this boot.
191 Configuration
.OriginalHideTpm
= PrivateData
->HideTpm
;
194 // Display current TPM state.
196 if (PrivateData
->TcgProtocol
!= NULL
) {
197 Status
= GetTpmState (PrivateData
->TcgProtocol
, &TpmEnable
, &TpmActivate
);
198 if (EFI_ERROR (Status
)) {
206 TpmEnable
? L
"Enabled" : L
"Disabled",
207 TpmActivate
? L
"Activated" : L
"Deactivated"
209 Configuration
.TpmEnable
= TpmEnable
;
210 Configuration
.TpmActivate
= TpmActivate
;
212 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM_STATE_CONTENT
), State
, NULL
);
215 BufferSize
= sizeof (Configuration
);
216 ConfigRequest
= Request
;
217 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
219 // Request has no request element, construct full request string.
220 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
221 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
223 ConfigRequestHdr
= HiiConstructConfigHdr (&mTcgFormSetGuid
, mTcgStorageName
, PrivateData
->DriverHandle
);
224 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
225 ConfigRequest
= AllocateZeroPool (Size
);
226 ASSERT (ConfigRequest
!= NULL
);
227 AllocatedRequest
= TRUE
;
228 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
) BufferSize
);
229 FreePool (ConfigRequestHdr
);
232 Status
= gHiiConfigRouting
->BlockToConfig (
235 (UINT8
*) &Configuration
,
241 // Free the allocated config request string.
243 if (AllocatedRequest
) {
244 FreePool (ConfigRequest
);
247 // Set Progress string to the original request string.
249 if (Request
== NULL
) {
251 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
252 *Progress
= Request
+ StrLen (Request
);
259 This function processes the results of changes in configuration.
261 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
262 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
264 @param[out] Progress A pointer to a string filled in with the offset of
265 the most recent '&' before the first failing
266 name/value pair (or the beginning of the string if
267 the failure is in the first name/value pair) or
268 the terminating NULL if all was successful.
270 @retval EFI_SUCCESS The Results is processed successfully.
271 @retval EFI_INVALID_PARAMETER Configuration is NULL.
272 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
279 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
280 IN CONST EFI_STRING Configuration
,
281 OUT EFI_STRING
*Progress
286 TCG_CONFIGURATION TcgConfiguration
;
288 if (Configuration
== NULL
|| Progress
== NULL
) {
289 return EFI_INVALID_PARAMETER
;
292 *Progress
= Configuration
;
293 if (!HiiIsConfigHdrMatch (Configuration
, &mTcgFormSetGuid
, mTcgStorageName
)) {
294 return EFI_NOT_FOUND
;
298 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
300 BufferSize
= sizeof (TCG_CONFIGURATION
);
301 Status
= gHiiConfigRouting
->ConfigToBlock (
304 (UINT8
*) &TcgConfiguration
,
308 if (EFI_ERROR (Status
)) {
312 PcdSetBool (PcdMorEnable
, TcgConfiguration
.MorState
);
313 PcdSetBool (PcdHideTpm
, TcgConfiguration
.HideTpm
);
319 Save TPM request to variable space.
321 @param[in] PpRequest Physical Presence request command.
323 @retval EFI_SUCCESS The operation is finished successfully.
324 @retval Others Other errors as indicated.
334 EFI_PHYSICAL_PRESENCE PpData
;
337 // Save TPM command to variable.
339 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
340 Status
= gRT
->GetVariable (
341 PHYSICAL_PRESENCE_VARIABLE
,
342 &gEfiPhysicalPresenceGuid
,
347 if (EFI_ERROR (Status
)) {
351 PpData
.PPRequest
= PpRequest
;
352 Status
= gRT
->SetVariable (
353 PHYSICAL_PRESENCE_VARIABLE
,
354 &gEfiPhysicalPresenceGuid
,
355 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
359 if (EFI_ERROR(Status
)) {
366 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
372 This function processes the results of changes in configuration.
374 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
375 @param[in] Action Specifies the type of action taken by the browser.
376 @param[in] QuestionId A unique value which is sent to the original
377 exporting driver so that it can identify the type
379 @param[in] Type The type of value for the question.
380 @param[in] Value A pointer to the data being sent to the original
382 @param[out] ActionRequest On return, points to the action requested by the
385 @retval EFI_SUCCESS The callback successfully handled the action.
386 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
387 variable and its data.
388 @retval EFI_DEVICE_ERROR The variable could not be saved.
389 @retval EFI_UNSUPPORTED The specified Action is not supported by the
396 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
397 IN EFI_BROWSER_ACTION Action
,
398 IN EFI_QUESTION_ID QuestionId
,
400 IN EFI_IFR_TYPE_VALUE
*Value
,
401 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
404 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
405 return EFI_INVALID_PARAMETER
;
408 if ((Action
!= EFI_BROWSER_ACTION_CHANGING
) || (QuestionId
!= KEY_TPM_ACTION
)) {
409 return EFI_UNSUPPORTED
;
412 SavePpRequest (Value
->u8
);
419 This function publish the TCG configuration Form for TPM device.
421 @param[in, out] PrivateData Points to TCG configuration private data.
423 @retval EFI_SUCCESS HII Form is installed for this network device.
424 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
425 @retval Others Other errors as indicated.
429 InstallTcgConfigForm (
430 IN OUT TCG_CONFIG_PRIVATE_DATA
*PrivateData
434 EFI_HII_HANDLE HiiHandle
;
435 EFI_HANDLE DriverHandle
;
436 VOID
*StartOpCodeHandle
;
437 VOID
*EndOpCodeHandle
;
438 EFI_IFR_GUID_LABEL
*StartLabel
;
439 EFI_IFR_GUID_LABEL
*EndLabel
;
441 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
444 ConfigAccess
= &PrivateData
->ConfigAccess
;
445 Status
= gBS
->InstallMultipleProtocolInterfaces (
447 &gEfiDevicePathProtocolGuid
,
448 &mTcgHiiVendorDevicePath
,
449 &gEfiHiiConfigAccessProtocolGuid
,
453 if (EFI_ERROR (Status
)) {
457 PrivateData
->DriverHandle
= DriverHandle
;
460 // Publish the HII package list
462 HiiHandle
= HiiAddPackages (
469 if (HiiHandle
== NULL
) {
470 gBS
->UninstallMultipleProtocolInterfaces (
472 &gEfiDevicePathProtocolGuid
,
473 &mTcgHiiVendorDevicePath
,
474 &gEfiHiiConfigAccessProtocolGuid
,
479 return EFI_OUT_OF_RESOURCES
;
482 PrivateData
->HiiHandle
= HiiHandle
;
485 // Remove the Hide TPM question from the IFR
487 if (!PcdGetBool (PcdHideTpmSupport
)) {
489 // Allocate space for creation of UpdateData Buffer
491 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
492 ASSERT (StartOpCodeHandle
!= NULL
);
494 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
495 ASSERT (EndOpCodeHandle
!= NULL
);
498 // Create Hii Extend Label OpCode as the start opcode
500 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
501 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
502 StartLabel
->Number
= LABEL_TCG_CONFIGURATION_HIDETPM
;
505 // Create Hii Extend Label OpCode as the end opcode
507 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
508 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
509 EndLabel
->Number
= LABEL_END
;
511 HiiUpdateForm (HiiHandle
, NULL
, TCG_CONFIGURATION_FORM_ID
, StartOpCodeHandle
, EndOpCodeHandle
);
513 HiiFreeOpCodeHandle (StartOpCodeHandle
);
514 HiiFreeOpCodeHandle (EndOpCodeHandle
);
521 This function removes TCG configuration Form.
523 @param[in, out] PrivateData Points to TCG configuration private data.
527 UninstallTcgConfigForm (
528 IN OUT TCG_CONFIG_PRIVATE_DATA
*PrivateData
532 // Uninstall HII package list
534 if (PrivateData
->HiiHandle
!= NULL
) {
535 HiiRemovePackages (PrivateData
->HiiHandle
);
536 PrivateData
->HiiHandle
= NULL
;
540 // Uninstall HII Config Access Protocol
542 if (PrivateData
->DriverHandle
!= NULL
) {
543 gBS
->UninstallMultipleProtocolInterfaces (
544 PrivateData
->DriverHandle
,
545 &gEfiDevicePathProtocolGuid
,
546 &mTcgHiiVendorDevicePath
,
547 &gEfiHiiConfigAccessProtocolGuid
,
548 &PrivateData
->ConfigAccess
,
551 PrivateData
->DriverHandle
= NULL
;
554 FreePool (PrivateData
);