jiaxinwu
2015-07-03 03:39:17 UTC
Version4 include small update from reviewer's comments:
Change and add some help messages in uni file.
Revert copyright year in UefiShellNetwork1CommandsLib.c file since there is no code change in this file.
This patch update ShellPkg ping/ifconfig library source code to consume Ip4Config2 protocol.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: jiaxinwu <***@intel.com>
---
.../UefiShellNetwork1CommandsLib/Ifconfig.c | 2439 ++++++++------------
.../Library/UefiShellNetwork1CommandsLib/Ping.c | 19 +-
.../UefiShellNetwork1CommandsLib.h | 8 +-
.../UefiShellNetwork1CommandsLib.inf | 6 +-
.../UefiShellNetwork1CommandsLib.uni | Bin 20112 -> 20078 bytes
5 files changed, 990 insertions(+), 1482 deletions(-)
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
index fa00d6c..6977d6b 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
@@ -1,7 +1,7 @@
/** @file
- The implementation for ifcommand shell command.
+ The implementation for Shell command ifconfig based on IP4Config2 protocol.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -9,1774 +9,1285 @@
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
**/
#include "UefiShellNetwork1CommandsLib.h"
-#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE)
-#define EFI_IP4_TO_U32(EfiIpAddr) (*(IP4_ADDR*)((EfiIpAddr).Addr))
-
-BOOLEAN mIp4ConfigExist = FALSE;
-STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;
+typedef enum {
+ IfConfigOpList = 1,
+ IfConfigOpSet = 2,
+ IfConfigOpClear = 3
+} IFCONFIG_OPCODE;
+
+typedef enum {
+ VarCheckReserved = -1,
+ VarCheckOk = 0,
+ VarCheckDuplicate,
+ VarCheckConflict,
+ VarCheckUnknown,
+ VarCheckLackValue,
+ VarCheckOutOfMem
+} VAR_CHECK_CODE;
+
+typedef enum {
+ FlagTypeSingle = 0,
+ FlagTypeNeedVar,
+ FlagTypeNeedSet,
+ FlagTypeSkipUnknown
+} VAR_CHECK_FLAG_TYPE;
+
+#define MACADDRMAXSIZE 32
+
+typedef struct _IFCONFIG_INTERFACE_CB {
+ EFI_HANDLE NicHandle;
+ LIST_ENTRY Link;
+ EFI_IP4_CONFIG2_PROTOCOL *IfCfg;
+ EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
+ EFI_IP4_CONFIG2_POLICY Policy;
+ UINT32 DnsCnt;
+ EFI_IPv4_ADDRESS DnsAddr[1];
+} IFCONFIG_INTERFACE_CB;
+
+typedef struct _ARG_LIST ARG_LIST;
+
+struct _ARG_LIST {
+ ARG_LIST *Next;
+ CHAR16 *Arg;
+};
+
+typedef struct _IFCONFIG4_PRIVATE_DATA {
+ LIST_ENTRY IfList;
+
+ UINT32 OpCode;
+ CHAR16 *IfName;
+ ARG_LIST *VarArg;
+} IFCONFIG_PRIVATE_DATA;
+
+typedef struct _VAR_CHECK_ITEM{
+ CHAR16 *FlagStr;
+ UINT32 FlagID;
+ UINT32 ConflictMask;
+ VAR_CHECK_FLAG_TYPE FlagType;
+} VAR_CHECK_ITEM;
+
+SHELL_PARAM_ITEM mIfConfigCheckList[] = {
+ {
+ L"-b",
+ TypeFlag
+ },
+ {
+ L"-l",
+ TypeValue
+ },
+ {
+ L"-r",
+ TypeValue
+ },
+ {
+ L"-c",
+ TypeValue
+ },
+ {
+ L"-s",
+ TypeMaxValue
+ },
+ {
+ NULL,
+ TypeMax
+ },
+};
+
+VAR_CHECK_ITEM mSetCheckList[] = {
+ {
+ L"static",
+ 0x00000001,
+ 0x00000001,
+ FlagTypeSingle
+ },
+ {
+ L"dhcp",
+ 0x00000002,
+ 0x00000001,
+ FlagTypeSingle
+ },
+ {
+ L"dns",
+ 0x00000008,
+ 0x00000004,
+ FlagTypeSingle
+ },
+ {
+ NULL,
+ 0x0,
+ 0x0,
+ FlagTypeSkipUnknown
+ },
+};
-STATIC CONST UINTN SecondsToNanoSeconds = 10000000;
-STATIC CONST CHAR16 DhcpString[5] = L"DHCP";
-STATIC CONST CHAR16 StaticString[7] = L"STATIC";
STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";
-typedef struct {
- LIST_ENTRY Link;
- EFI_HANDLE Handle;
- NIC_ADDR NicAddress;
- CHAR16 Name[IP4_NIC_NAME_LENGTH];
- BOOLEAN MediaPresentSupported;
- BOOLEAN MediaPresent;
- EFI_IP4_CONFIG_PROTOCOL *Ip4Config;
- NIC_IP4_CONFIG_INFO *ConfigInfo;
-} NIC_INFO;
-
-typedef struct {
- EFI_IP_ADDRESS DestIp;
- EFI_MAC_ADDRESS DestMac;
- EFI_IP_ADDRESS LocalIp;
- EFI_MAC_ADDRESS LocalMac;
- UINT8 MacLen;
- EFI_EVENT OnResolved;
- BOOLEAN Duplicate;
-} ARP_REQUEST;
-
-STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
- {L"-c", TypeValue},
- {L"-l", TypeValue},
- {L"-s", TypeMaxValue},
- {NULL, TypeMax}
- };
-
-STATIC LIST_ENTRY NicInfoList;
-STATIC BOOLEAN ArpResolved;
-STATIC BOOLEAN mTimeout;
-
/**
- Count the space delimited items in a string.
-
- @param[in] String A pointer to the string to count.
-
- @return The number of space-delimited items.
- @retval 0xFF an error occured.
-**/
-UINT8
-EFIAPI
-CountSubItems (
- IN CONST CHAR16 *String
- )
-{
- CONST CHAR16 *Walker;
- UINT8 Count;
-
- if (String == NULL || *String == CHAR_NULL) {
- return (0xFF);
- }
+ Split a string with specified separator and save the substring to a list.
- for (Walker = String, Count = 0 ; Walker != NULL && *Walker != CHAR_NULL ; Walker = (StrStr(Walker, L" ")==NULL?NULL:StrStr(Walker, L" ")+1), Count++);
- return (Count);
-}
+ @param[in] String The pointer of the input string.
+ @param[in] Separator The specified separator.
-/**
- Find the NIC_INFO by the specified nic name.
+ @return The pointer of headnode of ARG_LIST.
- @param[in] Name The pointer to the string containing the NIC name.
-
- @return The pointer to the NIC_INFO if there is a NIC_INFO named by Name.
- @retval NULL No NIC_INFO was found for Name.
**/
-NIC_INFO*
-EFIAPI
-IfconfigFindNicByName (
- IN CONST CHAR16 *Name
+ARG_LIST *
+SplitStrToList (
+ IN CONST CHAR16 *String,
+ IN CHAR16 Separator
)
{
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
- NIC_INFO *Info;
- CHAR16 *TempString;
-
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- Info = BASE_CR (Entry, NIC_INFO, Link);
- TempString = (CHAR16*)Info->Name;
+ CHAR16 *Str;
+ CHAR16 *ArgStr;
+ ARG_LIST *ArgList;
+ ARG_LIST *ArgNode;
- if (StringNoCaseCompare (&Name, &TempString) == 0) {
- return Info;
- }
+ if (*String == L'\0') {
+ return NULL;
}
- return NULL;
-}
-
-/**
- Tests whether a child handle is a child device of the controller.
-
- @param[in] ControllerHandle A handle for a (parent) controller to test.
- @param[in] ChildHandle A child handle to test.
- @param[in] ProtocolGuid Supplies the protocol that the child controller
- opens on its parent controller.
-
- @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
- @retval EFI_UNSUPPORTED ChildHandle is not a child of the ControllerHandle.
-**/
-EFI_STATUS
-EFIAPI
-TestChildHandle (
- IN CONST EFI_HANDLE ControllerHandle,
- IN CONST EFI_HANDLE ChildHandle,
- IN CONST EFI_GUID *ProtocolGuid
- )
-{
- EFI_STATUS Status;
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
- UINTN EntryCount;
- UINTN Index;
-
- ASSERT (ProtocolGuid != NULL);
-
//
- // Retrieve the list of agents that are consuming the specific protocol
- // on ControllerHandle.
+ // Copy the CONST string to a local copy.
//
- Status = gBS->OpenProtocolInformation (
- ControllerHandle,
- (EFI_GUID *) ProtocolGuid,
- &OpenInfoBuffer,
- &EntryCount
- );
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
+ Str = AllocateCopyPool (StrSize (String), String);
+ ASSERT (Str != NULL);
+ ArgStr = Str;
//
- // Inspect if ChildHandle is one of the agents.
+ // init a node for the list head.
//
- Status = EFI_UNSUPPORTED;
- for (Index = 0; Index < EntryCount; Index++) {
- if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&
- (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
- Status = EFI_SUCCESS;
- break;
- }
- }
-
- FreePool (OpenInfoBuffer);
- return Status;
-}
-
-/**
- Get the child handle of the NIC handle.
-
- @param[in] Controller Routing information: GUID.
- @param[out] ChildHandle Returned child handle.
-
- @retval EFI_SUCCESS Successfully to get child handle.
-**/
-EFI_STATUS
-GetChildHandle (
- IN EFI_HANDLE Controller,
- OUT EFI_HANDLE *ChildHandle
- )
-{
- EFI_STATUS Status;
- EFI_HANDLE *Handles;
- UINTN HandleCount;
- UINTN Index;
- EFI_DEVICE_PATH_PROTOCOL *ChildDeviceDevicePath;
- VENDOR_DEVICE_PATH *VendorDeviceNode;
+ ArgNode = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
+ ASSERT (ArgNode != NULL);
+ ArgList = ArgNode;
//
- // Locate all EFI Hii Config Access protocols
+ // Split the local copy and save in the list node.
//
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiHiiConfigAccessProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
- );
- if (EFI_ERROR (Status) || (HandleCount == 0)) {
- return Status;
- }
-
- Status = EFI_NOT_FOUND;
-
- for (Index = 0; Index < HandleCount; Index++) {
-
- Status = TestChildHandle (Controller, Handles[Index], &gEfiManagedNetworkServiceBindingProtocolGuid);
- if (!EFI_ERROR (Status)) {
- //
- // Get device path on the child handle
- //
- Status = gBS->HandleProtocol (
- Handles[Index],
- &gEfiDevicePathProtocolGuid,
- (VOID **) &ChildDeviceDevicePath
- );
-
- if (!EFI_ERROR (Status)) {
- while (!IsDevicePathEnd (ChildDeviceDevicePath)) {
- ChildDeviceDevicePath = NextDevicePathNode (ChildDeviceDevicePath);
- //
- // Parse one instance
- //
- if (ChildDeviceDevicePath->Type == HARDWARE_DEVICE_PATH &&
- ChildDeviceDevicePath->SubType == HW_VENDOR_DP) {
- VendorDeviceNode = (VENDOR_DEVICE_PATH *) ChildDeviceDevicePath;
- if (CompareMem (&VendorDeviceNode->Guid, &gEfiNicIp4ConfigVariableGuid, sizeof (EFI_GUID)) == 0) {
- //
- // Found item matched gEfiNicIp4ConfigVariableGuid
- //
- *ChildHandle = Handles[Index];
- FreePool (Handles);
- return EFI_SUCCESS;
- }
- }
- }
- }
+ while (*Str != L'\0') {
+ if (*Str == Separator) {
+ *Str = L'\0';
+ ArgNode->Arg = ArgStr;
+ ArgStr = Str + 1;
+ ArgNode->Next = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
+ ASSERT (ArgNode->Next != NULL);
+ ArgNode = ArgNode->Next;
}
+
+ Str++;
}
- FreePool (Handles);
- return Status;
+ ArgNode->Arg = ArgStr;
+ ArgNode->Next = NULL;
+
+ return ArgList;
}
/**
- Append OFFSET/WIDTH/VALUE items at the beginning of string.
-
- @param[in, out] String The pointer to the string to append onto.
- @param[in] MaxLen The max number of UNICODE char in String
- including the terminate NULL char.
- @param[in] Offset Offset value.
- @param[in] Width Width value.
- @param[in] Block Point to data buffer.
-
- @return The count of unicode character that were appended.
-**/
-UINTN
-EFIAPI
-AppendOffsetWidthValue (
- IN OUT CHAR16 *String,
- IN UINTN MaxLen,
- IN UINTN Offset,
- IN UINTN Width,
- IN CONST UINT8 *Block
- )
-
-{
- CHAR16 *OriString;
-
- OriString = String;
-
- StrnCpyS (String, MaxLen, L"&OFFSET=", 9);
- String += StrLen (L"&OFFSET=");
- String += UnicodeSPrint (String, 20, L"%x", Offset);
-
- StrnCpyS (String, MaxLen, L"&WIDTH=", 8);
- String += StrLen (L"&WIDTH=");
- String += UnicodeSPrint (String, 20, L"%x", Width);
+ Check the correctness of input Args with '-s' option.
- if (Block != NULL) {
- StrnCpyS (String, MaxLen, L"&VALUE=", 8);
- String += StrLen (L"&VALUE=");
- while ((Width--) != 0) {
- String += UnicodeSPrint (String, 20, L"%x", Block[Width]);
- }
- }
-
- return String - OriString;
-}
+ @param[in] CheckList The pointer of VAR_CHECK_ITEM array.
+ @param[in] Name The pointer of input arg.
+ @param[in] Init The switch to execute the check.
-/**
- Converts the unicode character of the string from uppercase to lowercase.
- This is a internal function.
+ @return VarCheckOk Valid parameter or Initialize check successfully.
+ @return VarCheckDuplicate Duplicated parameter happened.
+ @return VarCheckConflict Conflicted parameter happened
+ @return VarCheckUnknown Unknown parameter.
- @param ConfigString String to be converted
**/
-CHAR16*
-EFIAPI
-HiiToLower (
- IN CHAR16 *ConfigString
- )
+VAR_CHECK_CODE
+IfConfigRetriveCheckListByName(
+ IN VAR_CHECK_ITEM *CheckList,
+ IN CHAR16 *Name,
+ IN BOOLEAN Init
+)
{
- CHAR16 *String;
- BOOLEAN Lower;
-
- //
- // Convert all hex digits in range [A-F] in the configuration header to [a-f]
- //
- for (String = ConfigString, Lower = FALSE; String != NULL && *String != L'\0'; String++) {
- if (*String == L'=') {
- Lower = TRUE;
- } else if (*String == L'&') {
- Lower = FALSE;
- } else if (Lower && *String >= L'A' && *String <= L'F') {
- *String = (CHAR16) (*String - L'A' + L'a');
- }
+ STATIC UINT32 CheckDuplicate;
+ STATIC UINT32 CheckConflict;
+ VAR_CHECK_CODE RtCode;
+ UINT32 Index;
+ VAR_CHECK_ITEM Arg;
+
+ if (Init) {
+ CheckDuplicate = 0;
+ CheckConflict = 0;
+ return VarCheckOk;
}
- return (ConfigString);
-}
-
-
-/**
- Construct <ConfigHdr> using routing information GUID/NAME/PATH.
-
- @param[in] Guid Routing information: GUID.
- @param[in] Name Routing information: NAME.
- @param[in] DriverHandle Driver handle which contains the routing information: PATH.
-
- @retval NULL An error occured.
- @return The pointer to configHdr string.
-**/
-CHAR16 *
-EFIAPI
-ConstructConfigHdr (
- IN CONST EFI_GUID *Guid,
- IN CONST CHAR16 *Name,
- IN EFI_HANDLE DriverHandle
- )
-{
- EFI_STATUS Status;
- CHAR16 *ConfigHdr;
- UINTN ConfigHdrBufferSize;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- CHAR16 *String;
- UINTN Index;
- UINT8 *Buffer;
- UINTN DevicePathLength;
- UINTN NameLength;
+ RtCode = VarCheckOk;
+ Index = 0;
+ Arg = CheckList[Index];
//
- // Get the device path from handle installed EFI HII Config Access protocol
+ // Check the Duplicated/Conflicted/Unknown input Args.
//
- Status = gBS->HandleProtocol (
- DriverHandle,
- &gEfiDevicePathProtocolGuid,
- (VOID **) &DevicePath
- );
- if (EFI_ERROR (Status)) {
- return NULL;
- }
+ while (Arg.FlagStr != NULL) {
+ if (StrCmp (Arg.FlagStr, Name) == 0) {
- DevicePathLength = GetDevicePathSize (DevicePath);
- NameLength = StrLen (Name);
- ConfigHdrBufferSize = (5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16);
- ConfigHdr = AllocateZeroPool (ConfigHdrBufferSize);
- if (ConfigHdr == NULL) {
- return NULL;
- }
+ if (CheckDuplicate & Arg.FlagID) {
+ RtCode = VarCheckDuplicate;
+ break;
+ }
- String = ConfigHdr;
- StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"GUID=", 6);
- String += StrLen (L"GUID=");
+ if (CheckConflict & Arg.ConflictMask) {
+ RtCode = VarCheckConflict;
+ break;
+ }
- //
- // Append Guid converted to <HexCh>32
- //
- for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {
- String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);
- }
+ CheckDuplicate |= Arg.FlagID;
+ CheckConflict |= Arg.ConflictMask;
+ break;
+ }
- //
- // Append L"&NAME="
- //
- StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&NAME=", 7);
- String += StrLen (L"&NAME=");
- for (Index = 0; Index < NameLength ; Index++) {
- String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);
+ Arg = CheckList[++Index];
}
-
- //
- // Append L"&PATH="
- //
- StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&PATH=", 7);
- String += StrLen (L"&PATH=");
- for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {
- String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);
+
+ if (Arg.FlagStr == NULL) {
+ RtCode = VarCheckUnknown;
}
- return (HiiToLower(ConfigHdr));
+ return RtCode;
}
/**
- Get network physical device NIC information.
+ The notify function of create event when performing a manual config.
- @param[in] Handle The network physical device handle.
- @param[out] NicAddr NIC information.
+ @param[in] Event The event this notify function registered to.
+ @param[in] Context Pointer to the context data registered to the event.
- @retval EFI_SUCCESS Get NIC information successfully.
-**/
-EFI_STATUS
+**/
+VOID
EFIAPI
-IfConfigGetNicMacInfo (
- IN EFI_HANDLE Handle,
- OUT NIC_ADDR *NicAddr
- )
+IfConfigManualAddressNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
{
- EFI_STATUS Status;
- EFI_HANDLE MnpHandle;
- EFI_SIMPLE_NETWORK_MODE SnpMode;
- EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
-
- MnpHandle = NULL;
- Mnp = NULL;
-
- Status = NetLibCreateServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- &MnpHandle
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Status = gBS->HandleProtocol (
- MnpHandle,
- &gEfiManagedNetworkProtocolGuid,
- (VOID **) &Mnp
- );
- if (EFI_ERROR (Status)) {
- goto ON_ERROR;
- }
-
- Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);
- if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
- goto ON_ERROR;
- }
-
- NicAddr->Type = (UINT16) SnpMode.IfType;
- NicAddr->Len = (UINT8) SnpMode.HwAddressSize;
- CopyMem (&NicAddr->MacAddr, &SnpMode.CurrentAddress, NicAddr->Len);
-
-ON_ERROR:
-
- NetLibDestroyServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- MnpHandle
- );
-
- return Status;
-
+ *((BOOLEAN *) Context) = TRUE;
}
+
/**
- Get network physical device NIC information.
+ Print MAC address.
- @param[in] Handle The network physical device handle.
- @param[out] MediaPresentSupported
- Upon successful return, TRUE is media present
- is supported. FALSE otherwise.
- @param[out] MediaPresent Upon successful return, TRUE is media present
- is enabled. FALSE otherwise.
+ @param[in] Node The pointer of MAC address buffer.
+ @param[in] Size The size of MAC address buffer.
- @retval EFI_SUCCESS The operation was successful.
**/
-EFI_STATUS
-EFIAPI
-IfConfigGetNicMediaStatus (
- IN EFI_HANDLE Handle,
- OUT BOOLEAN *MediaPresentSupported,
- OUT BOOLEAN *MediaPresent
- )
-
+VOID
+IfConfigPrintMacAddr (
+ IN UINT8 *Node,
+ IN UINT32 Size
+ )
{
- EFI_STATUS Status;
- EFI_HANDLE MnpHandle;
- EFI_SIMPLE_NETWORK_MODE SnpMode;
- EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
-
- MnpHandle = NULL;
- Mnp = NULL;
-
- Status = NetLibCreateServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- &MnpHandle
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ UINTN Index;
- Status = gBS->HandleProtocol (
- MnpHandle,
- &gEfiManagedNetworkProtocolGuid,
- (VOID **) &Mnp
- );
- if (EFI_ERROR (Status)) {
- goto ON_ERROR;
- }
+ ASSERT (Size <= MACADDRMAXSIZE);
- Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);
- if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
- goto ON_ERROR;
+ for (Index = 0; Index < Size; Index++) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_BODY), gShellNetwork1HiiHandle, Node[Index]);
+ if (Index + 1 < Size) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_COLON), gShellNetwork1HiiHandle);
+ }
}
-
- *MediaPresentSupported = SnpMode.MediaPresentSupported;
- *MediaPresent = SnpMode.MediaPresent;
-ON_ERROR:
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE), gShellNetwork1HiiHandle);
+}
- NetLibDestroyServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- MnpHandle
- );
- return Status;
+/**
+ The get current status of all handles.
-}
+ @param[in] IfName The pointer of IfName(interface name).
+ @param[in] IfList The pointer of IfList(interface list).
-/**
- Get all Nic's information through HII service.
+ @retval EFI_SUCCESS The get status processed successfully.
+ @retval others The get status process failed.
- @retval EFI_SUCCESS All the nic information is collected.
**/
EFI_STATUS
-EFIAPI
-IfconfigGetAllNicInfoByHii (
- VOID
+IfConfigGetInterfaceInfo (
+ IN CHAR16 *IfName,
+ IN LIST_ENTRY *IfList
)
{
- EFI_STATUS Status;
- EFI_HANDLE *Handles;
- UINTN HandleCount;
- CHAR16 *ConfigResp;
- UINTN ConfigRespBufferSize;
- CHAR16 *ConfigHdr;
- UINTN Index;
- CHAR16 *AccessProgress;
- CHAR16 *AccessResults;
- UINTN BufferSize;
- NIC_INFO *NicInfo;
- NIC_IP4_CONFIG_INFO *NicConfigRequest;
- NIC_IP4_CONFIG_INFO *NicConfig;
- CHAR16 *String;
- UINTN Length;
- UINTN Offset;
- EFI_HANDLE ChildHandle;
-
- AccessResults = NULL;
- ConfigHdr = NULL;
- ConfigResp = NULL;
- NicConfigRequest = NULL;
- NicInfo = NULL;
-
- InitializeListHead (&NicInfoList);
+ EFI_STATUS Status;
+ UINTN HandleIndex;
+ UINTN HandleNum;
+ EFI_HANDLE *HandleBuffer;
+ EFI_IP4_CONFIG2_PROTOCOL *Ip4Cfg2;
+ EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ UINTN DataSize;
- //
- // Check if HII Config Routing protocol available.
- //
- Status = gBS->LocateProtocol (
- &gEfiHiiConfigRoutingProtocolGuid,
- NULL,
- (VOID**)&mHiiConfigRouting
- );
- if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
- }
+ HandleBuffer = NULL;
+ HandleNum = 0;
+
+ IfInfo = NULL;
+ IfCb = NULL;
//
- // Locate all network device handles
+ // Locate all the handles with ip4 service binding protocol.
//
Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
+ ByProtocol,
+ &gEfiIp4ServiceBindingProtocolGuid,
+ NULL,
+ &HandleNum,
+ &HandleBuffer
);
- if (EFI_ERROR (Status) || (HandleCount == 0)) {
- return EFI_NOT_FOUND;
+ if (EFI_ERROR (Status) || (HandleNum == 0)) {
+ return EFI_ABORTED;
}
- for (Index = 0; Index < HandleCount; Index++) {
- Status = GetChildHandle (Handles[Index], &ChildHandle);
+ //
+ // Enumerate all handles that installed with ip4 service binding protocol.
+ //
+ for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
+ IfCb = NULL;
+ IfInfo = NULL;
+ DataSize = 0;
+
+ //
+ // Ip4config protocol and ip4 service binding protocol are installed
+ // on the same handle.
+ //
+ ASSERT (HandleBuffer != NULL);
+ Status = gBS->HandleProtocol (
+ HandleBuffer[HandleIndex],
+ &gEfiIp4Config2ProtocolGuid,
+ (VOID **) &Ip4Cfg2
+ );
+
if (EFI_ERROR (Status)) {
- //
- // If failed to get Child handle, try NIC controller handle for back-compatibility.
- //
- ChildHandle = Handles[Index];
+ goto ON_ERROR;
}
+
//
- // Construct configuration request string header
+ // Get the interface information size.
//
- ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);
- if (ConfigHdr != NULL) {
- Length = StrLen (ConfigHdr);
- } else {
- Length = 0;
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeInterfaceInfo,
+ &DataSize,
+ NULL
+ );
+
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ goto ON_ERROR;
}
- ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);
- ConfigResp = AllocateZeroPool (ConfigRespBufferSize);
- if (ConfigResp == NULL) {
+
+ IfInfo = AllocateZeroPool (DataSize);
+
+ if (IfInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
- if (ConfigHdr != NULL) {
- StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
- }
-
+
//
- // Append OFFSET/WIDTH pair
+ // Get the interface info.
//
- String = ConfigResp + Length;
- Offset = 0;
- AppendOffsetWidthValue (String,
- ConfigRespBufferSize/sizeof(CHAR16) - Length,
- Offset,
- NIC_ITEM_CONFIG_SIZE,
- NULL
- );
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeInterfaceInfo,
+ &DataSize,
+ IfInfo
+ );
- NicInfo = AllocateZeroPool (sizeof (NIC_INFO));
- if (NicInfo == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+ if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
- NicInfo->Handle = Handles[Index];
-
+
//
- // Get network physical devcie MAC information
+ // Check the interface name if required.
//
- IfConfigGetNicMacInfo (Handles[Index], &NicInfo->NicAddress);
- if (NicInfo->NicAddress.Type == NET_IFTYPE_ETHERNET) {
- UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"eth%d", Index);
- } else {
- UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"unk%d", Index);
+ if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) != 0)) {
+ FreePool (IfInfo);
+ continue;
}
+ DataSize = 0;
+
//
- // Get media status
+ // Get the size of dns server list.
//
- IfConfigGetNicMediaStatus (Handles[Index], &NicInfo->MediaPresentSupported, &NicInfo->MediaPresent);
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeDnsServer,
+ &DataSize,
+ NULL
+ );
+
+ if ((Status != EFI_BUFFER_TOO_SMALL) && (Status != EFI_NOT_FOUND)) {
+ goto ON_ERROR;
+ }
+
+ IfCb = AllocateZeroPool (sizeof (IFCONFIG_INTERFACE_CB) + DataSize);
- NicConfigRequest = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
- if (NicConfigRequest == NULL) {
+ if (IfCb == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
+ IfCb->NicHandle = HandleBuffer[HandleIndex];
+ IfCb->IfInfo = IfInfo;
+ IfCb->IfCfg = Ip4Cfg2;
+ IfCb->DnsCnt = (UINT32) (DataSize / sizeof (EFI_IPv4_ADDRESS));
+
//
- // Get network parameters by HII service
+ // Get the dns server list if has.
//
- Status = mHiiConfigRouting->ExtractConfig (
- mHiiConfigRouting,
- ConfigResp,
- &AccessProgress,
- &AccessResults
- );
- if (!EFI_ERROR (Status)) {
- BufferSize = NIC_ITEM_CONFIG_SIZE;
- Status = mHiiConfigRouting->ConfigToBlock (
- mHiiConfigRouting,
- AccessResults,
- (UINT8 *) NicConfigRequest,
- &BufferSize,
- &AccessProgress
- );
- if (!EFI_ERROR (Status)) {
- BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * NicConfigRequest->Ip4Info.RouteTableSize;
- NicConfig = AllocateZeroPool (BufferSize);
- if (NicConfig == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- goto ON_ERROR;
- }
- CopyMem (NicConfig, NicConfigRequest, BufferSize);
-
- //
- // If succeeds to get NIC configuration, fix up routetable pointer.
- //
- NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (&NicConfig->Ip4Info + 1);
- NicInfo->ConfigInfo = NicConfig;
-
- } else {
- NicInfo->ConfigInfo = NULL;
+ if (DataSize > 0) {
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeDnsServer,
+ &DataSize,
+ IfCb->DnsAddr
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
}
-
- FreePool (AccessResults);
-
- } else {
- NicInfo->ConfigInfo = NULL;
}
//
- // Add the Nic's info to the global NicInfoList.
+ // Get the config policy.
//
- InsertTailList (&NicInfoList, &NicInfo->Link);
+ DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypePolicy,
+ &DataSize,
+ &IfCb->Policy
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ InsertTailList (IfList, &IfCb->Link);
- FreePool (NicConfigRequest);
- FreePool (ConfigResp);
- FreePool (ConfigHdr);
+ if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) == 0)) {
+ //
+ // Only need the appointed interface, keep the allocated buffer.
+ //
+ IfCb = NULL;
+ IfInfo = NULL;
+ break;
+ }
}
- FreePool (Handles);
+ if (HandleBuffer != NULL) {
+ FreePool (HandleBuffer);
+ }
return EFI_SUCCESS;
-
+
ON_ERROR:
- if (AccessResults != NULL) {
- FreePool (AccessResults);
- }
- if (NicConfigRequest != NULL) {
- FreePool (NicConfigRequest);
- }
- if (NicInfo != NULL) {
- FreePool (NicInfo);
- }
- if (ConfigResp != NULL) {
- FreePool (ConfigResp);
- }
- if (ConfigHdr != NULL) {
- FreePool (ConfigHdr);
+
+ if (IfInfo != NULL) {
+ FreePool (IfInfo);
}
- FreePool (Handles);
+ if (IfCb != NULL) {
+ FreePool (IfCb);
+ }
return Status;
}
/**
- Set the address for the specified nic by HII service.
+ The list process of the ifconfig command.
- @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.
- @param[in] Config The command line arguments for the set operation.
+ @param[in] IfList The pointer of IfList(interface list).
+
+ @retval EFI_SUCCESS The ifconfig command list processed successfully.
+ @retval others The ifconfig command list process failed.
- @retval EFI_SUCCESS The address set operation is done.
**/
-SHELL_STATUS
-EFIAPI
-IfconfigSetNicAddrByHii (
- IN CONST NIC_INFO *NicInfo,
- IN CONST NIC_IP4_CONFIG_INFO *Config
+EFI_STATUS
+IfConfigShowInterfaceInfo (
+ IN LIST_ENTRY *IfList
)
{
- EFI_STATUS Status;
- SHELL_STATUS ShellStatus;
- NIC_IP4_CONFIG_INFO *NicConfig;
- CHAR16 *ConfigResp;
- UINTN ConfigRespBufferSize;
- CHAR16 *ConfigHdr;
- CHAR16 *AccessProgress;
- CHAR16 *AccessResults;
- CHAR16 *String;
- UINTN Length;
- UINTN Offset;
- EFI_HANDLE ChildHandle;
-
- AccessResults = NULL;
- ConfigHdr = NULL;
- ConfigResp = NULL;
- NicConfig = NULL;
- ShellStatus = SHELL_SUCCESS;
-
- Status = GetChildHandle (NicInfo->Handle, &ChildHandle);
- if (EFI_ERROR (Status)) {
- //
- // If failed to get Child handle, try NIC controller handle for back-compatibility
- //
- ChildHandle = NicInfo->Handle;
- }
- //
- // Construct config request string header
- //
- ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);
- if (ConfigHdr != NULL) {
- Length = StrLen (ConfigHdr);
- } else {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- goto ON_EXIT;
- }
- ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);
- ConfigResp = AllocateZeroPool (ConfigRespBufferSize);
- if (ConfigResp == NULL) {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- goto ON_EXIT;
- }
- if (ConfigHdr != NULL) {
- StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
- }
+ EFI_STATUS Status;
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *Next;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ EFI_IPv4_ADDRESS Gateway;
+ UINT32 Index;
- NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
- if (NicConfig == NULL) {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- goto ON_EXIT;
- }
+ Status = EFI_SUCCESS;
- if (Config != NULL) {
- CopyMem (NicConfig, Config, sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * Config->Ip4Info.RouteTableSize);
+ if (IsListEmpty (IfList)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);
}
//
- // Append OFFSET/WIDTH pair
+ // Go through the interface list.
//
- String = ConfigResp + Length;
- Offset = 0;
- AppendOffsetWidthValue (String,
- ConfigRespBufferSize/sizeof(CHAR16) - Length,
- Offset,
- NIC_ITEM_CONFIG_SIZE,
- NULL
- );
+ NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {
+ IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);
- //
- // Call HII helper function to generate configuration string
- //
- Status = mHiiConfigRouting->BlockToConfig (
- mHiiConfigRouting,
- ConfigResp,
- (UINT8 *) NicConfig,
- NIC_ITEM_CONFIG_SIZE,
- &AccessResults,
- &AccessProgress
- );
- if (EFI_ERROR (Status)) {
- ShellStatus = SHELL_NOT_FOUND;
- goto ON_EXIT;
- }
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK), gShellNetwork1HiiHandle);
- //
- // Set IP setting by HII servie
- //
- Status = mHiiConfigRouting->RouteConfig (
- mHiiConfigRouting,
- AccessResults,
- &AccessProgress
- );
- if (EFI_ERROR(Status)) {
- ShellStatus = SHELL_ACCESS_DENIED;
- }
+ //
+ // Print interface name.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_IF_NAME), gShellNetwork1HiiHandle, IfCb->IfInfo->Name);
-ON_EXIT:
- SHELL_FREE_NON_NULL(AccessResults);
- SHELL_FREE_NON_NULL(NicConfig);
- SHELL_FREE_NON_NULL(ConfigResp);
- SHELL_FREE_NON_NULL(ConfigHdr);
+ //
+ // Print interface config policy.
+ //
+ if (IfCb->Policy == Ip4Config2PolicyDhcp) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_DHCP), gShellNetwork1HiiHandle);
+ } else {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_MAN), gShellNetwork1HiiHandle);
+ }
- return ShellStatus;
-}
+ //
+ // Print mac address of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_HEAD), gShellNetwork1HiiHandle);
-/**
- The callback function for the Arp address resolved event.
+ IfConfigPrintMacAddr (
+ IfCb->IfInfo->HwAddress.Addr,
+ IfCb->IfInfo->HwAddressSize
+ );
- @param[in] Event The event this function is registered to.
- @param[in] Context The context registered to the event.
-**/
-VOID
-EFIAPI
-IfconfigOnArpResolved (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- ARP_REQUEST *Request;
- UINT8 Index;
+ //
+ // Print IPv4 address list of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_HEAD), gShellNetwork1HiiHandle);
- Request = (ARP_REQUEST *) Context;
- ASSERT (Request != NULL);
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[0],
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[1],
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[2],
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[3]
+ );
+
+ //
+ // Print subnet mask list of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_SUBNET_MASK_HEAD), gShellNetwork1HiiHandle);
- Request->Duplicate = FALSE;
-
- if (0 == CompareMem (&Request->LocalMac, &Request->DestMac, Request->MacLen)) {
ShellPrintHiiEx(
-1,
-1,
NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Already Configured",
- (UINTN)Request->DestIp.v4.Addr[0],
- (UINTN)Request->DestIp.v4.Addr[1],
- (UINTN)Request->DestIp.v4.Addr[2],
- (UINTN)Request->DestIp.v4.Addr[3]
+ STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[0],
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[1],
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[2],
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[3]
);
- ArpResolved = TRUE;
- return;
- }
-
- for (Index = 0; Index < Request->MacLen; Index++) {
- if (Request->DestMac.Addr[Index] != 0) {
- Request->Duplicate = TRUE;
- }
- }
- if (Request->Duplicate) {
+ //
+ // Print default gateway of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_GATEWAY_HEAD), gShellNetwork1HiiHandle);
+
+ ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));
+
+ for (Index = 0; Index < IfCb->IfInfo->RouteTableSize; Index++) {
+ if ((CompareMem (&IfCb->IfInfo->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&
+ (CompareMem (&IfCb->IfInfo->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){
+ CopyMem (&Gateway, &IfCb->IfInfo->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
+ }
+ }
+
ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR),
- gShellNetwork1HiiHandle,
- (UINTN)Request->DestMac.Addr[0],
- (UINTN)Request->DestMac.Addr[1],
- (UINTN)Request->DestMac.Addr[2],
- (UINTN)Request->DestMac.Addr[3],
- (UINTN)Request->DestMac.Addr[4],
- (UINTN)Request->DestMac.Addr[5]
- );
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN)Gateway.Addr[0],
+ (UINTN)Gateway.Addr[1],
+ (UINTN)Gateway.Addr[2],
+ (UINTN)Gateway.Addr[3]
+ );
+
+ //
+ // Print route table entry.
+ //
+ ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, IfCb->IfInfo->RouteTableSize);
+
+ for (Index = 0; Index < IfCb->IfInfo->RouteTableSize; Index++) {
+ ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);
+
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
+ gShellNetwork1HiiHandle,
+ L"Subnet ",
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[0],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[1],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[2],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[3]
+ );
+
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
+ gShellNetwork1HiiHandle,
+ L"Netmask",
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[0],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[1],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[2],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[3]
+ );
+
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
+ gShellNetwork1HiiHandle,
+ L"Gateway",
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[0],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[1],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[2],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[3]
+ );
+ }
+
+ //
+ // Print dns server addresses list of the interface if has.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_HEAD), gShellNetwork1HiiHandle);
+
+ for (Index = 0; Index < IfCb->DnsCnt; Index++) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN) IfCb->DnsAddr[Index].Addr[0],
+ (UINTN) IfCb->DnsAddr[Index].Addr[1],
+ (UINTN) IfCb->DnsAddr[Index].Addr[2],
+ (UINTN) IfCb->DnsAddr[Index].Addr[3]
+ );
+
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE), gShellNetwork1HiiHandle);
+ }
}
+
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK), gShellNetwork1HiiHandle);
- ArpResolved = TRUE;
- return ;
+ return EFI_SUCCESS;
}
/**
- Check whether the address to be configured conflicts with other hosts.
+ The clean process of the ifconfig command to clear interface info.
+
+ @param[in] IfList The pointer of IfList(interface list).
- @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
- @param[in] IpAddr The IPv4 address to be configured to the Nic.
+ @retval EFI_SUCCESS The ifconfig command clean processed successfully.
+ @retval others The ifconfig command clean process failed.
- @return TRUE Some other host already uses the IpAddr.
- @return FALSE The address is unused.
**/
-BOOLEAN
-EFIAPI
-IfconfigIsIpDuplicate (
- IN NIC_INFO *NicInfo,
- IN IP4_ADDR IpAddr
+EFI_STATUS
+IfConfigClearInterfaceInfo (
+ IN LIST_ENTRY *IfList
)
{
- EFI_ARP_PROTOCOL *Arp;
- EFI_ARP_CONFIG_DATA ArpCfgData;
- EFI_HANDLE ArpHandle;
- ARP_REQUEST Request;
- EFI_STATUS Status;
-
- Arp = NULL;
- ArpHandle = NULL;
- ZeroMem (&Request, sizeof (ARP_REQUEST));
-
- Status = NetLibCreateServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiArpServiceBindingProtocolGuid,
- &ArpHandle
- );
-
- if (EFI_ERROR (Status)) {
- return FALSE;
- }
+ EFI_STATUS Status;
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *Next;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ EFI_IP4_CONFIG2_POLICY Policy;
- Status = gBS->OpenProtocol (
- ArpHandle,
- &gEfiArpProtocolGuid,
- (VOID**)&Arp,
- gImageHandle,
- ArpHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
+ Policy = Ip4Config2PolicyDhcp;
+ Status = EFI_SUCCESS;
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
+ if (IsListEmpty (IfList)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);
}
//
- // Set up the Arp requests
+ // Go through the interface list.
//
- EFI_IP4_TO_U32 (Request.DestIp.v4) = IpAddr;
- EFI_IP4_TO_U32 (Request.LocalIp.v4) = 0xffffffff;
- Request.LocalMac = NicInfo->NicAddress.MacAddr;
- Request.MacLen = NicInfo->NicAddress.Len;
-
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL,
- TPL_CALLBACK,
- IfconfigOnArpResolved,
- (VOID *) &Request,
- &Request.OnResolved
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- ArpCfgData.SwAddressType = 0x0800;
- ArpCfgData.SwAddressLength = 4;
- ArpCfgData.StationAddress = &Request.LocalIp;
- ArpCfgData.EntryTimeOut = 0;
- ArpCfgData.RetryCount = 3;
- ArpCfgData.RetryTimeOut = 0;
-
- Status = Arp->Configure (Arp, &ArpCfgData);
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- Status = Arp->Request (
- Arp,
- &Request.DestIp,
- Request.OnResolved,
- &Request.DestMac
- );
-
- if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {
- goto ON_EXIT;
- }
-
- while (!ArpResolved) {
+ NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {
+ IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);
- }
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypePolicy,
+ sizeof (EFI_IP4_CONFIG2_POLICY),
+ &Policy
+ );
-ON_EXIT:
- if (Request.OnResolved != NULL) {
- gBS->CloseEvent (Request.OnResolved);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
}
- NetLibDestroyServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiArpServiceBindingProtocolGuid,
- ArpHandle
- );
-
- return Request.Duplicate;
+ return Status;
}
/**
- The callback function for the timer event used to get map.
+ The set process of the ifconfig command.
- @param[in] Event The event this function is registered to.
- @param[in] Context The context registered to the event.
-**/
-VOID
-EFIAPI
-TimeoutToGetMap (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- mTimeout = TRUE;
- return ;
-}
+ @param[in] IfList The pointer of IfList(interface list).
+ @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
-/**
- Create an IP child, use it to start the auto configuration, then destroy it.
-
- @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
+ @retval EFI_SUCCESS The ifconfig command set processed successfully.
+ @retval others The ifconfig command set process failed.
- @retval EFI_SUCCESS The configuration is done.
**/
EFI_STATUS
-EFIAPI
-IfconfigStartIp4(
- IN NIC_INFO *NicInfo
+IfConfigSetInterfaceInfo (
+ IN LIST_ENTRY *IfList,
+ IN ARG_LIST *VarArg
)
{
- EFI_IP4_PROTOCOL *Ip4;
- EFI_HANDLE Ip4Handle;
- EFI_HANDLE TimerToGetMap;
- EFI_IP4_CONFIG_DATA Ip4ConfigData;
- EFI_IP4_MODE_DATA Ip4Mode;
- EFI_STATUS Status;
- //
- // Get the Ip4ServiceBinding Protocol
- //
- Ip4Handle = NULL;
- Ip4 = NULL;
- TimerToGetMap = NULL;
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR), gShellNetwork1HiiHandle);
+ EFI_STATUS Status;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ VAR_CHECK_CODE CheckCode;
+ EFI_EVENT TimeOutEvt;
+ EFI_EVENT MappedEvt;
+ BOOLEAN IsAddressOk;
- Status = NetLibCreateServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiIp4ServiceBindingProtocolGuid,
- &Ip4Handle
- );
+ EFI_IP4_CONFIG2_POLICY Policy;
+ EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress;
+ UINTN DataSize;
+ EFI_IPv4_ADDRESS Gateway;
+ EFI_IPv4_ADDRESS *Dns;
+ ARG_LIST *Tmp;
+ UINTN Index;
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ CONST CHAR16* TempString;
- Status = gBS->OpenProtocol (
- Ip4Handle,
- &gEfiIp4ProtocolGuid,
- (VOID **) &Ip4,
- NicInfo->Handle,
- gImageHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
+ Dns = NULL;
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
+ if (IsListEmpty (IfList)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);
+ return EFI_INVALID_PARAMETER;
}
-
- Ip4ConfigData.DefaultProtocol = EFI_IP_PROTO_ICMP;
- Ip4ConfigData.AcceptAnyProtocol = FALSE;
- Ip4ConfigData.AcceptIcmpErrors = FALSE;
- Ip4ConfigData.AcceptBroadcast = FALSE;
- Ip4ConfigData.AcceptPromiscuous = FALSE;
- Ip4ConfigData.UseDefaultAddress = TRUE;
- ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
- ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
- Ip4ConfigData.TypeOfService = 0;
- Ip4ConfigData.TimeToLive = 1;
- Ip4ConfigData.DoNotFragment = FALSE;
- Ip4ConfigData.RawData = FALSE;
- Ip4ConfigData.ReceiveTimeout = 0;
- Ip4ConfigData.TransmitTimeout = 0;
-
- Status = Ip4->Configure (Ip4, &Ip4ConfigData);
-
- if (Status == EFI_NO_MAPPING) {
- mTimeout = FALSE;
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL | EVT_TIMER,
- TPL_CALLBACK,
- TimeoutToGetMap,
- NULL,
- &TimerToGetMap
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- Status = gBS->SetTimer (
- TimerToGetMap,
- TimerRelative,
- MultU64x32 (SecondsToNanoSeconds, 5)
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE), gShellNetwork1HiiHandle);
-
- while (!mTimeout) {
- Ip4->Poll (Ip4);
- if (!EFI_ERROR (Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL)) &&
- Ip4Mode.IsConfigured) {
- break;
- }
- }
- }
-
- Status = Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL);
+ //
+ // Make sure to set only one interface each time.
+ //
+ IfCb = NET_LIST_USER_STRUCT (IfList->ForwardLink, IFCONFIG_INTERFACE_CB, Link);
+ Status = EFI_SUCCESS;
- if ((Status == EFI_SUCCESS) && Ip4Mode.IsConfigured) {
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Default",
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[0],
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[1],
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[2],
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[3]
- );
- }
-
-ON_EXIT:
+ //
+ // Initialize check list mechanism.
+ //
+ CheckCode = IfConfigRetriveCheckListByName(
+ NULL,
+ NULL,
+ TRUE
+ );
+ //
+ // Create events & timers for asynchronous settings.
+ //
+ Status = gBS->CreateEvent (
+ EVT_TIMER,
+ TPL_CALLBACK,
+ NULL,
+ NULL,
+ &TimeOutEvt
+ );
if (EFI_ERROR (Status)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
}
- if (TimerToGetMap != NULL) {
- gBS->SetTimer (TimerToGetMap, TimerCancel, 0);
- gBS->CloseEvent (TimerToGetMap);
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ IfConfigManualAddressNotify,
+ &IsAddressOk,
+ &MappedEvt
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
}
- NetLibDestroyServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiIp4ServiceBindingProtocolGuid,
- Ip4Handle
- );
-
- return Status;
-}
-
-/**
- Set the address for the nic specified by the params.
+ //
+ // Parse the setting variables.
+ //
+ while (VarArg != NULL) {
+ //
+ // Check invalid parameters (duplication & unknown & conflict).
+ //
+ CheckCode = IfConfigRetriveCheckListByName(
+ mSetCheckList,
+ VarArg->Arg,
+ FALSE
+ );
- @param[in] Argc The count of the passed in Params.
- @param[in] Params The command line arguments for the set operation.
+ if (VarCheckOk != CheckCode) {
+ switch (CheckCode) {
+ case VarCheckDuplicate:
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_DUPLICATE_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);
+ break;
- @retval EFI_SUCCESS The address set operation is done.
- @return Some error occurs.
-**/
-SHELL_STATUS
-EFIAPI
-IfconfigSetNicAddr (
- IN UINTN Argc,
- IN CONST CHAR16 *Params
- )
-{
- NIC_IP4_CONFIG_INFO *Config;
- NIC_IP4_CONFIG_INFO *OldConfig;
- EFI_IP_ADDRESS Ip;
- EFI_IP_ADDRESS Mask;
- EFI_IP_ADDRESS Gateway;
- NIC_INFO *Info;
- BOOLEAN Permanent;
- SHELL_STATUS ShellStatus;
- CONST CHAR16 *Walker;
- CHAR16 *Temp;
- CONST CHAR16 *DhcpTemp;
- CONST CHAR16 *StaticTemp;
- CONST CHAR16 *PermTemp;
- UINT32 NetworkBytes1;
- UINT32 NetworkBytes2;
- EFI_STATUS Status;
-
- Walker = Params;
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
- Info = IfconfigFindNicByName (Temp);
-
- if (Info == NULL) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND), gShellNetwork1HiiHandle, Temp);
- return SHELL_NOT_FOUND;
- }
+ case VarCheckConflict:
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_CONFLICT_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);
+ break;
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")==NULL?0:StrStr(Walker, L" ")-Walker);
+ case VarCheckUnknown:
+ //
+ // To handle unsupported option.
+ //
+ TempString = PermanentString;
+ if (StringNoCaseCompare(&VarArg->Arg, &TempString) == 0) {
+ ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION), gShellNetwork1HiiHandle, PermanentString);
+ goto ON_EXIT;
+ }
- Config = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));
- if (Config == NULL) {
- return SHELL_OUT_OF_RESOURCES;
- }
+ //
+ // To handle unknown option.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_UNKNOWN_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);
+ break;
- Config->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Config + 1);
+ default:
+ break;
+ }
- OldConfig = Info->ConfigInfo;
- Permanent = FALSE;
- ShellStatus = SHELL_INVALID_PARAMETER;
+ VarArg = VarArg->Next;
+ continue;
+ }
- DhcpTemp = DhcpString;
- StaticTemp = StaticString;
-
- if (StringNoCaseCompare(&Temp, &DhcpTemp) == 0) {
//
- // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent
+ // Process valid variables.
//
- if ((Argc != 2) && (Argc!= 3)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ if (StrCmp(VarArg->Arg, L"dhcp") == 0) {
+ //
+ // Set dhcp config policy
+ //
+ Policy = Ip4Config2PolicyDhcp;
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypePolicy,
+ sizeof (EFI_IP4_CONFIG2_POLICY),
+ &Policy
+ );
+
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
- if (Argc == 3) {
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, 0);
+ VarArg= VarArg->Next;
- PermTemp = PermanentString;
- if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing");
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
+ } else if (StrCmp (VarArg->Arg, L"static") == 0) {
+ //
+ // Set manual config policy.
+ //
+ Policy = Ip4Config2PolicyStatic;
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypePolicy,
+ sizeof (EFI_IP4_CONFIG2_POLICY),
+ &Policy
+ );
+
+ if (EFI_ERROR(Status)) {
goto ON_EXIT;
}
- Permanent = TRUE;
- }
+ VarArg= VarArg->Next;
- if ((OldConfig != NULL) && (OldConfig->Source == IP4_CONFIG_SOURCE_DHCP) &&
- (OldConfig->Permanent == Permanent)) {
+ ZeroMem (&ManualAddress, sizeof (ManualAddress));
+
+ //
+ // Get manual IP address.
+ //
+ Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.Address);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED), gShellNetwork1HiiHandle, Info->Name);
- ShellStatus = SHELL_ALREADY_STARTED;
- goto ON_EXIT;
- }
+ //
+ // Get subnetmask.
+ //
+ VarArg = VarArg->Next;
+ Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.SubnetMask);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
- Config->Source = IP4_CONFIG_SOURCE_DHCP;
- } else if (StringNoCaseCompare(&Temp, &StaticTemp) == 0) {
- //
- // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and
- // eth0 static IP NETMASK GATEWAY permanent
- //
- if ((Argc != 5) && (Argc != 6)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ //
+ // Get gateway.
+ //
+ VarArg = VarArg->Next;
+ Status = NetLibStrToIp4 (VarArg->Arg, &Gateway);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
+
+ IsAddressOk = FALSE;
+
+ Status = IfCb->IfCfg->RegisterDataNotify (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeManualAddress,
+ MappedEvt
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
+ DataSize = sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS);
- if (EFI_ERROR (NetLibStrToIp4 (Temp, &Ip.v4))) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeManualAddress,
+ DataSize,
+ &ManualAddress
+ );
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
- if (EFI_ERROR (NetLibStrToIp4 (Temp, &Mask.v4))) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ if (Status == EFI_NOT_READY) {
+ gBS->SetTimer (TimeOutEvt, TimerRelative, 50000000);
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- if (Argc == 6) {
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
- } else {
- Temp = StrnCatGrow(&Temp, NULL, Walker, 0);
- }
- if (EFI_ERROR (NetLibStrToIp4 (Temp, &Gateway.v4))) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {
+ if (IsAddressOk) {
+ Status = EFI_SUCCESS;
+ break;
+ }
+ }
+ }
- if (Argc == 6) {
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, 0);
+ IfCb->IfCfg->UnregisterDataNotify (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeManualAddress,
+ MappedEvt
+ );
- PermTemp = PermanentString;
- if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing");
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);
goto ON_EXIT;
}
- Permanent = TRUE;
- }
+ //
+ // Set gateway.
+ //
+ DataSize = sizeof (EFI_IPv4_ADDRESS);
+
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeGateway,
+ DataSize,
+ &Gateway
+ );
+ VarArg = VarArg->Next;
+
+ } else if (StrCmp (VarArg->Arg, L"dns") == 0) {
+ //
+ // Get DNS addresses.
+ //
+ VarArg = VarArg->Next;
+ Tmp = VarArg;
+ Index = 0;
+ while (Tmp != NULL) {
+ Index ++;
+ Tmp = Tmp->Next;
+ }
- NetworkBytes1 = NTOHL (Ip.Addr[0]);
- NetworkBytes2 = NTOHL (Mask.Addr[0]);
- if ((Ip.Addr[0] == 0) || (Mask.Addr[0] == 0) ||
- !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {
+ Dns = AllocatePool (Index * sizeof (EFI_IPv4_ADDRESS));
+ ASSERT(Dns != NULL);
+ Tmp = VarArg;
+ Index = 0;
+ while (Tmp != NULL) {
+ Status = NetLibStrToIp4 (Tmp->Arg, Dns + Index);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
+ Index ++;
+ Tmp = Tmp->Next;
+ }
+
+ VarArg = Tmp;
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR), gShellNetwork1HiiHandle);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
+ //
+ // Set DNS addresses.
+ //
+ DataSize = Index * sizeof (EFI_IPv4_ADDRESS);
+
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeDnsServer,
+ DataSize,
+ Dns
+ );
}
+ }
- NetworkBytes1 = NTOHL (Gateway.Addr[0]);
- if (!IP4_NET_EQUAL (Ip.Addr[0], Gateway.Addr[0], Mask.Addr[0]) ||
- !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ON_EXIT:
+ if (Dns != NULL) {
+ FreePool (Dns);
+ }
+
+ return EFI_SUCCESS;
- //
- // Set the configuration up, two route table entries are added:
- // one for the direct connected network, and another for the
- // default gateway. Remember, some structure members are cleared
- // by AllocateZeroPool
- //
- Config->Source = IP4_CONFIG_SOURCE_STATIC;
- Config->Ip4Info.RouteTableSize = 2;
+}
- CopyMem (&Config->Ip4Info.StationAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));
- CopyMem (&Config->Ip4Info.SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));
+/**
+ The ifconfig command main process.
- Ip.Addr[0] = Ip.Addr[0] & Mask.Addr[0];
+ @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
- CopyMem (&Config->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));
- CopyMem (&Config->Ip4Info.RouteTable[0].SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));
- CopyMem (&Config->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));
- } else {
- // neither static or DHCP. error.
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig");
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ @retval EFI_SUCCESS ifconfig command processed successfully.
+ @retval others The ifconfig command process failed.
- CopyMem (&Config->NicAddr, &Info->NicAddress, sizeof (NIC_ADDR));
- Config->Permanent = Permanent;
+**/
+EFI_STATUS
+IfConfig (
+ IN IFCONFIG_PRIVATE_DATA *Private
+ )
+{
+ EFI_STATUS Status;
//
- // Use HII service to set NIC address
+ // Get configure information of all interfaces.
//
- ShellStatus = IfconfigSetNicAddrByHii (Info, Config);
- if (ShellStatus != SHELL_SUCCESS) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_SET_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);
- goto ON_EXIT;
- }
+ Status = IfConfigGetInterfaceInfo (
+ Private->IfName,
+ &Private->IfList
+ );
- Status = IfconfigStartIp4 (Info);
- if (EFI_ERROR(Status)) {
- ShellStatus = SHELL_ACCESS_DENIED;
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
}
- if (ShellStatus != SHELL_SUCCESS) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);
+ switch (Private->OpCode) {
+ case IfConfigOpList:
+ Status = IfConfigShowInterfaceInfo (&Private->IfList);
+ break;
+
+ case IfConfigOpClear:
+ Status = IfConfigClearInterfaceInfo (&Private->IfList);
+ break;
+
+ case IfConfigOpSet:
+ Status = IfConfigSetInterfaceInfo (&Private->IfList, Private->VarArg);
+ break;
+
+ default:
+ Status = EFI_ABORTED;
}
-
+
ON_EXIT:
- SHELL_FREE_NON_NULL(Config);
-
- return ShellStatus;
+
+ return Status;
}
/**
- Show the address information for the nic specified.
+ The ifconfig command cleanup process, free the allocated memory.
+
+ @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
- @param[in] Name A pointer to the string containg the nic's name, if NULL,
- all nics' information is shown.
**/
VOID
-EFIAPI
-IfconfigShowNicInfo (
- IN CONST CHAR16 *Name
+IfConfigCleanup (
+ IN IFCONFIG_PRIVATE_DATA *Private
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *NextEntry;
- NIC_INFO *NicInfo;
- UINT32 Index;
- EFI_IP4_IPCONFIG_DATA *Ip4Config;
- EFI_IPv4_ADDRESS Gateway;
- CONST CHAR16 *TempString;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ ARG_LIST *ArgNode;
+ ARG_LIST *ArgHead;
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- NicInfo = BASE_CR (Entry, NIC_INFO, Link);
+ ASSERT (Private != NULL);
- TempString = (CHAR16*)NicInfo->Name;
- if ((Name != NULL) && (StringNoCaseCompare (&Name, &TempString) != 0)) {
- continue;
- }
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NAME), gShellNetwork1HiiHandle, NicInfo->Name);
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR),
- gShellNetwork1HiiHandle,
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[0],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[1],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[2],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[3],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[4],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[5]
- );
-
- Print (L" Media State: %s\n", NicInfo->MediaPresent ? L"Media present" : L"Media disconnected");
-
- if (NicInfo->ConfigInfo == NULL) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED), gShellNetwork1HiiHandle);
- continue;
- }
+ //
+ // Clean the list which save the set config Args.
+ //
+ if (Private->VarArg != NULL) {
+ ArgHead = Private->VarArg;
- if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_DHCP) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"DHCP");
- } else if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_STATIC) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"STATIC");
- } else {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"Unknown");
+ while (ArgHead->Next != NULL) {
+ ArgNode = ArgHead->Next;
+ FreePool (ArgHead);
+ ArgHead = ArgNode;
}
- ShellPrintHiiEx(-1, -1, NULL,
- STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS),
- gShellNetwork1HiiHandle,
- (NicInfo->ConfigInfo->Permanent? L"TRUE":L"FALSE")
- );
-
- Ip4Config = &NicInfo->ConfigInfo->Ip4Info;
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"IP address",
- (UINTN)Ip4Config->StationAddress.Addr[0],
- (UINTN)Ip4Config->StationAddress.Addr[1],
- (UINTN)Ip4Config->StationAddress.Addr[2],
- (UINTN)Ip4Config->StationAddress.Addr[3]
- );
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Mask",
- (UINTN)Ip4Config->SubnetMask.Addr[0],
- (UINTN)Ip4Config->SubnetMask.Addr[1],
- (UINTN)Ip4Config->SubnetMask.Addr[2],
- (UINTN)Ip4Config->SubnetMask.Addr[3]
- );
-
- ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));
-
- for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {
- if ((CompareMem (&Ip4Config->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&
- (CompareMem (&Ip4Config->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){
- CopyMem (&Gateway, &Ip4Config->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
- }
- }
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Gateway",
- (UINTN)Gateway.Addr[0],
- (UINTN)Gateway.Addr[1],
- (UINTN)Gateway.Addr[2],
- (UINTN)Gateway.Addr[3]
- );
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, Ip4Config->RouteTableSize);
-
- for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Subnet",
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[0],
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[1],
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[2],
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[3]
- );
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Netmask",
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[0],
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[1],
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[2],
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[3]
- );
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Gateway",
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[0],
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[1],
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[2],
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[3]
- );
- }
+ FreePool (ArgHead);
}
- return ;
-}
+ if (Private->IfName != NULL) {
+ FreePool (Private->IfName);
+ }
-/**
- Clear address configuration for the nic specified.
+ //
+ // Clean the IFCONFIG_INTERFACE_CB list.
+ //
+ NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->IfList) {
+ IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);
- @param[in] Name A pointer to the string containg the nic's name,
- if NULL, all nics address configurations are cleared.
+ RemoveEntryList (&IfCb->Link);
- @retval EFI_SUCCESS The address configuration is cleared.
- @return Some error occurs.
-**/
-EFI_STATUS
-EFIAPI
-IfconfigClearNicAddr (
- IN CONST CHAR16 *Name
- )
-{
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
- NIC_INFO *Info;
- EFI_STATUS Status;
-
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- Info = BASE_CR (Entry, NIC_INFO, Link);
+ if (IfCb->IfInfo != NULL) {
- if ((Name != NULL) && (StrCmp (Name, Info->Name) != 0)) {
- continue;
+ FreePool (IfCb->IfInfo);
}
-// if (Info->NicIp4Config == NULL) {
- Status = IfconfigSetNicAddrByHii (Info, NULL);
-// } else {
-// Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);
-// }
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ FreePool (IfCb);
}
- return EFI_SUCCESS;
-
+ FreePool (Private);
}
/**
Function for 'ifconfig' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
+
+ @retval EFI_SUCCESS ifconfig command processed successfully.
+ @retval others The ifconfig command process failed.
+
**/
SHELL_STATUS
EFIAPI
ShellCommandRunIfconfig (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Package;
- CHAR16 *ProblemParam;
- SHELL_STATUS ShellStatus;
- BOOLEAN ListOperation;
- BOOLEAN ClearOperation;
- BOOLEAN SetOperation;
- CONST CHAR16 *Item;
- LIST_ENTRY *Entry;
- NIC_INFO *Info;
-
- InitializeListHead (&NicInfoList);
- Status = EFI_INVALID_PARAMETER;
- ShellStatus = SHELL_SUCCESS;
+ EFI_STATUS Status;
+ IFCONFIG_PRIVATE_DATA *Private;
+ LIST_ENTRY *ParamPackage;
+ CONST CHAR16 *ValueStr;
+ ARG_LIST *ArgList;
+ CHAR16 *ProblemParam;
+ CHAR16 *Str;
+
+ Private = NULL;
+
+ Status = ShellCommandLineParseEx (mIfConfigCheckList, &ParamPackage, &ProblemParam, TRUE, FALSE);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam);
+ goto ON_EXIT;
+ }
//
- // initialize the shell lib (we must be in non-auto-init...)
+ // To handle unsupported option.
//
- Status = ShellInitialize();
- ASSERT_EFI_ERROR(Status);
+ if (ShellCommandLineGetFlag (ParamPackage, L"-c")) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION), gShellNetwork1HiiHandle,L"-c");
+ goto ON_EXIT;
+ }
//
- // parse the command line
+ // To handle no option.
//
- Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
- if (EFI_ERROR(Status)) {
- if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam);
- FreePool(ProblemParam);
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else {
- ASSERT(FALSE);
- }
-
- goto Done;
+ if (!ShellCommandLineGetFlag (ParamPackage, L"-r") && !ShellCommandLineGetFlag (ParamPackage, L"-s") &&
+ !ShellCommandLineGetFlag (ParamPackage, L"-l")) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_OPTION), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
}
- ClearOperation = ShellCommandLineGetFlag(Package, L"-c");
- ListOperation = ShellCommandLineGetFlag(Package, L"-l");
- SetOperation = ShellCommandLineGetFlag(Package, L"-s");
-
- if ((ClearOperation && ListOperation)
- ||(SetOperation && ListOperation)
- ||(ClearOperation && SetOperation)
- ) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- } else if (!ClearOperation && !ListOperation && !SetOperation) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
+ //
+ // To handle conflict options.
+ //
+ if (((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-s"))) ||
+ ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||
+ ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l")))) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig");
+ goto ON_EXIT;
}
-
-
- Status = IfconfigGetAllNicInfoByHii ();
- if (EFI_ERROR (Status)) {
- if (mIp4ConfigExist) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL), gShellNetwork1HiiHandle, Status);
- } else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellNetwork1HiiHandle, L"ifconfig", L"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid);
- }
- return SHELL_NOT_FOUND;
+ Status = EFI_INVALID_PARAMETER;
+
+ Private = AllocateZeroPool (sizeof (IFCONFIG_PRIVATE_DATA));
+
+ if (Private == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ON_EXIT;
}
- if (ListOperation) {
- Item = ShellCommandLineGetValue (Package, L"-l");
+ InitializeListHead (&Private->IfList);
- if (Item != NULL && CountSubItems(Item) > 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-l");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- }
+ //
+ // To get interface name for the list option.
+ //
+ if (ShellCommandLineGetFlag (ParamPackage, L"-l")) {
+ Private->OpCode = IfConfigOpList;
+ ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");
+ if (ValueStr != NULL) {
+ Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
+ ASSERT (Str != NULL);
+ Private->IfName = Str;
+ }
+ }
+
+ //
+ // To get interface name for the clear option.
+ //
+ if (ShellCommandLineGetFlag (ParamPackage, L"-r")) {
+ Private->OpCode = IfConfigOpClear;
+ ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");
+ if (ValueStr != NULL) {
+ Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
+ ASSERT (Str != NULL);
+ Private->IfName = Str;
+ }
+ }
+
+ //
+ // To get interface name and corresponding Args for the set option.
+ //
+ if (ShellCommandLineGetFlag (ParamPackage, L"-s")) {
+ ValueStr = ShellCommandLineGetValue (ParamPackage, L"-s");
+ if (ValueStr == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_INTERFACE), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
+ }
//
- // Show the configuration.
+ // To split the configuration into multi-section.
//
- IfconfigShowNicInfo (Item);
- } else if (SetOperation) {
- Item = ShellCommandLineGetValue (Package, L"-s");
+ ArgList = SplitStrToList (ValueStr, L' ');
+ ASSERT (ArgList != NULL);
- //
- // The correct command line arguments for setting address are:
- // IfConfig -s eth0 DHCP [permanent]
- // IfConfig -s eth0 static ip netmask gateway [permanent]
- //
- if (Item == NULL || (CountSubItems(Item) < 2) || (CountSubItems(Item) > 6) || (CountSubItems(Item) == 4)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_NO_VALUE), gShellNetwork1HiiHandle, L"ifconfig", L"-s");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- }
+ Private->OpCode = IfConfigOpSet;
+ Private->IfName = ArgList->Arg;
- ShellStatus = IfconfigSetNicAddr (CountSubItems(Item), Item);
- } else if (ClearOperation) {
- Item = ShellCommandLineGetValue (Package, L"-c");
+ Private->VarArg = ArgList->Next;
- if (Item != NULL && CountSubItems(Item) > 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-c");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
+ if (Private->IfName == NULL || Private->VarArg == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
}
-
- IfconfigClearNicAddr (Item);
- } else {
- ASSERT(FALSE);
}
+
+ //
+ // Main process of ifconfig.
+ //
+ Status = IfConfig (Private);
-Done:
- while (!IsListEmpty (&NicInfoList)) {
- Entry = NicInfoList.ForwardLink;
- Info = BASE_CR (Entry, NIC_INFO, Link);
-
- RemoveEntryList (Entry);
-
- if (Info->ConfigInfo != NULL) {
- FreePool (Info->ConfigInfo);
- }
-
- FreePool (Info);
- }
+ON_EXIT:
- if (Package != NULL) {
- ShellCommandLineFreeVarList(Package);
+ ShellCommandLineFreeVarList (ParamPackage);
+
+ if (Private != NULL) {
+ IfConfigCleanup (Private);
}
- return (ShellStatus);
+ return Status;
}
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
index e23588a..fda062d 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
@@ -953,11 +953,11 @@ PingCreateIpInstance (
// Ip6config protocol and ip6 service binding protocol are installed
// on the same handle.
//
Status = gBS->HandleProtocol (
HandleBuffer[HandleIndex],
- Private->IpChoice == PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4ConfigProtocolGuid,
+ Private->IpChoice == PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4Config2ProtocolGuid,
(VOID **) &IpXCfg
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
@@ -971,12 +971,13 @@ PingCreateIpInstance (
Ip6ConfigDataTypeInterfaceInfo,
&IfInfoSize,
NULL
);
} else {
- Status = ((EFI_IP4_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
&IfInfoSize,
NULL
);
}
@@ -1007,12 +1008,13 @@ PingCreateIpInstance (
Ip6ConfigDataTypeInterfaceInfo,
&IfInfoSize,
IpXInterfaceInfo
);
} else {
- Status = ((EFI_IP4_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
&IfInfoSize,
IpXInterfaceInfo
);
}
@@ -1043,11 +1045,11 @@ PingCreateIpInstance (
}
} else {
//
// IP4 address check
//
- if (EFI_IP4_EQUAL (&Private->SrcAddress, &((EFI_IP4_IPCONFIG_DATA*)IpXInterfaceInfo)->StationAddress)) {
+ if (EFI_IP4_EQUAL (&Private->SrcAddress, &((EFI_IP4_CONFIG2_INTERFACE_INFO*)IpXInterfaceInfo)->StationAddress)) {
//
// Match a certain interface address.
//
break;
}
@@ -1135,15 +1137,10 @@ PingCreateIpInstance (
ZeroMem (&Ip4Config, sizeof (EFI_IP4_CONFIG_DATA));
//
// Configure the ip4 instance for icmp4 packet exchange.
//
-// PING_IP4_COPY_ADDRESS (&Ip4Config.StationAddress, &Private->SrcAddress);
-// Ip4Config.SubnetMask.Addr[0] = 0xFF;
-// Ip4Config.SubnetMask.Addr[1] = 0xFF;
-// Ip4Config.SubnetMask.Addr[2] = 0xFF;
-// Ip4Config.SubnetMask.Addr[3] = 0x00;
Ip4Config.DefaultProtocol = 1;
Ip4Config.AcceptAnyProtocol = FALSE;
Ip4Config.AcceptBroadcast = FALSE;
Ip4Config.AcceptIcmpErrors = TRUE;
Ip4Config.AcceptPromiscuous = FALSE;
@@ -1427,10 +1424,14 @@ ON_EXIT:
/**
Function for 'ping' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
+
+ @retval SHELL_SUCCESS The ping processed successfullly.
+ @retval others The ping processed unsuccessfully.
+
**/
SHELL_STATUS
EFIAPI
ShellCommandRunPing (
IN EFI_HANDLE ImageHandle,
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
index 68a7c93..98b40df 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
@@ -1,9 +1,9 @@
/** @file
header file for NULL named library for network1 shell command functions.
- Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>
+ Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
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
@@ -24,13 +24,11 @@
#include <Protocol/Cpu.h>
#include <Protocol/ServiceBinding.h>
#include <Protocol/Ip6.h>
#include <Protocol/Ip6Config.h>
#include <Protocol/Ip4.h>
-#include <Protocol/Ip4Config.h>
-#include <Protocol/HiiConfigAccess.h>
-#include <Protocol/HiiConfigRouting.h>
+#include <Protocol/Ip4Config2.h>
#include <Protocol/Arp.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
@@ -45,12 +43,10 @@
#include <Library/HiiLib.h>
#include <Library/NetLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
-#include <Guid/NicIp4ConfigNvData.h>
-
extern EFI_HANDLE gShellNetwork1HiiHandle;
/**
Function for 'ping' command.
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
index 527d2ef..6dfbbe5 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
@@ -57,11 +57,11 @@
gEfiCpuArchProtocolGuid ## CONSUMES
gEfiIp6ProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp6ConfigProtocolGuid ## SOMETIMES_CONSUMES
- gEfiIp6ProtocolGuid ## SOMETIMES_CONSUMES
- gEfiIp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
- gEfiIp6ConfigProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiIp4ProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiIp4ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiIp4Config2ProtocolGuid ## SOMETIMES_CONSUMES
[Guids]
gShellNetwork1HiiGuid ## SOMETIMES_CONSUMES ## HII
\ No newline at end of file
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
index aa27c678339c5e94c9c936d9a7ea74b6b043c200..1971ebc5f69c0e7de6ef2252de0428ac75bfaaaf 100644
GIT binary patch
delta 2471
zcmc&#T})eL7=9~b{0vrTDP5tghZ=;nU0FM!fWRm%KZP>***@12nrGc_le#Q!HnoO5@
z>tfJ%F<$76F<u##*~Az#&A9M-dgHYkjb;~1cITzfd%kmMDVmtL#GHKR`_B2^?|Gm1
z_uKy1^5i4S_OF(%`@g+s<8}KTj1E5Du%^#D4NL5<=-@z8n6EhAWnXm%A8Xv<K<5iQ
zQ****@KsG>mWaL-Zl1W`0ZnV=x6V^-qPnl(_MZ3rRfWO{<8T;eco}ebI|VQ`H0Ok
zM`vl4=4b}***@YjlG(vGoVLgL&f}hsd`JvzI(nupO{#>C9R#$1AHYtmFjV-q3mMvPN
z4cfxrb^Oa=FGGuvTf^54PWdDCNs3a8CifvbS+n|@1zE61X@$~s89180TA*b)Sz(;y
z`V$WJ2779ibP}>6aW3Yl5<O{JrHsfs3z}lEVhT?***@4&&c(7qs6&=Rb<49&%s
zrThtQJW<Etj&Qxwnt<eW=***@5WpeMS5G~x)+***@k14E*8H74cXBAFd_Z3i}
zJ*|***@mPfwY3Nvl7lL3jj4$z{a4hU;)JEeN8yIJ?o7H``LCaW41jP424s{Q}7sBQO
zyuP2wZn!I>n8Xb06_?Eey8a^%iAam&*d)***@UBtVTOQ<Wdpt#Jz@?{L<4Bn+yKLaLw
zG+4>*&dS;pvMmbVBqiG!4BE~3iU*e9^(<nna(EMbG<Z0JIB8-JySsdRD(I`N!hbKl
z0<MS$XS?3vulzn_qx_XW&hBY$>Z#_N5l!Tem^&c~^LLRso(~+dkHRY{cx42>k!WEh
znOd&***@ybPQ4(?N%tA7X>WrgKQ^<{JtS<3=e`rr<5C0HJ2(DF~8iwQu&P?*Tc8}EY
zEyY1NpZq_bnqsA5-VsGq(ld!><9xp_SfM!faWoPVTdI^uf=2mXc+63-K&rs3z-yIu
z?tihe3>6`;&FYNwG*tta;ITO5V>H9a{?iIY5Ts+N?0*B1D}MU$wTO<l02u?<^>?^>
zhmkCb{9Duw<dW3A)W3mT24rsSu~((QNn#e4$odP2(is-***@DvooUqwho
zIb!s_HabONdfk+5F?~C;FSkqv=vYSQGqPMd4F5dntSHghrf}pY8P>B|dXD&IR`2;H
z-tB<j;9*wHqcbjKZwZ>gY7FP)KDvlm;%B0ORSC-Okf)T<Kh}+j0`***@0zx$8dJ5N
zL!Zy=dD-Mw$gBkJ#{<>K>BIVMX;kl{NGm^Xck}nXw)}***@x7AqmOCzvoe5=KgAL{$e
zV#)FEFWqz9L<IX0Rk=lFCFp~AUggk)iw8a3kgK;kYENSKJb0~P+~Cldr|c>%$sLIP
zrS6TrPPLc0T5*Q+?dR=0)Ov{PG#hT;!}-***@p4Cw+***@UG7=H=L7NU7XEtV0Y4ZE
zd@^pabn`c3ZPESaiOyAAgi;I|X1Vs1%he^g1(Q~=Q&ga!|7QO4i4UIRq2vTVnR<=q
zCy(=|!3Jwd?D$&T$wR|+{CMJJ{%PuHx$awDJ>#_W$lKbBzMa#1x0h<E8vU`C=i7Z4
L-Wq(%KYjcK*m3RL
delta 2872
zcmdT`OH5;B6#lDHC|EkQln%qAx1}uu105bhVTc0hh0>AtBg6=4N+}Nq%1qmVK{N5O
zGSLO*Ok9{51JOiRKGK-XLXFJQxNtTm?ie#}W-)OVx-drl&VO%*hh-+SG^E^f|NGx_
zzVn^$od4dxZrHkE*t%<I{***@xNtkhKKrVnlN^7>t=k(***@EbbEms?7z_W`EF`2`;6|D
z-J&bT7W&a*q<fBQ)Zka><CA~TcKNp4KWuNI4^GX&_K>gQ3%T}p#ZU73SLH?ODX7fc
zZ2F;)zI9s7A<-u$MMMmXun5wQ*+#Dx)K4qIExcj?YYQSM)<go=WwD60VR23<VhSr!
zF(+0;9CvB#P(%`T8vmDZU6<=oJYT^R>06{kE!}y+R>E)0<Lxwl4Y0j*+vp{KT^XHr
z7TXxfh(y$n>lE%(dec=~^JqMiVoAg)***@Hf57cUG{(x2)_^4iytRm^z`g>6DcBtQ
zGAzb(G*3k|O5|y}8g|fgiq(*!sM5s<?GZ3C0^j|3D+Gk&U=SD!YFv+FEldwoo9i$>
z#-f0U70F)|csH3PR~#0v^HUWW1;wcF!wzC+9P0^st=n6q$hsssAK(j{Mp4NLus2S(
z{mu5AoKeJ7P9C*1Uve)}G*;V5*Og~WdJ#uOHW5VXMQ-D?tDKq5>EodeB=0~K#ye-h
zF)LtIqP~FDi?EiFmm(SG{|OO8J(4oln8X}{0(*hDPfX+b5{;ccdpz!{MR-gj$_B2R
***@XLJ7OK&M;5>*0u6Rc;c<5z4g;m1`ZmyTHxtduls3RkT&P?IXY<D8QCt;$_-*r@|5
zMn{>L|6cGoNiL6#W_-o8=XZCxQ914q4L>7Kz#H?X*<5W_C41MRb5AXD6f&t5=A)T*
znz`0N*`tHdA9wDb&idCMU9VjE#*W1m0|U#@8)MUY{2;<8x`$UAWli-7VLVKRgNquL
z?JNre$SOAv-Kn!NEr2_!3tDSLF6=VgvN$*4{4&5PdVmz}wSlvWJ&ORxL@}f_ltmjr
zDOfzN=B3ycvATeJ_7TNzLr;hc>E}O+DQ%AI2vi}***@v4C=srWK|{b<mvB
zo~KFV=ekfH)1RW=>b4qf=<ScQTtj20x~|9#EG)7$6dEFX8ja6FwjbQjP0hn_oSL0>
z<_+VJ-<rT%%uq}Ul~?$W2egjDIf|Ud#Sn5DhBd5Lf(1GWe-pG@)u{U#g^#3cUT))r
z<aXcJjwix#4Q>i}-=R;d+4|i(lCPtr7kxGS+~!8L4<8xl$fcIk_W6S871RVx4|E%{
z#!IjmSx`sZBw8?>8-e|aEM}WjUp>dqXa1W-D}CgfvP_^kMle<)S`-@dRq!6O#+?>f
zp$GN0&***@nxj}fs0=CI^***@pnWkal_;^hSZl!pa#!eOQSL80sdqnTp$r>AYG<X|<B9
zC*1UQR|g}?-0!++FvRGS=RbG63;`c4#H^SlL!g|#ZfVD^5{sR-Tc0syPl6<Ec6ZZO
z>j_fuL4YTjWVf1UkKw?}wrx!Bu_PZFR2{O?z<{-gj~2Z*aCF+~R>w)Y+gIx1V}=L2
zb~MG%IodJF`{huiOKKIlhpZ+ZXe)T0rnQ0cJQ<C4JIcwbS}oeZczAS?tKFXI>038A
z6p=GW`l|mM+Uqk0SU@~ykFt<GMH1X9atDX!vB6?(;M4-yJv;*9C{***@TBHM6M(uY
z2MfQ?vpp$=2oDU}q$P)>(T2`5?E4ZD=LlKJYF{%c*>daftbgS&9VoX(#v16D$6!Ia
zlngZ-mu==o$YA*YrfWWwF8$MfHS<>Z{ijSkw)te6XGZh+OW*?7MP+O`DoRm&TkQp`
e)HC=l{T4RTDNC{EzjdDhvorAN7G_Z>fByoOonQd~
Change and add some help messages in uni file.
Revert copyright year in UefiShellNetwork1CommandsLib.c file since there is no code change in this file.
This patch update ShellPkg ping/ifconfig library source code to consume Ip4Config2 protocol.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: jiaxinwu <***@intel.com>
---
.../UefiShellNetwork1CommandsLib/Ifconfig.c | 2439 ++++++++------------
.../Library/UefiShellNetwork1CommandsLib/Ping.c | 19 +-
.../UefiShellNetwork1CommandsLib.h | 8 +-
.../UefiShellNetwork1CommandsLib.inf | 6 +-
.../UefiShellNetwork1CommandsLib.uni | Bin 20112 -> 20078 bytes
5 files changed, 990 insertions(+), 1482 deletions(-)
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
index fa00d6c..6977d6b 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
@@ -1,7 +1,7 @@
/** @file
- The implementation for ifcommand shell command.
+ The implementation for Shell command ifconfig based on IP4Config2 protocol.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@@ -9,1774 +9,1285 @@
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
**/
#include "UefiShellNetwork1CommandsLib.h"
-#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE)
-#define EFI_IP4_TO_U32(EfiIpAddr) (*(IP4_ADDR*)((EfiIpAddr).Addr))
-
-BOOLEAN mIp4ConfigExist = FALSE;
-STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;
+typedef enum {
+ IfConfigOpList = 1,
+ IfConfigOpSet = 2,
+ IfConfigOpClear = 3
+} IFCONFIG_OPCODE;
+
+typedef enum {
+ VarCheckReserved = -1,
+ VarCheckOk = 0,
+ VarCheckDuplicate,
+ VarCheckConflict,
+ VarCheckUnknown,
+ VarCheckLackValue,
+ VarCheckOutOfMem
+} VAR_CHECK_CODE;
+
+typedef enum {
+ FlagTypeSingle = 0,
+ FlagTypeNeedVar,
+ FlagTypeNeedSet,
+ FlagTypeSkipUnknown
+} VAR_CHECK_FLAG_TYPE;
+
+#define MACADDRMAXSIZE 32
+
+typedef struct _IFCONFIG_INTERFACE_CB {
+ EFI_HANDLE NicHandle;
+ LIST_ENTRY Link;
+ EFI_IP4_CONFIG2_PROTOCOL *IfCfg;
+ EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
+ EFI_IP4_CONFIG2_POLICY Policy;
+ UINT32 DnsCnt;
+ EFI_IPv4_ADDRESS DnsAddr[1];
+} IFCONFIG_INTERFACE_CB;
+
+typedef struct _ARG_LIST ARG_LIST;
+
+struct _ARG_LIST {
+ ARG_LIST *Next;
+ CHAR16 *Arg;
+};
+
+typedef struct _IFCONFIG4_PRIVATE_DATA {
+ LIST_ENTRY IfList;
+
+ UINT32 OpCode;
+ CHAR16 *IfName;
+ ARG_LIST *VarArg;
+} IFCONFIG_PRIVATE_DATA;
+
+typedef struct _VAR_CHECK_ITEM{
+ CHAR16 *FlagStr;
+ UINT32 FlagID;
+ UINT32 ConflictMask;
+ VAR_CHECK_FLAG_TYPE FlagType;
+} VAR_CHECK_ITEM;
+
+SHELL_PARAM_ITEM mIfConfigCheckList[] = {
+ {
+ L"-b",
+ TypeFlag
+ },
+ {
+ L"-l",
+ TypeValue
+ },
+ {
+ L"-r",
+ TypeValue
+ },
+ {
+ L"-c",
+ TypeValue
+ },
+ {
+ L"-s",
+ TypeMaxValue
+ },
+ {
+ NULL,
+ TypeMax
+ },
+};
+
+VAR_CHECK_ITEM mSetCheckList[] = {
+ {
+ L"static",
+ 0x00000001,
+ 0x00000001,
+ FlagTypeSingle
+ },
+ {
+ L"dhcp",
+ 0x00000002,
+ 0x00000001,
+ FlagTypeSingle
+ },
+ {
+ L"dns",
+ 0x00000008,
+ 0x00000004,
+ FlagTypeSingle
+ },
+ {
+ NULL,
+ 0x0,
+ 0x0,
+ FlagTypeSkipUnknown
+ },
+};
-STATIC CONST UINTN SecondsToNanoSeconds = 10000000;
-STATIC CONST CHAR16 DhcpString[5] = L"DHCP";
-STATIC CONST CHAR16 StaticString[7] = L"STATIC";
STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";
-typedef struct {
- LIST_ENTRY Link;
- EFI_HANDLE Handle;
- NIC_ADDR NicAddress;
- CHAR16 Name[IP4_NIC_NAME_LENGTH];
- BOOLEAN MediaPresentSupported;
- BOOLEAN MediaPresent;
- EFI_IP4_CONFIG_PROTOCOL *Ip4Config;
- NIC_IP4_CONFIG_INFO *ConfigInfo;
-} NIC_INFO;
-
-typedef struct {
- EFI_IP_ADDRESS DestIp;
- EFI_MAC_ADDRESS DestMac;
- EFI_IP_ADDRESS LocalIp;
- EFI_MAC_ADDRESS LocalMac;
- UINT8 MacLen;
- EFI_EVENT OnResolved;
- BOOLEAN Duplicate;
-} ARP_REQUEST;
-
-STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
- {L"-c", TypeValue},
- {L"-l", TypeValue},
- {L"-s", TypeMaxValue},
- {NULL, TypeMax}
- };
-
-STATIC LIST_ENTRY NicInfoList;
-STATIC BOOLEAN ArpResolved;
-STATIC BOOLEAN mTimeout;
-
/**
- Count the space delimited items in a string.
-
- @param[in] String A pointer to the string to count.
-
- @return The number of space-delimited items.
- @retval 0xFF an error occured.
-**/
-UINT8
-EFIAPI
-CountSubItems (
- IN CONST CHAR16 *String
- )
-{
- CONST CHAR16 *Walker;
- UINT8 Count;
-
- if (String == NULL || *String == CHAR_NULL) {
- return (0xFF);
- }
+ Split a string with specified separator and save the substring to a list.
- for (Walker = String, Count = 0 ; Walker != NULL && *Walker != CHAR_NULL ; Walker = (StrStr(Walker, L" ")==NULL?NULL:StrStr(Walker, L" ")+1), Count++);
- return (Count);
-}
+ @param[in] String The pointer of the input string.
+ @param[in] Separator The specified separator.
-/**
- Find the NIC_INFO by the specified nic name.
+ @return The pointer of headnode of ARG_LIST.
- @param[in] Name The pointer to the string containing the NIC name.
-
- @return The pointer to the NIC_INFO if there is a NIC_INFO named by Name.
- @retval NULL No NIC_INFO was found for Name.
**/
-NIC_INFO*
-EFIAPI
-IfconfigFindNicByName (
- IN CONST CHAR16 *Name
+ARG_LIST *
+SplitStrToList (
+ IN CONST CHAR16 *String,
+ IN CHAR16 Separator
)
{
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
- NIC_INFO *Info;
- CHAR16 *TempString;
-
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- Info = BASE_CR (Entry, NIC_INFO, Link);
- TempString = (CHAR16*)Info->Name;
+ CHAR16 *Str;
+ CHAR16 *ArgStr;
+ ARG_LIST *ArgList;
+ ARG_LIST *ArgNode;
- if (StringNoCaseCompare (&Name, &TempString) == 0) {
- return Info;
- }
+ if (*String == L'\0') {
+ return NULL;
}
- return NULL;
-}
-
-/**
- Tests whether a child handle is a child device of the controller.
-
- @param[in] ControllerHandle A handle for a (parent) controller to test.
- @param[in] ChildHandle A child handle to test.
- @param[in] ProtocolGuid Supplies the protocol that the child controller
- opens on its parent controller.
-
- @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
- @retval EFI_UNSUPPORTED ChildHandle is not a child of the ControllerHandle.
-**/
-EFI_STATUS
-EFIAPI
-TestChildHandle (
- IN CONST EFI_HANDLE ControllerHandle,
- IN CONST EFI_HANDLE ChildHandle,
- IN CONST EFI_GUID *ProtocolGuid
- )
-{
- EFI_STATUS Status;
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
- UINTN EntryCount;
- UINTN Index;
-
- ASSERT (ProtocolGuid != NULL);
-
//
- // Retrieve the list of agents that are consuming the specific protocol
- // on ControllerHandle.
+ // Copy the CONST string to a local copy.
//
- Status = gBS->OpenProtocolInformation (
- ControllerHandle,
- (EFI_GUID *) ProtocolGuid,
- &OpenInfoBuffer,
- &EntryCount
- );
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
+ Str = AllocateCopyPool (StrSize (String), String);
+ ASSERT (Str != NULL);
+ ArgStr = Str;
//
- // Inspect if ChildHandle is one of the agents.
+ // init a node for the list head.
//
- Status = EFI_UNSUPPORTED;
- for (Index = 0; Index < EntryCount; Index++) {
- if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&
- (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
- Status = EFI_SUCCESS;
- break;
- }
- }
-
- FreePool (OpenInfoBuffer);
- return Status;
-}
-
-/**
- Get the child handle of the NIC handle.
-
- @param[in] Controller Routing information: GUID.
- @param[out] ChildHandle Returned child handle.
-
- @retval EFI_SUCCESS Successfully to get child handle.
-**/
-EFI_STATUS
-GetChildHandle (
- IN EFI_HANDLE Controller,
- OUT EFI_HANDLE *ChildHandle
- )
-{
- EFI_STATUS Status;
- EFI_HANDLE *Handles;
- UINTN HandleCount;
- UINTN Index;
- EFI_DEVICE_PATH_PROTOCOL *ChildDeviceDevicePath;
- VENDOR_DEVICE_PATH *VendorDeviceNode;
+ ArgNode = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
+ ASSERT (ArgNode != NULL);
+ ArgList = ArgNode;
//
- // Locate all EFI Hii Config Access protocols
+ // Split the local copy and save in the list node.
//
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiHiiConfigAccessProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
- );
- if (EFI_ERROR (Status) || (HandleCount == 0)) {
- return Status;
- }
-
- Status = EFI_NOT_FOUND;
-
- for (Index = 0; Index < HandleCount; Index++) {
-
- Status = TestChildHandle (Controller, Handles[Index], &gEfiManagedNetworkServiceBindingProtocolGuid);
- if (!EFI_ERROR (Status)) {
- //
- // Get device path on the child handle
- //
- Status = gBS->HandleProtocol (
- Handles[Index],
- &gEfiDevicePathProtocolGuid,
- (VOID **) &ChildDeviceDevicePath
- );
-
- if (!EFI_ERROR (Status)) {
- while (!IsDevicePathEnd (ChildDeviceDevicePath)) {
- ChildDeviceDevicePath = NextDevicePathNode (ChildDeviceDevicePath);
- //
- // Parse one instance
- //
- if (ChildDeviceDevicePath->Type == HARDWARE_DEVICE_PATH &&
- ChildDeviceDevicePath->SubType == HW_VENDOR_DP) {
- VendorDeviceNode = (VENDOR_DEVICE_PATH *) ChildDeviceDevicePath;
- if (CompareMem (&VendorDeviceNode->Guid, &gEfiNicIp4ConfigVariableGuid, sizeof (EFI_GUID)) == 0) {
- //
- // Found item matched gEfiNicIp4ConfigVariableGuid
- //
- *ChildHandle = Handles[Index];
- FreePool (Handles);
- return EFI_SUCCESS;
- }
- }
- }
- }
+ while (*Str != L'\0') {
+ if (*Str == Separator) {
+ *Str = L'\0';
+ ArgNode->Arg = ArgStr;
+ ArgStr = Str + 1;
+ ArgNode->Next = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
+ ASSERT (ArgNode->Next != NULL);
+ ArgNode = ArgNode->Next;
}
+
+ Str++;
}
- FreePool (Handles);
- return Status;
+ ArgNode->Arg = ArgStr;
+ ArgNode->Next = NULL;
+
+ return ArgList;
}
/**
- Append OFFSET/WIDTH/VALUE items at the beginning of string.
-
- @param[in, out] String The pointer to the string to append onto.
- @param[in] MaxLen The max number of UNICODE char in String
- including the terminate NULL char.
- @param[in] Offset Offset value.
- @param[in] Width Width value.
- @param[in] Block Point to data buffer.
-
- @return The count of unicode character that were appended.
-**/
-UINTN
-EFIAPI
-AppendOffsetWidthValue (
- IN OUT CHAR16 *String,
- IN UINTN MaxLen,
- IN UINTN Offset,
- IN UINTN Width,
- IN CONST UINT8 *Block
- )
-
-{
- CHAR16 *OriString;
-
- OriString = String;
-
- StrnCpyS (String, MaxLen, L"&OFFSET=", 9);
- String += StrLen (L"&OFFSET=");
- String += UnicodeSPrint (String, 20, L"%x", Offset);
-
- StrnCpyS (String, MaxLen, L"&WIDTH=", 8);
- String += StrLen (L"&WIDTH=");
- String += UnicodeSPrint (String, 20, L"%x", Width);
+ Check the correctness of input Args with '-s' option.
- if (Block != NULL) {
- StrnCpyS (String, MaxLen, L"&VALUE=", 8);
- String += StrLen (L"&VALUE=");
- while ((Width--) != 0) {
- String += UnicodeSPrint (String, 20, L"%x", Block[Width]);
- }
- }
-
- return String - OriString;
-}
+ @param[in] CheckList The pointer of VAR_CHECK_ITEM array.
+ @param[in] Name The pointer of input arg.
+ @param[in] Init The switch to execute the check.
-/**
- Converts the unicode character of the string from uppercase to lowercase.
- This is a internal function.
+ @return VarCheckOk Valid parameter or Initialize check successfully.
+ @return VarCheckDuplicate Duplicated parameter happened.
+ @return VarCheckConflict Conflicted parameter happened
+ @return VarCheckUnknown Unknown parameter.
- @param ConfigString String to be converted
**/
-CHAR16*
-EFIAPI
-HiiToLower (
- IN CHAR16 *ConfigString
- )
+VAR_CHECK_CODE
+IfConfigRetriveCheckListByName(
+ IN VAR_CHECK_ITEM *CheckList,
+ IN CHAR16 *Name,
+ IN BOOLEAN Init
+)
{
- CHAR16 *String;
- BOOLEAN Lower;
-
- //
- // Convert all hex digits in range [A-F] in the configuration header to [a-f]
- //
- for (String = ConfigString, Lower = FALSE; String != NULL && *String != L'\0'; String++) {
- if (*String == L'=') {
- Lower = TRUE;
- } else if (*String == L'&') {
- Lower = FALSE;
- } else if (Lower && *String >= L'A' && *String <= L'F') {
- *String = (CHAR16) (*String - L'A' + L'a');
- }
+ STATIC UINT32 CheckDuplicate;
+ STATIC UINT32 CheckConflict;
+ VAR_CHECK_CODE RtCode;
+ UINT32 Index;
+ VAR_CHECK_ITEM Arg;
+
+ if (Init) {
+ CheckDuplicate = 0;
+ CheckConflict = 0;
+ return VarCheckOk;
}
- return (ConfigString);
-}
-
-
-/**
- Construct <ConfigHdr> using routing information GUID/NAME/PATH.
-
- @param[in] Guid Routing information: GUID.
- @param[in] Name Routing information: NAME.
- @param[in] DriverHandle Driver handle which contains the routing information: PATH.
-
- @retval NULL An error occured.
- @return The pointer to configHdr string.
-**/
-CHAR16 *
-EFIAPI
-ConstructConfigHdr (
- IN CONST EFI_GUID *Guid,
- IN CONST CHAR16 *Name,
- IN EFI_HANDLE DriverHandle
- )
-{
- EFI_STATUS Status;
- CHAR16 *ConfigHdr;
- UINTN ConfigHdrBufferSize;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- CHAR16 *String;
- UINTN Index;
- UINT8 *Buffer;
- UINTN DevicePathLength;
- UINTN NameLength;
+ RtCode = VarCheckOk;
+ Index = 0;
+ Arg = CheckList[Index];
//
- // Get the device path from handle installed EFI HII Config Access protocol
+ // Check the Duplicated/Conflicted/Unknown input Args.
//
- Status = gBS->HandleProtocol (
- DriverHandle,
- &gEfiDevicePathProtocolGuid,
- (VOID **) &DevicePath
- );
- if (EFI_ERROR (Status)) {
- return NULL;
- }
+ while (Arg.FlagStr != NULL) {
+ if (StrCmp (Arg.FlagStr, Name) == 0) {
- DevicePathLength = GetDevicePathSize (DevicePath);
- NameLength = StrLen (Name);
- ConfigHdrBufferSize = (5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16);
- ConfigHdr = AllocateZeroPool (ConfigHdrBufferSize);
- if (ConfigHdr == NULL) {
- return NULL;
- }
+ if (CheckDuplicate & Arg.FlagID) {
+ RtCode = VarCheckDuplicate;
+ break;
+ }
- String = ConfigHdr;
- StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"GUID=", 6);
- String += StrLen (L"GUID=");
+ if (CheckConflict & Arg.ConflictMask) {
+ RtCode = VarCheckConflict;
+ break;
+ }
- //
- // Append Guid converted to <HexCh>32
- //
- for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {
- String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);
- }
+ CheckDuplicate |= Arg.FlagID;
+ CheckConflict |= Arg.ConflictMask;
+ break;
+ }
- //
- // Append L"&NAME="
- //
- StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&NAME=", 7);
- String += StrLen (L"&NAME=");
- for (Index = 0; Index < NameLength ; Index++) {
- String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);
+ Arg = CheckList[++Index];
}
-
- //
- // Append L"&PATH="
- //
- StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&PATH=", 7);
- String += StrLen (L"&PATH=");
- for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {
- String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);
+
+ if (Arg.FlagStr == NULL) {
+ RtCode = VarCheckUnknown;
}
- return (HiiToLower(ConfigHdr));
+ return RtCode;
}
/**
- Get network physical device NIC information.
+ The notify function of create event when performing a manual config.
- @param[in] Handle The network physical device handle.
- @param[out] NicAddr NIC information.
+ @param[in] Event The event this notify function registered to.
+ @param[in] Context Pointer to the context data registered to the event.
- @retval EFI_SUCCESS Get NIC information successfully.
-**/
-EFI_STATUS
+**/
+VOID
EFIAPI
-IfConfigGetNicMacInfo (
- IN EFI_HANDLE Handle,
- OUT NIC_ADDR *NicAddr
- )
+IfConfigManualAddressNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
{
- EFI_STATUS Status;
- EFI_HANDLE MnpHandle;
- EFI_SIMPLE_NETWORK_MODE SnpMode;
- EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
-
- MnpHandle = NULL;
- Mnp = NULL;
-
- Status = NetLibCreateServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- &MnpHandle
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Status = gBS->HandleProtocol (
- MnpHandle,
- &gEfiManagedNetworkProtocolGuid,
- (VOID **) &Mnp
- );
- if (EFI_ERROR (Status)) {
- goto ON_ERROR;
- }
-
- Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);
- if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
- goto ON_ERROR;
- }
-
- NicAddr->Type = (UINT16) SnpMode.IfType;
- NicAddr->Len = (UINT8) SnpMode.HwAddressSize;
- CopyMem (&NicAddr->MacAddr, &SnpMode.CurrentAddress, NicAddr->Len);
-
-ON_ERROR:
-
- NetLibDestroyServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- MnpHandle
- );
-
- return Status;
-
+ *((BOOLEAN *) Context) = TRUE;
}
+
/**
- Get network physical device NIC information.
+ Print MAC address.
- @param[in] Handle The network physical device handle.
- @param[out] MediaPresentSupported
- Upon successful return, TRUE is media present
- is supported. FALSE otherwise.
- @param[out] MediaPresent Upon successful return, TRUE is media present
- is enabled. FALSE otherwise.
+ @param[in] Node The pointer of MAC address buffer.
+ @param[in] Size The size of MAC address buffer.
- @retval EFI_SUCCESS The operation was successful.
**/
-EFI_STATUS
-EFIAPI
-IfConfigGetNicMediaStatus (
- IN EFI_HANDLE Handle,
- OUT BOOLEAN *MediaPresentSupported,
- OUT BOOLEAN *MediaPresent
- )
-
+VOID
+IfConfigPrintMacAddr (
+ IN UINT8 *Node,
+ IN UINT32 Size
+ )
{
- EFI_STATUS Status;
- EFI_HANDLE MnpHandle;
- EFI_SIMPLE_NETWORK_MODE SnpMode;
- EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
-
- MnpHandle = NULL;
- Mnp = NULL;
-
- Status = NetLibCreateServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- &MnpHandle
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ UINTN Index;
- Status = gBS->HandleProtocol (
- MnpHandle,
- &gEfiManagedNetworkProtocolGuid,
- (VOID **) &Mnp
- );
- if (EFI_ERROR (Status)) {
- goto ON_ERROR;
- }
+ ASSERT (Size <= MACADDRMAXSIZE);
- Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);
- if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
- goto ON_ERROR;
+ for (Index = 0; Index < Size; Index++) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_BODY), gShellNetwork1HiiHandle, Node[Index]);
+ if (Index + 1 < Size) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_COLON), gShellNetwork1HiiHandle);
+ }
}
-
- *MediaPresentSupported = SnpMode.MediaPresentSupported;
- *MediaPresent = SnpMode.MediaPresent;
-ON_ERROR:
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE), gShellNetwork1HiiHandle);
+}
- NetLibDestroyServiceChild (
- Handle,
- gImageHandle,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- MnpHandle
- );
- return Status;
+/**
+ The get current status of all handles.
-}
+ @param[in] IfName The pointer of IfName(interface name).
+ @param[in] IfList The pointer of IfList(interface list).
-/**
- Get all Nic's information through HII service.
+ @retval EFI_SUCCESS The get status processed successfully.
+ @retval others The get status process failed.
- @retval EFI_SUCCESS All the nic information is collected.
**/
EFI_STATUS
-EFIAPI
-IfconfigGetAllNicInfoByHii (
- VOID
+IfConfigGetInterfaceInfo (
+ IN CHAR16 *IfName,
+ IN LIST_ENTRY *IfList
)
{
- EFI_STATUS Status;
- EFI_HANDLE *Handles;
- UINTN HandleCount;
- CHAR16 *ConfigResp;
- UINTN ConfigRespBufferSize;
- CHAR16 *ConfigHdr;
- UINTN Index;
- CHAR16 *AccessProgress;
- CHAR16 *AccessResults;
- UINTN BufferSize;
- NIC_INFO *NicInfo;
- NIC_IP4_CONFIG_INFO *NicConfigRequest;
- NIC_IP4_CONFIG_INFO *NicConfig;
- CHAR16 *String;
- UINTN Length;
- UINTN Offset;
- EFI_HANDLE ChildHandle;
-
- AccessResults = NULL;
- ConfigHdr = NULL;
- ConfigResp = NULL;
- NicConfigRequest = NULL;
- NicInfo = NULL;
-
- InitializeListHead (&NicInfoList);
+ EFI_STATUS Status;
+ UINTN HandleIndex;
+ UINTN HandleNum;
+ EFI_HANDLE *HandleBuffer;
+ EFI_IP4_CONFIG2_PROTOCOL *Ip4Cfg2;
+ EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ UINTN DataSize;
- //
- // Check if HII Config Routing protocol available.
- //
- Status = gBS->LocateProtocol (
- &gEfiHiiConfigRoutingProtocolGuid,
- NULL,
- (VOID**)&mHiiConfigRouting
- );
- if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
- }
+ HandleBuffer = NULL;
+ HandleNum = 0;
+
+ IfInfo = NULL;
+ IfCb = NULL;
//
- // Locate all network device handles
+ // Locate all the handles with ip4 service binding protocol.
//
Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiManagedNetworkServiceBindingProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
+ ByProtocol,
+ &gEfiIp4ServiceBindingProtocolGuid,
+ NULL,
+ &HandleNum,
+ &HandleBuffer
);
- if (EFI_ERROR (Status) || (HandleCount == 0)) {
- return EFI_NOT_FOUND;
+ if (EFI_ERROR (Status) || (HandleNum == 0)) {
+ return EFI_ABORTED;
}
- for (Index = 0; Index < HandleCount; Index++) {
- Status = GetChildHandle (Handles[Index], &ChildHandle);
+ //
+ // Enumerate all handles that installed with ip4 service binding protocol.
+ //
+ for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
+ IfCb = NULL;
+ IfInfo = NULL;
+ DataSize = 0;
+
+ //
+ // Ip4config protocol and ip4 service binding protocol are installed
+ // on the same handle.
+ //
+ ASSERT (HandleBuffer != NULL);
+ Status = gBS->HandleProtocol (
+ HandleBuffer[HandleIndex],
+ &gEfiIp4Config2ProtocolGuid,
+ (VOID **) &Ip4Cfg2
+ );
+
if (EFI_ERROR (Status)) {
- //
- // If failed to get Child handle, try NIC controller handle for back-compatibility.
- //
- ChildHandle = Handles[Index];
+ goto ON_ERROR;
}
+
//
- // Construct configuration request string header
+ // Get the interface information size.
//
- ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);
- if (ConfigHdr != NULL) {
- Length = StrLen (ConfigHdr);
- } else {
- Length = 0;
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeInterfaceInfo,
+ &DataSize,
+ NULL
+ );
+
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ goto ON_ERROR;
}
- ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);
- ConfigResp = AllocateZeroPool (ConfigRespBufferSize);
- if (ConfigResp == NULL) {
+
+ IfInfo = AllocateZeroPool (DataSize);
+
+ if (IfInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
- if (ConfigHdr != NULL) {
- StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
- }
-
+
//
- // Append OFFSET/WIDTH pair
+ // Get the interface info.
//
- String = ConfigResp + Length;
- Offset = 0;
- AppendOffsetWidthValue (String,
- ConfigRespBufferSize/sizeof(CHAR16) - Length,
- Offset,
- NIC_ITEM_CONFIG_SIZE,
- NULL
- );
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeInterfaceInfo,
+ &DataSize,
+ IfInfo
+ );
- NicInfo = AllocateZeroPool (sizeof (NIC_INFO));
- if (NicInfo == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+ if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
- NicInfo->Handle = Handles[Index];
-
+
//
- // Get network physical devcie MAC information
+ // Check the interface name if required.
//
- IfConfigGetNicMacInfo (Handles[Index], &NicInfo->NicAddress);
- if (NicInfo->NicAddress.Type == NET_IFTYPE_ETHERNET) {
- UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"eth%d", Index);
- } else {
- UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"unk%d", Index);
+ if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) != 0)) {
+ FreePool (IfInfo);
+ continue;
}
+ DataSize = 0;
+
//
- // Get media status
+ // Get the size of dns server list.
//
- IfConfigGetNicMediaStatus (Handles[Index], &NicInfo->MediaPresentSupported, &NicInfo->MediaPresent);
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeDnsServer,
+ &DataSize,
+ NULL
+ );
+
+ if ((Status != EFI_BUFFER_TOO_SMALL) && (Status != EFI_NOT_FOUND)) {
+ goto ON_ERROR;
+ }
+
+ IfCb = AllocateZeroPool (sizeof (IFCONFIG_INTERFACE_CB) + DataSize);
- NicConfigRequest = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
- if (NicConfigRequest == NULL) {
+ if (IfCb == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
+ IfCb->NicHandle = HandleBuffer[HandleIndex];
+ IfCb->IfInfo = IfInfo;
+ IfCb->IfCfg = Ip4Cfg2;
+ IfCb->DnsCnt = (UINT32) (DataSize / sizeof (EFI_IPv4_ADDRESS));
+
//
- // Get network parameters by HII service
+ // Get the dns server list if has.
//
- Status = mHiiConfigRouting->ExtractConfig (
- mHiiConfigRouting,
- ConfigResp,
- &AccessProgress,
- &AccessResults
- );
- if (!EFI_ERROR (Status)) {
- BufferSize = NIC_ITEM_CONFIG_SIZE;
- Status = mHiiConfigRouting->ConfigToBlock (
- mHiiConfigRouting,
- AccessResults,
- (UINT8 *) NicConfigRequest,
- &BufferSize,
- &AccessProgress
- );
- if (!EFI_ERROR (Status)) {
- BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * NicConfigRequest->Ip4Info.RouteTableSize;
- NicConfig = AllocateZeroPool (BufferSize);
- if (NicConfig == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- goto ON_ERROR;
- }
- CopyMem (NicConfig, NicConfigRequest, BufferSize);
-
- //
- // If succeeds to get NIC configuration, fix up routetable pointer.
- //
- NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (&NicConfig->Ip4Info + 1);
- NicInfo->ConfigInfo = NicConfig;
-
- } else {
- NicInfo->ConfigInfo = NULL;
+ if (DataSize > 0) {
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypeDnsServer,
+ &DataSize,
+ IfCb->DnsAddr
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
}
-
- FreePool (AccessResults);
-
- } else {
- NicInfo->ConfigInfo = NULL;
}
//
- // Add the Nic's info to the global NicInfoList.
+ // Get the config policy.
//
- InsertTailList (&NicInfoList, &NicInfo->Link);
+ DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);
+ Status = Ip4Cfg2->GetData (
+ Ip4Cfg2,
+ Ip4Config2DataTypePolicy,
+ &DataSize,
+ &IfCb->Policy
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ InsertTailList (IfList, &IfCb->Link);
- FreePool (NicConfigRequest);
- FreePool (ConfigResp);
- FreePool (ConfigHdr);
+ if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) == 0)) {
+ //
+ // Only need the appointed interface, keep the allocated buffer.
+ //
+ IfCb = NULL;
+ IfInfo = NULL;
+ break;
+ }
}
- FreePool (Handles);
+ if (HandleBuffer != NULL) {
+ FreePool (HandleBuffer);
+ }
return EFI_SUCCESS;
-
+
ON_ERROR:
- if (AccessResults != NULL) {
- FreePool (AccessResults);
- }
- if (NicConfigRequest != NULL) {
- FreePool (NicConfigRequest);
- }
- if (NicInfo != NULL) {
- FreePool (NicInfo);
- }
- if (ConfigResp != NULL) {
- FreePool (ConfigResp);
- }
- if (ConfigHdr != NULL) {
- FreePool (ConfigHdr);
+
+ if (IfInfo != NULL) {
+ FreePool (IfInfo);
}
- FreePool (Handles);
+ if (IfCb != NULL) {
+ FreePool (IfCb);
+ }
return Status;
}
/**
- Set the address for the specified nic by HII service.
+ The list process of the ifconfig command.
- @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.
- @param[in] Config The command line arguments for the set operation.
+ @param[in] IfList The pointer of IfList(interface list).
+
+ @retval EFI_SUCCESS The ifconfig command list processed successfully.
+ @retval others The ifconfig command list process failed.
- @retval EFI_SUCCESS The address set operation is done.
**/
-SHELL_STATUS
-EFIAPI
-IfconfigSetNicAddrByHii (
- IN CONST NIC_INFO *NicInfo,
- IN CONST NIC_IP4_CONFIG_INFO *Config
+EFI_STATUS
+IfConfigShowInterfaceInfo (
+ IN LIST_ENTRY *IfList
)
{
- EFI_STATUS Status;
- SHELL_STATUS ShellStatus;
- NIC_IP4_CONFIG_INFO *NicConfig;
- CHAR16 *ConfigResp;
- UINTN ConfigRespBufferSize;
- CHAR16 *ConfigHdr;
- CHAR16 *AccessProgress;
- CHAR16 *AccessResults;
- CHAR16 *String;
- UINTN Length;
- UINTN Offset;
- EFI_HANDLE ChildHandle;
-
- AccessResults = NULL;
- ConfigHdr = NULL;
- ConfigResp = NULL;
- NicConfig = NULL;
- ShellStatus = SHELL_SUCCESS;
-
- Status = GetChildHandle (NicInfo->Handle, &ChildHandle);
- if (EFI_ERROR (Status)) {
- //
- // If failed to get Child handle, try NIC controller handle for back-compatibility
- //
- ChildHandle = NicInfo->Handle;
- }
- //
- // Construct config request string header
- //
- ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);
- if (ConfigHdr != NULL) {
- Length = StrLen (ConfigHdr);
- } else {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- goto ON_EXIT;
- }
- ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);
- ConfigResp = AllocateZeroPool (ConfigRespBufferSize);
- if (ConfigResp == NULL) {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- goto ON_EXIT;
- }
- if (ConfigHdr != NULL) {
- StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
- }
+ EFI_STATUS Status;
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *Next;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ EFI_IPv4_ADDRESS Gateway;
+ UINT32 Index;
- NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
- if (NicConfig == NULL) {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- goto ON_EXIT;
- }
+ Status = EFI_SUCCESS;
- if (Config != NULL) {
- CopyMem (NicConfig, Config, sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * Config->Ip4Info.RouteTableSize);
+ if (IsListEmpty (IfList)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);
}
//
- // Append OFFSET/WIDTH pair
+ // Go through the interface list.
//
- String = ConfigResp + Length;
- Offset = 0;
- AppendOffsetWidthValue (String,
- ConfigRespBufferSize/sizeof(CHAR16) - Length,
- Offset,
- NIC_ITEM_CONFIG_SIZE,
- NULL
- );
+ NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {
+ IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);
- //
- // Call HII helper function to generate configuration string
- //
- Status = mHiiConfigRouting->BlockToConfig (
- mHiiConfigRouting,
- ConfigResp,
- (UINT8 *) NicConfig,
- NIC_ITEM_CONFIG_SIZE,
- &AccessResults,
- &AccessProgress
- );
- if (EFI_ERROR (Status)) {
- ShellStatus = SHELL_NOT_FOUND;
- goto ON_EXIT;
- }
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK), gShellNetwork1HiiHandle);
- //
- // Set IP setting by HII servie
- //
- Status = mHiiConfigRouting->RouteConfig (
- mHiiConfigRouting,
- AccessResults,
- &AccessProgress
- );
- if (EFI_ERROR(Status)) {
- ShellStatus = SHELL_ACCESS_DENIED;
- }
+ //
+ // Print interface name.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_IF_NAME), gShellNetwork1HiiHandle, IfCb->IfInfo->Name);
-ON_EXIT:
- SHELL_FREE_NON_NULL(AccessResults);
- SHELL_FREE_NON_NULL(NicConfig);
- SHELL_FREE_NON_NULL(ConfigResp);
- SHELL_FREE_NON_NULL(ConfigHdr);
+ //
+ // Print interface config policy.
+ //
+ if (IfCb->Policy == Ip4Config2PolicyDhcp) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_DHCP), gShellNetwork1HiiHandle);
+ } else {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_MAN), gShellNetwork1HiiHandle);
+ }
- return ShellStatus;
-}
+ //
+ // Print mac address of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_HEAD), gShellNetwork1HiiHandle);
-/**
- The callback function for the Arp address resolved event.
+ IfConfigPrintMacAddr (
+ IfCb->IfInfo->HwAddress.Addr,
+ IfCb->IfInfo->HwAddressSize
+ );
- @param[in] Event The event this function is registered to.
- @param[in] Context The context registered to the event.
-**/
-VOID
-EFIAPI
-IfconfigOnArpResolved (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- ARP_REQUEST *Request;
- UINT8 Index;
+ //
+ // Print IPv4 address list of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_HEAD), gShellNetwork1HiiHandle);
- Request = (ARP_REQUEST *) Context;
- ASSERT (Request != NULL);
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[0],
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[1],
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[2],
+ (UINTN)IfCb->IfInfo->StationAddress.Addr[3]
+ );
+
+ //
+ // Print subnet mask list of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_SUBNET_MASK_HEAD), gShellNetwork1HiiHandle);
- Request->Duplicate = FALSE;
-
- if (0 == CompareMem (&Request->LocalMac, &Request->DestMac, Request->MacLen)) {
ShellPrintHiiEx(
-1,
-1,
NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Already Configured",
- (UINTN)Request->DestIp.v4.Addr[0],
- (UINTN)Request->DestIp.v4.Addr[1],
- (UINTN)Request->DestIp.v4.Addr[2],
- (UINTN)Request->DestIp.v4.Addr[3]
+ STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[0],
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[1],
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[2],
+ (UINTN)IfCb->IfInfo->SubnetMask.Addr[3]
);
- ArpResolved = TRUE;
- return;
- }
-
- for (Index = 0; Index < Request->MacLen; Index++) {
- if (Request->DestMac.Addr[Index] != 0) {
- Request->Duplicate = TRUE;
- }
- }
- if (Request->Duplicate) {
+ //
+ // Print default gateway of the interface.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_GATEWAY_HEAD), gShellNetwork1HiiHandle);
+
+ ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));
+
+ for (Index = 0; Index < IfCb->IfInfo->RouteTableSize; Index++) {
+ if ((CompareMem (&IfCb->IfInfo->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&
+ (CompareMem (&IfCb->IfInfo->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){
+ CopyMem (&Gateway, &IfCb->IfInfo->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
+ }
+ }
+
ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR),
- gShellNetwork1HiiHandle,
- (UINTN)Request->DestMac.Addr[0],
- (UINTN)Request->DestMac.Addr[1],
- (UINTN)Request->DestMac.Addr[2],
- (UINTN)Request->DestMac.Addr[3],
- (UINTN)Request->DestMac.Addr[4],
- (UINTN)Request->DestMac.Addr[5]
- );
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN)Gateway.Addr[0],
+ (UINTN)Gateway.Addr[1],
+ (UINTN)Gateway.Addr[2],
+ (UINTN)Gateway.Addr[3]
+ );
+
+ //
+ // Print route table entry.
+ //
+ ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, IfCb->IfInfo->RouteTableSize);
+
+ for (Index = 0; Index < IfCb->IfInfo->RouteTableSize; Index++) {
+ ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);
+
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
+ gShellNetwork1HiiHandle,
+ L"Subnet ",
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[0],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[1],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[2],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[3]
+ );
+
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
+ gShellNetwork1HiiHandle,
+ L"Netmask",
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[0],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[1],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[2],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[3]
+ );
+
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
+ gShellNetwork1HiiHandle,
+ L"Gateway",
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[0],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[1],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[2],
+ (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[3]
+ );
+ }
+
+ //
+ // Print dns server addresses list of the interface if has.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_HEAD), gShellNetwork1HiiHandle);
+
+ for (Index = 0; Index < IfCb->DnsCnt; Index++) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_BODY),
+ gShellNetwork1HiiHandle,
+ (UINTN) IfCb->DnsAddr[Index].Addr[0],
+ (UINTN) IfCb->DnsAddr[Index].Addr[1],
+ (UINTN) IfCb->DnsAddr[Index].Addr[2],
+ (UINTN) IfCb->DnsAddr[Index].Addr[3]
+ );
+
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE), gShellNetwork1HiiHandle);
+ }
}
+
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK), gShellNetwork1HiiHandle);
- ArpResolved = TRUE;
- return ;
+ return EFI_SUCCESS;
}
/**
- Check whether the address to be configured conflicts with other hosts.
+ The clean process of the ifconfig command to clear interface info.
+
+ @param[in] IfList The pointer of IfList(interface list).
- @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
- @param[in] IpAddr The IPv4 address to be configured to the Nic.
+ @retval EFI_SUCCESS The ifconfig command clean processed successfully.
+ @retval others The ifconfig command clean process failed.
- @return TRUE Some other host already uses the IpAddr.
- @return FALSE The address is unused.
**/
-BOOLEAN
-EFIAPI
-IfconfigIsIpDuplicate (
- IN NIC_INFO *NicInfo,
- IN IP4_ADDR IpAddr
+EFI_STATUS
+IfConfigClearInterfaceInfo (
+ IN LIST_ENTRY *IfList
)
{
- EFI_ARP_PROTOCOL *Arp;
- EFI_ARP_CONFIG_DATA ArpCfgData;
- EFI_HANDLE ArpHandle;
- ARP_REQUEST Request;
- EFI_STATUS Status;
-
- Arp = NULL;
- ArpHandle = NULL;
- ZeroMem (&Request, sizeof (ARP_REQUEST));
-
- Status = NetLibCreateServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiArpServiceBindingProtocolGuid,
- &ArpHandle
- );
-
- if (EFI_ERROR (Status)) {
- return FALSE;
- }
+ EFI_STATUS Status;
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *Next;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ EFI_IP4_CONFIG2_POLICY Policy;
- Status = gBS->OpenProtocol (
- ArpHandle,
- &gEfiArpProtocolGuid,
- (VOID**)&Arp,
- gImageHandle,
- ArpHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
+ Policy = Ip4Config2PolicyDhcp;
+ Status = EFI_SUCCESS;
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
+ if (IsListEmpty (IfList)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);
}
//
- // Set up the Arp requests
+ // Go through the interface list.
//
- EFI_IP4_TO_U32 (Request.DestIp.v4) = IpAddr;
- EFI_IP4_TO_U32 (Request.LocalIp.v4) = 0xffffffff;
- Request.LocalMac = NicInfo->NicAddress.MacAddr;
- Request.MacLen = NicInfo->NicAddress.Len;
-
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL,
- TPL_CALLBACK,
- IfconfigOnArpResolved,
- (VOID *) &Request,
- &Request.OnResolved
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- ArpCfgData.SwAddressType = 0x0800;
- ArpCfgData.SwAddressLength = 4;
- ArpCfgData.StationAddress = &Request.LocalIp;
- ArpCfgData.EntryTimeOut = 0;
- ArpCfgData.RetryCount = 3;
- ArpCfgData.RetryTimeOut = 0;
-
- Status = Arp->Configure (Arp, &ArpCfgData);
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- Status = Arp->Request (
- Arp,
- &Request.DestIp,
- Request.OnResolved,
- &Request.DestMac
- );
-
- if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {
- goto ON_EXIT;
- }
-
- while (!ArpResolved) {
+ NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {
+ IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);
- }
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypePolicy,
+ sizeof (EFI_IP4_CONFIG2_POLICY),
+ &Policy
+ );
-ON_EXIT:
- if (Request.OnResolved != NULL) {
- gBS->CloseEvent (Request.OnResolved);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
}
- NetLibDestroyServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiArpServiceBindingProtocolGuid,
- ArpHandle
- );
-
- return Request.Duplicate;
+ return Status;
}
/**
- The callback function for the timer event used to get map.
+ The set process of the ifconfig command.
- @param[in] Event The event this function is registered to.
- @param[in] Context The context registered to the event.
-**/
-VOID
-EFIAPI
-TimeoutToGetMap (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- mTimeout = TRUE;
- return ;
-}
+ @param[in] IfList The pointer of IfList(interface list).
+ @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
-/**
- Create an IP child, use it to start the auto configuration, then destroy it.
-
- @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
+ @retval EFI_SUCCESS The ifconfig command set processed successfully.
+ @retval others The ifconfig command set process failed.
- @retval EFI_SUCCESS The configuration is done.
**/
EFI_STATUS
-EFIAPI
-IfconfigStartIp4(
- IN NIC_INFO *NicInfo
+IfConfigSetInterfaceInfo (
+ IN LIST_ENTRY *IfList,
+ IN ARG_LIST *VarArg
)
{
- EFI_IP4_PROTOCOL *Ip4;
- EFI_HANDLE Ip4Handle;
- EFI_HANDLE TimerToGetMap;
- EFI_IP4_CONFIG_DATA Ip4ConfigData;
- EFI_IP4_MODE_DATA Ip4Mode;
- EFI_STATUS Status;
- //
- // Get the Ip4ServiceBinding Protocol
- //
- Ip4Handle = NULL;
- Ip4 = NULL;
- TimerToGetMap = NULL;
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR), gShellNetwork1HiiHandle);
+ EFI_STATUS Status;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ VAR_CHECK_CODE CheckCode;
+ EFI_EVENT TimeOutEvt;
+ EFI_EVENT MappedEvt;
+ BOOLEAN IsAddressOk;
- Status = NetLibCreateServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiIp4ServiceBindingProtocolGuid,
- &Ip4Handle
- );
+ EFI_IP4_CONFIG2_POLICY Policy;
+ EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress;
+ UINTN DataSize;
+ EFI_IPv4_ADDRESS Gateway;
+ EFI_IPv4_ADDRESS *Dns;
+ ARG_LIST *Tmp;
+ UINTN Index;
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ CONST CHAR16* TempString;
- Status = gBS->OpenProtocol (
- Ip4Handle,
- &gEfiIp4ProtocolGuid,
- (VOID **) &Ip4,
- NicInfo->Handle,
- gImageHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
+ Dns = NULL;
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
+ if (IsListEmpty (IfList)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);
+ return EFI_INVALID_PARAMETER;
}
-
- Ip4ConfigData.DefaultProtocol = EFI_IP_PROTO_ICMP;
- Ip4ConfigData.AcceptAnyProtocol = FALSE;
- Ip4ConfigData.AcceptIcmpErrors = FALSE;
- Ip4ConfigData.AcceptBroadcast = FALSE;
- Ip4ConfigData.AcceptPromiscuous = FALSE;
- Ip4ConfigData.UseDefaultAddress = TRUE;
- ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
- ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
- Ip4ConfigData.TypeOfService = 0;
- Ip4ConfigData.TimeToLive = 1;
- Ip4ConfigData.DoNotFragment = FALSE;
- Ip4ConfigData.RawData = FALSE;
- Ip4ConfigData.ReceiveTimeout = 0;
- Ip4ConfigData.TransmitTimeout = 0;
-
- Status = Ip4->Configure (Ip4, &Ip4ConfigData);
-
- if (Status == EFI_NO_MAPPING) {
- mTimeout = FALSE;
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL | EVT_TIMER,
- TPL_CALLBACK,
- TimeoutToGetMap,
- NULL,
- &TimerToGetMap
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- Status = gBS->SetTimer (
- TimerToGetMap,
- TimerRelative,
- MultU64x32 (SecondsToNanoSeconds, 5)
- );
-
- if (EFI_ERROR (Status)) {
- goto ON_EXIT;
- }
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE), gShellNetwork1HiiHandle);
-
- while (!mTimeout) {
- Ip4->Poll (Ip4);
- if (!EFI_ERROR (Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL)) &&
- Ip4Mode.IsConfigured) {
- break;
- }
- }
- }
-
- Status = Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL);
+ //
+ // Make sure to set only one interface each time.
+ //
+ IfCb = NET_LIST_USER_STRUCT (IfList->ForwardLink, IFCONFIG_INTERFACE_CB, Link);
+ Status = EFI_SUCCESS;
- if ((Status == EFI_SUCCESS) && Ip4Mode.IsConfigured) {
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Default",
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[0],
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[1],
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[2],
- (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[3]
- );
- }
-
-ON_EXIT:
+ //
+ // Initialize check list mechanism.
+ //
+ CheckCode = IfConfigRetriveCheckListByName(
+ NULL,
+ NULL,
+ TRUE
+ );
+ //
+ // Create events & timers for asynchronous settings.
+ //
+ Status = gBS->CreateEvent (
+ EVT_TIMER,
+ TPL_CALLBACK,
+ NULL,
+ NULL,
+ &TimeOutEvt
+ );
if (EFI_ERROR (Status)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
}
- if (TimerToGetMap != NULL) {
- gBS->SetTimer (TimerToGetMap, TimerCancel, 0);
- gBS->CloseEvent (TimerToGetMap);
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ IfConfigManualAddressNotify,
+ &IsAddressOk,
+ &MappedEvt
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
}
- NetLibDestroyServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiIp4ServiceBindingProtocolGuid,
- Ip4Handle
- );
-
- return Status;
-}
-
-/**
- Set the address for the nic specified by the params.
+ //
+ // Parse the setting variables.
+ //
+ while (VarArg != NULL) {
+ //
+ // Check invalid parameters (duplication & unknown & conflict).
+ //
+ CheckCode = IfConfigRetriveCheckListByName(
+ mSetCheckList,
+ VarArg->Arg,
+ FALSE
+ );
- @param[in] Argc The count of the passed in Params.
- @param[in] Params The command line arguments for the set operation.
+ if (VarCheckOk != CheckCode) {
+ switch (CheckCode) {
+ case VarCheckDuplicate:
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_DUPLICATE_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);
+ break;
- @retval EFI_SUCCESS The address set operation is done.
- @return Some error occurs.
-**/
-SHELL_STATUS
-EFIAPI
-IfconfigSetNicAddr (
- IN UINTN Argc,
- IN CONST CHAR16 *Params
- )
-{
- NIC_IP4_CONFIG_INFO *Config;
- NIC_IP4_CONFIG_INFO *OldConfig;
- EFI_IP_ADDRESS Ip;
- EFI_IP_ADDRESS Mask;
- EFI_IP_ADDRESS Gateway;
- NIC_INFO *Info;
- BOOLEAN Permanent;
- SHELL_STATUS ShellStatus;
- CONST CHAR16 *Walker;
- CHAR16 *Temp;
- CONST CHAR16 *DhcpTemp;
- CONST CHAR16 *StaticTemp;
- CONST CHAR16 *PermTemp;
- UINT32 NetworkBytes1;
- UINT32 NetworkBytes2;
- EFI_STATUS Status;
-
- Walker = Params;
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
- Info = IfconfigFindNicByName (Temp);
-
- if (Info == NULL) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND), gShellNetwork1HiiHandle, Temp);
- return SHELL_NOT_FOUND;
- }
+ case VarCheckConflict:
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_CONFLICT_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);
+ break;
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")==NULL?0:StrStr(Walker, L" ")-Walker);
+ case VarCheckUnknown:
+ //
+ // To handle unsupported option.
+ //
+ TempString = PermanentString;
+ if (StringNoCaseCompare(&VarArg->Arg, &TempString) == 0) {
+ ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION), gShellNetwork1HiiHandle, PermanentString);
+ goto ON_EXIT;
+ }
- Config = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));
- if (Config == NULL) {
- return SHELL_OUT_OF_RESOURCES;
- }
+ //
+ // To handle unknown option.
+ //
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_UNKNOWN_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);
+ break;
- Config->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Config + 1);
+ default:
+ break;
+ }
- OldConfig = Info->ConfigInfo;
- Permanent = FALSE;
- ShellStatus = SHELL_INVALID_PARAMETER;
+ VarArg = VarArg->Next;
+ continue;
+ }
- DhcpTemp = DhcpString;
- StaticTemp = StaticString;
-
- if (StringNoCaseCompare(&Temp, &DhcpTemp) == 0) {
//
- // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent
+ // Process valid variables.
//
- if ((Argc != 2) && (Argc!= 3)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ if (StrCmp(VarArg->Arg, L"dhcp") == 0) {
+ //
+ // Set dhcp config policy
+ //
+ Policy = Ip4Config2PolicyDhcp;
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypePolicy,
+ sizeof (EFI_IP4_CONFIG2_POLICY),
+ &Policy
+ );
+
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
- if (Argc == 3) {
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, 0);
+ VarArg= VarArg->Next;
- PermTemp = PermanentString;
- if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing");
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
+ } else if (StrCmp (VarArg->Arg, L"static") == 0) {
+ //
+ // Set manual config policy.
+ //
+ Policy = Ip4Config2PolicyStatic;
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypePolicy,
+ sizeof (EFI_IP4_CONFIG2_POLICY),
+ &Policy
+ );
+
+ if (EFI_ERROR(Status)) {
goto ON_EXIT;
}
- Permanent = TRUE;
- }
+ VarArg= VarArg->Next;
- if ((OldConfig != NULL) && (OldConfig->Source == IP4_CONFIG_SOURCE_DHCP) &&
- (OldConfig->Permanent == Permanent)) {
+ ZeroMem (&ManualAddress, sizeof (ManualAddress));
+
+ //
+ // Get manual IP address.
+ //
+ Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.Address);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED), gShellNetwork1HiiHandle, Info->Name);
- ShellStatus = SHELL_ALREADY_STARTED;
- goto ON_EXIT;
- }
+ //
+ // Get subnetmask.
+ //
+ VarArg = VarArg->Next;
+ Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.SubnetMask);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
- Config->Source = IP4_CONFIG_SOURCE_DHCP;
- } else if (StringNoCaseCompare(&Temp, &StaticTemp) == 0) {
- //
- // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and
- // eth0 static IP NETMASK GATEWAY permanent
- //
- if ((Argc != 5) && (Argc != 6)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ //
+ // Get gateway.
+ //
+ VarArg = VarArg->Next;
+ Status = NetLibStrToIp4 (VarArg->Arg, &Gateway);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
+
+ IsAddressOk = FALSE;
+
+ Status = IfCb->IfCfg->RegisterDataNotify (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeManualAddress,
+ MappedEvt
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
+ DataSize = sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS);
- if (EFI_ERROR (NetLibStrToIp4 (Temp, &Ip.v4))) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeManualAddress,
+ DataSize,
+ &ManualAddress
+ );
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
- if (EFI_ERROR (NetLibStrToIp4 (Temp, &Mask.v4))) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ if (Status == EFI_NOT_READY) {
+ gBS->SetTimer (TimeOutEvt, TimerRelative, 50000000);
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- if (Argc == 6) {
- Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);
- } else {
- Temp = StrnCatGrow(&Temp, NULL, Walker, 0);
- }
- if (EFI_ERROR (NetLibStrToIp4 (Temp, &Gateway.v4))) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {
+ if (IsAddressOk) {
+ Status = EFI_SUCCESS;
+ break;
+ }
+ }
+ }
- if (Argc == 6) {
- Walker += StrLen(Temp) + 1;
- FreePool(Temp);
- Temp = NULL;
- Temp = StrnCatGrow(&Temp, NULL, Walker, 0);
+ IfCb->IfCfg->UnregisterDataNotify (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeManualAddress,
+ MappedEvt
+ );
- PermTemp = PermanentString;
- if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing");
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);
goto ON_EXIT;
}
- Permanent = TRUE;
- }
+ //
+ // Set gateway.
+ //
+ DataSize = sizeof (EFI_IPv4_ADDRESS);
+
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeGateway,
+ DataSize,
+ &Gateway
+ );
+ VarArg = VarArg->Next;
+
+ } else if (StrCmp (VarArg->Arg, L"dns") == 0) {
+ //
+ // Get DNS addresses.
+ //
+ VarArg = VarArg->Next;
+ Tmp = VarArg;
+ Index = 0;
+ while (Tmp != NULL) {
+ Index ++;
+ Tmp = Tmp->Next;
+ }
- NetworkBytes1 = NTOHL (Ip.Addr[0]);
- NetworkBytes2 = NTOHL (Mask.Addr[0]);
- if ((Ip.Addr[0] == 0) || (Mask.Addr[0] == 0) ||
- !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {
+ Dns = AllocatePool (Index * sizeof (EFI_IPv4_ADDRESS));
+ ASSERT(Dns != NULL);
+ Tmp = VarArg;
+ Index = 0;
+ while (Tmp != NULL) {
+ Status = NetLibStrToIp4 (Tmp->Arg, Dns + Index);
+ if (EFI_ERROR(Status)) {
+ goto ON_EXIT;
+ }
+ Index ++;
+ Tmp = Tmp->Next;
+ }
+
+ VarArg = Tmp;
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR), gShellNetwork1HiiHandle);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
+ //
+ // Set DNS addresses.
+ //
+ DataSize = Index * sizeof (EFI_IPv4_ADDRESS);
+
+ Status = IfCb->IfCfg->SetData (
+ IfCb->IfCfg,
+ Ip4Config2DataTypeDnsServer,
+ DataSize,
+ Dns
+ );
}
+ }
- NetworkBytes1 = NTOHL (Gateway.Addr[0]);
- if (!IP4_NET_EQUAL (Ip.Addr[0], Gateway.Addr[0], Mask.Addr[0]) ||
- !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle);
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ON_EXIT:
+ if (Dns != NULL) {
+ FreePool (Dns);
+ }
+
+ return EFI_SUCCESS;
- //
- // Set the configuration up, two route table entries are added:
- // one for the direct connected network, and another for the
- // default gateway. Remember, some structure members are cleared
- // by AllocateZeroPool
- //
- Config->Source = IP4_CONFIG_SOURCE_STATIC;
- Config->Ip4Info.RouteTableSize = 2;
+}
- CopyMem (&Config->Ip4Info.StationAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));
- CopyMem (&Config->Ip4Info.SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));
+/**
+ The ifconfig command main process.
- Ip.Addr[0] = Ip.Addr[0] & Mask.Addr[0];
+ @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
- CopyMem (&Config->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));
- CopyMem (&Config->Ip4Info.RouteTable[0].SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));
- CopyMem (&Config->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));
- } else {
- // neither static or DHCP. error.
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig");
- ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);
- goto ON_EXIT;
- }
+ @retval EFI_SUCCESS ifconfig command processed successfully.
+ @retval others The ifconfig command process failed.
- CopyMem (&Config->NicAddr, &Info->NicAddress, sizeof (NIC_ADDR));
- Config->Permanent = Permanent;
+**/
+EFI_STATUS
+IfConfig (
+ IN IFCONFIG_PRIVATE_DATA *Private
+ )
+{
+ EFI_STATUS Status;
//
- // Use HII service to set NIC address
+ // Get configure information of all interfaces.
//
- ShellStatus = IfconfigSetNicAddrByHii (Info, Config);
- if (ShellStatus != SHELL_SUCCESS) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_SET_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);
- goto ON_EXIT;
- }
+ Status = IfConfigGetInterfaceInfo (
+ Private->IfName,
+ &Private->IfList
+ );
- Status = IfconfigStartIp4 (Info);
- if (EFI_ERROR(Status)) {
- ShellStatus = SHELL_ACCESS_DENIED;
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
}
- if (ShellStatus != SHELL_SUCCESS) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);
+ switch (Private->OpCode) {
+ case IfConfigOpList:
+ Status = IfConfigShowInterfaceInfo (&Private->IfList);
+ break;
+
+ case IfConfigOpClear:
+ Status = IfConfigClearInterfaceInfo (&Private->IfList);
+ break;
+
+ case IfConfigOpSet:
+ Status = IfConfigSetInterfaceInfo (&Private->IfList, Private->VarArg);
+ break;
+
+ default:
+ Status = EFI_ABORTED;
}
-
+
ON_EXIT:
- SHELL_FREE_NON_NULL(Config);
-
- return ShellStatus;
+
+ return Status;
}
/**
- Show the address information for the nic specified.
+ The ifconfig command cleanup process, free the allocated memory.
+
+ @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
- @param[in] Name A pointer to the string containg the nic's name, if NULL,
- all nics' information is shown.
**/
VOID
-EFIAPI
-IfconfigShowNicInfo (
- IN CONST CHAR16 *Name
+IfConfigCleanup (
+ IN IFCONFIG_PRIVATE_DATA *Private
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *NextEntry;
- NIC_INFO *NicInfo;
- UINT32 Index;
- EFI_IP4_IPCONFIG_DATA *Ip4Config;
- EFI_IPv4_ADDRESS Gateway;
- CONST CHAR16 *TempString;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ ARG_LIST *ArgNode;
+ ARG_LIST *ArgHead;
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- NicInfo = BASE_CR (Entry, NIC_INFO, Link);
+ ASSERT (Private != NULL);
- TempString = (CHAR16*)NicInfo->Name;
- if ((Name != NULL) && (StringNoCaseCompare (&Name, &TempString) != 0)) {
- continue;
- }
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NAME), gShellNetwork1HiiHandle, NicInfo->Name);
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR),
- gShellNetwork1HiiHandle,
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[0],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[1],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[2],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[3],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[4],
- (UINTN)NicInfo->NicAddress.MacAddr.Addr[5]
- );
-
- Print (L" Media State: %s\n", NicInfo->MediaPresent ? L"Media present" : L"Media disconnected");
-
- if (NicInfo->ConfigInfo == NULL) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED), gShellNetwork1HiiHandle);
- continue;
- }
+ //
+ // Clean the list which save the set config Args.
+ //
+ if (Private->VarArg != NULL) {
+ ArgHead = Private->VarArg;
- if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_DHCP) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"DHCP");
- } else if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_STATIC) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"STATIC");
- } else {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"Unknown");
+ while (ArgHead->Next != NULL) {
+ ArgNode = ArgHead->Next;
+ FreePool (ArgHead);
+ ArgHead = ArgNode;
}
- ShellPrintHiiEx(-1, -1, NULL,
- STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS),
- gShellNetwork1HiiHandle,
- (NicInfo->ConfigInfo->Permanent? L"TRUE":L"FALSE")
- );
-
- Ip4Config = &NicInfo->ConfigInfo->Ip4Info;
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"IP address",
- (UINTN)Ip4Config->StationAddress.Addr[0],
- (UINTN)Ip4Config->StationAddress.Addr[1],
- (UINTN)Ip4Config->StationAddress.Addr[2],
- (UINTN)Ip4Config->StationAddress.Addr[3]
- );
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Mask",
- (UINTN)Ip4Config->SubnetMask.Addr[0],
- (UINTN)Ip4Config->SubnetMask.Addr[1],
- (UINTN)Ip4Config->SubnetMask.Addr[2],
- (UINTN)Ip4Config->SubnetMask.Addr[3]
- );
-
- ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));
-
- for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {
- if ((CompareMem (&Ip4Config->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&
- (CompareMem (&Ip4Config->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){
- CopyMem (&Gateway, &Ip4Config->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
- }
- }
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Gateway",
- (UINTN)Gateway.Addr[0],
- (UINTN)Gateway.Addr[1],
- (UINTN)Gateway.Addr[2],
- (UINTN)Gateway.Addr[3]
- );
-
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, Ip4Config->RouteTableSize);
-
- for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Subnet",
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[0],
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[1],
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[2],
- (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[3]
- );
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Netmask",
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[0],
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[1],
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[2],
- (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[3]
- );
-
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR),
- gShellNetwork1HiiHandle,
- L"Gateway",
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[0],
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[1],
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[2],
- (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[3]
- );
- }
+ FreePool (ArgHead);
}
- return ;
-}
+ if (Private->IfName != NULL) {
+ FreePool (Private->IfName);
+ }
-/**
- Clear address configuration for the nic specified.
+ //
+ // Clean the IFCONFIG_INTERFACE_CB list.
+ //
+ NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->IfList) {
+ IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);
- @param[in] Name A pointer to the string containg the nic's name,
- if NULL, all nics address configurations are cleared.
+ RemoveEntryList (&IfCb->Link);
- @retval EFI_SUCCESS The address configuration is cleared.
- @return Some error occurs.
-**/
-EFI_STATUS
-EFIAPI
-IfconfigClearNicAddr (
- IN CONST CHAR16 *Name
- )
-{
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
- NIC_INFO *Info;
- EFI_STATUS Status;
-
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- Info = BASE_CR (Entry, NIC_INFO, Link);
+ if (IfCb->IfInfo != NULL) {
- if ((Name != NULL) && (StrCmp (Name, Info->Name) != 0)) {
- continue;
+ FreePool (IfCb->IfInfo);
}
-// if (Info->NicIp4Config == NULL) {
- Status = IfconfigSetNicAddrByHii (Info, NULL);
-// } else {
-// Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);
-// }
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ FreePool (IfCb);
}
- return EFI_SUCCESS;
-
+ FreePool (Private);
}
/**
Function for 'ifconfig' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
+
+ @retval EFI_SUCCESS ifconfig command processed successfully.
+ @retval others The ifconfig command process failed.
+
**/
SHELL_STATUS
EFIAPI
ShellCommandRunIfconfig (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Package;
- CHAR16 *ProblemParam;
- SHELL_STATUS ShellStatus;
- BOOLEAN ListOperation;
- BOOLEAN ClearOperation;
- BOOLEAN SetOperation;
- CONST CHAR16 *Item;
- LIST_ENTRY *Entry;
- NIC_INFO *Info;
-
- InitializeListHead (&NicInfoList);
- Status = EFI_INVALID_PARAMETER;
- ShellStatus = SHELL_SUCCESS;
+ EFI_STATUS Status;
+ IFCONFIG_PRIVATE_DATA *Private;
+ LIST_ENTRY *ParamPackage;
+ CONST CHAR16 *ValueStr;
+ ARG_LIST *ArgList;
+ CHAR16 *ProblemParam;
+ CHAR16 *Str;
+
+ Private = NULL;
+
+ Status = ShellCommandLineParseEx (mIfConfigCheckList, &ParamPackage, &ProblemParam, TRUE, FALSE);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam);
+ goto ON_EXIT;
+ }
//
- // initialize the shell lib (we must be in non-auto-init...)
+ // To handle unsupported option.
//
- Status = ShellInitialize();
- ASSERT_EFI_ERROR(Status);
+ if (ShellCommandLineGetFlag (ParamPackage, L"-c")) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION), gShellNetwork1HiiHandle,L"-c");
+ goto ON_EXIT;
+ }
//
- // parse the command line
+ // To handle no option.
//
- Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
- if (EFI_ERROR(Status)) {
- if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam);
- FreePool(ProblemParam);
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else {
- ASSERT(FALSE);
- }
-
- goto Done;
+ if (!ShellCommandLineGetFlag (ParamPackage, L"-r") && !ShellCommandLineGetFlag (ParamPackage, L"-s") &&
+ !ShellCommandLineGetFlag (ParamPackage, L"-l")) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_OPTION), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
}
- ClearOperation = ShellCommandLineGetFlag(Package, L"-c");
- ListOperation = ShellCommandLineGetFlag(Package, L"-l");
- SetOperation = ShellCommandLineGetFlag(Package, L"-s");
-
- if ((ClearOperation && ListOperation)
- ||(SetOperation && ListOperation)
- ||(ClearOperation && SetOperation)
- ) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- } else if (!ClearOperation && !ListOperation && !SetOperation) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
+ //
+ // To handle conflict options.
+ //
+ if (((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-s"))) ||
+ ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||
+ ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l")))) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig");
+ goto ON_EXIT;
}
-
-
- Status = IfconfigGetAllNicInfoByHii ();
- if (EFI_ERROR (Status)) {
- if (mIp4ConfigExist) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL), gShellNetwork1HiiHandle, Status);
- } else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellNetwork1HiiHandle, L"ifconfig", L"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid);
- }
- return SHELL_NOT_FOUND;
+ Status = EFI_INVALID_PARAMETER;
+
+ Private = AllocateZeroPool (sizeof (IFCONFIG_PRIVATE_DATA));
+
+ if (Private == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ON_EXIT;
}
- if (ListOperation) {
- Item = ShellCommandLineGetValue (Package, L"-l");
+ InitializeListHead (&Private->IfList);
- if (Item != NULL && CountSubItems(Item) > 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-l");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- }
+ //
+ // To get interface name for the list option.
+ //
+ if (ShellCommandLineGetFlag (ParamPackage, L"-l")) {
+ Private->OpCode = IfConfigOpList;
+ ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");
+ if (ValueStr != NULL) {
+ Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
+ ASSERT (Str != NULL);
+ Private->IfName = Str;
+ }
+ }
+
+ //
+ // To get interface name for the clear option.
+ //
+ if (ShellCommandLineGetFlag (ParamPackage, L"-r")) {
+ Private->OpCode = IfConfigOpClear;
+ ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");
+ if (ValueStr != NULL) {
+ Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
+ ASSERT (Str != NULL);
+ Private->IfName = Str;
+ }
+ }
+
+ //
+ // To get interface name and corresponding Args for the set option.
+ //
+ if (ShellCommandLineGetFlag (ParamPackage, L"-s")) {
+ ValueStr = ShellCommandLineGetValue (ParamPackage, L"-s");
+ if (ValueStr == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_INTERFACE), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
+ }
//
- // Show the configuration.
+ // To split the configuration into multi-section.
//
- IfconfigShowNicInfo (Item);
- } else if (SetOperation) {
- Item = ShellCommandLineGetValue (Package, L"-s");
+ ArgList = SplitStrToList (ValueStr, L' ');
+ ASSERT (ArgList != NULL);
- //
- // The correct command line arguments for setting address are:
- // IfConfig -s eth0 DHCP [permanent]
- // IfConfig -s eth0 static ip netmask gateway [permanent]
- //
- if (Item == NULL || (CountSubItems(Item) < 2) || (CountSubItems(Item) > 6) || (CountSubItems(Item) == 4)) {
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_NO_VALUE), gShellNetwork1HiiHandle, L"ifconfig", L"-s");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- }
+ Private->OpCode = IfConfigOpSet;
+ Private->IfName = ArgList->Arg;
- ShellStatus = IfconfigSetNicAddr (CountSubItems(Item), Item);
- } else if (ClearOperation) {
- Item = ShellCommandLineGetValue (Package, L"-c");
+ Private->VarArg = ArgList->Next;
- if (Item != NULL && CountSubItems(Item) > 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-c");
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
+ if (Private->IfName == NULL || Private->VarArg == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
+ goto ON_EXIT;
}
-
- IfconfigClearNicAddr (Item);
- } else {
- ASSERT(FALSE);
}
+
+ //
+ // Main process of ifconfig.
+ //
+ Status = IfConfig (Private);
-Done:
- while (!IsListEmpty (&NicInfoList)) {
- Entry = NicInfoList.ForwardLink;
- Info = BASE_CR (Entry, NIC_INFO, Link);
-
- RemoveEntryList (Entry);
-
- if (Info->ConfigInfo != NULL) {
- FreePool (Info->ConfigInfo);
- }
-
- FreePool (Info);
- }
+ON_EXIT:
- if (Package != NULL) {
- ShellCommandLineFreeVarList(Package);
+ ShellCommandLineFreeVarList (ParamPackage);
+
+ if (Private != NULL) {
+ IfConfigCleanup (Private);
}
- return (ShellStatus);
+ return Status;
}
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
index e23588a..fda062d 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
@@ -953,11 +953,11 @@ PingCreateIpInstance (
// Ip6config protocol and ip6 service binding protocol are installed
// on the same handle.
//
Status = gBS->HandleProtocol (
HandleBuffer[HandleIndex],
- Private->IpChoice == PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4ConfigProtocolGuid,
+ Private->IpChoice == PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4Config2ProtocolGuid,
(VOID **) &IpXCfg
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
@@ -971,12 +971,13 @@ PingCreateIpInstance (
Ip6ConfigDataTypeInterfaceInfo,
&IfInfoSize,
NULL
);
} else {
- Status = ((EFI_IP4_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
&IfInfoSize,
NULL
);
}
@@ -1007,12 +1008,13 @@ PingCreateIpInstance (
Ip6ConfigDataTypeInterfaceInfo,
&IfInfoSize,
IpXInterfaceInfo
);
} else {
- Status = ((EFI_IP4_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
&IfInfoSize,
IpXInterfaceInfo
);
}
@@ -1043,11 +1045,11 @@ PingCreateIpInstance (
}
} else {
//
// IP4 address check
//
- if (EFI_IP4_EQUAL (&Private->SrcAddress, &((EFI_IP4_IPCONFIG_DATA*)IpXInterfaceInfo)->StationAddress)) {
+ if (EFI_IP4_EQUAL (&Private->SrcAddress, &((EFI_IP4_CONFIG2_INTERFACE_INFO*)IpXInterfaceInfo)->StationAddress)) {
//
// Match a certain interface address.
//
break;
}
@@ -1135,15 +1137,10 @@ PingCreateIpInstance (
ZeroMem (&Ip4Config, sizeof (EFI_IP4_CONFIG_DATA));
//
// Configure the ip4 instance for icmp4 packet exchange.
//
-// PING_IP4_COPY_ADDRESS (&Ip4Config.StationAddress, &Private->SrcAddress);
-// Ip4Config.SubnetMask.Addr[0] = 0xFF;
-// Ip4Config.SubnetMask.Addr[1] = 0xFF;
-// Ip4Config.SubnetMask.Addr[2] = 0xFF;
-// Ip4Config.SubnetMask.Addr[3] = 0x00;
Ip4Config.DefaultProtocol = 1;
Ip4Config.AcceptAnyProtocol = FALSE;
Ip4Config.AcceptBroadcast = FALSE;
Ip4Config.AcceptIcmpErrors = TRUE;
Ip4Config.AcceptPromiscuous = FALSE;
@@ -1427,10 +1424,14 @@ ON_EXIT:
/**
Function for 'ping' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
+
+ @retval SHELL_SUCCESS The ping processed successfullly.
+ @retval others The ping processed unsuccessfully.
+
**/
SHELL_STATUS
EFIAPI
ShellCommandRunPing (
IN EFI_HANDLE ImageHandle,
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
index 68a7c93..98b40df 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
@@ -1,9 +1,9 @@
/** @file
header file for NULL named library for network1 shell command functions.
- Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>
+ Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
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
@@ -24,13 +24,11 @@
#include <Protocol/Cpu.h>
#include <Protocol/ServiceBinding.h>
#include <Protocol/Ip6.h>
#include <Protocol/Ip6Config.h>
#include <Protocol/Ip4.h>
-#include <Protocol/Ip4Config.h>
-#include <Protocol/HiiConfigAccess.h>
-#include <Protocol/HiiConfigRouting.h>
+#include <Protocol/Ip4Config2.h>
#include <Protocol/Arp.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
@@ -45,12 +43,10 @@
#include <Library/HiiLib.h>
#include <Library/NetLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
-#include <Guid/NicIp4ConfigNvData.h>
-
extern EFI_HANDLE gShellNetwork1HiiHandle;
/**
Function for 'ping' command.
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
index 527d2ef..6dfbbe5 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
@@ -57,11 +57,11 @@
gEfiCpuArchProtocolGuid ## CONSUMES
gEfiIp6ProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp6ConfigProtocolGuid ## SOMETIMES_CONSUMES
- gEfiIp6ProtocolGuid ## SOMETIMES_CONSUMES
- gEfiIp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
- gEfiIp6ConfigProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiIp4ProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiIp4ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiIp4Config2ProtocolGuid ## SOMETIMES_CONSUMES
[Guids]
gShellNetwork1HiiGuid ## SOMETIMES_CONSUMES ## HII
\ No newline at end of file
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
index aa27c678339c5e94c9c936d9a7ea74b6b043c200..1971ebc5f69c0e7de6ef2252de0428ac75bfaaaf 100644
GIT binary patch
delta 2471
zcmc&#T})eL7=9~b{0vrTDP5tghZ=;nU0FM!fWRm%KZP>***@12nrGc_le#Q!HnoO5@
z>tfJ%F<$76F<u##*~Az#&A9M-dgHYkjb;~1cITzfd%kmMDVmtL#GHKR`_B2^?|Gm1
z_uKy1^5i4S_OF(%`@g+s<8}KTj1E5Du%^#D4NL5<=-@z8n6EhAWnXm%A8Xv<K<5iQ
zQ****@KsG>mWaL-Zl1W`0ZnV=x6V^-qPnl(_MZ3rRfWO{<8T;eco}ebI|VQ`H0Ok
zM`vl4=4b}***@YjlG(vGoVLgL&f}hsd`JvzI(nupO{#>C9R#$1AHYtmFjV-q3mMvPN
z4cfxrb^Oa=FGGuvTf^54PWdDCNs3a8CifvbS+n|@1zE61X@$~s89180TA*b)Sz(;y
z`V$WJ2779ibP}>6aW3Yl5<O{JrHsfs3z}lEVhT?***@4&&c(7qs6&=Rb<49&%s
zrThtQJW<Etj&Qxwnt<eW=***@5WpeMS5G~x)+***@k14E*8H74cXBAFd_Z3i}
zJ*|***@mPfwY3Nvl7lL3jj4$z{a4hU;)JEeN8yIJ?o7H``LCaW41jP424s{Q}7sBQO
zyuP2wZn!I>n8Xb06_?Eey8a^%iAam&*d)***@UBtVTOQ<Wdpt#Jz@?{L<4Bn+yKLaLw
zG+4>*&dS;pvMmbVBqiG!4BE~3iU*e9^(<nna(EMbG<Z0JIB8-JySsdRD(I`N!hbKl
z0<MS$XS?3vulzn_qx_XW&hBY$>Z#_N5l!Tem^&c~^LLRso(~+dkHRY{cx42>k!WEh
znOd&***@ybPQ4(?N%tA7X>WrgKQ^<{JtS<3=e`rr<5C0HJ2(DF~8iwQu&P?*Tc8}EY
zEyY1NpZq_bnqsA5-VsGq(ld!><9xp_SfM!faWoPVTdI^uf=2mXc+63-K&rs3z-yIu
z?tihe3>6`;&FYNwG*tta;ITO5V>H9a{?iIY5Ts+N?0*B1D}MU$wTO<l02u?<^>?^>
zhmkCb{9Duw<dW3A)W3mT24rsSu~((QNn#e4$odP2(is-***@DvooUqwho
zIb!s_HabONdfk+5F?~C;FSkqv=vYSQGqPMd4F5dntSHghrf}pY8P>B|dXD&IR`2;H
z-tB<j;9*wHqcbjKZwZ>gY7FP)KDvlm;%B0ORSC-Okf)T<Kh}+j0`***@0zx$8dJ5N
zL!Zy=dD-Mw$gBkJ#{<>K>BIVMX;kl{NGm^Xck}nXw)}***@x7AqmOCzvoe5=KgAL{$e
zV#)FEFWqz9L<IX0Rk=lFCFp~AUggk)iw8a3kgK;kYENSKJb0~P+~Cldr|c>%$sLIP
zrS6TrPPLc0T5*Q+?dR=0)Ov{PG#hT;!}-***@p4Cw+***@UG7=H=L7NU7XEtV0Y4ZE
zd@^pabn`c3ZPESaiOyAAgi;I|X1Vs1%he^g1(Q~=Q&ga!|7QO4i4UIRq2vTVnR<=q
zCy(=|!3Jwd?D$&T$wR|+{CMJJ{%PuHx$awDJ>#_W$lKbBzMa#1x0h<E8vU`C=i7Z4
L-Wq(%KYjcK*m3RL
delta 2872
zcmdT`OH5;B6#lDHC|EkQln%qAx1}uu105bhVTc0hh0>AtBg6=4N+}Nq%1qmVK{N5O
zGSLO*Ok9{51JOiRKGK-XLXFJQxNtTm?ie#}W-)OVx-drl&VO%*hh-+SG^E^f|NGx_
zzVn^$od4dxZrHkE*t%<I{***@xNtkhKKrVnlN^7>t=k(***@EbbEms?7z_W`EF`2`;6|D
z-J&bT7W&a*q<fBQ)Zka><CA~TcKNp4KWuNI4^GX&_K>gQ3%T}p#ZU73SLH?ODX7fc
zZ2F;)zI9s7A<-u$MMMmXun5wQ*+#Dx)K4qIExcj?YYQSM)<go=WwD60VR23<VhSr!
zF(+0;9CvB#P(%`T8vmDZU6<=oJYT^R>06{kE!}y+R>E)0<Lxwl4Y0j*+vp{KT^XHr
z7TXxfh(y$n>lE%(dec=~^JqMiVoAg)***@Hf57cUG{(x2)_^4iytRm^z`g>6DcBtQ
zGAzb(G*3k|O5|y}8g|fgiq(*!sM5s<?GZ3C0^j|3D+Gk&U=SD!YFv+FEldwoo9i$>
z#-f0U70F)|csH3PR~#0v^HUWW1;wcF!wzC+9P0^st=n6q$hsssAK(j{Mp4NLus2S(
z{mu5AoKeJ7P9C*1Uve)}G*;V5*Og~WdJ#uOHW5VXMQ-D?tDKq5>EodeB=0~K#ye-h
zF)LtIqP~FDi?EiFmm(SG{|OO8J(4oln8X}{0(*hDPfX+b5{;ccdpz!{MR-gj$_B2R
***@XLJ7OK&M;5>*0u6Rc;c<5z4g;m1`ZmyTHxtduls3RkT&P?IXY<D8QCt;$_-*r@|5
zMn{>L|6cGoNiL6#W_-o8=XZCxQ914q4L>7Kz#H?X*<5W_C41MRb5AXD6f&t5=A)T*
znz`0N*`tHdA9wDb&idCMU9VjE#*W1m0|U#@8)MUY{2;<8x`$UAWli-7VLVKRgNquL
z?JNre$SOAv-Kn!NEr2_!3tDSLF6=VgvN$*4{4&5PdVmz}wSlvWJ&ORxL@}f_ltmjr
zDOfzN=B3ycvATeJ_7TNzLr;hc>E}O+DQ%AI2vi}***@v4C=srWK|{b<mvB
zo~KFV=ekfH)1RW=>b4qf=<ScQTtj20x~|9#EG)7$6dEFX8ja6FwjbQjP0hn_oSL0>
z<_+VJ-<rT%%uq}Ul~?$W2egjDIf|Ud#Sn5DhBd5Lf(1GWe-pG@)u{U#g^#3cUT))r
z<aXcJjwix#4Q>i}-=R;d+4|i(lCPtr7kxGS+~!8L4<8xl$fcIk_W6S871RVx4|E%{
z#!IjmSx`sZBw8?>8-e|aEM}WjUp>dqXa1W-D}CgfvP_^kMle<)S`-@dRq!6O#+?>f
zp$GN0&***@nxj}fs0=CI^***@pnWkal_;^hSZl!pa#!eOQSL80sdqnTp$r>AYG<X|<B9
zC*1UQR|g}?-0!++FvRGS=RbG63;`c4#H^SlL!g|#ZfVD^5{sR-Tc0syPl6<Ec6ZZO
z>j_fuL4YTjWVf1UkKw?}wrx!Bu_PZFR2{O?z<{-gj~2Z*aCF+~R>w)Y+gIx1V}=L2
zb~MG%IodJF`{huiOKKIlhpZ+ZXe)T0rnQ0cJQ<C4JIcwbS}oeZczAS?tKFXI>038A
z6p=GW`l|mM+Uqk0SU@~ykFt<GMH1X9atDX!vB6?(;M4-yJv;*9C{***@TBHM6M(uY
z2MfQ?vpp$=2oDU}q$P)>(T2`5?E4ZD=LlKJYF{%c*>daftbgS&9VoX(#v16D$6!Ia
zlngZ-mu==o$YA*YrfWWwF8$MfHS<>Z{ijSkw)te6XGZh+OW*?7MP+O`DoRm&TkQp`
e)HC=l{T4RTDNC{EzjdDhvorAN7G_Z>fByoOonQd~
--
1.9.5.msysgit.1
1.9.5.msysgit.1