Update the code to follow UEFI spec, process date/time/ref value type as buffer type when in an expression.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15690 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
Implementation for handling the User Interface option processing.
|
||||
|
||||
|
||||
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
@ -98,6 +98,107 @@ HiiValueToUINT64 (
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
/**
|
||||
Check whether this value type can be transfer to EFI_IFR_TYPE_BUFFER type.
|
||||
|
||||
EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to
|
||||
EFI_IFR_TYPE_BUFFER when do the value compare.
|
||||
|
||||
@param Value Expression value to compare on.
|
||||
|
||||
@retval TRUE This value type can be transter to EFI_IFR_TYPE_BUFFER type.
|
||||
@retval FALSE This value type can't be transter to EFI_IFR_TYPE_BUFFER type.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsTypeInBuffer (
|
||||
IN EFI_HII_VALUE *Value
|
||||
)
|
||||
{
|
||||
switch (Value->Type) {
|
||||
case EFI_IFR_TYPE_BUFFER:
|
||||
case EFI_IFR_TYPE_DATE:
|
||||
case EFI_IFR_TYPE_TIME:
|
||||
case EFI_IFR_TYPE_REF:
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Check whether this value type can be transfer to EFI_IFR_TYPE_UINT64
|
||||
|
||||
@param Value Expression value to compare on.
|
||||
|
||||
@retval TRUE This value type can be transter to EFI_IFR_TYPE_BUFFER type.
|
||||
@retval FALSE This value type can't be transter to EFI_IFR_TYPE_BUFFER type.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsTypeInUINT64 (
|
||||
IN EFI_HII_VALUE *Value
|
||||
)
|
||||
{
|
||||
switch (Value->Type) {
|
||||
case EFI_IFR_TYPE_NUM_SIZE_8:
|
||||
case EFI_IFR_TYPE_NUM_SIZE_16:
|
||||
case EFI_IFR_TYPE_NUM_SIZE_32:
|
||||
case EFI_IFR_TYPE_NUM_SIZE_64:
|
||||
case EFI_IFR_TYPE_BOOLEAN:
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Return the buffer length and buffer pointer for this value.
|
||||
|
||||
EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to
|
||||
EFI_IFR_TYPE_BUFFER when do the value compare.
|
||||
|
||||
@param Value Expression value to compare on.
|
||||
@param Buf Return the buffer pointer.
|
||||
@param BufLen Return the buffer length.
|
||||
|
||||
**/
|
||||
VOID
|
||||
GetBufAndLenForValue (
|
||||
IN EFI_HII_VALUE *Value,
|
||||
OUT UINT8 **Buf,
|
||||
OUT UINT16 *BufLen
|
||||
)
|
||||
{
|
||||
switch (Value->Type) {
|
||||
case EFI_IFR_TYPE_BUFFER:
|
||||
*Buf = Value->Buffer;
|
||||
*BufLen = Value->BufferLen;
|
||||
break;
|
||||
|
||||
case EFI_IFR_TYPE_DATE:
|
||||
*Buf = (UINT8 *) (&Value->Value.date);
|
||||
*BufLen = (UINT16) sizeof (EFI_HII_DATE);
|
||||
break;
|
||||
|
||||
case EFI_IFR_TYPE_TIME:
|
||||
*Buf = (UINT8 *) (&Value->Value.time);
|
||||
*BufLen = (UINT16) sizeof (EFI_HII_TIME);
|
||||
break;
|
||||
|
||||
case EFI_IFR_TYPE_REF:
|
||||
*Buf = (UINT8 *) (&Value->Value.ref);
|
||||
*BufLen = (UINT16) sizeof (EFI_HII_REF);
|
||||
break;
|
||||
|
||||
default:
|
||||
*Buf = NULL;
|
||||
*BufLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Compare two Hii value.
|
||||
|
||||
@ -125,21 +226,12 @@ CompareHiiValue (
|
||||
CHAR16 *Str1;
|
||||
CHAR16 *Str2;
|
||||
UINTN Len;
|
||||
UINT8 *Buf1;
|
||||
UINT16 Buf1Len;
|
||||
UINT8 *Buf2;
|
||||
UINT16 Buf2Len;
|
||||
|
||||
if (Value1->Type >= EFI_IFR_TYPE_OTHER || Value2->Type >= EFI_IFR_TYPE_OTHER ) {
|
||||
if (Value1->Type != EFI_IFR_TYPE_BUFFER && Value2->Type != EFI_IFR_TYPE_BUFFER) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
if (Value1->Type == EFI_IFR_TYPE_STRING || Value2->Type == EFI_IFR_TYPE_STRING ) {
|
||||
if (Value1->Type != Value2->Type) {
|
||||
//
|
||||
// Both Operator should be type of String
|
||||
//
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (Value1->Type == EFI_IFR_TYPE_STRING && Value2->Type == EFI_IFR_TYPE_STRING) {
|
||||
if (Value1->Value.string == 0 || Value2->Value.string == 0) {
|
||||
//
|
||||
// StringId 0 is reserved
|
||||
@ -174,22 +266,21 @@ CompareHiiValue (
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (Value1->Type == EFI_IFR_TYPE_BUFFER || Value2->Type == EFI_IFR_TYPE_BUFFER ) {
|
||||
if (Value1->Type != Value2->Type) {
|
||||
//
|
||||
// Both Operator should be type of Buffer.
|
||||
//
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
Len = Value1->BufferLen > Value2->BufferLen ? Value2->BufferLen : Value1->BufferLen;
|
||||
*Result = CompareMem (Value1->Buffer, Value2->Buffer, Len);
|
||||
if ((*Result == 0) && (Value1->BufferLen != Value2->BufferLen))
|
||||
{
|
||||
//
|
||||
// Take types(date, time, ref, buffer) as buffer
|
||||
//
|
||||
if (IsTypeInBuffer(Value1) && IsTypeInBuffer(Value2)) {
|
||||
GetBufAndLenForValue(Value1, &Buf1, &Buf1Len);
|
||||
GetBufAndLenForValue(Value2, &Buf2, &Buf2Len);
|
||||
|
||||
Len = Buf1Len > Buf2Len ? Buf2Len : Buf1Len;
|
||||
*Result = CompareMem (Buf1, Buf2, Len);
|
||||
if ((*Result == 0) && (Buf1Len != Buf2Len)) {
|
||||
//
|
||||
// In this case, means base on samll number buffer, the data is same
|
||||
// So which value has more data, which value is bigger.
|
||||
//
|
||||
*Result = Value1->BufferLen > Value2->BufferLen ? 1 : -1;
|
||||
*Result = Buf1Len > Buf2Len ? 1 : -1;
|
||||
}
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@ -197,16 +288,19 @@ CompareHiiValue (
|
||||
//
|
||||
// Take remain types(integer, boolean, date/time) as integer
|
||||
//
|
||||
Temp64 = HiiValueToUINT64(Value1) - HiiValueToUINT64(Value2);
|
||||
if (Temp64 > 0) {
|
||||
*Result = 1;
|
||||
} else if (Temp64 < 0) {
|
||||
*Result = -1;
|
||||
} else {
|
||||
*Result = 0;
|
||||
if (IsTypeInUINT64(Value1) && IsTypeInUINT64(Value2)) {
|
||||
Temp64 = HiiValueToUINT64(Value1) - HiiValueToUINT64(Value2);
|
||||
if (Temp64 > 0) {
|
||||
*Result = 1;
|
||||
} else if (Temp64 < 0) {
|
||||
*Result = -1;
|
||||
} else {
|
||||
*Result = 0;
|
||||
}
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user