+++ /dev/null
-/** @file\r
- Helper functions for configuring or getting the parameters relating to Ip4.\r
-\r
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-#include "Ip4Impl.h"\r
-\r
-CHAR16 mIp4Config2StorageName[] = L"IP4_CONFIG2_IFR_NVDATA";\r
-\r
-/**\r
- Calculate the prefix length of the IPv4 subnet mask.\r
-\r
- @param[in] SubnetMask The IPv4 subnet mask.\r
-\r
- @return The prefix length of the subnet mask.\r
- @retval 0 Other errors as indicated.\r
-\r
-**/\r
-UINT8\r
-GetSubnetMaskPrefixLength (\r
- IN EFI_IPv4_ADDRESS *SubnetMask\r
- )\r
-{\r
- UINT8 Len;\r
- UINT32 ReverseMask;\r
-\r
- //\r
- // The SubnetMask is in network byte order.\r
- //\r
- ReverseMask = SwapBytes32 (*(UINT32 *)&SubnetMask[0]);\r
-\r
- //\r
- // Reverse it.\r
- //\r
- ReverseMask = ~ReverseMask;\r
-\r
- if ((ReverseMask & (ReverseMask + 1)) != 0) {\r
- return 0;\r
- }\r
-\r
- Len = 0;\r
-\r
- while (ReverseMask != 0) {\r
- ReverseMask = ReverseMask >> 1;\r
- Len++;\r
- }\r
-\r
- return (UINT8) (32 - Len);\r
-}\r
-\r
-/**\r
- Convert the decimal dotted IPv4 address into the binary IPv4 address.\r
-\r
- @param[in] Str The UNICODE string.\r
- @param[out] Ip The storage to return the IPv4 address.\r
-\r
- @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
- @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4Config2StrToIp (\r
- IN CHAR16 *Str,\r
- OUT EFI_IPv4_ADDRESS *Ip\r
- )\r
-{\r
- UINTN Index;\r
- UINTN Number;\r
-\r
- Index = 0;\r
-\r
- while (*Str != L'\0') {\r
-\r
- if (Index > 3) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Number = 0;\r
- while ((*Str >= L'0') && (*Str <= L'9')) {\r
- Number = Number * 10 + (*Str - L'0');\r
- Str++;\r
- }\r
-\r
- if (Number > 0xFF) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Ip->Addr[Index] = (UINT8) Number;\r
-\r
- if ((*Str != L'\0') && (*Str != L'.')) {\r
- //\r
- // The current character should be either the NULL terminator or\r
- // the dot delimiter.\r
- //\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (*Str == L'.') {\r
- //\r
- // Skip the delimiter.\r
- //\r
- Str++;\r
- }\r
-\r
- Index++;\r
- }\r
-\r
- if (Index != 4) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Convert the decimal dotted IPv4 addresses separated by space into the binary IPv4 address list.\r
-\r
- @param[in] Str The UNICODE string contains IPv4 addresses.\r
- @param[out] PtrIpList The storage to return the IPv4 address list.\r
- @param[out] IpCount The size of the IPv4 address list.\r
-\r
- @retval EFI_SUCCESS The binary IP address list is returned in PtrIpList.\r
- @retval EFI_OUT_OF_RESOURCES Error occurs in allocating memory.\r
- @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4Config2StrToIpList (\r
- IN CHAR16 *Str,\r
- OUT EFI_IPv4_ADDRESS **PtrIpList,\r
- OUT UINTN *IpCount\r
- )\r
-{\r
- UINTN BeginIndex;\r
- UINTN EndIndex;\r
- UINTN Index;\r
- UINTN IpIndex;\r
- CHAR16 *StrTemp;\r
- BOOLEAN SpaceTag;\r
-\r
- BeginIndex = 0;\r
- EndIndex = BeginIndex;\r
- Index = 0;\r
- IpIndex = 0;\r
- StrTemp = NULL;\r
- SpaceTag = TRUE;\r
-\r
- *PtrIpList = NULL;\r
- *IpCount = 0;\r
-\r
- if (Str == NULL) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- //\r
- // Get the number of Ip.\r
- //\r
- while (*(Str + Index) != L'\0') {\r
- if (*(Str + Index) == L' ') {\r
- SpaceTag = TRUE;\r
- } else {\r
- if (SpaceTag) {\r
- (*IpCount)++;\r
- SpaceTag = FALSE;\r
- }\r
- }\r
-\r
- Index++;\r
- }\r
-\r
- if (*IpCount == 0) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- //\r
- // Allocate buffer for IpList.\r
- //\r
- *PtrIpList = AllocateZeroPool(*IpCount * sizeof(EFI_IPv4_ADDRESS));\r
- if (*PtrIpList == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Get IpList from Str.\r
- //\r
- Index = 0;\r
- while (*(Str + Index) != L'\0') {\r
- if (*(Str + Index) == L' ') {\r
- if(!SpaceTag) {\r
- StrTemp = AllocateZeroPool((EndIndex - BeginIndex + 1) * sizeof(CHAR16));\r
- if (StrTemp == NULL) {\r
- FreePool(*PtrIpList);\r
- *PtrIpList = NULL;\r
- *IpCount = 0;\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- CopyMem (StrTemp, Str + BeginIndex, (EndIndex - BeginIndex) * sizeof(CHAR16));\r
- *(StrTemp + (EndIndex - BeginIndex)) = L'\0';\r
-\r
- if (Ip4Config2StrToIp (StrTemp, &((*PtrIpList)[IpIndex])) != EFI_SUCCESS) {\r
- FreePool(StrTemp);\r
- FreePool(*PtrIpList);\r
- *PtrIpList = NULL;\r
- *IpCount = 0;\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- BeginIndex = EndIndex;\r
- IpIndex++;\r
-\r
- FreePool(StrTemp);\r
- }\r
-\r
- BeginIndex++;\r
- EndIndex++;\r
- SpaceTag = TRUE;\r
- } else {\r
- EndIndex++;\r
- SpaceTag = FALSE;\r
- }\r
-\r
- Index++;\r
-\r
- if (*(Str + Index) == L'\0') {\r
- if (!SpaceTag) {\r
- StrTemp = AllocateZeroPool((EndIndex - BeginIndex + 1) * sizeof(CHAR16));\r
- if (StrTemp == NULL) {\r
- FreePool(*PtrIpList);\r
- *PtrIpList = NULL;\r
- *IpCount = 0;\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- CopyMem (StrTemp, Str + BeginIndex, (EndIndex - BeginIndex) * sizeof(CHAR16));\r
- *(StrTemp + (EndIndex - BeginIndex)) = L'\0';\r
-\r
- if (Ip4Config2StrToIp (StrTemp, &((*PtrIpList)[IpIndex])) != EFI_SUCCESS) {\r
- FreePool(StrTemp);\r
- FreePool(*PtrIpList);\r
- *PtrIpList = NULL;\r
- *IpCount = 0;\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- FreePool(StrTemp);\r
- }\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Convert the IPv4 address into a dotted string.\r
-\r
- @param[in] Ip The IPv4 address.\r
- @param[out] Str The dotted IP string.\r
-\r
-**/\r
-VOID\r
-Ip4Config2IpToStr (\r
- IN EFI_IPv4_ADDRESS *Ip,\r
- OUT CHAR16 *Str\r
- )\r
-{\r
- UnicodeSPrint (\r
- Str,\r
- 2 * IP4_STR_MAX_SIZE,\r
- L"%d.%d.%d.%d",\r
- Ip->Addr[0],\r
- Ip->Addr[1],\r
- Ip->Addr[2],\r
- Ip->Addr[3]\r
- );\r
-}\r
-\r
-\r
-/**\r
- Convert the IPv4 address list into string consists of several decimal\r
- dotted IPv4 addresses separated by space.\r
-\r
- @param[in] Ip The IPv4 address list.\r
- @param[in] IpCount The size of IPv4 address list.\r
- @param[out] Str The string contains several decimal dotted\r
- IPv4 addresses separated by space.\r
-\r
- @retval EFI_SUCCESS Operation is success.\r
- @retval EFI_OUT_OF_RESOURCES Error occurs in allocating memory.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4Config2IpListToStr (\r
- IN EFI_IPv4_ADDRESS *Ip,\r
- IN UINTN IpCount,\r
- OUT CHAR16 *Str\r
- )\r
-{\r
- UINTN Index;\r
- UINTN TemIndex;\r
- UINTN StrIndex;\r
- CHAR16 *TempStr;\r
- EFI_IPv4_ADDRESS *TempIp;\r
-\r
- Index = 0;\r
- TemIndex = 0;\r
- StrIndex = 0;\r
- TempStr = NULL;\r
- TempIp = NULL;\r
-\r
- for (Index = 0; Index < IpCount; Index ++) {\r
- TempIp = Ip + Index;\r
- if (TempStr == NULL) {\r
- TempStr = AllocateZeroPool(2 * IP4_STR_MAX_SIZE);\r
- if (TempStr == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- }\r
-\r
- UnicodeSPrint (\r
- TempStr,\r
- 2 * IP4_STR_MAX_SIZE,\r
- L"%d.%d.%d.%d",\r
- TempIp->Addr[0],\r
- TempIp->Addr[1],\r
- TempIp->Addr[2],\r
- TempIp->Addr[3]\r
- );\r
-\r
- for (TemIndex = 0; TemIndex < IP4_STR_MAX_SIZE; TemIndex ++) {\r
- if (*(TempStr + TemIndex) == L'\0') {\r
- if (Index == IpCount - 1) {\r
- Str[StrIndex++] = L'\0';\r
- } else {\r
- Str[StrIndex++] = L' ';\r
- }\r
- break;\r
- } else {\r
- Str[StrIndex++] = *(TempStr + TemIndex);\r
- }\r
- }\r
- }\r
-\r
- if (TempStr != NULL) {\r
- FreePool(TempStr);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- The notify function of create event when performing a manual configuration.\r
-\r
- @param[in] Event The pointer of Event.\r
- @param[in] Context The pointer of Context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-Ip4Config2ManualAddressNotify (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- *((BOOLEAN *) Context) = TRUE;\r
-}\r
-\r
-/**\r
- Convert the network configuration data into the IFR data.\r
-\r
- @param[in] Instance The IP4 config2 instance.\r
- @param[in, out] IfrNvData The IFR nv data.\r
-\r
- @retval EFI_SUCCESS The configure parameter to IFR data was\r
- set successfully.\r
- @retval EFI_INVALID_PARAMETER Source instance or target IFR data is not available.\r
- @retval Others Other errors as indicated.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4Config2ConvertConfigNvDataToIfrNvData (\r
- IN IP4_CONFIG2_INSTANCE *Instance,\r
- IN OUT IP4_CONFIG2_IFR_NVDATA *IfrNvData\r
- )\r
-{\r
- IP4_SERVICE *IpSb;\r
- EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;\r
- EFI_IP4_CONFIG2_INTERFACE_INFO *Ip4Info;\r
- EFI_IP4_CONFIG2_POLICY Policy;\r
- UINTN DataSize;\r
- UINTN GatewaySize;\r
- EFI_IPv4_ADDRESS GatewayAddress;\r
- EFI_STATUS Status;\r
- UINTN DnsSize;\r
- UINTN DnsCount;\r
- EFI_IPv4_ADDRESS *DnsAddress;\r
-\r
- Status = EFI_SUCCESS;\r
- Ip4Config2 = &Instance->Ip4Config2;\r
- Ip4Info = NULL;\r
- DnsAddress = NULL;\r
- GatewaySize = sizeof (EFI_IPv4_ADDRESS);\r
-\r
- if ((IfrNvData == NULL) || (Instance == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- NET_CHECK_SIGNATURE (Instance, IP4_CONFIG2_INSTANCE_SIGNATURE);\r
-\r
- IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r
-\r
- if (IpSb->DefaultInterface->Configured) {\r
- IfrNvData->Configure = 1;\r
- } else {\r
- IfrNvData->Configure = 0;\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Get the Policy info.\r
- //\r
- DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypePolicy,\r
- &DataSize,\r
- &Policy\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- if (Policy == Ip4Config2PolicyStatic) {\r
- IfrNvData->DhcpEnable = FALSE;\r
- } else if (Policy == Ip4Config2PolicyDhcp) {\r
- IfrNvData->DhcpEnable = TRUE;\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Get the interface info.\r
- //\r
- DataSize = 0;\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypeInterfaceInfo,\r
- &DataSize,\r
- NULL\r
- );\r
- if (Status != EFI_BUFFER_TOO_SMALL) {\r
- return Status;\r
- }\r
-\r
- Ip4Info = AllocateZeroPool (DataSize);\r
- if (Ip4Info == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- return Status;\r
- }\r
-\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypeInterfaceInfo,\r
- &DataSize,\r
- Ip4Info\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Get the Gateway info.\r
- //\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypeGateway,\r
- &GatewaySize,\r
- &GatewayAddress\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Get the Dns info.\r
- //\r
- DnsSize = 0;\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypeDnsServer,\r
- &DnsSize,\r
- NULL\r
- );\r
- if ((Status != EFI_BUFFER_TOO_SMALL) && (Status != EFI_NOT_FOUND)) {\r
- goto Exit;\r
- }\r
-\r
- DnsCount = (UINT32) (DnsSize / sizeof (EFI_IPv4_ADDRESS));\r
-\r
- if (DnsSize > 0) {\r
- DnsAddress = AllocateZeroPool(DnsSize);\r
- if (DnsAddress == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Exit;\r
- }\r
-\r
- Status = Ip4Config2->GetData (\r
- Ip4Config2,\r
- Ip4Config2DataTypeDnsServer,\r
- &DnsSize,\r
- DnsAddress\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
- }\r
-\r
- Ip4Config2IpToStr (&Ip4Info->StationAddress, IfrNvData->StationAddress);\r
- Ip4Config2IpToStr (&Ip4Info->SubnetMask, IfrNvData->SubnetMask);\r
- Ip4Config2IpToStr (&GatewayAddress, IfrNvData->GatewayAddress);\r
- Status = Ip4Config2IpListToStr (DnsAddress, DnsCount, IfrNvData->DnsAddress);\r
-\r
-Exit:\r
-\r
- if (DnsAddress != NULL) {\r
- FreePool(DnsAddress);\r
- }\r
-\r
- if (Ip4Info != NULL) {\r
- FreePool(Ip4Info);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Convert the IFR data into the network configuration data and set the IP\r
- configure parameters for the NIC.\r
-\r
- @param[in] IfrFormNvData The IFR NV data.\r
- @param[in, out] Instance The IP4 config2 instance.\r
-\r
- @retval EFI_SUCCESS The configure parameter for this NIC was\r
- set successfully.\r
- @retval EFI_INVALID_PARAMETER The address information for setting is invalid.\r
- @retval Others Other errors as indicated.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4Config2ConvertIfrNvDataToConfigNvData (\r
- IN IP4_CONFIG2_IFR_NVDATA *IfrFormNvData,\r
- IN OUT IP4_CONFIG2_INSTANCE *Instance\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_IP4_CONFIG2_PROTOCOL *Ip4Cfg2;\r
- IP4_CONFIG2_NVDATA *Ip4NvData;\r
-\r
- EFI_IP_ADDRESS StationAddress;\r
- EFI_IP_ADDRESS SubnetMask;\r
- EFI_IP_ADDRESS Gateway;\r
- IP4_ADDR Ip;\r
- EFI_IPv4_ADDRESS *DnsAddress;\r
- UINTN DnsCount;\r
- UINTN Index;\r
-\r
- EFI_EVENT TimeoutEvent;\r
- EFI_EVENT SetAddressEvent;\r
- BOOLEAN IsAddressOk;\r
- UINTN DataSize;\r
- EFI_INPUT_KEY Key;\r
-\r
- Status = EFI_SUCCESS;\r
- Ip4Cfg2 = &Instance->Ip4Config2;\r
- Ip4NvData = &Instance->Ip4NvData;\r
-\r
- DnsCount = 0;\r
- DnsAddress = NULL;\r
-\r
- TimeoutEvent = NULL;\r
- SetAddressEvent = NULL;\r
-\r
-\r
-\r
- if (Instance == NULL || IfrFormNvData == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (IfrFormNvData->Configure != TRUE) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- if (IfrFormNvData->DhcpEnable == TRUE) {\r
- Ip4NvData->Policy = Ip4Config2PolicyDhcp;\r
-\r
- Status = Ip4Cfg2->SetData (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypePolicy,\r
- sizeof (EFI_IP4_CONFIG2_POLICY),\r
- &Ip4NvData->Policy\r
- );\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
- } else {\r
- //\r
- // Get Ip4NvData from IfrFormNvData if it is valid.\r
- //\r
- Ip4NvData->Policy = Ip4Config2PolicyStatic;\r
-\r
- Status = Ip4Config2StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);\r
- if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);\r
- if (EFI_ERROR (Status) ||\r
- (SubnetMask.Addr[0] != 0 && !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), NTOHL (SubnetMask.Addr[0]))) ||\r
- !Ip4StationAddressValid (NTOHL (StationAddress.Addr[0]), NTOHL (SubnetMask.Addr[0]))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r
- if (EFI_ERROR (Status) ||\r
- (Gateway.Addr[0] != 0 && SubnetMask.Addr[0] != 0 && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL (SubnetMask.Addr[0])))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Ip4Config2StrToIpList (IfrFormNvData->DnsAddress, &DnsAddress, &DnsCount);\r
- if (!EFI_ERROR (Status) && DnsCount > 0) {\r
- for (Index = 0; Index < DnsCount; Index ++) {\r
- CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR));\r
- if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);\r
- FreePool(DnsAddress);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
- } else {\r
- if (EFI_ERROR (Status)) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);\r
- }\r
- }\r
-\r
- if (Ip4NvData->ManualAddress != NULL) {\r
- FreePool(Ip4NvData->ManualAddress);\r
- }\r
- Ip4NvData->ManualAddressCount = 1;\r
- Ip4NvData->ManualAddress = AllocateZeroPool(sizeof(EFI_IP4_CONFIG2_MANUAL_ADDRESS));\r
- if (Ip4NvData->ManualAddress == NULL) {\r
- if (DnsAddress != NULL) {\r
- FreePool(DnsAddress);\r
- }\r
-\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- CopyMem(&Ip4NvData->ManualAddress->Address, &StationAddress.v4, sizeof(EFI_IPv4_ADDRESS));\r
- CopyMem(&Ip4NvData->ManualAddress->SubnetMask, &SubnetMask.v4, sizeof(EFI_IPv4_ADDRESS));\r
-\r
- if (Ip4NvData->GatewayAddress != NULL) {\r
- FreePool(Ip4NvData->GatewayAddress);\r
- }\r
- Ip4NvData->GatewayAddressCount = 1;\r
- Ip4NvData->GatewayAddress = AllocateZeroPool(sizeof(EFI_IPv4_ADDRESS));\r
- if (Ip4NvData->GatewayAddress == NULL) {\r
- if (DnsAddress != NULL) {\r
- FreePool(DnsAddress);\r
- }\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- CopyMem(Ip4NvData->GatewayAddress, &Gateway.v4, sizeof(EFI_IPv4_ADDRESS));\r
-\r
- if (Ip4NvData->DnsAddress != NULL) {\r
- FreePool(Ip4NvData->DnsAddress);\r
- }\r
- Ip4NvData->DnsAddressCount = (UINT32) DnsCount;\r
- Ip4NvData->DnsAddress = DnsAddress;\r
-\r
- //\r
- // Setting Ip4NvData.\r
- //\r
- Status = Ip4Cfg2->SetData (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypePolicy,\r
- sizeof (EFI_IP4_CONFIG2_POLICY),\r
- &Ip4NvData->Policy\r
- );\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Create events & timers for asynchronous settings.\r
- //\r
- Status = gBS->CreateEvent (\r
- EVT_TIMER,\r
- TPL_CALLBACK,\r
- NULL,\r
- NULL,\r
- &TimeoutEvent\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- Ip4Config2ManualAddressNotify,\r
- &IsAddressOk,\r
- &SetAddressEvent\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- IsAddressOk = FALSE;\r
-\r
- Status = Ip4Cfg2->RegisterDataNotify (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypeManualAddress,\r
- SetAddressEvent\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Set ManualAddress.\r
- //\r
- DataSize = Ip4NvData->ManualAddressCount * sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS);\r
- Status = Ip4Cfg2->SetData (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypeManualAddress,\r
- DataSize,\r
- (VOID *) Ip4NvData->ManualAddress\r
- );\r
-\r
- if (Status == EFI_NOT_READY) {\r
- gBS->SetTimer (TimeoutEvent, TimerRelative, 50000000);\r
- while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {\r
- if (IsAddressOk) {\r
- Status = EFI_SUCCESS;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- Ip4Cfg2->UnregisterDataNotify (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypeManualAddress,\r
- SetAddressEvent\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Set gateway.\r
- //\r
- DataSize = Ip4NvData->GatewayAddressCount * sizeof (EFI_IPv4_ADDRESS);\r
- Status = Ip4Cfg2->SetData (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypeGateway,\r
- DataSize,\r
- Ip4NvData->GatewayAddress\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
-\r
- //\r
- // Set DNS addresses.\r
- //\r
- if (Ip4NvData->DnsAddressCount > 0 && Ip4NvData->DnsAddress != NULL) {\r
- DataSize = Ip4NvData->DnsAddressCount * sizeof (EFI_IPv4_ADDRESS);\r
- Status = Ip4Cfg2->SetData (\r
- Ip4Cfg2,\r
- Ip4Config2DataTypeDnsServer,\r
- DataSize,\r
- Ip4NvData->DnsAddress\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Exit;\r
- }\r
- }\r
- }\r
-\r
-Exit:\r
- if (SetAddressEvent != NULL) {\r
- gBS->CloseEvent (SetAddressEvent);\r
- }\r
-\r
- if (TimeoutEvent != NULL) {\r
- gBS->CloseEvent (TimeoutEvent);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- This function allows the caller to request the current\r
- configuration for one or more named elements. The resulting\r
- string is in <ConfigAltResp> format. Any and all alternative\r
- configuration strings shall also be appended to the end of the\r
- current configuration string. If they are, they must appear\r
- after the current configuration. They must contain the same\r
- routing (GUID, NAME, PATH) as the current configuration string.\r
- They must have an additional description indicating the type of\r
- alternative configuration the string represents,\r
- "ALTCFG=<StringToken>". That <StringToken> (when\r
- converted from Hex UNICODE to binary) is a reference to a\r
- string in the associated string pack.\r
-\r
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param[in] Request A null-terminated Unicode string in\r
- <ConfigRequest> format. Note that this\r
- includes the routing information as well as\r
- the configurable name / value pairs. It is\r
- invalid for this string to be in\r
- <MultiConfigRequest> format.\r
- @param[out] Progress On return, points to a character in the\r
- Request string. Points to the string's null\r
- terminator if request was successful. Points\r
- to the most recent "&" before the first\r
- failing name / value pair (or the beginning\r
- of the string if the failure is in the first\r
- name / value pair) if the request was not\r
- successful.\r
- @param[out] Results A null-terminated Unicode string in\r
- <ConfigAltResp> format which has all values\r
- filled in for the names in the Request string.\r
- String to be allocated by the called function.\r
-\r
- @retval EFI_SUCCESS The Results string is filled with the\r
- values corresponding to all requested\r
- names.\r
- @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
- parts of the results that must be\r
- stored awaiting possible future\r
- protocols.\r
- @retval EFI_NOT_FOUND Routing data doesn't match any\r
- known driver. Progress set to the\r
- first character in the routing header.\r
- Note: There is no requirement that the\r
- driver validate the routing data. It\r
- must skip the <ConfigHdr> in order to\r
- process the names.\r
- @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r
- to most recent & before the\r
- error or the beginning of the\r
- string.\r
- @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r
- to the & before the name in\r
- question.Currently not implemented.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-Ip4FormExtractConfig (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN CONST EFI_STRING Request,\r
- OUT EFI_STRING *Progress,\r
- OUT EFI_STRING *Results\r
- )\r
-{\r
- EFI_STATUS Status;\r
- IP4_CONFIG2_INSTANCE *Ip4Config2Instance;\r
- IP4_FORM_CALLBACK_INFO *Private;\r
- IP4_CONFIG2_IFR_NVDATA *IfrFormNvData;\r
- EFI_STRING ConfigRequestHdr;\r
- EFI_STRING ConfigRequest;\r
- BOOLEAN AllocatedRequest;\r
- EFI_STRING FormResult;\r
- UINTN Size;\r
- UINTN BufferSize;\r
-\r
- if (Progress == NULL || Results == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
- IfrFormNvData = NULL;\r
- ConfigRequest = NULL;\r
- FormResult = NULL;\r
- Size = 0;\r
- AllocatedRequest = FALSE;\r
- ConfigRequest = Request;\r
- Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);\r
- Ip4Config2Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);\r
- BufferSize = sizeof (IP4_CONFIG2_IFR_NVDATA);\r
- *Progress = Request;\r
-\r
- //\r
- // Check Request data in <ConfigHdr>.\r
- //\r
- if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {\r
- IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));\r
- if (IfrFormNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Ip4Config2ConvertConfigNvDataToIfrNvData (Ip4Config2Instance, IfrFormNvData);\r
-\r
- if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
- //\r
- // Request has no request element, construct full request string.\r
- // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
- // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
- //\r
- ConfigRequestHdr = HiiConstructConfigHdr (&gIp4Config2NvDataGuid, mIp4Config2StorageName, Private->ChildHandle);\r
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
- ConfigRequest = AllocateZeroPool (Size);\r
- if (ConfigRequest == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Failure;\r
- }\r
- AllocatedRequest = TRUE;\r
-\r
- UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
- FreePool (ConfigRequestHdr);\r
- }\r
-\r
- //\r
- // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
- //\r
- Status = gHiiConfigRouting->BlockToConfig (\r
- gHiiConfigRouting,\r
- ConfigRequest,\r
- (UINT8 *) IfrFormNvData,\r
- BufferSize,\r
- &FormResult,\r
- Progress\r
- );\r
-\r
- FreePool (IfrFormNvData);\r
-\r
- //\r
- // Free the allocated config request string.\r
- //\r
- if (AllocatedRequest) {\r
- FreePool (ConfigRequest);\r
- ConfigRequest = NULL;\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Failure;\r
- }\r
- }\r
-\r
- if (Request == NULL || HiiIsConfigHdrMatch (Request, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {\r
- *Results = FormResult;\r
- } else {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
-Failure:\r
- //\r
- // Set Progress string to the original request string.\r
- //\r
- if (Request == NULL) {\r
- *Progress = NULL;\r
- } else if (StrStr (Request, L"OFFSET") == NULL) {\r
- *Progress = Request + StrLen (Request);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- This function applies changes in a driver's configuration.\r
- Input is a Configuration, which has the routing data for this\r
- driver followed by name / value configuration pairs. The driver\r
- must apply those pairs to its configurable storage. If the\r
- driver's configuration is stored in a linear block of data\r
- and the driver's name / value pairs are in <BlockConfig>\r
- format, it may use the ConfigToBlock helper function (above) to\r
- simplify the job. Currently not implemented.\r
-\r
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param[in] Configuration A null-terminated Unicode string in\r
- <ConfigString> format.\r
- @param[out] Progress A pointer to a string filled in with the\r
- offset of the most recent '&' before the\r
- first failing name / value pair (or the\r
- beginn ing of the string if the failure\r
- is in the first name / value pair) or\r
- the terminating NULL if all was\r
- successful.\r
-\r
- @retval EFI_SUCCESS The results have been distributed or are\r
- awaiting distribution.\r
- @retval EFI_OUT_OF_MEMORY Not enough memory to store the\r
- parts of the results that must be\r
- stored awaiting possible future\r
- protocols.\r
- @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r
- Results parameter would result\r
- in this type of error.\r
- @retval EFI_NOT_FOUND Target for the specified routing data\r
- was not found.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-Ip4FormRouteConfig (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN CONST EFI_STRING Configuration,\r
- OUT EFI_STRING *Progress\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINTN BufferSize;\r
- IP4_CONFIG2_IFR_NVDATA *IfrFormNvData;\r
- IP4_CONFIG2_INSTANCE *Ip4Config2Instance;\r
- IP4_FORM_CALLBACK_INFO *Private;\r
-\r
- Status = EFI_SUCCESS;\r
- IfrFormNvData = NULL;\r
-\r
- if (Configuration == NULL || Progress == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- *Progress = Configuration;\r
-\r
- Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);\r
- Ip4Config2Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);\r
-\r
- //\r
- // Check Routing data in <ConfigHdr>.\r
- //\r
- if (HiiIsConfigHdrMatch (Configuration, &gIp4Config2NvDataGuid, mIp4Config2StorageName)) {\r
- //\r
- // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
- //\r
- IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));\r
- if (IfrFormNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- BufferSize = 0;\r
-\r
- Status = gHiiConfigRouting->ConfigToBlock (\r
- gHiiConfigRouting,\r
- Configuration,\r
- (UINT8 *) IfrFormNvData,\r
- &BufferSize,\r
- Progress\r
- );\r
- if (Status != EFI_BUFFER_TOO_SMALL) {\r
- return Status;\r
- }\r
-\r
- Status = gHiiConfigRouting->ConfigToBlock (\r
- gHiiConfigRouting,\r
- Configuration,\r
- (UINT8 *) IfrFormNvData,\r
- &BufferSize,\r
- Progress\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- Status = Ip4Config2ConvertIfrNvDataToConfigNvData (IfrFormNvData, Ip4Config2Instance);\r
- }\r
-\r
- FreePool (IfrFormNvData);\r
- } else {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- return Status;\r
-\r
-}\r
-\r
-/**\r
- This function is called to provide results data to the driver.\r
- This data consists of a unique key that is used to identify\r
- which data is either being passed back or being asked for.\r
-\r
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param[in] Action Specifies the type of action taken by the browser.\r
- @param[in] QuestionId A unique value which is sent to the original\r
- exporting driver so that it can identify the type\r
- of data to expect. The format of the data tends to\r
- vary based on the opcode that enerated the callback.\r
- @param[in] Type The type of value for the question.\r
- @param[in] Value A pointer to the data being sent to the original\r
- exporting driver.\r
- @param[out] ActionRequest On return, points to the action requested by the\r
- callback function.\r
-\r
- @retval EFI_SUCCESS The callback successfully handled the action.\r
- @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
- variable and its data.\r
- @retval EFI_DEVICE_ERROR The variable could not be saved.\r
- @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
- callback.Currently not implemented.\r
- @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.\r
- @retval Others Other errors as indicated.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-Ip4FormCallback (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN EFI_BROWSER_ACTION Action,\r
- IN EFI_QUESTION_ID QuestionId,\r
- IN UINT8 Type,\r
- IN EFI_IFR_TYPE_VALUE *Value,\r
- OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
- )\r
-{\r
- EFI_STATUS Status;\r
- IP4_CONFIG2_INSTANCE *Instance;\r
- IP4_CONFIG2_IFR_NVDATA *IfrFormNvData;\r
- IP4_FORM_CALLBACK_INFO *Private;\r
-\r
- EFI_IP_ADDRESS StationAddress;\r
- EFI_IP_ADDRESS SubnetMask;\r
- EFI_IP_ADDRESS Gateway;\r
- IP4_ADDR Ip;\r
- EFI_IPv4_ADDRESS *DnsAddress;\r
- UINTN DnsCount;\r
- UINTN Index;\r
- EFI_INPUT_KEY Key;\r
-\r
- IfrFormNvData = NULL;\r
- DnsCount = 0;\r
- DnsAddress = NULL;\r
-\r
- if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
- Private = IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This);\r
- Instance = IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private);\r
-\r
- IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA));\r
- if (IfrFormNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Retrieve uncommitted data from Browser\r
- //\r
- if (!HiiGetBrowserData (&gIp4Config2NvDataGuid, mIp4Config2StorageName, sizeof (IP4_CONFIG2_IFR_NVDATA), (UINT8 *) IfrFormNvData)) {\r
- FreePool (IfrFormNvData);\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
-\r
- switch (QuestionId) {\r
- case KEY_LOCAL_IP:\r
- Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);\r
- if (EFI_ERROR (Status) || IP4_IS_UNSPECIFIED (NTOHL (StationAddress.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (StationAddress.Addr[0]))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
- Status = EFI_INVALID_PARAMETER;\r
- }\r
- break;\r
-\r
- case KEY_SUBNET_MASK:\r
- Status = Ip4Config2StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);\r
- if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
- Status = EFI_INVALID_PARAMETER;\r
- }\r
- break;\r
-\r
- case KEY_GATE_WAY:\r
- Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r
- if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST(NTOHL(Gateway.Addr[0]))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
- Status = EFI_INVALID_PARAMETER;\r
- }\r
- break;\r
-\r
- case KEY_DNS:\r
- Status = Ip4Config2StrToIpList (IfrFormNvData->DnsAddress, &DnsAddress, &DnsCount);\r
- if (!EFI_ERROR (Status) && DnsCount > 0) {\r
- for (Index = 0; Index < DnsCount; Index ++) {\r
- CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR));\r
- if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);\r
- Status = EFI_INVALID_PARAMETER;\r
- break;\r
- }\r
- }\r
- } else {\r
- if (EFI_ERROR (Status)) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);\r
- }\r
- }\r
-\r
- if(DnsAddress != NULL) {\r
- FreePool(DnsAddress);\r
- }\r
- break;\r
-\r
- case KEY_SAVE_CHANGES:\r
- Status = Ip4Config2ConvertIfrNvDataToConfigNvData (IfrFormNvData, Instance);\r
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
- break;\r
-\r
- default:\r
- break;\r
- }\r
-\r
- FreePool (IfrFormNvData);\r
-\r
- return Status;\r
- }\r
-\r
- //\r
- // All other action return unsupported.\r
- //\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- Install HII Config Access protocol for network device and allocate resource.\r
-\r
- @param[in, out] Instance The IP4 config2 Instance.\r
-\r
- @retval EFI_SUCCESS The HII Config Access protocol is installed.\r
- @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
- @retval Others Other errors as indicated.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4Config2FormInit (\r
- IN OUT IP4_CONFIG2_INSTANCE *Instance\r
- )\r
-{\r
- EFI_STATUS Status;\r
- IP4_SERVICE *IpSb;\r
- IP4_FORM_CALLBACK_INFO *CallbackInfo;\r
- EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
- VENDOR_DEVICE_PATH VendorDeviceNode;\r
- EFI_SERVICE_BINDING_PROTOCOL *MnpSb;\r
- CHAR16 *MacString;\r
- CHAR16 MenuString[128];\r
- CHAR16 PortString[128];\r
- CHAR16 *OldMenuString;\r
- EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
-\r
- IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r
- ASSERT (IpSb != NULL);\r
-\r
- CallbackInfo = &Instance->CallbackInfo;\r
-\r
- CallbackInfo->Signature = IP4_FORM_CALLBACK_INFO_SIGNATURE;\r
-\r
- Status = gBS->HandleProtocol (\r
- IpSb->Controller,\r
- &gEfiDevicePathProtocolGuid,\r
- (VOID **) &ParentDevicePath\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Construct device path node for EFI HII Config Access protocol,\r
- // which consists of controller physical device path and one hardware\r
- // vendor guid node.\r
- //\r
- ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));\r
- VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;\r
- VendorDeviceNode.Header.SubType = HW_VENDOR_DP;\r
-\r
- CopyGuid (&VendorDeviceNode.Guid, &gEfiCallerIdGuid);\r
-\r
- SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));\r
- CallbackInfo->HiiVendorDevicePath = AppendDevicePathNode (\r
- ParentDevicePath,\r
- (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode\r
- );\r
- if (CallbackInfo->HiiVendorDevicePath == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Error;\r
- }\r
-\r
- ConfigAccess = &CallbackInfo->HiiConfigAccessProtocol;\r
- ConfigAccess->ExtractConfig = Ip4FormExtractConfig;\r
- ConfigAccess->RouteConfig = Ip4FormRouteConfig;\r
- ConfigAccess->Callback = Ip4FormCallback;\r
-\r
- //\r
- // Install Device Path Protocol and Config Access protocol on new handle\r
- //\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &CallbackInfo->ChildHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- CallbackInfo->HiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- ConfigAccess,\r
- NULL\r
- );\r
-\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // Open the Parent Handle for the child\r
- //\r
- Status = gBS->OpenProtocol (\r
- IpSb->Controller,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- (VOID **) &MnpSb,\r
- IpSb->Image,\r
- CallbackInfo->ChildHandle,\r
- EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
- );\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Error;\r
- }\r
-\r
- //\r
- // Publish our HII data\r
- //\r
- CallbackInfo->RegisteredHandle = HiiAddPackages (\r
- &gIp4Config2NvDataGuid,\r
- CallbackInfo->ChildHandle,\r
- Ip4DxeStrings,\r
- Ip4Config2Bin,\r
- NULL\r
- );\r
- if (CallbackInfo->RegisteredHandle == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Error;\r
- }\r
-\r
- //\r
- // Append MAC string in the menu help string and tile help string\r
- //\r
- Status = NetLibGetMacString (IpSb->Controller, IpSb->Image, &MacString);\r
- if (!EFI_ERROR (Status)) {\r
- OldMenuString = HiiGetString (\r
- CallbackInfo->RegisteredHandle,\r
- STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP),\r
- NULL\r
- );\r
- UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);\r
- HiiSetString (\r
- CallbackInfo->RegisteredHandle,\r
- STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP),\r
- MenuString,\r
- NULL\r
- );\r
-\r
- UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);\r
- HiiSetString (\r
- CallbackInfo->RegisteredHandle,\r
- STRING_TOKEN (STR_IP4_DEVICE_FORM_HELP),\r
- PortString,\r
- NULL\r
- );\r
-\r
- FreePool (MacString);\r
- FreePool (OldMenuString);\r
-\r
- return EFI_SUCCESS;\r
- }\r
-\r
-Error:\r
- Ip4Config2FormUnload (Instance);\r
- return Status;\r
-}\r
-\r
-/**\r
- Uninstall the HII Config Access protocol for network devices and free up the resources.\r
-\r
- @param[in, out] Instance The IP4 config2 instance to unload a form.\r
-\r
-**/\r
-VOID\r
-Ip4Config2FormUnload (\r
- IN OUT IP4_CONFIG2_INSTANCE *Instance\r
- )\r
-{\r
- IP4_SERVICE *IpSb;\r
- IP4_FORM_CALLBACK_INFO *CallbackInfo;\r
- IP4_CONFIG2_NVDATA *Ip4NvData;\r
-\r
- IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r
- ASSERT (IpSb != NULL);\r
-\r
- CallbackInfo = &Instance->CallbackInfo;\r
-\r
- if (CallbackInfo->ChildHandle != NULL) {\r
- //\r
- // Close the child handle\r
- //\r
- gBS->CloseProtocol (\r
- IpSb->Controller,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- IpSb->Image,\r
- CallbackInfo->ChildHandle\r
- );\r
-\r
- //\r
- // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
- //\r
- gBS->UninstallMultipleProtocolInterfaces (\r
- CallbackInfo->ChildHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- CallbackInfo->HiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &CallbackInfo->HiiConfigAccessProtocol,\r
- NULL\r
- );\r
- }\r
-\r
- if (CallbackInfo->HiiVendorDevicePath != NULL) {\r
- FreePool (CallbackInfo->HiiVendorDevicePath);\r
- }\r
-\r
- if (CallbackInfo->RegisteredHandle != NULL) {\r
- //\r
- // Remove HII package list\r
- //\r
- HiiRemovePackages (CallbackInfo->RegisteredHandle);\r
- }\r
-\r
- Ip4NvData = &Instance->Ip4NvData;\r
-\r
- if(Ip4NvData->ManualAddress != NULL) {\r
- FreePool(Ip4NvData->ManualAddress);\r
- }\r
-\r
- if(Ip4NvData->GatewayAddress != NULL) {\r
- FreePool(Ip4NvData->GatewayAddress);\r
- }\r
-\r
- if(Ip4NvData->DnsAddress != NULL) {\r
- FreePool(Ip4NvData->DnsAddress);\r
- }\r
-\r
- Ip4NvData->ManualAddressCount = 0;\r
- Ip4NvData->GatewayAddressCount = 0;\r
- Ip4NvData->DnsAddressCount = 0;\r
-}\r