]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Setup.c
index 2da4cadd2dc71e1aa293461987acc4ebb02a5f54..288f1c31977e8c8f245bd385a00cd01f5c985543 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
 Entry and initialization module for the browser.\r
 \r
-Copyright (c) 2007 - 2014, 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
-\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
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -53,8 +47,11 @@ LIST_ENTRY      gBrowserStorageList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserSto
 LIST_ENTRY      gBrowserSaveFailFormSetList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserSaveFailFormSetList);\r
 \r
 BOOLEAN               mSystemSubmit = FALSE;\r
-BOOLEAN               gResetRequired;\r
+BOOLEAN               gResetRequiredFormLevel;\r
+BOOLEAN               gResetRequiredSystemLevel = FALSE;\r
 BOOLEAN               gExitRequired;\r
+BOOLEAN               gFlagReconnect;\r
+BOOLEAN               gCallbackReconnect;\r
 BROWSER_SETTING_SCOPE gBrowserSettingScope = FormSetLevel;\r
 BOOLEAN               mBrowserScopeFirstSet = TRUE;\r
 EXIT_HANDLER          ExitHandlerFunction = NULL;\r
@@ -66,8 +63,6 @@ FORM_BROWSER_FORMSET  *mSystemLevelFormSet;
 CHAR16            *gEmptyString;\r
 CHAR16            *mUnknownString = L"!";\r
 \r
-EFI_GUID  gZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};\r
-\r
 extern EFI_GUID        mCurrentFormSetGuid;\r
 extern EFI_HII_HANDLE  mCurrentHiiHandle;\r
 extern UINT16          mCurrentFormId;\r
@@ -151,7 +146,7 @@ GetFirstFormId (
 **/\r
 FORM_ENTRY_INFO *\r
 UiFindMenuList (\r
-  IN EFI_HII_HANDLE       HiiHandle, \r
+  IN EFI_HII_HANDLE       HiiHandle,\r
   IN EFI_GUID             *FormSetGuid,\r
   IN UINT16               FormId\r
   )\r
@@ -167,7 +162,7 @@ UiFindMenuList (
   while (!IsNull (&mPrivateData.FormBrowserEx2.FormViewHistoryHead, Link)) {\r
     MenuList = FORM_ENTRY_INFO_FROM_LINK (Link);\r
     Link = GetNextNode (&mPrivateData.FormBrowserEx2.FormViewHistoryHead, Link);\r
-    \r
+\r
     //\r
     // If already find the menu, free the menus behind it.\r
     //\r
@@ -181,7 +176,7 @@ UiFindMenuList (
     // Find the same FromSet.\r
     //\r
     if (MenuList->HiiHandle == HiiHandle) {\r
-      if (CompareGuid (&MenuList->FormSetGuid, &gZeroGuid)) {\r
+      if (IsZeroGuid (&MenuList->FormSetGuid)) {\r
         //\r
         // FormSetGuid is not specified.\r
         //\r
@@ -207,7 +202,7 @@ UiFindMenuList (
 \r
   @param  CurrentMenu    Current Menu\r
   @param  SettingLevel   Whether find parent menu in Form Level or Formset level.\r
-                         In form level, just find the parent menu; \r
+                         In form level, just find the parent menu;\r
                          In formset level, find the parent menu which has different\r
                          formset guid value.\r
 \r
@@ -227,7 +222,7 @@ UiFindParentMenu (
   if (CurrentMenu == NULL) {\r
     return NULL;\r
   }\r
-  \r
+\r
   ParentMenu = NULL;\r
   Link       = &CurrentMenu->Link;\r
 \r
@@ -284,7 +279,7 @@ UiFreeMenuList (
 \r
 /**\r
   Copy current Menu list to the new menu list.\r
-  \r
+\r
   @param  NewMenuListHead        New create Menu list.\r
   @param  CurrentMenuListHead    Current Menu list.\r
 \r
@@ -483,11 +478,13 @@ SendForm (
   UINTN                         Index;\r
   FORM_BROWSER_FORMSET          *FormSet;\r
   FORM_ENTRY_INFO               *MenuList;\r
+  BOOLEAN                       RetVal;\r
 \r
   //\r
   // If EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found, return EFI_UNSUPPORTED.\r
   //\r
   if (mFormDisplay == NULL) {\r
+    DEBUG ((DEBUG_ERROR, "Fatal Error! EDKII_FORM_DISPLAY_ENGINE_PROTOCOL not found!"));\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -496,8 +493,10 @@ SendForm (
   //\r
   SaveBrowserContext ();\r
 \r
-  gResetRequired = FALSE;\r
+  gFlagReconnect = FALSE;\r
+  gResetRequiredFormLevel = FALSE;\r
   gExitRequired  = FALSE;\r
+  gCallbackReconnect = FALSE;\r
   Status         = EFI_SUCCESS;\r
   gEmptyString   = L"";\r
   gDisplayFormData.ScreenDimensions = (EFI_SCREEN_DESCRIPTOR *) ScreenDimensions;\r
@@ -547,6 +546,15 @@ SendForm (
       gCurrentSelection = NULL;\r
       mSystemLevelFormSet = NULL;\r
 \r
+      if (gFlagReconnect || gCallbackReconnect) {\r
+        RetVal = ReconnectController (FormSet->DriverHandle);\r
+        if (!RetVal) {\r
+          PopupErrorMessage(BROWSER_RECONNECT_FAIL, NULL, NULL, NULL);\r
+        }\r
+        gFlagReconnect = FALSE;\r
+        gCallbackReconnect = FALSE;\r
+      }\r
+\r
       //\r
       // If no data is changed, don't need to save current FormSet into the maintain list.\r
       //\r
@@ -566,7 +574,7 @@ SendForm (
 \r
   if (ActionRequest != NULL) {\r
     *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
-    if (gResetRequired) {\r
+    if (gResetRequiredFormLevel) {\r
       *ActionRequest = EFI_BROWSER_ACTION_REQUEST_RESET;\r
     }\r
   }\r
@@ -608,7 +616,7 @@ SendForm (
                                  distribution.\r
 \r
 **/\r
-EFI_STATUS \r
+EFI_STATUS\r
 ProcessStorage (\r
   IN OUT UINTN                         *ResultsDataSize,\r
   IN OUT EFI_STRING                    *ResultsData,\r
@@ -621,6 +629,8 @@ ProcessStorage (
   CHAR16                *StrPtr;\r
   UINTN                 BufferSize;\r
   UINTN                 TmpSize;\r
+  UINTN                 MaxLen;\r
+  FORMSET_STORAGE       *BrowserStorage;\r
 \r
   if (RetrieveData) {\r
     //\r
@@ -635,15 +645,17 @@ ProcessStorage (
     // Skip <ConfigHdr> and '&' to point to <ConfigBody> when first copy the configbody.\r
     // Also need to consider add "\0" at first time.\r
     //\r
-    StrPtr     = ConfigResp + StrLen (Storage->ConfigHdr) + 1;\r
+    StrPtr = StrStr (ConfigResp, L"PATH");\r
+    ASSERT (StrPtr != NULL);\r
+    StrPtr = StrStr (StrPtr, L"&");\r
+    StrPtr += 1;\r
     BufferSize = StrSize (StrPtr);\r
 \r
-\r
     //\r
     // Copy the data if the input buffer is bigger enough.\r
     //\r
     if (*ResultsDataSize >= BufferSize) {\r
-      StrCpy (*ResultsData, StrPtr);\r
+      StrCpyS (*ResultsData, *ResultsDataSize / sizeof (CHAR16), StrPtr);\r
     }\r
 \r
     *ResultsDataSize = BufferSize;\r
@@ -652,14 +664,17 @@ ProcessStorage (
     //\r
     // Prepare <ConfigResp>\r
     //\r
+    BrowserStorage = GetFstStgFromBrsStg (Storage);\r
+    ASSERT (BrowserStorage != NULL);\r
     TmpSize = StrLen (*ResultsData);\r
-    BufferSize = (TmpSize + StrLen (Storage->ConfigHdr) + 2) * sizeof (CHAR16);\r
+    BufferSize = (TmpSize + StrLen (BrowserStorage->ConfigHdr) + 2) * sizeof (CHAR16);\r
+    MaxLen = BufferSize / sizeof (CHAR16);\r
     ConfigResp = AllocateZeroPool (BufferSize);\r
     ASSERT (ConfigResp != NULL);\r
 \r
-    StrCpy (ConfigResp, Storage->ConfigHdr);\r
-    StrCat (ConfigResp, L"&");\r
-    StrCat (ConfigResp, *ResultsData);\r
+    StrCpyS (ConfigResp, MaxLen, BrowserStorage->ConfigHdr);\r
+    StrCatS (ConfigResp, MaxLen, L"&");\r
+    StrCatS (ConfigResp, MaxLen, *ResultsData);\r
 \r
     //\r
     // Update Browser uncommited data\r
@@ -675,8 +690,8 @@ ProcessStorage (
 }\r
 \r
 /**\r
-  This routine called this service in the browser to retrieve or set certain uncommitted \r
-  state information that resides in the open formsets. \r
+  This routine called this service in the browser to retrieve or set certain uncommitted\r
+  state information that resides in the open formsets.\r
 \r
   @param  This                   A pointer to the EFI_FORM_BROWSER2_PROTOCOL\r
                                  instance.\r
@@ -780,7 +795,7 @@ BrowserCallback (
       //\r
       // Different formsets may have same varstore, so here just set the flag\r
       // not exit the circle.\r
-      // \r
+      //\r
       Found = TRUE;\r
       break;\r
     }\r
@@ -805,7 +820,7 @@ BrowserCallback (
     }\r
 \r
     FormsetStorage = FORMSET_STORAGE_FROM_LINK (Link);\r
-    \r
+\r
     Status = ProcessStorage (&TotalSize, &ResultsData, RetrieveData, FormsetStorage->BrowserStorage);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -816,7 +831,7 @@ BrowserCallback (
     Status = TotalSize <= *ResultsDataSize ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;\r
     *ResultsDataSize = TotalSize;\r
   }\r
-   \r
+\r
   return Status;\r
 \r
 }\r
@@ -836,13 +851,11 @@ FormDisplayCallback (
   IN VOID         *Context\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-\r
   if (mFormDisplay != NULL) {\r
     return;\r
   }\r
 \r
-  Status = gBS->LocateProtocol (\r
+  gBS->LocateProtocol (\r
                   &gEdkiiFormDisplayEngineProtocolGuid,\r
                   NULL,\r
                   (VOID **) &mFormDisplay\r
@@ -917,10 +930,10 @@ InitializeSetup (
                   &mPrivateData.FormBrowserEx2\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   Status = gBS->InstallProtocolInterface (\r
                   &mPrivateData.Handle,\r
-                  &gEfiFormBrowserExProtocolGuid,\r
+                  &gEdkiiFormBrowserExProtocolGuid,\r
                   EFI_NATIVE_INTERFACE,\r
                   &mPrivateData.FormBrowserEx\r
                   );\r
@@ -943,7 +956,7 @@ InitializeSetup (
       &Registration\r
       );\r
   }\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -1062,19 +1075,19 @@ NewStringCat (
   )\r
 {\r
   CHAR16  *NewString;\r
-  UINTN   TmpSize;\r
+  UINTN   MaxLen;\r
 \r
   if (*Dest == NULL) {\r
     NewStringCpy (Dest, Src);\r
     return;\r
   }\r
 \r
-  TmpSize = StrSize (*Dest);\r
-  NewString = AllocateZeroPool (TmpSize + StrSize (Src) - 1);\r
+  MaxLen = ( StrSize (*Dest) + StrSize (Src) - 1) / sizeof (CHAR16);\r
+  NewString = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
   ASSERT (NewString != NULL);\r
 \r
-  StrCpy (NewString, *Dest);\r
-  StrCat (NewString, Src);\r
+  StrCpyS (NewString, MaxLen, *Dest);\r
+  StrCatS (NewString, MaxLen, Src);\r
 \r
   FreePool (*Dest);\r
   *Dest = NewString;\r
@@ -1219,6 +1232,7 @@ StorageToConfigResp (
   LIST_ENTRY              *Link;\r
   NAME_VALUE_NODE         *Node;\r
   UINT8                   *SourceBuf;\r
+  FORMSET_STORAGE         *FormsetStorage;\r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -1238,7 +1252,9 @@ StorageToConfigResp (
 \r
   case EFI_HII_VARSTORE_NAME_VALUE:\r
     *ConfigResp = NULL;\r
-    NewStringCat (ConfigResp, Storage->ConfigHdr);\r
+    FormsetStorage = GetFstStgFromBrsStg(Storage);\r
+    ASSERT (FormsetStorage != NULL);\r
+    NewStringCat (ConfigResp, FormsetStorage->ConfigHdr);\r
 \r
     Link = GetFirstNode (&Storage->NameValueListHead);\r
     while (!IsNull (&Storage->NameValueListHead, Link)) {\r
@@ -1346,6 +1362,71 @@ ConfigRespToStorage (
   return Status;\r
 }\r
 \r
+/**\r
+  Get bit field value from the buffer and then set the value for the question.\r
+  Note: Data type UINT32 can cover all the bit field value.\r
+\r
+  @param  Question        The question refer to bit field.\r
+  @param  Buffer          Point to the buffer which the question value get from.\r
+\r
+**/\r
+VOID\r
+GetBitsQuestionValue (\r
+  IN  FORM_BROWSER_STATEMENT *Question,\r
+  IN  UINT8                  *Buffer\r
+  )\r
+{\r
+  UINTN    StartBit;\r
+  UINTN    EndBit;\r
+  UINT32   RetVal;\r
+  UINT32   BufferValue;\r
+\r
+  StartBit = Question->BitVarOffset % 8;\r
+  EndBit = StartBit + Question->BitStorageWidth - 1;\r
+\r
+  CopyMem ((UINT8 *) &BufferValue, Buffer, Question->StorageWidth);\r
+\r
+  RetVal = BitFieldRead32 (BufferValue, StartBit, EndBit);\r
+\r
+  //\r
+  // Set question value.\r
+  // Note: Since Question with BufferValue (orderedlist, password, string)are not supported to refer bit field.\r
+  // Only oneof/checkbox/oneof can support bit field.So we can copy the value to the Hiivalue of Question directly.\r
+  //\r
+  CopyMem ((UINT8 *) &Question->HiiValue.Value, (UINT8 *) &RetVal, Question->StorageWidth);\r
+}\r
+\r
+/**\r
+  Set bit field value to the buffer.\r
+  Note: Data type UINT32 can cover all the bit field value.\r
+\r
+  @param  Question        The question refer to bit field.\r
+  @param  Buffer          Point to the buffer which the question value set to.\r
+  @param  Value           The bit field value need to set.\r
+\r
+**/\r
+VOID\r
+SetBitsQuestionValue (\r
+  IN     FORM_BROWSER_STATEMENT *Question,\r
+  IN OUT UINT8                  *Buffer,\r
+  IN     UINT32                 Value\r
+  )\r
+{\r
+  UINT32   Operand;\r
+  UINTN    StartBit;\r
+  UINTN    EndBit;\r
+  UINT32   RetVal;\r
+\r
+  StartBit = Question->BitVarOffset % 8;\r
+  EndBit = StartBit + Question->BitStorageWidth - 1;\r
+\r
+  CopyMem ((UINT8*) &Operand, Buffer, Question->StorageWidth);\r
+\r
+  RetVal = BitFieldWrite32 (Operand, StartBit, EndBit, Value);\r
+\r
+  CopyMem (Buffer, (UINT8*) &RetVal, Question->StorageWidth);\r
+}\r
+\r
 /**\r
   Convert the buffer value to HiiValue.\r
 \r
@@ -1373,9 +1454,12 @@ BufferToValue (
   BOOLEAN                      IsString;\r
   UINTN                        Length;\r
   EFI_STATUS                   Status;\r
+  UINT8                        *Buffer;\r
+\r
+  Buffer = NULL;\r
 \r
   IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  TRUE : FALSE);\r
-  if (Question->Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+  if (Question->Storage->Type == EFI_HII_VARSTORE_BUFFER ||\r
       Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
     IsBufferStorage = TRUE;\r
   } else {\r
@@ -1394,7 +1478,15 @@ BufferToValue (
     //\r
     // Other type of Questions\r
     //\r
-    Dst = (UINT8 *) &Question->HiiValue.Value;\r
+    if (Question->QuestionReferToBitField) {\r
+      Buffer = (UINT8 *)AllocateZeroPool (Question->StorageWidth);\r
+      if (Buffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      Dst = Buffer;\r
+    } else {\r
+      Dst = (UINT8 *) &Question->HiiValue.Value;\r
+    }\r
   }\r
 \r
   //\r
@@ -1408,46 +1500,55 @@ BufferToValue (
   *StringPtr = L'\0';\r
 \r
   LengthStr = StrLen (Value);\r
+\r
+  //\r
+  // Value points to a Unicode hexadecimal string, we need to convert the string to the value with CHAR16/UINT8...type.\r
+  // When generating the Value string, we follow this rule: 1 byte -> 2 Unicode characters (for string: 2 byte(CHAR16) ->4 Unicode characters).\r
+  // So the maximum value string length of a question is : Question->StorageWidth * 2.\r
+  // If the value string length > Question->StorageWidth * 2, only set the string length as Question->StorageWidth * 2, then convert.\r
+  //\r
+  if (LengthStr > (UINTN) Question->StorageWidth * 2) {\r
+    Length = (UINTN) Question->StorageWidth * 2;\r
+  } else {\r
+    Length = LengthStr;\r
+  }\r
+\r
   Status    = EFI_SUCCESS;\r
   if (!IsBufferStorage && IsString) {\r
     //\r
     // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"\r
     // Add string tail char L'\0' into Length\r
     //\r
-    Length    = Question->StorageWidth + sizeof (CHAR16);\r
-    if (Length < ((LengthStr / 4 + 1) * 2)) {\r
-      Status = EFI_BUFFER_TOO_SMALL;\r
-    } else {\r
-      DstBuf = (CHAR16 *) Dst;\r
-      ZeroMem (TemStr, sizeof (TemStr));\r
-      for (Index = 0; Index < LengthStr; Index += 4) {\r
-        StrnCpy (TemStr, Value + Index, 4);\r
-        DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
-      }\r
-      //\r
-      // Add tailing L'\0' character\r
-      //\r
-      DstBuf[Index/4] = L'\0';\r
+    DstBuf = (CHAR16 *) Dst;\r
+    ZeroMem (TemStr, sizeof (TemStr));\r
+    for (Index = 0; Index < Length; Index += 4) {\r
+      StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value + Index, 4);\r
+      DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
     }\r
+    //\r
+    // Add tailing L'\0' character\r
+    //\r
+    DstBuf[Index/4] = L'\0';\r
   } else {\r
-    if (Question->StorageWidth < ((LengthStr + 1) / 2)) {\r
-      Status = EFI_BUFFER_TOO_SMALL;\r
-    } else {\r
-      ZeroMem (TemStr, sizeof (TemStr));\r
-      for (Index = 0; Index < LengthStr; Index ++) {\r
-        TemStr[0] = Value[LengthStr - Index - 1];\r
-        DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
-        if ((Index & 1) == 0) {\r
-          Dst [Index/2] = DigitUint8;\r
-        } else {\r
-          Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);\r
-        }\r
+    ZeroMem (TemStr, sizeof (TemStr));\r
+    for (Index = 0; Index < Length; Index ++) {\r
+      TemStr[0] = Value[LengthStr - Index - 1];\r
+      DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+      if ((Index & 1) == 0) {\r
+        Dst [Index/2] = DigitUint8;\r
+      } else {\r
+        Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);\r
       }\r
     }\r
   }\r
 \r
   *StringPtr = TempChar;\r
 \r
+  if (Buffer != NULL && Question->QuestionReferToBitField) {\r
+    GetBitsQuestionValue (Question, Buffer);\r
+    FreePool (Buffer);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -1477,6 +1578,7 @@ GetQuestionValue (
   UINTN               StorageWidth;\r
   EFI_TIME            EfiTime;\r
   BROWSER_STORAGE     *Storage;\r
+  FORMSET_STORAGE     *FormsetStorage;\r
   EFI_IFR_TYPE_VALUE  *QuestionValue;\r
   CHAR16              *ConfigRequest;\r
   CHAR16              *Progress;\r
@@ -1484,6 +1586,7 @@ GetQuestionValue (
   CHAR16              *Value;\r
   UINTN               Length;\r
   BOOLEAN             IsBufferStorage;\r
+  UINTN               MaxLen;\r
 \r
   Status = EFI_SUCCESS;\r
   Value  = NULL;\r
@@ -1511,17 +1614,17 @@ GetQuestionValue (
         FreePool (Question->ValueExpression->Result.Buffer);\r
       }\r
       Question->HiiValue.Type = Question->ValueExpression->Result.Type;\r
-      CopyMem (&Question->HiiValue.Value, &Question->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));      \r
+      CopyMem (&Question->HiiValue.Value, &Question->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));\r
     }\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Get question value by read expression.\r
   //\r
   if (Question->ReadExpression != NULL && Form->FormType == STANDARD_MAP_FORM_TYPE) {\r
     Status = EvaluateExpression (FormSet, Form, Question->ReadExpression);\r
-    if (!EFI_ERROR (Status) && \r
+    if (!EFI_ERROR (Status) &&\r
       ((Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER) || (Question->ReadExpression->Result.Type == EFI_IFR_TYPE_BUFFER))) {\r
       //\r
       // Only update question value to the valid result.\r
@@ -1538,7 +1641,7 @@ GetQuestionValue (
         FreePool (Question->ReadExpression->Result.Buffer);\r
       }\r
       Question->HiiValue.Type = Question->ReadExpression->Result.Type;\r
-      CopyMem (&Question->HiiValue.Value, &Question->ReadExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));       \r
+      CopyMem (&Question->HiiValue.Value, &Question->ReadExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -1574,7 +1677,16 @@ GetQuestionValue (
       }\r
 \r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        if (Question->Operand == EFI_IFR_DATE_OP){\r
+          QuestionValue->date.Year  = 0xff;\r
+          QuestionValue->date.Month = 0xff;\r
+          QuestionValue->date.Day   = 0xff;\r
+        } else {\r
+          QuestionValue->time.Hour   = 0xff;\r
+          QuestionValue->time.Minute = 0xff;\r
+          QuestionValue->time.Second = 0xff;\r
+        }\r
+        return EFI_SUCCESS;\r
       }\r
 \r
       if (Question->Operand == EFI_IFR_DATE_OP) {\r
@@ -1630,7 +1742,7 @@ GetQuestionValue (
     Dst = (UINT8 *) &Question->HiiValue.Value;\r
   }\r
 \r
-  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+  if (Storage->Type == EFI_HII_VARSTORE_BUFFER ||\r
       Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
     IsBufferStorage = TRUE;\r
   } else {\r
@@ -1641,13 +1753,23 @@ GetQuestionValue (
       if (GetValueFrom == GetSetValueWithEditBuffer) {\r
         //\r
         // Copy from storage Edit buffer\r
+        // If the Question refer to bit filed, get the value in the related bit filed.\r
         //\r
-        CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+        if (Question->QuestionReferToBitField) {\r
+          GetBitsQuestionValue (Question, Storage->EditBuffer + Question->VarStoreInfo.VarOffset);\r
+        } else {\r
+          CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+        }\r
       } else {\r
         //\r
         // Copy from storage Edit buffer\r
+        // If the Question refer to bit filed, get the value in the related bit filed.\r
         //\r
-        CopyMem (Dst, Storage->Buffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+        if (Question->QuestionReferToBitField) {\r
+          GetBitsQuestionValue (Question, Storage->Buffer + Question->VarStoreInfo.VarOffset);\r
+        } else {\r
+          CopyMem (Dst, Storage->Buffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+        }\r
       }\r
     } else {\r
       Value = NULL;\r
@@ -1661,26 +1783,30 @@ GetQuestionValue (
       FreePool (Value);\r
     }\r
   } else {\r
+    FormsetStorage = GetFstStgFromVarId(FormSet, Question->VarStoreId);\r
+    ASSERT (FormsetStorage != NULL);\r
     //\r
     // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||\r
     //                   <ConfigHdr> + "&" + <VariableName>\r
     //\r
     if (IsBufferStorage) {\r
-      Length = StrLen (Storage->ConfigHdr);\r
+      Length = StrLen (FormsetStorage->ConfigHdr);\r
       Length += StrLen (Question->BlockName);\r
     } else {\r
-      Length = StrLen (Storage->ConfigHdr);\r
+      Length = StrLen (FormsetStorage->ConfigHdr);\r
       Length += StrLen (Question->VariableName) + 1;\r
     }\r
-    ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));\r
+    // Allocate buffer include '\0'\r
+    MaxLen = Length + 1;\r
+    ConfigRequest = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
     ASSERT (ConfigRequest != NULL);\r
 \r
-    StrCpy (ConfigRequest, Storage->ConfigHdr);\r
+    StrCpyS (ConfigRequest, MaxLen, FormsetStorage->ConfigHdr);\r
     if (IsBufferStorage) {\r
-      StrCat (ConfigRequest, Question->BlockName);\r
+      StrCatS (ConfigRequest, MaxLen, Question->BlockName);\r
     } else {\r
-      StrCat (ConfigRequest, L"&");\r
-      StrCat (ConfigRequest, Question->VariableName);\r
+      StrCatS (ConfigRequest, MaxLen, L"&");\r
+      StrCatS (ConfigRequest, MaxLen, Question->VariableName);\r
     }\r
 \r
     //\r
@@ -1773,6 +1899,7 @@ SetQuestionValue (
   UINTN               BufferLen;\r
   UINTN               StorageWidth;\r
   BROWSER_STORAGE     *Storage;\r
+  FORMSET_STORAGE     *FormsetStorage;\r
   EFI_IFR_TYPE_VALUE  *QuestionValue;\r
   CHAR16              *ConfigResp;\r
   CHAR16              *Progress;\r
@@ -1785,6 +1912,7 @@ SetQuestionValue (
   CHAR16              *TemString;\r
   UINTN               Index;\r
   NAME_VALUE_NODE     *Node;\r
+  UINTN               MaxLen;\r
 \r
   Status = EFI_SUCCESS;\r
   Node   = NULL;\r
@@ -1799,7 +1927,7 @@ SetQuestionValue (
   if (Question->ValueExpression != NULL) {\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Before set question value, evaluate its write expression.\r
   //\r
@@ -1894,7 +2022,7 @@ SetQuestionValue (
     Src = (UINT8 *) &Question->HiiValue.Value;\r
   }\r
 \r
-  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+  if (Storage->Type == EFI_HII_VARSTORE_BUFFER ||\r
       Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
     IsBufferStorage = TRUE;\r
   } else {\r
@@ -1907,13 +2035,23 @@ SetQuestionValue (
       if (SetValueTo == GetSetValueWithEditBuffer) {\r
         //\r
         // Copy to storage edit buffer\r
-        //      \r
-        CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+        // If the Question refer to bit filed, copy the value in related bit filed to storage edit buffer.\r
+        //\r
+        if (Question->QuestionReferToBitField) {\r
+          SetBitsQuestionValue (Question, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, (UINT32)(*Src));\r
+        } else {\r
+          CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+        }\r
       } else if (SetValueTo == GetSetValueWithBuffer) {\r
         //\r
-        // Copy to storage edit buffer\r
-        //     \r
-        CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+        // Copy to storage buffer\r
+        // If the Question refer to bit filed, copy the value in related bit filed to storage buffer.\r
+        //\r
+        if (Question->QuestionReferToBitField) {\r
+          SetBitsQuestionValue (Question, Storage->Buffer + Question->VarStoreInfo.VarOffset, (UINT32)(*Src));\r
+        } else {\r
+          CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+        }\r
       }\r
     } else {\r
       if (IsString) {\r
@@ -1930,7 +2068,14 @@ SetQuestionValue (
         TemName = (CHAR16 *) Src;\r
         TemString = Value;\r
         for (; *TemName != L'\0'; TemName++) {\r
-          TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
+          UnicodeValueToStringS (\r
+            TemString,\r
+            BufferLen - ((UINTN)TemString - (UINTN)Value),\r
+            PREFIX_ZERO | RADIX_HEX,\r
+            *TemName,\r
+            4\r
+            );\r
+          TemString += StrnLenS (TemString, (BufferLen - ((UINTN)TemString - (UINTN)Value)) / sizeof (CHAR16));\r
         }\r
       } else {\r
         BufferLen = StorageWidth * 2 + 1;\r
@@ -1942,7 +2087,14 @@ SetQuestionValue (
         TemBuffer = Src + StorageWidth - 1;\r
         TemString = Value;\r
         for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {\r
-          TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+          UnicodeValueToStringS (\r
+            TemString,\r
+            BufferLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)Value),\r
+            PREFIX_ZERO | RADIX_HEX,\r
+            *TemBuffer,\r
+            2\r
+            );\r
+          TemString += StrnLenS (TemString, BufferLen - ((UINTN)TemString - (UINTN)Value) / sizeof (CHAR16));\r
         }\r
       }\r
 \r
@@ -1967,17 +2119,20 @@ SetQuestionValue (
     } else {\r
       Length += (StorageWidth * 2);\r
     }\r
-    ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));\r
+    FormsetStorage = GetFstStgFromVarId(FormSet, Question->VarStoreId);\r
+    ASSERT (FormsetStorage != NULL);\r
+    MaxLen = StrLen (FormsetStorage->ConfigHdr) + Length + 1;\r
+    ConfigResp = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
     ASSERT (ConfigResp != NULL);\r
 \r
-    StrCpy (ConfigResp, Storage->ConfigHdr);\r
+    StrCpyS (ConfigResp, MaxLen, FormsetStorage->ConfigHdr);\r
     if (IsBufferStorage) {\r
-      StrCat (ConfigResp, Question->BlockName);\r
-      StrCat (ConfigResp, L"&VALUE=");\r
+      StrCatS (ConfigResp, MaxLen, Question->BlockName);\r
+      StrCatS (ConfigResp, MaxLen, L"&VALUE=");\r
     } else {\r
-      StrCat (ConfigResp, L"&");\r
-      StrCat (ConfigResp, Question->VariableName);\r
-      StrCat (ConfigResp, L"=");\r
+      StrCatS (ConfigResp, MaxLen, L"&");\r
+      StrCatS (ConfigResp, MaxLen, Question->VariableName);\r
+      StrCatS (ConfigResp, MaxLen, L"=");\r
     }\r
 \r
     Value = ConfigResp + StrLen (ConfigResp);\r
@@ -1989,7 +2144,14 @@ SetQuestionValue (
       TemName = (CHAR16 *) Src;\r
       TemString = Value;\r
       for (; *TemName != L'\0'; TemName++) {\r
-        TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
+        UnicodeValueToStringS (\r
+          TemString,\r
+          MaxLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)ConfigResp),\r
+          PREFIX_ZERO | RADIX_HEX,\r
+          *TemName,\r
+          4\r
+          );\r
+        TemString += StrnLenS (TemString, MaxLen - ((UINTN)TemString - (UINTN)ConfigResp) / sizeof (CHAR16));\r
       }\r
     } else {\r
       //\r
@@ -1998,7 +2160,14 @@ SetQuestionValue (
       TemBuffer = Src + StorageWidth - 1;\r
       TemString = Value;\r
       for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {\r
-        TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+        UnicodeValueToStringS (\r
+          TemString,\r
+          MaxLen * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)ConfigResp),\r
+          PREFIX_ZERO | RADIX_HEX,\r
+          *TemBuffer,\r
+          2\r
+          );\r
+        TemString += StrnLenS (TemString, MaxLen - ((UINTN)TemString - (UINTN)ConfigResp) / sizeof (CHAR16));\r
       }\r
     }\r
 \r
@@ -2024,7 +2193,7 @@ SetQuestionValue (
       return Status;\r
     }\r
     FreePool (ConfigResp);\r
-    \r
+\r
     //\r
     // Sync storage, from editbuffer to buffer.\r
     //\r
@@ -2147,9 +2316,9 @@ ValidateQuestion (
 }\r
 \r
 /**\r
-  Perform question check. \r
-  \r
-  If one question has more than one check, process form high priority to low. \r
+  Perform question check.\r
+\r
+  If one question has more than one check, process form high priority to low.\r
   Only one error info will be popup.\r
 \r
   @param  FormSet                FormSet data structure.\r
@@ -2250,7 +2419,7 @@ NoSubmitCheck (
 \r
   @param  Storage                The storage which need to sync.\r
   @param  ConfigRequest          The config request string which used to sync storage.\r
-  @param  SyncOrRestore          Sync the buffer to editbuffer or Restore  the \r
+  @param  SyncOrRestore          Sync the buffer to editbuffer or Restore  the\r
                                  editbuffer to buffer\r
                                  if TRUE, copy the editbuffer to the buffer.\r
                                  if FALSE, copy the buffer to the editbuffer.\r
@@ -2277,7 +2446,7 @@ SynchronizeStorage (
   Status = EFI_SUCCESS;\r
   Result = NULL;\r
 \r
-  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+  if (Storage->Type == EFI_HII_VARSTORE_BUFFER ||\r
       (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) {\r
     BufferSize = Storage->Size;\r
 \r
@@ -2385,6 +2554,10 @@ SendDiscardInfoToDriver (
     //\r
     GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer);\r
 \r
+    if (Question->Operand == EFI_IFR_STRING_OP){\r
+      HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r
+    }\r
+\r
     if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
       TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
     } else {\r
@@ -2403,6 +2576,94 @@ SendDiscardInfoToDriver (
   }\r
 }\r
 \r
+/**\r
+  When submit the question value, call the callback function with Submitted type\r
+  to inform the hii driver.\r
+\r
+  @param  FormSet                FormSet data structure.\r
+  @param  Form                   Form data structure.\r
+\r
+**/\r
+VOID\r
+SubmitCallbackForForm (\r
+  IN FORM_BROWSER_FORMSET             *FormSet,\r
+  IN FORM_BROWSER_FORM                *Form\r
+  )\r
+{\r
+  LIST_ENTRY                  *Link;\r
+  FORM_BROWSER_STATEMENT      *Question;\r
+  EFI_IFR_TYPE_VALUE          *TypeValue;\r
+  EFI_BROWSER_ACTION_REQUEST  ActionRequest;\r
+\r
+  if (FormSet->ConfigAccess == NULL) {\r
+    return;\r
+  }\r
+\r
+  Link = GetFirstNode (&Form->StatementListHead);\r
+  while (!IsNull (&Form->StatementListHead, Link)) {\r
+    Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
+    Link = GetNextNode (&Form->StatementListHead, Link);\r
+\r
+    if (Question->Storage == NULL || Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+      continue;\r
+    }\r
+\r
+    if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {\r
+       continue;\r
+    }\r
+\r
+    if (Question->Operand == EFI_IFR_PASSWORD_OP) {\r
+       continue;\r
+    }\r
+\r
+    if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
+      TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
+    } else {\r
+      TypeValue = &Question->HiiValue.Value;\r
+    }\r
+\r
+    ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
+    FormSet->ConfigAccess->Callback (\r
+                             FormSet->ConfigAccess,\r
+                             EFI_BROWSER_ACTION_SUBMITTED,\r
+                             Question->QuestionId,\r
+                             Question->HiiValue.Type,\r
+                             TypeValue,\r
+                             &ActionRequest\r
+                             );\r
+  }\r
+}\r
+\r
+/**\r
+  When value set Success, call the submit callback function.\r
+\r
+  @param  FormSet                FormSet data structure.\r
+  @param  Form                   Form data structure.\r
+\r
+**/\r
+VOID\r
+SubmitCallback (\r
+  IN FORM_BROWSER_FORMSET             *FormSet,\r
+  IN FORM_BROWSER_FORM                *Form\r
+  )\r
+{\r
+  FORM_BROWSER_FORM       *CurrentForm;\r
+  LIST_ENTRY              *Link;\r
+\r
+  if (Form != NULL) {\r
+    SubmitCallbackForForm(FormSet, Form);\r
+    return;\r
+  }\r
+\r
+  Link = GetFirstNode (&FormSet->FormListHead);\r
+  while (!IsNull (&FormSet->FormListHead, Link)) {\r
+    CurrentForm = FORM_BROWSER_FORM_FROM_LINK (Link);\r
+    Link = GetNextNode (&FormSet->FormListHead, Link);\r
+\r
+    SubmitCallbackForForm(FormSet, CurrentForm);\r
+  }\r
+}\r
+\r
 /**\r
   Validate the HiiHandle.\r
 \r
@@ -2511,9 +2772,16 @@ UpdateFlagForForm (
     //\r
     // Only the changed data has been saved, then need to set the reset flag.\r
     //\r
-    if (SetFlag && OldValue && !Question->ValueChanged && ((Question->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) != 0)) {\r
-      gResetRequired = TRUE;\r
-    } \r
+    if (SetFlag && OldValue && !Question->ValueChanged) {\r
+      if ((Question->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) != 0) {\r
+        gResetRequiredFormLevel = TRUE;\r
+        gResetRequiredSystemLevel = TRUE;\r
+      }\r
+\r
+      if ((Question->QuestionFlags & EFI_IFR_FLAG_RECONNECT_REQUIRED) != 0) {\r
+        gFlagReconnect = TRUE;\r
+      }\r
+    }\r
   }\r
 }\r
 \r
@@ -2522,7 +2790,7 @@ UpdateFlagForForm (
   Also clean ValueChanged flag for all statements.\r
 \r
   Form level or formset level, only one.\r
-  \r
+\r
   @param  SetFlag                Whether need to set the Reset Flag.\r
   @param  FormSet                FormSet data structure.\r
   @param  Form                   Form data structure.\r
@@ -2532,7 +2800,7 @@ VOID
 ValueChangeResetFlagUpdate (\r
   IN BOOLEAN                          SetFlag,\r
   IN FORM_BROWSER_FORMSET             *FormSet,\r
-  IN FORM_BROWSER_FORM                *Form  \r
+  IN FORM_BROWSER_FORM                *Form\r
   )\r
 {\r
   FORM_BROWSER_FORM       *CurrentForm;\r
@@ -2553,8 +2821,8 @@ ValueChangeResetFlagUpdate (
 }\r
 \r
 /**\r
-  Base on the return Progress string to find the form. \r
-  \r
+  Base on the return Progress string to find the form.\r
+\r
   Base on the first return Offset/Width (Name) string to find the form\r
   which keep this string.\r
 \r
@@ -2683,6 +2951,11 @@ FindQuestionFromProgress (
           *RetQuestion = Statement;\r
           break;\r
         }\r
+\r
+        if (Statement->VariableName != NULL && StrStr (Statement->VariableName, Progress) != NULL) {\r
+          *RetQuestion = Statement;\r
+          break;\r
+        }\r
       }\r
     }\r
 \r
@@ -2703,6 +2976,108 @@ FindQuestionFromProgress (
   return (BOOLEAN) (*RetForm != NULL);\r
 }\r
 \r
+/**\r
+  Base on the return Progress string to get the SyncConfigRequest and RestoreConfigRequest\r
+  for form and formset.\r
+\r
+  @param  Storage                 Storage which has this Progress string.\r
+  @param  ConfigRequest           The ConfigRequest string.\r
+  @param  Progress                The Progress string which has the first fail string.\r
+  @param  RestoreConfigRequest    Return the RestoreConfigRequest string.\r
+  @param  SyncConfigRequest       Return the SyncConfigRequest string.\r
+\r
+**/\r
+VOID\r
+GetSyncRestoreConfigRequest(\r
+  IN  BROWSER_STORAGE   *Storage,\r
+  IN  EFI_STRING        ConfigRequest,\r
+  IN  EFI_STRING        Progress,\r
+  OUT EFI_STRING        *RestoreConfigRequest,\r
+  OUT EFI_STRING        *SyncConfigRequest\r
+  )\r
+{\r
+  EFI_STRING    EndStr;\r
+  EFI_STRING    ConfigHdrEndStr;\r
+  EFI_STRING    ElementStr;\r
+  UINTN         TotalSize;\r
+  UINTN         RestoreEleSize;\r
+  UINTN         SyncSize;\r
+\r
+  ASSERT ((*Progress == L'&') || (*Progress == L'G'));\r
+  //\r
+  // If the Progress starts with ConfigHdr, means the failure is in the first name / value pair.\r
+  // Need to restore all the fields in the ConfigRequest.\r
+  //\r
+  if (*Progress == L'G') {\r
+    *RestoreConfigRequest = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest);\r
+    ASSERT (*RestoreConfigRequest != NULL);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Find the first fail "NAME" or "OFFSET=0x####&WIDTH=0x####" string.\r
+  //\r
+  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+    //\r
+    // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset,\r
+    // here, just keep the "Fred" string.\r
+    //\r
+    EndStr = StrStr (Progress, L"=");\r
+    ASSERT (EndStr != NULL);\r
+    *EndStr = L'\0';\r
+    //\r
+    // Find the ConfigHdr in ConfigRequest.\r
+    //\r
+    ConfigHdrEndStr = StrStr (ConfigRequest, L"PATH=");\r
+    ASSERT (ConfigHdrEndStr != NULL);\r
+    while (*ConfigHdrEndStr != L'&') {\r
+      ConfigHdrEndStr++;\r
+    }\r
+  } else {\r
+    //\r
+    // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####",\r
+    // here, just keep the "OFFSET=0x####&WIDTH=0x####" string.\r
+    //\r
+    EndStr = StrStr (Progress, L"&VALUE=");\r
+    ASSERT (EndStr != NULL);\r
+    *EndStr = L'\0';\r
+    //\r
+    // Find the ConfigHdr in ConfigRequest.\r
+    //\r
+    ConfigHdrEndStr = StrStr (ConfigRequest, L"&OFFSET=");\r
+  }\r
+  //\r
+  // Find the first fail pair in the ConfigRequest.\r
+  //\r
+  ElementStr = StrStr (ConfigRequest, Progress);\r
+  ASSERT (ElementStr != NULL);\r
+  //\r
+  // To get the RestoreConfigRequest.\r
+  //\r
+  RestoreEleSize = StrSize (ElementStr);\r
+  TotalSize = (ConfigHdrEndStr - ConfigRequest) * sizeof (CHAR16) + RestoreEleSize + sizeof (CHAR16);\r
+  *RestoreConfigRequest = AllocateZeroPool (TotalSize);\r
+  ASSERT (*RestoreConfigRequest != NULL);\r
+  StrnCpyS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ConfigRequest, ConfigHdrEndStr - ConfigRequest);\r
+  StrCatS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ElementStr);\r
+  //\r
+  // To get the SyncConfigRequest.\r
+  //\r
+  SyncSize = StrSize (ConfigRequest) - RestoreEleSize + sizeof (CHAR16);\r
+  *SyncConfigRequest = AllocateZeroPool (SyncSize);\r
+  ASSERT (*SyncConfigRequest != NULL);\r
+  StrnCpyS (*SyncConfigRequest, SyncSize / sizeof (CHAR16), ConfigRequest, SyncSize / sizeof (CHAR16) - 1);\r
+\r
+  //\r
+  // restore the Progress string to the original format.\r
+  //\r
+  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+    *EndStr = L'=';\r
+  } else {\r
+    *EndStr = L'&';\r
+  }\r
+}\r
+\r
 /**\r
   Popup an save error info and get user input.\r
 \r
@@ -2728,9 +3103,9 @@ ConfirmSaveFail (
   ASSERT (StringBuffer != NULL);\r
 \r
   UnicodeSPrint (\r
-    StringBuffer, \r
-    24 * sizeof (CHAR16) + StrSize (FormTitle), \r
-    L"Submit Fail For Form: %s.", \r
+    StringBuffer,\r
+    24 * sizeof (CHAR16) + StrSize (FormTitle),\r
+    L"Submit Fail For Form: %s.",\r
     FormTitle\r
     );\r
 \r
@@ -2767,9 +3142,9 @@ ConfirmNoSubmitFail (
   ASSERT (StringBuffer != NULL);\r
 \r
   UnicodeSPrint (\r
-    StringBuffer, \r
-    24 * sizeof (CHAR16) + StrSize (FormTitle), \r
-    L"NO_SUBMIT_IF error For Form: %s.", \r
+    StringBuffer,\r
+    24 * sizeof (CHAR16) + StrSize (FormTitle),\r
+    L"NO_SUBMIT_IF error For Form: %s.",\r
     FormTitle\r
     );\r
 \r
@@ -2870,7 +3245,7 @@ DiscardForm (
     while (!IsNull (&FormSet->FormListHead, Link)) {\r
       Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
       Link = GetNextNode (&FormSet->FormListHead, Link);\r
-      \r
+\r
       //\r
       // Call callback with Changed type to inform the driver.\r
       //\r
@@ -2911,7 +3286,7 @@ DiscardForm (
     mSystemLevelFormSet = OldFormSet;\r
   }\r
 \r
-  return EFI_SUCCESS;  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -2936,6 +3311,9 @@ SubmitForForm (
   EFI_STRING              Progress;\r
   BROWSER_STORAGE         *Storage;\r
   FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;\r
+  BOOLEAN                 SubmitFormFail;\r
+\r
+  SubmitFormFail = FALSE;\r
 \r
   if (!IsNvUpdateRequiredForForm (Form)) {\r
     return EFI_SUCCESS;\r
@@ -2979,13 +3357,19 @@ SubmitForForm (
                                       ConfigResp,\r
                                       &Progress\r
                                       );\r
-    FreePool (ConfigResp);\r
 \r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest.\r
+      //\r
+      SubmitFormFail = TRUE;\r
+      GetSyncRestoreConfigRequest (ConfigInfo->Storage, ConfigInfo->ConfigRequest, Progress, &ConfigInfo->RestoreConfigRequest, &ConfigInfo->SyncConfigRequest);\r
       InsertTailList (&gBrowserSaveFailFormSetList, &ConfigInfo->SaveFailLink);\r
+      FreePool (ConfigResp);\r
       continue;\r
     }\r
 \r
+    FreePool (ConfigResp);\r
     //\r
     // 3. Config success, update storage shadow Buffer, only update the data belong to this form.\r
     //\r
@@ -3001,11 +3385,22 @@ SubmitForForm (
       while (!IsNull (&gBrowserSaveFailFormSetList, Link)) {\r
         ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link);\r
         Link = GetNextNode (&gBrowserSaveFailFormSetList, Link);\r
-\r
-        SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE);\r
+        //\r
+        // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+        // base on the SyncConfigRequest to Sync the buffer.\r
+        //\r
+        SynchronizeStorage (ConfigInfo->Storage, ConfigInfo->RestoreConfigRequest, FALSE);\r
+        FreePool (ConfigInfo->RestoreConfigRequest);\r
+        ConfigInfo->RestoreConfigRequest = NULL;\r
+        if (ConfigInfo->SyncConfigRequest != NULL) {\r
+          SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->SyncConfigRequest, TRUE);\r
+          FreePool (ConfigInfo->SyncConfigRequest);\r
+          ConfigInfo->SyncConfigRequest = NULL;\r
+        }\r
 \r
         Status = EFI_SUCCESS;\r
       }\r
+      SendDiscardInfoToDriver (FormSet,Form);\r
     } else {\r
       Status = EFI_UNSUPPORTED;\r
     }\r
@@ -3025,6 +3420,13 @@ SubmitForForm (
   //\r
   ValueChangeResetFlagUpdate(TRUE, FormSet, Form);\r
 \r
+  //\r
+  // 6 Call callback with Submitted type to inform the driver.\r
+  //\r
+  if (!SubmitFormFail) {\r
+    SubmitCallback (FormSet, Form);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -3033,9 +3435,9 @@ SubmitForForm (
 \r
   @param  FormSet                FormSet data structure.\r
   @param  SkipProcessFail        Whether skip to process the save failed storage.\r
-                                 If submit formset is called when do system level save, \r
-                                 set this value to true and process the failed formset \r
-                                 together. \r
+                                 If submit formset is called when do system level save,\r
+                                 set this value to true and process the failed formset\r
+                                 together.\r
                                  if submit formset is called when do formset level save,\r
                                  set the value to false and process the failed storage\r
                                  right after process all storages for this formset.\r
@@ -3059,14 +3461,18 @@ SubmitForFormSet (
   FORM_BROWSER_FORM       *Form;\r
   BOOLEAN                 HasInserted;\r
   FORM_BROWSER_STATEMENT  *Question;\r
+  BOOLEAN                 SubmitFormSetFail;\r
+  BOOLEAN                 DiscardChange;\r
 \r
   HasInserted = FALSE;\r
+  SubmitFormSetFail = FALSE;\r
+  DiscardChange     = FALSE;\r
 \r
   if (!IsNvUpdateRequiredForFormSet (FormSet)) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  Form = NULL; \r
+  Form = NULL;\r
   Status = NoSubmitCheck (FormSet, &Form, &Question);\r
   if (EFI_ERROR (Status)) {\r
     if (SkipProcessFail) {\r
@@ -3120,6 +3526,11 @@ SubmitForFormSet (
                                       &Progress\r
                                       );\r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest.\r
+      //\r
+      SubmitFormSetFail = TRUE;\r
+      GetSyncRestoreConfigRequest (FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, Progress, &FormSetStorage->RestoreConfigRequest, &FormSetStorage->SyncConfigRequest);\r
       InsertTailList (&FormSet->SaveFailStorageListHead, &FormSetStorage->SaveFailLink);\r
       if (!HasInserted) {\r
         //\r
@@ -3156,13 +3567,24 @@ SubmitForFormSet (
       // If not in system level, just handl the save failed storage here.\r
       //\r
       if (ConfirmSaveFail (Form->FormTitle, FormSet->HiiHandle) == BROWSER_ACTION_DISCARD) {\r
+        DiscardChange = TRUE;\r
         Link = GetFirstNode (&FormSet->SaveFailStorageListHead);\r
         while (!IsNull (&FormSet->SaveFailStorageListHead, Link)) {\r
           FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link);\r
           Storage        = FormSetStorage->BrowserStorage;\r
           Link = GetNextNode (&FormSet->SaveFailStorageListHead, Link);\r
-\r
-          SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
+          //\r
+          // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+          // base on the SyncConfigRequest to Sync the buffer.\r
+          //\r
+          SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE);\r
+          FreePool (FormSetStorage->RestoreConfigRequest);\r
+          FormSetStorage->RestoreConfigRequest = NULL;\r
+          if (FormSetStorage->SyncConfigRequest != NULL) {\r
+            SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE);\r
+            FreePool (FormSetStorage->SyncConfigRequest);\r
+            FormSetStorage->SyncConfigRequest = NULL;\r
+          }\r
 \r
           Status = EFI_SUCCESS;\r
         }\r
@@ -3194,11 +3616,33 @@ SubmitForFormSet (
     }\r
   }\r
 \r
+  //\r
+  // If user discard the change, send the discard info to driver.\r
+  //\r
+  if (DiscardChange) {\r
+    Link = GetFirstNode (&FormSet->FormListHead);\r
+    while (!IsNull (&FormSet->FormListHead, Link)) {\r
+      Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
+      Link = GetNextNode (&FormSet->FormListHead, Link);\r
+      //\r
+      // Call callback with Changed type to inform the driver.\r
+      //\r
+      SendDiscardInfoToDriver (FormSet, Form);\r
+    }\r
+  }\r
+\r
   //\r
   // 5. Update the NV flag.\r
-  // \r
+  //\r
   ValueChangeResetFlagUpdate(TRUE, FormSet, NULL);\r
 \r
+  //\r
+  // 6. Call callback with Submitted type to inform the driver.\r
+  //\r
+  if (!SubmitFormSetFail) {\r
+    SubmitCallback (FormSet, NULL);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -3216,8 +3660,8 @@ SubmitForSystem (
 {\r
   EFI_STATUS              Status;\r
   LIST_ENTRY              *Link;\r
+  LIST_ENTRY              *FormLink;\r
   LIST_ENTRY              *StorageLink;\r
-  BROWSER_STORAGE         *Storage;\r
   FORMSET_STORAGE         *FormSetStorage;\r
   FORM_BROWSER_FORM       *Form;\r
   FORM_BROWSER_FORMSET    *LocalFormSet;\r
@@ -3240,7 +3684,7 @@ SubmitForSystem (
 \r
     //\r
     // Remove maintain backup list after save except for the current using FormSet.\r
-    //  \r
+    //\r
     if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) {\r
       CleanBrowserStorage(LocalFormSet);\r
       RemoveEntryList (&LocalFormSet->Link);\r
@@ -3283,7 +3727,6 @@ SubmitForSystem (
         StorageLink = GetFirstNode (&LocalFormSet->StorageListHead);\r
         while (!IsNull (&LocalFormSet->StorageListHead, StorageLink)) {\r
           FormSetStorage = FORMSET_STORAGE_FROM_LINK (StorageLink);\r
-          Storage        = FormSetStorage->BrowserStorage;\r
           StorageLink = GetNextNode (&LocalFormSet->StorageListHead, StorageLink);\r
 \r
           SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
@@ -3292,13 +3735,32 @@ SubmitForSystem (
         StorageLink = GetFirstNode (&LocalFormSet->SaveFailStorageListHead);\r
         while (!IsNull (&LocalFormSet->SaveFailStorageListHead, StorageLink)) {\r
           FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink);\r
-          Storage        = FormSetStorage->BrowserStorage;\r
           StorageLink = GetNextNode (&LocalFormSet->SaveFailStorageListHead, StorageLink);\r
-\r
-          SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
+          //\r
+          // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+          // base on the SyncConfigRequest to Sync the buffer.\r
+          //\r
+          SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE);\r
+          FreePool (FormSetStorage->RestoreConfigRequest);\r
+          FormSetStorage->RestoreConfigRequest = NULL;\r
+          if ( FormSetStorage->SyncConfigRequest != NULL) {\r
+            SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE);\r
+            FreePool (FormSetStorage->SyncConfigRequest);\r
+            FormSetStorage->SyncConfigRequest = NULL;\r
+          }\r
         }\r
       }\r
 \r
+      FormLink = GetFirstNode (&LocalFormSet->FormListHead);\r
+      while (!IsNull (&LocalFormSet->FormListHead, FormLink)) {\r
+        Form = FORM_BROWSER_FORM_FROM_LINK (FormLink);\r
+        FormLink = GetNextNode (&LocalFormSet->FormListHead, FormLink);\r
+        //\r
+        // Call callback with Changed type to inform the driver.\r
+        //\r
+        SendDiscardInfoToDriver (LocalFormSet, Form);\r
+      }\r
+\r
       if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) {\r
         CleanBrowserStorage(LocalFormSet);\r
         RemoveEntryList (&LocalFormSet->Link);\r
@@ -3453,6 +3915,11 @@ GetOffsetFromConfigResp (
   // Type is EFI_HII_VARSTORE_EFI_VARIABLE or EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER\r
   //\r
 \r
+  //\r
+  // Convert all hex digits in ConfigResp to lower case before searching.\r
+  //\r
+  HiiToLower (ConfigResp);\r
+\r
   //\r
   // 1. Directly use Question->BlockName to find.\r
   //\r
@@ -3464,7 +3931,7 @@ GetOffsetFromConfigResp (
     RequestElement += StrLen (Question->BlockName) + StrLen (L"&VALUE=");\r
     return RequestElement;\r
   }\r
-  \r
+\r
   //\r
   // 2. Change all hex digits in Question->BlockName to lower and compare again.\r
   //\r
@@ -3500,7 +3967,7 @@ GetDefaultValueFromAltCfg (
   IN     FORM_BROWSER_FORM                *Form,\r
   IN OUT FORM_BROWSER_STATEMENT           *Question\r
   )\r
-{ \r
+{\r
   BROWSER_STORAGE              *Storage;\r
   FORMSET_STORAGE              *FormSetStorage;\r
   CHAR16                       *ConfigResp;\r
@@ -3566,7 +4033,7 @@ INTN
 GetDefaultIdForCallBack (\r
   UINTN DefaultId\r
   )\r
-{ \r
+{\r
   if (DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) {\r
     return EFI_BROWSER_ACTION_DEFAULT_STANDARD;\r
   } else if (DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
@@ -3746,9 +4213,15 @@ GetQuestionDefault (
   EFI_BROWSER_ACTION_REQUEST      ActionRequest;\r
   INTN                            Action;\r
   CHAR16                          *NewString;\r
+  EFI_IFR_TYPE_VALUE              *TypeValue;\r
+  UINT16                          OriginalDefaultId;\r
+  FORMSET_DEFAULTSTORE            *DefaultStore;\r
+  LIST_ENTRY                      *DefaultLink;\r
 \r
   Status   = EFI_NOT_FOUND;\r
   StrValue = NULL;\r
+  OriginalDefaultId  = DefaultId;\r
+  DefaultLink        = GetFirstNode (&FormSet->DefaultStoreListHead);\r
 \r
   //\r
   // Statement don't have storage, skip them\r
@@ -3761,11 +4234,19 @@ GetQuestionDefault (
   // There are Five ways to specify default value for a Question:\r
   //  1, use call back function (highest priority)\r
   //  2, use ExtractConfig function\r
-  //  3, use nested EFI_IFR_DEFAULT \r
+  //  3, use nested EFI_IFR_DEFAULT\r
   //  4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)\r
   //  5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)\r
   //\r
+ReGetDefault:\r
   HiiValue = &Question->HiiValue;\r
+  TypeValue = &HiiValue->Value;\r
+  if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {\r
+    //\r
+    // For orderedlist, need to pass the BufferValue to Callback function.\r
+    //\r
+    TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
+  }\r
 \r
   //\r
   // Get Question defaut value from call back function.\r
@@ -3779,7 +4260,7 @@ GetQuestionDefault (
                              Action,\r
                              Question->QuestionId,\r
                              HiiValue->Type,\r
-                             &HiiValue->Value,\r
+                             TypeValue,\r
                              &ActionRequest\r
                              );\r
     if (!EFI_ERROR (Status)) {\r
@@ -3789,6 +4270,7 @@ GetQuestionDefault (
 \r
         ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth);\r
         if (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth) {\r
+          ZeroMem (Question->BufferValue, Question->StorageWidth);\r
           CopyMem (Question->BufferValue, NewString, StrSize (NewString));\r
         } else {\r
           CopyMem (Question->BufferValue, NewString, Question->StorageWidth);\r
@@ -3803,7 +4285,7 @@ GetQuestionDefault (
   //\r
   // Get default value from altcfg string.\r
   //\r
-  if (ConfigAccess != NULL) {  \r
+  if (ConfigAccess != NULL) {\r
     Status = GetDefaultValueFromAltCfg(FormSet, Form, Question);\r
     if (!EFI_ERROR (Status)) {\r
         return Status;\r
@@ -3840,12 +4322,17 @@ GetQuestionDefault (
             FreePool (Default->ValueExpression->Result.Buffer);\r
           }\r
           HiiValue->Type = Default->ValueExpression->Result.Type;\r
-          CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));       \r
+          CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));\r
         } else {\r
           //\r
           // Default value is embedded in EFI_IFR_DEFAULT\r
           //\r
-          CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE));\r
+          if (Default->Value.Type == EFI_IFR_TYPE_BUFFER) {\r
+            ASSERT (HiiValue->Buffer != NULL);\r
+            CopyMem (HiiValue->Buffer, Default->Value.Buffer, Default->Value.BufferLen);\r
+          } else {\r
+            CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE));\r
+          }\r
         }\r
 \r
         if (HiiValue->Type == EFI_IFR_TYPE_STRING) {\r
@@ -3854,6 +4341,7 @@ GetQuestionDefault (
             return EFI_NOT_FOUND;\r
           }\r
           if (Question->StorageWidth > StrSize (StrValue)) {\r
+            ZeroMem (Question->BufferValue, Question->StorageWidth);\r
             CopyMem (Question->BufferValue, StrValue, StrSize (StrValue));\r
           } else {\r
             CopyMem (Question->BufferValue, StrValue, Question->StorageWidth);\r
@@ -3908,8 +4396,6 @@ GetQuestionDefault (
           ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0))\r
          ) {\r
         HiiValue->Value.b = TRUE;\r
-      } else {\r
-        HiiValue->Value.b = FALSE;\r
       }\r
 \r
       return EFI_SUCCESS;\r
@@ -3917,17 +4403,71 @@ GetQuestionDefault (
   }\r
 \r
   //\r
-  // For Questions without default\r
+  // For question without default value for current default Id, we try to re-get the default value form other default id in the DefaultStoreList.\r
+  // If get, will exit the function, if not, will choose next default id in the DefaultStoreList.\r
+  // The default id in DefaultStoreList are in ascending order to make sure choose the smallest default id every time.\r
+  //\r
+  while (!IsNull(&FormSet->DefaultStoreListHead, DefaultLink)) {\r
+    DefaultStore = FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink);\r
+    DefaultLink = GetNextNode (&FormSet->DefaultStoreListHead,DefaultLink);\r
+    DefaultId = DefaultStore->DefaultId;\r
+    if (DefaultId == OriginalDefaultId) {\r
+      continue;\r
+    }\r
+    goto ReGetDefault;\r
+  }\r
+\r
+  //\r
+  // For Questions without default value for all the default id in the DefaultStoreList.\r
   //\r
   Status = EFI_NOT_FOUND;\r
   switch (Question->Operand) {\r
+  case EFI_IFR_CHECKBOX_OP:\r
+    HiiValue->Value.b = FALSE;\r
+    Status = EFI_SUCCESS;\r
+    break;\r
+\r
   case EFI_IFR_NUMERIC_OP:\r
     //\r
     // Take minimum value as numeric default value\r
     //\r
-    if ((HiiValue->Value.u64 < Question->Minimum) || (HiiValue->Value.u64 > Question->Maximum)) {\r
-      HiiValue->Value.u64 = Question->Minimum;\r
-      Status = EFI_SUCCESS;\r
+    if ((Question->Flags & EFI_IFR_DISPLAY) == 0) {\r
+      //\r
+      // In EFI_IFR_DISPLAY_INT_DEC type, should check value with int* type.\r
+      //\r
+      switch (Question->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+      case EFI_IFR_NUMERIC_SIZE_1:\r
+        if (((INT8) HiiValue->Value.u8 < (INT8) Question->Minimum) || ((INT8) HiiValue->Value.u8 > (INT8) Question->Maximum)) {\r
+          HiiValue->Value.u8 = (UINT8) Question->Minimum;\r
+          Status = EFI_SUCCESS;\r
+        }\r
+        break;\r
+      case EFI_IFR_NUMERIC_SIZE_2:\r
+        if (((INT16) HiiValue->Value.u16 < (INT16) Question->Minimum) || ((INT16) HiiValue->Value.u16 > (INT16) Question->Maximum)) {\r
+          HiiValue->Value.u16 = (UINT16) Question->Minimum;\r
+          Status = EFI_SUCCESS;\r
+        }\r
+        break;\r
+      case EFI_IFR_NUMERIC_SIZE_4:\r
+        if (((INT32) HiiValue->Value.u32 < (INT32) Question->Minimum) || ((INT32) HiiValue->Value.u32 > (INT32) Question->Maximum)) {\r
+          HiiValue->Value.u32 = (UINT32) Question->Minimum;\r
+          Status = EFI_SUCCESS;\r
+        }\r
+        break;\r
+      case EFI_IFR_NUMERIC_SIZE_8:\r
+        if (((INT64) HiiValue->Value.u64 < (INT64) Question->Minimum) || ((INT64) HiiValue->Value.u64 > (INT64) Question->Maximum)) {\r
+          HiiValue->Value.u64 = Question->Minimum;\r
+          Status = EFI_SUCCESS;\r
+        }\r
+        break;\r
+      default:\r
+        break;\r
+      }\r
+    } else {\r
+      if ((HiiValue->Value.u64 < Question->Minimum) || (HiiValue->Value.u64 > Question->Maximum)) {\r
+        HiiValue->Value.u64 = Question->Minimum;\r
+        Status = EFI_SUCCESS;\r
+      }\r
     }\r
     break;\r
 \r
@@ -3991,13 +4531,15 @@ GetQuestionDefault (
   @param  FormSet                Form data structure.\r
   @param  Form                   Form data structure.\r
   @param  DefaultId              The Class of the default.\r
+  @param  BrowserStorage         The input request storage for the questions.\r
 \r
 **/\r
 VOID\r
 ExtractAltCfgForForm (\r
   IN FORM_BROWSER_FORMSET   *FormSet,\r
   IN FORM_BROWSER_FORM      *Form,\r
-  IN UINT16                 DefaultId\r
+  IN UINT16                 DefaultId,\r
+  IN BROWSER_STORAGE        *BrowserStorage\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -4018,10 +4560,13 @@ ExtractAltCfgForForm (
     FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link);\r
     Storage        = FormSetStorage->BrowserStorage;\r
     Link = GetNextNode (&FormSet->StorageListHead, Link);\r
+    if (BrowserStorage != NULL && BrowserStorage != Storage) {\r
+      continue;\r
+    }\r
 \r
     if (Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE &&\r
         FormSetStorage->ElementCount != 0 &&\r
-        FormSetStorage->ConfigAltResp != NULL) {\r
+        FormSetStorage->HasCallAltCfg) {\r
       return;\r
     }\r
   }\r
@@ -4035,6 +4580,10 @@ ExtractAltCfgForForm (
     Link = GetNextNode (&Form->ConfigRequestHead, Link);\r
 \r
     Storage = ConfigInfo->Storage;\r
+    if (BrowserStorage != NULL && BrowserStorage != Storage) {\r
+      continue;\r
+    }\r
+\r
     if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
       continue;\r
     }\r
@@ -4112,12 +4661,14 @@ CleanAltCfgForForm (
 \r
   @param  FormSet                Form data structure.\r
   @param  DefaultId              The Class of the default.\r
+  @param  BrowserStorage         The input request storage for the questions.\r
 \r
 **/\r
 VOID\r
 ExtractAltCfgForFormSet (\r
   IN FORM_BROWSER_FORMSET   *FormSet,\r
-  IN UINT16                 DefaultId\r
+  IN UINT16                 DefaultId,\r
+  IN BROWSER_STORAGE        *BrowserStorage\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -4134,6 +4685,10 @@ ExtractAltCfgForFormSet (
     Storage        = FormSetStorage->BrowserStorage;\r
     Link = GetNextNode (&FormSet->StorageListHead, Link);\r
 \r
+    if (BrowserStorage != NULL && BrowserStorage != Storage) {\r
+      continue;\r
+    }\r
+\r
     if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
       continue;\r
     }\r
@@ -4145,6 +4700,8 @@ ExtractAltCfgForFormSet (
       continue;\r
     }\r
 \r
+    FormSetStorage->HasCallAltCfg = TRUE;\r
+\r
     //\r
     // 2. Get value through hii config routine protocol.\r
     //\r
@@ -4205,13 +4762,15 @@ CleanAltCfgForFormSet (
       FreePool (FormSetStorage->ConfigAltResp);\r
       FormSetStorage->ConfigAltResp = NULL;\r
     }\r
+\r
+    FormSetStorage->HasCallAltCfg = FALSE;\r
   }\r
 }\r
 \r
 /**\r
   Reset Questions to their initial value or default value in a Form, Formset or System.\r
 \r
-  GetDefaultValueScope parameter decides which questions will reset \r
+  GetDefaultValueScope parameter decides which questions will reset\r
   to its default value.\r
 \r
   @param  FormSet                FormSet data structure.\r
@@ -4223,6 +4782,7 @@ CleanAltCfgForFormSet (
   @param  RetrieveValueFirst     Whether call the retrieve call back to\r
                                  get the initial value before get default\r
                                  value.\r
+  @param  SkipGetAltCfg          Whether skip the get altcfg string process.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_UNSUPPORTED        Unsupport SettingScope.\r
@@ -4236,7 +4796,8 @@ ExtractDefault (
   IN BROWSER_SETTING_SCOPE            SettingScope,\r
   IN BROWSER_GET_DEFAULT_VALUE        GetDefaultValueScope,\r
   IN BROWSER_STORAGE                  *Storage OPTIONAL,\r
-  IN BOOLEAN                          RetrieveValueFirst\r
+  IN BOOLEAN                          RetrieveValueFirst,\r
+  IN BOOLEAN                          SkipGetAltCfg\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -4263,7 +4824,9 @@ ExtractDefault (
     //\r
     // Prepare the AltCfg String for form.\r
     //\r
-    ExtractAltCfgForForm (FormSet, Form, DefaultId);\r
+    if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) {\r
+      ExtractAltCfgForForm (FormSet, Form, DefaultId, Storage);\r
+    }\r
 \r
     //\r
     // Extract Form default\r
@@ -4325,24 +4888,30 @@ ExtractDefault (
     //\r
     // Clean the AltCfg String.\r
     //\r
-    CleanAltCfgForForm(Form);\r
+    if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) {\r
+      CleanAltCfgForForm(Form);\r
+    }\r
   } else if (SettingScope == FormSetLevel) {\r
     //\r
     // Prepare the AltCfg String for formset.\r
     //\r
-    ExtractAltCfgForFormSet (FormSet, DefaultId);\r
+    if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) {\r
+      ExtractAltCfgForFormSet (FormSet, DefaultId, Storage);\r
+    }\r
 \r
     FormLink = GetFirstNode (&FormSet->FormListHead);\r
     while (!IsNull (&FormSet->FormListHead, FormLink)) {\r
       Form = FORM_BROWSER_FORM_FROM_LINK (FormLink);\r
-      ExtractDefault (FormSet, Form, DefaultId, FormLevel, GetDefaultValueScope, Storage, RetrieveValueFirst);\r
+      ExtractDefault (FormSet, Form, DefaultId, FormLevel, GetDefaultValueScope, Storage, RetrieveValueFirst, SkipGetAltCfg);\r
       FormLink = GetNextNode (&FormSet->FormListHead, FormLink);\r
     }\r
 \r
     //\r
     // Clean the AltCfg String.\r
     //\r
-    CleanAltCfgForFormSet (FormSet);\r
+    if (!SkipGetAltCfg && (GetDefaultValueScope != GetDefaultForNoStorage)) {\r
+      CleanAltCfgForFormSet (FormSet);\r
+    }\r
   } else if (SettingScope == SystemLevel) {\r
     //\r
     // Preload all Hii formset.\r
@@ -4364,7 +4933,7 @@ ExtractDefault (
 \r
       mSystemLevelFormSet = LocalFormSet;\r
 \r
-      ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst);\r
+      ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst, SkipGetAltCfg);\r
     }\r
 \r
     mSystemLevelFormSet = OldFormSet;\r
@@ -4492,7 +5061,7 @@ IsQuestionValueChanged (
 /**\r
   Initialize Question's Edit copy from Storage.\r
 \r
-  @param  Selection              Selection contains the information about \r
+  @param  Selection              Selection contains the information about\r
                                  the Selection, form and formset to be displayed.\r
                                  Selection action may be updated in retrieve callback.\r
                                  If Selection is NULL, only initialize Question value.\r
@@ -4512,7 +5081,7 @@ LoadFormConfig (
   EFI_STATUS                  Status;\r
   LIST_ENTRY                  *Link;\r
   FORM_BROWSER_STATEMENT      *Question;\r
-  \r
+\r
   Link = GetFirstNode (&Form->StatementListHead);\r
   while (!IsNull (&Form->StatementListHead, Link)) {\r
     Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
@@ -4542,7 +5111,7 @@ LoadFormConfig (
 /**\r
   Initialize Question's Edit copy from Storage for the whole Formset.\r
 \r
-  @param  Selection              Selection contains the information about \r
+  @param  Selection              Selection contains the information about\r
                                  the Selection, form and formset to be displayed.\r
                                  Selection action may be updated in retrieve callback.\r
                                  If Selection is NULL, only initialize Question value.\r
@@ -4578,7 +5147,7 @@ LoadFormSetConfig (
 \r
   //\r
   // Finished question initialization.\r
-  // \r
+  //\r
   FormSet->QuestionInited = TRUE;\r
 \r
   return EFI_SUCCESS;\r
@@ -4614,20 +5183,20 @@ RemoveElement (
   DestStr = NewStr;\r
   NewStr += StrLen (RequestElement);\r
   CopyMem (DestStr, NewStr, StrSize (NewStr));\r
-  \r
-  Storage->SpareStrLen += StrLen (RequestElement);  \r
+\r
+  Storage->SpareStrLen += StrLen (RequestElement);\r
 }\r
 \r
 /**\r
   Adjust config request in storage, remove the request elements existed in the input ConfigRequest.\r
 \r
-  @param  Storage                Pointer to the browser storage.\r
+  @param  Storage                Pointer to the formset storage.\r
   @param  ConfigRequest          The pointer to the Request element.\r
 \r
 **/\r
 VOID\r
 RemoveConfigRequest (\r
-  BROWSER_STORAGE   *Storage,\r
+  FORMSET_STORAGE   *Storage,\r
   CHAR16            *ConfigRequest\r
   )\r
 {\r
@@ -4642,7 +5211,7 @@ RemoveConfigRequest (
     return;\r
   }\r
 \r
-  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+  if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
     //\r
     // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage\r
     //\r
@@ -4657,10 +5226,10 @@ RemoveConfigRequest (
   //\r
   // Find SearchKey storage\r
   //\r
-  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+  if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
     RequestElement = StrStr (ConfigRequest, L"PATH");\r
     ASSERT (RequestElement != NULL);\r
-    RequestElement = StrStr (RequestElement, SearchKey);    \r
+    RequestElement = StrStr (RequestElement, SearchKey);\r
   } else {\r
     RequestElement = StrStr (ConfigRequest, SearchKey);\r
   }\r
@@ -4681,7 +5250,7 @@ RemoveConfigRequest (
       *NextRequestElement = L'\0';\r
     }\r
 \r
-    RemoveElement (Storage, RequestElement);\r
+    RemoveElement (Storage->BrowserStorage, RequestElement);\r
 \r
     if (NextRequestElement != NULL) {\r
       //\r
@@ -4696,10 +5265,10 @@ RemoveConfigRequest (
   //\r
   // If no request element remain, just remove the ConfigRequest string.\r
   //\r
-  if (StrCmp (Storage->ConfigRequest, Storage->ConfigHdr) == 0) {\r
-    FreePool (Storage->ConfigRequest);\r
-    Storage->ConfigRequest = NULL;\r
-    Storage->SpareStrLen   = 0;\r
+  if (StrCmp (Storage->BrowserStorage->ConfigRequest, Storage->ConfigHdr) == 0) {\r
+    FreePool (Storage->BrowserStorage->ConfigRequest);\r
+    Storage->BrowserStorage->ConfigRequest = NULL;\r
+    Storage->BrowserStorage->SpareStrLen   = 0;\r
   }\r
 }\r
 \r
@@ -4727,10 +5296,10 @@ CleanBrowserStorage (
         continue;\r
       }\r
 \r
-      RemoveConfigRequest (Storage->BrowserStorage, Storage->ConfigRequest);\r
+      RemoveConfigRequest (Storage, Storage->ConfigRequest);\r
     } else if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_BUFFER ||\r
                Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
-      if (Storage->BrowserStorage->ConfigRequest != NULL) { \r
+      if (Storage->BrowserStorage->ConfigRequest != NULL) {\r
         FreePool (Storage->BrowserStorage->ConfigRequest);\r
         Storage->BrowserStorage->ConfigRequest = NULL;\r
       }\r
@@ -4749,7 +5318,7 @@ CleanBrowserStorage (
   @retval FALSE       The Element not in the configReqeust String.\r
 \r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 ElementValidation (\r
   BROWSER_STORAGE   *BrowserStorage,\r
   CHAR16            *RequestElement\r
@@ -4776,8 +5345,11 @@ AppendConfigRequest (
   CHAR16   *NewStr;\r
   UINTN    StringSize;\r
   UINTN    StrLength;\r
+  UINTN    MaxLen;\r
 \r
   StrLength = StrLen (RequestElement);\r
+  StringSize = (*ConfigRequest != NULL) ? StrSize (*ConfigRequest) : sizeof (CHAR16);\r
+  MaxLen = StringSize / sizeof (CHAR16) + *SpareStrLen;\r
 \r
   //\r
   // Append <RequestElement> to <ConfigRequest>\r
@@ -4786,8 +5358,8 @@ AppendConfigRequest (
     //\r
     // Old String buffer is not sufficient for RequestElement, allocate a new one\r
     //\r
-    StringSize = (*ConfigRequest != NULL) ? StrSize (*ConfigRequest) : sizeof (CHAR16);\r
-    NewStr = AllocateZeroPool (StringSize + CONFIG_REQUEST_STRING_INCREMENTAL * sizeof (CHAR16));\r
+    MaxLen = StringSize / sizeof (CHAR16) + CONFIG_REQUEST_STRING_INCREMENTAL;\r
+    NewStr = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
     ASSERT (NewStr != NULL);\r
 \r
     if (*ConfigRequest != NULL) {\r
@@ -4798,7 +5370,7 @@ AppendConfigRequest (
     *SpareStrLen   = CONFIG_REQUEST_STRING_INCREMENTAL;\r
   }\r
 \r
-  StrCat (*ConfigRequest, RequestElement);\r
+  StrCatS (*ConfigRequest, MaxLen, RequestElement);\r
   *SpareStrLen -= StrLength;\r
 }\r
 \r
@@ -4813,7 +5385,7 @@ AppendConfigRequest (
   @retval FALSE                  All elements covered by current used elements.\r
 \r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 ConfigRequestAdjust (\r
   IN  BROWSER_STORAGE         *Storage,\r
   IN  CHAR16                  *Request,\r
@@ -4823,13 +5395,11 @@ ConfigRequestAdjust (
   CHAR16       *RequestElement;\r
   CHAR16       *NextRequestElement;\r
   CHAR16       *NextElementBakup;\r
-  UINTN        SpareBufLen;\r
   CHAR16       *SearchKey;\r
   CHAR16       *ValueKey;\r
   BOOLEAN      RetVal;\r
   CHAR16       *ConfigRequest;\r
 \r
-  SpareBufLen    = 0;\r
   RetVal         = FALSE;\r
   NextElementBakup = NULL;\r
   ValueKey         = NULL;\r
@@ -4864,7 +5434,7 @@ ConfigRequestAdjust (
   if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
     RequestElement = StrStr (ConfigRequest, L"PATH");\r
     ASSERT (RequestElement != NULL);\r
-    RequestElement = StrStr (RequestElement, SearchKey);    \r
+    RequestElement = StrStr (RequestElement, SearchKey);\r
   } else {\r
     RequestElement = StrStr (ConfigRequest, SearchKey);\r
   }\r
@@ -4900,7 +5470,7 @@ ConfigRequestAdjust (
         *NextRequestElement = L'\0';\r
       }\r
     }\r
\r
+\r
     if (!ElementValidation (Storage, RequestElement)) {\r
       //\r
       // Add this element to the Storage->BrowserStorage->AllRequestElement.\r
@@ -4926,158 +5496,6 @@ ConfigRequestAdjust (
   return RetVal;\r
 }\r
 \r
-/**\r
-\r
-  Base on ConfigRequest info to get default value for current formset. \r
-\r
-  ConfigRequest info include the info about which questions in current formset need to \r
-  get default value. This function only get these questions default value.\r
-  \r
-  @param  FormSet                FormSet data structure.\r
-  @param  Storage                Storage need to update value.\r
-  @param  ConfigRequest          The config request string.\r
-\r
-**/\r
-VOID\r
-GetDefaultForFormset (\r
-  IN FORM_BROWSER_FORMSET    *FormSet,\r
-  IN BROWSER_STORAGE         *Storage,\r
-  IN CHAR16                  *ConfigRequest\r
-  )\r
-{\r
-  UINT8             *BackUpBuf;\r
-  UINTN             BufferSize;\r
-  LIST_ENTRY        BackUpList;\r
-  NAME_VALUE_NODE   *Node;\r
-  LIST_ENTRY        *Link;\r
-  LIST_ENTRY        *NodeLink;\r
-  NAME_VALUE_NODE   *TmpNode;\r
-  EFI_STATUS        Status;\r
-  EFI_STRING        Progress;\r
-  EFI_STRING        Result;\r
-\r
-  BackUpBuf = NULL;\r
-  InitializeListHead(&BackUpList);\r
-\r
-  //\r
-  // Back update the edit buffer.\r
-  // \r
-  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
-      (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) {\r
-    BackUpBuf = AllocateCopyPool (Storage->Size, Storage->EditBuffer);\r
-    ASSERT (BackUpBuf != NULL);\r
-  } else if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
-    Link = GetFirstNode (&Storage->NameValueListHead);\r
-    while (!IsNull (&Storage->NameValueListHead, Link)) {\r
-      Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
-      Link = GetNextNode (&Storage->NameValueListHead, Link);\r
-\r
-      //\r
-      // Only back Node belong to this formset.\r
-      //\r
-      if (StrStr (Storage->ConfigRequest, Node->Name) == NULL) {\r
-        continue;\r
-      }\r
-\r
-      TmpNode = AllocateCopyPool (sizeof (NAME_VALUE_NODE), Node);\r
-      ASSERT (TmpNode != NULL);\r
-      TmpNode->Name = AllocateCopyPool (StrSize(Node->Name) * sizeof (CHAR16), Node->Name);\r
-      ASSERT (TmpNode->Name != NULL);\r
-      TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue);\r
-      ASSERT (TmpNode->EditValue != NULL);\r
-\r
-      InsertTailList(&BackUpList, &TmpNode->Link);\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get default value.\r
-  //\r
-  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage, TRUE);\r
-\r
-  //\r
-  // Update the question value based on the input ConfigRequest.\r
-  //\r
-  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
-      (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) {\r
-    ASSERT (BackUpBuf != NULL);\r
-    BufferSize = Storage->Size;\r
-    Status = mHiiConfigRouting->BlockToConfig(\r
-                                  mHiiConfigRouting,\r
-                                  ConfigRequest,\r
-                                  Storage->EditBuffer,\r
-                                  BufferSize,\r
-                                  &Result,\r
-                                  &Progress\r
-                                  );\r
-    ASSERT_EFI_ERROR (Status);\r
-    \r
-    Status = mHiiConfigRouting->ConfigToBlock (\r
-                                  mHiiConfigRouting,\r
-                                  Result,\r
-                                  BackUpBuf,\r
-                                  &BufferSize,\r
-                                  &Progress\r
-                                  );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    if (Result != NULL) {\r
-      FreePool (Result);\r
-    }\r
-    \r
-    CopyMem (Storage->EditBuffer, BackUpBuf, Storage->Size);\r
-    FreePool (BackUpBuf);\r
-  } else if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
-    //\r
-    // Update question value, only element in ConfigReqeust will be update.\r
-    //\r
-    Link = GetFirstNode (&BackUpList);\r
-    while (!IsNull (&BackUpList, Link)) {\r
-      Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
-      Link = GetNextNode (&BackUpList, Link);\r
-\r
-      if (StrStr (ConfigRequest, Node->Name) != NULL) {\r
-        continue;\r
-      }\r
-\r
-      NodeLink = GetFirstNode (&Storage->NameValueListHead);\r
-      while (!IsNull (&Storage->NameValueListHead, NodeLink)) {\r
-        TmpNode  = NAME_VALUE_NODE_FROM_LINK (NodeLink);\r
-        NodeLink = GetNextNode (&Storage->NameValueListHead, NodeLink);\r
-      \r
-        if (StrCmp (Node->Name, TmpNode->Name) != 0) {\r
-          continue;\r
-        }\r
-\r
-        FreePool (TmpNode->EditValue);\r
-        TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue);\r
-\r
-        RemoveEntryList (&Node->Link);\r
-        FreePool (Node->EditValue);\r
-        FreePool (Node->Name);\r
-        FreePool (Node);\r
-      }\r
-    }\r
-\r
-    //\r
-    // Restore the Name/Value node.\r
-    //  \r
-    Link = GetFirstNode (&BackUpList);\r
-    while (!IsNull (&BackUpList, Link)) {\r
-      Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
-      Link = GetNextNode (&BackUpList, Link);\r
\r
-      //\r
-      // Free this node.\r
-      //\r
-      RemoveEntryList (&Node->Link);\r
-      FreePool (Node->EditValue);\r
-      FreePool (Node->Name);\r
-      FreePool (Node);\r
-    }\r
-  }\r
-}\r
-\r
 /**\r
   Fill storage's edit copy with settings requested from Configuration Driver.\r
 \r
@@ -5121,7 +5539,7 @@ LoadStorage (
       }\r
 \r
       //\r
-      // Just update the ConfigRequest, if storage already initialized. \r
+      // Just update the ConfigRequest, if storage already initialized.\r
       //\r
       if (Storage->BrowserStorage->Initialized) {\r
         ConfigRequestAdjust(Storage->BrowserStorage, Storage->ConfigRequest, FALSE);\r
@@ -5141,14 +5559,14 @@ LoadStorage (
     // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWW"followed by a Null-terminator\r
     //\r
-    StrLen = StrSize (Storage->BrowserStorage->ConfigHdr) + 20 * sizeof (CHAR16);\r
+    StrLen = StrSize (Storage->ConfigHdr) + 20 * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (StrLen);\r
     ASSERT (ConfigRequest != NULL);\r
     UnicodeSPrint (\r
-               ConfigRequest, \r
-               StrLen, \r
-               L"%s&OFFSET=0&WIDTH=%04x", \r
-               Storage->BrowserStorage->ConfigHdr,\r
+               ConfigRequest,\r
+               StrLen,\r
+               L"%s&OFFSET=0&WIDTH=%04x",\r
+               Storage->ConfigHdr,\r
                Storage->BrowserStorage->Size);\r
   } else {\r
     ConfigRequest = Storage->ConfigRequest;\r
@@ -5168,7 +5586,7 @@ LoadStorage (
   // If get value fail, extract default from IFR binary\r
   //\r
   if (EFI_ERROR (Status)) {\r
-    ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE);\r
+    ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE, TRUE);\r
   } else {\r
     //\r
     // Convert Result from <ConfigAltResp> to <ConfigResp>\r
@@ -5177,7 +5595,7 @@ LoadStorage (
     if (StrPtr != NULL) {\r
       *StrPtr = L'\0';\r
     }\r
-    \r
+\r
     Status = ConfigRespToStorage (Storage->BrowserStorage, Result);\r
     FreePool (Result);\r
   }\r
@@ -5185,7 +5603,7 @@ LoadStorage (
   Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), Storage->ConfigRequest);\r
 \r
   //\r
-  // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer. \r
+  // Input NULL for ConfigRequest field means sync all fields from editbuffer to buffer.\r
   //\r
   SynchronizeStorage(Storage->BrowserStorage, NULL, TRUE);\r
 \r
@@ -5313,8 +5731,8 @@ InitializeCurrentSetting (
 \r
   //\r
   // Extract default from IFR binary for no storage questions.\r
-  //  \r
-  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForNoStorage, NULL, TRUE);\r
+  //\r
+  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForNoStorage, NULL, TRUE, FALSE);\r
 \r
   //\r
   // Request current settings from Configuration Driver\r
@@ -5426,7 +5844,7 @@ GetIfrBinaryData (
           //\r
           // Try to compare against formset GUID\r
           //\r
-          if (CompareGuid (FormSetGuid, &gZeroGuid) || \r
+          if (IsZeroGuid (FormSetGuid) ||\r
               CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {\r
             break;\r
           }\r
@@ -5565,7 +5983,7 @@ InitializeFormSet (
 \r
 \r
 /**\r
-  Save globals used by previous call to SendForm(). SendForm() may be called from \r
+  Save globals used by previous call to SendForm(). SendForm() may be called from\r
   HiiConfigAccess.Callback(), this will cause SendForm() be reentried.\r
   So, save globals of previous call to SendForm() and restore them upon exit.\r
 \r
@@ -5575,8 +5993,9 @@ SaveBrowserContext (
   VOID\r
   )\r
 {\r
-  BROWSER_CONTEXT  *Context;\r
-  FORM_ENTRY_INFO     *MenuList;\r
+  BROWSER_CONTEXT      *Context;\r
+  FORM_ENTRY_INFO      *MenuList;\r
+  FORM_BROWSER_FORMSET *FormSet;\r
 \r
   gBrowserContextCount++;\r
   if (gBrowserContextCount == 1) {\r
@@ -5595,11 +6014,17 @@ SaveBrowserContext (
   // Save FormBrowser context\r
   //\r
   Context->Selection            = gCurrentSelection;\r
-  Context->ResetRequired        = gResetRequired;\r
+  Context->ResetRequired        = gResetRequiredFormLevel;\r
+  Context->FlagReconnect        = gFlagReconnect;\r
+  Context->CallbackReconnect    = gCallbackReconnect;\r
   Context->ExitRequired         = gExitRequired;\r
   Context->HiiHandle            = mCurrentHiiHandle;\r
   Context->FormId               = mCurrentFormId;\r
   CopyGuid (&Context->FormSetGuid, &mCurrentFormSetGuid);\r
+  Context->SystemLevelFormSet   = mSystemLevelFormSet;\r
+  Context->CurFakeQestId        = mCurFakeQestId;\r
+  Context->HiiPackageListUpdated = mHiiPackageListUpdated;\r
+  Context->FinishRetrieveCall   = mFinishRetrieveCall;\r
 \r
   //\r
   // Save the menu history data.\r
@@ -5612,6 +6037,17 @@ SaveBrowserContext (
     InsertTailList(&Context->FormHistoryList, &MenuList->Link);\r
   }\r
 \r
+  //\r
+  // Save formset list.\r
+  //\r
+  InitializeListHead(&Context->FormSetList);\r
+  while (!IsListEmpty (&gBrowserFormSetList)) {\r
+    FormSet = FORM_BROWSER_FORMSET_FROM_LINK (gBrowserFormSetList.ForwardLink);\r
+    RemoveEntryList (&FormSet->Link);\r
+\r
+    InsertTailList(&Context->FormSetList, &FormSet->Link);\r
+  }\r
+\r
   //\r
   // Insert to FormBrowser context list\r
   //\r
@@ -5630,7 +6066,8 @@ RestoreBrowserContext (
 {\r
   LIST_ENTRY       *Link;\r
   BROWSER_CONTEXT  *Context;\r
-  FORM_ENTRY_INFO     *MenuList;\r
+  FORM_ENTRY_INFO      *MenuList;\r
+  FORM_BROWSER_FORMSET *FormSet;\r
 \r
   ASSERT (gBrowserContextCount != 0);\r
   gBrowserContextCount--;\r
@@ -5650,11 +6087,17 @@ RestoreBrowserContext (
   // Restore FormBrowser context\r
   //\r
   gCurrentSelection     = Context->Selection;\r
-  gResetRequired        = Context->ResetRequired;\r
+  gResetRequiredFormLevel = Context->ResetRequired;\r
+  gFlagReconnect        = Context->FlagReconnect;\r
+  gCallbackReconnect    = Context->CallbackReconnect;\r
   gExitRequired         = Context->ExitRequired;\r
   mCurrentHiiHandle     = Context->HiiHandle;\r
   mCurrentFormId        = Context->FormId;\r
   CopyGuid (&mCurrentFormSetGuid, &Context->FormSetGuid);\r
+  mSystemLevelFormSet   = Context->SystemLevelFormSet;\r
+  mCurFakeQestId        = Context->CurFakeQestId;\r
+  mHiiPackageListUpdated = Context->HiiPackageListUpdated;\r
+  mFinishRetrieveCall   = Context->FinishRetrieveCall;\r
 \r
   //\r
   // Restore the menu history data.\r
@@ -5666,6 +6109,16 @@ RestoreBrowserContext (
     InsertTailList(&mPrivateData.FormBrowserEx2.FormViewHistoryHead, &MenuList->Link);\r
   }\r
 \r
+  //\r
+  // Restore the Formset data.\r
+  //\r
+  while (!IsListEmpty (&Context->FormSetList)) {\r
+    FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Context->FormSetList.ForwardLink);\r
+    RemoveEntryList (&FormSet->Link);\r
+\r
+    InsertTailList(&gBrowserFormSetList, &FormSet->Link);\r
+  }\r
+\r
   //\r
   // Remove from FormBrowser context list\r
   //\r
@@ -5675,13 +6128,13 @@ RestoreBrowserContext (
 \r
 /**\r
   Find the matched FormSet context in the backup maintain list based on HiiHandle.\r
-  \r
+\r
   @param Handle  The Hii Handle.\r
-  \r
+\r
   @return the found FormSet context. If no found, NULL will return.\r
 \r
 **/\r
-FORM_BROWSER_FORMSET * \r
+FORM_BROWSER_FORMSET *\r
 GetFormSetFromHiiHandle (\r
   EFI_HII_HANDLE Handle\r
   )\r
@@ -5700,15 +6153,15 @@ GetFormSetFromHiiHandle (
       return FormSet;\r
     }\r
   }\r
-  \r
+\r
   return NULL;\r
 }\r
 \r
 /**\r
   Check whether the input HII handle is the FormSet that is being used.\r
-  \r
+\r
   @param Handle  The Hii Handle.\r
-  \r
+\r
   @retval TRUE   HII handle is being used.\r
   @retval FALSE  HII handle is not being used.\r
 \r
@@ -5742,20 +6195,20 @@ IsHiiHandleInBrowserContext (
     }\r
     Link = GetNextNode (&gBrowserContextList, Link);\r
   }\r
-  \r
+\r
   return FALSE;\r
 }\r
 \r
 /**\r
-  Perform Password check. \r
+  Perform Password check.\r
   Passwork may be encrypted by driver that requires the specific check.\r
-  \r
+\r
   @param  Form             Form where Password Statement is in.\r
   @param  Statement        Password statement\r
   @param  PasswordString   Password string to be checked. It may be NULL.\r
                            NULL means to restore password.\r
                            "" string can be used to checked whether old password does exist.\r
-  \r
+\r
   @return Status     Status of Password check.\r
 **/\r
 EFI_STATUS\r
@@ -5781,31 +6234,12 @@ PasswordCheck (
       return EFI_UNSUPPORTED;\r
     }\r
   } else {\r
-    if (PasswordString == NULL) {\r
-      return EFI_SUCCESS;\r
-    } \r
-\r
-    //\r
-    // Check whether has preexisted password.\r
     //\r
-    if (PasswordString[0] == 0) {\r
-      if (*((CHAR16 *) Question->BufferValue) == 0) {\r
-        return EFI_SUCCESS;\r
-      } else {\r
-        return EFI_NOT_READY;\r
-      }\r
-    }\r
-\r
+    // If a password doesn't have the CALLBACK flag, browser will not handle it.\r
     //\r
-    // Check whether the input password is same as preexisted password.\r
-    //\r
-    if (StrnCmp (PasswordString, (CHAR16 *) Question->BufferValue, Question->StorageWidth/sizeof (CHAR16)) == 0) {\r
-      return EFI_SUCCESS;\r
-    } else {\r
-      return EFI_NOT_READY;\r
-    }\r
+    return EFI_UNSUPPORTED;\r
   }\r
-    \r
+\r
   //\r
   // Prepare password string in HII database\r
   //\r
@@ -5839,7 +6273,7 @@ PasswordCheck (
 \r
 /**\r
   Find the registered HotKey based on KeyData.\r
-  \r
+\r
   @param[in] KeyData     A pointer to a buffer that describes the keystroke\r
                          information for the hot key.\r
 \r
@@ -5861,7 +6295,7 @@ GetHotKeyFromRegisterList (
     }\r
     Link = GetNextNode (&gBrowserHotKeyList, Link);\r
   }\r
-  \r
+\r
   return NULL;\r
 }\r
 \r
@@ -5870,11 +6304,11 @@ GetHotKeyFromRegisterList (
   All hot keys have the same scope. The mixed hot keys with the different level are not supported.\r
   If no scope is set, the default scope will be FormSet level.\r
   After all registered hot keys are removed, previous Scope can reset to another level.\r
-  \r
-  @param[in] Scope               Scope level to be set. \r
-  \r
+\r
+  @param[in] Scope               Scope level to be set.\r
+\r
   @retval EFI_SUCCESS            Scope is set correctly.\r
-  @retval EFI_INVALID_PARAMETER  Scope is not the valid value specified in BROWSER_SETTING_SCOPE. \r
+  @retval EFI_INVALID_PARAMETER  Scope is not the valid value specified in BROWSER_SETTING_SCOPE.\r
   @retval EFI_UNSPPORTED         Scope level is different from current one that the registered hot keys have.\r
 \r
 **/\r
@@ -5907,19 +6341,20 @@ SetScope (
   Only support hot key that is not printable character (control key, function key, etc.).\r
   If the action value is zero, the hot key will be unregistered if it has been registered.\r
   If the same hot key has been registered, the new action and help string will override the previous ones.\r
-  \r
+\r
   @param[in] KeyData     A pointer to a buffer that describes the keystroke\r
-                         information for the hot key. Its type is EFI_INPUT_KEY to \r
+                         information for the hot key. Its type is EFI_INPUT_KEY to\r
                          be supported by all ConsoleIn devices.\r
-  @param[in] Action      Action value that describes what action will be trigged when the hot key is pressed. \r
+  @param[in] Action      Action value that describes what action will be trigged when the hot key is pressed.\r
   @param[in] DefaultId   Specifies the type of defaults to retrieve, which is only for DEFAULT action.\r
   @param[in] HelpString  Help string that describes the hot key information.\r
                          Its value may be NULL for the unregistered hot key.\r
-  \r
+\r
   @retval EFI_SUCCESS            Hot key is registered or unregistered.\r
   @retval EFI_INVALID_PARAMETER  KeyData is NULL or HelpString is NULL on register.\r
   @retval EFI_NOT_FOUND          KeyData is not found to be unregistered.\r
   @retval EFI_UNSUPPORTED        Key represents a printable character. It is conflicted with Browser.\r
+  @retval EFI_ALREADY_STARTED    Key already been registered for one hot key.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -5935,7 +6370,7 @@ RegisterHotKey (
   //\r
   // Check input parameters.\r
   //\r
-  if (KeyData == NULL || KeyData->UnicodeChar != CHAR_NULL || \r
+  if (KeyData == NULL || KeyData->UnicodeChar != CHAR_NULL ||\r
      (Action != BROWSER_ACTION_UNREGISTER && HelpString == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -5944,14 +6379,14 @@ RegisterHotKey (
   // Check whether the input KeyData is in BrowserHotKeyList.\r
   //\r
   HotKey = GetHotKeyFromRegisterList (KeyData);\r
-  \r
+\r
   //\r
   // Unregister HotKey\r
   //\r
   if (Action == BROWSER_ACTION_UNREGISTER) {\r
     if (HotKey != NULL) {\r
       //\r
-      // The registered HotKey is found.  \r
+      // The registered HotKey is found.\r
       // Remove it from List, and free its resource.\r
       //\r
       RemoveEntryList (&HotKey->Link);\r
@@ -5960,25 +6395,24 @@ RegisterHotKey (
       return EFI_SUCCESS;\r
     } else {\r
       //\r
-      // The registered HotKey is not found. \r
+      // The registered HotKey is not found.\r
       //\r
       return EFI_NOT_FOUND;\r
     }\r
   }\r
-  \r
+\r
+  if (HotKey != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
   //\r
-  // Register HotKey into List.\r
+  // Create new Key, and add it into List.\r
   //\r
-  if (HotKey == NULL) {\r
-    //\r
-    // Create new Key, and add it into List.\r
-    //\r
-    HotKey = AllocateZeroPool (sizeof (BROWSER_HOT_KEY));\r
-    ASSERT (HotKey != NULL);\r
-    HotKey->Signature = BROWSER_HOT_KEY_SIGNATURE;\r
-    HotKey->KeyData   = AllocateCopyPool (sizeof (EFI_INPUT_KEY), KeyData);\r
-    InsertTailList (&gBrowserHotKeyList, &HotKey->Link);\r
-  }\r
+  HotKey = AllocateZeroPool (sizeof (BROWSER_HOT_KEY));\r
+  ASSERT (HotKey != NULL);\r
+  HotKey->Signature = BROWSER_HOT_KEY_SIGNATURE;\r
+  HotKey->KeyData   = AllocateCopyPool (sizeof (EFI_INPUT_KEY), KeyData);\r
+  InsertTailList (&gBrowserHotKeyList, &HotKey->Link);\r
 \r
   //\r
   // Fill HotKey information.\r
@@ -5994,11 +6428,11 @@ RegisterHotKey (
 }\r
 \r
 /**\r
-  Register Exit handler function. \r
-  When more than one handler function is registered, the latter one will override the previous one. \r
-  When NULL handler is specified, the previous Exit handler will be unregistered. \r
-  \r
-  @param[in] Handler      Pointer to handler function. \r
+  Register Exit handler function.\r
+  When more than one handler function is registered, the latter one will override the previous one.\r
+  When NULL handler is specified, the previous Exit handler will be unregistered.\r
+\r
+  @param[in] Handler      Pointer to handler function.\r
 \r
 **/\r
 VOID\r
@@ -6070,7 +6504,7 @@ IsBrowserDataModified (
   @retval EFI_INVALID_PARAMETER    The input action value is invalid.\r
 \r
 **/\r
-EFI_STATUS \r
+EFI_STATUS\r
 EFIAPI\r
 ExecuteAction (\r
   IN UINT32        Action,\r
@@ -6090,7 +6524,7 @@ ExecuteAction (
   Form    = NULL;\r
   if (gBrowserSettingScope < SystemLevel) {\r
     FormSet = gCurrentSelection->FormSet;\r
-    Form    = gCurrentSelection->Form; \r
+    Form    = gCurrentSelection->Form;\r
   }\r
 \r
   //\r
@@ -6107,7 +6541,7 @@ ExecuteAction (
   // Executet the difault action.\r
   //\r
   if ((Action & BROWSER_ACTION_DEFAULT) != 0) {\r
-    Status = ExtractDefault (FormSet, Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE);\r
+    Status = ExtractDefault (FormSet, Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE, FALSE);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -6128,7 +6562,8 @@ ExecuteAction (
   // Executet the reset action.\r
   //\r
   if ((Action & BROWSER_ACTION_RESET) != 0) {\r
-    gResetRequired = TRUE;\r
+    gResetRequiredFormLevel = TRUE;\r
+    gResetRequiredSystemLevel = TRUE;\r
   }\r
 \r
   //\r
@@ -6184,16 +6619,16 @@ SaveReminder (
       break;\r
     }\r
   }\r
-  \r
+\r
   //\r
-  // No data is changed. No save is required. \r
+  // No data is changed. No save is required.\r
   //\r
   if (!IsDataChanged) {\r
     return DataSavedAction;\r
   }\r
-  \r
+\r
   //\r
-  // If data is changed, prompt user to save or discard it. \r
+  // If data is changed, prompt user to save or discard it.\r
   //\r
   do {\r
     ConfirmRet = (UINT32) mFormDisplay->ConfirmDataChange();\r
@@ -6228,6 +6663,6 @@ IsResetRequired (
   VOID\r
   )\r
 {\r
-  return gResetRequired;\r
+  return gResetRequiredSystemLevel;\r
 }\r
 \r