]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
MdeModulePkg: Add UNI files for BootManagerPolicyDxe driver.
[mirror_edk2.git] / ShellPkg / Library / UefiShellNetwork1CommandsLib / Ifconfig.c
index 3bfdf847dea2a59cc9b4050e7ec3fc559c6f1ff5..7c3f80985352ee073d4adbc705d5991c73be0600 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   The implementation for ifcommand shell command.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2006 - 2012, 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
@@ -20,7 +21,7 @@
 BOOLEAN                                 mIp4ConfigExist    = FALSE;\r
 STATIC EFI_HII_CONFIG_ROUTING_PROTOCOL  *mHiiConfigRouting = NULL;\r
 \r
-STATIC CONST UINTN SEC_TO_NS            = 10000000;\r
+STATIC CONST UINTN SecondsToNanoSeconds = 10000000;\r
 STATIC CONST CHAR16 DhcpString[5]       = L"DHCP";\r
 STATIC CONST CHAR16 StaticString[7]     = L"STATIC";\r
 STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";\r
@@ -173,7 +174,7 @@ TestChildHandle (
   Get the child handle of the NIC handle.\r
 \r
   @param[in] Controller     Routing information: GUID.\r
-  @param[in] ChildHandle    Returned child handle.\r
+  @param[out] ChildHandle   Returned child handle.\r
 \r
   @retval EFI_SUCCESS         Successfully to get child handle.\r
 **/\r
@@ -249,10 +250,10 @@ GetChildHandle (
 /**\r
   Append OFFSET/WIDTH/VALUE items at the beginning of string.\r
 \r
-  @param[in,out]  String      The pointer to the string to append onto.\r
-  @param[in]      Offset      Offset value.\r
-  @param[in]      Width       Width value.\r
-  @param[in]      Block       Point to data buffer.\r
+  @param[in, out]  String      The pointer to the string to append onto.\r
+  @param[in]       Offset      Offset value.\r
+  @param[in]       Width       Width value.\r
+  @param[in]       Block       Point to data buffer.\r
 \r
   @return The count of unicode character that were appended.\r
 **/\r
@@ -270,16 +271,16 @@ AppendOffsetWidthValue (
 \r
   OriString = String;\r
 \r
-  StrCpy (String, L"&OFFSET=");\r
+  StrnCpy (String, L"&OFFSET=", 9);\r
   String += StrLen (L"&OFFSET=");\r
   String += UnicodeSPrint (String, 20, L"%x", Offset);\r
 \r
-  StrCpy (String,L"&WIDTH=");\r
+  StrnCpy (String,L"&WIDTH=", 8);\r
   String += StrLen (L"&WIDTH=");\r
   String += UnicodeSPrint (String, 20, L"%x", Width);\r
 \r
   if (Block != NULL) {\r
-    StrCpy (String,L"&VALUE=");\r
+    StrnCpy (String,L"&VALUE=", 8);\r
     String += StrLen (L"&VALUE=");\r
     while ((Width--) != 0) {\r
       String += UnicodeSPrint (String, 20, L"%x", Block[Width]);\r
@@ -368,7 +369,7 @@ ConstructConfigHdr (
   } \r
 \r
   String = ConfigHdr;\r
-  StrCpy (String, L"GUID=");\r
+  StrnCpy (String, L"GUID=", 6);\r
   String += StrLen (L"GUID=");\r
 \r
   //\r
@@ -381,7 +382,7 @@ ConstructConfigHdr (
   //\r
   // Append L"&NAME="\r
   //\r
-  StrCpy (String, L"&NAME=");\r
+  StrnCpy (String, L"&NAME=", 7);\r
   String += StrLen (L"&NAME=");\r
   for (Index = 0; Index < NameLength ; Index++) {\r
     String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);\r
@@ -390,7 +391,7 @@ ConstructConfigHdr (
   //\r
   // Append L"&PATH="\r
   //\r
-  StrCpy (String, L"&PATH=");\r
+  StrnCpy (String, L"&PATH=", 7);\r
   String += StrLen (L"&PATH=");\r
   for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {\r
     String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);\r
@@ -617,7 +618,7 @@ IfconfigGetAllNicInfoByHii (
       goto ON_ERROR;\r
     }\r
     if (ConfigHdr != NULL) {\r
-      StrCpy (ConfigResp, ConfigHdr);\r
+      StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r
     }\r
  \r
     //\r
@@ -781,11 +782,16 @@ IfconfigSetNicAddrByHii (
   if (ConfigHdr != NULL) {\r
     Length = StrLen (ConfigHdr);\r
   } else {\r
-    Length = 0;\r
+    ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
   }\r
   ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
+  if (ConfigResp == NULL) {\r
+    ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
   if (ConfigHdr != NULL) {\r
-    StrCpy (ConfigResp, ConfigHdr);\r
+    StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);\r
   }\r
 \r
   NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
@@ -1037,7 +1043,7 @@ TimeoutToGetMap (
 }\r
 \r
 /**\r
-  Create an IP child, use it to start the auto configuration, then destory it.\r
+  Create an IP child, use it to start the auto configuration, then destroy it.\r
 \r
   @param[in] NicInfo    The pointer to the NIC_INFO of the Nic to be configured.\r
 \r
@@ -1110,7 +1116,7 @@ IfconfigStartIp4(
     mTimeout = FALSE;\r
     Status  = gBS->CreateEvent (\r
                     EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
-                    TPL_CALLBACK - 1,\r
+                    TPL_CALLBACK,\r
                     TimeoutToGetMap,\r
                     NULL,\r
                     &TimerToGetMap\r
@@ -1123,7 +1129,7 @@ IfconfigStartIp4(
     Status = gBS->SetTimer (\r
                    TimerToGetMap,\r
                    TimerRelative,\r
-                   MultU64x32 (SEC_TO_NS, 5)\r
+                   MultU64x32 (SecondsToNanoSeconds, 5)\r
                    );\r
     \r
     if (EFI_ERROR (Status)) {\r
@@ -1244,10 +1250,10 @@ IfconfigSetNicAddr (
   \r
   if (StringNoCaseCompare(&Temp, &DhcpTemp) == 0) {\r
     //\r
-    // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP perment\r
+    // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent\r
     //\r
     if ((Argc != 2) && (Argc!= 3)) {\r
-      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, Temp);\r
+      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp);  \r
       ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
       goto ON_EXIT;\r
     }\r
@@ -1260,7 +1266,7 @@ IfconfigSetNicAddr (
 \r
       PermTemp = PermanentString;\r
       if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {\r
-        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, Temp, PermanentString, L"Nothing");\r
+        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing");  \r
         ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
         goto ON_EXIT;\r
       }\r
@@ -1269,7 +1275,7 @@ IfconfigSetNicAddr (
     }\r
 \r
     if ((OldConfig != NULL) && (OldConfig->Source == IP4_CONFIG_SOURCE_DHCP) &&\r
-        (OldConfig->Perment == Permanent)) {\r
+        (OldConfig->Permanent == Permanent)) {\r
 \r
       ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED), gShellNetwork1HiiHandle, Info->Name);\r
       ShellStatus = SHELL_ALREADY_STARTED;\r
@@ -1280,10 +1286,10 @@ IfconfigSetNicAddr (
   } else if (StringNoCaseCompare(&Temp, &StaticTemp) == 0) {\r
     //\r
     // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and\r
-    // eth0 static IP NETMASK GATEWAY perment\r
+    // eth0 static IP NETMASK GATEWAY permanent \r
     //\r
     if ((Argc != 5) && (Argc != 6)) {\r
-      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, Temp);\r
+      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ifconfig", Temp);  \r
       ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
       goto ON_EXIT;\r
     }\r
@@ -1331,7 +1337,7 @@ IfconfigSetNicAddr (
 \r
       PermTemp = PermanentString;\r
       if (StringNoCaseCompare(&Temp, &PermTemp) != 0) {\r
-        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, Temp, PermanentString, L"Nothing");\r
+        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_OP2), gShellNetwork1HiiHandle, L"ifconfig", Temp, PermanentString, L"Nothing");  \r
         ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
         goto ON_EXIT;\r
       }\r
@@ -1377,13 +1383,13 @@ IfconfigSetNicAddr (
     CopyMem (&Config->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));\r
   } else {\r
     // neither static or DHCP.  error.\r
-    ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle);\r
+    ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig");  \r
     ASSERT(ShellStatus == SHELL_INVALID_PARAMETER);\r
     goto ON_EXIT;\r
   }\r
 \r
   CopyMem (&Config->NicAddr, &Info->NicAddress, sizeof (NIC_ADDR));\r
-  Config->Perment = Permanent;\r
+  Config->Permanent = Permanent;\r
 \r
   //\r
   // Use HII service to set NIC address\r
@@ -1469,9 +1475,9 @@ IfconfigShowNicInfo (
     }\r
 \r
     ShellPrintHiiEx(-1, -1, NULL,\r
-      STRING_TOKEN (STR_IFCONFIG_PERMENT_STATUS),\r
+      STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS),\r
       gShellNetwork1HiiHandle,\r
-      (NicInfo->ConfigInfo->Perment? L"TRUE":L"FALSE")\r
+      (NicInfo->ConfigInfo->Permanent? L"TRUE":L"FALSE")\r
       );\r
 \r
     Ip4Config = &NicInfo->ConfigInfo->Ip4Info;\r
@@ -1654,7 +1660,7 @@ ShellCommandRunIfconfig (
   Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
   if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellNetwork1HiiHandle, ProblemParam);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellNetwork1HiiHandle, L"ifconfig", ProblemParam);  \r
       FreePool(ProblemParam);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
@@ -1672,11 +1678,11 @@ ShellCommandRunIfconfig (
     ||(SetOperation   && ListOperation)\r
     ||(ClearOperation && SetOperation)\r
     ) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellNetwork1HiiHandle, L"ifconfig");  \r
     ShellStatus = SHELL_INVALID_PARAMETER;\r
     goto Done;\r
   } else if (!ClearOperation && !ListOperation && !SetOperation) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellNetwork1HiiHandle, L"ifconfig");  \r
     ShellStatus = SHELL_INVALID_PARAMETER;\r
     goto Done;\r
   }\r
@@ -1687,7 +1693,7 @@ ShellCommandRunIfconfig (
     if (mIp4ConfigExist) {\r
       ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_GET_NIC_FAIL), gShellNetwork1HiiHandle, Status);\r
     } else {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellNetwork1HiiHandle, L"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellNetwork1HiiHandle, L"ifconfig", L"gEfiIp4ConfigProtocolGuid", &gEfiIp4ConfigProtocolGuid);  \r
     }\r
 \r
     return SHELL_NOT_FOUND;\r
@@ -1697,7 +1703,7 @@ ShellCommandRunIfconfig (
     Item = ShellCommandLineGetValue (Package, L"-l");\r
 \r
     if (Item != NULL && CountSubItems(Item) > 1) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"-l");\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-l");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       goto Done;\r
     } \r
@@ -1711,11 +1717,11 @@ ShellCommandRunIfconfig (
 \r
     //\r
     // The correct command line arguments for setting address are:\r
-    // IfConfig -s eth0 DHCP [perment]\r
-    // IfConfig -s eth0 static ip netmask gateway [perment]\r
+    // IfConfig -s eth0 DHCP [permanent]\r
+    // IfConfig -s eth0 static ip netmask gateway [permanent]\r
     //\r
     if (Item == NULL || (CountSubItems(Item) < 2) || (CountSubItems(Item) > 6) || (CountSubItems(Item) == 4)) {\r
-      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"-s");\r
+      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_GEN_NO_VALUE), gShellNetwork1HiiHandle, L"ifconfig", L"-s");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       goto Done;\r
     }\r
@@ -1725,7 +1731,7 @@ ShellCommandRunIfconfig (
     Item = ShellCommandLineGetValue (Package, L"-c");\r
 \r
     if (Item != NULL && CountSubItems(Item) > 1) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"-c");\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellNetwork1HiiHandle, L"ifconfig", Item, L"-c");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       goto Done;\r
     }\r