2 The implementation for ifcommand shell command.
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.
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] MaxLen The max number of UNICODE char in String
255 including the terminate NULL char.
256 @param[in] Offset Offset value.
257 @param[in] Width Width value.
258 @param[in] Block Point to data buffer.
260 @return The count of unicode character that were appended.
264 AppendOffsetWidthValue (
265 IN OUT CHAR16
*String
,
269 IN CONST UINT8
*Block
277 StrnCpyS (String
, MaxLen
, L
"&OFFSET=", 9);
278 String
+= StrLen (L
"&OFFSET=");
279 String
+= UnicodeSPrint (String
, 20, L
"%x", Offset
);
281 StrnCpyS (String
, MaxLen
, L
"&WIDTH=", 8);
282 String
+= StrLen (L
"&WIDTH=");
283 String
+= UnicodeSPrint (String
, 20, L
"%x", Width
);
286 StrnCpyS (String
, MaxLen
, L
"&VALUE=", 8);
287 String
+= StrLen (L
"&VALUE=");
288 while ((Width
--) != 0) {
289 String
+= UnicodeSPrint (String
, 20, L
"%x", Block
[Width
]);
293 return String
- OriString
;
297 Converts the unicode character of the string from uppercase to lowercase.
298 This is a internal function.
300 @param ConfigString String to be converted
305 IN CHAR16
*ConfigString
312 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
314 for (String
= ConfigString
, Lower
= FALSE
; String
!= NULL
&& *String
!= L
'\0'; String
++) {
315 if (*String
== L
'=') {
317 } else if (*String
== L
'&') {
319 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
320 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
324 return (ConfigString
);
329 Construct <ConfigHdr> using routing information GUID/NAME/PATH.
331 @param[in] Guid Routing information: GUID.
332 @param[in] Name Routing information: NAME.
333 @param[in] DriverHandle Driver handle which contains the routing information: PATH.
335 @retval NULL An error occured.
336 @return The pointer to configHdr string.
341 IN CONST EFI_GUID
*Guid
,
342 IN CONST CHAR16
*Name
,
343 IN EFI_HANDLE DriverHandle
348 UINTN ConfigHdrBufferSize
;
349 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
353 UINTN DevicePathLength
;
357 // Get the device path from handle installed EFI HII Config Access protocol
359 Status
= gBS
->HandleProtocol (
361 &gEfiDevicePathProtocolGuid
,
362 (VOID
**) &DevicePath
364 if (EFI_ERROR (Status
)) {
368 DevicePathLength
= GetDevicePathSize (DevicePath
);
369 NameLength
= StrLen (Name
);
370 ConfigHdrBufferSize
= (5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathLength
* 2 + 1) * sizeof (CHAR16
);
371 ConfigHdr
= AllocateZeroPool (ConfigHdrBufferSize
);
372 if (ConfigHdr
== NULL
) {
377 StrnCpyS (String
, ConfigHdrBufferSize
/sizeof(CHAR16
), L
"GUID=", 6);
378 String
+= StrLen (L
"GUID=");
381 // Append Guid converted to <HexCh>32
383 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
384 String
+= UnicodeSPrint (String
, 6, L
"%02x", *Buffer
++);
390 StrnCpyS (String
, ConfigHdrBufferSize
/sizeof(CHAR16
), L
"&NAME=", 7);
391 String
+= StrLen (L
"&NAME=");
392 for (Index
= 0; Index
< NameLength
; Index
++) {
393 String
+= UnicodeSPrint (String
, 10, L
"00%x", Name
[Index
]);
399 StrnCpyS (String
, ConfigHdrBufferSize
/sizeof(CHAR16
), L
"&PATH=", 7);
400 String
+= StrLen (L
"&PATH=");
401 for (Index
= 0, Buffer
= (UINT8
*) DevicePath
; Index
< DevicePathLength
; Index
++) {
402 String
+= UnicodeSPrint (String
, 6, L
"%02x", *Buffer
++);
405 return (HiiToLower(ConfigHdr
));
409 Get network physical device NIC information.
411 @param[in] Handle The network physical device handle.
412 @param[out] NicAddr NIC information.
414 @retval EFI_SUCCESS Get NIC information successfully.
418 IfConfigGetNicMacInfo (
419 IN EFI_HANDLE Handle
,
420 OUT NIC_ADDR
*NicAddr
424 EFI_HANDLE MnpHandle
;
425 EFI_SIMPLE_NETWORK_MODE SnpMode
;
426 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
431 Status
= NetLibCreateServiceChild (
434 &gEfiManagedNetworkServiceBindingProtocolGuid
,
437 if (EFI_ERROR (Status
)) {
441 Status
= gBS
->HandleProtocol (
443 &gEfiManagedNetworkProtocolGuid
,
446 if (EFI_ERROR (Status
)) {
450 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
451 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
455 NicAddr
->Type
= (UINT16
) SnpMode
.IfType
;
456 NicAddr
->Len
= (UINT8
) SnpMode
.HwAddressSize
;
457 CopyMem (&NicAddr
->MacAddr
, &SnpMode
.CurrentAddress
, NicAddr
->Len
);
461 NetLibDestroyServiceChild (
464 &gEfiManagedNetworkServiceBindingProtocolGuid
,
473 Get network physical device NIC information.
475 @param[in] Handle The network physical device handle.
476 @param[out] MediaPresentSupported
477 Upon successful return, TRUE is media present
478 is supported. FALSE otherwise.
479 @param[out] MediaPresent Upon successful return, TRUE is media present
480 is enabled. FALSE otherwise.
482 @retval EFI_SUCCESS The operation was successful.
486 IfConfigGetNicMediaStatus (
487 IN EFI_HANDLE Handle
,
488 OUT BOOLEAN
*MediaPresentSupported
,
489 OUT BOOLEAN
*MediaPresent
494 EFI_HANDLE MnpHandle
;
495 EFI_SIMPLE_NETWORK_MODE SnpMode
;
496 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
501 Status
= NetLibCreateServiceChild (
504 &gEfiManagedNetworkServiceBindingProtocolGuid
,
507 if (EFI_ERROR (Status
)) {
511 Status
= gBS
->HandleProtocol (
513 &gEfiManagedNetworkProtocolGuid
,
516 if (EFI_ERROR (Status
)) {
520 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
521 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
525 *MediaPresentSupported
= SnpMode
.MediaPresentSupported
;
526 *MediaPresent
= SnpMode
.MediaPresent
;
530 NetLibDestroyServiceChild (
533 &gEfiManagedNetworkServiceBindingProtocolGuid
,
542 Get all Nic's information through HII service.
544 @retval EFI_SUCCESS All the nic information is collected.
548 IfconfigGetAllNicInfoByHii (
556 UINTN ConfigRespBufferSize
;
559 CHAR16
*AccessProgress
;
560 CHAR16
*AccessResults
;
563 NIC_IP4_CONFIG_INFO
*NicConfigRequest
;
564 NIC_IP4_CONFIG_INFO
*NicConfig
;
568 EFI_HANDLE ChildHandle
;
570 AccessResults
= NULL
;
573 NicConfigRequest
= NULL
;
576 InitializeListHead (&NicInfoList
);
579 // Check if HII Config Routing protocol available.
581 Status
= gBS
->LocateProtocol (
582 &gEfiHiiConfigRoutingProtocolGuid
,
584 (VOID
**)&mHiiConfigRouting
586 if (EFI_ERROR (Status
)) {
587 return EFI_NOT_FOUND
;
591 // Locate all network device handles
593 Status
= gBS
->LocateHandleBuffer (
595 &gEfiManagedNetworkServiceBindingProtocolGuid
,
600 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
601 return EFI_NOT_FOUND
;
604 for (Index
= 0; Index
< HandleCount
; Index
++) {
605 Status
= GetChildHandle (Handles
[Index
], &ChildHandle
);
606 if (EFI_ERROR (Status
)) {
608 // If failed to get Child handle, try NIC controller handle for back-compatibility.
610 ChildHandle
= Handles
[Index
];
613 // Construct configuration request string header
615 ConfigHdr
= ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, ChildHandle
);
616 if (ConfigHdr
!= NULL
) {
617 Length
= StrLen (ConfigHdr
);
621 ConfigRespBufferSize
= (Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
);
622 ConfigResp
= AllocateZeroPool (ConfigRespBufferSize
);
623 if (ConfigResp
== NULL
) {
624 Status
= EFI_OUT_OF_RESOURCES
;
627 if (ConfigHdr
!= NULL
) {
628 StrnCpyS (ConfigResp
, ConfigRespBufferSize
/sizeof(CHAR16
), ConfigHdr
, Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100 - 1);
632 // Append OFFSET/WIDTH pair
634 String
= ConfigResp
+ Length
;
636 AppendOffsetWidthValue (String
,
637 ConfigRespBufferSize
/sizeof(CHAR16
) - Length
,
639 NIC_ITEM_CONFIG_SIZE
,
643 NicInfo
= AllocateZeroPool (sizeof (NIC_INFO
));
644 if (NicInfo
== NULL
) {
645 Status
= EFI_OUT_OF_RESOURCES
;
648 NicInfo
->Handle
= Handles
[Index
];
651 // Get network physical devcie MAC information
653 IfConfigGetNicMacInfo (Handles
[Index
], &NicInfo
->NicAddress
);
654 if (NicInfo
->NicAddress
.Type
== NET_IFTYPE_ETHERNET
) {
655 UnicodeSPrint (NicInfo
->Name
, IP4_NIC_NAME_LENGTH
, L
"eth%d", Index
);
657 UnicodeSPrint (NicInfo
->Name
, IP4_NIC_NAME_LENGTH
, L
"unk%d", Index
);
663 IfConfigGetNicMediaStatus (Handles
[Index
], &NicInfo
->MediaPresentSupported
, &NicInfo
->MediaPresent
);
665 NicConfigRequest
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
666 if (NicConfigRequest
== NULL
) {
667 Status
= EFI_OUT_OF_RESOURCES
;
672 // Get network parameters by HII service
674 Status
= mHiiConfigRouting
->ExtractConfig (
680 if (!EFI_ERROR (Status
)) {
681 BufferSize
= NIC_ITEM_CONFIG_SIZE
;
682 Status
= mHiiConfigRouting
->ConfigToBlock (
685 (UINT8
*) NicConfigRequest
,
689 if (!EFI_ERROR (Status
)) {
690 BufferSize
= sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * NicConfigRequest
->Ip4Info
.RouteTableSize
;
691 NicConfig
= AllocateZeroPool (BufferSize
);
692 if (NicConfig
== NULL
) {
693 Status
= EFI_OUT_OF_RESOURCES
;
696 CopyMem (NicConfig
, NicConfigRequest
, BufferSize
);
699 // If succeeds to get NIC configuration, fix up routetable pointer.
701 NicConfig
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (&NicConfig
->Ip4Info
+ 1);
702 NicInfo
->ConfigInfo
= NicConfig
;
705 NicInfo
->ConfigInfo
= NULL
;
708 FreePool (AccessResults
);
711 NicInfo
->ConfigInfo
= NULL
;
715 // Add the Nic's info to the global NicInfoList.
717 InsertTailList (&NicInfoList
, &NicInfo
->Link
);
719 FreePool (NicConfigRequest
);
720 FreePool (ConfigResp
);
721 FreePool (ConfigHdr
);
729 if (AccessResults
!= NULL
) {
730 FreePool (AccessResults
);
732 if (NicConfigRequest
!= NULL
) {
733 FreePool (NicConfigRequest
);
735 if (NicInfo
!= NULL
) {
738 if (ConfigResp
!= NULL
) {
739 FreePool (ConfigResp
);
741 if (ConfigHdr
!= NULL
) {
742 FreePool (ConfigHdr
);
751 Set the address for the specified nic by HII service.
753 @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.
754 @param[in] Config The command line arguments for the set operation.
756 @retval EFI_SUCCESS The address set operation is done.
760 IfconfigSetNicAddrByHii (
761 IN CONST NIC_INFO
*NicInfo
,
762 IN CONST NIC_IP4_CONFIG_INFO
*Config
766 SHELL_STATUS ShellStatus
;
767 NIC_IP4_CONFIG_INFO
*NicConfig
;
769 UINTN ConfigRespBufferSize
;
771 CHAR16
*AccessProgress
;
772 CHAR16
*AccessResults
;
776 EFI_HANDLE ChildHandle
;
778 AccessResults
= NULL
;
782 ShellStatus
= SHELL_SUCCESS
;
784 Status
= GetChildHandle (NicInfo
->Handle
, &ChildHandle
);
785 if (EFI_ERROR (Status
)) {
787 // If failed to get Child handle, try NIC controller handle for back-compatibility
789 ChildHandle
= NicInfo
->Handle
;
792 // Construct config request string header
794 ConfigHdr
= ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, ChildHandle
);
795 if (ConfigHdr
!= NULL
) {
796 Length
= StrLen (ConfigHdr
);
798 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
801 ConfigRespBufferSize
= (Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100) * sizeof (CHAR16
);
802 ConfigResp
= AllocateZeroPool (ConfigRespBufferSize
);
803 if (ConfigResp
== NULL
) {
804 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
807 if (ConfigHdr
!= NULL
) {
808 StrnCpyS (ConfigResp
, ConfigRespBufferSize
/sizeof(CHAR16
), ConfigHdr
, Length
+ NIC_ITEM_CONFIG_SIZE
* 2 + 100 - 1);
811 NicConfig
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
812 if (NicConfig
== NULL
) {
813 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
817 if (Config
!= NULL
) {
818 CopyMem (NicConfig
, Config
, sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * Config
->Ip4Info
.RouteTableSize
);
822 // Append OFFSET/WIDTH pair
824 String
= ConfigResp
+ Length
;
826 AppendOffsetWidthValue (String
,
827 ConfigRespBufferSize
/sizeof(CHAR16
) - Length
,
829 NIC_ITEM_CONFIG_SIZE
,
834 // Call HII helper function to generate configuration string
836 Status
= mHiiConfigRouting
->BlockToConfig (
840 NIC_ITEM_CONFIG_SIZE
,
844 if (EFI_ERROR (Status
)) {
845 ShellStatus
= SHELL_NOT_FOUND
;
850 // Set IP setting by HII servie
852 Status
= mHiiConfigRouting
->RouteConfig (
857 if (EFI_ERROR(Status
)) {
858 ShellStatus
= SHELL_ACCESS_DENIED
;
862 SHELL_FREE_NON_NULL(AccessResults
);
863 SHELL_FREE_NON_NULL(NicConfig
);
864 SHELL_FREE_NON_NULL(ConfigResp
);
865 SHELL_FREE_NON_NULL(ConfigHdr
);
871 The callback function for the Arp address resolved event.
873 @param[in] Event The event this function is registered to.
874 @param[in] Context The context registered to the event.
878 IfconfigOnArpResolved (
883 ARP_REQUEST
*Request
;
886 Request
= (ARP_REQUEST
*) Context
;
887 ASSERT (Request
!= NULL
);
889 Request
->Duplicate
= FALSE
;
891 if (0 == CompareMem (&Request
->LocalMac
, &Request
->DestMac
, Request
->MacLen
)) {
896 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
897 gShellNetwork1HiiHandle
,
898 L
"Already Configured",
899 (UINTN
)Request
->DestIp
.v4
.Addr
[0],
900 (UINTN
)Request
->DestIp
.v4
.Addr
[1],
901 (UINTN
)Request
->DestIp
.v4
.Addr
[2],
902 (UINTN
)Request
->DestIp
.v4
.Addr
[3]
908 for (Index
= 0; Index
< Request
->MacLen
; Index
++) {
909 if (Request
->DestMac
.Addr
[Index
] != 0) {
910 Request
->Duplicate
= TRUE
;
914 if (Request
->Duplicate
) {
919 STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR
),
920 gShellNetwork1HiiHandle
,
921 (UINTN
)Request
->DestMac
.Addr
[0],
922 (UINTN
)Request
->DestMac
.Addr
[1],
923 (UINTN
)Request
->DestMac
.Addr
[2],
924 (UINTN
)Request
->DestMac
.Addr
[3],
925 (UINTN
)Request
->DestMac
.Addr
[4],
926 (UINTN
)Request
->DestMac
.Addr
[5]
935 Check whether the address to be configured conflicts with other hosts.
937 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
938 @param[in] IpAddr The IPv4 address to be configured to the Nic.
940 @return TRUE Some other host already uses the IpAddr.
941 @return FALSE The address is unused.
945 IfconfigIsIpDuplicate (
946 IN NIC_INFO
*NicInfo
,
950 EFI_ARP_PROTOCOL
*Arp
;
951 EFI_ARP_CONFIG_DATA ArpCfgData
;
952 EFI_HANDLE ArpHandle
;
958 ZeroMem (&Request
, sizeof (ARP_REQUEST
));
960 Status
= NetLibCreateServiceChild (
963 &gEfiArpServiceBindingProtocolGuid
,
967 if (EFI_ERROR (Status
)) {
971 Status
= gBS
->OpenProtocol (
973 &gEfiArpProtocolGuid
,
977 EFI_OPEN_PROTOCOL_GET_PROTOCOL
980 if (EFI_ERROR (Status
)) {
985 // Set up the Arp requests
987 EFI_IP4_TO_U32 (Request
.DestIp
.v4
) = IpAddr
;
988 EFI_IP4_TO_U32 (Request
.LocalIp
.v4
) = 0xffffffff;
989 Request
.LocalMac
= NicInfo
->NicAddress
.MacAddr
;
990 Request
.MacLen
= NicInfo
->NicAddress
.Len
;
992 Status
= gBS
->CreateEvent (
995 IfconfigOnArpResolved
,
1000 if (EFI_ERROR (Status
)) {
1004 ArpCfgData
.SwAddressType
= 0x0800;
1005 ArpCfgData
.SwAddressLength
= 4;
1006 ArpCfgData
.StationAddress
= &Request
.LocalIp
;
1007 ArpCfgData
.EntryTimeOut
= 0;
1008 ArpCfgData
.RetryCount
= 3;
1009 ArpCfgData
.RetryTimeOut
= 0;
1011 Status
= Arp
->Configure (Arp
, &ArpCfgData
);
1013 if (EFI_ERROR (Status
)) {
1017 Status
= Arp
->Request (
1024 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_READY
)) {
1028 while (!ArpResolved
) {
1033 if (Request
.OnResolved
!= NULL
) {
1034 gBS
->CloseEvent (Request
.OnResolved
);
1037 NetLibDestroyServiceChild (
1040 &gEfiArpServiceBindingProtocolGuid
,
1044 return Request
.Duplicate
;
1048 The callback function for the timer event used to get map.
1050 @param[in] Event The event this function is registered to.
1051 @param[in] Context The context registered to the event.
1065 Create an IP child, use it to start the auto configuration, then destroy it.
1067 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.
1069 @retval EFI_SUCCESS The configuration is done.
1074 IN NIC_INFO
*NicInfo
1077 EFI_IP4_PROTOCOL
*Ip4
;
1078 EFI_HANDLE Ip4Handle
;
1079 EFI_HANDLE TimerToGetMap
;
1080 EFI_IP4_CONFIG_DATA Ip4ConfigData
;
1081 EFI_IP4_MODE_DATA Ip4Mode
;
1085 // Get the Ip4ServiceBinding Protocol
1089 TimerToGetMap
= NULL
;
1091 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR
), gShellNetwork1HiiHandle
);
1093 Status
= NetLibCreateServiceChild (
1096 &gEfiIp4ServiceBindingProtocolGuid
,
1100 if (EFI_ERROR (Status
)) {
1104 Status
= gBS
->OpenProtocol (
1106 &gEfiIp4ProtocolGuid
,
1110 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1113 if (EFI_ERROR (Status
)) {
1117 Ip4ConfigData
.DefaultProtocol
= EFI_IP_PROTO_ICMP
;
1118 Ip4ConfigData
.AcceptAnyProtocol
= FALSE
;
1119 Ip4ConfigData
.AcceptIcmpErrors
= FALSE
;
1120 Ip4ConfigData
.AcceptBroadcast
= FALSE
;
1121 Ip4ConfigData
.AcceptPromiscuous
= FALSE
;
1122 Ip4ConfigData
.UseDefaultAddress
= TRUE
;
1123 ZeroMem (&Ip4ConfigData
.StationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1124 ZeroMem (&Ip4ConfigData
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
1125 Ip4ConfigData
.TypeOfService
= 0;
1126 Ip4ConfigData
.TimeToLive
= 1;
1127 Ip4ConfigData
.DoNotFragment
= FALSE
;
1128 Ip4ConfigData
.RawData
= FALSE
;
1129 Ip4ConfigData
.ReceiveTimeout
= 0;
1130 Ip4ConfigData
.TransmitTimeout
= 0;
1132 Status
= Ip4
->Configure (Ip4
, &Ip4ConfigData
);
1134 if (Status
== EFI_NO_MAPPING
) {
1136 Status
= gBS
->CreateEvent (
1137 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
1144 if (EFI_ERROR (Status
)) {
1148 Status
= gBS
->SetTimer (
1151 MultU64x32 (SecondsToNanoSeconds
, 5)
1154 if (EFI_ERROR (Status
)) {
1158 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE
), gShellNetwork1HiiHandle
);
1163 if (!EFI_ERROR (Ip4
->GetModeData (Ip4
, &Ip4Mode
, NULL
, NULL
)) &&
1164 Ip4Mode
.IsConfigured
) {
1170 Status
= Ip4
->GetModeData (Ip4
, &Ip4Mode
, NULL
, NULL
);
1172 if ((Status
== EFI_SUCCESS
) && Ip4Mode
.IsConfigured
) {
1177 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1178 gShellNetwork1HiiHandle
,
1180 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[0],
1181 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[1],
1182 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[2],
1183 (UINTN
)Ip4Mode
.ConfigData
.StationAddress
.Addr
[3]
1189 if (EFI_ERROR (Status
)) {
1190 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL
), gShellNetwork1HiiHandle
);
1193 if (TimerToGetMap
!= NULL
) {
1194 gBS
->SetTimer (TimerToGetMap
, TimerCancel
, 0);
1195 gBS
->CloseEvent (TimerToGetMap
);
1198 NetLibDestroyServiceChild (
1201 &gEfiIp4ServiceBindingProtocolGuid
,
1209 Set the address for the nic specified by the params.
1211 @param[in] Argc The count of the passed in Params.
1212 @param[in] Params The command line arguments for the set operation.
1214 @retval EFI_SUCCESS The address set operation is done.
1215 @return Some error occurs.
1219 IfconfigSetNicAddr (
1221 IN CONST CHAR16
*Params
1224 NIC_IP4_CONFIG_INFO
*Config
;
1225 NIC_IP4_CONFIG_INFO
*OldConfig
;
1227 EFI_IP_ADDRESS Mask
;
1228 EFI_IP_ADDRESS Gateway
;
1231 SHELL_STATUS ShellStatus
;
1232 CONST CHAR16
*Walker
;
1234 CONST CHAR16
*DhcpTemp
;
1235 CONST CHAR16
*StaticTemp
;
1236 CONST CHAR16
*PermTemp
;
1237 UINT32 NetworkBytes1
;
1238 UINT32 NetworkBytes2
;
1243 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1244 Info
= IfconfigFindNicByName (Temp
);
1247 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND
), gShellNetwork1HiiHandle
, Temp
);
1248 return SHELL_NOT_FOUND
;
1251 Walker
+= StrLen(Temp
) + 1;
1254 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")==NULL
?0:StrStr(Walker
, L
" ")-Walker
);
1256 Config
= AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO
) + 2 * sizeof (EFI_IP4_ROUTE_TABLE
));
1257 if (Config
== NULL
) {
1258 return SHELL_OUT_OF_RESOURCES
;
1261 Config
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (Config
+ 1);
1263 OldConfig
= Info
->ConfigInfo
;
1265 ShellStatus
= SHELL_INVALID_PARAMETER
;
1267 DhcpTemp
= DhcpString
;
1268 StaticTemp
= StaticString
;
1270 if (StringNoCaseCompare(&Temp
, &DhcpTemp
) == 0) {
1272 // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent
1274 if ((Argc
!= 2) && (Argc
!= 3)) {
1275 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PARAM_INV
), gShellNetwork1HiiHandle
, L
"ifconfig", Temp
);
1276 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1281 Walker
+= StrLen(Temp
) + 1;
1284 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1286 PermTemp
= PermanentString
;
1287 if (StringNoCaseCompare(&Temp
, &PermTemp
) != 0) {
1288 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_OP2
), gShellNetwork1HiiHandle
, L
"ifconfig", Temp
, PermanentString
, L
"Nothing");
1289 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1296 if ((OldConfig
!= NULL
) && (OldConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) &&
1297 (OldConfig
->Permanent
== Permanent
)) {
1299 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED
), gShellNetwork1HiiHandle
, Info
->Name
);
1300 ShellStatus
= SHELL_ALREADY_STARTED
;
1304 Config
->Source
= IP4_CONFIG_SOURCE_DHCP
;
1305 } else if (StringNoCaseCompare(&Temp
, &StaticTemp
) == 0) {
1307 // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and
1308 // eth0 static IP NETMASK GATEWAY permanent
1310 if ((Argc
!= 5) && (Argc
!= 6)) {
1311 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PARAM_INV
), gShellNetwork1HiiHandle
, L
"ifconfig", Temp
);
1312 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1316 Walker
+= StrLen(Temp
) + 1;
1319 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1321 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Ip
.v4
))) {
1322 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1323 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1327 Walker
+= StrLen(Temp
) + 1;
1330 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1331 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Mask
.v4
))) {
1332 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1333 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1337 Walker
+= StrLen(Temp
) + 1;
1341 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, StrStr(Walker
, L
" ")-Walker
);
1343 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1345 if (EFI_ERROR (NetLibStrToIp4 (Temp
, &Gateway
.v4
))) {
1346 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR
), gShellNetwork1HiiHandle
, Temp
);
1347 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1352 Walker
+= StrLen(Temp
) + 1;
1355 Temp
= StrnCatGrow(&Temp
, NULL
, Walker
, 0);
1357 PermTemp
= PermanentString
;
1358 if (StringNoCaseCompare(&Temp
, &PermTemp
) != 0) {
1359 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_PROBLEM_OP2
), gShellNetwork1HiiHandle
, L
"ifconfig", Temp
, PermanentString
, L
"Nothing");
1360 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1367 NetworkBytes1
= NTOHL (Ip
.Addr
[0]);
1368 NetworkBytes2
= NTOHL (Mask
.Addr
[0]);
1369 if ((Ip
.Addr
[0] == 0) || (Mask
.Addr
[0] == 0) ||
1370 !NetIp4IsUnicast (NetworkBytes1
, NetworkBytes2
)) {
1372 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR
), gShellNetwork1HiiHandle
);
1373 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1377 NetworkBytes1
= NTOHL (Gateway
.Addr
[0]);
1378 if (!IP4_NET_EQUAL (Ip
.Addr
[0], Gateway
.Addr
[0], Mask
.Addr
[0]) ||
1379 !NetIp4IsUnicast (NetworkBytes1
, NetworkBytes2
)) {
1381 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY
), gShellNetwork1HiiHandle
);
1382 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1387 // Set the configuration up, two route table entries are added:
1388 // one for the direct connected network, and another for the
1389 // default gateway. Remember, some structure members are cleared
1390 // by AllocateZeroPool
1392 Config
->Source
= IP4_CONFIG_SOURCE_STATIC
;
1393 Config
->Ip4Info
.RouteTableSize
= 2;
1395 CopyMem (&Config
->Ip4Info
.StationAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1396 CopyMem (&Config
->Ip4Info
.SubnetMask
, &Mask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1398 Ip
.Addr
[0] = Ip
.Addr
[0] & Mask
.Addr
[0];
1400 CopyMem (&Config
->Ip4Info
.RouteTable
[0].SubnetAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1401 CopyMem (&Config
->Ip4Info
.RouteTable
[0].SubnetMask
, &Mask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1402 CopyMem (&Config
->Ip4Info
.RouteTable
[1].GatewayAddress
, &Gateway
.v4
, sizeof (EFI_IPv4_ADDRESS
));
1404 // neither static or DHCP. error.
1405 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_TOO_FEW
), gShellNetwork1HiiHandle
, L
"ifconfig");
1406 ASSERT(ShellStatus
== SHELL_INVALID_PARAMETER
);
1410 CopyMem (&Config
->NicAddr
, &Info
->NicAddress
, sizeof (NIC_ADDR
));
1411 Config
->Permanent
= Permanent
;
1414 // Use HII service to set NIC address
1416 ShellStatus
= IfconfigSetNicAddrByHii (Info
, Config
);
1417 if (ShellStatus
!= SHELL_SUCCESS
) {
1418 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_SET_FAIL
), gShellNetwork1HiiHandle
, ShellStatus
^MAX_BIT
);
1422 Status
= IfconfigStartIp4 (Info
);
1423 if (EFI_ERROR(Status
)) {
1424 ShellStatus
= SHELL_ACCESS_DENIED
;
1427 if (ShellStatus
!= SHELL_SUCCESS
) {
1428 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL
), gShellNetwork1HiiHandle
, ShellStatus
^MAX_BIT
);
1432 SHELL_FREE_NON_NULL(Config
);
1438 Show the address information for the nic specified.
1440 @param[in] Name A pointer to the string containg the nic's name, if NULL,
1441 all nics' information is shown.
1445 IfconfigShowNicInfo (
1446 IN CONST CHAR16
*Name
1450 LIST_ENTRY
*NextEntry
;
1453 EFI_IP4_IPCONFIG_DATA
*Ip4Config
;
1454 EFI_IPv4_ADDRESS Gateway
;
1455 CONST CHAR16
*TempString
;
1457 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
1458 NicInfo
= BASE_CR (Entry
, NIC_INFO
, Link
);
1460 TempString
= (CHAR16
*)NicInfo
->Name
;
1461 if ((Name
!= NULL
) && (StringNoCaseCompare (&Name
, &TempString
) != 0)) {
1465 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_NIC_NAME
), gShellNetwork1HiiHandle
, NicInfo
->Name
);
1471 STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR
),
1472 gShellNetwork1HiiHandle
,
1473 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[0],
1474 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[1],
1475 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[2],
1476 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[3],
1477 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[4],
1478 (UINTN
)NicInfo
->NicAddress
.MacAddr
.Addr
[5]
1481 Print (L
" Media State: %s\n", NicInfo
->MediaPresent
? L
"Media present" : L
"Media disconnected");
1483 if (NicInfo
->ConfigInfo
== NULL
) {
1484 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED
), gShellNetwork1HiiHandle
);
1488 if (NicInfo
->ConfigInfo
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
1489 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"DHCP");
1490 } else if (NicInfo
->ConfigInfo
->Source
== IP4_CONFIG_SOURCE_STATIC
) {
1491 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"STATIC");
1493 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE
), gShellNetwork1HiiHandle
, L
"Unknown");
1496 ShellPrintHiiEx(-1, -1, NULL
,
1497 STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS
),
1498 gShellNetwork1HiiHandle
,
1499 (NicInfo
->ConfigInfo
->Permanent
? L
"TRUE":L
"FALSE")
1502 Ip4Config
= &NicInfo
->ConfigInfo
->Ip4Info
;
1508 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1509 gShellNetwork1HiiHandle
,
1511 (UINTN
)Ip4Config
->StationAddress
.Addr
[0],
1512 (UINTN
)Ip4Config
->StationAddress
.Addr
[1],
1513 (UINTN
)Ip4Config
->StationAddress
.Addr
[2],
1514 (UINTN
)Ip4Config
->StationAddress
.Addr
[3]
1520 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1521 gShellNetwork1HiiHandle
,
1523 (UINTN
)Ip4Config
->SubnetMask
.Addr
[0],
1524 (UINTN
)Ip4Config
->SubnetMask
.Addr
[1],
1525 (UINTN
)Ip4Config
->SubnetMask
.Addr
[2],
1526 (UINTN
)Ip4Config
->SubnetMask
.Addr
[3]
1529 ZeroMem (&Gateway
, sizeof (EFI_IPv4_ADDRESS
));
1531 for (Index
= 0; Index
< Ip4Config
->RouteTableSize
; Index
++) {
1532 if ((CompareMem (&Ip4Config
->RouteTable
[Index
].SubnetAddress
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) &&
1533 (CompareMem (&Ip4Config
->RouteTable
[Index
].SubnetMask
, &mZeroIp4Addr
, sizeof (EFI_IPv4_ADDRESS
)) == 0) ){
1534 CopyMem (&Gateway
, &Ip4Config
->RouteTable
[Index
].GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
1542 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1543 gShellNetwork1HiiHandle
,
1545 (UINTN
)Gateway
.Addr
[0],
1546 (UINTN
)Gateway
.Addr
[1],
1547 (UINTN
)Gateway
.Addr
[2],
1548 (UINTN
)Gateway
.Addr
[3]
1551 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE
), gShellNetwork1HiiHandle
, Ip4Config
->RouteTableSize
);
1553 for (Index
= 0; Index
< Ip4Config
->RouteTableSize
; Index
++) {
1554 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX
), gShellNetwork1HiiHandle
, Index
);
1560 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1561 gShellNetwork1HiiHandle
,
1563 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[0],
1564 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[1],
1565 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[2],
1566 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetAddress
.Addr
[3]
1573 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1574 gShellNetwork1HiiHandle
,
1576 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[0],
1577 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[1],
1578 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[2],
1579 (UINTN
)Ip4Config
->RouteTable
[Index
].SubnetMask
.Addr
[3]
1586 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR
),
1587 gShellNetwork1HiiHandle
,
1589 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[0],
1590 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[1],
1591 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[2],
1592 (UINTN
)Ip4Config
->RouteTable
[Index
].GatewayAddress
.Addr
[3]
1601 Clear address configuration for the nic specified.
1603 @param[in] Name A pointer to the string containg the nic's name,
1604 if NULL, all nics address configurations are cleared.
1606 @retval EFI_SUCCESS The address configuration is cleared.
1607 @return Some error occurs.
1611 IfconfigClearNicAddr (
1612 IN CONST CHAR16
*Name
1616 LIST_ENTRY
*NextEntry
;
1620 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &NicInfoList
) {
1621 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
1623 if ((Name
!= NULL
) && (StrCmp (Name
, Info
->Name
) != 0)) {
1627 // if (Info->NicIp4Config == NULL) {
1628 Status
= IfconfigSetNicAddrByHii (Info
, NULL
);
1630 // Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);
1633 if (EFI_ERROR (Status
)) {
1643 Function for 'ifconfig' command.
1645 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1646 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1650 ShellCommandRunIfconfig (
1651 IN EFI_HANDLE ImageHandle
,
1652 IN EFI_SYSTEM_TABLE
*SystemTable
1656 LIST_ENTRY
*Package
;
1657 CHAR16
*ProblemParam
;
1658 SHELL_STATUS ShellStatus
;
1659 BOOLEAN ListOperation
;
1660 BOOLEAN ClearOperation
;
1661 BOOLEAN SetOperation
;
1666 InitializeListHead (&NicInfoList
);
1667 Status
= EFI_INVALID_PARAMETER
;
1668 ShellStatus
= SHELL_SUCCESS
;
1671 // initialize the shell lib (we must be in non-auto-init...)
1673 Status
= ShellInitialize();
1674 ASSERT_EFI_ERROR(Status
);
1677 // parse the command line
1679 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
1680 if (EFI_ERROR(Status
)) {
1681 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1682 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellNetwork1HiiHandle
, L
"ifconfig", ProblemParam
);
1683 FreePool(ProblemParam
);
1684 ShellStatus
= SHELL_INVALID_PARAMETER
;
1692 ClearOperation
= ShellCommandLineGetFlag(Package
, L
"-c");
1693 ListOperation
= ShellCommandLineGetFlag(Package
, L
"-l");
1694 SetOperation
= ShellCommandLineGetFlag(Package
, L
"-s");
1696 if ((ClearOperation
&& ListOperation
)
1697 ||(SetOperation
&& ListOperation
)
1698 ||(ClearOperation
&& SetOperation
)
1700 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellNetwork1HiiHandle
, L
"ifconfig");
1701 ShellStatus
= SHELL_INVALID_PARAMETER
;
1703 } else if (!ClearOperation
&& !ListOperation
&& !SetOperation
) {
1704 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellNetwork1HiiHandle
, L
"ifconfig");
1705 ShellStatus
= SHELL_INVALID_PARAMETER
;
1710 Status
= IfconfigGetAllNicInfoByHii ();
1711 if (EFI_ERROR (Status
)) {
1712 if (mIp4ConfigExist
) {
1713 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL
), gShellNetwork1HiiHandle
, Status
);
1715 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROTOCOL_NF
), gShellNetwork1HiiHandle
, L
"ifconfig", L
"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid
);
1718 return SHELL_NOT_FOUND
;
1721 if (ListOperation
) {
1722 Item
= ShellCommandLineGetValue (Package
, L
"-l");
1724 if (Item
!= NULL
&& CountSubItems(Item
) > 1) {
1725 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"ifconfig", Item
, L
"-l");
1726 ShellStatus
= SHELL_INVALID_PARAMETER
;
1731 // Show the configuration.
1733 IfconfigShowNicInfo (Item
);
1734 } else if (SetOperation
) {
1735 Item
= ShellCommandLineGetValue (Package
, L
"-s");
1738 // The correct command line arguments for setting address are:
1739 // IfConfig -s eth0 DHCP [permanent]
1740 // IfConfig -s eth0 static ip netmask gateway [permanent]
1742 if (Item
== NULL
|| (CountSubItems(Item
) < 2) || (CountSubItems(Item
) > 6) || (CountSubItems(Item
) == 4)) {
1743 ShellPrintHiiEx(-1, -1, NULL
,STRING_TOKEN (STR_GEN_NO_VALUE
), gShellNetwork1HiiHandle
, L
"ifconfig", L
"-s");
1744 ShellStatus
= SHELL_INVALID_PARAMETER
;
1748 ShellStatus
= IfconfigSetNicAddr (CountSubItems(Item
), Item
);
1749 } else if (ClearOperation
) {
1750 Item
= ShellCommandLineGetValue (Package
, L
"-c");
1752 if (Item
!= NULL
&& CountSubItems(Item
) > 1) {
1753 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellNetwork1HiiHandle
, L
"ifconfig", Item
, L
"-c");
1754 ShellStatus
= SHELL_INVALID_PARAMETER
;
1758 IfconfigClearNicAddr (Item
);
1764 while (!IsListEmpty (&NicInfoList
)) {
1765 Entry
= NicInfoList
.ForwardLink
;
1766 Info
= BASE_CR (Entry
, NIC_INFO
, Link
);
1768 RemoveEntryList (Entry
);
1770 if (Info
->ConfigInfo
!= NULL
) {
1771 FreePool (Info
->ConfigInfo
);
1777 if (Package
!= NULL
) {
1778 ShellCommandLineFreeVarList(Package
);
1781 return (ShellStatus
);