EFI_STATUS Status;\r
UINTN Index;\r
UINTN BufferSize;\r
+ UINTN PasswordMaxSize;\r
CHAR16 *Password;\r
CHAR16 *EncodedPassword;\r
BOOLEAN OldPassword;\r
}\r
\r
OldPassword = FALSE;\r
+ PasswordMaxSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);\r
//\r
// Check whether we have any old password set\r
//\r
- for (Index = 0; Index < 20; Index++) {\r
+ for (Index = 0; Index < PasswordMaxSize / sizeof (UINT16); Index++) {\r
if (PrivateData->Configuration.WhatIsThePassword2[Index] != 0) {\r
OldPassword = TRUE;\r
break;\r
if (Password == NULL) {\r
return EFI_NOT_READY;\r
}\r
- if (StrLen (Password) > 20) {\r
+ if (StrSize (Password) > PasswordMaxSize) {\r
FreePool (Password);\r
return EFI_NOT_READY;\r
}\r
//\r
// Validate old password\r
//\r
- EncodedPassword = AllocateZeroPool (21 * sizeof (CHAR16));\r
+ EncodedPassword = AllocateZeroPool (PasswordMaxSize);\r
ASSERT (EncodedPassword != NULL);\r
- StrnCpy (EncodedPassword, Password, 21);\r
- EncodePassword (EncodedPassword, 20 * sizeof (CHAR16));\r
- if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, 20 * sizeof (CHAR16)) != 0) {\r
+ StrnCpy (EncodedPassword, Password, StrLen (Password));\r
+ EncodePassword (EncodedPassword, StrLen (EncodedPassword) * sizeof (CHAR16));\r
+ if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, StrLen (EncodedPassword) * sizeof (CHAR16)) != 0) {\r
//\r
// Old password mismatch, return EFI_NOT_READY to prompt for error message\r
//\r
if (TempPassword == NULL) {\r
return EFI_NOT_READY;\r
}\r
- if (StrLen (TempPassword) > PasswordSize / sizeof (CHAR16)) {\r
+ if (StrSize (TempPassword) > PasswordSize) {\r
FreePool (TempPassword);\r
return EFI_NOT_READY;\r
}\r
- StrnCpy (Password, TempPassword, PasswordSize / sizeof (CHAR16));\r
+ StrnCpy (Password, TempPassword, StrLen (TempPassword));\r
FreePool (TempPassword);\r
\r
//\r
//\r
// Update password's clear text in the screen\r
//\r
- CopyMem (Configuration->PasswordClearText, Password, PasswordSize);\r
+ CopyMem (Configuration->PasswordClearText, Password, StrSize (Password));\r
\r
//\r
// Update uncommitted data of Browser\r
//\r
// Set password\r
//\r
- EncodePassword (Password, PasswordSize);\r
+ EncodePassword (Password, StrLen (Password) * 2);\r
Status = gRT->SetVariable(\r
VariableName,\r
&mFormSetGuid,\r
UINTN BufferSize;\r
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;\r
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
+ EFI_STRING ConfigRequestHdr;\r
+ EFI_STRING ConfigRequest;\r
+ UINTN Size;\r
+\r
+ //\r
+ // Initialize the local variables.\r
+ //\r
+ ConfigRequestHdr = NULL;\r
+ ConfigRequest = NULL;\r
+ Size = 0;\r
+ *Progress = Request;\r
\r
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
HiiConfigRouting = PrivateData->HiiConfigRouting;\r
\r
//\r
- //\r
- // Get Buffer Storage data from EFI variable\r
+ // Get Buffer Storage data from EFI variable.\r
+ // Try to get the current setting from variable.\r
//\r
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
- Status = gRT->GetVariable (\r
- VariableName,\r
- &mFormSetGuid,\r
- NULL,\r
- &BufferSize,\r
- &PrivateData->Configuration\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
+ gRT->GetVariable (\r
+ VariableName,\r
+ &mFormSetGuid,\r
+ NULL,\r
+ &BufferSize,\r
+ &PrivateData->Configuration\r
+ );\r
+ \r
if (Request == NULL) {\r
//\r
- // Request is set to NULL, return all configurable elements together with ALTCFG\r
+ // Request is set to NULL, construct full request string.\r
//\r
- *Results = HiiConstructConfigAltResp (\r
- &mFormSetGuid,\r
- VariableName,\r
- PrivateData->DriverHandle[0],\r
- &PrivateData->Configuration,\r
- BufferSize,\r
- VfrMyIfrNVDataBlockName,\r
- STRING_TOKEN (STR_STANDARD_DEFAULT_PROMPT),\r
- VfrMyIfrNVDataDefault0000,\r
- STRING_TOKEN (STR_MANUFACTURE_DEFAULT_PROMPT),\r
- VfrMyIfrNVDataDefault0001,\r
- 0,\r
- NULL\r
- );\r
- \r
+\r
//\r
- // No matched storage is found.\r
+ // First Set ConfigRequestHdr string.\r
//\r
- if (*Results == NULL) {\r
- return EFI_NOT_FOUND;\r
- }\r
+ ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
+ ASSERT (ConfigRequestHdr != NULL);\r
\r
- return EFI_SUCCESS;\r
+ //\r
+ // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r
+ // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
+ //\r
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
+ ConfigRequest = AllocateZeroPool (Size);\r
+ UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
+ FreePool (ConfigRequestHdr);\r
+ } else {\r
+ ConfigRequest = Request;\r
}\r
\r
//\r
// Check routing data in <ConfigHdr>.\r
// Note: if only one Storage is used, then this checking could be skipped.\r
//\r
- if (!HiiIsConfigHdrMatch (Request, &mFormSetGuid, VariableName)) {\r
- *Progress = Request;\r
+ if (!HiiIsConfigHdrMatch (ConfigRequest, &mFormSetGuid, VariableName)) {\r
+ if (Request == NULL) {\r
+ FreePool (ConfigRequest);\r
+ }\r
return EFI_NOT_FOUND;\r
}\r
\r
//\r
Status = HiiConfigRouting->BlockToConfig (\r
HiiConfigRouting,\r
- Request,\r
+ ConfigRequest,\r
(UINT8 *) &PrivateData->Configuration,\r
BufferSize,\r
Results,\r
Progress\r
);\r
+ \r
+ if (Request == NULL) {\r
+ FreePool (ConfigRequest);\r
+ }\r
+\r
return Status;\r
}\r
\r
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
HiiConfigRouting = PrivateData->HiiConfigRouting;\r
\r
+ //\r
// Check routing data in <ConfigHdr>.\r
// Note: if only one Storage is used, then this checking could be skipped.\r
//\r
// Get Buffer Storage data from EFI variable\r
//\r
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
- Status = gRT->GetVariable (\r
- VariableName,\r
- &mFormSetGuid,\r
- NULL,\r
- &BufferSize,\r
- &PrivateData->Configuration\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
+ gRT->GetVariable (\r
+ VariableName,\r
+ &mFormSetGuid,\r
+ NULL,\r
+ &BufferSize,\r
+ &PrivateData->Configuration\r
+ );\r
\r
//\r
// Convert <ConfigResp> to buffer data by helper function ConfigToBlock()\r
if ((Value == NULL) || (ActionRequest == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
+ \r
+ if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ \r
\r
Status = EFI_SUCCESS;\r
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
CHAR16 *NewString;\r
UINTN BufferSize;\r
DRIVER_SAMPLE_CONFIGURATION *Configuration;\r
- BOOLEAN ExtractIfrDefault;\r
+ BOOLEAN ActionFlag;\r
+ EFI_STRING ConfigRequestHdr; \r
\r
//\r
- // Initialize the library and our protocol.\r
+ // Initialize the local variables.\r
//\r
+ ConfigRequestHdr = NULL;\r
\r
//\r
// Initialize screen dimensions for SendForm().\r
//\r
// Try to read NV config EFI variable first\r
//\r
- ExtractIfrDefault = TRUE;\r
+ ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, DriverHandle[0]);\r
+ ASSERT (ConfigRequestHdr != NULL);\r
+\r
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
Status = gRT->GetVariable (VariableName, &mFormSetGuid, NULL, &BufferSize, Configuration);\r
- if (!EFI_ERROR (Status) && (BufferSize == sizeof (DRIVER_SAMPLE_CONFIGURATION))) {\r
- ExtractIfrDefault = FALSE;\r
- }\r
-\r
- if (ExtractIfrDefault) {\r
+ if (EFI_ERROR (Status)) {\r
//\r
// EFI variable for NV config doesn't exit, we should build this variable\r
// based on default values stored in IFR\r
//\r
- BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
- Status = HiiIfrLibExtractDefault (Configuration, &BufferSize, 1, VfrMyIfrNVDataDefault0000);\r
-\r
- if (!EFI_ERROR (Status)) {\r
- gRT->SetVariable(\r
- VariableName,\r
- &mFormSetGuid,\r
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
- sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
- Configuration\r
- );\r
- }\r
+ ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
+ ASSERT (ActionFlag);\r
+ } else {\r
+ //\r
+ // EFI variable does exist and Validate Current Setting\r
+ //\r
+ ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
+ ASSERT (ActionFlag);\r
}\r
+ \r
+ FreePool (ConfigRequestHdr);\r
+\r
\r
//\r
- // Default this driver is built into Flash device image, \r
+ // In default, this driver is built into Flash device image, \r
// the following code doesn't run.\r
//\r
\r
HiiRemovePackages (HiiHandle[1]);\r
}\r
\r
- return Status;\r
+ return EFI_SUCCESS;\r
}\r
\r
/**\r