+++ /dev/null
-/** @file\r
- Helper functions for configuring or getting the parameters relating to Ip4.\r
-\r
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "Ip4ConfigNv.h"\r
-#include "NicIp4Variable.h"\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
-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
-EFI_STATUS\r
-Ip4StrToIp (\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 IPv4 address into a dotted string.\r
-\r
- @param[in] Ip The IPv4 address.\r
- @param[out] Str The dotted IP string.\r
-**/\r
-VOID\r
-Ip4ConfigIpToStr (\r
- IN EFI_IPv4_ADDRESS *Ip,\r
- OUT CHAR16 *Str\r
- )\r
-{\r
- UnicodeSPrint (Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]);\r
-}\r
-\r
-\r
-/**\r
- Convert the network configuration data into the IFR data.\r
-\r
- @param[in] Ip4ConfigInstance The IP4Config instance\r
- @param[out] IfrFormNvData The IFR nv data.\r
-**/\r
-VOID\r
-Ip4ConfigConvertDeviceConfigDataToIfrNvData (\r
- IN IP4_CONFIG_INSTANCE *Ip4ConfigInstance,\r
- OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData\r
- )\r
-{\r
- NIC_IP4_CONFIG_INFO *NicConfig;\r
-\r
- NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);\r
- if (NicConfig != NULL) {\r
- IfrFormNvData->Configure = 1;\r
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = TRUE;\r
- if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r
- IfrFormNvData->DhcpEnable = 1;\r
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE;\r
- } else {\r
- IfrFormNvData->DhcpEnable = 0;\r
- Ip4ConfigIpToStr (&NicConfig->Ip4Info.StationAddress, IfrFormNvData->StationAddress);\r
- Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);\r
- Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);\r
-\r
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE;\r
- CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, &NicConfig->Ip4Info.StationAddress, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &NicConfig->Ip4Info.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, &NicConfig->Ip4Info.RouteTable[1].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
- }\r
-\r
- FreePool (NicConfig);\r
- } else {\r
- IfrFormNvData->Configure = 0;\r
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = FALSE;\r
- }\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] Ip4ConfigInstance The IP4Config instance.\r
-\r
- @retval EFI_SUCCESS The configure parameter for this NIC was\r
- set successfully.\r
- @retval EFI_ALREADY_STARTED There is a pending auto configuration.\r
- @retval EFI_NOT_FOUND No auto configure parameter is found.\r
-\r
-**/\r
-EFI_STATUS\r
-Ip4ConfigConvertIfrNvDataToDeviceConfigData (\r
- IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData,\r
- IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_IP_ADDRESS HostIp;\r
- EFI_IP_ADDRESS SubnetMask;\r
- EFI_IP_ADDRESS Gateway;\r
- EFI_INPUT_KEY Key;\r
- NIC_IP4_CONFIG_INFO *NicInfo;\r
- EFI_IP_ADDRESS Ip;\r
-\r
- ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r
-\r
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = IfrFormNvData->Configure;\r
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = IfrFormNvData->DhcpEnable;\r
- Ip4StrToIp (IfrFormNvData->StationAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp);\r
- Ip4StrToIp (IfrFormNvData->SubnetMask, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask);\r
- Ip4StrToIp (IfrFormNvData->GatewayAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway);\r
-\r
- if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured) {\r
- //\r
- // Clear the variable\r
- //\r
- ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r
-\r
- Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);\r
- if (Status == EFI_NOT_FOUND) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- return Status;\r
- }\r
-\r
- NicInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));\r
- ASSERT (NicInfo != NULL);\r
-\r
- NicInfo->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (NicInfo + 1);\r
-\r
- if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled) {\r
- CopyMem (&HostIp.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, sizeof (HostIp.v4));\r
- CopyMem (&SubnetMask.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, sizeof (SubnetMask.v4));\r
- CopyMem (&Gateway.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, sizeof (Gateway.v4));\r
-\r
- if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if (EFI_IP4_EQUAL (&SubnetMask, &mZeroIp4Addr)) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((Gateway.Addr[0] != 0)) {\r
- if (SubnetMask.Addr[0] == 0) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL);\r
- return EFI_INVALID_PARAMETER;\r
-\r
- } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL);\r
- return EFI_INVALID_PARAMETER; }\r
- }\r
-\r
- NicInfo->Source = IP4_CONFIG_SOURCE_STATIC;\r
- NicInfo->Ip4Info.RouteTableSize = 2;\r
-\r
- CopyMem (&NicInfo->Ip4Info.StationAddress, &HostIp.v4, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&NicInfo->Ip4Info.SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- Ip.Addr[0] = HostIp.Addr[0] & SubnetMask.Addr[0];\r
-\r
- CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&NicInfo->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));\r
-\r
- } else {\r
- NicInfo->Source = IP4_CONFIG_SOURCE_DHCP;\r
- ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, sizeof (EFI_IPv4_ADDRESS));\r
- ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
- ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, sizeof (EFI_IPv4_ADDRESS));\r
- }\r
-\r
- NicInfo->Permanent = TRUE;\r
- CopyMem (&NicInfo->NicAddr, &Ip4ConfigInstance->NicAddr, sizeof (NIC_ADDR));\r
-\r
- return EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\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
-Ip4DeviceExtractConfig (\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
- NIC_IP4_CONFIG_INFO *IfrDeviceNvData;\r
- NIC_IP4_CONFIG_INFO *NicConfig;\r
- IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r
- IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r
- EFI_STRING ConfigRequestHdr;\r
- EFI_STRING ConfigRequest;\r
- EFI_STRING DeviceResult;\r
- EFI_STRING FormResult;\r
- CHAR16 *StrPointer;\r
- BOOLEAN AllocatedRequest;\r
- UINTN Size;\r
- UINTN BufferSize;\r
-\r
- if (Progress == NULL || Results == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- *Progress = Request;\r
- Size = 0;\r
- DeviceResult = NULL;\r
- FormResult = NULL;\r
- ConfigRequest = NULL;\r
- Status = EFI_SUCCESS;\r
- AllocatedRequest = FALSE;\r
- Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r
-\r
- //\r
- // Check Request data in <ConfigHdr>.\r
- //\r
- if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
- IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
- if (IfrDeviceNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);\r
- if (NicConfig == NULL) {\r
- return EFI_NOT_FOUND;\r
- }\r
- CopyMem (IfrDeviceNvData, NicConfig, SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig));\r
- FreePool (NicConfig);\r
-\r
- ConfigRequest = Request;\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 (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle);\r
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
- ConfigRequest = AllocateZeroPool (Size);\r
- ASSERT (ConfigRequest != NULL);\r
- AllocatedRequest = TRUE;\r
- BufferSize = NIC_ITEM_CONFIG_SIZE;\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 *) IfrDeviceNvData,\r
- NIC_ITEM_CONFIG_SIZE,\r
- &DeviceResult,\r
- Progress\r
- );\r
-\r
- FreePool (IfrDeviceNvData);\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, &gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
-\r
- IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r
- if (IfrFormNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData);\r
-\r
- ConfigRequest = Request;\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 (&gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle);\r
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
- ConfigRequest = AllocateZeroPool (Size);\r
- ASSERT (ConfigRequest != NULL);\r
- AllocatedRequest = TRUE;\r
- BufferSize = sizeof (IP4_CONFIG_IFR_NVDATA);\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
- sizeof (IP4_CONFIG_IFR_NVDATA),\r
- &FormResult,\r
- Progress\r
- );\r
-\r
- FreePool (IfrFormNvData);\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) {\r
- Size = StrLen (DeviceResult);\r
- Size = Size + 1;\r
- Size = Size + StrLen (FormResult) + 1;\r
- *Results = AllocateZeroPool (Size * sizeof (CHAR16));\r
- ASSERT (*Results != NULL);\r
- StrPointer = *Results;\r
- StrCpyS (StrPointer, Size, DeviceResult);\r
- StrPointer = StrPointer + StrLen (StrPointer);\r
- *StrPointer = L'&';\r
- StrCpyS (StrPointer + 1, StrLen (FormResult) + 1, FormResult);\r
- FreePool (DeviceResult);\r
- FreePool (FormResult);\r
- } else if (HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
- *Results = DeviceResult;\r
- } else if (HiiIsConfigHdrMatch (Request, &gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\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
-Ip4DeviceRouteConfig (\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
- NIC_IP4_CONFIG_INFO *IfrDeviceNvData;\r
- IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r
- NIC_IP4_CONFIG_INFO *NicInfo;\r
- IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r
- EFI_MAC_ADDRESS ZeroMac;\r
-\r
- if (Configuration == NULL || Progress == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Reclaim Ip4Config variable\r
- //\r
- Ip4ConfigReclaimVariable ();\r
-\r
- *Progress = Configuration;\r
-\r
- Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r
-\r
- //\r
- // Check Routing data in <ConfigHdr>.\r
- //\r
- if (HiiIsConfigHdrMatch (Configuration, &gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
- //\r
- // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
- //\r
- IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r
- if (IfrFormNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- BufferSize = NIC_ITEM_CONFIG_SIZE;\r
- Status = gHiiConfigRouting->ConfigToBlock (\r
- gHiiConfigRouting,\r
- Configuration,\r
- (UINT8 *) IfrFormNvData,\r
- &BufferSize,\r
- Progress\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);\r
- }\r
-\r
- FreePool (IfrFormNvData);\r
-\r
- } else if (HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
-\r
- IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
- if (IfrDeviceNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- BufferSize = NIC_ITEM_CONFIG_SIZE;\r
- Status = gHiiConfigRouting->ConfigToBlock (\r
- gHiiConfigRouting,\r
- Configuration,\r
- (UINT8 *) IfrDeviceNvData,\r
- &BufferSize,\r
- Progress\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS));\r
- if (CompareMem (&IfrDeviceNvData->NicAddr.MacAddr, &ZeroMac, IfrDeviceNvData->NicAddr.Len) != 0) {\r
- BufferSize = SIZEOF_NIC_IP4_CONFIG_INFO (IfrDeviceNvData);\r
- NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData);\r
- if (NicInfo == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\r
- FreePool (NicInfo);\r
- } else {\r
- ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r
- Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);\r
- }\r
- }\r
-\r
- FreePool (IfrDeviceNvData);\r
-\r
- } else {\r
-\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
-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
- IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r
- IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r
- EFI_IP_ADDRESS HostIp;\r
- EFI_IP_ADDRESS SubnetMask;\r
- EFI_IP_ADDRESS Gateway;\r
- EFI_STATUS Status;\r
- EFI_INPUT_KEY Key;\r
-\r
- if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
- Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r
-\r
- IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r
- if (IfrFormNvData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Retrive uncommitted data from Browser\r
- //\r
- if (!HiiGetBrowserData (&gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_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 = Ip4StrToIp (IfrFormNvData->StationAddress, &HostIp.v4);\r
- if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
- Status = EFI_INVALID_PARAMETER;\r
- } else {\r
- CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r
- }\r
-\r
- break;\r
-\r
- case KEY_SUBNET_MASK:\r
- Status = Ip4StrToIp (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
- } else {\r
- CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
- }\r
-\r
- break;\r
-\r
- case KEY_GATE_WAY:\r
- Status = Ip4StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r
- if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
- CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
- Status = EFI_INVALID_PARAMETER;\r
- } else {\r
- CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r
- }\r
-\r
- break;\r
-\r
- case KEY_SAVE_CHANGES:\r
- Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);\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] Instance The IP4 Config 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
-EFI_STATUS\r
-Ip4ConfigDeviceInit (\r
- IN IP4_CONFIG_INSTANCE *Instance\r
- )\r
-{\r
- EFI_STATUS Status;\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
-\r
- ConfigAccess = &Instance->HiiConfigAccessProtocol;\r
- ConfigAccess->ExtractConfig = Ip4DeviceExtractConfig;\r
- ConfigAccess->RouteConfig = Ip4DeviceRouteConfig;\r
- ConfigAccess->Callback = Ip4FormCallback;\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, &gEfiNicIp4ConfigVariableGuid);\r
-\r
- SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));\r
- Instance->HiiVendorDevicePath = AppendDevicePathNode (\r
- Instance->ParentDevicePath,\r
- (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode\r
- );\r
-\r
- Instance->ChildHandle = NULL;\r
- //\r
- // Install Device Path Protocol and Config Access protocol on new handle\r
- //\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &Instance->ChildHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- Instance->HiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- ConfigAccess,\r
- NULL\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // Open the Parent Handle for the child\r
- //\r
- Status = gBS->OpenProtocol (\r
- Instance->Controller,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- (VOID **) &MnpSb,\r
- Instance->Image,\r
- Instance->ChildHandle,\r
- EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
- );\r
- }\r
-\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Publish our HII data\r
- //\r
- Instance->RegisteredHandle = HiiAddPackages (\r
- &gNicIp4ConfigNvDataGuid,\r
- Instance->ChildHandle,\r
- Ip4ConfigDxeStrings,\r
- Ip4ConfigDxeBin,\r
- NULL\r
- );\r
- if (Instance->RegisteredHandle == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Append MAC string in the menu help string and tile help string\r
- //\r
- Status = NetLibGetMacString (Instance->Controller, Instance->Image, &MacString);\r
- if (!EFI_ERROR (Status)) {\r
- OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_HELP), NULL);\r
- UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);\r
- HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_HELP), MenuString, NULL);\r
-\r
- UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);\r
- HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_HELP), PortString, NULL);\r
- FreePool (MacString);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Uninstall HII Config Access protocol for network device and free resource.\r
-\r
- @param[in] Instance The IP4 Config instance.\r
-\r
- @retval EFI_SUCCESS The HII Config Access protocol is uninstalled.\r
- @retval Others Other errors as indicated.\r
-**/\r
-EFI_STATUS\r
-Ip4ConfigDeviceUnload (\r
- IN IP4_CONFIG_INSTANCE *Instance\r
- )\r
-{\r
- //\r
- // Remove HII package list\r
- //\r
- HiiRemovePackages (Instance->RegisteredHandle);\r
-\r
- //\r
- // Close the child handle\r
- //\r
- gBS->CloseProtocol (\r
- Instance->Controller,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- Instance->Image,\r
- Instance->ChildHandle\r
- );\r
-\r
- //\r
- // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
- //\r
- gBS->UninstallMultipleProtocolInterfaces (\r
- Instance->ChildHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- Instance->HiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &Instance->HiiConfigAccessProtocol,\r
- NULL\r
- );\r
-\r
- return EFI_SUCCESS;\r
-}\r