/** @file\r
The driver binding for IP4 CONFIG protocol.\r
\r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2012, 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
\r
#include "Ip4Config.h"\r
#include "Ip4ConfigNv.h"\r
+#include "NicIp4Variable.h"\r
\r
EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {\r
Ip4ConfigDriverBindingSupported,\r
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
+ {\r
+ 0\r
+ }\r
+ },\r
+ {\r
+ {\r
+ 0\r
+ }\r
+ },\r
+ {\r
+ {\r
+ 0\r
+ }\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
+ {\r
+ 0\r
+ }\r
+ }\r
+ },\r
+ (CHAR16 *) NULL,\r
+ (NIC_IP4_CONFIG_INFO *) NULL,\r
+ (EFI_DHCP4_PROTOCOL *) NULL,\r
+ NULL,\r
+ NULL,\r
+ NULL,\r
+ TRUE,\r
+ FALSE\r
+};\r
\r
/**\r
The entry point for IP4 config driver which install the driver\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
- IP4_CONFIG_VARIABLE *NewVariable;\r
EFI_STATUS Status;\r
- UINT32 Index;\r
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
\r
Status = gBS->HandleProtocol (\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
- Instance->Signature = IP4_CONFIG_INSTANCE_SIGNATURE;\r
Instance->Controller = ControllerHandle;\r
Instance->Image = This->DriverBindingHandle;\r
Instance->ParentDevicePath = ParentDevicePath;\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
//\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
);\r
\r
if (EFI_ERROR (Status)) {\r
- mIp4ConfigNicList[Index] = NULL;\r
goto ON_ERROR;\r
}\r
\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
+ // A dedicated timer is used to poll underlying media status.\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
+ Status = gBS->CreateEvent (\r
+ EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
+ TPL_CALLBACK,\r
+ MediaChangeDetect,\r
+ Instance,\r
+ &Instance->Timer\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
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
}\r
\r
//\r
- // Delete the non-permant configuration and remove the previous\r
- // acquired DHCP parameters. Only doing DHCP itself is permant\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
- 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
+ //\r
+ // Delete the non-permanent configuration.\r
+ //\r
+ Ip4ConfigWriteVariable (Instance, NULL);\r
+ }\r
+\r
FreePool (NicConfig);\r
}\r
\r
NetLibDestroyServiceChild (\r
ControllerHandle,\r
This->DriverBindingHandle,\r
- &gEfiManagedNetworkProtocolGuid,\r
+ &gEfiManagedNetworkServiceBindingProtocolGuid,\r
MnpHandle\r
);\r
\r
Instance->MnpHandle = NULL;\r
}\r
\r
+ if (Instance->MacString != NULL) {\r
+ FreePool (Instance->MacString);\r
+ }\r
+\r
+ if (Instance->Timer != NULL) {\r
+ gBS->SetTimer (Instance->Timer, TimerCancel, 0);\r
+ gBS->CloseEvent (Instance->Timer);\r
+ Instance->Timer = NULL;\r
+ }\r
+ \r
Ip4ConfigCleanConfig (Instance);\r
- mIp4ConfigNicList[Instance->NicIndex] = NULL;\r
FreePool (Instance);\r
\r
return EFI_SUCCESS;\r
}\r
-\r