]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Application/IfConfig6/IfConfig6.c
NetworkPkg: Support print help information using -? command.
[mirror_edk2.git] / NetworkPkg / Application / IfConfig6 / IfConfig6.c
index 9e228ca7bc76b50e5af6ecb204f86e07f746fce3..8bd62437492404b74595dc92f1fc3bcb04acd2b4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation for Shell application IfConfig6.\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -19,6 +19,7 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiHiiServicesLib.h>\r
 #include <Library/HiiLib.h>\r
 #include <Library/NetLib.h>\r
 \r
@@ -46,10 +47,6 @@ SHELL_PARAM_ITEM    mIfConfig6CheckList[] = {
     L"-r",\r
     TypeValue\r
   },\r
-  {\r
-    L"-?",\r
-    TypeFlag\r
-  },\r
   {\r
     NULL,\r
     TypeMax\r
@@ -127,16 +124,15 @@ SplitStrToList (
   ARG_LIST    *ArgList;\r
   ARG_LIST    *ArgNode;\r
 \r
-  if (*String == L'\0') {\r
+  if (String == NULL || *String == L'\0') {\r
     return NULL;\r
   }\r
 \r
   //\r
   // Copy the CONST string to a local copy.\r
   //\r
-  Str     = (CHAR16 *) AllocateZeroPool (StrSize (String));\r
+  Str     = AllocateCopyPool (StrSize (String), String);\r
   ASSERT (Str != NULL);\r
-  Str     = StrnCpy (Str, String, StrLen (String));\r
   ArgStr  = Str;\r
 \r
   //\r
@@ -1649,20 +1645,45 @@ IfConfig6Initialize (
   IN  EFI_SYSTEM_TABLE    *SystemTable\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  IFCONFIG6_PRIVATE_DATA    *Private;\r
-  LIST_ENTRY                *ParamPackage;\r
-  CONST CHAR16              *ValueStr;\r
-  ARG_LIST                  *ArgList;\r
-  CHAR16                    *ProblemParam;\r
-  CHAR16                    *Str;\r
+  EFI_STATUS                    Status;\r
+  IFCONFIG6_PRIVATE_DATA        *Private;\r
+  EFI_HII_PACKAGE_LIST_HEADER   *PackageList;\r
+  LIST_ENTRY                    *ParamPackage;\r
+  CONST CHAR16                  *ValueStr;\r
+  ARG_LIST                      *ArgList;\r
+  CHAR16                        *ProblemParam;\r
+  CHAR16                        *Str;\r
 \r
   Private = NULL;\r
 \r
   //\r
-  // Register our string package with HII and return the handle to it.\r
+  // Retrieve HII package list from ImageHandle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ImageHandle,\r
+                  &gEfiHiiPackageListProtocolGuid,\r
+                  (VOID **) &PackageList,\r
+                  ImageHandle,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
-  mHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, IfConfig6Strings, NULL);\r
+  // Publish HII package list to HII Database.\r
+  //\r
+  Status = gHiiDatabase->NewPackageList (\r
+                          gHiiDatabase,\r
+                          PackageList,\r
+                          NULL,\r
+                          &mHiiHandle\r
+                          );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
   ASSERT (mHiiHandle != NULL);\r
 \r
   Status = ShellCommandLineParseEx (mIfConfig6CheckList, &ParamPackage, &ProblemParam, TRUE, FALSE);\r
@@ -1675,7 +1696,7 @@ IfConfig6Initialize (
   // To handle no option.\r
   //\r
   if (!ShellCommandLineGetFlag (ParamPackage, L"-r") && !ShellCommandLineGetFlag (ParamPackage, L"-s") &&\r
-      !ShellCommandLineGetFlag (ParamPackage, L"-?") && !ShellCommandLineGetFlag (ParamPackage, L"-l")) {\r
+      !ShellCommandLineGetFlag (ParamPackage, L"-l")) {\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_LACK_OPTION), mHiiHandle);\r
     goto ON_EXIT;\r
   }\r
@@ -1684,20 +1705,10 @@ IfConfig6Initialize (
   //\r
   if (((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-s"))) ||\r
       ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||\r
-      ((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))) ||\r
-      ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||\r
-      ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))) ||\r
-      ((ShellCommandLineGetFlag (ParamPackage, L"-l")) && (ShellCommandLineGetFlag (ParamPackage, L"-?")))) {\r
+      ((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l")))) {\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_CONFLICT_OPTIONS), mHiiHandle);\r
     goto ON_EXIT;\r
   }\r
-  //\r
-  // To show the help information of ifconfig6 command.\r
-  //\r
-  if (ShellCommandLineGetFlag (ParamPackage, L"-?")) {\r
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_HELP), mHiiHandle);\r
-    goto ON_EXIT;\r
-  }\r
 \r
   Status = EFI_INVALID_PARAMETER;\r
 \r
@@ -1717,10 +1728,8 @@ IfConfig6Initialize (
     Private->OpCode = IfConfig6OpList;\r
     ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");\r
     if (ValueStr != NULL) {\r
-      Str             = (CHAR16 *) AllocateZeroPool (StrSize (ValueStr));\r
+      Str             = AllocateCopyPool (StrSize (ValueStr), ValueStr);\r
       ASSERT (Str != NULL);\r
-\r
-      Str             = StrnCpy (Str, ValueStr, StrLen (ValueStr));\r
       Private->IfName = Str;\r
     }\r
   }\r
@@ -1731,10 +1740,8 @@ IfConfig6Initialize (
     Private->OpCode = IfConfig6OpClear;\r
     ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");\r
     if (ValueStr != NULL) {\r
-      Str             = (CHAR16 *) AllocateZeroPool (StrSize (ValueStr));\r
+      Str             = AllocateCopyPool (StrSize (ValueStr), ValueStr);\r
       ASSERT (Str != NULL);\r
-\r
-      Str             = StrnCpy (Str, ValueStr, StrLen (ValueStr));\r
       Private->IfName = Str;\r
     }\r
   }\r