/** Convert the network configuration data into the IFR data. @param[in] Ip4ConfigInstance The IP4Config instance @param[out] IfrFormNvData The IFR nv data. **/ VOID Ip4ConfigConvertDeviceConfigDataToIfrNvData ( IN IP4_CONFIG_INSTANCE *Ip4ConfigInstance, OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData ) { NIC_IP4_CONFIG_INFO *NicConfig; 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; } }
/** This function allows the caller to request the current configuration for one or more named elements. The resulting string is in <ConfigAltResp> 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=<StringToken>". That <StringToken> (when converted from Hex UNICODE to binary) is a reference to a string in the associated string pack. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. @param[in] Request A null-terminated Unicode string in <ConfigRequest> 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 <MultiConfigRequest> 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 <ConfigAltResp> format which has all values filled in for the names in the Request string. String to be allocated by the called function. @retval EFI_SUCCESS The Results string is filled with the values corresponding to all requested names. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the results that must be stored awaiting possible future protocols. @retval EFI_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 <ConfigHdr> in order to process the names. @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set to most recent & before the error or the beginning of the string. @retval EFI_INVALID_PARAMETER Unknown name. Progress points to the & before the name in question.Currently not implemented. **/ EFI_STATUS EFIAPI Ip4DeviceExtractConfig ( IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Request, OUT EFI_STRING *Progress, OUT EFI_STRING *Results ) { EFI_STATUS Status; UINTN ConfigLen; NIC_IP4_CONFIG_INFO *IfrDeviceNvData; IP4_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 (Progress == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; } *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 <ConfigHdr>. // 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; } ConfigLen = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2; Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, IfrDeviceNvData); if (EFI_ERROR (Status)) { FreePool (IfrDeviceNvData); return EFI_NOT_FOUND; } 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 <ConfigHdr> 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 <ConfigResp> 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; } } if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { IfrFormNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); 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 <ConfigHdr> template // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator // ConfigRequestHdr = HiiConstructConfigHdr (&mNicIp4ConfigNvDataGuid, 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 <ConfigResp> 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; } } if (Request == NULL) { Size = StrLen (DeviceResult); Size = Size + 1; Size = Size + StrLen (FormResult) + 1; *Results = AllocateZeroPool (Size * sizeof (CHAR16)); ASSERT (*Results != NULL); StrPointer = *Results; StrCpy (StrPointer, DeviceResult); StrPointer = StrPointer + StrLen (StrPointer); *StrPointer = L'&'; StrCpy (StrPointer + 1, FormResult); FreePool (DeviceResult); FreePool (FormResult); } else if (HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { *Results = DeviceResult; } else if (HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) { *Results = FormResult; } else { return EFI_NOT_FOUND; } Failure: // // Set Progress string to the original request string. // if (Request == NULL) { *Progress = NULL; } else if (StrStr (Request, L"OFFSET") == NULL) { *Progress = Request + StrLen (Request); } return Status; }