Implementation for handling the User Interface option processing.\r
\r
\r
-Copyright (c) 2004 - 2012, 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) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
Concatenate a narrow string to another string.\r
\r
@param Destination The destination string.\r
+ @param DestMax The Max length of destination string.\r
@param Source The source string. The string to be concatenated.\r
to the end of Destination.\r
\r
VOID\r
NewStrCat (\r
IN OUT CHAR16 *Destination,\r
+ IN UINTN DestMax,\r
IN CHAR16 *Source\r
)\r
{\r
Destination[Length] = NARROW_CHAR;\r
Length++;\r
\r
- StrCpy (Destination + Length, Source);\r
+ StrCpyS (Destination + Length, DestMax - Length, Source);\r
}\r
\r
/**\r
return RetVal;\r
}\r
\r
+/**\r
+ Check whether this value type can be transfer to EFI_IFR_TYPE_BUFFER type.\r
+\r
+ EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
+ EFI_IFR_TYPE_BUFFER when do the value compare.\r
+\r
+ @param Value Expression value to compare on.\r
+\r
+ @retval TRUE This value type can be transter to EFI_IFR_TYPE_BUFFER type.\r
+ @retval FALSE This value type can't be transter to EFI_IFR_TYPE_BUFFER type.\r
+\r
+**/\r
+BOOLEAN\r
+IsTypeInBuffer (\r
+ IN EFI_HII_VALUE *Value\r
+ )\r
+{\r
+ switch (Value->Type) {\r
+ case EFI_IFR_TYPE_BUFFER:\r
+ case EFI_IFR_TYPE_DATE:\r
+ case EFI_IFR_TYPE_TIME:\r
+ case EFI_IFR_TYPE_REF:\r
+ return TRUE;\r
+\r
+ default:\r
+ return FALSE;\r
+ }\r
+}\r
+\r
+/**\r
+ Check whether this value type can be transfer to EFI_IFR_TYPE_UINT64\r
+\r
+ @param Value Expression value to compare on.\r
+\r
+ @retval TRUE This value type can be transter to EFI_IFR_TYPE_BUFFER type.\r
+ @retval FALSE This value type can't be transter to EFI_IFR_TYPE_BUFFER type.\r
+\r
+**/\r
+BOOLEAN\r
+IsTypeInUINT64 (\r
+ IN EFI_HII_VALUE *Value\r
+ )\r
+{\r
+ switch (Value->Type) {\r
+ case EFI_IFR_TYPE_NUM_SIZE_8:\r
+ case EFI_IFR_TYPE_NUM_SIZE_16:\r
+ case EFI_IFR_TYPE_NUM_SIZE_32:\r
+ case EFI_IFR_TYPE_NUM_SIZE_64:\r
+ case EFI_IFR_TYPE_BOOLEAN:\r
+ return TRUE;\r
+\r
+ default:\r
+ return FALSE;\r
+ }\r
+}\r
+\r
+/**\r
+ Return the buffer length and buffer pointer for this value.\r
+\r
+ EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
+ EFI_IFR_TYPE_BUFFER when do the value compare.\r
+\r
+ @param Value Expression value to compare on.\r
+ @param Buf Return the buffer pointer.\r
+ @param BufLen Return the buffer length.\r
+\r
+**/\r
+VOID\r
+GetBufAndLenForValue (\r
+ IN EFI_HII_VALUE *Value,\r
+ OUT UINT8 **Buf,\r
+ OUT UINT16 *BufLen\r
+ )\r
+{\r
+ switch (Value->Type) {\r
+ case EFI_IFR_TYPE_BUFFER:\r
+ *Buf = Value->Buffer;\r
+ *BufLen = Value->BufferLen;\r
+ break;\r
+\r
+ case EFI_IFR_TYPE_DATE:\r
+ *Buf = (UINT8 *) (&Value->Value.date);\r
+ *BufLen = (UINT16) sizeof (EFI_HII_DATE);\r
+ break;\r
+\r
+ case EFI_IFR_TYPE_TIME:\r
+ *Buf = (UINT8 *) (&Value->Value.time);\r
+ *BufLen = (UINT16) sizeof (EFI_HII_TIME);\r
+ break;\r
+\r
+ case EFI_IFR_TYPE_REF:\r
+ *Buf = (UINT8 *) (&Value->Value.ref);\r
+ *BufLen = (UINT16) sizeof (EFI_HII_REF);\r
+ break;\r
+\r
+ default:\r
+ *Buf = NULL;\r
+ *BufLen = 0;\r
+ }\r
+}\r
+\r
/**\r
Compare two Hii value.\r
\r
CHAR16 *Str1;\r
CHAR16 *Str2;\r
UINTN Len;\r
+ UINT8 *Buf1;\r
+ UINT16 Buf1Len;\r
+ UINT8 *Buf2;\r
+ UINT16 Buf2Len;\r
\r
- if (Value1->Type >= EFI_IFR_TYPE_OTHER || Value2->Type >= EFI_IFR_TYPE_OTHER ) {\r
- if (Value1->Type != EFI_IFR_TYPE_BUFFER && Value2->Type != EFI_IFR_TYPE_BUFFER) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- }\r
-\r
- if (Value1->Type == EFI_IFR_TYPE_STRING || Value2->Type == EFI_IFR_TYPE_STRING ) {\r
- if (Value1->Type != Value2->Type) {\r
- //\r
- // Both Operator should be type of String\r
- //\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
+ if (Value1->Type == EFI_IFR_TYPE_STRING && Value2->Type == EFI_IFR_TYPE_STRING) {\r
if (Value1->Value.string == 0 || Value2->Value.string == 0) {\r
//\r
// StringId 0 is reserved\r
return EFI_SUCCESS;\r
}\r
\r
- if (Value1->Type == EFI_IFR_TYPE_BUFFER || Value2->Type == EFI_IFR_TYPE_BUFFER ) {\r
- if (Value1->Type != Value2->Type) {\r
- //\r
- // Both Operator should be type of Buffer.\r
- //\r
- return EFI_UNSUPPORTED;\r
- }\r
- Len = Value1->BufferLen > Value2->BufferLen ? Value2->BufferLen : Value1->BufferLen;\r
- *Result = CompareMem (Value1->Buffer, Value2->Buffer, Len);\r
- if ((*Result == 0) && (Value1->BufferLen != Value2->BufferLen))\r
- {\r
+ //\r
+ // Take types(date, time, ref, buffer) as buffer\r
+ //\r
+ if (IsTypeInBuffer(Value1) && IsTypeInBuffer(Value2)) {\r
+ GetBufAndLenForValue(Value1, &Buf1, &Buf1Len);\r
+ GetBufAndLenForValue(Value2, &Buf2, &Buf2Len);\r
+\r
+ Len = Buf1Len > Buf2Len ? Buf2Len : Buf1Len;\r
+ *Result = CompareMem (Buf1, Buf2, Len);\r
+ if ((*Result == 0) && (Buf1Len != Buf2Len)) {\r
//\r
// In this case, means base on samll number buffer, the data is same\r
// So which value has more data, which value is bigger.\r
//\r
- *Result = Value1->BufferLen > Value2->BufferLen ? 1 : -1;\r
+ *Result = Buf1Len > Buf2Len ? 1 : -1;\r
}\r
return EFI_SUCCESS;\r
- } \r
+ }\r
\r
//\r
// Take remain types(integer, boolean, date/time) as integer\r
//\r
- Temp64 = HiiValueToUINT64(Value1) - HiiValueToUINT64(Value2);\r
- if (Temp64 > 0) {\r
- *Result = 1;\r
- } else if (Temp64 < 0) {\r
- *Result = -1;\r
- } else {\r
- *Result = 0;\r
+ if (IsTypeInUINT64(Value1) && IsTypeInUINT64(Value2)) {\r
+ Temp64 = HiiValueToUINT64(Value1) - HiiValueToUINT64(Value2);\r
+ if (Temp64 > 0) {\r
+ *Result = 1;\r
+ } else if (Temp64 < 0) {\r
+ *Result = -1;\r
+ } else {\r
+ *Result = 0;\r
+ }\r
+ return EFI_SUCCESS;\r
}\r
\r
- return EFI_SUCCESS;\r
+ return EFI_UNSUPPORTED;\r
}\r
\r
/**\r
ZeroMem (&Value, sizeof (EFI_HII_VALUE));\r
Value.Type = Option->OptionOpCode->Type;\r
CopyMem (&Value.Value, &Option->OptionOpCode->Value, Option->OptionOpCode->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));\r
- \r
+\r
if ((CompareHiiValue (&Value, OptionValue, &Result, NULL) == EFI_SUCCESS) && (Result == 0)) {\r
return Option;\r
}\r
@param Type Type of the data in this array.\r
@param Value The value to be find.\r
@param Index The index in the array which has same value with Value.\r
- \r
+\r
@retval TRUE Found the value in the array.\r
@retval FALSE Not found the value.\r
\r
**/\r
-BOOLEAN \r
+BOOLEAN\r
FindArrayData (\r
IN VOID *Array,\r
IN UINT8 Type,\r
UINTN Count;\r
UINT64 TmpValue;\r
UINT64 ValueComp;\r
- \r
+\r
ASSERT (Array != NULL);\r
\r
Count = 0;\r
\r
default:\r
return EFI_UNSUPPORTED;\r
- break;\r
}\r
\r
UnicodeSPrint (FormattedNumber, BufferSize, Format, Value);\r
\r
StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
ASSERT (StringPtr);\r
- \r
+\r
//\r
// Use a NULL password to test whether old password is required\r
//\r
Status = Question->PasswordCheck (gFormData, Question, StringPtr);\r
if (Status == EFI_NOT_AVAILABLE_YET || Status == EFI_UNSUPPORTED) {\r
//\r
- // Password can't be set now. \r
+ // Password can't be set now.\r
//\r
+ if (Status == EFI_UNSUPPORTED) {\r
+ do {\r
+ CreateDialog (&Key, gEmptyString, gPasswordUnsupported, gPressEnter, gEmptyString, NULL);\r
+ } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+ }\r
FreePool (StringPtr);\r
return EFI_SUCCESS;\r
}\r
return Status;\r
}\r
}\r
- \r
+\r
//\r
// Ask for new password\r
//\r
FreePool (StringPtr);\r
return Status;\r
}\r
- \r
+\r
//\r
// Confirm new password\r
//\r
FreePool (TempString);\r
return Status;\r
}\r
- \r
+\r
//\r
// Compare two typed-in new passwords\r
//\r
- if (StrCmp (StringPtr, TempString) == 0) { \r
+ if (StrCmp (StringPtr, TempString) == 0) {\r
gUserInput->InputValue.Buffer = AllocateCopyPool (Question->CurrentValue.BufferLen, StringPtr);\r
gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;\r
gUserInput->InputValue.Type = Question->CurrentValue.Type;\r
gUserInput->InputValue.Value.string = HiiSetString(gFormData->HiiHandle, gUserInput->InputValue.Value.string, StringPtr, NULL);\r
- FreePool (StringPtr); \r
\r
Status = EFI_SUCCESS;\r
-\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // Reset state machine for password\r
- //\r
- Question->PasswordCheck (gFormData, Question, NULL);\r
- }\r
-\r
- return Status;\r
} else {\r
//\r
// Reset state machine for password\r
//\r
Question->PasswordCheck (gFormData, Question, NULL);\r
- \r
+\r
//\r
// Two password mismatch, prompt error message\r
//\r
\r
Status = EFI_INVALID_PARAMETER;\r
}\r
- \r
+ ZeroMem (TempString, (Maximum + 1) * sizeof (CHAR16));\r
+ ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));\r
FreePool (TempString);\r
FreePool (StringPtr);\r
\r
UINTN Index2;\r
UINT8 *ValueArray;\r
UINT8 ValueType;\r
- EFI_STRING_ID StringId;\r
EFI_IFR_ORDERED_LIST *OrderList;\r
BOOLEAN ValueInvalid;\r
+ UINTN MaxLen;\r
\r
Status = EFI_SUCCESS;\r
\r
StringPtr = NULL;\r
Character[1] = L'\0';\r
*OptionString = NULL;\r
- StringId = 0;\r
ValueInvalid = FALSE;\r
\r
ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));\r
// We now know how many strings we will have, so we can allocate the\r
// space required for the array or strings.\r
//\r
- *OptionString = AllocateZeroPool (OrderList->MaxContainers * BufferSize);\r
+ MaxLen = OrderList->MaxContainers * BufferSize / sizeof (CHAR16);\r
+ *OptionString = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
ASSERT (*OptionString);\r
\r
HiiValue.Type = ValueType;\r
// Exit current DisplayForm with new value.\r
//\r
gUserInput->SelectedStatement = Question;\r
- \r
+ gMisMatch = TRUE;\r
ValueArray = AllocateZeroPool (Question->CurrentValue.BufferLen);\r
ASSERT (ValueArray != NULL);\r
gUserInput->InputValue.Buffer = ValueArray;\r
gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;\r
gUserInput->InputValue.Type = Question->CurrentValue.Type;\r
- \r
+\r
Link = GetFirstNode (&Question->OptionListHead);\r
Index2 = 0;\r
while (!IsNull (&Question->OptionListHead, Link) && Index2 < OrderList->MaxContainers) {\r
}\r
\r
Character[0] = LEFT_ONEOF_DELIMITER;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
StringPtr = GetToken (OneOfOption->OptionOpCode->Option, gFormData->HiiHandle);\r
ASSERT (StringPtr != NULL);\r
- NewStrCat (OptionString[0], StringPtr);\r
+ NewStrCat (OptionString[0], MaxLen, StringPtr);\r
Character[0] = RIGHT_ONEOF_DELIMITER;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
Character[0] = CHAR_CARRIAGE_RETURN;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
FreePool (StringPtr);\r
}\r
\r
// Not report error, just get the correct option string info.\r
//\r
Character[0] = LEFT_ONEOF_DELIMITER;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
StringPtr = GetToken (OneOfOption->OptionOpCode->Option, gFormData->HiiHandle);\r
ASSERT (StringPtr != NULL);\r
- NewStrCat (OptionString[0], StringPtr);\r
+ NewStrCat (OptionString[0], MaxLen, StringPtr);\r
Character[0] = RIGHT_ONEOF_DELIMITER;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
Character[0] = CHAR_CARRIAGE_RETURN;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
FreePool (StringPtr);\r
\r
continue;\r
// Exit current DisplayForm with new value.\r
//\r
gUserInput->SelectedStatement = Question;\r
- \r
+ gMisMatch = TRUE;\r
ValueArray = AllocateCopyPool (Question->CurrentValue.BufferLen, Question->CurrentValue.Buffer);\r
ASSERT (ValueArray != NULL);\r
gUserInput->InputValue.Buffer = ValueArray;\r
gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;\r
gUserInput->InputValue.Type = Question->CurrentValue.Type;\r
}\r
- \r
+\r
SetArrayData (ValueArray, ValueType, Index++, OneOfOption->OptionOpCode->Value.u64);\r
}\r
\r
//\r
Status = GetSelectionInputPopUp (MenuOption);\r
} else {\r
+ MaxLen = BufferSize / sizeof(CHAR16);\r
*OptionString = AllocateZeroPool (BufferSize);\r
ASSERT (*OptionString);\r
\r
if (SkipErrorValue) {\r
//\r
// Not report error, just get the correct option string info.\r
- // \r
+ //\r
Link = GetFirstNode (&Question->OptionListHead);\r
OneOfOption = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);\r
} else {\r
break;\r
}\r
gUserInput->SelectedStatement = Question;\r
-\r
+ gMisMatch = TRUE;\r
FreePool (*OptionString);\r
*OptionString = NULL;\r
return EFI_NOT_FOUND;\r
}\r
\r
Character[0] = LEFT_ONEOF_DELIMITER;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
StringPtr = GetToken (OneOfOption->OptionOpCode->Option, gFormData->HiiHandle);\r
ASSERT (StringPtr != NULL);\r
- NewStrCat (OptionString[0], StringPtr);\r
+ NewStrCat (OptionString[0], MaxLen, StringPtr);\r
Character[0] = RIGHT_ONEOF_DELIMITER;\r
- NewStrCat (OptionString[0], Character);\r
+ NewStrCat (OptionString[0], MaxLen, Character);\r
\r
FreePool (StringPtr);\r
}\r
// Perform inconsistent check\r
//\r
return EFI_SUCCESS;\r
- } else { \r
+ } else {\r
*OptionString = AllocateZeroPool (BufferSize);\r
ASSERT (*OptionString);\r
\r
switch (MenuOption->Sequence) {\r
case 0:\r
*OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
- UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Month);\r
+ if (QuestionValue->Value.date.Month == 0xff){\r
+ UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"??");\r
+ } else {\r
+ UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Month);\r
+ }\r
*(OptionString[0] + 3) = DATE_SEPARATOR;\r
break;\r
\r
case 1:\r
SetUnicodeMem (OptionString[0], 4, L' ');\r
- UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Day);\r
+ if (QuestionValue->Value.date.Day == 0xff){\r
+ UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"??");\r
+ } else {\r
+ UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Day);\r
+ }\r
*(OptionString[0] + 6) = DATE_SEPARATOR;\r
break;\r
\r
case 2:\r
SetUnicodeMem (OptionString[0], 7, L' ');\r
- UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%04d", QuestionValue->Value.date.Year);\r
+ if (QuestionValue->Value.date.Year == 0xff){\r
+ UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"????");\r
+ } else {\r
+ UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%04d", QuestionValue->Value.date.Year);\r
+ }\r
*(OptionString[0] + 11) = RIGHT_NUMERIC_DELIMITER;\r
break;\r
}\r
switch (MenuOption->Sequence) {\r
case 0:\r
*OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
- UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Hour);\r
+ if (QuestionValue->Value.time.Hour == 0xff){\r
+ UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"??");\r
+ } else {\r
+ UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Hour);\r
+ }\r
*(OptionString[0] + 3) = TIME_SEPARATOR;\r
break;\r
\r
case 1:\r
SetUnicodeMem (OptionString[0], 4, L' ');\r
- UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Minute);\r
+ if (QuestionValue->Value.time.Minute == 0xff){\r
+ UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"??");\r
+ } else {\r
+ UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Minute);\r
+ }\r
*(OptionString[0] + 6) = TIME_SEPARATOR;\r
break;\r
\r
case 2:\r
SetUnicodeMem (OptionString[0], 7, L' ');\r
- UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Second);\r
+ if (QuestionValue->Value.time.Second == 0xff){\r
+ UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"??");\r
+ } else {\r
+ UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Second);\r
+ }\r
*(OptionString[0] + 9) = RIGHT_NUMERIC_DELIMITER;\r
break;\r
}\r
FreePool (StringPtr);\r
return Status;\r
}\r
- \r
+\r
gUserInput->InputValue.Buffer = AllocateCopyPool (Question->CurrentValue.BufferLen, StringPtr);\r
gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;\r
gUserInput->InputValue.Type = Question->CurrentValue.Type;\r
FreePool (OutputString);\r
}\r
\r
- return TotalRowNum; \r
+ return TotalRowNum;\r
}\r