]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Impl.c
index f470844ee4d9930b975900cd3867290b1a41bc51..41b5e9599775c54c6db7e71d0a3356c978fdc475 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   This file implement the EFI_DHCP4_PROTOCOL interface.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -467,7 +467,7 @@ DhcpCopyConfigure (
 {\r
   EFI_DHCP4_PACKET_OPTION   **DstOptions;\r
   EFI_DHCP4_PACKET_OPTION   **SrcOptions;\r
-  INTN                      Len;\r
+  UINTN                     Len;\r
   UINT32                    Index;\r
 \r
   CopyMem (Dst, Src, sizeof (*Dst));\r
@@ -910,16 +910,17 @@ EfiDhcp4RenewRebind (
 \r
   if (DhcpSb->DhcpState == Dhcp4Stopped) {\r
     Status = EFI_NOT_STARTED;\r
-    goto ON_ERROR;\r
+    goto ON_EXIT;\r
   }\r
 \r
   if (DhcpSb->DhcpState != Dhcp4Bound) {\r
     Status = EFI_ACCESS_DENIED;\r
-    goto ON_ERROR;\r
+    goto ON_EXIT;\r
   }\r
 \r
   if (DHCP_IS_BOOTP (DhcpSb->Para)) {\r
-    return EFI_SUCCESS;\r
+    Status = EFI_SUCCESS;\r
+    goto ON_EXIT;\r
   }\r
 \r
   //\r
@@ -931,6 +932,12 @@ EfiDhcp4RenewRebind (
     DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE);\r
   }\r
 \r
+  //\r
+  // Clear initial time to make sure that elapsed-time\r
+  // is set to 0 for first REQUEST in renewal process.\r
+  //\r
+  Instance->ElaspedTime = 0;\r
+\r
   Status = DhcpSendMessage (\r
              DhcpSb,\r
              DhcpSb->Selected,\r
@@ -941,7 +948,7 @@ EfiDhcp4RenewRebind (
 \r
   if (EFI_ERROR (Status)) {\r
     DhcpSetState (DhcpSb, Dhcp4Bound, FALSE);\r
-    goto ON_ERROR;\r
+    goto ON_EXIT;\r
   }\r
 \r
   DhcpSb->ExtraRefresh        = TRUE;\r
@@ -961,7 +968,7 @@ EfiDhcp4RenewRebind (
 \r
   return EFI_SUCCESS;\r
 \r
-ON_ERROR:\r
+ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
@@ -1174,6 +1181,7 @@ EfiDhcp4Build (
   @retval other         Other error occurs.\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Dhcp4InstanceConfigUdpIo (\r
   IN UDP_IO       *UdpIo,\r
   IN VOID         *Context\r
@@ -1226,6 +1234,8 @@ Dhcp4InstanceCreateUdpIo (
   )\r
 {\r
   DHCP_SERVICE  *DhcpSb;\r
+  EFI_STATUS    Status;\r
+  VOID          *Udp4;\r
 \r
   ASSERT (Instance->Token != NULL);\r
 \r
@@ -1240,7 +1250,19 @@ Dhcp4InstanceCreateUdpIo (
   if (Instance->UdpIo == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   } else {\r
-    return EFI_SUCCESS;\r
+    Status = gBS->OpenProtocol (\r
+                    Instance->UdpIo->UdpHandle,\r
+                    &gEfiUdp4ProtocolGuid,\r
+                    (VOID **) &Udp4,\r
+                    Instance->Service->Image,\r
+                    Instance->Handle,\r
+                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      UdpIoFreeIo (Instance->UdpIo);\r
+      Instance->UdpIo = NULL;\r
+    }\r
+    return Status;\r
   }\r
 }\r
 \r
@@ -1251,6 +1273,7 @@ Dhcp4InstanceCreateUdpIo (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpDummyExtFree (\r
   IN VOID                   *Arg\r
   )\r
@@ -1270,6 +1293,7 @@ DhcpDummyExtFree (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 PxeDhcpInput (\r
   NET_BUF                   *UdpPacket,\r
   UDP_END_POINT             *EndPoint,\r
@@ -1406,6 +1430,12 @@ SIGNAL_USER:
   //\r
   NetbufQueFlush (&Instance->ResponseQueue);\r
   UdpIoCleanIo (Instance->UdpIo);\r
+  gBS->CloseProtocol (\r
+         Instance->UdpIo->UdpHandle,\r
+         &gEfiUdp4ProtocolGuid,\r
+         Instance->Service->Image,\r
+         Instance->Handle\r
+         );\r
   UdpIoFreeIo (Instance->UdpIo);\r
   Instance->UdpIo = NULL;\r
   Instance->Token = NULL;\r
@@ -1571,6 +1601,12 @@ ON_ERROR:
 \r
   if (EFI_ERROR (Status) && (Instance->UdpIo != NULL)) {\r
     UdpIoCleanIo (Instance->UdpIo);\r
+    gBS->CloseProtocol (\r
+           Instance->UdpIo->UdpHandle,\r
+           &gEfiUdp4ProtocolGuid,\r
+           Instance->Service->Image,\r
+           Instance->Handle\r
+           );\r
     UdpIoFreeIo (Instance->UdpIo);\r
     Instance->UdpIo = NULL;\r
     Instance->Token = NULL;\r
@@ -1719,3 +1755,19 @@ EfiDhcp4Parse (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  Set the elapsed time based on the given instance and the pointer to the\r
+  elapsed time option.\r
+\r
+  @param[in]      Elapsed       The pointer to the position to append.\r
+  @param[in]      Instance      The pointer to the Dhcp4 instance.\r
+**/\r
+VOID\r
+SetElapsedTime (\r
+  IN     UINT16                 *Elapsed,\r
+  IN     DHCP_PROTOCOL          *Instance\r
+  )\r
+{\r
+  WriteUnaligned16 (Elapsed, HTONS(Instance->ElaspedTime));\r
+}\r