Revision: 16162
          http://sourceforge.net/p/edk2/code/16162
Author:   ydong10
Date:     2014-09-23 08:06:23 +0000 (Tue, 23 Sep 2014)
Log Message:
-----------
Refine get default value process for browser. 
Before get default value for each questions, call ExtractConfig function to get 
the altcfg string for all formset. Later when question try to get default value 
from AltCfg string, just get the value from the saved altcfg string instead of 
call ExtractConfig function to get it.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <[email protected]>
Reviewed-by: Liming Gao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
    trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
    trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h

Modified: trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c        
2014-09-23 06:20:59 UTC (rev 16161)
+++ trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c        
2014-09-23 08:06:23 UTC (rev 16162)
@@ -586,7 +586,7 @@
     StrLen = UnicodeSPrint (
                RequestElement,
                30 * sizeof (CHAR16),
-               L"&OFFSET=%x&WIDTH=%x",
+               L"&OFFSET=%04x&WIDTH=%04x",
                Question->VarStoreInfo.VarOffset,
                Question->StorageWidth
                );

Modified: trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c   2014-09-23 
06:20:59 UTC (rev 16161)
+++ trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c   2014-09-23 
08:06:23 UTC (rev 16162)
@@ -1346,7 +1346,111 @@
   return Status;
 }
 
+/**
+  Convert the buffer value to HiiValue.
 
+  @param  Question               The question.
+  @param  Value                  Unicode buffer save the question value.
+
+  @retval  Status whether convert the value success.
+
+**/
+EFI_STATUS
+BufferToValue (
+  IN OUT FORM_BROWSER_STATEMENT           *Question,
+  IN     CHAR16                           *Value
+  )
+{
+  CHAR16                       *StringPtr;
+  BOOLEAN                      IsBufferStorage;
+  CHAR16                       *DstBuf;
+  CHAR16                       TempChar;
+  UINTN                        LengthStr;
+  UINT8                        *Dst;
+  CHAR16                       TemStr[5];
+  UINTN                        Index;
+  UINT8                        DigitUint8;
+  BOOLEAN                      IsString;
+  UINTN                        Length;
+  EFI_STATUS                   Status;
+
+  IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  
TRUE : FALSE);
+  if (Question->Storage->Type == EFI_HII_VARSTORE_BUFFER || 
+      Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {
+    IsBufferStorage = TRUE;
+  } else {
+    IsBufferStorage = FALSE;
+  }
+
+  //
+  // Question Value is provided by Buffer Storage or NameValue Storage
+  //
+  if (Question->BufferValue != NULL) {
+    //
+    // This Question is password or orderedlist
+    //
+    Dst = Question->BufferValue;
+  } else {
+    //
+    // Other type of Questions
+    //
+    Dst = (UINT8 *) &Question->HiiValue.Value;
+  }
+
+  //
+  // Temp cut at the end of this section, end with '\0' or '&'.
+  //
+  StringPtr = Value;
+  while (*StringPtr != L'\0' && *StringPtr != L'&') {
+    StringPtr++;
+  }
+  TempChar = *StringPtr;
+  *StringPtr = L'\0';
+
+  LengthStr = StrLen (Value);
+  Status    = EFI_SUCCESS;
+  if (!IsBufferStorage && IsString) {
+    //
+    // Convert Config String to Unicode String, e.g "0041004200430044" => 
"ABCD"
+    // Add string tail char L'\0' into Length
+    //
+    Length    = Question->StorageWidth + sizeof (CHAR16);
+    if (Length < ((LengthStr / 4 + 1) * 2)) {
+      Status = EFI_BUFFER_TOO_SMALL;
+    } else {
+      DstBuf = (CHAR16 *) Dst;
+      ZeroMem (TemStr, sizeof (TemStr));
+      for (Index = 0; Index < LengthStr; Index += 4) {
+        StrnCpy (TemStr, Value + Index, 4);
+        DstBuf[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
+      }
+      //
+      // Add tailing L'\0' character
+      //
+      DstBuf[Index/4] = L'\0';
+    }
+  } else {
+    if (Question->StorageWidth < ((LengthStr + 1) / 2)) {
+      Status = EFI_BUFFER_TOO_SMALL;
+    } else {
+      ZeroMem (TemStr, sizeof (TemStr));
+      for (Index = 0; Index < LengthStr; Index ++) {
+        TemStr[0] = Value[LengthStr - Index - 1];
+        DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
+        if ((Index & 1) == 0) {
+          Dst [Index/2] = DigitUint8;
+        } else {
+          Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
+        }
+      }
+    }
+  }
+
+  *StringPtr = TempChar;
+
+  return Status;
+}
+
 /**
   Get Question's current Value.
 
@@ -1378,14 +1482,8 @@
   CHAR16              *Progress;
   CHAR16              *Result;
   CHAR16              *Value;
-  CHAR16              *StringPtr;
   UINTN               Length;
-  UINTN               Index;
-  UINTN               LengthStr;
   BOOLEAN             IsBufferStorage;
-  BOOLEAN             IsString;
-  CHAR16              TemStr[5];
-  UINT8               DigitUint8;
 
   Status = EFI_SUCCESS;
   Value  = NULL;
@@ -1538,7 +1636,6 @@
   } else {
     IsBufferStorage = FALSE;
   }
-  IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  
TRUE : FALSE);
   if (GetValueFrom == GetSetValueWithEditBuffer || GetValueFrom == 
GetSetValueWithBuffer ) {
     if (IsBufferStorage) {
       if (GetValueFrom == GetSetValueWithEditBuffer) {
@@ -1560,45 +1657,7 @@
       }
 
       ASSERT (Value != NULL);
-      LengthStr = StrLen (Value);
-      Status    = EFI_SUCCESS;
-      if (IsString) {
-        //
-        // Convert Config String to Unicode String, e.g "0041004200430044" => 
"ABCD"
-        // Add string tail char L'\0' into Length
-        //
-        Length    = StorageWidth + sizeof (CHAR16);
-        if (Length < ((LengthStr / 4 + 1) * 2)) {
-          Status = EFI_BUFFER_TOO_SMALL;
-        } else {
-          StringPtr = (CHAR16 *) Dst;
-          ZeroMem (TemStr, sizeof (TemStr));
-          for (Index = 0; Index < LengthStr; Index += 4) {
-            StrnCpy (TemStr, Value + Index, 4);
-            StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
-          }
-          //
-          // Add tailing L'\0' character
-          //
-          StringPtr[Index/4] = L'\0';
-        }
-      } else {
-        if (StorageWidth < ((LengthStr + 1) / 2)) {
-          Status = EFI_BUFFER_TOO_SMALL;
-        } else {
-          ZeroMem (TemStr, sizeof (TemStr));
-          for (Index = 0; Index < LengthStr; Index ++) {
-            TemStr[0] = Value[LengthStr - Index - 1];
-            DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
-            if ((Index & 1) == 0) {
-              Dst [Index/2] = DigitUint8;
-            } else {
-              Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
-            }
-          }
-        }
-      }
-
+      Status = BufferToValue (Question, Value);
       FreePool (Value);
     }
   } else {
@@ -1663,54 +1722,7 @@
     //
     Value = Value + 1;
 
-    //
-    // Suppress <AltResp> if any
-    //
-    StringPtr = Value;
-    while (*StringPtr != L'\0' && *StringPtr != L'&') {
-      StringPtr++;
-    }
-    *StringPtr = L'\0';
-
-    LengthStr = StrLen (Value);
-    Status    = EFI_SUCCESS;
-    if (!IsBufferStorage && IsString) {
-      //
-      // Convert Config String to Unicode String, e.g "0041004200430044" => 
"ABCD"
-      // Add string tail char L'\0' into Length
-      //
-      Length    = StorageWidth + sizeof (CHAR16);
-      if (Length < ((LengthStr / 4 + 1) * 2)) {
-        Status = EFI_BUFFER_TOO_SMALL;
-      } else {
-        StringPtr = (CHAR16 *) Dst;
-        ZeroMem (TemStr, sizeof (TemStr));
-        for (Index = 0; Index < LengthStr; Index += 4) {
-          StrnCpy (TemStr, Value + Index, 4);
-          StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
-        }
-        //
-        // Add tailing L'\0' character
-        //
-        StringPtr[Index/4] = L'\0';
-      }
-    } else {
-      if (StorageWidth < ((LengthStr + 1) / 2)) {
-        Status = EFI_BUFFER_TOO_SMALL;
-      } else {
-        ZeroMem (TemStr, sizeof (TemStr));
-        for (Index = 0; Index < LengthStr; Index ++) {
-          TemStr[0] = Value[LengthStr - Index - 1];
-          DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
-          if ((Index & 1) == 0) {
-            Dst [Index/2] = DigitUint8;
-          } else {
-            Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
-          }
-        }
-      }
-    }
-
+    Status = BufferToValue (Question, Value);
     if (EFI_ERROR (Status)) {
       FreePool (Result);
       return Status;
@@ -3373,205 +3385,173 @@
 }
 
 /**
-  Get Question default value from AltCfg string.
+  Converts the unicode character of the string from uppercase to lowercase.
+  This is a internal function.
 
-  @param  FormSet                The form set.
-  @param  Question               The question.
-  @param  DefaultId              The default Id.
+  @param ConfigString  String to be converted
 
-  @retval EFI_SUCCESS            Question is reset to default value.
-
 **/
-EFI_STATUS
-GetDefaultValueFromAltCfg (
-  IN     FORM_BROWSER_FORMSET             *FormSet,
-  IN OUT FORM_BROWSER_STATEMENT           *Question,
-  IN     UINT16                           DefaultId
+VOID
+EFIAPI
+HiiToLower (
+  IN EFI_STRING  ConfigString
   )
 {
-  BOOLEAN             IsBufferStorage;
-  BOOLEAN             IsString;  
-  UINTN               Length;
-  BROWSER_STORAGE     *Storage;
-  CHAR16              *ConfigRequest;
-  CHAR16              *Progress;
-  CHAR16              *Result;
-  CHAR16              *ConfigResp;
-  CHAR16              *Value;
-  CHAR16              *StringPtr;
-  UINTN               LengthStr;
-  UINT8               *Dst;
-  CHAR16              TemStr[5];
-  UINTN               Index;
-  UINT8               DigitUint8;
-  EFI_STATUS          Status;
+  EFI_STRING  String;
+  BOOLEAN     Lower;
 
-  Status        = EFI_NOT_FOUND;
-  Length        = 0;
-  Dst           = NULL;
-  ConfigRequest = NULL;
-  Result        = NULL;
-  ConfigResp    = NULL;
-  Value         = NULL;
-  Storage       = Question->Storage;
+  ASSERT (ConfigString != NULL);
 
-  if ((Storage == NULL) || (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) {
-    return Status;
-  }
-
   //
-  // Question Value is provided by Buffer Storage or NameValue Storage
+  // Convert all hex digits in range [A-F] in the configuration header to [a-f]
   //
-  if (Question->BufferValue != NULL) {
-    //
-    // This Question is password or orderedlist
-    //
-    Dst = Question->BufferValue;
-  } else {
-    //
-    // Other type of Questions
-    //
-    Dst = (UINT8 *) &Question->HiiValue.Value;
+  for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) {
+    if (*String == L'=') {
+      Lower = TRUE;
+    } else if (*String == L'&') {
+      Lower = FALSE;
+    } else if (Lower && *String >= L'A' && *String <= L'F') {
+      *String = (CHAR16) (*String - L'A' + L'a');
+    }
   }
+}
 
-  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == 
EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {
-    IsBufferStorage = TRUE;
-  } else {
-    IsBufferStorage = FALSE;
-  }
-  IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  
TRUE : FALSE);
+/**
+  Find the point in the ConfigResp string for this question.
 
+  @param  Question               The question.
+  @param  ConfigResp             Get ConfigResp string.
+
+  @retval  point to the offset where is for this question.
+
+**/
+CHAR16 *
+GetOffsetFromConfigResp (
+  IN FORM_BROWSER_STATEMENT           *Question,
+  IN CHAR16                           *ConfigResp
+  )
+{
+  CHAR16                       *RequestElement;
+  CHAR16                       *BlockData;
+
   //
-  // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
-  //                   <ConfigHdr> + "&" + <VariableName>
+  // Type is EFI_HII_VARSTORE_NAME_VALUE.
   //
-  if (IsBufferStorage) {
-    Length  = StrLen (Storage->ConfigHdr);
-    Length += StrLen (Question->BlockName);
-  } else {
-    Length  = StrLen (Storage->ConfigHdr);
-    Length += StrLen (Question->VariableName) + 1;
-  }
-  ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
-  ASSERT (ConfigRequest != NULL);
+  if (Question->Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {
+    RequestElement = StrStr (ConfigResp, Question->VariableName);
+    if (RequestElement != NULL) {
+      //
+      // Skip the "VariableName=" field.
+      //
+      RequestElement += StrLen (Question->VariableName) + 1;
+    }
 
-  StrCpy (ConfigRequest, Storage->ConfigHdr);
-  if (IsBufferStorage) {
-    StrCat (ConfigRequest, Question->BlockName);
-  } else {
-    StrCat (ConfigRequest, L"&");
-    StrCat (ConfigRequest, Question->VariableName);
+    return RequestElement;
   }
 
-  Status = mHiiConfigRouting->ExtractConfig (
-                                    mHiiConfigRouting,
-                                    ConfigRequest,
-                                    &Progress,
-                                    &Result
-                                    );
-  if (EFI_ERROR (Status)) {
-    goto Done;
-  }
+  //
+  // Type is EFI_HII_VARSTORE_EFI_VARIABLE or 
EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
+  //
 
   //
-  // Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, 
DevicePath, AltCfgId, AltCfgResp)
-  //    Get the default configuration string according to the default ID.
+  // 1. Directly use Question->BlockName to find.
   //
-  Status = mHiiConfigRouting->GetAltConfig (
-                                mHiiConfigRouting,
-                                Result,
-                                &Storage->Guid,
-                                Storage->Name,
-                                NULL,
-                                &DefaultId,  // it can be NULL to get the 
current setting.
-                                &ConfigResp
-                              );
+  RequestElement = StrStr (ConfigResp, Question->BlockName);
+  if (RequestElement != NULL) {
+    //
+    // Skip the "Question->BlockName&VALUE=" field.
+    //
+    RequestElement += StrLen (Question->BlockName) + StrLen (L"&VALUE=");
+    return RequestElement;
+  }
   
   //
-  // The required setting can't be found. So, it is not required to be 
validated and set.
+  // 2. Change all hex digits in Question->BlockName to lower and compare 
again.
   //
-  if (EFI_ERROR (Status)) {
-    goto Done;
-  }
+  BlockData = AllocateCopyPool (StrSize(Question->BlockName), 
Question->BlockName);
+  ASSERT (BlockData != NULL);
+  HiiToLower (BlockData);
+  RequestElement = StrStr (ConfigResp, BlockData);
+  FreePool (BlockData);
 
-  if (ConfigResp == NULL) {
-    Status = EFI_NOT_FOUND;
-    goto Done;
-  }
-
-  //
-  // Skip <ConfigRequest>
-  //
-  if (IsBufferStorage) {
-    Value = StrStr (ConfigResp, L"&VALUE");
-    ASSERT (Value != NULL);
+  if (RequestElement != NULL) {
     //
-    // Skip "&VALUE"
+    // Skip the "Question->BlockName&VALUE=" field.
     //
-    Value = Value + 6;
-  } else {
-    Value = StrStr (ConfigResp, Question->VariableName);
-    ASSERT (Value != NULL);
+    RequestElement += StrLen (Question->BlockName) + StrLen (L"&VALUE=");
+  }
 
-    Value = Value + StrLen (Question->VariableName);
+  return RequestElement;
+}
+
+/**
+  Get Question default value from AltCfg string.
+
+  @param  FormSet                The form set.
+  @param  Form                   The form
+  @param  Question               The question.
+
+  @retval EFI_SUCCESS            Question is reset to default value.
+
+**/
+EFI_STATUS
+GetDefaultValueFromAltCfg (
+  IN     FORM_BROWSER_FORMSET             *FormSet,
+  IN     FORM_BROWSER_FORM                *Form,
+  IN OUT FORM_BROWSER_STATEMENT           *Question
+  )
+{ 
+  BROWSER_STORAGE              *Storage;
+  FORMSET_STORAGE              *FormSetStorage;
+  CHAR16                       *ConfigResp;
+  CHAR16                       *Value;
+  LIST_ENTRY                   *Link;
+  FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;
+
+  Storage = Question->Storage;
+  if ((Storage == NULL) || (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) {
+    return EFI_NOT_FOUND;
   }
-  if (*Value != '=') {
-    Status = EFI_NOT_FOUND;
-    goto Done;
-  }
+
   //
-  // Skip '=', point to value
+  // Try to get AltCfg string from form. If not found it, then
+  // try to get it from formset.
   //
-  Value = Value + 1;
+  ConfigResp    = NULL;
+  Link = GetFirstNode (&Form->ConfigRequestHead);
+  while (!IsNull (&Form->ConfigRequestHead, Link)) {
+    ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);
+    Link = GetNextNode (&Form->ConfigRequestHead, Link);
 
-  //
-  // Suppress <AltResp> if any
-  //
-  StringPtr = Value;
-  while (*StringPtr != L'\0' && *StringPtr != L'&') {
-    StringPtr++;
+    if (Storage == ConfigInfo->Storage) {
+      ConfigResp = ConfigInfo->ConfigAltResp;
+      break;
+    }
   }
-  *StringPtr = L'\0';
 
-  LengthStr = StrLen (Value);
-  if (!IsBufferStorage && IsString) {
-    StringPtr = (CHAR16 *) Dst;
-    ZeroMem (TemStr, sizeof (TemStr));
-    for (Index = 0; Index < LengthStr; Index += 4) {
-      StrnCpy (TemStr, Value + Index, 4);
-      StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
-    }
-    //
-    // Add tailing L'\0' character
-    //
-    StringPtr[Index/4] = L'\0';
-  } else {
-    ZeroMem (TemStr, sizeof (TemStr));
-    for (Index = 0; Index < LengthStr; Index ++) {
-      TemStr[0] = Value[LengthStr - Index - 1];
-      DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
-      if ((Index & 1) == 0) {
-        Dst [Index/2] = DigitUint8;
-      } else {
-        Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
+  if (ConfigResp == NULL) {
+    Link = GetFirstNode (&FormSet->StorageListHead);
+    while (!IsNull (&FormSet->StorageListHead, Link)) {
+      FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link);
+      Link = GetNextNode (&FormSet->StorageListHead, Link);
+
+      if (Storage == FormSetStorage->BrowserStorage) {
+        ConfigResp = FormSetStorage->ConfigAltResp;
+        break;
       }
     }
   }
 
-Done:
-  if (ConfigRequest != NULL){
-    FreePool (ConfigRequest);
+  if (ConfigResp == NULL) {
+    return EFI_NOT_FOUND;
   }
 
-  if (ConfigResp != NULL) {
-    FreePool (ConfigResp);
+  Value = GetOffsetFromConfigResp (Question, ConfigResp);
+  if (Value == NULL) {
+    return EFI_NOT_FOUND;
   }
-  
-  if (Result != NULL) {
-    FreePool (Result);
-  }
 
-  return Status;
+  return BufferToValue (Question, Value);
 }
 
 /**
@@ -3824,7 +3804,7 @@
   // Get default value from altcfg string.
   //
   if (ConfigAccess != NULL) {  
-    Status = GetDefaultValueFromAltCfg(FormSet, Question, DefaultId);
+    Status = GetDefaultValueFromAltCfg(FormSet, Form, Question);
     if (!EFI_ERROR (Status)) {
         return Status;
     }
@@ -4005,8 +3985,230 @@
   return Status;
 }
 
+/**
+  Get AltCfg string for current form.
 
+  @param  FormSet                Form data structure.
+  @param  Form                   Form data structure.
+  @param  DefaultId              The Class of the default.
+
+**/
+VOID
+ExtractAltCfgForForm (
+  IN FORM_BROWSER_FORMSET   *FormSet,
+  IN FORM_BROWSER_FORM      *Form,
+  IN UINT16                 DefaultId
+  )
+{
+  EFI_STATUS                   Status;
+  LIST_ENTRY                   *Link;
+  CHAR16                       *ConfigResp;
+  CHAR16                       *Progress;
+  CHAR16                       *Result;
+  BROWSER_STORAGE              *Storage;
+  FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;
+  FORMSET_STORAGE              *FormSetStorage;
+
+  //
+  // Check whether has get AltCfg string for this formset.
+  // If yes, no need to get AltCfg for form.
+  //
+  Link = GetFirstNode (&FormSet->StorageListHead);
+  while (!IsNull (&FormSet->StorageListHead, Link)) {
+    FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link);
+    Storage        = FormSetStorage->BrowserStorage;
+    Link = GetNextNode (&FormSet->StorageListHead, Link);
+
+    if (Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE &&
+        FormSetStorage->ElementCount != 0 &&
+        FormSetStorage->ConfigAltResp != NULL) {
+      return;
+    }
+  }
+
+  //
+  // Get AltCfg string for each form.
+  //
+  Link = GetFirstNode (&Form->ConfigRequestHead);
+  while (!IsNull (&Form->ConfigRequestHead, Link)) {
+    ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);
+    Link = GetNextNode (&Form->ConfigRequestHead, Link);
+
+    Storage = ConfigInfo->Storage;
+    if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
+      continue;
+    }
+
+    //
+    // 1. Skip if there is no RequestElement
+    //
+    if (ConfigInfo->ElementCount == 0) {
+      continue;
+    }
+
+    //
+    // 2. Get value through hii config routine protocol.
+    //
+    Status = mHiiConfigRouting->ExtractConfig (
+                                      mHiiConfigRouting,
+                                      ConfigInfo->ConfigRequest,
+                                      &Progress,
+                                      &Result
+                                      );
+    if (EFI_ERROR (Status)) {
+      continue;
+    }
+
+    //
+    // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, 
Name, DevicePath, AltCfgId, AltCfgResp)
+    //    Get the default configuration string according to the default ID.
+    //
+    Status = mHiiConfigRouting->GetAltConfig (
+                                  mHiiConfigRouting,
+                                  Result,
+                                  &Storage->Guid,
+                                  Storage->Name,
+                                  NULL,
+                                  &DefaultId,  // it can be NULL to get the 
current setting.
+                                  &ConfigResp
+                                );
+    FreePool (Result);
+    if (EFI_ERROR (Status)) {
+      continue;
+    }
+
+    ConfigInfo->ConfigAltResp = ConfigResp;
+  }
+}
+
 /**
+  Clean AltCfg string for current form.
+
+  @param  Form                   Form data structure.
+
+**/
+VOID
+CleanAltCfgForForm (
+  IN FORM_BROWSER_FORM   *Form
+  )
+{
+  LIST_ENTRY              *Link;
+  FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;
+
+  Link = GetFirstNode (&Form->ConfigRequestHead);
+  while (!IsNull (&Form->ConfigRequestHead, Link)) {
+    ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);
+    Link = GetNextNode (&Form->ConfigRequestHead, Link);
+
+    if (ConfigInfo->ConfigAltResp != NULL) {
+      FreePool (ConfigInfo->ConfigAltResp);
+      ConfigInfo->ConfigAltResp = NULL;
+    }
+  }
+}
+
+/**
+  Get AltCfg string for current formset.
+
+  @param  FormSet                Form data structure.
+  @param  DefaultId              The Class of the default.
+
+**/
+VOID
+ExtractAltCfgForFormSet (
+  IN FORM_BROWSER_FORMSET   *FormSet,
+  IN UINT16                 DefaultId
+  )
+{
+  EFI_STATUS              Status;
+  LIST_ENTRY              *Link;
+  CHAR16                  *ConfigResp;
+  CHAR16                  *Progress;
+  CHAR16                  *Result;
+  BROWSER_STORAGE         *Storage;
+  FORMSET_STORAGE         *FormSetStorage;
+
+  Link = GetFirstNode (&FormSet->StorageListHead);
+  while (!IsNull (&FormSet->StorageListHead, Link)) {
+    FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link);
+    Storage        = FormSetStorage->BrowserStorage;
+    Link = GetNextNode (&FormSet->StorageListHead, Link);
+
+    if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
+      continue;
+    }
+
+    //
+    // 1. Skip if there is no RequestElement
+    //
+    if (FormSetStorage->ElementCount == 0) {
+      continue;
+    }
+
+    //
+    // 2. Get value through hii config routine protocol.
+    //
+    Status = mHiiConfigRouting->ExtractConfig (
+                                      mHiiConfigRouting,
+                                      FormSetStorage->ConfigRequest,
+                                      &Progress,
+                                      &Result
+                                      );
+    if (EFI_ERROR (Status)) {
+      continue;
+    }
+
+    //
+    // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, 
Name, DevicePath, AltCfgId, AltCfgResp)
+    //    Get the default configuration string according to the default ID.
+    //
+    Status = mHiiConfigRouting->GetAltConfig (
+                                  mHiiConfigRouting,
+                                  Result,
+                                  &Storage->Guid,
+                                  Storage->Name,
+                                  NULL,
+                                  &DefaultId,  // it can be NULL to get the 
current setting.
+                                  &ConfigResp
+                                );
+
+    FreePool (Result);
+    if (EFI_ERROR (Status)) {
+      continue;
+    }
+
+    FormSetStorage->ConfigAltResp = ConfigResp;
+  }
+
+}
+
+/**
+  Clean AltCfg string for current formset.
+
+  @param  FormSet                Form data structure.
+
+**/
+VOID
+CleanAltCfgForFormSet (
+  IN FORM_BROWSER_FORMSET   *FormSet
+  )
+{
+  LIST_ENTRY              *Link;
+  FORMSET_STORAGE         *FormSetStorage;
+
+  Link = GetFirstNode (&FormSet->StorageListHead);
+  while (!IsNull (&FormSet->StorageListHead, Link)) {
+    FormSetStorage = FORMSET_STORAGE_FROM_LINK (Link);
+    Link = GetNextNode (&FormSet->StorageListHead, Link);
+
+    if (FormSetStorage->ConfigAltResp != NULL) {
+      FreePool (FormSetStorage->ConfigAltResp);
+      FormSetStorage->ConfigAltResp = NULL;
+    }
+  }
+}
+
+/**
   Reset Questions to their initial value or default value in a Form, Formset 
or System.
 
   GetDefaultValueScope parameter decides which questions will reset 
@@ -4056,9 +4258,14 @@
   if (GetDefaultValueScope == GetDefaultForStorage && Storage == NULL) {
     return EFI_UNSUPPORTED;
   }
-  
+
   if (SettingScope == FormLevel) {
     //
+    // Prepare the AltCfg String for form.
+    //
+    ExtractAltCfgForForm (FormSet, Form, DefaultId);
+
+    //
     // Extract Form default
     //
     Link = GetFirstNode (&Form->StatementListHead);
@@ -4114,13 +4321,28 @@
         SetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer);
       }
     }
+
+    //
+    // Clean the AltCfg String.
+    //
+    CleanAltCfgForForm(Form);
   } else if (SettingScope == FormSetLevel) {
+    //
+    // Prepare the AltCfg String for formset.
+    //
+    ExtractAltCfgForFormSet (FormSet, DefaultId);
+
     FormLink = GetFirstNode (&FormSet->FormListHead);
     while (!IsNull (&FormSet->FormListHead, FormLink)) {
       Form = FORM_BROWSER_FORM_FROM_LINK (FormLink);
       ExtractDefault (FormSet, Form, DefaultId, FormLevel, 
GetDefaultValueScope, Storage, RetrieveValueFirst);
       FormLink = GetNextNode (&FormSet->FormListHead, FormLink);
     }
+
+    //
+    // Clean the AltCfg String.
+    //
+    CleanAltCfgForFormSet (FormSet);
   } else if (SettingScope == SystemLevel) {
     //
     // Preload all Hii formset.

Modified: trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h   2014-09-23 
06:20:59 UTC (rev 16161)
+++ trunk/edk2/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h   2014-09-23 
08:06:23 UTC (rev 16162)
@@ -171,6 +171,7 @@
   BROWSER_STORAGE  *BrowserStorage;
 
   CHAR16           *ConfigRequest; // <ConfigRequest> = <ConfigHdr> + 
<RequestElement>
+  CHAR16           *ConfigAltResp; // Alt config response string for this 
ConfigRequest.
   UINTN            ElementCount;   // Number of <RequestElement> in the 
<ConfigRequest>
   UINTN            SpareStrLen;    // Spare length of ConfigRequest string 
buffer
 } FORMSET_STORAGE;
@@ -379,6 +380,7 @@
   LIST_ENTRY            SaveFailLink;
 
   CHAR16                *ConfigRequest; // <ConfigRequest> = <ConfigHdr> + 
<RequestElement>
+  CHAR16                *ConfigAltResp; // Alt config response string for this 
ConfigRequest.
   UINTN                 ElementCount;   // Number of <RequestElement> in the 
<ConfigRequest>  
   UINTN                 SpareStrLen;
 


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to