]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. update to use 1 EFI Variable per NIC (instead of converge all NIC configuration...
authorxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 5 Jul 2010 02:03:20 +0000 (02:03 +0000)
committerxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 5 Jul 2010 02:03:20 +0000 (02:03 +0000)
2. remove unnecessary Unload function EfiIp4ConfigUnload (use default Unload function NetLibDefaultUnload instead), remove global array for NIC handle tracking since it’s driver model driver.
3. add Ip4Config Variable reclaim to HiiConfigAccess.RouteConfig() to remove variable for NIC which has been removed from the system.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10628 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h
MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c
MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h

index 8f26b6f79b7678bc8d0a6d753d8bec053c6c141f..cc3f6fb97f80e9728fdf2e05677f273b2be9fb0d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This code implements the IP4Config and NicIp4Config protocols.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, 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<BR>\r
@@ -13,43 +13,32 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "Ip4Config.h"\r
-\r
-IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE];\r
+#include "NicIp4Variable.h"\r
 \r
 \r
 /**\r
   Get the NIC's configure information from the IP4 configure variable.\r
   It will remove the invalid variable.\r
 \r
-  @param  NicAddr                The NIC to check\r
+  @param  Instance               The IP4 CONFIG instance.\r
 \r
   @return NULL if no configure for the NIC in the variable, or it is invalid.\r
           Otherwise the pointer to the NIC's IP configure parameter will be returned.\r
 \r
 **/\r
 NIC_IP4_CONFIG_INFO *\r
-Ip4ConfigGetNicInfo (\r
-  IN  NIC_ADDR              *NicAddr\r
+EfiNicIp4ConfigGetInfo (\r
+  IN  IP4_CONFIG_INSTANCE   *Instance\r
   )\r
 {\r
-  IP4_CONFIG_VARIABLE       *Variable;\r
-  IP4_CONFIG_VARIABLE       *NewVariable;\r
-  NIC_IP4_CONFIG_INFO       *Config;\r
+  NIC_IP4_CONFIG_INFO *NicConfig;\r
 \r
   //\r
-  // Read the configuration parameter for this NicAddr from\r
+  // Read the configuration parameter for this NIC from\r
   // the EFI variable\r
   //\r
-  Variable = Ip4ConfigReadVariable ();\r
-\r
-  if (Variable == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  Config = Ip4ConfigFindNicVariable (Variable, NicAddr);\r
-\r
-  if (Config == NULL) {\r
-    FreePool (Variable);\r
+  NicConfig = Ip4ConfigReadVariable (Instance);\r
+  if (NicConfig == NULL) {\r
     return NULL;\r
   }\r
 \r
@@ -57,85 +46,16 @@ Ip4ConfigGetNicInfo (
   // Validate the configuration, if the configuration is invalid,\r
   // remove it from the variable.\r
   //\r
-  if (!Ip4ConfigIsValid (Config)) {\r
-    NewVariable = Ip4ConfigModifyVariable (Variable, &Config->NicAddr, NULL);\r
-    Ip4ConfigWriteVariable (NewVariable);\r
-\r
-    if (NewVariable != NULL) {\r
-      FreePool (NewVariable);\r
-    };\r
-\r
-    FreePool (Config);\r
-    Config = NULL;\r
-  }\r
-\r
-  FreePool (Variable);\r
-  return Config;\r
-}\r
-\r
-\r
-/**\r
-  Get the configure parameter for this NIC.\r
-\r
-  @param  Instance               The IP4 CONFIG Instance.\r
-  @param  ConfigLen              The length of the NicConfig buffer.\r
-  @param  NicConfig              The buffer to receive the NIC's configure\r
-                                 parameter.\r
-\r
-  @retval EFI_SUCCESS            The configure parameter for this NIC was\r
-                                 obtained successfully .\r
-  @retval EFI_INVALID_PARAMETER  This or ConfigLen is NULL.\r
-  @retval EFI_NOT_FOUND          There is no configure parameter for the NIC in\r
-                                 NVRam.\r
-  @retval EFI_BUFFER_TOO_SMALL   The ConfigLen is too small or the NicConfig is\r
-                                 NULL.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiNicIp4ConfigGetInfo (\r
-  IN  IP4_CONFIG_INSTANCE         *Instance,\r
-  IN OUT  UINTN                   *ConfigLen,\r
-  OUT NIC_IP4_CONFIG_INFO         *NicConfig\r
-  )\r
-{\r
-  NIC_IP4_CONFIG_INFO *Config;\r
-  EFI_STATUS          Status;\r
-  UINTN               Len;\r
-\r
-  if ((Instance == NULL) || (ConfigLen == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Read the Nic's configuration parameter from variable\r
-  //\r
-  Config    = Ip4ConfigGetNicInfo (&Instance->NicAddr);\r
+  if (!Ip4ConfigIsValid (NicConfig)) {\r
+    Ip4ConfigWriteVariable (Instance, NULL);\r
 \r
-  if (Config == NULL) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  //\r
-  // Copy the data to user's buffer\r
-  //\r
-  Len = SIZEOF_NIC_IP4_CONFIG_INFO (Config);\r
-\r
-  if ((*ConfigLen < Len) || (NicConfig == NULL)) {\r
-    Status = EFI_BUFFER_TOO_SMALL;\r
-  } else {\r
-    Status = EFI_SUCCESS;\r
-    CopyMem (NicConfig, Config, Len);\r
-    Ip4ConfigFixRouteTablePointer (&NicConfig->Ip4Info);\r
+    FreePool (NicConfig);\r
+    NicConfig = NULL;\r
   }\r
 \r
-  *ConfigLen = Len;\r
-\r
-  FreePool (Config);\r
-  return Status;\r
+  return NicConfig;\r
 }\r
 \r
-\r
 /**\r
   Set the IP configure parameters for this NIC.\r
 \r
@@ -167,9 +87,7 @@ EfiNicIp4ConfigSetInfo (
   IN BOOLEAN                      Reconfig\r
   )\r
 {\r
-  IP4_CONFIG_VARIABLE *Variable;\r
-  IP4_CONFIG_VARIABLE *NewVariable;\r
-  EFI_STATUS          Status;\r
+  EFI_STATUS  Status;\r
 \r
   //\r
   // Validate the parameters\r
@@ -190,26 +108,7 @@ EfiNicIp4ConfigSetInfo (
   //\r
   // Update the parameter in the configure variable\r
   //\r
-  Variable = Ip4ConfigReadVariable ();\r
-\r
-  if ((Variable == NULL) && (NicConfig == NULL)) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NicConfig);\r
-  Status      = Ip4ConfigWriteVariable (NewVariable);\r
-\r
-  if (NewVariable != NULL) {\r
-    FreePool (NewVariable);\r
-  }\r
-\r
-  //\r
-  // Variable is NULL when saving the first configure parameter\r
-  //\r
-  if (Variable != NULL) {\r
-    FreePool (Variable);\r
-  }\r
-\r
+  Status = Ip4ConfigWriteVariable (Instance, NicConfig);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -420,7 +319,7 @@ EfiIp4ConfigStart (
   Instance->DoneEvent     = DoneEvent;\r
   Instance->ReconfigEvent = ReconfigEvent;\r
 \r
-  Instance->NicConfig     = Ip4ConfigGetNicInfo (&Instance->NicAddr);\r
+  Instance->NicConfig     = EfiNicIp4ConfigGetInfo (Instance);\r
 \r
   if (Instance->NicConfig == NULL) {\r
     Source = IP4_CONFIG_SOURCE_DHCP;\r
index 5eadad27461513a048c93f9bb0984a40bdff156d..87bc25c2f15c1a05410d6bd69612ba9b4d845399 100644 (file)
@@ -26,6 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/ServiceBinding.h>\r
 \r
 #include <Guid/MdeModuleHii.h>\r
+#include <Guid/NicIp4ConfigNvData.h>\r
 \r
 #include <Library/DevicePathLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -41,8 +42,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DpcLib.h>\r
 #include <Library/UefiHiiServicesLib.h>\r
 \r
-#include "NicIp4Variable.h"\r
-\r
 typedef struct _IP4_CONFIG_INSTANCE IP4_CONFIG_INSTANCE;\r
 \r
 //\r
@@ -52,7 +51,6 @@ extern EFI_DRIVER_BINDING_PROTOCOL     gIp4ConfigDriverBinding;
 extern EFI_COMPONENT_NAME_PROTOCOL     gIp4ConfigComponentName;\r
 extern EFI_COMPONENT_NAME2_PROTOCOL    gIp4ConfigComponentName2;\r
 \r
-extern IP4_CONFIG_INSTANCE             *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE];\r
 extern EFI_IP4_CONFIG_PROTOCOL         mIp4ConfigProtocolTemplate;\r
 \r
 #define IP4_PROTO_ICMP                 0x01\r
@@ -122,8 +120,7 @@ struct _IP4_CONFIG_INSTANCE {
   // Identity of this interface and some configuration info.\r
   //\r
   NIC_ADDR                        NicAddr;\r
-  UINT16                          NicName[IP4_NIC_NAME_LENGTH];\r
-  UINT32                          NicIndex;\r
+  CHAR16                          *MacString;\r
   NIC_IP4_CONFIG_INFO             *NicConfig;\r
 \r
   //\r
@@ -173,28 +170,18 @@ EfiNicIp4ConfigSetInfo (
   );\r
 \r
 /**\r
-  Get the configure parameter for this NIC.\r
+  Get the NIC's configure information from the IP4 configure variable.\r
+  It will remove the invalid variable.\r
 \r
-  @param  Instance               The IP4 CONFIG Instance.\r
-  @param  ConfigLen              The length of the NicConfig buffer.\r
-  @param  NicConfig              The buffer to receive the NIC's configure\r
-                                 parameter.\r
+  @param  Instance               The IP4 CONFIG instance.\r
 \r
-  @retval EFI_SUCCESS            The configure parameter for this NIC was\r
-                                 obtained successfully .\r
-  @retval EFI_INVALID_PARAMETER  This or ConfigLen is NULL.\r
-  @retval EFI_NOT_FOUND          There is no configure parameter for the NIC in\r
-                                 NVRam.\r
-  @retval EFI_BUFFER_TOO_SMALL   The ConfigLen is too small or the NicConfig is\r
-                                 NULL.\r
+  @return NULL if no configure for the NIC in the variable, or it is invalid.\r
+          Otherwise the pointer to the NIC's IP configure parameter will be returned.\r
 \r
 **/\r
-EFI_STATUS\r
-EFIAPI\r
+NIC_IP4_CONFIG_INFO *\r
 EfiNicIp4ConfigGetInfo (\r
-  IN  IP4_CONFIG_INSTANCE         *Instance,\r
-  IN OUT  UINTN                   *ConfigLen,\r
-  OUT NIC_IP4_CONFIG_INFO         *NicConfig\r
+  IN  IP4_CONFIG_INSTANCE   *Instance\r
   );\r
 \r
 /**\r
index 0cc2918e43cd5bcf56a8f6d73aa21cc203cb3831..dfa4cdcd8f9911c5adfd1207d27a4d1c7b47319d 100644 (file)
@@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "Ip4Config.h"\r
 #include "Ip4ConfigNv.h"\r
+#include "NicIp4Variable.h"\r
 \r
 EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {\r
   Ip4ConfigDriverBindingSupported,\r
@@ -25,42 +26,6 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {
   NULL\r
 };\r
 \r
-/**\r
-  Stop all the auto configuration when the IP4 configure driver is\r
-  being unloaded.\r
-\r
-  @param  ImageHandle          The driver that is being unloaded\r
-\r
-  @retval EFI_SUCCESS          The driver has been ready for unload.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EfiIp4ConfigUnload (\r
-  IN EFI_HANDLE             ImageHandle\r
-  )\r
-{\r
-  UINT32      Index;\r
-\r
-  //\r
-  //  Stop all the IP4_CONFIG instances\r
-  //\r
-  for (Index = 0; Index < MAX_IP4_CONFIG_IN_VARIABLE; Index++) {\r
-    if (mIp4ConfigNicList[Index] == NULL) {\r
-      continue;\r
-    }\r
-\r
-    gIp4ConfigDriverBinding.Stop (\r
-                              &gIp4ConfigDriverBinding,\r
-                              mIp4ConfigNicList[Index]->MnpHandle,\r
-                              0,\r
-                              NULL\r
-                              );\r
-  }\r
-\r
-  return NetLibDefaultUnload (ImageHandle);\r
-}\r
-\r
 /**\r
   The entry point for IP4 config driver which install the driver\r
   binding and component name protocol on its image.\r
@@ -152,11 +117,8 @@ Ip4ConfigDriverBindingStart (
   EFI_HANDLE                    MnpHandle;\r
   IP4_CONFIG_INSTANCE           *Instance;\r
   EFI_SIMPLE_NETWORK_MODE       SnpMode;\r
-  IP4_CONFIG_VARIABLE           *Variable;\r
   NIC_IP4_CONFIG_INFO           *NicConfig;\r
-  IP4_CONFIG_VARIABLE           *NewVariable;\r
   EFI_STATUS                    Status;\r
-  UINT32                        Index;\r
   EFI_DEVICE_PATH_PROTOCOL      *ParentDevicePath;\r
 \r
   Status = gBS->HandleProtocol (\r
@@ -218,7 +180,7 @@ Ip4ConfigDriverBindingStart (
   //\r
   // Allocate an instance then initialize it\r
   //\r
-  Instance = AllocatePool (sizeof (IP4_CONFIG_INSTANCE));\r
+  Instance = AllocateZeroPool (sizeof (IP4_CONFIG_INSTANCE));\r
 \r
   if (Instance == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -258,30 +220,15 @@ Ip4ConfigDriverBindingStart (
   //\r
   // Add it to the global list, and compose the name\r
   //\r
-  for (Index = 0; Index < MAX_IP4_CONFIG_IN_VARIABLE; Index++) {\r
-    if (mIp4ConfigNicList[Index] == NULL) {\r
-      mIp4ConfigNicList[Index]  = Instance;\r
-      Instance->NicIndex        = Index;\r
-\r
-      if (Instance->NicAddr.Type == NET_IFTYPE_ETHERNET) {\r
-        UnicodeSPrint (Instance->NicName, (UINTN) IP4_NIC_NAME_LENGTH, L"eth%d", Index);\r
-      } else {\r
-        UnicodeSPrint (Instance->NicName, (UINTN) IP4_NIC_NAME_LENGTH, L"unk%d", Index);\r
-      }\r
-\r
-      break;\r
-    }\r
-  }\r
-\r
-  if (Index == MAX_IP4_CONFIG_IN_VARIABLE) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
+  Status = NetLibGetMacString (Instance->Controller, Instance->Image, &Instance->MacString);\r
+  if (EFI_ERROR (Status)) {\r
     goto ON_ERROR;\r
   }\r
 \r
   Status = Ip4ConfigDeviceInit (Instance);\r
 \r
   //\r
-  // Install the IP4_CONFIG and NIC_IP4CONFIG protocols\r
+  // Install the IP4_CONFIG protocols\r
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &ControllerHandle,\r
@@ -291,7 +238,6 @@ Ip4ConfigDriverBindingStart (
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    mIp4ConfigNicList[Index] = NULL;\r
     goto ON_ERROR;\r
   }\r
 \r
@@ -299,50 +245,27 @@ Ip4ConfigDriverBindingStart (
   // Get the previous configure parameters. If an error happend here,\r
   // just ignore it because the driver should be able to operate.\r
   //\r
-  Variable = Ip4ConfigReadVariable ();\r
-\r
-  if (Variable == NULL) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  NicConfig = Ip4ConfigFindNicVariable (Variable, &Instance->NicAddr);\r
-\r
-  if (NicConfig == NULL) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  //\r
-  // Don't modify the permant static configuration\r
-  //\r
-  if (NicConfig->Perment && (NicConfig->Source == IP4_CONFIG_SOURCE_STATIC)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  //\r
-  // Delete the non-permant configuration and remove the previous\r
-  // acquired DHCP parameters. Only doing DHCP itself is permant\r
-  //\r
-  NewVariable = NULL;\r
-\r
-  if (!NicConfig->Perment) {\r
-    NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NULL);\r
-\r
-  } else if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r
-    ZeroMem (&NicConfig->Ip4Info, sizeof (EFI_IP4_IPCONFIG_DATA));\r
-    NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NicConfig);\r
-\r
-  }\r
-\r
-  Ip4ConfigWriteVariable (NewVariable);\r
-\r
-  if (NewVariable != NULL) {\r
-    FreePool (NewVariable);\r
-  }\r
-\r
-ON_EXIT:\r
-  FreePool (Variable);\r
-\r
+  NicConfig = Ip4ConfigReadVariable (Instance);\r
   if (NicConfig != NULL) {\r
+    if (NicConfig->Perment) {\r
+      if (NicConfig->Source == IP4_CONFIG_SOURCE_STATIC) {\r
+        //\r
+        // Don't modify the permanent static configuration.\r
+        //\r
+      } else if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r
+        //\r
+        // Remove the previous acquired DHCP parameters.\r
+        //\r
+        ZeroMem (&NicConfig->Ip4Info, sizeof (EFI_IP4_IPCONFIG_DATA));\r
+        Ip4ConfigWriteVariable (Instance, NicConfig);\r
+      }\r
+    } else {\r
+      //\r
+      // Delete the non-permanent configuration.\r
+      //\r
+      Ip4ConfigWriteVariable (Instance, NULL);\r
+    }\r
+\r
     FreePool (NicConfig);\r
   }\r
 \r
@@ -505,10 +428,12 @@ Ip4ConfigDriverBindingStop (
     Instance->MnpHandle = NULL;\r
   }\r
 \r
+  if (Instance->MacString != NULL) {\r
+    FreePool (Instance->MacString);\r
+  }\r
+\r
   Ip4ConfigCleanConfig (Instance);\r
-  mIp4ConfigNicList[Instance->NicIndex] = NULL;\r
   FreePool (Instance);\r
 \r
   return EFI_SUCCESS;\r
 }\r
-\r
index 4330afef5f56fe40210e4f0b98b8f9dfa07c6554..530b5668a017b5b1c0ef25d942f8813bb1e1cff2 100644 (file)
@@ -21,7 +21,7 @@
   MODULE_TYPE                    = UEFI_DRIVER\r
   VERSION_STRING                 = 1.0\r
   ENTRY_POINT                    = Ip4ConfigDriverEntryPoint\r
-  UNLOAD_IMAGE                   = EfiIp4ConfigUnload\r
+  UNLOAD_IMAGE                   = NetLibDefaultUnload\r
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
@@ -67,4 +67,4 @@
 \r
 [Guids]\r
   gEfiNicIp4ConfigVariableGuid                  ## CONSUMES ## Guid\r
-  \r
+\r
index c0d27aac78c1f6eeed8a7155d070239e25577c44..fa78678adea2845cf856d08e61e746a497f2b579 100644 (file)
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "Ip4ConfigNv.h"\r
+#include "NicIp4Variable.h"\r
 \r
 EFI_GUID  mNicIp4ConfigNvDataGuid = EFI_NIC_IP4_CONFIG_NVDATA_GUID;\r
 \r
@@ -61,14 +62,14 @@ GetSubnetMaskPrefixLength (
   Convert the decimal dotted IPv4 address into the binary IPv4 address.\r
 \r
   @param[in]   Str             The UNICODE string.\r
-  @param[out]  Ip              The storage to return the ASCII string.\r
+  @param[out]  Ip              The storage to return the IPv4 address.\r
 \r
   @retval EFI_SUCCESS           The binary IP address is returned in Ip.\r
   @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
 **/\r
 EFI_STATUS\r
-Ip4AsciiStrToIp (\r
-  IN  CHAR            *Str,\r
+Ip4StrToIp (\r
+  IN  CHAR16            *Str,\r
   OUT EFI_IPv4_ADDRESS  *Ip\r
   )\r
 {\r
@@ -77,15 +78,15 @@ Ip4AsciiStrToIp (
 \r
   Index = 0;\r
 \r
-  while (*Str != 0) {\r
+  while (*Str != L'\0') {\r
 \r
     if (Index > 3) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
     Number = 0;\r
-    while (NET_IS_DIGIT (*Str)) {\r
-      Number = Number * 10 + (*Str - '0');\r
+    while ((*Str >= L'0') && (*Str <= L'9')) {\r
+      Number = Number * 10 + (*Str - L'0');\r
       Str++;\r
     }\r
 \r
@@ -95,7 +96,7 @@ Ip4AsciiStrToIp (
 \r
     Ip->Addr[Index] = (UINT8) Number;\r
 \r
-    if ((*Str != '\0') && (*Str != '.')) {\r
+    if ((*Str != L'\0') && (*Str != L'.')) {\r
       //\r
       // The current character should be either the NULL terminator or\r
       // the dot delimiter.\r
@@ -103,7 +104,7 @@ Ip4AsciiStrToIp (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    if (*Str == '.') {\r
+    if (*Str == L'.') {\r
       //\r
       // Skip the delimiter.\r
       //\r
@@ -148,15 +149,10 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
   OUT IP4_CONFIG_IFR_NVDATA     *IfrFormNvData\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  NIC_IP4_CONFIG_INFO           *NicConfig;\r
-  UINTN                         ConfigLen;\r
-\r
-  ConfigLen = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2;\r
-  NicConfig = AllocateZeroPool (ConfigLen);\r
-  ASSERT (NicConfig != NULL);\r
-  Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, NicConfig);\r
-  if (!EFI_ERROR (Status)) {\r
+  NIC_IP4_CONFIG_INFO  *NicConfig;\r
+\r
+  NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);\r
+  if (NicConfig != NULL) {\r
     IfrFormNvData->Configure = 1;\r
     if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r
       IfrFormNvData->DhcpEnable = 1;\r
@@ -166,17 +162,18 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
       Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);\r
       Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);\r
     }\r
+\r
+    FreePool (NicConfig);\r
   } else {\r
     IfrFormNvData->Configure = 0;\r
   }\r
-\r
-  FreePool (NicConfig);\r
 }\r
 \r
 /**\r
   Convert the IFR data into the network configuration data and set the IP\r
   configure parameters for the NIC.\r
 \r
+  @param[in]       IfrFormNvData     The IFR NV data.\r
   @param[in, out]  Ip4ConfigInstance The IP4Config instance.\r
 \r
   @retval EFI_SUCCESS            The configure parameter for this NIC was\r
@@ -187,6 +184,7 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
 **/\r
 EFI_STATUS\r
 Ip4ConfigConvertIfrNvDataToDeviceConfigData (\r
+  IN     IP4_CONFIG_IFR_NVDATA     *IfrFormNvData,\r
   IN OUT IP4_CONFIG_INSTANCE       *Ip4ConfigInstance\r
   )\r
 {\r
@@ -198,6 +196,14 @@ Ip4ConfigConvertIfrNvDataToDeviceConfigData (
   NIC_IP4_CONFIG_INFO       *NicInfo;\r
   EFI_IP_ADDRESS            Ip;\r
 \r
+  ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r
+\r
+  Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = IfrFormNvData->Configure;\r
+  Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = IfrFormNvData->DhcpEnable;\r
+  Ip4StrToIp (IfrFormNvData->StationAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp);\r
+  Ip4StrToIp (IfrFormNvData->SubnetMask, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask);\r
+  Ip4StrToIp (IfrFormNvData->GatewayAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway);\r
+\r
   if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured) {\r
     //\r
     // Clear the variable\r
@@ -332,8 +338,8 @@ Ip4DeviceExtractConfig (
   )\r
 {\r
   EFI_STATUS                       Status;\r
-  UINTN                            ConfigLen;\r
   NIC_IP4_CONFIG_INFO              *IfrDeviceNvData;\r
+  NIC_IP4_CONFIG_INFO              *NicConfig;\r
   IP4_CONFIG_INSTANCE              *Ip4ConfigInstance;\r
   IP4_CONFIG_IFR_NVDATA            *IfrFormNvData;\r
   EFI_STRING                       ConfigRequestHdr;\r
@@ -367,12 +373,12 @@ Ip4DeviceExtractConfig (
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    ConfigLen = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2;\r
-    Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, IfrDeviceNvData);\r
-    if (EFI_ERROR (Status)) {\r
-      FreePool (IfrDeviceNvData);\r
+    NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);\r
+    if (NicConfig == NULL) {\r
       return EFI_NOT_FOUND;\r
     }\r
+    CopyMem (IfrDeviceNvData, NicConfig, SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig));\r
+    FreePool (NicConfig);\r
 \r
     ConfigRequest = Request;\r
     if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
@@ -415,11 +421,11 @@ Ip4DeviceExtractConfig (
     if (EFI_ERROR (Status)) {\r
       goto Failure;\r
     }\r
-  } \r
-  \r
+  }\r
+\r
   if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
 \r
-    IfrFormNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
+    IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r
     if (IfrFormNvData == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -442,7 +448,7 @@ Ip4DeviceExtractConfig (
       UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
       FreePool (ConfigRequestHdr);\r
     }\r
\r
+\r
     //\r
     // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
     //\r
@@ -499,7 +505,7 @@ Failure:
   } else if (StrStr (Request, L"OFFSET") == NULL) {\r
     *Progress = Request + StrLen (Request);\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -556,6 +562,11 @@ Ip4DeviceRouteConfig (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  //\r
+  // Reclaim Ip4Config variable\r
+  //\r
+  Ip4ConfigReclaimVariable ();\r
+\r
   *Progress = Configuration;\r
 \r
   Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r
@@ -581,7 +592,7 @@ Ip4DeviceRouteConfig (
                                   Progress\r
                                   );\r
     if (!EFI_ERROR (Status)) {\r
-      Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);\r
+      Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);\r
     }\r
 \r
     FreePool (IfrFormNvData);\r
@@ -604,9 +615,13 @@ Ip4DeviceRouteConfig (
     if (!EFI_ERROR (Status)) {\r
       ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS));\r
       if (CompareMem (&IfrDeviceNvData->NicAddr.MacAddr, &ZeroMac, IfrDeviceNvData->NicAddr.Len) != 0) {\r
-        BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * IfrDeviceNvData->Ip4Info.RouteTableSize;\r
+        BufferSize = SIZEOF_NIC_IP4_CONFIG_INFO (IfrDeviceNvData);\r
         NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData);\r
+        if (NicInfo == NULL) {\r
+          return EFI_OUT_OF_RESOURCES;\r
+        }\r
         Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\r
+        FreePool (NicInfo);\r
       } else {\r
         ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r
         Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);\r
@@ -662,7 +677,6 @@ Ip4FormCallback (
   )\r
 {\r
   IP4_CONFIG_INSTANCE       *Ip4ConfigInstance;\r
-  CHAR8                     Ip4String[IP4_STR_MAX_SIZE];\r
   IP4_CONFIG_IFR_NVDATA     *IfrFormNvData;\r
   EFI_IP_ADDRESS            HostIp;\r
   EFI_IP_ADDRESS            SubnetMask;\r
@@ -670,11 +684,11 @@ Ip4FormCallback (
   EFI_STATUS                Status;\r
   EFI_INPUT_KEY             Key;\r
 \r
-  if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
+  if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
     //\r
     // Do nothing for UEFI OPEN/CLOSE Action\r
     //\r
-    return EFI_SUCCESS;
+    return EFI_SUCCESS;\r
   }\r
 \r
   Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r
@@ -695,27 +709,8 @@ Ip4FormCallback (
   Status = EFI_SUCCESS;\r
 \r
   switch (QuestionId) {\r
-\r
-  case KEY_ENABLE:\r
-    if (IfrFormNvData->Configure == 0) {\r
-      Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = FALSE;\r
-    } else {\r
-      Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = TRUE;\r
-    }\r
-    break;\r
-\r
-  case KEY_DHCP_ENABLE:\r
-    if (IfrFormNvData->DhcpEnable == 0) {\r
-      Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE;\r
-    } else {\r
-      Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE;\r
-    }\r
-\r
-    break;\r
-\r
   case KEY_LOCAL_IP:\r
-    UnicodeStrToAsciiStr (IfrFormNvData->StationAddress, Ip4String);\r
-    Status = Ip4AsciiStrToIp (Ip4String, &HostIp.v4);\r
+    Status = Ip4StrToIp (IfrFormNvData->StationAddress, &HostIp.v4);\r
     if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -726,10 +721,9 @@ Ip4FormCallback (
     break;\r
 \r
   case KEY_SUBNET_MASK:\r
-    UnicodeStrToAsciiStr (IfrFormNvData->SubnetMask, Ip4String);\r
-    Status = Ip4AsciiStrToIp (Ip4String, &SubnetMask.v4);\r
+    Status = Ip4StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);\r
     if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
-      CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid SubnetMask!", NULL);\r
+      CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
       CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
@@ -738,8 +732,7 @@ Ip4FormCallback (
     break;\r
 \r
   case KEY_GATE_WAY:\r
-    UnicodeStrToAsciiStr (IfrFormNvData->GatewayAddress, Ip4String);\r
-    Status = Ip4AsciiStrToIp (Ip4String, &Gateway.v4);\r
+    Status = Ip4StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r
     if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -750,25 +743,14 @@ Ip4FormCallback (
     break;\r
 \r
   case KEY_SAVE_CHANGES:\r
-\r
-    Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);\r
-\r
+    Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);\r
     *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
-\r
     break;\r
 \r
   default:\r
-\r
     break;\r
   }\r
 \r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Pass changed uncommitted data back to Form Browser\r
-    //\r
-    HiiSetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData, NULL);\r
-  }\r
-\r
   FreePool (IfrFormNvData);\r
 \r
   return Status;\r
index 2d75c6d90e51a9bc763fa76cef07d8638058f557..3b4168e974071a2ddc4bb445c815c1041aa82d0a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The header file of IP4ConfigNv.c\r
 \r
-Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2010, 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
@@ -21,7 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 extern UINT8  Ip4ConfigDxeBin[];\r
 extern UINT8  Ip4ConfigDxeStrings[];\r
 \r
-#define NIC_ITEM_CONFIG_SIZE   sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE\r
+#define NIC_ITEM_CONFIG_SIZE   (sizeof (NIC_IP4_CONFIG_INFO) + (sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE))\r
 \r
 \r
 /**\r
index 59996ea77b0c14edad5439ae2e1d101690fd3b3c..5ae6ea8c45a33961342debe1d4c7be81963ee2be 100644 (file)
@@ -40,7 +40,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /// of variable length.\r
 ///\r
 typedef struct {\r
-  UINT16          NicAddr[3];                        ///< NIC MAC address\r
   UINT8           Configure;                         ///< NIC configure status\r
   UINT8           DhcpEnable;                        ///< Static or DHCP\r
   CHAR16          StationAddress[IP4_STR_MAX_SIZE];  ///< IP addresses\r
index 2d645beec0dd98d28a0e540c25d8b3712c2853eb..f283db019d75c7ee76fbf859210357c779424d8c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Routines used to operate the Ip4 configure variable.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, 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<BR>\r
@@ -12,8 +12,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
+#include "Ip4Config.h"\r
 #include "NicIp4Variable.h"\r
 \r
+BOOLEAN  mIp4ConfigVariableReclaimed = FALSE;\r
 \r
 /**\r
   Check whether the configure parameter is valid.\r
@@ -77,302 +79,225 @@ Ip4ConfigIsValid (
 /**\r
   Read the ip4 configure variable from the EFI variable.\r
 \r
-  None\r
+  @param  Instance     The IP4 CONFIG instance.\r
 \r
-  @return The IP4 configure read if it is there and is valid, otherwise NULL\r
+  @return The IP4 configure read if it is there and is valid, otherwise NULL.\r
 \r
 **/\r
-IP4_CONFIG_VARIABLE *\r
+NIC_IP4_CONFIG_INFO *\r
 Ip4ConfigReadVariable (\r
-  VOID\r
+  IN  IP4_CONFIG_INSTANCE   *Instance\r
   )\r
 {\r
-  IP4_CONFIG_VARIABLE       *Variable;\r
-  EFI_STATUS                Status;\r
-  UINTN                     Size;\r
-  UINT16                    CheckSum;\r
-\r
-  //\r
-  // Get the size of variable, then allocate a buffer to read the variable.\r
-  //\r
-  Size     = 0;\r
-  Variable = NULL;\r
-  Status   = gRT->GetVariable (\r
-                    EFI_NIC_IP4_CONFIG_VARIABLE,\r
-                    &gEfiNicIp4ConfigVariableGuid,\r
-                    NULL,\r
-                    &Size,\r
-                    NULL\r
-                    );\r
-\r
-  if (Status != EFI_BUFFER_TOO_SMALL) {\r
-    return NULL;\r
-  }\r
-\r
-  if (Size < sizeof (IP4_CONFIG_VARIABLE)) {\r
-    goto REMOVE_VARIABLE;\r
-  }\r
-\r
-  Variable = AllocatePool (Size);\r
+  NIC_IP4_CONFIG_INFO *NicConfig;\r
 \r
-  if (Variable == NULL) {\r
-    return NULL;\r
+  NicConfig = GetVariable (Instance->MacString, &gEfiNicIp4ConfigVariableGuid);\r
+  if (NicConfig != NULL) {\r
+    Ip4ConfigFixRouteTablePointer (&NicConfig->Ip4Info);\r
   }\r
 \r
-  Status = gRT->GetVariable (\r
-                  EFI_NIC_IP4_CONFIG_VARIABLE,\r
-                  &gEfiNicIp4ConfigVariableGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  Variable\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  //\r
-  // Verify the checksum, variable size and count\r
-  //\r
-  CheckSum = (UINT16) (~NetblockChecksum ((UINT8 *) Variable, (UINT32)Size));\r
-\r
-  if ((CheckSum != 0) || (Size != Variable->Len)) {\r
-    goto REMOVE_VARIABLE;\r
-  }\r
-\r
-  if ((Variable->Count < 1) || (Variable->Count > MAX_IP4_CONFIG_IN_VARIABLE)) {\r
-    goto REMOVE_VARIABLE;\r
-  }\r
-\r
-  return Variable;\r
-\r
-REMOVE_VARIABLE:\r
-  Ip4ConfigWriteVariable (NULL);\r
-\r
-ON_ERROR:\r
-  if (Variable != NULL) {\r
-    FreePool (Variable);\r
-  }\r
-\r
-  return NULL;\r
+  return NicConfig;\r
 }\r
 \r
-\r
 /**\r
   Write the IP4 configure variable to the NVRAM. If Config\r
   is NULL, remove the variable.\r
 \r
-  @param  Config       The IP4 configure data to write\r
+  @param  Instance     The IP4 CONFIG instance.\r
+  @param  NicConfig    The IP4 configure data to write.\r
 \r
-  @retval EFI_SUCCESS  The variable is written to the NVRam\r
+  @retval EFI_SUCCESS  The variable is written to the NVRam.\r
   @retval Others       Failed to write the variable.\r
 \r
 **/\r
 EFI_STATUS\r
 Ip4ConfigWriteVariable (\r
-  IN IP4_CONFIG_VARIABLE    *Config        OPTIONAL\r
+  IN IP4_CONFIG_INSTANCE    *Instance,\r
+  IN NIC_IP4_CONFIG_INFO    *NicConfig OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
+  EFI_STATUS  Status;\r
 \r
   Status = gRT->SetVariable (\r
-                  EFI_NIC_IP4_CONFIG_VARIABLE,\r
+                  Instance->MacString,\r
                   &gEfiNicIp4ConfigVariableGuid,\r
                   IP4_CONFIG_VARIABLE_ATTRIBUTES,\r
-                  (Config == NULL) ? 0 : Config->Len,\r
-                  Config\r
+                  (NicConfig == NULL) ? 0 : SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig),\r
+                  NicConfig\r
                   );\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
-  Locate the IP4 configure parameters from the variable.If a\r
-  configuration is found, copy it to a newly allocated block\r
-  of memory to avoid the alignment problem. Caller should\r
-  release the memory after use.\r
+  Check whether a NIC exist in the platform given its MAC address.\r
 \r
-  @param  Variable     The IP4 configure variable to search in\r
-  @param  NicAddr      The interface address to check\r
+  @param  NicAddr      The MAC address for the NIC to be checked.\r
 \r
-  @return The point to the NIC's IP4 configure info if it is found\r
-          in the IP4 variable, otherwise NULL.\r
+  @retval TRUE         The NIC exist in the platform.\r
+  @retval FALSE        The NIC doesn't exist in the platform.\r
 \r
 **/\r
-NIC_IP4_CONFIG_INFO *\r
-Ip4ConfigFindNicVariable (\r
-  IN IP4_CONFIG_VARIABLE    *Variable,\r
+BOOLEAN\r
+Ip4ConfigIsNicExist (\r
   IN NIC_ADDR               *NicAddr\r
   )\r
 {\r
-  NIC_IP4_CONFIG_INFO       Temp;\r
-  NIC_IP4_CONFIG_INFO       *Config;\r
-  UINT32                    Index;\r
-  UINT8                     *Cur;\r
-  UINT32                    Len;\r
-\r
-  Cur = (UINT8*)&Variable->ConfigInfo;\r
+  EFI_STATUS      Status;\r
+  EFI_HANDLE      *HandleBuffer;\r
+  UINTN           NumberOfHandles;\r
+  UINTN           Index;\r
+  BOOLEAN         Found;\r
+  UINTN           AddrSize;\r
+  EFI_MAC_ADDRESS MacAddr;\r
 \r
-  for (Index = 0; Index < Variable->Count; Index++) {\r
-    //\r
-    // Copy the data to Temp to avoid the alignment problems\r
-    //\r
-    CopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));\r
-    Len = SIZEOF_NIC_IP4_CONFIG_INFO (&Temp);\r
+  //\r
+  // Locate Service Binding handles.\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                 ByProtocol,\r
+                 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+                 NULL,\r
+                 &NumberOfHandles,\r
+                 &HandleBuffer\r
+                 );\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
 \r
+  Found = FALSE;\r
+  for (Index = 0; Index < NumberOfHandles; Index++) {\r
     //\r
-    // Found the matching configuration parameters, allocate\r
-    // a block of memory then copy it out.\r
+    // Get MAC address.\r
     //\r
-    if (NIC_ADDR_EQUAL (&Temp.NicAddr, NicAddr)) {\r
-      Config = AllocatePool (Len);\r
-\r
-      if (Config == NULL) {\r
-        return NULL;\r
-      }\r
-\r
-      CopyMem (Config, Cur, Len);\r
-      Ip4ConfigFixRouteTablePointer (&Config->Ip4Info);\r
-      return Config;\r
+    AddrSize = 0;\r
+    Status = NetLibGetMacAddress (HandleBuffer[Index], &MacAddr, &AddrSize);\r
+    if (EFI_ERROR (Status)) {\r
+      Found = FALSE;\r
+      goto Exit;\r
     }\r
 \r
-    Cur += Len;\r
+    if ((NicAddr->Len == AddrSize) && (CompareMem (NicAddr->MacAddr.Addr, MacAddr.Addr, AddrSize) == 0)) {\r
+      Found = TRUE;\r
+      goto Exit;\r
+    }\r
   }\r
 \r
-  return NULL;\r
+Exit:\r
+  FreePool (HandleBuffer);\r
+  return Found;\r
 }\r
 \r
-\r
 /**\r
-  Modify the configuration parameter for the NIC in the variable.\r
-  If Config is NULL, old configuration will be remove from the new\r
-  variable. Otherwise, append it or replace the old one.\r
-\r
-  @param  Variable     The IP4 variable to change\r
-  @param  NicAddr      The interface to search\r
-  @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
-          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
+  Reclaim Ip4Config Variables for NIC which has been removed from the platform.\r
 \r
 **/\r
-IP4_CONFIG_VARIABLE *\r
-Ip4ConfigModifyVariable (\r
-  IN IP4_CONFIG_VARIABLE    *Variable     OPTIONAL,\r
-  IN NIC_ADDR               *NicAddr,\r
-  IN NIC_IP4_CONFIG_INFO    *Config       OPTIONAL\r
+VOID\r
+Ip4ConfigReclaimVariable (\r
+  VOID\r
   )\r
 {\r
-  NIC_IP4_CONFIG_INFO       Temp;\r
-  NIC_IP4_CONFIG_INFO       *Old;\r
-  IP4_CONFIG_VARIABLE       *NewVar;\r
-  UINT32                    Len;\r
-  UINT32                    TotalLen;\r
-  UINT32                    Count;\r
-  UINT8                     *Next;\r
-  UINT8                     *Cur;\r
-  UINT32                    Index;\r
-\r
-  ASSERT ((Variable != NULL) || (Config != NULL));\r
+  EFI_STATUS           Status;\r
+  UINTN                VariableNameSize;\r
+  CHAR16               *VariableName;\r
+  CHAR16               *CurrentVariableName;\r
+  EFI_GUID             VendorGuid;\r
+  UINTN                VariableNameBufferSize;\r
+  NIC_IP4_CONFIG_INFO  *NicConfig;\r
 \r
   //\r
-  // Compute the total length\r
+  // Check whether we need perform reclaim.\r
   //\r
-  if (Variable != NULL) {\r
-    //\r
-    // Variable != NULL, then Config can be NULL or not.  and so is\r
-    // the Old. If old configure exists, it is removed from the\r
-    // Variable. New configure is append to the variable.\r
-    //\r
-    //\r
-    Count     = Variable->Count;\r
-    Cur       = (UINT8 *)&Variable->ConfigInfo;\r
-    TotalLen  = Variable->Len;\r
+  if (mIp4ConfigVariableReclaimed) {\r
+    return;\r
+  }\r
+  mIp4ConfigVariableReclaimed = TRUE;\r
 \r
-    Old       = Ip4ConfigFindNicVariable (Variable, NicAddr);\r
+  //\r
+  // Get all Ip4Config Variable.\r
+  //\r
+  VariableNameSize = sizeof (CHAR16);\r
+  VariableName = AllocateZeroPool (VariableNameSize);\r
+  VariableNameBufferSize = VariableNameSize;\r
+\r
+  while (TRUE) {\r
+    Status = gRT->GetNextVariableName (\r
+                    &VariableNameSize,\r
+                    VariableName,\r
+                    &VendorGuid\r
+                    );\r
 \r
-    if (Old != NULL) {\r
-      TotalLen -= SIZEOF_NIC_IP4_CONFIG_INFO (Old);\r
-      FreePool (Old);\r
+Check:\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      VariableName = ReallocatePool (VariableNameBufferSize, VariableNameSize, VariableName);\r
+      VariableNameBufferSize = VariableNameSize;\r
+      //\r
+      // Try again using the new buffer.\r
+      //\r
+      Status = gRT->GetNextVariableName (\r
+                      &VariableNameSize,\r
+                      VariableName,\r
+                      &VendorGuid\r
+                      );\r
     }\r
 \r
-    if (Config != NULL) {\r
-      TotalLen += SIZEOF_NIC_IP4_CONFIG_INFO (Config);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // No more variable available, finish search.\r
+      //\r
+      break;\r
     }\r
 \r
     //\r
-    // Return NULL if the only NIC_IP4_CONFIG_INFO is being removed.\r
+    // Check variable GUID.\r
     //\r
-    if (TotalLen < sizeof (IP4_CONFIG_VARIABLE)) {\r
-      return NULL;\r
+    if (!CompareGuid (&VendorGuid, &gEfiNicIp4ConfigVariableGuid)) {\r
+      continue;\r
     }\r
 \r
-  } else {\r
-    //\r
-    // Variable == NULL and Config != NULL, Create a new variable with\r
-    // this NIC configure.\r
-    //\r
-    Count     = 0;\r
-    Cur       = NULL;\r
-    TotalLen  = sizeof (IP4_CONFIG_VARIABLE) - sizeof (NIC_IP4_CONFIG_INFO)\r
-                + SIZEOF_NIC_IP4_CONFIG_INFO (Config);\r
-  }\r
-\r
-  ASSERT (TotalLen >= sizeof (IP4_CONFIG_VARIABLE));\r
-\r
-  NewVar = AllocateZeroPool (TotalLen);\r
-\r
-  if (NewVar == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  NewVar->Len = TotalLen;\r
-\r
-  //\r
-  // Copy the other configure parameters from the old variable\r
-  //\r
-  Next = (UINT8 *)&NewVar->ConfigInfo;\r
-\r
-  for (Index = 0; Index < Count; Index++) {\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
-      CopyMem (Next, Cur, Len);\r
-      Next += Len;\r
-      NewVar->Count++;\r
+    NicConfig = GetVariable (VariableName, &gEfiNicIp4ConfigVariableGuid);\r
+    if (NicConfig == NULL) {\r
+      break;\r
     }\r
 \r
-    Cur += Len;\r
-  }\r
-\r
-  //\r
-  // Append the new configure if it isn't NULL.\r
-  //\r
-  Len = 0;\r
-\r
-  if (Config != NULL) {\r
-    Len = SIZEOF_NIC_IP4_CONFIG_INFO (Config);\r
-\r
-    CopyMem (Next, Config, Len);\r
-    NewVar->Count++;\r
+    if (!Ip4ConfigIsNicExist (&NicConfig->NicAddr)) {\r
+      //\r
+      // No NIC found for this Ip4Config variable, remove it.\r
+      // Since we are in loop of GetNextVariableName(), we need move on to next\r
+      // Variable first and then delete current Variable.\r
+      //\r
+      CurrentVariableName = AllocateCopyPool (VariableNameSize, VariableName);\r
+      Status = gRT->GetNextVariableName (\r
+                      &VariableNameSize,\r
+                      VariableName,\r
+                      &VendorGuid\r
+                      );\r
+\r
+      gRT->SetVariable (\r
+             CurrentVariableName,\r
+             &gEfiNicIp4ConfigVariableGuid,\r
+             IP4_CONFIG_VARIABLE_ATTRIBUTES,\r
+             0,\r
+             NULL\r
+             );\r
+      FreePool (CurrentVariableName);\r
+\r
+      //\r
+      // We already get next variable, go to check it.\r
+      //\r
+      goto Check;\r
+    }\r
   }\r
 \r
-  ASSERT (Next + Len == (UINT8 *) NewVar + TotalLen);\r
-\r
-  NewVar->CheckSum = (UINT16) (~NetblockChecksum ((UINT8 *) NewVar, TotalLen));\r
-  return NewVar;\r
+  FreePool (VariableName);\r
 }\r
 \r
 /**\r
-  Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure. \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
+\r
   @param  ConfigData     The IP4 IP configure data.\r
 \r
 **/\r
@@ -382,7 +307,7 @@ Ip4ConfigFixRouteTablePointer (
   )\r
 {\r
   //\r
-  // The memory used for route table entries must immediately follow \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
index 89e5503c52fff2a65f797481cc165c2cd530518d..2f8defe789002dd4b227eb62918b8f6d63f3313b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Routines used to operate the Ip4 configure variable.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, 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<BR>\r
@@ -15,29 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef _NIC_IP4_VARIABLE_H_\r
 #define _NIC_IP4_VARIABLE_H_\r
 \r
-#include <Uefi.h>\r
-\r
-#include <Guid/NicIp4ConfigNvData.h>\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
-///\r
-/// IP4_CONFIG_VARIABLE is the EFI variable to\r
-/// save the configuration. IP4_CONFIG_VARIABLE is\r
-/// of variable length.\r
-///\r
-typedef struct {\r
-  UINT32                    Len;        ///< Total length of the variable\r
-  UINT16                    CheckSum;   ///< CheckSum, the same as IP4 head checksum\r
-  UINT32                    Count;      ///< Number of NIC_IP4_CONFIG_INFO follows\r
-  NIC_IP4_CONFIG_INFO       ConfigInfo;\r
-} IP4_CONFIG_VARIABLE;\r
-\r
 //\r
 // Return the size of NIC_IP4_CONFIG_INFO and EFI_IP4_IPCONFIG_DATA.\r
 // They are of variable size\r
@@ -73,78 +50,48 @@ Ip4ConfigIsValid (
 /**\r
   Read the ip4 configure variable from the EFI variable.\r
 \r
-  None\r
+  @param  Instance     The IP4 CONFIG instance.\r
 \r
-  @return The IP4 configure read if it is there and is valid, otherwise NULL\r
+  @return The IP4 configure read if it is there and is valid, otherwise NULL.\r
 \r
 **/\r
-IP4_CONFIG_VARIABLE *\r
+NIC_IP4_CONFIG_INFO *\r
 Ip4ConfigReadVariable (\r
-  VOID\r
+  IN  IP4_CONFIG_INSTANCE   *Instance\r
   );\r
 \r
 /**\r
   Write the IP4 configure variable to the NVRAM. If Config\r
   is NULL, remove the variable.\r
 \r
-  @param  Config       The IP4 configure data to write\r
+  @param  Instance     The IP4 CONFIG instance.\r
+  @param  NicConfig    The IP4 configure data to write.\r
 \r
-  @retval EFI_SUCCESS  The variable is written to the NVRam\r
+  @retval EFI_SUCCESS  The variable is written to the NVRam.\r
   @retval Others       Failed to write the variable.\r
 \r
 **/\r
 EFI_STATUS\r
 Ip4ConfigWriteVariable (\r
-  IN IP4_CONFIG_VARIABLE    *Config        OPTIONAL\r
+  IN IP4_CONFIG_INSTANCE    *Instance,\r
+  IN NIC_IP4_CONFIG_INFO    *NicConfig OPTIONAL\r
   );\r
 \r
 /**\r
-  Locate the IP4 configure parameters from the variable.If a\r
-  configuration is found, copy it to a newly allocated block\r
-  of memory to avoid the alignment problem. Caller should\r
-  release the memory after use.\r
-\r
-  @param  Variable     The IP4 configure variable to search in\r
-  @param  NicAddr      The interface address to check\r
-\r
-  @return The point to the NIC's IP4 configure info if it is found\r
-          in the IP4 variable, otherwise NULL.\r
+  Reclaim Ip4Config Variables for NIC which has been removed from the platform.\r
 \r
 **/\r
-NIC_IP4_CONFIG_INFO *\r
-Ip4ConfigFindNicVariable (\r
-  IN IP4_CONFIG_VARIABLE    *Variable,\r
-  IN NIC_ADDR               *NicAddr\r
+VOID\r
+Ip4ConfigReclaimVariable (\r
+  VOID\r
   );\r
 \r
 /**\r
-  Modify the configuration parameter for the NIC in the variable.\r
-  If Config is NULL, old configuration will be remove from the new\r
-  variable. Otherwise, append it or replace the old one.\r
+  Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure.\r
 \r
-  @param  Variable     The IP4 variable to change\r
-  @param  NicAddr      The interface to search\r
-  @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
-          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 NIC_ADDR               *NicAddr,\r
-  IN NIC_IP4_CONFIG_INFO    *Config       OPTIONAL\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
+\r
   @param  ConfigData     The IP4 IP configure data.\r
 \r
 **/\r