2 HII Config Access protocol implementation of TCG configuration module.
4 Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "TcgConfigImpl.h"
11 CHAR16 mTcgStorageName
[] = L
"TCG_CONFIGURATION";
13 TCG_CONFIG_PRIVATE_DATA mTcgConfigPrivateDateTemplate
= {
14 TCG_CONFIG_PRIVATE_DATA_SIGNATURE
,
22 HII_VENDOR_DEVICE_PATH mTcgHiiVendorDevicePath
= {
28 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
29 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
32 TCG_CONFIG_FORM_SET_GUID
36 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
38 (UINT8
) (END_DEVICE_PATH_LENGTH
),
39 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
45 Get current state of TPM device.
47 @param[in] TcgProtocol Point to EFI_TCG_PROTOCOL instance.
48 @param[out] TpmEnable Flag to indicate TPM is enabled or not.
49 @param[out] TpmActivate Flag to indicate TPM is activated or not.
51 @retval EFI_SUCCESS State is successfully returned.
52 @retval EFI_DEVICE_ERROR Failed to get TPM response.
53 @retval Others Other errors as indicated.
58 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
59 OUT BOOLEAN
*TpmEnable
, OPTIONAL
60 OUT BOOLEAN
*TpmActivate OPTIONAL
64 TPM_RSP_COMMAND_HDR
*TpmRsp
;
66 TPM_PERMANENT_FLAGS
*TpmPermanentFlags
;
69 ASSERT (TcgProtocol
!= NULL
);
72 // Get TPM Permanent flags (TpmEnable, TpmActivate)
74 if ((TpmEnable
!= NULL
) || (TpmActivate
!= NULL
)) {
75 TpmSendSize
= sizeof (TPM_RQU_COMMAND_HDR
) + sizeof (UINT32
) * 3;
76 *(UINT16
*)&CmdBuf
[0] = SwapBytes16 (TPM_TAG_RQU_COMMAND
);
77 *(UINT32
*)&CmdBuf
[2] = SwapBytes32 (TpmSendSize
);
78 *(UINT32
*)&CmdBuf
[6] = SwapBytes32 (TPM_ORD_GetCapability
);
80 *(UINT32
*)&CmdBuf
[10] = SwapBytes32 (TPM_CAP_FLAG
);
81 *(UINT32
*)&CmdBuf
[14] = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT
));
82 *(UINT32
*)&CmdBuf
[18] = SwapBytes32 (TPM_CAP_FLAG_PERMANENT
);
84 Status
= TcgProtocol
->PassThroughToTpm (
91 TpmRsp
= (TPM_RSP_COMMAND_HDR
*) &CmdBuf
[0];
92 if (EFI_ERROR (Status
) || (TpmRsp
->tag
!= SwapBytes16 (TPM_TAG_RSP_COMMAND
)) || (TpmRsp
->returnCode
!= 0)) {
93 return EFI_DEVICE_ERROR
;
96 TpmPermanentFlags
= (TPM_PERMANENT_FLAGS
*) &CmdBuf
[sizeof (TPM_RSP_COMMAND_HDR
) + sizeof (UINT32
)];
98 if (TpmEnable
!= NULL
) {
99 *TpmEnable
= (BOOLEAN
) !TpmPermanentFlags
->disable
;
102 if (TpmActivate
!= NULL
) {
103 *TpmActivate
= (BOOLEAN
) !TpmPermanentFlags
->deactivated
;
111 This function allows a caller to extract the current configuration for one
112 or more named elements from the target driver.
114 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
115 @param[in] Request A null-terminated Unicode string in
116 <ConfigRequest> format.
117 @param[out] Progress On return, points to a character in the Request
118 string. Points to the string's null terminator if
119 request was successful. Points to the most recent
120 '&' before the first failing name/value pair (or
121 the beginning of the string if the failure is in
122 the first name/value pair) if the request was not
124 @param[out] Results A null-terminated Unicode string in
125 <ConfigAltResp> format which has all values filled
126 in for the names in the Request string. String to
127 be allocated by the called function.
129 @retval EFI_SUCCESS The Results is filled with the requested values.
130 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
131 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
132 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
139 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
140 IN CONST EFI_STRING Request
,
141 OUT EFI_STRING
*Progress
,
142 OUT EFI_STRING
*Results
146 TCG_CONFIG_PRIVATE_DATA
*PrivateData
;
147 EFI_STRING ConfigRequestHdr
;
148 EFI_STRING ConfigRequest
;
149 BOOLEAN AllocatedRequest
;
154 if (Progress
== NULL
|| Results
== NULL
) {
155 return EFI_INVALID_PARAMETER
;
159 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gTcgConfigFormSetGuid
, mTcgStorageName
)) {
160 return EFI_NOT_FOUND
;
163 ConfigRequestHdr
= NULL
;
164 ConfigRequest
= NULL
;
165 AllocatedRequest
= FALSE
;
168 PrivateData
= TCG_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
171 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
173 PrivateData
->Configuration
->TpmOperation
= PHYSICAL_PRESENCE_NO_ACTION
;
176 // Get current TPM state.
178 if (PrivateData
->TcgProtocol
!= NULL
) {
179 Status
= GetTpmState (PrivateData
->TcgProtocol
, &TpmEnable
, &TpmActivate
);
180 if (EFI_ERROR (Status
)) {
184 PrivateData
->Configuration
->TpmEnable
= TpmEnable
;
185 PrivateData
->Configuration
->TpmActivate
= TpmActivate
;
188 ConfigRequest
= Request
;
189 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
191 // Request has no request element, construct full request string.
192 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
193 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
195 ConfigRequestHdr
= HiiConstructConfigHdr (&gTcgConfigFormSetGuid
, mTcgStorageName
, PrivateData
->DriverHandle
);
196 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
197 ConfigRequest
= AllocateZeroPool (Size
);
198 ASSERT (ConfigRequest
!= NULL
);
199 AllocatedRequest
= TRUE
;
200 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, sizeof (TCG_CONFIGURATION
));
201 FreePool (ConfigRequestHdr
);
204 Status
= gHiiConfigRouting
->BlockToConfig (
207 (UINT8
*) PrivateData
->Configuration
,
208 sizeof (TCG_CONFIGURATION
),
213 // Free the allocated config request string.
215 if (AllocatedRequest
) {
216 FreePool (ConfigRequest
);
219 // Set Progress string to the original request string.
221 if (Request
== NULL
) {
223 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
224 *Progress
= Request
+ StrLen (Request
);
231 This function processes the results of changes in configuration.
233 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
234 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
236 @param[out] Progress A pointer to a string filled in with the offset of
237 the most recent '&' before the first failing
238 name/value pair (or the beginning of the string if
239 the failure is in the first name/value pair) or
240 the terminating NULL if all was successful.
242 @retval EFI_SUCCESS The Results is processed successfully.
243 @retval EFI_INVALID_PARAMETER Configuration is NULL.
244 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
251 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
252 IN CONST EFI_STRING Configuration
,
253 OUT EFI_STRING
*Progress
258 TCG_CONFIGURATION TcgConfiguration
;
260 if (Configuration
== NULL
|| Progress
== NULL
) {
261 return EFI_INVALID_PARAMETER
;
264 *Progress
= Configuration
;
265 if (!HiiIsConfigHdrMatch (Configuration
, &gTcgConfigFormSetGuid
, mTcgStorageName
)) {
266 return EFI_NOT_FOUND
;
270 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
272 BufferSize
= sizeof (TCG_CONFIGURATION
);
273 Status
= gHiiConfigRouting
->ConfigToBlock (
276 (UINT8
*) &TcgConfiguration
,
280 if (EFI_ERROR (Status
)) {
288 Save TPM request to variable space.
290 @param[in] PpRequest Physical Presence request command.
292 @retval EFI_SUCCESS The operation is finished successfully.
293 @retval Others Other errors as indicated.
303 EFI_PHYSICAL_PRESENCE PpData
;
306 // Save TPM command to variable.
308 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
309 Status
= gRT
->GetVariable (
310 PHYSICAL_PRESENCE_VARIABLE
,
311 &gEfiPhysicalPresenceGuid
,
316 if (EFI_ERROR (Status
)) {
320 PpData
.PPRequest
= PpRequest
;
321 Status
= gRT
->SetVariable (
322 PHYSICAL_PRESENCE_VARIABLE
,
323 &gEfiPhysicalPresenceGuid
,
324 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
328 if (EFI_ERROR(Status
)) {
336 This function processes the results of changes in configuration.
338 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
339 @param[in] Action Specifies the type of action taken by the browser.
340 @param[in] QuestionId A unique value which is sent to the original
341 exporting driver so that it can identify the type
343 @param[in] Type The type of value for the question.
344 @param[in] Value A pointer to the data being sent to the original
346 @param[out] ActionRequest On return, points to the action requested by the
349 @retval EFI_SUCCESS The callback successfully handled the action.
350 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
351 variable and its data.
352 @retval EFI_DEVICE_ERROR The variable could not be saved.
353 @retval EFI_UNSUPPORTED The specified Action is not supported by the
360 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
361 IN EFI_BROWSER_ACTION Action
,
362 IN EFI_QUESTION_ID QuestionId
,
364 IN EFI_IFR_TYPE_VALUE
*Value
,
365 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
368 TCG_CONFIG_PRIVATE_DATA
*PrivateData
;
371 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
372 return EFI_INVALID_PARAMETER
;
375 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
376 if (QuestionId
== KEY_TPM_ACTION
) {
378 PrivateData
= TCG_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
383 PrivateData
->Configuration
->TpmEnable
? L
"Enabled" : L
"Disabled",
384 PrivateData
->Configuration
->TpmActivate
? L
"Activated" : L
"Deactivated"
386 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM_STATE_CONTENT
), State
, NULL
);
391 if ((Action
!= EFI_BROWSER_ACTION_CHANGED
) || (QuestionId
!= KEY_TPM_ACTION
)) {
392 return EFI_UNSUPPORTED
;
395 SavePpRequest (Value
->u8
);
396 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
402 This function publish the TCG configuration Form for TPM device.
404 @param[in, out] PrivateData Points to TCG configuration private data.
406 @retval EFI_SUCCESS HII Form is installed for this network device.
407 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
408 @retval Others Other errors as indicated.
412 InstallTcgConfigForm (
413 IN OUT TCG_CONFIG_PRIVATE_DATA
*PrivateData
417 EFI_HII_HANDLE HiiHandle
;
418 EFI_HANDLE DriverHandle
;
419 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
422 ConfigAccess
= &PrivateData
->ConfigAccess
;
423 Status
= gBS
->InstallMultipleProtocolInterfaces (
425 &gEfiDevicePathProtocolGuid
,
426 &mTcgHiiVendorDevicePath
,
427 &gEfiHiiConfigAccessProtocolGuid
,
431 if (EFI_ERROR (Status
)) {
435 PrivateData
->DriverHandle
= DriverHandle
;
438 // Publish the HII package list
440 HiiHandle
= HiiAddPackages (
441 &gTcgConfigFormSetGuid
,
447 if (HiiHandle
== NULL
) {
448 gBS
->UninstallMultipleProtocolInterfaces (
450 &gEfiDevicePathProtocolGuid
,
451 &mTcgHiiVendorDevicePath
,
452 &gEfiHiiConfigAccessProtocolGuid
,
457 return EFI_OUT_OF_RESOURCES
;
460 PrivateData
->HiiHandle
= HiiHandle
;
466 This function removes TCG configuration Form.
468 @param[in, out] PrivateData Points to TCG configuration private data.
472 UninstallTcgConfigForm (
473 IN OUT TCG_CONFIG_PRIVATE_DATA
*PrivateData
477 // Uninstall HII package list
479 if (PrivateData
->HiiHandle
!= NULL
) {
480 HiiRemovePackages (PrivateData
->HiiHandle
);
481 PrivateData
->HiiHandle
= NULL
;
485 // Uninstall HII Config Access Protocol
487 if (PrivateData
->DriverHandle
!= NULL
) {
488 gBS
->UninstallMultipleProtocolInterfaces (
489 PrivateData
->DriverHandle
,
490 &gEfiDevicePathProtocolGuid
,
491 &mTcgHiiVendorDevicePath
,
492 &gEfiHiiConfigAccessProtocolGuid
,
493 &PrivateData
->ConfigAccess
,
496 PrivateData
->DriverHandle
= NULL
;
499 if (PrivateData
->Configuration
!= NULL
) {
500 FreePool(PrivateData
->Configuration
);
502 FreePool (PrivateData
);