]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
Fix a typo in Ip4ConfigDriverBindingStart(): it should be gEfiManagedNetworkServiceBi...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4ConfigDxe / Ip4ConfigDriver.c
index 60cf318772ec23e30d96709ea84fd947c4c714d5..fdbb26cd78a69f04e47efc33f36f3bf374ce8f1f 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   The driver binding for IP4 CONFIG protocol.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\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
 http://opensource.org/licenses/bsd-license.php\r
@@ -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,41 +26,59 @@ 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
+// The intance of template of IP4 Config private data\r
+//\r
+IP4_CONFIG_INSTANCE        mIp4ConfigTemplate = {\r
+  IP4_CONFIG_INSTANCE_SIGNATURE,\r
+  NULL,\r
+  NULL,\r
+  (EFI_DEVICE_PATH_PROTOCOL *) NULL,\r
+  {\r
+    NULL,\r
+    NULL,\r
+    NULL\r
+  },\r
+  {\r
+    NULL,\r
+    NULL,\r
+    NULL\r
+  },\r
+  NULL,\r
+  (EFI_DEVICE_PATH_PROTOCOL *) NULL,\r
+  NULL,\r
+  {\r
+    FALSE,\r
+    FALSE,\r
+    {\r
+      0\r
+    },\r
+    {\r
+      0\r
+    },\r
+    {\r
+      0\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
+  0,\r
+  (EFI_MANAGED_NETWORK_PROTOCOL *) NULL,\r
+  NULL,\r
+  NULL,\r
+  NULL,\r
+  EFI_NOT_READY,\r
+  {\r
+    0,\r
+    0,\r
+    {\r
+      0\r
+    }\r
+  },\r
+  (CHAR16 *) NULL,\r
+  (NIC_IP4_CONFIG_INFO *) NULL,\r
+  (EFI_DHCP4_PROTOCOL *) NULL,\r
+  NULL,\r
+  NULL\r
+};\r
 \r
 /**\r
   The entry point for IP4 config driver which install the driver\r
@@ -152,13 +171,10 @@ 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
+\r
   Status = gBS->HandleProtocol (\r
                   ControllerHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
@@ -218,14 +234,13 @@ Ip4ConfigDriverBindingStart (
   //\r
   // Allocate an instance then initialize it\r
   //\r
-  Instance = AllocatePool (sizeof (IP4_CONFIG_INSTANCE));\r
+  Instance = AllocateCopyPool (sizeof (IP4_CONFIG_INSTANCE), &mIp4ConfigTemplate);\r
 \r
   if (Instance == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_ERROR;\r
   }\r
 \r
-  Instance->Signature         = IP4_CONFIG_INSTANCE_SIGNATURE;\r
   Instance->Controller        = ControllerHandle;\r
   Instance->Image             = This->DriverBindingHandle;\r
   Instance->ParentDevicePath  = ParentDevicePath;\r
@@ -236,15 +251,6 @@ Ip4ConfigDriverBindingStart (
   Instance->Mnp               = Mnp;\r
   Instance->MnpHandle         = MnpHandle;\r
 \r
-  Instance->DoneEvent         = NULL;\r
-  Instance->ReconfigEvent     = NULL;\r
-  Instance->Result            = EFI_NOT_READY;\r
-  Instance->NicConfig         = NULL;\r
-\r
-  Instance->Dhcp4             = NULL;\r
-  Instance->Dhcp4Handle       = NULL;\r
-  Instance->Dhcp4Event        = NULL;\r
-\r
   Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r
 \r
   if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
@@ -258,30 +264,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 +282,6 @@ Ip4ConfigDriverBindingStart (
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    mIp4ConfigNicList[Index] = NULL;\r
     goto ON_ERROR;\r
   }\r
 \r
@@ -299,50 +289,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
@@ -365,7 +332,7 @@ ON_ERROR:
   NetLibDestroyServiceChild (\r
     ControllerHandle,\r
     This->DriverBindingHandle,\r
-    &gEfiManagedNetworkProtocolGuid,\r
+    &gEfiManagedNetworkServiceBindingProtocolGuid,\r
     MnpHandle\r
     );\r
 \r
@@ -505,10 +472,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