public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch 0/2] Add HTTP Boot Callback Protocol support.
@ 2017-06-14  9:36 Fu Siyuan
  2017-06-14  9:36 ` [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7 Fu Siyuan
  2017-06-14  9:36 ` [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support Fu Siyuan
  0 siblings, 2 replies; 5+ messages in thread
From: Fu Siyuan @ 2017-06-14  9:36 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ye Ting, Wu Jiaxin

Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>

Fu Siyuan (2):
  MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7.
  NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support.

 MdePkg/Include/Protocol/HttpBootCallback.h | 100 +++++++++++++
 MdePkg/MdePkg.dec                          |   7 +-
 NetworkPkg/HttpBootDxe/HttpBootClient.c    |  67 ++++++++-
 NetworkPkg/HttpBootDxe/HttpBootClient.h    |   4 +-
 NetworkPkg/HttpBootDxe/HttpBootDhcp4.c     |  26 +++-
 NetworkPkg/HttpBootDxe/HttpBootDhcp6.c     | 106 ++++++++------
 NetworkPkg/HttpBootDxe/HttpBootDxe.h       |  14 ++
 NetworkPkg/HttpBootDxe/HttpBootDxe.inf     |   3 +-
 NetworkPkg/HttpBootDxe/HttpBootImpl.c      | 221 +++++++++++++++++++++++++++--
 NetworkPkg/HttpBootDxe/HttpBootImpl.h      |   2 +
 NetworkPkg/HttpBootDxe/HttpBootSupport.c   |  29 ++++
 NetworkPkg/HttpBootDxe/HttpBootSupport.h   |  34 +++++
 12 files changed, 551 insertions(+), 62 deletions(-)
 create mode 100644 MdePkg/Include/Protocol/HttpBootCallback.h

-- 
2.13.0.windows.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7.
  2017-06-14  9:36 [Patch 0/2] Add HTTP Boot Callback Protocol support Fu Siyuan
@ 2017-06-14  9:36 ` Fu Siyuan
  2017-06-15  7:59   ` Wu, Jiaxin
  2017-06-14  9:36 ` [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support Fu Siyuan
  1 sibling, 1 reply; 5+ messages in thread
From: Fu Siyuan @ 2017-06-14  9:36 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ye Ting, Wu Jiaxin

Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
---
 MdePkg/Include/Protocol/HttpBootCallback.h | 100 +++++++++++++++++++++++++++++
 MdePkg/MdePkg.dec                          |   7 +-
 2 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 MdePkg/Include/Protocol/HttpBootCallback.h

diff --git a/MdePkg/Include/Protocol/HttpBootCallback.h b/MdePkg/Include/Protocol/HttpBootCallback.h
new file mode 100644
index 0000000000..7542b30e03
--- /dev/null
+++ b/MdePkg/Include/Protocol/HttpBootCallback.h
@@ -0,0 +1,100 @@
+/** @file
+  This file defines the EFI HTTP Boot Callback Protocol interface.
+
+  Copyright (c) 2017, 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
+  which 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.
+
+  @par Revision Reference:
+  This Protocol is introduced in UEFI Specification 2.7
+
+**/
+
+#ifndef __EFI_HTTP_BOOT_CALLBACK_H__
+#define __EFI_HTTP_BOOT_CALLBACK_H__
+
+#define EFI_HTTP_BOOT_CALLBACK_PROTOCOL_GUID \
+  { \
+    0xba23b311, 0x343d, 0x11e6, {0x91, 0x85, 0x58, 0x20, 0xb1, 0xd6, 0x52, 0x99} \
+  }
+
+typedef struct _EFI_HTTP_BOOT_CALLBACK_PROTOCOL  EFI_HTTP_BOOT_CALLBACK_PROTOCOL;
+
+///
+/// EFI_HTTP_BOOT_CALLBACK_DATA_TYPE
+///
+typedef enum {
+  ///
+  /// Data points to a DHCP4 packet which is about to transmit or has received.
+  ///
+  HttpBootDhcp4,
+  ///
+  /// Data points to a DHCP6 packet which is about to be transmit or has received.
+  ///
+  HttpBootDhcp6,
+  ///
+  /// Data points to an EFI_HTTP_MESSAGE structure, whichcontians a HTTP request message
+  /// to be transmitted.
+  ///
+  HttpBootHttpRequest,
+  ///
+  /// Data points to an EFI_HTTP_MESSAGE structure, which contians a received HTTP 
+  /// response message.
+  ///
+  HttpBootHttpResponse,
+  ///
+  /// Part of the entity body has been received from the HTTP server. Data points to the
+  /// buffer of the entity body data.
+  ///
+  HttpBootHttpEntityBody,
+  HttpBootTypeMax
+} EFI_HTTP_BOOT_CALLBACK_DATA_TYPE;
+
+/**
+  Callback function that is invoked when the HTTP Boot driver is about to transmit or has received a
+  packet.
+
+  This function is invoked when the HTTP Boot driver is about to transmit or has received packet.
+  Parameters DataType and Received specify the type of event and the format of the buffer pointed
+  to by Data. Due to the polling nature of UEFI device drivers, this callback function should not
+  execute for more than 5 ms.
+  The returned status code determines the behavior of the HTTP Boot driver.
+
+  @param[in]  This                Pointer to the EFI_HTTP_BOOT_CALLBACK_PROTOCOL instance.
+  @param[in]  DataType            The event that occurs in the current state.
+  @param[in]  Received            TRUE if the callback is being invoked due to a receive event.
+                                  FALSE if the callback is being invoked due to a transmit event.
+  @param[in]  DataLength          The length in bytes of the buffer pointed to by Data.
+  @param[in]  Data                A pointer to the buffer of data, the data type is specified by
+                                  DataType.
+                                  
+  @retval EFI_SUCCESS             Tells the HTTP Boot driver to continue the HTTP Boot process.
+  @retval EFI_ABORTED             Tells the HTTP Boot driver to abort the current HTTP Boot process.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * EFI_HTTP_BOOT_CALLBACK) (
+  IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL    *This,
+  IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE   DataType,
+  IN BOOLEAN                            Received,
+  IN UINT32                             DataLength,
+  IN VOID                               *Data   OPTIONAL
+ );
+
+///
+/// EFI HTTP Boot Callback Protocol is invoked when the HTTP Boot driver is about to transmit or 
+/// has received a packet. The EFI HTTP Boot Callback Protocol must be installed on the same handle
+/// as the Load File Protocol for the HTTP Boot.
+///
+struct _EFI_HTTP_BOOT_CALLBACK_PROTOCOL {
+  EFI_HTTP_BOOT_CALLBACK Callback;
+};
+
+extern EFI_GUID gEfiHttpBootCallbackProtocolGuid;
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 7a7504b7a3..a55e8ce1d9 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -2,7 +2,7 @@
 # This Package provides all definitions, library classes and libraries instances.
 #
 # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of
-# EFI1.10/UEFI2.6/PI1.4 and some Industry Standards.
+# EFI1.10/UEFI2.7/PI1.4 and some Industry Standards.
 #
 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
@@ -1671,6 +1671,9 @@
   ## Include/Protocol/BluetoothLeConfig.h
   gEfiBluetoothLeConfigProtocolGuid         = { 0x8f76da58, 0x1f99, 0x4275, { 0xa4, 0xec, 0x47, 0x56, 0x51, 0x5b, 0x1c, 0xe8 } }
 
+  ## Include/Protocol/HttpBootCallback.h
+  gEfiHttpBootCallbackProtocolGuid   = {0xba23b311, 0x343d, 0x11e6, {0x91, 0x85, 0x58, 0x20, 0xb1, 0xd6, 0x52, 0x99}}
+
   #
   # Protocols defined in Shell2.0
   #
@@ -1685,7 +1688,7 @@
   #
   ## Include/Protocol/ShellDynamicCommand.h
   gEfiShellDynamicCommandProtocolGuid  = { 0x3c7200e9, 0x005f, 0x4ea4, {0x87, 0xde, 0xa3, 0xdf, 0xac, 0x8a, 0x27, 0xc3 }}
-
+  
 #
 # [Error.gEfiMdePkgTokenSpaceGuid]
 #   0x80000001 | Invalid value provided.
-- 
2.13.0.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support.
  2017-06-14  9:36 [Patch 0/2] Add HTTP Boot Callback Protocol support Fu Siyuan
  2017-06-14  9:36 ` [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7 Fu Siyuan
@ 2017-06-14  9:36 ` Fu Siyuan
  2017-06-15  7:59   ` Wu, Jiaxin
  1 sibling, 1 reply; 5+ messages in thread
From: Fu Siyuan @ 2017-06-14  9:36 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ye Ting, Wu Jiaxin

This patch updates the HTTP Boot driver to install a default HTTP Callback protocol
if the platform doesn't provide one. This callback implementation will print the
boot file download progress in percentage format.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootClient.c  |  67 +++++++++-
 NetworkPkg/HttpBootDxe/HttpBootClient.h  |   4 +-
 NetworkPkg/HttpBootDxe/HttpBootDhcp4.c   |  26 +++-
 NetworkPkg/HttpBootDxe/HttpBootDhcp6.c   | 106 +++++++++------
 NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  14 ++
 NetworkPkg/HttpBootDxe/HttpBootDxe.inf   |   3 +-
 NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 221 +++++++++++++++++++++++++++++--
 NetworkPkg/HttpBootDxe/HttpBootImpl.h    |   2 +
 NetworkPkg/HttpBootDxe/HttpBootSupport.c |  29 ++++
 NetworkPkg/HttpBootDxe/HttpBootSupport.h |  34 +++++
 10 files changed, 446 insertions(+), 60 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootDxe/HttpBootClient.c
index 99db3d5505..68f5a49bad 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
@@ -233,7 +233,6 @@ HttpBootDhcp4ExtractUriInfo (
   //
   // All boot informations are valid here.
   //
-  AsciiPrint ("\n  URI: %a", Private->BootFileUri);
 
   //
   // Update the device path to include the IP and boot URI information.
@@ -401,7 +400,7 @@ HttpBootDhcp6ExtractUriInfo (
   //
   // All boot informations are valid here.
   //
-  AsciiPrint ("\n  URI: %a", Private->BootFileUri);
+
   //
   // Update the device path to include the IP and boot URI information.
   //
@@ -452,6 +451,40 @@ HttpBootDiscoverBootInfo (
 }
 
 /**
+  HttpIo Callback function which will be invoked when specified HTTP_IO_CALLBACK_EVENT happened.
+
+  @param[in]    EventType      Indicate the Event type that occurs in the current callback.
+  @param[in]    Message        HTTP message which will be send to, or just received from HTTP server.
+  @param[in]    Context        The Callback Context pointer.
+  
+  @retval EFI_SUCCESS          Tells the HttpIo to continue the HTTP process.
+  @retval Others               Tells the HttpIo to abort the current HTTP process.
+**/
+EFI_STATUS
+EFIAPI
+HttpBootHttpIoCallback (
+  IN  HTTP_IO_CALLBACK_EVENT    EventType,
+  IN  EFI_HTTP_MESSAGE          *Message,
+  IN  VOID                      *Context
+  )
+{
+  HTTP_BOOT_PRIVATE_DATA       *Private;
+  EFI_STATUS                   Status;
+  Private = (HTTP_BOOT_PRIVATE_DATA *) Context;
+  if (Private->HttpBootCallback != NULL) {
+    Status = Private->HttpBootCallback->Callback (
+               Private->HttpBootCallback,
+               EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse,
+               EventType == HttpIoRequest ? FALSE : TRUE,
+               sizeof (EFI_HTTP_MESSAGE),
+               (VOID *) Message
+               );
+    return Status;
+  }
+  return EFI_SUCCESS;
+}
+
+/**
   Create a HttpIo instance for the file download.
 
   @param[in]    Private        The pointer to the driver's private data.
@@ -490,6 +523,8 @@ HttpBootCreateHttpIo (
              Private->Controller,
              Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4,
              &ConfigData,
+             HttpBootHttpIoCallback,
+             (VOID *) Private,
              &Private->HttpIo
              );
   if (EFI_ERROR (Status)) {
@@ -686,6 +721,8 @@ HttpBootGetBootFileCallback (
 {
   HTTP_BOOT_CALLBACK_DATA      *CallbackData;
   HTTP_BOOT_ENTITY_DATA        *NewEntityData;
+  EFI_STATUS                   Status;
+  EFI_HTTP_BOOT_CALLBACK_PROTOCOL   *HttpBootCallback;
 
   //
   // We only care about the entity data.
@@ -695,6 +732,19 @@ HttpBootGetBootFileCallback (
   }
 
   CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;
+  HttpBootCallback = CallbackData->Private->HttpBootCallback;
+  if (HttpBootCallback != NULL) {
+    Status = HttpBootCallback->Callback (
+               HttpBootCallback,
+               HttpBootHttpEntityBody,
+               TRUE,
+               (UINT32)Length,
+               Data
+               );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
   //
   // Copy data if caller has provided a buffer.
   //
@@ -977,6 +1027,7 @@ HttpBootGetBootFile (
   Context.Buffer     = Buffer;
   Context.BufferSize = *BufferSize;
   Context.Cache      = Cache;
+  Context.Private    = Private;
   Status = HttpInitMsgParser (
              HeaderOnly? HttpMethodHead : HttpMethodGet,
              ResponseData->Response.StatusCode,
@@ -1032,6 +1083,18 @@ HttpBootGetBootFile (
           goto ERROR_6;
         }
         ReceivedSize += ResponseBody.BodyLength;
+        if (Private->HttpBootCallback != NULL) {
+          Status = Private->HttpBootCallback->Callback (
+                     Private->HttpBootCallback,
+                     HttpBootHttpEntityBody,
+                     TRUE,
+                     (UINT32)ResponseBody.BodyLength,
+                     ResponseBody.Body
+                     );
+          if (EFI_ERROR (Status)) {
+            goto ERROR_6;
+          }
+        }
       }
     } else {
       //
diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.h b/NetworkPkg/HttpBootDxe/HttpBootClient.h
index 2c32341460..dd58719b40 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.h
@@ -1,7 +1,7 @@
 /** @file
   Declaration of the boot file download function.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<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.  
@@ -64,6 +64,8 @@ typedef struct {
   UINTN                      CopyedSize;
   UINTN                      BufferSize;
   UINT8                      *Buffer;
+
+  HTTP_BOOT_PRIVATE_DATA     *Private;
 } HTTP_BOOT_CALLBACK_DATA;
 
 /**
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
index fcea916225..a8cee04c25 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
@@ -1,7 +1,7 @@
 /** @file
   Functions implementation related with DHCPv4 for HTTP boot driver.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, 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
@@ -609,8 +609,13 @@ HttpBootDhcp4CallBack (
   EFI_DHCP4_PACKET_OPTION              *MaxMsgSize;
   UINT16                               Value;
   EFI_STATUS                           Status;
+  BOOLEAN                              Received;
 
-  if ((Dhcp4Event != Dhcp4RcvdOffer) && (Dhcp4Event != Dhcp4SelectOffer)) {
+  if ((Dhcp4Event != Dhcp4SendDiscover) && 
+      (Dhcp4Event != Dhcp4RcvdOffer) && 
+      (Dhcp4Event != Dhcp4SendRequest) && 
+      (Dhcp4Event != Dhcp4RcvdAck) && 
+      (Dhcp4Event != Dhcp4SelectOffer)) {
     return EFI_SUCCESS;
   }
   
@@ -628,6 +633,23 @@ HttpBootDhcp4CallBack (
     Value = HTONS (HTTP_BOOT_DHCP4_PACKET_MAX_SIZE);
     CopyMem (MaxMsgSize->Data, &Value, sizeof (Value));
   }
+  
+  //
+  // Callback to user if any packets sent or received.
+  //
+  if (Private->HttpBootCallback != NULL && Dhcp4Event != Dhcp4SelectOffer) {
+    Received = (BOOLEAN) (Dhcp4Event == Dhcp4RcvdOffer || Dhcp4Event == Dhcp4RcvdAck);
+    Status = Private->HttpBootCallback->Callback (
+               Private->HttpBootCallback, 
+               HttpBootDhcp4,
+               Received,
+               Packet->Length,
+               &Packet->Dhcp4
+               );
+    if (EFI_ERROR (Status)) {
+      return EFI_ABORTED;
+    }
+  }
 
   Status = EFI_SUCCESS;
   switch (Dhcp4Event) {
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c b/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
index f2b81957b7..4eea895368 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
@@ -1,7 +1,7 @@
 /** @file
   Functions implementation related with DHCPv6 for HTTP boot driver.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, 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
@@ -431,56 +431,78 @@ HttpBootDhcp6CallBack (
   OUT EFI_DHCP6_PACKET             **NewPacket     OPTIONAL
   )
 {
-   HTTP_BOOT_PRIVATE_DATA          *Private;
-   EFI_DHCP6_PACKET                *SelectAd;
-   EFI_STATUS                      Status;
+  HTTP_BOOT_PRIVATE_DATA          *Private;
+  EFI_DHCP6_PACKET                *SelectAd;
+  EFI_STATUS                      Status;
+  BOOLEAN                         Received;
+  
+  if ((Dhcp6Event != Dhcp6SendSolicit) &&
+    (Dhcp6Event != Dhcp6RcvdAdvertise) &&
+    (Dhcp6Event != Dhcp6SendRequest) &&
+    (Dhcp6Event != Dhcp6RcvdReply) &&
+    (Dhcp6Event != Dhcp6SelectAdvertise)) {
+    return EFI_SUCCESS;
+  }
 
-   ASSERT (Packet != NULL);
+  ASSERT (Packet != NULL);
+  
+  Private     = (HTTP_BOOT_PRIVATE_DATA *) Context;
+  Status = EFI_SUCCESS;
+  if (Private->HttpBootCallback != NULL && Dhcp6Event != Dhcp6SelectAdvertise) {
+    Received = (BOOLEAN) (Dhcp6Event == Dhcp6RcvdAdvertise || Dhcp6Event == Dhcp6RcvdReply);
+    Status = Private->HttpBootCallback->Callback (
+               Private->HttpBootCallback, 
+               HttpBootDhcp6,
+               Received,
+               Packet->Length,
+               &Packet->Dhcp6
+               );
+    if (EFI_ERROR (Status)) {
+      return EFI_ABORTED;
+    }
+  }
+  switch (Dhcp6Event) {
    
-   Private     = (HTTP_BOOT_PRIVATE_DATA *) Context;
-   Status = EFI_SUCCESS;
-   switch (Dhcp6Event) {
-    
-   case Dhcp6RcvdAdvertise:
-     Status = EFI_NOT_READY;
+  case Dhcp6RcvdAdvertise:
+    Status = EFI_NOT_READY;
     if (Packet->Length > HTTP_BOOT_DHCP6_PACKET_MAX_SIZE) {
       //
       // Ignore the incoming packets which exceed the maximum length.
       //
       break;
     }
-     if (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM) {
-       //
-       // Cache the dhcp offers to OfferBuffer[] for select later, and record
-       // the OfferIndex and OfferCount.
-       // If error happens, just ignore this packet and continue to wait more offer.
-       //
-       HttpBootCacheDhcp6Offer (Private, Packet);
-     }
-     break;
-
-   case Dhcp6SelectAdvertise:
-     //
-     // Select offer by the default policy or by order, and record the SelectIndex
-     // and SelectProxyType.
-     //
-     HttpBootSelectDhcpOffer (Private);
-
-     if (Private->SelectIndex == 0) {
-       Status = EFI_ABORTED;
-     } else {
-       ASSERT (NewPacket != NULL);
-       SelectAd   = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;
-       *NewPacket = AllocateZeroPool (SelectAd->Size);
-       if (*NewPacket == NULL) {
-         return EFI_OUT_OF_RESOURCES;
-       }
-       CopyMem (*NewPacket, SelectAd, SelectAd->Size);
-     }
-     break;
+    if (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM) {
+      //
+      // Cache the dhcp offers to OfferBuffer[] for select later, and record
+      // the OfferIndex and OfferCount.
+      // If error happens, just ignore this packet and continue to wait more offer.
+      //
+      HttpBootCacheDhcp6Offer (Private, Packet);
+    }
+    break;
+
+  case Dhcp6SelectAdvertise:
+    //
+    // Select offer by the default policy or by order, and record the SelectIndex
+    // and SelectProxyType.
+    //
+    HttpBootSelectDhcpOffer (Private);
+
+    if (Private->SelectIndex == 0) {
+      Status = EFI_ABORTED;
+    } else {
+      ASSERT (NewPacket != NULL);
+      SelectAd   = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;
+      *NewPacket = AllocateZeroPool (SelectAd->Size);
+      if (*NewPacket == NULL) {
+        return EFI_OUT_OF_RESOURCES;
+      }
+      CopyMem (*NewPacket, SelectAd, SelectAd->Size);
+    }
+    break;
      
-   default:
-     break;
+  default:
+    break;
   }
 
   return Status;   
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index a1e6792514..235bf37b78 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
@@ -62,6 +62,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 // Produced Protocols
 //
 #include <Protocol/LoadFile.h>
+#include <Protocol/HttpBootCallback.h>
 
 //
 // Consumed Guids
@@ -133,6 +134,14 @@ struct _HTTP_BOOT_VIRTUAL_NIC {
   CallbackInfo, \
   HTTP_BOOT_PRIVATE_DATA_SIGNATURE \
   )
+  
+#define HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL(CallbackProtocol) \
+    CR ( \
+    CallbackProtocol, \
+    HTTP_BOOT_PRIVATE_DATA, \
+    LoadFileCallback, \
+    HTTP_BOOT_PRIVATE_DATA_SIGNATURE \
+    )
 
 struct _HTTP_BOOT_PRIVATE_DATA {
   UINT32                                    Signature;
@@ -168,6 +177,11 @@ struct _HTTP_BOOT_PRIVATE_DATA {
   EFI_LOAD_FILE_PROTOCOL                    LoadFile;
   EFI_DEVICE_PATH_PROTOCOL                  *DevicePath;
   UINT32                                    Id;
+  EFI_HTTP_BOOT_CALLBACK_PROTOCOL           *HttpBootCallback;
+  EFI_HTTP_BOOT_CALLBACK_PROTOCOL           LoadFileCallback;
+  UINTN                                     FileSize;
+  UINTN                                     ReceivedSize;
+  UINTN                                     Percentage;
 
   //
   // HII callback info block
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
index ec983ba7ad..4d6c5e5048 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
@@ -85,7 +85,8 @@
   gEfiNetworkInterfaceIdentifierProtocolGuid_31   ## SOMETIMES_CONSUMES
   gEfiRamDiskProtocolGuid                         ## SOMETIMES_CONSUMES
   gEfiHiiConfigAccessProtocolGuid                 ## BY_START
-
+  gEfiHttpBootCallbackProtocolGuid                ## SOMETIMES_PRODUCES
+  
 [Guids]
   ## SOMETIMES_CONSUMES ## GUID # HiiIsConfigHdrMatch   mHttpBootConfigStorageName
   ## SOMETIMES_PRODUCES ## GUID # HiiConstructConfigHdr mHttpBootConfigStorageName
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index cf6de80a17..809baeb879 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -16,6 +16,84 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "HttpBootDxe.h"
 
 /**
+  Install HTTP Boot Callback Protocol if not installed before.
+
+  @param[in] Private           Pointer to HTTP Boot private data.
+
+  @retval EFI_SUCCESS          HTTP Boot Callback Protocol installed succesfully.
+  @retval Others               Failed to install HTTP Boot Callback Protocol.
+
+**/
+EFI_STATUS
+HttpBootInstallCallback (
+  IN HTTP_BOOT_PRIVATE_DATA           *Private
+  )
+{
+  EFI_STATUS                  Status;
+  EFI_HANDLE                  ControllerHandle;
+
+  if (!Private->UsingIpv6) {
+    ControllerHandle = Private->Ip4Nic->Controller;
+  } else {
+    ControllerHandle = Private->Ip6Nic->Controller;
+  }
+
+  //
+  // Check whether gEfiHttpBootCallbackProtocolGuid already installed.
+  //
+  Status = gBS->HandleProtocol (
+                  ControllerHandle,
+                  &gEfiHttpBootCallbackProtocolGuid,
+                  (VOID **) &Private->HttpBootCallback
+                  );
+  if (Status == EFI_UNSUPPORTED) {
+
+    CopyMem (
+      &Private->LoadFileCallback,
+      &gHttpBootDxeHttpBootCallback,
+      sizeof (EFI_HTTP_BOOT_CALLBACK_PROTOCOL)
+      );
+
+    //
+    // Install a default callback if user didn't offer one.
+    //
+    Status = gBS->InstallProtocolInterface (
+                    &ControllerHandle,
+                    &gEfiHttpBootCallbackProtocolGuid,
+                    EFI_NATIVE_INTERFACE,
+                    &Private->LoadFileCallback
+                    );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+    Private->HttpBootCallback = &Private->LoadFileCallback;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Uninstall HTTP Boot Callback Protocol if it's installed by this driver.
+
+  @param[in] Private           Pointer to HTTP Boot private data.
+
+**/
+VOID
+HttpBootUninstallCallback (
+  IN HTTP_BOOT_PRIVATE_DATA           *Private
+  )
+{
+  if (Private->HttpBootCallback == &Private->LoadFileCallback) {
+    gBS->UninstallProtocolInterface (
+          Private->Controller,
+          &gEfiHttpBootCallbackProtocolGuid,
+          &Private->HttpBootCallback
+          );
+    Private->HttpBootCallback = NULL;
+  }
+}
+
+/**
   Enable the use of UEFI HTTP boot function.
 
   If the driver has already been started but not satisfy the requirement (IP stack and 
@@ -144,6 +222,7 @@ HttpBootStart (
     }
   }
   Private->Started   = TRUE;
+  Print (L"\n>>Start HTTP Boot over IPv%d", Private->UsingIpv6 ? 6 : 4);
 
   return EFI_SUCCESS;
 }
@@ -237,7 +316,10 @@ HttpBootLoadFile (
     return EFI_NOT_STARTED;
   }
 
-  Status = EFI_DEVICE_ERROR;
+  Status = HttpBootInstallCallback (Private);
+  if (EFI_ERROR(Status)) {
+    goto ON_EXIT;
+  }
 
   if (Private->BootFileUri == NULL) {
     //
@@ -245,7 +327,7 @@ HttpBootLoadFile (
     //
     Status = HttpBootDiscoverBootInfo (Private);
     if (EFI_ERROR (Status)) {
-      return Status;
+      goto ON_EXIT;
     }
   }
 
@@ -255,7 +337,7 @@ HttpBootLoadFile (
     //
     Status = HttpBootCreateHttpIo (Private);
     if (EFI_ERROR (Status)) {
-      return Status;
+      goto ON_EXIT;
     }
   }
 
@@ -287,7 +369,7 @@ HttpBootLoadFile (
                  &Private->ImageType
                  );
       if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
-        return Status;
+        goto ON_EXIT;
       }
     }
   }
@@ -295,19 +377,24 @@ HttpBootLoadFile (
   if (*BufferSize < Private->BootFileSize) {
     *BufferSize = Private->BootFileSize;
     *ImageType = Private->ImageType;
-    return EFI_BUFFER_TOO_SMALL;
+    Status = EFI_BUFFER_TOO_SMALL;
+    goto ON_EXIT;
   }
 
   //
   // Load the boot file into Buffer
   //
-  return  HttpBootGetBootFile (
-            Private,
-            FALSE,
-            BufferSize,
-            Buffer,
-            ImageType
-            );
+  Status = HttpBootGetBootFile (
+             Private,
+             FALSE,
+             BufferSize,
+             Buffer,
+             ImageType
+             );
+  
+ON_EXIT:
+  HttpBootUninstallCallback (Private);
+  return Status;
 }
 
 /**
@@ -520,3 +607,113 @@ GLOBAL_REMOVE_IF_UNREFERENCED
 EFI_LOAD_FILE_PROTOCOL  gHttpBootDxeLoadFile = {
   HttpBootDxeLoadFile
 };
+
+/**
+  Callback function that is invoked when the HTTP Boot driver is about to transmit or has received a
+  packet.
+
+  This function is invoked when the HTTP Boot driver is about to transmit or has received packet.
+  Parameters DataType and Received specify the type of event and the format of the buffer pointed
+  to by Data. Due to the polling nature of UEFI device drivers, this callback function should not
+  execute for more than 5 ms.
+  The returned status code determines the behavior of the HTTP Boot driver.
+
+  @param[in]  This                Pointer to the EFI_HTTP_BOOT_CALLBACK_PROTOCOL instance.
+  @param[in]  DataType            The event that occurs in the current state.
+  @param[in]  Received            TRUE if the callback is being invoked due to a receive event.
+                                  FALSE if the callback is being invoked due to a transmit event.
+  @param[in]  DataLength          The length in bytes of the buffer pointed to by Data.
+  @param[in]  Data                A pointer to the buffer of data, the data type is specified by
+                                  DataType.
+                                  
+  @retval EFI_SUCCESS             Tells the HTTP Boot driver to continue the HTTP Boot process.
+  @retval EFI_ABORTED             Tells the HTTP Boot driver to abort the current HTTP Boot process.
+**/
+EFI_STATUS
+HttpBootCallback (
+  IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL     *This,
+  IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE    DataType,
+  IN BOOLEAN                             Received,
+  IN UINT32                              DataLength,
+  IN VOID                                *Data     OPTIONAL
+  )
+{
+  EFI_HTTP_MESSAGE        *HttpMessage;
+  EFI_HTTP_HEADER         *HttpHeader;
+  HTTP_BOOT_PRIVATE_DATA  *Private;
+  UINTN                   Percentage;
+
+  Private = HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL(This);
+
+  switch (DataType) {
+  case HttpBootDhcp4:
+  case HttpBootDhcp6:
+    Print (L".");
+    break;
+
+  case HttpBootHttpRequest:
+    if (Data != NULL) {
+      HttpMessage = (EFI_HTTP_MESSAGE *) Data;
+      if (HttpMessage->Data.Request->Method == HttpMethodGet &&
+          HttpMessage->Data.Request->Url != NULL) {
+        Print (L"\n  URI: %s\n", HttpMessage->Data.Request->Url);
+      }
+    }
+    break;
+
+  case HttpBootHttpResponse:
+    if (Data != NULL) {
+      HttpMessage = (EFI_HTTP_MESSAGE *) Data;
+      HttpHeader = HttpFindHeader (
+                     HttpMessage->HeaderCount,
+                     HttpMessage->Headers,
+                     HTTP_HEADER_CONTENT_LENGTH
+                     );
+      if (HttpHeader != NULL) {
+        Private->FileSize = AsciiStrDecimalToUintn (HttpHeader->FieldValue);
+        Private->ReceivedSize = 0;
+        Private->Percentage   = 0;
+      }
+    }
+    break;
+
+  case HttpBootHttpEntityBody:
+    if (DataLength != 0) {
+      if (Private->FileSize != 0) {
+        //
+        // We already know the file size, print in percentage format.
+        //
+        if (Private->ReceivedSize == 0) {
+          Print (L"  File Size: %lu\n", Private->FileSize);
+        }
+        Private->ReceivedSize += DataLength;
+        Percentage = (Private->ReceivedSize * 100) / Private->FileSize;
+        if (Private->Percentage != Percentage) {
+          Private->Percentage = Percentage;
+          Print (L"\r  Downloading...%d%%", Percentage);
+        }
+      } else {
+        //
+        // In some case we couldn't get the file size from the HTTP header, so we
+        // just print the downloaded file size.
+        //
+        Private->ReceivedSize += DataLength;
+        Print (L"\r  Downloading...%d Bytes", Private->ReceivedSize);
+      }
+    }
+    break;
+
+  default:
+    break;
+  };
+
+  return EFI_SUCCESS;
+}
+
+///
+/// HTTP Boot Callback Protocol instance
+///
+GLOBAL_REMOVE_IF_UNREFERENCED 
+EFI_HTTP_BOOT_CALLBACK_PROTOCOL  gHttpBootDxeHttpBootCallback = {
+  HttpBootCallback
+};
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.h b/NetworkPkg/HttpBootDxe/HttpBootImpl.h
index 7066338175..da58bb6583 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.h
@@ -47,4 +47,6 @@ HttpBootStop (
   IN HTTP_BOOT_PRIVATE_DATA           *Private
   );
 
+extern EFI_HTTP_BOOT_CALLBACK_PROTOCOL  gHttpBootDxeHttpBootCallback;
+
 #endif
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index 8fe81eb8d9..5024f2e676 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
@@ -671,6 +671,9 @@ HttpIoNotify (
   @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[in]  Callback       Callback function which will be invoked when specified
+                             HTTP_IO_CALLBACK_EVENT happened.
+  @param[in]  Context        The Context data which will be passed to the Callback function.
   @param[out] HttpIo         The HTTP_IO.
   
   @retval EFI_SUCCESS            The HTTP_IO is created and configured.
@@ -687,6 +690,8 @@ HttpIoCreateIo (
   IN EFI_HANDLE             Controller,
   IN UINT8                  IpVersion,
   IN HTTP_IO_CONFIG_DATA    *ConfigData,
+  IN HTTP_IO_CALLBACK       Callback,
+  IN VOID                   *Context,
   OUT HTTP_IO               *HttpIo
   )
 {
@@ -739,6 +744,8 @@ HttpIoCreateIo (
   HttpIo->Controller  = Controller;
   HttpIo->IpVersion   = IpVersion;
   HttpIo->Http        = Http;
+  HttpIo->Callback    = Callback;
+  HttpIo->Context     = Context;
 
   ZeroMem (&HttpConfigData, sizeof (EFI_HTTP_CONFIG_DATA));
   HttpConfigData.HttpVersion        = HttpVersion11;
@@ -908,6 +915,17 @@ HttpIoSendRequest (
   HttpIo->ReqToken.Message->BodyLength   = BodyLength;
   HttpIo->ReqToken.Message->Body         = Body;
 
+  if (HttpIo->Callback != NULL) {
+    Status = HttpIo->Callback (
+               HttpIoRequest,
+               HttpIo->ReqToken.Message,
+               HttpIo->Context
+               );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
   //
   // Queue the request token to HTTP instances.
   //
@@ -1016,6 +1034,17 @@ HttpIoRecvResponse (
     HttpIo->IsRxDone = FALSE;
   }
 
+  if (!EFI_ERROR (HttpIo->RspToken.Status) && HttpIo->Callback != NULL) {
+    Status = HttpIo->Callback (
+               HttpIoResponse,
+               HttpIo->RspToken.Message,
+               HttpIo->Context
+               );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
   //
   // Store the received data into the wrapper.
   //
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
index 65302d2be2..f2b1846c05 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
@@ -145,6 +145,32 @@ HttpBootSetHeader (
   IN  CHAR8                *FieldValue
   );
 
+///
+/// HTTP_IO_CALLBACK_EVENT
+///
+typedef enum {
+  HttpIoRequest,
+  HttpIoResponse
+} HTTP_IO_CALLBACK_EVENT;
+
+/**
+  HttpIo Callback function which will be invoked when specified HTTP_IO_CALLBACK_EVENT happened.
+
+  @param[in]    EventType      Indicate the Event type that occurs in the current callback.
+  @param[in]    Message        HTTP message which will be send to, or just received from HTTP server.
+  @param[in]    Context        The Callback Context pointer.
+  
+  @retval EFI_SUCCESS          Tells the HttpIo to continue the HTTP process.
+  @retval Others               Tells the HttpIo to abort the current HTTP process.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * HTTP_IO_CALLBACK) (
+  IN  HTTP_IO_CALLBACK_EVENT    EventType,
+  IN  EFI_HTTP_MESSAGE          *Message,
+  IN  VOID                      *Context
+  );
+
 //
 // HTTP_IO configuration data for IPv4
 //
@@ -189,6 +215,9 @@ typedef struct {
   
   EFI_HTTP_PROTOCOL         *Http;
 
+  HTTP_IO_CALLBACK          Callback;
+  VOID                      *Context;
+
   EFI_HTTP_TOKEN            ReqToken;
   EFI_HTTP_MESSAGE          ReqMessage;
   EFI_HTTP_TOKEN            RspToken;
@@ -252,6 +281,9 @@ HttpBootCommonNotify (
   @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[in]  Callback       Callback function which will be invoked when specified
+                             HTTP_IO_CALLBACK_EVENT happened.
+  @param[in]  Context        The Context data which will be passed to the Callback function.
   @param[out] HttpIo         The HTTP_IO.
   
   @retval EFI_SUCCESS            The HTTP_IO is created and configured.
@@ -268,6 +300,8 @@ HttpIoCreateIo (
   IN EFI_HANDLE             Controller,
   IN UINT8                  IpVersion,
   IN HTTP_IO_CONFIG_DATA    *ConfigData,
+  IN HTTP_IO_CALLBACK       Callback,
+  IN VOID                   *Context,
   OUT HTTP_IO               *HttpIo
   );
 
-- 
2.13.0.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support.
  2017-06-14  9:36 ` [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support Fu Siyuan
@ 2017-06-15  7:59   ` Wu, Jiaxin
  0 siblings, 0 replies; 5+ messages in thread
From: Wu, Jiaxin @ 2017-06-15  7:59 UTC (permalink / raw)
  To: Fu, Siyuan, edk2-devel@lists.01.org; +Cc: Ye, Ting

Hi Siyuan,

In HttpBootCallback(), below output seems to be incorrect for the FileSize display in NT32, please check it.

Print (L"  File Size: %lu\n", Private->FileSize);

Print (L"\r  Downloading...%d Bytes", Private->ReceivedSize);

Thanks,
Jiaxin

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Fu
> Siyuan
> Sent: Wednesday, June 14, 2017 5:37 PM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [edk2] [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot
> Callback protocol support.
> 
> This patch updates the HTTP Boot driver to install a default HTTP Callback
> protocol
> if the platform doesn't provide one. This callback implementation will print
> the
> boot file download progress in percentage format.
> 
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
> ---
>  NetworkPkg/HttpBootDxe/HttpBootClient.c  |  67 +++++++++-
>  NetworkPkg/HttpBootDxe/HttpBootClient.h  |   4 +-
>  NetworkPkg/HttpBootDxe/HttpBootDhcp4.c   |  26 +++-
>  NetworkPkg/HttpBootDxe/HttpBootDhcp6.c   | 106 +++++++++------
>  NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  14 ++
>  NetworkPkg/HttpBootDxe/HttpBootDxe.inf   |   3 +-
>  NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 221
> +++++++++++++++++++++++++++++--
>  NetworkPkg/HttpBootDxe/HttpBootImpl.h    |   2 +
>  NetworkPkg/HttpBootDxe/HttpBootSupport.c |  29 ++++
>  NetworkPkg/HttpBootDxe/HttpBootSupport.h |  34 +++++
>  10 files changed, 446 insertions(+), 60 deletions(-)
> 
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c
> b/NetworkPkg/HttpBootDxe/HttpBootClient.c
> index 99db3d5505..68f5a49bad 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
> +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
> @@ -233,7 +233,6 @@ HttpBootDhcp4ExtractUriInfo (
>    //
>    // All boot informations are valid here.
>    //
> -  AsciiPrint ("\n  URI: %a", Private->BootFileUri);
> 
>    //
>    // Update the device path to include the IP and boot URI information.
> @@ -401,7 +400,7 @@ HttpBootDhcp6ExtractUriInfo (
>    //
>    // All boot informations are valid here.
>    //
> -  AsciiPrint ("\n  URI: %a", Private->BootFileUri);
> +
>    //
>    // Update the device path to include the IP and boot URI information.
>    //
> @@ -452,6 +451,40 @@ HttpBootDiscoverBootInfo (
>  }
> 
>  /**
> +  HttpIo Callback function which will be invoked when specified
> HTTP_IO_CALLBACK_EVENT happened.
> +
> +  @param[in]    EventType      Indicate the Event type that occurs in the
> current callback.
> +  @param[in]    Message        HTTP message which will be send to, or just
> received from HTTP server.
> +  @param[in]    Context        The Callback Context pointer.
> +
> +  @retval EFI_SUCCESS          Tells the HttpIo to continue the HTTP process.
> +  @retval Others               Tells the HttpIo to abort the current HTTP process.
> +**/
> +EFI_STATUS
> +EFIAPI
> +HttpBootHttpIoCallback (
> +  IN  HTTP_IO_CALLBACK_EVENT    EventType,
> +  IN  EFI_HTTP_MESSAGE          *Message,
> +  IN  VOID                      *Context
> +  )
> +{
> +  HTTP_BOOT_PRIVATE_DATA       *Private;
> +  EFI_STATUS                   Status;
> +  Private = (HTTP_BOOT_PRIVATE_DATA *) Context;
> +  if (Private->HttpBootCallback != NULL) {
> +    Status = Private->HttpBootCallback->Callback (
> +               Private->HttpBootCallback,
> +               EventType == HttpIoRequest ? HttpBootHttpRequest :
> HttpBootHttpResponse,
> +               EventType == HttpIoRequest ? FALSE : TRUE,
> +               sizeof (EFI_HTTP_MESSAGE),
> +               (VOID *) Message
> +               );
> +    return Status;
> +  }
> +  return EFI_SUCCESS;
> +}
> +
> +/**
>    Create a HttpIo instance for the file download.
> 
>    @param[in]    Private        The pointer to the driver's private data.
> @@ -490,6 +523,8 @@ HttpBootCreateHttpIo (
>               Private->Controller,
>               Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4,
>               &ConfigData,
> +             HttpBootHttpIoCallback,
> +             (VOID *) Private,
>               &Private->HttpIo
>               );
>    if (EFI_ERROR (Status)) {
> @@ -686,6 +721,8 @@ HttpBootGetBootFileCallback (
>  {
>    HTTP_BOOT_CALLBACK_DATA      *CallbackData;
>    HTTP_BOOT_ENTITY_DATA        *NewEntityData;
> +  EFI_STATUS                   Status;
> +  EFI_HTTP_BOOT_CALLBACK_PROTOCOL   *HttpBootCallback;
> 
>    //
>    // We only care about the entity data.
> @@ -695,6 +732,19 @@ HttpBootGetBootFileCallback (
>    }
> 
>    CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;
> +  HttpBootCallback = CallbackData->Private->HttpBootCallback;
> +  if (HttpBootCallback != NULL) {
> +    Status = HttpBootCallback->Callback (
> +               HttpBootCallback,
> +               HttpBootHttpEntityBody,
> +               TRUE,
> +               (UINT32)Length,
> +               Data
> +               );
> +    if (EFI_ERROR (Status)) {
> +      return Status;
> +    }
> +  }
>    //
>    // Copy data if caller has provided a buffer.
>    //
> @@ -977,6 +1027,7 @@ HttpBootGetBootFile (
>    Context.Buffer     = Buffer;
>    Context.BufferSize = *BufferSize;
>    Context.Cache      = Cache;
> +  Context.Private    = Private;
>    Status = HttpInitMsgParser (
>               HeaderOnly? HttpMethodHead : HttpMethodGet,
>               ResponseData->Response.StatusCode,
> @@ -1032,6 +1083,18 @@ HttpBootGetBootFile (
>            goto ERROR_6;
>          }
>          ReceivedSize += ResponseBody.BodyLength;
> +        if (Private->HttpBootCallback != NULL) {
> +          Status = Private->HttpBootCallback->Callback (
> +                     Private->HttpBootCallback,
> +                     HttpBootHttpEntityBody,
> +                     TRUE,
> +                     (UINT32)ResponseBody.BodyLength,
> +                     ResponseBody.Body
> +                     );
> +          if (EFI_ERROR (Status)) {
> +            goto ERROR_6;
> +          }
> +        }
>        }
>      } else {
>        //
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.h
> b/NetworkPkg/HttpBootDxe/HttpBootClient.h
> index 2c32341460..dd58719b40 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootClient.h
> +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Declaration of the boot file download function.
> 
> -Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
>  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<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.
> @@ -64,6 +64,8 @@ typedef struct {
>    UINTN                      CopyedSize;
>    UINTN                      BufferSize;
>    UINT8                      *Buffer;
> +
> +  HTTP_BOOT_PRIVATE_DATA     *Private;
>  } HTTP_BOOT_CALLBACK_DATA;
> 
>  /**
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
> b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
> index fcea916225..a8cee04c25 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
> +++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Functions implementation related with DHCPv4 for HTTP boot driver.
> 
> -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2015 - 2017, 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
> @@ -609,8 +609,13 @@ HttpBootDhcp4CallBack (
>    EFI_DHCP4_PACKET_OPTION              *MaxMsgSize;
>    UINT16                               Value;
>    EFI_STATUS                           Status;
> +  BOOLEAN                              Received;
> 
> -  if ((Dhcp4Event != Dhcp4RcvdOffer) && (Dhcp4Event != Dhcp4SelectOffer))
> {
> +  if ((Dhcp4Event != Dhcp4SendDiscover) &&
> +      (Dhcp4Event != Dhcp4RcvdOffer) &&
> +      (Dhcp4Event != Dhcp4SendRequest) &&
> +      (Dhcp4Event != Dhcp4RcvdAck) &&
> +      (Dhcp4Event != Dhcp4SelectOffer)) {
>      return EFI_SUCCESS;
>    }
> 
> @@ -628,6 +633,23 @@ HttpBootDhcp4CallBack (
>      Value = HTONS (HTTP_BOOT_DHCP4_PACKET_MAX_SIZE);
>      CopyMem (MaxMsgSize->Data, &Value, sizeof (Value));
>    }
> +
> +  //
> +  // Callback to user if any packets sent or received.
> +  //
> +  if (Private->HttpBootCallback != NULL && Dhcp4Event != Dhcp4SelectOffer)
> {
> +    Received = (BOOLEAN) (Dhcp4Event == Dhcp4RcvdOffer || Dhcp4Event
> == Dhcp4RcvdAck);
> +    Status = Private->HttpBootCallback->Callback (
> +               Private->HttpBootCallback,
> +               HttpBootDhcp4,
> +               Received,
> +               Packet->Length,
> +               &Packet->Dhcp4
> +               );
> +    if (EFI_ERROR (Status)) {
> +      return EFI_ABORTED;
> +    }
> +  }
> 
>    Status = EFI_SUCCESS;
>    switch (Dhcp4Event) {
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
> b/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
> index f2b81957b7..4eea895368 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
> +++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Functions implementation related with DHCPv6 for HTTP boot driver.
> 
> -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2015 - 2017, 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
> @@ -431,56 +431,78 @@ HttpBootDhcp6CallBack (
>    OUT EFI_DHCP6_PACKET             **NewPacket     OPTIONAL
>    )
>  {
> -   HTTP_BOOT_PRIVATE_DATA          *Private;
> -   EFI_DHCP6_PACKET                *SelectAd;
> -   EFI_STATUS                      Status;
> +  HTTP_BOOT_PRIVATE_DATA          *Private;
> +  EFI_DHCP6_PACKET                *SelectAd;
> +  EFI_STATUS                      Status;
> +  BOOLEAN                         Received;
> +
> +  if ((Dhcp6Event != Dhcp6SendSolicit) &&
> +    (Dhcp6Event != Dhcp6RcvdAdvertise) &&
> +    (Dhcp6Event != Dhcp6SendRequest) &&
> +    (Dhcp6Event != Dhcp6RcvdReply) &&
> +    (Dhcp6Event != Dhcp6SelectAdvertise)) {
> +    return EFI_SUCCESS;
> +  }
> 
> -   ASSERT (Packet != NULL);
> +  ASSERT (Packet != NULL);
> +
> +  Private     = (HTTP_BOOT_PRIVATE_DATA *) Context;
> +  Status = EFI_SUCCESS;
> +  if (Private->HttpBootCallback != NULL && Dhcp6Event !=
> Dhcp6SelectAdvertise) {
> +    Received = (BOOLEAN) (Dhcp6Event == Dhcp6RcvdAdvertise ||
> Dhcp6Event == Dhcp6RcvdReply);
> +    Status = Private->HttpBootCallback->Callback (
> +               Private->HttpBootCallback,
> +               HttpBootDhcp6,
> +               Received,
> +               Packet->Length,
> +               &Packet->Dhcp6
> +               );
> +    if (EFI_ERROR (Status)) {
> +      return EFI_ABORTED;
> +    }
> +  }
> +  switch (Dhcp6Event) {
> 
> -   Private     = (HTTP_BOOT_PRIVATE_DATA *) Context;
> -   Status = EFI_SUCCESS;
> -   switch (Dhcp6Event) {
> -
> -   case Dhcp6RcvdAdvertise:
> -     Status = EFI_NOT_READY;
> +  case Dhcp6RcvdAdvertise:
> +    Status = EFI_NOT_READY;
>      if (Packet->Length > HTTP_BOOT_DHCP6_PACKET_MAX_SIZE) {
>        //
>        // Ignore the incoming packets which exceed the maximum length.
>        //
>        break;
>      }
> -     if (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM) {
> -       //
> -       // Cache the dhcp offers to OfferBuffer[] for select later, and record
> -       // the OfferIndex and OfferCount.
> -       // If error happens, just ignore this packet and continue to wait more
> offer.
> -       //
> -       HttpBootCacheDhcp6Offer (Private, Packet);
> -     }
> -     break;
> -
> -   case Dhcp6SelectAdvertise:
> -     //
> -     // Select offer by the default policy or by order, and record the
> SelectIndex
> -     // and SelectProxyType.
> -     //
> -     HttpBootSelectDhcpOffer (Private);
> -
> -     if (Private->SelectIndex == 0) {
> -       Status = EFI_ABORTED;
> -     } else {
> -       ASSERT (NewPacket != NULL);
> -       SelectAd   = &Private->OfferBuffer[Private->SelectIndex -
> 1].Dhcp6.Packet.Offer;
> -       *NewPacket = AllocateZeroPool (SelectAd->Size);
> -       if (*NewPacket == NULL) {
> -         return EFI_OUT_OF_RESOURCES;
> -       }
> -       CopyMem (*NewPacket, SelectAd, SelectAd->Size);
> -     }
> -     break;
> +    if (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM) {
> +      //
> +      // Cache the dhcp offers to OfferBuffer[] for select later, and record
> +      // the OfferIndex and OfferCount.
> +      // If error happens, just ignore this packet and continue to wait more
> offer.
> +      //
> +      HttpBootCacheDhcp6Offer (Private, Packet);
> +    }
> +    break;
> +
> +  case Dhcp6SelectAdvertise:
> +    //
> +    // Select offer by the default policy or by order, and record the
> SelectIndex
> +    // and SelectProxyType.
> +    //
> +    HttpBootSelectDhcpOffer (Private);
> +
> +    if (Private->SelectIndex == 0) {
> +      Status = EFI_ABORTED;
> +    } else {
> +      ASSERT (NewPacket != NULL);
> +      SelectAd   = &Private->OfferBuffer[Private->SelectIndex -
> 1].Dhcp6.Packet.Offer;
> +      *NewPacket = AllocateZeroPool (SelectAd->Size);
> +      if (*NewPacket == NULL) {
> +        return EFI_OUT_OF_RESOURCES;
> +      }
> +      CopyMem (*NewPacket, SelectAd, SelectAd->Size);
> +    }
> +    break;
> 
> -   default:
> -     break;
> +  default:
> +    break;
>    }
> 
>    return Status;
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> index a1e6792514..235bf37b78 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> @@ -62,6 +62,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
>  // Produced Protocols
>  //
>  #include <Protocol/LoadFile.h>
> +#include <Protocol/HttpBootCallback.h>
> 
>  //
>  // Consumed Guids
> @@ -133,6 +134,14 @@ struct _HTTP_BOOT_VIRTUAL_NIC {
>    CallbackInfo, \
>    HTTP_BOOT_PRIVATE_DATA_SIGNATURE \
>    )
> +
> +#define
> HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL(CallbackProtoco
> l) \
> +    CR ( \
> +    CallbackProtocol, \
> +    HTTP_BOOT_PRIVATE_DATA, \
> +    LoadFileCallback, \
> +    HTTP_BOOT_PRIVATE_DATA_SIGNATURE \
> +    )
> 
>  struct _HTTP_BOOT_PRIVATE_DATA {
>    UINT32                                    Signature;
> @@ -168,6 +177,11 @@ struct _HTTP_BOOT_PRIVATE_DATA {
>    EFI_LOAD_FILE_PROTOCOL                    LoadFile;
>    EFI_DEVICE_PATH_PROTOCOL                  *DevicePath;
>    UINT32                                    Id;
> +  EFI_HTTP_BOOT_CALLBACK_PROTOCOL           *HttpBootCallback;
> +  EFI_HTTP_BOOT_CALLBACK_PROTOCOL           LoadFileCallback;
> +  UINTN                                     FileSize;
> +  UINTN                                     ReceivedSize;
> +  UINTN                                     Percentage;
> 
>    //
>    // HII callback info block
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
> b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
> index ec983ba7ad..4d6c5e5048 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
> +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
> @@ -85,7 +85,8 @@
>    gEfiNetworkInterfaceIdentifierProtocolGuid_31   ##
> SOMETIMES_CONSUMES
>    gEfiRamDiskProtocolGuid                         ## SOMETIMES_CONSUMES
>    gEfiHiiConfigAccessProtocolGuid                 ## BY_START
> -
> +  gEfiHttpBootCallbackProtocolGuid                ## SOMETIMES_PRODUCES
> +
>  [Guids]
>    ## SOMETIMES_CONSUMES ## GUID # HiiIsConfigHdrMatch
> mHttpBootConfigStorageName
>    ## SOMETIMES_PRODUCES ## GUID # HiiConstructConfigHdr
> mHttpBootConfigStorageName
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
> b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
> index cf6de80a17..809baeb879 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
> +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
> @@ -16,6 +16,84 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
>  #include "HttpBootDxe.h"
> 
>  /**
> +  Install HTTP Boot Callback Protocol if not installed before.
> +
> +  @param[in] Private           Pointer to HTTP Boot private data.
> +
> +  @retval EFI_SUCCESS          HTTP Boot Callback Protocol installed succesfully.
> +  @retval Others               Failed to install HTTP Boot Callback Protocol.
> +
> +**/
> +EFI_STATUS
> +HttpBootInstallCallback (
> +  IN HTTP_BOOT_PRIVATE_DATA           *Private
> +  )
> +{
> +  EFI_STATUS                  Status;
> +  EFI_HANDLE                  ControllerHandle;
> +
> +  if (!Private->UsingIpv6) {
> +    ControllerHandle = Private->Ip4Nic->Controller;
> +  } else {
> +    ControllerHandle = Private->Ip6Nic->Controller;
> +  }
> +
> +  //
> +  // Check whether gEfiHttpBootCallbackProtocolGuid already installed.
> +  //
> +  Status = gBS->HandleProtocol (
> +                  ControllerHandle,
> +                  &gEfiHttpBootCallbackProtocolGuid,
> +                  (VOID **) &Private->HttpBootCallback
> +                  );
> +  if (Status == EFI_UNSUPPORTED) {
> +
> +    CopyMem (
> +      &Private->LoadFileCallback,
> +      &gHttpBootDxeHttpBootCallback,
> +      sizeof (EFI_HTTP_BOOT_CALLBACK_PROTOCOL)
> +      );
> +
> +    //
> +    // Install a default callback if user didn't offer one.
> +    //
> +    Status = gBS->InstallProtocolInterface (
> +                    &ControllerHandle,
> +                    &gEfiHttpBootCallbackProtocolGuid,
> +                    EFI_NATIVE_INTERFACE,
> +                    &Private->LoadFileCallback
> +                    );
> +    if (EFI_ERROR (Status)) {
> +      return Status;
> +    }
> +    Private->HttpBootCallback = &Private->LoadFileCallback;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Uninstall HTTP Boot Callback Protocol if it's installed by this driver.
> +
> +  @param[in] Private           Pointer to HTTP Boot private data.
> +
> +**/
> +VOID
> +HttpBootUninstallCallback (
> +  IN HTTP_BOOT_PRIVATE_DATA           *Private
> +  )
> +{
> +  if (Private->HttpBootCallback == &Private->LoadFileCallback) {
> +    gBS->UninstallProtocolInterface (
> +          Private->Controller,
> +          &gEfiHttpBootCallbackProtocolGuid,
> +          &Private->HttpBootCallback
> +          );
> +    Private->HttpBootCallback = NULL;
> +  }
> +}
> +
> +/**
>    Enable the use of UEFI HTTP boot function.
> 
>    If the driver has already been started but not satisfy the requirement (IP
> stack and
> @@ -144,6 +222,7 @@ HttpBootStart (
>      }
>    }
>    Private->Started   = TRUE;
> +  Print (L"\n>>Start HTTP Boot over IPv%d", Private->UsingIpv6 ? 6 : 4);
> 
>    return EFI_SUCCESS;
>  }
> @@ -237,7 +316,10 @@ HttpBootLoadFile (
>      return EFI_NOT_STARTED;
>    }
> 
> -  Status = EFI_DEVICE_ERROR;
> +  Status = HttpBootInstallCallback (Private);
> +  if (EFI_ERROR(Status)) {
> +    goto ON_EXIT;
> +  }
> 
>    if (Private->BootFileUri == NULL) {
>      //
> @@ -245,7 +327,7 @@ HttpBootLoadFile (
>      //
>      Status = HttpBootDiscoverBootInfo (Private);
>      if (EFI_ERROR (Status)) {
> -      return Status;
> +      goto ON_EXIT;
>      }
>    }
> 
> @@ -255,7 +337,7 @@ HttpBootLoadFile (
>      //
>      Status = HttpBootCreateHttpIo (Private);
>      if (EFI_ERROR (Status)) {
> -      return Status;
> +      goto ON_EXIT;
>      }
>    }
> 
> @@ -287,7 +369,7 @@ HttpBootLoadFile (
>                   &Private->ImageType
>                   );
>        if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
> -        return Status;
> +        goto ON_EXIT;
>        }
>      }
>    }
> @@ -295,19 +377,24 @@ HttpBootLoadFile (
>    if (*BufferSize < Private->BootFileSize) {
>      *BufferSize = Private->BootFileSize;
>      *ImageType = Private->ImageType;
> -    return EFI_BUFFER_TOO_SMALL;
> +    Status = EFI_BUFFER_TOO_SMALL;
> +    goto ON_EXIT;
>    }
> 
>    //
>    // Load the boot file into Buffer
>    //
> -  return  HttpBootGetBootFile (
> -            Private,
> -            FALSE,
> -            BufferSize,
> -            Buffer,
> -            ImageType
> -            );
> +  Status = HttpBootGetBootFile (
> +             Private,
> +             FALSE,
> +             BufferSize,
> +             Buffer,
> +             ImageType
> +             );
> +
> +ON_EXIT:
> +  HttpBootUninstallCallback (Private);
> +  return Status;
>  }
> 
>  /**
> @@ -520,3 +607,113 @@ GLOBAL_REMOVE_IF_UNREFERENCED
>  EFI_LOAD_FILE_PROTOCOL  gHttpBootDxeLoadFile = {
>    HttpBootDxeLoadFile
>  };
> +
> +/**
> +  Callback function that is invoked when the HTTP Boot driver is about to
> transmit or has received a
> +  packet.
> +
> +  This function is invoked when the HTTP Boot driver is about to transmit or
> has received packet.
> +  Parameters DataType and Received specify the type of event and the
> format of the buffer pointed
> +  to by Data. Due to the polling nature of UEFI device drivers, this callback
> function should not
> +  execute for more than 5 ms.
> +  The returned status code determines the behavior of the HTTP Boot driver.
> +
> +  @param[in]  This                Pointer to the
> EFI_HTTP_BOOT_CALLBACK_PROTOCOL instance.
> +  @param[in]  DataType            The event that occurs in the current state.
> +  @param[in]  Received            TRUE if the callback is being invoked due to a
> receive event.
> +                                  FALSE if the callback is being invoked due to a transmit
> event.
> +  @param[in]  DataLength          The length in bytes of the buffer pointed to
> by Data.
> +  @param[in]  Data                A pointer to the buffer of data, the data type is
> specified by
> +                                  DataType.
> +
> +  @retval EFI_SUCCESS             Tells the HTTP Boot driver to continue the
> HTTP Boot process.
> +  @retval EFI_ABORTED             Tells the HTTP Boot driver to abort the current
> HTTP Boot process.
> +**/
> +EFI_STATUS
> +HttpBootCallback (
> +  IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL     *This,
> +  IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE    DataType,
> +  IN BOOLEAN                             Received,
> +  IN UINT32                              DataLength,
> +  IN VOID                                *Data     OPTIONAL
> +  )
> +{
> +  EFI_HTTP_MESSAGE        *HttpMessage;
> +  EFI_HTTP_HEADER         *HttpHeader;
> +  HTTP_BOOT_PRIVATE_DATA  *Private;
> +  UINTN                   Percentage;
> +
> +  Private =
> HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_PROTOCOL(This);
> +
> +  switch (DataType) {
> +  case HttpBootDhcp4:
> +  case HttpBootDhcp6:
> +    Print (L".");
> +    break;
> +
> +  case HttpBootHttpRequest:
> +    if (Data != NULL) {
> +      HttpMessage = (EFI_HTTP_MESSAGE *) Data;
> +      if (HttpMessage->Data.Request->Method == HttpMethodGet &&
> +          HttpMessage->Data.Request->Url != NULL) {
> +        Print (L"\n  URI: %s\n", HttpMessage->Data.Request->Url);
> +      }
> +    }
> +    break;
> +
> +  case HttpBootHttpResponse:
> +    if (Data != NULL) {
> +      HttpMessage = (EFI_HTTP_MESSAGE *) Data;
> +      HttpHeader = HttpFindHeader (
> +                     HttpMessage->HeaderCount,
> +                     HttpMessage->Headers,
> +                     HTTP_HEADER_CONTENT_LENGTH
> +                     );
> +      if (HttpHeader != NULL) {
> +        Private->FileSize = AsciiStrDecimalToUintn (HttpHeader->FieldValue);
> +        Private->ReceivedSize = 0;
> +        Private->Percentage   = 0;
> +      }
> +    }
> +    break;
> +
> +  case HttpBootHttpEntityBody:
> +    if (DataLength != 0) {
> +      if (Private->FileSize != 0) {
> +        //
> +        // We already know the file size, print in percentage format.
> +        //
> +        if (Private->ReceivedSize == 0) {
> +          Print (L"  File Size: %lu\n", Private->FileSize);
> +        }
> +        Private->ReceivedSize += DataLength;
> +        Percentage = (Private->ReceivedSize * 100) / Private->FileSize;
> +        if (Private->Percentage != Percentage) {
> +          Private->Percentage = Percentage;
> +          Print (L"\r  Downloading...%d%%", Percentage);
> +        }
> +      } else {
> +        //
> +        // In some case we couldn't get the file size from the HTTP header, so
> we
> +        // just print the downloaded file size.
> +        //
> +        Private->ReceivedSize += DataLength;
> +        Print (L"\r  Downloading...%d Bytes", Private->ReceivedSize);
> +      }
> +    }
> +    break;
> +
> +  default:
> +    break;
> +  };
> +
> +  return EFI_SUCCESS;
> +}
> +
> +///
> +/// HTTP Boot Callback Protocol instance
> +///
> +GLOBAL_REMOVE_IF_UNREFERENCED
> +EFI_HTTP_BOOT_CALLBACK_PROTOCOL  gHttpBootDxeHttpBootCallback = {
> +  HttpBootCallback
> +};
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.h
> b/NetworkPkg/HttpBootDxe/HttpBootImpl.h
> index 7066338175..da58bb6583 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.h
> +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.h
> @@ -47,4 +47,6 @@ HttpBootStop (
>    IN HTTP_BOOT_PRIVATE_DATA           *Private
>    );
> 
> +extern EFI_HTTP_BOOT_CALLBACK_PROTOCOL
> gHttpBootDxeHttpBootCallback;
> +
>  #endif
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> index 8fe81eb8d9..5024f2e676 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> @@ -671,6 +671,9 @@ HttpIoNotify (
>    @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[in]  Callback       Callback function which will be invoked when
> specified
> +                             HTTP_IO_CALLBACK_EVENT happened.
> +  @param[in]  Context        The Context data which will be passed to the
> Callback function.
>    @param[out] HttpIo         The HTTP_IO.
> 
>    @retval EFI_SUCCESS            The HTTP_IO is created and configured.
> @@ -687,6 +690,8 @@ HttpIoCreateIo (
>    IN EFI_HANDLE             Controller,
>    IN UINT8                  IpVersion,
>    IN HTTP_IO_CONFIG_DATA    *ConfigData,
> +  IN HTTP_IO_CALLBACK       Callback,
> +  IN VOID                   *Context,
>    OUT HTTP_IO               *HttpIo
>    )
>  {
> @@ -739,6 +744,8 @@ HttpIoCreateIo (
>    HttpIo->Controller  = Controller;
>    HttpIo->IpVersion   = IpVersion;
>    HttpIo->Http        = Http;
> +  HttpIo->Callback    = Callback;
> +  HttpIo->Context     = Context;
> 
>    ZeroMem (&HttpConfigData, sizeof (EFI_HTTP_CONFIG_DATA));
>    HttpConfigData.HttpVersion        = HttpVersion11;
> @@ -908,6 +915,17 @@ HttpIoSendRequest (
>    HttpIo->ReqToken.Message->BodyLength   = BodyLength;
>    HttpIo->ReqToken.Message->Body         = Body;
> 
> +  if (HttpIo->Callback != NULL) {
> +    Status = HttpIo->Callback (
> +               HttpIoRequest,
> +               HttpIo->ReqToken.Message,
> +               HttpIo->Context
> +               );
> +    if (EFI_ERROR (Status)) {
> +      return Status;
> +    }
> +  }
> +
>    //
>    // Queue the request token to HTTP instances.
>    //
> @@ -1016,6 +1034,17 @@ HttpIoRecvResponse (
>      HttpIo->IsRxDone = FALSE;
>    }
> 
> +  if (!EFI_ERROR (HttpIo->RspToken.Status) && HttpIo->Callback != NULL) {
> +    Status = HttpIo->Callback (
> +               HttpIoResponse,
> +               HttpIo->RspToken.Message,
> +               HttpIo->Context
> +               );
> +    if (EFI_ERROR (Status)) {
> +      return Status;
> +    }
> +  }
> +
>    //
>    // Store the received data into the wrapper.
>    //
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h
> b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
> index 65302d2be2..f2b1846c05 100644
> --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h
> +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
> @@ -145,6 +145,32 @@ HttpBootSetHeader (
>    IN  CHAR8                *FieldValue
>    );
> 
> +///
> +/// HTTP_IO_CALLBACK_EVENT
> +///
> +typedef enum {
> +  HttpIoRequest,
> +  HttpIoResponse
> +} HTTP_IO_CALLBACK_EVENT;
> +
> +/**
> +  HttpIo Callback function which will be invoked when specified
> HTTP_IO_CALLBACK_EVENT happened.
> +
> +  @param[in]    EventType      Indicate the Event type that occurs in the
> current callback.
> +  @param[in]    Message        HTTP message which will be send to, or just
> received from HTTP server.
> +  @param[in]    Context        The Callback Context pointer.
> +
> +  @retval EFI_SUCCESS          Tells the HttpIo to continue the HTTP process.
> +  @retval Others               Tells the HttpIo to abort the current HTTP process.
> +**/
> +typedef
> +EFI_STATUS
> +(EFIAPI * HTTP_IO_CALLBACK) (
> +  IN  HTTP_IO_CALLBACK_EVENT    EventType,
> +  IN  EFI_HTTP_MESSAGE          *Message,
> +  IN  VOID                      *Context
> +  );
> +
>  //
>  // HTTP_IO configuration data for IPv4
>  //
> @@ -189,6 +215,9 @@ typedef struct {
> 
>    EFI_HTTP_PROTOCOL         *Http;
> 
> +  HTTP_IO_CALLBACK          Callback;
> +  VOID                      *Context;
> +
>    EFI_HTTP_TOKEN            ReqToken;
>    EFI_HTTP_MESSAGE          ReqMessage;
>    EFI_HTTP_TOKEN            RspToken;
> @@ -252,6 +281,9 @@ HttpBootCommonNotify (
>    @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[in]  Callback       Callback function which will be invoked when
> specified
> +                             HTTP_IO_CALLBACK_EVENT happened.
> +  @param[in]  Context        The Context data which will be passed to the
> Callback function.
>    @param[out] HttpIo         The HTTP_IO.
> 
>    @retval EFI_SUCCESS            The HTTP_IO is created and configured.
> @@ -268,6 +300,8 @@ HttpIoCreateIo (
>    IN EFI_HANDLE             Controller,
>    IN UINT8                  IpVersion,
>    IN HTTP_IO_CONFIG_DATA    *ConfigData,
> +  IN HTTP_IO_CALLBACK       Callback,
> +  IN VOID                   *Context,
>    OUT HTTP_IO               *HttpIo
>    );
> 
> --
> 2.13.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7.
  2017-06-14  9:36 ` [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7 Fu Siyuan
@ 2017-06-15  7:59   ` Wu, Jiaxin
  0 siblings, 0 replies; 5+ messages in thread
From: Wu, Jiaxin @ 2017-06-15  7:59 UTC (permalink / raw)
  To: Fu, Siyuan, edk2-devel@lists.01.org; +Cc: Ye, Ting

Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>



> -----Original Message-----
> From: Fu, Siyuan
> Sent: Wednesday, June 14, 2017 5:37 PM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol
> in UEFI 2.7.
> 
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
> ---
>  MdePkg/Include/Protocol/HttpBootCallback.h | 100
> +++++++++++++++++++++++++++++
>  MdePkg/MdePkg.dec                          |   7 +-
>  2 files changed, 105 insertions(+), 2 deletions(-)
>  create mode 100644 MdePkg/Include/Protocol/HttpBootCallback.h
> 
> diff --git a/MdePkg/Include/Protocol/HttpBootCallback.h
> b/MdePkg/Include/Protocol/HttpBootCallback.h
> new file mode 100644
> index 0000000000..7542b30e03
> --- /dev/null
> +++ b/MdePkg/Include/Protocol/HttpBootCallback.h
> @@ -0,0 +1,100 @@
> +/** @file
> +  This file defines the EFI HTTP Boot Callback Protocol interface.
> +
> +  Copyright (c) 2017, 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
> +  which 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.
> +
> +  @par Revision Reference:
> +  This Protocol is introduced in UEFI Specification 2.7
> +
> +**/
> +
> +#ifndef __EFI_HTTP_BOOT_CALLBACK_H__
> +#define __EFI_HTTP_BOOT_CALLBACK_H__
> +
> +#define EFI_HTTP_BOOT_CALLBACK_PROTOCOL_GUID \
> +  { \
> +    0xba23b311, 0x343d, 0x11e6, {0x91, 0x85, 0x58, 0x20, 0xb1, 0xd6, 0x52,
> 0x99} \
> +  }
> +
> +typedef struct _EFI_HTTP_BOOT_CALLBACK_PROTOCOL
> EFI_HTTP_BOOT_CALLBACK_PROTOCOL;
> +
> +///
> +/// EFI_HTTP_BOOT_CALLBACK_DATA_TYPE
> +///
> +typedef enum {
> +  ///
> +  /// Data points to a DHCP4 packet which is about to transmit or has
> received.
> +  ///
> +  HttpBootDhcp4,
> +  ///
> +  /// Data points to a DHCP6 packet which is about to be transmit or has
> received.
> +  ///
> +  HttpBootDhcp6,
> +  ///
> +  /// Data points to an EFI_HTTP_MESSAGE structure, whichcontians a HTTP
> request message
> +  /// to be transmitted.
> +  ///
> +  HttpBootHttpRequest,
> +  ///
> +  /// Data points to an EFI_HTTP_MESSAGE structure, which contians a
> received HTTP
> +  /// response message.
> +  ///
> +  HttpBootHttpResponse,
> +  ///
> +  /// Part of the entity body has been received from the HTTP server. Data
> points to the
> +  /// buffer of the entity body data.
> +  ///
> +  HttpBootHttpEntityBody,
> +  HttpBootTypeMax
> +} EFI_HTTP_BOOT_CALLBACK_DATA_TYPE;
> +
> +/**
> +  Callback function that is invoked when the HTTP Boot driver is about to
> transmit or has received a
> +  packet.
> +
> +  This function is invoked when the HTTP Boot driver is about to transmit or
> has received packet.
> +  Parameters DataType and Received specify the type of event and the
> format of the buffer pointed
> +  to by Data. Due to the polling nature of UEFI device drivers, this callback
> function should not
> +  execute for more than 5 ms.
> +  The returned status code determines the behavior of the HTTP Boot driver.
> +
> +  @param[in]  This                Pointer to the
> EFI_HTTP_BOOT_CALLBACK_PROTOCOL instance.
> +  @param[in]  DataType            The event that occurs in the current state.
> +  @param[in]  Received            TRUE if the callback is being invoked due to a
> receive event.
> +                                  FALSE if the callback is being invoked due to a transmit
> event.
> +  @param[in]  DataLength          The length in bytes of the buffer pointed to
> by Data.
> +  @param[in]  Data                A pointer to the buffer of data, the data type is
> specified by
> +                                  DataType.
> +
> +  @retval EFI_SUCCESS             Tells the HTTP Boot driver to continue the
> HTTP Boot process.
> +  @retval EFI_ABORTED             Tells the HTTP Boot driver to abort the current
> HTTP Boot process.
> +**/
> +typedef
> +EFI_STATUS
> +(EFIAPI * EFI_HTTP_BOOT_CALLBACK) (
> +  IN EFI_HTTP_BOOT_CALLBACK_PROTOCOL    *This,
> +  IN EFI_HTTP_BOOT_CALLBACK_DATA_TYPE   DataType,
> +  IN BOOLEAN                            Received,
> +  IN UINT32                             DataLength,
> +  IN VOID                               *Data   OPTIONAL
> + );
> +
> +///
> +/// EFI HTTP Boot Callback Protocol is invoked when the HTTP Boot driver is
> about to transmit or
> +/// has received a packet. The EFI HTTP Boot Callback Protocol must be
> installed on the same handle
> +/// as the Load File Protocol for the HTTP Boot.
> +///
> +struct _EFI_HTTP_BOOT_CALLBACK_PROTOCOL {
> +  EFI_HTTP_BOOT_CALLBACK Callback;
> +};
> +
> +extern EFI_GUID gEfiHttpBootCallbackProtocolGuid;
> +
> +#endif
> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
> index 7a7504b7a3..a55e8ce1d9 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -2,7 +2,7 @@
>  # This Package provides all definitions, library classes and libraries instances.
>  #
>  # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of
> -# EFI1.10/UEFI2.6/PI1.4 and some Industry Standards.
> +# EFI1.10/UEFI2.7/PI1.4 and some Industry Standards.
>  #
>  # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
>  # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> @@ -1671,6 +1671,9 @@
>    ## Include/Protocol/BluetoothLeConfig.h
>    gEfiBluetoothLeConfigProtocolGuid         = { 0x8f76da58, 0x1f99, 0x4275,
> { 0xa4, 0xec, 0x47, 0x56, 0x51, 0x5b, 0x1c, 0xe8 } }
> 
> +  ## Include/Protocol/HttpBootCallback.h
> +  gEfiHttpBootCallbackProtocolGuid   = {0xba23b311, 0x343d, 0x11e6, {0x91,
> 0x85, 0x58, 0x20, 0xb1, 0xd6, 0x52, 0x99}}
> +
>    #
>    # Protocols defined in Shell2.0
>    #
> @@ -1685,7 +1688,7 @@
>    #
>    ## Include/Protocol/ShellDynamicCommand.h
>    gEfiShellDynamicCommandProtocolGuid  = { 0x3c7200e9, 0x005f, 0x4ea4,
> {0x87, 0xde, 0xa3, 0xdf, 0xac, 0x8a, 0x27, 0xc3 }}
> -
> +
>  #
>  # [Error.gEfiMdePkgTokenSpaceGuid]
>  #   0x80000001 | Invalid value provided.
> --
> 2.13.0.windows.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-15  8:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-14  9:36 [Patch 0/2] Add HTTP Boot Callback Protocol support Fu Siyuan
2017-06-14  9:36 ` [Patch 1/2] MdePkg: Add header file for HTTP Boot Callback protocol in UEFI 2.7 Fu Siyuan
2017-06-15  7:59   ` Wu, Jiaxin
2017-06-14  9:36 ` [Patch 2/2] NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support Fu Siyuan
2017-06-15  7:59   ` Wu, Jiaxin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox