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
522 IFCONFIG_INTERFACE_CB
*IfCb
;
523 EFI_IPv4_ADDRESS Gateway
;
526 if (IsListEmpty (IfList
)) {
527 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE
), gShellNetwork1HiiHandle
);
531 // Go through the interface list.
533 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, IfList
) {
534 IfCb
= NET_LIST_USER_STRUCT (Entry
, IFCONFIG_INTERFACE_CB
, Link
);
536 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK
), gShellNetwork1HiiHandle
);
539 // Print interface name.
541 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_IF_NAME
), gShellNetwork1HiiHandle
, IfCb
->IfInfo
->Name
);
544 // Print interface config policy.
546 if (IfCb
->Policy
== Ip4Config2PolicyDhcp
) {
547 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_DHCP
), gShellNetwork1HiiHandle
);
549 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_MAN
), gShellNetwork1HiiHandle
);
553 // Print mac address of the interface.
555 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_HEAD
), gShellNetwork1HiiHandle
);
557 IfConfigPrintMacAddr (
558 IfCb
->IfInfo
->HwAddress
.Addr
,
559 IfCb
->IfInfo
->HwAddressSize
563 // Print IPv4 address list of the interface.
565 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_HEAD
), gShellNetwork1HiiHandle
);
571 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY
),
572 gShellNetwork1HiiHandle
,
573 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[0],
574 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[1],
575 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[2],
576 (UINTN
)IfCb
->IfInfo
->StationAddress
.Addr
[3]
580 // Print subnet mask list of the interface.
582 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_SUBNET_MASK_HEAD
), gShellNetwork1HiiHandle
);
588 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY
),
589 gShellNetwork1HiiHandle
,
590 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[0],
591 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[1],
592 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[2],
593 (UINTN
)IfCb
->IfInfo
->SubnetMask
.Addr
[3]
597 // Print default gateway of the interface.
599 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_GATEWAY_HEAD
), gShellNetwork1HiiHandle
);
601 ZeroMem (&Gateway
, sizeof (EFI_IPv4_ADDRESS
));
603 for (Index
= 0; Index
< IfCb
->IfInfo
->RouteTableSize
; Index
++) {
604 if ((CompareMem (&IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) &&
605 (CompareMem (&IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) ){
606 CopyMem (&Gateway
, &IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
614 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY
),
615 gShellNetwork1HiiHandle
,
616 (UINTN
)Gateway
.Addr
[0],
617 (UINTN
)Gateway
.Addr
[1],
618 (UINTN
)Gateway
.Addr
[2],
619 (UINTN
)Gateway
.Addr
[3]
623 // Print route table entry.
625 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE
), gShellNetwork1HiiHandle
, IfCb
->IfInfo
->RouteTableSize
);
627 for (Index
= 0; Index
< IfCb
->IfInfo
->RouteTableSize
; Index
++) {
628 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX
), gShellNetwork1HiiHandle
, Index
);
634 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
635 gShellNetwork1HiiHandle
,
637 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[0],
638 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[1],
639 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[2],
640 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetAddress
.Addr
[3]
647 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
648 gShellNetwork1HiiHandle
,
650 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[0],
651 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[1],
652 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[2],
653 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].SubnetMask
.Addr
[3]
660 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
661 gShellNetwork1HiiHandle
,
663 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[0],
664 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[1],
665 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[2],
666 (UINTN
)IfCb
->IfInfo
->RouteTable
[Index
].GatewayAddress
.Addr
[3]
671 // Print dns server addresses list of the interface if has.
673 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_HEAD
), gShellNetwork1HiiHandle
);
675 for (Index
= 0; Index
< IfCb
->DnsCnt
; Index
++) {
680 STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_BODY
),
681 gShellNetwork1HiiHandle
,
682 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[0],
683 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[1],
684 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[2],
685 (UINTN
) IfCb
->DnsAddr
[Index
].Addr
[3]
688 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE
), gShellNetwork1HiiHandle
);
692 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK
), gShellNetwork1HiiHandle
);
698 The clean process of the ifconfig command to clear interface info.
700 @param[in] IfList The pointer of IfList(interface list).
702 @retval EFI_SUCCESS The ifconfig command clean processed successfully.
703 @retval others The ifconfig command clean process failed.
707 IfConfigClearInterfaceInfo (
708 IN LIST_ENTRY
*IfList
714 IFCONFIG_INTERFACE_CB
*IfCb
;
715 EFI_IP4_CONFIG2_POLICY Policy
;
717 Policy
= Ip4Config2PolicyDhcp
;
718 Status
= EFI_SUCCESS
;
720 if (IsListEmpty (IfList
)) {
721 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE
), gShellNetwork1HiiHandle
);
725 // Go through the interface list.
727 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, IfList
) {
728 IfCb
= NET_LIST_USER_STRUCT (Entry
, IFCONFIG_INTERFACE_CB
, Link
);
730 Status
= IfCb
->IfCfg
->SetData (
732 Ip4Config2DataTypePolicy
,
733 sizeof (EFI_IP4_CONFIG2_POLICY
),
737 if (EFI_ERROR (Status
)) {
746 The set process of the ifconfig command.
748 @param[in] IfList The pointer of IfList(interface list).
749 @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
751 @retval EFI_SUCCESS The ifconfig command set processed successfully.
752 @retval others The ifconfig command set process failed.
756 IfConfigSetInterfaceInfo (
757 IN LIST_ENTRY
*IfList
,
763 IFCONFIG_INTERFACE_CB
*IfCb
;
764 VAR_CHECK_CODE CheckCode
;
765 EFI_EVENT TimeOutEvt
;
769 EFI_IP4_CONFIG2_POLICY Policy
;
770 EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress
;
772 EFI_IPv4_ADDRESS Gateway
;
773 EFI_IPv4_ADDRESS
*Dns
;
777 CONST CHAR16
* TempString
;
781 if (IsListEmpty (IfList
)) {
782 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE
), gShellNetwork1HiiHandle
);
783 return EFI_INVALID_PARAMETER
;
787 // Make sure to set only one interface each time.
789 IfCb
= NET_LIST_USER_STRUCT (IfList
->ForwardLink
, IFCONFIG_INTERFACE_CB
, Link
);
790 Status
= EFI_SUCCESS
;
793 // Initialize check list mechanism.
795 CheckCode
= IfConfigRetriveCheckListByName(
802 // Create events & timers for asynchronous settings.
804 Status
= gBS
->CreateEvent (
811 if (EFI_ERROR (Status
)) {
815 Status
= gBS
->CreateEvent (
818 IfConfigManualAddressNotify
,
822 if (EFI_ERROR (Status
)) {
827 // Parse the setting variables.
829 while (VarArg
!= NULL
) {
831 // Check invalid parameters (duplication & unknown & conflict).
833 CheckCode
= IfConfigRetriveCheckListByName(
839 if (VarCheckOk
!= CheckCode
) {
841 case VarCheckDuplicate
:
842 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_DUPLICATE_COMMAND
), gShellNetwork1HiiHandle
, VarArg
->Arg
);
845 case VarCheckConflict
:
846 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_CONFLICT_COMMAND
), gShellNetwork1HiiHandle
, VarArg
->Arg
);
849 case VarCheckUnknown
:
851 // To handle unsupported option.
853 TempString
= PermanentString
;
854 if (StringNoCaseCompare(&VarArg
->Arg
, &TempString
) == 0) {
855 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION
), gShellNetwork1HiiHandle
, PermanentString
);
860 // To handle unknown option.
862 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_UNKNOWN_COMMAND
), gShellNetwork1HiiHandle
, VarArg
->Arg
);
869 VarArg
= VarArg
->Next
;
874 // Process valid variables.
876 if (StrCmp(VarArg
->Arg
, L
"dhcp") == 0) {
878 // Set dhcp config policy
880 Policy
= Ip4Config2PolicyDhcp
;
881 Status
= IfCb
->IfCfg
->SetData (
883 Ip4Config2DataTypePolicy
,
884 sizeof (EFI_IP4_CONFIG2_POLICY
),
888 if (EFI_ERROR(Status
)) {
892 VarArg
= VarArg
->Next
;
894 } else if (StrCmp (VarArg
->Arg
, L
"static") == 0) {
896 // Set manual config policy.
898 Policy
= Ip4Config2PolicyStatic
;
899 Status
= IfCb
->IfCfg
->SetData (
901 Ip4Config2DataTypePolicy
,
902 sizeof (EFI_IP4_CONFIG2_POLICY
),
906 if (EFI_ERROR(Status
)) {
910 VarArg
= VarArg
->Next
;
912 ZeroMem (&ManualAddress
, sizeof (ManualAddress
));
915 // Get manual IP address.
917 Status
= NetLibStrToIp4 (VarArg
->Arg
, &ManualAddress
.Address
);
918 if (EFI_ERROR(Status
)) {
925 VarArg
= VarArg
->Next
;
926 Status
= NetLibStrToIp4 (VarArg
->Arg
, &ManualAddress
.SubnetMask
);
927 if (EFI_ERROR(Status
)) {
934 VarArg
= VarArg
->Next
;
935 Status
= NetLibStrToIp4 (VarArg
->Arg
, &Gateway
);
936 if (EFI_ERROR(Status
)) {
942 Status
= IfCb
->IfCfg
->RegisterDataNotify (
944 Ip4Config2DataTypeManualAddress
,
947 if (EFI_ERROR (Status
)) {
951 DataSize
= sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS
);
953 Status
= IfCb
->IfCfg
->SetData (
955 Ip4Config2DataTypeManualAddress
,
960 if (Status
== EFI_NOT_READY
) {
961 gBS
->SetTimer (TimeOutEvt
, TimerRelative
, 50000000);
963 while (EFI_ERROR (gBS
->CheckEvent (TimeOutEvt
))) {
965 Status
= EFI_SUCCESS
;
971 IfCb
->IfCfg
->UnregisterDataNotify (
973 Ip4Config2DataTypeManualAddress
,
977 if (EFI_ERROR (Status
)) {
978 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED
), gShellNetwork1HiiHandle
, Status
);
985 DataSize
= sizeof (EFI_IPv4_ADDRESS
);
987 Status
= IfCb
->IfCfg
->SetData (
989 Ip4Config2DataTypeGateway
,
993 VarArg
= VarArg
->Next
;
995 } else if (StrCmp (VarArg
->Arg
, L
"dns") == 0) {
997 // Get DNS addresses.
999 VarArg
= VarArg
->Next
;
1002 while (Tmp
!= NULL
) {
1007 Dns
= AllocatePool (Index
* sizeof (EFI_IPv4_ADDRESS
));
1008 ASSERT(Dns
!= NULL
);
1011 while (Tmp
!= NULL
) {
1012 Status
= NetLibStrToIp4 (Tmp
->Arg
, Dns
+ Index
);
1013 if (EFI_ERROR(Status
)) {
1023 // Set DNS addresses.
1025 DataSize
= Index
* sizeof (EFI_IPv4_ADDRESS
);
1027 Status
= IfCb
->IfCfg
->SetData (
1029 Ip4Config2DataTypeDnsServer
,
1046 The ifconfig command main process.
1048 @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
1050 @retval EFI_SUCCESS ifconfig command processed successfully.
1051 @retval others The ifconfig command process failed.
1056 IN IFCONFIG_PRIVATE_DATA
*Private
1062 // Get configure information of all interfaces.
1064 Status
= IfConfigGetInterfaceInfo (
1069 if (EFI_ERROR (Status
)) {
1073 switch (Private
->OpCode
) {
1074 case IfConfigOpList
:
1075 Status
= IfConfigShowInterfaceInfo (&Private
->IfList
);
1078 case IfConfigOpClear
:
1079 Status
= IfConfigClearInterfaceInfo (&Private
->IfList
);
1083 Status
= IfConfigSetInterfaceInfo (&Private
->IfList
, Private
->VarArg
);
1087 Status
= EFI_ABORTED
;
1096 The ifconfig command cleanup process, free the allocated memory.
1098 @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.
1103 IN IFCONFIG_PRIVATE_DATA
*Private
1107 LIST_ENTRY
*NextEntry
;
1108 IFCONFIG_INTERFACE_CB
*IfCb
;
1112 ASSERT (Private
!= NULL
);
1115 // Clean the list which save the set config Args.
1117 if (Private
->VarArg
!= NULL
) {
1118 ArgHead
= Private
->VarArg
;
1120 while (ArgHead
->Next
!= NULL
) {
1121 ArgNode
= ArgHead
->Next
;
1129 if (Private
->IfName
!= NULL
) {
1130 FreePool (Private
->IfName
);
1134 // Clean the IFCONFIG_INTERFACE_CB list.
1136 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &Private
->IfList
) {
1137 IfCb
= NET_LIST_USER_STRUCT (Entry
, IFCONFIG_INTERFACE_CB
, Link
);
1139 RemoveEntryList (&IfCb
->Link
);
1141 if (IfCb
->IfInfo
!= NULL
) {
1143 FreePool (IfCb
->IfInfo
);
1153 Function for 'ifconfig' command.
1155 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1156 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1158 @retval EFI_SUCCESS ifconfig command processed successfully.
1159 @retval others The ifconfig command process failed.
1164 ShellCommandRunIfconfig (
1165 IN EFI_HANDLE ImageHandle
,
1166 IN EFI_SYSTEM_TABLE
*SystemTable
1170 IFCONFIG_PRIVATE_DATA
*Private
;
1171 LIST_ENTRY
*ParamPackage
;
1172 CONST CHAR16
*ValueStr
;
1174 CHAR16
*ProblemParam
;
1179 Status
= ShellCommandLineParseEx (mIfConfigCheckList
, &ParamPackage
, &ProblemParam
, TRUE
, FALSE
);
1180 if (EFI_ERROR (Status
)) {
1181 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellNetwork1HiiHandle
, L
"ifconfig", ProblemParam
);
1186 // To handle unsupported option.
1188 if (ShellCommandLineGetFlag (ParamPackage
, L
"-c")) {
1189 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION
), gShellNetwork1HiiHandle
,L
"-c");
1194 // To handle no option.
1196 if (!ShellCommandLineGetFlag (ParamPackage
, L
"-r") && !ShellCommandLineGetFlag (ParamPackage
, L
"-s") &&
1197 !ShellCommandLineGetFlag (ParamPackage
, L
"-l")) {
1198 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_LACK_OPTION
), gShellNetwork1HiiHandle
);
1203 // To handle conflict options.
1205 if (((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-s"))) ||
1206 ((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l"))) ||
1207 ((ShellCommandLineGetFlag (ParamPackage
, L
"-s")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l")))) {
1208 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellNetwork1HiiHandle
, L
"ifconfig");
1212 Status
= EFI_INVALID_PARAMETER
;
1214 Private
= AllocateZeroPool (sizeof (IFCONFIG_PRIVATE_DATA
));
1216 if (Private
== NULL
) {
1217 Status
= EFI_OUT_OF_RESOURCES
;
1221 InitializeListHead (&Private
->IfList
);
1224 // To get interface name for the list option.
1226 if (ShellCommandLineGetFlag (ParamPackage
, L
"-l")) {
1227 Private
->OpCode
= IfConfigOpList
;
1228 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-l");
1229 if (ValueStr
!= NULL
) {
1230 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1231 ASSERT (Str
!= NULL
);
1232 Private
->IfName
= Str
;
1237 // To get interface name for the clear option.
1239 if (ShellCommandLineGetFlag (ParamPackage
, L
"-r")) {
1240 Private
->OpCode
= IfConfigOpClear
;
1241 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-r");
1242 if (ValueStr
!= NULL
) {
1243 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1244 ASSERT (Str
!= NULL
);
1245 Private
->IfName
= Str
;
1250 // To get interface name and corresponding Args for the set option.
1252 if (ShellCommandLineGetFlag (ParamPackage
, L
"-s")) {
1253 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-s");
1254 if (ValueStr
== NULL
) {
1255 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_LACK_INTERFACE
), gShellNetwork1HiiHandle
);
1260 // To split the configuration into multi-section.
1262 ArgList
= SplitStrToList (ValueStr
, L
' ');
1263 ASSERT (ArgList
!= NULL
);
1265 Private
->OpCode
= IfConfigOpSet
;
1266 Private
->IfName
= ArgList
->Arg
;
1268 Private
->VarArg
= ArgList
->Next
;
1270 if (Private
->IfName
== NULL
|| Private
->VarArg
== NULL
) {
1271 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND
), gShellNetwork1HiiHandle
);
1277 // Main process of ifconfig.
1279 Status
= IfConfig (Private
);
1283 ShellCommandLineFreeVarList (ParamPackage
);
1285 if (Private
!= NULL
) {
1286 IfConfigCleanup (Private
);