+++ /dev/null
-/** @file\r
- <Todo: Add file description>\r
-\r
-Copyright (c) 2007 - 2008, Intel Corporation. <BR>\r
-All rights reserved. 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 "LibraryInternal.h"\r
-\r
-\r
-CHAR16\r
-InternalNibbleToHexChar (\r
- IN UINT8 Nibble\r
- )\r
-/*++\r
-\r
- Routine Description:\r
- Converts the low nibble of a byte to hex unicode character.\r
-\r
- Arguments:\r
- Nibble - lower nibble of a byte.\r
-\r
- Returns:\r
- Hex unicode character.\r
-\r
---*/\r
-{\r
- Nibble &= 0x0F;\r
- if (Nibble <= 0x9) {\r
- return (CHAR16)(Nibble + L'0');\r
- }\r
-\r
- return (CHAR16)(Nibble - 0xA + L'A');\r
-}\r
-\r
-\r
-/**\r
- Converts binary buffer to Unicode string.\r
- At a minimum, any blob of data could be represented as a hex string.\r
-\r
- @param Str Pointer to the string.\r
- @param HexStringBufferLength Length in bytes of buffer to hold the hex string.\r
- Includes tailing '\0' character. If routine return\r
- with EFI_SUCCESS, containing length of hex string\r
- buffer. If routine return with\r
- EFI_BUFFER_TOO_SMALL, containg length of hex\r
- string buffer desired.\r
- @param Buf Buffer to be converted from.\r
- @param Len Length in bytes of the buffer to be converted.\r
-\r
- @retval EFI_SUCCESS Routine success.\r
- @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.\r
-\r
-**/\r
-EFI_STATUS\r
-R8_BufToHexString (\r
- IN OUT CHAR16 *Str,\r
- IN OUT UINTN *HexStringBufferLength,\r
- IN UINT8 *Buf,\r
- IN UINTN Len\r
- )\r
-{\r
- //\r
- // Porting Guide:\r
- // This library interface is simply obsolete.\r
- // Include the source code to user code.\r
- //\r
- UINTN Idx;\r
- UINT8 Byte;\r
- UINTN StrLen;\r
-\r
- //\r
- // Make sure string is either passed or allocate enough.\r
- // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.\r
- // Plus the Unicode termination character.\r
- //\r
- StrLen = Len * 2;\r
- if (StrLen > ((*HexStringBufferLength) - 1)) {\r
- *HexStringBufferLength = StrLen + 1;\r
- return EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- *HexStringBufferLength = StrLen + 1;\r
- //\r
- // Ends the string.\r
- //\r
- Str[StrLen] = L'\0';\r
-\r
- for (Idx = 0; Idx < Len; Idx++) {\r
-\r
- Byte = Buf[Idx];\r
- Str[StrLen - 1 - Idx * 2] = InternalNibbleToHexChar (Byte);\r
- Str[StrLen - 2 - Idx * 2] = InternalNibbleToHexChar ((UINT8)(Byte >> 4));\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
-\r
-/**\r
- Converts Unicode string to binary buffer.\r
- The conversion may be partial.\r
- The first character in the string that is not hex digit stops the conversion.\r
- At a minimum, any blob of data could be represented as a hex string.\r
-\r
- @param Buf Pointer to buffer that receives the data.\r
- @param Len Length in bytes of the buffer to hold converted\r
- data. If routine return with EFI_SUCCESS,\r
- containing length of converted data. If routine\r
- return with EFI_BUFFER_TOO_SMALL, containg length\r
- of buffer desired.\r
- @param Str String to be converted from.\r
- @param ConvertedStrLen Length of the Hex String consumed.\r
-\r
- @retval EFI_SUCCESS Routine Success.\r
- @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.\r
-\r
-**/\r
-EFI_STATUS\r
-R8_HexStringToBuf (\r
- IN OUT UINT8 *Buf,\r
- IN OUT UINTN *Len,\r
- IN CHAR16 *Str,\r
- OUT UINTN *ConvertedStrLen OPTIONAL\r
- )\r
-{\r
- //\r
- // Porting Guide:\r
- // This library interface is simply obsolete.\r
- // Include the source code to user code.\r
- //\r
-\r
- UINTN HexCnt;\r
- UINTN Idx;\r
- UINTN BufferLength;\r
- UINT8 Digit;\r
- UINT8 Byte;\r
-\r
- //\r
- // Find out how many hex characters the string has.\r
- //\r
- for (Idx = 0, HexCnt = 0; R8_IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);\r
-\r
- if (HexCnt == 0) {\r
- *Len = 0;\r
- return EFI_SUCCESS;\r
- }\r
- //\r
- // Two Unicode characters make up 1 buffer byte. Round up.\r
- //\r
- BufferLength = (HexCnt + 1) / 2;\r
-\r
- //\r
- // Test if buffer is passed enough.\r
- //\r
- if (BufferLength > (*Len)) {\r
- *Len = BufferLength;\r
- return EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- *Len = BufferLength;\r
-\r
- for (Idx = 0; Idx < HexCnt; Idx++) {\r
-\r
- R8_IsHexDigit (&Digit, Str[HexCnt - 1 - Idx]);\r
-\r
- //\r
- // For odd charaters, write the lower nibble for each buffer byte,\r
- // and for even characters, the upper nibble.\r
- //\r
- if ((Idx & 1) == 0) {\r
- Byte = Digit;\r
- } else {\r
- Byte = Buf[Idx / 2];\r
- Byte &= 0x0F;\r
- Byte = (UINT8) (Byte | Digit << 4);\r
- }\r
-\r
- Buf[Idx / 2] = Byte;\r
- }\r
-\r
- if (ConvertedStrLen != NULL) {\r
- *ConvertedStrLen = HexCnt;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Determines if a Unicode character is a hexadecimal digit.\r
- The test is case insensitive.\r
-\r
- @param Digit Pointer to byte that receives the value of the hex\r
- character.\r
- @param Char Unicode character to test.\r
-\r
- @retval TRUE If the character is a hexadecimal digit.\r
- @retval FALSE Otherwise.\r
-\r
-**/\r
-BOOLEAN\r
-R8_IsHexDigit (\r
- OUT UINT8 *Digit,\r
- IN CHAR16 Char\r
- )\r
-{\r
- //\r
- // Porting Guide:\r
- // This library interface is simply obsolete.\r
- // Include the source code to user code.\r
- //\r
-\r
- if ((Char >= L'0') && (Char <= L'9')) {\r
- *Digit = (UINT8) (Char - L'0');\r
- return TRUE;\r
- }\r
-\r
- if ((Char >= L'A') && (Char <= L'F')) {\r
- *Digit = (UINT8) (Char - L'A' + 0x0A);\r
- return TRUE;\r
- }\r
-\r
- if ((Char >= L'a') && (Char <= L'f')) {\r
- *Digit = (UINT8) (Char - L'a' + 0x0A);\r
- return TRUE;\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-\r
+++ /dev/null
-/** @file\r
- <Todo: Add file description>\r
-\r
-Copyright (c) 2007 - 2008, Intel Corporation. <BR>\r
-All rights reserved. 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
-\r
-\r
-/**\r
- Converts binary buffer to Unicode string.\r
- At a minimum, any blob of data could be represented as a hex string.\r
-\r
- @param Str Pointer to the string.\r
- @param HexStringBufferLength Length in bytes of buffer to hold the hex string.\r
- Includes tailing '\0' character. If routine return\r
- with EFI_SUCCESS, containing length of hex string\r
- buffer. If routine return with\r
- EFI_BUFFER_TOO_SMALL, containg length of hex\r
- string buffer desired.\r
- @param Buf Buffer to be converted from.\r
- @param Len Length in bytes of the buffer to be converted.\r
-\r
- @retval EFI_SUCCESS Routine success.\r
- @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.\r
-\r
-**/\r
-EFI_STATUS\r
-R8_BufToHexString (\r
- IN OUT CHAR16 *Str,\r
- IN OUT UINTN *HexStringBufferLength,\r
- IN UINT8 *Buf,\r
- IN UINTN Len\r
- )\r
-;\r
-\r
-\r
-\r
-\r
-/**\r
- Converts Unicode string to binary buffer.\r
- The conversion may be partial.\r
- The first character in the string that is not hex digit stops the conversion.\r
- At a minimum, any blob of data could be represented as a hex string.\r
-\r
- @param Buf Pointer to buffer that receives the data.\r
- @param Len Length in bytes of the buffer to hold converted\r
- data. If routine return with EFI_SUCCESS,\r
- containing length of converted data. If routine\r
- return with EFI_BUFFER_TOO_SMALL, containg length\r
- of buffer desired.\r
- @param Str String to be converted from.\r
- @param ConvertedStrLen Length of the Hex String consumed.\r
-\r
- @retval EFI_SUCCESS Routine Success.\r
- @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.\r
-\r
-**/\r
-EFI_STATUS\r
-R8_HexStringToBuf (\r
- IN OUT UINT8 *Buf,\r
- IN OUT UINTN *Len,\r
- IN CHAR16 *Str,\r
- OUT UINTN *ConvertedStrLen OPTIONAL\r
- )\r
-;\r
-\r
-/**\r
- Determines if a Unicode character is a hexadecimal digit.\r
- The test is case insensitive.\r
-\r
- @param Digit Pointer to byte that receives the value of the hex\r
- character.\r
- @param Char Unicode character to test.\r
-\r
- @retval TRUE If the character is a hexadecimal digit.\r
- @retval FALSE Otherwise.\r
-\r
-**/\r
-BOOLEAN\r
-R8_IsHexDigit (\r
- OUT UINT8 *Digit,\r
- IN CHAR16 Char\r
- )\r
-;\r
-\r
+++ /dev/null
-/**@file
- Copyright (c) 2007, Intel Corporation
-
- All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-
-**/
-
-#include "UefiIfrLibraryInternal.h"
-
-
-CHAR16
-InternalNibbleToHexChar (
- IN UINT8 Nibble
- )
-/*++
-
- Routine Description:
- Converts the low nibble of a byte to hex unicode character.
-
- Arguments:
- Nibble - lower nibble of a byte.
-
- Returns:
- Hex unicode character.
-
---*/
-{
- Nibble &= 0x0F;
- if (Nibble <= 0x9) {
- return (CHAR16)(Nibble + L'0');
- }
-
- return (CHAR16)(Nibble - 0xA + L'A');
-}
-
-
-/**
- Converts binary buffer to Unicode string.
- At a minimum, any blob of data could be represented as a hex string.
-
- @param Str Pointer to the string.
- @param HexStringBufferLength Length in bytes of buffer to hold the hex string.
- Includes tailing '\0' character. If routine return
- with EFI_SUCCESS, containing length of hex string
- buffer. If routine return with
- EFI_BUFFER_TOO_SMALL, containg length of hex
- string buffer desired.
- @param Buf Buffer to be converted from.
- @param Len Length in bytes of the buffer to be converted.
-
- @retval EFI_SUCCESS Routine success.
- @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.
-
-**/
-EFI_STATUS
-R8_BufToHexString (
- IN OUT CHAR16 *Str,
- IN OUT UINTN *HexStringBufferLength,
- IN UINT8 *Buf,
- IN UINTN Len
- )
-{
- //
- // Porting Guide:
- // This library interface is simply obsolete.
- // Include the source code to user code.
- //
- 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 = Len * 2;
- if (StrLen > ((*HexStringBufferLength) - 1)) {
- *HexStringBufferLength = StrLen + 1;
- return EFI_BUFFER_TOO_SMALL;
- }
-
- *HexStringBufferLength = StrLen + 1;
- //
- // Ends the string.
- //
- Str[StrLen] = L'\0';
-
- for (Idx = 0; Idx < Len; Idx++) {
-
- Byte = Buf[Idx];
- Str[StrLen - 1 - Idx * 2] = InternalNibbleToHexChar (Byte);
- Str[StrLen - 2 - Idx * 2] = InternalNibbleToHexChar ((UINT8)(Byte >> 4));
- }
-
- return EFI_SUCCESS;
-}
-
-
-
-
-/**
- Converts Unicode string to binary buffer.
- The conversion may be partial.
- The first character in the string that is not hex digit stops the conversion.
- At a minimum, any blob of data could be represented as a hex string.
-
- @param Buf Pointer to buffer that receives the data.
- @param Len 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.
- @param ConvertedStrLen Length of the Hex String consumed.
-
- @retval EFI_SUCCESS Routine Success.
- @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.
-
-**/
-EFI_STATUS
-R8_HexStringToBuf (
- IN OUT UINT8 *Buf,
- IN OUT UINTN *Len,
- IN CHAR16 *Str,
- OUT UINTN *ConvertedStrLen OPTIONAL
- )
-{
- //
- // Porting Guide:
- // This library interface is simply obsolete.
- // Include the source code to user code.
- //
-
- UINTN HexCnt;
- UINTN Idx;
- UINTN BufferLength;
- UINT8 Digit;
- UINT8 Byte;
-
- Digit = 0;
- //
- // Find out how many hex characters the string has.
- //
- for (Idx = 0, HexCnt = 0; R8_IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);
-
- if (HexCnt == 0) {
- *Len = 0;
- return EFI_SUCCESS;
- }
- //
- // Two Unicode characters make up 1 buffer byte. Round up.
- //
- BufferLength = (HexCnt + 1) / 2;
-
- //
- // Test if buffer is passed enough.
- //
- if (BufferLength > (*Len)) {
- *Len = BufferLength;
- return EFI_BUFFER_TOO_SMALL;
- }
-
- *Len = BufferLength;
-
- for (Idx = 0; Idx < HexCnt; Idx++) {
-
- R8_IsHexDigit (&Digit, Str[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 = Buf[Idx / 2];
- Byte &= 0x0F;
- Byte = (UINT8) (Byte | Digit << 4);
- }
-
- Buf[Idx / 2] = Byte;
- }
-
- if (ConvertedStrLen != NULL) {
- *ConvertedStrLen = HexCnt;
- }
-
- return EFI_SUCCESS;
-}
-
-
-/**
- Determines if a Unicode character is a hexadecimal digit.
- The test is case insensitive.
-
- @param Digit Pointer to byte that receives the value of the hex
- character.
- @param Char Unicode character to test.
-
- @retval TRUE If the character is a hexadecimal digit.
- @retval FALSE Otherwise.
-
-**/
-BOOLEAN
-R8_IsHexDigit (
- OUT UINT8 *Digit,
- IN CHAR16 Char
- )
-{
- //
- // Porting Guide:
- // This library interface is simply obsolete.
- // Include the source code to user code.
- //
-
- 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;
-}
-
-
+++ /dev/null
-/**@file
- Copyright (c) 2007, Intel Corporation
-
- All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-
-**/
-
-
-
-/**
- Converts binary buffer to Unicode string.
- At a minimum, any blob of data could be represented as a hex string.
-
- @param Str Pointer to the string.
- @param HexStringBufferLength Length in bytes of buffer to hold the hex string.
- Includes tailing '\0' character. If routine return
- with EFI_SUCCESS, containing length of hex string
- buffer. If routine return with
- EFI_BUFFER_TOO_SMALL, containg length of hex
- string buffer desired.
- @param Buf Buffer to be converted from.
- @param Len Length in bytes of the buffer to be converted.
-
- @retval EFI_SUCCESS Routine success.
- @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.
-
-**/
-EFI_STATUS
-R8_BufToHexString (
- IN OUT CHAR16 *Str,
- IN OUT UINTN *HexStringBufferLength,
- IN UINT8 *Buf,
- IN UINTN Len
- )
-;
-
-
-
-
-/**
- Converts Unicode string to binary buffer.
- The conversion may be partial.
- The first character in the string that is not hex digit stops the conversion.
- At a minimum, any blob of data could be represented as a hex string.
-
- @param Buf Pointer to buffer that receives the data.
- @param Len 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.
- @param ConvertedStrLen Length of the Hex String consumed.
-
- @retval EFI_SUCCESS Routine Success.
- @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.
-
-**/
-EFI_STATUS
-R8_HexStringToBuf (
- IN OUT UINT8 *Buf,
- IN OUT UINTN *Len,
- IN CHAR16 *Str,
- OUT UINTN *ConvertedStrLen OPTIONAL
- )
-;
-
-/**
- Determines if a Unicode character is a hexadecimal digit.
- The test is case insensitive.
-
- @param Digit Pointer to byte that receives the value of the hex
- character.
- @param Char Unicode character to test.
-
- @retval TRUE If the character is a hexadecimal digit.
- @retval FALSE Otherwise.
-
-**/
-BOOLEAN
-R8_IsHexDigit (
- OUT UINT8 *Digit,
- IN CHAR16 Char
- )
-;
-