]> 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 7f0149fa009bf0efcba0fd84fc3aa48a1db4c29d..fdbb26cd78a69f04e47efc33f36f3bf374ce8f1f 100644 (file)
 /** @file\r
 /** @file\r
+  The driver binding for IP4 CONFIG protocol.\r
 \r
 \r
-Copyright (c) 2006, Intel Corporation\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
 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
 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
-  Ip4ConfigDriver.c\r
-\r
-Abstract:\r
-\r
-  The driver binding for IP4 CONFIG protocol.\r
-\r
-\r
 **/\r
 \r
 \r
 #include "Ip4Config.h"\r
 **/\r
 \r
 \r
 #include "Ip4Config.h"\r
+#include "Ip4ConfigNv.h"\r
+#include "NicIp4Variable.h"\r
 \r
 \r
+EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {\r
+  Ip4ConfigDriverBindingSupported,\r
+  Ip4ConfigDriverBindingStart,\r
+  Ip4ConfigDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\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
+  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
 \r
 /**\r
-  Stop all the auto configuration when the IP4 configure driver is\r
-  being unloaded.\r
+  The entry point for IP4 config driver which install the driver\r
+  binding and component name protocol on its image.\r
 \r
 \r
-  @param  ImageHandle          The driver that is being unloaded\r
+  @param  ImageHandle            The image handle of the driver.\r
+  @param  SystemTable            The system table.\r
 \r
 \r
-  @retval EFI_SUCCESS          The driver has been ready for unload.\r
+  @retval EFI_SUCCES             All the related protocols are installed on the driver.\r
+  @retval Others                 Failed to install protocols.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\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
-EFI_STATUS\r
 Ip4ConfigDriverEntryPoint (\r
   IN EFI_HANDLE             ImageHandle,\r
   IN EFI_SYSTEM_TABLE       *SystemTable\r
   )\r
 Ip4ConfigDriverEntryPoint (\r
   IN EFI_HANDLE             ImageHandle,\r
   IN EFI_SYSTEM_TABLE       *SystemTable\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  The entry point for IP4 config driver which install the driver\r
-  binding and component name protocol on its image.\r
-\r
-Arguments:\r
-\r
-  ImageHandle - The Image handle of the driver\r
-  SystemTable - The system table\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - All the related protocols are installed on the driver\r
-  Others      - Failed to install the protocol\r
-\r
---*/\r
 {\r
   return EfiLibInstallDriverBindingComponentName2 (\r
            ImageHandle,\r
 {\r
   return EfiLibInstallDriverBindingComponentName2 (\r
            ImageHandle,\r
@@ -158,11 +171,18 @@ Ip4ConfigDriverBindingStart (
   EFI_HANDLE                    MnpHandle;\r
   IP4_CONFIG_INSTANCE           *Instance;\r
   EFI_SIMPLE_NETWORK_MODE       SnpMode;\r
   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
   NIC_IP4_CONFIG_INFO           *NicConfig;\r
-  IP4_CONFIG_VARIABLE           *NewVariable;\r
   EFI_STATUS                    Status;\r
   EFI_STATUS                    Status;\r
-  UINT32                        Index;\r
+  EFI_DEVICE_PATH_PROTOCOL      *ParentDevicePath;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Check for multiple start.\r
 \r
   //\r
   // Check for multiple start.\r
@@ -214,33 +234,23 @@ Ip4ConfigDriverBindingStart (
   //\r
   // Allocate an instance then initialize it\r
   //\r
   //\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
 \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->Controller        = ControllerHandle;\r
   Instance->Image             = This->DriverBindingHandle;\r
+  Instance->ParentDevicePath  = ParentDevicePath;\r
 \r
   CopyMem (&Instance->Ip4ConfigProtocol, &mIp4ConfigProtocolTemplate, sizeof (mIp4ConfigProtocolTemplate));\r
 \r
   CopyMem (&Instance->Ip4ConfigProtocol, &mIp4ConfigProtocolTemplate, sizeof (mIp4ConfigProtocolTemplate));\r
-  CopyMem (&Instance->NicIp4Protocol, &mNicIp4ConfigProtocolTemplate, sizeof (mNicIp4ConfigProtocolTemplate));\r
 \r
   Instance->State             = IP4_CONFIG_STATE_IDLE;\r
   Instance->Mnp               = Mnp;\r
   Instance->MnpHandle         = MnpHandle;\r
 \r
 \r
   Instance->State             = IP4_CONFIG_STATE_IDLE;\r
   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
   Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r
 \r
   if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
@@ -249,53 +259,29 @@ Ip4ConfigDriverBindingStart (
 \r
   Instance->NicAddr.Type    = (UINT16) SnpMode.IfType;\r
   Instance->NicAddr.Len     = (UINT8) SnpMode.HwAddressSize;\r
 \r
   Instance->NicAddr.Type    = (UINT16) SnpMode.IfType;\r
   Instance->NicAddr.Len     = (UINT8) SnpMode.HwAddressSize;\r
-  CopyMem (&Instance->NicAddr.MacAddr, &SnpMode.CurrentAddress, sizeof (Instance->NicAddr.MacAddr));\r
+  CopyMem (&Instance->NicAddr.MacAddr, &SnpMode.CurrentAddress, Instance->NicAddr.Len);\r
 \r
   //\r
   // Add it to the global list, and compose the name\r
   //\r
 \r
   //\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
-        Instance->NicName[0]  = 'e';\r
-        Instance->NicName[1]  = 't';\r
-        Instance->NicName[2]  = 'h';\r
-        Instance->NicName[3]  = (UINT16) ('0' + Index);\r
-        Instance->NicName[4]  = 0;\r
-      } else {\r
-        Instance->NicName[0]  = 'u';\r
-        Instance->NicName[1]  = 'n';\r
-        Instance->NicName[2]  = 'k';\r
-        Instance->NicName[3]  = (UINT16) ('0' + Index);\r
-        Instance->NicName[4]  = 0;\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
     goto ON_ERROR;\r
   }\r
 \r
+  Status = Ip4ConfigDeviceInit (Instance);\r
+\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
                   &gEfiIp4ConfigProtocolGuid,\r
                   &Instance->Ip4ConfigProtocol,\r
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &ControllerHandle,\r
                   &gEfiIp4ConfigProtocolGuid,\r
                   &Instance->Ip4ConfigProtocol,\r
-                  &gEfiNicIp4ConfigProtocolGuid,\r
-                  &Instance->NicIp4Protocol,\r
                   NULL\r
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
                   NULL\r
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    mIp4ConfigNicList[Index] = NULL;\r
     goto ON_ERROR;\r
   }\r
 \r
     goto ON_ERROR;\r
   }\r
 \r
@@ -303,58 +289,35 @@ 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
   // 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
-    gBS->FreePool (NewVariable);\r
-  }\r
-\r
-ON_EXIT:\r
-  gBS->FreePool (Variable);\r
-\r
+  NicConfig = Ip4ConfigReadVariable (Instance);\r
   if (NicConfig != NULL) {\r
   if (NicConfig != NULL) {\r
-    gBS->FreePool (NicConfig);\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
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
   if (Instance != NULL) {\r
   }\r
 \r
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
   if (Instance != NULL) {\r
-    gBS->FreePool (Instance);\r
+    FreePool (Instance);\r
   }\r
 \r
   if (Mnp != NULL) {\r
   }\r
 \r
   if (Mnp != NULL) {\r
@@ -369,7 +332,7 @@ ON_ERROR:
   NetLibDestroyServiceChild (\r
     ControllerHandle,\r
     This->DriverBindingHandle,\r
   NetLibDestroyServiceChild (\r
     ControllerHandle,\r
     This->DriverBindingHandle,\r
-    &gEfiManagedNetworkProtocolGuid,\r
+    &gEfiManagedNetworkServiceBindingProtocolGuid,\r
     MnpHandle\r
     );\r
 \r
     MnpHandle\r
     );\r
 \r
@@ -471,6 +434,8 @@ Ip4ConfigDriverBindingStop (
 \r
   Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config);\r
 \r
 \r
   Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config);\r
 \r
+  Ip4ConfigDeviceUnload (Instance);\r
+\r
   //\r
   // Unload the protocols first to inform the top drivers\r
   //\r
   //\r
   // Unload the protocols first to inform the top drivers\r
   //\r
@@ -478,8 +443,6 @@ Ip4ConfigDriverBindingStop (
                   NicHandle,\r
                   &gEfiIp4ConfigProtocolGuid,\r
                   &Instance->Ip4ConfigProtocol,\r
                   NicHandle,\r
                   &gEfiIp4ConfigProtocolGuid,\r
                   &Instance->Ip4ConfigProtocol,\r
-                  &gEfiNicIp4ConfigProtocolGuid,\r
-                  &Instance->NicIp4Protocol,\r
                   NULL\r
                   );\r
 \r
                   NULL\r
                   );\r
 \r
@@ -509,18 +472,12 @@ Ip4ConfigDriverBindingStop (
     Instance->MnpHandle = NULL;\r
   }\r
 \r
     Instance->MnpHandle = NULL;\r
   }\r
 \r
+  if (Instance->MacString != NULL) {\r
+    FreePool (Instance->MacString);\r
+  }\r
+\r
   Ip4ConfigCleanConfig (Instance);\r
   Ip4ConfigCleanConfig (Instance);\r
-  mIp4ConfigNicList[Instance->NicIndex] = NULL;\r
-  gBS->FreePool (Instance);\r
+  FreePool (Instance);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
-\r
-EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {\r
-  Ip4ConfigDriverBindingSupported,\r
-  Ip4ConfigDriverBindingStart,\r
-  Ip4ConfigDriverBindingStop,\r
-  0xa,\r
-  NULL,\r
-  NULL\r
-};\r