/** @file
The implementation for Ping6 application.
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/ServiceBinding.h>
#include <Protocol/Ip6Config.h>
#include "Ping6.h"
{
L"-l",
},
{
L"-n",
},
{
L"-s",
},
{
L"-?",
},
{
NULL,
},
};
//
// Global Variables in Ping6 application.
//
/**
The result is saved in the globle variable mFrequency
@retval EFI_SUCCESS Caculated the frequency successfully.
@retval Others Failed to caculate the frequency.
**/
)
{
return Status;
}
//
// For NT32 Simulator only. 358049 is a similar value to keep timer granularity.
// Set the timer period by ourselves.
//
}
//
// The timer period is in femtosecond (1 femtosecond is 1e-15 second).
//
return EFI_SUCCESS;
}
/**
Get and caculate the duration in ms.
@param[in] Begin The start point of time.
@param[in] End The end point of time.
@return The duration in ms.
**/
)
{
}
/**
Destroy IPING6_ICMP6_TX_INFO, and recollect the memory.
@param[in] TxInfo The pointer to PING6_ICMP6_TX_INFO.
**/
)
{
}
}
}
}
}
}
}
}
/**
Match the request, and reply with SequenceNum/TimeStamp.
@param[in] Private The pointer to PING6_PRIVATE_DATA.
@param[in] Packet The pointer to ICMP6_ECHO_REQUEST_REPLY.
@retval EFI_SUCCESS The match is successful.
@retval EFI_NOT_FOUND The reply can't be matched with any request.
**/
)
{
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
The original intention is to send a request.
Currently, the application retransmits an icmp6 echo request packet
per second in sendnumber times that is specified by the user.
Because nothing can be done here, all things move to the timer rountine.
@param[in] Event A EFI_EVENT type event.
@param[in] Context The pointer to Context.
**/
)
{
}
/**
receive reply, match and print reply infomation.
@param[in] Event A EFI_EVENT type event.
@param[in] Context The pointer to context.
**/
)
{
return;
}
goto ON_EXIT;
}
goto ON_EXIT;
}
goto ON_EXIT;
}
goto ON_EXIT;
}
//
// Check whether the reply matches the sent request before.
//
goto ON_EXIT;
}
//
// Display statistics on this icmp6 echo reply packet.
//
if (Rtt != 0) {
} else {
}
-1,
-1,
NULL,
Near,
);
//
// Continue to receive icmp6 echo reply packets.
//
}
} else {
//
// All reply have already been received from the dest host.
//
}
//
// Singal to recycle the each rxdata here, not at the end of process.
//
}
/**
Initial EFI_IP6_COMPLETION_TOKEN.
@param[in] Private The pointer of PING6_PRIVATE_DATA.
@param[in] TimeStamp The TimeStamp of request.
@param[in] SequenceNum The SequenceNum of request.
@return The pointer of EFI_IP6_COMPLETION_TOKEN.
**/
)
{
return NULL;
}
//
// Assembly icmp6 echo request packet.
//
Request->Identifier = 0;
//
// Leave check sum to ip6 layer, since it has no idea of source address
// selection.
//
return NULL;
}
//
// Assembly ipv6 token for transmit.
//
TxData->OverrideData = 0;
TxData->ExtHdrsLength = 0;
return NULL;
}
);
return NULL;
}
return Token;
}
/**
Transmit the EFI_IP6_COMPLETION_TOKEN.
@param[in] Private The pointer of PING6_PRIVATE_DATA.
@retval EFI_SUCCESS Transmitted successfully.
@retval EFI_OUT_OF_RESOURCES No memory is available on the platform.
@retval others Transmitted unsuccessfully.
**/
)
{
return EFI_OUT_OF_RESOURCES;
}
);
return EFI_OUT_OF_RESOURCES;
}
return Status;
}
return EFI_SUCCESS;
}
/**
Place a completion token into the receive packet queue to receive the echo reply.
@param[in] Private The pointer of PING6_PRIVATE_DATA.
@retval EFI_SUCCESS Put the token into the receive packet queue successfully.
@retval others Put the token into the receive packet queue unsuccessfully.
**/
)
{
);
return Status;
}
}
/**
Remove the timeout request from the list.
@param[in] Event A EFI_EVENT type event.
@param[in] Context The pointer to Context.
**/
)
{
//
// Retransmit icmp6 echo request packets per second in sendnumber times.
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_SEND_REQUEST), mHiiHandle, Private->TxCount + 1);
}
}
}
//
// Check whether any icmp6 echo request in the list timeout.
//
//
// Remove the timeout echo request from txlist.
//
if (Time > PING6_DEFAULT_TIMEOUT) {
}
//
// Remove the timeout icmp6 echo request from list.
//
//
// All the left icmp6 echo request in the list timeout.
//
}
}
}
}
/**
Create a valid IP6 instance.
@param[in] Private The pointer of PING6_PRIVATE_DATA.
@retval EFI_SUCCESS Create a valid IP6 instance successfully.
@retval EFI_ABORTED Locate handle with ip6 service binding protocol unsuccessfully.
@retval EFI_INVALID_PARAMETER The source address is unspecified when the destination address is a link -ocal address.
@retval EFI_OUT_OF_RESOURCES No memory is available on the platform.
@retval EFI_NOT_FOUND The source address is not found.
**/
)
{
HandleBuffer = NULL;
IfInfoSize = 0;
//
// Locate all the handles with ip6 service binding protocol.
//
NULL,
);
return EFI_ABORTED;
}
//
// Source address is required when pinging a link-local address on multi-
// interfaces host.
//
(HandleNum > 1)) {
goto ON_ERROR;
}
//
// For each ip6 protocol, check interface addresses list.
//
IfInfoSize = 0;
);
goto ON_ERROR;
}
//
// No need to match interface address.
//
break;
} else {
//
// Ip6config protocol and ip6 service binding protocol are installed
// on the same handle.
//
);
goto ON_ERROR;
}
//
// Get the interface information size.
//
);
if (Status != EFI_BUFFER_TOO_SMALL) {
goto ON_ERROR;
}
goto ON_ERROR;
}
//
// Get the interface info.
//
);
goto ON_ERROR;
}
//
// Check whether the source address is one of the interface addresses.
//
//
// Match a certain interface address.
//
break;
}
}
//
// Found a nic handle with right interface address.
//
break;
}
}
}
//
// No exact interface address matched.
//
if (HandleIndex == HandleNum) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_SOURCE_NOT_FOUND), mHiiHandle, mIp6SrcString);
goto ON_ERROR;
}
goto ON_ERROR;
}
);
goto ON_ERROR;
}
//
// Configure the ip6 instance for icmp6 packet exchange.
//
Ip6Config.TrafficClass = 0;
Ip6Config.ReceiveTimeout = 0;
Ip6Config.TransmitTimeout = 0;
goto ON_ERROR;
}
return EFI_SUCCESS;
if (HandleBuffer != NULL) {
}
}
}
return Status;
}
/**
Destory the IP6 instance.
@param[in] Private The pointer of PING6_PRIVATE_DATA.
**/
)
{
gBS->CloseProtocol (
);
);
}
}
/**
The Ping6 Process.
@param[in] ImageHandle The firmware allocated handle for the UEFI image.
@param[in] SendNumber The send request count.
@param[in] BufferSize The send buffer size.
@param[in] SrcAddress The source IPv6 address.
@param[in] DstAddress The destination IPv6 address.
@retval EFI_SUCCESS The ping6 processed successfullly.
@retval others The ping6 processed unsuccessfully.
**/
Ping6 (
)
{
//
// Open and configure a ip6 instance for ping6.
//
goto ON_EXIT;
}
//
// Print the command line itself.
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_START), mHiiHandle, mIp6DstString, Private->BufferSize);
//
// Create a ipv6 token to receive the first icmp6 echo reply packet.
//
goto ON_EXIT;
}
//
// Create and start timer to send icmp6 echo request packet per second.
//
);
goto ON_EXIT;
}
//
// Create a ipv6 token to send the first icmp6 echo request packet.
//
//
// EFI_NOT_READY for IPsec is enable and IKE is not established.
//
if(Status == EFI_NOT_FOUND) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_NOSOURCE_INDOMAIN), mHiiHandle, mIp6DstString);
}
goto ON_EXIT;
}
);
goto ON_EXIT;
}
//
// Control the ping6 process by two factors:
// 1. Hot key
// 2. Private->Status
// 2.1. success means all icmp6 echo request packets get reply packets.
// 2.2. timeout means the last icmp6 echo reply request timeout to get reply.
// 2.3. noready means ping6 process is on-the-go.
//
//
// Terminate the ping6 process by 'esc' or 'ctl-c'.
//
goto ON_STAT;
}
}
}
//
// Display the statistics in all.
//
-1,
-1,
NULL,
);
}
-1,
-1,
NULL,
);
}
}
}
}
}
}
}
return Status;
}
/**
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 Ping6 application that parses the command line input and calls the Ping6 process.
@param[in] ImageHandle The firmware allocated handle for the UEFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETETR Input parameters combination is invalid.
@retval Others Some errors occur.
**/
)
{
//
// Register our string package with HII and return the handle to it.
//
goto ON_EXIT;
}
goto ON_EXIT;
}
SendNumber = 10;
BufferSize = 16;
//
// Parse the paramter of count number.
//
//
// ShellStrToUintn will return 0 when input is 0 or an invalid input string.
//
goto ON_EXIT;
}
}
//
// Parse the paramter of buffer size.
//
//
// ShellStrToUintn will return 0 when input is 0 or an invalid input string.
//
goto ON_EXIT;
}
}
//
// Parse the paramter of source ip address.
//
goto ON_EXIT;
}
}
//
// Parse the paramter of destination ip address.
//
if (NonOptionCount != 2) {
goto ON_EXIT;
}
goto ON_EXIT;
}
}
//
// Get frequency to calculate the time from ticks.
//
Status = Ping6GetFrequency ();
goto ON_EXIT;
}
//
// Enter into ping6 process.
//
);
return Status;
}