]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
correct the minor format.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index 8bcd498e77da92a51981fe5a0a3c35588ff420e0..eaf230d1d494bc2a1bbed421a0bf7b50e66a4910 100644 (file)
@@ -80,6 +80,10 @@ GetDevicePath (
   UINTN      Length;\r
   EFI_STRING PathHdr;\r
   EFI_STRING DevicePathString;\r
+  UINT8      *DevicePathBuffer;\r
+  CHAR16     TemStr[2];\r
+  UINTN      Index;\r
+  UINT8      DigitUint8;\r
 \r
   if (String == NULL || DevicePath == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -114,21 +118,52 @@ GetDevicePath (
   // as the device path resides in RAM memory.\r
   // Translate the data into binary.\r
   //\r
-  Length /= 2;\r
-  *DevicePath = (UINT8 *) AllocateZeroPool (Length);\r
-  if (*DevicePath == NULL) {\r
+  DevicePathBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);\r
+  if (DevicePathBuffer == NULL) {\r
     FreePool (DevicePathString);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  HexStringToBufInReverseOrder (*DevicePath, &Length, DevicePathString);\r
+  ZeroMem (TemStr, sizeof (TemStr));\r
+  for (Index = 0; DevicePathString[Index] != L'\0'; Index ++) {\r
+    TemStr[0] = DevicePathString[Index];\r
+    DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+    if ((Index & 1) == 0) {\r
+      DevicePathBuffer [Index/2] = DigitUint8;\r
+    } else {\r
+      DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
+    }\r
+  }\r
 \r
   FreePool (DevicePathString);\r
+  \r
+  *DevicePath = DevicePathBuffer;\r
 \r
   return EFI_SUCCESS;\r
 \r
 }\r
 \r
+/**\r
+  Converts the unicode character of the string from uppercase to lowercase.\r
+  This is a internal function.\r
+\r
+  @param Str     String to be converted\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HiiToLower (\r
+  IN OUT CHAR16    *Str\r
+  )\r
+{\r
+  CHAR16      *Ptr;\r
+  \r
+  for (Ptr = Str; *Ptr != L'\0'; Ptr++) {\r
+    if (*Ptr >= L'A' && *Ptr <= L'Z') {\r
+      *Ptr = (CHAR16) (*Ptr - L'A' + L'a');\r
+    }\r
+  }\r
+}\r
 \r
 /**\r
   Generate a sub string then output it.\r
@@ -159,8 +194,11 @@ GenerateSubStr (
 {\r
   UINTN       Length;\r
   EFI_STRING  Str;\r
-  EFI_STATUS  Status;\r
   EFI_STRING  StringHeader;\r
+  CHAR16      *TemString;\r
+  CHAR16      *TemName;\r
+  UINT8       *TemBuffer;\r
+  UINTN       Index;\r
 \r
   ASSERT (String != NULL && SubStr != NULL);\r
 \r
@@ -171,34 +209,55 @@ GenerateSubStr (
   }\r
 \r
   Length = StrLen (String) + BufferLen * 2 + 1 + 1;\r
-  Str = AllocateZeroPool (Length * sizeof (CHAR16));\r
+  Str    = AllocateZeroPool (Length * sizeof (CHAR16));\r
   ASSERT (Str != NULL);\r
 \r
   StrCpy (Str, String);\r
   Length = (BufferLen * 2 + 1) * sizeof (CHAR16);\r
 \r
-  Status       = EFI_SUCCESS;\r
   StringHeader = Str + StrLen (String);\r
+  TemString    = (CHAR16 *) StringHeader;\r
 \r
   switch (Flag) {\r
   case 1:\r
-    Status = BufInReverseOrderToHexString (StringHeader, (UINT8 *) Buffer, BufferLen);\r
+    //\r
+    // Convert Buffer to Hex String in reverse order\r
+    //\r
+    TemBuffer = ((UINT8 *) Buffer);\r
+    for (Index = 0; Index < BufferLen; Index ++, TemBuffer ++) {\r
+      TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+    }\r
     break;\r
   case 2:\r
-    Status = UnicodeToConfigString (StringHeader, &Length, (CHAR16 *) Buffer);\r
+    //\r
+    // Check buffer is enough\r
+    //\r
+    TemName = (CHAR16 *) Buffer;\r
+    ASSERT (Length < ((StrLen (TemName) * 4 + 1) * sizeof (CHAR16)));\r
+    //\r
+    // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
+    //\r
+    for (; *TemName != L'\0'; TemName++) {\r
+      TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
+    }\r
     break;\r
   case 3:\r
-    Status = BufToHexString (StringHeader, &Length, (UINT8 *) Buffer, BufferLen);\r
     //\r
-    // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r
+    // Convert Buffer to Hex String\r
     //\r
-    ToLower (StringHeader);\r
+    TemBuffer = ((UINT8 *) Buffer) + BufferLen - 1;\r
+    for (Index = 0; Index < BufferLen; Index ++, TemBuffer --) {\r
+      TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+    }\r
     break;\r
   default:\r
     break;\r
   }\r
 \r
-  ASSERT_EFI_ERROR (Status);\r
+  //\r
+  // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r
+  //\r
+  HiiToLower (StringHeader);\r
   StrCat (Str, L"&");\r
 \r
   *SubStr = Str;\r
@@ -302,8 +361,8 @@ AppendToMultiString (
                                   MultiStringSize + AppendStringSize,\r
                                   (VOID *) (*MultiString)\r
                                   );\r
+    ASSERT (*MultiString != NULL);\r
   }\r
-\r
   //\r
   // Append the incoming string\r
   //\r
@@ -344,14 +403,17 @@ GetValueOfNumber (
   EFI_STRING               Str;\r
   UINT8                    *Buf;\r
   EFI_STATUS               Status;\r
+  UINT8                    DigitUint8;\r
+  UINTN                    Index;\r
+  CHAR16                   TemStr[2];\r
 \r
   ASSERT (StringPtr != NULL && Number != NULL && Len != NULL);\r
-  ASSERT (*StringPtr != 0);\r
+  ASSERT (*StringPtr != L'\0');\r
 \r
   Buf = NULL;\r
 \r
   TmpPtr = StringPtr;\r
-  while (*StringPtr != 0 && *StringPtr != L'&') {\r
+  while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
     StringPtr++;\r
   }\r
   *Len   = StringPtr - TmpPtr;\r
@@ -363,7 +425,7 @@ GetValueOfNumber (
     goto Exit;\r
   }\r
   CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));\r
-  *(Str + *Len) = 0;\r
+  *(Str + *Len) = L'\0';\r
 \r
   Length = (Length + 1) / 2;\r
   Buf = (UINT8 *) AllocateZeroPool (Length);\r
@@ -371,10 +433,17 @@ GetValueOfNumber (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Exit;\r
   }\r
-\r
-  Status = HexStringToBuf (Buf, &Length, Str, NULL);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Exit;\r
+  \r
+  Length = *Len;\r
+  ZeroMem (TemStr, sizeof (TemStr));\r
+  for (Index = 0; Index < Length; Index ++) {\r
+    TemStr[0] = Str[Length - Index - 1];\r
+    DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+    if ((Index & 1) == 0) {\r
+      Buf [Index/2] = DigitUint8;\r
+    } else {\r
+      Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);\r
+    }\r
   }\r
 \r
   *Number = Buf;\r
@@ -384,6 +453,7 @@ Exit:
   if (Str != NULL) {\r
     FreePool (Str);\r
   }\r
+\r
   return Status;\r
 }\r
 \r
@@ -452,15 +522,6 @@ HiiConfigRoutingExtractConfig (
   EFI_STRING                          AccessResults;\r
   BOOLEAN                             FirstElement;\r
 \r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   if (This == NULL || Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -660,15 +721,6 @@ HiiConfigRoutingExportConfig (
   UINTN                               NumberConfigAccessHandles;\r
   BOOLEAN                             FirstElement;\r
 \r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   if (This == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -784,15 +836,6 @@ HiiConfigRoutingRouteConfig (
   EFI_HII_CONFIG_ACCESS_PROTOCOL      *ConfigAccess;\r
   EFI_STRING                          AccessProgress;\r
 \r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   if (This == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -986,6 +1029,9 @@ HiiBlockToConfig (
   UINT8                               *Value;\r
   EFI_STRING                          ValueStr;\r
   EFI_STRING                          ConfigElement;\r
+  UINTN                               Index;\r
+  UINT8                               *TemBuffer;\r
+  CHAR16                              *TemString;\r
 \r
   if (This == NULL || Progress == NULL || Config == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1134,10 +1180,13 @@ HiiBlockToConfig (
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Exit;\r
     }\r
-\r
-    Status = BufToHexString (ValueStr, &Length, Value, Width);\r
-    ASSERT_EFI_ERROR (Status);\r
-    ToLower (ValueStr);\r
+    \r
+    TemString = ValueStr;\r
+    TemBuffer = Value + Width - 1;\r
+    for (Index = 0; Index < Width; Index ++, TemBuffer --) {\r
+      TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+    }\r
+    HiiToLower (ValueStr);\r
 \r
     FreePool (Value);\r
     Value = NULL;\r
@@ -1321,7 +1370,7 @@ HiiConfigToBlock (
     // Get Offset\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigResp;\r
       goto Exit;\r
     }\r
@@ -1369,7 +1418,7 @@ HiiConfigToBlock (
     // Get Value\r
     //\r
     Status = GetValueOfNumber (StringPtr, &Value, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigResp;\r
       goto Exit;\r
     }\r
@@ -1490,15 +1539,6 @@ HiiGetAltCfg (
   BOOLEAN                             NameFlag;\r
   BOOLEAN                             PathFlag;\r
 \r
-  //\r
-  // For size reduction, please define PcdSupportFullConfigRoutingProtocol \r
-  // as FALSE. But this renders the system to not 100% compliant with\r
-  // UEFI 2.1. Use this with caution.\r
-  //\r
-  if (!FeaturePcdGet (PcdSupportFullConfigRoutingProtocol)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   HdrStart = NULL;\r
   HdrEnd   = NULL;\r
   GuidStr  = NULL;\r
@@ -1643,7 +1683,7 @@ HiiGetAltCfg (
 \r
 Exit:\r
 \r
-  if (!EFI_ERROR (Status)) {\r
+  if (!EFI_ERROR (Status) && (Result != NULL)) {\r
     //\r
     // Copy the <ConfigHdr> and <ConfigBody>\r
     //\r