-/**\r
- Converts a list of string to a specified buffer.\r
-\r
- @param Buf The output buffer that contains the string.\r
- @param BufferLength The length of the buffer\r
- @param Str The input string that contains the hex number\r
-\r
- @retval EFI_SUCCESS The string was successfully converted to the buffer.\r
-\r
-**/\r
-EFI_STATUS\r
-StrToBuf (\r
- OUT UINT8 *Buf,\r
- IN UINTN BufferLength,\r
- IN CHAR16 *Str\r
- )\r
-{\r
- UINTN Index;\r
- UINTN StrLength;\r
- UINT8 Digit;\r
- UINT8 Byte;\r
-\r
- Digit = 0;\r
-\r
- //\r
- // Two hex char make up one byte\r
- //\r
- StrLength = BufferLength * sizeof (CHAR16);\r
-\r
- for(Index = 0; Index < StrLength; Index++, Str++) {\r
-\r
- if ((*Str >= L'a') && (*Str <= L'f')) {\r
- Digit = (UINT8) (*Str - L'a' + 0x0A);\r
- } else if ((*Str >= L'A') && (*Str <= L'F')) {\r
- Digit = (UINT8) (*Str - L'A' + 0x0A);\r
- } else if ((*Str >= L'0') && (*Str <= L'9')) {\r
- Digit = (UINT8) (*Str - L'0');\r
- } else {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // For odd characters, write the upper nibble for each buffer byte,\r
- // and for even characters, the lower nibble.\r
- //\r
- if ((Index & 1) == 0) {\r
- Byte = (UINT8) (Digit << 4);\r
- } else {\r
- Byte = Buf[Index / 2];\r
- Byte &= 0xF0;\r
- Byte = (UINT8) (Byte | Digit);\r
- }\r
-\r
- Buf[Index / 2] = Byte;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Converts a string to GUID value.\r
- Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\r
-\r
- @param Str The registry format GUID string that contains the GUID value.\r
- @param Guid A pointer to the converted GUID value.\r
-\r
- @retval EFI_SUCCESS The GUID string was successfully converted to the GUID value.\r
- @retval EFI_UNSUPPORTED The input string is not in registry format.\r
- @return others Some error occurred when converting part of GUID value.\r
-\r
-**/\r
-EFI_STATUS\r
-DevicePathLibStrToGuid (\r
- IN CHAR16 *Str,\r
- OUT EFI_GUID *Guid\r
- )\r
-{\r
- //\r
- // Get the first UINT32 data\r
- //\r
- Guid->Data1 = (UINT32) StrHexToUint64 (Str);\r
- while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
- Str ++;\r
- }\r
- \r
- if (IS_HYPHEN (*Str)) {\r
- Str++;\r
- } else {\r
- return EFI_UNSUPPORTED;\r
- }\r
- \r
- //\r
- // Get the second UINT16 data\r
- //\r
- Guid->Data2 = (UINT16) StrHexToUint64 (Str);\r
- while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
- Str ++;\r
- }\r
-\r
- if (IS_HYPHEN (*Str)) {\r
- Str++;\r
- } else {\r
- return EFI_UNSUPPORTED;\r
- }\r
- \r
- //\r
- // Get the third UINT16 data\r
- //\r
- Guid->Data3 = (UINT16) StrHexToUint64 (Str);\r
- while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
- Str ++;\r
- }\r
-\r
- if (IS_HYPHEN (*Str)) {\r
- Str++;\r
- } else {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- //\r
- // Get the following 8 bytes data\r
- // \r
- StrToBuf (&Guid->Data4[0], 2, Str);\r
- //\r
- // Skip 2 byte hex chars\r
- //\r
- Str += 2 * 2;\r
-\r
- if (IS_HYPHEN (*Str)) {\r
- Str++;\r
- } else {\r
- return EFI_UNSUPPORTED;\r
- }\r
- StrToBuf (&Guid->Data4[2], 6, Str);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Converts a string to IPv4 address\r
-\r
- @param Str A string representation of IPv4 address.\r
- @param IPv4Addr A pointer to the converted IPv4 address.\r
-\r
-**/\r
-VOID\r
-StrToIPv4Addr (\r
- IN OUT CHAR16 **Str,\r
- OUT EFI_IPv4_ADDRESS *IPv4Addr\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < 4; Index++) {\r
- IPv4Addr->Addr[Index] = (UINT8) Strtoi (SplitStr (Str, L'.'));\r
- }\r
-}\r
-\r
-/**\r
- Converts a string to IPv4 address\r
-\r
- @param Str A string representation of IPv6 address.\r
- @param IPv6Addr A pointer to the converted IPv6 address.\r
-\r
-**/\r
-VOID\r
-StrToIPv6Addr (\r
- IN OUT CHAR16 **Str,\r
- OUT EFI_IPv6_ADDRESS *IPv6Addr\r
- )\r
-{\r
- UINTN Index;\r
- UINT16 Data;\r
-\r
- for (Index = 0; Index < 8; Index++) {\r
- Data = (UINT16) StrHexToUintn (SplitStr (Str, L':'));\r
- IPv6Addr->Addr[Index * 2] = (UINT8) (Data >> 8);\r
- IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);\r
- }\r
-}\r
-\r