]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
MdeModulePkg: Remove DHCP4.TransmitReceive()and DORA process dependency.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Impl.c
index a0a53a4e33665cc160ad1a00d94f4eb9253e0cdb..ac4b11f09402a1cadc793db6038c5fb1c01c8574 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 - 2015, 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
@@ -770,6 +770,7 @@ ON_EXIT:
   @retval EFI_ALREADY_STARTED   Some other EFI DHCPv4 Protocol instance already started the\r
                                 DHCP process.\r
   @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.\r
+  @retval EFI_NO_MEDIA          There was a media error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -909,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
@@ -930,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
@@ -940,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
@@ -960,7 +968,7 @@ EfiDhcp4RenewRebind (
 \r
   return EFI_SUCCESS;\r
 \r
-ON_ERROR:\r
+ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
@@ -1173,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
@@ -1182,7 +1191,10 @@ Dhcp4InstanceConfigUdpIo (
   DHCP_SERVICE                      *DhcpSb;\r
   EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN  *Token;\r
   EFI_UDP4_CONFIG_DATA              UdpConfigData;\r
-  IP4_ADDR                          Ip;\r
+  IP4_ADDR                          ClientAddr;\r
+  IP4_ADDR                          Ip;   \r
+  INTN                              Class; \r
+  IP4_ADDR                          SubnetMask;\r
 \r
   Instance = (DHCP_PROTOCOL *) Context;\r
   DhcpSb   = Instance->Service;\r
@@ -1195,10 +1207,14 @@ Dhcp4InstanceConfigUdpIo (
   UdpConfigData.TimeToLive         = 64;\r
   UdpConfigData.DoNotFragment      = TRUE;\r
 \r
-  Ip = HTONL (DhcpSb->ClientAddr);\r
+  ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr);\r
+  Ip = HTONL (ClientAddr);\r
   CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
-\r
-  Ip = HTONL (DhcpSb->Netmask);\r
+  \r
+  Class = NetGetIpClass (ClientAddr);\r
+  ASSERT (Class < IP4_ADDR_CLASSE);\r
+  SubnetMask = gIp4AllMasks[Class << 3];\r
+  Ip = HTONL (SubnetMask);\r
   CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   if ((Token->ListenPointCount == 0) || (Token->ListenPoints[0].ListenPort == 0)) {\r
@@ -1225,6 +1241,8 @@ Dhcp4InstanceCreateUdpIo (
   )\r
 {\r
   DHCP_SERVICE  *DhcpSb;\r
+  EFI_STATUS    Status;\r
+  VOID          *Udp4;\r
 \r
   ASSERT (Instance->Token != NULL);\r
 \r
@@ -1239,7 +1257,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
@@ -1250,6 +1280,7 @@ Dhcp4InstanceCreateUdpIo (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpDummyExtFree (\r
   IN VOID                   *Arg\r
   )\r
@@ -1269,6 +1300,7 @@ DhcpDummyExtFree (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 PxeDhcpInput (\r
   NET_BUF                   *UdpPacket,\r
   UDP_END_POINT             *EndPoint,\r
@@ -1332,7 +1364,7 @@ PxeDhcpInput (
   //\r
   if ((Head->OpCode != BOOTP_REPLY) ||\r
       (Head->Xid != Token->Packet->Dhcp4.Header.Xid) ||\r
-      (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) {\r
+      (CompareMem (&Token->Packet->Dhcp4.Header.ClientHwAddr[0], Head->ClientHwAddr, Head->HwAddrLen) != 0)) {\r
     goto RESTART;\r
   }\r
 \r
@@ -1405,6 +1437,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
@@ -1450,6 +1488,8 @@ EfiDhcp4TransmitReceive (
   IP4_ADDR       Ip;\r
   DHCP_SERVICE   *DhcpSb;\r
   EFI_IP_ADDRESS Gateway;\r
+  IP4_ADDR       ClientAddr;\r
+  INTN           Class;\r
   IP4_ADDR       SubnetMask;\r
 \r
   if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) {\r
@@ -1458,6 +1498,7 @@ EfiDhcp4TransmitReceive (
 \r
   Instance = DHCP_INSTANCE_FROM_THIS (This);\r
   DhcpSb   = Instance->Service;\r
+  DhcpSb->ActiveChild = Instance;\r
 \r
   if (Instance->Token != NULL) {\r
     //\r
@@ -1481,8 +1522,9 @@ EfiDhcp4TransmitReceive (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (DhcpSb->ClientAddr == 0) {\r
-\r
+  ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr);\r
+  \r
+  if (ClientAddr == 0) {\r
     return EFI_NO_MAPPING;\r
   }\r
 \r
@@ -1542,9 +1584,11 @@ EfiDhcp4TransmitReceive (
   //\r
   // Get the gateway.\r
   //\r
-  SubnetMask = DhcpSb->Netmask;\r
+  Class = NetGetIpClass (ClientAddr);\r
+  ASSERT (Class < IP4_ADDR_CLASSE);\r
+  SubnetMask = gIp4AllMasks[Class << 3];\r
   ZeroMem (&Gateway, sizeof (Gateway));\r
-  if (!IP4_NET_EQUAL (DhcpSb->ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) {\r
+  if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) {\r
     CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
     Gateway.Addr[0] = NTOHL (Gateway.Addr[0]);\r
   }\r
@@ -1570,6 +1614,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
@@ -1718,3 +1768,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