TianoCore EDK2 master
Loading...
Searching...
No Matches
Ifconfig6.c
Go to the documentation of this file.
1
11
12enum {
13 IfConfig6OpList = 1,
14 IfConfig6OpSet = 2,
15 IfConfig6OpClear = 3
16};
17
18typedef enum {
19 VarCheckReserved = -1,
20 VarCheckOk = 0,
21 VarCheckDuplicate,
22 VarCheckConflict,
23 VarCheckUnknown,
24 VarCheckLackValue,
25 VarCheckOutOfMem
26} VAR_CHECK_CODE;
27
28typedef enum {
29 FlagTypeSingle = 0,
30 FlagTypeNeedVar,
31 FlagTypeNeedSet,
32 FlagTypeSkipUnknown
33} VAR_CHECK_FLAG_TYPE;
34
35#define MACADDRMAXSIZE 32
36#define PREFIXMAXLEN 16
37
39 EFI_HANDLE NicHandle;
40 LIST_ENTRY Link;
46 UINT32 DnsCnt;
47 EFI_IPv6_ADDRESS DnsAddr[1];
49
50typedef struct _ARG_LIST ARG_LIST;
51
52struct _ARG_LIST {
53 ARG_LIST *Next;
54 CHAR16 *Arg;
55};
56
58 EFI_HANDLE ImageHandle;
59 LIST_ENTRY IfList;
60
61 UINT32 OpCode;
62 CHAR16 *IfName;
63 ARG_LIST *VarArg;
65
66typedef struct _VAR_CHECK_ITEM {
67 CHAR16 *FlagStr;
68 UINT32 FlagID;
69 UINT32 ConflictMask;
70 VAR_CHECK_FLAG_TYPE FlagType;
72
73SHELL_PARAM_ITEM mIfConfig6CheckList[] = {
74 {
75 L"-b",
77 },
78 {
79 L"-s",
81 },
82 {
83 L"-l",
85 },
86 {
87 L"-r",
89 },
90 {
91 L"-?",
93 },
94 {
95 NULL,
96 TypeMax
97 },
98};
99
100VAR_CHECK_ITEM mIfConfig6SetCheckList[] = {
101 {
102 L"auto",
103 0x00000001,
104 0x00000001,
105 FlagTypeSingle
106 },
107 {
108 L"man",
109 0x00000002,
110 0x00000001,
111 FlagTypeSingle
112 },
113 {
114 L"host",
115 0x00000004,
116 0x00000002,
117 FlagTypeSingle
118 },
119 {
120 L"dad",
121 0x00000008,
122 0x00000004,
123 FlagTypeSingle
124 },
125 {
126 L"gw",
127 0x00000010,
128 0x00000008,
129 FlagTypeSingle
130 },
131 {
132 L"dns",
133 0x00000020,
134 0x00000010,
135 FlagTypeSingle
136 },
137 {
138 L"id",
139 0x00000040,
140 0x00000020,
141 FlagTypeSingle
142 },
143 {
144 NULL,
145 0x0,
146 0x0,
147 FlagTypeSkipUnknown
148 },
149};
150
156VOID
158 ARG_LIST *List
159 )
160{
161 ARG_LIST *Next;
162
163 while (List->Next != NULL) {
164 Next = List->Next;
165 FreePool (List);
166 List = Next;
167 }
168
169 FreePool (List);
170}
171
181ARG_LIST *
183 IN CONST CHAR16 *String,
184 IN CHAR16 Separator
185 )
186{
187 CHAR16 *Str;
188 CHAR16 *ArgStr;
189 ARG_LIST *ArgList;
190 ARG_LIST *ArgNode;
191
192 if ((String == NULL) || (*String == L'\0')) {
193 return NULL;
194 }
195
196 //
197 // Copy the CONST string to a local copy.
198 //
199 Str = AllocateCopyPool (StrSize (String), String);
200 if (Str == NULL) {
201 return NULL;
202 }
203
204 ArgStr = Str;
205
206 //
207 // init a node for the list head.
208 //
209 ArgNode = (ARG_LIST *)AllocateZeroPool (sizeof (ARG_LIST));
210 if (ArgNode == NULL) {
211 return NULL;
212 }
213
214 ArgList = ArgNode;
215
216 //
217 // Split the local copy and save in the list node.
218 //
219 while (*Str != L'\0') {
220 if (*Str == Separator) {
221 *Str = L'\0';
222 ArgNode->Arg = ArgStr;
223 ArgStr = Str + 1;
224 ArgNode->Next = (ARG_LIST *)AllocateZeroPool (sizeof (ARG_LIST));
225 if (ArgNode->Next == NULL) {
226 //
227 // Free the local copy of string stored in the first node
228 //
229 FreePool (ArgList->Arg);
230 IfConfig6FreeArgList (ArgList);
231 return NULL;
232 }
233
234 ArgNode = ArgNode->Next;
235 }
236
237 Str++;
238 }
239
240 ArgNode->Arg = ArgStr;
241 ArgNode->Next = NULL;
242
243 return ArgList;
244}
245
256VAR_CHECK_CODE
258 IN VAR_CHECK_ITEM *CheckList,
259 IN CHAR16 *Name,
260 IN BOOLEAN Init
261 )
262{
263 STATIC UINT32 CheckDuplicate;
264 STATIC UINT32 CheckConflict;
265 VAR_CHECK_CODE RtCode;
266 UINT32 Index;
267 VAR_CHECK_ITEM Arg;
268
269 if (Init) {
270 CheckDuplicate = 0;
271 CheckConflict = 0;
272 return VarCheckOk;
273 }
274
275 RtCode = VarCheckOk;
276 Index = 0;
277 Arg = CheckList[Index];
278
279 //
280 // Check the Duplicated/Conflicted/Unknown input Args.
281 //
282 while (Arg.FlagStr != NULL) {
283 if (StrCmp (Arg.FlagStr, Name) == 0) {
284 if (CheckDuplicate & Arg.FlagID) {
285 RtCode = VarCheckDuplicate;
286 break;
287 }
288
289 if (CheckConflict & Arg.ConflictMask) {
290 RtCode = VarCheckConflict;
291 break;
292 }
293
294 CheckDuplicate |= Arg.FlagID;
295 CheckConflict |= Arg.ConflictMask;
296 break;
297 }
298
299 Arg = CheckList[++Index];
300 }
301
302 if (Arg.FlagStr == NULL) {
303 RtCode = VarCheckUnknown;
304 }
305
306 return RtCode;
307}
308
316VOID
317EFIAPI
319 IN EFI_EVENT Event,
320 IN VOID *Context
321 )
322{
323 *((BOOLEAN *)Context) = TRUE;
324}
325
333VOID
335 IN UINT8 *Node,
336 IN UINT32 Size
337 )
338{
339 UINTN Index;
340
341 ASSERT (Size <= MACADDRMAXSIZE);
342
343 for (Index = 0; Index < Size; Index++) {
344 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_BODY), gShellNetwork2HiiHandle, Node[Index]);
345 if (Index + 1 < Size) {
346 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON), gShellNetwork2HiiHandle);
347 }
348 }
349
350 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
351}
352
360VOID
363 IN UINT8 *PrefixLen
364 )
365{
366 UINTN Index;
367 BOOLEAN Short;
368
369 Short = FALSE;
370
371 for (Index = 0; Index < PREFIXMAXLEN; Index = Index + 2) {
372 if (!Short && (Index + 1 < PREFIXMAXLEN) && (Index % 2 == 0) && (Ip->Addr[Index] == 0) && (Ip->Addr[Index + 1] == 0)) {
373 //
374 // Deal with the case of ::.
375 //
376 if (Index == 0) {
377 //
378 // :: is at the beginning of the address.
379 //
380 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON), gShellNetwork2HiiHandle);
381 }
382
383 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON), gShellNetwork2HiiHandle);
384
385 while ((Index < PREFIXMAXLEN) && (Ip->Addr[Index] == 0) && (Ip->Addr[Index + 1] == 0)) {
386 Index = Index + 2;
387 if (Index > PREFIXMAXLEN - 2) {
388 break;
389 }
390 }
391
392 Short = TRUE;
393
394 if (Index == PREFIXMAXLEN) {
395 //
396 // :: is at the end of the address.
397 //
398 break;
399 }
400 }
401
402 if (Index < PREFIXMAXLEN - 1) {
403 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY), gShellNetwork2HiiHandle, Ip->Addr[Index]);
404 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY), gShellNetwork2HiiHandle, Ip->Addr[Index + 1]);
405 }
406
407 if (Index + 2 < PREFIXMAXLEN) {
408 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON), gShellNetwork2HiiHandle);
409 }
410 }
411
412 if (PrefixLen != NULL) {
413 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_PREFIX_LEN), gShellNetwork2HiiHandle, *PrefixLen);
414 }
415}
416
430 IN OUT ARG_LIST **Arg,
432 OUT UINTN *BufSize
433 )
434{
435 EFI_STATUS Status;
437 ARG_LIST *VarArg;
438 EFI_IPv6_ADDRESS Address;
439 UINT8 Prefix;
440 UINT8 AddrCnt;
441
442 Prefix = 0;
443 AddrCnt = 0;
444 *BufSize = 0;
445 *Buf = NULL;
446 VarArg = *Arg;
447 Status = EFI_SUCCESS;
448
449 //
450 // Go through the list to check the correctness of input host ip6 address.
451 //
452 while ((!EFI_ERROR (Status)) && (VarArg != NULL)) {
453 Status = NetLibStrToIp6andPrefix (VarArg->Arg, &Address, &Prefix);
454
455 if (EFI_ERROR (Status)) {
456 //
457 // host ip ip ... gw
458 //
459 break;
460 }
461
462 VarArg = VarArg->Next;
463 AddrCnt++;
464 }
465
466 if (AddrCnt == 0) {
467 return EFI_INVALID_PARAMETER;
468 }
469
470 AddrBuf = AllocateZeroPool (AddrCnt * sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));
471 if (AddrBuf == NULL) {
472 ASSERT (AddrBuf != NULL);
473 return EFI_OUT_OF_RESOURCES;
474 }
475
476 AddrCnt = 0;
477 VarArg = *Arg;
478 Status = EFI_SUCCESS;
479
480 //
481 // Go through the list to fill in the EFI_IP6_CONFIG_MANUAL_ADDRESS structure.
482 //
483 while ((!EFI_ERROR (Status)) && (VarArg != NULL)) {
484 Status = NetLibStrToIp6andPrefix (VarArg->Arg, &Address, &Prefix);
485
486 if (EFI_ERROR (Status)) {
487 break;
488 }
489
490 //
491 // If prefix length is not set, set it as Zero here. In the IfConfigSetInterfaceInfo()
492 // Zero prefix, length will be transfered to default prefix length.
493 //
494 if (Prefix == 0xFF) {
495 Prefix = 0;
496 }
497
498 AddrBuf[AddrCnt].IsAnycast = FALSE;
499 AddrBuf[AddrCnt].PrefixLength = Prefix;
500 IP6_COPY_ADDRESS (&AddrBuf[AddrCnt].Address, &Address);
501 VarArg = VarArg->Next;
502 AddrCnt++;
503 }
504
505 *Arg = VarArg;
506
507 if (EFI_ERROR (Status) && (Status != EFI_INVALID_PARAMETER)) {
508 goto ON_ERROR;
509 }
510
511 *Buf = AddrBuf;
512 *BufSize = AddrCnt * sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS);
513
514 return EFI_SUCCESS;
515
516ON_ERROR:
517
518 FreePool (AddrBuf);
519 return Status;
520}
521
535 IN OUT ARG_LIST **Arg,
536 OUT EFI_IPv6_ADDRESS **Buf,
537 OUT UINTN *BufSize
538 )
539{
540 EFI_STATUS Status;
541 EFI_IPv6_ADDRESS *AddrBuf;
542 ARG_LIST *VarArg;
543 EFI_IPv6_ADDRESS Address;
544 UINT8 Prefix;
545 UINT8 AddrCnt;
546
547 AddrCnt = 0;
548 *BufSize = 0;
549 *Buf = NULL;
550 VarArg = *Arg;
551 Status = EFI_SUCCESS;
552
553 //
554 // Go through the list to check the correctness of input gw/dns address.
555 //
556 while ((!EFI_ERROR (Status)) && (VarArg != NULL)) {
557 Status = NetLibStrToIp6andPrefix (VarArg->Arg, &Address, &Prefix);
558
559 if (EFI_ERROR (Status)) {
560 //
561 // gw ip ip ... host
562 //
563 break;
564 }
565
566 VarArg = VarArg->Next;
567 AddrCnt++;
568 }
569
570 if (AddrCnt == 0) {
571 return EFI_INVALID_PARAMETER;
572 }
573
574 AddrBuf = AllocateZeroPool (AddrCnt * sizeof (EFI_IPv6_ADDRESS));
575 if (AddrBuf == NULL) {
576 ASSERT (AddrBuf != NULL);
577 return EFI_OUT_OF_RESOURCES;
578 }
579
580 AddrCnt = 0;
581 VarArg = *Arg;
582 Status = EFI_SUCCESS;
583
584 //
585 // Go through the list to fill in the EFI_IPv6_ADDRESS structure.
586 //
587 while ((!EFI_ERROR (Status)) && (VarArg != NULL)) {
588 Status = NetLibStrToIp6andPrefix (VarArg->Arg, &Address, &Prefix);
589
590 if (EFI_ERROR (Status)) {
591 break;
592 }
593
594 IP6_COPY_ADDRESS (&AddrBuf[AddrCnt], &Address);
595
596 VarArg = VarArg->Next;
597 AddrCnt++;
598 }
599
600 *Arg = VarArg;
601
602 if (EFI_ERROR (Status) && (Status != EFI_INVALID_PARAMETER)) {
603 goto ON_ERROR;
604 }
605
606 *Buf = AddrBuf;
607 *BufSize = AddrCnt * sizeof (EFI_IPv6_ADDRESS);
608
609 return EFI_SUCCESS;
610
611ON_ERROR:
612
613 FreePool (AddrBuf);
614 return Status;
615}
616
629 IN OUT ARG_LIST **Arg,
631 )
632{
633 UINT8 Index;
634 UINT8 NodeVal;
635 CHAR16 *IdStr;
636
637 if (*Arg == NULL) {
638 return EFI_INVALID_PARAMETER;
639 }
640
641 Index = 0;
642 IdStr = (*Arg)->Arg;
643 ASSERT (IfId != NULL);
645 ASSERT (*IfId != NULL);
646
647 while ((*IdStr != L'\0') && (Index < 8)) {
648 NodeVal = 0;
649 while ((*IdStr != L':') && (*IdStr != L'\0')) {
650 if ((*IdStr <= L'F') && (*IdStr >= L'A')) {
651 NodeVal = (UINT8)((NodeVal << 4) + *IdStr - L'A' + 10);
652 } else if ((*IdStr <= L'f') && (*IdStr >= L'a')) {
653 NodeVal = (UINT8)((NodeVal << 4) + *IdStr - L'a' + 10);
654 } else if ((*IdStr <= L'9') && (*IdStr >= L'0')) {
655 NodeVal = (UINT8)((NodeVal << 4) + *IdStr - L'0');
656 } else {
657 FreePool (*IfId);
658 return EFI_INVALID_PARAMETER;
659 }
660
661 IdStr++;
662 }
663
664 (*IfId)->Id[Index++] = NodeVal;
665
666 if (*IdStr == L':') {
667 IdStr++;
668 }
669 }
670
671 *Arg = (*Arg)->Next;
672 return EFI_SUCCESS;
673}
674
687 IN OUT ARG_LIST **Arg,
688 OUT UINT32 *Xmits
689 )
690{
691 CHAR16 *ValStr;
692
693 if (*Arg == NULL) {
694 return EFI_INVALID_PARAMETER;
695 }
696
697 ValStr = (*Arg)->Arg;
698 *Xmits = 0;
699
700 while (*ValStr != L'\0') {
701 if ((*ValStr <= L'9') && (*ValStr >= L'0')) {
702 *Xmits = (*Xmits * 10) + (*ValStr - L'0');
703 } else {
704 return EFI_INVALID_PARAMETER;
705 }
706
707 ValStr++;
708 }
709
710 *Arg = (*Arg)->Next;
711 return EFI_SUCCESS;
712}
713
727 IN EFI_HANDLE ImageHandle,
728 IN CHAR16 *IfName,
729 IN LIST_ENTRY *IfList
730 )
731{
732 EFI_STATUS Status;
733 UINTN HandleIndex;
734 UINTN HandleNum;
735 EFI_HANDLE *HandleBuffer;
739 UINTN DataSize;
740
741 HandleBuffer = NULL;
742 HandleNum = 0;
743
744 IfInfo = NULL;
745 IfCb = NULL;
746
747 //
748 // Locate all the handles with ip6 service binding protocol.
749 //
750 Status = gBS->LocateHandleBuffer (
752 &gEfiIp6ServiceBindingProtocolGuid,
753 NULL,
754 &HandleNum,
755 &HandleBuffer
756 );
757 if (EFI_ERROR (Status) || (HandleNum == 0)) {
758 return Status;
759 }
760
761 //
762 // Enumerate all handles that installed with ip6 service binding protocol.
763 //
764 for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
765 IfCb = NULL;
766 IfInfo = NULL;
767 DataSize = 0;
768
769 //
770 // Ip6config protocol and ip6 service binding protocol are installed
771 // on the same handle.
772 //
773 ASSERT (HandleBuffer != NULL);
774 Status = gBS->HandleProtocol (
775 HandleBuffer[HandleIndex],
776 &gEfiIp6ConfigProtocolGuid,
777 (VOID **)&Ip6Cfg
778 );
779
780 if (EFI_ERROR (Status)) {
781 goto ON_ERROR;
782 }
783
784 //
785 // Get the interface information size.
786 //
787 Status = Ip6Cfg->GetData (
788 Ip6Cfg,
790 &DataSize,
791 NULL
792 );
793
794 if (Status != EFI_BUFFER_TOO_SMALL) {
795 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
796 goto ON_ERROR;
797 }
798
799 IfInfo = AllocateZeroPool (DataSize);
800
801 if (IfInfo == NULL) {
802 Status = EFI_OUT_OF_RESOURCES;
803 goto ON_ERROR;
804 }
805
806 //
807 // Get the interface info.
808 //
809 Status = Ip6Cfg->GetData (
810 Ip6Cfg,
812 &DataSize,
813 IfInfo
814 );
815
816 if (EFI_ERROR (Status)) {
817 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
818 goto ON_ERROR;
819 }
820
821 //
822 // Check the interface name if required.
823 //
824 if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) != 0)) {
825 FreePool (IfInfo);
826 continue;
827 }
828
829 DataSize = 0;
830 //
831 // Get the size of dns server list.
832 //
833 Status = Ip6Cfg->GetData (
834 Ip6Cfg,
836 &DataSize,
837 NULL
838 );
839
840 if ((Status != EFI_BUFFER_TOO_SMALL) && (Status != EFI_NOT_FOUND)) {
841 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
842 goto ON_ERROR;
843 }
844
845 IfCb = AllocateZeroPool (sizeof (IFCONFIG6_INTERFACE_CB) + DataSize);
846
847 if (IfCb == NULL) {
848 Status = EFI_OUT_OF_RESOURCES;
849 goto ON_ERROR;
850 }
851
852 IfCb->NicHandle = HandleBuffer[HandleIndex];
853 IfCb->IfInfo = IfInfo;
854 IfCb->IfCfg = Ip6Cfg;
855 IfCb->DnsCnt = (UINT32)(DataSize / sizeof (EFI_IPv6_ADDRESS));
856
857 //
858 // Get the dns server list if has.
859 //
860 if (DataSize > 0) {
861 Status = Ip6Cfg->GetData (
862 Ip6Cfg,
864 &DataSize,
865 IfCb->DnsAddr
866 );
867
868 if (EFI_ERROR (Status)) {
869 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
870 goto ON_ERROR;
871 }
872 }
873
874 //
875 // Get the interface id if has.
876 //
877 DataSize = sizeof (EFI_IP6_CONFIG_INTERFACE_ID);
878 IfCb->IfId = AllocateZeroPool (DataSize);
879
880 if (IfCb->IfId == NULL) {
881 goto ON_ERROR;
882 }
883
884 Status = Ip6Cfg->GetData (
885 Ip6Cfg,
887 &DataSize,
888 IfCb->IfId
889 );
890
891 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
892 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
893 goto ON_ERROR;
894 }
895
896 if (Status == EFI_NOT_FOUND) {
897 FreePool (IfCb->IfId);
898 IfCb->IfId = NULL;
899 }
900
901 //
902 // Get the config policy.
903 //
904 DataSize = sizeof (EFI_IP6_CONFIG_POLICY);
905 Status = Ip6Cfg->GetData (
906 Ip6Cfg,
908 &DataSize,
909 &IfCb->Policy
910 );
911
912 if (EFI_ERROR (Status)) {
913 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
914 goto ON_ERROR;
915 }
916
917 //
918 // Get the dad transmits.
919 //
921 Status = Ip6Cfg->GetData (
922 Ip6Cfg,
924 &DataSize,
925 &IfCb->Xmits
926 );
927
928 if (EFI_ERROR (Status)) {
929 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
930 goto ON_ERROR;
931 }
932
933 InsertTailList (IfList, &IfCb->Link);
934
935 if ((IfName != NULL) && (StrCmp (IfName, IfInfo->Name) == 0)) {
936 //
937 // Only need the appointed interface, keep the allocated buffer.
938 //
939 IfCb = NULL;
940 IfInfo = NULL;
941 break;
942 }
943 }
944
945 if (HandleBuffer != NULL) {
946 FreePool (HandleBuffer);
947 }
948
949 return EFI_SUCCESS;
950
951ON_ERROR:
952
953 if (IfInfo != NULL) {
954 FreePool (IfInfo);
955 }
956
957 if (IfCb != NULL) {
958 if (IfCb->IfId != NULL) {
959 FreePool (IfCb->IfId);
960 }
961
962 FreePool (IfCb);
963 }
964
965 return Status;
966}
967
979 IN LIST_ENTRY *IfList
980 )
981{
982 LIST_ENTRY *Entry;
984 UINTN Index;
985
986 Entry = IfList->ForwardLink;
987
988 if (IsListEmpty (IfList)) {
989 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE), gShellNetwork2HiiHandle);
990 }
991
992 //
993 // Go through the interface list.
994 //
995 while (Entry != IfList) {
996 IfCb = BASE_CR (Entry, IFCONFIG6_INTERFACE_CB, Link);
997
998 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_BREAK), gShellNetwork2HiiHandle);
999
1000 //
1001 // Print interface name.
1002 //
1003 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IF_NAME), gShellNetwork2HiiHandle, IfCb->IfInfo->Name);
1004
1005 //
1006 // Print interface config policy.
1007 //
1008 if (IfCb->Policy == Ip6ConfigPolicyAutomatic) {
1009 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_POLICY_AUTO), gShellNetwork2HiiHandle);
1010 } else {
1011 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_POLICY_MAN), gShellNetwork2HiiHandle);
1012 }
1013
1014 //
1015 // Print dad transmit.
1016 //
1017 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_DAD_TRANSMITS), gShellNetwork2HiiHandle, IfCb->Xmits);
1018
1019 //
1020 // Print interface id if has.
1021 //
1022 if (IfCb->IfId != NULL) {
1023 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_INTERFACE_ID_HEAD), gShellNetwork2HiiHandle);
1024
1026 IfCb->IfId->Id,
1027 8
1028 );
1029 }
1030
1031 //
1032 // Print mac address of the interface.
1033 //
1034 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_HEAD), gShellNetwork2HiiHandle);
1035
1037 IfCb->IfInfo->HwAddress.Addr,
1038 IfCb->IfInfo->HwAddressSize
1039 );
1040
1041 //
1042 // Print ip addresses list of the interface.
1043 //
1044 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_HEAD), gShellNetwork2HiiHandle);
1045
1046 for (Index = 0; Index < IfCb->IfInfo->AddressInfoCount; Index++) {
1048 &IfCb->IfInfo->AddressInfo[Index].Address,
1049 &IfCb->IfInfo->AddressInfo[Index].PrefixLength
1050 );
1051 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
1052 }
1053
1054 //
1055 // Print dns server addresses list of the interface if has.
1056 //
1057 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_DNS_ADDR_HEAD), gShellNetwork2HiiHandle);
1058
1059 for (Index = 0; Index < IfCb->DnsCnt; Index++) {
1061 &IfCb->DnsAddr[Index],
1062 NULL
1063 );
1064 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
1065 }
1066
1067 //
1068 // Print route table of the interface if has.
1069 //
1070 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_ROUTE_HEAD), gShellNetwork2HiiHandle);
1071
1072 for (Index = 0; Index < IfCb->IfInfo->RouteCount; Index++) {
1074 &IfCb->IfInfo->RouteTable[Index].Destination,
1075 &IfCb->IfInfo->RouteTable[Index].PrefixLength
1076 );
1077 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_JOINT), gShellNetwork2HiiHandle);
1078
1080 &IfCb->IfInfo->RouteTable[Index].Gateway,
1081 NULL
1082 );
1083 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
1084 }
1085
1086 Entry = Entry->ForwardLink;
1087 }
1088
1089 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_BREAK), gShellNetwork2HiiHandle);
1090 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
1091
1092 return SHELL_SUCCESS;
1093}
1094
1107 IN LIST_ENTRY *IfList,
1108 IN CHAR16 *IfName
1109 )
1110{
1111 EFI_STATUS Status;
1112 SHELL_STATUS ShellStatus;
1113 LIST_ENTRY *Entry;
1115 EFI_IP6_CONFIG_POLICY Policy;
1116
1117 Entry = IfList->ForwardLink;
1118 Status = EFI_SUCCESS;
1119 ShellStatus = SHELL_SUCCESS;
1120
1121 if (IsListEmpty (IfList)) {
1122 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE), gShellNetwork2HiiHandle);
1123 }
1124
1125 //
1126 // Go through the interface list.If the interface name is specified, then
1127 // need to refresh the configuration.
1128 //
1129 while (Entry != IfList) {
1130 IfCb = BASE_CR (Entry, IFCONFIG6_INTERFACE_CB, Link);
1131
1132 if ((IfName != NULL) && (StrCmp (IfName, IfCb->IfInfo->Name) == 0)) {
1133 Policy = Ip6ConfigPolicyManual;
1134
1135 Status = IfCb->IfCfg->SetData (
1136 IfCb->IfCfg,
1138 sizeof (EFI_IP6_CONFIG_POLICY),
1139 &Policy
1140 );
1141 if (EFI_ERROR (Status)) {
1142 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork2HiiHandle, L"ifconfig6");
1143 ShellStatus = SHELL_ACCESS_DENIED;
1144 break;
1145 }
1146 }
1147
1148 Policy = Ip6ConfigPolicyAutomatic;
1149
1150 Status = IfCb->IfCfg->SetData (
1151 IfCb->IfCfg,
1153 sizeof (EFI_IP6_CONFIG_POLICY),
1154 &Policy
1155 );
1156
1157 if (EFI_ERROR (Status)) {
1158 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork2HiiHandle, L"ifconfig6");
1159 ShellStatus = SHELL_ACCESS_DENIED;
1160 break;
1161 }
1162
1163 Entry = Entry->ForwardLink;
1164 }
1165
1166 return ShellStatus;
1167}
1168
1181 IN LIST_ENTRY *IfList,
1182 IN ARG_LIST *VarArg
1183 )
1184{
1185 EFI_STATUS Status;
1186 SHELL_STATUS ShellStatus;
1189 EFI_IPv6_ADDRESS *CfgAddr;
1190 UINTN AddrSize;
1191 EFI_IP6_CONFIG_INTERFACE_ID *InterfaceId;
1192 UINT32 DadXmits;
1193 UINT32 CurDadXmits;
1194 UINTN CurDadXmitsLen;
1195 EFI_IP6_CONFIG_POLICY Policy;
1196
1197 VAR_CHECK_CODE CheckCode;
1198 EFI_EVENT TimeOutEvt;
1199 EFI_EVENT MappedEvt;
1200 BOOLEAN IsAddressOk;
1201
1202 UINTN DataSize;
1203 UINTN Index;
1204 UINT32 Index2;
1205 BOOLEAN IsAddressSet;
1207
1208 CfgManAddr = NULL;
1209 CfgAddr = NULL;
1210 TimeOutEvt = NULL;
1211 MappedEvt = NULL;
1212 IfInfo = NULL;
1213 InterfaceId = NULL;
1214 CurDadXmits = 0;
1215
1216 if (IsListEmpty (IfList)) {
1217 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE), gShellNetwork2HiiHandle);
1219 }
1220
1221 //
1222 // Make sure to set only one interface each time.
1223 //
1224 IfCb = BASE_CR (IfList->ForwardLink, IFCONFIG6_INTERFACE_CB, Link);
1225 Status = EFI_SUCCESS;
1226 ShellStatus = SHELL_SUCCESS;
1227
1228 //
1229 // Initialize check list mechanism.
1230 //
1232 NULL,
1233 NULL,
1234 TRUE
1235 );
1236
1237 //
1238 // Create events & timers for asynchronous settings.
1239 //
1240 Status = gBS->CreateEvent (
1241 EVT_TIMER,
1242 TPL_CALLBACK,
1243 NULL,
1244 NULL,
1245 &TimeOutEvt
1246 );
1247 if (EFI_ERROR (Status)) {
1248 ShellStatus = SHELL_ACCESS_DENIED;
1249 goto ON_EXIT;
1250 }
1251
1252 Status = gBS->CreateEvent (
1253 EVT_NOTIFY_SIGNAL,
1254 TPL_NOTIFY,
1256 &IsAddressOk,
1257 &MappedEvt
1258 );
1259 if (EFI_ERROR (Status)) {
1260 ShellStatus = SHELL_ACCESS_DENIED;
1261 goto ON_EXIT;
1262 }
1263
1264 //
1265 // Parse the setting variables.
1266 //
1267 while (VarArg != NULL) {
1268 //
1269 // Check invalid parameters (duplication & unknown & conflict).
1270 //
1272 mIfConfig6SetCheckList,
1273 VarArg->Arg,
1274 FALSE
1275 );
1276
1277 if (VarCheckOk != CheckCode) {
1278 switch (CheckCode) {
1279 case VarCheckDuplicate:
1280 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_DUPLICATE_COMMAND), gShellNetwork2HiiHandle, VarArg->Arg);
1281 break;
1282
1283 case VarCheckConflict:
1284 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_CONFLICT_COMMAND), gShellNetwork2HiiHandle, VarArg->Arg);
1285 break;
1286
1287 case VarCheckUnknown:
1288 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_UNKNOWN_COMMAND), gShellNetwork2HiiHandle, VarArg->Arg);
1289 break;
1290
1291 default:
1292 break;
1293 }
1294
1295 VarArg = VarArg->Next;
1296 continue;
1297 }
1298
1299 //
1300 // Process valid variables.
1301 //
1302 if (StrCmp (VarArg->Arg, L"auto") == 0) {
1303 //
1304 // Set automaic config policy
1305 //
1306 Policy = Ip6ConfigPolicyAutomatic;
1307 Status = IfCb->IfCfg->SetData (
1308 IfCb->IfCfg,
1310 sizeof (EFI_IP6_CONFIG_POLICY),
1311 &Policy
1312 );
1313
1314 if (EFI_ERROR (Status)) {
1315 ShellStatus = SHELL_ACCESS_DENIED;
1316 goto ON_EXIT;
1317 }
1318
1319 VarArg = VarArg->Next;
1320
1321 if (VarArg != NULL) {
1322 if (StrCmp (VarArg->Arg, L"host") == 0) {
1323 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_IP_CONFIG), gShellNetwork2HiiHandle, Status);
1324 ShellStatus = SHELL_INVALID_PARAMETER;
1325 goto ON_EXIT;
1326 } else if (StrCmp (VarArg->Arg, L"gw") == 0) {
1327 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_GW_CONFIG), gShellNetwork2HiiHandle, Status);
1328 ShellStatus = SHELL_INVALID_PARAMETER;
1329 goto ON_EXIT;
1330 } else if (StrCmp (VarArg->Arg, L"dns") == 0) {
1331 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_DNS_CONFIG), gShellNetwork2HiiHandle, Status);
1332 ShellStatus = SHELL_INVALID_PARAMETER;
1333 goto ON_EXIT;
1334 }
1335 }
1336 } else if (StrCmp (VarArg->Arg, L"man") == 0) {
1337 //
1338 // Set manual config policy.
1339 //
1340 Policy = Ip6ConfigPolicyManual;
1341 Status = IfCb->IfCfg->SetData (
1342 IfCb->IfCfg,
1344 sizeof (EFI_IP6_CONFIG_POLICY),
1345 &Policy
1346 );
1347
1348 if (EFI_ERROR (Status)) {
1349 ShellStatus = SHELL_ACCESS_DENIED;
1350 goto ON_EXIT;
1351 }
1352
1353 VarArg = VarArg->Next;
1354 } else if (StrCmp (VarArg->Arg, L"host") == 0) {
1355 //
1356 // Parse till the next tag or the end of command line.
1357 //
1358 VarArg = VarArg->Next;
1360 &VarArg,
1361 &CfgManAddr,
1362 &AddrSize
1363 );
1364
1365 if (EFI_ERROR (Status)) {
1366 if (Status == EFI_INVALID_PARAMETER) {
1367 ShellStatus = SHELL_INVALID_PARAMETER;
1368 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS), gShellNetwork2HiiHandle, L"host");
1369 continue;
1370 } else {
1371 ShellStatus = SHELL_ACCESS_DENIED;
1372 goto ON_EXIT;
1373 }
1374 }
1375
1376 //
1377 // Set static host ip6 address list.
1378 // This is a asynchronous process.
1379 //
1380 IsAddressOk = FALSE;
1381
1382 Status = IfCb->IfCfg->RegisterDataNotify (
1383 IfCb->IfCfg,
1385 MappedEvt
1386 );
1387 if (EFI_ERROR (Status)) {
1388 ShellStatus = SHELL_ACCESS_DENIED;
1389 goto ON_EXIT;
1390 }
1391
1392 Status = IfCb->IfCfg->SetData (
1393 IfCb->IfCfg,
1395 AddrSize,
1396 CfgManAddr
1397 );
1398
1399 if (Status == EFI_NOT_READY) {
1400 //
1401 // Get current dad transmits count.
1402 //
1403 CurDadXmitsLen = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS);
1404 IfCb->IfCfg->GetData (
1405 IfCb->IfCfg,
1407 &CurDadXmitsLen,
1408 &CurDadXmits
1409 );
1410
1411 gBS->SetTimer (TimeOutEvt, TimerRelative, 50000000 + 10000000 * CurDadXmits);
1412
1413 while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {
1414 if (IsAddressOk) {
1415 Status = EFI_SUCCESS;
1416 break;
1417 }
1418 }
1419 }
1420
1421 IfCb->IfCfg->UnregisterDataNotify (
1422 IfCb->IfCfg,
1424 MappedEvt
1425 );
1426
1427 if (EFI_ERROR (Status)) {
1428 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_MAN_HOST), gShellNetwork2HiiHandle, Status);
1429 ShellStatus = SHELL_ACCESS_DENIED;
1430 goto ON_EXIT;
1431 }
1432
1433 //
1434 // Check whether the address is set successfully.
1435 //
1436 DataSize = 0;
1437
1438 Status = IfCb->IfCfg->GetData (
1439 IfCb->IfCfg,
1441 &DataSize,
1442 NULL
1443 );
1444
1445 if (Status != EFI_BUFFER_TOO_SMALL) {
1446 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
1447 ShellStatus = SHELL_ACCESS_DENIED;
1448 goto ON_EXIT;
1449 }
1450
1451 IfInfo = AllocateZeroPool (DataSize);
1452
1453 if (IfInfo == NULL) {
1454 ShellStatus = SHELL_OUT_OF_RESOURCES;
1455 goto ON_EXIT;
1456 }
1457
1458 Status = IfCb->IfCfg->GetData (
1459 IfCb->IfCfg,
1461 &DataSize,
1462 IfInfo
1463 );
1464
1465 if (EFI_ERROR (Status)) {
1466 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
1467 ShellStatus = SHELL_ACCESS_DENIED;
1468 goto ON_EXIT;
1469 }
1470
1471 for ( Index = 0; Index < (UINTN)(AddrSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS)); Index++) {
1472 IsAddressSet = FALSE;
1473 //
1474 // By default, the prefix length 0 is regarded as 64.
1475 //
1476 if (CfgManAddr[Index].PrefixLength == 0) {
1477 CfgManAddr[Index].PrefixLength = 64;
1478 }
1479
1480 for (Index2 = 0; Index2 < IfInfo->AddressInfoCount; Index2++) {
1481 if (EFI_IP6_EQUAL (&IfInfo->AddressInfo[Index2].Address, &CfgManAddr[Index].Address) &&
1482 (IfInfo->AddressInfo[Index2].PrefixLength == CfgManAddr[Index].PrefixLength))
1483 {
1484 IsAddressSet = TRUE;
1485 break;
1486 }
1487 }
1488
1489 if (!IsAddressSet) {
1490 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_ADDRESS_FAILED), gShellNetwork2HiiHandle);
1492 &CfgManAddr[Index].Address,
1493 &CfgManAddr[Index].PrefixLength
1494 );
1495 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
1496 }
1497 }
1498 } else if (StrCmp (VarArg->Arg, L"gw") == 0) {
1499 //
1500 // Parse till the next tag or the end of command line.
1501 //
1502 VarArg = VarArg->Next;
1504 &VarArg,
1505 &CfgAddr,
1506 &AddrSize
1507 );
1508
1509 if (EFI_ERROR (Status)) {
1510 if (Status == EFI_INVALID_PARAMETER) {
1511 ShellStatus = SHELL_INVALID_PARAMETER;
1512 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS), gShellNetwork2HiiHandle, L"gw");
1513 continue;
1514 } else {
1515 ShellStatus = SHELL_ACCESS_DENIED;
1516 goto ON_EXIT;
1517 }
1518 }
1519
1520 //
1521 // Set static gateway ip6 address list.
1522 //
1523 Status = IfCb->IfCfg->SetData (
1524 IfCb->IfCfg,
1526 AddrSize,
1527 CfgAddr
1528 );
1529
1530 if (EFI_ERROR (Status)) {
1531 ShellStatus = SHELL_ACCESS_DENIED;
1532 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_MAN_GW), gShellNetwork2HiiHandle, Status);
1533 goto ON_EXIT;
1534 }
1535 } else if (StrCmp (VarArg->Arg, L"dns") == 0) {
1536 //
1537 // Parse till the next tag or the end of command line.
1538 //
1539 VarArg = VarArg->Next;
1541 &VarArg,
1542 &CfgAddr,
1543 &AddrSize
1544 );
1545
1546 if (EFI_ERROR (Status)) {
1547 if (Status == EFI_INVALID_PARAMETER) {
1548 ShellStatus = SHELL_INVALID_PARAMETER;
1549 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS), gShellNetwork2HiiHandle, L"dns");
1550 continue;
1551 } else {
1552 ShellStatus = SHELL_ACCESS_DENIED;
1553 goto ON_EXIT;
1554 }
1555 }
1556
1557 //
1558 // Set static DNS server ip6 address list.
1559 //
1560 Status = IfCb->IfCfg->SetData (
1561 IfCb->IfCfg,
1563 AddrSize,
1564 CfgAddr
1565 );
1566
1567 if (EFI_ERROR (Status)) {
1568 ShellStatus = SHELL_ACCESS_DENIED;
1569 goto ON_EXIT;
1570 }
1571 } else if (StrCmp (VarArg->Arg, L"id") == 0) {
1572 //
1573 // Parse till the next tag or the end of command line.
1574 //
1575 VarArg = VarArg->Next;
1576 Status = IfConfig6ParseInterfaceId (&VarArg, &InterfaceId);
1577
1578 if (EFI_ERROR (Status)) {
1579 ShellStatus = SHELL_INVALID_PARAMETER;
1580 goto ON_EXIT;
1581 }
1582
1583 //
1584 // Set alternative interface id.
1585 //
1586 Status = IfCb->IfCfg->SetData (
1587 IfCb->IfCfg,
1590 InterfaceId
1591 );
1592
1593 if (EFI_ERROR (Status)) {
1594 ShellStatus = SHELL_ACCESS_DENIED;
1595 goto ON_EXIT;
1596 }
1597 } else if (StrCmp (VarArg->Arg, L"dad") == 0) {
1598 //
1599 // Parse till the next tag or the end of command line.
1600 //
1601 VarArg = VarArg->Next;
1602 Status = IfConfig6ParseDadXmits (&VarArg, &DadXmits);
1603
1604 if (EFI_ERROR (Status)) {
1605 ShellStatus = SHELL_ACCESS_DENIED;
1606 goto ON_EXIT;
1607 }
1608
1609 //
1610 // Set dad transmits count.
1611 //
1612 Status = IfCb->IfCfg->SetData (
1613 IfCb->IfCfg,
1616 &DadXmits
1617 );
1618
1619 if (EFI_ERROR (Status)) {
1620 ShellStatus = SHELL_ACCESS_DENIED;
1621 goto ON_EXIT;
1622 }
1623 }
1624 }
1625
1626ON_EXIT:
1627
1628 if (CfgManAddr != NULL) {
1629 FreePool (CfgManAddr);
1630 }
1631
1632 if (CfgAddr != NULL) {
1633 FreePool (CfgAddr);
1634 }
1635
1636 if (MappedEvt != NULL) {
1637 gBS->CloseEvent (MappedEvt);
1638 }
1639
1640 if (TimeOutEvt != NULL) {
1641 gBS->CloseEvent (TimeOutEvt);
1642 }
1643
1644 if (IfInfo != NULL) {
1645 FreePool (IfInfo);
1646 }
1647
1648 return ShellStatus;
1649}
1650
1662 IN IFCONFIG6_PRIVATE_DATA *Private
1663 )
1664{
1665 EFI_STATUS Status;
1666 SHELL_STATUS ShellStatus;
1667
1668 ShellStatus = SHELL_SUCCESS;
1669
1670 //
1671 // Get configure information of all interfaces.
1672 //
1673 Status = IfConfig6GetInterfaceInfo (
1674 Private->ImageHandle,
1675 Private->IfName,
1676 &Private->IfList
1677 );
1678
1679 if (EFI_ERROR (Status)) {
1680 ShellStatus = SHELL_NOT_FOUND;
1681 goto ON_EXIT;
1682 }
1683
1684 switch (Private->OpCode) {
1685 case IfConfig6OpList:
1686 ShellStatus = IfConfig6ShowInterfaceInfo (&Private->IfList);
1687 break;
1688
1689 case IfConfig6OpClear:
1690 ShellStatus = IfConfig6ClearInterfaceInfo (&Private->IfList, Private->IfName);
1691 break;
1692
1693 case IfConfig6OpSet:
1694 ShellStatus = IfConfig6SetInterfaceInfo (&Private->IfList, Private->VarArg);
1695 break;
1696
1697 default:
1698 ShellStatus = SHELL_UNSUPPORTED;
1699 }
1700
1701ON_EXIT:
1702
1703 return ShellStatus;
1704}
1705
1712VOID
1714 IN IFCONFIG6_PRIVATE_DATA *Private
1715 )
1716{
1717 LIST_ENTRY *Entry;
1718 LIST_ENTRY *NextEntry;
1720
1721 ASSERT (Private != NULL);
1722
1723 //
1724 // Clean the list which save the set config Args.
1725 //
1726 if (Private->VarArg != NULL) {
1727 IfConfig6FreeArgList (Private->VarArg);
1728 }
1729
1730 if (Private->IfName != NULL) {
1731 FreePool (Private->IfName);
1732 }
1733
1734 //
1735 // Clean the IFCONFIG6_INTERFACE_CB list.
1736 //
1737 Entry = Private->IfList.ForwardLink;
1738 NextEntry = Entry->ForwardLink;
1739
1740 while (Entry != &Private->IfList) {
1741 IfCb = BASE_CR (Entry, IFCONFIG6_INTERFACE_CB, Link);
1742
1743 RemoveEntryList (&IfCb->Link);
1744
1745 if (IfCb->IfId != NULL) {
1746 FreePool (IfCb->IfId);
1747 }
1748
1749 if (IfCb->IfInfo != NULL) {
1750 FreePool (IfCb->IfInfo);
1751 }
1752
1753 FreePool (IfCb);
1754
1755 Entry = NextEntry;
1756 NextEntry = Entry->ForwardLink;
1757 }
1758
1759 FreePool (Private);
1760}
1761
1773EFIAPI
1775 IN EFI_HANDLE ImageHandle,
1776 IN EFI_SYSTEM_TABLE *SystemTable
1777 )
1778{
1779 EFI_STATUS Status;
1780 SHELL_STATUS ShellStatus;
1781 IFCONFIG6_PRIVATE_DATA *Private;
1782 LIST_ENTRY *ParamPackage;
1783 CONST CHAR16 *ValueStr;
1784 ARG_LIST *ArgList;
1785 CHAR16 *ProblemParam;
1786 CHAR16 *Str;
1787
1788 Private = NULL;
1789 Status = EFI_INVALID_PARAMETER;
1790 ShellStatus = SHELL_SUCCESS;
1791
1792 Status = ShellCommandLineParseEx (mIfConfig6CheckList, &ParamPackage, &ProblemParam, TRUE, FALSE);
1793 if (EFI_ERROR (Status)) {
1794 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_COMMAND), gShellNetwork2HiiHandle, L"ifconfig6", ProblemParam);
1795 ShellStatus = SHELL_INVALID_PARAMETER;
1796 goto ON_EXIT;
1797 }
1798
1799 //
1800 // To handle no option.
1801 //
1802 if (!ShellCommandLineGetFlag (ParamPackage, L"-r") && !ShellCommandLineGetFlag (ParamPackage, L"-s") &&
1803 !ShellCommandLineGetFlag (ParamPackage, L"-?") && !ShellCommandLineGetFlag (ParamPackage, L"-l"))
1804 {
1805 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_LACK_OPTION), gShellNetwork2HiiHandle);
1806 ShellStatus = SHELL_INVALID_PARAMETER;
1807 goto ON_EXIT;
1808 }
1809
1810 //
1811 // To handle conflict options.
1812 //
1813 if (((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-s"))) ||
1814 ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||
1815 ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))) ||
1816 ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||
1817 ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))) ||
1818 ((ShellCommandLineGetFlag (ParamPackage, L"-l")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))))
1819 {
1820 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_CONFLICT_OPTIONS), gShellNetwork2HiiHandle);
1821 ShellStatus = SHELL_INVALID_PARAMETER;
1822 goto ON_EXIT;
1823 }
1824
1825 Private = AllocateZeroPool (sizeof (IFCONFIG6_PRIVATE_DATA));
1826
1827 if (Private == NULL) {
1828 ShellStatus = SHELL_OUT_OF_RESOURCES;
1829 goto ON_EXIT;
1830 }
1831
1832 InitializeListHead (&Private->IfList);
1833
1834 //
1835 // To get interface name for the list option.
1836 //
1837 if (ShellCommandLineGetFlag (ParamPackage, L"-l")) {
1838 Private->OpCode = IfConfig6OpList;
1839 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");
1840 if (ValueStr != NULL) {
1841 Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
1842 if (Str == NULL) {
1843 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork2HiiHandle, L"ifconfig6");
1844 ShellStatus = SHELL_OUT_OF_RESOURCES;
1845 goto ON_EXIT;
1846 }
1847
1848 Private->IfName = Str;
1849 }
1850 }
1851
1852 //
1853 // To get interface name for the clear option.
1854 //
1855 if (ShellCommandLineGetFlag (ParamPackage, L"-r")) {
1856 Private->OpCode = IfConfig6OpClear;
1857 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");
1858 if (ValueStr != NULL) {
1859 Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
1860 if (Str == NULL) {
1861 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork2HiiHandle, L"ifconfig6");
1862 ShellStatus = SHELL_OUT_OF_RESOURCES;
1863 goto ON_EXIT;
1864 }
1865
1866 Private->IfName = Str;
1867 }
1868 }
1869
1870 //
1871 // To get interface name and corresponding Args for the set option.
1872 //
1873 if (ShellCommandLineGetFlag (ParamPackage, L"-s")) {
1874 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-s");
1875 if (ValueStr == NULL) {
1876 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_INTERFACE), gShellNetwork2HiiHandle);
1877 ShellStatus = SHELL_INVALID_PARAMETER;
1878 goto ON_EXIT;
1879 }
1880
1881 //
1882 // To split the configuration into multi-section.
1883 //
1884 ArgList = IfConfig6SplitStrToList (ValueStr, L' ');
1885 if (ArgList == NULL) {
1886 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork2HiiHandle, L"ifconfig6");
1887 ShellStatus = SHELL_OUT_OF_RESOURCES;
1888 goto ON_EXIT;
1889 }
1890
1891 Private->OpCode = IfConfig6OpSet;
1892 Private->IfName = ArgList->Arg;
1893
1894 Private->VarArg = ArgList->Next;
1895
1896 if ((Private->IfName == NULL) || (Private->VarArg == NULL)) {
1897 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_COMMAND), gShellNetwork2HiiHandle);
1898 ShellStatus = SHELL_INVALID_PARAMETER;
1899 goto ON_EXIT;
1900 }
1901 }
1902
1903 //
1904 // Main process of ifconfig6.
1905 //
1906 ShellStatus = IfConfig6 (Private);
1907
1908ON_EXIT:
1909
1910 ShellCommandLineFreeVarList (ParamPackage);
1911 if (Private != NULL) {
1912 IfConfig6Cleanup (Private);
1913 }
1914
1915 return ShellStatus;
1916}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
VOID IfConfig6PrintIpAddr(IN EFI_IPv6_ADDRESS *Ip, IN UINT8 *PrefixLen)
Definition: Ifconfig6.c:361
VOID IfConfig6FreeArgList(ARG_LIST *List)
Definition: Ifconfig6.c:157
SHELL_STATUS IfConfig6ClearInterfaceInfo(IN LIST_ENTRY *IfList, IN CHAR16 *IfName)
Definition: Ifconfig6.c:1106
EFI_STATUS IfConfig6ParseInterfaceId(IN OUT ARG_LIST **Arg, OUT EFI_IP6_CONFIG_INTERFACE_ID **IfId)
Definition: Ifconfig6.c:628
SHELL_STATUS EFIAPI ShellCommandRunIfconfig6(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Ifconfig6.c:1774
SHELL_STATUS IfConfig6(IN IFCONFIG6_PRIVATE_DATA *Private)
Definition: Ifconfig6.c:1661
EFI_STATUS IfConfig6ParseDadXmits(IN OUT ARG_LIST **Arg, OUT UINT32 *Xmits)
Definition: Ifconfig6.c:686
SHELL_STATUS IfConfig6SetInterfaceInfo(IN LIST_ENTRY *IfList, IN ARG_LIST *VarArg)
Definition: Ifconfig6.c:1180
ARG_LIST * IfConfig6SplitStrToList(IN CONST CHAR16 *String, IN CHAR16 Separator)
Definition: Ifconfig6.c:182
EFI_STATUS IfConfig6ParseGwDnsAddressList(IN OUT ARG_LIST **Arg, OUT EFI_IPv6_ADDRESS **Buf, OUT UINTN *BufSize)
Definition: Ifconfig6.c:534
VOID EFIAPI IfConfig6ManualAddressNotify(IN EFI_EVENT Event, IN VOID *Context)
Definition: Ifconfig6.c:318
SHELL_STATUS IfConfig6ShowInterfaceInfo(IN LIST_ENTRY *IfList)
Definition: Ifconfig6.c:978
EFI_STATUS IfConfig6GetInterfaceInfo(IN EFI_HANDLE ImageHandle, IN CHAR16 *IfName, IN LIST_ENTRY *IfList)
Definition: Ifconfig6.c:726
VAR_CHECK_CODE IfConfig6RetriveCheckListByName(IN VAR_CHECK_ITEM *CheckList, IN CHAR16 *Name, IN BOOLEAN Init)
Definition: Ifconfig6.c:257
VOID IfConfig6PrintMacAddr(IN UINT8 *Node, IN UINT32 Size)
Definition: Ifconfig6.c:334
VOID IfConfig6Cleanup(IN IFCONFIG6_PRIVATE_DATA *Private)
Definition: Ifconfig6.c:1713
EFI_STATUS IfConfig6ParseManualAddressList(IN OUT ARG_LIST **Arg, OUT EFI_IP6_CONFIG_MANUAL_ADDRESS **Buf, OUT UINTN *BufSize)
Definition: Ifconfig6.c:429
@ Ip6ConfigDataTypeDupAddrDetectTransmits
Definition: Ip6Config.h:59
@ Ip6ConfigDataTypeGateway
Definition: Ip6Config.h:79
@ Ip6ConfigDataTypeAltInterfaceId
Definition: Ip6Config.h:42
@ Ip6ConfigDataTypeManualAddress
Definition: Ip6Config.h:68
@ Ip6ConfigDataTypeInterfaceInfo
Definition: Ip6Config.h:32
@ Ip6ConfigDataTypePolicy
Definition: Ip6Config.h:50
@ Ip6ConfigDataTypeDnsServer
Definition: Ip6Config.h:90
EFI_IP6_CONFIG_POLICY
Definition: Ip6Config.h:154
@ Ip6ConfigPolicyManual
Definition: Ip6Config.h:163
@ Ip6ConfigPolicyAutomatic
Definition: Ip6Config.h:175
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define BASE_CR(Record, TYPE, Field)
Definition: Base.h:891
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_ACCESS_DENIED
Definition: Shell.h:106
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_UNSUPPORTED
Definition: Shell.h:40
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI NetLibStrToIp6andPrefix(IN CONST CHAR16 *String, OUT EFI_IPv6_ADDRESS *Ip6Address, OUT UINT8 *PrefixLength)
Definition: DxeNetLib.c:3185
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeMaxValue
A flag followed by all the command line data before the next flag.
Definition: ShellLib.h:704
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
EFI_STATUS EFIAPI ShellCommandLineParseEx(IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, OUT CHAR16 **ProblemParam OPTIONAL, IN BOOLEAN AutoPageBreak, IN BOOLEAN AlwaysAllowNumbers)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
IPv6_ADDRESS EFI_IPv6_ADDRESS
Definition: UefiBaseType.h:90
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
@ TimerRelative
Definition: UefiSpec.h:539
@ ByProtocol
Definition: UefiSpec.h:1518
UINT8 PrefixLength
The length of the prefix associated with the Address.
Definition: Ip6.h:222
EFI_IPv6_ADDRESS Address
The IPv6 address.
Definition: Ip6.h:221
EFI_IP6_ROUTE_TABLE * RouteTable
Definition: Ip6Config.h:138
EFI_IP6_ADDRESS_INFO * AddressInfo
Definition: Ip6Config.h:129
EFI_MAC_ADDRESS HwAddress
Definition: Ip6Config.h:118
UINT8 PrefixLength
The length, in bits, of the prefix associated with this Address.
Definition: Ip6Config.h:196
EFI_IPv6_ADDRESS Address
The IPv6 unicast address.
Definition: Ip6Config.h:194
BOOLEAN IsAnycast
Set to TRUE if Address is anycast.
Definition: Ip6Config.h:195
UINT8 PrefixLength
Definition: Ip6.h:243
EFI_IPv6_ADDRESS Gateway
Definition: Ip6.h:235
EFI_IPv6_ADDRESS Destination
Definition: Ip6.h:239