2 The implementation for ifcommand shell command.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellNetwork1CommandsLib.h"
17 #define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE)
18 #define EFI_IP4_TO_U32(EfiIpAddr) (*(IP4_ADDR*)((EfiIpAddr).Addr))
20 BOOLEAN mIp4ConfigExist
= FALSE
;
21 STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
= NULL
;
23 STATIC CONST UINTN SEC_TO_NS
= 10000000;
24 STATIC CONST CHAR16 DhcpString
[5] = L
"DHCP";
25 STATIC CONST CHAR16 StaticString
[7] = L
"STATIC";
26 STATIC CONST CHAR16 PermanentString
[10] = L
"PERMANENT";
32 CHAR16 Name
[IP4_NIC_NAME_LENGTH
];
33 BOOLEAN MediaPresentSupported
;
35 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
36 NIC_IP4_CONFIG_INFO
*ConfigInfo
;
40 EFI_IP_ADDRESS DestIp
;
41 EFI_MAC_ADDRESS DestMac
;
42 EFI_IP_ADDRESS LocalIp
;
43 EFI_MAC_ADDRESS LocalMac
;
49 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
52 {L
"-s", TypeMaxValue
},
56 STATIC LIST_ENTRY NicInfoList
;
57 STATIC BOOLEAN ArpResolved
;
58 STATIC BOOLEAN mTimeout
;
61 Count the space delimited items in a string.
63 @param[in] String A pointer to the string to count.
65 @return The number of space-delimited items.
66 @retval 0xFF an error occured.
71 IN CONST CHAR16
*String
77 if (String
== NULL
|| *String
== CHAR_NULL
) {
81 for (Walker
= String
, Count
= 0 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
; Walker
= (StrStr(Walker
, L
" ")==NULL
?NULL
:StrStr(Walker
, L
" ")+1), Count
++);
86 Find the NIC_INFO by the specified nic name.
88 @param[in] Name The pointer to the string containing the NIC name.
90 @return The pointer to the NIC_INFO if there is a NIC_INFO named by Name.
91 @retval NULL No NIC_INFO was found for Name.
95 IfconfigFindNicByName (
100 LIST_ENTRY
*NextEntry
;
104 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
105 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
106 TempString
= (CHAR16
*)Info
->Name
;
108 if (StringNoCaseCompare (&Name
, &TempString
) == 0) {
117 Tests whether a child handle is a child device of the controller.
119 @param[in] ControllerHandle A handle for a (parent) controller to test.
120 @param[in] ChildHandle A child handle to test.
121 @param[in] ProtocolGuid Supplies the protocol that the child controller
122 opens on its parent controller.
124 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
125 @retval EFI_UNSUPPORTED ChildHandle is not a child of the ControllerHandle.
130 IN CONST EFI_HANDLE ControllerHandle
,
131 IN CONST EFI_HANDLE ChildHandle
,
132 IN CONST EFI_GUID
*ProtocolGuid
136 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
140 ASSERT (ProtocolGuid
!= NULL
);
143 // Retrieve the list of agents that are consuming the specific protocol
144 // on ControllerHandle.
146 Status
= gBS
->OpenProtocolInformation (
148 (EFI_GUID
*) ProtocolGuid
,
152 if (EFI_ERROR (Status
)) {
153 return EFI_UNSUPPORTED
;
157 // Inspect if ChildHandle is one of the agents.
159 Status
= EFI_UNSUPPORTED
;
160 for (Index
= 0; Index
< EntryCount
; Index
++) {
161 if ((OpenInfoBuffer
[Index
].ControllerHandle
== ChildHandle
) &&
162 (OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
163 Status
= EFI_SUCCESS
;
168 FreePool (OpenInfoBuffer
);
173 Get the child handle of the NIC handle.
175 @param[in] Controller Routing information: GUID.
176 @param[in] ChildHandle Returned child handle.
178 @retval EFI_SUCCESS Successfully to get child handle.
182 IN EFI_HANDLE Controller
,
183 OUT EFI_HANDLE
*ChildHandle
190 EFI_DEVICE_PATH_PROTOCOL
*ChildDeviceDevicePath
;
191 VENDOR_DEVICE_PATH
*VendorDeviceNode
;
194 // Locate all EFI Hii Config Access protocols
196 Status
= gBS
->LocateHandleBuffer (
198 &gEfiHiiConfigAccessProtocolGuid
,
203 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
207 Status
= EFI_NOT_FOUND
;
209 for (Index
= 0; Index
< HandleCount
; Index
++) {
211 Status
= TestChildHandle (Controller
, Handles
[Index
], &gEfiManagedNetworkServiceBindingProtocolGuid
);
212 if (!EFI_ERROR (Status
)) {
214 // Get device path on the child handle
216 Status
= gBS
->HandleProtocol (
218 &gEfiDevicePathProtocolGuid
,
219 (VOID
**) &ChildDeviceDevicePath
222 if (!EFI_ERROR (Status
)) {
223 while (!IsDevicePathEnd (ChildDeviceDevicePath
)) {
224 ChildDeviceDevicePath
= NextDevicePathNode (ChildDeviceDevicePath
);
226 // Parse one instance
228 if (ChildDeviceDevicePath
->Type
== HARDWARE_DEVICE_PATH
&&
229 ChildDeviceDevicePath
->SubType
== HW_VENDOR_DP
) {
230 VendorDeviceNode
= (VENDOR_DEVICE_PATH
*) ChildDeviceDevicePath
;
231 if (CompareMem (&VendorDeviceNode
->Guid
, &gEfiNicIp4ConfigVariableGuid
, sizeof (EFI_GUID
)) == 0) {
233 // Found item matched gEfiNicIp4ConfigVariableGuid
235 *ChildHandle
= Handles
[Index
];
250 Append OFFSET/WIDTH/VALUE items at the beginning of string.
252 @param[in,out] String The pointer to the string to append onto.
253 @param[in] Offset Offset value.
254 @param[in] Width Width value.
255 @param[in] Block Point to data buffer.
257 @return The count of unicode character that were appended.
261 AppendOffsetWidthValue (
262 IN OUT CHAR16
*String
,
265 IN CONST UINT8
*Block
273 StrCpy (String
, L
"&OFFSET=");
274 String
+= StrLen (L
"&OFFSET=");
275 String
+= UnicodeSPrint (String
, 20, L
"%x", Offset
);
277 StrCpy (String
,L
"&WIDTH=");
278 String
+= StrLen (L
"&WIDTH=");
279 String
+= UnicodeSPrint (String
, 20, L
"%x", Width
);
282 StrCpy (String
,L
"&VALUE=");
283 String
+= StrLen (L
"&VALUE=");
284 while ((Width
--) != 0) {
285 String
+= UnicodeSPrint (String
, 20, L
"%x", Block
[Width
]);
289 return String
- OriString
;
293 Converts the unicode character of the string from uppercase to lowercase.
294 This is a internal function.
296 @param ConfigString String to be converted
301 IN CHAR16
*ConfigString
308 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
310 for (String
= ConfigString
, Lower
= FALSE
; String
!= NULL
&& *String
!= L
'\0'; String
++) {
311 if (*String
== L
'=') {
313 } else if (*String
== L
'&') {
315 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
316 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
320 return (ConfigString
);
325 Construct <ConfigHdr> using routing information GUID/NAME/PATH.
327 @param[in] Guid Routing information: GUID.
328 @param[in] Name Routing information: NAME.
329 @param[in] DriverHandle Driver handle which contains the routing information: PATH.
331 @retval NULL An error occured.
332 @return The pointer to configHdr string.
337 IN CONST EFI_GUID
*Guid
,
338 IN CONST CHAR16
*Name
,
339 IN EFI_HANDLE DriverHandle
344 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
348 UINTN DevicePathLength
;
352 // Get the device path from handle installed EFI HII Config Access protocol
354 Status
= gBS
->HandleProtocol (
356 &gEfiDevicePathProtocolGuid
,
357 (VOID
**) &DevicePath
359 if (EFI_ERROR (Status
)) {
363 DevicePathLength
= GetDevicePathSize (DevicePath
);
364 NameLength
= StrLen (Name
);
365 ConfigHdr
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathLength
* 2 + 1) * sizeof (CHAR16
));
366 if (ConfigHdr
== NULL
) {
371 StrCpy (String
, L
"GUID=");
372 String
+= StrLen (L
"GUID=");
375 // Append Guid converted to <HexCh>32
377 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
378 String
+= UnicodeSPrint (String
, 6, L
"%02x", *Buffer
++);
384 StrCpy (String
, L
"&NAME=");
385 String
+= StrLen (L
"&NAME=");
386 for (Index
= 0; Index
< NameLength
; Index
++) {
387 String
+= UnicodeSPrint (String
, 10, L
"00%x", Name
[Index
]);
393 StrCpy (String
, L
"&PATH=");
394 String
+= StrLen (L
"&PATH=");
395 for (Index
= 0, Buffer
= (UINT8
*) DevicePath
; Index
< DevicePathLength
; Index
++) {
396 String
+= UnicodeSPrint (String
, 6, L
"%02x", *Buffer
++);
399 return (HiiToLower(ConfigHdr
));
403 Get network physical device NIC information.
405 @param[in] Handle The network physical device handle.
406 @param[out] NicAddr NIC information.
408 @retval EFI_SUCCESS Get NIC information successfully.
412 IfConfigGetNicMacInfo (
413 IN EFI_HANDLE Handle
,
414 OUT NIC_ADDR
*NicAddr
418 EFI_HANDLE MnpHandle
;
419 EFI_SIMPLE_NETWORK_MODE SnpMode
;
420 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
425 Status
= NetLibCreateServiceChild (
428 &gEfiManagedNetworkServiceBindingProtocolGuid
,
431 if (EFI_ERROR (Status
)) {
435 Status
= gBS
->HandleProtocol (
437 &gEfiManagedNetworkProtocolGuid
,
440 if (EFI_ERROR (Status
)) {
444 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
445 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
449 NicAddr
->Type
= (UINT16
) SnpMode
.IfType
;
450 NicAddr
->Len
= (UINT8
) SnpMode
.HwAddressSize
;
451 CopyMem (&NicAddr
->MacAddr
, &SnpMode
.CurrentAddress
, NicAddr
->Len
);
455 NetLibDestroyServiceChild (
458 &gEfiManagedNetworkServiceBindingProtocolGuid
,
467 Get network physical device NIC information.
469 @param[in] Handle The network physical device handle.
470 @param[out] MediaPresentSupported
471 Upon successful return, TRUE is media present
472 is supported. FALSE otherwise.
473 @param[out] MediaPresent Upon successful return, TRUE is media present
474 is enabled. FALSE otherwise.
476 @retval EFI_SUCCESS The operation was successful.
480 IfConfigGetNicMediaStatus (
481 IN EFI_HANDLE Handle
,
482 OUT BOOLEAN
*MediaPresentSupported
,
483 OUT BOOLEAN
*MediaPresent
488 EFI_HANDLE MnpHandle
;
489 EFI_SIMPLE_NETWORK_MODE SnpMode
;
490 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
495 Status
= NetLibCreateServiceChild (
498 &gEfiManagedNetworkServiceBindingProtocolGuid
,
501 if (EFI_ERROR (Status
)) {
505 Status
= gBS
->HandleProtocol (
507 &gEfiManagedNetworkProtocolGuid
,
510 if (EFI_ERROR (Status
)) {
514 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
515 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
519 *MediaPresentSupported
= SnpMode
.MediaPresentSupported
;
520 *MediaPresent
= SnpMode
.MediaPresent
;
524 NetLibDestroyServiceChild (
527 &gEfiManagedNetworkServiceBindingProtocolGuid
,
536 Get all Nic's information through HII service.
538 @retval EFI_SUCCESS All the nic information is collected.
542 IfconfigGetAllNicInfoByHii (
552 CHAR16
*AccessProgress
;
553 CHAR16
*AccessResults
;
556 NIC_IP4_CONFIG_INFO
*NicConfigRequest
;
557 NIC_IP4_CONFIG_INFO
*NicConfig
;
561 EFI_HANDLE ChildHandle
;
563 AccessResults
= NULL
;
566 NicConfigRequest
= NULL
;
569 InitializeListHead (&NicInfoList
);
572 // Check if HII Config Routing protocol available.
574 Status
= gBS
->LocateProtocol (
575 &gEfiHiiConfigRoutingProtocolGuid
,
577 (VOID
**)&mHiiConfigRouting
579 if (EFI_ERROR (Status
)) {
580 return EFI_NOT_FOUND
;
584 // Locate all network device handles
586 Status
= gBS
->LocateHandleBuffer (
588 &gEfiManagedNetworkServiceBindingProtocolGuid
,
593 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
594 return EFI_NOT_FOUND
;
597 for (Index
= 0; Index
< HandleCount
; Index
++) {
598 Status
= GetChildHandle (Handles
[Index
], &ChildHandle
);
599 if (EFI_ERROR (Status
)) {
601 // If failed to get Child handle, try NIC controller handle for back-compatibility.
603 ChildHandle
= Handles
[Index
];
606 // Construct configuration request string header
608 ConfigHdr
= ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, ChildHandle
);
609 if (ConfigHdr
!= NULL
) {
610 Length
= StrLen (ConfigHdr
);
614 ConfigResp
= AllocateZeroPool ((Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
));
615 if (ConfigResp
== NULL
) {
616 Status
= EFI_OUT_OF_RESOURCES
;
619 if (ConfigHdr
!= NULL
) {
620 StrCpy (ConfigResp
, ConfigHdr
);
624 // Append OFFSET/WIDTH pair
626 String
= ConfigResp
+ Length
;
628 AppendOffsetWidthValue (String
, Offset
, NIC_ITEM_CONFIG_SIZE
, NULL
);
630 NicInfo
= AllocateZeroPool (sizeof (NIC_INFO
));
631 if (NicInfo
== NULL
) {
632 Status
= EFI_OUT_OF_RESOURCES
;
635 NicInfo
->Handle
= Handles
[Index
];
638 // Get network physical devcie MAC information
640 IfConfigGetNicMacInfo (Handles
[Index
], &NicInfo
->NicAddress
);
641 if (NicInfo
->NicAddress
.Type
== NET_IFTYPE_ETHERNET
) {
642 UnicodeSPrint (NicInfo
->Name
, IP4_NIC_NAME_LENGTH
, L
"eth%d", Index
);
644 UnicodeSPrint (NicInfo
->Name
, IP4_NIC_NAME_LENGTH
, L
"unk%d", Index
);
650 IfConfigGetNicMediaStatus (Handles
[Index
], &NicInfo
->MediaPresentSupported
, &NicInfo
->MediaPresent
);
652 NicConfigRequest
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
653 if (NicConfigRequest
== NULL
) {
654 Status
= EFI_OUT_OF_RESOURCES
;
659 // Get network parameters by HII service
661 Status
= mHiiConfigRouting
->ExtractConfig (
667 if (!EFI_ERROR (Status
)) {
668 BufferSize
= NIC_ITEM_CONFIG_SIZE
;
669 Status
= mHiiConfigRouting
->ConfigToBlock (
672 (UINT8
*) NicConfigRequest
,
676 if (!EFI_ERROR (Status
)) {
677 BufferSize
= sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * NicConfigRequest
->Ip4Info
.RouteTableSize
;
678 NicConfig
= AllocateZeroPool (BufferSize
);
679 if (NicConfig
== NULL
) {
680 Status
= EFI_OUT_OF_RESOURCES
;
683 CopyMem (NicConfig
, NicConfigRequest
, BufferSize
);
686 // If succeeds to get NIC configuration, fix up routetable pointer.
688 NicConfig
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (&NicConfig
->Ip4Info
+ 1);
689 NicInfo
->ConfigInfo
= NicConfig
;
692 NicInfo
->ConfigInfo
= NULL
;
695 FreePool (AccessResults
);
698 NicInfo
->ConfigInfo
= NULL
;
702 // Add the Nic's info to the global NicInfoList.
704 InsertTailList (&NicInfoList
, &NicInfo
->Link
);
706 FreePool (NicConfigRequest
);
707 FreePool (ConfigResp
);
708 FreePool (ConfigHdr
);
716 if (AccessResults
!= NULL
) {
717 FreePool (AccessResults
);
719 if (NicConfigRequest
!= NULL
) {
720 FreePool (NicConfigRequest
);
722 if (NicInfo
!= NULL
) {
725 if (ConfigResp
!= NULL
) {
726 FreePool (ConfigResp
);
728 if (ConfigHdr
!= NULL
) {
729 FreePool (ConfigHdr
);
738 Set the address for the specified nic by HII service.
740 @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.
741 @param[in] Config The command line arguments for the set operation.
743 @retval EFI_SUCCESS The address set operation is done.
747 IfconfigSetNicAddrByHii (
748 IN CONST NIC_INFO
*NicInfo
,
749 IN CONST NIC_IP4_CONFIG_INFO
*Config
753 SHELL_STATUS ShellStatus
;
754 NIC_IP4_CONFIG_INFO
*NicConfig
;
757 CHAR16
*AccessProgress
;
758 CHAR16
*AccessResults
;
762 EFI_HANDLE ChildHandle
;
764 AccessResults
= NULL
;
768 ShellStatus
= SHELL_SUCCESS
;
770 Status
= GetChildHandle (NicInfo
->Handle
, &ChildHandle
);
771 if (EFI_ERROR (Status
)) {
773 // If failed to get Child handle, try NIC controller handle for back-compatibility
775 ChildHandle
= NicInfo
->Handle
;
778 // Construct config request string header
780 ConfigHdr
= ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, ChildHandle
);
781 if (ConfigHdr
!= NULL
) {
782 Length
= StrLen (ConfigHdr
);
786 ConfigResp
= AllocateZeroPool ((Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
));
787 if (ConfigHdr
!= NULL
) {
788 StrCpy (ConfigResp
, ConfigHdr
);
791 NicConfig
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
792 if (NicConfig
== NULL
) {
793 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
797 if (Config
!= NULL
) {
798 CopyMem (NicConfig
, Config
, sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * Config
->Ip4Info
.RouteTableSize
);
802 // Append OFFSET/WIDTH pair
804 String
= ConfigResp
+ Length
;
806 AppendOffsetWidthValue (String
, Offset
, NIC_ITEM_CONFIG_SIZE
, NULL
);
809 // Call HII helper function to generate configuration string
811 Status
= mHiiConfigRouting
->BlockToConfig (
815 NIC_ITEM_CONFIG_SIZE
,
819 if (EFI_ERROR (Status
)) {
820 ShellStatus
= SHELL_NOT_FOUND
;
825 // Set IP setting by HII servie
827 Status
= mHiiConfigRouting
->RouteConfig (
832 if (EFI_ERROR(Status
)) {
833 ShellStatus
= SHELL_ACCESS_DENIED
;
837 SHELL_FREE_NON_NULL(AccessResults
);
838 SHELL_FREE_NON_NULL(NicConfig
);
839 SHELL_FREE_NON_NULL(ConfigResp
);
840 SHELL_FREE_NON_NULL(ConfigHdr
);
846 The callback function for the Arp address resolved event.
848 @param[in] Event The event this function is registered to.
849 @param[in] Context The context registered to the event.
853 IfconfigOnArpResolved (
858 ARP_REQUEST
*Request
;
861 Request
= (ARP_REQUEST
*) Context
;
862 ASSERT (Request
!= NULL
);
864 Request
->Duplicate
= FALSE
;
866 if (0 == CompareMem (&Request
->LocalMac
, &Request
->DestMac
, Request
->MacLen
)) {
871 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
872 gShellNetwork1HiiHandle
,
873 L
"Already Configured",
874 (UINTN
)Request
->DestIp
.v4
.Addr
[0],
875 (UINTN
)Request
->DestIp
.v4
.Addr
[1],
876 (UINTN
)Request
->DestIp
.v4
.Addr
[2],
877 (UINTN
)Request
->DestIp
.v4
.Addr
[3]
883 for (Index
= 0; Index
< Request
->MacLen
; Index
++) {
884 if (Request
->DestMac
.Addr
[Index
] != 0) {
885 Request
->Duplicate
= TRUE
;
889 if (Request
->Duplicate
) {
894 STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR
),
895 gShellNetwork1HiiHandle
,
896 (UINTN
)Request
->DestMac
.Addr
[0],
897 (UINTN
)Request
->DestMac
.Addr
[1],
898 (UINTN
)Request
->DestMac
.Addr
[2],
899 (UINTN
)Request
->DestMac
.Addr
[3],
900 (UINTN
)Request
->DestMac
.Addr
[4],
901 (UINTN
)Request
->DestMac
.Addr
[5]
910 Check whether the address to be configured conflicts with other hosts.
912 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
913 @param[in] IpAddr The IPv4 address to be configured to the Nic.
915 @return TRUE Some other host already uses the IpAddr.
916 @return FALSE The address is unused.
920 IfconfigIsIpDuplicate (
921 IN NIC_INFO
*NicInfo
,
925 EFI_ARP_PROTOCOL
*Arp
;
926 EFI_ARP_CONFIG_DATA ArpCfgData
;
927 EFI_HANDLE ArpHandle
;
933 ZeroMem (&Request
, sizeof (ARP_REQUEST
));
935 Status
= NetLibCreateServiceChild (
938 &gEfiArpServiceBindingProtocolGuid
,
942 if (EFI_ERROR (Status
)) {
946 Status
= gBS
->OpenProtocol (
948 &gEfiArpProtocolGuid
,
952 EFI_OPEN_PROTOCOL_GET_PROTOCOL
955 if (EFI_ERROR (Status
)) {
960 // Set up the Arp requests
962 EFI_IP4_TO_U32 (Request
.DestIp
.v4
) = IpAddr
;
963 EFI_IP4_TO_U32 (Request
.LocalIp
.v4
) = 0xffffffff;
964 Request
.LocalMac
= NicInfo
->NicAddress
.MacAddr
;
965 Request
.MacLen
= NicInfo
->NicAddress
.Len
;
967 Status
= gBS
->CreateEvent (
970 IfconfigOnArpResolved
,
975 if (EFI_ERROR (Status
)) {
979 ArpCfgData
.SwAddressType
= 0x0800;
980 ArpCfgData
.SwAddressLength
= 4;
981 ArpCfgData
.StationAddress
= &Request
.LocalIp
;
982 ArpCfgData
.EntryTimeOut
= 0;
983 ArpCfgData
.RetryCount
= 3;
984 ArpCfgData
.RetryTimeOut
= 0;
986 Status
= Arp
->Configure (Arp
, &ArpCfgData
);
988 if (EFI_ERROR (Status
)) {
992 Status
= Arp
->Request (
999 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_READY
)) {
1003 while (!ArpResolved
) {
1008 if (Request
.OnResolved
!= NULL
) {
1009 gBS
->CloseEvent (Request
.OnResolved
);
1012 NetLibDestroyServiceChild (
1015 &gEfiArpServiceBindingProtocolGuid
,
1019 return Request
.Duplicate
;
1023 The callback function for the timer event used to get map.
1025 @param[in] Event The event this function is registered to.
1026 @param[in] Context The context registered to the event.
1040 Create an IP child, use it to start the auto configuration, then destory it.
1042 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
1044 @retval EFI_SUCCESS The configuration is done.
1049 IN NIC_INFO
*NicInfo
1052 EFI_IP4_PROTOCOL
*Ip4
;
1053 EFI_HANDLE Ip4Handle
;
1054 EFI_HANDLE TimerToGetMap
;
1055 EFI_IP4_CONFIG_DATA Ip4ConfigData
;
1056 EFI_IP4_MODE_DATA Ip4Mode
;
1060 // Get the Ip4ServiceBinding Protocol
1064 TimerToGetMap
= NULL
;
1066 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR
), gShellNetwork1HiiHandle
);
1068 Status
= NetLibCreateServiceChild (
1071 &gEfiIp4ServiceBindingProtocolGuid
,
1075 if (EFI_ERROR (Status
)) {
1079 Status
= gBS
->OpenProtocol (
1081 &gEfiIp4ProtocolGuid
,
1085 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1088 if (EFI_ERROR (Status
)) {
1092 Ip4ConfigData
.DefaultProtocol
= EFI_IP_PROTO_ICMP
;
1093 Ip4ConfigData
.AcceptAnyProtocol
= FALSE
;
1094 Ip4ConfigData
.AcceptIcmpErrors
= FALSE
;
1095 Ip4ConfigData
.AcceptBroadcast
= FALSE
;
1096 Ip4ConfigData
.AcceptPromiscuous
= FALSE
;
1097 Ip4ConfigData
.UseDefaultAddress
= TRUE
;
1098 ZeroMem (&Ip4ConfigData
.StationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1099 ZeroMem (&Ip4ConfigData
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
1100 Ip4ConfigData
.TypeOfService
= 0;
1101 Ip4ConfigData
.TimeToLive
= 1;
1102 Ip4ConfigData
.DoNotFragment
= FALSE
;
1103 Ip4ConfigData
.RawData
= FALSE
;
1104 Ip4ConfigData
.ReceiveTimeout
= 0;
1105 Ip4ConfigData
.TransmitTimeout
= 0;
1107 Status
= Ip4
->Configure (Ip4
, &Ip4ConfigData
);
1109 if (Status
== EFI_NO_MAPPING
) {
1111 Status
= gBS
->CreateEvent (
1112 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
1119 if (EFI_ERROR (Status
)) {
1123 Status
= gBS
->SetTimer (
1126 MultU64x32 (SEC_TO_NS
, 5)
1129 if (EFI_ERROR (Status
)) {
1133 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE
), gShellNetwork1HiiHandle
);
1138 if (!EFI_ERROR (Ip4
->GetModeData (Ip4
, &Ip4Mode
, NULL
, NULL
)) &&
1139 Ip4Mode
.IsConfigured
) {
1145 Status
= Ip4
->GetModeData (Ip4
, &Ip4Mode
, NULL
, NULL
);
1147 if ((Status
== EFI_SUCCESS
) && Ip4Mode
.IsConfigured
) {
1152 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1153 gShellNetwork1HiiHandle
,
1155 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[0],
1156 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[1],
1157 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[2],
1158 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[3]
1164 if (EFI_ERROR (Status
)) {
1165 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL
), gShellNetwork1HiiHandle
);
1168 if (TimerToGetMap
!= NULL
) {
1169 gBS
->SetTimer (TimerToGetMap
, TimerCancel
, 0);
1170 gBS
->CloseEvent (TimerToGetMap
);
1173 NetLibDestroyServiceChild (
1176 &gEfiIp4ServiceBindingProtocolGuid
,
1184 Set the address for the nic specified by the params.
1186 @param[in] Argc The count of the passed in Params.
1187 @param[in] Params The command line arguments for the set operation.
1189 @retval EFI_SUCCESS The address set operation is done.
1190 @return Some error occurs.
1194 IfconfigSetNicAddr (
1196 IN CONST CHAR16
*Params
1199 NIC_IP4_CONFIG_INFO
*Config
;
1200 NIC_IP4_CONFIG_INFO
*OldConfig
;
1202 EFI_IP_ADDRESS Mask
;
1203 EFI_IP_ADDRESS Gateway
;
1206 SHELL_STATUS ShellStatus
;
1207 CONST CHAR16
*Walker
;
1209 CONST CHAR16
*DhcpTemp
;
1210 CONST CHAR16
*StaticTemp
;
1211 CONST CHAR16
*PermTemp
;
1212 UINT32 NetworkBytes1
;
1213 UINT32 NetworkBytes2
;
1218 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1219 Info
= IfconfigFindNicByName (Temp
);
1222 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND
), gShellNetwork1HiiHandle
, Temp
);
1223 return SHELL_NOT_FOUND
;
1226 Walker
+= StrLen(Temp
) + 1;
1229 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")==NULL
?0:StrStr(Walker
, L
" ")-Walker
);
1231 Config
= AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO
) + 2 * sizeof (EFI_IP4_ROUTE_TABLE
));
1232 if (Config
== NULL
) {
1233 return SHELL_OUT_OF_RESOURCES
;
1236 Config
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (Config
+ 1);
1238 OldConfig
= Info
->ConfigInfo
;
1240 ShellStatus
= SHELL_INVALID_PARAMETER
;
1242 DhcpTemp
= DhcpString
;
1243 StaticTemp
= StaticString
;
1245 if (StringNoCaseCompare(&Temp
, &DhcpTemp
) == 0) {
1247 // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP perment
1249 if ((Argc
!= 2) && (Argc
!= 3)) {
1250 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, Temp
);
1251 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1256 Walker
+= StrLen(Temp
) + 1;
1259 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1261 PermTemp
= PermanentString
;
1262 if (StringNoCaseCompare(&Temp
, &PermTemp
) != 0) {
1263 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_OP2
), gShellNetwork1HiiHandle
, Temp
, PermanentString
, L
"Nothing");
1264 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1271 if ((OldConfig
!= NULL
) && (OldConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) &&
1272 (OldConfig
->Perment
== Permanent
)) {
1274 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED
), gShellNetwork1HiiHandle
, Info
->Name
);
1275 ShellStatus
= SHELL_ALREADY_STARTED
;
1279 Config
->Source
= IP4_CONFIG_SOURCE_DHCP
;
1280 } else if (StringNoCaseCompare(&Temp
, &StaticTemp
) == 0) {
1282 // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and
1283 // eth0 static IP NETMASK GATEWAY perment
1285 if ((Argc
!= 5) && (Argc
!= 6)) {
1286 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, Temp
);
1287 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1291 Walker
+= StrLen(Temp
) + 1;
1294 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1296 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Ip
.v4
))) {
1297 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1298 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1302 Walker
+= StrLen(Temp
) + 1;
1305 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1306 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Mask
.v4
))) {
1307 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1308 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1312 Walker
+= StrLen(Temp
) + 1;
1316 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1318 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1320 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Gateway
.v4
))) {
1321 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1322 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1327 Walker
+= StrLen(Temp
) + 1;
1330 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1332 PermTemp
= PermanentString
;
1333 if (StringNoCaseCompare(&Temp
, &PermTemp
) != 0) {
1334 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_OP2
), gShellNetwork1HiiHandle
, Temp
, PermanentString
, L
"Nothing");
1335 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1342 NetworkBytes1
= NTOHL (Ip
.Addr
[0]);
1343 NetworkBytes2
= NTOHL (Mask
.Addr
[0]);
1344 if ((Ip
.Addr
[0] == 0) || (Mask
.Addr
[0] == 0) ||
1345 !NetIp4IsUnicast (NetworkBytes1
, NetworkBytes2
)) {
1347 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR
), gShellNetwork1HiiHandle
);
1348 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1352 NetworkBytes1
= NTOHL (Gateway
.Addr
[0]);
1353 if (!IP4_NET_EQUAL (Ip
.Addr
[0], Gateway
.Addr
[0], Mask
.Addr
[0]) ||
1354 !NetIp4IsUnicast (NetworkBytes1
, NetworkBytes2
)) {
1356 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY
), gShellNetwork1HiiHandle
);
1357 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1362 // Set the configuration up, two route table entries are added:
1363 // one for the direct connected network, and another for the
1364 // default gateway. Remember, some structure members are cleared
1365 // by AllocateZeroPool
1367 Config
->Source
= IP4_CONFIG_SOURCE_STATIC
;
1368 Config
->Ip4Info
.RouteTableSize
= 2;
1370 CopyMem (&Config
->Ip4Info
.StationAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1371 CopyMem (&Config
->Ip4Info
.SubnetMask
, &Mask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1373 Ip
.Addr
[0] = Ip
.Addr
[0] & Mask
.Addr
[0];
1375 CopyMem (&Config
->Ip4Info
.RouteTable
[0].SubnetAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1376 CopyMem (&Config
->Ip4Info
.RouteTable
[0].SubnetMask
, &Mask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1377 CopyMem (&Config
->Ip4Info
.RouteTable
[1].GatewayAddress
, &Gateway
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1379 // neither static or DHCP. error.
1380 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_TOO_FEW
), gShellNetwork1HiiHandle
);
1381 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1385 CopyMem (&Config
->NicAddr
, &Info
->NicAddress
, sizeof (NIC_ADDR
));
1386 Config
->Perment
= Permanent
;
1389 // Use HII service to set NIC address
1391 ShellStatus
= IfconfigSetNicAddrByHii (Info
, Config
);
1392 if (ShellStatus
!= SHELL_SUCCESS
) {
1393 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_SET_FAIL
), gShellNetwork1HiiHandle
, ShellStatus
^MAX_BIT
);
1397 Status
= IfconfigStartIp4 (Info
);
1398 if (EFI_ERROR(Status
)) {
1399 ShellStatus
= SHELL_ACCESS_DENIED
;
1402 if (ShellStatus
!= SHELL_SUCCESS
) {
1403 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL
), gShellNetwork1HiiHandle
, ShellStatus
^MAX_BIT
);
1407 SHELL_FREE_NON_NULL(Config
);
1413 Show the address information for the nic specified.
1415 @param[in] Name A pointer to the string containg the nic's name, if NULL,
1416 all nics' information is shown.
1420 IfconfigShowNicInfo (
1421 IN CONST CHAR16
*Name
1425 LIST_ENTRY
*NextEntry
;
1428 EFI_IP4_IPCONFIG_DATA
*Ip4Config
;
1429 EFI_IPv4_ADDRESS Gateway
;
1430 CONST CHAR16
*TempString
;
1432 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
1433 NicInfo
= BASE_CR (Entry
, NIC_INFO
, Link
);
1435 TempString
= (CHAR16
*)NicInfo
->Name
;
1436 if ((Name
!= NULL
) && (StringNoCaseCompare (&Name
, &TempString
) != 0)) {
1440 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_NIC_NAME
), gShellNetwork1HiiHandle
, NicInfo
->Name
);
1446 STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR
),
1447 gShellNetwork1HiiHandle
,
1448 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[0],
1449 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[1],
1450 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[2],
1451 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[3],
1452 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[4],
1453 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[5]
1456 Print (L
" Media State: %s\n", NicInfo
->MediaPresent
? L
"Media present" : L
"Media disconnected");
1458 if (NicInfo
->ConfigInfo
== NULL
) {
1459 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED
), gShellNetwork1HiiHandle
);
1463 if (NicInfo
->ConfigInfo
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
1464 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"DHCP");
1465 } else if (NicInfo
->ConfigInfo
->Source
== IP4_CONFIG_SOURCE_STATIC
) {
1466 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"STATIC");
1468 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"Unknown");
1471 ShellPrintHiiEx(-1, -1, NULL
,
1472 STRING_TOKEN (STR_IFCONFIG_PERMENT_STATUS
),
1473 gShellNetwork1HiiHandle
,
1474 (NicInfo
->ConfigInfo
->Perment
? L
"TRUE":L
"FALSE")
1477 Ip4Config
= &NicInfo
->ConfigInfo
->Ip4Info
;
1483 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1484 gShellNetwork1HiiHandle
,
1486 (UINTN
)Ip4Config
->StationAddress
.Addr
[0],
1487 (UINTN
)Ip4Config
->StationAddress
.Addr
[1],
1488 (UINTN
)Ip4Config
->StationAddress
.Addr
[2],
1489 (UINTN
)Ip4Config
->StationAddress
.Addr
[3]
1495 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1496 gShellNetwork1HiiHandle
,
1498 (UINTN
)Ip4Config
->SubnetMask
.Addr
[0],
1499 (UINTN
)Ip4Config
->SubnetMask
.Addr
[1],
1500 (UINTN
)Ip4Config
->SubnetMask
.Addr
[2],
1501 (UINTN
)Ip4Config
->SubnetMask
.Addr
[3]
1504 ZeroMem (&Gateway
, sizeof (EFI_IPv4_ADDRESS
));
1506 for (Index
= 0; Index
< Ip4Config
->RouteTableSize
; Index
++) {
1507 if ((CompareMem (&Ip4Config
->RouteTable
[Index
].SubnetAddress
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) &&
1508 (CompareMem (&Ip4Config
->RouteTable
[Index
].SubnetMask
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) ){
1509 CopyMem (&Gateway
, &Ip4Config
->RouteTable
[Index
].GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
1517 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1518 gShellNetwork1HiiHandle
,
1520 (UINTN
)Gateway
.Addr
[0],
1521 (UINTN
)Gateway
.Addr
[1],
1522 (UINTN
)Gateway
.Addr
[2],
1523 (UINTN
)Gateway
.Addr
[3]
1526 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE
), gShellNetwork1HiiHandle
, Ip4Config
->RouteTableSize
);
1528 for (Index
= 0; Index
< Ip4Config
->RouteTableSize
; Index
++) {
1529 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX
), gShellNetwork1HiiHandle
, Index
);
1535 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1536 gShellNetwork1HiiHandle
,
1538 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[0],
1539 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[1],
1540 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[2],
1541 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[3]
1548 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1549 gShellNetwork1HiiHandle
,
1551 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[0],
1552 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[1],
1553 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[2],
1554 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[3]
1561 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1562 gShellNetwork1HiiHandle
,
1564 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[0],
1565 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[1],
1566 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[2],
1567 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[3]
1576 Clear address configuration for the nic specified.
1578 @param[in] Name A pointer to the string containg the nic's name,
1579 if NULL, all nics address configurations are cleared.
1581 @retval EFI_SUCCESS The address configuration is cleared.
1582 @return Some error occurs.
1586 IfconfigClearNicAddr (
1587 IN CONST CHAR16
*Name
1591 LIST_ENTRY
*NextEntry
;
1595 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
1596 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
1598 if ((Name
!= NULL
) && (StrCmp (Name
, Info
->Name
) != 0)) {
1602 // if (Info->NicIp4Config == NULL) {
1603 Status
= IfconfigSetNicAddrByHii (Info
, NULL
);
1605 // Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);
1608 if (EFI_ERROR (Status
)) {
1618 Function for 'ifconfig' command.
1620 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1621 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1625 ShellCommandRunIfconfig (
1626 IN EFI_HANDLE ImageHandle
,
1627 IN EFI_SYSTEM_TABLE
*SystemTable
1631 LIST_ENTRY
*Package
;
1632 CHAR16
*ProblemParam
;
1633 SHELL_STATUS ShellStatus
;
1634 BOOLEAN ListOperation
;
1635 BOOLEAN ClearOperation
;
1636 BOOLEAN SetOperation
;
1641 InitializeListHead (&NicInfoList
);
1642 Status
= EFI_INVALID_PARAMETER
;
1643 ShellStatus
= SHELL_SUCCESS
;
1646 // initialize the shell lib (we must be in non-auto-init...)
1648 Status
= ShellInitialize();
1649 ASSERT_EFI_ERROR(Status
);
1652 // parse the command line
1654 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1655 if (EFI_ERROR(Status
)) {
1656 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1657 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellNetwork1HiiHandle
, ProblemParam
);
1658 FreePool(ProblemParam
);
1659 ShellStatus
= SHELL_INVALID_PARAMETER
;
1667 ClearOperation
= ShellCommandLineGetFlag(Package
, L
"-c");
1668 ListOperation
= ShellCommandLineGetFlag(Package
, L
"-l");
1669 SetOperation
= ShellCommandLineGetFlag(Package
, L
"-s");
1671 if ((ClearOperation
&& ListOperation
)
1672 ||(SetOperation
&& ListOperation
)
1673 ||(ClearOperation
&& SetOperation
)
1675 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellNetwork1HiiHandle
);
1676 ShellStatus
= SHELL_INVALID_PARAMETER
;
1678 } else if (!ClearOperation
&& !ListOperation
&& !SetOperation
) {
1679 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellNetwork1HiiHandle
);
1680 ShellStatus
= SHELL_INVALID_PARAMETER
;
1685 Status
= IfconfigGetAllNicInfoByHii ();
1686 if (EFI_ERROR (Status
)) {
1687 if (mIp4ConfigExist
) {
1688 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL
), gShellNetwork1HiiHandle
, Status
);
1690 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROTOCOL_NF
), gShellNetwork1HiiHandle
, L
"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid
);
1693 return SHELL_NOT_FOUND
;
1696 if (ListOperation
) {
1697 Item
= ShellCommandLineGetValue (Package
, L
"-l");
1699 if (Item
!= NULL
&& CountSubItems(Item
) > 1) {
1700 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"-l");
1701 ShellStatus
= SHELL_INVALID_PARAMETER
;
1706 // Show the configuration.
1708 IfconfigShowNicInfo (Item
);
1709 } else if (SetOperation
) {
1710 Item
= ShellCommandLineGetValue (Package
, L
"-s");
1713 // The correct command line arguments for setting address are:
1714 // IfConfig -s eth0 DHCP [perment]
1715 // IfConfig -s eth0 static ip netmask gateway [perment]
1717 if (Item
== NULL
|| (CountSubItems(Item
) < 2) || (CountSubItems(Item
) > 6) || (CountSubItems(Item
) == 4)) {
1718 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"-s");
1719 ShellStatus
= SHELL_INVALID_PARAMETER
;
1723 ShellStatus
= IfconfigSetNicAddr (CountSubItems(Item
), Item
);
1724 } else if (ClearOperation
) {
1725 Item
= ShellCommandLineGetValue (Package
, L
"-c");
1727 if (Item
!= NULL
&& CountSubItems(Item
) > 1) {
1728 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"-c");
1729 ShellStatus
= SHELL_INVALID_PARAMETER
;
1733 IfconfigClearNicAddr (Item
);
1739 while (!IsListEmpty (&NicInfoList
)) {
1740 Entry
= NicInfoList
.ForwardLink
;
1741 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
1743 RemoveEntryList (Entry
);
1745 if (Info
->ConfigInfo
!= NULL
) {
1746 FreePool (Info
->ConfigInfo
);
1752 if (Package
!= NULL
) {
1753 ShellCommandLineFreeVarList(Package
);
1756 return (ShellStatus
);