From 638868496cafa80a7212f654559944f34f65598a Mon Sep 17 00:00:00 2001 From: vanjeff Date: Wed, 13 May 2009 09:29:44 +0000 Subject: 1. retired NicIp4ConfigProtocolGuid 2. moved NicIp4ConfigVariableGuid to Include/Guid/NicIp4ConfigNvData.h 3. updated Ip4ConfigDxe module to publish one setup page to Get/Set network parameters. Also, Ip4ConfgiDxe installed EFI HII Config Access protocol for each network devices. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8309 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Include/Guid/NicIp4ConfigNvData.h | 73 ++ MdeModulePkg/Include/Protocol/NicIp4Config.h | 177 --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 105 +- MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf | 11 +- MdeModulePkg/MdeModulePkg.dec | 9 +- .../Universal/Network/Ip4ConfigDxe/Ip4Config.c | 65 +- .../Universal/Network/Ip4ConfigDxe/Ip4Config.h | 132 ++- .../Network/Ip4ConfigDxe/Ip4ConfigDriver.c | 22 +- .../Network/Ip4ConfigDxe/Ip4ConfigDxe.inf | 20 +- .../Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr | 92 ++ .../Network/Ip4ConfigDxe/Ip4ConfigDxeStrings.uni | Bin 0 -> 3036 bytes .../Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c | 1139 ++++++++++++++++++++ .../Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h | 104 ++ .../Universal/Network/Ip4ConfigDxe/Ip4NvData.h | 59 + .../Network/Ip4ConfigDxe/NicIp4Variable.h | 18 +- 15 files changed, 1734 insertions(+), 292 deletions(-) create mode 100644 MdeModulePkg/Include/Guid/NicIp4ConfigNvData.h delete mode 100644 MdeModulePkg/Include/Protocol/NicIp4Config.h create mode 100644 MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr create mode 100644 MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxeStrings.uni create mode 100644 MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c create mode 100644 MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h create mode 100644 MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Include/Guid/NicIp4ConfigNvData.h b/MdeModulePkg/Include/Guid/NicIp4ConfigNvData.h new file mode 100644 index 0000000..94a2a5b --- /dev/null +++ b/MdeModulePkg/Include/Guid/NicIp4ConfigNvData.h @@ -0,0 +1,73 @@ +/** @file + This file defines NIC_IP4_CONFIG_INFO structure. + +Copyright (c) 2009, 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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __NIC_IP4_CONFIG_NVDATA_H__ +#define __NIC_IP4_CONFIG_NVDATA_H__ + +#include + +#define EFI_NIC_IP4_CONFIG_VARIABLE_GUID \ + { \ + 0xd8944553, 0xc4dd, 0x41f4, { 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b } \ + } + +#define EFI_NIC_IP4_CONFIG_VARIABLE L"EfiNicIp4ConfigVariable" + +typedef enum { + // + // Config source: dhcp or static + // + IP4_CONFIG_SOURCE_DHCP = 0, + IP4_CONFIG_SOURCE_STATIC, + IP4_CONFIG_SOURCE_MAX, + + IP4_NIC_NAME_LENGTH = 64, + MAX_IP4_CONFIG_IN_VARIABLE = 16 +} IP4_CONFIG_TYPE; + +// +// The following structures are used by drivers/applications other +// than EFI_IP4_PROTOCOL, such as ifconfig shell application, to +// communicate the IP configuration information to EFI_IP4_CONFIG_PROTOCOL. +// EFI_IP4_CONFIG_PROTOCOL in turn is used by EFI_IP4_PROTOCOL to get +// the default IP4 configuration. ifconfig can't use the EFI_IP4_PROTOCOL +// because it don't know how to configure the default IP address even +// it has got the address. +// + +/// +/// NIC_ADDR contains the interface's type and MAC address to identify +/// a specific NIC. +/// +typedef struct { + UINT16 Type; ///< Interface type + UINT8 Len; ///< Length of MAC address + EFI_MAC_ADDRESS MacAddr; ///< MAC address of interface +} NIC_ADDR; + +/// +/// NIC_IP4_CONFIG_INFO contains the IP4 configure +/// parameters for that NIC. NIC_IP4_CONFIG_INFO is +/// of variable length. +/// +typedef struct { + NIC_ADDR NicAddr; ///< Link layer address to identify the NIC + UINT32 Source; ///< Static or DHCP + BOOLEAN Perment; ///< Survive the reboot or not + EFI_IP4_IPCONFIG_DATA Ip4Info; ///< IP addresses +} NIC_IP4_CONFIG_INFO; + +extern EFI_GUID gEfiNicIp4ConfigVariableGuid; + +#endif diff --git a/MdeModulePkg/Include/Protocol/NicIp4Config.h b/MdeModulePkg/Include/Protocol/NicIp4Config.h deleted file mode 100644 index 28284fe..0000000 --- a/MdeModulePkg/Include/Protocol/NicIp4Config.h +++ /dev/null @@ -1,177 +0,0 @@ -/** @file - This file defines NicIp4Config Protocol. - EFI_NIC_IP4_CONFIG_PROTOCOL is a proprietary protocol, not defined by UEFI2.0. - -Copyright (c) 2006 - 2008, 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 -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __NIC_IP4_CONFIG_H__ -#define __NIC_IP4_CONFIG_H__ - -#include - - -#define EFI_NIC_IP4_CONFIG_PROTOCOL_GUID \ - { \ - 0xdca3d4d, 0x12da, 0x4728, { 0xbf, 0x7e, 0x86, 0xce, 0xb9, 0x28, 0xd0, 0x67 } \ - } - -#define EFI_NIC_IP4_CONFIG_VARIABLE_GUID \ - { \ - 0xd8944553, 0xc4dd, 0x41f4, { 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b } \ - } - -#define EFI_NIC_IP4_CONFIG_VARIABLE L"EfiNicIp4ConfigVariable" - - -typedef struct _EFI_NIC_IP4_CONFIG_PROTOCOL EFI_NIC_IP4_CONFIG_PROTOCOL; - -typedef enum { - // - // Config source: dhcp or static - // - IP4_CONFIG_SOURCE_DHCP = 0, - IP4_CONFIG_SOURCE_STATIC, - IP4_CONFIG_SOURCE_MAX, - - IP4_NIC_NAME_LENGTH = 64, - MAX_IP4_CONFIG_IN_VARIABLE = 16 -} IP4_CONFIG_TYPE; - -// -// The following structures are used by drivers/applications other -// than EFI_IP4_PROTOCOL, such as ifconfig shell application, to -// communicate the IP configuration information to EFI_IP4_CONFIG_PROTOCOL. -// EFI_IP4_CONFIG_PROTOCOL in turn is used by EFI_IP4_PROTOCOL to get -// the default IP4 configuration. ifconfig can't use the EFI_IP4_PROTOCOL -// because it don't know how to configure the default IP address even -// it has got the address. -// - -/// -/// NIC_ADDR contains the interface's type and MAC address to identify -/// a specific NIC. -/// -typedef struct { - UINT16 Type; ///< Interface type - UINT8 Len; ///< Length of MAC address - EFI_MAC_ADDRESS MacAddr; ///< MAC address of interface -} NIC_ADDR; - -/// -/// NIC_IP4_CONFIG_INFO contains the IP4 configure -/// parameters for that NIC. NIC_IP4_CONFIG_INFO is -/// of variable length. -/// -typedef struct { - NIC_ADDR NicAddr; ///< Link layer address to identify the NIC - UINT32 Source; ///< Static or DHCP - BOOLEAN Perment; ///< Survive the reboot or not - EFI_IP4_IPCONFIG_DATA Ip4Info; ///< IP addresses -} NIC_IP4_CONFIG_INFO; - -/// -/// 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; - -/** - Get the configure parameter for this NIC. - - @param This The NIC IP4 CONFIG protocol. - @param Len 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. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_NIC_IP4_CONFIG_GET_INFO)( - IN EFI_NIC_IP4_CONFIG_PROTOCOL *This, - IN OUT UINTN *Len, - OUT NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL - ); - -/** - 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 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 This The NIC IP4 CONFIG protocol - @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 . - @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 - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_NIC_IP4_CONFIG_SET_INFO)( - IN EFI_NIC_IP4_CONFIG_PROTOCOL *This, - IN NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL, - IN BOOLEAN ReConfig - ); - -/** - Return the name and MAC address for the NIC. The Name, if not NULL, - has at least IP4_NIC_NAME_LENGTH bytes. - - @param This The NIC IP4 CONFIG protocol - @param Name The buffer to return the name - @param NicAddr The buffer to return the MAC addr - - @retval EFI_INVALID_PARAMETER This is NULL - @retval EFI_SUCCESS The name or address of the NIC are returned. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_NIC_IP4_CONFIG_GET_NAME)( - IN EFI_NIC_IP4_CONFIG_PROTOCOL *This, - OUT UINT16 *Name OPTIONAL, - OUT NIC_ADDR *NicAddr OPTIONAL - ); - -struct _EFI_NIC_IP4_CONFIG_PROTOCOL { - EFI_NIC_IP4_CONFIG_GET_NAME GetName; - EFI_NIC_IP4_CONFIG_GET_INFO GetInfo; - EFI_NIC_IP4_CONFIG_SET_INFO SetInfo; -}; - -extern EFI_GUID gEfiNicIp4ConfigVariableGuid; -extern EFI_GUID gEfiNicIp4ConfigProtocolGuid; -#endif diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c index b69bd20..59da12c 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -15,11 +15,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include -#include +#include #include #include #include +#include + #include #include #include @@ -28,11 +30,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include +#include EFI_DPC_PROTOCOL *mDpc = NULL; GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mNetLibHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; +#define NIC_ITEM_CONFIG_SIZE sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2 + // // All the supported IP4 maskes in host byte order. // @@ -1248,43 +1254,98 @@ NetLibDefaultAddressIsStatic ( IN EFI_HANDLE Controller ) { - EFI_STATUS Status; - EFI_NIC_IP4_CONFIG_PROTOCOL *NicIp4; - UINTN Len; - NIC_IP4_CONFIG_INFO *ConfigInfo; - BOOLEAN IsStatic; - - Status = gBS->HandleProtocol ( - Controller, - &gEfiNicIp4ConfigProtocolGuid, - (VOID **) &NicIp4 - ); + EFI_STATUS Status; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + UINTN Len; + NIC_IP4_CONFIG_INFO *ConfigInfo; + BOOLEAN IsStatic; + EFI_STRING ConfigHdr; + EFI_STRING ConfigResp; + EFI_STRING AccessProgress; + EFI_STRING AccessResults; + EFI_STRING String; + + ConfigInfo = NULL; + ConfigHdr = NULL; + ConfigResp = NULL; + AccessProgress = NULL; + AccessResults = NULL; + IsStatic = TRUE; + + Status = gBS->LocateProtocol ( + &gEfiHiiConfigRoutingProtocolGuid, + NULL, + (VOID **) &HiiConfigRouting + ); if (EFI_ERROR (Status)) { return TRUE; } - Len = 0; - Status = NicIp4->GetInfo (NicIp4, &Len, NULL); - if (Status != EFI_BUFFER_TOO_SMALL) { - return TRUE; + // + // Construct config request string header + // + ConfigHdr = HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Controller); + + Len = StrLen (ConfigHdr); + ConfigResp = AllocateZeroPool (Len + NIC_ITEM_CONFIG_SIZE * 2 + 200); + if (ConfigResp == NULL) { + goto ON_EXIT; + } + StrCpy (ConfigResp, ConfigHdr); + + String = ConfigResp + Len; + UnicodeSPrint ( + String, + (8 + 4 + 7 + 4) * sizeof (CHAR16), + L"&OFFSET=%04X&WIDTH=%04X", + OFFSET_OF (NIC_IP4_CONFIG_INFO, Source), + sizeof (UINT32) + ); + + Status = HiiConfigRouting->ExtractConfig ( + HiiConfigRouting, + ConfigResp, + &AccessProgress, + &AccessResults + ); + if (EFI_ERROR (Status)) { + goto ON_EXIT; } - ConfigInfo = AllocatePool (Len); + ConfigInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO)); if (ConfigInfo == NULL) { - return TRUE; + goto ON_EXIT; } - IsStatic = TRUE; - Status = NicIp4->GetInfo (NicIp4, &Len, ConfigInfo); + ConfigInfo->Source = IP4_CONFIG_SOURCE_STATIC; + Len = NIC_ITEM_CONFIG_SIZE; + Status = HiiConfigRouting->ConfigToBlock ( + HiiConfigRouting, + AccessResults, + (UINT8 *) ConfigInfo, + &Len, + &AccessProgress + ); if (EFI_ERROR (Status)) { goto ON_EXIT; } IsStatic = (BOOLEAN) (ConfigInfo->Source == IP4_CONFIG_SOURCE_STATIC); - + ON_EXIT: - gBS->FreePool (ConfigInfo); + if (AccessResults != NULL) { + FreePool (AccessResults); + } + if (ConfigInfo != NULL) { + FreePool (ConfigInfo); + } + if (ConfigResp != NULL) { + FreePool (ConfigResp); + } + if (ConfigHdr != NULL) { + FreePool (ConfigHdr); + } return IsStatic; } diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf index 4ac01a7..2f2b2d0 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf @@ -1,7 +1,7 @@ /** @file Instance of DxeNetLib. -Copyright (c) 2006, Intel Corporation.
+Copyright (c) 2006 - 2009, 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 @@ -48,13 +48,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. UefiLib MemoryAllocationLib DevicePathLib - + HiiLib + PrintLib + +[Guids] + gEfiNicIp4ConfigVariableGuid + [Protocols] gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiNicIp4ConfigProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiDpcProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiComponentNameProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiComponentName2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiHiiConfigRoutingProtocolGuid # PROTOCOL ALWAYS_CONSUMED [Depex] gEfiDpcProtocolGuid diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 4b8b85b..d4905a8 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -121,6 +121,9 @@ ## Include/Guid/Crc32GuidedSectionExtraction.h gEfiCrc32GuidedSectionExtractionGuid = { 0xFC1BCDB0, 0x7D31, 0x49aa, {0x93, 0x6A, 0xA4, 0x60, 0x0D, 0x9D, 0xD0, 0x83 } } + ## Include/Guid/NicIp4ConfigNvData.h + gEfiNicIp4ConfigVariableGuid = {0xd8944553, 0xc4dd, 0x41f4, { 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b }} + [Protocols.common] ## Load File protocol provides capability to load and unload EFI image into memory and execute it. ## Include/Protocol/LoadPe32Image.h @@ -136,12 +139,6 @@ ## Include/Protocol/GenericMemoryTest.h gEfiGenericMemTestProtocolGuid = { 0x309DE7F1, 0x7F5E, 0x4ACE, { 0xB4, 0x9C, 0x53, 0x1B, 0xE5, 0xAA, 0x95, 0xEF }} - ## Include/Protocol/NicIp4Config.h - gEfiNicIp4ConfigProtocolGuid = {0xdca3d4d, 0x12da, 0x4728, { 0xbf, 0x7e, 0x86, 0xce, 0xb9, 0x28, 0xd0, 0x67 }} - - ## Include/Protocol/NicIp4Config.h - gEfiNicIp4ConfigVariableGuid = {0xd8944553, 0xc4dd, 0x41f4, { 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b }} - ## Include/Protocol/Dpc.h gEfiDpcProtocolGuid = {0x480f8ae9, 0xc46, 0x4aa9, { 0xbc, 0x89, 0xdb, 0x9f, 0xba, 0x61, 0x98, 0x6 }} diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c index 291ea1a..ed130d9 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 - 2008, Intel Corporation.
+Copyright (c) 2006 - 2009, 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
@@ -16,45 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE]; -/** - Return the name and MAC address for the NIC. The Name, if not NULL, - has at least IP4_NIC_NAME_LENGTH bytes. - - @param This The NIC IP4 CONFIG protocol - @param Name The buffer to return the name - @param NicAddr The buffer to return the MAC addr - - @retval EFI_INVALID_PARAMETER This is NULL - @retval EFI_SUCCESS The name or address of the NIC are returned. - -**/ -EFI_STATUS -EFIAPI -EfiNicIp4ConfigGetName ( - IN EFI_NIC_IP4_CONFIG_PROTOCOL *This, - OUT UINT16 *Name OPTIONAL, - OUT NIC_ADDR *NicAddr OPTIONAL - ) -{ - IP4_CONFIG_INSTANCE *Instance; - - if (This == NULL) { - return EFI_INVALID_PARAMETER; - } - - Instance = IP4_CONFIG_INSTANCE_FROM_NIC_IP4CONFIG (This); - - if (Name != NULL) { - CopyMem (Name, Instance->NicName, IP4_NIC_NAME_LENGTH); - } - - if (NicAddr != NULL) { - CopyMem (NicAddr, &Instance->NicAddr, sizeof (*NicAddr)); - } - - return EFI_SUCCESS; -} - /** Get the NIC's configure information from the IP4 configure variable. @@ -116,7 +77,7 @@ Ip4ConfigGetNicInfo ( /** Get the configure parameter for this NIC. - @param This The NIC IP4 CONFIG protocol. + @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. @@ -133,24 +94,22 @@ Ip4ConfigGetNicInfo ( EFI_STATUS EFIAPI EfiNicIp4ConfigGetInfo ( - IN EFI_NIC_IP4_CONFIG_PROTOCOL *This, + IN IP4_CONFIG_INSTANCE *Instance, IN OUT UINTN *ConfigLen, OUT NIC_IP4_CONFIG_INFO *NicConfig ) { - IP4_CONFIG_INSTANCE *Instance; NIC_IP4_CONFIG_INFO *Config; EFI_STATUS Status; UINTN Len; - if ((This == NULL) || (ConfigLen == NULL)) { + if ((Instance == NULL) || (ConfigLen == NULL)) { return EFI_INVALID_PARAMETER; } // // Read the Nic's configuration parameter from variable // - Instance = IP4_CONFIG_INSTANCE_FROM_NIC_IP4CONFIG (This); Config = Ip4ConfigGetNicInfo (&Instance->NicAddr); if (Config == NULL) { @@ -187,7 +146,7 @@ EfiNicIp4ConfigGetInfo ( the configure has finished or not started yet. If NicConfig, the NIC's configure parameter is removed from the variable. - @param This The NIC IP4 CONFIG protocol + @param Instance The IP4 CONFIG instance. @param NicConfig The new NIC IP4 configure parameter @param Reconfig Inform the IP4 driver to restart the auto configuration @@ -203,12 +162,11 @@ EfiNicIp4ConfigGetInfo ( EFI_STATUS EFIAPI EfiNicIp4ConfigSetInfo ( - IN EFI_NIC_IP4_CONFIG_PROTOCOL *This, + IN IP4_CONFIG_INSTANCE *Instance, IN NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL, IN BOOLEAN Reconfig ) { - IP4_CONFIG_INSTANCE *Instance; IP4_CONFIG_VARIABLE *Variable; IP4_CONFIG_VARIABLE *NewVariable; EFI_STATUS Status; @@ -216,12 +174,10 @@ EfiNicIp4ConfigSetInfo ( // // Validate the parameters // - if (This == NULL) { + if (Instance == NULL) { return EFI_INVALID_PARAMETER; } - Instance = IP4_CONFIG_INSTANCE_FROM_NIC_IP4CONFIG (This); - if ((NicConfig != NULL) && (!Ip4ConfigIsValid (NicConfig) || !NIC_ADDR_EQUAL (&NicConfig->NicAddr, &Instance->NicAddr))) { return EFI_INVALID_PARAMETER; @@ -372,7 +328,7 @@ Ip4ConfigOnDhcp4Complete ( // ignore the return status of EfiNicIp4ConfigSetInfo. Network // stack can operate even that failed. // - EfiNicIp4ConfigSetInfo (&Instance->NicIp4Protocol, Instance->NicConfig, FALSE); + EfiNicIp4ConfigSetInfo (Instance, Instance->NicConfig, FALSE); } ON_EXIT: @@ -802,8 +758,3 @@ EFI_IP4_CONFIG_PROTOCOL mIp4ConfigProtocolTemplate = { EfiIp4ConfigGetData }; -EFI_NIC_IP4_CONFIG_PROTOCOL mNicIp4ConfigProtocolTemplate = { - EfiNicIp4ConfigGetName, - EfiNicIp4ConfigGetInfo, - EfiNicIp4ConfigSetInfo -}; diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h index e18c22c..c685fc7 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h @@ -1,7 +1,7 @@ /** @file Header file for IP4Config driver. -Copyright (c) 2006 - 2008, Intel Corporation.
+Copyright (c) 2006 - 2009, 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
@@ -20,7 +20,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include +#include +#include +#include + +#include #include #include #include @@ -29,13 +35,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include +#include #include "NicIp4Variable.h" typedef struct _IP4_CONFIG_INSTANCE IP4_CONFIG_INSTANCE; // -// Global variables +// Global variables // extern EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding; extern EFI_COMPONENT_NAME_PROTOCOL gIp4ConfigComponentName; @@ -43,7 +51,6 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gIp4ConfigComponentName2; extern IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE]; extern EFI_IP4_CONFIG_PROTOCOL mIp4ConfigProtocolTemplate; -extern EFI_NIC_IP4_CONFIG_PROTOCOL mNicIp4ConfigProtocolTemplate; #define IP4_PROTO_ICMP 0x01 #define IP4_CONFIG_INSTANCE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'C') @@ -71,13 +78,53 @@ typedef struct { } IP4_CONFIG_DHCP4_OPTION; #pragma pack() + +typedef struct { + UINTN DeviceNum; + BOOLEAN Enabled; + EFI_IPv4_ADDRESS LocalIp; + EFI_IPv4_ADDRESS SubnetMask; + EFI_IPv4_ADDRESS Gateway; +} IP4_CONFIG_SESSION_DATA; + +typedef struct _IP4_CONFIG_FORM_ENTRY { + LIST_ENTRY Link; + IP4_CONFIG_INSTANCE *Ip4ConfigInstance; + EFI_HANDLE Controller; + CHAR16 MacString[95]; + EFI_STRING_ID PortTitleToken; + EFI_STRING_ID PortTitleHelpToken; + IP4_CONFIG_SESSION_DATA SessionConfigData; +} IP4CONFIG_FORM_ENTRY; + +#define IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'C') + +typedef struct _IP4_FORM_CALLBACK_INFO_INSTANCE { + UINTN Signature; + EFI_HANDLE DriverHandle; + EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess; + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + EFI_HII_CONFIG_ROUTING_PROTOCOL *ConfigRouting; + EFI_HII_HANDLE RegisteredHandle; + IP4CONFIG_FORM_ENTRY *Current; +} IP4_FORM_CALLBACK_INFO; + +#define IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK(Callback) \ + CR ( \ + Callback, \ + IP4_FORM_CALLBACK_INFO, \ + ConfigAccess, \ + IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE \ + ) + struct _IP4_CONFIG_INSTANCE { UINT32 Signature; EFI_HANDLE Controller; EFI_HANDLE Image; EFI_IP4_CONFIG_PROTOCOL Ip4ConfigProtocol; - EFI_NIC_IP4_CONFIG_PROTOCOL NicIp4Protocol; + + IP4_FORM_CALLBACK_INFO Ip4FormCallbackInfo; // // NicConfig's state, such as IP4_CONFIG_STATE_IDLE @@ -116,8 +163,65 @@ struct _IP4_CONFIG_INSTANCE { #define IP4_CONFIG_INSTANCE_FROM_IP4CONFIG(this) \ CR (this, IP4_CONFIG_INSTANCE, Ip4ConfigProtocol, IP4_CONFIG_INSTANCE_SIGNATURE) -#define IP4_CONFIG_INSTANCE_FROM_NIC_IP4CONFIG(this) \ - CR (this, IP4_CONFIG_INSTANCE, NicIp4Protocol, IP4_CONFIG_INSTANCE_SIGNATURE) +#define IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO(this) \ + CR (this, IP4_CONFIG_INSTANCE, Ip4FormCallbackInfo, IP4_CONFIG_INSTANCE_SIGNATURE) + + +/** + 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 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 Reconfig Inform the IP4 driver to restart the auto + 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 + +**/ +EFI_STATUS +EFIAPI +EfiNicIp4ConfigSetInfo ( + IN IP4_CONFIG_INSTANCE *Instance, + IN NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL, + IN BOOLEAN Reconfig + ); + +/** + 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 + ); /** Release all the DHCP related resources. @@ -144,7 +248,7 @@ VOID Ip4ConfigCleanConfig ( IN IP4_CONFIG_INSTANCE *Instance ); - + // // EFI Component Name Functions // @@ -168,7 +272,7 @@ Ip4ConfigCleanConfig ( languages specified in SupportedLanguages. The number of languages supported by a driver is up to the driver writer. Language is specified - in RFC 4646 or ISO 639-2 language code format. + in RFC 3066 or ISO 639-2 language code format. @param DriverName[out] A pointer to the Unicode string to return. This Unicode string is the name of the driver specified by This in the language @@ -225,14 +329,14 @@ Ip4ConfigComponentNameGetDriverName ( languages specified in SupportedLanguages. The number of languages supported by a driver is up to the driver writer. Language is specified in - RFC 4646 or ISO 639-2 language code format. + RFC 3066 or ISO 639-2 language code format. @param ControllerName[out] A pointer to the Unicode string to return. This Unicode string is the name of the controller specified by ControllerHandle and ChildHandle in the language specified by Language from the point of view of the driver specified by This. - + @retval EFI_SUCCESS The Unicode string for the user readable name in the language specified by Language for the driver specified by This was returned in @@ -258,7 +362,7 @@ Ip4ConfigComponentNameGetControllerName ( IN CHAR8 *Language, OUT CHAR16 **ControllerName ); - + /** Test to see if this driver supports ControllerHandle. @@ -279,7 +383,7 @@ Ip4ConfigDriverBindingSupported ( IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ); - + /** Start this driver on ControllerHandle. @@ -300,7 +404,7 @@ Ip4ConfigDriverBindingStart ( IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ); - + /** Stop this driver on ControllerHandle. @@ -322,5 +426,5 @@ Ip4ConfigDriverBindingStop ( IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ); - + #endif diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c index 7fcd6b8..ade299d 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c @@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "Ip4Config.h" +#include "Ip4ConfigNV.h" EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding = { Ip4ConfigDriverBindingSupported, @@ -41,6 +42,8 @@ EfiIp4ConfigUnload ( { UINT32 Index; + Ip4ConfigFormUnload (); + // // Stop all the IP4_CONFIG instances // @@ -78,6 +81,8 @@ Ip4ConfigDriverEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable ) { + Ip4ConfigFormInit (); + return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, @@ -219,7 +224,6 @@ Ip4ConfigDriverBindingStart ( Instance->Image = This->DriverBindingHandle; CopyMem (&Instance->Ip4ConfigProtocol, &mIp4ConfigProtocolTemplate, sizeof (mIp4ConfigProtocolTemplate)); - CopyMem (&Instance->NicIp4Protocol, &mNicIp4ConfigProtocolTemplate, sizeof (mNicIp4ConfigProtocolTemplate)); Instance->State = IP4_CONFIG_STATE_IDLE; Instance->Mnp = Mnp; @@ -242,7 +246,7 @@ Ip4ConfigDriverBindingStart ( Instance->NicAddr.Type = (UINT16) SnpMode.IfType; Instance->NicAddr.Len = (UINT8) SnpMode.HwAddressSize; - CopyMem (&Instance->NicAddr.MacAddr, &SnpMode.CurrentAddress, sizeof (Instance->NicAddr.MacAddr)); + CopyMem (&Instance->NicAddr.MacAddr, &SnpMode.CurrentAddress, Instance->NicAddr.Len); // // Add it to the global list, and compose the name @@ -275,6 +279,14 @@ Ip4ConfigDriverBindingStart ( goto ON_ERROR; } + Status = Ip4ConfigDeviceInit (Instance); + if (!EFI_ERROR (Status)) { + // + // Try to add a port configuration page for this controller. + // + Ip4ConfigUpdateForm (Instance, TRUE); + } + // // Install the IP4_CONFIG and NIC_IP4CONFIG protocols // @@ -282,8 +294,6 @@ Ip4ConfigDriverBindingStart ( &ControllerHandle, &gEfiIp4ConfigProtocolGuid, &Instance->Ip4ConfigProtocol, - &gEfiNicIp4ConfigProtocolGuid, - &Instance->NicIp4Protocol, NULL ); @@ -464,6 +474,8 @@ Ip4ConfigDriverBindingStop ( Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config); + Ip4ConfigDeviceUnload (Instance); + // // Unload the protocols first to inform the top drivers // @@ -471,8 +483,6 @@ Ip4ConfigDriverBindingStop ( NicHandle, &gEfiIp4ConfigProtocolGuid, &Instance->Ip4ConfigProtocol, - &gEfiNicIp4ConfigProtocolGuid, - &Instance->NicIp4Protocol, NULL ); diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf index e7e509a..8a3aed7 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf @@ -2,7 +2,7 @@ # Component name for module Ip4Config # # FIX ME! -# Copyright (c) 2006, Intel Corporation +# Copyright (c) 2006 - 2009, 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 @@ -40,6 +40,11 @@ Ip4Config.h NicIp4Variable.h Ip4Config.c + Ip4ConfigDxe.vfr + Ip4ConfigDxeStrings.uni + Ip4NvData.h + Ip4ConfigNv.h + Ip4ConfigNv.c [Packages] MdePkg/MdePkg.dec @@ -53,13 +58,20 @@ UefiRuntimeServicesTableLib DebugLib NetLib + HiiLib + PrintLib [Protocols] gEfiDhcp4ServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiManagedNetworkServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiIp4ConfigProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiIp4ConfigProtocolGuid # PROTOCOL ALWAYS_PRODUCED gEfiManagedNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiDhcp4ProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiNicIp4ConfigVariableGuid # PROTOCOL ALWAYS_CONSUMED - gEfiNicIp4ConfigProtocolGuid # PROTOCOL ALWAYS_CONSUMED \ No newline at end of file + gEfiHiiDatabaseProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiHiiConfigAccessProtocolGuid # PROTOCOL ALWAYS_CONSUMED + +[Guids] + gEfiIfrTianoGuid ## CONSUMES ## Guid + gEfiNicIp4ConfigVariableGuid ## CONSUMES ## Guid + \ No newline at end of file diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr new file mode 100644 index 0000000..eb5b408 --- /dev/null +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.vfr @@ -0,0 +1,92 @@ +/** @file + Vfr file for IP4 config. + +Copyright (c) 2009, 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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ +#include "Ip4NvData.h" + +#define EFI_NETWORK_DEVICE_CLASS 0x04 + +formset + guid = EFI_NIC_IP4_CONFIG_VARIABLE_GUID, + title = STRING_TOKEN(STR_IP4_CONFIG_FORM_TITLE), + help = STRING_TOKEN(STR_IP4_CONFIG_FORM_HELP), + class = EFI_NETWORK_DEVICE_CLASS, + subclass = 0x03, + + varstore IP4_CONFIG_IFR_NVDATA, + name = EfiNicIp4ConfigVariable, + guid = EFI_NIC_IP4_CONFIG_VARIABLE_GUID; + + form formid = FORMID_MAIN_FORM, + title = STRING_TOKEN(STR_IP4_MAIN_FORM_TITLE); + + label DEVICE_ENTRY_LABEL; + label LABEL_END; + + endform; + + form formid = FORMID_DEVICE_FORM, + title = STRING_TOKEN(STR_IP4_DEVICE_FORM_TITLE); + + checkbox varid = EfiNicIp4ConfigVariable.DhcpEnable, + prompt = STRING_TOKEN(STR_IP4_ENABLE_DHCP), + help = STRING_TOKEN(STR_IP4_ENABLE_DHCP), + flags = INTERACTIVE, + key = KEY_DHCP_ENABLE, + endcheckbox; + + suppressif ideqval EfiNicIp4ConfigVariable.DhcpEnable == 0x01; + string varid = EfiNicIp4ConfigVariable.StationAddress, + prompt = STRING_TOKEN(STR_IP4_LOCAL_IP_ADDRESS), + help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP), + flags = INTERACTIVE, + key = KEY_LOCAL_IP, + minsize = IP_MIN_SIZE, + maxsize = IP_MAX_SIZE, + endstring; + + string varid = EfiNicIp4ConfigVariable.SubnetMask, + prompt = STRING_TOKEN(STR_IP4_LOCAL_MASK), + help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP), + flags = INTERACTIVE, + key = KEY_SUBNET_MASK, + minsize = IP_MIN_SIZE, + maxsize = IP_MAX_SIZE, + endstring; + + string varid = EfiNicIp4ConfigVariable.GatewayAddress, + prompt = STRING_TOKEN(STR_IP4_LOCAL_GATEWAY), + help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP), + flags = INTERACTIVE, + key = KEY_GATE_WAY, + minsize = IP_MIN_SIZE, + maxsize = IP_MAX_SIZE, + endstring; + endif; + + subtitle text = STRING_TOKEN(STR_NULL); + + goto FORMID_DEVICE_FORM, + prompt = STRING_TOKEN (STR_SAVE_CHANGES), + help = STRING_TOKEN (STR_SAVE_CHANGES), + flags = INTERACTIVE, + key = KEY_SAVE_CHANGES; + + goto FORMID_MAIN_FORM, + prompt = STRING_TOKEN (STR_RETURN_MAIN_FORM), + help = STRING_TOKEN (STR_RETURN_MAIN_FORM), + flags = 0; + + endform; + +endformset; + diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxeStrings.uni b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxeStrings.uni new file mode 100644 index 0000000..8951913 Binary files /dev/null and b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxeStrings.uni differ diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c new file mode 100644 index 0000000..c25e682 --- /dev/null +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c @@ -0,0 +1,1139 @@ +/** @file + Helper functions for configuring or getting the parameters relating to Ip4. + +Copyright (c) 2009, 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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "Ip4ConfigNv.h" + +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Ip4HexString[] = "0123456789ABCDEFabcdef"; + +UINTN mNumberOfIp4Devices = 0; + +IP4_FORM_CALLBACK_INFO *mCallbackInfo = NULL; + +LIST_ENTRY mIp4ConfigFormList = { + &mIp4ConfigFormList, + &mIp4ConfigFormList +}; + +HII_VENDOR_DEVICE_PATH mIp4ConifgHiiVendorDevicePath = { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8) (sizeof (VENDOR_DEVICE_PATH)), + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + // + // {6D3FD906-42B9-4220-9E63-9D8C972D58EE} + // + { 0x6d3fd906, 0x42b9, 0x4220, { 0x9e, 0x63, 0x9d, 0x8c, 0x97, 0x2d, 0x58, 0xee } } + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8) (END_DEVICE_PATH_LENGTH), + (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + +/** + 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. + + @param[in] SubnetMask The IPv4 subnet mask. + + @return The prefix length of the subnet mask. + @retval 0 Other errors as indicated. +**/ +UINT8 +GetSubnetMaskPrefixLength ( + IN EFI_IPv4_ADDRESS *SubnetMask + ) +{ + UINT8 Len; + UINT32 ReverseMask; + + // + // The SubnetMask is in network byte order. + // + ReverseMask = (SubnetMask->Addr[0] << 24) | (SubnetMask->Addr[1] << 16) | (SubnetMask->Addr[2] << 8) | (SubnetMask->Addr[3]); + + // + // Reverse it. + // + ReverseMask = ~ReverseMask; + + if ((ReverseMask & (ReverseMask + 1)) != 0) { + return 0; + } + + Len = 0; + + while (ReverseMask != 0) { + ReverseMask = ReverseMask >> 1; + Len++; + } + + return (UINT8) (32 - Len); +} + +/** + 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. + + @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, + OUT EFI_IPv4_ADDRESS *Ip + ) +{ + UINTN Index; + UINTN Number; + + Index = 0; + + while (*Str != 0) { + + if (Index > 3) { + return EFI_INVALID_PARAMETER; + } + + Number = 0; + while (NET_IS_DIGIT (*Str)) { + Number = Number * 10 + (*Str - '0'); + Str++; + } + + if (Number > 0xFF) { + return EFI_INVALID_PARAMETER; + } + + Ip->Addr[Index] = (UINT8) Number; + + if ((*Str != '\0') && (*Str != '.')) { + // + // The current character should be either the NULL terminator or + // the dot delimiter. + // + return EFI_INVALID_PARAMETER; + } + + if (*Str == '.') { + // + // Skip the delimiter. + // + Str++; + } + + Index++; + } + + if (Index != 4) { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + Convert the IPv4 address into a dotted string. + + @param[in] Ip The IPv4 address. + @param[out] Str The dotted IP string. +**/ +VOID +Ip4ConfigIpToStr ( + IN EFI_IPv4_ADDRESS *Ip, + OUT CHAR16 *Str + ) +{ + UnicodeSPrint (Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]); +} + + +/** + Convert the network configuration data into the IFR data. + + @param[in] ConfigFormEntry The IP4 configuration form entry. + @param[out] IfrNvData The IFR nv data. +**/ +VOID +Ip4ConfigConvertDeviceConfigDataToIfrNvData ( + IN IP4_CONFIG_INSTANCE *Ip4ConfigInstance, + OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData + ) +{ + EFI_STATUS Status; + NIC_IP4_CONFIG_INFO *NicConfig; + UINTN ConfigLen; + + IfrFormNvData->DhcpEnable = 1; + + 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)) { + if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) { + IfrFormNvData->DhcpEnable = 1; + } else { + IfrFormNvData->DhcpEnable = 0; + Ip4ConfigIpToStr (&NicConfig->Ip4Info.StationAddress, IfrFormNvData->StationAddress); + Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask); + Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress); + } + } + FreePool (NicConfig); +} + +/** + Get the IP4 configuration form entry by the index of the goto opcode actived. + + @param[in] Index The 0-based index of the goto opcode actived. + + @return The IP4 configuration form entry found. +**/ +IP4CONFIG_FORM_ENTRY * +Ip4GetConfigFormEntryByIndex ( + IN UINT32 Index + ) +{ + UINT32 CurrentIndex; + LIST_ENTRY *Entry; + IP4CONFIG_FORM_ENTRY *ConfigFormEntry; + + CurrentIndex = 0; + ConfigFormEntry = NULL; + + NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) { + if (CurrentIndex == Index) { + ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link); + break; + } + + CurrentIndex++; + } + + return ConfigFormEntry; +} + +/** + This function allows the caller to request the current + configuration for one or more named elements. The resulting + string is in format. Any and all alternative + configuration strings shall also be appended to the end of the + current configuration string. If they are, they must appear + after the current configuration. They must contain the same + routing (GUID, NAME, PATH) as the current configuration string. + They must have an additional description indicating the type of + alternative configuration the string represents, + "ALTCFG=". That (when + converted from Hex UNICODE to binary) is a reference to a + string in the associated string pack. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Request A null-terminated Unicode string in + format. Note that this + includes the routing information as well as + the configurable name / value pairs. It is + invalid for this string to be in + format. + @param[out] Progress On return, points to a character in the + Request string. Points to the string's null + terminator if request was successful. Points + to the most recent "&" before the first + failing name / value pair (or the beginning + of the string if the failure is in the first + name / value pair) if the request was not + successful. + @param[out] Results A null-terminated Unicode string in + format which has all values + filled in for the names in the Request string. + String to be allocated by the called function. + + @retval EFI_SUCCESS The Results string is filled with the + values corresponding to all requested + names. + @retval EFI_OUT_OF_RESOURCES Not enough memory to store the + 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. + Note: There is no requirement that the + driver validate the routing data. It + must skip the in order to + process the names. + @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set + to most recent & before the + error or the beginning of the + string. + @retval EFI_INVALID_PARAMETER Unknown name. Progress points + to the & before the name in + question.Currently not implemented. +**/ +EFI_STATUS +EFIAPI +Ip4DeviceExtractConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Request, + OUT EFI_STRING *Progress, + OUT EFI_STRING *Results + ) +{ + EFI_STATUS Status; + UINTN ConfigLen; + NIC_IP4_CONFIG_INFO *IfrDeviceNvData; + IP4_FORM_CALLBACK_INFO *Private; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + IP4_CONFIG_INSTANCE *Ip4ConfigInstance; + + if (Request == NULL) { + return EFI_INVALID_PARAMETER; + } + + *Progress = Request; + + Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); + Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO (Private); + + IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); + if (IfrDeviceNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, IfrDeviceNvData); + if (EFI_ERROR (Status)) { + FreePool (IfrDeviceNvData); + return EFI_NOT_FOUND; + } + + // + // Convert buffer data to by helper function BlockToConfig() + // + HiiConfigRouting = Private->ConfigRouting; + Status = HiiConfigRouting->BlockToConfig ( + HiiConfigRouting, + Request, + (UINT8 *) IfrDeviceNvData, + NIC_ITEM_CONFIG_SIZE, + Results, + Progress + ); + + *Progress = Request + StrLen (Request); + FreePool (IfrDeviceNvData); + + return Status; +} + +/** + This function applies changes in a driver's configuration. + Input is a Configuration, which has the routing data for this + driver followed by name / value configuration pairs. The driver + must apply those pairs to its configurable storage. If the + driver's configuration is stored in a linear block of data + and the driver's name / value pairs are in + format, it may use the ConfigToBlock helper function (above) to + simplify the job. Currently not implemented. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Configuration A null-terminated Unicode string in + format. + @param[out] Progress A pointer to a string filled in with the + offset of the most recent '&' before the + first failing name / value pair (or the + beginn ing of the string if the failure + is in the first name / value pair) or + the terminating NULL if all was + successful. + + @retval EFI_SUCCESS The results have been distributed or are + awaiting distribution. + @retval EFI_OUT_OF_MEMORY Not enough memory to store the + parts of the results that must be + stored awaiting possible future + protocols. + @retval EFI_INVALID_PARAMETERS Passing in a NULL for the + Results parameter would result + in this type of error. + @retval EFI_NOT_FOUND Target for the specified routing data + was not found. +**/ +EFI_STATUS +EFIAPI +Ip4DeviceRouteConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Configuration, + OUT EFI_STRING *Progress + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + NIC_IP4_CONFIG_INFO *IfrDeviceNvData; + IP4_FORM_CALLBACK_INFO *Private; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + IP4_CONFIG_INSTANCE *Ip4ConfigInstance; + EFI_MAC_ADDRESS ZeroMac; + + if (Configuration == NULL) { + return EFI_INVALID_PARAMETER; + } + + *Progress = Configuration; + + Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); + Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO (Private); + + IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); + if (IfrDeviceNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Convert buffer data to by helper function BlockToConfig() + // + HiiConfigRouting = Private->ConfigRouting; + BufferSize = NIC_ITEM_CONFIG_SIZE; + Status = HiiConfigRouting->ConfigToBlock ( + HiiConfigRouting, + Configuration, + (UINT8 *) IfrDeviceNvData, + &BufferSize, + Progress + ); + if (!EFI_ERROR (Status)) { + ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS)); + if (CompareMem (&IfrDeviceNvData->NicAddr.MacAddr, &ZeroMac, IfrDeviceNvData->NicAddr.Len) != 0) { + Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, IfrDeviceNvData, TRUE); + } else { + Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE); + } + } + + *Progress = Configuration + StrLen (Configuration); + FreePool (IfrDeviceNvData); + return Status; + +} + +/** + This function allows the caller to request the current + configuration for one or more named elements. The resulting + string is in format. Any and all alternative + configuration strings shall also be appended to the end of the + current configuration string. If they are, they must appear + after the current configuration. They must contain the same + routing (GUID, NAME, PATH) as the current configuration string. + They must have an additional description indicating the type of + alternative configuration the string represents, + "ALTCFG=". That (when + converted from Hex UNICODE to binary) is a reference to a + string in the associated string pack. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Request A null-terminated Unicode string in + format. Note that this + includes the routing information as well as + the configurable name / value pairs. It is + invalid for this string to be in + format. + @param[out] Progress On return, points to a character in the + Request string. Points to the string's null + terminator if request was successful. Points + to the most recent "&" before the first + failing name / value pair (or the beginning + of the string if the failure is in the first + name / value pair) if the request was not + successful. + @param[out] Results A null-terminated Unicode string in + format which has all values + filled in for the names in the Request string. + String to be allocated by the called function. + + @retval EFI_SUCCESS The Results string is filled with the + values corresponding to all requested + names. + @retval EFI_OUT_OF_RESOURCES Not enough memory to store the + 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. + Note: There is no requirement that the + driver validate the routing data. It + must skip the in order to + process the names. + @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set + to most recent & before the + error or the beginning of the + string. + @retval EFI_INVALID_PARAMETER Unknown name. Progress points + to the & before the name in + question.Currently not implemented. +**/ +EFI_STATUS +EFIAPI +Ip4FormExtractConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Request, + OUT EFI_STRING *Progress, + OUT EFI_STRING *Results + ) +{ + return EFI_NOT_FOUND; +} + +/** + This function applies changes in a driver's configuration. + Input is a Configuration, which has the routing data for this + driver followed by name / value configuration pairs. The driver + must apply those pairs to its configurable storage. If the + driver's configuration is stored in a linear block of data + and the driver's name / value pairs are in + format, it may use the ConfigToBlock helper function (above) to + simplify the job. Currently not implemented. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Configuration A null-terminated Unicode string in + format. + @param[out] Progress A pointer to a string filled in with the + offset of the most recent '&' before the + first failing name / value pair (or the + beginn ing of the string if the failure + is in the first name / value pair) or + the terminating NULL if all was + successful. + + @retval EFI_SUCCESS The results have been distributed or are + awaiting distribution. + @retval EFI_OUT_OF_MEMORY Not enough memory to store the + parts of the results that must be + stored awaiting possible future + protocols. + @retval EFI_INVALID_PARAMETERS Passing in a NULL for the + Results parameter would result + in this type of error. + @retval EFI_NOT_FOUND Target for the specified routing data + was not found. +**/ +EFI_STATUS +EFIAPI +Ip4FormRouteConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Configuration, + OUT EFI_STRING *Progress + ) +{ + return EFI_NOT_FOUND; +} + +/** + This function is called to provide results data to the driver. + This data consists of a unique key that is used to identify + which data is either being passed back or being asked for. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Action Specifies the type of action taken by the browser. + @param[in] QuestionId A unique value which is sent to the original + exporting driver so that it can identify the type + of data to expect. The format of the data tends to + vary based on the opcode that enerated the callback. + @param[in] Type The type of value for the question. + @param[in] Value A pointer to the data being sent to the original + exporting driver. + @param[out] ActionRequest On return, points to the action requested by the + callback function. + + @retval EFI_SUCCESS The callback successfully handled the action. + @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the + variable and its data. + @retval EFI_DEVICE_ERROR The variable could not be saved. + @retval EFI_UNSUPPORTED The specified Action is not supported by the + callback.Currently not implemented. + @retval EFI_INVALID_PARAMETERS Passing in wrong parameter. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +EFIAPI +Ip4FormCallback ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN EFI_BROWSER_ACTION Action, + IN EFI_QUESTION_ID QuestionId, + IN UINT8 Type, + IN EFI_IFR_TYPE_VALUE *Value, + OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest + ) +{ + IP4_CONFIG_INSTANCE *Ip4ConfigInstance; + IP4_FORM_CALLBACK_INFO *Private; + CHAR8 Ip4String[IP4_STR_MAX_SIZE]; + CHAR16 PortString[128]; + EFI_STRING_ID DeviceFormTitleToken; + IP4_CONFIG_IFR_NVDATA *IfrFormNvData; + IP4CONFIG_FORM_ENTRY *ConfigFormEntry; + EFI_IP_ADDRESS HostIp; + EFI_IP_ADDRESS SubnetMask; + EFI_IP_ADDRESS Gateway; + EFI_STATUS Status; + EFI_INPUT_KEY Key; + NIC_IP4_CONFIG_INFO *NicInfo; + EFI_IP_ADDRESS Ip; + + ConfigFormEntry = NULL; + + Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); + + IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA)); + if (IfrFormNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Retrive uncommitted data from Browser + // + if (!HiiGetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData)) { + FreePool (IfrFormNvData); + return EFI_NOT_FOUND; + } + + Status = EFI_SUCCESS; + + switch (QuestionId) { + + case KEY_DHCP_ENABLE: + if (IfrFormNvData->DhcpEnable == 0) { + Private->Current->SessionConfigData.Enabled = FALSE; + } else { + Private->Current->SessionConfigData.Enabled = TRUE; + } + + break; + + case KEY_LOCAL_IP: + UnicodeStrToAsciiStr (IfrFormNvData->StationAddress, Ip4String); + Status = Ip4AsciiStrToIp (Ip4String, &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; + } else { + CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4)); + } + + break; + + case KEY_SUBNET_MASK: + UnicodeStrToAsciiStr (IfrFormNvData->SubnetMask, Ip4String); + Status = Ip4AsciiStrToIp (Ip4String, &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); + Status = EFI_INVALID_PARAMETER; + } else { + CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4)); + } + + break; + + case KEY_GATE_WAY: + UnicodeStrToAsciiStr (IfrFormNvData->GatewayAddress, Ip4String); + Status = Ip4AsciiStrToIp (Ip4String, &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; + } else { + CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4)); + } + + break; + + case KEY_SAVE_CHANGES: + Ip4ConfigInstance = Private->Current->Ip4ConfigInstance; + NicInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE)); + NicInfo->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (NicInfo + 1); + + if (!Private->Current->SessionConfigData.Enabled) { + CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalIp, sizeof (HostIp.v4)); + CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4)); + CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gateway, sizeof (Gateway.v4)); + + if ((Gateway.Addr[0] != 0)) { + if (SubnetMask.Addr[0] == 0) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL); + Status = EFI_INVALID_PARAMETER; + break; + } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL); + Status = EFI_INVALID_PARAMETER; + break; + } + } + + NicInfo->Source = IP4_CONFIG_SOURCE_STATIC; + NicInfo->Ip4Info.RouteTableSize = 2; + + CopyMem (&NicInfo->Ip4Info.StationAddress, &HostIp.v4, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&NicInfo->Ip4Info.SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS)); + + Ip.Addr[0] = HostIp.Addr[0] & SubnetMask.Addr[0]; + + CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&NicInfo->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS)); + } else { + NicInfo->Source = IP4_CONFIG_SOURCE_DHCP; + } + + NicInfo->Perment = TRUE; + CopyMem (&NicInfo->NicAddr, &Ip4ConfigInstance->NicAddr, sizeof (NIC_ADDR)); + + EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE); + + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; + break; + + default: + if ((QuestionId >= KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberOfIp4Devices + KEY_DEVICE_ENTRY_BASE))) { + // + // In case goto the device configuration form, update the device form title. + // + ConfigFormEntry = Ip4GetConfigFormEntryByIndex ((UINT32) (QuestionId - KEY_DEVICE_ENTRY_BASE)); + ASSERT (ConfigFormEntry != NULL); + + Ip4ConfigInstance = ConfigFormEntry->Ip4ConfigInstance; + + UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString); + DeviceFormTitleToken = (EFI_STRING_ID) STR_IP4_DEVICE_FORM_TITLE; + HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL); + + Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData); + + Private->Current = ConfigFormEntry; + } + + 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; +} + +/** + Install HII Config Access protocol for network device and allocate resource. + + @param[in] Instance The IP4 Config instance. + + @retval EFI_SUCCESS The HII Config Access protocol is installed. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +Ip4ConfigDeviceInit ( + IN IP4_CONFIG_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + IP4_FORM_CALLBACK_INFO *CallbackInfo; + + Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase); + if (EFI_ERROR (Status)) { + return Status; + } + + CallbackInfo = &Instance->Ip4FormCallbackInfo; + + CallbackInfo->Signature = IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE; + CallbackInfo->HiiDatabase = HiiDatabase; + + CallbackInfo->ConfigAccess.ExtractConfig = Ip4DeviceExtractConfig; + CallbackInfo->ConfigAccess.RouteConfig = Ip4DeviceRouteConfig; + CallbackInfo->ConfigAccess.Callback = NULL; + + Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting); + if (EFI_ERROR (Status)) { + return Status; + } + + CallbackInfo->DriverHandle = Instance->Controller; + // + // Install Device Path Protocol and Config Access protocol to driver handle + // + Status = gBS->InstallMultipleProtocolInterfaces ( + &CallbackInfo->DriverHandle, + &gEfiHiiConfigAccessProtocolGuid, + &CallbackInfo->ConfigAccess, + NULL + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Uninstall HII Config Access protocol for network device and free resource. + + @param[in] Instance The IP4 Config instance. + + @retval EFI_SUCCESS The HII Config Access protocol is uninstalled. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +Ip4ConfigDeviceUnload ( + IN IP4_CONFIG_INSTANCE *Instance + ) +{ + IP4_FORM_CALLBACK_INFO *CallbackInfo; + + CallbackInfo = &Instance->Ip4FormCallbackInfo; + + Ip4ConfigUpdateForm (Instance, FALSE); + + // + // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL + // + gBS->UninstallMultipleProtocolInterfaces ( + CallbackInfo->DriverHandle, + &gEfiHiiConfigAccessProtocolGuid, + &CallbackInfo->ConfigAccess, + NULL + ); + + return EFI_SUCCESS; +} + +/** + Unload the network configuration form, this includes: delete all the network + device configuration entries, uninstall the form callback protocol and + free the resources used. + + @retval EFI_SUCCESS The network configuration form is unloaded. +**/ +EFI_STATUS +Ip4ConfigFormUnload ( + VOID + ) +{ + IP4CONFIG_FORM_ENTRY *ConfigFormEntry; + + while (!IsListEmpty (&mIp4ConfigFormList)) { + // + // Uninstall the device forms as the network driver instance may fail to + // control the controller but still install the device configuration form. + // In such case, upon driver unloading, the driver instance's driverbinding. + // stop () won't be called, so we have to take this chance here to uninstall + // the device form. + // + ConfigFormEntry = NET_LIST_USER_STRUCT (mIp4ConfigFormList.ForwardLink, IP4CONFIG_FORM_ENTRY, Link); + Ip4ConfigUpdateForm (ConfigFormEntry->Ip4ConfigInstance, FALSE); + } + + // + // Remove HII package list + // + mCallbackInfo->HiiDatabase->RemovePackageList ( + mCallbackInfo->HiiDatabase, + mCallbackInfo->RegisteredHandle + ); + + // + // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL + // + gBS->UninstallMultipleProtocolInterfaces ( + mCallbackInfo->DriverHandle, + &gEfiDevicePathProtocolGuid, + &mIp4ConifgHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &mCallbackInfo->ConfigAccess, + NULL + ); + + FreePool (mCallbackInfo); + + return EFI_SUCCESS; +} + +/** + Updates the network configuration form to add/delete an entry for the network + device specified by the Instance. + + @param[in] Instance The IP4 Config instance. + @param[in] AddForm Whether to add or delete a form entry. + + @retval EFI_SUCCESS The network configuration form is updated. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +Ip4ConfigUpdateForm ( + IN IP4_CONFIG_INSTANCE *Instance, + IN BOOLEAN AddForm + ) +{ + LIST_ENTRY *Entry; + IP4CONFIG_FORM_ENTRY *ConfigFormEntry; + BOOLEAN EntryExisted; + EFI_STATUS Status; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + CHAR16 PortString[128]; + UINT16 FormIndex; + VOID *StartOpCodeHandle; + VOID *EndOpCodeHandle; + EFI_IFR_GUID_LABEL *StartLabel; + EFI_IFR_GUID_LABEL *EndLabel; + + ConfigFormEntry = NULL; + EntryExisted = FALSE; + + NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) { + ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link); + + if (ConfigFormEntry->Controller == Instance->Controller) { + EntryExisted = TRUE; + break; + } + } + + if (AddForm) { + if (EntryExisted) { + return EFI_SUCCESS; + } else { + // + // Add a new form. + // + ConfigFormEntry = (IP4CONFIG_FORM_ENTRY *) AllocateZeroPool (sizeof (IP4CONFIG_FORM_ENTRY)); + if (ConfigFormEntry == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ConfigFormEntry->Ip4ConfigInstance = Instance; + InitializeListHead (&ConfigFormEntry->Link); + ConfigFormEntry->Controller = Instance->Controller; + + // + // Get the simple network protocol and convert the MAC address into + // the formatted string. + // + Status = gBS->HandleProtocol ( + Instance->Controller, + &gEfiSimpleNetworkProtocolGuid, + (VOID **)&Snp + ); + ASSERT (Status == EFI_SUCCESS); + + Ip4MacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString); + + // + // Compose the Port string and create a new EFI_STRING_ID. + // + UnicodeSPrint (PortString, 128, L"%s %s", Instance->NicName, ConfigFormEntry->MacString); + ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); + + // + // Compose the help string of this port and create a new EFI_STRING_ID. + // + UnicodeSPrint (PortString, 128, L"Set the network parameters on eth%d %s", 0, ConfigFormEntry->MacString); + ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); + + InsertTailList (&mIp4ConfigFormList, &ConfigFormEntry->Link); + mNumberOfIp4Devices++; + } + } else { + ASSERT (EntryExisted); + + mNumberOfIp4Devices--; + RemoveEntryList (&ConfigFormEntry->Link); + gBS->FreePool (ConfigFormEntry); + } + + // + // Init OpCode Handle + // + StartOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle != NULL); + + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number = DEVICE_ENTRY_LABEL; + + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = LABEL_END; + + FormIndex = 0; + + FormIndex = 0; + NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) { + ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link); + + HiiCreateGotoOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + FORMID_DEVICE_FORM, // Target Form ID + ConfigFormEntry->PortTitleToken, // Prompt text + ConfigFormEntry->PortTitleHelpToken, // Help text + EFI_IFR_FLAG_CALLBACK, // Question flag + (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex) // Question ID + ); + + FormIndex++; + } + + HiiUpdateForm ( + mCallbackInfo->RegisteredHandle, + &gEfiNicIp4ConfigVariableGuid, + FORMID_MAIN_FORM, + StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL + EndOpCodeHandle // LABEL_END + ); + + HiiFreeOpCodeHandle (StartOpCodeHandle); + HiiFreeOpCodeHandle (EndOpCodeHandle); + + return EFI_SUCCESS; +} + +/** + Initialize the network configuration form, this includes: delete all the network + device configuration entries, install the form callback protocol and + allocate the resources used. + + @retval EFI_SUCCESS The network configuration form is unloaded. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +Ip4ConfigFormInit ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + IP4_FORM_CALLBACK_INFO *CallbackInfo; + + Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase); + if (EFI_ERROR (Status)) { + return Status; + } + + CallbackInfo = (IP4_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (IP4_FORM_CALLBACK_INFO)); + if (CallbackInfo == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CallbackInfo->Signature = IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE; + CallbackInfo->HiiDatabase = HiiDatabase; + + CallbackInfo->ConfigAccess.ExtractConfig = Ip4FormExtractConfig; + CallbackInfo->ConfigAccess.RouteConfig = Ip4FormRouteConfig; + CallbackInfo->ConfigAccess.Callback = Ip4FormCallback; + + Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting); + if (EFI_ERROR (Status)) { + return Status; + } + + CallbackInfo->DriverHandle = NULL; + // + // Install Device Path Protocol and Config Access protocol to driver handle + // + Status = gBS->InstallMultipleProtocolInterfaces ( + &CallbackInfo->DriverHandle, + &gEfiDevicePathProtocolGuid, + &mIp4ConifgHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &CallbackInfo->ConfigAccess, + NULL + ); + ASSERT_EFI_ERROR (Status); + + // + // Publish our HII data + // + CallbackInfo->RegisteredHandle = HiiAddPackages ( + &gEfiNicIp4ConfigVariableGuid, + CallbackInfo->DriverHandle, + Ip4ConfigDxeStrings, + Ip4ConfigDxeBin, + NULL + ); + if (CallbackInfo->RegisteredHandle == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mCallbackInfo = CallbackInfo; + + return Status; +} diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h new file mode 100644 index 0000000..2eb8b91 --- /dev/null +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.h @@ -0,0 +1,104 @@ +/** @file + The header file of IP4ConfigNV.c + +Copyright (c) 2009, 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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _IP4_CONFIGNV_H_ +#define _IP4_CONFIGNV_H_ + +#include "Ip4Config.h" +#include "Ip4NVData.h" + +extern UINT8 Ip4ConfigDxeBin[]; +extern UINT8 Ip4ConfigDxeStrings[]; + +#define NIC_ITEM_CONFIG_SIZE sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2 + + +/// +/// HII specific Vendor Device Path definition. +/// +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; + +/** + Updates the network configuration form to add/delete an entry for the network + device specified by the Instance. + + @param[in] Instance The IP4 Config instance. + @param[in] AddForm Whether to add or delete a form entry. + + @retval EFI_SUCCESS The network configuration form is updated. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +Ip4ConfigUpdateForm ( + IN IP4_CONFIG_INSTANCE *Instance, + IN BOOLEAN AddForm + ); + +/** + Install HII Config Access protocol for network device and allocate resource. + + @param[in] Instance The IP4 Config instance. + + @retval EFI_SUCCESS The HII Config Access protocol is installed. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +Ip4ConfigDeviceInit ( + IN IP4_CONFIG_INSTANCE *Instance + ); + +/** + Uninstall HII Config Access protocol for network device and free resource. + + @param[in] Instance The IP4 Config instance. + + @retval EFI_SUCCESS The HII Config Access protocol is uninstalled. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +Ip4ConfigDeviceUnload ( + IN IP4_CONFIG_INSTANCE *Instance + ); + +/** + Initialize the network configuration form, this includes: delete all the network + device configuration entries, install the form callback protocol and + allocate the resources used. + + @retval EFI_SUCCESS The network configuration form is unloaded. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +Ip4ConfigFormInit ( + VOID + ); + +/** + Unload the network configuration form, this includes: delete all the network + device configuration entries, uninstall the form callback protocol and + free the resources used. + + @retval EFI_SUCCESS The network configuration form is unloaded. +**/ +EFI_STATUS +Ip4ConfigFormUnload ( + VOID + ); + +#endif diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h new file mode 100644 index 0000000..ac2b3dc --- /dev/null +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4NvData.h @@ -0,0 +1,59 @@ +/** @file + Routines used to operate the Ip4 configure variable. + +Copyright (c) 2009, 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
+http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _NIC_IP4_NV_DATA_H_ +#define _NIC_IP4_NV_DATA_H_ + + +// +// one copy from NicIp4ConfigNvData.h +// +#define EFI_NIC_IP4_CONFIG_VARIABLE_GUID \ + { \ + 0xd8944553, 0xc4dd, 0x41f4, { 0x9b, 0x30, 0xe1, 0x39, 0x7c, 0xfb, 0x26, 0x7b } \ + } + +#define FORMID_MAIN_FORM 1 +#define FORMID_DEVICE_FORM 2 + +#define KEY_DHCP_ENABLE 0x101 +#define KEY_LOCAL_IP 0x102 +#define KEY_SUBNET_MASK 0x103 +#define KEY_GATE_WAY 0x104 +#define KEY_SAVE_CHANGES 0x105 + +#define DEVICE_ENTRY_LABEL 0x1234 +#define LABEL_END 0xffff + +#define KEY_DEVICE_ENTRY_BASE 0x1000 + +#define IP_MIN_SIZE 7 +#define IP_MAX_SIZE 15 +#define IP4_STR_MAX_SIZE 16 + +/// +/// NIC_IP4_CONFIG_INFO contains the IP4 configure +/// parameters for that NIC. NIC_IP4_CONFIG_INFO is +/// of variable length. +/// +typedef struct { + UINT16 NicAddr[3]; ///< NIC MAC address + UINT8 Reserved; ///< Reserved bits + UINT8 DhcpEnable; ///< Static or DHCP + CHAR16 StationAddress[IP4_STR_MAX_SIZE]; ///< IP addresses + CHAR16 SubnetMask[IP4_STR_MAX_SIZE]; ///< Subnet address + CHAR16 GatewayAddress[IP4_STR_MAX_SIZE]; ///< Gateway address +} IP4_CONFIG_IFR_NVDATA; + +#endif diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/NicIp4Variable.h index 11ba50c..6a4e941 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 - 2008, Intel Corporation.
+Copyright (c) 2006 - 2009, 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
@@ -17,6 +17,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include +#include + #include #include #include @@ -24,8 +26,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #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. @@ -143,3 +154,4 @@ Ip4ConfigFixRouteTablePointer ( ); #endif + -- cgit v1.1