summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2010-11-17 03:39:19 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2010-11-17 03:39:19 +0000
commit4886a0a9374398a42a4fe4c4732abcf2781caa0e (patch)
treed4871c52769c25aa51485c4a12aea29b1e4c8869
parent8830867de1d311a9566270441826f5d94b0d4cc0 (diff)
downloadedk2-4886a0a9374398a42a4fe4c4732abcf2781caa0e.tar.gz
edk2-4886a0a9374398a42a4fe4c4732abcf2781caa0e.tar.bz2
edk2-4886a0a9374398a42a4fe4c4732abcf2781caa0e.zip
sync patch r10180, r10191, r10628, r10720, r10772 from main trunk.
1. Update to use 1 EFI Variable per NIC (instead of converge all NIC configuration into one EFI Variable), this remove the limitation that max NIC configuration will depend on PcdMaxVariableSize. 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. 4. Update HiiConfigAccess.ExtractConfig interface produced by the following drivers to support NULL request string and ConfigHdr request string without any request element according to the latest UEFI specification. 5. Update the title Network Configuration to IPv4 Network Configuration. 6. Fix one issue: Some last IP settings may be lost when IP setting was re-set. 7. Fix a typo in Ip4ConfigDriverBindingStart(): it should be gEfiManagedNetworkServiceBindingProtocolGuid instead of gEfiManagedNetworkProtocolGuid. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2008@11072 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/Include/Library/NetLib.h24
-rw-r--r--MdeModulePkg/Library/DxeNetLib/DxeNetLib.c170
-rw-r--r--MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf2
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/ComponentName.c4
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c247
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h171
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c201
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf14
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr4
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c322
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h6
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h5
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c369
-rw-r--r--MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h87
14 files changed, 853 insertions, 773 deletions
diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h
index 7addeeef79..d920a2a842 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -734,6 +734,30 @@ NetLibDestroyServiceChild (
);
/**
+ Get MAC address associated with the network service handle.
+
+ There should be MNP Service Binding Protocol installed on the input ServiceHandle.
+ If SNP is installed on the ServiceHandle or its parent handle, MAC address will
+ be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.
+
+ @param[in] ServiceHandle The handle where network service binding protocols are
+ installed on.
+ @param[out] MacAddress The pointer to store the returned MAC address.
+ @param[out] AddressSize The length of returned MAC address.
+
+ @retval EFI_SUCCESS MAC address was returned successfully.
+ @retval Others Failed to get SNP mode data.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibGetMacAddress (
+ IN EFI_HANDLE ServiceHandle,
+ OUT EFI_MAC_ADDRESS *MacAddress,
+ OUT UINTN *AddressSize
+ );
+
+/**
Convert the mac address of the simple network protocol installed on
SnpHandle to a unicode string. Callers are responsible for freeing the
string storage.
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index f18aa41e34..926666822b 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/DriverBinding.h>
#include <Protocol/ServiceBinding.h>
#include <Protocol/SimpleNetwork.h>
+#include <Protocol/ManagedNetwork.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/ComponentName.h>
#include <Protocol/ComponentName2.h>
@@ -1151,6 +1152,175 @@ NetLibDestroyServiceChild (
return Status;
}
+/**
+ Get handle with Simple Network Protocol installed on it.
+
+ There should be MNP Service Binding Protocol installed on the input ServiceHandle.
+ If Simple Network Protocol is already installed on the ServiceHandle, the
+ ServiceHandle will be returned. If SNP is not installed on the ServiceHandle,
+ try to find its parent handle with SNP installed.
+
+ @param[in] ServiceHandle The handle where network service binding protocols are
+ installed on.
+ @param[out] Snp The pointer to store the address of the SNP instance.
+ This is an optional parameter that may be NULL.
+
+ @return The SNP handle, or NULL if not found.
+
+**/
+EFI_HANDLE
+EFIAPI
+NetLibGetSnpHandle (
+ IN EFI_HANDLE ServiceHandle,
+ OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ EFI_SIMPLE_NETWORK_PROTOCOL *SnpInstance;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_HANDLE SnpHandle;
+
+ //
+ // Try to open SNP from ServiceHandle
+ //
+ SnpInstance = NULL;
+ Status = gBS->HandleProtocol (ServiceHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &SnpInstance);
+ if (!EFI_ERROR (Status)) {
+ if (Snp != NULL) {
+ *Snp = SnpInstance;
+ }
+ return ServiceHandle;
+ }
+
+ //
+ // Failed to open SNP, try to get SNP handle by LocateDevicePath()
+ //
+ DevicePath = DevicePathFromHandle (ServiceHandle);
+ if (DevicePath == NULL) {
+ return NULL;
+ }
+
+ SnpHandle = NULL;
+ Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &DevicePath, &SnpHandle);
+ if (EFI_ERROR (Status)) {
+ //
+ // Failed to find SNP handle
+ //
+ return NULL;
+ }
+
+ Status = gBS->HandleProtocol (SnpHandle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &SnpInstance);
+ if (!EFI_ERROR (Status)) {
+ if (Snp != NULL) {
+ *Snp = SnpInstance;
+ }
+ return SnpHandle;
+ }
+
+ return NULL;
+}
+
+
+/**
+ Get MAC address associated with the network service handle.
+
+ There should be MNP Service Binding Protocol installed on the input ServiceHandle.
+ If SNP is installed on the ServiceHandle or its parent handle, MAC address will
+ be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.
+
+ @param[in] ServiceHandle The handle where network service binding protocols are
+ installed on.
+ @param[out] MacAddress The pointer to store the returned MAC address.
+ @param[out] AddressSize The length of returned MAC address.
+
+ @retval EFI_SUCCESS MAC address is returned successfully.
+ @retval Others Failed to get SNP mode data.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibGetMacAddress (
+ IN EFI_HANDLE ServiceHandle,
+ OUT EFI_MAC_ADDRESS *MacAddress,
+ OUT UINTN *AddressSize
+ )
+{
+ EFI_STATUS Status;
+ EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
+ EFI_SIMPLE_NETWORK_MODE *SnpMode;
+ EFI_SIMPLE_NETWORK_MODE SnpModeData;
+ EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
+ EFI_SERVICE_BINDING_PROTOCOL *MnpSb;
+ EFI_HANDLE *SnpHandle;
+ EFI_HANDLE MnpChildHandle;
+
+ ASSERT (MacAddress != NULL);
+ ASSERT (AddressSize != NULL);
+
+ //
+ // Try to get SNP handle
+ //
+ Snp = NULL;
+ SnpHandle = NetLibGetSnpHandle (ServiceHandle, &Snp);
+ if (SnpHandle != NULL) {
+ //
+ // SNP found, use it directly
+ //
+ SnpMode = Snp->Mode;
+ } else {
+ //
+ // Failed to get SNP handle, try to get MAC address from MNP
+ //
+ MnpChildHandle = NULL;
+ Status = gBS->HandleProtocol (
+ ServiceHandle,
+ &gEfiManagedNetworkServiceBindingProtocolGuid,
+ (VOID **) &MnpSb
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Create a MNP child
+ //
+ Status = MnpSb->CreateChild (MnpSb, &MnpChildHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Open MNP protocol
+ //
+ Status = gBS->HandleProtocol (
+ MnpChildHandle,
+ &gEfiManagedNetworkProtocolGuid,
+ (VOID **) &Mnp
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Try to get SNP mode from MNP
+ //
+ Status = Mnp->GetModeData (Mnp, NULL, &SnpModeData);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ SnpMode = &SnpModeData;
+
+ //
+ // Destroy the MNP child
+ //
+ MnpSb->DestroyChild (MnpSb, MnpChildHandle);
+ }
+
+ *AddressSize = SnpMode->HwAddressSize;
+ CopyMem (MacAddress->Addr, SnpMode->CurrentAddress.Addr, SnpMode->HwAddressSize);
+
+ return EFI_SUCCESS;
+}
/**
Convert the mac address of the simple network protocol installed on
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
index 05d68d70e0..00ac82157f 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
@@ -54,6 +54,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
[Protocols]
gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiManagedNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiManagedNetworkServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiComponentNameProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiComponentName2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiHiiConfigRoutingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/ComponentName.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/ComponentName.c
index dbb67904f5..08bd74a82c 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/ComponentName.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/ComponentName.c
@@ -1,8 +1,8 @@
/** @file
UEFI Component Name(2) protocol implementation for Ip4ConfigDxe driver.
-Copyright (c) 2006 - 2007, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
index 5f8821a4d6..2c74a80308 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
@@ -1,8 +1,8 @@
/** @file
This code implements the IP4Config and NicIp4Config protocols.
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
@@ -13,43 +13,40 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Ip4Config.h"
+#include "NicIp4Variable.h"
-IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE];
-
+//
+// Ip4 Config Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_IP4_CONFIG_PROTOCOL mIp4ConfigProtocolTemplate = {
+ EfiIp4ConfigStart,
+ EfiIp4ConfigStop,
+ EfiIp4ConfigGetData
+};
/**
Get the NIC's configure information from the IP4 configure variable.
It will remove the invalid variable.
- @param NicAddr The NIC to check
+ @param Instance The IP4 CONFIG instance.
@return NULL if no configure for the NIC in the variable, or it is invalid.
Otherwise the pointer to the NIC's IP configure parameter will be returned.
**/
NIC_IP4_CONFIG_INFO *
-Ip4ConfigGetNicInfo (
- IN NIC_ADDR *NicAddr
+EfiNicIp4ConfigGetInfo (
+ IN IP4_CONFIG_INSTANCE *Instance
)
{
- IP4_CONFIG_VARIABLE *Variable;
- IP4_CONFIG_VARIABLE *NewVariable;
- NIC_IP4_CONFIG_INFO *Config;
+ NIC_IP4_CONFIG_INFO *NicConfig;
//
- // Read the configuration parameter for this NicAddr from
+ // Read the configuration parameter for this NIC from
// the EFI variable
//
- Variable = Ip4ConfigReadVariable ();
-
- if (Variable == NULL) {
- return NULL;
- }
-
- Config = Ip4ConfigFindNicVariable (Variable, NicAddr);
-
- if (Config == NULL) {
- FreePool (Variable);
+ NicConfig = Ip4ConfigReadVariable (Instance);
+ if (NicConfig == NULL) {
return NULL;
}
@@ -57,106 +54,37 @@ Ip4ConfigGetNicInfo (
// Validate the configuration, if the configuration is invalid,
// remove it from the variable.
//
- if (!Ip4ConfigIsValid (Config)) {
- NewVariable = Ip4ConfigModifyVariable (Variable, &Config->NicAddr, NULL);
- Ip4ConfigWriteVariable (NewVariable);
-
- if (NewVariable != NULL) {
- FreePool (NewVariable);
- };
-
- FreePool (Config);
- Config = NULL;
- }
-
- FreePool (Variable);
- return Config;
-}
-
-
-/**
- Get the configure parameter for this NIC.
-
- @param Instance The IP4 CONFIG Instance.
- @param ConfigLen The length of the NicConfig buffer.
- @param NicConfig The buffer to receive the NIC's configure
- parameter.
-
- @retval EFI_SUCCESS The configure parameter for this NIC was
- obtained successfully .
- @retval EFI_INVALID_PARAMETER This or ConfigLen is NULL.
- @retval EFI_NOT_FOUND There is no configure parameter for the NIC in
- NVRam.
- @retval EFI_BUFFER_TOO_SMALL The ConfigLen is too small or the NicConfig is
- NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-EfiNicIp4ConfigGetInfo (
- IN IP4_CONFIG_INSTANCE *Instance,
- IN OUT UINTN *ConfigLen,
- OUT NIC_IP4_CONFIG_INFO *NicConfig
- )
-{
- NIC_IP4_CONFIG_INFO *Config;
- EFI_STATUS Status;
- UINTN Len;
-
- if ((Instance == NULL) || (ConfigLen == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Read the Nic's configuration parameter from variable
- //
- Config = Ip4ConfigGetNicInfo (&Instance->NicAddr);
+ if (!Ip4ConfigIsValid (NicConfig)) {
+ Ip4ConfigWriteVariable (Instance, NULL);
- if (Config == NULL) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Copy the data to user's buffer
- //
- Len = SIZEOF_NIC_IP4_CONFIG_INFO (Config);
-
- if ((*ConfigLen < Len) || (NicConfig == NULL)) {
- Status = EFI_BUFFER_TOO_SMALL;
- } else {
- Status = EFI_SUCCESS;
- CopyMem (NicConfig, Config, Len);
- Ip4ConfigFixRouteTablePointer (&NicConfig->Ip4Info);
+ FreePool (NicConfig);
+ NicConfig = NULL;
}
- *ConfigLen = Len;
-
- FreePool (Config);
- return Status;
+ return NicConfig;
}
-
/**
- Set the IP configure parameters for this NIC.
+ Set the IP configure parameters for this NIC.
- If Reconfig is TRUE, the IP driver will be informed to discard current
- auto configure parameter and restart the auto configuration process.
+ If Reconfig is TRUE, the IP driver will be informed to discard current
+ auto configure parameter and restart the auto configuration process.
If current there is a pending auto configuration, EFI_ALREADY_STARTED is
returned. You can only change the configure setting when either
the configure has finished or not started yet. If NicConfig, the
NIC's configure parameter is removed from the variable.
@param Instance The IP4 CONFIG instance.
- @param NicConfig The new NIC IP4 configure parameter
+ @param NicConfig The new NIC IP4 configure parameter.
@param Reconfig Inform the IP4 driver to restart the auto
- configuration
-
- @retval EFI_SUCCESS The configure parameter for this NIC was
- set successfully .
+ configuration.
+
+ @retval EFI_SUCCESS The configure parameter for this NIC was
+ set successfully.
@retval EFI_INVALID_PARAMETER This is NULL or the configure parameter is
invalid.
@retval EFI_ALREADY_STARTED There is a pending auto configuration.
- @retval EFI_NOT_FOUND No auto configure parameter is found
+ @retval EFI_NOT_FOUND No auto configure parameter is found.
**/
EFI_STATUS
@@ -167,9 +95,7 @@ EfiNicIp4ConfigSetInfo (
IN BOOLEAN Reconfig
)
{
- IP4_CONFIG_VARIABLE *Variable;
- IP4_CONFIG_VARIABLE *NewVariable;
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Validate the parameters
@@ -190,26 +116,7 @@ EfiNicIp4ConfigSetInfo (
//
// Update the parameter in the configure variable
//
- Variable = Ip4ConfigReadVariable ();
-
- if ((Variable == NULL) && (NicConfig == NULL)) {
- return EFI_NOT_FOUND;
- }
-
- NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NicConfig);
- Status = Ip4ConfigWriteVariable (NewVariable);
-
- if (NewVariable != NULL) {
- FreePool (NewVariable);
- }
-
- //
- // Variable is NULL when saving the first configure parameter
- //
- if (Variable != NULL) {
- FreePool (Variable);
- }
-
+ Status = Ip4ConfigWriteVariable (Instance, NicConfig);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -342,47 +249,47 @@ ON_EXIT:
/**
Starts running the configuration policy for the EFI IPv4 Protocol driver.
-
- The Start() function is called to determine and to begin the platform
- configuration policy by the EFI IPv4 Protocol driver. This determination may
- be as simple as returning EFI_UNSUPPORTED if there is no EFI IPv4 Protocol
- driver configuration policy. It may be as involved as loading some defaults
- from nonvolatile storage, downloading dynamic data from a DHCP server, and
+
+ The Start() function is called to determine and to begin the platform
+ configuration policy by the EFI IPv4 Protocol driver. This determination may
+ be as simple as returning EFI_UNSUPPORTED if there is no EFI IPv4 Protocol
+ driver configuration policy. It may be as involved as loading some defaults
+ from nonvolatile storage, downloading dynamic data from a DHCP server, and
checking permissions with a site policy server.
- Starting the configuration policy is just the beginning. It may finish almost
- instantly or it may take several minutes before it fails to retrieve configuration
- information from one or more servers. Once the policy is started, drivers
- should use the DoneEvent parameter to determine when the configuration policy
- has completed. EFI_IP4_CONFIG_PROTOCOL.GetData() must then be called to
+ Starting the configuration policy is just the beginning. It may finish almost
+ instantly or it may take several minutes before it fails to retrieve configuration
+ information from one or more servers. Once the policy is started, drivers
+ should use the DoneEvent parameter to determine when the configuration policy
+ has completed. EFI_IP4_CONFIG_PROTOCOL.GetData() must then be called to
determine if the configuration succeeded or failed.
- Until the configuration completes successfully, EFI IPv4 Protocol driver instances
+ Until the configuration completes successfully, EFI IPv4 Protocol driver instances
that are attempting to use default configurations must return EFI_NO_MAPPING.
- Once the configuration is complete, the EFI IPv4 Configuration Protocol driver
- signals DoneEvent. The configuration may need to be updated in the future,
- however; in this case, the EFI IPv4 Configuration Protocol driver must signal
- ReconfigEvent, and all EFI IPv4 Protocol driver instances that are using default
- configurations must return EFI_NO_MAPPING until the configuration policy has
+ Once the configuration is complete, the EFI IPv4 Configuration Protocol driver
+ signals DoneEvent. The configuration may need to be updated in the future,
+ however; in this case, the EFI IPv4 Configuration Protocol driver must signal
+ ReconfigEvent, and all EFI IPv4 Protocol driver instances that are using default
+ configurations must return EFI_NO_MAPPING until the configuration policy has
been rerun.
@param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.
- @param DoneEvent Event that will be signaled when the EFI IPv4
- Protocol driver configuration policy completes
+ @param DoneEvent Event that will be signaled when the EFI IPv4
+ Protocol driver configuration policy completes
execution. This event must be of type EVT_NOTIFY_SIGNAL.
- @param ReconfigEvent Event that will be signaled when the EFI IPv4
- Protocol driver configuration needs to be updated.
+ @param ReconfigEvent Event that will be signaled when the EFI IPv4
+ Protocol driver configuration needs to be updated.
This event must be of type EVT_NOTIFY_SIGNAL.
-
- @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol
+
+ @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol
driver is now running.
@retval EFI_INVALID_PARAMETER One or more of the following parameters is NULL:
This
DoneEvent
ReconfigEvent
@retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
- @retval EFI_ALREADY_STARTED The configuration policy for the EFI IPv4 Protocol
+ @retval EFI_ALREADY_STARTED The configuration policy for the EFI IPv4 Protocol
driver was already started.
@retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
- @retval EFI_UNSUPPORTED This interface does not support the EFI IPv4 Protocol
+ @retval EFI_UNSUPPORTED This interface does not support the EFI IPv4 Protocol
driver configuration.
**/
@@ -420,7 +327,7 @@ EfiIp4ConfigStart (
Instance->DoneEvent = DoneEvent;
Instance->ReconfigEvent = ReconfigEvent;
- Instance->NicConfig = Ip4ConfigGetNicInfo (&Instance->NicAddr);
+ Instance->NicConfig = EfiNicIp4ConfigGetInfo (Instance);
if (Instance->NicConfig == NULL) {
Source = IP4_CONFIG_SOURCE_DHCP;
@@ -546,18 +453,18 @@ ON_EXIT:
/**
Stops running the configuration policy for the EFI IPv4 Protocol driver.
-
- The Stop() function stops the configuration policy for the EFI IPv4 Protocol driver.
+
+ The Stop() function stops the configuration policy for the EFI IPv4 Protocol driver.
All configuration data will be lost after calling Stop().
@param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.
- @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol
+ @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol
driver has been stopped.
@retval EFI_INVALID_PARAMETER This is NULL.
- @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol
+ @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol
driver was not started.
-
+
**/
EFI_STATUS
EFIAPI
@@ -600,26 +507,26 @@ ON_EXIT:
/**
Returns the default configuration data (if any) for the EFI IPv4 Protocol driver.
- The GetData() function returns the current configuration data for the EFI IPv4
+ The GetData() function returns the current configuration data for the EFI IPv4
Protocol driver after the configuration policy has completed.
-
+
@param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.
- @param ConfigDataSize On input, the size of the ConfigData buffer.
- On output, the count of bytes that were written
+ @param ConfigDataSize On input, the size of the ConfigData buffer.
+ On output, the count of bytes that were written
into the ConfigData buffer.
- @param ConfigData Pointer to the EFI IPv4 Configuration Protocol
- driver configuration data structure.
- Type EFI_IP4_IPCONFIG_DATA is defined in
+ @param ConfigData Pointer to the EFI IPv4 Configuration Protocol
+ driver configuration data structure.
+ Type EFI_IP4_IPCONFIG_DATA is defined in
"Related Definitions" below.
@retval EFI_SUCCESS The EFI IPv4 Protocol driver configuration has been returned.
@retval EFI_INVALID_PARAMETER This is NULL.
- @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol
+ @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol
driver is not running.
@retval EFI_NOT_READY EFI IPv4 Protocol driver configuration is still running.
@retval EFI_ABORTED EFI IPv4 Protocol driver configuration could not complete.
Currently not implemented.
- @retval EFI_BUFFER_TOO_SMALL *ConfigDataSize is smaller than the configuration
+ @retval EFI_BUFFER_TOO_SMALL *ConfigDataSize is smaller than the configuration
data buffer or ConfigData is NULL.
**/
@@ -752,9 +659,3 @@ Ip4ConfigCleanConfig (
Ip4ConfigCleanDhcp4 (Instance);
}
-EFI_IP4_CONFIG_PROTOCOL mIp4ConfigProtocolTemplate = {
- EfiIp4ConfigStart,
- EfiIp4ConfigStop,
- EfiIp4ConfigGetData
-};
-
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
index cd2e6cd396..eacd893890 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
@@ -1,8 +1,8 @@
/** @file
Header file for IP4Config driver.
-Copyright (c) 2006 - 2010, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
@@ -26,6 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/ServiceBinding.h>
#include <Guid/MdeModuleHii.h>
+#include <Guid/NicIp4ConfigNvData.h>
#include <Library/DevicePathLib.h>
#include <Library/DebugLib.h>
@@ -41,9 +42,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/DpcLib.h>
#include <Library/UefiHiiServicesLib.h>
-#include "NicIp4Variable.h"
-
-typedef struct _IP4_CONFIG_INSTANCE IP4_CONFIG_INSTANCE;
//
// Global variables
@@ -51,8 +49,7 @@ typedef struct _IP4_CONFIG_INSTANCE IP4_CONFIG_INSTANCE;
extern EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gIp4ConfigComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gIp4ConfigComponentName2;
-
-extern IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE];
+
extern EFI_IP4_CONFIG_PROTOCOL mIp4ConfigProtocolTemplate;
#define IP4_PROTO_ICMP 0x01
@@ -86,12 +83,12 @@ typedef struct _IP4CONFIG_CALLBACK_INFO {
EFI_IPv4_ADDRESS Gateway;
} IP4_SETTING_INFO;
-struct _IP4_CONFIG_INSTANCE {
+typedef struct _IP4_CONFIG_INSTANCE {
UINT32 Signature;
EFI_HANDLE Controller;
EFI_HANDLE Image;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
-
+
EFI_IP4_CONFIG_PROTOCOL Ip4ConfigProtocol;
EFI_HII_CONFIG_ACCESS_PROTOCOL HiiConfigAccessProtocol;
@@ -122,8 +119,7 @@ struct _IP4_CONFIG_INSTANCE {
// Identity of this interface and some configuration info.
//
NIC_ADDR NicAddr;
- UINT16 NicName[IP4_NIC_NAME_LENGTH];
- UINT32 NicIndex;
+ CHAR16 *MacString;
NIC_IP4_CONFIG_INFO *NicConfig;
//
@@ -132,7 +128,7 @@ struct _IP4_CONFIG_INSTANCE {
EFI_DHCP4_PROTOCOL *Dhcp4;
EFI_HANDLE Dhcp4Handle;
EFI_EVENT Dhcp4Event;
-};
+} IP4_CONFIG_INSTANCE;
#define IP4_CONFIG_INSTANCE_FROM_IP4CONFIG(this) \
CR (this, IP4_CONFIG_INSTANCE, Ip4ConfigProtocol, IP4_CONFIG_INSTANCE_SIGNATURE)
@@ -142,26 +138,26 @@ struct _IP4_CONFIG_INSTANCE {
/**
- Set the IP configure parameters for this NIC.
+ Set the IP configure parameters for this NIC.
- If Reconfig is TRUE, the IP driver will be informed to discard current
- auto configure parameter and restart the auto configuration process.
+ If Reconfig is TRUE, the IP driver will be informed to discard current
+ auto configure parameter and restart the auto configuration process.
If current there is a pending auto configuration, EFI_ALREADY_STARTED is
returned. You can only change the configure setting when either
the configure has finished or not started yet. If NicConfig, the
NIC's configure parameter is removed from the variable.
@param Instance The IP4 CONFIG instance.
- @param NicConfig The new NIC IP4 configure parameter
+ @param NicConfig The new NIC IP4 configure parameter.
@param Reconfig Inform the IP4 driver to restart the auto
- configuration
-
- @retval EFI_SUCCESS The configure parameter for this NIC was
- set successfully .
+ configuration.
+
+ @retval EFI_SUCCESS The configure parameter for this NIC was
+ set successfully.
@retval EFI_INVALID_PARAMETER This is NULL or the configure parameter is
invalid.
@retval EFI_ALREADY_STARTED There is a pending auto configuration.
- @retval EFI_NOT_FOUND No auto configure parameter is found
+ @retval EFI_NOT_FOUND No auto configure parameter is found.
**/
EFI_STATUS
@@ -173,28 +169,18 @@ EfiNicIp4ConfigSetInfo (
);
/**
- Get the configure parameter for this NIC.
+ Get the NIC's configure information from the IP4 configure variable.
+ It will remove the invalid variable.
- @param Instance The IP4 CONFIG Instance.
- @param ConfigLen The length of the NicConfig buffer.
- @param NicConfig The buffer to receive the NIC's configure
- parameter.
+ @param Instance The IP4 CONFIG instance.
- @retval EFI_SUCCESS The configure parameter for this NIC was
- obtained successfully .
- @retval EFI_INVALID_PARAMETER This or ConfigLen is NULL.
- @retval EFI_NOT_FOUND There is no configure parameter for the NIC in
- NVRam.
- @retval EFI_BUFFER_TOO_SMALL The ConfigLen is too small or the NicConfig is
- NULL.
+ @return NULL if no configure for the NIC in the variable, or it is invalid.
+ Otherwise the pointer to the NIC's IP configure parameter will be returned.
**/
-EFI_STATUS
-EFIAPI
+NIC_IP4_CONFIG_INFO *
EfiNicIp4ConfigGetInfo (
- IN IP4_CONFIG_INSTANCE *Instance,
- IN OUT UINTN *ConfigLen,
- OUT NIC_IP4_CONFIG_INFO *NicConfig
+ IN IP4_CONFIG_INSTANCE *Instance
);
/**
@@ -401,4 +387,113 @@ Ip4ConfigDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer
);
+/**
+ Starts running the configuration policy for the EFI IPv4 Protocol driver.
+
+ The Start() function is called to determine and to begin the platform
+ configuration policy by the EFI IPv4 Protocol driver. This determination may
+ be as simple as returning EFI_UNSUPPORTED if there is no EFI IPv4 Protocol
+ driver configuration policy. It may be as involved as loading some defaults
+ from nonvolatile storage, downloading dynamic data from a DHCP server, and
+ checking permissions with a site policy server.
+ Starting the configuration policy is just the beginning. It may finish almost
+ instantly or it may take several minutes before it fails to retrieve configuration
+ information from one or more servers. Once the policy is started, drivers
+ should use the DoneEvent parameter to determine when the configuration policy
+ has completed. EFI_IP4_CONFIG_PROTOCOL.GetData() must then be called to
+ determine if the configuration succeeded or failed.
+ Until the configuration completes successfully, EFI IPv4 Protocol driver instances
+ that are attempting to use default configurations must return EFI_NO_MAPPING.
+ Once the configuration is complete, the EFI IPv4 Configuration Protocol driver
+ signals DoneEvent. The configuration may need to be updated in the future,
+ however; in this case, the EFI IPv4 Configuration Protocol driver must signal
+ ReconfigEvent, and all EFI IPv4 Protocol driver instances that are using default
+ configurations must return EFI_NO_MAPPING until the configuration policy has
+ been rerun.
+
+ @param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.
+ @param DoneEvent Event that will be signaled when the EFI IPv4
+ Protocol driver configuration policy completes
+ execution. This event must be of type EVT_NOTIFY_SIGNAL.
+ @param ReconfigEvent Event that will be signaled when the EFI IPv4
+ Protocol driver configuration needs to be updated.
+ This event must be of type EVT_NOTIFY_SIGNAL.
+
+ @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol
+ driver is now running.
+ @retval EFI_INVALID_PARAMETER One or more of the following parameters is NULL:
+ This
+ DoneEvent
+ ReconfigEvent
+ @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
+ @retval EFI_ALREADY_STARTED The configuration policy for the EFI IPv4 Protocol
+ driver was already started.
+ @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
+ @retval EFI_UNSUPPORTED This interface does not support the EFI IPv4 Protocol
+ driver configuration.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiIp4ConfigStart (
+ IN EFI_IP4_CONFIG_PROTOCOL *This,
+ IN EFI_EVENT DoneEvent,
+ IN EFI_EVENT ReconfigEvent
+ );
+
+/**
+ Stops running the configuration policy for the EFI IPv4 Protocol driver.
+
+ The Stop() function stops the configuration policy for the EFI IPv4 Protocol driver.
+ All configuration data will be lost after calling Stop().
+
+ @param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.
+
+ @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol
+ driver has been stopped.
+ @retval EFI_INVALID_PARAMETER This is NULL.
+ @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol
+ driver was not started.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiIp4ConfigStop (
+ IN EFI_IP4_CONFIG_PROTOCOL *This
+ );
+
+/**
+ Returns the default configuration data (if any) for the EFI IPv4 Protocol driver.
+
+ The GetData() function returns the current configuration data for the EFI IPv4
+ Protocol driver after the configuration policy has completed.
+
+ @param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.
+ @param ConfigDataSize On input, the size of the ConfigData buffer.
+ On output, the count of bytes that were written
+ into the ConfigData buffer.
+ @param ConfigData Pointer to the EFI IPv4 Configuration Protocol
+ driver configuration data structure.
+ Type EFI_IP4_IPCONFIG_DATA is defined in
+ "Related Definitions" below.
+
+ @retval EFI_SUCCESS The EFI IPv4 Protocol driver configuration has been returned.
+ @retval EFI_INVALID_PARAMETER This is NULL.
+ @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol
+ driver is not running.
+ @retval EFI_NOT_READY EFI IPv4 Protocol driver configuration is still running.
+ @retval EFI_ABORTED EFI IPv4 Protocol driver configuration could not complete.
+ Currently not implemented.
+ @retval EFI_BUFFER_TOO_SMALL *ConfigDataSize is smaller than the configuration
+ data buffer or ConfigData is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiIp4ConfigGetData (
+ IN EFI_IP4_CONFIG_PROTOCOL *This,
+ IN OUT UINTN *ConfigDataSize,
+ OUT EFI_IP4_IPCONFIG_DATA *ConfigData OPTIONAL
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
index 60cf318772..fdbb26cd78 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c
@@ -1,8 +1,8 @@
/** @file
The driver binding for IP4 CONFIG protocol.
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
@@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "Ip4Config.h"
#include "Ip4ConfigNv.h"
+#include "NicIp4Variable.h"
EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {
Ip4ConfigDriverBindingSupported,
@@ -25,41 +26,59 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = {
NULL
};
-/**
- Stop all the auto configuration when the IP4 configure driver is
- being unloaded.
-
- @param ImageHandle The driver that is being unloaded
-
- @retval EFI_SUCCESS The driver has been ready for unload.
-
-**/
-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;
+//
+// 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
}
-
- gIp4ConfigDriverBinding.Stop (
- &gIp4ConfigDriverBinding,
- mIp4ConfigNicList[Index]->MnpHandle,
- 0,
- NULL
- );
- }
-
- return NetLibDefaultUnload (ImageHandle);
-}
+ },
+ 0,
+ (EFI_MANAGED_NETWORK_PROTOCOL *) NULL,
+ NULL,
+ NULL,
+ NULL,
+ EFI_NOT_READY,
+ {
+ 0,
+ 0,
+ {
+ 0
+ }
+ },
+ (CHAR16 *) NULL,
+ (NIC_IP4_CONFIG_INFO *) NULL,
+ (EFI_DHCP4_PROTOCOL *) NULL,
+ NULL,
+ NULL
+};
/**
The entry point for IP4 config driver which install the driver
@@ -152,13 +171,10 @@ 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,
@@ -218,14 +234,13 @@ Ip4ConfigDriverBindingStart (
//
// Allocate an instance then initialize it
//
- Instance = AllocatePool (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;
@@ -236,15 +251,6 @@ Ip4ConfigDriverBindingStart (
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)) {
@@ -258,30 +264,15 @@ Ip4ConfigDriverBindingStart (
//
// 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) {
- UnicodeSPrint (Instance->NicName, (UINTN) IP4_NIC_NAME_LENGTH, L"eth%d", Index);
- } else {
- UnicodeSPrint (Instance->NicName, (UINTN) IP4_NIC_NAME_LENGTH, L"unk%d", Index);
- }
-
- 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,
@@ -291,7 +282,6 @@ Ip4ConfigDriverBindingStart (
);
if (EFI_ERROR (Status)) {
- mIp4ConfigNicList[Index] = NULL;
goto ON_ERROR;
}
@@ -299,50 +289,27 @@ Ip4ConfigDriverBindingStart (
// Get the previous configure parameters. If an error happend here,
// just ignore it because the driver should be able to operate.
//
- Variable = Ip4ConfigReadVariable ();
-
- if (Variable == NULL) {
- return EFI_SUCCESS;
- }
-
- NicConfig = Ip4ConfigFindNicVariable (Variable, &Instance->NicAddr);
-
- if (NicConfig == NULL) {
- goto ON_EXIT;
- }
-
- //
- // Don't modify the permant static configuration
- //
- if (NicConfig->Perment && (NicConfig->Source == IP4_CONFIG_SOURCE_STATIC)) {
- goto ON_EXIT;
- }
-
- //
- // Delete the non-permant configuration and remove the previous
- // acquired DHCP parameters. Only doing DHCP itself is permant
- //
- NewVariable = NULL;
-
- if (!NicConfig->Perment) {
- NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NULL);
-
- } else if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {
- ZeroMem (&NicConfig->Ip4Info, sizeof (EFI_IP4_IPCONFIG_DATA));
- NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NicConfig);
-
- }
-
- Ip4ConfigWriteVariable (NewVariable);
-
- if (NewVariable != NULL) {
- FreePool (NewVariable);
- }
-
-ON_EXIT:
- FreePool (Variable);
-
+ NicConfig = Ip4ConfigReadVariable (Instance);
if (NicConfig != NULL) {
+ if (NicConfig->Perment) {
+ if (NicConfig->Source == IP4_CONFIG_SOURCE_STATIC) {
+ //
+ // Don't modify the permanent static configuration.
+ //
+ } else if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {
+ //
+ // Remove the previous acquired DHCP parameters.
+ //
+ ZeroMem (&NicConfig->Ip4Info, sizeof (EFI_IP4_IPCONFIG_DATA));
+ Ip4ConfigWriteVariable (Instance, NicConfig);
+ }
+ } else {
+ //
+ // Delete the non-permanent configuration.
+ //
+ Ip4ConfigWriteVariable (Instance, NULL);
+ }
+
FreePool (NicConfig);
}
@@ -365,7 +332,7 @@ ON_ERROR:
NetLibDestroyServiceChild (
ControllerHandle,
This->DriverBindingHandle,
- &gEfiManagedNetworkProtocolGuid,
+ &gEfiManagedNetworkServiceBindingProtocolGuid,
MnpHandle
);
@@ -505,10 +472,12 @@ Ip4ConfigDriverBindingStop (
Instance->MnpHandle = NULL;
}
+ if (Instance->MacString != NULL) {
+ FreePool (Instance->MacString);
+ }
+
Ip4ConfigCleanConfig (Instance);
- mIp4ConfigNicList[Instance->NicIndex] = NULL;
FreePool (Instance);
return EFI_SUCCESS;
}
-
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
index e49c895a85..530b5668a0 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
@@ -1,9 +1,9 @@
-#/** @file
+## @file
# Component name for module Ip4Config
#
-# Copyright (c) 2006 - 2009, Intel Corporation
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
#
-# All rights reserved. This program and the accompanying materials
+# 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
# http://opensource.org/licenses/bsd-license.php
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
-#**/
+##
[Defines]
INF_VERSION = 0x00010005
@@ -21,14 +21,14 @@
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = Ip4ConfigDriverEntryPoint
- UNLOAD_IMAGE = EfiIp4ConfigUnload
+ UNLOAD_IMAGE = NetLibDefaultUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
-[Sources.common]
+[Sources]
ComponentName.c
NicIp4Variable.c
Ip4ConfigDriver.c
@@ -67,4 +67,4 @@
[Guids]
gEfiNicIp4ConfigVariableGuid ## CONSUMES ## Guid
-
+
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr
index 578045ffe2..5b5685db42 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr
@@ -1,8 +1,8 @@
/** @file
Vfr file for IP4 config.
-Copyright (c) 2009 - 2010, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+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
http://opensource.org/licenses/bsd-license.php
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c
index c3fbcb978e..871a989e5d 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c
@@ -1,8 +1,8 @@
/** @file
Helper functions for configuring or getting the parameters relating to Ip4.
-Copyright (c) 2009 - 2010, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+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
http://opensource.org/licenses/bsd-license.php
@@ -13,45 +13,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Ip4ConfigNv.h"
-
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Ip4HexString[] = "0123456789ABCDEFabcdef";
+#include "NicIp4Variable.h"
EFI_GUID mNicIp4ConfigNvDataGuid = EFI_NIC_IP4_CONFIG_NVDATA_GUID;
-//
-// Template used to mark the end of a list of packages
-//
-GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = {
- sizeof (EFI_HII_PACKAGE_HEADER),
- EFI_HII_PACKAGE_END
-};
-
-
-/**
- Convert the mac address into a hexadecimal encoded "-" seperated string.
-
- @param[in] Mac The mac address.
- @param[in] Len Length in bytes of the mac address.
- @param[out] Str The storage to return the mac string.
-
-**/
-VOID
-Ip4MacAddrToStr (
- IN EFI_MAC_ADDRESS *Mac,
- IN UINT32 Len,
- OUT CHAR16 *Str
- )
-{
- UINT32 Index;
-
- for (Index = 0; Index < Len; Index++) {
- Str[3 * Index] = (CHAR16) Ip4HexString[(Mac->Addr[Index] >> 4) & 0x0F];
- Str[3 * Index + 1] = (CHAR16) Ip4HexString[Mac->Addr[Index] & 0x0F];
- Str[3 * Index + 2] = L'-';
- }
-
- Str[3 * Index - 1] = L'\0';
-}
/**
Calculate the prefix length of the IPv4 subnet mask.
@@ -72,7 +37,7 @@ GetSubnetMaskPrefixLength (
//
// The SubnetMask is in network byte order.
//
- ReverseMask = (SubnetMask->Addr[0] << 24) | (SubnetMask->Addr[1] << 16) | (SubnetMask->Addr[2] << 8) | (SubnetMask->Addr[3]);
+ ReverseMask = SwapBytes32 (*(UINT32 *)&SubnetMask[0]);
//
// Reverse it.
@@ -97,14 +62,14 @@ GetSubnetMaskPrefixLength (
Convert the decimal dotted IPv4 address into the binary IPv4 address.
@param[in] Str The UNICODE string.
- @param[out] Ip The storage to return the ASCII string.
+ @param[out] Ip The storage to return the IPv4 address.
@retval EFI_SUCCESS The binary IP address is returned in Ip.
@retval EFI_INVALID_PARAMETER The IP string is malformatted.
**/
EFI_STATUS
-Ip4AsciiStrToIp (
- IN CHAR8 *Str,
+Ip4StrToIp (
+ IN CHAR16 *Str,
OUT EFI_IPv4_ADDRESS *Ip
)
{
@@ -113,15 +78,15 @@ Ip4AsciiStrToIp (
Index = 0;
- while (*Str != 0) {
+ while (*Str != L'\0') {
if (Index > 3) {
return EFI_INVALID_PARAMETER;
}
Number = 0;
- while (NET_IS_DIGIT (*Str)) {
- Number = Number * 10 + (*Str - '0');
+ while ((*Str >= L'0') && (*Str <= L'9')) {
+ Number = Number * 10 + (*Str - L'0');
Str++;
}
@@ -131,7 +96,7 @@ Ip4AsciiStrToIp (
Ip->Addr[Index] = (UINT8) Number;
- if ((*Str != '\0') && (*Str != '.')) {
+ if ((*Str != L'\0') && (*Str != L'.')) {
//
// The current character should be either the NULL terminator or
// the dot delimiter.
@@ -139,7 +104,7 @@ Ip4AsciiStrToIp (
return EFI_INVALID_PARAMETER;
}
- if (*Str == '.') {
+ if (*Str == L'.') {
//
// Skip the delimiter.
//
@@ -184,35 +149,39 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData
)
{
- EFI_STATUS Status;
- NIC_IP4_CONFIG_INFO *NicConfig;
- UINTN ConfigLen;
-
- ConfigLen = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2;
- NicConfig = AllocateZeroPool (ConfigLen);
- ASSERT (NicConfig != NULL);
- Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, NicConfig);
- if (!EFI_ERROR (Status)) {
+ NIC_IP4_CONFIG_INFO *NicConfig;
+
+ NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);
+ if (NicConfig != NULL) {
IfrFormNvData->Configure = 1;
+ Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = TRUE;
if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {
IfrFormNvData->DhcpEnable = 1;
+ Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE;
} else {
IfrFormNvData->DhcpEnable = 0;
Ip4ConfigIpToStr (&NicConfig->Ip4Info.StationAddress, IfrFormNvData->StationAddress);
Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);
Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);
+
+ Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE;
+ CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, &NicConfig->Ip4Info.StationAddress, sizeof (EFI_IPv4_ADDRESS));
+ CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &NicConfig->Ip4Info.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
+ CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, &NicConfig->Ip4Info.RouteTable[1].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
}
+
+ FreePool (NicConfig);
} else {
IfrFormNvData->Configure = 0;
+ Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = FALSE;
}
-
- FreePool (NicConfig);
}
/**
Convert the IFR data into the network configuration data and set the IP
configure parameters for the NIC.
+ @param[in] IfrFormNvData The IFR NV data.
@param[in, out] Ip4ConfigInstance The IP4Config instance.
@retval EFI_SUCCESS The configure parameter for this NIC was
@@ -223,6 +192,7 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
**/
EFI_STATUS
Ip4ConfigConvertIfrNvDataToDeviceConfigData (
+ IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData,
IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance
)
{
@@ -234,6 +204,14 @@ Ip4ConfigConvertIfrNvDataToDeviceConfigData (
NIC_IP4_CONFIG_INFO *NicInfo;
EFI_IP_ADDRESS Ip;
+ ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));
+
+ Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = IfrFormNvData->Configure;
+ Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = IfrFormNvData->DhcpEnable;
+ Ip4StrToIp (IfrFormNvData->StationAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp);
+ Ip4StrToIp (IfrFormNvData->SubnetMask, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask);
+ Ip4StrToIp (IfrFormNvData->GatewayAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway);
+
if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured) {
//
// Clear the variable
@@ -343,12 +321,6 @@ Ip4ConfigConvertIfrNvDataToDeviceConfigData (
parts of the results that must be
stored awaiting possible future
protocols.
- @retval EFI_INVALID_PARAMETER For example, passing in a NULL
- for the Request parameter
- would result in this type of
- error. In this case, the
- Progress parameter would be
- set to NULL.
@retval EFI_NOT_FOUND Routing data doesn't match any
known driver. Progress set to the
first character in the routing header.
@@ -374,76 +346,173 @@ Ip4DeviceExtractConfig (
)
{
EFI_STATUS Status;
- UINTN ConfigLen;
NIC_IP4_CONFIG_INFO *IfrDeviceNvData;
+ NIC_IP4_CONFIG_INFO *NicConfig;
IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
+ EFI_STRING ConfigRequestHdr;
+ EFI_STRING ConfigRequest;
+ EFI_STRING DeviceResult;
+ EFI_STRING FormResult;
+ CHAR16 *StrPointer;
+ BOOLEAN AllocatedRequest;
+ UINTN Size;
+ UINTN BufferSize;
- if (Request == NULL || Progress == NULL || Results == NULL) {
+ if (Progress == NULL || Results == NULL) {
return EFI_INVALID_PARAMETER;
}
- *Progress = Request;
-
+ *Progress = Request;
+ Size = 0;
+ DeviceResult = NULL;
+ FormResult = NULL;
+ ConfigRequest = NULL;
+ Status = EFI_SUCCESS;
+ AllocatedRequest = FALSE;
Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);
//
// Check Request data in <ConfigHdr>.
//
- if (HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
+ if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
if (IfrDeviceNvData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- ConfigLen = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2;
- Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, IfrDeviceNvData);
- if (EFI_ERROR (Status)) {
- FreePool (IfrDeviceNvData);
+ NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);
+ if (NicConfig == NULL) {
return EFI_NOT_FOUND;
}
-
+ CopyMem (IfrDeviceNvData, NicConfig, SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig));
+ FreePool (NicConfig);
+
+ ConfigRequest = Request;
+ if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
+ //
+ // Request has no request element, construct full request string.
+ // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
+ // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
+ //
+ ConfigRequestHdr = HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle);
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ ASSERT (ConfigRequest != NULL);
+ AllocatedRequest = TRUE;
+ BufferSize = NIC_ITEM_CONFIG_SIZE;
+ UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
+ FreePool (ConfigRequestHdr);
+ }
+
//
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
//
Status = gHiiConfigRouting->BlockToConfig (
gHiiConfigRouting,
- Request,
+ ConfigRequest,
(UINT8 *) IfrDeviceNvData,
NIC_ITEM_CONFIG_SIZE,
- Results,
+ &DeviceResult,
Progress
);
-
+
FreePool (IfrDeviceNvData);
+ //
+ // Free the allocated config request string.
+ //
+ if (AllocatedRequest) {
+ FreePool (ConfigRequest);
+ ConfigRequest = NULL;
+ }
- } else if (HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
+ if (EFI_ERROR (Status)) {
+ goto Failure;
+ }
+ }
- IfrFormNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
+ if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
+
+ IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));
if (IfrFormNvData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
-
+
Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData);
-
+
+ ConfigRequest = Request;
+ if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
+ //
+ // Request has no request element, construct full request string.
+ // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
+ // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
+ //
+ ConfigRequestHdr = HiiConstructConfigHdr (&mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle);
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ ASSERT (ConfigRequest != NULL);
+ AllocatedRequest = TRUE;
+ BufferSize = sizeof (IP4_CONFIG_IFR_NVDATA);
+ UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
+ FreePool (ConfigRequestHdr);
+ }
+
//
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
//
Status = gHiiConfigRouting->BlockToConfig (
gHiiConfigRouting,
- Request,
+ ConfigRequest,
(UINT8 *) IfrFormNvData,
sizeof (IP4_CONFIG_IFR_NVDATA),
- Results,
+ &FormResult,
Progress
);
-
+
FreePool (IfrFormNvData);
+ //
+ // Free the allocated config request string.
+ //
+ if (AllocatedRequest) {
+ FreePool (ConfigRequest);
+ ConfigRequest = NULL;
+ }
+
+ if (EFI_ERROR (Status)) {
+ goto Failure;
+ }
+ }
+ if (Request == NULL) {
+ Size = StrLen (DeviceResult);
+ Size = Size + 1;
+ Size = Size + StrLen (FormResult) + 1;
+ *Results = AllocateZeroPool (Size * sizeof (CHAR16));
+ ASSERT (*Results != NULL);
+ StrPointer = *Results;
+ StrCpy (StrPointer, DeviceResult);
+ StrPointer = StrPointer + StrLen (StrPointer);
+ *StrPointer = L'&';
+ StrCpy (StrPointer + 1, FormResult);
+ FreePool (DeviceResult);
+ FreePool (FormResult);
+ } else if (HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
+ *Results = DeviceResult;
+ } else if (HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
+ *Results = FormResult;
} else {
return EFI_NOT_FOUND;
}
+Failure:
+ //
+ // Set Progress string to the original request string.
+ //
+ if (Request == NULL) {
+ *Progress = NULL;
+ } else if (StrStr (Request, L"OFFSET") == NULL) {
+ *Progress = Request + StrLen (Request);
+ }
return Status;
}
@@ -492,7 +561,7 @@ Ip4DeviceRouteConfig (
EFI_STATUS Status;
UINTN BufferSize;
NIC_IP4_CONFIG_INFO *IfrDeviceNvData;
- IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
+ IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
NIC_IP4_CONFIG_INFO *NicInfo;
IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
EFI_MAC_ADDRESS ZeroMac;
@@ -501,6 +570,11 @@ Ip4DeviceRouteConfig (
return EFI_INVALID_PARAMETER;
}
+ //
+ // Reclaim Ip4Config variable
+ //
+ Ip4ConfigReclaimVariable ();
+
*Progress = Configuration;
Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);
@@ -526,9 +600,9 @@ Ip4DeviceRouteConfig (
Progress
);
if (!EFI_ERROR (Status)) {
- Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);
+ Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);
}
-
+
FreePool (IfrFormNvData);
} else if (HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
@@ -549,9 +623,13 @@ Ip4DeviceRouteConfig (
if (!EFI_ERROR (Status)) {
ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS));
if (CompareMem (&IfrDeviceNvData->NicAddr.MacAddr, &ZeroMac, IfrDeviceNvData->NicAddr.Len) != 0) {
- BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * IfrDeviceNvData->Ip4Info.RouteTableSize;
- NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData);
+ BufferSize = SIZEOF_NIC_IP4_CONFIG_INFO (IfrDeviceNvData);
+ NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData);
+ if (NicInfo == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);
+ FreePool (NicInfo);
} else {
ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));
Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);
@@ -564,7 +642,7 @@ Ip4DeviceRouteConfig (
return EFI_NOT_FOUND;
}
-
+
return Status;
}
@@ -607,7 +685,6 @@ Ip4FormCallback (
)
{
IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
- CHAR8 Ip4String[IP4_STR_MAX_SIZE];
IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
EFI_IP_ADDRESS HostIp;
EFI_IP_ADDRESS SubnetMask;
@@ -633,27 +710,8 @@ Ip4FormCallback (
Status = EFI_SUCCESS;
switch (QuestionId) {
-
- case KEY_ENABLE:
- if (IfrFormNvData->Configure == 0) {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = FALSE;
- } else {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = TRUE;
- }
- break;
-
- case KEY_DHCP_ENABLE:
- if (IfrFormNvData->DhcpEnable == 0) {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE;
- } else {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE;
- }
-
- break;
-
case KEY_LOCAL_IP:
- UnicodeStrToAsciiStr (IfrFormNvData->StationAddress, Ip4String);
- Status = Ip4AsciiStrToIp (Ip4String, &HostIp.v4);
+ Status = Ip4StrToIp (IfrFormNvData->StationAddress, &HostIp.v4);
if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
Status = EFI_INVALID_PARAMETER;
@@ -664,10 +722,9 @@ Ip4FormCallback (
break;
case KEY_SUBNET_MASK:
- UnicodeStrToAsciiStr (IfrFormNvData->SubnetMask, Ip4String);
- Status = Ip4AsciiStrToIp (Ip4String, &SubnetMask.v4);
+ Status = Ip4StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);
if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid SubnetMask!", NULL);
+ CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);
Status = EFI_INVALID_PARAMETER;
} else {
CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));
@@ -676,8 +733,7 @@ Ip4FormCallback (
break;
case KEY_GATE_WAY:
- UnicodeStrToAsciiStr (IfrFormNvData->GatewayAddress, Ip4String);
- Status = Ip4AsciiStrToIp (Ip4String, &Gateway.v4);
+ Status = Ip4StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);
if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
Status = EFI_INVALID_PARAMETER;
@@ -688,24 +744,14 @@ Ip4FormCallback (
break;
case KEY_SAVE_CHANGES:
- Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);
-
+ Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
-
break;
default:
-
break;
}
- if (!EFI_ERROR (Status)) {
- //
- // Pass changed uncommitted data back to Form Browser
- //
- HiiSetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData, NULL);
- }
-
FreePool (IfrFormNvData);
return Status;
@@ -729,7 +775,7 @@ Ip4ConfigDeviceInit (
EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
VENDOR_DEVICE_PATH VendorDeviceNode;
EFI_SERVICE_BINDING_PROTOCOL *MnpSb;
- CHAR16 MacString[95];
+ CHAR16 *MacString;
CHAR16 MenuString[128];
CHAR16 PortString[128];
CHAR16 *OldMenuString;
@@ -763,7 +809,7 @@ Ip4ConfigDeviceInit (
Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->ChildHandle,
&gEfiDevicePathProtocolGuid,
- Instance->HiiVendorDevicePath,
+ Instance->HiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
ConfigAccess,
NULL
@@ -777,13 +823,13 @@ Ip4ConfigDeviceInit (
&gEfiManagedNetworkServiceBindingProtocolGuid,
(VOID **) &MnpSb,
Instance->Image,
- Instance->ChildHandle,
+ Instance->ChildHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
}
ASSERT_EFI_ERROR (Status);
-
+
//
// Publish our HII data
//
@@ -801,14 +847,16 @@ Ip4ConfigDeviceInit (
//
// Append MAC string in the menu string and tile string
//
- Ip4MacAddrToStr (&Instance->NicAddr.MacAddr, Instance->NicAddr.Len, MacString);
-
- OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), NULL);
+ Status = NetLibGetMacString (Instance->Controller, Instance->Image, &MacString);
+ if (!EFI_ERROR (Status)) {
+ OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), NULL);
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
- HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), MenuString, NULL);
+ HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), MenuString, NULL);
UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
- HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_TITLE), PortString, NULL);
+ HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_TITLE), PortString, NULL);
+ FreePool (MacString);
+ }
return Status;
}
@@ -847,7 +895,7 @@ Ip4ConfigDeviceUnload (
gBS->UninstallMultipleProtocolInterfaces (
Instance->ChildHandle,
&gEfiDevicePathProtocolGuid,
- Instance->HiiVendorDevicePath,
+ Instance->HiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
&Instance->HiiConfigAccessProtocol,
NULL
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h
index 54e5405461..3b4168e974 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h
@@ -1,8 +1,8 @@
/** @file
The header file of IP4ConfigNv.c
-Copyright (c) 2009, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+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
http://opensource.org/licenses/bsd-license.php
@@ -21,7 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
extern UINT8 Ip4ConfigDxeBin[];
extern UINT8 Ip4ConfigDxeStrings[];
-#define NIC_ITEM_CONFIG_SIZE sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE
+#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + (sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE))
/**
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h
index 13941e1867..5ae6ea8c45 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h
@@ -1,8 +1,8 @@
/** @file
Routines used to operate the Ip4 configure variable.
-Copyright (c) 2009 - 2010, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
@@ -40,7 +40,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
/// of variable length.
///
typedef struct {
- UINT16 NicAddr[3]; ///< NIC MAC address
UINT8 Configure; ///< NIC configure status
UINT8 DhcpEnable; ///< Static or DHCP
CHAR16 StationAddress[IP4_STR_MAX_SIZE]; ///< IP addresses
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c
index b948cf8c7b..696f363a62 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c
@@ -1,8 +1,8 @@
/** @file
Routines used to operate the Ip4 configure variable.
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
@@ -12,8 +12,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
+#include "Ip4Config.h"
#include "NicIp4Variable.h"
+BOOLEAN mIp4ConfigVariableReclaimed = FALSE;
/**
Check whether the configure parameter is valid.
@@ -77,302 +79,225 @@ Ip4ConfigIsValid (
/**
Read the ip4 configure variable from the EFI variable.
- None
+ @param Instance The IP4 CONFIG instance.
- @return The IP4 configure read if it is there and is valid, otherwise NULL
+ @return The IP4 configure read if it is there and is valid, otherwise NULL.
**/
-IP4_CONFIG_VARIABLE *
+NIC_IP4_CONFIG_INFO *
Ip4ConfigReadVariable (
- VOID
+ IN IP4_CONFIG_INSTANCE *Instance
)
{
- IP4_CONFIG_VARIABLE *Variable;
- EFI_STATUS Status;
- UINTN Size;
- UINT16 CheckSum;
-
- //
- // Get the size of variable, then allocate a buffer to read the variable.
- //
- Size = 0;
- Variable = NULL;
- Status = gRT->GetVariable (
- EFI_NIC_IP4_CONFIG_VARIABLE,
- &gEfiNicIp4ConfigVariableGuid,
- NULL,
- &Size,
- NULL
- );
-
- if (Status != EFI_BUFFER_TOO_SMALL) {
- return NULL;
- }
-
- if (Size < sizeof (IP4_CONFIG_VARIABLE)) {
- goto REMOVE_VARIABLE;
- }
-
- Variable = AllocatePool (Size);
+ NIC_IP4_CONFIG_INFO *NicConfig;
- if (Variable == NULL) {
- return NULL;
+ NicConfig = GetVariable (Instance->MacString, &gEfiNicIp4ConfigVariableGuid);
+ if (NicConfig != NULL) {
+ Ip4ConfigFixRouteTablePointer (&NicConfig->Ip4Info);
}
- Status = gRT->GetVariable (
- EFI_NIC_IP4_CONFIG_VARIABLE,
- &gEfiNicIp4ConfigVariableGuid,
- NULL,
- &Size,
- Variable
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_ERROR;
- }
-
- //
- // Verify the checksum, variable size and count
- //
- CheckSum = (UINT16) (~NetblockChecksum ((UINT8 *) Variable, (UINT32)Size));
-
- if ((CheckSum != 0) || (Size != Variable->Len)) {
- goto REMOVE_VARIABLE;
- }
-
- if ((Variable->Count < 1) || (Variable->Count > MAX_IP4_CONFIG_IN_VARIABLE)) {
- goto REMOVE_VARIABLE;
- }
-
- return Variable;
-
-REMOVE_VARIABLE:
- Ip4ConfigWriteVariable (NULL);
-
-ON_ERROR:
- if (Variable != NULL) {
- FreePool (Variable);
- }
-
- return NULL;
+ return NicConfig;
}
-
/**
Write the IP4 configure variable to the NVRAM. If Config
is NULL, remove the variable.
- @param Config The IP4 configure data to write
+ @param Instance The IP4 CONFIG instance.
+ @param NicConfig The IP4 configure data to write.
- @retval EFI_SUCCESS The variable is written to the NVRam
+ @retval EFI_SUCCESS The variable is written to the NVRam.
@retval Others Failed to write the variable.
**/
EFI_STATUS
Ip4ConfigWriteVariable (
- IN IP4_CONFIG_VARIABLE *Config OPTIONAL
+ IN IP4_CONFIG_INSTANCE *Instance,
+ IN NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = gRT->SetVariable (
- EFI_NIC_IP4_CONFIG_VARIABLE,
+ Instance->MacString,
&gEfiNicIp4ConfigVariableGuid,
IP4_CONFIG_VARIABLE_ATTRIBUTES,
- (Config == NULL) ? 0 : Config->Len,
- Config
+ (NicConfig == NULL) ? 0 : SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig),
+ NicConfig
);
return Status;
}
-
/**
- Locate the IP4 configure parameters from the variable.If a
- configuration is found, copy it to a newly allocated block
- of memory to avoid the alignment problem. Caller should
- release the memory after use.
+ Check whether a NIC exist in the platform given its MAC address.
- @param Variable The IP4 configure variable to search in
- @param NicAddr The interface address to check
+ @param NicAddr The MAC address for the NIC to be checked.
- @return The point to the NIC's IP4 configure info if it is found
- in the IP4 variable, otherwise NULL.
+ @retval TRUE The NIC exist in the platform.
+ @retval FALSE The NIC doesn't exist in the platform.
**/
-NIC_IP4_CONFIG_INFO *
-Ip4ConfigFindNicVariable (
- IN IP4_CONFIG_VARIABLE *Variable,
+BOOLEAN
+Ip4ConfigIsNicExist (
IN NIC_ADDR *NicAddr
)
{
- NIC_IP4_CONFIG_INFO Temp;
- NIC_IP4_CONFIG_INFO *Config;
- UINT32 Index;
- UINT8 *Cur;
- UINT32 Len;
-
- Cur = (UINT8*)&Variable->ConfigInfo;
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer;
+ UINTN NumberOfHandles;
+ UINTN Index;
+ BOOLEAN Found;
+ UINTN AddrSize;
+ EFI_MAC_ADDRESS MacAddr;
- for (Index = 0; Index < Variable->Count; Index++) {
- //
- // Copy the data to Temp to avoid the alignment problems
- //
- CopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));
- Len = SIZEOF_NIC_IP4_CONFIG_INFO (&Temp);
+ //
+ // Locate Service Binding handles.
+ //
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiManagedNetworkServiceBindingProtocolGuid,
+ NULL,
+ &NumberOfHandles,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ Found = FALSE;
+ for (Index = 0; Index < NumberOfHandles; Index++) {
//
- // Found the matching configuration parameters, allocate
- // a block of memory then copy it out.
+ // Get MAC address.
//
- if (NIC_ADDR_EQUAL (&Temp.NicAddr, NicAddr)) {
- Config = AllocatePool (Len);
-
- if (Config == NULL) {
- return NULL;
- }
-
- CopyMem (Config, Cur, Len);
- Ip4ConfigFixRouteTablePointer (&Config->Ip4Info);
- return Config;
+ AddrSize = 0;
+ Status = NetLibGetMacAddress (HandleBuffer[Index], &MacAddr, &AddrSize);
+ if (EFI_ERROR (Status)) {
+ Found = FALSE;
+ goto Exit;
}
- Cur += Len;
+ if ((NicAddr->Len == AddrSize) && (CompareMem (NicAddr->MacAddr.Addr, MacAddr.Addr, AddrSize) == 0)) {
+ Found = TRUE;
+ goto Exit;
+ }
}
- return NULL;
+Exit:
+ FreePool (HandleBuffer);
+ return Found;
}
-
/**
- Modify the configuration parameter for the NIC in the variable.
- If Config is NULL, old configuration will be remove from the new
- variable. Otherwise, append it or replace the old one.
-
- @param Variable The IP4 variable to change
- @param NicAddr The interface to search
- @param Config The new configuration parameter (NULL to remove the old)
-
- @return The new IP4_CONFIG_VARIABLE variable if the new variable has at
- least one NIC configure and no EFI_OUT_OF_RESOURCES failure.
- Return NULL either because failed to locate memory for new variable
- or the only NIC configure is removed from the Variable.
+ Reclaim Ip4Config Variables for NIC which has been removed from the platform.
**/
-IP4_CONFIG_VARIABLE *
-Ip4ConfigModifyVariable (
- IN IP4_CONFIG_VARIABLE *Variable OPTIONAL,
- IN NIC_ADDR *NicAddr,
- IN NIC_IP4_CONFIG_INFO *Config OPTIONAL
+VOID
+Ip4ConfigReclaimVariable (
+ VOID
)
{
- NIC_IP4_CONFIG_INFO Temp;
- NIC_IP4_CONFIG_INFO *Old;
- IP4_CONFIG_VARIABLE *NewVar;
- UINT32 Len;
- UINT32 TotalLen;
- UINT32 Count;
- UINT8 *Next;
- UINT8 *Cur;
- UINT32 Index;
-
- ASSERT ((Variable != NULL) || (Config != NULL));
+ EFI_STATUS Status;
+ UINTN VariableNameSize;
+ CHAR16 *VariableName;
+ CHAR16 *CurrentVariableName;
+ EFI_GUID VendorGuid;
+ UINTN VariableNameBufferSize;
+ NIC_IP4_CONFIG_INFO *NicConfig;
//
- // Compute the total length
+ // Check whether we need perform reclaim.
//
- if (Variable != NULL) {
- //
- // Variable != NULL, then Config can be NULL or not. and so is
- // the Old. If old configure exists, it is removed from the
- // Variable. New configure is append to the variable.
- //
- //
- Count = Variable->Count;
- Cur = (UINT8 *)&Variable->ConfigInfo;
- TotalLen = Variable->Len;
+ if (mIp4ConfigVariableReclaimed) {
+ return;
+ }
+ mIp4ConfigVariableReclaimed = TRUE;
- Old = Ip4ConfigFindNicVariable (Variable, NicAddr);
+ //
+ // Get all Ip4Config Variable.
+ //
+ VariableNameSize = sizeof (CHAR16);
+ VariableName = AllocateZeroPool (VariableNameSize);
+ VariableNameBufferSize = VariableNameSize;
+
+ while (TRUE) {
+ Status = gRT->GetNextVariableName (
+ &VariableNameSize,
+ VariableName,
+ &VendorGuid
+ );
- if (Old != NULL) {
- TotalLen -= SIZEOF_NIC_IP4_CONFIG_INFO (Old);
- FreePool (Old);
+Check:
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ VariableName = ReallocatePool (VariableNameBufferSize, VariableNameSize, VariableName);
+ VariableNameBufferSize = VariableNameSize;
+ //
+ // Try again using the new buffer.
+ //
+ Status = gRT->GetNextVariableName (
+ &VariableNameSize,
+ VariableName,
+ &VendorGuid
+ );
}
- if (Config != NULL) {
- TotalLen += SIZEOF_NIC_IP4_CONFIG_INFO (Config);
+ if (EFI_ERROR (Status)) {
+ //
+ // No more variable available, finish search.
+ //
+ break;
}
//
- // Return NULL if the only NIC_IP4_CONFIG_INFO is being removed.
+ // Check variable GUID.
//
- if (TotalLen < sizeof (IP4_CONFIG_VARIABLE)) {
- return NULL;
+ if (!CompareGuid (&VendorGuid, &gEfiNicIp4ConfigVariableGuid)) {
+ continue;
}
- } else {
- //
- // Variable == NULL and Config != NULL, Create a new variable with
- // this NIC configure.
- //
- Count = 0;
- Cur = NULL;
- TotalLen = sizeof (IP4_CONFIG_VARIABLE) - sizeof (NIC_IP4_CONFIG_INFO)
- + SIZEOF_NIC_IP4_CONFIG_INFO (Config);
- }
-
- ASSERT (TotalLen >= sizeof (IP4_CONFIG_VARIABLE));
-
- NewVar = AllocateZeroPool (TotalLen);
-
- if (NewVar == NULL) {
- return NULL;
- }
-
- NewVar->Len = TotalLen;
-
- //
- // Copy the other configure parameters from the old variable
- //
- Next = (UINT8 *)&NewVar->ConfigInfo;
-
- for (Index = 0; Index < Count; Index++) {
- CopyMem (&Temp, Cur, sizeof (NIC_IP4_CONFIG_INFO));
- Len = SIZEOF_NIC_IP4_CONFIG_INFO (&Temp);
-
- if (!NIC_ADDR_EQUAL (&Temp.NicAddr, NicAddr)) {
- CopyMem (Next, Cur, Len);
- Next += Len;
- NewVar->Count++;
+ NicConfig = GetVariable (VariableName, &gEfiNicIp4ConfigVariableGuid);
+ if (NicConfig == NULL) {
+ break;
}
- Cur += Len;
- }
-
- //
- // Append the new configure if it isn't NULL.
- //
- Len = 0;
-
- if (Config != NULL) {
- Len = SIZEOF_NIC_IP4_CONFIG_INFO (Config);
-
- CopyMem (Next, Config, Len);
- NewVar->Count++;
+ if (!Ip4ConfigIsNicExist (&NicConfig->NicAddr)) {
+ //
+ // No NIC found for this Ip4Config variable, remove it.
+ // Since we are in loop of GetNextVariableName(), we need move on to next
+ // Variable first and then delete current Variable.
+ //
+ CurrentVariableName = AllocateCopyPool (VariableNameSize, VariableName);
+ Status = gRT->GetNextVariableName (
+ &VariableNameSize,
+ VariableName,
+ &VendorGuid
+ );
+
+ gRT->SetVariable (
+ CurrentVariableName,
+ &gEfiNicIp4ConfigVariableGuid,
+ IP4_CONFIG_VARIABLE_ATTRIBUTES,
+ 0,
+ NULL
+ );
+ FreePool (CurrentVariableName);
+
+ //
+ // We already get next variable, go to check it.
+ //
+ goto Check;
+ }
}
- ASSERT (Next + Len == (UINT8 *) NewVar + TotalLen);
-
- NewVar->CheckSum = (UINT16) (~NetblockChecksum ((UINT8 *) NewVar, TotalLen));
- return NewVar;
+ FreePool (VariableName);
}
/**
- Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure.
-
+ Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure.
+
The pointer is set to be immediately follow the ConfigData if there're entries
in the RouteTable. Otherwise it is set to NULL.
-
+
@param ConfigData The IP4 IP configure data.
**/
@@ -382,7 +307,7 @@ Ip4ConfigFixRouteTablePointer (
)
{
//
- // The memory used for route table entries must immediately follow
+ // The memory used for route table entries must immediately follow
// the ConfigData and be not packed.
//
if (ConfigData->RouteTableSize > 0) {
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h
index 6a4e94193e..2f8defe789 100644
--- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h
+++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h
@@ -1,8 +1,8 @@
/** @file
Routines used to operate the Ip4 configure variable.
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>
-All rights reserved. This program and the accompanying materials
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+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<BR>
http://opensource.org/licenses/bsd-license.php
@@ -15,29 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef _NIC_IP4_VARIABLE_H_
#define _NIC_IP4_VARIABLE_H_
-#include <Uefi.h>
-
-#include <Guid/NicIp4ConfigNvData.h>
-
-#include <Library/NetLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-
-///
-/// IP4_CONFIG_VARIABLE is the EFI variable to
-/// save the configuration. IP4_CONFIG_VARIABLE is
-/// of variable length.
-///
-typedef struct {
- UINT32 Len; ///< Total length of the variable
- UINT16 CheckSum; ///< CheckSum, the same as IP4 head checksum
- UINT32 Count; ///< Number of NIC_IP4_CONFIG_INFO follows
- NIC_IP4_CONFIG_INFO ConfigInfo;
-} IP4_CONFIG_VARIABLE;
-
//
// Return the size of NIC_IP4_CONFIG_INFO and EFI_IP4_IPCONFIG_DATA.
// They are of variable size
@@ -73,78 +50,48 @@ Ip4ConfigIsValid (
/**
Read the ip4 configure variable from the EFI variable.
- None
+ @param Instance The IP4 CONFIG instance.
- @return The IP4 configure read if it is there and is valid, otherwise NULL
+ @return The IP4 configure read if it is there and is valid, otherwise NULL.
**/
-IP4_CONFIG_VARIABLE *
+NIC_IP4_CONFIG_INFO *
Ip4ConfigReadVariable (
- VOID
+ IN IP4_CONFIG_INSTANCE *Instance
);
/**
Write the IP4 configure variable to the NVRAM. If Config
is NULL, remove the variable.
- @param Config The IP4 configure data to write
+ @param Instance The IP4 CONFIG instance.
+ @param NicConfig The IP4 configure data to write.
- @retval EFI_SUCCESS The variable is written to the NVRam
+ @retval EFI_SUCCESS The variable is written to the NVRam.
@retval Others Failed to write the variable.
**/
EFI_STATUS
Ip4ConfigWriteVariable (
- IN IP4_CONFIG_VARIABLE *Config OPTIONAL
+ IN IP4_CONFIG_INSTANCE *Instance,
+ IN NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL
);
/**
- Locate the IP4 configure parameters from the variable.If a
- configuration is found, copy it to a newly allocated block
- of memory to avoid the alignment problem. Caller should
- release the memory after use.
-
- @param Variable The IP4 configure variable to search in
- @param NicAddr The interface address to check
-
- @return The point to the NIC's IP4 configure info if it is found
- in the IP4 variable, otherwise NULL.
+ Reclaim Ip4Config Variables for NIC which has been removed from the platform.
**/
-NIC_IP4_CONFIG_INFO *
-Ip4ConfigFindNicVariable (
- IN IP4_CONFIG_VARIABLE *Variable,
- IN NIC_ADDR *NicAddr
+VOID
+Ip4ConfigReclaimVariable (
+ VOID
);
/**
- Modify the configuration parameter for the NIC in the variable.
- If Config is NULL, old configuration will be remove from the new
- variable. Otherwise, append it or replace the old one.
+ Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure.
- @param Variable The IP4 variable to change
- @param NicAddr The interface to search
- @param Config The new configuration parameter (NULL to remove the old)
-
- @return The new IP4_CONFIG_VARIABLE variable if the new variable has at
- least one NIC configure and no EFI_OUT_OF_RESOURCES failure.
- Return NULL either because failed to locate memory for new variable
- or the only NIC configure is removed from the Variable.
-
-**/
-IP4_CONFIG_VARIABLE *
-Ip4ConfigModifyVariable (
- IN IP4_CONFIG_VARIABLE *Variable OPTIONAL,
- IN NIC_ADDR *NicAddr,
- IN NIC_IP4_CONFIG_INFO *Config OPTIONAL
- );
-
-/**
- Fix the RouteTable pointer in an EFI_IP4_IPCONFIG_DATA structure.
-
The pointer is set to be immediately follow the ConfigData if there're entries
in the RouteTable. Otherwise it is set to NULL.
-
+
@param ConfigData The IP4 IP configure data.
**/