]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootSupport.c
NetworkPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootSupport.c
index e21b50d06696dd9b06a1117d0809df4ee75ff08b..61814d3b64ff485eb250f0bfa98e8cbc117d31b1 100644 (file)
-/** @file
-  Support functions implementation for UEFI HTTP boot driver.
-
-Copyright (c) 2015, 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 that accompanies this distribution.  
-The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php.                                          
-    
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "HttpBootDxe.h"
-
-
-/**
-  Get the Nic handle using any child handle in the IPv4 stack.
-
-  @param[in]  ControllerHandle    Pointer to child handle over IPv4.
-
-  @return NicHandle               The pointer to the Nic handle.
-  @return NULL                    Can't find the Nic handle.
-
-**/
-EFI_HANDLE
-HttpBootGetNicByIp4Children (
-  IN EFI_HANDLE                 ControllerHandle
-  )
-{
-  EFI_HANDLE                    NicHandle;
-
-  NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiHttpProtocolGuid);
-  if (NicHandle == NULL) {
-    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid);
-    if (NicHandle == NULL) {
-      return NULL;
-    }
-  }
-
-  return NicHandle;
-}
-
-
-/**
-  This function is to convert UINTN to ASCII string with the required formatting.
-
-  @param[in]  Number         Numeric value to be converted.
-  @param[in]  Buffer         The pointer to the buffer for ASCII string.
-  @param[in]  Length         The length of the required format.
-
-**/
-VOID
-HttpBootUintnToAscDecWithFormat (
-  IN UINTN                       Number,
-  IN UINT8                       *Buffer,
-  IN INTN                        Length
-  )
-{
-  UINTN                          Remainder;
-
-  while (Length > 0) {
-    Length--;
-    Remainder      = Number % 10;
-    Number        /= 10;
-    Buffer[Length] = (UINT8) ('0' + Remainder);
-  }
-}
-
-/**
-  This function is to display the IPv4 address.
-
-  @param[in]  Ip        The pointer to the IPv4 address.
-
-**/
-VOID
-HttpBootShowIp4Addr (
-  IN EFI_IPv4_ADDRESS   *Ip
-  )
-{
-  UINTN                 Index;
-
-  for (Index = 0; Index < 4; Index++) {
-    AsciiPrint ("%d", Ip->Addr[Index]);
-    if (Index < 3) {
-      AsciiPrint (".");
-    }
-  }
-}
-
-/**
-  Create a HTTP_IO_HEADER to hold the HTTP header items.
-
-  @param[in]  MaxHeaderCount         The maximun number of HTTP header in this holder.
-
-  @return    A pointer of the HTTP header holder or NULL if failed.
-  
-**/
-HTTP_IO_HEADER *
-HttpBootCreateHeader (
-  UINTN                     MaxHeaderCount
-)
-{
-  HTTP_IO_HEADER        *HttpIoHeader;
-
-  if (MaxHeaderCount == 0) {
-    return NULL;
-  }
-
-  HttpIoHeader = AllocateZeroPool (sizeof (HTTP_IO_HEADER) + MaxHeaderCount * sizeof (EFI_HTTP_HEADER));
-  if (HttpIoHeader == NULL) {
-    return NULL;
-  }
-
-  HttpIoHeader->MaxHeaderCount = MaxHeaderCount;
-  HttpIoHeader->Headers = (EFI_HTTP_HEADER *) (HttpIoHeader + 1);
-
-  return HttpIoHeader;
-}
-
-/**
-  Destroy the HTTP_IO_HEADER and release the resouces. 
-
-  @param[in]  HttpIoHeader       Point to the HTTP header holder to be destroyed.
-
-**/
-VOID
-HttpBootFreeHeader (
-  IN  HTTP_IO_HEADER       *HttpIoHeader
-  )
-{
-  UINTN      Index;
-  
-  if (HttpIoHeader != NULL) {
-    if (HttpIoHeader->HeaderCount != 0) {
-      for (Index = 0; Index < HttpIoHeader->HeaderCount; Index++) {
-        FreePool (HttpIoHeader->Headers[Index].FieldName);
-        FreePool (HttpIoHeader->Headers[Index].FieldValue);
-      }
-    }
-    FreePool (HttpIoHeader);
-  }
-}
-
-/**
-  Find a specified header field according to the field name.
-
-  @param[in]   HeaderCount      Number of HTTP header structures in Headers list. 
-  @param[in]   Headers          Array containing list of HTTP headers.
-  @param[in]   FieldName        Null terminated string which describes a field name. 
-
-  @return    Pointer to the found header or NULL.
-
-**/
-EFI_HTTP_HEADER *
-HttpBootFindHeader (
-  IN  UINTN                HeaderCount,
-  IN  EFI_HTTP_HEADER      *Headers,
-  IN  CHAR8                *FieldName
-  )
-{
-  UINTN                 Index;
-  
-  if (HeaderCount == 0 || Headers == NULL || FieldName == NULL) {
-    return NULL;
-  }
-
-  for (Index = 0; Index < HeaderCount; Index++){
-    //
-    // Field names are case-insensitive (RFC 2616).
-    //
-    if (AsciiStriCmp (Headers[Index].FieldName, FieldName) == 0) {
-      return &Headers[Index];
-    }
-  }
-  return NULL;
-}
-
-/**
-  Set or update a HTTP header with the field name and corresponding value.
-
-  @param[in]  HttpIoHeader       Point to the HTTP header holder.
-  @param[in]  FieldName          Null terminated string which describes a field name. 
-  @param[in]  FieldValue         Null terminated string which describes the corresponding field value.
-
-  @retval  EFI_SUCCESS           The HTTP header has been set or updated.
-  @retval  EFI_INVALID_PARAMETER Any input parameter is invalid.
-  @retval  EFI_OUT_OF_RESOURCES  Insufficient resource to complete the operation.
-  @retval  Other                 Unexpected error happened.
-  
-**/
-EFI_STATUS
-HttpBootSetHeader (
-  IN  HTTP_IO_HEADER       *HttpIoHeader,
-  IN  CHAR8                *FieldName,
-  IN  CHAR8                *FieldValue
-  )
-{
-  EFI_HTTP_HEADER       *Header;
-  UINTN                 StrSize;
-  CHAR8                 *NewFieldValue;
-  
-  if (HttpIoHeader == NULL || FieldName == NULL || FieldValue == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  Header = HttpBootFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);
-  if (Header == NULL) {
-    //
-    // Add a new header.
-    //
-    if (HttpIoHeader->HeaderCount >= HttpIoHeader->MaxHeaderCount) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-    Header = &HttpIoHeader->Headers[HttpIoHeader->HeaderCount];
-
-    StrSize = AsciiStrSize (FieldName);
-    Header->FieldName = AllocatePool (StrSize);
-    if (Header->FieldName == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-    CopyMem (Header->FieldName, FieldName, StrSize);
-    Header->FieldName[StrSize -1] = '\0';
-
-    StrSize = AsciiStrSize (FieldValue);
-    Header->FieldValue = AllocatePool (StrSize);
-    if (Header->FieldValue == NULL) {
-      FreePool (Header->FieldName);
-      return EFI_OUT_OF_RESOURCES;
-    }
-    CopyMem (Header->FieldValue, FieldValue, StrSize);
-    Header->FieldValue[StrSize -1] = '\0';
-
-    HttpIoHeader->HeaderCount++;
-  } else {
-    //
-    // Update an existing one.
-    //
-    StrSize = AsciiStrSize (FieldValue);
-    NewFieldValue = AllocatePool (StrSize);
-    if (NewFieldValue == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-    CopyMem (NewFieldValue, FieldValue, StrSize);
-    NewFieldValue[StrSize -1] = '\0';
-    
-    if (Header->FieldValue != NULL) {
-      FreePool (Header->FieldValue);
-    }
-    Header->FieldValue = NewFieldValue;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Notify the callback function when an event is triggered.
-
-  @param[in]  Event           The triggered event.
-  @param[in]  Context         The opaque parameter to the function.
-
-**/
-VOID
-EFIAPI
-HttpIoCommonNotify (
-  IN EFI_EVENT           Event,
-  IN VOID                *Context
-  )
-{
-  *((BOOLEAN *) Context) = TRUE;
-}
-
-/**
-  Create a HTTP_IO to access the HTTP service. It will create and configure
-  a HTTP child handle.
-
-  @param[in]  Image          The handle of the driver image.
-  @param[in]  Controller     The handle of the controller.
-  @param[in]  IpVersion      IP_VERSION_4 or IP_VERSION_6.
-  @param[in]  ConfigData     The HTTP_IO configuration data.
-  @param[out] HttpIo         The HTTP_IO.
-  
-  @retval EFI_SUCCESS            The HTTP_IO is created and configured.
-  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.
-  @retval EFI_UNSUPPORTED        One or more of the control options are not
-                                 supported in the implementation.
-  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.
-  @retval Others                 Failed to create the HTTP_IO or configure it.
-
-**/
-EFI_STATUS
-HttpIoCreateIo (
-  IN EFI_HANDLE             Image,
-  IN EFI_HANDLE             Controller,
-  IN UINT8                  IpVersion,
-  IN HTTP_IO_CONFIG_DATA    *ConfigData,
-  OUT HTTP_IO               *HttpIo
-  )
-{
-  EFI_STATUS                Status;
-  EFI_HTTP_CONFIG_DATA      HttpConfigData;
-  EFI_HTTPv4_ACCESS_POINT   Http4AccessPoint;
-  EFI_HTTP_PROTOCOL         *Http;
-  EFI_EVENT                 Event;
-  
-  if ((Image == NULL) || (Controller == NULL) || (ConfigData == NULL) || (HttpIo == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (IpVersion != IP_VERSION_4 && IpVersion != IP_VERSION_6) {
-    return EFI_UNSUPPORTED;
-  }
-
-  ZeroMem (HttpIo, sizeof (HTTP_IO));
-  
-  //
-  // Create the HTTP child instance and get the HTTP protocol.
-  //  
-  Status = NetLibCreateServiceChild (
-             Controller,
-             Image,
-             &gEfiHttpServiceBindingProtocolGuid,
-             &HttpIo->Handle
-             );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = gBS->OpenProtocol (
-                  HttpIo->Handle,
-                  &gEfiHttpProtocolGuid,
-                  (VOID **) &Http,
-                  Image,
-                  Controller,
-                  EFI_OPEN_PROTOCOL_BY_DRIVER
-                  );
-  if (EFI_ERROR (Status) || (Http == NULL)) {
-    goto ON_ERROR;
-  }
-
-  //
-  // Init the configuration data and configure the HTTP child.
-  //
-  HttpIo->Image       = Image;
-  HttpIo->Controller  = Controller;
-  HttpIo->IpVersion   = IpVersion;
-  HttpIo->Http        = Http;
-
-  ZeroMem (&HttpConfigData, sizeof (EFI_HTTP_CONFIG_DATA));
-  HttpConfigData.HttpVersion        = HttpVersion11;
-  HttpConfigData.TimeOutMillisec    = ConfigData->Config4.RequestTimeOut;
-  if (HttpIo->IpVersion == IP_VERSION_4) {
-    HttpConfigData.LocalAddressIsIPv6 = FALSE;
-    
-    Http4AccessPoint.UseDefaultAddress = ConfigData->Config4.UseDefaultAddress;
-    Http4AccessPoint.LocalPort         = ConfigData->Config4.LocalPort;
-    IP4_COPY_ADDRESS (&Http4AccessPoint.LocalAddress, &ConfigData->Config4.LocalIp);
-    IP4_COPY_ADDRESS (&Http4AccessPoint.LocalSubnet, &ConfigData->Config4.SubnetMask);
-    HttpConfigData.AccessPoint.IPv4Node = &Http4AccessPoint;   
-  } else {
-    ASSERT (FALSE);
-  }
-  
-  Status = Http->Configure (Http, &HttpConfigData);
-  if (EFI_ERROR (Status)) {
-    goto ON_ERROR;
-  }
-
-  //
-  // Create events for variuos asynchronous operations.
-  //
-  Status = gBS->CreateEvent (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_NOTIFY,
-                  HttpIoCommonNotify,
-                  &HttpIo->IsTxDone,
-                  &Event
-                  );
-  if (EFI_ERROR (Status)) {
-    goto ON_ERROR;
-  }
-  HttpIo->ReqToken.Event = Event;
-  HttpIo->ReqToken.Message = &HttpIo->ReqMessage;
-
-  Status = gBS->CreateEvent (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_NOTIFY,
-                  HttpIoCommonNotify,
-                  &HttpIo->IsRxDone,
-                  &Event
-                  );
-  if (EFI_ERROR (Status)) {
-    goto ON_ERROR;
-  }
-  HttpIo->RspToken.Event = Event;
-  HttpIo->RspToken.Message = &HttpIo->RspMessage;
-
-  return EFI_SUCCESS;
-  
-ON_ERROR:
-  HttpIoDestroyIo (HttpIo);
-
-  return Status;
-}
-
-/**
-  Destroy the HTTP_IO and release the resouces. 
-
-  @param[in]  HttpIo          The HTTP_IO which wraps the HTTP service to be destroyed.
-
-**/
-VOID
-HttpIoDestroyIo (
-  IN HTTP_IO                *HttpIo
-  )
-{
-  EFI_HTTP_PROTOCOL         *Http;
-  EFI_EVENT                 Event;
-
-  if (HttpIo == NULL) {
-    return;
-  }
-
-  Event = HttpIo->ReqToken.Event;
-  if (Event != NULL) {
-    gBS->CloseEvent (Event);
-  }
-
-  Event = HttpIo->RspToken.Event;
-  if (Event != NULL) {
-    gBS->CloseEvent (Event);
-  }
-  
-  Http = HttpIo->Http;
-  if (Http != NULL) {
-    Http->Configure (Http, NULL);
-    gBS->CloseProtocol (
-           HttpIo->Handle,
-           &gEfiHttpProtocolGuid,
-           HttpIo->Image,
-           HttpIo->Controller
-           );
-  }
-
-  NetLibDestroyServiceChild (
-    HttpIo->Controller,
-    HttpIo->Image,
-    &gEfiHttpServiceBindingProtocolGuid,
-    HttpIo->Handle
-    );
-}
-
-/**
-  Synchronously send a HTTP REQUEST message to the server.
-  
-  @param[in]   HttpIo           The HttpIo wrapping the HTTP service.
-  @param[in]   Request          A pointer to storage such data as URL and HTTP method.
-  @param[in]   HeaderCount      Number of HTTP header structures in Headers list. 
-  @param[in]   Headers          Array containing list of HTTP headers.
-  @param[in]   BodyLength       Length in bytes of the HTTP body.
-  @param[in]   Body             Body associated with the HTTP request. 
-  
-  @retval EFI_SUCCESS            The HTTP request is trasmitted.
-  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.
-  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.
-  @retval EFI_DEVICE_ERROR       An unexpected network or system error occurred.
-  @retval Others                 Other errors as indicated.
-
-**/
-EFI_STATUS
-HttpIoSendRequest (
-  IN  HTTP_IO                *HttpIo,
-  IN  EFI_HTTP_REQUEST_DATA  *Request,
-  IN  UINTN                  HeaderCount,
-  IN  EFI_HTTP_HEADER        *Headers,
-  IN  UINTN                  BodyLength,
-  IN  VOID                   *Body
-  )
-{
-  EFI_STATUS                 Status;
-  EFI_HTTP_PROTOCOL          *Http;
-
-  if (HttpIo == NULL || HttpIo->Http == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  HttpIo->ReqToken.Status  = EFI_NOT_READY;
-  HttpIo->ReqToken.Message->Data.Request = Request;
-  HttpIo->ReqToken.Message->HeaderCount  = HeaderCount;
-  HttpIo->ReqToken.Message->Headers      = Headers;
-  HttpIo->ReqToken.Message->BodyLength   = BodyLength;
-  HttpIo->ReqToken.Message->Body         = Body;
-
-  //
-  // Queue the request token to HTTP instances.
-  //
-  Http = HttpIo->Http;
-  HttpIo->IsTxDone = FALSE;
-  Status = Http->Request (
-                   Http,
-                   &HttpIo->ReqToken
-                   );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Poll the network until transmit finish.
-  //
-  while (!HttpIo->IsTxDone) {
-    Http->Poll (Http);
-  }
-
-  return HttpIo->ReqToken.Status;
-}
-
-/**
-  Synchronously receive a HTTP RESPONSE message from the server.
-  
-  @param[in]   HttpIo           The HttpIo wrapping the HTTP service.
-  @param[in]   RecvMsgHeader    TRUE to receive a new HTTP response (from message header).
-                                FALSE to continue receive the previous response message.
-  @param[out]  ResponseData     Point to a wrapper of the received response data.
-  
-  @retval EFI_SUCCESS            The HTTP resopnse is received.
-  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.
-  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.
-  @retval EFI_DEVICE_ERROR       An unexpected network or system error occurred.
-  @retval Others                 Other errors as indicated.
-
-**/
-EFI_STATUS
-HttpIoRecvResponse (
-  IN      HTTP_IO                  *HttpIo,
-  IN      BOOLEAN                  RecvMsgHeader,
-     OUT  HTTP_IO_RESOPNSE_DATA    *ResponseData
-  )
-{
-  EFI_STATUS                 Status;
-  EFI_HTTP_PROTOCOL          *Http;
-
-  if (HttpIo == NULL || HttpIo->Http == NULL || ResponseData == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Queue the response token to HTTP instances.
-  //
-  HttpIo->RspToken.Status  = EFI_NOT_READY;
-  if (RecvMsgHeader) {
-    HttpIo->RspToken.Message->Data.Response = &ResponseData->Response;
-  } else {
-    HttpIo->RspToken.Message->Data.Response = NULL;
-  }
-  HttpIo->RspToken.Message->HeaderCount   = 0;
-  HttpIo->RspToken.Message->Headers       = NULL;
-  HttpIo->RspToken.Message->BodyLength    = ResponseData->BodyLength;
-  HttpIo->RspToken.Message->Body          = ResponseData->Body;
-
-  Http = HttpIo->Http;
-  HttpIo->IsRxDone = FALSE;
-  Status = Http->Response (
-                   Http,
-                   &HttpIo->RspToken
-                   );
-  
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Poll the network until transmit finish.
-  //
-  while (!HttpIo->IsRxDone) {
-    Http->Poll (Http);
-  }
-
-  //
-  // Store the received data into the wrapper.
-  //
-  Status = HttpIo->ReqToken.Status;
-  if (!EFI_ERROR (Status)) {
-    ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;
-    ResponseData->Headers     = HttpIo->RspToken.Message->Headers;
-    ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;
-  }
-
-  return Status;
-}
+/** @file\r
+  Support functions implementation for UEFI HTTP boot driver.\r
+\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "HttpBootDxe.h"\r
+\r
+\r
+/**\r
+  Get the Nic handle using any child handle in the IPv4 stack.\r
+\r
+  @param[in]  ControllerHandle    Pointer to child handle over IPv4.\r
+\r
+  @return NicHandle               The pointer to the Nic handle.\r
+  @return NULL                    Can't find the Nic handle.\r
+\r
+**/\r
+EFI_HANDLE\r
+HttpBootGetNicByIp4Children (\r
+  IN EFI_HANDLE                 ControllerHandle\r
+  )\r
+{\r
+  EFI_HANDLE                    NicHandle;\r
+\r
+  NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiHttpProtocolGuid);\r
+  if (NicHandle == NULL) {\r
+    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid);\r
+    if (NicHandle == NULL) {\r
+      return NULL;\r
+    }\r
+  }\r
+\r
+  return NicHandle;\r
+}\r
+\r
+/**\r
+  Get the Nic handle using any child handle in the IPv6 stack.\r
+\r
+  @param[in]  ControllerHandle    Pointer to child handle over IPv6.\r
+\r
+  @return NicHandle               The pointer to the Nic handle.\r
+  @return NULL                    Can't find the Nic handle.\r
+\r
+**/\r
+EFI_HANDLE\r
+HttpBootGetNicByIp6Children (\r
+  IN EFI_HANDLE                 ControllerHandle\r
+  )\r
+{\r
+  EFI_HANDLE                    NicHandle;\r
+  NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiHttpProtocolGuid);\r
+  if (NicHandle == NULL) {\r
+    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp6ProtocolGuid);\r
+    if (NicHandle == NULL) {\r
+      return NULL;\r
+    }\r
+  }\r
+\r
+  return NicHandle;\r
+}\r
+\r
+/**\r
+  This function is to convert UINTN to ASCII string with the required formatting.\r
+\r
+  @param[in]  Number         Numeric value to be converted.\r
+  @param[in]  Buffer         The pointer to the buffer for ASCII string.\r
+  @param[in]  Length         The length of the required format.\r
+\r
+**/\r
+VOID\r
+HttpBootUintnToAscDecWithFormat (\r
+  IN UINTN                       Number,\r
+  IN UINT8                       *Buffer,\r
+  IN INTN                        Length\r
+  )\r
+{\r
+  UINTN                          Remainder;\r
+\r
+  for (; Length > 0; Length--) {\r
+    Remainder      = Number % 10;\r
+    Number        /= 10;\r
+    Buffer[Length - 1] = (UINT8) ('0' + Remainder);\r
+  }\r
+}\r
+\r
+/**\r
+  This function is to display the IPv4 address.\r
+\r
+  @param[in]  Ip        The pointer to the IPv4 address.\r
+\r
+**/\r
+VOID\r
+HttpBootShowIp4Addr (\r
+  IN EFI_IPv4_ADDRESS   *Ip\r
+  )\r
+{\r
+  UINTN                 Index;\r
+\r
+  for (Index = 0; Index < 4; Index++) {\r
+    AsciiPrint ("%d", Ip->Addr[Index]);\r
+    if (Index < 3) {\r
+      AsciiPrint (".");\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+  This function is to display the IPv6 address.\r
+\r
+  @param[in]  Ip        The pointer to the IPv6 address.\r
+\r
+**/\r
+VOID\r
+HttpBootShowIp6Addr (\r
+  IN EFI_IPv6_ADDRESS   *Ip\r
+  )\r
+{\r
+  UINTN                 Index;\r
+\r
+  for (Index = 0; Index < 16; Index++) {\r
+\r
+    if (Ip->Addr[Index] != 0) {\r
+      AsciiPrint ("%x", Ip->Addr[Index]);\r
+    }\r
+    Index++;\r
+    if (Index > 15) {\r
+      return;\r
+    }\r
+    if (((Ip->Addr[Index] & 0xf0) == 0) && (Ip->Addr[Index - 1] != 0)) {\r
+      AsciiPrint ("0");\r
+    }\r
+    AsciiPrint ("%x", Ip->Addr[Index]);\r
+    if (Index < 15) {\r
+      AsciiPrint (":");\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+  This function is to display the HTTP error status.\r
+\r
+  @param[in]      StatusCode      The status code value in HTTP message.\r
+\r
+**/\r
+VOID\r
+HttpBootPrintErrorMessage (\r
+  EFI_HTTP_STATUS_CODE            StatusCode\r
+  )\r
+{\r
+  AsciiPrint ("\n");\r
+\r
+  switch (StatusCode) {\r
+  case HTTP_STATUS_300_MULTIPLE_CHOICES:\r
+    AsciiPrint ("\n  Redirection: 300 Multiple Choices");\r
+    break;\r
+\r
+  case HTTP_STATUS_301_MOVED_PERMANENTLY:\r
+    AsciiPrint ("\n  Redirection: 301 Moved Permanently");\r
+    break;\r
+\r
+  case HTTP_STATUS_302_FOUND:\r
+    AsciiPrint ("\n  Redirection: 302 Found");\r
+    break;\r
+\r
+  case HTTP_STATUS_303_SEE_OTHER:\r
+    AsciiPrint ("\n  Redirection: 303 See Other");\r
+    break;\r
+\r
+  case HTTP_STATUS_304_NOT_MODIFIED:\r
+    AsciiPrint ("\n  Redirection: 304 Not Modified");\r
+    break;\r
+\r
+  case HTTP_STATUS_305_USE_PROXY:\r
+    AsciiPrint ("\n  Redirection: 305 Use Proxy");\r
+    break;\r
+\r
+  case HTTP_STATUS_307_TEMPORARY_REDIRECT:\r
+    AsciiPrint ("\n  Redirection: 307 Temporary Redirect");\r
+    break;\r
+\r
+  case HTTP_STATUS_308_PERMANENT_REDIRECT:\r
+    AsciiPrint ("\n  Redirection: 308 Permanent Redirect");\r
+    break;\r
+\r
+  case HTTP_STATUS_400_BAD_REQUEST:\r
+    AsciiPrint ("\n  Client Error: 400 Bad Request");\r
+    break;\r
+\r
+  case HTTP_STATUS_401_UNAUTHORIZED:\r
+    AsciiPrint ("\n  Client Error: 401 Unauthorized");\r
+    break;\r
+\r
+  case HTTP_STATUS_402_PAYMENT_REQUIRED:\r
+    AsciiPrint ("\n  Client Error: 402 Payment Required");\r
+    break;\r
+\r
+  case HTTP_STATUS_403_FORBIDDEN:\r
+    AsciiPrint ("\n  Client Error: 403 Forbidden");\r
+    break;\r
+\r
+  case HTTP_STATUS_404_NOT_FOUND:\r
+    AsciiPrint ("\n  Client Error: 404 Not Found");\r
+    break;\r
+\r
+  case HTTP_STATUS_405_METHOD_NOT_ALLOWED:\r
+    AsciiPrint ("\n  Client Error: 405 Method Not Allowed");\r
+    break;\r
+\r
+  case HTTP_STATUS_406_NOT_ACCEPTABLE:\r
+    AsciiPrint ("\n  Client Error: 406 Not Acceptable");\r
+    break;\r
+\r
+  case HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED:\r
+    AsciiPrint ("\n  Client Error: 407 Proxy Authentication Required");\r
+    break;\r
+\r
+  case HTTP_STATUS_408_REQUEST_TIME_OUT:\r
+    AsciiPrint ("\n  Client Error: 408 Request Timeout");\r
+    break;\r
+\r
+  case HTTP_STATUS_409_CONFLICT:\r
+    AsciiPrint ("\n  Client Error: 409 Conflict");\r
+    break;\r
+\r
+  case HTTP_STATUS_410_GONE:\r
+    AsciiPrint ("\n  Client Error: 410 Gone");\r
+    break;\r
+\r
+  case HTTP_STATUS_411_LENGTH_REQUIRED:\r
+    AsciiPrint ("\n  Client Error: 411 Length Required");\r
+    break;\r
+\r
+  case HTTP_STATUS_412_PRECONDITION_FAILED:\r
+    AsciiPrint ("\n  Client Error: 412 Precondition Failed");\r
+    break;\r
+\r
+  case HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE:\r
+    AsciiPrint ("\n  Client Error: 413 Request Entity Too Large");\r
+    break;\r
+\r
+  case HTTP_STATUS_414_REQUEST_URI_TOO_LARGE:\r
+    AsciiPrint ("\n  Client Error: 414 Request URI Too Long");\r
+    break;\r
+\r
+  case HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE:\r
+    AsciiPrint ("\n  Client Error: 415 Unsupported Media Type");\r
+    break;\r
+\r
+  case HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED:\r
+    AsciiPrint ("\n  Client Error: 416 Requested Range Not Satisfiable");\r
+    break;\r
+\r
+  case HTTP_STATUS_417_EXPECTATION_FAILED:\r
+    AsciiPrint ("\n  Client Error: 417 Expectation Failed");\r
+    break;\r
+\r
+  case HTTP_STATUS_500_INTERNAL_SERVER_ERROR:\r
+    AsciiPrint ("\n  Server Error: 500 Internal Server Error");\r
+    break;\r
+\r
+  case HTTP_STATUS_501_NOT_IMPLEMENTED:\r
+    AsciiPrint ("\n  Server Error: 501 Not Implemented");\r
+    break;\r
+\r
+  case HTTP_STATUS_502_BAD_GATEWAY:\r
+    AsciiPrint ("\n  Server Error: 502 Bad Gateway");\r
+    break;\r
+\r
+  case HTTP_STATUS_503_SERVICE_UNAVAILABLE:\r
+    AsciiPrint ("\n  Server Error: 503 Service Unavailable");\r
+    break;\r
+\r
+  case HTTP_STATUS_504_GATEWAY_TIME_OUT:\r
+    AsciiPrint ("\n  Server Error: 504 Gateway Timeout");\r
+    break;\r
+\r
+  case HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED:\r
+    AsciiPrint ("\n  Server Error: 505 HTTP Version Not Supported");\r
+    break;\r
+\r
+  default: ;\r
+\r
+  }\r
+}\r
+\r
+/**\r
+  Notify the callback function when an event is triggered.\r
+\r
+  @param[in]  Event           The triggered event.\r
+  @param[in]  Context         The opaque parameter to the function.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HttpBootCommonNotify (\r
+  IN EFI_EVENT           Event,\r
+  IN VOID                *Context\r
+  )\r
+{\r
+  *((BOOLEAN *) Context) = TRUE;\r
+}\r
+\r
+/**\r
+  Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
+\r
+  @param[in]  Private             The pointer to the driver's private data.\r
+  @param[in]  HostName            Pointer to buffer containing hostname.\r
+  @param[out] IpAddress           On output, pointer to buffer containing IPv6 address.\r
+\r
+  @retval EFI_SUCCESS             Operation succeeded.\r
+  @retval EFI_DEVICE_ERROR        An unexpected network error occurred.\r
+  @retval Others                  Other errors as indicated.\r
+**/\r
+EFI_STATUS\r
+HttpBootDns (\r
+  IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
+  IN     CHAR16                   *HostName,\r
+     OUT EFI_IPv6_ADDRESS         *IpAddress\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_DNS6_PROTOCOL               *Dns6;\r
+  EFI_DNS6_CONFIG_DATA            Dns6ConfigData;\r
+  EFI_DNS6_COMPLETION_TOKEN       Token;\r
+  EFI_HANDLE                      Dns6Handle;\r
+  EFI_IP6_CONFIG_PROTOCOL         *Ip6Config;\r
+  EFI_IPv6_ADDRESS                *DnsServerList;\r
+  UINTN                           DnsServerListCount;\r
+  UINTN                           DataSize;\r
+  BOOLEAN                         IsDone;\r
+\r
+  DnsServerList       = NULL;\r
+  DnsServerListCount  = 0;\r
+  Dns6                = NULL;\r
+  Dns6Handle          = NULL;\r
+  ZeroMem (&Token, sizeof (EFI_DNS6_COMPLETION_TOKEN));\r
+\r
+  //\r
+  // Get DNS server list from EFI IPv6 Configuration protocol.\r
+  //\r
+  Status = gBS->HandleProtocol (Private->Controller, &gEfiIp6ConfigProtocolGuid, (VOID **) &Ip6Config);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Get the required size.\r
+    //\r
+    DataSize = 0;\r
+    Status = Ip6Config->GetData (Ip6Config, Ip6ConfigDataTypeDnsServer, &DataSize, NULL);\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      DnsServerList = AllocatePool (DataSize);\r
+      if (DnsServerList == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      Status = Ip6Config->GetData (Ip6Config, Ip6ConfigDataTypeDnsServer, &DataSize, DnsServerList);\r
+      if (EFI_ERROR (Status)) {\r
+        FreePool (DnsServerList);\r
+        DnsServerList = NULL;\r
+      } else {\r
+        DnsServerListCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
+      }\r
+    }\r
+  }\r
+  //\r
+  // Create a DNSv6 child instance and get the protocol.\r
+  //\r
+  Status = NetLibCreateServiceChild (\r
+             Private->Controller,\r
+             Private->Ip6Nic->ImageHandle,\r
+             &gEfiDns6ServiceBindingProtocolGuid,\r
+             &Dns6Handle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Dns6Handle,\r
+                  &gEfiDns6ProtocolGuid,\r
+                  (VOID **) &Dns6,\r
+                  Private->Ip6Nic->ImageHandle,\r
+                  Private->Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Configure DNS6 instance for the DNS server address and protocol.\r
+  //\r
+  ZeroMem (&Dns6ConfigData, sizeof (EFI_DNS6_CONFIG_DATA));\r
+  Dns6ConfigData.DnsServerCount = (UINT32)DnsServerListCount;\r
+  Dns6ConfigData.DnsServerList  = DnsServerList;\r
+  Dns6ConfigData.EnableDnsCache = TRUE;\r
+  Dns6ConfigData.Protocol       = EFI_IP_PROTO_UDP;\r
+  IP6_COPY_ADDRESS (&Dns6ConfigData.StationIp,&Private->StationIp.v6);\r
+  Status = Dns6->Configure (\r
+                    Dns6,\r
+                    &Dns6ConfigData\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Token.Status = EFI_NOT_READY;\r
+  IsDone       = FALSE;\r
+  //\r
+  // Create event to set the  IsDone flag when name resolution is finished.\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  HttpBootCommonNotify,\r
+                  &IsDone,\r
+                  &Token.Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Start asynchronous name resolution.\r
+  //\r
+  Status = Dns6->HostNameToIp (Dns6, HostName, &Token);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  while (!IsDone) {\r
+    Dns6->Poll (Dns6);\r
+  }\r
+\r
+  //\r
+  // Name resolution is done, check result.\r
+  //\r
+  Status = Token.Status;\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Token.RspData.H2AData == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+    if (Token.RspData.H2AData->IpCount == 0 || Token.RspData.H2AData->IpList == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+    //\r
+    // We just return the first IPv6 address from DNS protocol.\r
+    //\r
+    IP6_COPY_ADDRESS (IpAddress, Token.RspData.H2AData->IpList);\r
+    Status = EFI_SUCCESS;\r
+  }\r
+Exit:\r
+\r
+  if (Token.Event != NULL) {\r
+    gBS->CloseEvent (Token.Event);\r
+  }\r
+  if (Token.RspData.H2AData != NULL) {\r
+    if (Token.RspData.H2AData->IpList != NULL) {\r
+      FreePool (Token.RspData.H2AData->IpList);\r
+    }\r
+    FreePool (Token.RspData.H2AData);\r
+  }\r
+\r
+  if (Dns6 != NULL) {\r
+    Dns6->Configure (Dns6, NULL);\r
+\r
+    gBS->CloseProtocol (\r
+           Dns6Handle,\r
+           &gEfiDns6ProtocolGuid,\r
+           Private->Ip6Nic->ImageHandle,\r
+           Private->Controller\r
+           );\r
+  }\r
+\r
+  if (Dns6Handle != NULL) {\r
+    NetLibDestroyServiceChild (\r
+      Private->Controller,\r
+      Private->Ip6Nic->ImageHandle,\r
+      &gEfiDns6ServiceBindingProtocolGuid,\r
+      Dns6Handle\r
+      );\r
+  }\r
+\r
+  if (DnsServerList != NULL) {\r
+    FreePool (DnsServerList);\r
+  }\r
+\r
+  return Status;\r
+}\r
+/**\r
+  Create a HTTP_IO_HEADER to hold the HTTP header items.\r
+\r
+  @param[in]  MaxHeaderCount         The maximun number of HTTP header in this holder.\r
+\r
+  @return    A pointer of the HTTP header holder or NULL if failed.\r
+\r
+**/\r
+HTTP_IO_HEADER *\r
+HttpBootCreateHeader (\r
+  UINTN                     MaxHeaderCount\r
+  )\r
+{\r
+  HTTP_IO_HEADER        *HttpIoHeader;\r
+\r
+  if (MaxHeaderCount == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  HttpIoHeader = AllocateZeroPool (sizeof (HTTP_IO_HEADER) + MaxHeaderCount * sizeof (EFI_HTTP_HEADER));\r
+  if (HttpIoHeader == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  HttpIoHeader->MaxHeaderCount = MaxHeaderCount;\r
+  HttpIoHeader->Headers = (EFI_HTTP_HEADER *) (HttpIoHeader + 1);\r
+\r
+  return HttpIoHeader;\r
+}\r
+\r
+/**\r
+  Destroy the HTTP_IO_HEADER and release the resouces.\r
+\r
+  @param[in]  HttpIoHeader       Point to the HTTP header holder to be destroyed.\r
+\r
+**/\r
+VOID\r
+HttpBootFreeHeader (\r
+  IN  HTTP_IO_HEADER       *HttpIoHeader\r
+  )\r
+{\r
+  UINTN      Index;\r
+\r
+  if (HttpIoHeader != NULL) {\r
+    if (HttpIoHeader->HeaderCount != 0) {\r
+      for (Index = 0; Index < HttpIoHeader->HeaderCount; Index++) {\r
+        FreePool (HttpIoHeader->Headers[Index].FieldName);\r
+        FreePool (HttpIoHeader->Headers[Index].FieldValue);\r
+      }\r
+    }\r
+    FreePool (HttpIoHeader);\r
+  }\r
+}\r
+\r
+/**\r
+  Set or update a HTTP header with the field name and corresponding value.\r
+\r
+  @param[in]  HttpIoHeader       Point to the HTTP header holder.\r
+  @param[in]  FieldName          Null terminated string which describes a field name.\r
+  @param[in]  FieldValue         Null terminated string which describes the corresponding field value.\r
+\r
+  @retval  EFI_SUCCESS           The HTTP header has been set or updated.\r
+  @retval  EFI_INVALID_PARAMETER Any input parameter is invalid.\r
+  @retval  EFI_OUT_OF_RESOURCES  Insufficient resource to complete the operation.\r
+  @retval  Other                 Unexpected error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootSetHeader (\r
+  IN  HTTP_IO_HEADER       *HttpIoHeader,\r
+  IN  CHAR8                *FieldName,\r
+  IN  CHAR8                *FieldValue\r
+  )\r
+{\r
+  EFI_HTTP_HEADER       *Header;\r
+  UINTN                 StrSize;\r
+  CHAR8                 *NewFieldValue;\r
+\r
+  if (HttpIoHeader == NULL || FieldName == NULL || FieldValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Header = HttpFindHeader (HttpIoHeader->HeaderCount, HttpIoHeader->Headers, FieldName);\r
+  if (Header == NULL) {\r
+    //\r
+    // Add a new header.\r
+    //\r
+    if (HttpIoHeader->HeaderCount >= HttpIoHeader->MaxHeaderCount) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Header = &HttpIoHeader->Headers[HttpIoHeader->HeaderCount];\r
+\r
+    StrSize = AsciiStrSize (FieldName);\r
+    Header->FieldName = AllocatePool (StrSize);\r
+    if (Header->FieldName == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (Header->FieldName, FieldName, StrSize);\r
+    Header->FieldName[StrSize -1] = '\0';\r
+\r
+    StrSize = AsciiStrSize (FieldValue);\r
+    Header->FieldValue = AllocatePool (StrSize);\r
+    if (Header->FieldValue == NULL) {\r
+      FreePool (Header->FieldName);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (Header->FieldValue, FieldValue, StrSize);\r
+    Header->FieldValue[StrSize -1] = '\0';\r
+\r
+    HttpIoHeader->HeaderCount++;\r
+  } else {\r
+    //\r
+    // Update an existing one.\r
+    //\r
+    StrSize = AsciiStrSize (FieldValue);\r
+    NewFieldValue = AllocatePool (StrSize);\r
+    if (NewFieldValue == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (NewFieldValue, FieldValue, StrSize);\r
+    NewFieldValue[StrSize -1] = '\0';\r
+\r
+    if (Header->FieldValue != NULL) {\r
+      FreePool (Header->FieldValue);\r
+    }\r
+    Header->FieldValue = NewFieldValue;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Notify the callback function when an event is triggered.\r
+\r
+  @param[in]  Context         The opaque parameter to the function.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HttpIoNotifyDpc (\r
+  IN VOID                *Context\r
+  )\r
+{\r
+  *((BOOLEAN *) Context) = TRUE;\r
+}\r
+\r
+/**\r
+  Request HttpIoNotifyDpc as a DPC at TPL_CALLBACK.\r
+\r
+  @param[in]  Event                 The event signaled.\r
+  @param[in]  Context               The opaque parameter to the function.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HttpIoNotify (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  //\r
+  // Request HttpIoNotifyDpc as a DPC at TPL_CALLBACK\r
+  //\r
+  QueueDpc (TPL_CALLBACK, HttpIoNotifyDpc, Context);\r
+}\r
+\r
+/**\r
+  Create a HTTP_IO to access the HTTP service. It will create and configure\r
+  a HTTP child handle.\r
+\r
+  @param[in]  Image          The handle of the driver image.\r
+  @param[in]  Controller     The handle of the controller.\r
+  @param[in]  IpVersion      IP_VERSION_4 or IP_VERSION_6.\r
+  @param[in]  ConfigData     The HTTP_IO configuration data.\r
+  @param[in]  Callback       Callback function which will be invoked when specified\r
+                             HTTP_IO_CALLBACK_EVENT happened.\r
+  @param[in]  Context        The Context data which will be passed to the Callback function.\r
+  @param[out] HttpIo         The HTTP_IO.\r
+\r
+  @retval EFI_SUCCESS            The HTTP_IO is created and configured.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED        One or more of the control options are not\r
+                                 supported in the implementation.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+  @retval Others                 Failed to create the HTTP_IO or configure it.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpIoCreateIo (\r
+  IN EFI_HANDLE             Image,\r
+  IN EFI_HANDLE             Controller,\r
+  IN UINT8                  IpVersion,\r
+  IN HTTP_IO_CONFIG_DATA    *ConfigData,\r
+  IN HTTP_IO_CALLBACK       Callback,\r
+  IN VOID                   *Context,\r
+  OUT HTTP_IO               *HttpIo\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_HTTP_CONFIG_DATA      HttpConfigData;\r
+  EFI_HTTPv4_ACCESS_POINT   Http4AccessPoint;\r
+  EFI_HTTPv6_ACCESS_POINT   Http6AccessPoint;\r
+  EFI_HTTP_PROTOCOL         *Http;\r
+  EFI_EVENT                 Event;\r
+\r
+  if ((Image == NULL) || (Controller == NULL) || (ConfigData == NULL) || (HttpIo == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (IpVersion != IP_VERSION_4 && IpVersion != IP_VERSION_6) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  ZeroMem (HttpIo, sizeof (HTTP_IO));\r
+\r
+  //\r
+  // Create the HTTP child instance and get the HTTP protocol.\r
+  //\r
+  Status = NetLibCreateServiceChild (\r
+             Controller,\r
+             Image,\r
+             &gEfiHttpServiceBindingProtocolGuid,\r
+             &HttpIo->Handle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  HttpIo->Handle,\r
+                  &gEfiHttpProtocolGuid,\r
+                  (VOID **) &Http,\r
+                  Image,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) || (Http == NULL)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  //\r
+  // Init the configuration data and configure the HTTP child.\r
+  //\r
+  HttpIo->Image       = Image;\r
+  HttpIo->Controller  = Controller;\r
+  HttpIo->IpVersion   = IpVersion;\r
+  HttpIo->Http        = Http;\r
+  HttpIo->Callback    = Callback;\r
+  HttpIo->Context     = Context;\r
+\r
+  ZeroMem (&HttpConfigData, sizeof (EFI_HTTP_CONFIG_DATA));\r
+  HttpConfigData.HttpVersion        = HttpVersion11;\r
+  HttpConfigData.TimeOutMillisec    = ConfigData->Config4.RequestTimeOut;\r
+  if (HttpIo->IpVersion == IP_VERSION_4) {\r
+    HttpConfigData.LocalAddressIsIPv6 = FALSE;\r
+\r
+    Http4AccessPoint.UseDefaultAddress = ConfigData->Config4.UseDefaultAddress;\r
+    Http4AccessPoint.LocalPort         = ConfigData->Config4.LocalPort;\r
+    IP4_COPY_ADDRESS (&Http4AccessPoint.LocalAddress, &ConfigData->Config4.LocalIp);\r
+    IP4_COPY_ADDRESS (&Http4AccessPoint.LocalSubnet, &ConfigData->Config4.SubnetMask);\r
+    HttpConfigData.AccessPoint.IPv4Node = &Http4AccessPoint;\r
+  } else {\r
+    HttpConfigData.LocalAddressIsIPv6 = TRUE;\r
+    Http6AccessPoint.LocalPort        = ConfigData->Config6.LocalPort;\r
+    IP6_COPY_ADDRESS (&Http6AccessPoint.LocalAddress, &ConfigData->Config6.LocalIp);\r
+    HttpConfigData.AccessPoint.IPv6Node = &Http6AccessPoint;\r
+  }\r
+\r
+  Status = Http->Configure (Http, &HttpConfigData);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  //\r
+  // Create events for variuos asynchronous operations.\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  HttpIoNotify,\r
+                  &HttpIo->IsTxDone,\r
+                  &Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+  HttpIo->ReqToken.Event = Event;\r
+  HttpIo->ReqToken.Message = &HttpIo->ReqMessage;\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  HttpIoNotify,\r
+                  &HttpIo->IsRxDone,\r
+                  &Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+  HttpIo->RspToken.Event = Event;\r
+  HttpIo->RspToken.Message = &HttpIo->RspMessage;\r
+\r
+  //\r
+  // Create TimeoutEvent for response\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER,\r
+                  TPL_CALLBACK,\r
+                  NULL,\r
+                  NULL,\r
+                  &Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+  HttpIo->TimeoutEvent = Event;\r
+\r
+  return EFI_SUCCESS;\r
+\r
+ON_ERROR:\r
+  HttpIoDestroyIo (HttpIo);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Destroy the HTTP_IO and release the resouces.\r
+\r
+  @param[in]  HttpIo          The HTTP_IO which wraps the HTTP service to be destroyed.\r
+\r
+**/\r
+VOID\r
+HttpIoDestroyIo (\r
+  IN HTTP_IO                *HttpIo\r
+  )\r
+{\r
+  EFI_HTTP_PROTOCOL         *Http;\r
+  EFI_EVENT                 Event;\r
+\r
+  if (HttpIo == NULL) {\r
+    return;\r
+  }\r
+\r
+  Event = HttpIo->ReqToken.Event;\r
+  if (Event != NULL) {\r
+    gBS->CloseEvent (Event);\r
+  }\r
+\r
+  Event = HttpIo->RspToken.Event;\r
+  if (Event != NULL) {\r
+    gBS->CloseEvent (Event);\r
+  }\r
+\r
+  Event = HttpIo->TimeoutEvent;\r
+  if (Event != NULL) {\r
+    gBS->CloseEvent (Event);\r
+  }\r
+\r
+  Http = HttpIo->Http;\r
+  if (Http != NULL) {\r
+    Http->Configure (Http, NULL);\r
+    gBS->CloseProtocol (\r
+           HttpIo->Handle,\r
+           &gEfiHttpProtocolGuid,\r
+           HttpIo->Image,\r
+           HttpIo->Controller\r
+           );\r
+  }\r
+\r
+  NetLibDestroyServiceChild (\r
+    HttpIo->Controller,\r
+    HttpIo->Image,\r
+    &gEfiHttpServiceBindingProtocolGuid,\r
+    HttpIo->Handle\r
+    );\r
+}\r
+\r
+/**\r
+  Synchronously send a HTTP REQUEST message to the server.\r
+\r
+  @param[in]   HttpIo           The HttpIo wrapping the HTTP service.\r
+  @param[in]   Request          A pointer to storage such data as URL and HTTP method.\r
+  @param[in]   HeaderCount      Number of HTTP header structures in Headers list.\r
+  @param[in]   Headers          Array containing list of HTTP headers.\r
+  @param[in]   BodyLength       Length in bytes of the HTTP body.\r
+  @param[in]   Body             Body associated with the HTTP request.\r
+\r
+  @retval EFI_SUCCESS            The HTTP request is trasmitted.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+  @retval EFI_DEVICE_ERROR       An unexpected network or system error occurred.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpIoSendRequest (\r
+  IN  HTTP_IO                *HttpIo,\r
+  IN  EFI_HTTP_REQUEST_DATA  *Request,\r
+  IN  UINTN                  HeaderCount,\r
+  IN  EFI_HTTP_HEADER        *Headers,\r
+  IN  UINTN                  BodyLength,\r
+  IN  VOID                   *Body\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_HTTP_PROTOCOL          *Http;\r
+\r
+  if (HttpIo == NULL || HttpIo->Http == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  HttpIo->ReqToken.Status  = EFI_NOT_READY;\r
+  HttpIo->ReqToken.Message->Data.Request = Request;\r
+  HttpIo->ReqToken.Message->HeaderCount  = HeaderCount;\r
+  HttpIo->ReqToken.Message->Headers      = Headers;\r
+  HttpIo->ReqToken.Message->BodyLength   = BodyLength;\r
+  HttpIo->ReqToken.Message->Body         = Body;\r
+\r
+  if (HttpIo->Callback != NULL) {\r
+    Status = HttpIo->Callback (\r
+               HttpIoRequest,\r
+               HttpIo->ReqToken.Message,\r
+               HttpIo->Context\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Queue the request token to HTTP instances.\r
+  //\r
+  Http = HttpIo->Http;\r
+  HttpIo->IsTxDone = FALSE;\r
+  Status = Http->Request (\r
+                   Http,\r
+                   &HttpIo->ReqToken\r
+                   );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Poll the network until transmit finish.\r
+  //\r
+  while (!HttpIo->IsTxDone) {\r
+    Http->Poll (Http);\r
+  }\r
+\r
+  return HttpIo->ReqToken.Status;\r
+}\r
+\r
+/**\r
+  Synchronously receive a HTTP RESPONSE message from the server.\r
+\r
+  @param[in]   HttpIo           The HttpIo wrapping the HTTP service.\r
+  @param[in]   RecvMsgHeader    TRUE to receive a new HTTP response (from message header).\r
+                                FALSE to continue receive the previous response message.\r
+  @param[out]  ResponseData     Point to a wrapper of the received response data.\r
+\r
+  @retval EFI_SUCCESS            The HTTP response is received.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+  @retval EFI_DEVICE_ERROR       An unexpected network or system error occurred.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpIoRecvResponse (\r
+  IN      HTTP_IO                  *HttpIo,\r
+  IN      BOOLEAN                  RecvMsgHeader,\r
+     OUT  HTTP_IO_RESPONSE_DATA    *ResponseData\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_HTTP_PROTOCOL          *Http;\r
+\r
+  if (HttpIo == NULL || HttpIo->Http == NULL || ResponseData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Start the timer, and wait Timeout seconds to receive the header packet.\r
+  //\r
+  Status = gBS->SetTimer (HttpIo->TimeoutEvent, TimerRelative, HTTP_BOOT_RESPONSE_TIMEOUT * TICKS_PER_MS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Queue the response token to HTTP instances.\r
+  //\r
+  HttpIo->RspToken.Status  = EFI_NOT_READY;\r
+  if (RecvMsgHeader) {\r
+    HttpIo->RspToken.Message->Data.Response = &ResponseData->Response;\r
+  } else {\r
+    HttpIo->RspToken.Message->Data.Response = NULL;\r
+  }\r
+  HttpIo->RspToken.Message->HeaderCount   = 0;\r
+  HttpIo->RspToken.Message->Headers       = NULL;\r
+  HttpIo->RspToken.Message->BodyLength    = ResponseData->BodyLength;\r
+  HttpIo->RspToken.Message->Body          = ResponseData->Body;\r
+\r
+  Http = HttpIo->Http;\r
+  HttpIo->IsRxDone = FALSE;\r
+  Status = Http->Response (\r
+                   Http,\r
+                   &HttpIo->RspToken\r
+                   );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->SetTimer (HttpIo->TimeoutEvent, TimerCancel, 0);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Poll the network until receive finish.\r
+  //\r
+  while (!HttpIo->IsRxDone && ((HttpIo->TimeoutEvent == NULL) || EFI_ERROR (gBS->CheckEvent (HttpIo->TimeoutEvent)))) {\r
+    Http->Poll (Http);\r
+  }\r
+\r
+  gBS->SetTimer (HttpIo->TimeoutEvent, TimerCancel, 0);\r
+\r
+  if (!HttpIo->IsRxDone) {\r
+    //\r
+    // Timeout occurs, cancel the response token.\r
+    //\r
+    Http->Cancel (Http, &HttpIo->RspToken);\r
+\r
+    Status = EFI_TIMEOUT;\r
+\r
+    return Status;\r
+  } else {\r
+    HttpIo->IsRxDone = FALSE;\r
+  }\r
+\r
+  if ((HttpIo->Callback != NULL) &&\r
+      (HttpIo->RspToken.Status == EFI_SUCCESS || HttpIo->RspToken.Status == EFI_HTTP_ERROR)) {\r
+    Status = HttpIo->Callback (\r
+               HttpIoResponse,\r
+               HttpIo->RspToken.Message,\r
+               HttpIo->Context\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Store the received data into the wrapper.\r
+  //\r
+  ResponseData->Status = HttpIo->RspToken.Status;\r
+  ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;\r
+  ResponseData->Headers     = HttpIo->RspToken.Message->Headers;\r
+  ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function checks the HTTP(S) URI scheme.\r
+\r
+  @param[in]    Uri              The pointer to the URI string.\r
+\r
+  @retval EFI_SUCCESS            The URI scheme is valid.\r
+  @retval EFI_INVALID_PARAMETER  The URI scheme is not HTTP or HTTPS.\r
+  @retval EFI_ACCESS_DENIED      HTTP is disabled and the URI is HTTP.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootCheckUriScheme (\r
+  IN      CHAR8                  *Uri\r
+  )\r
+{\r
+  UINTN                Index;\r
+  EFI_STATUS           Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // Convert the scheme to all lower case.\r
+  //\r
+  for (Index = 0; Index < AsciiStrLen (Uri); Index++) {\r
+    if (Uri[Index] == ':') {\r
+      break;\r
+    }\r
+    if (Uri[Index] >= 'A' && Uri[Index] <= 'Z') {\r
+      Uri[Index] -= (CHAR8)('A' - 'a');\r
+    }\r
+  }\r
+\r
+  //\r
+  // Return EFI_INVALID_PARAMETER if the URI is not HTTP or HTTPS.\r
+  //\r
+  if ((AsciiStrnCmp (Uri, "http://", 7) != 0) && (AsciiStrnCmp (Uri, "https://", 8) != 0)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootCheckUriScheme: Invalid Uri.\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // HTTP is disabled, return EFI_ACCESS_DENIED if the URI is HTTP.\r
+  //\r
+  if (!PcdGetBool (PcdAllowHttpConnections) && (AsciiStrnCmp (Uri, "http://", 7) == 0)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootCheckUriScheme: HTTP is disabled.\n"));\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Get the URI address string from the input device path.\r
+\r
+  Caller need to free the buffer in the UriAddress pointer.\r
+\r
+  @param[in]   FilePath         Pointer to the device path which contains a URI device path node.\r
+  @param[out]  UriAddress       The URI address string extract from the device path.\r
+\r
+  @retval EFI_SUCCESS            The URI string is returned.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootParseFilePath (\r
+  IN     EFI_DEVICE_PATH_PROTOCOL     *FilePath,\r
+     OUT CHAR8                        **UriAddress\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  URI_DEVICE_PATH           *UriDevicePath;\r
+  CHAR8                     *Uri;\r
+  UINTN                     UriStrLength;\r
+\r
+  if (FilePath == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *UriAddress = NULL;\r
+\r
+  //\r
+  // Extract the URI address from the FilePath\r
+  //\r
+  TempDevicePath = FilePath;\r
+  while (!IsDevicePathEnd (TempDevicePath)) {\r
+    if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
+        (DevicePathSubType (TempDevicePath) == MSG_URI_DP)) {\r
+      UriDevicePath = (URI_DEVICE_PATH*) TempDevicePath;\r
+      //\r
+      // UEFI Spec doesn't require the URI to be a NULL-terminated string\r
+      // So we allocate a new buffer and always append a '\0' to it.\r
+      //\r
+      UriStrLength = DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
+      if (UriStrLength == 0) {\r
+        //\r
+        // return a NULL UriAddress if it's a empty URI device path node.\r
+        //\r
+        break;\r
+      }\r
+      Uri = AllocatePool (UriStrLength + 1);\r
+      if (Uri == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      CopyMem (Uri, UriDevicePath->Uri, DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL));\r
+      Uri[DevicePathNodeLength (UriDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL)] = '\0';\r
+\r
+      *UriAddress = Uri;\r
+    }\r
+    TempDevicePath = NextDevicePathNode (TempDevicePath);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function returns the image type according to server replied HTTP message\r
+  and also the image's URI info.\r
+\r
+  @param[in]    Uri              The pointer to the image's URI string.\r
+  @param[in]    UriParser        URI Parse result returned by NetHttpParseUrl().\r
+  @param[in]    HeaderCount      Number of HTTP header structures in Headers list.\r
+  @param[in]    Headers          Array containing list of HTTP headers.\r
+  @param[out]   ImageType        The image type of the downloaded file.\r
+\r
+  @retval EFI_SUCCESS            The image type is returned in ImageType.\r
+  @retval EFI_INVALID_PARAMETER  ImageType, Uri or UriParser is NULL.\r
+  @retval EFI_INVALID_PARAMETER  HeaderCount is not zero, and Headers is NULL.\r
+  @retval EFI_NOT_FOUND          Failed to identify the image type.\r
+  @retval Others                 Unexpect error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootCheckImageType (\r
+  IN      CHAR8                  *Uri,\r
+  IN      VOID                   *UriParser,\r
+  IN      UINTN                  HeaderCount,\r
+  IN      EFI_HTTP_HEADER        *Headers,\r
+     OUT  HTTP_BOOT_IMAGE_TYPE   *ImageType\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_HTTP_HEADER       *Header;\r
+  CHAR8                 *FilePath;\r
+  CHAR8                 *FilePost;\r
+\r
+  if (Uri == NULL || UriParser == NULL || ImageType == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (HeaderCount != 0 && Headers == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Determine the image type by the HTTP Content-Type header field first.\r
+  //   "application/efi"         -> EFI Image\r
+  //   "application/vnd.efi-iso" -> CD/DVD Image\r
+  //   "application/vnd.efi-img" -> Virtual Disk Image\r
+  //\r
+  Header = HttpFindHeader (HeaderCount, Headers, HTTP_HEADER_CONTENT_TYPE);\r
+  if (Header != NULL) {\r
+    if (AsciiStriCmp (Header->FieldValue, HTTP_CONTENT_TYPE_APP_EFI) == 0) {\r
+      *ImageType = ImageTypeEfi;\r
+      return EFI_SUCCESS;\r
+    } else if (AsciiStriCmp (Header->FieldValue, HTTP_CONTENT_TYPE_APP_ISO) == 0) {\r
+      *ImageType = ImageTypeVirtualCd;\r
+      return EFI_SUCCESS;\r
+    } else if (AsciiStriCmp (Header->FieldValue, HTTP_CONTENT_TYPE_APP_IMG) == 0) {\r
+      *ImageType = ImageTypeVirtualDisk;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Determine the image type by file extension:\r
+  //   *.efi -> EFI Image\r
+  //   *.iso -> CD/DVD Image\r
+  //   *.img -> Virtual Disk Image\r
+  //\r
+  Status = HttpUrlGetPath (\r
+             Uri,\r
+             UriParser,\r
+             &FilePath\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  FilePost = FilePath + AsciiStrLen (FilePath) - 4;\r
+  if (AsciiStrCmp (FilePost, ".efi") == 0) {\r
+    *ImageType = ImageTypeEfi;\r
+  } else if (AsciiStrCmp (FilePost, ".iso") == 0) {\r
+    *ImageType = ImageTypeVirtualCd;\r
+  } else if (AsciiStrCmp (FilePost, ".img") == 0) {\r
+    *ImageType = ImageTypeVirtualDisk;\r
+  } else {\r
+    *ImageType = ImageTypeMax;\r
+  }\r
+\r
+  FreePool (FilePath);\r
+\r
+  return (*ImageType < ImageTypeMax) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+  This function register the RAM disk info to the system.\r
+\r
+  @param[in]       Private         The pointer to the driver's private data.\r
+  @param[in]       BufferSize      The size of Buffer in bytes.\r
+  @param[in]       Buffer          The base address of the RAM disk.\r
+  @param[in]       ImageType       The image type of the file in Buffer.\r
+\r
+  @retval EFI_SUCCESS              The RAM disk has been registered.\r
+  @retval EFI_NOT_FOUND            No RAM disk protocol instances were found.\r
+  @retval EFI_UNSUPPORTED          The ImageType is not supported.\r
+  @retval Others                   Unexpected error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootRegisterRamDisk (\r
+  IN  HTTP_BOOT_PRIVATE_DATA       *Private,\r
+  IN  UINTN                        BufferSize,\r
+  IN  VOID                         *Buffer,\r
+  IN  HTTP_BOOT_IMAGE_TYPE         ImageType\r
+  )\r
+{\r
+  EFI_RAM_DISK_PROTOCOL      *RamDisk;\r
+  EFI_STATUS                 Status;\r
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath;\r
+  EFI_GUID                   *RamDiskType;\r
+\r
+  ASSERT (Private != NULL);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (BufferSize != 0);\r
+\r
+  Status = gBS->LocateProtocol (&gEfiRamDiskProtocolGuid, NULL, (VOID**) &RamDisk);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "HTTP Boot: Couldn't find the RAM Disk protocol - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  if (ImageType == ImageTypeVirtualCd) {\r
+    RamDiskType = &gEfiVirtualCdGuid;\r
+  } else if (ImageType == ImageTypeVirtualDisk) {\r
+    RamDiskType = &gEfiVirtualDiskGuid;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = RamDisk->Register (\r
+             (UINTN)Buffer,\r
+             (UINT64)BufferSize,\r
+             RamDiskType,\r
+             Private->UsingIpv6 ? Private->Ip6Nic->DevicePath : Private->Ip4Nic->DevicePath,\r
+             &DevicePath\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "HTTP Boot: Failed to register RAM Disk - %r\n", Status));\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Indicate if the HTTP status code indicates a redirection.\r
+\r
+  @param[in]  StatusCode      HTTP status code from server.\r
+\r
+  @return                     TRUE if it's redirection.\r
+\r
+**/\r
+BOOLEAN\r
+HttpBootIsHttpRedirectStatusCode (\r
+  IN   EFI_HTTP_STATUS_CODE        StatusCode\r
+  )\r
+{\r
+  if (StatusCode == HTTP_STATUS_301_MOVED_PERMANENTLY ||\r
+      StatusCode == HTTP_STATUS_302_FOUND ||\r
+      StatusCode == HTTP_STATUS_307_TEMPORARY_REDIRECT ||\r
+      StatusCode == HTTP_STATUS_308_PERMANENT_REDIRECT) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r