ShellPkg: Update ping/ifconfig library source code to consume Ip4Config2 protocol.
[mirror_edk2.git] / ShellPkg / Library / UefiShellNetwork1CommandsLib / Ifconfig.c
CommitLineData
68fb0527 1/** @file\r
7c25b7ea 2 The implementation for Shell command ifconfig based on IP4Config2 protocol.\r
68fb0527 3\r
c011b6c9 4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
e75390f0 5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
68fb0527 6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
7c25b7ea 14\r
68fb0527 15**/\r
16\r
17#include "UefiShellNetwork1CommandsLib.h"\r
18\r
7c25b7ea 19typedef enum {\r
20 IfConfigOpList = 1,\r
21 IfConfigOpSet = 2,\r
22 IfConfigOpClear = 3\r
23} IFCONFIG_OPCODE;\r
24\r
25typedef enum {\r
26 VarCheckReserved = -1,\r
27 VarCheckOk = 0,\r
28 VarCheckDuplicate,\r
29 VarCheckConflict,\r
30 VarCheckUnknown,\r
31 VarCheckLackValue,\r
32 VarCheckOutOfMem\r
33} VAR_CHECK_CODE;\r
34\r
35typedef enum {\r
36 FlagTypeSingle = 0,\r
37 FlagTypeNeedVar,\r
38 FlagTypeNeedSet,\r
39 FlagTypeSkipUnknown\r
40} VAR_CHECK_FLAG_TYPE;\r
41\r
42#define MACADDRMAXSIZE 32\r
43\r
44typedef struct _IFCONFIG_INTERFACE_CB {\r
45 EFI_HANDLE NicHandle;\r
46 LIST_ENTRY Link;\r
47 EFI_IP4_CONFIG2_PROTOCOL *IfCfg;\r
48 EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo; \r
49 EFI_IP4_CONFIG2_POLICY Policy;\r
50 UINT32 DnsCnt;\r
51 EFI_IPv4_ADDRESS DnsAddr[1];\r
52} IFCONFIG_INTERFACE_CB;\r
53\r
54typedef struct _ARG_LIST ARG_LIST;\r
55\r
56struct _ARG_LIST {\r
57 ARG_LIST *Next;\r
58 CHAR16 *Arg;\r
59};\r
60\r
61typedef struct _IFCONFIG4_PRIVATE_DATA {\r
62 LIST_ENTRY IfList;\r
63\r
64 UINT32 OpCode;\r
65 CHAR16 *IfName;\r
66 ARG_LIST *VarArg;\r
67} IFCONFIG_PRIVATE_DATA;\r
68\r
69typedef struct _VAR_CHECK_ITEM{\r
70 CHAR16 *FlagStr;\r
71 UINT32 FlagID;\r
72 UINT32 ConflictMask;\r
73 VAR_CHECK_FLAG_TYPE FlagType;\r
74} VAR_CHECK_ITEM;\r
75\r
76SHELL_PARAM_ITEM mIfConfigCheckList[] = {\r
77 {\r
78 L"-b",\r
79 TypeFlag\r
80 },\r
81 {\r
82 L"-l",\r
83 TypeValue\r
84 },\r
85 {\r
86 L"-r",\r
87 TypeValue\r
88 },\r
89 {\r
90 L"-c",\r
91 TypeValue\r
92 },\r
93 {\r
94 L"-s",\r
95 TypeMaxValue\r
96 },\r
97 {\r
98 NULL,\r
99 TypeMax\r
100 },\r
101};\r
102\r
103VAR_CHECK_ITEM mSetCheckList[] = {\r
104 {\r
105 L"static",\r
106 0x00000001,\r
107 0x00000001,\r
108 FlagTypeSingle\r
109 },\r
110 {\r
111 L"dhcp",\r
112 0x00000002,\r
113 0x00000001,\r
114 FlagTypeSingle\r
115 },\r
116 {\r
117 L"dns",\r
118 0x00000008,\r
119 0x00000004,\r
120 FlagTypeSingle\r
121 },\r
122 {\r
123 NULL,\r
124 0x0,\r
125 0x0,\r
126 FlagTypeSkipUnknown\r
127 },\r
128};\r
68fb0527 129\r
68fb0527 130STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";\r
131\r
68fb0527 132/**\r
7c25b7ea 133 Split a string with specified separator and save the substring to a list.\r
68fb0527 134\r
7c25b7ea 135 @param[in] String The pointer of the input string.\r
136 @param[in] Separator The specified separator.\r
68fb0527 137\r
7c25b7ea 138 @return The pointer of headnode of ARG_LIST.\r
68fb0527 139\r
68fb0527 140**/\r
7c25b7ea 141ARG_LIST *\r
142SplitStrToList (\r
143 IN CONST CHAR16 *String,\r
144 IN CHAR16 Separator\r
68fb0527 145 )\r
146{\r
7c25b7ea 147 CHAR16 *Str;\r
148 CHAR16 *ArgStr;\r
149 ARG_LIST *ArgList;\r
150 ARG_LIST *ArgNode;\r
68fb0527 151\r
7c25b7ea 152 if (*String == L'\0') {\r
153 return NULL;\r
68fb0527 154 }\r
155\r
68fb0527 156 //\r
7c25b7ea 157 // Copy the CONST string to a local copy.\r
68fb0527 158 //\r
7c25b7ea 159 Str = AllocateCopyPool (StrSize (String), String);\r
160 ASSERT (Str != NULL);\r
161 ArgStr = Str;\r
68fb0527 162\r
163 //\r
7c25b7ea 164 // init a node for the list head.\r
68fb0527 165 //\r
7c25b7ea 166 ArgNode = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));\r
167 ASSERT (ArgNode != NULL);\r
168 ArgList = ArgNode;\r
68fb0527 169\r
170 //\r
7c25b7ea 171 // Split the local copy and save in the list node.\r
68fb0527 172 //\r
7c25b7ea 173 while (*Str != L'\0') {\r
174 if (*Str == Separator) {\r
175 *Str = L'\0';\r
176 ArgNode->Arg = ArgStr;\r
177 ArgStr = Str + 1;\r
178 ArgNode->Next = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));\r
179 ASSERT (ArgNode->Next != NULL);\r
180 ArgNode = ArgNode->Next;\r
68fb0527 181 }\r
7c25b7ea 182\r
183 Str++;\r
68fb0527 184 }\r
185\r
7c25b7ea 186 ArgNode->Arg = ArgStr;\r
187 ArgNode->Next = NULL;\r
188\r
189 return ArgList;\r
68fb0527 190}\r
191\r
192/**\r
7c25b7ea 193 Check the correctness of input Args with '-s' option.\r
68fb0527 194\r
7c25b7ea 195 @param[in] CheckList The pointer of VAR_CHECK_ITEM array.\r
196 @param[in] Name The pointer of input arg.\r
197 @param[in] Init The switch to execute the check.\r
68fb0527 198\r
7c25b7ea 199 @return VarCheckOk Valid parameter or Initialize check successfully.\r
200 @return VarCheckDuplicate Duplicated parameter happened.\r
201 @return VarCheckConflict Conflicted parameter happened\r
202 @return VarCheckUnknown Unknown parameter.\r
68fb0527 203\r
68fb0527 204**/\r
7c25b7ea 205VAR_CHECK_CODE\r
206IfConfigRetriveCheckListByName(\r
207 IN VAR_CHECK_ITEM *CheckList,\r
208 IN CHAR16 *Name,\r
209 IN BOOLEAN Init\r
210)\r
68fb0527 211{\r
7c25b7ea 212 STATIC UINT32 CheckDuplicate;\r
213 STATIC UINT32 CheckConflict;\r
214 VAR_CHECK_CODE RtCode;\r
215 UINT32 Index;\r
216 VAR_CHECK_ITEM Arg;\r
217\r
218 if (Init) {\r
219 CheckDuplicate = 0;\r
220 CheckConflict = 0;\r
221 return VarCheckOk;\r
68fb0527 222 }\r
223\r
7c25b7ea 224 RtCode = VarCheckOk;\r
225 Index = 0;\r
226 Arg = CheckList[Index];\r
68fb0527 227\r
228 //\r
7c25b7ea 229 // Check the Duplicated/Conflicted/Unknown input Args.\r
68fb0527 230 //\r
7c25b7ea 231 while (Arg.FlagStr != NULL) {\r
232 if (StrCmp (Arg.FlagStr, Name) == 0) {\r
68fb0527 233\r
7c25b7ea 234 if (CheckDuplicate & Arg.FlagID) {\r
235 RtCode = VarCheckDuplicate;\r
236 break;\r
237 }\r
68fb0527 238\r
7c25b7ea 239 if (CheckConflict & Arg.ConflictMask) {\r
240 RtCode = VarCheckConflict;\r
241 break;\r
242 }\r
68fb0527 243\r
7c25b7ea 244 CheckDuplicate |= Arg.FlagID;\r
245 CheckConflict |= Arg.ConflictMask;\r
246 break;\r
247 }\r
68fb0527 248\r
7c25b7ea 249 Arg = CheckList[++Index];\r
68fb0527 250 }\r
7c25b7ea 251\r
252 if (Arg.FlagStr == NULL) {\r
253 RtCode = VarCheckUnknown;\r
68fb0527 254 }\r
255\r
7c25b7ea 256 return RtCode;\r
68fb0527 257}\r
258\r
259/**\r
7c25b7ea 260 The notify function of create event when performing a manual config.\r
68fb0527 261\r
7c25b7ea 262 @param[in] Event The event this notify function registered to.\r
263 @param[in] Context Pointer to the context data registered to the event.\r
68fb0527 264\r
7c25b7ea 265**/\r
266VOID\r
68fb0527 267EFIAPI\r
7c25b7ea 268IfConfigManualAddressNotify (\r
269 IN EFI_EVENT Event,\r
270 IN VOID *Context\r
271 )\r
68fb0527 272{\r
7c25b7ea 273 *((BOOLEAN *) Context) = TRUE;\r
68fb0527 274}\r
275\r
7c25b7ea 276\r
68fb0527 277/**\r
7c25b7ea 278 Print MAC address.\r
68fb0527 279\r
7c25b7ea 280 @param[in] Node The pointer of MAC address buffer.\r
281 @param[in] Size The size of MAC address buffer.\r
68fb0527 282\r
68fb0527 283**/\r
7c25b7ea 284VOID\r
285IfConfigPrintMacAddr (\r
286 IN UINT8 *Node,\r
287 IN UINT32 Size\r
288 )\r
68fb0527 289{\r
7c25b7ea 290 UINTN Index;\r
68fb0527 291\r
7c25b7ea 292 ASSERT (Size <= MACADDRMAXSIZE);\r
68fb0527 293\r
7c25b7ea 294 for (Index = 0; Index < Size; Index++) {\r
295 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_BODY), gShellNetwork1HiiHandle, Node[Index]);\r
296 if (Index + 1 < Size) {\r
297 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_COLON), gShellNetwork1HiiHandle);\r
298 }\r
68fb0527 299 }\r
68fb0527 300\r
7c25b7ea 301 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE), gShellNetwork1HiiHandle);\r
302}\r
68fb0527 303\r
68fb0527 304\r
7c25b7ea 305/**\r
306 The get current status of all handles.\r
68fb0527 307\r
7c25b7ea 308 @param[in] IfName The pointer of IfName(interface name).\r
309 @param[in] IfList The pointer of IfList(interface list).\r
68fb0527 310\r
7c25b7ea 311 @retval EFI_SUCCESS The get status processed successfully.\r
312 @retval others The get status process failed.\r
68fb0527 313\r
68fb0527 314**/\r
315EFI_STATUS\r
7c25b7ea 316IfConfigGetInterfaceInfo (\r
317 IN CHAR16 *IfName,\r
318 IN LIST_ENTRY *IfList\r
68fb0527 319 )\r
320{\r
7c25b7ea 321 EFI_STATUS Status;\r
322 UINTN HandleIndex;\r
323 UINTN HandleNum;\r
324 EFI_HANDLE *HandleBuffer;\r
325 EFI_IP4_CONFIG2_PROTOCOL *Ip4Cfg2;\r
326 EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;\r
327 IFCONFIG_INTERFACE_CB *IfCb;\r
328 UINTN DataSize;\r
68fb0527 329\r
7c25b7ea 330 HandleBuffer = NULL;\r
331 HandleNum = 0;\r
332\r
333 IfInfo = NULL;\r
334 IfCb = NULL;\r
68fb0527 335\r
336 //\r
7c25b7ea 337 // Locate all the handles with ip4 service binding protocol.\r
68fb0527 338 //\r
339 Status = gBS->LocateHandleBuffer (\r
7c25b7ea 340 ByProtocol,\r
341 &gEfiIp4ServiceBindingProtocolGuid,\r
342 NULL,\r
343 &HandleNum,\r
344 &HandleBuffer\r
68fb0527 345 );\r
7c25b7ea 346 if (EFI_ERROR (Status) || (HandleNum == 0)) {\r
347 return EFI_ABORTED;\r
68fb0527 348 }\r
349\r
7c25b7ea 350 //\r
351 // Enumerate all handles that installed with ip4 service binding protocol.\r
352 //\r
353 for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {\r
354 IfCb = NULL;\r
355 IfInfo = NULL;\r
356 DataSize = 0;\r
357\r
358 //\r
359 // Ip4config protocol and ip4 service binding protocol are installed\r
360 // on the same handle.\r
361 //\r
362 ASSERT (HandleBuffer != NULL);\r
363 Status = gBS->HandleProtocol (\r
364 HandleBuffer[HandleIndex],\r
365 &gEfiIp4Config2ProtocolGuid,\r
366 (VOID **) &Ip4Cfg2\r
367 );\r
368\r
68fb0527 369 if (EFI_ERROR (Status)) {\r
7c25b7ea 370 goto ON_ERROR;\r
68fb0527 371 }\r
7c25b7ea 372 \r
68fb0527 373 //\r
7c25b7ea 374 // Get the interface information size.\r
68fb0527 375 //\r
7c25b7ea 376 Status = Ip4Cfg2->GetData (\r
377 Ip4Cfg2,\r
378 Ip4Config2DataTypeInterfaceInfo,\r
379 &DataSize,\r
380 NULL\r
381 );\r
382\r
383 if (Status != EFI_BUFFER_TOO_SMALL) {\r
384 goto ON_ERROR;\r
33c031ee 385 }\r
7c25b7ea 386\r
387 IfInfo = AllocateZeroPool (DataSize);\r
388\r
389 if (IfInfo == NULL) {\r
68fb0527 390 Status = EFI_OUT_OF_RESOURCES;\r
391 goto ON_ERROR;\r
392 }\r
7c25b7ea 393 \r
68fb0527 394 //\r
7c25b7ea 395 // Get the interface info.\r
68fb0527 396 //\r
7c25b7ea 397 Status = Ip4Cfg2->GetData (\r
398 Ip4Cfg2,\r
399 Ip4Config2DataTypeInterfaceInfo,\r
400 &DataSize,\r
401 IfInfo\r
402 );\r
68fb0527 403\r
7c25b7ea 404 if (EFI_ERROR (Status)) {\r
68fb0527 405 goto ON_ERROR;\r
406 }\r
7c25b7ea 407 \r
68fb0527 408 //\r
7c25b7ea 409 // Check the interface name if required.\r
68fb0527 410 //\r
7c25b7ea 411 if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) != 0)) {\r
412 FreePool (IfInfo);\r
413 continue;\r
68fb0527 414 }\r
415\r
7c25b7ea 416 DataSize = 0;\r
417 \r
68fb0527 418 //\r
7c25b7ea 419 // Get the size of dns server list.\r
68fb0527 420 //\r
7c25b7ea 421 Status = Ip4Cfg2->GetData (\r
422 Ip4Cfg2,\r
423 Ip4Config2DataTypeDnsServer,\r
424 &DataSize,\r
425 NULL\r
426 );\r
427\r
428 if ((Status != EFI_BUFFER_TOO_SMALL) && (Status != EFI_NOT_FOUND)) {\r
429 goto ON_ERROR;\r
430 }\r
431\r
432 IfCb = AllocateZeroPool (sizeof (IFCONFIG_INTERFACE_CB) + DataSize);\r
68fb0527 433\r
7c25b7ea 434 if (IfCb == NULL) {\r
68fb0527 435 Status = EFI_OUT_OF_RESOURCES;\r
436 goto ON_ERROR;\r
437 }\r
438\r
7c25b7ea 439 IfCb->NicHandle = HandleBuffer[HandleIndex];\r
440 IfCb->IfInfo = IfInfo;\r
441 IfCb->IfCfg = Ip4Cfg2;\r
442 IfCb->DnsCnt = (UINT32) (DataSize / sizeof (EFI_IPv4_ADDRESS));\r
443\r
68fb0527 444 //\r
7c25b7ea 445 // Get the dns server list if has.\r
68fb0527 446 //\r
7c25b7ea 447 if (DataSize > 0) {\r
448 Status = Ip4Cfg2->GetData (\r
449 Ip4Cfg2,\r
450 Ip4Config2DataTypeDnsServer,\r
451 &DataSize,\r
452 IfCb->DnsAddr\r
453 );\r
454\r
455 if (EFI_ERROR (Status)) {\r
456 goto ON_ERROR;\r
68fb0527 457 }\r
68fb0527 458 }\r
459\r
460 //\r
7c25b7ea 461 // Get the config policy.\r
68fb0527 462 //\r
7c25b7ea 463 DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);\r
464 Status = Ip4Cfg2->GetData (\r
465 Ip4Cfg2,\r
466 Ip4Config2DataTypePolicy,\r
467 &DataSize,\r
468 &IfCb->Policy\r
469 );\r
470\r
471 if (EFI_ERROR (Status)) {\r
472 goto ON_ERROR;\r
473 }\r
474\r
475 InsertTailList (IfList, &IfCb->Link);\r
68fb0527 476\r
7c25b7ea 477 if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) == 0)) {\r
478 //\r
479 // Only need the appointed interface, keep the allocated buffer.\r
480 //\r
481 IfCb = NULL;\r
482 IfInfo = NULL;\r
483 break;\r
484 }\r
68fb0527 485 }\r
486\r
7c25b7ea 487 if (HandleBuffer != NULL) {\r
488 FreePool (HandleBuffer);\r
489 }\r
68fb0527 490\r
491 return EFI_SUCCESS;\r
7c25b7ea 492\r
68fb0527 493ON_ERROR:\r
7c25b7ea 494\r
495 if (IfInfo != NULL) {\r
496 FreePool (IfInfo);\r
68fb0527 497 }\r
498\r
7c25b7ea 499 if (IfCb != NULL) {\r
500 FreePool (IfCb);\r
501 }\r
68fb0527 502\r
503 return Status;\r
504}\r
505\r
506/**\r
7c25b7ea 507 The list process of the ifconfig command.\r
68fb0527 508\r
7c25b7ea 509 @param[in] IfList The pointer of IfList(interface list).\r
510\r
511 @retval EFI_SUCCESS The ifconfig command list processed successfully.\r
512 @retval others The ifconfig command list process failed.\r
68fb0527 513\r
68fb0527 514**/\r
7c25b7ea 515EFI_STATUS\r
516IfConfigShowInterfaceInfo (\r
517 IN LIST_ENTRY *IfList\r
68fb0527 518 )\r
519{\r
7c25b7ea 520 EFI_STATUS Status;\r
521 LIST_ENTRY *Entry;\r
522 LIST_ENTRY *Next;\r
523 IFCONFIG_INTERFACE_CB *IfCb;\r
524 EFI_IPv4_ADDRESS Gateway;\r
525 UINT32 Index;\r
68fb0527 526\r
7c25b7ea 527 Status = EFI_SUCCESS;\r
68fb0527 528\r
7c25b7ea 529 if (IsListEmpty (IfList)) {\r
530 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);\r
68fb0527 531 }\r
532\r
533 //\r
7c25b7ea 534 // Go through the interface list.\r
68fb0527 535 //\r
7c25b7ea 536 NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {\r
537 IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);\r
68fb0527 538\r
7c25b7ea 539 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK), gShellNetwork1HiiHandle);\r
68fb0527 540\r
7c25b7ea 541 //\r
542 // Print interface name.\r
543 //\r
544 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_IF_NAME), gShellNetwork1HiiHandle, IfCb->IfInfo->Name);\r
68fb0527 545\r
7c25b7ea 546 //\r
547 // Print interface config policy.\r
548 //\r
549 if (IfCb->Policy == Ip4Config2PolicyDhcp) {\r
550 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_DHCP), gShellNetwork1HiiHandle);\r
551 } else {\r
552 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_POLICY_MAN), gShellNetwork1HiiHandle);\r
553 }\r
68fb0527 554\r
7c25b7ea 555 //\r
556 // Print mac address of the interface.\r
557 //\r
558 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_MAC_ADDR_HEAD), gShellNetwork1HiiHandle);\r
68fb0527 559\r
7c25b7ea 560 IfConfigPrintMacAddr (\r
561 IfCb->IfInfo->HwAddress.Addr,\r
562 IfCb->IfInfo->HwAddressSize\r
563 );\r
68fb0527 564\r
7c25b7ea 565 //\r
566 // Print IPv4 address list of the interface.\r
567 //\r
568 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_HEAD), gShellNetwork1HiiHandle);\r
68fb0527 569\r
7c25b7ea 570 ShellPrintHiiEx(\r
571 -1, \r
572 -1, \r
573 NULL,\r
574 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY), \r
575 gShellNetwork1HiiHandle,\r
576 (UINTN)IfCb->IfInfo->StationAddress.Addr[0],\r
577 (UINTN)IfCb->IfInfo->StationAddress.Addr[1],\r
578 (UINTN)IfCb->IfInfo->StationAddress.Addr[2],\r
579 (UINTN)IfCb->IfInfo->StationAddress.Addr[3]\r
580 );\r
581\r
582 //\r
583 // Print subnet mask list of the interface.\r
584 //\r
585 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_SUBNET_MASK_HEAD), gShellNetwork1HiiHandle);\r
68fb0527 586\r
68fb0527 587 ShellPrintHiiEx(\r
588 -1, \r
589 -1, \r
590 NULL,\r
7c25b7ea 591 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY), \r
592 gShellNetwork1HiiHandle,\r
593 (UINTN)IfCb->IfInfo->SubnetMask.Addr[0],\r
594 (UINTN)IfCb->IfInfo->SubnetMask.Addr[1],\r
595 (UINTN)IfCb->IfInfo->SubnetMask.Addr[2],\r
596 (UINTN)IfCb->IfInfo->SubnetMask.Addr[3]\r
68fb0527 597 );\r
68fb0527 598\r
7c25b7ea 599 //\r
600 // Print default gateway of the interface.\r
601 //\r
602 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_GATEWAY_HEAD), gShellNetwork1HiiHandle);\r
603\r
604 ZeroMem (&Gateway, sizeof (EFI_IPv4_ADDRESS));\r
605 \r
606 for (Index = 0; Index < IfCb->IfInfo->RouteTableSize; Index++) {\r
607 if ((CompareMem (&IfCb->IfInfo->RouteTable[Index].SubnetAddress, &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) &&\r
608 (CompareMem (&IfCb->IfInfo->RouteTable[Index].SubnetMask , &mZeroIp4Addr, sizeof (EFI_IPv4_ADDRESS)) == 0) ){\r
609 CopyMem (&Gateway, &IfCb->IfInfo->RouteTable[Index].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
610 }\r
611 } \r
612\r
68fb0527 613 ShellPrintHiiEx(\r
7c25b7ea 614 -1, \r
615 -1, \r
616 NULL,\r
617 STRING_TOKEN (STR_IFCONFIG_INFO_IP_ADDR_BODY), \r
618 gShellNetwork1HiiHandle,\r
619 (UINTN)Gateway.Addr[0],\r
620 (UINTN)Gateway.Addr[1],\r
621 (UINTN)Gateway.Addr[2],\r
622 (UINTN)Gateway.Addr[3]\r
623 );\r
624 \r
625 //\r
626 // Print route table entry.\r
627 //\r
628 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_SIZE), gShellNetwork1HiiHandle, IfCb->IfInfo->RouteTableSize);\r
629\r
630 for (Index = 0; Index < IfCb->IfInfo->RouteTableSize; Index++) {\r
631 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_ROUTES_ENTRY_INDEX), gShellNetwork1HiiHandle, Index);\r
632\r
633 ShellPrintHiiEx(\r
634 -1, \r
635 -1, \r
636 NULL,\r
637 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
638 gShellNetwork1HiiHandle, \r
639 L"Subnet ",\r
640 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[0],\r
641 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[1],\r
642 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[2],\r
643 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetAddress.Addr[3]\r
644 );\r
645\r
646 ShellPrintHiiEx(\r
647 -1, \r
648 -1, \r
649 NULL,\r
650 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
651 gShellNetwork1HiiHandle, \r
652 L"Netmask",\r
653 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[0],\r
654 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[1],\r
655 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[2],\r
656 (UINTN)IfCb->IfInfo->RouteTable[Index].SubnetMask.Addr[3]\r
657 );\r
658\r
659 ShellPrintHiiEx(\r
660 -1, \r
661 -1, \r
662 NULL,\r
663 STRING_TOKEN (STR_IFCONFIG_SHOW_IP_ADDR), \r
664 gShellNetwork1HiiHandle, \r
665 L"Gateway",\r
666 (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[0],\r
667 (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[1],\r
668 (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[2],\r
669 (UINTN)IfCb->IfInfo->RouteTable[Index].GatewayAddress.Addr[3]\r
670 );\r
671 }\r
672\r
673 //\r
674 // Print dns server addresses list of the interface if has.\r
675 //\r
676 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_HEAD), gShellNetwork1HiiHandle);\r
677\r
678 for (Index = 0; Index < IfCb->DnsCnt; Index++) {\r
679 ShellPrintHiiEx(\r
680 -1, \r
681 -1, \r
682 NULL,\r
683 STRING_TOKEN (STR_IFCONFIG_INFO_DNS_ADDR_BODY), \r
684 gShellNetwork1HiiHandle,\r
685 (UINTN) IfCb->DnsAddr[Index].Addr[0],\r
686 (UINTN) IfCb->DnsAddr[Index].Addr[1],\r
687 (UINTN) IfCb->DnsAddr[Index].Addr[2],\r
688 (UINTN) IfCb->DnsAddr[Index].Addr[3]\r
689 );\r
690\r
691 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_NEWLINE), gShellNetwork1HiiHandle);\r
692 }\r
68fb0527 693 }\r
7c25b7ea 694 \r
695 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INFO_BREAK), gShellNetwork1HiiHandle);\r
68fb0527 696\r
7c25b7ea 697 return EFI_SUCCESS;\r
68fb0527 698}\r
699\r
700/**\r
7c25b7ea 701 The clean process of the ifconfig command to clear interface info.\r
702\r
703 @param[in] IfList The pointer of IfList(interface list).\r
68fb0527 704\r
7c25b7ea 705 @retval EFI_SUCCESS The ifconfig command clean processed successfully.\r
706 @retval others The ifconfig command clean process failed.\r
68fb0527 707\r
68fb0527 708**/\r
7c25b7ea 709EFI_STATUS\r
710IfConfigClearInterfaceInfo (\r
711 IN LIST_ENTRY *IfList\r
68fb0527 712 )\r
713{\r
7c25b7ea 714 EFI_STATUS Status;\r
715 LIST_ENTRY *Entry;\r
716 LIST_ENTRY *Next;\r
717 IFCONFIG_INTERFACE_CB *IfCb;\r
718 EFI_IP4_CONFIG2_POLICY Policy;\r
68fb0527 719\r
7c25b7ea 720 Policy = Ip4Config2PolicyDhcp;\r
721 Status = EFI_SUCCESS;\r
68fb0527 722\r
7c25b7ea 723 if (IsListEmpty (IfList)) {\r
724 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);\r
68fb0527 725 }\r
726\r
727 //\r
7c25b7ea 728 // Go through the interface list.\r
68fb0527 729 //\r
7c25b7ea 730 NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {\r
731 IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);\r
68fb0527 732 \r
7c25b7ea 733 Status = IfCb->IfCfg->SetData (\r
734 IfCb->IfCfg,\r
735 Ip4Config2DataTypePolicy,\r
736 sizeof (EFI_IP4_CONFIG2_POLICY),\r
737 &Policy\r
738 );\r
68fb0527 739\r
7c25b7ea 740 if (EFI_ERROR (Status)) {\r
741 break;\r
742 }\r
68fb0527 743 }\r
744\r
7c25b7ea 745 return Status;\r
68fb0527 746}\r
747\r
748/**\r
7c25b7ea 749 The set process of the ifconfig command.\r
68fb0527 750\r
7c25b7ea 751 @param[in] IfList The pointer of IfList(interface list).\r
752 @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).\r
68fb0527 753\r
7c25b7ea 754 @retval EFI_SUCCESS The ifconfig command set processed successfully.\r
755 @retval others The ifconfig command set process failed.\r
68fb0527 756\r
68fb0527 757**/\r
758EFI_STATUS\r
7c25b7ea 759IfConfigSetInterfaceInfo (\r
760 IN LIST_ENTRY *IfList,\r
761 IN ARG_LIST *VarArg\r
68fb0527 762 )\r
763{\r
68fb0527 764\r
7c25b7ea 765 EFI_STATUS Status;\r
766 IFCONFIG_INTERFACE_CB *IfCb;\r
767 VAR_CHECK_CODE CheckCode;\r
768 EFI_EVENT TimeOutEvt;\r
769 EFI_EVENT MappedEvt;\r
770 BOOLEAN IsAddressOk;\r
68fb0527 771\r
7c25b7ea 772 EFI_IP4_CONFIG2_POLICY Policy;\r
773 EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress;\r
774 UINTN DataSize;\r
775 EFI_IPv4_ADDRESS Gateway;\r
776 EFI_IPv4_ADDRESS *Dns;\r
777 ARG_LIST *Tmp;\r
778 UINTN Index;\r
68fb0527 779\r
7c25b7ea 780 CONST CHAR16* TempString;\r
68fb0527 781\r
7c25b7ea 782 Dns = NULL;\r
68fb0527 783\r
7c25b7ea 784 if (IsListEmpty (IfList)) {\r
785 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_INTERFACE), gShellNetwork1HiiHandle);\r
786 return EFI_INVALID_PARAMETER;\r
68fb0527 787 }\r
68fb0527 788 \r
7c25b7ea 789 //\r
790 // Make sure to set only one interface each time.\r
791 //\r
792 IfCb = NET_LIST_USER_STRUCT (IfList->ForwardLink, IFCONFIG_INTERFACE_CB, Link);\r
793 Status = EFI_SUCCESS;\r
68fb0527 794\r
7c25b7ea 795 //\r
796 // Initialize check list mechanism.\r
797 //\r
798 CheckCode = IfConfigRetriveCheckListByName(\r
799 NULL,\r
800 NULL,\r
801 TRUE\r
802 );\r
68fb0527 803\r
7c25b7ea 804 //\r
805 // Create events & timers for asynchronous settings.\r
806 //\r
807 Status = gBS->CreateEvent (\r
808 EVT_TIMER,\r
809 TPL_CALLBACK,\r
810 NULL,\r
811 NULL,\r
812 &TimeOutEvt\r
813 );\r
68fb0527 814 if (EFI_ERROR (Status)) {\r
7c25b7ea 815 goto ON_EXIT;\r
68fb0527 816 }\r
817\r
7c25b7ea 818 Status = gBS->CreateEvent (\r
819 EVT_NOTIFY_SIGNAL,\r
820 TPL_NOTIFY,\r
821 IfConfigManualAddressNotify,\r
822 &IsAddressOk,\r
823 &MappedEvt\r
824 );\r
825 if (EFI_ERROR (Status)) {\r
826 goto ON_EXIT;\r
68fb0527 827 }\r
828\r
7c25b7ea 829 //\r
830 // Parse the setting variables.\r
831 //\r
832 while (VarArg != NULL) {\r
833 //\r
834 // Check invalid parameters (duplication & unknown & conflict).\r
835 //\r
836 CheckCode = IfConfigRetriveCheckListByName(\r
837 mSetCheckList,\r
838 VarArg->Arg,\r
839 FALSE\r
840 );\r
68fb0527 841\r
7c25b7ea 842 if (VarCheckOk != CheckCode) {\r
843 switch (CheckCode) {\r
844 case VarCheckDuplicate:\r
845 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_DUPLICATE_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);\r
846 break;\r
68fb0527 847\r
7c25b7ea 848 case VarCheckConflict:\r
849 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_CONFLICT_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);\r
850 break;\r
68fb0527 851\r
7c25b7ea 852 case VarCheckUnknown:\r
853 //\r
854 // To handle unsupported option.\r
855 //\r
856 TempString = PermanentString;\r
857 if (StringNoCaseCompare(&VarArg->Arg, &TempString) == 0) {\r
858 ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION), gShellNetwork1HiiHandle, PermanentString);\r
859 goto ON_EXIT;\r
860 }\r
68fb0527 861\r
7c25b7ea 862 //\r
863 // To handle unknown option.\r
864 //\r
865 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_UNKNOWN_COMMAND), gShellNetwork1HiiHandle, VarArg->Arg);\r
866 break;\r
68fb0527 867\r
7c25b7ea 868 default:\r
869 break;\r
870 }\r
68fb0527 871\r
7c25b7ea 872 VarArg = VarArg->Next;\r
873 continue; \r
874 }\r
68fb0527 875\r
68fb0527 876 //\r
7c25b7ea 877 // Process valid variables.\r
68fb0527 878 //\r
7c25b7ea 879 if (StrCmp(VarArg->Arg, L"dhcp") == 0) {\r
880 //\r
881 // Set dhcp config policy\r
882 //\r
883 Policy = Ip4Config2PolicyDhcp;\r
884 Status = IfCb->IfCfg->SetData (\r
885 IfCb->IfCfg,\r
886 Ip4Config2DataTypePolicy,\r
887 sizeof (EFI_IP4_CONFIG2_POLICY),\r
888 &Policy\r
889 );\r
890\r
891 if (EFI_ERROR(Status)) {\r
892 goto ON_EXIT;\r
893 }\r
68fb0527 894\r
7c25b7ea 895 VarArg= VarArg->Next; \r
68fb0527 896\r
7c25b7ea 897 } else if (StrCmp (VarArg->Arg, L"static") == 0) {\r
898 //\r
899 // Set manual config policy.\r
900 //\r
901 Policy = Ip4Config2PolicyStatic;\r
902 Status = IfCb->IfCfg->SetData (\r
903 IfCb->IfCfg,\r
904 Ip4Config2DataTypePolicy,\r
905 sizeof (EFI_IP4_CONFIG2_POLICY),\r
906 &Policy\r
907 );\r
908\r
909 if (EFI_ERROR(Status)) {\r
68fb0527 910 goto ON_EXIT;\r
911 }\r
912\r
7c25b7ea 913 VarArg= VarArg->Next; \r
68fb0527 914\r
7c25b7ea 915 ZeroMem (&ManualAddress, sizeof (ManualAddress));\r
916 \r
917 //\r
918 // Get manual IP address.\r
919 //\r
920 Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.Address);\r
921 if (EFI_ERROR(Status)) {\r
922 goto ON_EXIT;\r
923 }\r
68fb0527 924\r
7c25b7ea 925 //\r
926 // Get subnetmask.\r
927 // \r
928 VarArg = VarArg->Next;\r
929 Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.SubnetMask);\r
930 if (EFI_ERROR(Status)) {\r
931 goto ON_EXIT;\r
932 }\r
68fb0527 933\r
7c25b7ea 934 //\r
935 // Get gateway.\r
936 //\r
937 VarArg = VarArg->Next;\r
938 Status = NetLibStrToIp4 (VarArg->Arg, &Gateway);\r
939 if (EFI_ERROR(Status)) {\r
940 goto ON_EXIT;\r
941 }\r
942 \r
943 IsAddressOk = FALSE;\r
944\r
945 Status = IfCb->IfCfg->RegisterDataNotify (\r
946 IfCb->IfCfg,\r
947 Ip4Config2DataTypeManualAddress,\r
948 MappedEvt\r
949 );\r
950 if (EFI_ERROR (Status)) {\r
951 goto ON_EXIT;\r
952 }\r
68fb0527 953\r
7c25b7ea 954 DataSize = sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS);\r
68fb0527 955\r
7c25b7ea 956 Status = IfCb->IfCfg->SetData (\r
957 IfCb->IfCfg,\r
958 Ip4Config2DataTypeManualAddress,\r
959 DataSize,\r
960 &ManualAddress\r
961 );\r
68fb0527 962\r
7c25b7ea 963 if (Status == EFI_NOT_READY) {\r
964 gBS->SetTimer (TimeOutEvt, TimerRelative, 50000000);\r
68fb0527 965\r
7c25b7ea 966 while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {\r
967 if (IsAddressOk) {\r
968 Status = EFI_SUCCESS;\r
969 break;\r
970 }\r
971 }\r
972 }\r
68fb0527 973\r
7c25b7ea 974 IfCb->IfCfg->UnregisterDataNotify (\r
975 IfCb->IfCfg,\r
976 Ip4Config2DataTypeManualAddress,\r
977 MappedEvt\r
978 );\r
68fb0527 979\r
7c25b7ea 980 if (EFI_ERROR (Status)) {\r
981 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);\r
68fb0527 982 goto ON_EXIT;\r
983 }\r
984\r
7c25b7ea 985 //\r
986 // Set gateway.\r
987 //\r
988 DataSize = sizeof (EFI_IPv4_ADDRESS);\r
989\r
990 Status = IfCb->IfCfg->SetData (\r
991 IfCb->IfCfg,\r
992 Ip4Config2DataTypeGateway,\r
993 DataSize,\r
994 &Gateway\r
995 );\r
996 VarArg = VarArg->Next;\r
997 \r
998 } else if (StrCmp (VarArg->Arg, L"dns") == 0) {\r
999 //\r
1000 // Get DNS addresses.\r
1001 //\r
1002 VarArg = VarArg->Next;\r
1003 Tmp = VarArg;\r
1004 Index = 0;\r
1005 while (Tmp != NULL) {\r
1006 Index ++;\r
1007 Tmp = Tmp->Next;\r
1008 }\r
68fb0527 1009\r
7c25b7ea 1010 Dns = AllocatePool (Index * sizeof (EFI_IPv4_ADDRESS));\r
1011 ASSERT(Dns != NULL);\r
1012 Tmp = VarArg;\r
1013 Index = 0;\r
1014 while (Tmp != NULL) {\r
1015 Status = NetLibStrToIp4 (Tmp->Arg, Dns + Index);\r
1016 if (EFI_ERROR(Status)) {\r
1017 goto ON_EXIT;\r
1018 }\r
1019 Index ++;\r
1020 Tmp = Tmp->Next;\r
1021 }\r
1022 \r
1023 VarArg = Tmp;\r
68fb0527 1024\r
7c25b7ea 1025 //\r
1026 // Set DNS addresses.\r
1027 //\r
1028 DataSize = Index * sizeof (EFI_IPv4_ADDRESS);\r
1029\r
1030 Status = IfCb->IfCfg->SetData (\r
1031 IfCb->IfCfg,\r
1032 Ip4Config2DataTypeDnsServer,\r
1033 DataSize,\r
1034 Dns\r
1035 );\r
68fb0527 1036 }\r
7c25b7ea 1037 }\r
68fb0527 1038\r
7c25b7ea 1039ON_EXIT:\r
1040 if (Dns != NULL) {\r
1041 FreePool (Dns);\r
1042 }\r
1043 \r
1044 return EFI_SUCCESS;\r
68fb0527 1045\r
7c25b7ea 1046}\r
68fb0527 1047\r
7c25b7ea 1048/**\r
1049 The ifconfig command main process.\r
68fb0527 1050\r
7c25b7ea 1051 @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.\r
68fb0527 1052\r
7c25b7ea 1053 @retval EFI_SUCCESS ifconfig command processed successfully.\r
1054 @retval others The ifconfig command process failed.\r
68fb0527 1055\r
7c25b7ea 1056**/\r
1057EFI_STATUS\r
1058IfConfig (\r
1059 IN IFCONFIG_PRIVATE_DATA *Private\r
1060 )\r
1061{\r
1062 EFI_STATUS Status;\r
68fb0527 1063\r
1064 //\r
7c25b7ea 1065 // Get configure information of all interfaces.\r
68fb0527 1066 //\r
7c25b7ea 1067 Status = IfConfigGetInterfaceInfo (\r
1068 Private->IfName,\r
1069 &Private->IfList\r
1070 );\r
68fb0527 1071\r
7c25b7ea 1072 if (EFI_ERROR (Status)) {\r
1073 goto ON_EXIT;\r
68fb0527 1074 }\r
1075\r
7c25b7ea 1076 switch (Private->OpCode) {\r
1077 case IfConfigOpList:\r
1078 Status = IfConfigShowInterfaceInfo (&Private->IfList);\r
1079 break;\r
1080\r
1081 case IfConfigOpClear:\r
1082 Status = IfConfigClearInterfaceInfo (&Private->IfList);\r
1083 break;\r
1084\r
1085 case IfConfigOpSet:\r
1086 Status = IfConfigSetInterfaceInfo (&Private->IfList, Private->VarArg);\r
1087 break;\r
1088\r
1089 default:\r
1090 Status = EFI_ABORTED;\r
68fb0527 1091 }\r
7c25b7ea 1092\r
68fb0527 1093ON_EXIT:\r
7c25b7ea 1094\r
1095 return Status;\r
68fb0527 1096}\r
1097\r
1098/**\r
7c25b7ea 1099 The ifconfig command cleanup process, free the allocated memory.\r
1100\r
1101 @param[in] Private The pointer of IFCONFIG_PRIVATE_DATA.\r
68fb0527 1102\r
68fb0527 1103**/\r
1104VOID\r
7c25b7ea 1105IfConfigCleanup (\r
1106 IN IFCONFIG_PRIVATE_DATA *Private\r
68fb0527 1107 )\r
1108{\r
1109 LIST_ENTRY *Entry;\r
1110 LIST_ENTRY *NextEntry;\r
7c25b7ea 1111 IFCONFIG_INTERFACE_CB *IfCb;\r
1112 ARG_LIST *ArgNode;\r
1113 ARG_LIST *ArgHead;\r
68fb0527 1114\r
7c25b7ea 1115 ASSERT (Private != NULL);\r
68fb0527 1116\r
7c25b7ea 1117 //\r
1118 // Clean the list which save the set config Args.\r
1119 //\r
1120 if (Private->VarArg != NULL) {\r
1121 ArgHead = Private->VarArg;\r
68fb0527 1122\r
7c25b7ea 1123 while (ArgHead->Next != NULL) {\r
1124 ArgNode = ArgHead->Next;\r
1125 FreePool (ArgHead);\r
1126 ArgHead = ArgNode;\r
68fb0527 1127 }\r
1128\r
7c25b7ea 1129 FreePool (ArgHead);\r
68fb0527 1130 }\r
1131\r
7c25b7ea 1132 if (Private->IfName != NULL) {\r
1133 FreePool (Private->IfName);\r
1134 }\r
68fb0527 1135\r
7c25b7ea 1136 //\r
1137 // Clean the IFCONFIG_INTERFACE_CB list.\r
1138 //\r
1139 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->IfList) {\r
1140 IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);\r
68fb0527 1141\r
7c25b7ea 1142 RemoveEntryList (&IfCb->Link);\r
68fb0527 1143\r
7c25b7ea 1144 if (IfCb->IfInfo != NULL) {\r
68fb0527 1145\r
7c25b7ea 1146 FreePool (IfCb->IfInfo);\r
68fb0527 1147 }\r
1148\r
7c25b7ea 1149 FreePool (IfCb);\r
68fb0527 1150 }\r
1151\r
7c25b7ea 1152 FreePool (Private);\r
68fb0527 1153}\r
1154\r
1155/**\r
1156 Function for 'ifconfig' command.\r
1157\r
1158 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
1159 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
7c25b7ea 1160\r
1161 @retval EFI_SUCCESS ifconfig command processed successfully.\r
1162 @retval others The ifconfig command process failed.\r
1163 \r
68fb0527 1164**/\r
1165SHELL_STATUS\r
1166EFIAPI\r
1167ShellCommandRunIfconfig (\r
1168 IN EFI_HANDLE ImageHandle,\r
1169 IN EFI_SYSTEM_TABLE *SystemTable\r
1170 )\r
1171{\r
7c25b7ea 1172 EFI_STATUS Status;\r
1173 IFCONFIG_PRIVATE_DATA *Private;\r
1174 LIST_ENTRY *ParamPackage;\r
1175 CONST CHAR16 *ValueStr;\r
1176 ARG_LIST *ArgList;\r
1177 CHAR16 *ProblemParam;\r
1178 CHAR16 *Str;\r
1179\r
1180 Private = NULL;\r
1181\r
1182 Status = ShellCommandLineParseEx (mIfConfigCheckList, &ParamPackage, &ProblemParam, TRUE, FALSE);\r
1183 if (EFI_ERROR (Status)) {\r
1184 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam);\r
1185 goto ON_EXIT;\r
1186 }\r
68fb0527 1187\r
1188 //\r
7c25b7ea 1189 // To handle unsupported option.\r
68fb0527 1190 //\r
7c25b7ea 1191 if (ShellCommandLineGetFlag (ParamPackage, L"-c")) {\r
1192 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_UNSUPPORTED_OPTION), gShellNetwork1HiiHandle,L"-c");\r
1193 goto ON_EXIT;\r
1194 }\r
68fb0527 1195\r
1196 //\r
7c25b7ea 1197 // To handle no option.\r
68fb0527 1198 //\r
7c25b7ea 1199 if (!ShellCommandLineGetFlag (ParamPackage, L"-r") && !ShellCommandLineGetFlag (ParamPackage, L"-s") &&\r
1200 !ShellCommandLineGetFlag (ParamPackage, L"-l")) {\r
1201 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_OPTION), gShellNetwork1HiiHandle);\r
1202 goto ON_EXIT;\r
68fb0527 1203 }\r
1204\r
7c25b7ea 1205 //\r
1206 // To handle conflict options.\r
1207 //\r
1208 if (((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-s"))) ||\r
1209 ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||\r
1210 ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l")))) {\r
1211 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig");\r
1212 goto ON_EXIT;\r
68fb0527 1213 }\r
68fb0527 1214\r
7c25b7ea 1215 Status = EFI_INVALID_PARAMETER;\r
1216\r
1217 Private = AllocateZeroPool (sizeof (IFCONFIG_PRIVATE_DATA));\r
1218\r
1219 if (Private == NULL) {\r
1220 Status = EFI_OUT_OF_RESOURCES;\r
1221 goto ON_EXIT;\r
68fb0527 1222 }\r
1223\r
7c25b7ea 1224 InitializeListHead (&Private->IfList);\r
68fb0527 1225\r
7c25b7ea 1226 //\r
1227 // To get interface name for the list option.\r
1228 //\r
1229 if (ShellCommandLineGetFlag (ParamPackage, L"-l")) {\r
1230 Private->OpCode = IfConfigOpList;\r
1231 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");\r
1232 if (ValueStr != NULL) {\r
1233 Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);\r
1234 ASSERT (Str != NULL);\r
1235 Private->IfName = Str;\r
1236 }\r
1237 }\r
1238 \r
1239 //\r
1240 // To get interface name for the clear option.\r
1241 //\r
1242 if (ShellCommandLineGetFlag (ParamPackage, L"-r")) {\r
1243 Private->OpCode = IfConfigOpClear;\r
1244 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");\r
1245 if (ValueStr != NULL) {\r
1246 Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);\r
1247 ASSERT (Str != NULL);\r
1248 Private->IfName = Str;\r
1249 }\r
1250 }\r
1251 \r
1252 //\r
1253 // To get interface name and corresponding Args for the set option.\r
1254 //\r
1255 if (ShellCommandLineGetFlag (ParamPackage, L"-s")) {\r
1256 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-s");\r
1257 if (ValueStr == NULL) {\r
1258 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_INTERFACE), gShellNetwork1HiiHandle);\r
1259 goto ON_EXIT;\r
1260 }\r
68fb0527 1261 \r
1262 //\r
7c25b7ea 1263 // To split the configuration into multi-section.\r
68fb0527 1264 //\r
7c25b7ea 1265 ArgList = SplitStrToList (ValueStr, L' ');\r
1266 ASSERT (ArgList != NULL);\r
68fb0527 1267\r
7c25b7ea 1268 Private->OpCode = IfConfigOpSet;\r
1269 Private->IfName = ArgList->Arg;\r
68fb0527 1270\r
7c25b7ea 1271 Private->VarArg = ArgList->Next;\r
68fb0527 1272\r
7c25b7ea 1273 if (Private->IfName == NULL || Private->VarArg == NULL) {\r
1274 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);\r
1275 goto ON_EXIT;\r
68fb0527 1276 }\r
68fb0527 1277 }\r
7c25b7ea 1278 \r
1279 //\r
1280 // Main process of ifconfig.\r
1281 //\r
1282 Status = IfConfig (Private);\r
68fb0527 1283\r
7c25b7ea 1284ON_EXIT:\r
68fb0527 1285\r
7c25b7ea 1286 ShellCommandLineFreeVarList (ParamPackage);\r
1287 \r
1288 if (Private != NULL) {\r
1289 IfConfigCleanup (Private);\r
68fb0527 1290 }\r
1291\r
7c25b7ea 1292 return Status;\r
68fb0527 1293}\r