X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4ConfigDxe%2FIp4ConfigDriver.c;h=56cce6e6f09817e85774b6bdf2679afc09daaabf;hb=2638c111076f9a49d4766ca5acbafa0eb7f66a18;hp=081db47d49caf1146547d48641f0723ddbca5dd0;hpb=67a58d0ffddc625bda615b9fb2b335e8d7ab979f;p=mirror_edk2.git
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
index 081db47d49..56cce6e6f0 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
@@ -1,90 +1,116 @@
/** @file
+ The driver binding for IP4 CONFIG protocol.
-Copyright (c) 2006, Intel Corporation
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
+which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-Module Name:
-
- Ip4ConfigDriver.c
-
-Abstract:
-
- The driver binding for IP4 CONFIG protocol.
-
-
**/
#include "Ip4Config.h"
+#include "Ip4ConfigNv.h"
+#include "NicIp4Variable.h"
+EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {
+ Ip4ConfigDriverBindingSupported,
+ Ip4ConfigDriverBindingStart,
+ Ip4ConfigDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+//
+// The intance of template of IP4 Config private data
+//
+IP4_CONFIG_INSTANCE mIp4ConfigTemplate = {
+ IP4_CONFIG_INSTANCE_SIGNATURE,
+ NULL,
+ NULL,
+ (EFI_DEVICE_PATH_PROTOCOL *) NULL,
+ {
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ NULL,
+ NULL,
+ NULL
+ },
+ NULL,
+ (EFI_DEVICE_PATH_PROTOCOL *) NULL,
+ NULL,
+ {
+ FALSE,
+ FALSE,
+ {
+ {
+ 0
+ }
+ },
+ {
+ {
+ 0
+ }
+ },
+ {
+ {
+ 0
+ }
+ }
+ },
+ 0,
+ (EFI_MANAGED_NETWORK_PROTOCOL *) NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ {
+ 0,
+ 0,
+ {
+ {
+ 0
+ }
+ }
+ },
+ (CHAR16 *) NULL,
+ (NIC_IP4_CONFIG_INFO *) NULL,
+ (EFI_DHCP4_PROTOCOL *) NULL,
+ NULL,
+ NULL,
+ NULL,
+ TRUE,
+ FALSE
+};
/**
- Stop all the auto configuration when the IP4 configure driver is
- being unloaded.
+ The entry point for IP4 config driver which install the driver
+ binding and component name protocol on its image.
- @param ImageHandle The driver that is being unloaded
+ @param ImageHandle The image handle of the driver.
+ @param SystemTable The system table.
- @retval EFI_SUCCESS The driver has been ready for unload.
+ @retval EFI_SUCCES All the related protocols are installed on the driver.
+ @retval Others Failed to install protocols.
**/
EFI_STATUS
EFIAPI
-EfiIp4ConfigUnload (
- IN EFI_HANDLE ImageHandle
- )
-{
- UINT32 Index;
-
- //
- // Stop all the IP4_CONFIG instances
- //
- for (Index = 0; Index < MAX_IP4_CONFIG_IN_VARIABLE; Index++) {
- if (mIp4ConfigNicList[Index] == NULL) {
- continue;
- }
-
- gIp4ConfigDriverBinding.Stop (
- &gIp4ConfigDriverBinding,
- mIp4ConfigNicList[Index]->MnpHandle,
- 0,
- NULL
- );
- }
-
- return NetLibDefaultUnload (ImageHandle);
-}
-
-
-EFI_STATUS
Ip4ConfigDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
-/*++
-
-Routine Description:
-
- The entry point for IP4 config driver which install the driver
- binding and component name protocol on its image.
-
-Arguments:
-
- ImageHandle - The Image handle of the driver
- SystemTable - The system table
-
-Returns:
-
- EFI_SUCCESS - All the related protocols are installed on the driver
- Others - Failed to install the protocol
-
---*/
{
+ mIp4ConfigTemplate.Result = EFI_NOT_READY;
+
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
@@ -158,11 +184,18 @@ Ip4ConfigDriverBindingStart (
EFI_HANDLE MnpHandle;
IP4_CONFIG_INSTANCE *Instance;
EFI_SIMPLE_NETWORK_MODE SnpMode;
- IP4_CONFIG_VARIABLE *Variable;
NIC_IP4_CONFIG_INFO *NicConfig;
- IP4_CONFIG_VARIABLE *NewVariable;
EFI_STATUS Status;
- UINT32 Index;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+
+ Status = gBS->HandleProtocol (
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID **) &ParentDevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
//
// Check for multiple start.
@@ -214,33 +247,23 @@ Ip4ConfigDriverBindingStart (
//
// Allocate an instance then initialize it
//
- Instance = NetAllocatePool (sizeof (IP4_CONFIG_INSTANCE));
+ Instance = AllocateCopyPool (sizeof (IP4_CONFIG_INSTANCE), &mIp4ConfigTemplate);
if (Instance == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
- Instance->Signature = IP4_CONFIG_INSTANCE_SIGNATURE;
Instance->Controller = ControllerHandle;
Instance->Image = This->DriverBindingHandle;
+ Instance->ParentDevicePath = ParentDevicePath;
CopyMem (&Instance->Ip4ConfigProtocol, &mIp4ConfigProtocolTemplate, sizeof (mIp4ConfigProtocolTemplate));
- CopyMem (&Instance->NicIp4Protocol, &mNicIp4ConfigProtocolTemplate, sizeof (mNicIp4ConfigProtocolTemplate));
Instance->State = IP4_CONFIG_STATE_IDLE;
Instance->Mnp = Mnp;
Instance->MnpHandle = MnpHandle;
- Instance->DoneEvent = NULL;
- Instance->ReconfigEvent = NULL;
- Instance->Result = EFI_NOT_READY;
- Instance->NicConfig = NULL;
-
- Instance->Dhcp4 = NULL;
- Instance->Dhcp4Handle = NULL;
- Instance->Dhcp4Event = NULL;
-
Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);
if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
@@ -249,112 +272,68 @@ Ip4ConfigDriverBindingStart (
Instance->NicAddr.Type = (UINT16) SnpMode.IfType;
Instance->NicAddr.Len = (UINT8) SnpMode.HwAddressSize;
- CopyMem (&Instance->NicAddr.MacAddr, &SnpMode.CurrentAddress, sizeof (Instance->NicAddr.MacAddr));
+ CopyMem (&Instance->NicAddr.MacAddr, &SnpMode.CurrentAddress, Instance->NicAddr.Len);
//
// Add it to the global list, and compose the name
//
- for (Index = 0; Index < MAX_IP4_CONFIG_IN_VARIABLE; Index++) {
- if (mIp4ConfigNicList[Index] == NULL) {
- mIp4ConfigNicList[Index] = Instance;
- Instance->NicIndex = Index;
-
- if (Instance->NicAddr.Type == NET_IFTYPE_ETHERNET) {
- Instance->NicName[0] = 'e';
- Instance->NicName[1] = 't';
- Instance->NicName[2] = 'h';
- Instance->NicName[3] = (UINT16) ('0' + Index);
- Instance->NicName[4] = 0;
- } else {
- Instance->NicName[0] = 'u';
- Instance->NicName[1] = 'n';
- Instance->NicName[2] = 'k';
- Instance->NicName[3] = (UINT16) ('0' + Index);
- Instance->NicName[4] = 0;
- }
-
- break;
- }
- }
-
- if (Index == MAX_IP4_CONFIG_IN_VARIABLE) {
- Status = EFI_OUT_OF_RESOURCES;
+ Status = NetLibGetMacString (Instance->Controller, Instance->Image, &Instance->MacString);
+ if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
+ Status = Ip4ConfigDeviceInit (Instance);
+
//
- // Install the IP4_CONFIG and NIC_IP4CONFIG protocols
+ // Install the IP4_CONFIG protocols
//
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiIp4ConfigProtocolGuid,
&Instance->Ip4ConfigProtocol,
- &gEfiNicIp4ConfigProtocolGuid,
- &Instance->NicIp4Protocol,
NULL
);
if (EFI_ERROR (Status)) {
- mIp4ConfigNicList[Index] = NULL;
goto ON_ERROR;
}
//
- // Get the previous configure parameters. If an error happend here,
- // just ignore it because the driver should be able to operate.
+ // A dedicated timer is used to poll underlying media status.
//
- Variable = Ip4ConfigReadVariable ();
-
- if (Variable == NULL) {
- return EFI_SUCCESS;
- }
-
- NicConfig = Ip4ConfigFindNicVariable (Variable, &Instance->NicAddr);
-
- if (NicConfig == NULL) {
- goto ON_EXIT;
- }
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL | EVT_TIMER,
+ TPL_CALLBACK,
+ MediaChangeDetect,
+ Instance,
+ &Instance->Timer
+ );
- //
- // Don't modify the permant static configuration
- //
- if (NicConfig->Perment && (NicConfig->Source == IP4_CONFIG_SOURCE_STATIC)) {
- goto ON_EXIT;
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
}
//
- // Delete the non-permant configuration and remove the previous
- // acquired DHCP parameters. Only doing DHCP itself is permant
+ // Get the previous configure parameters. If an error happend here,
+ // just ignore it because the driver should be able to operate.
//
- NewVariable = NULL;
-
- if (!NicConfig->Perment) {
- NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NULL);
-
- } else if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {
- NetZeroMem (&NicConfig->Ip4Info, sizeof (EFI_IP4_IPCONFIG_DATA));
- NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NicConfig);
-
- }
-
- Ip4ConfigWriteVariable (NewVariable);
-
- if (NewVariable != NULL) {
- NetFreePool (NewVariable);
- }
-
-ON_EXIT:
- NetFreePool (Variable);
-
+ NicConfig = Ip4ConfigReadVariable (Instance);
if (NicConfig != NULL) {
- NetFreePool (NicConfig);
+ if (!NicConfig->Permanent) {
+ //
+ // Delete the non-permanent configuration.
+ //
+ Ip4ConfigWriteVariable (Instance, NULL);
+ }
+
+ FreePool (NicConfig);
}
return EFI_SUCCESS;
ON_ERROR:
if (Instance != NULL) {
- NetFreePool (Instance);
+ FreePool (Instance);
}
if (Mnp != NULL) {
@@ -369,7 +348,7 @@ ON_ERROR:
NetLibDestroyServiceChild (
ControllerHandle,
This->DriverBindingHandle,
- &gEfiManagedNetworkProtocolGuid,
+ &gEfiManagedNetworkServiceBindingProtocolGuid,
MnpHandle
);
@@ -471,6 +450,8 @@ Ip4ConfigDriverBindingStop (
Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config);
+ Ip4ConfigDeviceUnload (Instance);
+
//
// Unload the protocols first to inform the top drivers
//
@@ -478,8 +459,6 @@ Ip4ConfigDriverBindingStop (
NicHandle,
&gEfiIp4ConfigProtocolGuid,
&Instance->Ip4ConfigProtocol,
- &gEfiNicIp4ConfigProtocolGuid,
- &Instance->NicIp4Protocol,
NULL
);
@@ -509,18 +488,18 @@ Ip4ConfigDriverBindingStop (
Instance->MnpHandle = NULL;
}
+ if (Instance->MacString != NULL) {
+ FreePool (Instance->MacString);
+ }
+
+ if (Instance->Timer != NULL) {
+ gBS->SetTimer (Instance->Timer, TimerCancel, 0);
+ gBS->CloseEvent (Instance->Timer);
+ Instance->Timer = NULL;
+ }
+
Ip4ConfigCleanConfig (Instance);
- mIp4ConfigNicList[Instance->NicIndex] = NULL;
- NetFreePool (Instance);
+ FreePool (Instance);
return EFI_SUCCESS;
}
-
-EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {
- Ip4ConfigDriverBindingSupported,
- Ip4ConfigDriverBindingStart,
- Ip4ConfigDriverBindingStop,
- 0xa,
- NULL,
- NULL
-};