]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
MdeModulePkg: Fix some typos of "according"
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Impl.c
index e8e127da480ca8c04512dd408d7d3ae127b0052a..1db4c667d7cce721048ba2f02fb1a395e2e43f98 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This file implement the EFI_DHCP4_PROTOCOL interface.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, 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
@@ -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
@@ -660,9 +660,7 @@ EfiDhcp4Configure (
     }\r
 \r
     CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR));\r
-\r
-    if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {\r
-\r
+    if (IP4_IS_LOCAL_BROADCAST(NTOHL (Ip))) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
@@ -932,6 +930,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
@@ -1185,7 +1189,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
@@ -1198,10 +1205,26 @@ 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
+  if (DhcpSb->Netmask == 0) {\r
+    //\r
+    // The Dhcp4.TransmitReceive() API should be able to used at any time according to\r
+    // UEFI spec, while in classless addressing network, the netmask must be explicitly\r
+    // provided together with the station address.\r
+    // If the DHCP instance haven't be configured with a valid netmask, we could only\r
+    // compute it according to the classful addressing rule.\r
+    //\r
+    Class = NetGetIpClass (ClientAddr);\r
+    ASSERT (Class < IP4_ADDR_CLASSE);\r
+    SubnetMask = gIp4AllMasks[Class << 3];\r
+  } else {\r
+    SubnetMask = DhcpSb->Netmask;\r
+  }\r
+\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
@@ -1228,6 +1251,8 @@ Dhcp4InstanceCreateUdpIo (
   )\r
 {\r
   DHCP_SERVICE  *DhcpSb;\r
+  EFI_STATUS    Status;\r
+  VOID          *Udp4;\r
 \r
   ASSERT (Instance->Token != NULL);\r
 \r
@@ -1242,7 +1267,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
@@ -1282,7 +1319,6 @@ PxeDhcpInput (
   )\r
 {\r
   DHCP_PROTOCOL                     *Instance;\r
-  DHCP_SERVICE                      *DhcpSb;\r
   EFI_DHCP4_HEADER                  *Head;\r
   NET_BUF                           *Wrap;\r
   EFI_DHCP4_PACKET                  *Packet;\r
@@ -1293,7 +1329,6 @@ PxeDhcpInput (
   Wrap     = NULL;\r
   Instance = (DHCP_PROTOCOL *) Context;\r
   Token    = Instance->Token;\r
-  DhcpSb   = Instance->Service;\r
 \r
   //\r
   // Don't restart receive if error occurs or DHCP is destroyed.\r
@@ -1337,7 +1372,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
@@ -1410,6 +1445,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
@@ -1455,7 +1496,7 @@ EfiDhcp4TransmitReceive (
   IP4_ADDR       Ip;\r
   DHCP_SERVICE   *DhcpSb;\r
   EFI_IP_ADDRESS Gateway;\r
-  IP4_ADDR       SubnetMask;\r
+  IP4_ADDR       ClientAddr;\r
 \r
   if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1486,8 +1527,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
@@ -1547,9 +1589,8 @@ EfiDhcp4TransmitReceive (
   //\r
   // Get the gateway.\r
   //\r
-  SubnetMask = DhcpSb->Netmask;\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], DhcpSb->Netmask)) {\r
     CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
     Gateway.Addr[0] = NTOHL (Gateway.Addr[0]);\r
   }\r
@@ -1575,6 +1616,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
@@ -1723,3 +1770,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