/** @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
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
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
/**\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
\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
} \r
\r
String = ConfigHdr;\r
- StrCpy (String, L"GUID=");\r
+ StrnCpy (String, L"GUID=", 6);\r
String += StrLen (L"GUID=");\r
\r
//\r
//\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
//\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
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
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
}\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
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
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
\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
\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
}\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
} 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
\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
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
}\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
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
||(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
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
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
\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
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