diff options
Diffstat (limited to 'MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c')
-rw-r--r-- | MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c | 124 |
1 files changed, 53 insertions, 71 deletions
diff --git a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c index c0d27aac78..fa78678ade 100644 --- a/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c +++ b/MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
#include "Ip4ConfigNv.h"
+#include "NicIp4Variable.h"
EFI_GUID mNicIp4ConfigNvDataGuid = EFI_NIC_IP4_CONFIG_NVDATA_GUID;
@@ -61,14 +62,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
)
{
@@ -77,15 +78,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++;
}
@@ -95,7 +96,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.
@@ -103,7 +104,7 @@ Ip4AsciiStrToIp ( return EFI_INVALID_PARAMETER;
}
- if (*Str == '.') {
+ if (*Str == L'.') {
//
// Skip the delimiter.
//
@@ -148,15 +149,10 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData ( OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData
)
{
- EFI_STATUS Status;
- NIC_IP4_CONFIG_INFO *NicConfig;
- UINTN ConfigLen;
-
- 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)) {
+ NIC_IP4_CONFIG_INFO *NicConfig;
+
+ NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);
+ if (NicConfig != NULL) {
IfrFormNvData->Configure = 1;
if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {
IfrFormNvData->DhcpEnable = 1;
@@ -166,17 +162,18 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData ( Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);
Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);
}
+
+ FreePool (NicConfig);
} else {
IfrFormNvData->Configure = 0;
}
-
- FreePool (NicConfig);
}
/**
Convert the IFR data into the network configuration data and set the IP
configure parameters for the NIC.
+ @param[in] IfrFormNvData The IFR NV data.
@param[in, out] Ip4ConfigInstance The IP4Config instance.
@retval EFI_SUCCESS The configure parameter for this NIC was
@@ -187,6 +184,7 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData ( **/
EFI_STATUS
Ip4ConfigConvertIfrNvDataToDeviceConfigData (
+ IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData,
IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance
)
{
@@ -198,6 +196,14 @@ Ip4ConfigConvertIfrNvDataToDeviceConfigData ( NIC_IP4_CONFIG_INFO *NicInfo;
EFI_IP_ADDRESS Ip;
+ ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));
+
+ 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
@@ -332,8 +338,8 @@ Ip4DeviceExtractConfig ( )
{
EFI_STATUS Status;
- UINTN ConfigLen;
NIC_IP4_CONFIG_INFO *IfrDeviceNvData;
+ NIC_IP4_CONFIG_INFO *NicConfig;
IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
EFI_STRING ConfigRequestHdr;
@@ -367,12 +373,12 @@ Ip4DeviceExtractConfig ( 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);
+ 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)) {
@@ -415,11 +421,11 @@ Ip4DeviceExtractConfig ( if (EFI_ERROR (Status)) {
goto Failure;
}
- }
-
+ }
+
if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
- IfrFormNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
+ IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));
if (IfrFormNvData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -442,7 +448,7 @@ Ip4DeviceExtractConfig ( UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
}
-
+
//
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
//
@@ -499,7 +505,7 @@ Failure: } else if (StrStr (Request, L"OFFSET") == NULL) {
*Progress = Request + StrLen (Request);
}
-
+
return Status;
}
@@ -556,6 +562,11 @@ Ip4DeviceRouteConfig ( return EFI_INVALID_PARAMETER;
}
+ //
+ // Reclaim Ip4Config variable
+ //
+ Ip4ConfigReclaimVariable ();
+
*Progress = Configuration;
Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);
@@ -581,7 +592,7 @@ Ip4DeviceRouteConfig ( Progress
);
if (!EFI_ERROR (Status)) {
- Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);
+ Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);
}
FreePool (IfrFormNvData);
@@ -604,9 +615,13 @@ Ip4DeviceRouteConfig ( 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;
+ 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);
@@ -662,7 +677,6 @@ Ip4FormCallback ( )
{
IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
- CHAR8 Ip4String[IP4_STR_MAX_SIZE];
IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
EFI_IP_ADDRESS HostIp;
EFI_IP_ADDRESS SubnetMask;
@@ -670,11 +684,11 @@ Ip4FormCallback ( EFI_STATUS Status;
EFI_INPUT_KEY Key;
- if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) { + if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
//
// Do nothing for UEFI OPEN/CLOSE Action
//
- return EFI_SUCCESS; + return EFI_SUCCESS;
}
Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);
@@ -695,27 +709,8 @@ Ip4FormCallback ( Status = EFI_SUCCESS;
switch (QuestionId) {
-
- case KEY_ENABLE:
- if (IfrFormNvData->Configure == 0) {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = FALSE;
- } else {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = TRUE;
- }
- break;
-
- case KEY_DHCP_ENABLE:
- if (IfrFormNvData->DhcpEnable == 0) {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE;
- } else {
- Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE;
- }
-
- break;
-
case KEY_LOCAL_IP:
- UnicodeStrToAsciiStr (IfrFormNvData->StationAddress, Ip4String);
- Status = Ip4AsciiStrToIp (Ip4String, &HostIp.v4);
+ 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;
@@ -726,10 +721,9 @@ Ip4FormCallback ( break;
case KEY_SUBNET_MASK:
- UnicodeStrToAsciiStr (IfrFormNvData->SubnetMask, Ip4String);
- Status = Ip4AsciiStrToIp (Ip4String, &SubnetMask.v4);
+ 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 SubnetMask!", NULL);
+ 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));
@@ -738,8 +732,7 @@ Ip4FormCallback ( break;
case KEY_GATE_WAY:
- UnicodeStrToAsciiStr (IfrFormNvData->GatewayAddress, Ip4String);
- Status = Ip4AsciiStrToIp (Ip4String, &Gateway.v4);
+ 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;
@@ -750,25 +743,14 @@ Ip4FormCallback ( break;
case KEY_SAVE_CHANGES:
-
- Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);
-
+ Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
-
break;
default:
-
break;
}
- if (!EFI_ERROR (Status)) {
- //
- // Pass changed uncommitted data back to Form Browser
- //
- HiiSetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData, NULL);
- }
-
FreePool (IfrFormNvData);
return Status;
|