]> 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 ca84f2ad9b8242c737f40c978e335d680eda15f6..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
@@ -329,17 +329,24 @@ HttpBootParseDhcp6Packet (
   @param[in]  Dst          The pointer to the cache buffer for DHCPv6 packet.\r
   @param[in]  Src          The pointer to the DHCPv6 packet to be cached.\r
 \r
+  @retval     EFI_SUCCESS                Packet is copied.\r
+  @retval     EFI_BUFFER_TOO_SMALL       Cache buffer is not big enough to hold the packet.\r
+\r
 **/\r
-VOID\r
+EFI_STATUS\r
 HttpBootCacheDhcp6Packet (\r
   IN EFI_DHCP6_PACKET          *Dst,\r
   IN EFI_DHCP6_PACKET          *Src\r
   )\r
 {\r
-  ASSERT (Dst->Size >= Src->Length);\r
+  if (Dst->Size < Src->Length) {\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
 \r
   CopyMem (&Dst->Dhcp6, &Src->Dhcp6, Src->Length);\r
   Dst->Length = Src->Length;\r
+  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -348,8 +355,11 @@ HttpBootCacheDhcp6Packet (
   @param[in]  Private               The pointer to HTTP_BOOT_PRIVATE_DATA.\r
   @param[in]  RcvdOffer             The pointer to the received offer packet.\r
 \r
+  @retval     EFI_SUCCESS      Cache and parse the packet successfully.\r
+  @retval     Others           Operation failed.\r
+\r
 **/\r
-VOID\r
+EFI_STATUS\r
 HttpBootCacheDhcp6Offer (\r
   IN HTTP_BOOT_PRIVATE_DATA  *Private,\r
   IN EFI_DHCP6_PACKET        *RcvdOffer\r
@@ -358,6 +368,7 @@ HttpBootCacheDhcp6Offer (
   HTTP_BOOT_DHCP6_PACKET_CACHE   *Cache6;\r
   EFI_DHCP6_PACKET               *Offer;\r
   HTTP_BOOT_OFFER_TYPE           OfferType;\r
+  EFI_STATUS                     Status;\r
 \r
   Cache6 = &Private->OfferBuffer[Private->OfferNum].Dhcp6;\r
   Offer  = &Cache6->Packet.Offer;\r
@@ -365,13 +376,16 @@ HttpBootCacheDhcp6Offer (
   //\r
   // Cache the content of DHCPv6 packet firstly.\r
   //\r
-  HttpBootCacheDhcp6Packet(Offer, RcvdOffer);\r
+  Status = HttpBootCacheDhcp6Packet(Offer, RcvdOffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Validate the DHCPv6 packet, and parse the options and offer type.\r
   //\r
   if (EFI_ERROR (HttpBootParseDhcp6Packet (Cache6))) {\r
-    return ;\r
+    return EFI_ABORTED;\r
   }\r
 \r
   //\r
@@ -382,7 +396,9 @@ HttpBootCacheDhcp6Offer (
   ASSERT (Private->OfferCount[OfferType] < HTTP_BOOT_OFFER_MAX_NUM);\r
   Private->OfferIndex[OfferType][Private->OfferCount[OfferType]] = Private->OfferNum;\r
   Private->OfferCount[OfferType]++;\r
-  Private->OfferNum++;  \r
+  Private->OfferNum++;\r
+  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -415,55 +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
-       //\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