summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>2008-05-23 05:25:44 +0000
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>2008-05-23 05:25:44 +0000
commitd9e5c1fffb22d39dd52ef23febe40cd4e2ee0965 (patch)
tree23b9c355ca02dbee8566b71685c63c319e9ee08d
parent254ba2477fd0b101228da33db03efed95c6489ae (diff)
downloadedk2-d9e5c1fffb22d39dd52ef23febe40cd4e2ee0965.zip
edk2-d9e5c1fffb22d39dd52ef23febe40cd4e2ee0965.tar.gz
edk2-d9e5c1fffb22d39dd52ef23febe40cd4e2ee0965.tar.bz2
1) Add BufToHexString, HexStringToBuf and IsHexDigit to BaseLib.
2) Remove the duplicated functions implementation from the modules that reference these APIs git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5282 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdePkg/Include/Library/BaseLib.h129
-rw-r--r--MdePkg/Include/Library/IfrSupportLib.h1180
-rw-r--r--MdePkg/Library/BaseLib/String.c239
-rw-r--r--MdePkg/Library/IfrSupportLib/IfrSupportLib.inf3
-rw-r--r--MdePkg/Library/IfrSupportLib/UefiIfrForm.c63
-rw-r--r--MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h4
6 files changed, 963 insertions, 655 deletions
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index cf337b7..0733da1 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -604,6 +604,134 @@ StrHexToUint64 (
IN CONST CHAR16 *String
);
+/**
+ Convert a nibble in the low 4 bits of a byte to a Unicode hexadecimal character.
+
+ This function converts a nibble in the low 4 bits of a byte to a Unicode hexadecimal
+ character For example, the nibble 0x01 and 0x0A will converted to L'1' and L'A'
+ respectively.
+
+ The upper nibble in the input byte will be masked off.
+
+ @param Nibble The nibble which is in the low 4 bits of the input byte.
+
+ @retval CHAR16 The Unicode hexadecimal character.
+
+**/
+CHAR16
+EFIAPI
+NibbleToHexChar (
+ IN UINT8 Nibble
+ )
+;
+
+/**
+ Convert binary buffer to a Unicode String in a specified sequence.
+
+ This function converts bytes in the binary Buffer Buf to a Unicode String Str.
+ Each byte will be represented by two Unicode characters. For example, byte 0xA1 will
+ be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character
+ for the Most Significant Nibble will be put before the Unicode Character for the Least Significant
+ Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1".
+ For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the
+ the last character in the output string. The one next to first byte will be put into the
+ character before the last character. This rules applies to the rest of the bytes. The Unicode
+ character by the last byte will be put into the first character in the output string. For example,
+ the input buffer for a 64-bits unsigned integrer 0x12345678abcdef1234 will be converted to
+ a Unicode string equal to L"12345678abcdef1234".
+
+ @param String On input, String is pointed to the buffer allocated for the convertion.
+ @param StringLen The Length of String buffer to hold the output String. The length must include the tailing '\0' character.
+ The StringLen required to convert a N bytes Buffer will be a least equal to or greater
+ than 2*N + 1.
+ @param Buffer The pointer to a input buffer.
+ @param BufferSizeInBytes Lenth in bytes of the input buffer.
+
+
+ @retval EFI_SUCCESS The convertion is successfull. All bytes in Buffer has been convert to the corresponding
+ Unicode character and placed into the right place in String.
+ @retval EFI_BUFFER_TOO_SMALL StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to
+ complete the convertion.
+**/
+RETURN_STATUS
+EFIAPI
+BufToHexString (
+ IN OUT CHAR16 *String,
+ IN OUT UINTN *StringLen,
+ IN CONST UINT8 *Buffer,
+ IN UINTN BufferSizeInBytes
+ )
+;
+
+
+/**
+ Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.
+
+ This function converts a Unicode string consisting of characters in the range of Hexadecimal
+ character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop
+ at the first non-hexadecimal character or the NULL character. The convertion process can be
+ simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be
+ converted into one byte. The first Unicode character represents the Most Significant Nibble and the
+ second Unicode character represents the Least Significant Nibble in the output byte.
+ The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode
+ characters represent the the byte preceding the last byte. This rule applies to the rest pairs of bytes.
+ The last pair represent the first byte in the output buffer.
+
+ For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes
+ (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".
+
+ If String has N valid hexadecimal characters for conversion, the caller must make sure Buffer is at least
+ N/2 (if N is even) or (N+1)/2 (if N if odd) bytes.
+
+ @param Buffer The output buffer allocated by the caller.
+ @param BufferSizeInBytes On input, the size in bytes of Buffer. On output, it is updated to
+ contain the size of the Buffer which is actually used for the converstion.
+ For Unicode string with 2*N hexadecimal characters (not including the
+ tailing NULL character), N bytes of Buffer will be used for the output.
+ @param String The input hexadecimal string.
+ @param ConvertedStrLen The number of hexadecimal characters used to produce content in output
+ buffer Buffer.
+
+ @retval RETURN_BUFFER_TOO_SMALL The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes
+ will be updated to the size required for the converstion.
+ @retval RETURN_SUCCESS The convertion is successful or the first Unicode character from String
+ is hexadecimal. If ConvertedStrLen is not NULL, it is updated
+ to the number of hexadecimal character used for the converstion.
+**/
+RETURN_STATUS
+EFIAPI
+HexStringToBuf (
+ OUT UINT8 *Buffer,
+ IN OUT UINTN *BufferSizeInBytes,
+ IN CONST CHAR16 *String,
+ OUT UINTN *ConvertedStrLen OPTIONAL
+ )
+;
+
+
+/**
+ Test if a Unicode character is a hexadecimal digit. If true, the input
+ Unicode character is converted to a byte.
+
+ This function tests if a Unicode character is a hexadecimal digit. If true, the input
+ Unicode character is converted to a byte. For example, Unicode character
+ L'A' will be converted to 0x0A.
+
+ If Digit is NULL, then ASSERT.
+
+ @retval TRUE Char is in the range of Hexadecimal number. Digit is updated
+ to the byte value of the number.
+ @retval FALSE Char is not in the range of Hexadecimal number. Digit is keep
+ intact.
+
+**/
+BOOLEAN
+EFIAPI
+IsHexDigit (
+ OUT UINT8 *Digit,
+ IN CHAR16 Char
+ )
+;
/**
Convert one Null-terminated Unicode string to a Null-terminated
@@ -7108,3 +7236,4 @@ AsmPrepareAndThunk16 (
#endif
+
diff --git a/MdePkg/Include/Library/IfrSupportLib.h b/MdePkg/Include/Library/IfrSupportLib.h
index e3885e1..b8d3183 100644
--- a/MdePkg/Include/Library/IfrSupportLib.h
+++ b/MdePkg/Include/Library/IfrSupportLib.h
@@ -1,5 +1,5 @@
/** @file
- The file contain all library functions and definitions for IFR opcode creation and
+ The file contain all library functions and definitions for IFR opcode creation and
related Form Browser utility Operations.
Copyright (c) 2007, Intel Corporation
@@ -11,594 +11,590 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-**/
-
-#ifndef _IFR_SUPPORT_LIBRARY_H
-#define _IFR_SUPPORT_LIBRARY_H
-
-
-#include <Protocol/HiiFont.h>
-#include <Protocol/HiiImage.h>
-#include <Protocol/HiiString.h>
-#include <Protocol/HiiDatabase.h>
-#include <Protocol/HiiConfigRouting.h>
-#include <Protocol/HiiConfigAccess.h>
-#include <Protocol/FormBrowser2.h>
-#include <Protocol/SimpleTextOut.h>
-
-#include <Guid/GlobalVariable.h>
-
-//
-// The architectural variable "Lang" and "LangCodes" are deprecated in UEFI
-// specification. While, UEFI specification also states that these deprecated
-// variables may be provided for backwards compatibility.
-// If "LANG_SUPPORT" is defined, "Lang" and "LangCodes" will be produced;
-// If "LANG_SUPPORT" is undefined, "Lang" and "LangCodes" will not be produced.
-//
-#define LANG_SUPPORT
-
-#define EFI_LANGUAGE_VARIABLE L"Lang"
-#define EFI_LANGUAGE_CODES_VARIABLE L"LangCodes"
-
-#define UEFI_LANGUAGE_VARIABLE L"PlatformLang"
-#define UEFI_LANGUAGE_CODES_VARIABLE L"PlatformLangCodes"
-
-//
-// Limited buffer size recommended by RFC4646 (4.3. Length Considerations)
-// (42 characters plus a NULL terminator)
-//
-#define RFC_3066_ENTRY_SIZE (42 + 1)
-#define ISO_639_2_ENTRY_SIZE 3
-
-#define INVALID_VARSTORE_ID 0
-
-#define QUESTION_FLAGS (EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY)
-#define QUESTION_FLAGS_MASK (~QUESTION_FLAGS)
-
-extern EFI_HII_DATABASE_PROTOCOL *gIfrLibHiiDatabase;
-extern EFI_HII_STRING_PROTOCOL *gIfrLibHiiString;
-
-#pragma pack(1)
-typedef struct {
- EFI_STRING_ID StringToken;
- EFI_IFR_TYPE_VALUE Value;
- UINT8 Flags;
-} IFR_OPTION;
-#pragma pack()
-
-typedef struct {
- //
- // Buffer size allocated for Data.
- //
- UINT32 BufferSize;
-
- //
- // Offset in Data to append the newly created opcode binary.
- // It will be adjusted automatically in Create***OpCode(), and should be
- // initialized to 0 before invocation of a serial of Create***OpCode()
- //
- UINT32 Offset;
-
- //
- // The destination buffer for created op-codes
- //
- UINT8 *Data;
-} EFI_HII_UPDATE_DATA;
-
-
-/**
- Create EFI_IFR_END_OP opcode.
-
- If Data is NULL or Data->Data is NULL, then ASSERT.
-
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateEndOpCode (
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_DEFAULT_OP opcode.
-
- @param Value Value for the default
- @param Type Type for the default
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER The type is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateDefaultOpCode (
- IN EFI_IFR_TYPE_VALUE *Value,
- IN UINT8 Type,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_ACTION_OP opcode.
-
- @param QuestionId Question ID
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param QuestionConfig String ID for configuration
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateActionOpCode (
- IN EFI_QUESTION_ID QuestionId,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN EFI_STRING_ID QuestionConfig,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_SUBTITLE_OP opcode.
-
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param Flags Subtitle opcode flags
- @param Scope Subtitle Scope bit
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateSubTitleOpCode (
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 Flags,
- IN UINT8 Scope,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_TEXT_OP opcode.
-
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param TextTwo String ID for text two
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateTextOpCode (
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN EFI_STRING_ID TextTwo,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_REF_OP opcode.
-
- @param FormId Destination Form ID
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param QuestionId Question ID
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateGotoOpCode (
- IN EFI_FORM_ID FormId,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN EFI_QUESTION_ID QuestionId,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_ONE_OF_OPTION_OP opcode.
-
- @param QuestionId Question ID
- @param OptionList The list of Options.
- @param Type The data type.
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateOneOfOptionOpCode (
- IN UINTN OptionCount,
- IN IFR_OPTION *OptionsList,
- IN UINT8 Type,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_ONE_OF_OP opcode.
-
- @param QuestionId Question ID
- @param VarStoreId Storage ID
- @param VarOffset Offset in Storage
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param OneOfFlags Flags for oneof opcode
- @param OptionsList List of options
- @param OptionCount Number of options in option list
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateOneOfOpCode (
- IN EFI_QUESTION_ID QuestionId,
- IN EFI_VARSTORE_ID VarStoreId,
- IN UINT16 VarOffset,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN UINT8 OneOfFlags,
- IN IFR_OPTION *OptionsList,
- IN UINTN OptionCount,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_ORDERED_LIST_OP opcode.
-
- @param QuestionId Question ID
- @param VarStoreId Storage ID
- @param VarOffset Offset in Storage
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param Flags Flags for ordered list opcode
- @param DataType Type for option value
- @param MaxContainers Maximum count for options in this ordered list
- @param OptionsList List of options
- @param OptionCount Number of options in option list
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateOrderedListOpCode (
- IN EFI_QUESTION_ID QuestionId,
- IN EFI_VARSTORE_ID VarStoreId,
- IN UINT16 VarOffset,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN UINT8 Flags,
- IN UINT8 DataType,
- IN UINT8 MaxContainers,
- IN IFR_OPTION *OptionsList,
- IN UINTN OptionCount,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_CHECKBOX_OP opcode.
-
- @param QuestionId Question ID
- @param VarStoreId Storage ID
- @param VarOffset Offset in Storage
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param CheckBoxFlags Flags for checkbox opcode
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateCheckBoxOpCode (
- IN EFI_QUESTION_ID QuestionId,
- IN EFI_VARSTORE_ID VarStoreId,
- IN UINT16 VarOffset,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN UINT8 CheckBoxFlags,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_NUMERIC_OP opcode.
-
- @param QuestionId Question ID
- @param VarStoreId Storage ID
- @param VarOffset Offset in Storage
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param NumericFlags Flags for numeric opcode
- @param Minimum Numeric minimum value
- @param Maximum Numeric maximum value
- @param Step Numeric step for edit
- @param Default Numeric default value
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateNumericOpCode (
- IN EFI_QUESTION_ID QuestionId,
- IN EFI_VARSTORE_ID VarStoreId,
- IN UINT16 VarOffset,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN UINT8 NumericFlags,
- IN UINT64 Minimum,
- IN UINT64 Maximum,
- IN UINT64 Step,
- IN UINT64 Default,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Create EFI_IFR_STRING_OP opcode.
-
- @param QuestionId Question ID
- @param VarStoreId Storage ID
- @param VarOffset Offset in Storage
- @param Prompt String ID for Prompt
- @param Help String ID for Help
- @param QuestionFlags Flags in Question Header
- @param StringFlags Flags for string opcode
- @param MinSize String minimum length
- @param MaxSize String maximum length
- @param Data Destination for the created opcode binary
-
- @retval EFI_SUCCESS Opcode create success
- @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
- @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
-
-**/
-EFI_STATUS
-EFIAPI
-CreateStringOpCode (
- IN EFI_QUESTION_ID QuestionId,
- IN EFI_VARSTORE_ID VarStoreId,
- IN UINT16 VarOffset,
- IN EFI_STRING_ID Prompt,
- IN EFI_STRING_ID Help,
- IN UINT8 QuestionFlags,
- IN UINT8 StringFlags,
- IN UINT8 MinSize,
- IN UINT8 MaxSize,
- IN OUT EFI_HII_UPDATE_DATA *Data
- )
-;
-
-/**
- Converts binary buffer to Unicode string in reversed byte order to BufToHexString().
-
- @param Str String for output
- @param Buffer Binary buffer.
- @param BufferSize Size of the buffer in bytes.
-
- @retval EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-BufferToHexString (
- IN OUT CHAR16 *Str,
- IN UINT8 *Buffer,
- IN UINTN BufferSize
- )
-;
-
-/**
- Converts Hex String to binary buffer in reversed byte order to HexStringToBuf().
-
- @param Buffer Pointer to buffer that receives the data.
- @param BufferSize Length in bytes of the buffer to hold converted
- data. If routine return with EFI_SUCCESS,
- containing length of converted data. If routine
- return with EFI_BUFFER_TOO_SMALL, containg length
- of buffer desired.
- @param Str String to be converted from.
-
- @retval EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-HexStringToBuffer (
- IN OUT UINT8 *Buffer,
- IN OUT UINTN *BufferSize,
- IN CHAR16 *Str
- )
-;
-
-/**
- Construct <ConfigHdr> using routing information GUID/NAME/PATH.
-
- @param ConfigHdr Pointer to the ConfigHdr string.
- @param StrBufferLen On input: Length in bytes of buffer to hold the
- ConfigHdr string. Includes tailing '\0' character.
- On output: If return EFI_SUCCESS, containing
- length of ConfigHdr string buffer. If return
- EFI_BUFFER_TOO_SMALL, containg length of string
- buffer desired.
- @param Guid Routing information: GUID.
- @param Name Routing information: NAME.
- @param DriverHandle Driver handle which contains the routing
- information: PATH.
-
- @retval EFI_SUCCESS Routine success.
- @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small.
-
-**/
-EFI_STATUS
-EFIAPI
-ConstructConfigHdr (
- IN OUT CHAR16 *ConfigHdr,
- IN OUT UINTN *StrBufferLen,
- IN EFI_GUID *Guid,
- IN CHAR16 *Name, OPTIONAL
- IN EFI_HANDLE *DriverHandle
- )
-
-;
-
-/**
- Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string.
-
- @param String The string to be searched in.
- @param Offset Offset in BlockName.
- @param Width Width in BlockName.
-
- @retval TRUE Block name found.
- @retval FALSE Block name not found.
-
-**/
-BOOLEAN
-EFIAPI
-FindBlockName (
- IN OUT CHAR16 *String,
- UINTN Offset,
- UINTN Width
- )
-;
-
-/**
- This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser.
-
- @param VariableGuid An optional field to indicate the target variable
- GUID name to use.
- @param VariableName An optional field to indicate the target
- human-readable variable name.
- @param BufferSize On input: Length in bytes of buffer to hold
- retrived data. On output: If return
- EFI_BUFFER_TOO_SMALL, containg length of buffer
- desired.
- @param Buffer Buffer to hold retrived data.
-
- @retval EFI_SUCCESS Routine success.
- @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small.
-
-**/
-EFI_STATUS
-EFIAPI
-GetBrowserData (
- EFI_GUID *VariableGuid, OPTIONAL
- CHAR16 *VariableName, OPTIONAL
- UINTN *BufferSize,
- UINT8 *Buffer
- )
-;
-
-/**
- This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser.
-
- @param VariableGuid An optional field to indicate the target variable
- GUID name to use.
- @param VariableName An optional field to indicate the target
- human-readable variable name.
- @param BufferSize Length in bytes of buffer to hold retrived data.
- @param Buffer Buffer to hold retrived data.
- @param RequestElement An optional field to specify which part of the
- buffer data will be send back to Browser. If NULL,
- the whole buffer of data will be committed to
- Browser. <RequestElement> ::=
- &OFFSET=<Number>&WIDTH=<Number>*
-
- @retval EFI_SUCCESS Routine success.
- @retval Other Updating Browser uncommitted data failed.
-
-**/
-EFI_STATUS
-EFIAPI
-SetBrowserData (
- EFI_GUID *VariableGuid, OPTIONAL
- CHAR16 *VariableName, OPTIONAL
- UINTN BufferSize,
- UINT8 *Buffer,
- CHAR16 *RequestElement OPTIONAL
- )
-;
-
-/**
- Draw a dialog and return the selected key.
-
- @param NumberOfLines The number of lines for the dialog box
- @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
- @param String Pointer to the first string in the list
- @param ... A series of (quantity == NumberOfLines) text
- strings which will be used to construct the dialog
- box
-
- @retval EFI_SUCCESS Displayed dialog and received user interaction
- @retval EFI_INVALID_PARAMETER One of the parameters was invalid.
-
-**/
-
-EFI_STATUS
-EFIAPI
-IfrLibCreatePopUp (
- IN UINTN NumberOfLines,
- OUT EFI_INPUT_KEY *KeyValue,
- IN CHAR16 *String,
- ...
- )
-;
-
-#endif
+**/
+
+#ifndef _IFR_SUPPORT_LIBRARY_H
+#define _IFR_SUPPORT_LIBRARY_H
+
+
+#include <Protocol/HiiFont.h>
+#include <Protocol/HiiImage.h>
+#include <Protocol/HiiString.h>
+#include <Protocol/HiiDatabase.h>
+#include <Protocol/HiiConfigRouting.h>
+#include <Protocol/HiiConfigAccess.h>
+#include <Protocol/FormBrowser2.h>
+#include <Protocol/SimpleTextOut.h>
+
+#include <Guid/GlobalVariable.h>
+
+//
+// The architectural variable "Lang" and "LangCodes" are deprecated in UEFI
+// specification. While, UEFI specification also states that these deprecated
+// variables may be provided for backwards compatibility.
+
+#define EFI_LANGUAGE_VARIABLE L"Lang"
+#define EFI_LANGUAGE_CODES_VARIABLE L"LangCodes"
+
+#define UEFI_LANGUAGE_VARIABLE L"PlatformLang"
+#define UEFI_LANGUAGE_CODES_VARIABLE L"PlatformLangCodes"
+
+//
+// Limited buffer size recommended by RFC4646 (4.3. Length Considerations)
+// (42 characters plus a NULL terminator)
+//
+#define RFC_3066_ENTRY_SIZE (42 + 1)
+#define ISO_639_2_ENTRY_SIZE 3
+
+#define INVALID_VARSTORE_ID 0
+
+#define QUESTION_FLAGS (EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY)
+#define QUESTION_FLAGS_MASK (~QUESTION_FLAGS)
+
+extern EFI_HII_DATABASE_PROTOCOL *gIfrLibHiiDatabase;
+extern EFI_HII_STRING_PROTOCOL *gIfrLibHiiString;
+
+#pragma pack(1)
+typedef struct {
+ EFI_STRING_ID StringToken;
+ EFI_IFR_TYPE_VALUE Value;
+ UINT8 Flags;
+} IFR_OPTION;
+#pragma pack()
+
+typedef struct {
+ //
+ // Buffer size allocated for Data.
+ //
+ UINT32 BufferSize;
+
+ //
+ // Offset in Data to append the newly created opcode binary.
+ // It will be adjusted automatically in Create***OpCode(), and should be
+ // initialized to 0 before invocation of a serial of Create***OpCode()
+ //
+ UINT32 Offset;
+
+ //
+ // The destination buffer for created op-codes
+ //
+ UINT8 *Data;
+} EFI_HII_UPDATE_DATA;
+
+
+/**
+ Create EFI_IFR_END_OP opcode.
+
+ If Data is NULL or Data->Data is NULL, then ASSERT.
+
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateEndOpCode (
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_DEFAULT_OP opcode.
+
+ @param Value Value for the default
+ @param Type Type for the default
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER The type is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateDefaultOpCode (
+ IN EFI_IFR_TYPE_VALUE *Value,
+ IN UINT8 Type,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_ACTION_OP opcode.
+
+ @param QuestionId Question ID
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param QuestionConfig String ID for configuration
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateActionOpCode (
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN EFI_STRING_ID QuestionConfig,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_SUBTITLE_OP opcode.
+
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param Flags Subtitle opcode flags
+ @param Scope Subtitle Scope bit
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateSubTitleOpCode (
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 Flags,
+ IN UINT8 Scope,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_TEXT_OP opcode.
+
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param TextTwo String ID for text two
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateTextOpCode (
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN EFI_STRING_ID TextTwo,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_REF_OP opcode.
+
+ @param FormId Destination Form ID
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param QuestionId Question ID
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateGotoOpCode (
+ IN EFI_FORM_ID FormId,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN EFI_QUESTION_ID QuestionId,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_ONE_OF_OPTION_OP opcode.
+
+ @param QuestionId Question ID
+ @param OptionList The list of Options.
+ @param Type The data type.
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateOneOfOptionOpCode (
+ IN UINTN OptionCount,
+ IN IFR_OPTION *OptionsList,
+ IN UINT8 Type,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_ONE_OF_OP opcode.
+
+ @param QuestionId Question ID
+ @param VarStoreId Storage ID
+ @param VarOffset Offset in Storage
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param OneOfFlags Flags for oneof opcode
+ @param OptionsList List of options
+ @param OptionCount Number of options in option list
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateOneOfOpCode (
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 OneOfFlags,
+ IN IFR_OPTION *OptionsList,
+ IN UINTN OptionCount,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_ORDERED_LIST_OP opcode.
+
+ @param QuestionId Question ID
+ @param VarStoreId Storage ID
+ @param VarOffset Offset in Storage
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param Flags Flags for ordered list opcode
+ @param DataType Type for option value
+ @param MaxContainers Maximum count for options in this ordered list
+ @param OptionsList List of options
+ @param OptionCount Number of options in option list
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateOrderedListOpCode (
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 Flags,
+ IN UINT8 DataType,
+ IN UINT8 MaxContainers,
+ IN IFR_OPTION *OptionsList,
+ IN UINTN OptionCount,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_CHECKBOX_OP opcode.
+
+ @param QuestionId Question ID
+ @param VarStoreId Storage ID
+ @param VarOffset Offset in Storage
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param CheckBoxFlags Flags for checkbox opcode
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateCheckBoxOpCode (
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 CheckBoxFlags,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_NUMERIC_OP opcode.
+
+ @param QuestionId Question ID
+ @param VarStoreId Storage ID
+ @param VarOffset Offset in Storage
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param NumericFlags Flags for numeric opcode
+ @param Minimum Numeric minimum value
+ @param Maximum Numeric maximum value
+ @param Step Numeric step for edit
+ @param Default Numeric default value
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateNumericOpCode (
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 NumericFlags,
+ IN UINT64 Minimum,
+ IN UINT64 Maximum,
+ IN UINT64 Step,
+ IN UINT64 Default,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Create EFI_IFR_STRING_OP opcode.
+
+ @param QuestionId Question ID
+ @param VarStoreId Storage ID
+ @param VarOffset Offset in Storage
+ @param Prompt String ID for Prompt
+ @param Help String ID for Help
+ @param QuestionFlags Flags in Question Header
+ @param StringFlags Flags for string opcode
+ @param MinSize String minimum length
+ @param MaxSize String maximum length
+ @param Data Destination for the created opcode binary
+
+ @retval EFI_SUCCESS Opcode create success
+ @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
+ @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
+
+**/
+EFI_STATUS
+EFIAPI
+CreateStringOpCode (
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 StringFlags,
+ IN UINT8 MinSize,
+ IN UINT8 MaxSize,
+ IN OUT EFI_HII_UPDATE_DATA *Data
+ )
+;
+
+/**
+ Converts binary buffer to Unicode string in reversed byte order to BufToHexString().
+
+ @param Str String for output
+ @param Buffer Binary buffer.
+ @param BufferSize Size of the buffer in bytes.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+BufferToHexString (
+ IN OUT CHAR16 *Str,
+ IN UINT8 *Buffer,
+ IN UINTN BufferSize
+ )
+;
+
+/**
+ Converts Hex String to binary buffer in reversed byte order to HexStringToBuf().
+
+ @param Buffer Pointer to buffer that receives the data.
+ @param BufferSize Length in bytes of the buffer to hold converted
+ data. If routine return with EFI_SUCCESS,
+ containing length of converted data. If routine
+ return with EFI_BUFFER_TOO_SMALL, containg length
+ of buffer desired.
+ @param Str String to be converted from.
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+HexStringToBuffer (
+ IN OUT UINT8 *Buffer,
+ IN OUT UINTN *BufferSize,
+ IN CHAR16 *Str
+ )
+;
+
+/**
+ Construct <ConfigHdr> using routing information GUID/NAME/PATH.
+
+ @param ConfigHdr Pointer to the ConfigHdr string.
+ @param StrBufferLen On input: Length in bytes of buffer to hold the
+ ConfigHdr string. Includes tailing '\0' character.
+ On output: If return EFI_SUCCESS, containing
+ length of ConfigHdr string buffer. If return
+ EFI_BUFFER_TOO_SMALL, containg length of string
+ buffer desired.
+ @param Guid Routing information: GUID.
+ @param Name Routing information: NAME.
+ @param DriverHandle Driver handle which contains the routing
+ information: PATH.
+
+ @retval EFI_SUCCESS Routine success.
+ @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small.
+
+**/
+EFI_STATUS
+EFIAPI
+ConstructConfigHdr (
+ IN OUT CHAR16 *ConfigHdr,
+ IN OUT UINTN *StrBufferLen,
+ IN EFI_GUID *Guid,
+ IN CHAR16 *Name, OPTIONAL
+ IN EFI_HANDLE *DriverHandle
+ )
+
+;
+
+/**
+ Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string.
+
+ @param String The string to be searched in.
+ @param Offset Offset in BlockName.
+ @param Width Width in BlockName.
+
+ @retval TRUE Block name found.
+ @retval FALSE Block name not found.
+
+**/
+BOOLEAN
+EFIAPI
+FindBlockName (
+ IN OUT CHAR16 *String,
+ UINTN Offset,
+ UINTN Width
+ )
+;
+
+/**
+ This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser.
+
+ @param VariableGuid An optional field to indicate the target variable
+ GUID name to use.
+ @param VariableName An optional field to indicate the target
+ human-readable variable name.
+ @param BufferSize On input: Length in bytes of buffer to hold
+ retrived data. On output: If return
+ EFI_BUFFER_TOO_SMALL, containg length of buffer
+ desired.
+ @param Buffer Buffer to hold retrived data.
+
+ @retval EFI_SUCCESS Routine success.
+ @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small.
+
+**/
+EFI_STATUS
+EFIAPI
+GetBrowserData (
+ EFI_GUID *VariableGuid, OPTIONAL
+ CHAR16 *VariableName, OPTIONAL
+ UINTN *BufferSize,
+ UINT8 *Buffer
+ )
+;
+
+/**
+ This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser.
+
+ @param VariableGuid An optional field to indicate the target variable
+ GUID name to use.
+ @param VariableName An optional field to indicate the target
+ human-readable variable name.
+ @param BufferSize Length in bytes of buffer to hold retrived data.
+ @param Buffer Buffer to hold retrived data.
+ @param RequestElement An optional field to specify which part of the
+ buffer data will be send back to Browser. If NULL,
+ the whole buffer of data will be committed to
+ Browser. <RequestElement> ::=
+ &OFFSET=<Number>&WIDTH=<Number>*
+
+ @retval EFI_SUCCESS Routine success.
+ @retval Other Updating Browser uncommitted data failed.
+
+**/
+EFI_STATUS
+EFIAPI
+SetBrowserData (
+ EFI_GUID *VariableGuid, OPTIONAL
+ CHAR16 *VariableName, OPTIONAL
+ UINTN BufferSize,
+ UINT8 *Buffer,
+ CHAR16 *RequestElement OPTIONAL
+ )
+;
+
+/**
+ Draw a dialog and return the selected key.
+
+ @param NumberOfLines The number of lines for the dialog box
+ @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
+ @param String Pointer to the first string in the list
+ @param ... A series of (quantity == NumberOfLines) text
+ strings which will be used to construct the dialog
+ box
+
+ @retval EFI_SUCCESS Displayed dialog and received user interaction
+ @retval EFI_INVALID_PARAMETER One of the parameters was invalid.
+
+**/
+
+EFI_STATUS
+EFIAPI
+IfrLibCreatePopUp (
+ IN UINTN NumberOfLines,
+ OUT EFI_INPUT_KEY *KeyValue,
+ IN CHAR16 *String,
+ ...
+ )
+;
+
+#endif
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index 94471f3..909262e 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -2073,3 +2073,242 @@ BcdToDecimal8 (
}
+/**
+ Convert a nibble in the low 4 bits of a byte to a Unicode hexadecimal character.
+
+ This function converts a nibble in the low 4 bits of a byte to a Unicode hexadecimal
+ character For example, the nibble 0x01 and 0x0A will converted to L'1' and L'A'
+ respectively.
+
+ The upper nibble in the input byte will be masked off.
+
+ @param Nibble The nibble which is in the low 4 bits of the input byte.
+
+ @retval CHAR16 The Unicode hexadecimal character.
+
+**/
+CHAR16
+NibbleToHexChar (
+ IN UINT8 Nibble
+ )
+{
+ Nibble &= 0x0F;
+ if (Nibble <= 0x9) {
+ return (CHAR16)(Nibble + L'0');
+ }
+
+ return (CHAR16)(Nibble - 0xA + L'A');
+}
+
+/**
+ Convert binary buffer to a Unicode String in a specified sequence.
+
+ This function converts bytes in the binary Buffer Buf to a Unicode String Str.
+ Each byte will be represented by two Unicode characters. For example, byte 0xA1 will
+ be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character
+ for the Most Significant Nibble will be put before the Unicode Character for the Least Significant
+ Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1".
+ For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the
+ the last character in the output string. The one next to first byte will be put into the
+ character before the last character. This rules applies to the rest of the bytes. The Unicode
+ character by the last byte will be put into the first character in the output string. For example,
+ the input buffer for a 64-bits unsigned integrer 0x12345678abcdef1234 will be converted to
+ a Unicode string equal to L"12345678abcdef1234".
+
+ @param String On input, String is pointed to the buffer allocated for the convertion.
+ @param StringLen The Length of String buffer to hold the output String. The length must include the tailing '\0' character.
+ The StringLen required to convert a N bytes Buffer will be a least equal to or greater
+ than 2*N + 1.
+ @param Buffer The pointer to a input buffer.
+ @param BufferSizeInBytes Lenth in bytes of the input buffer.
+
+
+ @retval EFI_SUCCESS The convertion is successfull. All bytes in Buffer has been convert to the corresponding
+ Unicode character and placed into the right place in String.
+ @retval EFI_BUFFER_TOO_SMALL StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to
+ complete the convertion.
+**/
+RETURN_STATUS
+EFIAPI
+BufToHexString (
+ IN OUT CHAR16 *String,
+ IN OUT UINTN *StringLen,
+ IN CONST UINT8 *Buffer,
+ IN UINTN BufferSizeInBytes
+ )
+{
+ UINTN Idx;
+ UINT8 Byte;
+ UINTN StrLen;
+
+ //
+ // Make sure string is either passed or allocate enough.
+ // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
+ // Plus the Unicode termination character.
+ //
+ StrLen = BufferSizeInBytes * 2;
+ if (StrLen > ((*StringLen) - 1)) {
+ *StringLen = StrLen + 1;
+ return RETURN_BUFFER_TOO_SMALL;
+ }
+
+ *StringLen = StrLen + 1;
+ //
+ // Ends the string.
+ //
+ String[StrLen] = L'\0';
+
+ for (Idx = 0; Idx < BufferSizeInBytes; Idx++) {
+
+ Byte = Buffer[Idx];
+ String[StrLen - 1 - Idx * 2] = NibbleToHexChar (Byte);
+ String[StrLen - 2 - Idx * 2] = NibbleToHexChar ((UINT8)(Byte >> 4));
+ }
+
+ return RETURN_SUCCESS;
+}
+
+
+/**
+ Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.
+
+ This function converts a Unicode string consisting of characters in the range of Hexadecimal
+ character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop
+ at the first non-hexadecimal character or the NULL character. The convertion process can be
+ simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be
+ converted into one byte. The first Unicode character represents the Most Significant Nibble and the
+ second Unicode character represents the Least Significant Nibble in the output byte.
+ The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode
+ characters represent the the byte preceding the last byte. This rule applies to the rest pairs of bytes.
+ The last pair represent the first byte in the output buffer.
+
+ For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes
+ (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".
+
+ If String has N valid hexadecimal characters for conversion, the caller must make sure Buffer is at least
+ N/2 (if N is even) or (N+1)/2 (if N if odd) bytes.
+
+ @param Buffer The output buffer allocated by the caller.
+ @param BufferSizeInBytes On input, the size in bytes of Buffer. On output, it is updated to
+ contain the size of the Buffer which is actually used for the converstion.
+ For Unicode string with 2*N hexadecimal characters (not including the
+ tailing NULL character), N bytes of Buffer will be used for the output.
+ @param String The input hexadecimal string.
+ @param ConvertedStrLen The number of hexadecimal characters used to produce content in output
+ buffer Buffer.
+
+ @retval RETURN_BUFFER_TOO_SMALL The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes
+ will be updated to the size required for the converstion.
+ @retval RETURN_SUCCESS The convertion is successful or the first Unicode character from String
+ is hexadecimal. If ConvertedStrLen is not NULL, it is updated
+ to the number of hexadecimal character used for the converstion.
+**/
+RETURN_STATUS
+EFIAPI
+HexStringToBuf (
+ OUT UINT8 *Buffer,
+ IN OUT UINTN *BufferSizeInBytes,
+ IN CONST CHAR16 *String,
+ OUT UINTN *ConvertedStrLen OPTIONAL
+ )
+{
+ UINTN HexCnt;
+ UINTN Idx;
+ UINTN BufferLength;
+ UINT8 Digit;
+ UINT8 Byte;
+
+ //
+ // Find out how many hex characters the string has.
+ //
+ for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, String[Idx]); Idx++, HexCnt++);
+
+ if (HexCnt == 0) {
+ *ConvertedStrLen = 0;
+ return RETURN_SUCCESS;
+ }
+ //
+ // Two Unicode characters make up 1 buffer byte. Round up.
+ //
+ BufferLength = (HexCnt + 1) / 2;
+
+ //
+ // Test if buffer is passed enough.
+ //
+ if (BufferLength > (*BufferSizeInBytes)) {
+ *BufferSizeInBytes = BufferLength;
+ return RETURN_BUFFER_TOO_SMALL;
+ }
+
+ *BufferSizeInBytes = BufferLength;
+
+ for (Idx = 0; Idx < HexCnt; Idx++) {
+
+ IsHexDigit (&Digit, String[HexCnt - 1 - Idx]);
+
+ //
+ // For odd charaters, write the lower nibble for each buffer byte,
+ // and for even characters, the upper nibble.
+ //
+ if ((Idx & 1) == 0) {
+ Byte = Digit;
+ } else {
+ Byte = Buffer[Idx / 2];
+ Byte &= 0x0F;
+ Byte = (UINT8) (Byte | Digit << 4);
+ }
+
+ Buffer[Idx / 2] = Byte;
+ }
+
+ if (ConvertedStrLen != NULL) {
+ *ConvertedStrLen = HexCnt;
+ }
+
+ return RETURN_SUCCESS;
+}
+
+
+/**
+ Test if a Unicode character is a hexadecimal digit. If true, the input
+ Unicode character is converted to a byte.
+
+ This function tests if a Unicode character is a hexadecimal digit. If true, the input
+ Unicode character is converted to a byte. For example, Unicode character
+ L'A' will be converted to 0x0A.
+
+ If Digit is NULL, then ASSERT.
+
+ @retval TRUE Char is in the range of Hexadecimal number. Digit is updated
+ to the byte value of the number.
+ @retval FALSE Char is not in the range of Hexadecimal number. Digit is keep
+ intact.
+
+**/
+BOOLEAN
+IsHexDigit (
+ OUT UINT8 *Digit,
+ IN CHAR16 Char
+ )
+{
+ ASSERT (Digit != NULL);
+
+ if ((Char >= L'0') && (Char <= L'9')) {
+ *Digit = (UINT8) (Char - L'0');
+ return TRUE;
+ }
+
+ if ((Char >= L'A') && (Char <= L'F')) {
+ *Digit = (UINT8) (Char - L'A' + 0x0A);
+ return TRUE;
+ }
+
+ if ((Char >= L'a') && (Char <= L'f')) {
+ *Digit = (UINT8) (Char - L'a' + 0x0A);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
diff --git a/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf b/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf
index a8d5df4..98ac18c 100644
--- a/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf
+++ b/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf
@@ -38,8 +38,6 @@
UefiIfrForm.c
UefiIfrLibraryInternal.h
UefiIfrOpCodeCreation.c
- R8Lib.h
- R8Lib.c
[Packages]
@@ -71,4 +69,3 @@
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang
- \ No newline at end of file
diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrForm.c b/MdePkg/Library/IfrSupportLib/UefiIfrForm.c
index e630e3e..8963789 100644
--- a/MdePkg/Library/IfrSupportLib/UefiIfrForm.c
+++ b/MdePkg/Library/IfrSupportLib/UefiIfrForm.c
@@ -27,55 +27,6 @@ Abstract:
//
UINT16 mFakeConfigHdr[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=0";
-#if 0
-STATIC
-EFI_STATUS
-GetPackageDataFromPackageList (
- IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList,
- IN UINT32 PackageIndex,
- OUT UINT32 *BufferLen,
- OUT EFI_HII_PACKAGE_HEADER **Buffer
- )
-{
- UINT32 Index;
- EFI_HII_PACKAGE_HEADER *Package;
- UINT32 Offset;
- UINT32 PackageListLength;
- EFI_HII_PACKAGE_HEADER PackageHeader = {0, 0};
-
- ASSERT(HiiPackageList != NULL);
-
- if ((BufferLen == NULL) || (Buffer == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- Package = NULL;
- Index = 0;
- Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
- CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32));
- while (Offset < PackageListLength) {
- Package = (EFI_HII_PACKAGE_HEADER *) (((UINT8 *) HiiPackageList) + Offset);
- CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
- if (Index == PackageIndex) {
- break;
- }
- Offset += PackageHeader.Length;
- Index++;
- }
- if (Offset >= PackageListLength) {
- //
- // no package found in this Package List
- //
- return EFI_NOT_FOUND;
- }
-
- *BufferLen = PackageHeader.Length;
- *Buffer = Package;
- return EFI_SUCCESS;
-}
-#endif
-
-
/**
Draw a dialog and return the selected key.
@@ -301,7 +252,7 @@ SwapBuffer (
/**
- Converts binary buffer to Unicode string in reversed byte order from R8_BufToHexString().
+ Converts binary buffer to Unicode string in reversed byte order from BufToHexString().
@param Str String for output
@param Buffer Binary buffer.
@@ -326,7 +277,7 @@ BufferToHexString (
SwapBuffer (NewBuffer, BufferSize);
StrBufferLen = (BufferSize + 1) * sizeof (CHAR16);
- Status = R8_BufToHexString (Str, &StrBufferLen, NewBuffer, BufferSize);
+ Status = BufToHexString (Str, &StrBufferLen, NewBuffer, BufferSize);
gBS->FreePool (NewBuffer);
@@ -335,7 +286,7 @@ BufferToHexString (
/**
- Converts Hex String to binary buffer in reversed byte order from R8_HexStringToBuf().
+ Converts Hex String to binary buffer in reversed byte order from HexStringToBuf().
@param Buffer Pointer to buffer that receives the data.
@param BufferSize Length in bytes of the buffer to hold converted
@@ -360,7 +311,7 @@ HexStringToBuffer (
UINTN ConvertedStrLen;
ConvertedStrLen = 0;
- Status = R8_HexStringToBuf (Buffer, BufferSize, Str, &ConvertedStrLen);
+ Status = HexStringToBuf (Buffer, BufferSize, Str, &ConvertedStrLen);
if (!EFI_ERROR (Status)) {
SwapBuffer (Buffer, ConvertedStrLen);
}
@@ -496,7 +447,7 @@ FindBlockName (
Data = 0;
BufferSize = sizeof (UINTN);
- Status = R8_HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen);
+ Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen);
if (EFI_ERROR (Status)) {
return FALSE;
}
@@ -513,7 +464,7 @@ FindBlockName (
Data = 0;
BufferSize = sizeof (UINTN);
- Status = R8_HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen);
+ Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen);
if (EFI_ERROR (Status)) {
return FALSE;
}
@@ -710,7 +661,7 @@ SetBrowserData (
//
StringPtr = BlockName + 16;
BufferLen = sizeof (BlockName) - (16 * sizeof (CHAR16));
- R8_BufToHexString (StringPtr, &BufferLen, (UINT8 *) &BufferSize, sizeof (UINTN));
+ BufToHexString (StringPtr, &BufferLen, (UINT8 *) &BufferSize, sizeof (UINTN));
Request = BlockName;
} else {
diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h b/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h
index dd41c7a..dade859 100644
--- a/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h
+++ b/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h
@@ -40,8 +40,4 @@ Abstract:
#include <Library/HiiLib.h>
#include <Library/PcdLib.h>
-//#include <MdeModuleHii.h>
-
-#include "R8Lib.h"
-
#endif