2 The implementation for ifcommand shell command.
4 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2006 - 2012, 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.
16 #include "UefiShellNetwork1CommandsLib.h"
18 #define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE)
19 #define EFI_IP4_TO_U32(EfiIpAddr) (*(IP4_ADDR*)((EfiIpAddr).Addr))
21 BOOLEAN mIp4ConfigExist
= FALSE
;
22 STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
= NULL
;
24 STATIC CONST UINTN SecondsToNanoSeconds
= 10000000;
25 STATIC CONST CHAR16 DhcpString
[5] = L
"DHCP";
26 STATIC CONST CHAR16 StaticString
[7] = L
"STATIC";
27 STATIC CONST CHAR16 PermanentString
[10] = L
"PERMANENT";
33 CHAR16 Name
[IP4_NIC_NAME_LENGTH
];
34 BOOLEAN MediaPresentSupported
;
36 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
37 NIC_IP4_CONFIG_INFO
*ConfigInfo
;
41 EFI_IP_ADDRESS DestIp
;
42 EFI_MAC_ADDRESS DestMac
;
43 EFI_IP_ADDRESS LocalIp
;
44 EFI_MAC_ADDRESS LocalMac
;
50 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
53 {L
"-s", TypeMaxValue
},
57 STATIC LIST_ENTRY NicInfoList
;
58 STATIC BOOLEAN ArpResolved
;
59 STATIC BOOLEAN mTimeout
;
62 Count the space delimited items in a string.
64 @param[in] String A pointer to the string to count.
66 @return The number of space-delimited items.
67 @retval 0xFF an error occured.
72 IN CONST CHAR16
*String
78 if (String
== NULL
|| *String
== CHAR_NULL
) {
82 for (Walker
= String
, Count
= 0 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
; Walker
= (StrStr(Walker
, L
" ")==NULL
?NULL
:StrStr(Walker
, L
" ")+1), Count
++);
87 Find the NIC_INFO by the specified nic name.
89 @param[in] Name The pointer to the string containing the NIC name.
91 @return The pointer to the NIC_INFO if there is a NIC_INFO named by Name.
92 @retval NULL No NIC_INFO was found for Name.
96 IfconfigFindNicByName (
101 LIST_ENTRY
*NextEntry
;
105 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
106 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
107 TempString
= (CHAR16
*)Info
->Name
;
109 if (StringNoCaseCompare (&Name
, &TempString
) == 0) {
118 Tests whether a child handle is a child device of the controller.
120 @param[in] ControllerHandle A handle for a (parent) controller to test.
121 @param[in] ChildHandle A child handle to test.
122 @param[in] ProtocolGuid Supplies the protocol that the child controller
123 opens on its parent controller.
125 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
126 @retval EFI_UNSUPPORTED ChildHandle is not a child of the ControllerHandle.
131 IN CONST EFI_HANDLE ControllerHandle
,
132 IN CONST EFI_HANDLE ChildHandle
,
133 IN CONST EFI_GUID
*ProtocolGuid
137 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
141 ASSERT (ProtocolGuid
!= NULL
);
144 // Retrieve the list of agents that are consuming the specific protocol
145 // on ControllerHandle.
147 Status
= gBS
->OpenProtocolInformation (
149 (EFI_GUID
*) ProtocolGuid
,
153 if (EFI_ERROR (Status
)) {
154 return EFI_UNSUPPORTED
;
158 // Inspect if ChildHandle is one of the agents.
160 Status
= EFI_UNSUPPORTED
;
161 for (Index
= 0; Index
< EntryCount
; Index
++) {
162 if ((OpenInfoBuffer
[Index
].ControllerHandle
== ChildHandle
) &&
163 (OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
164 Status
= EFI_SUCCESS
;
169 FreePool (OpenInfoBuffer
);
174 Get the child handle of the NIC handle.
176 @param[in] Controller Routing information: GUID.
177 @param[out] ChildHandle Returned child handle.
179 @retval EFI_SUCCESS Successfully to get child handle.
183 IN EFI_HANDLE Controller
,
184 OUT EFI_HANDLE
*ChildHandle
191 EFI_DEVICE_PATH_PROTOCOL
*ChildDeviceDevicePath
;
192 VENDOR_DEVICE_PATH
*VendorDeviceNode
;
195 // Locate all EFI Hii Config Access protocols
197 Status
= gBS
->LocateHandleBuffer (
199 &gEfiHiiConfigAccessProtocolGuid
,
204 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
208 Status
= EFI_NOT_FOUND
;
210 for (Index
= 0; Index
< HandleCount
; Index
++) {
212 Status
= TestChildHandle (Controller
, Handles
[Index
], &gEfiManagedNetworkServiceBindingProtocolGuid
);
213 if (!EFI_ERROR (Status
)) {
215 // Get device path on the child handle
217 Status
= gBS
->HandleProtocol (
219 &gEfiDevicePathProtocolGuid
,
220 (VOID
**) &ChildDeviceDevicePath
223 if (!EFI_ERROR (Status
)) {
224 while (!IsDevicePathEnd (ChildDeviceDevicePath
)) {
225 ChildDeviceDevicePath
= NextDevicePathNode (ChildDeviceDevicePath
);
227 // Parse one instance
229 if (ChildDeviceDevicePath
->Type
== HARDWARE_DEVICE_PATH
&&
230 ChildDeviceDevicePath
->SubType
== HW_VENDOR_DP
) {
231 VendorDeviceNode
= (VENDOR_DEVICE_PATH
*) ChildDeviceDevicePath
;
232 if (CompareMem (&VendorDeviceNode
->Guid
, &gEfiNicIp4ConfigVariableGuid
, sizeof (EFI_GUID
)) == 0) {
234 // Found item matched gEfiNicIp4ConfigVariableGuid
236 *ChildHandle
= Handles
[Index
];
251 Append OFFSET/WIDTH/VALUE items at the beginning of string.
253 @param[in, out] String The pointer to the string to append onto.
254 @param[in] Offset Offset value.
255 @param[in] Width Width value.
256 @param[in] Block Point to data buffer.
258 @return The count of unicode character that were appended.
262 AppendOffsetWidthValue (
263 IN OUT CHAR16
*String
,
266 IN CONST UINT8
*Block
274 StrCpy (String
, L
"&OFFSET=");
275 String
+= StrLen (L
"&OFFSET=");
276 String
+= UnicodeSPrint (String
, 20, L
"%x", Offset
);
278 StrCpy (String
,L
"&WIDTH=");
279 String
+= StrLen (L
"&WIDTH=");
280 String
+= UnicodeSPrint (String
, 20, L
"%x", Width
);
283 StrCpy (String
,L
"&VALUE=");
284 String
+= StrLen (L
"&VALUE=");
285 while ((Width
--) != 0) {
286 String
+= UnicodeSPrint (String
, 20, L
"%x", Block
[Width
]);
290 return String
- OriString
;
294 Converts the unicode character of the string from uppercase to lowercase.
295 This is a internal function.
297 @param ConfigString String to be converted
302 IN CHAR16
*ConfigString
309 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
311 for (String
= ConfigString
, Lower
= FALSE
; String
!= NULL
&& *String
!= L
'\0'; String
++) {
312 if (*String
== L
'=') {
314 } else if (*String
== L
'&') {
316 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
317 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
321 return (ConfigString
);
326 Construct <ConfigHdr> using routing information GUID/NAME/PATH.
328 @param[in] Guid Routing information: GUID.
329 @param[in] Name Routing information: NAME.
330 @param[in] DriverHandle Driver handle which contains the routing information: PATH.
332 @retval NULL An error occured.
333 @return The pointer to configHdr string.
338 IN CONST EFI_GUID
*Guid
,
339 IN CONST CHAR16
*Name
,
340 IN EFI_HANDLE DriverHandle
345 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
349 UINTN DevicePathLength
;
353 // Get the device path from handle installed EFI HII Config Access protocol
355 Status
= gBS
->HandleProtocol (
357 &gEfiDevicePathProtocolGuid
,
358 (VOID
**) &DevicePath
360 if (EFI_ERROR (Status
)) {
364 DevicePathLength
= GetDevicePathSize (DevicePath
);
365 NameLength
= StrLen (Name
);
366 ConfigHdr
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathLength
* 2 + 1) * sizeof (CHAR16
));
367 if (ConfigHdr
== NULL
) {
372 StrCpy (String
, L
"GUID=");
373 String
+= StrLen (L
"GUID=");
376 // Append Guid converted to <HexCh>32
378 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
379 String
+= UnicodeSPrint (String
, 6, L
"%02x", *Buffer
++);
385 StrCpy (String
, L
"&NAME=");
386 String
+= StrLen (L
"&NAME=");
387 for (Index
= 0; Index
< NameLength
; Index
++) {
388 String
+= UnicodeSPrint (String
, 10, L
"00%x", Name
[Index
]);
394 StrCpy (String
, L
"&PATH=");
395 String
+= StrLen (L
"&PATH=");
396 for (Index
= 0, Buffer
= (UINT8
*) DevicePath
; Index
< DevicePathLength
; Index
++) {
397 String
+= UnicodeSPrint (String
, 6, L
"%02x", *Buffer
++);
400 return (HiiToLower(ConfigHdr
));
404 Get network physical device NIC information.
406 @param[in] Handle The network physical device handle.
407 @param[out] NicAddr NIC information.
409 @retval EFI_SUCCESS Get NIC information successfully.
413 IfConfigGetNicMacInfo (
414 IN EFI_HANDLE Handle
,
415 OUT NIC_ADDR
*NicAddr
419 EFI_HANDLE MnpHandle
;
420 EFI_SIMPLE_NETWORK_MODE SnpMode
;
421 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
426 Status
= NetLibCreateServiceChild (
429 &gEfiManagedNetworkServiceBindingProtocolGuid
,
432 if (EFI_ERROR (Status
)) {
436 Status
= gBS
->HandleProtocol (
438 &gEfiManagedNetworkProtocolGuid
,
441 if (EFI_ERROR (Status
)) {
445 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
446 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
450 NicAddr
->Type
= (UINT16
) SnpMode
.IfType
;
451 NicAddr
->Len
= (UINT8
) SnpMode
.HwAddressSize
;
452 CopyMem (&NicAddr
->MacAddr
, &SnpMode
.CurrentAddress
, NicAddr
->Len
);
456 NetLibDestroyServiceChild (
459 &gEfiManagedNetworkServiceBindingProtocolGuid
,
468 Get network physical device NIC information.
470 @param[in] Handle The network physical device handle.
471 @param[out] MediaPresentSupported
472 Upon successful return, TRUE is media present
473 is supported. FALSE otherwise.
474 @param[out] MediaPresent Upon successful return, TRUE is media present
475 is enabled. FALSE otherwise.
477 @retval EFI_SUCCESS The operation was successful.
481 IfConfigGetNicMediaStatus (
482 IN EFI_HANDLE Handle
,
483 OUT BOOLEAN
*MediaPresentSupported
,
484 OUT BOOLEAN
*MediaPresent
489 EFI_HANDLE MnpHandle
;
490 EFI_SIMPLE_NETWORK_MODE SnpMode
;
491 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
496 Status
= NetLibCreateServiceChild (
499 &gEfiManagedNetworkServiceBindingProtocolGuid
,
502 if (EFI_ERROR (Status
)) {
506 Status
= gBS
->HandleProtocol (
508 &gEfiManagedNetworkProtocolGuid
,
511 if (EFI_ERROR (Status
)) {
515 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
516 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
520 *MediaPresentSupported
= SnpMode
.MediaPresentSupported
;
521 *MediaPresent
= SnpMode
.MediaPresent
;
525 NetLibDestroyServiceChild (
528 &gEfiManagedNetworkServiceBindingProtocolGuid
,
537 Get all Nic's information through HII service.
539 @retval EFI_SUCCESS All the nic information is collected.
543 IfconfigGetAllNicInfoByHii (
553 CHAR16
*AccessProgress
;
554 CHAR16
*AccessResults
;
557 NIC_IP4_CONFIG_INFO
*NicConfigRequest
;
558 NIC_IP4_CONFIG_INFO
*NicConfig
;
562 EFI_HANDLE ChildHandle
;
564 AccessResults
= NULL
;
567 NicConfigRequest
= NULL
;
570 InitializeListHead (&NicInfoList
);
573 // Check if HII Config Routing protocol available.
575 Status
= gBS
->LocateProtocol (
576 &gEfiHiiConfigRoutingProtocolGuid
,
578 (VOID
**)&mHiiConfigRouting
580 if (EFI_ERROR (Status
)) {
581 return EFI_NOT_FOUND
;
585 // Locate all network device handles
587 Status
= gBS
->LocateHandleBuffer (
589 &gEfiManagedNetworkServiceBindingProtocolGuid
,
594 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
595 return EFI_NOT_FOUND
;
598 for (Index
= 0; Index
< HandleCount
; Index
++) {
599 Status
= GetChildHandle (Handles
[Index
], &ChildHandle
);
600 if (EFI_ERROR (Status
)) {
602 // If failed to get Child handle, try NIC controller handle for back-compatibility.
604 ChildHandle
= Handles
[Index
];
607 // Construct configuration request string header
609 ConfigHdr
= ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, ChildHandle
);
610 if (ConfigHdr
!= NULL
) {
611 Length
= StrLen (ConfigHdr
);
615 ConfigResp
= AllocateZeroPool ((Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
));
616 if (ConfigResp
== NULL
) {
617 Status
= EFI_OUT_OF_RESOURCES
;
620 if (ConfigHdr
!= NULL
) {
621 StrCpy (ConfigResp
, ConfigHdr
);
625 // Append OFFSET/WIDTH pair
627 String
= ConfigResp
+ Length
;
629 AppendOffsetWidthValue (String
, Offset
, NIC_ITEM_CONFIG_SIZE
, NULL
);
631 NicInfo
= AllocateZeroPool (sizeof (NIC_INFO
));
632 if (NicInfo
== NULL
) {
633 Status
= EFI_OUT_OF_RESOURCES
;
636 NicInfo
->Handle
= Handles
[Index
];
639 // Get network physical devcie MAC information
641 IfConfigGetNicMacInfo (Handles
[Index
], &NicInfo
->NicAddress
);
642 if (NicInfo
->NicAddress
.Type
== NET_IFTYPE_ETHERNET
) {
643 UnicodeSPrint (NicInfo
->Name
, IP4_NIC_NAME_LENGTH
, L
"eth%d", Index
);
645 UnicodeSPrint (NicInfo
->Name
, IP4_NIC_NAME_LENGTH
, L
"unk%d", Index
);
651 IfConfigGetNicMediaStatus (Handles
[Index
], &NicInfo
->MediaPresentSupported
, &NicInfo
->MediaPresent
);
653 NicConfigRequest
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
654 if (NicConfigRequest
== NULL
) {
655 Status
= EFI_OUT_OF_RESOURCES
;
660 // Get network parameters by HII service
662 Status
= mHiiConfigRouting
->ExtractConfig (
668 if (!EFI_ERROR (Status
)) {
669 BufferSize
= NIC_ITEM_CONFIG_SIZE
;
670 Status
= mHiiConfigRouting
->ConfigToBlock (
673 (UINT8
*) NicConfigRequest
,
677 if (!EFI_ERROR (Status
)) {
678 BufferSize
= sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * NicConfigRequest
->Ip4Info
.RouteTableSize
;
679 NicConfig
= AllocateZeroPool (BufferSize
);
680 if (NicConfig
== NULL
) {
681 Status
= EFI_OUT_OF_RESOURCES
;
684 CopyMem (NicConfig
, NicConfigRequest
, BufferSize
);
687 // If succeeds to get NIC configuration, fix up routetable pointer.
689 NicConfig
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (&NicConfig
->Ip4Info
+ 1);
690 NicInfo
->ConfigInfo
= NicConfig
;
693 NicInfo
->ConfigInfo
= NULL
;
696 FreePool (AccessResults
);
699 NicInfo
->ConfigInfo
= NULL
;
703 // Add the Nic's info to the global NicInfoList.
705 InsertTailList (&NicInfoList
, &NicInfo
->Link
);
707 FreePool (NicConfigRequest
);
708 FreePool (ConfigResp
);
709 FreePool (ConfigHdr
);
717 if (AccessResults
!= NULL
) {
718 FreePool (AccessResults
);
720 if (NicConfigRequest
!= NULL
) {
721 FreePool (NicConfigRequest
);
723 if (NicInfo
!= NULL
) {
726 if (ConfigResp
!= NULL
) {
727 FreePool (ConfigResp
);
729 if (ConfigHdr
!= NULL
) {
730 FreePool (ConfigHdr
);
739 Set the address for the specified nic by HII service.
741 @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.
742 @param[in] Config The command line arguments for the set operation.
744 @retval EFI_SUCCESS The address set operation is done.
748 IfconfigSetNicAddrByHii (
749 IN CONST NIC_INFO
*NicInfo
,
750 IN CONST NIC_IP4_CONFIG_INFO
*Config
754 SHELL_STATUS ShellStatus
;
755 NIC_IP4_CONFIG_INFO
*NicConfig
;
758 CHAR16
*AccessProgress
;
759 CHAR16
*AccessResults
;
763 EFI_HANDLE ChildHandle
;
765 AccessResults
= NULL
;
769 ShellStatus
= SHELL_SUCCESS
;
771 Status
= GetChildHandle (NicInfo
->Handle
, &ChildHandle
);
772 if (EFI_ERROR (Status
)) {
774 // If failed to get Child handle, try NIC controller handle for back-compatibility
776 ChildHandle
= NicInfo
->Handle
;
779 // Construct config request string header
781 ConfigHdr
= ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, ChildHandle
);
782 if (ConfigHdr
!= NULL
) {
783 Length
= StrLen (ConfigHdr
);
785 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
788 ConfigResp
= AllocateZeroPool ((Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
));
789 if (ConfigResp
== NULL
) {
790 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
793 if (ConfigHdr
!= NULL
) {
794 StrCpy (ConfigResp
, ConfigHdr
);
797 NicConfig
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
798 if (NicConfig
== NULL
) {
799 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
803 if (Config
!= NULL
) {
804 CopyMem (NicConfig
, Config
, sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * Config
->Ip4Info
.RouteTableSize
);
808 // Append OFFSET/WIDTH pair
810 String
= ConfigResp
+ Length
;
812 AppendOffsetWidthValue (String
, Offset
, NIC_ITEM_CONFIG_SIZE
, NULL
);
815 // Call HII helper function to generate configuration string
817 Status
= mHiiConfigRouting
->BlockToConfig (
821 NIC_ITEM_CONFIG_SIZE
,
825 if (EFI_ERROR (Status
)) {
826 ShellStatus
= SHELL_NOT_FOUND
;
831 // Set IP setting by HII servie
833 Status
= mHiiConfigRouting
->RouteConfig (
838 if (EFI_ERROR(Status
)) {
839 ShellStatus
= SHELL_ACCESS_DENIED
;
843 SHELL_FREE_NON_NULL(AccessResults
);
844 SHELL_FREE_NON_NULL(NicConfig
);
845 SHELL_FREE_NON_NULL(ConfigResp
);
846 SHELL_FREE_NON_NULL(ConfigHdr
);
852 The callback function for the Arp address resolved event.
854 @param[in] Event The event this function is registered to.
855 @param[in] Context The context registered to the event.
859 IfconfigOnArpResolved (
864 ARP_REQUEST
*Request
;
867 Request
= (ARP_REQUEST
*) Context
;
868 ASSERT (Request
!= NULL
);
870 Request
->Duplicate
= FALSE
;
872 if (0 == CompareMem (&Request
->LocalMac
, &Request
->DestMac
, Request
->MacLen
)) {
877 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
878 gShellNetwork1HiiHandle
,
879 L
"Already Configured",
880 (UINTN
)Request
->DestIp
.v4
.Addr
[0],
881 (UINTN
)Request
->DestIp
.v4
.Addr
[1],
882 (UINTN
)Request
->DestIp
.v4
.Addr
[2],
883 (UINTN
)Request
->DestIp
.v4
.Addr
[3]
889 for (Index
= 0; Index
< Request
->MacLen
; Index
++) {
890 if (Request
->DestMac
.Addr
[Index
] != 0) {
891 Request
->Duplicate
= TRUE
;
895 if (Request
->Duplicate
) {
900 STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR
),
901 gShellNetwork1HiiHandle
,
902 (UINTN
)Request
->DestMac
.Addr
[0],
903 (UINTN
)Request
->DestMac
.Addr
[1],
904 (UINTN
)Request
->DestMac
.Addr
[2],
905 (UINTN
)Request
->DestMac
.Addr
[3],
906 (UINTN
)Request
->DestMac
.Addr
[4],
907 (UINTN
)Request
->DestMac
.Addr
[5]
916 Check whether the address to be configured conflicts with other hosts.
918 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
919 @param[in] IpAddr The IPv4 address to be configured to the Nic.
921 @return TRUE Some other host already uses the IpAddr.
922 @return FALSE The address is unused.
926 IfconfigIsIpDuplicate (
927 IN NIC_INFO
*NicInfo
,
931 EFI_ARP_PROTOCOL
*Arp
;
932 EFI_ARP_CONFIG_DATA ArpCfgData
;
933 EFI_HANDLE ArpHandle
;
939 ZeroMem (&Request
, sizeof (ARP_REQUEST
));
941 Status
= NetLibCreateServiceChild (
944 &gEfiArpServiceBindingProtocolGuid
,
948 if (EFI_ERROR (Status
)) {
952 Status
= gBS
->OpenProtocol (
954 &gEfiArpProtocolGuid
,
958 EFI_OPEN_PROTOCOL_GET_PROTOCOL
961 if (EFI_ERROR (Status
)) {
966 // Set up the Arp requests
968 EFI_IP4_TO_U32 (Request
.DestIp
.v4
) = IpAddr
;
969 EFI_IP4_TO_U32 (Request
.LocalIp
.v4
) = 0xffffffff;
970 Request
.LocalMac
= NicInfo
->NicAddress
.MacAddr
;
971 Request
.MacLen
= NicInfo
->NicAddress
.Len
;
973 Status
= gBS
->CreateEvent (
976 IfconfigOnArpResolved
,
981 if (EFI_ERROR (Status
)) {
985 ArpCfgData
.SwAddressType
= 0x0800;
986 ArpCfgData
.SwAddressLength
= 4;
987 ArpCfgData
.StationAddress
= &Request
.LocalIp
;
988 ArpCfgData
.EntryTimeOut
= 0;
989 ArpCfgData
.RetryCount
= 3;
990 ArpCfgData
.RetryTimeOut
= 0;
992 Status
= Arp
->Configure (Arp
, &ArpCfgData
);
994 if (EFI_ERROR (Status
)) {
998 Status
= Arp
->Request (
1005 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_READY
)) {
1009 while (!ArpResolved
) {
1014 if (Request
.OnResolved
!= NULL
) {
1015 gBS
->CloseEvent (Request
.OnResolved
);
1018 NetLibDestroyServiceChild (
1021 &gEfiArpServiceBindingProtocolGuid
,
1025 return Request
.Duplicate
;
1029 The callback function for the timer event used to get map.
1031 @param[in] Event The event this function is registered to.
1032 @param[in] Context The context registered to the event.
1046 Create an IP child, use it to start the auto configuration, then destroy it.
1048 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
1050 @retval EFI_SUCCESS The configuration is done.
1055 IN NIC_INFO
*NicInfo
1058 EFI_IP4_PROTOCOL
*Ip4
;
1059 EFI_HANDLE Ip4Handle
;
1060 EFI_HANDLE TimerToGetMap
;
1061 EFI_IP4_CONFIG_DATA Ip4ConfigData
;
1062 EFI_IP4_MODE_DATA Ip4Mode
;
1066 // Get the Ip4ServiceBinding Protocol
1070 TimerToGetMap
= NULL
;
1072 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR
), gShellNetwork1HiiHandle
);
1074 Status
= NetLibCreateServiceChild (
1077 &gEfiIp4ServiceBindingProtocolGuid
,
1081 if (EFI_ERROR (Status
)) {
1085 Status
= gBS
->OpenProtocol (
1087 &gEfiIp4ProtocolGuid
,
1091 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1094 if (EFI_ERROR (Status
)) {
1098 Ip4ConfigData
.DefaultProtocol
= EFI_IP_PROTO_ICMP
;
1099 Ip4ConfigData
.AcceptAnyProtocol
= FALSE
;
1100 Ip4ConfigData
.AcceptIcmpErrors
= FALSE
;
1101 Ip4ConfigData
.AcceptBroadcast
= FALSE
;
1102 Ip4ConfigData
.AcceptPromiscuous
= FALSE
;
1103 Ip4ConfigData
.UseDefaultAddress
= TRUE
;
1104 ZeroMem (&Ip4ConfigData
.StationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1105 ZeroMem (&Ip4ConfigData
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
1106 Ip4ConfigData
.TypeOfService
= 0;
1107 Ip4ConfigData
.TimeToLive
= 1;
1108 Ip4ConfigData
.DoNotFragment
= FALSE
;
1109 Ip4ConfigData
.RawData
= FALSE
;
1110 Ip4ConfigData
.ReceiveTimeout
= 0;
1111 Ip4ConfigData
.TransmitTimeout
= 0;
1113 Status
= Ip4
->Configure (Ip4
, &Ip4ConfigData
);
1115 if (Status
== EFI_NO_MAPPING
) {
1117 Status
= gBS
->CreateEvent (
1118 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
1125 if (EFI_ERROR (Status
)) {
1129 Status
= gBS
->SetTimer (
1132 MultU64x32 (SecondsToNanoSeconds
, 5)
1135 if (EFI_ERROR (Status
)) {
1139 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE
), gShellNetwork1HiiHandle
);
1144 if (!EFI_ERROR (Ip4
->GetModeData (Ip4
, &Ip4Mode
, NULL
, NULL
)) &&
1145 Ip4Mode
.IsConfigured
) {
1151 Status
= Ip4
->GetModeData (Ip4
, &Ip4Mode
, NULL
, NULL
);
1153 if ((Status
== EFI_SUCCESS
) && Ip4Mode
.IsConfigured
) {
1158 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1159 gShellNetwork1HiiHandle
,
1161 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[0],
1162 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[1],
1163 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[2],
1164 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[3]
1170 if (EFI_ERROR (Status
)) {
1171 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL
), gShellNetwork1HiiHandle
);
1174 if (TimerToGetMap
!= NULL
) {
1175 gBS
->SetTimer (TimerToGetMap
, TimerCancel
, 0);
1176 gBS
->CloseEvent (TimerToGetMap
);
1179 NetLibDestroyServiceChild (
1182 &gEfiIp4ServiceBindingProtocolGuid
,
1190 Set the address for the nic specified by the params.
1192 @param[in] Argc The count of the passed in Params.
1193 @param[in] Params The command line arguments for the set operation.
1195 @retval EFI_SUCCESS The address set operation is done.
1196 @return Some error occurs.
1200 IfconfigSetNicAddr (
1202 IN CONST CHAR16
*Params
1205 NIC_IP4_CONFIG_INFO
*Config
;
1206 NIC_IP4_CONFIG_INFO
*OldConfig
;
1208 EFI_IP_ADDRESS Mask
;
1209 EFI_IP_ADDRESS Gateway
;
1212 SHELL_STATUS ShellStatus
;
1213 CONST CHAR16
*Walker
;
1215 CONST CHAR16
*DhcpTemp
;
1216 CONST CHAR16
*StaticTemp
;
1217 CONST CHAR16
*PermTemp
;
1218 UINT32 NetworkBytes1
;
1219 UINT32 NetworkBytes2
;
1224 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1225 Info
= IfconfigFindNicByName (Temp
);
1228 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND
), gShellNetwork1HiiHandle
, Temp
);
1229 return SHELL_NOT_FOUND
;
1232 Walker
+= StrLen(Temp
) + 1;
1235 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")==NULL
?0:StrStr(Walker
, L
" ")-Walker
);
1237 Config
= AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO
) + 2 * sizeof (EFI_IP4_ROUTE_TABLE
));
1238 if (Config
== NULL
) {
1239 return SHELL_OUT_OF_RESOURCES
;
1242 Config
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (Config
+ 1);
1244 OldConfig
= Info
->ConfigInfo
;
1246 ShellStatus
= SHELL_INVALID_PARAMETER
;
1248 DhcpTemp
= DhcpString
;
1249 StaticTemp
= StaticString
;
1251 if (StringNoCaseCompare(&Temp
, &DhcpTemp
) == 0) {
1253 // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent
1255 if ((Argc
!= 2) && (Argc
!= 3)) {
1256 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, Temp
);
1257 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1262 Walker
+= StrLen(Temp
) + 1;
1265 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1267 PermTemp
= PermanentString
;
1268 if (StringNoCaseCompare(&Temp
, &PermTemp
) != 0) {
1269 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_OP2
), gShellNetwork1HiiHandle
, Temp
, PermanentString
, L
"Nothing");
1270 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1277 if ((OldConfig
!= NULL
) && (OldConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) &&
1278 (OldConfig
->Permanent
== Permanent
)) {
1280 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED
), gShellNetwork1HiiHandle
, Info
->Name
);
1281 ShellStatus
= SHELL_ALREADY_STARTED
;
1285 Config
->Source
= IP4_CONFIG_SOURCE_DHCP
;
1286 } else if (StringNoCaseCompare(&Temp
, &StaticTemp
) == 0) {
1288 // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and
1289 // eth0 static IP NETMASK GATEWAY permanent
1291 if ((Argc
!= 5) && (Argc
!= 6)) {
1292 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, Temp
);
1293 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1297 Walker
+= StrLen(Temp
) + 1;
1300 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1302 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Ip
.v4
))) {
1303 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1304 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1308 Walker
+= StrLen(Temp
) + 1;
1311 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1312 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Mask
.v4
))) {
1313 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1314 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1318 Walker
+= StrLen(Temp
) + 1;
1322 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1324 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1326 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Gateway
.v4
))) {
1327 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1328 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1333 Walker
+= StrLen(Temp
) + 1;
1336 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1338 PermTemp
= PermanentString
;
1339 if (StringNoCaseCompare(&Temp
, &PermTemp
) != 0) {
1340 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_OP2
), gShellNetwork1HiiHandle
, Temp
, PermanentString
, L
"Nothing");
1341 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1348 NetworkBytes1
= NTOHL (Ip
.Addr
[0]);
1349 NetworkBytes2
= NTOHL (Mask
.Addr
[0]);
1350 if ((Ip
.Addr
[0] == 0) || (Mask
.Addr
[0] == 0) ||
1351 !NetIp4IsUnicast (NetworkBytes1
, NetworkBytes2
)) {
1353 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR
), gShellNetwork1HiiHandle
);
1354 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1358 NetworkBytes1
= NTOHL (Gateway
.Addr
[0]);
1359 if (!IP4_NET_EQUAL (Ip
.Addr
[0], Gateway
.Addr
[0], Mask
.Addr
[0]) ||
1360 !NetIp4IsUnicast (NetworkBytes1
, NetworkBytes2
)) {
1362 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY
), gShellNetwork1HiiHandle
);
1363 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1368 // Set the configuration up, two route table entries are added:
1369 // one for the direct connected network, and another for the
1370 // default gateway. Remember, some structure members are cleared
1371 // by AllocateZeroPool
1373 Config
->Source
= IP4_CONFIG_SOURCE_STATIC
;
1374 Config
->Ip4Info
.RouteTableSize
= 2;
1376 CopyMem (&Config
->Ip4Info
.StationAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1377 CopyMem (&Config
->Ip4Info
.SubnetMask
, &Mask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1379 Ip
.Addr
[0] = Ip
.Addr
[0] & Mask
.Addr
[0];
1381 CopyMem (&Config
->Ip4Info
.RouteTable
[0].SubnetAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1382 CopyMem (&Config
->Ip4Info
.RouteTable
[0].SubnetMask
, &Mask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1383 CopyMem (&Config
->Ip4Info
.RouteTable
[1].GatewayAddress
, &Gateway
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1385 // neither static or DHCP. error.
1386 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_TOO_FEW
), gShellNetwork1HiiHandle
);
1387 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1391 CopyMem (&Config
->NicAddr
, &Info
->NicAddress
, sizeof (NIC_ADDR
));
1392 Config
->Permanent
= Permanent
;
1395 // Use HII service to set NIC address
1397 ShellStatus
= IfconfigSetNicAddrByHii (Info
, Config
);
1398 if (ShellStatus
!= SHELL_SUCCESS
) {
1399 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_SET_FAIL
), gShellNetwork1HiiHandle
, ShellStatus
^MAX_BIT
);
1403 Status
= IfconfigStartIp4 (Info
);
1404 if (EFI_ERROR(Status
)) {
1405 ShellStatus
= SHELL_ACCESS_DENIED
;
1408 if (ShellStatus
!= SHELL_SUCCESS
) {
1409 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL
), gShellNetwork1HiiHandle
, ShellStatus
^MAX_BIT
);
1413 SHELL_FREE_NON_NULL(Config
);
1419 Show the address information for the nic specified.
1421 @param[in] Name A pointer to the string containg the nic's name, if NULL,
1422 all nics' information is shown.
1426 IfconfigShowNicInfo (
1427 IN CONST CHAR16
*Name
1431 LIST_ENTRY
*NextEntry
;
1434 EFI_IP4_IPCONFIG_DATA
*Ip4Config
;
1435 EFI_IPv4_ADDRESS Gateway
;
1436 CONST CHAR16
*TempString
;
1438 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
1439 NicInfo
= BASE_CR (Entry
, NIC_INFO
, Link
);
1441 TempString
= (CHAR16
*)NicInfo
->Name
;
1442 if ((Name
!= NULL
) && (StringNoCaseCompare (&Name
, &TempString
) != 0)) {
1446 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_NIC_NAME
), gShellNetwork1HiiHandle
, NicInfo
->Name
);
1452 STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR
),
1453 gShellNetwork1HiiHandle
,
1454 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[0],
1455 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[1],
1456 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[2],
1457 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[3],
1458 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[4],
1459 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[5]
1462 Print (L
" Media State: %s\n", NicInfo
->MediaPresent
? L
"Media present" : L
"Media disconnected");
1464 if (NicInfo
->ConfigInfo
== NULL
) {
1465 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED
), gShellNetwork1HiiHandle
);
1469 if (NicInfo
->ConfigInfo
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
1470 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"DHCP");
1471 } else if (NicInfo
->ConfigInfo
->Source
== IP4_CONFIG_SOURCE_STATIC
) {
1472 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"STATIC");
1474 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"Unknown");
1477 ShellPrintHiiEx(-1, -1, NULL
,
1478 STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS
),
1479 gShellNetwork1HiiHandle
,
1480 (NicInfo
->ConfigInfo
->Permanent
? L
"TRUE":L
"FALSE")
1483 Ip4Config
= &NicInfo
->ConfigInfo
->Ip4Info
;
1489 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1490 gShellNetwork1HiiHandle
,
1492 (UINTN
)Ip4Config
->StationAddress
.Addr
[0],
1493 (UINTN
)Ip4Config
->StationAddress
.Addr
[1],
1494 (UINTN
)Ip4Config
->StationAddress
.Addr
[2],
1495 (UINTN
)Ip4Config
->StationAddress
.Addr
[3]
1501 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1502 gShellNetwork1HiiHandle
,
1504 (UINTN
)Ip4Config
->SubnetMask
.Addr
[0],
1505 (UINTN
)Ip4Config
->SubnetMask
.Addr
[1],
1506 (UINTN
)Ip4Config
->SubnetMask
.Addr
[2],
1507 (UINTN
)Ip4Config
->SubnetMask
.Addr
[3]
1510 ZeroMem (&Gateway
, sizeof (EFI_IPv4_ADDRESS
));
1512 for (Index
= 0; Index
< Ip4Config
->RouteTableSize
; Index
++) {
1513 if ((CompareMem (&Ip4Config
->RouteTable
[Index
].SubnetAddress
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) &&
1514 (CompareMem (&Ip4Config
->RouteTable
[Index
].SubnetMask
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) ){
1515 CopyMem (&Gateway
, &Ip4Config
->RouteTable
[Index
].GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
1523 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1524 gShellNetwork1HiiHandle
,
1526 (UINTN
)Gateway
.Addr
[0],
1527 (UINTN
)Gateway
.Addr
[1],
1528 (UINTN
)Gateway
.Addr
[2],
1529 (UINTN
)Gateway
.Addr
[3]
1532 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE
), gShellNetwork1HiiHandle
, Ip4Config
->RouteTableSize
);
1534 for (Index
= 0; Index
< Ip4Config
->RouteTableSize
; Index
++) {
1535 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX
), gShellNetwork1HiiHandle
, Index
);
1541 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1542 gShellNetwork1HiiHandle
,
1544 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[0],
1545 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[1],
1546 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[2],
1547 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[3]
1554 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1555 gShellNetwork1HiiHandle
,
1557 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[0],
1558 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[1],
1559 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[2],
1560 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[3]
1567 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1568 gShellNetwork1HiiHandle
,
1570 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[0],
1571 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[1],
1572 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[2],
1573 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[3]
1582 Clear address configuration for the nic specified.
1584 @param[in] Name A pointer to the string containg the nic's name,
1585 if NULL, all nics address configurations are cleared.
1587 @retval EFI_SUCCESS The address configuration is cleared.
1588 @return Some error occurs.
1592 IfconfigClearNicAddr (
1593 IN CONST CHAR16
*Name
1597 LIST_ENTRY
*NextEntry
;
1601 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
1602 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
1604 if ((Name
!= NULL
) && (StrCmp (Name
, Info
->Name
) != 0)) {
1608 // if (Info->NicIp4Config == NULL) {
1609 Status
= IfconfigSetNicAddrByHii (Info
, NULL
);
1611 // Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);
1614 if (EFI_ERROR (Status
)) {
1624 Function for 'ifconfig' command.
1626 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1627 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1631 ShellCommandRunIfconfig (
1632 IN EFI_HANDLE ImageHandle
,
1633 IN EFI_SYSTEM_TABLE
*SystemTable
1637 LIST_ENTRY
*Package
;
1638 CHAR16
*ProblemParam
;
1639 SHELL_STATUS ShellStatus
;
1640 BOOLEAN ListOperation
;
1641 BOOLEAN ClearOperation
;
1642 BOOLEAN SetOperation
;
1647 InitializeListHead (&NicInfoList
);
1648 Status
= EFI_INVALID_PARAMETER
;
1649 ShellStatus
= SHELL_SUCCESS
;
1652 // initialize the shell lib (we must be in non-auto-init...)
1654 Status
= ShellInitialize();
1655 ASSERT_EFI_ERROR(Status
);
1658 // parse the command line
1660 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1661 if (EFI_ERROR(Status
)) {
1662 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1663 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellNetwork1HiiHandle
, ProblemParam
);
1664 FreePool(ProblemParam
);
1665 ShellStatus
= SHELL_INVALID_PARAMETER
;
1673 ClearOperation
= ShellCommandLineGetFlag(Package
, L
"-c");
1674 ListOperation
= ShellCommandLineGetFlag(Package
, L
"-l");
1675 SetOperation
= ShellCommandLineGetFlag(Package
, L
"-s");
1677 if ((ClearOperation
&& ListOperation
)
1678 ||(SetOperation
&& ListOperation
)
1679 ||(ClearOperation
&& SetOperation
)
1681 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellNetwork1HiiHandle
);
1682 ShellStatus
= SHELL_INVALID_PARAMETER
;
1684 } else if (!ClearOperation
&& !ListOperation
&& !SetOperation
) {
1685 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellNetwork1HiiHandle
);
1686 ShellStatus
= SHELL_INVALID_PARAMETER
;
1691 Status
= IfconfigGetAllNicInfoByHii ();
1692 if (EFI_ERROR (Status
)) {
1693 if (mIp4ConfigExist
) {
1694 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL
), gShellNetwork1HiiHandle
, Status
);
1696 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROTOCOL_NF
), gShellNetwork1HiiHandle
, L
"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid
);
1699 return SHELL_NOT_FOUND
;
1702 if (ListOperation
) {
1703 Item
= ShellCommandLineGetValue (Package
, L
"-l");
1705 if (Item
!= NULL
&& CountSubItems(Item
) > 1) {
1706 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"-l");
1707 ShellStatus
= SHELL_INVALID_PARAMETER
;
1712 // Show the configuration.
1714 IfconfigShowNicInfo (Item
);
1715 } else if (SetOperation
) {
1716 Item
= ShellCommandLineGetValue (Package
, L
"-s");
1719 // The correct command line arguments for setting address are:
1720 // IfConfig -s eth0 DHCP [permanent]
1721 // IfConfig -s eth0 static ip netmask gateway [permanent]
1723 if (Item
== NULL
|| (CountSubItems(Item
) < 2) || (CountSubItems(Item
) > 6) || (CountSubItems(Item
) == 4)) {
1724 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"-s");
1725 ShellStatus
= SHELL_INVALID_PARAMETER
;
1729 ShellStatus
= IfconfigSetNicAddr (CountSubItems(Item
), Item
);
1730 } else if (ClearOperation
) {
1731 Item
= ShellCommandLineGetValue (Package
, L
"-c");
1733 if (Item
!= NULL
&& CountSubItems(Item
) > 1) {
1734 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"-c");
1735 ShellStatus
= SHELL_INVALID_PARAMETER
;
1739 IfconfigClearNicAddr (Item
);
1745 while (!IsListEmpty (&NicInfoList
)) {
1746 Entry
= NicInfoList
.ForwardLink
;
1747 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
1749 RemoveEntryList (Entry
);
1751 if (Info
->ConfigInfo
!= NULL
) {
1752 FreePool (Info
->ConfigInfo
);
1758 if (Package
!= NULL
) {
1759 ShellCommandLineFreeVarList(Package
);
1762 return (ShellStatus
);