From cf30b996d5d47835bf72921f351bb34c6790d8be Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Tue, 29 Jul 2014 14:16:10 +0000 Subject: [PATCH] ArmPlatformPkg/Bds: Change the GetHIInput/EditHIInput to always return a valid IP address The new functions never return a invalid IP address. The user would be asked again if the IP address is mal-formed. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ronald Cron Reviewed-By: Olivier Martin git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15714 6f19259b-4bc3-4df7-8a09-765794883524 --- ArmPlatformPkg/Bds/BdsHelper.c | 59 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/ArmPlatformPkg/Bds/BdsHelper.c b/ArmPlatformPkg/Bds/BdsHelper.c index 8553577cf1..693bc7d12a 100644 --- a/ArmPlatformPkg/Bds/BdsHelper.c +++ b/ArmPlatformPkg/Bds/BdsHelper.c @@ -144,7 +144,9 @@ GetHIInputInteger ( 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. + the function. As long as the user does not define a valid IP + address, he is asked for one. He can always escape by + pressing ESC. @param[out] EFI_IP_ADDRESS OutIpAddr Returned IPv4 address. Valid if and only if the returned value @@ -152,8 +154,6 @@ GetHIInputInteger ( @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 **/ @@ -165,15 +165,20 @@ GetHIInputIP ( EFI_STATUS Status; CHAR16 CmdLine[48]; - CmdLine[0] = '\0'; - Status = EditHIInputStr (CmdLine, 48); - if (EFI_ERROR (Status)) { - return EFI_ABORTED; - } - - Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4); + while (TRUE) { + CmdLine[0] = '\0'; + Status = EditHIInputStr (CmdLine, 48); + if (EFI_ERROR (Status)) { + return EFI_ABORTED; + } - return Status; + Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4); + if (Status == EFI_INVALID_PARAMETER) { + Print (L"Invalid address\n"); + } else { + return Status; + } + } } /** @@ -183,7 +188,9 @@ GetHIInputIP ( 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. + the function. As long as the user does not define a valid IP + address, he is asked for one. He can always escape by + pressing ESC. @param[in ] EFI_IP_ADDRESS InIpAddr Input IPv4 address @param[out] EFI_IP_ADDRESS OutIpAddr Returned IPv4 address. Valid if @@ -206,20 +213,24 @@ EditHIInputIP ( 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] - ); + while (TRUE) { + 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 = EditHIInputStr (CmdLine, 48); + if (EFI_ERROR (Status)) { + return EFI_ABORTED; + } + Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4); + if (Status == EFI_INVALID_PARAMETER) { + Print (L"Invalid address\n"); + } else { + return Status; + } } - - Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4); - - return Status; } EFI_STATUS -- 2.39.2