]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
Use the minimum value for Numeric and the first option value for OneOf as their defau...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index 0339565350c4a951fadeeabdab023898166ff09a..e51de1371ad520762870b7b559f66c9baa2fffad 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+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
@@ -860,6 +860,7 @@ ParseIfrData (
   EFI_STRING               NameStr;\r
   EFI_STRING               TempStr;\r
   UINTN                    LengthString;\r
+  BOOLEAN                  FirstOneOfOption;\r
 \r
   LengthString     = 0;\r
   Status           = EFI_SUCCESS;\r
@@ -869,6 +870,7 @@ ParseIfrData (
   BlockData        = NULL;\r
   DefaultData      = NULL;\r
   VarDefaultName   = 0;\r
+  FirstOneOfOption = FALSE;\r
 \r
   //\r
   // Go through the form package to parse OpCode one by one.\r
@@ -1023,6 +1025,59 @@ ParseIfrData (
       // Add Block Data into VarStorageData BlockEntry\r
       //\r
       InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
+      \r
+      if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) {\r
+        //\r
+        // Set this flag to TRUE for the first oneof option.\r
+        //\r
+        FirstOneOfOption = TRUE;\r
+      } else if (IfrOpHdr->OpCode == EFI_IFR_NUMERIC_OP) {\r
+        //\r
+        // Numeric minimum value will be used as default value when no default is specified. \r
+        //\r
+\r
+        //\r
+        // Set standard ID and Get DefaultName String ID\r
+        //\r
+        VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
+        Status       = FindDefaultName (DefaultIdArray, VarDefaultId, &VarDefaultName);\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+        //\r
+        // Prepare new DefaultValue\r
+        //\r
+        DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r
+        if (DefaultData == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Done;\r
+        }\r
+        DefaultData->OpCode      = IfrOpHdr->OpCode;\r
+        DefaultData->DefaultId   = VarDefaultId;\r
+        DefaultData->DefaultName = VarDefaultName;\r
+\r
+        switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+        case EFI_IFR_NUMERIC_SIZE_1:\r
+          DefaultData->Value = (UINT64) IfrOneOf->data.u8.MinValue;\r
+          break;\r
+  \r
+        case EFI_IFR_NUMERIC_SIZE_2:\r
+          CopyMem (&DefaultData->Value, &IfrOneOf->data.u16.MinValue, sizeof (UINT16));\r
+          break;\r
+  \r
+        case EFI_IFR_NUMERIC_SIZE_4:\r
+          CopyMem (&DefaultData->Value, &IfrOneOf->data.u32.MinValue, sizeof (UINT32));\r
+          break;\r
+  \r
+        case EFI_IFR_NUMERIC_SIZE_8:\r
+          CopyMem (&DefaultData->Value, &IfrOneOf->data.u64.MinValue, sizeof (UINT64));\r
+          break;\r
+        }\r
+        //\r
+        // Add DefaultValue into current BlockData\r
+        //\r
+        InsertDefaultValue (BlockData, DefaultData);      \r
+      }\r
       break;\r
 \r
     case EFI_IFR_ORDERED_LIST_OP:\r
@@ -1099,7 +1154,7 @@ ParseIfrData (
       // Get Offset/Width by Question header and OneOf Flags\r
       //\r
       VarOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
-      VarWidth  = sizeof (BOOLEAN);\r
+      VarWidth  = (UINT16) sizeof (BOOLEAN);\r
 \r
       //\r
       // Check whether this question is in requested block array.\r
@@ -1402,7 +1457,13 @@ ParseIfrData (
         break;\r
       }\r
 \r
-      if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) {\r
+      if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) ||\r
+          (BlockData->OpCode == EFI_IFR_ONE_OF_OP && FirstOneOfOption)) {\r
+        //\r
+        // This flag is used to specify whether this option is the first. Set it to FALSE for the following options. \r
+        // The first oneof option value will be used as default value when no default value is specified. \r
+        //\r
+        FirstOneOfOption = FALSE;\r
         //\r
         // Set standard ID to Manufacture ID and Get DefaultName String ID\r
         //\r
@@ -3224,6 +3285,10 @@ Exit:
                                  value pair. Block is left updated and\r
                                  Progress points at the '&' preceding the first\r
                                  non-<BlockName>.\r
+  @retval EFI_DEVICE_ERROR       Block not large enough. Progress undefined.\r
+  @retval EFI_NOT_FOUND          Target for the specified routing data was not found.\r
+                                 Progress points to the "G" in "GUID" of the errant\r
+                                 routing data.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3245,13 +3310,14 @@ HiiConfigToBlock (
   UINTN                               Width;\r
   UINT8                               *Value;\r
   UINTN                               BufferSize;\r
+  UINTN                               MaxBlockSize;\r
 \r
   if (This == NULL || BlockSize == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (ConfigResp == NULL || Block == NULL) {\r
-    *Progress = ConfigResp;\r
+  *Progress = ConfigResp;\r
+  if (ConfigResp == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -3261,6 +3327,7 @@ HiiConfigToBlock (
   StringPtr  = ConfigResp;\r
   BufferSize = *BlockSize;\r
   Value      = NULL;\r
+  MaxBlockSize = 0;\r
 \r
   //\r
   // Jump <ConfigHdr>\r
@@ -3366,13 +3433,12 @@ HiiConfigToBlock (
     //\r
     // Update the Block with configuration info\r
     //\r
-\r
-    if (Offset + Width > BufferSize) {\r
-      return EFI_DEVICE_ERROR;\r
+    if ((Block != NULL) && (Offset + Width <= BufferSize)) {\r
+      CopyMem (Block + Offset, Value, Width);\r
+    }\r
+    if (Offset + Width > MaxBlockSize) {\r
+      MaxBlockSize = Offset + Width;\r
     }\r
-\r
-    CopyMem (Block + Offset, Value, Width);\r
-    *BlockSize = Offset + Width - 1;\r
 \r
     FreePool (Value);\r
     Value = NULL;\r
@@ -3397,6 +3463,20 @@ HiiConfigToBlock (
   }\r
 \r
   *Progress = StringPtr + StrLen (StringPtr);\r
+  *BlockSize = MaxBlockSize - 1;\r
+\r
+  if (MaxBlockSize > BufferSize) {\r
+    *BlockSize = MaxBlockSize;\r
+    if (Block != NULL) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  if (Block == NULL) {\r
+    *Progress = ConfigResp;\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 \r
 Exit:\r