/** @file
The implementation for Shell application IfConfig6.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/ShellLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/Ip6Config.h>
#include "IfConfig6.h"
{
L"-b",
},
{
L"-s",
},
{
L"-l",
},
{
L"-r",
},
{
L"-?",
},
{
NULL,
},
};
{
L"auto",
0x00000001,
0x00000001,
},
{
L"man",
0x00000002,
0x00000001,
},
{
L"host",
0x00000004,
0x00000002,
},
{
L"dad",
0x00000008,
0x00000004,
},
{
L"gw",
0x00000010,
0x00000008,
},
{
L"dns",
0x00000020,
0x00000010,
},
{
L"id",
0x00000040,
0x00000020,
},
{
NULL,
0x0,
0x0,
},
};
/**
Split a string with specified separator and save the substring to a list.
@param[in] String The pointer of the input string.
@param[in] Separator The specified separator.
@return The pointer of headnode of ARG_LIST.
**/
ARG_LIST *
)
{
if (*String == L'\0') {
return NULL;
}
//
// Copy the CONST string to a local copy.
//
//
// init a node for the list head.
//
//
// Split the local copy and save in the list node.
//
while (*Str != L'\0') {
*Str = L'\0';
}
Str++;
}
return ArgList;
}
/**
Check the correctness of input Args with '-s' option.
@param[in] CheckList The pointer of VAR_CHECK_ITEM array.
@param[in] Name The pointer of input arg.
@param[in] Init The switch to execute the check.
@return The value of VAR_CHECK_CODE.
**/
)
{
if (Init) {
CheckDuplicate = 0;
CheckConflict = 0;
return VarCheckOk;
}
RtCode = VarCheckOk;
Index = 0;
//
// Check the Duplicated/Conflicted/Unknown input Args.
//
break;
}
break;
}
break;
}
}
}
return RtCode;
}
/**
The notify function of create event when performing a manual config.
@param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registered to the event.
**/
)
{
}
/**
Print MAC address.
@param[in] Node The pointer of MAC address buffer.
@param[in] Size The size of MAC address buffer.
**/
)
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_BODY), mHiiHandle, Node[Index]);
}
}
}
/**
Print IPv6 address.
@param[in] Ip The pointer of Ip bufffer in EFI_IPv6_ADDRESS format.
@param[in] PrefixLen The pointer of PrefixLen that describes the size Prefix.
**/
)
{
if (!Short && (Index + 1 < PREFIXMAXLEN) && (Index % 2 == 0) && (Ip->Addr[Index] == 0) && (Ip->Addr[Index + 1] == 0)) {
//
// Deal with the case of ::.
//
if (Index == 0) {
//
// :: is at the beginning of the address.
//
}
break;
}
}
if (Index == PREFIXMAXLEN) {
//
// :: is at the end of the address.
//
break;
}
}
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY), mHiiHandle, Ip->Addr[Index]);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY), mHiiHandle, Ip->Addr[Index + 1]);
}
}
}
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_PREFIX_LEN), mHiiHandle, *PrefixLen);
}
}
/**
Pick up host IPv6 address in string format from Args with "-s" option and convert it to EFI_IP6_CONFIG_MANUAL_ADDRESS format.
@param[in, out] Arg The pointer of the address of ARG_LIST which save Args with the "-s" option.
@param[out] Buf The pointer of the address of EFI_IP6_CONFIG_MANUAL_ADDRESS.
@param[out] BufSize The pointer of BufSize that describes the size of Buf in bytes.
@retval EFI_SUCCESS The convertion is successful.
@retval Others Does't find the host address, or it is an invalid IPv6 address in string format.
**/
)
{
AddrCnt = 0;
*BufSize = 0;
//
// Go through the list to check the correctness of input host ip6 address.
//
//
// host ip ip ... gw
//
break;
}
AddrCnt++;
}
if (AddrCnt == 0) {
return EFI_INVALID_PARAMETER;
}
AddrCnt = 0;
//
// Go through the list to fill in the EFI_IP6_CONFIG_MANUAL_ADDRESS structure.
//
break;
}
//
// If prefix length is not set, set it as Zero here. In the IfConfigSetInterfaceInfo()
// Zero prefix, length will be transfered to default prefix length.
//
if (Prefix == 0xFF) {
Prefix = 0;
}
AddrCnt++;
}
goto ON_ERROR;
}
return EFI_SUCCESS;
return Status;
}
/**
Pick up gw/dns IPv6 address in string format from Args with "-s" option and convert it to EFI_IPv6_ADDRESS format.
@param[in, out] Arg The pointer of the address of ARG_LIST that save Args with the "-s" option.
@param[out] Buf The pointer of the address of EFI_IPv6_ADDRESS.
@param[out] BufSize The pointer of BufSize that describes the size of Buf in bytes.
@retval EFI_SUCCESS The conversion is successful.
@retval Others Doesn't find the host address, or it is an invalid IPv6 address in string format.
**/
)
{
AddrCnt = 0;
*BufSize = 0;
//
//
//
// gw ip ip ... host
//
break;
}
AddrCnt++;
}
if (AddrCnt == 0) {
return EFI_INVALID_PARAMETER;
}
AddrCnt = 0;
//
// Go through the list to fill in the EFI_IPv6_ADDRESS structure.
//
break;
}
AddrCnt++;
}
goto ON_ERROR;
}
return EFI_SUCCESS;
return Status;
}
/**
Parse InterfaceId in string format from Args with the "-s" option and convert it to EFI_IP6_CONFIG_INTERFACE_ID format.
@param[in, out] Arg The pointer of the address of ARG_LIST that saves Args with the "-s" option.
@param[out] IfId The pointer of EFI_IP6_CONFIG_INTERFACE_ID.
@retval EFI_SUCCESS The get status processed successfullly.
@retval EFI_INVALID_PARAMETER The get status process failed.
**/
)
{
return EFI_INVALID_PARAMETER;
}
Index = 0;
NodeVal = 0;
} else {
return EFI_INVALID_PARAMETER;
}
IdStr++;
}
if (*IdStr == L':') {
IdStr++;
}
}
return EFI_SUCCESS;
}
/**
Parse dad in string format from Args with the "-s" option and convert it to UINT32 format.
@param[in, out] Arg The pointer of the address of ARG_LIST that saves Args with the "-s" option.
@param[out] Xmits The pointer of Xmits.
@retval EFI_SUCCESS The get status processed successfully.
@retval others The get status process failed.
**/
)
{
return EFI_INVALID_PARAMETER;
}
*Xmits = 0;
while (*ValStr != L'\0') {
} else {
return EFI_INVALID_PARAMETER;
}
ValStr++;
}
return EFI_SUCCESS;
}
/**
The get current status of all handles.
@param[in] ImageHandle The handle of ImageHandle.
@param[in] IfName The pointer of IfName(interface name).
@param[in] IfList The pointer of IfList(interface list).
@retval EFI_SUCCESS The get status processed successfully.
@retval others The get status process failed.
**/
)
{
HandleBuffer = NULL;
HandleNum = 0;
//
// Locate all the handles with ip6 service binding protocol.
//
NULL,
);
return EFI_ABORTED;
}
//
// Enumerate all handles that installed with ip6 service binding protocol.
//
DataSize = 0;
//
// Ip6config protocol and ip6 service binding protocol are installed
// on the same handle.
//
);
goto ON_ERROR;
}
//
// Get the interface information size.
//
&DataSize,
);
if (Status != EFI_BUFFER_TOO_SMALL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
goto ON_ERROR;
}
//
// Get the interface info.
//
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
//
// Check the interface name if required.
//
continue;
}
DataSize = 0;
//
// Get the size of dns server list.
//
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
goto ON_ERROR;
}
//
// Get the dns server list if has.
//
if (DataSize > 0) {
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
}
//
// Get the interface id if has.
//
DataSize = sizeof (EFI_IP6_CONFIG_INTERFACE_ID);
goto ON_ERROR;
}
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
if (Status == EFI_NOT_FOUND) {
}
//
// Get the config policy.
//
DataSize = sizeof (EFI_IP6_CONFIG_POLICY);
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
//
// Get the dad transmits.
//
DataSize = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS);
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_ERROR;
}
//
// Only need the appointed interface, keep the allocated buffer.
//
break;
}
}
if (HandleBuffer != NULL) {
}
return EFI_SUCCESS;
}
}
}
return Status;
}
/**
The list process of the IfConfig6 application.
@param[in] IfList The pointer of IfList(interface list).
@retval EFI_SUCCESS The IfConfig6 list processed successfully.
@retval others The IfConfig6 list process failed.
**/
)
{
if (IsListEmpty (IfList)) {
}
//
// Go through the interface list.
//
//
// Print interface name.
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_IF_NAME), mHiiHandle, IfCb->IfInfo->Name);
//
// Print interface config policy.
//
} else {
}
//
// Print dad transmit.
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_INFO_DAD_TRANSMITS), mHiiHandle, IfCb->Xmits);
//
// Print interface id if has.
//
8
);
}
//
// Print mac address of the interface.
//
);
//
// Print ip addresses list of the interface.
//
);
}
//
// Print dns server addresses list of the interface if has.
//
);
}
//
// Print route table of the interface if has.
//
);
);
}
}
return Status;
}
/**
The clean process of the IfConfig6 application.
@param[in] IfList The pointer of IfList(interface list).
@retval EFI_SUCCESS The IfConfig6 clean processed successfully.
@retval others The IfConfig6 clean process failed.
**/
)
{
if (IsListEmpty (IfList)) {
}
//
// Go through the interface list.
//
sizeof (EFI_IP6_CONFIG_POLICY),
);
break;
}
}
return Status;
}
/**
The set process of the IfConfig6 application.
@param[in] IfList The pointer of IfList(interface list).
@param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
@retval EFI_SUCCESS The IfConfig6 set processed successfully.
@retval others The IfConfig6 set process failed.
**/
)
{
CfgManAddr = NULL;
TimeOutEvt = NULL;
InterfaceId = NULL;
CurDadXmits = 0;
if (IsListEmpty (IfList)) {
return EFI_INVALID_PARAMETER;
}
//
// Make sure to set only one interface each time.
//
//
// Initialize check list mechanism.
//
NULL,
NULL,
);
//
// Create events & timers for asynchronous settings.
//
NULL,
NULL,
);
goto ON_EXIT;
}
);
goto ON_EXIT;
}
//
// Parse the setting variables.
//
//
// Check invalid parameters (duplication & unknown & conflict).
//
);
if (VarCheckOk != CheckCode) {
switch (CheckCode) {
case VarCheckDuplicate:
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_DUPLICATE_COMMAND), mHiiHandle, VarArg->Arg);
break;
case VarCheckConflict:
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_CONFLICT_COMMAND), mHiiHandle, VarArg->Arg);
break;
case VarCheckUnknown:
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_UNKNOWN_COMMAND), mHiiHandle, VarArg->Arg);
break;
default:
break;
}
continue;
}
//
// Process valid variables.
//
//
// Set automaic config policy
//
sizeof (EFI_IP6_CONFIG_POLICY),
);
goto ON_EXIT;
}
//
// Set manual config policy.
//
sizeof (EFI_IP6_CONFIG_POLICY),
);
goto ON_EXIT;
}
//
// Parse till the next tag or the end of command line.
//
&VarArg,
);
if (Status == EFI_INVALID_PARAMETER) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS), mHiiHandle, L"host");
continue;
} else {
goto ON_EXIT;
}
}
//
// Set static host ip6 address list.
// This is a asynchronous process.
//
IsAddressOk = FALSE;
);
goto ON_EXIT;
}
);
if (Status == EFI_NOT_READY) {
//
// Get current dad transmits count.
//
);
if (IsAddressOk) {
break;
}
}
}
);
goto ON_EXIT;
}
//
// Check whether the address is set successfully.
//
DataSize = 0;
&DataSize,
);
if (Status != EFI_BUFFER_TOO_SMALL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_EXIT;
}
goto ON_EXIT;
}
&DataSize,
);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA), mHiiHandle, Status);
goto ON_EXIT;
}
//
// By default, the prefix length 0 is regarded as 64.
//
}
IsAddressSet = TRUE;
break;
}
}
if (!IsAddressSet) {
);
}
}
//
// Parse till the next tag or the end of command line.
//
&VarArg,
&CfgAddr,
);
if (Status == EFI_INVALID_PARAMETER) {
continue;
} else {
goto ON_EXIT;
}
}
//
// Set static gateway ip6 address list.
//
);
goto ON_EXIT;
}
//
// Parse till the next tag or the end of command line.
//
&VarArg,
&CfgAddr,
);
if (Status == EFI_INVALID_PARAMETER) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS), mHiiHandle, L"dns");
continue;
} else {
goto ON_EXIT;
}
}
//
// Set static dhs server ip6 address list.
//
);
goto ON_EXIT;
}
//
// Parse till the next tag or the end of command line.
//
goto ON_EXIT;
}
//
// Set alternative interface id.
//
sizeof (EFI_IP6_CONFIG_INTERFACE_ID),
);
goto ON_EXIT;
}
//
// Parse till the next tag or the end of command line.
//
goto ON_EXIT;
}
//
// Set dad transmits count.
//
sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS),
);
goto ON_EXIT;
}
}
}
if (CfgManAddr != NULL) {
}
}
}
if (TimeOutEvt != NULL) {
}
}
return Status;
}
/**
The IfConfig6 main process.
@param[in] Private The pointer of IFCONFIG6_PRIVATE_DATA.
@retval EFI_SUCCESS IfConfig6 processed successfully.
@retval others The IfConfig6 process failed.
**/
)
{
//
// Get configure information of all interfaces.
//
);
goto ON_EXIT;
}
case IfConfig6OpList:
break;
case IfConfig6OpClear:
break;
case IfConfig6OpSet:
break;
default:
}
return Status;
}
/**
The IfConfig6 cleanup process, free the allocated memory.
@param[in] Private The pointer of IFCONFIG6_PRIVATE_DATA.
**/
)
{
//
// Clean the list which save the set config Args.
//
}
}
//
// Clean the IFCONFIG6_INTERFACE_CB list.
//
}
}
}
}
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including
both device drivers and bus drivers.
The entry point for the IfConfig6 application which parses the command line input and calls the IfConfig6 process.
@param[in] ImageHandle The image handle of this application.
@param[in] SystemTable The pointer to the EFI System Table.
@retval EFI_SUCCESS The operation completed successfully.
@retval Others Some errors occur.
**/
)
{
//
// Register our string package with HII and return the handle to it.
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_COMMAND), mHiiHandle, ProblemParam);
goto ON_EXIT;
}
//
// To handle no option.
//
if (!ShellCommandLineGetFlag (ParamPackage, L"-r") && !ShellCommandLineGetFlag (ParamPackage, L"-s") &&
goto ON_EXIT;
}
//
// To handle conflict options.
//
if (((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-s"))) ||
((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||
((ShellCommandLineGetFlag (ParamPackage, L"-r")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))) ||
((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-l"))) ||
((ShellCommandLineGetFlag (ParamPackage, L"-s")) && (ShellCommandLineGetFlag (ParamPackage, L"-?"))) ||
((ShellCommandLineGetFlag (ParamPackage, L"-l")) && (ShellCommandLineGetFlag (ParamPackage, L"-?")))) {
goto ON_EXIT;
}
//
// To show the help information of ifconfig6 command.
//
goto ON_EXIT;
}
goto ON_EXIT;
}
//
// To get interface name for the list option.
//
}
}
//
// To get interface name for the clear option.
//
}
}
//
// To get interface name and corresponding Args for the set option.
//
goto ON_EXIT;
}
//
// To split the configuration into multi-section.
//
goto ON_EXIT;
}
}
//
// Main process of ifconfig6.
//
return Status;
}