Reviewed-by: Jaben Carsey <jaben.car...@intel.com> > -----Original Message----- > From: jiaxinwu [mailto:jiaxin...@intel.com] > Sent: Wednesday, July 01, 2015 8:45 AM > To: edk2-devel@lists.sourceforge.net > Subject: [edk2] [Patch] Update ShellPkg ping/ifconfig library. > Importance: High > > Version3 update mainly include comments from reviewer: > Recover renamed and removed string tokens in uni file. > Update ifconfig help info by using the standard shell output message. > Remove redundant string tokens for ifconfig compared to version2. > Remove redundant parameter in private data structure(ImageHandle). > Update IfConfigShowInterfaceInfo, IfConfigClearInterfaceInfo and > IfConfigCleanup to use standard linked list functions. > Remove –h option for ifconfig since it's not the standard shell behavior. > Update return codes for some functions. > Other coding style change. > > This patch update ShellPkg ping/ifconfig library source code to consume > Ip4Config2 protocol. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: jiaxinwu <jiaxin...@intel.com> > --- > .../UefiShellNetwork1CommandsLib/Ifconfig.c | 2439 ++++++++----------- > - > .../Library/UefiShellNetwork1CommandsLib/Ping.c | 19 +- > .../UefiShellNetwork1CommandsLib.c | 2 +- > .../UefiShellNetwork1CommandsLib.h | 8 +- > .../UefiShellNetwork1CommandsLib.inf | 6 +- > .../UefiShellNetwork1CommandsLib.uni | Bin 20112 -> 19664 > bytes > 6 files changed, 991 insertions(+), 1483 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:&gEfiIp4ConfigProtocolG > uid, > + Private->IpChoice == > PING_IP_CHOICE_IP6?&gEfiIp6ConfigProtocolGuid:&gEfiIp4Config2Protocol > Guid, > (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/UefiShellNetwork1Com > mandsLib.c > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.c > index 49849a6..557c69a 100644 > --- > a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.c > +++ > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.c > @@ -1,9 +1,9 @@ > /** @file > Main 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 > > diff --git > a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.h > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.h > index 68a7c93..98b40df 100644 > --- > a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.h > +++ > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.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/UefiShellNetwork1Com > mandsLib.inf > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.inf > index 527d2ef..6dfbbe5 100644 > --- > a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.inf > +++ > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.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/UefiShellNetwork1Com > mandsLib.uni > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com > mandsLib.uni > index > aa27c678339c5e94c9c936d9a7ea74b6b043c200..daad7892cdbb85e2e82377c6c > 5a56ccc859429a8 100644 > GIT binary patch > delta 2323 > zcmc&#Urd`- > 6hD=11qL$Om9Eg*k1p8Kc4h4>1sq6e`BUgd2P4Z8O{vgs4I4vXQxoHy > zuPz367Nd#2`lOiI#2B-f@!<33i|- > nZ#s`zV`QU@U^WE>GrD$R@6Z7SM_usj{^E>CB > zbMDs1mPa32wtlk2@BRFqjo0kA(E|L;(N(?QK3Zb8HNfG{7+- > e0%faRVAM4oWaNo0> > zYqs$p9b5cC+Xz2!-Zl1G`0ZoA>Su4e- > qibW=Uu)3vGWVP|FY|Qz2A1Pam4QC#e~hf > zKxb*57AS{rmgeX@jZ>QP80Rp~@Z%OcKM46;8foOi%4I5IbdA<%lgj8<*<$PR > T&Gpq > zpzBy&!`eFbinI*5Rm@)Hd??YLr6i?jW)HHHwYFfFAPe>cU7- > S90*<DSmS{yzT8)$3 > z- > s@mrWS~_^XCW&R=TeR)(NmzSR1|q<RZ|L9oWYlbjcI;7IK2NXv@eMjRDv~^p > t;tv > zd?>>my+=3}h_x%N8A#rMt}9gLos`R3qqjS)dofEH*qPM*n8&D=K{RlxtZ>r0uY > dyW > z1>IYU$5mKSfR1H&Ap$mIn28^SV|7oX9- > 2biKs$@wvhK4DTER$eKztwJX#X&LA#BdW > z>wB5(#NtK8BxP8yxNPpz^@Kd+Mm!Q@GibAP0snd~(RgA>aan- > nD`<!r{Ohg$518=N > zkw$j+HMZsvZAthhE78ti;5YAAJWzty%eZ3|!<*ov!NWz|lP31CJ09edkzi{R)_wF > M > zxZ*yz9Dj$u3I!33vMMXi{#ouEXy!K(n#dnEccK*IZxai=7(QU1fLHSH$~b%@w}p > {J > z>OozW3!y=;l1O7`9+F99XBv5$M{LYubdm3cqPsc=_`5_#aNE?WF- > VT%%nYCNdnJ!= > zDh|T=#Q*WN)G8J84lAM(o>>$d=bfR5RdF2RWFjiIG%1k`P4MTjNk`QJ$pSM2 > Uum@S > z>E{|7kP!mgrOrrAQ#o)E9!o<$ML9<FpHe7- > AQekR|LeH9+HVN6WmLQ+$QZb;zr)ol > zj6_l5-=c0HmL%^b{|)2@AanPCy(te)a%X9|*-#ZxD#H>ONkv#jjjb{jo`Pcds|Kki > zMvU6mLnkRlubHwQ)3>=jv1Kwq#WE_N5#>^0_=gdvwN7V`!jYF`Opj)%IpUXj > z2=*E > zx56QVhnY1GUvMFM>(C5VlQ=K$(FOE!e<li8)uHT+dg~eeW8Ro3@NS>- > u4&scqDfvK > z$@O*AdHE|ZoBXPgmBIVCFB`dVNPjJj?0uN%=HL8oel%#SOnJU(#^AIR0*l5sJ > &wxg > z&?gqlI{)(gXO@>ZI_=^SZ$IYkZ4S=~=nX)75sZqchP{~2nKO<~dK<1$N!~uxE%j > dP > zR;b;G)oLS~ZymSuX!ij=qS^539;$2(PaSlulOMpU!0jq~68K6ueZ#_EkKgC}li@p4 > ofAU+&M*isd%au>3-+zinv(x<hnG(<W2YAsRMDw+@QZt$DFAG)A5&!@I > > delta 2876 > zcmdT`UrbwN6#tqH3b?|cbX{f8OZhh#6beGez#+D!YuKRt%VK0{N;?X!gW0k__ > +s{E > z;)9sui)NZFGttCoTzJ`wM)qioffp0s(CEt^miVBF#yEe!?_M0+V9Op&b9>MIzVDv > % > zJLmk)Id}bi+scQwm0xUuTfe?rAsr<?`N)~p_iri-rK57rl4qsW^|O3y_esxzFXZll > zJ94G4Q`XB0<*xfZY4scO@xedjy63t+KjP|?51yZaTrZ7PU+T4gs(#S- > zYkrImx>Op > z- > tPFWM85V`IHD?|CRIX>sF(`L4Tn?SC~7%vD4%LjC$KiFLTXVh;6AT1SQ}Btl%b}u > zl2kJ)tIpzS2`3DdgS>?QdE77Q^(6MQ*wMOGUNy;D*jdgu(s+9bS1aTO*(huffA > ax3 > z>@9T?$*4v&g!>ep!g95?$@^qHlk#Vztq;0@xdE1llU5diBM+=iux3EM0(5!Ew0j > W} > zv1lLVYRoAkk%RJrQDMtV(&!@^R|4LTLe~&ZMS*4<(E^^Lx~Zo{C<d!b(4Rx(k} > 9Pw > zJ&cY>4D4lf<dQ(U%=pxvg~WC4hT%_0#g!j&NJl%V7Q_~7w$I}&cmkxc;yCg*ft > ZcU > zhCkriF;bE!_Q=cqm3AF*m6x%mUb$xMD<6c7F#Jlu${@TPmo?+anH_cfm;FgK > XGJcq > z+TkbjeqJL!2b>om5uKr9&Hn}XzlaqwB&9J&!Mi~qj;PbPzanFY+jqxZoq<Ni@- > ptr > z(92k*wYEGwNgBa|39?wT_cdo{>}k2#iM`|kIkIH=X4V7pQB97}ryQ>H`V_O8- > ^N|k > zQ8D8`h&WD4ZM{>b8%t%=@9Xm+YxLU0Pvi^G7DKE}nVBXZsok{BO3KiR+z(Y > b9`&@> > z!CZ%QWu62RS+9S2Ti$$fzIO6AwJWX^A}|lG5t~`r+Yu&FH(YJgIkoyi;lsgjGpR9 > M > z#5ys69A+8GPt8t- > 1#sgQnavVpV&|cj<XndGivVX>2J(0|+st{K$p9P!MM#TCi`jPa > zkl3Wsnrs=Y&f=LmlDIBg4l$8_{v>5|ySEx&7}Oa8LaPuE(ynR}Xs4i=iD~b5%Z$-e > zU{d7A=4b)KpO?X!?mDy8J!oP(wT~M$&CmIOg^h6$i3Z8`py)|t*Y@))YPP^}33 > y$M > zTb=pV1m0qV%%(y;{IM- > tD7<m_G_Fp;rx8daRwhW$N$8u9wdyuYR~%H!>EdM>vt@19 > zb)!B(yEdN$8{U>rYbgERFlx6@%5Y;H_nkgu`{6-xOa}Tr36?!6l0{xn_|Sb>=Xnki > z(S<D39jX(pxefTANn*q$+}J`4cIF_Uy5wf#RM`XyWE8C>VOo)~#wwn1nDH|$8 > }eI= > zv-cS-KEMdu!Lpc+ZvxgL>ZFQGc~c*3oPyV6;w&2a{ZK$kyG!j;nq@J`guPO+- > zRVN > z9VMdGdwsWUwv>GG;^!Viy$TvXnvOH- > jM#!6SvcN<bLC|&x!$$6cxx8qWN~0XR=W0! > zfsX;~tj-OD3tTA-yshF*S(TQ<*l3rUXptO0Q6cvtB`($mD~C;)XgRpkvKDEp<+x#! > zH%C+oRb&oJjwIb6;YYR13|BbV+_KnbdrnKhaPL7~LPu3~8Y>)q7qS1KwOIpA# > -i@k > zp2#Jedl#?ev!SnKGq|_coX_mQk49!|zAUha0PF&Y%xQ1ZxE1a;b(;>5glCbuB{; > +m > zZfII&(Q4Rm_%`QRPLmVw6TY2mcpJs(Jwm;&!x3uVBC+{plh=iK2`8;D9tOr?Hl- > {y > zqkqHIQ0*>W>NM$AB^$ATd>_3dn>{5#7SsRRW9QA46MKpoT~0iZ>Zr%gFN > AZ5F7i_T > gST^OI;ajpE*(V)?`|2OtRny4MG&K2?LzU?3Ut`2xSO5S3 > > -- > 1.9.5.msysgit.1 > >
------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel