From: xdu2 Date: Mon, 5 Jul 2010 02:03:20 +0000 (+0000) Subject: 1. update to use 1 EFI Variable per NIC (instead of converge all NIC configuration... X-Git-Tag: edk2-stable201903~15717 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=74df5026b22cd13ab09766a2ba49298b4c5f9ac0 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. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10628 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c index 8f26b6f79b..cc3f6fb97f 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c @@ -1,7 +1,7 @@ /** @file This code implements the IP4Config and NicIp4Config protocols. -Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2010, 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
@@ -13,43 +13,32 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "Ip4Config.h" - -IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE]; +#include "NicIp4Variable.h" /** 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,85 +46,16 @@ 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. @@ -167,9 +87,7 @@ EfiNicIp4ConfigSetInfo ( IN BOOLEAN Reconfig ) { - IP4_CONFIG_VARIABLE *Variable; - IP4_CONFIG_VARIABLE *NewVariable; - EFI_STATUS Status; + EFI_STATUS Status; // // Validate the parameters @@ -190,26 +108,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; } @@ -420,7 +319,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; diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h index 5eadad2746..87bc25c2f1 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h @@ -26,6 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include @@ -41,8 +42,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include -#include "NicIp4Variable.h" - typedef struct _IP4_CONFIG_INSTANCE IP4_CONFIG_INSTANCE; // @@ -52,7 +51,6 @@ 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 @@ -122,8 +120,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; // @@ -173,28 +170,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 ); /** diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c index 0cc2918e43..dfa4cdcd8f 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c @@ -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,42 +26,6 @@ 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; - } - - gIp4ConfigDriverBinding.Stop ( - &gIp4ConfigDriverBinding, - mIp4ConfigNicList[Index]->MnpHandle, - 0, - NULL - ); - } - - return NetLibDefaultUnload (ImageHandle); -} - /** The entry point for IP4 config driver which install the driver binding and component name protocol on its image. @@ -152,11 +117,8 @@ 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 ( @@ -218,7 +180,7 @@ Ip4ConfigDriverBindingStart ( // // Allocate an instance then initialize it // - Instance = AllocatePool (sizeof (IP4_CONFIG_INSTANCE)); + Instance = AllocateZeroPool (sizeof (IP4_CONFIG_INSTANCE)); if (Instance == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -258,30 +220,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 +238,6 @@ Ip4ConfigDriverBindingStart ( ); if (EFI_ERROR (Status)) { - mIp4ConfigNicList[Index] = NULL; goto ON_ERROR; } @@ -299,50 +245,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); } @@ -505,10 +428,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 4330afef5f..530b5668a0 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf @@ -21,7 +21,7 @@ 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. # @@ -67,4 +67,4 @@ [Guids] gEfiNicIp4ConfigVariableGuid ## CONSUMES ## Guid - + diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c index c0d27aac78..fa78678ade 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "Ip4ConfigNv.h" +#include "NicIp4Variable.h" EFI_GUID mNicIp4ConfigNvDataGuid = EFI_NIC_IP4_CONFIG_NVDATA_GUID; @@ -61,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 ) { @@ -77,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++; } @@ -95,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. @@ -103,7 +104,7 @@ Ip4AsciiStrToIp ( return EFI_INVALID_PARAMETER; } - if (*Str == '.') { + if (*Str == L'.') { // // Skip the delimiter. // @@ -148,15 +149,10 @@ 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; if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) { IfrFormNvData->DhcpEnable = 1; @@ -166,17 +162,18 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData ( Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask); Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress); } + + FreePool (NicConfig); } else { IfrFormNvData->Configure = 0; } - - 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 @@ -187,6 +184,7 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData ( **/ EFI_STATUS Ip4ConfigConvertIfrNvDataToDeviceConfigData ( + IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData, IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance ) { @@ -198,6 +196,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 @@ -332,8 +338,8 @@ 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; @@ -367,12 +373,12 @@ Ip4DeviceExtractConfig ( 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)) { @@ -415,11 +421,11 @@ Ip4DeviceExtractConfig ( if (EFI_ERROR (Status)) { goto Failure; } - } - + } + if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { - IfrFormNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); + IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA)); if (IfrFormNvData == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -442,7 +448,7 @@ Ip4DeviceExtractConfig ( UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); FreePool (ConfigRequestHdr); } - + // // Convert buffer data to by helper function BlockToConfig() // @@ -499,7 +505,7 @@ Failure: } else if (StrStr (Request, L"OFFSET") == NULL) { *Progress = Request + StrLen (Request); } - + return Status; } @@ -556,6 +562,11 @@ Ip4DeviceRouteConfig ( return EFI_INVALID_PARAMETER; } + // + // Reclaim Ip4Config variable + // + Ip4ConfigReclaimVariable (); + *Progress = Configuration; Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This); @@ -581,7 +592,7 @@ Ip4DeviceRouteConfig ( Progress ); if (!EFI_ERROR (Status)) { - Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance); + Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance); } FreePool (IfrFormNvData); @@ -604,9 +615,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; + 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); @@ -662,7 +677,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; @@ -670,11 +684,11 @@ Ip4FormCallback ( EFI_STATUS Status; EFI_INPUT_KEY Key; - if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) { + if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) { // // Do nothing for UEFI OPEN/CLOSE Action // - return EFI_SUCCESS; + return EFI_SUCCESS; } Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This); @@ -695,27 +709,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) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); Status = EFI_INVALID_PARAMETER; @@ -726,10 +721,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)); @@ -738,8 +732,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) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL); Status = EFI_INVALID_PARAMETER; @@ -750,25 +743,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; diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h index 2d75c6d90e..3b4168e974 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h @@ -1,7 +1,7 @@ /** @file The header file of IP4ConfigNv.c -Copyright (c) 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2010, 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 @@ -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 59996ea77b..5ae6ea8c45 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h @@ -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 2d645beec0..f283db019d 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.c @@ -1,7 +1,7 @@ /** @file Routines used to operate the Ip4 configure variable. -Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2010, 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
@@ -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 89e5503c52..2f8defe789 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h @@ -1,7 +1,7 @@ /** @file Routines used to operate the Ip4 configure variable. -Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2010, 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
@@ -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 - -#include - -#include -#include -#include -#include -#include -#include - -/// -/// 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. **/