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