TianoCore EDK2 master
Loading...
Searching...
No Matches
Ping.c File Reference

Go to the source code of this file.

Data Structures

struct  PING_IPX_PROTOCOL
 
union  PING_PACKET
 
struct  PING_IPX_COMPLETION_TOKEN
 
struct  _ICMPX_ECHO_REQUEST_REPLY
 
struct  _PING_ICMP_TX_INFO
 
struct  _PING_PRIVATE_DATA
 

Macros

#define PING_IP4_COPY_ADDRESS(Dest, Src)   (CopyMem ((Dest), (Src), sizeof (EFI_IPv4_ADDRESS)))
 
#define DEFAULT_TIMEOUT   5000
 
#define MAX_SEND_NUMBER   10000
 
#define MAX_BUFFER_SIZE   32768
 
#define DEFAULT_TIMER_PERIOD   358049
 
#define ONE_SECOND   10000000
 
#define PING_IP_CHOICE_IP4   1
 
#define PING_IP_CHOICE_IP6   2
 
#define DEFAULT_SEND_COUNT   10
 
#define DEFAULT_BUFFER_SIZE   16
 
#define ICMP_V4_ECHO_REQUEST   0x8
 
#define ICMP_V4_ECHO_REPLY   0x0
 
#define STALL_1_MILLI_SECOND   1000
 
#define PING_PRIVATE_DATA_SIGNATURE   SIGNATURE_32 ('P', 'i', 'n', 'g')
 

Typedefs

typedef EFI_STATUS(EFIAPI * PING_IPX_POLL) (IN VOID *This)
 
typedef EFI_STATUS(EFIAPI * PING_IPX_TRANSMIT) (IN VOID *This, IN VOID *Token)
 
typedef EFI_STATUS(EFIAPI * PING_IPX_RECEIVE) (IN VOID *This, IN VOID *Token)
 
typedef EFI_STATUS(EFIAPI * PING_IPX_CANCEL) (IN VOID *This, IN VOID *Token OPTIONAL)
 
typedef struct _ICMPX_ECHO_REQUEST_REPLY ICMPX_ECHO_REQUEST_REPLY
 
typedef struct _PING_ICMP_TX_INFO PING_ICMPX_TX_INFO
 
typedef struct _PING_PRIVATE_DATA PING_PRIVATE_DATA
 

Functions

UINT16 NetChecksum (IN UINT8 *Buffer, IN UINT32 Length)
 
VOID EFIAPI RttTimerTickRoutine (IN EFI_EVENT Event, IN VOID *Context)
 
UINT32 GetTimerPeriod (VOID)
 
EFI_STATUS PingInitRttTimer (PING_PRIVATE_DATA *Private)
 
VOID PingFreeRttTimer (PING_PRIVATE_DATA *Private)
 
UINT32 ReadTime (PING_PRIVATE_DATA *Private)
 
UINT32 CalculateTick (PING_PRIVATE_DATA *Private, IN UINT32 Begin, IN UINT32 End)
 
VOID PingDestroyTxInfo (IN PING_ICMPX_TX_INFO *TxInfo, IN UINT32 IpChoice)
 
EFI_STATUS Ping6MatchEchoReply (IN PING_PRIVATE_DATA *Private, IN ICMPX_ECHO_REQUEST_REPLY *Packet)
 
VOID EFIAPI Ping6OnEchoRequestSent (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI Ping6OnEchoReplyReceived (IN EFI_EVENT Event, IN VOID *Context)
 
PING_IPX_COMPLETION_TOKENPingGenerateToken (IN PING_PRIVATE_DATA *Private, IN UINT32 TimeStamp, IN UINT16 SequenceNum)
 
EFI_STATUS PingSendEchoRequest (IN PING_PRIVATE_DATA *Private)
 
EFI_STATUS Ping6ReceiveEchoReply (IN PING_PRIVATE_DATA *Private)
 
VOID EFIAPI Ping6OnTimerRoutine (IN EFI_EVENT Event, IN VOID *Context)
 
BOOLEAN PingNetIp4IsLinkLocalAddr (IN CONST EFI_IPv4_ADDRESS *Address)
 
BOOLEAN PingNetIp4IsUnspecifiedAddr (IN CONST EFI_IPv4_ADDRESS *Address)
 
EFI_STATUS PingCreateIpInstance (IN PING_PRIVATE_DATA *Private)
 
VOID Ping6DestroyIp6Instance (IN PING_PRIVATE_DATA *Private)
 
SHELL_STATUS ShellPing (IN UINT32 SendNumber, IN UINT32 BufferSize, IN EFI_IPv6_ADDRESS *SrcAddress, IN EFI_IPv6_ADDRESS *DstAddress, IN UINT32 IpChoice)
 
SHELL_STATUS EFIAPI ShellCommandRunPing (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

UINT64 mCurrentTick = 0
 
STATIC CONST SHELL_PARAM_ITEM PingParamList []
 
STATIC CONST CHAR16 * mDstString
 
STATIC CONST CHAR16 * mSrcString
 

Detailed Description

The implementation for Ping shell command.

(C) Copyright 2015 Hewlett-Packard Development Company, L.P.
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Ping.c.

Macro Definition Documentation

◆ DEFAULT_BUFFER_SIZE

#define DEFAULT_BUFFER_SIZE   16

Definition at line 102 of file Ping.c.

◆ DEFAULT_SEND_COUNT

#define DEFAULT_SEND_COUNT   10

Definition at line 101 of file Ping.c.

◆ DEFAULT_TIMEOUT

#define DEFAULT_TIMEOUT   5000

Definition at line 94 of file Ping.c.

◆ DEFAULT_TIMER_PERIOD

#define DEFAULT_TIMER_PERIOD   358049

Definition at line 97 of file Ping.c.

◆ ICMP_V4_ECHO_REPLY

#define ICMP_V4_ECHO_REPLY   0x0

Definition at line 104 of file Ping.c.

◆ ICMP_V4_ECHO_REQUEST

#define ICMP_V4_ECHO_REQUEST   0x8

Definition at line 103 of file Ping.c.

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   32768

Definition at line 96 of file Ping.c.

◆ MAX_SEND_NUMBER

#define MAX_SEND_NUMBER   10000

Definition at line 95 of file Ping.c.

◆ ONE_SECOND

#define ONE_SECOND   10000000

Definition at line 98 of file Ping.c.

◆ PING_IP4_COPY_ADDRESS

#define PING_IP4_COPY_ADDRESS (   Dest,
  Src 
)    (CopyMem ((Dest), (Src), sizeof (EFI_IPv4_ADDRESS)))

Definition at line 14 of file Ping.c.

◆ PING_IP_CHOICE_IP4

#define PING_IP_CHOICE_IP4   1

Definition at line 99 of file Ping.c.

◆ PING_IP_CHOICE_IP6

#define PING_IP_CHOICE_IP6   2

Definition at line 100 of file Ping.c.

◆ PING_PRIVATE_DATA_SIGNATURE

#define PING_PRIVATE_DATA_SIGNATURE   SIGNATURE_32 ('P', 'i', 'n', 'g')

Definition at line 107 of file Ping.c.

◆ STALL_1_MILLI_SECOND

#define STALL_1_MILLI_SECOND   1000

Definition at line 105 of file Ping.c.

Typedef Documentation

◆ PING_IPX_CANCEL

typedef EFI_STATUS(EFIAPI * PING_IPX_CANCEL) (IN VOID *This, IN VOID *Token OPTIONAL)

Definition at line 42 of file Ping.c.

◆ PING_IPX_POLL

typedef EFI_STATUS(EFIAPI * PING_IPX_POLL) (IN VOID *This)

Definition at line 22 of file Ping.c.

◆ PING_IPX_RECEIVE

typedef EFI_STATUS(EFIAPI * PING_IPX_RECEIVE) (IN VOID *This, IN VOID *Token)

Definition at line 35 of file Ping.c.

◆ PING_IPX_TRANSMIT

typedef EFI_STATUS(EFIAPI * PING_IPX_TRANSMIT) (IN VOID *This, IN VOID *Token)

Definition at line 28 of file Ping.c.

Function Documentation

◆ CalculateTick()

UINT32 CalculateTick ( PING_PRIVATE_DATA Private,
IN UINT32  Begin,
IN UINT32  End 
)

Calculate a duration in ms.

Parameters
[in]PrivateThe pointer to PING_PRIVATE_DATA.
[in]BeginThe start point of time.
[in]EndThe end point of time.
Returns
The duration in ms.
Return values
0The parameters were not valid.

Definition at line 397 of file Ping.c.

◆ GetTimerPeriod()

UINT32 GetTimerPeriod ( VOID  )

Get the timer period of the system.

This function tries to get the system timer period by creating an 1ms period timer.

Returns
System timer period in MS, or 0 if operation failed.

Definition at line 253 of file Ping.c.

◆ NetChecksum()

UINT16 NetChecksum ( IN UINT8 *  Buffer,
IN UINT32  Length 
)

Calculate the internet checksum (see RFC 1071).

Parameters
[in]PacketBuffer which contains the data to be checksummed.
[in]LengthLength to be checksummed.
Return values
ChecksumReturns the 16 bit ones complement of ones complement sum of 16 bit words

Definition at line 149 of file Ping.c.

◆ Ping6DestroyIp6Instance()

VOID Ping6DestroyIp6Instance ( IN PING_PRIVATE_DATA Private)

Destroy the IP instance.

Parameters
[in]PrivateThe pointer of PING_PRIVATE_DATA.

Definition at line 1327 of file Ping.c.

◆ Ping6MatchEchoReply()

EFI_STATUS Ping6MatchEchoReply ( IN PING_PRIVATE_DATA Private,
IN ICMPX_ECHO_REQUEST_REPLY Packet 
)

Match the request, and reply with SequenceNum/TimeStamp.

Parameters
[in]PrivateThe pointer to PING_PRIVATE_DATA.
[in]PacketThe pointer to ICMPX_ECHO_REQUEST_REPLY.
Return values
EFI_SUCCESSThe match is successful.
EFI_NOT_FOUNDThe reply can't be matched with any request.

Definition at line 487 of file Ping.c.

◆ Ping6OnEchoReplyReceived()

VOID EFIAPI Ping6OnEchoReplyReceived ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

receive reply, match and print reply infomation.

Parameters
[in]EventA EFI_EVENT type event.
[in]ContextThe pointer to context.

Definition at line 538 of file Ping.c.

◆ Ping6OnEchoRequestSent()

VOID EFIAPI Ping6OnEchoRequestSent ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

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 routine.

Parameters
[in]EventA EFI_EVENT type event.
[in]ContextThe pointer to Context.

Definition at line 522 of file Ping.c.

◆ Ping6OnTimerRoutine()

VOID EFIAPI Ping6OnTimerRoutine ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Remove the timeout request from the list.

Parameters
[in]EventA EFI_EVENT type event.
[in]ContextThe pointer to Context.

Definition at line 857 of file Ping.c.

◆ Ping6ReceiveEchoReply()

EFI_STATUS Ping6ReceiveEchoReply ( IN PING_PRIVATE_DATA Private)

Place a completion token into the receive packet queue to receive the echo reply.

Parameters
[in]PrivateThe pointer of PING_PRIVATE_DATA.
Return values
EFI_SUCCESSPut the token into the receive packet queue successfully.
othersPut the token into the receive packet queue unsuccessfully.

Definition at line 818 of file Ping.c.

◆ PingCreateIpInstance()

EFI_STATUS PingCreateIpInstance ( IN PING_PRIVATE_DATA Private)

Create a valid IP instance.

Parameters
[in]PrivateThe pointer of PING_PRIVATE_DATA.
Return values
EFI_SUCCESSCreate a valid IPx instance successfully.
EFI_ABORTEDLocate handle with ipx service binding protocol unsuccessfully.
EFI_INVALID_PARAMETERThe source address is unspecified when the destination address is a link-local address.
EFI_OUT_OF_RESOURCESNo memory is available on the platform.
EFI_NOT_FOUNDThe source address is not found.

Definition at line 969 of file Ping.c.

◆ PingDestroyTxInfo()

VOID PingDestroyTxInfo ( IN PING_ICMPX_TX_INFO TxInfo,
IN UINT32  IpChoice 
)

Destroy PING_ICMPX_TX_INFO, and recollect the memory.

Parameters
[in]TxInfoThe pointer to PING_ICMPX_TX_INFO.
[in]IpChoiceWhether the token is IPv4 or IPv6

Definition at line 417 of file Ping.c.

◆ PingFreeRttTimer()

VOID PingFreeRttTimer ( PING_PRIVATE_DATA Private)

Free RTT timer event resource.

Parameters
[in]PrivateThe pointer to PING_PRIVATE_DATA.

Definition at line 361 of file Ping.c.

◆ PingGenerateToken()

PING_IPX_COMPLETION_TOKEN * PingGenerateToken ( IN PING_PRIVATE_DATA Private,
IN UINT32  TimeStamp,
IN UINT16  SequenceNum 
)

Create a PING_IPX_COMPLETION_TOKEN.

Parameters
[in]PrivateThe pointer of PING_PRIVATE_DATA.
[in]TimeStampThe TimeStamp of request.
[in]SequenceNumThe SequenceNum of request.
Returns
The pointer of PING_IPX_COMPLETION_TOKEN.

Definition at line 662 of file Ping.c.

◆ PingInitRttTimer()

EFI_STATUS PingInitRttTimer ( PING_PRIVATE_DATA Private)

Initialize the timer event for RTT (round trip time).

Parameters
[in]PrivateThe pointer to PING_PRIVATE_DATA.
Return values
EFI_SUCCESSRTT timer is started.
OthersFailed to start the RTT timer.

Definition at line 318 of file Ping.c.

◆ PingNetIp4IsLinkLocalAddr()

BOOLEAN PingNetIp4IsLinkLocalAddr ( IN CONST EFI_IPv4_ADDRESS Address)

Determine if a IP4 address is Link Local.

169.254.1.0 through 169.254.254.255 is link local.

Parameters
[in]AddressThe address to test.
Return values
TRUEIt is.
FALSEIt is not.

Definition at line 934 of file Ping.c.

◆ PingNetIp4IsUnspecifiedAddr()

BOOLEAN PingNetIp4IsUnspecifiedAddr ( IN CONST EFI_IPv4_ADDRESS Address)

Determine if a IP4 address is unspecified.

Parameters
[in]AddressThe address to test.
Return values
TRUEIt is.
FALSEIt is not.

Definition at line 950 of file Ping.c.

◆ PingSendEchoRequest()

EFI_STATUS PingSendEchoRequest ( IN PING_PRIVATE_DATA Private)

Transmit the PING_IPX_COMPLETION_TOKEN.

Parameters
[in]PrivateThe pointer of PING_PRIVATE_DATA.
Return values
EFI_SUCCESSTransmitted successfully.
EFI_OUT_OF_RESOURCESNo memory is available on the platform.
othersTransmitted unsuccessfully.

Definition at line 765 of file Ping.c.

◆ ReadTime()

UINT32 ReadTime ( PING_PRIVATE_DATA Private)

Read the current time.

Parameters
[in]PrivateThe pointer to PING_PRIVATE_DATA.
Return values
thecurrent tick value.

Definition at line 379 of file Ping.c.

◆ RttTimerTickRoutine()

VOID EFIAPI RttTimerTickRoutine ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

RTT timer tick routine.

Parameters
[in]EventA EFI_EVENT type event.
[in]ContextThe pointer to Context.

Definition at line 232 of file Ping.c.

◆ ShellCommandRunPing()

SHELL_STATUS EFIAPI ShellCommandRunPing ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Function for 'ping' command.

Parameters
[in]ImageHandleHandle to the Image (NULL if Internal).
[in]SystemTablePointer to the System Table (NULL if Internal).
Return values
SHELL_SUCCESSThe ping processed successfullly.
othersThe ping processed unsuccessfully.

Definition at line 1581 of file Ping.c.

◆ ShellPing()

SHELL_STATUS ShellPing ( IN UINT32  SendNumber,
IN UINT32  BufferSize,
IN EFI_IPv6_ADDRESS SrcAddress,
IN EFI_IPv6_ADDRESS DstAddress,
IN UINT32  IpChoice 
)

The Ping Process.

Parameters
[in]SendNumberThe send request count.
[in]BufferSizeThe send buffer size.
[in]SrcAddressThe source address.
[in]DstAddressThe destination address.
[in]IpChoiceThe choice between IPv4 and IPv6.
Return values
SHELL_SUCCESSThe ping processed successfullly.
othersThe ping processed unsuccessfully.

Definition at line 1365 of file Ping.c.

Variable Documentation

◆ mCurrentTick

UINT64 mCurrentTick = 0

Definition at line 16 of file Ping.c.

◆ mDstString

STATIC CONST CHAR16* mDstString

Definition at line 220 of file Ping.c.

◆ mSrcString

STATIC CONST CHAR16* mSrcString

Definition at line 221 of file Ping.c.

◆ PingParamList

STATIC CONST SHELL_PARAM_ITEM PingParamList[]
Initial value:
= {
{
L"-l",
},
{
L"-n",
},
{
L"-s",
},
{
L"-_s",
},
{
L"-_ip6",
},
{
TypeMax
},
}
#define NULL
Definition: Base.h:319
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699

Reads and returns the current value of register. In IA64, the register is the Interval Timer Vector (ITV). In X86(IA32/X64), the register is the Time Stamp Counter (TSC)

Returns
The current value of the register.

Definition at line 190 of file Ping.c.