]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 14 Jun 2017 09:28:48 +0000 (17:28 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Thu, 22 Jun 2017 02:56:25 +0000 (10:56 +0800)
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.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg/HttpBootDxe/HttpBootClient.h
NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
NetworkPkg/HttpBootDxe/HttpBootDxe.h
NetworkPkg/HttpBootDxe/HttpBootDxe.inf
NetworkPkg/HttpBootDxe/HttpBootImpl.c
NetworkPkg/HttpBootDxe/HttpBootImpl.h
NetworkPkg/HttpBootDxe/HttpBootSupport.c
NetworkPkg/HttpBootDxe/HttpBootSupport.h

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