X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4ConfigDxe%2FIp4ConfigNv.c;h=794bb799490219248da952202e11f3709d69f250;hb=206b5f51beb15a22417c42e846678425de60c556;hp=d7a04b60b4778134cb7cd2cc531a0fa468c4184d;hpb=779ae3579848a36319d67a6ba012b4b9aa88aa6b;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c index d7a04b60b4..794bb79949 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c @@ -1,8 +1,8 @@ /** @file Helper functions for configuring or getting the parameters relating to Ip4. -Copyright (c) 2009, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2009 - 2015, 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 @@ -13,68 +13,7 @@ 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'; -} +#include "NicIp4Variable.h" /** Calculate the prefix length of the IPv4 subnet mask. @@ -95,7 +34,7 @@ GetSubnetMaskPrefixLength ( // // The SubnetMask is in network byte order. // - ReverseMask = (SubnetMask->Addr[0] << 24) | (SubnetMask->Addr[1] << 16) | (SubnetMask->Addr[2] << 8) | (SubnetMask->Addr[3]); + ReverseMask = SwapBytes32 (*(UINT32 *)&SubnetMask[0]); // // Reverse it. @@ -120,14 +59,14 @@ GetSubnetMaskPrefixLength ( Convert the decimal dotted IPv4 address into the binary IPv4 address. @param[in] Str The UNICODE string. - @param[out] Ip The storage to return the ASCII string. + @param[out] Ip The storage to return the IPv4 address. @retval EFI_SUCCESS The binary IP address is returned in Ip. @retval EFI_INVALID_PARAMETER The IP string is malformatted. **/ EFI_STATUS -Ip4AsciiStrToIp ( - IN CHAR8 *Str, +Ip4StrToIp ( + IN CHAR16 *Str, OUT EFI_IPv4_ADDRESS *Ip ) { @@ -136,15 +75,15 @@ Ip4AsciiStrToIp ( Index = 0; - while (*Str != 0) { + while (*Str != L'\0') { if (Index > 3) { return EFI_INVALID_PARAMETER; } Number = 0; - while (NET_IS_DIGIT (*Str)) { - Number = Number * 10 + (*Str - '0'); + while ((*Str >= L'0') && (*Str <= L'9')) { + Number = Number * 10 + (*Str - L'0'); Str++; } @@ -154,7 +93,7 @@ Ip4AsciiStrToIp ( Ip->Addr[Index] = (UINT8) Number; - if ((*Str != '\0') && (*Str != '.')) { + if ((*Str != L'\0') && (*Str != L'.')) { // // The current character should be either the NULL terminator or // the dot delimiter. @@ -162,7 +101,7 @@ Ip4AsciiStrToIp ( return EFI_INVALID_PARAMETER; } - if (*Str == '.') { + if (*Str == L'.') { // // Skip the delimiter. // @@ -207,58 +146,135 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData ( OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData ) { - EFI_STATUS Status; - NIC_IP4_CONFIG_INFO *NicConfig; - UINTN ConfigLen; - - IfrFormNvData->DhcpEnable = 1; + NIC_IP4_CONFIG_INFO *NicConfig; - 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)) { + NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance); + if (NicConfig != NULL) { + IfrFormNvData->Configure = 1; + Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = TRUE; if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) { IfrFormNvData->DhcpEnable = 1; + Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE; } else { IfrFormNvData->DhcpEnable = 0; Ip4ConfigIpToStr (&NicConfig->Ip4Info.StationAddress, IfrFormNvData->StationAddress); Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask); Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress); + + Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE; + CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, &NicConfig->Ip4Info.StationAddress, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &NicConfig->Ip4Info.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, &NicConfig->Ip4Info.RouteTable[1].GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); } + + FreePool (NicConfig); + } else { + IfrFormNvData->Configure = 0; + Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = FALSE; } - FreePool (NicConfig); } /** - Get the IP4 configuration form entry by the index of the goto opcode actived. + Convert the IFR data into the network configuration data and set the IP + configure parameters for the NIC. - @param[in] Index The 0-based index of the goto opcode actived. + @param[in] IfrFormNvData The IFR NV data. + @param[in, out] Ip4ConfigInstance The IP4Config instance. + + @retval EFI_SUCCESS The configure parameter for this NIC was + set successfully. + @retval EFI_ALREADY_STARTED There is a pending auto configuration. + @retval EFI_NOT_FOUND No auto configure parameter is found. - @return The IP4 configuration form entry found. **/ -IP4CONFIG_FORM_ENTRY * -Ip4GetConfigFormEntryByIndex ( - IN UINT32 Index +EFI_STATUS +Ip4ConfigConvertIfrNvDataToDeviceConfigData ( + IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData, + IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance ) { - UINT32 CurrentIndex; - LIST_ENTRY *Entry; - IP4CONFIG_FORM_ENTRY *ConfigFormEntry; + EFI_STATUS Status; + EFI_IP_ADDRESS HostIp; + EFI_IP_ADDRESS SubnetMask; + EFI_IP_ADDRESS Gateway; + EFI_INPUT_KEY Key; + NIC_IP4_CONFIG_INFO *NicInfo; + EFI_IP_ADDRESS Ip; - CurrentIndex = 0; - ConfigFormEntry = NULL; + ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO)); - NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) { - if (CurrentIndex == Index) { - ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link); - break; + Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = IfrFormNvData->Configure; + Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = IfrFormNvData->DhcpEnable; + Ip4StrToIp (IfrFormNvData->StationAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp); + Ip4StrToIp (IfrFormNvData->SubnetMask, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask); + Ip4StrToIp (IfrFormNvData->GatewayAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway); + + if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured) { + // + // Clear the variable + // + ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO)); + + Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE); + if (Status == EFI_NOT_FOUND) { + return EFI_SUCCESS; + } + + return Status; + } + + NicInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE)); + ASSERT (NicInfo != NULL); + + NicInfo->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (NicInfo + 1); + + if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled) { + CopyMem (&HostIp.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, sizeof (HostIp.v4)); + CopyMem (&SubnetMask.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, sizeof (SubnetMask.v4)); + CopyMem (&Gateway.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, sizeof (Gateway.v4)); + + if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); + return EFI_INVALID_PARAMETER; + } + if (EFI_IP4_EQUAL (&SubnetMask, &mZeroIp4Addr)) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL); + return EFI_INVALID_PARAMETER; } - CurrentIndex++; + 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); + return EFI_INVALID_PARAMETER; + + } 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); + return EFI_INVALID_PARAMETER; } + } + + 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; + ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, sizeof (EFI_IPv4_ADDRESS)); } - return ConfigFormEntry; + NicInfo->Permanent = TRUE; + CopyMem (&NicInfo->NicAddr, &Ip4ConfigInstance->NicAddr, sizeof (NIC_ADDR)); + + return EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE); } /** @@ -302,12 +318,6 @@ Ip4GetConfigFormEntryByIndex ( 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. @@ -333,53 +343,173 @@ Ip4DeviceExtractConfig ( ) { EFI_STATUS Status; - UINTN ConfigLen; NIC_IP4_CONFIG_INFO *IfrDeviceNvData; - IP4_FORM_CALLBACK_INFO *Private; - EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + NIC_IP4_CONFIG_INFO *NicConfig; IP4_CONFIG_INSTANCE *Ip4ConfigInstance; + IP4_CONFIG_IFR_NVDATA *IfrFormNvData; + EFI_STRING ConfigRequestHdr; + EFI_STRING ConfigRequest; + EFI_STRING DeviceResult; + EFI_STRING FormResult; + CHAR16 *StrPointer; + BOOLEAN AllocatedRequest; + UINTN Size; + UINTN BufferSize; - if (Request == NULL) { + if (Progress == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; } - *Progress = Request; + *Progress = Request; + Size = 0; + DeviceResult = NULL; + FormResult = NULL; + ConfigRequest = NULL; + Status = EFI_SUCCESS; + AllocatedRequest = FALSE; + Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This); // // Check Request data in . // - if (!HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { - return EFI_NOT_FOUND; + if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { + IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); + if (IfrDeviceNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance); + if (NicConfig == NULL) { + return EFI_NOT_FOUND; + } + CopyMem (IfrDeviceNvData, NicConfig, SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig)); + FreePool (NicConfig); + + ConfigRequest = Request; + if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { + // + // Request has no request element, construct full request string. + // Allocate and fill a buffer large enough to hold the template + // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator + // + ConfigRequestHdr = HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle); + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); + ASSERT (ConfigRequest != NULL); + AllocatedRequest = TRUE; + BufferSize = NIC_ITEM_CONFIG_SIZE; + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); + FreePool (ConfigRequestHdr); + } + + // + // Convert buffer data to by helper function BlockToConfig() + // + Status = gHiiConfigRouting->BlockToConfig ( + gHiiConfigRouting, + ConfigRequest, + (UINT8 *) IfrDeviceNvData, + NIC_ITEM_CONFIG_SIZE, + &DeviceResult, + Progress + ); + + FreePool (IfrDeviceNvData); + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + ConfigRequest = NULL; + } + + if (EFI_ERROR (Status)) { + goto Failure; + } } - Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); - Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO (Private); + if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { - IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); - if (IfrDeviceNvData == NULL) { - return EFI_OUT_OF_RESOURCES; + IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA)); + if (IfrFormNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData); + + ConfigRequest = Request; + if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { + // + // Request has no request element, construct full request string. + // Allocate and fill a buffer large enough to hold the template + // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator + // + ConfigRequestHdr = HiiConstructConfigHdr (&gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle); + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); + ASSERT (ConfigRequest != NULL); + AllocatedRequest = TRUE; + BufferSize = sizeof (IP4_CONFIG_IFR_NVDATA); + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); + FreePool (ConfigRequestHdr); + } + + // + // Convert buffer data to by helper function BlockToConfig() + // + Status = gHiiConfigRouting->BlockToConfig ( + gHiiConfigRouting, + ConfigRequest, + (UINT8 *) IfrFormNvData, + sizeof (IP4_CONFIG_IFR_NVDATA), + &FormResult, + Progress + ); + + FreePool (IfrFormNvData); + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + ConfigRequest = NULL; + } + + if (EFI_ERROR (Status)) { + goto Failure; + } } - Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, IfrDeviceNvData); - if (EFI_ERROR (Status)) { - FreePool (IfrDeviceNvData); + if (Request == NULL) { + Size = StrLen (DeviceResult); + Size = Size + 1; + Size = Size + StrLen (FormResult) + 1; + *Results = AllocateZeroPool (Size * sizeof (CHAR16)); + ASSERT (*Results != NULL); + StrPointer = *Results; + StrCpyS (StrPointer, Size, DeviceResult); + StrPointer = StrPointer + StrLen (StrPointer); + *StrPointer = L'&'; + StrCpyS (StrPointer + 1, StrLen (FormResult) + 1, FormResult); + FreePool (DeviceResult); + FreePool (FormResult); + } else if (HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { + *Results = DeviceResult; + } else if (HiiIsConfigHdrMatch (Request, &gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { + *Results = FormResult; + } else { return EFI_NOT_FOUND; } +Failure: // - // Convert buffer data to by helper function BlockToConfig() + // Set Progress string to the original request string. // - HiiConfigRouting = Private->ConfigRouting; - Status = HiiConfigRouting->BlockToConfig ( - HiiConfigRouting, - Request, - (UINT8 *) IfrDeviceNvData, - NIC_ITEM_CONFIG_SIZE, - Results, - Progress - ); - - FreePool (IfrDeviceNvData); + if (Request == NULL) { + *Progress = NULL; + } else if (StrStr (Request, L"OFFSET") == NULL) { + *Progress = Request + StrLen (Request); + } return Status; } @@ -428,191 +558,90 @@ Ip4DeviceRouteConfig ( EFI_STATUS Status; UINTN BufferSize; NIC_IP4_CONFIG_INFO *IfrDeviceNvData; + IP4_CONFIG_IFR_NVDATA *IfrFormNvData; NIC_IP4_CONFIG_INFO *NicInfo; - IP4_FORM_CALLBACK_INFO *Private; - EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; IP4_CONFIG_INSTANCE *Ip4ConfigInstance; EFI_MAC_ADDRESS ZeroMac; - if (Configuration == NULL) { + if (Configuration == NULL || Progress == NULL) { return EFI_INVALID_PARAMETER; } - *Progress = Configuration; - // - // Check Routing data in . + // Reclaim Ip4Config variable // - if (!HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { - return EFI_NOT_FOUND; - } + Ip4ConfigReclaimVariable (); - Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); - Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO (Private); + *Progress = Configuration; - IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); - if (IfrDeviceNvData == NULL) { - return EFI_OUT_OF_RESOURCES; - } + Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This); // - // Convert buffer data to by helper function BlockToConfig() + // Check Routing data in . // - 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) { - BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * IfrDeviceNvData->Ip4Info.RouteTableSize; - NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData); - Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE); - } else { - Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE); + if (HiiIsConfigHdrMatch (Configuration, &gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { + // + // Convert buffer data to by helper function BlockToConfig() + // + IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA)); + if (IfrFormNvData == NULL) { + return EFI_OUT_OF_RESOURCES; } - } - - FreePool (IfrDeviceNvData); - return Status; -} + BufferSize = NIC_ITEM_CONFIG_SIZE; + Status = gHiiConfigRouting->ConfigToBlock ( + gHiiConfigRouting, + Configuration, + (UINT8 *) IfrFormNvData, + &BufferSize, + Progress + ); + if (!EFI_ERROR (Status)) { + Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance); + } -/** - 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. + FreePool (IfrFormNvData); - @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. + } else if (HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { - @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 - ) -{ - if (Request == NULL || Progress == NULL || Results == NULL) { - return EFI_INVALID_PARAMETER; - } - *Progress = Request; - return EFI_NOT_FOUND; -} + IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); + if (IfrDeviceNvData == NULL) { + return EFI_OUT_OF_RESOURCES; + } -/** - 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. + BufferSize = NIC_ITEM_CONFIG_SIZE; + Status = gHiiConfigRouting->ConfigToBlock ( + gHiiConfigRouting, + 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) { + BufferSize = SIZEOF_NIC_IP4_CONFIG_INFO (IfrDeviceNvData); + NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData); + if (NicInfo == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE); + FreePool (NicInfo); + } else { + ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO)); + Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE); + } + } - @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. + FreePool (IfrDeviceNvData); - @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 - ) -{ - if (Configuration == NULL || Progress == NULL) { - return EFI_INVALID_PARAMETER; - } + } else { - *Progress = Configuration; - if (!HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { return EFI_NOT_FOUND; } - *Progress = Configuration + StrLen (Configuration); - return EFI_SUCCESS; + return Status; + } /** @@ -653,165 +682,83 @@ Ip4FormCallback ( ) { 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; + if (Action == EFI_BROWSER_ACTION_CHANGED) { + Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This); - 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; + IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA)); + if (IfrFormNvData == NULL) { + return EFI_OUT_OF_RESOURCES; } - break; - - case KEY_LOCAL_IP: - UnicodeStrToAsciiStr (IfrFormNvData->StationAddress, Ip4String); - Status = Ip4AsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); - Status = EFI_INVALID_PARAMETER; - } 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)); + // + // Retrive uncommitted data from Browser + // + if (!HiiGetBrowserData (&gNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData)) { + FreePool (IfrFormNvData); + return EFI_NOT_FOUND; } - break; - - case KEY_GATE_WAY: - UnicodeStrToAsciiStr (IfrFormNvData->GatewayAddress, Ip4String); - Status = Ip4AsciiStrToIp (Ip4String, &Gateway.v4); - if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL); - Status = EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4)); - } + Status = EFI_SUCCESS; - break; - - case KEY_SAVE_CHANGES: - Ip4ConfigInstance = Private->Current->Ip4ConfigInstance; - NicInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE)); - ASSERT (NicInfo != NULL); - - 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; - } + switch (QuestionId) { + case KEY_LOCAL_IP: + Status = Ip4StrToIp (IfrFormNvData->StationAddress, &HostIp.v4); + if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); + Status = EFI_INVALID_PARAMETER; + } else { + CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, &HostIp.v4, sizeof (HostIp.v4)); } - 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); + break; - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; - break; + case KEY_SUBNET_MASK: + Status = Ip4StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4); + if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL); + Status = EFI_INVALID_PARAMETER; + } else { + CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4)); + } - 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); + break; - Ip4ConfigInstance = ConfigFormEntry->Ip4ConfigInstance; + case KEY_GATE_WAY: + Status = Ip4StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4); + if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL); + Status = EFI_INVALID_PARAMETER; + } else { + CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, &Gateway.v4, sizeof (Gateway.v4)); + } - UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString); - DeviceFormTitleToken = (EFI_STRING_ID) STR_IP4_DEVICE_FORM_TITLE; - HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL); + break; - Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData); + case KEY_SAVE_CHANGES: + Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance); + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; + break; - Private->Current = ConfigFormEntry; + default: + break; } - break; - } - - if (!EFI_ERROR (Status)) { + FreePool (IfrFormNvData); - // - // Pass changed uncommitted data back to Form Browser - // - HiiSetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData, NULL); + return Status; } - FreePool (IfrFormNvData); - return Status; + // + // All other action return unsupported. + // + return EFI_UNSUPPORTED; } /** @@ -825,44 +772,96 @@ Ip4FormCallback ( **/ EFI_STATUS Ip4ConfigDeviceInit ( - IN IP4_CONFIG_INSTANCE *Instance + 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; - } + EFI_STATUS Status; + EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; + VENDOR_DEVICE_PATH VendorDeviceNode; + EFI_SERVICE_BINDING_PROTOCOL *MnpSb; + CHAR16 *MacString; + CHAR16 MenuString[128]; + CHAR16 PortString[128]; + CHAR16 *OldMenuString; - CallbackInfo = &Instance->Ip4FormCallbackInfo; + ConfigAccess = &Instance->HiiConfigAccessProtocol; + ConfigAccess->ExtractConfig = Ip4DeviceExtractConfig; + ConfigAccess->RouteConfig = Ip4DeviceRouteConfig; + ConfigAccess->Callback = Ip4FormCallback; - CallbackInfo->Signature = IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE; - CallbackInfo->HiiDatabase = HiiDatabase; + // + // Construct device path node for EFI HII Config Access protocol, + // which consists of controller physical device path and one hardware + // vendor guid node. + // + ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH)); + VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH; + VendorDeviceNode.Header.SubType = HW_VENDOR_DP; - CallbackInfo->ConfigAccess.ExtractConfig = Ip4DeviceExtractConfig; - CallbackInfo->ConfigAccess.RouteConfig = Ip4DeviceRouteConfig; - CallbackInfo->ConfigAccess.Callback = NULL; + CopyGuid (&VendorDeviceNode.Guid, &gEfiNicIp4ConfigVariableGuid); - Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting); - if (EFI_ERROR (Status)) { - return Status; - } + SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH)); + Instance->HiiVendorDevicePath = AppendDevicePathNode ( + Instance->ParentDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode + ); - CallbackInfo->DriverHandle = Instance->Controller; + Instance->ChildHandle = NULL; // - // Install Device Path Protocol and Config Access protocol to driver handle + // Install Device Path Protocol and Config Access protocol on new handle // Status = gBS->InstallMultipleProtocolInterfaces ( - &CallbackInfo->DriverHandle, + &Instance->ChildHandle, + &gEfiDevicePathProtocolGuid, + Instance->HiiVendorDevicePath, &gEfiHiiConfigAccessProtocolGuid, - &CallbackInfo->ConfigAccess, + ConfigAccess, NULL ); + if (!EFI_ERROR (Status)) { + // + // Open the Parent Handle for the child + // + Status = gBS->OpenProtocol ( + Instance->Controller, + &gEfiManagedNetworkServiceBindingProtocolGuid, + (VOID **) &MnpSb, + Instance->Image, + Instance->ChildHandle, + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); + } + ASSERT_EFI_ERROR (Status); + // + // Publish our HII data + // + Instance->RegisteredHandle = HiiAddPackages ( + &gNicIp4ConfigNvDataGuid, + Instance->ChildHandle, + Ip4ConfigDxeStrings, + Ip4ConfigDxeBin, + NULL + ); + if (Instance->RegisteredHandle == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Append MAC string in the menu help string and tile help string + // + Status = NetLibGetMacString (Instance->Controller, Instance->Image, &MacString); + if (!EFI_ERROR (Status)) { + OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_HELP), NULL); + UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString); + HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_HELP), MenuString, NULL); + + UnicodeSPrint (PortString, 128, L"MAC:%s", MacString); + HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_HELP), PortString, NULL); + FreePool (MacString); + } + return Status; } @@ -879,282 +878,32 @@ Ip4ConfigDeviceUnload ( IN IP4_CONFIG_INSTANCE *Instance ) { - IP4_FORM_CALLBACK_INFO *CallbackInfo; - - CallbackInfo = &Instance->Ip4FormCallbackInfo; - - Ip4ConfigUpdateForm (Instance, FALSE); - // - // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL + // Remove HII package list // - 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); - } + HiiRemovePackages (Instance->RegisteredHandle); // - // Remove HII package list + // Close the child handle // - mCallbackInfo->HiiDatabase->RemovePackageList ( - mCallbackInfo->HiiDatabase, - mCallbackInfo->RegisteredHandle - ); + gBS->CloseProtocol ( + Instance->Controller, + &gEfiManagedNetworkServiceBindingProtocolGuid, + Instance->Image, + Instance->ChildHandle + ); // // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL // gBS->UninstallMultipleProtocolInterfaces ( - mCallbackInfo->DriverHandle, + Instance->ChildHandle, &gEfiDevicePathProtocolGuid, - &mIp4ConifgHiiVendorDevicePath, + Instance->HiiVendorDevicePath, &gEfiHiiConfigAccessProtocolGuid, - &mCallbackInfo->ConfigAccess, + &Instance->HiiConfigAccessProtocol, 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; - 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; - - Status = NetLibGetMacString (Instance->Controller, Instance->Image, &ConfigFormEntry->MacString); - ASSERT (Status == EFI_SUCCESS); - - // - // 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); - FreePool (ConfigFormEntry->MacString); - 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; -}