Replace BufToHexString by UnicodeValueToString

Replace HexStringToBuf by StrHexToUint64

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8034 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4
2009-04-08 00:56:51 +00:00
parent dfbe9de95f
commit 63d55bb98a
12 changed files with 398 additions and 264 deletions

View File

@@ -64,21 +64,6 @@ IScsiIpToStr (
UnicodeSPrint ( Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]);
}
/**
Pop up an invalid notify which displays the message in Warning.
@param[in] Warning The warning message.
**/
VOID
PopUpInvalidNotify (
IN CHAR16 *Warning
)
{
EFI_INPUT_KEY Key;
IfrLibCreatePopUp (1, &Key, Warning);
}
/**
Update the list of iSCSI devices the iSCSI driver is controlling.
@@ -512,6 +497,7 @@ IScsiFormCallback (
EFI_IP_ADDRESS SubnetMask;
EFI_IP_ADDRESS Gateway;
EFI_STATUS Status;
EFI_INPUT_KEY Key;
Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);
@@ -534,7 +520,7 @@ IScsiFormCallback (
Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName);
if (EFI_ERROR (Status)) {
PopUpInvalidNotify (L"Invalid iSCSI Name!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);
}
break;
@@ -543,7 +529,7 @@ IScsiFormCallback (
IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);
if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {
PopUpInvalidNotify (L"Invalid IP address!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
Status = EFI_INVALID_PARAMETER;
} else {
CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));
@@ -555,7 +541,7 @@ IScsiFormCallback (
IScsiUnicodeStrToAsciiStr (IfrNvData->SubnetMask, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &SubnetMask.v4);
if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
PopUpInvalidNotify (L"Invalid Subnet Mask!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);
Status = EFI_INVALID_PARAMETER;
} else {
CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));
@@ -567,7 +553,7 @@ IScsiFormCallback (
IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);
if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {
PopUpInvalidNotify (L"Invalid Gateway!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
Status = EFI_INVALID_PARAMETER;
} else {
CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));
@@ -579,7 +565,7 @@ IScsiFormCallback (
IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);
if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {
PopUpInvalidNotify (L"Invalid IP address!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
Status = EFI_INVALID_PARAMETER;
} else {
CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp.v4, sizeof (HostIp.v4));
@@ -591,7 +577,7 @@ IScsiFormCallback (
IScsiUnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName);
Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));
if (EFI_ERROR (Status)) {
PopUpInvalidNotify (L"Invalid iSCSI Name!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);
} else {
AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);
}
@@ -609,7 +595,7 @@ IScsiFormCallback (
IScsiUnicodeStrToAsciiStr (IfrNvData->BootLun, LunString);
Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);
if (EFI_ERROR (Status)) {
PopUpInvalidNotify (L"Invalid LUN string!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid LUN string!", NULL);
} else {
CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun));
}
@@ -661,11 +647,11 @@ IScsiFormCallback (
if ((Gateway.Addr[0] != 0)) {
if (SubnetMask.Addr[0] == 0) {
PopUpInvalidNotify (L"Gateway address is set but subnet mask is zero.");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL);
Status = EFI_INVALID_PARAMETER;
break;
} else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {
PopUpInvalidNotify (L"Local IP and Gateway are not in the same subnet.");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL);
Status = EFI_INVALID_PARAMETER;
break;
}
@@ -677,7 +663,7 @@ IScsiFormCallback (
if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {
CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));
if (!Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {
PopUpInvalidNotify (L"Target IP is invalid!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);
Status = EFI_INVALID_PARAMETER;
break;
}
@@ -685,7 +671,7 @@ IScsiFormCallback (
if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) {
if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) {
PopUpInvalidNotify (L"CHAP Name or CHAP Secret is invalid!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"CHAP Name or CHAP Secret is invalid!", NULL);
Status = EFI_INVALID_PARAMETER;
break;
}
@@ -693,7 +679,7 @@ IScsiFormCallback (
if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) &&
((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0'))
) {
PopUpInvalidNotify (L"Reverse CHAP Name or Reverse CHAP Secret is invalid!");
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Reverse CHAP Name or Reverse CHAP Secret is invalid!", NULL);
Status = EFI_INVALID_PARAMETER;
break;
}

View File

@@ -123,55 +123,64 @@ IScsiAsciiStrToLun (
OUT UINT8 *Lun
)
{
UINT32 Index;
CHAR8 *LunUnitStr[4];
CHAR8 Digit;
UINTN Temp;
UINTN Index, IndexValue, IndexNum, SizeStr;
CHAR8 TemStr[2];
UINT8 TemValue;
UINT16 Value [4];
ZeroMem (Lun, 8);
ZeroMem (LunUnitStr, sizeof (LunUnitStr));
ZeroMem (TemStr, 2);
ZeroMem ((UINT8 *) Value, sizeof (Value));
SizeStr = AsciiStrLen (Str);
IndexValue = 0;
IndexNum = 0;
Index = 0;
LunUnitStr[0] = Str;
if (!IsHexDigit ((UINT8 *) &Digit, *Str)) {
return EFI_INVALID_PARAMETER;
}
while (*Str != '\0') {
//
// Legal representations of LUN:
// 4752-3A4F-6b7e-2F99,
// 6734-9-156f-127,
// 4186-9
//
if (*Str == '-') {
*Str = '\0';
Index++;
if (*(Str + 1) != '\0') {
if (!IsHexDigit ((UINT8 *) &Digit, *(Str + 1))) {
return EFI_INVALID_PARAMETER;
}
LunUnitStr[Index] = Str + 1;
for (Index = 0; Index < SizeStr; Index ++) {
TemStr[0] = Str[Index];
TemValue = (UINT8) AsciiStrHexToUint64 (TemStr);
if (TemValue == 0 && TemStr[0] != '0') {
if ((TemStr[0] != '-') || (IndexNum == 0)) {
//
// Invalid Lun Char
//
return EFI_INVALID_PARAMETER;
}
} else if (!IsHexDigit ((UINT8 *) &Digit, *Str)) {
}
if ((TemValue == 0) && (TemStr[0] == '-')) {
//
// Next Lun value
//
if (++IndexValue >= 4) {
//
// Max 4 Lun value
//
return EFI_INVALID_PARAMETER;
}
//
// Restart str index for the next lun value
//
IndexNum = 0;
continue;
}
if (++IndexNum > 4) {
//
// Each Lun Str can't exceed size 4, because it will be as UINT16 value
//
return EFI_INVALID_PARAMETER;
}
Str++;
//
// Combine UINT16 value
//
Value[IndexValue] = (UINT16) ((Value[IndexValue] << 4) + TemValue);
}
for (Index = 0; (Index < 4) && (LunUnitStr[Index] != NULL); Index++) {
if (AsciiStrLen (LunUnitStr[Index]) > 4) {
return EFI_INVALID_PARAMETER;
}
Temp = AsciiStrHexToUintn (LunUnitStr[Index]);
*((UINT16 *) &Lun[Index * 2]) = HTONS (Temp);
for (Index = 0; Index <= IndexValue; Index ++) {
*((UINT16 *) &Lun[Index * 2]) = HTONS (Value[Index]);
}
return EFI_SUCCESS;
}
@@ -434,52 +443,38 @@ IScsiHexToBin (
)
{
UINTN Index;
UINT32 HexCount;
CHAR8 *HexBuf;
UINTN Length;
UINT8 Digit;
UINT8 Byte;
Digit = 0;
CHAR8 TemStr[2];
ZeroMem (TemStr, sizeof (TemStr));
//
// Find out how many hex characters the string has.
//
HexBuf = HexStr;
if ((HexBuf[0] == '0') && ((HexBuf[1] == 'x') || (HexBuf[1] == 'X'))) {
HexBuf += 2;
if ((HexStr[0] == '0') && ((HexStr[1] == 'x') || (HexStr[1] == 'X'))) {
HexStr += 2;
}
Length = AsciiStrLen (HexStr);
for (Index = 0, HexCount = 0; IsHexDigit (&Digit, HexBuf[Index]); Index++, HexCount++)
;
if (HexCount == 0) {
*BinLength = 0;
return EFI_SUCCESS;
}
//
// Test if buffer is passed enough.
//
if (((HexCount + 1) / 2) > *BinLength) {
*BinLength = (HexCount + 1) / 2;
return EFI_BUFFER_TOO_SMALL;
}
*BinLength = (HexCount + 1) / 2;
for (Index = 0; Index < HexCount; Index++) {
IsHexDigit (&Digit, HexBuf[HexCount - 1 - Index]);
if ((Index & 1) == 0) {
Byte = Digit;
} else {
Byte = BinBuffer[*BinLength - 1 - Index / 2];
Byte &= 0x0F;
Byte = (UINT8) (Byte | (Digit << 4));
for (Index = 0; Index < Length; Index ++) {
TemStr[0] = HexStr[Index];
Digit = (UINT8) AsciiStrHexToUint64 (TemStr);
if (Digit == 0 && TemStr[0] != '0') {
//
// Invalid Lun Char
//
break;
}
if ((Index & 1) == 0) {
BinBuffer [Index/2] = Digit;
} else {
BinBuffer [Index/2] = (UINT8) ((BinBuffer [Index/2] << 4) + Digit);
}
BinBuffer[*BinLength - 1 - Index / 2] = Byte;
}
*BinLength = (UINT32) ((Index + 1)/2);
return EFI_SUCCESS;
}