1)Remove “Back to Previous Page'”, since it cannot go back to “Device Manager page.

2)Add Configure item in page.
3)Add more security check when storing IP setting, to correctly sync the operations between Ip4ConfigDxe and ifconfig.efi


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9693 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
vanjeff 2010-01-08 05:00:19 +00:00
parent 1ace000135
commit c22b6cdfa7
6 changed files with 117 additions and 70 deletions

View File

@ -1,7 +1,7 @@
/** @file
Header file for IP4Config driver.
Copyright (c) 2006 - 2009, Intel Corporation.<BR>
Copyright (c) 2006 - 2010, Intel Corporation.<BR>
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<BR>
@ -79,7 +79,8 @@ typedef struct {
#pragma pack()
typedef struct _IP4CONFIG_CALLBACK_INFO {
BOOLEAN Enabled;
BOOLEAN Configured;
BOOLEAN DhcpEnabled;
EFI_IPv4_ADDRESS LocalIp;
EFI_IPv4_ADDRESS SubnetMask;
EFI_IPv4_ADDRESS Gateway;

View File

@ -1,7 +1,7 @@
/** @file
The driver binding for IP4 CONFIG protocol.
Copyright (c) 2006 - 2009, Intel Corporation.<BR>
Copyright (c) 2006 - 2010, Intel Corporation.<BR>
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<BR>
@ -158,7 +158,7 @@ Ip4ConfigDriverBindingStart (
EFI_STATUS Status;
UINT32 Index;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
Status = gBS->HandleProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,

View File

@ -1,7 +1,7 @@
/** @file
Vfr file for IP4 config.
Copyright (c) 2009, Intel Corporation.<BR>
Copyright (c) 2009 - 2010, Intel Corporation.<BR>
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
@ -29,40 +29,52 @@ formset
form formid = FORMID_MAIN_FORM,
title = STRING_TOKEN(STR_IP4_DEVICE_FORM_TITLE);
checkbox varid = EfiNicIp4ConfigVariable.DhcpEnable,
prompt = STRING_TOKEN(STR_IP4_ENABLE_DHCP),
help = STRING_TOKEN(STR_IP4_ENABLE_DHCP),
checkbox varid = EfiNicIp4ConfigVariable.Configure,
prompt = STRING_TOKEN(STR_IP4_CONFIGURE),
help = STRING_TOKEN(STR_IP4_CONFIGURE),
flags = INTERACTIVE,
key = KEY_DHCP_ENABLE,
key = KEY_ENABLE,
endcheckbox;
suppressif ideqval EfiNicIp4ConfigVariable.DhcpEnable == 0x01;
string varid = EfiNicIp4ConfigVariable.StationAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_IP_ADDRESS),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_LOCAL_IP,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
suppressif ideqval EfiNicIp4ConfigVariable.Configure == 0x00;
string varid = EfiNicIp4ConfigVariable.SubnetMask,
prompt = STRING_TOKEN(STR_IP4_LOCAL_MASK),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_SUBNET_MASK,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
checkbox varid = EfiNicIp4ConfigVariable.DhcpEnable,
prompt = STRING_TOKEN(STR_IP4_ENABLE_DHCP),
help = STRING_TOKEN(STR_IP4_ENABLE_DHCP),
flags = INTERACTIVE,
key = KEY_DHCP_ENABLE,
endcheckbox;
endif;
suppressif ideqval EfiNicIp4ConfigVariable.DhcpEnable == 0x01 OR ideqval EfiNicIp4ConfigVariable.Configure == 0x00;
string varid = EfiNicIp4ConfigVariable.StationAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_IP_ADDRESS),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_LOCAL_IP,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
string varid = EfiNicIp4ConfigVariable.SubnetMask,
prompt = STRING_TOKEN(STR_IP4_LOCAL_MASK),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_SUBNET_MASK,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
string varid = EfiNicIp4ConfigVariable.GatewayAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_GATEWAY),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_GATE_WAY,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
string varid = EfiNicIp4ConfigVariable.GatewayAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_GATEWAY),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_GATE_WAY,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
endif;
subtitle text = STRING_TOKEN(STR_NULL);
@ -73,11 +85,6 @@ formset
flags = INTERACTIVE,
key = KEY_SAVE_CHANGES;
goto FORMID_MAIN_FORM,
prompt = STRING_TOKEN (STR_RETURN_MAIN_FORM),
help = STRING_TOKEN (STR_RETURN_MAIN_FORM),
flags = 0;
endform;
endformset;

View File

@ -1,7 +1,7 @@
/** @file
Helper functions for configuring or getting the parameters relating to Ip4.
Copyright (c) 2009, Intel Corporation.<BR>
Copyright (c) 2009 - 2010, Intel Corporation.<BR>
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
@ -152,13 +152,12 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
NIC_IP4_CONFIG_INFO *NicConfig;
UINTN ConfigLen;
IfrFormNvData->DhcpEnable = 1;
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)) {
IfrFormNvData->Configure = 1;
if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {
IfrFormNvData->DhcpEnable = 1;
} else {
@ -167,7 +166,10 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);
Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);
}
} else {
IfrFormNvData->Configure = 0;
}
FreePool (NicConfig);
}
@ -175,21 +177,20 @@ Ip4ConfigConvertDeviceConfigDataToIfrNvData (
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
@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.
**/
EFI_STATUS
Ip4ConfigConvertIfrNvDataToDeviceConfigData (
IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData,
IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance
)
{
EFI_STATUS Status;
EFI_IP_ADDRESS HostIp;
EFI_IP_ADDRESS SubnetMask;
EFI_IP_ADDRESS Gateway;
@ -197,16 +198,39 @@ Ip4ConfigConvertIfrNvDataToDeviceConfigData (
NIC_IP4_CONFIG_INFO *NicInfo;
EFI_IP_ADDRESS Ip;
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.Enabled) {
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;
}
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);
@ -228,8 +252,12 @@ Ip4ConfigConvertIfrNvDataToDeviceConfigData (
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));
}
NicInfo->Perment = TRUE;
@ -338,7 +366,7 @@ Ip4DeviceExtractConfig (
FreePool (IfrDeviceNvData);
return EFI_NOT_FOUND;
}
//
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
//
@ -350,7 +378,7 @@ Ip4DeviceExtractConfig (
Results,
Progress
);
FreePool (IfrDeviceNvData);
} else if (HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
@ -359,9 +387,9 @@ Ip4DeviceExtractConfig (
if (IfrFormNvData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData);
//
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
//
@ -373,7 +401,7 @@ Ip4DeviceExtractConfig (
Results,
Progress
);
FreePool (IfrFormNvData);
} else {
@ -428,7 +456,7 @@ Ip4DeviceRouteConfig (
EFI_STATUS Status;
UINTN BufferSize;
NIC_IP4_CONFIG_INFO *IfrDeviceNvData;
IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
IP4_CONFIG_IFR_NVDATA *IfrFormNvData;
NIC_IP4_CONFIG_INFO *NicInfo;
IP4_CONFIG_INSTANCE *Ip4ConfigInstance;
EFI_MAC_ADDRESS ZeroMac;
@ -462,9 +490,9 @@ Ip4DeviceRouteConfig (
Progress
);
if (!EFI_ERROR (Status)) {
Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);
Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);
}
FreePool (IfrFormNvData);
} else if (HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {
@ -486,9 +514,10 @@ Ip4DeviceRouteConfig (
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);
NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData);
Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);
} else {
ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));
Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);
}
}
@ -499,7 +528,7 @@ Ip4DeviceRouteConfig (
return EFI_NOT_FOUND;
}
return Status;
}
@ -569,11 +598,19 @@ Ip4FormCallback (
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.Enabled = FALSE;
Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = FALSE;
} else {
Ip4ConfigInstance->Ip4ConfigCallbackInfo.Enabled = TRUE;
Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = TRUE;
}
break;
@ -615,14 +652,15 @@ Ip4FormCallback (
break;
case KEY_SAVE_CHANGES:
Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);
Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance);
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
break;
default:
break;
}
@ -690,7 +728,7 @@ Ip4ConfigDeviceInit (
Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->ChildHandle,
&gEfiDevicePathProtocolGuid,
Instance->HiiVendorDevicePath,
Instance->HiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
ConfigAccess,
NULL
@ -704,13 +742,13 @@ Ip4ConfigDeviceInit (
&gEfiManagedNetworkServiceBindingProtocolGuid,
(VOID **) &MnpSb,
Instance->Image,
Instance->ChildHandle,
Instance->ChildHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
}
ASSERT_EFI_ERROR (Status);
//
// Publish our HII data
//
@ -733,7 +771,7 @@ Ip4ConfigDeviceInit (
OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), NULL);
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), MenuString, NULL);
UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_TITLE), PortString, NULL);
FreePool (MacString);
@ -776,7 +814,7 @@ Ip4ConfigDeviceUnload (
gBS->UninstallMultipleProtocolInterfaces (
Instance->ChildHandle,
&gEfiDevicePathProtocolGuid,
Instance->HiiVendorDevicePath,
Instance->HiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
&Instance->HiiConfigAccessProtocol,
NULL

View File

@ -1,7 +1,7 @@
/** @file
Routines used to operate the Ip4 configure variable.
Copyright (c) 2009, Intel Corporation.<BR>
Copyright (c) 2009 - 2010, Intel Corporation.<BR>
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<BR>
@ -23,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define FORMID_MAIN_FORM 1
#define FORMID_DEVICE_FORM 2
#define KEY_ENABLE 0x100
#define KEY_DHCP_ENABLE 0x101
#define KEY_LOCAL_IP 0x102
#define KEY_SUBNET_MASK 0x103
@ -40,7 +41,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
///
typedef struct {
UINT16 NicAddr[3]; ///< NIC MAC address
UINT8 Reserved; ///< Reserved bits
UINT8 Configure; ///< NIC configure status
UINT8 DhcpEnable; ///< Static or DHCP
CHAR16 StationAddress[IP4_STR_MAX_SIZE]; ///< IP addresses
CHAR16 SubnetMask[IP4_STR_MAX_SIZE]; ///< Subnet address