Reviewed-by: Eric Dong <eric.d...@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Fu 
> Siyuan
> Sent: Wednesday, March 23, 2016 3:39 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Jiaxin; Dong, Eric
> Subject: [edk2] [Patch] NetworkPkg: Fix HII related problem in HTTP boot 
> driver.
> 
> According to UEFI spec, HII_Config_Access.RouteConfig() should return success
> if the required configuration has been processed. Current HTTP boot driver
> may return error code in some situation, which failed the UEFI SCT test.
> This patch fix this issue by removing the returned error status code and 
> adding
> extra check point in the Callback() function, which will pop up a message box
> if user input an unsupported URI string.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan <siyuan...@intel.com>
> Cc: Dong Eric <eric.d...@intel.com>
> Cc: Wu Jiaxin <jiaxin...@intel.com>
> ---
>  NetworkPkg/HttpBootDxe/HttpBootConfig.c            | 77 
> +++++++++++++++++++---
>  NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h | 19 ++++--
>  NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr       |  6 +-
>  3 files changed, 85 insertions(+), 17 deletions(-)
> 
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfig.c 
> b/NetworkPkg/HttpBootDxe/HttpBootConfig.c
> index 0c1ff43..e7dd5db 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootConfig.c
> +++ b/NetworkPkg/HttpBootDxe/HttpBootConfig.c
> @@ -351,6 +351,7 @@ HttpBootFormExtractConfig (
>    //
>    BufferSize = sizeof (HTTP_BOOT_CONFIG_IFR_NVDATA);
>    ZeroMem (&CallbackInfo->HttpBootNvData, BufferSize);
> +  StrCpyS (CallbackInfo->HttpBootNvData.Description, 
> DESCRIPTION_STR_MAX_SIZE / sizeof (CHAR16),
> HTTP_BOOT_DEFAULT_DESCRIPTION_STR);
> 
>    ConfigRequest = Request;
>    if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
> @@ -376,7 +377,6 @@ HttpBootFormExtractConfig (
>                                  Results,
>                                  Progress
>                                  );
> -  ASSERT_EFI_ERROR (Status);
> 
>    //
>    // Free the allocated config request string.
> @@ -487,14 +487,14 @@ HttpBootFormRouteConfig (
>    //
>    // Create a new boot option according to the configuration data.
>    //
> -  Status = HttpBootAddBootOption (
> -             Private,
> -             (CallbackInfo->HttpBootNvData.IpVersion == 
> HTTP_BOOT_IP_VERSION_6) ? TRUE : FALSE,
> -             CallbackInfo->HttpBootNvData.Description,
> -             CallbackInfo->HttpBootNvData.Uri
> -             );
> +  HttpBootAddBootOption (
> +    Private,
> +    (CallbackInfo->HttpBootNvData.IpVersion == HTTP_BOOT_IP_VERSION_6) ? 
> TRUE : FALSE,
> +    CallbackInfo->HttpBootNvData.Description,
> +    CallbackInfo->HttpBootNvData.Uri
> +    );
> 
> -  return Status;
> +  return EFI_SUCCESS;
>  }
> 
>  /**
> @@ -533,7 +533,66 @@ HttpBootFormCallback (
>    OUT       EFI_BROWSER_ACTION_REQUEST       *ActionRequest
>    )
>  {
> -  return EFI_UNSUPPORTED;
> +  EFI_INPUT_KEY                   Key;
> +  UINTN                           Index;
> +  CHAR16                          *Uri;
> +  HTTP_BOOT_FORM_CALLBACK_INFO    *CallbackInfo;
> +
> +  if (This == NULL || Value == NULL) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);
> +
> +  if (Action != EFI_BROWSER_ACTION_CHANGING) {
> +    return EFI_UNSUPPORTED;
> +  }
> +
> +  switch (QuestionId) {
> +  case KEY_INITIATOR_URI:
> +    //
> +    // Get user input URI string
> +    //
> +    Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);
> +
> +    //
> +    // Convert the scheme to all lower case.
> +    //
> +    for (Index = 0; Index < StrLen (Uri); Index++) {
> +      if (Uri[Index] == L':') {
> +        break;
> +      }
> +      if (Uri[Index] >= L'A' && Uri[Index] <= L'Z') {
> +        Uri[Index] -= (CHAR16)(L'A' - L'a');
> +      }
> +    }
> +
> +    //
> +    // Set the converted URI string back
> +    //
> +    HiiSetString (CallbackInfo->RegisteredHandle, Value->string, Uri, NULL);
> +
> +    //
> +    // We only accept http and https, pop up a message box for unsupported 
> URI.
> +    //
> +    if ((StrnCmp (Uri, L"http://";, 7) != 0) && (StrnCmp (Uri, L"https://";, 
> 7) != 0)) {
> +      CreatePopUp (
> +        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
> +        &Key,
> +        L"ERROR: Unsupported URI!",
> +        L"Only supports HTTP and HTTPS",
> +        NULL
> +        );
> +    }
> +
> +    FreePool (Uri);
> +    break;
> +
> +  default:
> +    break;
> +  }
> +
> +  return EFI_SUCCESS;
>  }
> 
>  /**
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h 
> b/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h
> index 07043e7..37ce440 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h
> +++ b/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h
> @@ -17,24 +17,31 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
> EXPRESS OR IMPLIED.
> 
>  #include <Guid/HttpBootConfigHii.h>
> 
> -#define HTTP_BOOT_IP_VERSION_4         0
> -#define HTTP_BOOT_IP_VERSION_6         1
> +#define HTTP_BOOT_IP_VERSION_4       0
> +#define HTTP_BOOT_IP_VERSION_6       1
> 
>  //
>  // Macros used for an IPv4 or an IPv6 address.
>  //
> -#define URI_STR_MIN_SIZE           8
> -#define URI_STR_MAX_SIZE           255
> +#define URI_STR_MIN_SIZE             8
> +#define URI_STR_MAX_SIZE             255
> +
> +#define DESCRIPTION_STR_MIN_SIZE     6
> +#define DESCRIPTION_STR_MAX_SIZE     75
> 
>  #define CONFIGURATION_VARSTORE_ID    0x1234
> 
> -#define FORMID_MAIN_FORM    1
> +#define FORMID_MAIN_FORM             1
> +
> +#define KEY_INITIATOR_URI            0x101
> +
> +#define HTTP_BOOT_DEFAULT_DESCRIPTION_STR   L"UEFI HTTP"
> 
>  #pragma pack(1)
>  typedef struct _HTTP_BOOT_CONFIG_IFR_NVDATA {
>    UINT8     IpVersion;
>    UINT8     Padding;
> -  CHAR16    Description[URI_STR_MAX_SIZE];
> +  CHAR16    Description[DESCRIPTION_STR_MAX_SIZE];
>    CHAR16    Uri[URI_STR_MAX_SIZE];
>  } HTTP_BOOT_CONFIG_IFR_NVDATA;
>  #pragma pack()
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr 
> b/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr
> index e47c6af..7e8ddae 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr
> +++ b/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr
> @@ -31,8 +31,8 @@ formset
>      string  varid   = HTTP_BOOT_CONFIG_IFR_NVDATA.Description,
>              prompt  = STRING_TOKEN(STR_BOOT_DESCRIPTION_PROMPT),
>              help    = STRING_TOKEN(STR_NULL_STRING),
> -            minsize = 6,
> -            maxsize = 75,
> +            minsize = DESCRIPTION_STR_MIN_SIZE,
> +            maxsize = DESCRIPTION_STR_MAX_SIZE,
>      endstring;
> 
>      oneof varid  = HTTP_BOOT_CONFIG_IFR_NVDATA.IpVersion,
> @@ -45,6 +45,8 @@ formset
>      string  varid   = HTTP_BOOT_CONFIG_IFR_NVDATA.Uri,
>              prompt  = STRING_TOKEN(STR_BOOT_URI_PROMPT),
>              help    = STRING_TOKEN(STR_BOOT_URI_HELP),
> +            flags   = INTERACTIVE,
> +            key     = KEY_INITIATOR_URI,
>              minsize = URI_STR_MIN_SIZE,
>              maxsize = URI_STR_MAX_SIZE,
>      endstring;
> --
> 2.7.0.windows.2
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to