-/** @file\r
- HII Config Access protocol implementation of TREE configuration module.\r
- NOTE: This module is only for reference only, each platform should have its own setup page.\r
-\r
-Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "TrEEConfigImpl.h"\r
-#include <Library/PcdLib.h>\r
-#include <Library/Tpm2CommandLib.h>\r
-#include <Guid/TpmInstance.h>\r
-\r
-TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;\r
-\r
-TREE_CONFIG_PRIVATE_DATA mTrEEConfigPrivateDateTemplate = {\r
- TREE_CONFIG_PRIVATE_DATA_SIGNATURE,\r
- {\r
- TrEEExtractConfig,\r
- TrEERouteConfig,\r
- TrEECallback\r
- }\r
-};\r
-\r
-HII_VENDOR_DEVICE_PATH mTrEEHiiVendorDevicePath = {\r
- {\r
- {\r
- HARDWARE_DEVICE_PATH,\r
- HW_VENDOR_DP,\r
- {\r
- (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
- (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
- }\r
- },\r
- TREE_CONFIG_FORM_SET_GUID\r
- },\r
- {\r
- END_DEVICE_PATH_TYPE,\r
- END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
- { \r
- (UINT8) (END_DEVICE_PATH_LENGTH),\r
- (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
- }\r
- }\r
-};\r
-\r
-/**\r
- This function allows a caller to extract the current configuration for one\r
- or more named elements from the target driver.\r
-\r
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param[in] Request A null-terminated Unicode string in\r
- <ConfigRequest> format.\r
- @param[out] Progress On return, points to a character in the Request\r
- string. Points to the string's null terminator if\r
- request was successful. Points to the most recent\r
- '&' before the first failing name/value pair (or\r
- the beginning of the string if the failure is in\r
- the first name/value pair) if the request was not\r
- successful.\r
- @param[out] Results A null-terminated Unicode string in\r
- <ConfigAltResp> format which has all values filled\r
- in for the names in the Request string. String to\r
- be allocated by the called function.\r
-\r
- @retval EFI_SUCCESS The Results is filled with the requested values.\r
- @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
- @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
- driver.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-TrEEExtractConfig (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN CONST EFI_STRING Request,\r
- OUT EFI_STRING *Progress,\r
- OUT EFI_STRING *Results\r
- )\r
-{\r
- if (Progress == NULL || Results == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- *Progress = Request;\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-/**\r
- Save TPM request to variable space.\r
-\r
- @param[in] PpRequest Physical Presence request command.\r
-\r
- @retval EFI_SUCCESS The operation is finished successfully.\r
- @retval Others Other errors as indicated.\r
-\r
-**/\r
-EFI_STATUS\r
-SaveTrEEPpRequest (\r
- IN UINT8 PpRequest\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINTN DataSize;\r
- EFI_TREE_PHYSICAL_PRESENCE PpData;\r
-\r
- //\r
- // Save TPM command to variable.\r
- //\r
- DataSize = sizeof (EFI_TREE_PHYSICAL_PRESENCE);\r
- Status = gRT->GetVariable (\r
- TREE_PHYSICAL_PRESENCE_VARIABLE,\r
- &gEfiTrEEPhysicalPresenceGuid,\r
- NULL,\r
- &DataSize,\r
- &PpData\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- } \r
- \r
- PpData.PPRequest = PpRequest;\r
- Status = gRT->SetVariable (\r
- TREE_PHYSICAL_PRESENCE_VARIABLE,\r
- &gEfiTrEEPhysicalPresenceGuid,\r
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
- DataSize,\r
- &PpData\r
- );\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- This function processes the results of changes in configuration.\r
-\r
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
- format.\r
- @param[out] Progress A pointer to a string filled in with the offset of\r
- the most recent '&' before the first failing\r
- name/value pair (or the beginning of the string if\r
- the failure is in the first name/value pair) or\r
- the terminating NULL if all was successful.\r
-\r
- @retval EFI_SUCCESS The Results is processed successfully.\r
- @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
- driver.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-TrEERouteConfig (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN CONST EFI_STRING Configuration,\r
- OUT EFI_STRING *Progress\r
- )\r
-{\r
- if (Configuration == NULL || Progress == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-/**\r
- This function processes the results of changes in configuration.\r
-\r
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param[in] Action Specifies the type of action taken by the browser.\r
- @param[in] QuestionId A unique value which is sent to the original\r
- exporting driver so that it can identify the type\r
- of data to expect.\r
- @param[in] Type The type of value for the question.\r
- @param[in] Value A pointer to the data being sent to the original\r
- exporting driver.\r
- @param[out] ActionRequest On return, points to the action requested by the\r
- callback function.\r
-\r
- @retval EFI_SUCCESS The callback successfully handled the action.\r
- @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
- variable and its data.\r
- @retval EFI_DEVICE_ERROR The variable could not be saved.\r
- @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
- callback.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-TrEECallback (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN EFI_BROWSER_ACTION Action,\r
- IN EFI_QUESTION_ID QuestionId,\r
- IN UINT8 Type,\r
- IN EFI_IFR_TYPE_VALUE *Value,\r
- OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
- )\r
-{\r
- if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
- if (QuestionId == KEY_TPM_DEVICE) {\r
- return EFI_SUCCESS;\r
- }\r
- if (QuestionId == KEY_TPM2_OPERATION) {\r
- return SaveTrEEPpRequest (Value->u8);\r
- }\r
- }\r
-\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- This function publish the TREE configuration Form for TPM device.\r
-\r
- @param[in, out] PrivateData Points to TREE configuration private data.\r
-\r
- @retval EFI_SUCCESS HII Form is installed for this network device.\r
- @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
- @retval Others Other errors as indicated.\r
-\r
-**/\r
-EFI_STATUS\r
-InstallTrEEConfigForm (\r
- IN OUT TREE_CONFIG_PRIVATE_DATA *PrivateData\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HII_HANDLE HiiHandle;\r
- EFI_HANDLE DriverHandle;\r
- EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
-\r
- DriverHandle = NULL;\r
- ConfigAccess = &PrivateData->ConfigAccess;\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &DriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- &mTrEEHiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- ConfigAccess,\r
- NULL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- PrivateData->DriverHandle = DriverHandle;\r
-\r
- //\r
- // Publish the HII package list\r
- //\r
- HiiHandle = HiiAddPackages (\r
- &gTrEEConfigFormSetGuid,\r
- DriverHandle,\r
- TrEEConfigDxeStrings,\r
- TrEEConfigBin,\r
- NULL\r
- );\r
- if (HiiHandle == NULL) {\r
- gBS->UninstallMultipleProtocolInterfaces (\r
- DriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- &mTrEEHiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- ConfigAccess,\r
- NULL\r
- ); \r
-\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- \r
- PrivateData->HiiHandle = HiiHandle;\r
-\r
- //\r
- // Update static data\r
- //\r
- switch (PrivateData->TpmDeviceDetected) {\r
- case TPM_DEVICE_NULL:\r
- HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"Not Found", NULL);\r
- break;\r
- case TPM_DEVICE_1_2:\r
- HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);\r
- break;\r
- case TPM_DEVICE_2_0_DTPM:\r
- HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"TPM 2.0 (DTPM)", NULL);\r
- break;\r
- default:\r
- HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"Unknown", NULL);\r
- break;\r
- }\r
-\r
- return EFI_SUCCESS; \r
-}\r
-\r
-/**\r
- This function removes TREE configuration Form.\r
-\r
- @param[in, out] PrivateData Points to TREE configuration private data.\r
-\r
-**/\r
-VOID\r
-UninstallTrEEConfigForm (\r
- IN OUT TREE_CONFIG_PRIVATE_DATA *PrivateData\r
- )\r
-{\r
- //\r
- // Uninstall HII package list\r
- //\r
- if (PrivateData->HiiHandle != NULL) {\r
- HiiRemovePackages (PrivateData->HiiHandle);\r
- PrivateData->HiiHandle = NULL;\r
- }\r
-\r
- //\r
- // Uninstall HII Config Access Protocol\r
- //\r
- if (PrivateData->DriverHandle != NULL) {\r
- gBS->UninstallMultipleProtocolInterfaces (\r
- PrivateData->DriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- &mTrEEHiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &PrivateData->ConfigAccess,\r
- NULL\r
- );\r
- PrivateData->DriverHandle = NULL;\r
- }\r
- \r
- FreePool (PrivateData);\r
-}\r