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