Add Network1 profile.
[mirror_edk2.git] / ShellPkg / Library / UefiShellNetwork1CommandsLib / Ifconfig.c
CommitLineData
68fb0527 1/** @file\r
2 The implementation for ifcommand shell command.\r
3\r
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13**/\r
14\r
15#include "UefiShellNetwork1CommandsLib.h"\r
16\r
17#define NIC_ITEM_CONFIG_SIZE (sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE)\r
18#define EFI_IP4_TO_U32(EfiIpAddr) (*(IP4_ADDR*)((EfiIpAddr).Addr))\r
19\r
20BOOLEAN mIp4ConfigExist = FALSE;\r
21STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
22\r
23STATIC CONST UINTN SEC_TO_NS = 10000000;\r
24STATIC CONST CHAR16 DhcpString[5] = L"DHCP";\r
25STATIC CONST CHAR16 StaticString[7] = L"STATIC";\r
26STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";\r
27\r
28typedef struct {\r
29 LIST_ENTRY Link;\r
30 EFI_HANDLE Handle;\r
31 NIC_ADDR NicAddress;\r
32 CHAR16 Name[IP4_NIC_NAME_LENGTH];\r
33 BOOLEAN MediaPresentSupported;\r
34 BOOLEAN MediaPresent;\r
35 EFI_IP4_CONFIG_PROTOCOL *Ip4Config;\r
36 NIC_IP4_CONFIG_INFO *ConfigInfo;\r
37} NIC_INFO;\r
38\r
39typedef struct {\r
40 EFI_IP_ADDRESS DestIp;\r
41 EFI_MAC_ADDRESS DestMac;\r
42 EFI_IP_ADDRESS LocalIp;\r
43 EFI_MAC_ADDRESS LocalMac;\r
44 UINT8 MacLen;\r
45 EFI_EVENT OnResolved;\r
46 BOOLEAN Duplicate;\r
47} ARP_REQUEST;\r
48\r
49STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
50 {L"-c", TypeValue},\r
51 {L"-l", TypeValue},\r
52 {L"-s", TypeMaxValue},\r
53 {NULL, TypeMax}\r
54 };\r
55\r
56STATIC LIST_ENTRY NicInfoList;\r
57STATIC BOOLEAN ArpResolved;\r
58STATIC BOOLEAN mTimeout;\r
59\r
60/**\r
61 Count the space delimited items in a string.\r
62\r
63 @param[in] String A pointer to the string to count.\r
64\r
65 @return The number of space-delimited items.\r
66 @retval 0xFF an error occured.\r
67**/\r
68UINT8\r
69EFIAPI\r
70CountSubItems (\r
71 IN CONST CHAR16 *String\r
72 )\r
73{\r
74 CONST CHAR16 *Walker;\r
75 UINT8 Count;\r
76\r
77 if (String == NULL || *String == CHAR_NULL) {\r
78 return (0xFF);\r
79 }\r
80\r
81 for (Walker = String, Count = 0 ; Walker != NULL && *Walker != CHAR_NULL ; Walker = (StrStr(Walker, L" ")==NULL?NULL:StrStr(Walker, L" ")+1), Count++);\r
82 return (Count);\r
83}\r
84\r
85/**\r
86 Find the NIC_INFO by the specified nic name.\r
87\r
88 @param[in] Name The pointer to the string containing the NIC name.\r
89 \r
90 @return The pointer to the NIC_INFO if there is a NIC_INFO named by Name.\r
91 @retval NULL No NIC_INFO was found for Name.\r
92**/\r
93NIC_INFO*\r
94EFIAPI\r
95IfconfigFindNicByName (\r
96 IN CONST CHAR16 *Name\r
97 )\r
98{\r
99 LIST_ENTRY *Entry;\r
100 LIST_ENTRY *NextEntry;\r
101 NIC_INFO *Info;\r
102 CHAR16 *TempString;\r
103\r
104 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {\r
105 Info = BASE_CR (Entry, NIC_INFO, Link);\r
106 TempString = (CHAR16*)Info->Name;\r
107\r
108 if (StringNoCaseCompare (&Name, &TempString) == 0) {\r
109 return Info;\r
110 }\r
111 }\r
112\r
113 return NULL;\r
114}\r
115\r
116/**\r
117 Tests whether a child handle is a child device of the controller.\r
118\r
119 @param[in] ControllerHandle A handle for a (parent) controller to test.\r
120 @param[in] ChildHandle A child handle to test.\r
121 @param[in] ProtocolGuid Supplies the protocol that the child controller\r
122 opens on its parent controller.\r
123\r
124 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r
125 @retval EFI_UNSUPPORTED ChildHandle is not a child of the ControllerHandle.\r
126**/\r
127EFI_STATUS\r
128EFIAPI\r
129TestChildHandle (\r
130 IN CONST EFI_HANDLE ControllerHandle,\r
131 IN CONST EFI_HANDLE ChildHandle,\r
132 IN CONST EFI_GUID *ProtocolGuid\r
133 )\r
134{\r
135 EFI_STATUS Status;\r
136 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
137 UINTN EntryCount;\r
138 UINTN Index;\r
139\r
140 ASSERT (ProtocolGuid != NULL);\r
141\r
142 //\r
143 // Retrieve the list of agents that are consuming the specific protocol\r
144 // on ControllerHandle.\r
145 //\r
146 Status = gBS->OpenProtocolInformation (\r
147 ControllerHandle,\r
148 (EFI_GUID *) ProtocolGuid,\r
149 &OpenInfoBuffer,\r
150 &EntryCount\r
151 );\r
152 if (EFI_ERROR (Status)) {\r
153 return EFI_UNSUPPORTED;\r
154 }\r
155\r
156 //\r
157 // Inspect if ChildHandle is one of the agents.\r
158 //\r
159 Status = EFI_UNSUPPORTED;\r
160 for (Index = 0; Index < EntryCount; Index++) {\r
161 if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r
162 (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
163 Status = EFI_SUCCESS;\r
164 break;\r
165 }\r
166 }\r
167\r
168 FreePool (OpenInfoBuffer);\r
169 return Status;\r
170}\r
171\r
172/**\r
173 Get the child handle of the NIC handle.\r
174\r
175 @param[in] Controller Routing information: GUID.\r
176 @param[in] ChildHandle Returned child handle.\r
177\r
178 @retval EFI_SUCCESS Successfully to get child handle.\r
179**/\r
180EFI_STATUS \r
181GetChildHandle (\r
182 IN EFI_HANDLE Controller,\r
183 OUT EFI_HANDLE *ChildHandle\r
184 )\r
185{\r
186 EFI_STATUS Status;\r
187 EFI_HANDLE *Handles;\r
188 UINTN HandleCount;\r
189 UINTN Index;\r
190 EFI_DEVICE_PATH_PROTOCOL *ChildDeviceDevicePath;\r
191 VENDOR_DEVICE_PATH *VendorDeviceNode;\r
192\r
193 //\r
194 // Locate all EFI Hii Config Access protocols\r
195 //\r
196 Status = gBS->LocateHandleBuffer (\r
197 ByProtocol,\r
198 &gEfiHiiConfigAccessProtocolGuid,\r
199 NULL,\r
200 &HandleCount,\r
201 &Handles\r
202 );\r
203 if (EFI_ERROR (Status) || (HandleCount == 0)) {\r
204 return Status;\r
205 }\r
206\r
207 Status = EFI_NOT_FOUND;\r
208\r
209 for (Index = 0; Index < HandleCount; Index++) {\r
210 \r
211 Status = TestChildHandle (Controller, Handles[Index], &gEfiManagedNetworkServiceBindingProtocolGuid);\r
212 if (!EFI_ERROR (Status)) {\r
213 //\r
214 // Get device path on the child handle\r
215 //\r
216 Status = gBS->HandleProtocol (\r
217 Handles[Index],\r
218 &gEfiDevicePathProtocolGuid,\r
219 (VOID **) &ChildDeviceDevicePath\r
220 );\r
221 \r
222 if (!EFI_ERROR (Status)) {\r
223 while (!IsDevicePathEnd (ChildDeviceDevicePath)) {\r
224 ChildDeviceDevicePath = NextDevicePathNode (ChildDeviceDevicePath);\r
225 //\r
226 // Parse one instance\r
227 //\r
228 if (ChildDeviceDevicePath->Type == HARDWARE_DEVICE_PATH && \r
229 ChildDeviceDevicePath->SubType == HW_VENDOR_DP) {\r
230 VendorDeviceNode = (VENDOR_DEVICE_PATH *) ChildDeviceDevicePath;\r
231 if (CompareMem (&VendorDeviceNode->Guid, &gEfiNicIp4ConfigVariableGuid, sizeof (EFI_GUID)) == 0) {\r
232 //\r
233 // Found item matched gEfiNicIp4ConfigVariableGuid\r
234 //\r
235 *ChildHandle = Handles[Index];\r
236 FreePool (Handles);\r
237 return EFI_SUCCESS;\r
238 }\r
239 }\r
240 }\r
241 } \r
242 }\r
243 }\r
244\r
245 FreePool (Handles);\r
246 return Status; \r
247}\r
248\r
249/**\r
250 Append OFFSET/WIDTH/VALUE items at the beginning of string.\r
251\r
252 @param[in,out] String The pointer to the string to append onto.\r
253 @param[in] Offset Offset value.\r
254 @param[in] Width Width value.\r
255 @param[in] Block Point to data buffer.\r
256\r
257 @return The count of unicode character that were appended.\r
258**/\r
259UINTN\r
260EFIAPI\r
261AppendOffsetWidthValue (\r
262 IN OUT CHAR16 *String,\r
263 IN UINTN Offset,\r
264 IN UINTN Width,\r
265 IN CONST UINT8 *Block\r
266 )\r
267\r
268{\r
269 CHAR16 *OriString;\r
270\r
271 OriString = String;\r
272\r
273 StrCpy (String, L"&OFFSET=");\r
274 String += StrLen (L"&OFFSET=");\r
275 String += UnicodeSPrint (String, 20, L"%x", Offset);\r
276\r
277 StrCpy (String,L"&WIDTH=");\r
278 String += StrLen (L"&WIDTH=");\r
279 String += UnicodeSPrint (String, 20, L"%x", Width);\r
280\r
281 if (Block != NULL) {\r
282 StrCpy (String,L"&VALUE=");\r
283 String += StrLen (L"&VALUE=");\r
284 while ((Width--) != 0) {\r
285 String += UnicodeSPrint (String, 20, L"%x", Block[Width]);\r
286 }\r
287 }\r
288 \r
289 return String - OriString;\r
290}\r
291\r
292/**\r
293 Converts the unicode character of the string from uppercase to lowercase.\r
294 This is a internal function.\r
295\r
296 @param ConfigString String to be converted\r
297**/\r
298CHAR16* \r
299EFIAPI\r
300HiiToLower (\r
301 IN CHAR16 *ConfigString\r
302 )\r
303{\r
304 CHAR16 *String;\r
305 BOOLEAN Lower;\r
306\r
307 //\r
308 // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r
309 //\r
310 for (String = ConfigString, Lower = FALSE; String != NULL && *String != L'\0'; String++) {\r
311 if (*String == L'=') {\r
312 Lower = TRUE;\r
313 } else if (*String == L'&') {\r
314 Lower = FALSE;\r
315 } else if (Lower && *String >= L'A' && *String <= L'F') {\r
316 *String = (CHAR16) (*String - L'A' + L'a');\r
317 }\r
318 }\r
319\r
320 return (ConfigString);\r
321}\r
322\r
323\r
324/**\r
325 Construct <ConfigHdr> using routing information GUID/NAME/PATH.\r
326\r
327 @param[in] Guid Routing information: GUID.\r
328 @param[in] Name Routing information: NAME.\r
329 @param[in] DriverHandle Driver handle which contains the routing information: PATH.\r
330\r
331 @retval NULL An error occured.\r
332 @return The pointer to configHdr string.\r
333**/\r
334CHAR16 *\r
335EFIAPI\r
336ConstructConfigHdr (\r
337 IN CONST EFI_GUID *Guid,\r
338 IN CONST CHAR16 *Name,\r
339 IN EFI_HANDLE DriverHandle\r
340 )\r
341{\r
342 EFI_STATUS Status;\r
343 CHAR16 *ConfigHdr;\r
344 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
345 CHAR16 *String;\r
346 UINTN Index;\r
347 UINT8 *Buffer;\r
348 UINTN DevicePathLength;\r
349 UINTN NameLength;\r
350\r
351 //\r
352 // Get the device path from handle installed EFI HII Config Access protocol\r
353 //\r
354 Status = gBS->HandleProtocol (\r
355 DriverHandle,\r
356 &gEfiDevicePathProtocolGuid,\r
357 (VOID **) &DevicePath\r
358 );\r
359 if (EFI_ERROR (Status)) {\r
360 return NULL;\r
361 }\r
362\r
363 DevicePathLength = GetDevicePathSize (DevicePath);\r
364 NameLength = StrLen (Name);\r
365 ConfigHdr = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16));\r
366 if (ConfigHdr == NULL) {\r
367 return NULL;\r
368 } \r
369\r
370 String = ConfigHdr;\r
371 StrCpy (String, L"GUID=");\r
372 String += StrLen (L"GUID=");\r
373\r
374 //\r
375 // Append Guid converted to <HexCh>32\r
376 //\r
377 for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {\r
378 String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);\r
379 }\r
380\r
381 //\r
382 // Append L"&NAME="\r
383 //\r
384 StrCpy (String, L"&NAME=");\r
385 String += StrLen (L"&NAME=");\r
386 for (Index = 0; Index < NameLength ; Index++) {\r
387 String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);\r
388 }\r
389 \r
390 //\r
391 // Append L"&PATH="\r
392 //\r
393 StrCpy (String, L"&PATH=");\r
394 String += StrLen (L"&PATH=");\r
395 for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {\r
396 String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);\r
397 }\r
398\r
399 return (HiiToLower(ConfigHdr));\r
400}\r
401\r
402/**\r
403 Get network physical device NIC information.\r
404\r
405 @param[in] Handle The network physical device handle.\r
406 @param[out] NicAddr NIC information.\r
407\r
408 @retval EFI_SUCCESS Get NIC information successfully.\r
409**/ \r
410EFI_STATUS\r
411EFIAPI\r
412IfConfigGetNicMacInfo (\r
413 IN EFI_HANDLE Handle,\r
414 OUT NIC_ADDR *NicAddr\r
415 ) \r
416{\r
417 EFI_STATUS Status;\r
418 EFI_HANDLE MnpHandle;\r
419 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
420 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
421\r
422 MnpHandle = NULL;\r
423 Mnp = NULL;\r
424\r
425 Status = NetLibCreateServiceChild (\r
426 Handle,\r
427 gImageHandle, \r
428 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
429 &MnpHandle\r
430 );\r
431 if (EFI_ERROR (Status)) {\r
432 return Status;\r
433 }\r
434\r
435 Status = gBS->HandleProtocol (\r
436 MnpHandle,\r
437 &gEfiManagedNetworkProtocolGuid,\r
438 (VOID **) &Mnp\r
439 );\r
440 if (EFI_ERROR (Status)) {\r
441 goto ON_ERROR;\r
442 }\r
443\r
444 Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r
445 if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
446 goto ON_ERROR;\r
447 }\r
448 \r
449 NicAddr->Type = (UINT16) SnpMode.IfType;\r
450 NicAddr->Len = (UINT8) SnpMode.HwAddressSize;\r
451 CopyMem (&NicAddr->MacAddr, &SnpMode.CurrentAddress, NicAddr->Len);\r
452\r
453ON_ERROR:\r
454\r
455 NetLibDestroyServiceChild (\r
456 Handle,\r
457 gImageHandle, \r
458 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
459 MnpHandle\r
460 );\r
461\r
462 return Status;\r
463\r
464}\r
465\r
466/**\r
467 Get network physical device NIC information.\r
468\r
469 @param[in] Handle The network physical device handle.\r
470 @param[out] MediaPresentSupported\r
471 Upon successful return, TRUE is media present \r
472 is supported. FALSE otherwise.\r
473 @param[out] MediaPresent Upon successful return, TRUE is media present \r
474 is enabled. FALSE otherwise.\r
475\r
476 @retval EFI_SUCCESS The operation was successful.\r
477**/\r
478EFI_STATUS\r
479EFIAPI\r
480IfConfigGetNicMediaStatus (\r
481 IN EFI_HANDLE Handle,\r
482 OUT BOOLEAN *MediaPresentSupported,\r
483 OUT BOOLEAN *MediaPresent\r
484 ) \r
485 \r
486{\r
487 EFI_STATUS Status;\r
488 EFI_HANDLE MnpHandle;\r
489 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
490 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
491\r
492 MnpHandle = NULL;\r
493 Mnp = NULL;\r
494\r
495 Status = NetLibCreateServiceChild (\r
496 Handle,\r
497 gImageHandle, \r
498 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
499 &MnpHandle\r
500 );\r
501 if (EFI_ERROR (Status)) {\r
502 return Status;\r
503 }\r
504\r
505 Status = gBS->HandleProtocol (\r
506 MnpHandle,\r
507 &gEfiManagedNetworkProtocolGuid,\r
508 (VOID **) &Mnp\r
509 );\r
510 if (EFI_ERROR (Status)) {\r
511 goto ON_ERROR;\r
512 }\r
513\r
514 Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r
515 if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
516 goto ON_ERROR;\r
517 }\r
518 \r
519 *MediaPresentSupported = SnpMode.MediaPresentSupported;\r
520 *MediaPresent = SnpMode.MediaPresent;\r
521\r
522ON_ERROR:\r
523\r
524 NetLibDestroyServiceChild (\r
525 Handle,\r
526 gImageHandle, \r
527 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
528 MnpHandle\r
529 );\r
530\r
531 return Status;\r
532\r
533}\r
534\r
535/**\r
536 Get all Nic's information through HII service.\r
537\r
538 @retval EFI_SUCCESS All the nic information is collected.\r
539**/\r
540EFI_STATUS\r
541EFIAPI\r
542IfconfigGetAllNicInfoByHii (\r
543 VOID\r
544 )\r
545{\r
546 EFI_STATUS Status;\r
547 EFI_HANDLE *Handles;\r
548 UINTN HandleCount;\r
549 CHAR16 *ConfigResp;\r
550 CHAR16 *ConfigHdr;\r
551 UINTN Index;\r
552 CHAR16 *AccessProgress;\r
553 CHAR16 *AccessResults;\r
554 UINTN BufferSize;\r
555 NIC_INFO *NicInfo;\r
556 NIC_IP4_CONFIG_INFO *NicConfigRequest;\r
557 NIC_IP4_CONFIG_INFO *NicConfig;\r
558 CHAR16 *String;\r
559 UINTN Length;\r
560 UINTN Offset;\r
561 EFI_HANDLE ChildHandle;\r
562\r
563 AccessResults = NULL;\r
564 ConfigHdr = NULL;\r
565 ConfigResp = NULL;\r
566 NicConfigRequest = NULL;\r
567 NicInfo = NULL;\r
568\r
569 InitializeListHead (&NicInfoList);\r
570\r
571 //\r
572 // Check if HII Config Routing protocol available.\r
573 //\r
574 Status = gBS->LocateProtocol (\r
575 &gEfiHiiConfigRoutingProtocolGuid,\r
576 NULL,\r
577 (VOID**)&mHiiConfigRouting\r
578 );\r
579 if (EFI_ERROR (Status)) {\r
580 return EFI_NOT_FOUND;\r
581 }\r
582\r
583 //\r
584 // Locate all network device handles\r
585 //\r
586 Status = gBS->LocateHandleBuffer (\r
587 ByProtocol,\r
588 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
589 NULL,\r
590 &HandleCount,\r
591 &Handles\r
592 );\r
593 if (EFI_ERROR (Status) || (HandleCount == 0)) {\r
594 return EFI_NOT_FOUND;\r
595 }\r
596\r
597 for (Index = 0; Index < HandleCount; Index++) {\r
598 Status = GetChildHandle (Handles[Index], &ChildHandle);\r
599 if (EFI_ERROR (Status)) {\r
600 //\r
601 // If failed to get Child handle, try NIC controller handle for back-compatibility.\r
602 //\r
603 ChildHandle = Handles[Index];\r
604 }\r
605 //\r
606 // Construct configuration request string header\r
607 //\r
608 ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r
609 Length = StrLen (ConfigHdr);\r
610 ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
611 if (ConfigResp == NULL) {\r
612 Status = EFI_OUT_OF_RESOURCES;\r
613 goto ON_ERROR;\r
614 }\r
615 StrCpy (ConfigResp, ConfigHdr);\r
616 \r
617 //\r
618 // Append OFFSET/WIDTH pair\r
619 //\r
620 String = ConfigResp + Length;\r
621 Offset = 0;\r
622 AppendOffsetWidthValue (String, Offset, NIC_ITEM_CONFIG_SIZE, NULL);\r
623\r
624 NicInfo = AllocateZeroPool (sizeof (NIC_INFO));\r
625 if (NicInfo == NULL) {\r
626 Status = EFI_OUT_OF_RESOURCES;\r
627 goto ON_ERROR;\r
628 }\r
629 NicInfo->Handle = Handles[Index];\r
630\r
631 //\r
632 // Get network physical devcie MAC information\r
633 //\r
634 IfConfigGetNicMacInfo (Handles[Index], &NicInfo->NicAddress);\r
635 if (NicInfo->NicAddress.Type == NET_IFTYPE_ETHERNET) {\r
636 UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"eth%d", Index);\r
637 } else {\r
638 UnicodeSPrint (NicInfo->Name, IP4_NIC_NAME_LENGTH, L"unk%d", Index);\r
639 }\r
640\r
641 //\r
642 // Get media status\r
643 //\r
644 IfConfigGetNicMediaStatus (Handles[Index], &NicInfo->MediaPresentSupported, &NicInfo->MediaPresent);\r
645\r
646 NicConfigRequest = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
647 if (NicConfigRequest == NULL) {\r
648 Status = EFI_OUT_OF_RESOURCES;\r
649 goto ON_ERROR;\r
650 }\r
651\r
652 //\r
653 // Get network parameters by HII service\r
654 //\r
655 Status = mHiiConfigRouting->ExtractConfig (\r
656 mHiiConfigRouting,\r
657 ConfigResp,\r
658 &AccessProgress,\r
659 &AccessResults\r
660 );\r
661 if (!EFI_ERROR (Status)) {\r
662 BufferSize = NIC_ITEM_CONFIG_SIZE;\r
663 Status = mHiiConfigRouting->ConfigToBlock (\r
664 mHiiConfigRouting,\r
665 AccessResults,\r
666 (UINT8 *) NicConfigRequest,\r
667 &BufferSize,\r
668 &AccessProgress\r
669 );\r
670 if (!EFI_ERROR (Status)) {\r
671 BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * NicConfigRequest->Ip4Info.RouteTableSize;\r
672 NicConfig = AllocateZeroPool (BufferSize);\r
673 if (NicConfig == NULL) {\r
674 Status = EFI_OUT_OF_RESOURCES;\r
675 goto ON_ERROR;\r
676 }\r
677 CopyMem (NicConfig, NicConfigRequest, BufferSize);\r
678\r
679 //\r
680 // If succeeds to get NIC configuration, fix up routetable pointer.\r
681 //\r
682 NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (&NicConfig->Ip4Info + 1);\r
683 NicInfo->ConfigInfo = NicConfig;\r
684\r
685 } else {\r
686 NicInfo->ConfigInfo = NULL;\r
687 }\r
688\r
689 FreePool (AccessResults);\r
690\r
691 } else {\r
692 NicInfo->ConfigInfo = NULL;\r
693 }\r
694\r
695 //\r
696 // Add the Nic's info to the global NicInfoList.\r
697 //\r
698 InsertTailList (&NicInfoList, &NicInfo->Link);\r
699\r
700 FreePool (NicConfigRequest);\r
701 FreePool (ConfigResp);\r
702 FreePool (ConfigHdr);\r
703 }\r
704\r
705 FreePool (Handles);\r
706\r
707 return EFI_SUCCESS;\r
708 \r
709ON_ERROR:\r
710 if (AccessResults != NULL) {\r
711 FreePool (AccessResults);\r
712 }\r
713 if (NicConfigRequest != NULL) {\r
714 FreePool (NicConfigRequest);\r
715 }\r
716 if (NicInfo != NULL) {\r
717 FreePool (NicInfo);\r
718 }\r
719 if (ConfigResp != NULL) {\r
720 FreePool (ConfigResp);\r
721 }\r
722 if (ConfigHdr != NULL) {\r
723 FreePool (ConfigHdr);\r
724 }\r
725\r
726 FreePool (Handles);\r
727\r
728 return Status;\r
729}\r
730\r
731/**\r
732 Set the address for the specified nic by HII service.\r
733\r
734 @param[in] NicInfo A pointer to the NIC_INFO of the Nic to be configured.\r
735 @param[in] Config The command line arguments for the set operation.\r
736\r
737 @retval EFI_SUCCESS The address set operation is done.\r
738**/\r
739SHELL_STATUS\r
740EFIAPI\r
741IfconfigSetNicAddrByHii (\r
742 IN CONST NIC_INFO *NicInfo,\r
743 IN CONST NIC_IP4_CONFIG_INFO *Config\r
744 )\r
745{\r
746 EFI_STATUS Status;\r
747 SHELL_STATUS ShellStatus;\r
748 NIC_IP4_CONFIG_INFO *NicConfig;\r
749 CHAR16 *ConfigResp;\r
750 CHAR16 *ConfigHdr;\r
751 CHAR16 *AccessProgress;\r
752 CHAR16 *AccessResults;\r
753 CHAR16 *String;\r
754 UINTN Length;\r
755 UINTN Offset;\r
756 EFI_HANDLE ChildHandle;\r
757\r
758 AccessResults = NULL;\r
759 ConfigHdr = NULL;\r
760 ConfigResp = NULL;\r
761 NicConfig = NULL;\r
762 ShellStatus = SHELL_SUCCESS;\r
763\r
764 Status = GetChildHandle (NicInfo->Handle, &ChildHandle);\r
765 if (EFI_ERROR (Status)) {\r
766 //\r
767 // If failed to get Child handle, try NIC controller handle for back-compatibility\r
768 //\r
769 ChildHandle = NicInfo->Handle;\r
770 }\r
771 //\r
772 // Construct config request string header\r
773 //\r
774 ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r
775\r
776 Length = StrLen (ConfigHdr);\r
777 ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
778 StrCpy (ConfigResp, ConfigHdr);\r
779\r
780 NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
781 if (NicConfig == NULL) {\r
782 ShellStatus = SHELL_OUT_OF_RESOURCES;\r
783 goto ON_EXIT;\r
784 }\r
785\r
786 if (Config != NULL) {\r
787 CopyMem (NicConfig, Config, sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * Config->Ip4Info.RouteTableSize);\r
788 }\r
789\r
790 //\r
791 // Append OFFSET/WIDTH pair\r
792 //\r
793 String = ConfigResp + Length;\r
794 Offset = 0;\r
795 AppendOffsetWidthValue (String, Offset, NIC_ITEM_CONFIG_SIZE, NULL);\r
796\r
797 //\r
798 // Call HII helper function to generate configuration string\r
799 //\r
800 Status = mHiiConfigRouting->BlockToConfig (\r
801 mHiiConfigRouting,\r
802 ConfigResp,\r
803 (UINT8 *) NicConfig,\r
804 NIC_ITEM_CONFIG_SIZE,\r
805 &AccessResults,\r
806 &AccessProgress\r
807 );\r
808 if (EFI_ERROR (Status)) {\r
809 ShellStatus = SHELL_NOT_FOUND;\r
810 goto ON_EXIT;\r
811 }\r
812\r
813 //\r
814 // Set IP setting by HII servie\r
815 //\r
816 Status = mHiiConfigRouting->RouteConfig (\r
817 mHiiConfigRouting,\r
818 AccessResults,\r
819 &AccessProgress\r
820 );\r
821 if (EFI_ERROR(Status)) {\r
822 ShellStatus = SHELL_ACCESS_DENIED;\r
823 }\r
824\r
825ON_EXIT:\r
826 SHELL_FREE_NON_NULL(AccessResults);\r
827 SHELL_FREE_NON_NULL(NicConfig);\r
828 SHELL_FREE_NON_NULL(ConfigResp);\r
829 SHELL_FREE_NON_NULL(ConfigHdr);\r
830\r
831 return ShellStatus;\r
832}\r
833\r
834/**\r
835 The callback function for the Arp address resolved event.\r
836\r
837 @param[in] Event The event this function is registered to.\r
838 @param[in] Context The context registered to the event.\r
839**/\r
840VOID\r
841EFIAPI\r
842IfconfigOnArpResolved (\r
843 IN EFI_EVENT Event,\r
844 IN VOID *Context\r
845 )\r
846{\r
847 ARP_REQUEST *Request;\r
848 UINT8 Index;\r
849\r
850 Request = (ARP_REQUEST *) Context;\r
851 ASSERT (Request != NULL);\r
852\r
853 Request->Duplicate = FALSE;\r
854 \r
855 if (0 == CompareMem (&Request->LocalMac, &Request->DestMac, Request->MacLen)) {\r
856 ShellPrintHiiEx(\r
857 -1, \r
858 -1, \r
859 NULL,\r
860 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
861 gShellNetwork1HiiHandle, \r
862 L"Already Configured",\r
863 (UINTN)Request->DestIp.v4.Addr[0],\r
864 (UINTN)Request->DestIp.v4.Addr[1],\r
865 (UINTN)Request->DestIp.v4.Addr[2],\r
866 (UINTN)Request->DestIp.v4.Addr[3]\r
867 );\r
868 ArpResolved = TRUE;\r
869 return;\r
870 }\r
871 \r
872 for (Index = 0; Index < Request->MacLen; Index++) {\r
873 if (Request->DestMac.Addr[Index] != 0) {\r
874 Request->Duplicate = TRUE;\r
875 }\r
876 }\r
877\r
878 if (Request->Duplicate) {\r
879 ShellPrintHiiEx(\r
880 -1,\r
881 -1,\r
882 NULL,\r
883 STRING_TOKEN(STR_IFCONFIG_CONF_IP_ADDR), \r
884 gShellNetwork1HiiHandle, \r
885 (UINTN)Request->DestMac.Addr[0], \r
886 (UINTN)Request->DestMac.Addr[1], \r
887 (UINTN)Request->DestMac.Addr[2],\r
888 (UINTN)Request->DestMac.Addr[3], \r
889 (UINTN)Request->DestMac.Addr[4], \r
890 (UINTN)Request->DestMac.Addr[5]\r
891 ); \r
892 }\r
893\r
894 ArpResolved = TRUE;\r
895 return ;\r
896}\r
897\r
898/**\r
899 Check whether the address to be configured conflicts with other hosts.\r
900\r
901 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.\r
902 @param[in] IpAddr The IPv4 address to be configured to the Nic.\r
903\r
904 @return TRUE Some other host already uses the IpAddr.\r
905 @return FALSE The address is unused.\r
906**/\r
907BOOLEAN\r
908EFIAPI\r
909IfconfigIsIpDuplicate (\r
910 IN NIC_INFO *NicInfo,\r
911 IN IP4_ADDR IpAddr\r
912 )\r
913{\r
914 EFI_ARP_PROTOCOL *Arp;\r
915 EFI_ARP_CONFIG_DATA ArpCfgData;\r
916 EFI_HANDLE ArpHandle;\r
917 ARP_REQUEST Request;\r
918 EFI_STATUS Status;\r
919\r
920 Arp = NULL;\r
921 ArpHandle = NULL;\r
922 ZeroMem (&Request, sizeof (ARP_REQUEST));\r
923\r
924 Status = NetLibCreateServiceChild (\r
925 NicInfo->Handle,\r
926 gImageHandle, \r
927 &gEfiArpServiceBindingProtocolGuid,\r
928 &ArpHandle\r
929 );\r
930\r
931 if (EFI_ERROR (Status)) {\r
932 return FALSE;\r
933 }\r
934\r
935 Status = gBS->OpenProtocol (\r
936 ArpHandle,\r
937 &gEfiArpProtocolGuid,\r
938 (VOID**)&Arp,\r
939 gImageHandle,\r
940 ArpHandle,\r
941 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
942 );\r
943\r
944 if (EFI_ERROR (Status)) {\r
945 goto ON_EXIT;\r
946 }\r
947\r
948 //\r
949 // Set up the Arp requests\r
950 //\r
951 EFI_IP4_TO_U32 (Request.DestIp.v4) = IpAddr;\r
952 EFI_IP4_TO_U32 (Request.LocalIp.v4) = 0xffffffff;\r
953 Request.LocalMac = NicInfo->NicAddress.MacAddr;\r
954 Request.MacLen = NicInfo->NicAddress.Len;\r
955 \r
956 Status = gBS->CreateEvent (\r
957 EVT_NOTIFY_SIGNAL,\r
958 TPL_CALLBACK,\r
959 IfconfigOnArpResolved,\r
960 (VOID *) &Request,\r
961 &Request.OnResolved\r
962 );\r
963 \r
964 if (EFI_ERROR (Status)) {\r
965 goto ON_EXIT;\r
966 }\r
967 \r
968 ArpCfgData.SwAddressType = 0x0800;\r
969 ArpCfgData.SwAddressLength = 4;\r
970 ArpCfgData.StationAddress = &Request.LocalIp;\r
971 ArpCfgData.EntryTimeOut = 0;\r
972 ArpCfgData.RetryCount = 3;\r
973 ArpCfgData.RetryTimeOut = 0;\r
974 \r
975 Status = Arp->Configure (Arp, &ArpCfgData);\r
976 \r
977 if (EFI_ERROR (Status)) {\r
978 goto ON_EXIT;\r
979 }\r
980\r
981 Status = Arp->Request (\r
982 Arp,\r
983 &Request.DestIp,\r
984 Request.OnResolved,\r
985 &Request.DestMac\r
986 );\r
987 \r
988 if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {\r
989 goto ON_EXIT;\r
990 }\r
991\r
992 while (!ArpResolved) {\r
993 \r
994 }\r
995\r
996ON_EXIT:\r
997 if (Request.OnResolved != NULL) {\r
998 gBS->CloseEvent (Request.OnResolved);\r
999 }\r
1000\r
1001 NetLibDestroyServiceChild (\r
1002 NicInfo->Handle, \r
1003 gImageHandle, \r
1004 &gEfiArpServiceBindingProtocolGuid, \r
1005 ArpHandle\r
1006 );\r
1007\r
1008 return Request.Duplicate;\r
1009}\r
1010\r
1011/**\r
1012 The callback function for the timer event used to get map.\r
1013\r
1014 @param[in] Event The event this function is registered to.\r
1015 @param[in] Context The context registered to the event.\r
1016**/\r
1017VOID\r
1018EFIAPI\r
1019TimeoutToGetMap (\r
1020 IN EFI_EVENT Event,\r
1021 IN VOID *Context\r
1022 )\r
1023{\r
1024 mTimeout = TRUE;\r
1025 return ;\r
1026}\r
1027\r
1028/**\r
1029 Create an IP child, use it to start the auto configuration, then destory it.\r
1030\r
1031 @param[in] NicInfo The pointer to the NIC_INFO of the Nic to be configured.\r
1032\r
1033 @retval EFI_SUCCESS The configuration is done.\r
1034**/\r
1035EFI_STATUS\r
1036EFIAPI\r
1037IfconfigStartIp4(\r
1038 IN NIC_INFO *NicInfo\r
1039 )\r
1040{\r
1041 EFI_IP4_PROTOCOL *Ip4;\r
1042 EFI_HANDLE Ip4Handle;\r
1043 EFI_HANDLE TimerToGetMap;\r
1044 EFI_IP4_CONFIG_DATA Ip4ConfigData;\r
1045 EFI_IP4_MODE_DATA Ip4Mode;\r
1046 EFI_STATUS Status;\r
1047\r
1048 //\r
1049 // Get the Ip4ServiceBinding Protocol\r
1050 //\r
1051 Ip4Handle = NULL;\r
1052 Ip4 = NULL;\r
1053 TimerToGetMap = NULL;\r
1054\r
1055 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_START_SET_ADDR), gShellNetwork1HiiHandle);\r
1056\r
1057 Status = NetLibCreateServiceChild (\r
1058 NicInfo->Handle,\r
1059 gImageHandle,\r
1060 &gEfiIp4ServiceBindingProtocolGuid,\r
1061 &Ip4Handle\r
1062 );\r
1063\r
1064 if (EFI_ERROR (Status)) {\r
1065 return Status;\r
1066 }\r
1067\r
1068 Status = gBS->OpenProtocol (\r
1069 Ip4Handle,\r
1070 &gEfiIp4ProtocolGuid,\r
1071 (VOID **) &Ip4,\r
1072 NicInfo->Handle,\r
1073 gImageHandle,\r
1074 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1075 );\r
1076\r
1077 if (EFI_ERROR (Status)) {\r
1078 goto ON_EXIT;\r
1079 }\r
1080\r
1081 Ip4ConfigData.DefaultProtocol = EFI_IP_PROTO_ICMP;\r
1082 Ip4ConfigData.AcceptAnyProtocol = FALSE;\r
1083 Ip4ConfigData.AcceptIcmpErrors = FALSE;\r
1084 Ip4ConfigData.AcceptBroadcast = FALSE;\r
1085 Ip4ConfigData.AcceptPromiscuous = FALSE;\r
1086 Ip4ConfigData.UseDefaultAddress = TRUE;\r
1087 ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));\r
1088 ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
1089 Ip4ConfigData.TypeOfService = 0;\r
1090 Ip4ConfigData.TimeToLive = 1;\r
1091 Ip4ConfigData.DoNotFragment = FALSE;\r
1092 Ip4ConfigData.RawData = FALSE;\r
1093 Ip4ConfigData.ReceiveTimeout = 0;\r
1094 Ip4ConfigData.TransmitTimeout = 0;\r
1095\r
1096 Status = Ip4->Configure (Ip4, &Ip4ConfigData);\r
1097\r
1098 if (Status == EFI_NO_MAPPING) {\r
1099 mTimeout = FALSE;\r
1100 Status = gBS->CreateEvent (\r
1101 EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
1102 TPL_CALLBACK - 1,\r
1103 TimeoutToGetMap,\r
1104 NULL,\r
1105 &TimerToGetMap\r
1106 );\r
1107 \r
1108 if (EFI_ERROR (Status)) {\r
1109 goto ON_EXIT;\r
1110 }\r
1111 \r
1112 Status = gBS->SetTimer (\r
1113 TimerToGetMap,\r
1114 TimerRelative,\r
1115 MultU64x32 (SEC_TO_NS, 5)\r
1116 );\r
1117 \r
1118 if (EFI_ERROR (Status)) {\r
1119 goto ON_EXIT;\r
1120 }\r
1121\r
1122 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_WAIT_SET_DONE), gShellNetwork1HiiHandle);\r
1123 \r
1124 while (!mTimeout) {\r
1125 Ip4->Poll (Ip4);\r
1126 \r
1127 if (!EFI_ERROR (Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL)) && \r
1128 Ip4Mode.IsConfigured) { \r
1129 break;\r
1130 }\r
1131 } \r
1132 }\r
1133\r
1134 Status = Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL);\r
1135\r
1136 if ((Status == EFI_SUCCESS) && Ip4Mode.IsConfigured) {\r
1137 ShellPrintHiiEx(\r
1138 -1, \r
1139 -1, \r
1140 NULL,\r
1141 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1142 gShellNetwork1HiiHandle, \r
1143 L"Default",\r
1144 (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[0],\r
1145 (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[1],\r
1146 (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[2],\r
1147 (UINTN)Ip4Mode.ConfigData.StationAddress.Addr[3]\r
1148 );\r
1149 }\r
1150 \r
1151ON_EXIT: \r
1152\r
1153 if (EFI_ERROR (Status)) {\r
1154 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_DEF_ADDR_FAIL), gShellNetwork1HiiHandle);\r
1155 }\r
1156\r
1157 if (TimerToGetMap != NULL) {\r
1158 gBS->SetTimer (TimerToGetMap, TimerCancel, 0);\r
1159 gBS->CloseEvent (TimerToGetMap);\r
1160 }\r
1161\r
1162 NetLibDestroyServiceChild (\r
1163 NicInfo->Handle,\r
1164 gImageHandle,\r
1165 &gEfiIp4ServiceBindingProtocolGuid,\r
1166 Ip4Handle\r
1167 );\r
1168 \r
1169 return Status;\r
1170}\r
1171\r
1172/**\r
1173 Set the address for the nic specified by the params.\r
1174\r
1175 @param[in] Argc The count of the passed in Params.\r
1176 @param[in] Params The command line arguments for the set operation.\r
1177\r
1178 @retval EFI_SUCCESS The address set operation is done.\r
1179 @return Some error occurs.\r
1180**/\r
1181SHELL_STATUS\r
1182EFIAPI\r
1183IfconfigSetNicAddr (\r
1184 IN UINTN Argc,\r
1185 IN CONST CHAR16 *Params\r
1186 )\r
1187{\r
1188 NIC_IP4_CONFIG_INFO *Config;\r
1189 NIC_IP4_CONFIG_INFO *OldConfig;\r
1190 EFI_IP_ADDRESS Ip;\r
1191 EFI_IP_ADDRESS Mask;\r
1192 EFI_IP_ADDRESS Gateway;\r
1193 NIC_INFO *Info;\r
1194 BOOLEAN Permanent;\r
1195 SHELL_STATUS ShellStatus;\r
1196 CONST CHAR16 *Walker;\r
1197 CHAR16 *Temp;\r
1198 CONST CHAR16 *DhcpTemp;\r
1199 CONST CHAR16 *StaticTemp;\r
1200 CONST CHAR16 *PermTemp;\r
1201 UINT32 NetworkBytes1;\r
1202 UINT32 NetworkBytes2;\r
1203 EFI_STATUS Status;\r
1204\r
1205 Walker = Params;\r
1206 Temp = NULL;\r
1207 Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r
1208 Info = IfconfigFindNicByName (Temp);\r
1209\r
1210 if (Info == NULL) {\r
1211 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_NOT_FOUND), gShellNetwork1HiiHandle, Temp);\r
1212 return SHELL_NOT_FOUND;\r
1213 }\r
1214\r
1215 Walker += StrLen(Temp) + 1;\r
1216 FreePool(Temp);\r
1217 Temp = NULL;\r
1218 Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")==NULL?0:StrStr(Walker, L" ")-Walker);\r
1219\r
1220 Config = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));\r
1221 if (Config == NULL) {\r
1222 return SHELL_OUT_OF_RESOURCES;\r
1223 }\r
1224\r
1225 Config->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Config + 1);\r
1226\r
1227 OldConfig = Info->ConfigInfo;\r
1228 Permanent = FALSE;\r
1229 ShellStatus = SHELL_INVALID_PARAMETER;\r
1230\r
1231 DhcpTemp = DhcpString;\r
1232 StaticTemp = StaticString;\r
1233 \r
1234 if (StringNoCaseCompare(&Temp, &DhcpTemp) == 0) {\r
1235 //\r
1236 // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP perment\r
1237 //\r
1238 if ((Argc != 2) && (Argc!= 3)) {\r
1239 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, Temp);\r
1240 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1241 goto ON_EXIT;\r
1242 }\r
1243\r
1244 if (Argc == 3) {\r
1245 Walker += StrLen(Temp) + 1;\r
1246 FreePool(Temp);\r
1247 Temp = NULL;\r
1248 Temp = StrnCatGrow(&Temp, NULL, Walker, 0);\r
1249\r
1250 PermTemp = PermanentString;\r
1251 if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {\r
1252 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, Temp, PermanentString, L"Nothing");\r
1253 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1254 goto ON_EXIT;\r
1255 }\r
1256\r
1257 Permanent = TRUE;\r
1258 }\r
1259\r
1260 if ((OldConfig != NULL) && (OldConfig->Source == IP4_CONFIG_SOURCE_DHCP) &&\r
1261 (OldConfig->Perment == Permanent)) {\r
1262\r
1263 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED), gShellNetwork1HiiHandle, Info->Name);\r
1264 ShellStatus = SHELL_ALREADY_STARTED;\r
1265 goto ON_EXIT;\r
1266 }\r
1267\r
1268 Config->Source = IP4_CONFIG_SOURCE_DHCP;\r
1269 } else if (StringNoCaseCompare(&Temp, &StaticTemp) == 0) {\r
1270 //\r
1271 // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and\r
1272 // eth0 static IP NETMASK GATEWAY perment\r
1273 //\r
1274 if ((Argc != 5) && (Argc != 6)) {\r
1275 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, Temp);\r
1276 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1277 goto ON_EXIT;\r
1278 }\r
1279\r
1280 Walker += StrLen(Temp) + 1;\r
1281 FreePool(Temp);\r
1282 Temp = NULL;\r
1283 Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r
1284\r
1285 if (EFI_ERROR (NetLibStrToIp4 (Temp, &Ip.v4))) {\r
1286 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);\r
1287 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1288 goto ON_EXIT;\r
1289 }\r
1290\r
1291 Walker += StrLen(Temp) + 1;\r
1292 FreePool(Temp);\r
1293 Temp = NULL;\r
1294 Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r
1295 if (EFI_ERROR (NetLibStrToIp4 (Temp, &Mask.v4))) {\r
1296 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);\r
1297 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1298 goto ON_EXIT;\r
1299 }\r
1300\r
1301 Walker += StrLen(Temp) + 1;\r
1302 FreePool(Temp);\r
1303 Temp = NULL;\r
1304 if (Argc == 6) {\r
1305 Temp = StrnCatGrow(&Temp, NULL, Walker, StrStr(Walker, L" ")-Walker);\r
1306 } else {\r
1307 Temp = StrnCatGrow(&Temp, NULL, Walker, 0);\r
1308 }\r
1309 if (EFI_ERROR (NetLibStrToIp4 (Temp, &Gateway.v4))) {\r
1310 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IP_STR), gShellNetwork1HiiHandle, Temp);\r
1311 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1312 goto ON_EXIT;\r
1313 }\r
1314\r
1315 if (Argc == 6) {\r
1316 Walker += StrLen(Temp) + 1;\r
1317 FreePool(Temp);\r
1318 Temp = NULL;\r
1319 Temp = StrnCatGrow(&Temp, NULL, Walker, 0);\r
1320\r
1321 PermTemp = PermanentString;\r
1322 if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {\r
1323 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, Temp, PermanentString, L"Nothing");\r
1324 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1325 goto ON_EXIT;\r
1326 }\r
1327\r
1328 Permanent = TRUE;\r
1329 }\r
1330\r
1331 NetworkBytes1 = NTOHL (Ip.Addr[0]);\r
1332 NetworkBytes2 = NTOHL (Mask.Addr[0]);\r
1333 if ((Ip.Addr[0] == 0) || (Mask.Addr[0] == 0) ||\r
1334 !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {\r
1335\r
1336 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_ADDR_PAIR), gShellNetwork1HiiHandle);\r
1337 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1338 goto ON_EXIT;\r
1339 }\r
1340\r
1341 NetworkBytes1 = NTOHL (Gateway.Addr[0]);\r
1342 if (!IP4_NET_EQUAL (Ip.Addr[0], Gateway.Addr[0], Mask.Addr[0]) ||\r
1343 !NetIp4IsUnicast (NetworkBytes1, NetworkBytes2)) {\r
1344 \r
1345 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle);\r
1346 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1347 goto ON_EXIT;\r
1348 }\r
1349\r
1350 //\r
1351 // Set the configuration up, two route table entries are added:\r
1352 // one for the direct connected network, and another for the \r
1353 // default gateway. Remember, some structure members are cleared\r
1354 // by AllocateZeroPool\r
1355 //\r
1356 Config->Source = IP4_CONFIG_SOURCE_STATIC;\r
1357 Config->Ip4Info.RouteTableSize = 2;\r
1358\r
1359 CopyMem (&Config->Ip4Info.StationAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r
1360 CopyMem (&Config->Ip4Info.SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));\r
1361\r
1362 Ip.Addr[0] = Ip.Addr[0] & Mask.Addr[0];\r
1363\r
1364 CopyMem (&Config->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r
1365 CopyMem (&Config->Ip4Info.RouteTable[0].SubnetMask, &Mask.v4, sizeof (EFI_IPv4_ADDRESS));\r
1366 CopyMem (&Config->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));\r
1367 } else {\r
1368 // neither static or DHCP. error.\r
1369 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle);\r
1370 ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
1371 goto ON_EXIT;\r
1372 }\r
1373\r
1374 CopyMem (&Config->NicAddr, &Info->NicAddress, sizeof (NIC_ADDR));\r
1375 Config->Perment = Permanent;\r
1376\r
1377 //\r
1378 // Use HII service to set NIC address\r
1379 //\r
1380 ShellStatus = IfconfigSetNicAddrByHii (Info, Config);\r
1381 if (ShellStatus != SHELL_SUCCESS) {\r
1382 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_SET_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);\r
1383 goto ON_EXIT;\r
1384 } \r
1385\r
1386 Status = IfconfigStartIp4 (Info);\r
1387 if (EFI_ERROR(Status)) {\r
1388 ShellStatus = SHELL_ACCESS_DENIED;\r
1389 }\r
1390\r
1391 if (ShellStatus != SHELL_SUCCESS) {\r
1392 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_IP_CHILD_FAIL), gShellNetwork1HiiHandle, ShellStatus^MAX_BIT);\r
1393 }\r
1394 \r
1395ON_EXIT:\r
1396 SHELL_FREE_NON_NULL(Config);\r
1397 \r
1398 return ShellStatus;\r
1399}\r
1400\r
1401/**\r
1402 Show the address information for the nic specified.\r
1403\r
1404 @param[in] Name A pointer to the string containg the nic's name, if NULL, \r
1405 all nics' information is shown.\r
1406**/\r
1407VOID\r
1408EFIAPI\r
1409IfconfigShowNicInfo (\r
1410 IN CONST CHAR16 *Name\r
1411 )\r
1412{\r
1413 LIST_ENTRY *Entry;\r
1414 LIST_ENTRY *NextEntry;\r
1415 NIC_INFO *NicInfo;\r
1416 UINT32 Index;\r
1417 EFI_IP4_IPCONFIG_DATA *Ip4Config;\r
1418 EFI_IPv4_ADDRESS Gateway;\r
1419 CONST CHAR16 *TempString;\r
1420\r
1421 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {\r
1422 NicInfo = BASE_CR (Entry, NIC_INFO, Link);\r
1423\r
1424 TempString = (CHAR16*)NicInfo->Name;\r
1425 if ((Name != NULL) && (StringNoCaseCompare (&Name, &TempString) != 0)) {\r
1426 continue;\r
1427 }\r
1428\r
1429 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NAME), gShellNetwork1HiiHandle, NicInfo->Name);\r
1430\r
1431 ShellPrintHiiEx(\r
1432 -1,\r
1433 -1,\r
1434 NULL,\r
1435 STRING_TOKEN(STR_IFCONFIG_SHOW_MAC_ADDR), \r
1436 gShellNetwork1HiiHandle, \r
1437 (UINTN)NicInfo->NicAddress.MacAddr.Addr[0], \r
1438 (UINTN)NicInfo->NicAddress.MacAddr.Addr[1], \r
1439 (UINTN)NicInfo->NicAddress.MacAddr.Addr[2],\r
1440 (UINTN)NicInfo->NicAddress.MacAddr.Addr[3], \r
1441 (UINTN)NicInfo->NicAddress.MacAddr.Addr[4], \r
1442 (UINTN)NicInfo->NicAddress.MacAddr.Addr[5]\r
1443 ); \r
1444\r
1445 Print (L" Media State: %s\n", NicInfo->MediaPresent ? L"Media present" : L"Media disconnected");\r
1446\r
1447 if (NicInfo->ConfigInfo == NULL) {\r
1448 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_NIC_NOT_CONFIGURED), gShellNetwork1HiiHandle);\r
1449 continue;\r
1450 } \r
1451\r
1452 if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_DHCP) {\r
1453 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"DHCP");\r
1454 } else if (NicInfo->ConfigInfo->Source == IP4_CONFIG_SOURCE_STATIC) {\r
1455 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"STATIC");\r
1456 } else {\r
1457 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_CONFIG_SOURCE), gShellNetwork1HiiHandle, L"Unknown");\r
1458 }\r
1459\r
1460 ShellPrintHiiEx(-1, -1, NULL,\r
1461 STRING_TOKEN (STR_IFCONFIG_PERMENT_STATUS),\r
1462 gShellNetwork1HiiHandle,\r
1463 (NicInfo->ConfigInfo->Perment? L"TRUE":L"FALSE")\r
1464 );\r
1465\r
1466 Ip4Config = &NicInfo->ConfigInfo->Ip4Info;\r
1467\r
1468 ShellPrintHiiEx(\r
1469 -1, \r
1470 -1, \r
1471 NULL,\r
1472 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1473 gShellNetwork1HiiHandle, \r
1474 L"IP address",\r
1475 (UINTN)Ip4Config->StationAddress.Addr[0],\r
1476 (UINTN)Ip4Config->StationAddress.Addr[1],\r
1477 (UINTN)Ip4Config->StationAddress.Addr[2],\r
1478 (UINTN)Ip4Config->StationAddress.Addr[3]\r
1479 );\r
1480 ShellPrintHiiEx(\r
1481 -1, \r
1482 -1, \r
1483 NULL,\r
1484 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1485 gShellNetwork1HiiHandle, \r
1486 L"Mask",\r
1487 (UINTN)Ip4Config->SubnetMask.Addr[0],\r
1488 (UINTN)Ip4Config->SubnetMask.Addr[1],\r
1489 (UINTN)Ip4Config->SubnetMask.Addr[2],\r
1490 (UINTN)Ip4Config->SubnetMask.Addr[3]\r
1491 );\r
1492\r
1493 ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));\r
1494 \r
1495 for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {\r
1496 if ((CompareMem (&Ip4Config->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&\r
1497 (CompareMem (&Ip4Config->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){\r
1498 CopyMem (&Gateway, &Ip4Config->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
1499 }\r
1500 }\r
1501 \r
1502 ShellPrintHiiEx(\r
1503 -1, \r
1504 -1, \r
1505 NULL,\r
1506 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1507 gShellNetwork1HiiHandle, \r
1508 L"Gateway",\r
1509 (UINTN)Gateway.Addr[0],\r
1510 (UINTN)Gateway.Addr[1],\r
1511 (UINTN)Gateway.Addr[2],\r
1512 (UINTN)Gateway.Addr[3]\r
1513 );\r
1514\r
1515 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, Ip4Config->RouteTableSize);\r
1516\r
1517 for (Index = 0; Index < Ip4Config->RouteTableSize; Index++) {\r
1518 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);\r
1519\r
1520 ShellPrintHiiEx(\r
1521 -1, \r
1522 -1, \r
1523 NULL,\r
1524 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1525 gShellNetwork1HiiHandle, \r
1526 L"Subnet",\r
1527 (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[0],\r
1528 (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[1],\r
1529 (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[2],\r
1530 (UINTN)Ip4Config->RouteTable[Index].SubnetAddress.Addr[3]\r
1531 );\r
1532\r
1533 ShellPrintHiiEx(\r
1534 -1, \r
1535 -1, \r
1536 NULL,\r
1537 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1538 gShellNetwork1HiiHandle, \r
1539 L"Netmask",\r
1540 (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[0],\r
1541 (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[1],\r
1542 (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[2],\r
1543 (UINTN)Ip4Config->RouteTable[Index].SubnetMask.Addr[3]\r
1544 );\r
1545\r
1546 ShellPrintHiiEx(\r
1547 -1, \r
1548 -1, \r
1549 NULL,\r
1550 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
1551 gShellNetwork1HiiHandle, \r
1552 L"Gateway",\r
1553 (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[0],\r
1554 (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[1],\r
1555 (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[2],\r
1556 (UINTN)Ip4Config->RouteTable[Index].GatewayAddress.Addr[3]\r
1557 );\r
1558 }\r
1559 }\r
1560\r
1561 return ;\r
1562}\r
1563\r
1564/**\r
1565 Clear address configuration for the nic specified.\r
1566\r
1567 @param[in] Name A pointer to the string containg the nic's name, \r
1568 if NULL, all nics address configurations are cleared.\r
1569\r
1570 @retval EFI_SUCCESS The address configuration is cleared.\r
1571 @return Some error occurs.\r
1572**/\r
1573EFI_STATUS\r
1574EFIAPI\r
1575IfconfigClearNicAddr (\r
1576 IN CONST CHAR16 *Name\r
1577 )\r
1578{\r
1579 LIST_ENTRY *Entry;\r
1580 LIST_ENTRY *NextEntry;\r
1581 NIC_INFO *Info;\r
1582 EFI_STATUS Status;\r
1583 \r
1584 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &NicInfoList) {\r
1585 Info = BASE_CR (Entry, NIC_INFO, Link);\r
1586\r
1587 if ((Name != NULL) && (StrCmp (Name, Info->Name) != 0)) {\r
1588 continue;\r
1589 }\r
1590\r
1591// if (Info->NicIp4Config == NULL) { \r
1592 Status = IfconfigSetNicAddrByHii (Info, NULL);\r
1593// } else {\r
1594// Status = Info->NicIp4Config->SetInfo (Info->NicIp4Config, NULL, TRUE);\r
1595// }\r
1596\r
1597 if (EFI_ERROR (Status)) {\r
1598 return Status;\r
1599 }\r
1600 }\r
1601\r
1602 return EFI_SUCCESS;\r
1603 \r
1604}\r
1605\r
1606/**\r
1607 Function for 'ifconfig' command.\r
1608\r
1609 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
1610 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
1611**/\r
1612SHELL_STATUS\r
1613EFIAPI\r
1614ShellCommandRunIfconfig (\r
1615 IN EFI_HANDLE ImageHandle,\r
1616 IN EFI_SYSTEM_TABLE *SystemTable\r
1617 )\r
1618{\r
1619 EFI_STATUS Status;\r
1620 LIST_ENTRY *Package;\r
1621 CHAR16 *ProblemParam;\r
1622 SHELL_STATUS ShellStatus;\r
1623 BOOLEAN ListOperation;\r
1624 BOOLEAN ClearOperation;\r
1625 BOOLEAN SetOperation;\r
1626 CONST CHAR16 *Item;\r
1627 LIST_ENTRY *Entry;\r
1628 NIC_INFO *Info;\r
1629\r
1630 InitializeListHead (&NicInfoList);\r
1631 Status = EFI_INVALID_PARAMETER;\r
1632 ShellStatus = SHELL_SUCCESS;\r
1633\r
1634 //\r
1635 // initialize the shell lib (we must be in non-auto-init...)\r
1636 //\r
1637 Status = ShellInitialize();\r
1638 ASSERT_EFI_ERROR(Status);\r
1639\r
1640 //\r
1641 // parse the command line\r
1642 //\r
1643 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
1644 if (EFI_ERROR(Status)) {\r
1645 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
1646 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellNetwork1HiiHandle, ProblemParam);\r
1647 FreePool(ProblemParam);\r
1648 ShellStatus = SHELL_INVALID_PARAMETER;\r
1649 } else {\r
1650 ASSERT(FALSE);\r
1651 }\r
1652\r
1653 goto Done;\r
1654 }\r
1655\r
1656 ClearOperation = ShellCommandLineGetFlag(Package, L"-c");\r
1657 ListOperation = ShellCommandLineGetFlag(Package, L"-l");\r
1658 SetOperation = ShellCommandLineGetFlag(Package, L"-s");\r
1659\r
1660 if (ClearOperation && ListOperation \r
1661 ||SetOperation && ListOperation \r
1662 ||ClearOperation && SetOperation \r
1663 ) {\r
1664 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle);\r
1665 ShellStatus = SHELL_INVALID_PARAMETER;\r
1666 goto Done;\r
1667 } else if (!ClearOperation && !ListOperation && !SetOperation) {\r
1668 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle);\r
1669 ShellStatus = SHELL_INVALID_PARAMETER;\r
1670 goto Done;\r
1671 }\r
1672 \r
1673 \r
1674 Status = IfconfigGetAllNicInfoByHii ();\r
1675 if (EFI_ERROR (Status)) {\r
1676 if (mIp4ConfigExist) {\r
1677 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL), gShellNetwork1HiiHandle, Status);\r
1678 } else {\r
1679 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellNetwork1HiiHandle, L"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid);\r
1680 }\r
1681\r
1682 return SHELL_NOT_FOUND;\r
1683 }\r
1684\r
1685 if (ListOperation) {\r
1686 Item = ShellCommandLineGetValue (Package, L"-l");\r
1687\r
1688 if (Item != NULL && CountSubItems(Item) > 1) {\r
1689 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"-l");\r
1690 ShellStatus = SHELL_INVALID_PARAMETER;\r
1691 goto Done;\r
1692 } \r
1693 \r
1694 //\r
1695 // Show the configuration.\r
1696 //\r
1697 IfconfigShowNicInfo (Item);\r
1698 } else if (SetOperation) {\r
1699 Item = ShellCommandLineGetValue (Package, L"-s");\r
1700\r
1701 //\r
1702 // The correct command line arguments for setting address are:\r
1703 // IfConfig -s eth0 DHCP [perment]\r
1704 // IfConfig -s eth0 static ip netmask gateway [perment]\r
1705 //\r
1706 if (Item == NULL || (CountSubItems(Item) < 2) || (CountSubItems(Item) > 6) || (CountSubItems(Item) == 4)) {\r
1707 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"-s");\r
1708 ShellStatus = SHELL_INVALID_PARAMETER;\r
1709 goto Done;\r
1710 }\r
1711\r
1712 ShellStatus = IfconfigSetNicAddr (CountSubItems(Item), Item);\r
1713 } else if (ClearOperation) {\r
1714 Item = ShellCommandLineGetValue (Package, L"-c");\r
1715\r
1716 if (Item != NULL && CountSubItems(Item) > 1) {\r
1717 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"-c");\r
1718 ShellStatus = SHELL_INVALID_PARAMETER;\r
1719 goto Done;\r
1720 }\r
1721\r
1722 IfconfigClearNicAddr (Item);\r
1723 } else {\r
1724 ASSERT(FALSE);\r
1725 }\r
1726\r
1727Done:\r
1728 while (!IsListEmpty (&NicInfoList)) {\r
1729 Entry = NicInfoList.ForwardLink;\r
1730 Info = BASE_CR (Entry, NIC_INFO, Link);\r
1731\r
1732 RemoveEntryList (Entry);\r
1733\r
1734 if (Info->ConfigInfo != NULL) {\r
1735 FreePool (Info->ConfigInfo);\r
1736 }\r
1737\r
1738 FreePool (Info);\r
1739 }\r
1740\r
1741 if (Package != NULL) {\r
1742 ShellCommandLineFreeVarList(Package);\r
1743 }\r
1744\r
1745 return (ShellStatus);\r
1746}\r