]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | Shell application for VLAN configuration.\r | |
3 | \r | |
be6cd654 | 4 | Copyright (c) 2009 - 2016, 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 <Uefi.h>\r | |
17 | \r | |
18 | #include <Protocol/VlanConfig.h>\r | |
19 | \r | |
20 | #include <Library/UefiApplicationEntryPoint.h>\r | |
21 | #include <Library/UefiLib.h>\r | |
22 | #include <Library/ShellLib.h>\r | |
23 | #include <Library/MemoryAllocationLib.h>\r | |
24 | #include <Library/HiiLib.h>\r | |
25 | #include <Library/UefiBootServicesTableLib.h>\r | |
be6cd654 | 26 | #include <Library/UefiHiiServicesLib.h>\r |
a3bcde70 HT |
27 | #include <Library/NetLib.h>\r |
28 | \r | |
be6cd654 ZL |
29 | //\r |
30 | // String token ID of VConfig command help message text.\r | |
31 | //\r | |
32 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStringVConfigHelpTokenId = STRING_TOKEN (STR_VCONFIG_HELP);\r | |
33 | \r | |
a3bcde70 HT |
34 | #define INVALID_NIC_INDEX 0xffff\r |
35 | #define INVALID_VLAN_ID 0xffff\r | |
36 | \r | |
37 | //\r | |
38 | // This is the generated String package data for all .UNI files.\r | |
39 | // This data array is ready to be used as input of HiiAddPackages() to\r | |
40 | // create a packagelist (which contains Form packages, String packages, etc).\r | |
41 | //\r | |
42 | extern UINT8 VConfigStrings[];\r | |
43 | \r | |
44 | EFI_HANDLE mImageHandle = NULL;\r | |
45 | EFI_HII_HANDLE mHiiHandle = NULL;\r | |
46 | \r | |
47 | SHELL_PARAM_ITEM mParamList[] = {\r | |
48 | {\r | |
49 | L"-l",\r | |
50 | TypeValue\r | |
51 | },\r | |
52 | {\r | |
53 | L"-a",\r | |
54 | TypeMaxValue\r | |
55 | },\r | |
56 | {\r | |
57 | L"-d",\r | |
58 | TypeValue\r | |
59 | },\r | |
60 | {\r | |
61 | NULL,\r | |
62 | TypeMax\r | |
63 | }\r | |
64 | };\r | |
65 | \r | |
66 | /**\r | |
67 | Locate the network interface handle buffer.\r | |
68 | \r | |
69 | @param[out] NumberOfHandles Pointer to the number of handles.\r | |
70 | @param[out] HandleBuffer Pointer to the buffer to store the returned handles.\r | |
71 | \r | |
72 | **/\r | |
73 | VOID\r | |
74 | LocateNicHandleBuffer (\r | |
75 | OUT UINTN *NumberOfHandles,\r | |
76 | OUT EFI_HANDLE **HandleBuffer\r | |
77 | )\r | |
78 | {\r | |
79 | EFI_STATUS Status;\r | |
80 | \r | |
81 | *NumberOfHandles = 0;\r | |
82 | *HandleBuffer = NULL;\r | |
83 | \r | |
84 | Status = gBS->LocateHandleBuffer (\r | |
85 | ByProtocol,\r | |
86 | &gEfiVlanConfigProtocolGuid,\r | |
87 | NULL,\r | |
88 | NumberOfHandles,\r | |
89 | HandleBuffer\r | |
90 | );\r | |
91 | if (EFI_ERROR (Status)) {\r | |
92 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_LOCATE_FAIL), mHiiHandle, Status);\r | |
93 | }\r | |
94 | }\r | |
95 | \r | |
96 | /**\r | |
97 | Extract the decimal index from the network interface name.\r | |
98 | \r | |
99 | @param[in] Name Name of the network interface.\r | |
100 | \r | |
101 | @retval INVALID_NIC_INDEX Failed to extract the network interface index.\r | |
102 | @return others The network interface index.\r | |
103 | \r | |
104 | **/\r | |
105 | UINTN\r | |
106 | NicNameToIndex (\r | |
107 | IN CHAR16 *Name\r | |
108 | )\r | |
109 | {\r | |
110 | CHAR16 *Str;\r | |
111 | \r | |
112 | Str = Name + 3;\r | |
113 | if ((StrnCmp (Name, L"eth", 3) != 0) || (*Str == 0)) {\r | |
114 | return INVALID_NIC_INDEX;\r | |
115 | }\r | |
116 | \r | |
117 | while (*Str != 0) {\r | |
118 | if ((*Str < L'0') || (*Str > L'9')) {\r | |
119 | return INVALID_NIC_INDEX;\r | |
120 | }\r | |
121 | \r | |
122 | Str++;\r | |
123 | }\r | |
124 | \r | |
125 | return (UINT16) StrDecimalToUintn (Name + 3);\r | |
126 | }\r | |
127 | \r | |
128 | /**\r | |
129 | Find network interface device handle by its name.\r | |
130 | \r | |
131 | @param[in] Name Name of the network interface.\r | |
132 | \r | |
133 | @retval NULL Cannot find the network interface.\r | |
134 | @return others Handle of the network interface.\r | |
135 | \r | |
136 | **/\r | |
137 | EFI_HANDLE\r | |
138 | NicNameToHandle (\r | |
139 | IN CHAR16 *Name\r | |
140 | )\r | |
141 | {\r | |
142 | UINTN NumberOfHandles;\r | |
143 | EFI_HANDLE *HandleBuffer;\r | |
144 | UINTN Index;\r | |
145 | EFI_HANDLE Handle;\r | |
146 | \r | |
147 | //\r | |
148 | // Find all NIC handles.\r | |
149 | //\r | |
150 | LocateNicHandleBuffer (&NumberOfHandles, &HandleBuffer);\r | |
151 | if (NumberOfHandles == 0) {\r | |
152 | return NULL;\r | |
153 | }\r | |
154 | \r | |
155 | Index = NicNameToIndex (Name);\r | |
156 | if (Index >= NumberOfHandles) {\r | |
157 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_INVALID_IF), mHiiHandle, Name);\r | |
158 | Handle = NULL;\r | |
159 | } else {\r | |
160 | Handle = HandleBuffer[Index];\r | |
161 | }\r | |
162 | \r | |
163 | FreePool (HandleBuffer);\r | |
164 | return Handle;\r | |
165 | }\r | |
166 | \r | |
167 | /**\r | |
168 | Open VlanConfig protocol from a handle.\r | |
169 | \r | |
170 | @param[in] Handle The handle to open the VlanConfig protocol.\r | |
171 | \r | |
172 | @return The VlanConfig protocol interface.\r | |
173 | \r | |
174 | **/\r | |
175 | EFI_VLAN_CONFIG_PROTOCOL *\r | |
176 | OpenVlanConfigProtocol (\r | |
177 | IN EFI_HANDLE Handle\r | |
178 | )\r | |
179 | {\r | |
180 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
181 | \r | |
182 | VlanConfig = NULL;\r | |
183 | gBS->OpenProtocol (\r | |
184 | Handle,\r | |
185 | &gEfiVlanConfigProtocolGuid,\r | |
186 | (VOID **) &VlanConfig,\r | |
187 | mImageHandle,\r | |
188 | Handle,\r | |
189 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
190 | );\r | |
191 | \r | |
192 | return VlanConfig;\r | |
193 | }\r | |
194 | \r | |
195 | /**\r | |
196 | Close VlanConfig protocol of a handle.\r | |
197 | \r | |
198 | @param[in] Handle The handle to close the VlanConfig protocol.\r | |
199 | \r | |
200 | **/\r | |
201 | VOID\r | |
202 | CloseVlanConfigProtocol (\r | |
203 | IN EFI_HANDLE Handle\r | |
204 | )\r | |
205 | {\r | |
206 | gBS->CloseProtocol (\r | |
207 | Handle,\r | |
208 | &gEfiVlanConfigProtocolGuid,\r | |
209 | mImageHandle,\r | |
210 | Handle\r | |
211 | );\r | |
212 | }\r | |
213 | \r | |
214 | /**\r | |
215 | Display VLAN configuration of a network interface.\r | |
216 | \r | |
217 | @param[in] Handle Handle of the network interface.\r | |
218 | @param[in] NicIndex Index of the network interface.\r | |
219 | \r | |
220 | **/\r | |
221 | VOID\r | |
222 | ShowNicVlanInfo (\r | |
223 | IN EFI_HANDLE Handle,\r | |
224 | IN UINTN NicIndex\r | |
225 | )\r | |
226 | {\r | |
227 | CHAR16 *MacStr;\r | |
228 | EFI_STATUS Status;\r | |
229 | UINTN Index;\r | |
230 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
231 | UINT16 NumberOfVlan;\r | |
232 | EFI_VLAN_FIND_DATA *VlanData;\r | |
233 | \r | |
234 | VlanConfig = OpenVlanConfigProtocol (Handle);\r | |
235 | if (VlanConfig == NULL) {\r | |
236 | return ;\r | |
237 | }\r | |
238 | \r | |
239 | MacStr = NULL;\r | |
240 | Status = NetLibGetMacString (Handle, mImageHandle, &MacStr);\r | |
241 | if (EFI_ERROR (Status)) {\r | |
242 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_MAC_FAIL), mHiiHandle, Status);\r | |
243 | goto Exit;\r | |
244 | }\r | |
245 | \r | |
246 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_ETH_MAC), mHiiHandle, NicIndex, MacStr);\r | |
247 | \r | |
248 | Status = VlanConfig->Find (VlanConfig, NULL, &NumberOfVlan, &VlanData);\r | |
249 | if (EFI_ERROR (Status)) {\r | |
250 | if (Status == EFI_NOT_FOUND) {\r | |
251 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_VLAN), mHiiHandle);\r | |
252 | } else {\r | |
253 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_FIND_FAIL), mHiiHandle, Status);\r | |
254 | }\r | |
255 | \r | |
256 | goto Exit;\r | |
257 | }\r | |
258 | \r | |
259 | for (Index = 0; Index < NumberOfVlan; Index++) {\r | |
260 | ShellPrintHiiEx (\r | |
261 | -1,\r | |
262 | -1,\r | |
263 | NULL,\r | |
264 | STRING_TOKEN (STR_VCONFIG_VLAN_DISPLAY),\r | |
265 | mHiiHandle,\r | |
266 | VlanData[Index].VlanId,\r | |
267 | VlanData[Index].Priority\r | |
268 | );\r | |
269 | }\r | |
270 | \r | |
271 | FreePool (VlanData);\r | |
272 | \r | |
273 | Exit:\r | |
274 | CloseVlanConfigProtocol (Handle);\r | |
275 | \r | |
276 | if (MacStr != NULL) {\r | |
277 | FreePool (MacStr);\r | |
278 | }\r | |
279 | }\r | |
280 | \r | |
281 | /**\r | |
282 | Display the VLAN configuration of all, or a specified network interface.\r | |
283 | \r | |
284 | @param[in] Name Name of the network interface. If NULL, the VLAN\r | |
285 | configuration of all network will be displayed.\r | |
286 | \r | |
287 | **/\r | |
288 | VOID\r | |
289 | DisplayVlan (\r | |
290 | IN CHAR16 *Name OPTIONAL\r | |
291 | )\r | |
292 | {\r | |
293 | UINTN NumberOfHandles;\r | |
294 | EFI_HANDLE *HandleBuffer;\r | |
295 | UINTN Index;\r | |
296 | EFI_HANDLE NicHandle;\r | |
297 | \r | |
298 | if (Name != NULL) {\r | |
299 | //\r | |
300 | // Display specified NIC\r | |
301 | //\r | |
302 | NicHandle = NicNameToHandle (Name);\r | |
303 | if (NicHandle == NULL) {\r | |
304 | return ;\r | |
305 | }\r | |
306 | \r | |
307 | ShowNicVlanInfo (NicHandle, 0);\r | |
308 | return ;\r | |
309 | }\r | |
310 | \r | |
311 | //\r | |
312 | // Find all NIC handles\r | |
313 | //\r | |
314 | LocateNicHandleBuffer (&NumberOfHandles, &HandleBuffer);\r | |
315 | if (NumberOfHandles == 0) {\r | |
316 | return ;\r | |
317 | }\r | |
318 | \r | |
319 | for (Index = 0; Index < NumberOfHandles; Index++) {\r | |
320 | ShowNicVlanInfo (HandleBuffer[Index], Index);\r | |
321 | }\r | |
322 | \r | |
323 | FreePool (HandleBuffer);\r | |
324 | }\r | |
325 | \r | |
326 | /**\r | |
327 | Convert a NULL-terminated unicode decimal VLAN ID string to VLAN ID.\r | |
328 | \r | |
329 | @param[in] String Pointer to VLAN ID string from user input.\r | |
330 | \r | |
331 | @retval Value translated from String, or INVALID_VLAN_ID is string is invalid.\r | |
332 | \r | |
333 | **/\r | |
334 | UINT16\r | |
335 | StrToVlanId (\r | |
336 | IN CHAR16 *String\r | |
337 | )\r | |
338 | {\r | |
339 | CHAR16 *Str;\r | |
340 | \r | |
341 | if (String == NULL) {\r | |
342 | return INVALID_VLAN_ID;\r | |
343 | }\r | |
344 | \r | |
345 | Str = String;\r | |
346 | while ((*Str >= '0') && (*Str <= '9')) {\r | |
347 | Str++;\r | |
348 | }\r | |
349 | \r | |
350 | if (*Str != 0) {\r | |
351 | return INVALID_VLAN_ID;\r | |
352 | }\r | |
353 | \r | |
354 | return (UINT16) StrDecimalToUintn (String);\r | |
355 | }\r | |
356 | \r | |
357 | /**\r | |
358 | Add a VLAN device.\r | |
359 | \r | |
360 | @param[in] ParamStr Parameter string from user input.\r | |
361 | \r | |
362 | **/\r | |
363 | VOID\r | |
364 | AddVlan (\r | |
365 | IN CHAR16 *ParamStr\r | |
366 | )\r | |
367 | {\r | |
368 | CHAR16 *Name;\r | |
369 | CHAR16 *VlanIdStr;\r | |
370 | CHAR16 *PriorityStr;\r | |
371 | CHAR16 *StrPtr;\r | |
372 | BOOLEAN IsSpace;\r | |
373 | UINTN VlanId;\r | |
374 | UINTN Priority;\r | |
375 | EFI_HANDLE Handle;\r | |
376 | EFI_HANDLE VlanHandle;\r | |
377 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
378 | EFI_STATUS Status;\r | |
379 | \r | |
380 | VlanConfig = NULL;\r | |
381 | Priority = 0;\r | |
382 | \r | |
383 | if (ParamStr == NULL) {\r | |
384 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_IF), mHiiHandle);\r | |
385 | return ;\r | |
386 | }\r | |
387 | \r | |
388 | StrPtr = AllocateCopyPool (StrSize (ParamStr), ParamStr);\r | |
389 | if (StrPtr == NULL) {\r | |
390 | return ;\r | |
391 | }\r | |
392 | \r | |
393 | Name = StrPtr;\r | |
394 | VlanIdStr = NULL;\r | |
395 | PriorityStr = NULL;\r | |
396 | IsSpace = FALSE;\r | |
397 | while (*StrPtr != 0) {\r | |
398 | if (*StrPtr == L' ') {\r | |
399 | *StrPtr = 0;\r | |
400 | IsSpace = TRUE;\r | |
401 | } else {\r | |
402 | if (IsSpace) {\r | |
403 | //\r | |
404 | // Start of a parameter.\r | |
405 | //\r | |
406 | if (VlanIdStr == NULL) {\r | |
407 | //\r | |
408 | // 2nd parameter is VLAN ID.\r | |
409 | //\r | |
410 | VlanIdStr = StrPtr;\r | |
411 | } else if (PriorityStr == NULL) {\r | |
412 | //\r | |
413 | // 3rd parameter is Priority.\r | |
414 | //\r | |
415 | PriorityStr = StrPtr;\r | |
416 | } else {\r | |
417 | //\r | |
418 | // Ignore else parameters.\r | |
419 | //\r | |
420 | break;\r | |
421 | }\r | |
422 | }\r | |
423 | \r | |
424 | IsSpace = FALSE;\r | |
425 | }\r | |
426 | \r | |
427 | StrPtr++;\r | |
428 | }\r | |
429 | \r | |
430 | Handle = NicNameToHandle (Name);\r | |
431 | if (Handle == NULL) {\r | |
432 | goto Exit;\r | |
433 | }\r | |
434 | \r | |
435 | VlanConfig = OpenVlanConfigProtocol (Handle);\r | |
436 | if (VlanConfig == NULL) {\r | |
437 | goto Exit;\r | |
438 | }\r | |
439 | \r | |
440 | //\r | |
441 | // Check VLAN ID.\r | |
442 | //\r | |
443 | if ((VlanIdStr == NULL) || (*VlanIdStr == 0)) {\r | |
444 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_VID), mHiiHandle);\r | |
445 | goto Exit;\r | |
446 | }\r | |
447 | \r | |
448 | VlanId = StrToVlanId (VlanIdStr);\r | |
449 | if (VlanId > 4094) {\r | |
450 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_INVALID_VID), mHiiHandle, VlanIdStr);\r | |
451 | goto Exit;\r | |
452 | }\r | |
453 | \r | |
454 | //\r | |
455 | // Check Priority.\r | |
456 | //\r | |
457 | if ((PriorityStr != NULL) && (*PriorityStr != 0)) {\r | |
458 | Priority = StrDecimalToUintn (PriorityStr);\r | |
459 | if (Priority > 7) {\r | |
460 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_INVALID_PRIORITY), mHiiHandle, PriorityStr);\r | |
461 | goto Exit;\r | |
462 | }\r | |
463 | }\r | |
464 | \r | |
465 | //\r | |
466 | // Set VLAN\r | |
467 | //\r | |
468 | Status = VlanConfig->Set (VlanConfig, (UINT16) VlanId, (UINT8) Priority);\r | |
469 | if (EFI_ERROR (Status)) {\r | |
470 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_SET_FAIL), mHiiHandle, Status);\r | |
471 | goto Exit;\r | |
472 | }\r | |
473 | \r | |
474 | //\r | |
475 | // Connect the VLAN device.\r | |
476 | //\r | |
477 | VlanHandle = NetLibGetVlanHandle (Handle, (UINT16) VlanId);\r | |
478 | if (VlanHandle != NULL) {\r | |
479 | gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r | |
480 | }\r | |
481 | \r | |
482 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_SET_SUCCESS), mHiiHandle);\r | |
483 | \r | |
484 | Exit:\r | |
485 | if (VlanConfig != NULL) {\r | |
486 | CloseVlanConfigProtocol (Handle);\r | |
487 | }\r | |
488 | \r | |
489 | FreePool (Name);\r | |
490 | }\r | |
491 | \r | |
492 | /**\r | |
493 | Remove a VLAN device.\r | |
494 | \r | |
495 | @param[in] ParamStr Parameter string from user input.\r | |
496 | \r | |
497 | **/\r | |
498 | VOID\r | |
499 | DeleteVlan (\r | |
686d4d4a | 500 | IN CHAR16 *ParamStr\r |
a3bcde70 HT |
501 | )\r |
502 | {\r | |
503 | CHAR16 *Name;\r | |
504 | CHAR16 *VlanIdStr;\r | |
505 | CHAR16 *StrPtr;\r | |
506 | UINTN VlanId;\r | |
507 | EFI_HANDLE Handle;\r | |
508 | EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r | |
509 | EFI_STATUS Status;\r | |
510 | UINT16 NumberOfVlan;\r | |
511 | EFI_VLAN_FIND_DATA *VlanData;\r | |
512 | \r | |
513 | VlanConfig = NULL;\r | |
514 | \r | |
515 | if (ParamStr == NULL) {\r | |
516 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_IF), mHiiHandle);\r | |
517 | return ;\r | |
518 | }\r | |
519 | \r | |
520 | StrPtr = AllocateCopyPool (StrSize (ParamStr), ParamStr);\r | |
521 | if (StrPtr == NULL) {\r | |
522 | return ;\r | |
523 | }\r | |
524 | \r | |
525 | Name = StrPtr;\r | |
526 | VlanIdStr = NULL;\r | |
527 | while (*StrPtr != 0) {\r | |
528 | if (*StrPtr == L'.') {\r | |
529 | *StrPtr = 0;\r | |
530 | VlanIdStr = StrPtr + 1;\r | |
531 | break;\r | |
532 | }\r | |
533 | \r | |
534 | StrPtr++;\r | |
535 | }\r | |
536 | \r | |
537 | Handle = NicNameToHandle (Name);\r | |
538 | if (Handle == NULL) {\r | |
539 | goto Exit;\r | |
540 | }\r | |
541 | \r | |
542 | VlanConfig = OpenVlanConfigProtocol (Handle);\r | |
543 | if (VlanConfig == NULL) {\r | |
544 | goto Exit;\r | |
545 | }\r | |
546 | \r | |
547 | //\r | |
548 | // Check VLAN ID\r | |
549 | //\r | |
550 | if (VlanIdStr == NULL || *VlanIdStr == 0) {\r | |
551 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_VID), mHiiHandle);\r | |
552 | goto Exit;\r | |
553 | }\r | |
554 | \r | |
555 | VlanId = StrToVlanId (VlanIdStr);\r | |
556 | if (VlanId > 4094) {\r | |
557 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_INVALID_VID), mHiiHandle, VlanIdStr);\r | |
558 | goto Exit;\r | |
559 | }\r | |
560 | \r | |
561 | //\r | |
562 | // Delete VLAN.\r | |
563 | //\r | |
564 | Status = VlanConfig->Remove (VlanConfig, (UINT16) VlanId);\r | |
565 | if (EFI_ERROR (Status)) {\r | |
566 | if (Status == EFI_NOT_FOUND) {\r | |
567 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NOT_FOUND), mHiiHandle);\r | |
568 | } else {\r | |
569 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_REMOVE_FAIL), mHiiHandle, Status);\r | |
570 | }\r | |
571 | \r | |
572 | goto Exit;\r | |
573 | }\r | |
574 | \r | |
575 | //\r | |
576 | // Check whether this is the last VLAN to remove.\r | |
577 | //\r | |
578 | Status = VlanConfig->Find (VlanConfig, NULL, &NumberOfVlan, &VlanData);\r | |
579 | if (EFI_ERROR (Status)) {\r | |
580 | //\r | |
581 | // This is the last VLAN to remove, try to connect the controller handle.\r | |
582 | //\r | |
583 | gBS->ConnectController (Handle, NULL, NULL, TRUE);\r | |
584 | } else {\r | |
585 | FreePool (VlanData);\r | |
586 | }\r | |
587 | \r | |
588 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_REMOVE_SUCCESS), mHiiHandle);\r | |
589 | \r | |
590 | Exit:\r | |
591 | if (VlanConfig != NULL) {\r | |
592 | CloseVlanConfigProtocol (Handle);\r | |
593 | }\r | |
594 | \r | |
595 | FreePool (Name);\r | |
596 | }\r | |
597 | \r | |
598 | /**\r | |
599 | The actual entry point for the application.\r | |
600 | \r | |
601 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
602 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
603 | \r | |
604 | @retval EFI_SUCCESS The entry point executed successfully.\r | |
605 | @retval other Some error occur when executing this entry point.\r | |
606 | \r | |
607 | **/\r | |
608 | EFI_STATUS\r | |
609 | EFIAPI\r | |
610 | VlanConfigMain (\r | |
611 | IN EFI_HANDLE ImageHandle,\r | |
612 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
613 | )\r | |
614 | {\r | |
615 | LIST_ENTRY *List;\r | |
616 | CONST CHAR16 *Str;\r | |
be6cd654 ZL |
617 | EFI_HII_PACKAGE_LIST_HEADER *PackageList;\r |
618 | EFI_STATUS Status;\r | |
a3bcde70 HT |
619 | \r |
620 | mImageHandle = ImageHandle;\r | |
be6cd654 ZL |
621 | \r |
622 | //\r | |
623 | // Retrieve HII package list from ImageHandle\r | |
624 | //\r | |
625 | Status = gBS->OpenProtocol (\r | |
626 | ImageHandle,\r | |
627 | &gEfiHiiPackageListProtocolGuid,\r | |
628 | (VOID **) &PackageList,\r | |
629 | ImageHandle,\r | |
630 | NULL,\r | |
631 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
632 | );\r | |
633 | if (EFI_ERROR (Status)) {\r | |
634 | return Status;\r | |
635 | }\r | |
a3bcde70 HT |
636 | \r |
637 | //\r | |
be6cd654 | 638 | // Publish HII package list to HII Database.\r |
a3bcde70 | 639 | //\r |
be6cd654 ZL |
640 | Status = gHiiDatabase->NewPackageList (\r |
641 | gHiiDatabase,\r | |
642 | PackageList,\r | |
643 | NULL,\r | |
644 | &mHiiHandle\r | |
645 | );\r | |
646 | if (EFI_ERROR (Status)) {\r | |
647 | return Status;\r | |
648 | }\r | |
649 | \r | |
a3bcde70 HT |
650 | if (mHiiHandle == NULL) {\r |
651 | return EFI_SUCCESS;\r | |
652 | }\r | |
653 | \r | |
654 | List = NULL;\r | |
655 | ShellCommandLineParseEx (mParamList, &List, NULL, FALSE, FALSE);\r | |
656 | if (List == NULL) {\r | |
657 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_ARG), mHiiHandle);\r | |
658 | goto Exit;\r | |
659 | }\r | |
660 | \r | |
a3bcde70 HT |
661 | if (ShellCommandLineGetFlag (List, L"-l")) {\r |
662 | Str = ShellCommandLineGetValue (List, L"-l");\r | |
663 | DisplayVlan ((CHAR16 *) Str);\r | |
664 | goto Exit;\r | |
665 | }\r | |
666 | \r | |
667 | if (ShellCommandLineGetFlag (List, L"-a")) {\r | |
668 | Str = ShellCommandLineGetValue (List, L"-a");\r | |
669 | AddVlan ((CHAR16 *) Str);\r | |
670 | goto Exit;\r | |
671 | }\r | |
672 | \r | |
673 | if (ShellCommandLineGetFlag (List, L"-d")) {\r | |
674 | Str = ShellCommandLineGetValue (List, L"-d");\r | |
675 | DeleteVlan ((CHAR16 *) Str);\r | |
676 | goto Exit;\r | |
677 | }\r | |
678 | \r | |
679 | //\r | |
680 | // No valid argument till now.\r | |
681 | //\r | |
682 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VCONFIG_NO_ARG), mHiiHandle);\r | |
683 | \r | |
684 | Exit:\r | |
685 | if (List != NULL) {\r | |
686 | ShellCommandLineFreeVarList (List);\r | |
687 | }\r | |
688 | \r | |
689 | //\r | |
690 | // Remove our string package from HII database.\r | |
691 | //\r | |
692 | HiiRemovePackages (mHiiHandle);\r | |
693 | \r | |
694 | return EFI_SUCCESS;\r | |
695 | }\r |