2 HII Config Access protocol implementation of TREE configuration module.
3 NOTE: This module is only for reference only, each platform should have its own setup page.
5 Copyright (c) 2013, 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 "TrEEConfigImpl.h"
17 #include <Library/PcdLib.h>
18 #include <Library/Tpm2CommandLib.h>
19 #include <Guid/TpmInstance.h>
21 TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1] = TPM_INSTANCE_ID_LIST
;
23 TREE_CONFIG_PRIVATE_DATA mTrEEConfigPrivateDateTemplate
= {
24 TREE_CONFIG_PRIVATE_DATA_SIGNATURE
,
32 HII_VENDOR_DEVICE_PATH mTrEEHiiVendorDevicePath
= {
38 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
39 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
42 TREE_CONFIG_FORM_SET_GUID
46 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
48 (UINT8
) (END_DEVICE_PATH_LENGTH
),
49 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
55 This function allows a caller to extract the current configuration for one
56 or more named elements from the target driver.
58 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
59 @param[in] Request A null-terminated Unicode string in
60 <ConfigRequest> format.
61 @param[out] Progress On return, points to a character in the Request
62 string. Points to the string's null terminator if
63 request was successful. Points to the most recent
64 '&' before the first failing name/value pair (or
65 the beginning of the string if the failure is in
66 the first name/value pair) if the request was not
68 @param[out] Results A null-terminated Unicode string in
69 <ConfigAltResp> format which has all values filled
70 in for the names in the Request string. String to
71 be allocated by the called function.
73 @retval EFI_SUCCESS The Results is filled with the requested values.
74 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
75 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
76 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
83 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
84 IN CONST EFI_STRING Request
,
85 OUT EFI_STRING
*Progress
,
86 OUT EFI_STRING
*Results
91 TREE_CONFIGURATION Configuration
;
92 TREE_CONFIG_PRIVATE_DATA
*PrivateData
;
93 EFI_STRING ConfigRequestHdr
;
94 EFI_STRING ConfigRequest
;
95 BOOLEAN AllocatedRequest
;
99 if (Progress
== NULL
|| Results
== NULL
) {
100 return EFI_INVALID_PARAMETER
;
104 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gTrEEConfigFormSetGuid
, TREE_STORAGE_NAME
)) {
105 return EFI_NOT_FOUND
;
108 ConfigRequestHdr
= NULL
;
109 ConfigRequest
= NULL
;
110 AllocatedRequest
= FALSE
;
113 PrivateData
= TREE_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
116 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
118 BufferSize
= sizeof (Configuration
);
119 Status
= gRT
->GetVariable (
121 &gTrEEConfigFormSetGuid
,
126 ASSERT_EFI_ERROR (Status
);
129 // Get data from PCD to make sure data consistant - platform driver is suppose to construct this PCD accroding to Variable
131 for (Index
= 0; Index
< sizeof(mTpmInstanceId
)/sizeof(mTpmInstanceId
[0]); Index
++) {
132 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &mTpmInstanceId
[Index
].TpmInstanceGuid
)) {
133 Configuration
.TpmDevice
= mTpmInstanceId
[Index
].TpmDevice
;
138 BufferSize
= sizeof (Configuration
);
139 ConfigRequest
= Request
;
140 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
142 // Request has no request element, construct full request string.
143 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
144 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
146 ConfigRequestHdr
= HiiConstructConfigHdr (&gTrEEConfigFormSetGuid
, TREE_STORAGE_NAME
, PrivateData
->DriverHandle
);
147 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
148 ConfigRequest
= AllocateZeroPool (Size
);
149 ASSERT (ConfigRequest
!= NULL
);
150 AllocatedRequest
= TRUE
;
151 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
) BufferSize
);
152 FreePool (ConfigRequestHdr
);
155 Status
= gHiiConfigRouting
->BlockToConfig (
158 (UINT8
*) &Configuration
,
164 // Free the allocated config request string.
166 if (AllocatedRequest
) {
167 FreePool (ConfigRequest
);
170 // Set Progress string to the original request string.
172 if (Request
== NULL
) {
174 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
175 *Progress
= Request
+ StrLen (Request
);
182 Save TPM request to variable space.
184 @param[in] PpRequest Physical Presence request command.
186 @retval EFI_SUCCESS The operation is finished successfully.
187 @retval Others Other errors as indicated.
197 EFI_TREE_PHYSICAL_PRESENCE PpData
;
200 // Save TPM command to variable.
202 DataSize
= sizeof (EFI_TREE_PHYSICAL_PRESENCE
);
203 Status
= gRT
->GetVariable (
204 TREE_PHYSICAL_PRESENCE_VARIABLE
,
205 &gEfiTrEEPhysicalPresenceGuid
,
210 if (EFI_ERROR (Status
)) {
214 PpData
.PPRequest
= PpRequest
;
215 Status
= gRT
->SetVariable (
216 TREE_PHYSICAL_PRESENCE_VARIABLE
,
217 &gEfiTrEEPhysicalPresenceGuid
,
218 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
222 if (EFI_ERROR(Status
)) {
230 This function processes the results of changes in configuration.
232 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
233 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
235 @param[out] Progress A pointer to a string filled in with the offset of
236 the most recent '&' before the first failing
237 name/value pair (or the beginning of the string if
238 the failure is in the first name/value pair) or
239 the terminating NULL if all was successful.
241 @retval EFI_SUCCESS The Results is processed successfully.
242 @retval EFI_INVALID_PARAMETER Configuration is NULL.
243 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
250 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
251 IN CONST EFI_STRING Configuration
,
252 OUT EFI_STRING
*Progress
257 TREE_CONFIGURATION TrEEConfiguration
;
259 if (Configuration
== NULL
|| Progress
== NULL
) {
260 return EFI_INVALID_PARAMETER
;
263 *Progress
= Configuration
;
264 if (!HiiIsConfigHdrMatch (Configuration
, &gTrEEConfigFormSetGuid
, TREE_STORAGE_NAME
)) {
265 return EFI_NOT_FOUND
;
268 BufferSize
= sizeof (TrEEConfiguration
);
269 Status
= gRT
->GetVariable (
271 &gTrEEConfigFormSetGuid
,
276 ASSERT_EFI_ERROR (Status
);
279 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
281 BufferSize
= sizeof (TREE_CONFIGURATION
);
282 Status
= gHiiConfigRouting
->ConfigToBlock (
285 (UINT8
*) &TrEEConfiguration
,
289 if (EFI_ERROR (Status
)) {
294 // Save to variable so platform driver can get it.
296 Status
= gRT
->SetVariable (
298 &gTrEEConfigFormSetGuid
,
299 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
300 sizeof(TrEEConfiguration
),
304 SaveTrEEPpRequest (TrEEConfiguration
.Tpm2Operation
311 This function processes the results of changes in configuration.
313 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
314 @param[in] Action Specifies the type of action taken by the browser.
315 @param[in] QuestionId A unique value which is sent to the original
316 exporting driver so that it can identify the type
318 @param[in] Type The type of value for the question.
319 @param[in] Value A pointer to the data being sent to the original
321 @param[out] ActionRequest On return, points to the action requested by the
324 @retval EFI_SUCCESS The callback successfully handled the action.
325 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
326 variable and its data.
327 @retval EFI_DEVICE_ERROR The variable could not be saved.
328 @retval EFI_UNSUPPORTED The specified Action is not supported by the
335 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
336 IN EFI_BROWSER_ACTION Action
,
337 IN EFI_QUESTION_ID QuestionId
,
339 IN EFI_IFR_TYPE_VALUE
*Value
,
340 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
343 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
344 return EFI_INVALID_PARAMETER
;
347 if ((Action
!= EFI_BROWSER_ACTION_CHANGED
) ||
348 (QuestionId
!= KEY_TPM_DEVICE
)) {
349 return EFI_UNSUPPORTED
;
356 This function publish the TREE configuration Form for TPM device.
358 @param[in, out] PrivateData Points to TREE configuration private data.
360 @retval EFI_SUCCESS HII Form is installed for this network device.
361 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
362 @retval Others Other errors as indicated.
366 InstallTrEEConfigForm (
367 IN OUT TREE_CONFIG_PRIVATE_DATA
*PrivateData
371 EFI_HII_HANDLE HiiHandle
;
372 EFI_HANDLE DriverHandle
;
373 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
376 ConfigAccess
= &PrivateData
->ConfigAccess
;
377 Status
= gBS
->InstallMultipleProtocolInterfaces (
379 &gEfiDevicePathProtocolGuid
,
380 &mTrEEHiiVendorDevicePath
,
381 &gEfiHiiConfigAccessProtocolGuid
,
385 if (EFI_ERROR (Status
)) {
389 PrivateData
->DriverHandle
= DriverHandle
;
392 // Publish the HII package list
394 HiiHandle
= HiiAddPackages (
395 &gTrEEConfigFormSetGuid
,
397 TrEEConfigDxeStrings
,
401 if (HiiHandle
== NULL
) {
402 gBS
->UninstallMultipleProtocolInterfaces (
404 &gEfiDevicePathProtocolGuid
,
405 &mTrEEHiiVendorDevicePath
,
406 &gEfiHiiConfigAccessProtocolGuid
,
411 return EFI_OUT_OF_RESOURCES
;
414 PrivateData
->HiiHandle
= HiiHandle
;
420 This function removes TREE configuration Form.
422 @param[in, out] PrivateData Points to TREE configuration private data.
426 UninstallTrEEConfigForm (
427 IN OUT TREE_CONFIG_PRIVATE_DATA
*PrivateData
431 // Uninstall HII package list
433 if (PrivateData
->HiiHandle
!= NULL
) {
434 HiiRemovePackages (PrivateData
->HiiHandle
);
435 PrivateData
->HiiHandle
= NULL
;
439 // Uninstall HII Config Access Protocol
441 if (PrivateData
->DriverHandle
!= NULL
) {
442 gBS
->UninstallMultipleProtocolInterfaces (
443 PrivateData
->DriverHandle
,
444 &gEfiDevicePathProtocolGuid
,
445 &mTrEEHiiVendorDevicePath
,
446 &gEfiHiiConfigAccessProtocolGuid
,
447 &PrivateData
->ConfigAccess
,
450 PrivateData
->DriverHandle
= NULL
;
453 FreePool (PrivateData
);