2 The implementation for Shell command ifconfig based on IP4Config2 protocol.
4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "UefiShellNetwork1CommandsLib.h"
26 VarCheckReserved
= -1,
40 } VAR_CHECK_FLAG_TYPE
;
42 #define MACADDRMAXSIZE 32
44 typedef struct _IFCONFIG_INTERFACE_CB
{
47 EFI_IP4_CONFIG2_PROTOCOL
*IfCfg
;
48 EFI_IP4_CONFIG2_INTERFACE_INFO
*IfInfo
;
49 EFI_IP4_CONFIG2_POLICY Policy
;
51 EFI_IPv4_ADDRESS DnsAddr
[1];
52 } IFCONFIG_INTERFACE_CB
;
54 typedef struct _ARG_LIST ARG_LIST
;
61 typedef struct _IFCONFIG4_PRIVATE_DATA
{
67 } IFCONFIG_PRIVATE_DATA
;
69 typedef struct _VAR_CHECK_ITEM
{
73 VAR_CHECK_FLAG_TYPE FlagType
;
76 SHELL_PARAM_ITEM mIfConfigCheckList
[] = {
103 VAR_CHECK_ITEM mSetCheckList
[] = {
130 STATIC CONST CHAR16 PermanentString
[10] = L
"PERMANENT";
133 Split a string with specified separator and save the substring to a list.
135 @param[in] String The pointer of the input string.
136 @param[in] Separator The specified separator.
138 @return The pointer of headnode of ARG_LIST.
143 IN CONST CHAR16
*String
,
152 if (*String
== L
'\0') {
157 // Copy the CONST string to a local copy.
159 Str
= AllocateCopyPool (StrSize (String
), String
);
160 ASSERT (Str
!= NULL
);
164 // init a node for the list head.
166 ArgNode
= (ARG_LIST
*) AllocateZeroPool (sizeof (ARG_LIST
));
167 ASSERT (ArgNode
!= NULL
);
171 // Split the local copy and save in the list node.
173 while (*Str
!= L
'\0') {
174 if (*Str
== Separator
) {
176 ArgNode
->Arg
= ArgStr
;
178 ArgNode
->Next
= (ARG_LIST
*) AllocateZeroPool (sizeof (ARG_LIST
));
179 ASSERT (ArgNode
->Next
!= NULL
);
180 ArgNode
= ArgNode
->Next
;
186 ArgNode
->Arg
= ArgStr
;
187 ArgNode
->Next
= NULL
;
193 Check the correctness of input Args with '-s' option.
195 @param[in] CheckList The pointer of VAR_CHECK_ITEM array.
196 @param[in] Name The pointer of input arg.
197 @param[in] Init The switch to execute the check.
199 @return VarCheckOk Valid parameter or Initialize check successfully.
200 @return VarCheckDuplicate Duplicated parameter happened.
201 @return VarCheckConflict Conflicted parameter happened
202 @return VarCheckUnknown Unknown parameter.
206 IfConfigRetriveCheckListByName(
207 IN VAR_CHECK_ITEM
*CheckList
,
212 STATIC UINT32 CheckDuplicate
;
213 STATIC UINT32 CheckConflict
;
214 VAR_CHECK_CODE RtCode
;
226 Arg
= CheckList
[Index
];
229 // Check the Duplicated/Conflicted/Unknown input Args.
231 while (Arg
.FlagStr
!= NULL
) {
232 if (StrCmp (Arg
.FlagStr
, Name
) == 0) {
234 if (CheckDuplicate
& Arg
.FlagID
) {
235 RtCode
= VarCheckDuplicate
;
239 if (CheckConflict
& Arg
.ConflictMask
) {
240 RtCode
= VarCheckConflict
;
244 CheckDuplicate
|= Arg
.FlagID
;
245 CheckConflict
|= Arg
.ConflictMask
;
249 Arg
= CheckList
[++Index
];
252 if (Arg
.FlagStr
== NULL
) {
253 RtCode
= VarCheckUnknown
;
260 The notify function of create event when performing a manual config.
262 @param[in] Event The event this notify function registered to.
263 @param[in] Context Pointer to the context data registered to the event.
268 IfConfigManualAddressNotify (
273 *((BOOLEAN
*) Context
) = TRUE
;
280 @param[in] Node The pointer of MAC address buffer.
281 @param[in] Size The size of MAC address buffer.
285 IfConfigPrintMacAddr (
292 ASSERT (Size
<= MACADDRMAXSIZE
);
294 for (Index
= 0; Index
< Size
; Index
++) {
295 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_BODY
), gShellNetwork1HiiHandle
, Node
[Index
]);
296 if (Index
+ 1 < Size
) {
297 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_COLON
), gShellNetwork1HiiHandle
);
301 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE
), gShellNetwork1HiiHandle
);
306 The get current status of all handles.
308 @param[in] IfName The pointer of IfName(interface name).
309 @param[in] IfList The pointer of IfList(interface list).
311 @retval EFI_SUCCESS The get status processed successfully.
312 @retval others The get status process failed.
316 IfConfigGetInterfaceInfo (
318 IN LIST_ENTRY
*IfList
324 EFI_HANDLE
*HandleBuffer
;
325 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Cfg2
;
326 EFI_IP4_CONFIG2_INTERFACE_INFO
*IfInfo
;
327 IFCONFIG_INTERFACE_CB
*IfCb
;
337 // Locate all the handles with ip4 service binding protocol.
339 Status
= gBS
->LocateHandleBuffer (
341 &gEfiIp4ServiceBindingProtocolGuid
,
346 if (EFI_ERROR (Status
) || (HandleNum
== 0)) {
351 // Enumerate all handles that installed with ip4 service binding protocol.
353 for (HandleIndex
= 0; HandleIndex
< HandleNum
; HandleIndex
++) {
359 // Ip4config protocol and ip4 service binding protocol are installed
360 // on the same handle.
362 ASSERT (HandleBuffer
!= NULL
);
363 Status
= gBS
->HandleProtocol (
364 HandleBuffer
[HandleIndex
],
365 &gEfiIp4Config2ProtocolGuid
,
369 if (EFI_ERROR (Status
)) {
374 // Get the interface information size.
376 Status
= Ip4Cfg2
->GetData (
378 Ip4Config2DataTypeInterfaceInfo
,
383 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
387 IfInfo
= AllocateZeroPool (DataSize
);
389 if (IfInfo
== NULL
) {
390 Status
= EFI_OUT_OF_RESOURCES
;
395 // Get the interface info.
397 Status
= Ip4Cfg2
->GetData (
399 Ip4Config2DataTypeInterfaceInfo
,
404 if (EFI_ERROR (Status
)) {
409 // Check the interface name if required.
411 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfInfo
->Name
) != 0)) {
419 // Get the size of dns server list.
421 Status
= Ip4Cfg2
->GetData (
423 Ip4Config2DataTypeDnsServer
,
428 if ((Status
!= EFI_BUFFER_TOO_SMALL
) && (Status
!= EFI_NOT_FOUND
)) {
432 IfCb
= AllocateZeroPool (sizeof (IFCONFIG_INTERFACE_CB
) + DataSize
);
435 Status
= EFI_OUT_OF_RESOURCES
;
439 IfCb
->NicHandle
= HandleBuffer
[HandleIndex
];
440 IfCb
->IfInfo
= IfInfo
;
441 IfCb
->IfCfg
= Ip4Cfg2
;
442 IfCb
->DnsCnt
= (UINT32
) (DataSize
/ sizeof (EFI_IPv4_ADDRESS
));
445 // Get the dns server list if has.
448 Status
= Ip4Cfg2
->GetData (
450 Ip4Config2DataTypeDnsServer
,
455 if (EFI_ERROR (Status
)) {
461 // Get the config policy.
463 DataSize
= sizeof (EFI_IP4_CONFIG2_POLICY
);
464 Status
= Ip4Cfg2
->GetData (
466 Ip4Config2DataTypePolicy
,
471 if (EFI_ERROR (Status
)) {
475 InsertTailList (IfList
, &IfCb
->Link
);
477 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfInfo
->Name
) == 0)) {
479 // Only need the appointed interface, keep the allocated buffer.
487 if (HandleBuffer
!= NULL
) {
488 FreePool (HandleBuffer
);
495 if (IfInfo
!= NULL
) {
507 The list process of the ifconfig command.
509 @param[in] IfList The pointer of IfList(interface list).
511 @retval EFI_SUCCESS The ifconfig command list processed successfully.
512 @retval others The ifconfig command list process failed.
516 IfConfigShowInterfaceInfo (
517 IN LIST_ENTRY
*IfList
523 IFCONFIG_INTERFACE_CB
*IfCb
;
524 EFI_IPv4_ADDRESS Gateway
;
527 Status
= EFI_SUCCESS
;
529 if (IsListEmpty (IfList
)) {
530 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE
), gShellNetwork1HiiHandle
);
534 // Go through the interface list.
536 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, IfList
) {
537 IfCb
= NET_LIST_USER_STRUCT (Entry
, IFCONFIG_INTERFACE_CB
, Link
);
539 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK
), gShellNetwork1HiiHandle
);
542 // Print interface name.
544 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_IF_NAME
), gShellNetwork1HiiHandle
, IfCb
->IfInfo
->Name
);
547 // Print interface config policy.
549 if (IfCb
->Policy
== Ip4Config2PolicyDhcp
) {
550 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_DHCP
), gShellNetwork1HiiHandle
);
552 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_MAN
), gShellNetwork1HiiHandle
);
556 // Print mac address of the interface.
558 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_HEAD
), gShellNetwork1HiiHandle
);
560 IfConfigPrintMacAddr (
561 IfCb
->IfInfo
->HwAddress
.Addr
,
562 IfCb
->IfInfo
->HwAddressSize
566 // Print IPv4 address list of the interface.
568 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_HEAD
), gShellNetwork1HiiHandle
);
574 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY
),
575 gShellNetwork1HiiHandle
,
576 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[0],
577 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[1],
578 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[2],
579 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[3]
583 // Print subnet mask list of the interface.
585 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_SUBNET_MASK_HEAD
), gShellNetwork1HiiHandle
);
591 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY
),
592 gShellNetwork1HiiHandle
,
593 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[0],
594 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[1],
595 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[2],
596 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[3]
600 // Print default gateway of the interface.
602 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_GATEWAY_HEAD
), gShellNetwork1HiiHandle
);
604 ZeroMem (&Gateway
, sizeof (EFI_IPv4_ADDRESS
));
606 for (Index
= 0; Index
< IfCb
->IfInfo
->RouteTableSize
; Index
++) {
607 if ((CompareMem (&IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) &&
608 (CompareMem (&IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) ){
609 CopyMem (&Gateway
, &IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
617 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY
),
618 gShellNetwork1HiiHandle
,
619 (UINTN
)Gateway
.Addr
[0],
620 (UINTN
)Gateway
.Addr
[1],
621 (UINTN
)Gateway
.Addr
[2],
622 (UINTN
)Gateway
.Addr
[3]
626 // Print route table entry.
628 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE
), gShellNetwork1HiiHandle
, IfCb
->IfInfo
->RouteTableSize
);
630 for (Index
= 0; Index
< IfCb
->IfInfo
->RouteTableSize
; Index
++) {
631 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX
), gShellNetwork1HiiHandle
, Index
);
637 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
638 gShellNetwork1HiiHandle
,
640 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[0],
641 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[1],
642 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[2],
643 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[3]
650 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
651 gShellNetwork1HiiHandle
,
653 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[0],
654 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[1],
655 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[2],
656 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[3]
663 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
664 gShellNetwork1HiiHandle
,
666 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[0],
667 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[1],
668 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[2],
669 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[3]
674 // Print dns server addresses list of the interface if has.
676 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_HEAD
), gShellNetwork1HiiHandle
);
678 for (Index
= 0; Index
< IfCb
->DnsCnt
; Index
++) {
683 STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_BODY
),
684 gShellNetwork1HiiHandle
,
685 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[0],
686 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[1],
687 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[2],
688 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[3]
691 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE
), gShellNetwork1HiiHandle
);
695 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK
), gShellNetwork1HiiHandle
);
701 The clean process of the ifconfig command to clear interface info.
703 @param[in] IfList The pointer of IfList(interface list).
705 @retval EFI_SUCCESS The ifconfig command clean processed successfully.
706 @retval others The ifconfig command clean process failed.
710 IfConfigClearInterfaceInfo (
711 IN LIST_ENTRY
*IfList
717 IFCONFIG_INTERFACE_CB
*IfCb
;
718 EFI_IP4_CONFIG2_POLICY Policy
;
720 Policy
= Ip4Config2PolicyDhcp
;
721 Status
= EFI_SUCCESS
;
723 if (IsListEmpty (IfList
)) {
724 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE
), gShellNetwork1HiiHandle
);
728 // Go through the interface list.
730 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, IfList
) {
731 IfCb
= NET_LIST_USER_STRUCT (Entry
, IFCONFIG_INTERFACE_CB
, Link
);
733 Status
= IfCb
->IfCfg
->SetData (
735 Ip4Config2DataTypePolicy
,
736 sizeof (EFI_IP4_CONFIG2_POLICY
),
740 if (EFI_ERROR (Status
)) {
749 The set process of the ifconfig command.
751 @param[in] IfList The pointer of IfList(interface list).
752 @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
754 @retval EFI_SUCCESS The ifconfig command set processed successfully.
755 @retval others The ifconfig command set process failed.
759 IfConfigSetInterfaceInfo (
760 IN LIST_ENTRY
*IfList
,
766 IFCONFIG_INTERFACE_CB
*IfCb
;
767 VAR_CHECK_CODE CheckCode
;
768 EFI_EVENT TimeOutEvt
;
772 EFI_IP4_CONFIG2_POLICY Policy
;
773 EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress
;
775 EFI_IPv4_ADDRESS Gateway
;
776 EFI_IPv4_ADDRESS
*Dns
;
780 CONST CHAR16
* TempString
;
784 if (IsListEmpty (IfList
)) {
785 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE
), gShellNetwork1HiiHandle
);
786 return EFI_INVALID_PARAMETER
;
790 // Make sure to set only one interface each time.
792 IfCb
= NET_LIST_USER_STRUCT (IfList
->ForwardLink
, IFCONFIG_INTERFACE_CB
, Link
);
793 Status
= EFI_SUCCESS
;
796 // Initialize check list mechanism.
798 CheckCode
= IfConfigRetriveCheckListByName(
805 // Create events & timers for asynchronous settings.
807 Status
= gBS
->CreateEvent (
814 if (EFI_ERROR (Status
)) {
818 Status
= gBS
->CreateEvent (
821 IfConfigManualAddressNotify
,
825 if (EFI_ERROR (Status
)) {
830 // Parse the setting variables.
832 while (VarArg
!= NULL
) {
834 // Check invalid parameters (duplication & unknown & conflict).
836 CheckCode
= IfConfigRetriveCheckListByName(
842 if (VarCheckOk
!= CheckCode
) {
844 case VarCheckDuplicate
:
845 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_DUPLICATE_COMMAND
), gShellNetwork1HiiHandle
, VarArg
->Arg
);
848 case VarCheckConflict
:
849 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_CONFLICT_COMMAND
), gShellNetwork1HiiHandle
, VarArg
->Arg
);
852 case VarCheckUnknown
:
854 // To handle unsupported option.
856 TempString
= PermanentString
;
857 if (StringNoCaseCompare(&VarArg
->Arg
, &TempString
) == 0) {
858 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION
), gShellNetwork1HiiHandle
, PermanentString
);
863 // To handle unknown option.
865 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_UNKNOWN_COMMAND
), gShellNetwork1HiiHandle
, VarArg
->Arg
);
872 VarArg
= VarArg
->Next
;
877 // Process valid variables.
879 if (StrCmp(VarArg
->Arg
, L
"dhcp") == 0) {
881 // Set dhcp config policy
883 Policy
= Ip4Config2PolicyDhcp
;
884 Status
= IfCb
->IfCfg
->SetData (
886 Ip4Config2DataTypePolicy
,
887 sizeof (EFI_IP4_CONFIG2_POLICY
),
891 if (EFI_ERROR(Status
)) {
895 VarArg
= VarArg
->Next
;
897 } else if (StrCmp (VarArg
->Arg
, L
"static") == 0) {
899 // Set manual config policy.
901 Policy
= Ip4Config2PolicyStatic
;
902 Status
= IfCb
->IfCfg
->SetData (
904 Ip4Config2DataTypePolicy
,
905 sizeof (EFI_IP4_CONFIG2_POLICY
),
909 if (EFI_ERROR(Status
)) {
913 VarArg
= VarArg
->Next
;
915 ZeroMem (&ManualAddress
, sizeof (ManualAddress
));
918 // Get manual IP address.
920 Status
= NetLibStrToIp4 (VarArg
->Arg
, &ManualAddress
.Address
);
921 if (EFI_ERROR(Status
)) {
928 VarArg
= VarArg
->Next
;
929 Status
= NetLibStrToIp4 (VarArg
->Arg
, &ManualAddress
.SubnetMask
);
930 if (EFI_ERROR(Status
)) {
937 VarArg
= VarArg
->Next
;
938 Status
= NetLibStrToIp4 (VarArg
->Arg
, &Gateway
);
939 if (EFI_ERROR(Status
)) {
945 Status
= IfCb
->IfCfg
->RegisterDataNotify (
947 Ip4Config2DataTypeManualAddress
,
950 if (EFI_ERROR (Status
)) {
954 DataSize
= sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS
);
956 Status
= IfCb
->IfCfg
->SetData (
958 Ip4Config2DataTypeManualAddress
,
963 if (Status
== EFI_NOT_READY
) {
964 gBS
->SetTimer (TimeOutEvt
, TimerRelative
, 50000000);
966 while (EFI_ERROR (gBS
->CheckEvent (TimeOutEvt
))) {
968 Status
= EFI_SUCCESS
;
974 IfCb
->IfCfg
->UnregisterDataNotify (
976 Ip4Config2DataTypeManualAddress
,
980 if (EFI_ERROR (Status
)) {
981 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED
), gShellNetwork1HiiHandle
, Status
);
988 DataSize
= sizeof (EFI_IPv4_ADDRESS
);
990 Status
= IfCb
->IfCfg
->SetData (
992 Ip4Config2DataTypeGateway
,
996 VarArg
= VarArg
->Next
;
998 } else if (StrCmp (VarArg
->Arg
, L
"dns") == 0) {
1000 // Get DNS addresses.
1002 VarArg
= VarArg
->Next
;
1005 while (Tmp
!= NULL
) {
1010 Dns
= AllocatePool (Index
* sizeof (EFI_IPv4_ADDRESS
));
1011 ASSERT(Dns
!= NULL
);
1014 while (Tmp
!= NULL
) {
1015 Status
= NetLibStrToIp4 (Tmp
->Arg
, Dns
+ Index
);
1016 if (EFI_ERROR(Status
)) {
1026 // Set DNS addresses.
1028 DataSize
= Index
* sizeof (EFI_IPv4_ADDRESS
);
1030 Status
= IfCb
->IfCfg
->SetData (
1032 Ip4Config2DataTypeDnsServer
,
1049 The ifconfig command main process.
1051 @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
1053 @retval EFI_SUCCESS ifconfig command processed successfully.
1054 @retval others The ifconfig command process failed.
1059 IN IFCONFIG_PRIVATE_DATA
*Private
1065 // Get configure information of all interfaces.
1067 Status
= IfConfigGetInterfaceInfo (
1072 if (EFI_ERROR (Status
)) {
1076 switch (Private
->OpCode
) {
1077 case IfConfigOpList
:
1078 Status
= IfConfigShowInterfaceInfo (&Private
->IfList
);
1081 case IfConfigOpClear
:
1082 Status
= IfConfigClearInterfaceInfo (&Private
->IfList
);
1086 Status
= IfConfigSetInterfaceInfo (&Private
->IfList
, Private
->VarArg
);
1090 Status
= EFI_ABORTED
;
1099 The ifconfig command cleanup process, free the allocated memory.
1101 @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
1106 IN IFCONFIG_PRIVATE_DATA
*Private
1110 LIST_ENTRY
*NextEntry
;
1111 IFCONFIG_INTERFACE_CB
*IfCb
;
1115 ASSERT (Private
!= NULL
);
1118 // Clean the list which save the set config Args.
1120 if (Private
->VarArg
!= NULL
) {
1121 ArgHead
= Private
->VarArg
;
1123 while (ArgHead
->Next
!= NULL
) {
1124 ArgNode
= ArgHead
->Next
;
1132 if (Private
->IfName
!= NULL
) {
1133 FreePool (Private
->IfName
);
1137 // Clean the IFCONFIG_INTERFACE_CB list.
1139 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &Private
->IfList
) {
1140 IfCb
= NET_LIST_USER_STRUCT (Entry
, IFCONFIG_INTERFACE_CB
, Link
);
1142 RemoveEntryList (&IfCb
->Link
);
1144 if (IfCb
->IfInfo
!= NULL
) {
1146 FreePool (IfCb
->IfInfo
);
1156 Function for 'ifconfig' command.
1158 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1159 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1161 @retval EFI_SUCCESS ifconfig command processed successfully.
1162 @retval others The ifconfig command process failed.
1167 ShellCommandRunIfconfig (
1168 IN EFI_HANDLE ImageHandle
,
1169 IN EFI_SYSTEM_TABLE
*SystemTable
1173 IFCONFIG_PRIVATE_DATA
*Private
;
1174 LIST_ENTRY
*ParamPackage
;
1175 CONST CHAR16
*ValueStr
;
1177 CHAR16
*ProblemParam
;
1182 Status
= ShellCommandLineParseEx (mIfConfigCheckList
, &ParamPackage
, &ProblemParam
, TRUE
, FALSE
);
1183 if (EFI_ERROR (Status
)) {
1184 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellNetwork1HiiHandle
, L
"ifconfig", ProblemParam
);
1189 // To handle unsupported option.
1191 if (ShellCommandLineGetFlag (ParamPackage
, L
"-c")) {
1192 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION
), gShellNetwork1HiiHandle
,L
"-c");
1197 // To handle no option.
1199 if (!ShellCommandLineGetFlag (ParamPackage
, L
"-r") && !ShellCommandLineGetFlag (ParamPackage
, L
"-s") &&
1200 !ShellCommandLineGetFlag (ParamPackage
, L
"-l")) {
1201 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_LACK_OPTION
), gShellNetwork1HiiHandle
);
1206 // To handle conflict options.
1208 if (((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-s"))) ||
1209 ((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l"))) ||
1210 ((ShellCommandLineGetFlag (ParamPackage
, L
"-s")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l")))) {
1211 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellNetwork1HiiHandle
, L
"ifconfig");
1215 Status
= EFI_INVALID_PARAMETER
;
1217 Private
= AllocateZeroPool (sizeof (IFCONFIG_PRIVATE_DATA
));
1219 if (Private
== NULL
) {
1220 Status
= EFI_OUT_OF_RESOURCES
;
1224 InitializeListHead (&Private
->IfList
);
1227 // To get interface name for the list option.
1229 if (ShellCommandLineGetFlag (ParamPackage
, L
"-l")) {
1230 Private
->OpCode
= IfConfigOpList
;
1231 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-l");
1232 if (ValueStr
!= NULL
) {
1233 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1234 ASSERT (Str
!= NULL
);
1235 Private
->IfName
= Str
;
1240 // To get interface name for the clear option.
1242 if (ShellCommandLineGetFlag (ParamPackage
, L
"-r")) {
1243 Private
->OpCode
= IfConfigOpClear
;
1244 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-r");
1245 if (ValueStr
!= NULL
) {
1246 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1247 ASSERT (Str
!= NULL
);
1248 Private
->IfName
= Str
;
1253 // To get interface name and corresponding Args for the set option.
1255 if (ShellCommandLineGetFlag (ParamPackage
, L
"-s")) {
1256 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-s");
1257 if (ValueStr
== NULL
) {
1258 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_LACK_INTERFACE
), gShellNetwork1HiiHandle
);
1263 // To split the configuration into multi-section.
1265 ArgList
= SplitStrToList (ValueStr
, L
' ');
1266 ASSERT (ArgList
!= NULL
);
1268 Private
->OpCode
= IfConfigOpSet
;
1269 Private
->IfName
= ArgList
->Arg
;
1271 Private
->VarArg
= ArgList
->Next
;
1273 if (Private
->IfName
== NULL
|| Private
->VarArg
== NULL
) {
1274 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND
), gShellNetwork1HiiHandle
);
1280 // Main process of ifconfig.
1282 Status
= IfConfig (Private
);
1286 ShellCommandLineFreeVarList (ParamPackage
);
1288 if (Private
!= NULL
) {
1289 IfConfigCleanup (Private
);