summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorjiaxinwu <jiaxin.wu@intel.com>2015-07-08 02:53:41 +0000
committerjiaxinwu <jiaxinwu@Edk2>2015-07-08 02:53:41 +0000
commit7c25b7ea5b2c029a9e7a0be57f7c20f31d720c7d (patch)
tree01fe8318f0494ccc81612ac58447ac3737d3d110 /ShellPkg
parentcceb4ebd0839a923739b1f4075f7ec1bf8591eeb (diff)
downloadedk2-platforms-7c25b7ea5b2c029a9e7a0be57f7c20f31d720c7d.tar.xz
ShellPkg: Update ping/ifconfig library source code to consume Ip4Config2 protocol.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: jiaxinwu <jiaxin.wu@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Tapan Shah <tapandshah@hp.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17869 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c2439
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c19
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h8
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf6
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.unibin20112 -> 20078 bytes
5 files changed, 990 insertions, 1482 deletions
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
index fa00d6c6e9..6977d6b67f 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
@@ -1,5 +1,5 @@
/** @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>
@@ -11,1632 +11,1145 @@
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;
+ Split a string with specified separator and save the substring to a list.
- if (String == NULL || *String == CHAR_NULL) {
- return (0xFF);
- }
-
- 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.
+ Check the correctness of input Args with '-s' option.
- @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.
+ @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.
- @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;
+ @return VarCheckOk Valid parameter or Initialize check successfully.
+ @return VarCheckDuplicate Duplicated parameter happened.
+ @return VarCheckConflict Conflicted parameter happened
+ @return VarCheckUnknown Unknown parameter.
- 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);
-
- 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;
-}
-
-/**
- Converts the unicode character of the string from uppercase to lowercase.
- This is a internal function.
-
- @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;
+ }
- FreePool (NicConfigRequest);
- FreePool (ConfigResp);
- FreePool (ConfigHdr);
+ InsertTailList (IfList, &IfCb->Link);
+
+ 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.
-
- @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 ;
-}
+ The set process of the ifconfig command.
-/**
- Create an IP child, use it to start the auto configuration, then destroy it.
+ @param[in] IfList The pointer of IfList(interface list).
+ @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
- @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;
+ EFI_STATUS Status;
+ IFCONFIG_INTERFACE_CB *IfCb;
+ VAR_CHECK_CODE CheckCode;
+ EFI_EVENT TimeOutEvt;
+ EFI_EVENT MappedEvt;
+ BOOLEAN IsAddressOk;
- ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR), gShellNetwork1HiiHandle);
+ 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;
- Status = NetLibCreateServiceChild (
- NicInfo->Handle,
- gImageHandle,
- &gEfiIp4ServiceBindingProtocolGuid,
- &Ip4Handle
- );
+ CONST CHAR16* TempString;
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- 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;
-
- NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {
- NicInfo = BASE_CR (Entry, NIC_INFO, Link);
-
- 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;
- }
-
- 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");
- }
+ IFCONFIG_INTERFACE_CB *IfCb;
+ ARG_LIST *ArgNode;
+ ARG_LIST *ArgHead;
- ShellPrintHiiEx(-1, -1, NULL,
- STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS),
- gShellNetwork1HiiHandle,
- (NicInfo->ConfigInfo->Permanent? L"TRUE":L"FALSE")
- );
-
- Ip4Config = &NicInfo->ConfigInfo->Ip4Info;
+ ASSERT (Private != NULL);
- 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]
- );
+ //
+ // Clean the list which save the set config Args.
+ //
+ if (Private->VarArg != NULL) {
+ ArgHead = Private->VarArg;
- 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));
- }
+ while (ArgHead->Next != NULL) {
+ ArgNode = ArgHead->Next;
+ FreePool (ArgHead);
+ ArgHead = ArgNode;
}
-
- 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);
}
/**
@@ -1644,6 +1157,10 @@ IfconfigClearNicAddr (
@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
@@ -1652,131 +1169,125 @@ ShellCommandRunIfconfig (
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 e23588afdb..fda062de1d 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
@@ -955,7 +955,7 @@ PingCreateIpInstance (
//
Status = gBS->HandleProtocol (
HandleBuffer[HandleIndex],
- Private->IpChoice == PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4ConfigProtocolGuid,
+ Private->IpChoice == PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4Config2ProtocolGuid,
(VOID **) &IpXCfg
);
@@ -973,8 +973,9 @@ PingCreateIpInstance (
NULL
);
} else {
- Status = ((EFI_IP4_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
&IfInfoSize,
NULL
);
@@ -1009,8 +1010,9 @@ PingCreateIpInstance (
IpXInterfaceInfo
);
} else {
- Status = ((EFI_IP4_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
&IfInfoSize,
IpXInterfaceInfo
);
@@ -1045,7 +1047,7 @@ PingCreateIpInstance (
//
// 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.
//
@@ -1137,11 +1139,6 @@ PingCreateIpInstance (
//
// 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;
@@ -1429,6 +1426,10 @@ ON_EXIT:
@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
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
index 68a7c93c96..98b40df825 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.h
@@ -1,7 +1,7 @@
/** @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
@@ -26,9 +26,7 @@
#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>
@@ -47,8 +45,6 @@
#include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
-#include <Guid/NicIp4ConfigNvData.h>
-
extern EFI_HANDLE gShellNetwork1HiiHandle;
/**
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
index 527d2efbf0..6dfbbe52b2 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
@@ -59,9 +59,9 @@
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 aa27c67833..1971ebc5f6 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
Binary files differ