]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4ConfigDxe / NicIp4Variable.c
index d6e617eaa76ecd1a5d3aeb1f835bc2eb000832a9..2d645beec0dd98d28a0e540c25d8b3712c2853eb 100644 (file)
@@ -1,33 +1,17 @@
 /** @file\r
+  Routines used to operate the Ip4 configure variable.\r
 \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2009, 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
+which accompanies this distribution.  The full text of the license may be found at<BR>\r
 http://opensource.org/licenses/bsd-license.php\r
 \r
 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
-Module Name:\r
-\r
-  NicIp4Variable.c\r
-\r
-Abstract:\r
-\r
-  Routines used to operate the Ip4 configure variable\r
-\r
-\r
 **/\r
 \r
-\r
-#include <Library/NetLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-\r
 #include "NicIp4Variable.h"\r
 \r
 \r
@@ -61,7 +45,7 @@ Ip4ConfigIsValid (
     Netmask = EFI_NTOHL (IpConfig->SubnetMask);\r
 \r
     if ((Netmask == 0) || !IP4_IS_VALID_NETMASK (Netmask) ||\r
-        (Station == 0) || !Ip4IsUnicast (Station, Netmask)) {\r
+        (Station == 0) || !NetIp4IsUnicast (Station, Netmask)) {\r
       return FALSE;\r
     }\r
 \r
@@ -73,7 +57,7 @@ Ip4ConfigIsValid (
       Gateway = EFI_NTOHL (IpConfig->RouteTable[Index].GatewayAddress);\r
 \r
       if ((Gateway != 0) && (!IP4_NET_EQUAL (Station, Gateway, Netmask) ||\r
-          !Ip4IsUnicast (Gateway, Netmask))) {\r
+          !NetIp4IsUnicast (Gateway, Netmask))) {\r
         return FALSE;\r
       }\r
     }\r
@@ -91,7 +75,7 @@ Ip4ConfigIsValid (
 \r
 \r
 /**\r
-  Read the ip4 configure variable from the EFI variable\r
+  Read the ip4 configure variable from the EFI variable.\r
 \r
   None\r
 \r
@@ -129,7 +113,7 @@ Ip4ConfigReadVariable (
     goto REMOVE_VARIABLE;\r
   }\r
 \r
-  Variable = NetAllocatePool (Size);\r
+  Variable = AllocatePool (Size);\r
 \r
   if (Variable == NULL) {\r
     return NULL;\r
@@ -167,7 +151,7 @@ REMOVE_VARIABLE:
 \r
 ON_ERROR:\r
   if (Variable != NULL) {\r
-    NetFreePool (Variable);\r
+    FreePool (Variable);\r
   }\r
 \r
   return NULL;\r
@@ -186,7 +170,7 @@ ON_ERROR:
 **/\r
 EFI_STATUS\r
 Ip4ConfigWriteVariable (\r
-  IN IP4_CONFIG_VARIABLE    * Config        OPTIONAL\r
+  IN IP4_CONFIG_VARIABLE    *Config        OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -213,7 +197,7 @@ Ip4ConfigWriteVariable (
   @param  NicAddr      The interface address to check\r
 \r
   @return The point to the NIC's IP4 configure info if it is found\r
-  @return in the IP4 variable, otherwise NULL.\r
+          in the IP4 variable, otherwise NULL.\r
 \r
 **/\r
 NIC_IP4_CONFIG_INFO *\r
@@ -234,7 +218,7 @@ Ip4ConfigFindNicVariable (
     //\r
     // Copy the data to Temp to avoid the alignment problems\r
     //\r
-    NetCopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));\r
+    CopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));\r
     Len = SIZEOF_NIC_IP4_CONFIG_INFO (&Temp);\r
 \r
     //\r
@@ -242,13 +226,14 @@ Ip4ConfigFindNicVariable (
     // a block of memory then copy it out.\r
     //\r
     if (NIC_ADDR_EQUAL (&Temp.NicAddr, NicAddr)) {\r
-      Config = NetAllocatePool (Len);\r
+      Config = AllocatePool (Len);\r
 \r
       if (Config == NULL) {\r
         return NULL;\r
       }\r
 \r
-      NetCopyMem (Config, Cur, Len);\r
+      CopyMem (Config, Cur, Len);\r
+      Ip4ConfigFixRouteTablePointer (&Config->Ip4Info);\r
       return Config;\r
     }\r
 \r
@@ -269,14 +254,14 @@ Ip4ConfigFindNicVariable (
   @param  Config       The new configuration parameter (NULL to remove the old)\r
 \r
   @return The new IP4_CONFIG_VARIABLE variable if the new variable has at\r
-  @return least one NIC configure and no EFI_OUT_OF_RESOURCES failure.\r
-  @return Return NULL either because failed to locate memory for new variable\r
-  @return or the only NIC configure is removed from the Variable.\r
+          least one NIC configure and no EFI_OUT_OF_RESOURCES failure.\r
+          Return NULL either because failed to locate memory for new variable\r
+          or the only NIC configure is removed from the Variable.\r
 \r
 **/\r
 IP4_CONFIG_VARIABLE *\r
 Ip4ConfigModifyVariable (\r
-  IN IP4_CONFIG_VARIABLE    *Variable,    OPTIONAL\r
+  IN IP4_CONFIG_VARIABLE    *Variable     OPTIONAL,\r
   IN NIC_ADDR               *NicAddr,\r
   IN NIC_IP4_CONFIG_INFO    *Config       OPTIONAL\r
   )\r
@@ -311,7 +296,7 @@ Ip4ConfigModifyVariable (
 \r
     if (Old != NULL) {\r
       TotalLen -= SIZEOF_NIC_IP4_CONFIG_INFO (Old);\r
-      NetFreePool (Old);\r
+      FreePool (Old);\r
     }\r
 \r
     if (Config != NULL) {\r
@@ -338,7 +323,7 @@ Ip4ConfigModifyVariable (
 \r
   ASSERT (TotalLen >= sizeof (IP4_CONFIG_VARIABLE));\r
 \r
-  NewVar = NetAllocateZeroPool (TotalLen);\r
+  NewVar = AllocateZeroPool (TotalLen);\r
 \r
   if (NewVar == NULL) {\r
     return NULL;\r
@@ -352,11 +337,11 @@ Ip4ConfigModifyVariable (
   Next = (UINT8 *)&NewVar->ConfigInfo;\r
 \r
   for (Index = 0; Index < Count; Index++) {\r
-    NetCopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));\r
+    CopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));\r
     Len = SIZEOF_NIC_IP4_CONFIG_INFO (&Temp);\r
 \r
     if (!NIC_ADDR_EQUAL (&Temp.NicAddr, NicAddr)) {\r
-      NetCopyMem (Next, Cur, Len);\r
+      CopyMem (Next, Cur, Len);\r
       Next += Len;\r
       NewVar->Count++;\r
     }\r
@@ -372,7 +357,7 @@ Ip4ConfigModifyVariable (
   if (Config != NULL) {\r
     Len = SIZEOF_NIC_IP4_CONFIG_INFO (Config);\r
 \r
-    NetCopyMem (Next, Config, Len);\r
+    CopyMem (Next, Config, Len);\r
     NewVar->Count++;\r
   }\r
 \r
@@ -381,3 +366,29 @@ Ip4ConfigModifyVariable (
   NewVar->CheckSum = (UINT16) (~NetblockChecksum ((UINT8 *) NewVar, TotalLen));\r
   return NewVar;\r
 }\r
+\r
+/**\r
+  Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure. \r
+  \r
+  The pointer is set to be immediately follow the ConfigData if there're entries\r
+  in the RouteTable. Otherwise it is set to NULL.\r
+  \r
+  @param  ConfigData     The IP4 IP configure data.\r
+\r
+**/\r
+VOID\r
+Ip4ConfigFixRouteTablePointer (\r
+  IN OUT EFI_IP4_IPCONFIG_DATA  *ConfigData\r
+  )\r
+{\r
+  //\r
+  // The memory used for route table entries must immediately follow \r
+  // the ConfigData and be not packed.\r
+  //\r
+  if (ConfigData->RouteTableSize > 0) {\r
+    ConfigData->RouteTable = (EFI_IP4_ROUTE_TABLE *) (ConfigData + 1);\r
+  } else {\r
+    ConfigData->RouteTable = NULL;\r
+  }\r
+}\r
+\r