--- /dev/null
+/** @file\r
+ Functions in this module are associated with variable parsing operations and\r
+ are intended to be usable across variable driver source files.\r
+\r
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef _VARIABLE_PARSING_H_\r
+#define _VARIABLE_PARSING_H_\r
+\r
+#include <Guid/ImageAuthentication.h>\r
+#include "Variable.h"\r
+\r
+/**\r
+\r
+ This code checks if variable header is valid or not.\r
+\r
+ @param[in] Variable Pointer to the Variable Header.\r
+ @param[in] VariableStoreEnd Pointer to the Variable Store End.\r
+\r
+ @retval TRUE Variable header is valid.\r
+ @retval FALSE Variable header is not valid.\r
+\r
+**/\r
+BOOLEAN\r
+IsValidVariableHeader (\r
+ IN VARIABLE_HEADER *Variable,\r
+ IN VARIABLE_HEADER *VariableStoreEnd\r
+ );\r
+\r
+/**\r
+\r
+ This code gets the current status of Variable Store.\r
+\r
+ @param[in] VarStoreHeader Pointer to the Variable Store Header.\r
+\r
+ @retval EfiRaw Variable store status is raw.\r
+ @retval EfiValid Variable store status is valid.\r
+ @retval EfiInvalid Variable store status is invalid.\r
+\r
+**/\r
+VARIABLE_STORE_STATUS\r
+GetVariableStoreStatus (\r
+ IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+ );\r
+\r
+/**\r
+ This code gets the size of variable header.\r
+\r
+ @return Size of variable header in bytes in type UINTN.\r
+\r
+**/\r
+UINTN\r
+GetVariableHeaderSize (\r
+ VOID\r
+ );\r
+\r
+/**\r
+\r
+ This code gets the size of name of variable.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return UINTN Size of variable in bytes.\r
+\r
+**/\r
+UINTN\r
+NameSizeOfVariable (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+ This code sets the size of name of variable.\r
+\r
+ @param[in] Variable Pointer to the Variable Header.\r
+ @param[in] NameSize Name size to set.\r
+\r
+**/\r
+VOID\r
+SetNameSizeOfVariable (\r
+ IN VARIABLE_HEADER *Variable,\r
+ IN UINTN NameSize\r
+ );\r
+\r
+/**\r
+\r
+ This code gets the size of variable data.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return Size of variable in bytes.\r
+\r
+**/\r
+UINTN\r
+DataSizeOfVariable (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+ This code sets the size of variable data.\r
+\r
+ @param[in] Variable Pointer to the Variable Header.\r
+ @param[in] DataSize Data size to set.\r
+\r
+**/\r
+VOID\r
+SetDataSizeOfVariable (\r
+ IN VARIABLE_HEADER *Variable,\r
+ IN UINTN DataSize\r
+ );\r
+\r
+/**\r
+\r
+ This code gets the pointer to the variable name.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return Pointer to Variable Name which is Unicode encoding.\r
+\r
+**/\r
+CHAR16 *\r
+GetVariableNamePtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+ This code gets the pointer to the variable guid.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return A EFI_GUID* pointer to Vendor Guid.\r
+\r
+**/\r
+EFI_GUID *\r
+GetVendorGuidPtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+\r
+ This code gets the pointer to the variable data.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return Pointer to Variable Data.\r
+\r
+**/\r
+UINT8 *\r
+GetVariableDataPtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+ This code gets the variable data offset related to variable header.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return Variable Data offset.\r
+\r
+**/\r
+UINTN\r
+GetVariableDataOffset (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+\r
+ This code gets the pointer to the next variable header.\r
+\r
+ @param Variable Pointer to the Variable Header.\r
+\r
+ @return Pointer to next variable header.\r
+\r
+**/\r
+VARIABLE_HEADER *\r
+GetNextVariablePtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ );\r
+\r
+/**\r
+\r
+ Gets the pointer to the first variable header in given variable store area.\r
+\r
+ @param[in] VarStoreHeader Pointer to the Variable Store Header.\r
+\r
+ @return Pointer to the first variable header.\r
+\r
+**/\r
+VARIABLE_HEADER *\r
+GetStartPointer (\r
+ IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+ );\r
+\r
+/**\r
+\r
+ Gets the pointer to the end of the variable storage area.\r
+\r
+ This function gets pointer to the end of the variable storage\r
+ area, according to the input variable store header.\r
+\r
+ @param[in] VarStoreHeader Pointer to the Variable Store Header.\r
+\r
+ @return Pointer to the end of the variable storage area.\r
+\r
+**/\r
+VARIABLE_HEADER *\r
+GetEndPointer (\r
+ IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+ );\r
+\r
+/**\r
+ Compare two EFI_TIME data.\r
+\r
+\r
+ @param[in] FirstTime A pointer to the first EFI_TIME data.\r
+ @param[in] SecondTime A pointer to the second EFI_TIME data.\r
+\r
+ @retval TRUE The FirstTime is not later than the SecondTime.\r
+ @retval FALSE The FirstTime is later than the SecondTime.\r
+\r
+**/\r
+BOOLEAN\r
+VariableCompareTimeStampInternal (\r
+ IN EFI_TIME *FirstTime,\r
+ IN EFI_TIME *SecondTime\r
+ );\r
+\r
+/**\r
+ Find the variable in the specified variable store.\r
+\r
+ @param[in] VariableName Name of the variable to be found\r
+ @param[in] VendorGuid Vendor GUID to be found.\r
+ @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
+ check at runtime when searching variable.\r
+ @param[in, out] PtrTrack Variable Track Pointer structure that contains Variable Information.\r
+\r
+ @retval EFI_SUCCESS Variable found successfully\r
+ @retval EFI_NOT_FOUND Variable not found\r
+**/\r
+EFI_STATUS\r
+FindVariableEx (\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ IN BOOLEAN IgnoreRtCheck,\r
+ IN OUT VARIABLE_POINTER_TRACK *PtrTrack\r
+ );\r
+\r
+/**\r
+ This code Finds the Next available variable.\r
+\r
+ Caution: This function may receive untrusted input.\r
+ This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r
+\r
+ @param[in] VariableName Pointer to variable name.\r
+ @param[in] VendorGuid Variable Vendor Guid.\r
+ @param[out] VariablePtr Pointer to variable header address.\r
+\r
+ @retval EFI_SUCCESS The function completed successfully.\r
+ @retval EFI_NOT_FOUND The next variable was not found.\r
+ @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL.\r
+ @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r
+ GUID of an existing variable.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VariableServiceGetNextVariableInternal (\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ OUT VARIABLE_HEADER **VariablePtr\r
+ );\r
+\r
+/**\r
+ Routine used to track statistical information about variable usage.\r
+ The data is stored in the EFI system table so it can be accessed later.\r
+ VariableInfo.efi can dump out the table. Only Boot Services variable\r
+ accesses are tracked by this code. The PcdVariableCollectStatistics\r
+ build flag controls if this feature is enabled.\r
+\r
+ A read that hits in the cache will have Read and Cache true for\r
+ the transaction. Data is allocated by this routine, but never\r
+ freed.\r
+\r
+ @param[in] VariableName Name of the Variable to track.\r
+ @param[in] VendorGuid Guid of the Variable to track.\r
+ @param[in] Volatile TRUE if volatile FALSE if non-volatile.\r
+ @param[in] Read TRUE if GetVariable() was called.\r
+ @param[in] Write TRUE if SetVariable() was called.\r
+ @param[in] Delete TRUE if deleted via SetVariable().\r
+ @param[in] Cache TRUE for a cache hit.\r
+\r
+**/\r
+VOID\r
+UpdateVariableInfo (\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ IN BOOLEAN Volatile,\r
+ IN BOOLEAN Read,\r
+ IN BOOLEAN Write,\r
+ IN BOOLEAN Delete,\r
+ IN BOOLEAN Cache\r
+ );\r
+\r
+#endif\r