ArmPlatformPkg/Bds: Getting and editing IP addresses

Reworked GetHIInputIP() function to use "NetLibStrToIp4()" library
function to parse the IPv4 address instead of doing it by itself.

Added function EditHIInputIP() in BdsHelper.c to edit an IPv4 address.
To be used when updating a tftp boot option.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15660 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ronald Cron 2014-07-15 09:25:57 +00:00 committed by oliviermartin
parent 6d0ca2577c
commit 8bf4ad4475
7 changed files with 97 additions and 35 deletions

View File

@ -86,6 +86,9 @@
EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf
RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
# Networking Requirements for ArmPlatformPkg/Bds
NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
# EBL Related Libraries
EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

View File

@ -85,6 +85,9 @@
EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf
RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
# Networking Requirements for ArmPlatformPkg/Bds
NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
# EBL Related Libraries
EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

View File

@ -75,6 +75,9 @@
LcdPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEbLib.inf
ArmPlatformSysConfigLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/SysConfigArmRealViewEbLib/SysConfigArmRealViewEbLib.inf
# Networking Requirements for ArmPlatformPkg/Bds
NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
# EBL Related Libraries
EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

View File

@ -47,6 +47,7 @@
DebugLib
PrintLib
BaseLib
NetLib
[Guids]
gEfiFileSystemInfoGuid

View File

@ -12,6 +12,7 @@
*
**/
#include <Library/NetLib.h>
#include "BdsInternal.h"
EFI_STATUS
@ -137,43 +138,87 @@ GetHIInputInteger (
return Status;
}
/**
Get an IPv4 address
The function asks the user for an IPv4 address. If the input
string defines a valid IPv4 address, the four bytes of the
corresponding IPv4 address are extracted from the string and returned by
the function.
@param[out] EFI_IP_ADDRESS OutIpAddr Returned IPv4 address. Valid if
and only if the returned value
is equal to EFI_SUCCESS
@retval EFI_SUCCESS Input completed
@retval EFI_ABORTED Editing aborted by the user
@retval EFI_INVALID_PARAMETER The string returned by the user is
mal-formated
@retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to
lack of resource
**/
EFI_STATUS
GetHIInputIP (
OUT EFI_IP_ADDRESS *Ip
OUT EFI_IP_ADDRESS *OutIpAddr
)
{
CHAR16 CmdLine[255];
CHAR16 *Str;
EFI_STATUS Status;
CHAR16 CmdLine[48];
CmdLine[0] = '\0';
Status = EditHIInputStr (CmdLine,255);
if (!EFI_ERROR(Status)) {
Str = CmdLine;
Ip->v4.Addr[0] = (UINT8)StrDecimalToUintn (Str);
Str = StrStr (Str, L".");
if (Str == NULL) {
return EFI_INVALID_PARAMETER;
}
Ip->v4.Addr[1] = (UINT8)StrDecimalToUintn (++Str);
Str = StrStr (Str, L".");
if (Str == NULL) {
return EFI_INVALID_PARAMETER;
}
Ip->v4.Addr[2] = (UINT8)StrDecimalToUintn (++Str);
Str = StrStr (Str, L".");
if (Str == NULL) {
return EFI_INVALID_PARAMETER;
}
Ip->v4.Addr[3] = (UINT8)StrDecimalToUintn (++Str);
Status = EditHIInputStr (CmdLine, 48);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);
return Status;
}
/**
Edit an IPv4 address
The function displays as a string following the "%d.%d.%d.%d" format the
IPv4 address that is passed in and asks the user to modify it. If the
resulting string defines a valid IPv4 address, the four bytes of the
corresponding IPv4 address are extracted from the string and returned by
the function.
@param[in ] EFI_IP_ADDRESS InIpAddr Input IPv4 address
@param[out] EFI_IP_ADDRESS OutIpAddr Returned IPv4 address. Valid if
and only if the returned value
is equal to EFI_SUCCESS
@retval EFI_SUCCESS Update completed
@retval EFI_ABORTED Editing aborted by the user
@retval EFI_INVALID_PARAMETER The string returned by the user is
mal-formated
@retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to
lack of resource
**/
EFI_STATUS
EditHIInputIP (
IN EFI_IP_ADDRESS *InIpAddr,
OUT EFI_IP_ADDRESS *OutIpAddr
)
{
EFI_STATUS Status;
CHAR16 CmdLine[48];
UnicodeSPrint (
CmdLine, 48, L"%d.%d.%d.%d",
InIpAddr->v4.Addr[0], InIpAddr->v4.Addr[1],
InIpAddr->v4.Addr[2], InIpAddr->v4.Addr[3]
);
Status = EditHIInputStr (CmdLine, 48);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);
return Status;
}

View File

@ -160,6 +160,12 @@ GetHIInputIP (
OUT EFI_IP_ADDRESS *Ip
);
EFI_STATUS
EditHIInputIP (
IN EFI_IP_ADDRESS *InIpAddr,
OUT EFI_IP_ADDRESS *OutIpAddr
);
EFI_STATUS
GetHIInputBoolean (
OUT BOOLEAN *Value

View File

@ -122,6 +122,7 @@
DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf
FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf