]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
MdeModulePkg: Fix issue about current Ip4Dxe implementation for DHCP DORA process
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.c
index 561be165d835834f2498b353afe67a1eefd3c37f..004a8bc7034d0488d5ab5d43e7bfe8796ca1f303 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2014, 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
@@ -9,31 +9,24 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-\r
-Module Name:\r
-\r
-  Ip4Common.c\r
-\r
-Abstract:\r
-\r
-\r
 **/\r
 \r
 #include "Ip4Impl.h"\r
 \r
 \r
 /**\r
-  Return the cast type (Unicast/Boradcast) specific to a\r
+  Return the cast type (Unicast/Boradcast) specific to an\r
   interface. All the addresses are host byte ordered.\r
 \r
-  @param  IpAddr                The IP address to classify in host byte order\r
-  @param  IpIf                  The interface that IpAddr received from\r
+  @param[in]  IpAddr                The IP address to classify in host byte order\r
+  @param[in]  IpIf                  The interface that IpAddr received from\r
 \r
   @return The cast type of this IP address specific to the interface.\r
   @retval IP4_LOCAL_HOST        The IpAddr equals to the interface's address\r
   @retval IP4_SUBNET_BROADCAST  The IpAddr is a directed subnet boradcast to  the\r
                                 interface\r
   @retval IP4_NET_BROADCAST     The IpAddr is a network broadcast to the interface\r
+  @retval 0                     Otherwise.\r
 \r
 **/\r
 INTN\r
@@ -62,15 +55,15 @@ Ip4GetNetCast (
   This isn't the same as link layer cast type. For example, DHCP\r
   server may send local broadcast to the local unicast MAC.\r
 \r
-  @param  IpSb                  The IP4 service binding instance that received the\r
-                                packet\r
-  @param  Dst                   The destination address in the packet (host byte\r
-                                order)\r
-  @param  Src                   The source address in the packet (host byte order)\r
+  @param[in]  IpSb                  The IP4 service binding instance that received the\r
+                                    packet\r
+  @param[in]  Dst                   The destination address in the packet (host byte\r
+                                    order)\r
+  @param[in]  Src                   The source address in the packet (host byte order)\r
 \r
   @return The cast type for the Dst, it will return on the first non-promiscuous\r
-  @return cast type to a configured interface. If the packet doesn't match any of\r
-  @return the interface, multicast address and local broadcast address are checked.\r
+          cast type to a configured interface. If the packet doesn't match any of\r
+          the interface, multicast address and local broadcast address are checked.\r
 \r
 **/\r
 INTN\r
@@ -119,11 +112,11 @@ Ip4GetHostCast (
   if (Dst == IP4_ALLONE_ADDRESS) {\r
     IpIf = Ip4FindNet (IpSb, Src);\r
 \r
-    if (IpIf && !IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {\r
+    if (IpIf != NULL && !IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {\r
       return IP4_LOCAL_BROADCAST;\r
     }\r
 \r
-  } else if (IP4_IS_MULTICAST (Dst) && Ip4FindGroup (&IpSb->IgmpCtrl, Dst)) {\r
+  } else if (IP4_IS_MULTICAST (Dst) && Ip4FindGroup (&IpSb->IgmpCtrl, Dst) != NULL) {\r
     return IP4_MULTICAST;\r
   }\r
 \r
@@ -132,10 +125,10 @@ Ip4GetHostCast (
 \r
 \r
 /**\r
-  Find an interface whose configured IP address is Ip\r
+  Find an interface whose configured IP address is Ip.\r
 \r
-  @param  IpSb                  The IP4 service binding instance\r
-  @param  Ip                    The Ip address (host byte order) to find\r
+  @param[in]  IpSb                  The IP4 service binding instance\r
+  @param[in]  Ip                    The Ip address (host byte order) to find\r
 \r
   @return The IP4_INTERFACE point if found, otherwise NULL\r
 \r
@@ -164,8 +157,8 @@ Ip4FindInterface (
 /**\r
   Find an interface that Ip is on that connected network.\r
 \r
-  @param  IpSb                  The IP4 service binding instance\r
-  @param  Ip                    The Ip address (host byte order) to find\r
+  @param[in]  IpSb                  The IP4 service binding instance\r
+  @param[in]  Ip                    The Ip address (host byte order) to find\r
 \r
   @return The IP4_INTERFACE point if found, otherwise NULL\r
 \r
@@ -194,9 +187,9 @@ Ip4FindNet (
 /**\r
   Find an interface of the service with the same Ip/Netmask pair.\r
 \r
-  @param  IpSb                  Ip4 service binding instance\r
-  @param  Ip                    The Ip adress to find (host byte order)\r
-  @param  Netmask               The network to find (host byte order)\r
+  @param[in]  IpSb                  Ip4 service binding instance\r
+  @param[in]  Ip                    The Ip adress to find (host byte order)\r
+  @param[in]  Netmask               The network to find (host byte order)\r
 \r
   @return The IP4_INTERFACE point if found, otherwise NULL\r
 \r
@@ -228,12 +221,13 @@ Ip4FindStationAddress (
   Mnp's McastIpToMac to find the MAC address in stead of\r
   hard code the NIC to be Ethernet.\r
 \r
-  @param  Mnp                   The Mnp instance to get the MAC address.\r
-  @param  Multicast             The multicast IP address to translate.\r
-  @param  Mac                   The buffer to hold the translated address.\r
+  @param[in]  Mnp                   The Mnp instance to get the MAC address.\r
+  @param[in]  Multicast             The multicast IP address to translate.\r
+  @param[out] Mac                   The buffer to hold the translated address.\r
 \r
-  @return Returns EFI_SUCCESS if the multicast IP is successfully\r
-  @return translated to a multicast MAC address. Otherwise some error.\r
+  @retval EFI_SUCCESS if the multicast IP is successfully translated to a\r
+                      multicast MAC address.\r
+  @retval other       Otherwise some error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -255,7 +249,7 @@ Ip4GetMulticastMac (
   In spite of its name, it can also be used to convert from\r
   host to network byte order.\r
 \r
-  @param  Head                  The IP head to convert\r
+  @param[in]  Head                  The IP head to convert\r
 \r
   @return Point to the converted IP head\r
 \r
@@ -273,149 +267,3 @@ Ip4NtohHead (
 \r
   return Head;\r
 }\r
-\r
-\r
-/**\r
-  Set the Ip4 variable data.\r
-\r
-  @param  IpSb                  Ip4 service binding instance\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to set the variable.\r
-  @retval other                 Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4SetVariableData (\r
-  IN IP4_SERVICE  *IpSb\r
-  )\r
-{\r
-  UINT32                 NumConfiguredInstance;\r
-  LIST_ENTRY             *Entry;\r
-  UINTN                  VariableDataSize;\r
-  EFI_IP4_VARIABLE_DATA  *Ip4VariableData;\r
-  EFI_IP4_ADDRESS_PAIR   *Ip4AddressPair;\r
-  IP4_PROTOCOL           *IpInstance;\r
-  CHAR16                 *NewMacString;\r
-  EFI_STATUS             Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
-  //\r
-  // Go through the children list to count the configured children.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &IpSb->Children) {\r
-    IpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, Link, IP4_PROTOCOL_SIGNATURE);\r
-\r
-    if (IpInstance->State == IP4_STATE_CONFIGED) {\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Ip4VariableData. As there may be no IP child,\r
-  // we should add extra buffer for the address paris only if the number of configured\r
-  // children is more than 1.\r
-  //\r
-  VariableDataSize = sizeof (EFI_IP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_IP4_ADDRESS_PAIR) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Ip4VariableData = AllocatePool (VariableDataSize);\r
-  if (Ip4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Ip4VariableData->DriverHandle = IpSb->Image;\r
-  Ip4VariableData->AddressCount = NumConfiguredInstance;\r
-\r
-  Ip4AddressPair = &Ip4VariableData->AddressPairs[0];\r
-\r
-  //\r
-  // Go through the children list to fill the configured children's address pairs.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &IpSb->Children) {\r
-    IpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, Link, IP4_PROTOCOL_SIGNATURE);\r
-\r
-    if (IpInstance->State == IP4_STATE_CONFIGED) {\r
-      Ip4AddressPair->InstanceHandle       = IpInstance->Handle;\r
-      EFI_IP4 (Ip4AddressPair->Ip4Address) = NTOHL (IpInstance->Interface->Ip);\r
-      EFI_IP4 (Ip4AddressPair->SubnetMask) = NTOHL (IpInstance->Interface->SubnetMask);\r
-\r
-      Ip4AddressPair++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (IpSb->Controller, IpSb->Image, &NewMacString);\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (IpSb->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (IpSb->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             IpSb->MacString,\r
-             &gEfiIp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    gBS->FreePool (IpSb->MacString);\r
-  }\r
-\r
-  IpSb->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  IpSb->MacString,\r
-                  &gEfiIp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Ip4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  gBS->FreePool (Ip4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param  IpSb                  Ip4 service binding instance\r
-\r
-  @return None.\r
-\r
-**/\r
-VOID\r
-Ip4ClearVariableData (\r
-  IN IP4_SERVICE  *IpSb\r
-  )\r
-{\r
-  ASSERT (IpSb->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         IpSb->MacString,\r
-         &gEfiIp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  gBS->FreePool (IpSb->MacString);\r
-  IpSb->MacString = NULL;\r
-}\r