]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootDhcp6.c
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