Choco OS  V.0.16.9.0
Join to the chocolate world
Internet Control Message Protocol

module for handling ICMP packets More...

Data Structures

struct  oC_Icmp_Header_t
 stores ICMP message header More...
 
struct  oC_Icmp_Message_Echo_t
 stores ICMP echo message More...
 
struct  oC_Icmp_Message_Timestamp_t
 stores ICMP timestamp message More...
 
struct  oC_Icmp_Message_AddressMask_t
 stores ICMP Address Mask message More...
 
struct  oC_Icmp_Message_DestinationUnreachable_t
 stores ICMP Destination Unreachable message More...
 
struct  oC_Icmp_Datagram_t
 stores ICMP datagram More...
 
union  oC_Icmp_Packet_t
 stores ICMP packet (datagram + IP header) More...
 

Enumerations

Functions

oC_ErrorCode_t oC_Icmp_TurnOn (void)
 turns on ICMP module More...
 
oC_ErrorCode_t oC_Icmp_TurnOff (void)
 turns off ICMP module More...
 
bool oC_Icmp_IsTypeReserved (oC_Icmp_Type_t Type, oC_Process_t Process)
 checks if the given ICMP type is reserved More...
 
oC_ErrorCode_t oC_Icmp_ReserveType (oC_Icmp_Type_t Type, oC_Time_t Timeout)
 reserves a ICMP type More...
 
oC_ErrorCode_t oC_Icmp_ReleaseType (oC_Icmp_Type_t Type, oC_Time_t Timeout)
 releases a type More...
 
oC_ErrorCode_t oC_Icmp_ReleaseAllTypesReservedBy (oC_Process_t Process, oC_Time_t Timeout)
 releases all types reserved by the process More...
 
oC_ErrorCode_t oC_Icmp_CalculateChecksum (oC_Icmp_Packet_t *Packet, uint16_t *outChecksum)
 Calculates checksum for ICMP packet. More...
 
oC_Icmp_Packet_toC_Icmp_Packet_New (Allocator_t PacketAllocator, oC_Net_PacketType_t Type, oC_Icmp_Type_t IcmpType, uint8_t Code, const void *Data, uint16_t Size)
 allocates memory for a ICMP packet More...
 
bool oC_Icmp_Packet_SetSize (oC_Icmp_Packet_t *Packet, uint16_t Size)
 sets size of the packet
 
bool oC_Icmp_Packet_Delete (oC_Icmp_Packet_t **Packet)
 release memory allocated for a ICMP packet
 
void * oC_Icmp_Packet_GetMessageReference (oC_Icmp_Packet_t *Packet)
 returns reference to the message inside ICMP packet
 
oC_ErrorCode_t oC_Icmp_Send (oC_Netif_t Netif, const oC_Net_Address_t *Destination, oC_Icmp_Packet_t *Packet, oC_Time_t Timeout)
 sends ICMP packet More...
 
oC_ErrorCode_t oC_Icmp_Receive (oC_Netif_t Netif, oC_Icmp_Packet_t *outPacket, oC_Icmp_Type_t Type, oC_Time_t Timeout)
 receives ICMP packet More...
 

Detailed Description

Enumeration Type Documentation

The type is for storing ICMP type for the Type field in the oC_Icmp_Header_t struct.

Enumerator
oC_Icmp_Type_EchoReply 

Echo reply.

oC_Icmp_Type_DestinationUnreachable 

Destination unreachable message.

oC_Icmp_Type_SourceQuench 

Source Quench (depracated)

oC_Icmp_Type_RedirectMessage 

Redirect Message.

oC_Icmp_Type_EchoRequest 

Echo Request.

oC_Icmp_Type_RouterAdvertisement 

Router Advertisement.

oC_Icmp_Type_RouterSolicitation 

Router Solicitation.

oC_Icmp_Type_TimeExceeded 

Time Exceeded.

oC_Icmp_Type_ParameterProblemBadIpHeader 

Parameter Problem Bad Ip Header.

oC_Icmp_Type_Timestamp 

Timestamp.

oC_Icmp_Type_TimestampReply 

Timestamp Reply.

oC_Icmp_Type_InformationRequest 

Information Request.

oC_Icmp_Type_InformationReply 

Information Reply.

oC_Icmp_Type_AddressMaskRequest 

Address Mask Request.

oC_Icmp_Type_AddressMaskReply 

Address Mask Reply.

Definition at line 55 of file oc_icmp.h.

Function Documentation

oC_ErrorCode_t oC_Icmp_CalculateChecksum ( oC_Icmp_Packet_t Packet,
uint16_t *  outChecksum 
)

The function is for calculating checksum for ICMP packets. The packet has to be in the host byte endianess.

Parameters
PacketPacket to calculate a checksum
outChecksumDestination for a checksum
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet ICMP module is not turned on. Please call oC_Icmp_TurnOn first
oC_ErrorCode_AddressNotInRam Packet does not point to the RAM section
oC_ErrorCode_OutputAddressNotInRAM outChecksumCorrect or outExpectedChecksum does not point to the RAM section

Definition at line 469 of file oc_icmp.c.

bool oC_Icmp_IsTypeReserved ( oC_Icmp_Type_t  Type,
oC_Process_t  Process 
)

The function checks if the given type is reserved. If Process parameter is not NULL, the function will check if the given port is reserved by this process.

Parameters
TypeType to check
ProcessProcess which check if it is an owner of the port
Returns
true if the port is reserved

Definition at line 211 of file oc_icmp.c.

oC_Icmp_Packet_t* oC_Icmp_Packet_New ( Allocator_t  PacketAllocator,
oC_Net_PacketType_t  Type,
oC_Icmp_Type_t  IcmpType,
uint8_t  Code,
const void *  Data,
uint16_t  Size 
)

The function is for allocating memory for the ICMP packet. It calculates memory required for the packet including all headers of sub-layers. Memory should be released, when is not needed anymore by using the function oC_Icmp_Packet_Delete

Note
In case of failure, error can be read from the errors stack
Parameters
PacketAllocatorAllocator for the Memory Manager
TypeType of the packet (IPv4 or IPv6)
IcmpTypeType of the ICMP message
CodeCode (SubType) of the ICMP message
DataAddress of the data to put inside the UDP packet. It can be NULL if you dont want to fill it now
SizeSize of the data inside UDP packet
Returns
pointer to the allocated memory
See also
oC_Udp_Packet_Delete

Definition at line 513 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_Receive ( oC_Netif_t  Netif,
oC_Icmp_Packet_t outPacket,
oC_Icmp_Type_t  Type,
oC_Time_t  Timeout 
)

The function is for receiving ICMP packets at the selected UDP type. The type has to be reserved for the current process, otherwise receiving is not possible.

Note
Remember that you have to reserve a ICMP type by using function oC_Icmp_ReserveType before usage.
Warning
Function will receive only packets that matches Packet type, so if the type of the Packet is set to IPv4, the function will receive only packets that contains IPv4 address!
Parameters
NetifNetwork interface to receive packet from or NULL if not used
outPacketDestination for a received packet.
TypeICMP type of the message to receive the packet from. The type should be reserved before by calling a function oC_Icmp_ReserveType
TimeoutMaximum time for the send request
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet UDP module is not turned on. Please call oC_Udp_TurnOn first
oC_ErrorCode_NetifNotCorrect Netif is not correct (address is not correct or not valid anymore) and it is not NULL
oC_ErrorCode_TimeNotCorrect Timeout value is lower than 0!!
oC_ErrorCode_OutputAddressNotInRAM outPacket does not point to the RAM section
oC_ErrorCode_TypeNotReserved The given Type in Packet is not reserved by using the function oC_Udp_ReservePort
oC_ErrorCode_TypeReservedByDifferentProcess The given Type in Packet is already reserved by different process.
oC_ErrorCode_TypeBusy The given Type is busy (Maximum time for the request elapsed)
oC_ErrorCode_ModuleBusy Module is busy (Maximum time for the request elapsed)
oC_ErrorCode_Timeout Maximum time for the request elapsed
See also
oC_Icmp_Receive, oC_Icmp_TurnOn, oC_Icmp_ReserveType, oC_Icmp_Packet_New

Definition at line 742 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_ReleaseAllTypesReservedBy ( oC_Process_t  Process,
oC_Time_t  Timeout 
)

Only one application can use a type at once, otherwise it can cause loosing of datagrams. This function allows to release all reserved types that are owned by the given process when they are not needed anymore.

Note
This function can be called only by the root user. It is not enough to have admin privileges - you have to be a root.
Parameters
ProcessProcess that reserved some ICMP types
TimeoutMaximum time to wait for the module readiness
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet ICMP module is not turned on. Please call oC_Icmp_TurnOn first
oC_ErrorCode_ProcessNotCorrect Process is not correct or not valid anymore
oC_ErrorCode_TimeNotCorrect Timeout value is lower than 0!!
oC_ErrorCode_Timeout Module is still busy and maximum time for this operation has elapsed
oC_ErrorCode_PossibleOnlyForRoot Function can be called only by the root user. You are not permitted to perform this
See also
oC_Udp_Receive, oC_Udp_Send, oC_Udp_TurnOn, oC_Udp_ReleasePort

Definition at line 414 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_ReleaseType ( oC_Icmp_Type_t  Type,
oC_Time_t  Timeout 
)

Only one application can use a type at once, otherwise it can cause loosing of datagrams. This function allows to release reserved type when it is not needed anymore. Reservation is performed for a current process and only this process is able to use the reserved type. Usually all reserved types are automatically released, when the process is killed.

Parameters
TypeLocal type reserved by calling a function #oC_Icmp_ReservePort
TimeoutMaximum time to wait for the module readiness
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet ICMP module is not turned on. Please call oC_Icmp_TurnOn first
oC_ErrorCode_TimeNotCorrect Timeout value is lower than 0!!
oC_ErrorCode_Timeout Type is still busy and maximum time for this operation has elapsed
oC_ErrorCode_ModuleBusy Module is still busy and maximum time for this operation has elapsed
oC_ErrorCode_TypeNotReserved The given Type is not reserved by using the function #oC_Icmp_ReservePort
oC_ErrorCode_TypeReservedByDifferentProcess The given Type is reserved by different process.
oC_ErrorCode_TypeBusy The given Type is currently in use.
oC_ErrorCode_CannotDeleteObject Cannot delete Mutex related with the type
See also
oC_Icmp_Receive, oC_Icmp_Send, oC_Icmp_TurnOn, oC_Icmp_ReleasePort

Definition at line 347 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_ReserveType ( oC_Icmp_Type_t  Type,
oC_Time_t  Timeout 
)

Only one application can use a type at once, otherwise it can cause loosing of datagrams. This function allows to reserve a type before usage. Reservation is performed for a current process and only this process will be able to use the reserved type.

Parameters
TypeType to reserve
TimeoutMaximum time for the operation
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet ICMP module is not turned on. Please call oC_Icmp_TurnOn first
oC_ErrorCode_PortNotAvailable The are no free ports or the selected one is already reserved
oC_ErrorCode_TimeNotCorrect Timeout value is lower than 0!!
oC_ErrorCode_Timeout Type is still busy and maximum time for this operation has elapsed
oC_ErrorCode_ModuleBusy Module is still busy and maximum time for this operation has elapsed
See also
oC_Icmp_Receive, oC_Icmp_Send, oC_Icmp_TurnOn, oC_Icmp_ReleasePort

Definition at line 252 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_Send ( oC_Netif_t  Netif,
const oC_Net_Address_t Destination,
oC_Icmp_Packet_t Packet,
oC_Time_t  Timeout 
)

The function prepares ICMP packet and sends it to the recipient.

Note
Don't reserve a ICMP type if you only want to send ICMP packets of a type. Reserving packets is a mechanism for receiving
Parameters
NetifPointer to the configured network interface or NULL if not used
DestinationDestination address where the packet should be sent
PacketICMP packet to send allocated by the function oC_Icmp_Packet_New
TimeoutMaximum time for the send request
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet UDP module is not turned on. Please call oC_Udp_TurnOn first
oC_ErrorCode_NetifNotCorrect Netif is not correct (address is not correct or not valid anymore) and it is not NULL
oC_ErrorCode_AddressNotInRam Packet does not point to the RAM section
oC_ErrorCode_WrongAddress Destination is not correct memory address
oC_ErrorCode_IpAddressNotCorrect Destination stores IP address that is not correct (probably type is not set)
oC_ErrorCode_TimeNotCorrect Timeout value is lower than 0!!
oC_ErrorCode_Timeout Maximum time for the request elapsed
oC_ErrorCode_PacketNotCorrect ICMP packet is not correct (probably IP type is not set correctly)
oC_ErrorCode_TypeNotCorrect ICMP packet type and destination address type are not the same
oC_ErrorCode_CannotFindNetifForTheAddress Netif is not given (NULL) but we cannot find any that can achieve the given address
oC_ErrorCode_ModuleBusy Module is busy (Maximum time for the request elapsed)
See also
oC_Udp_Receive, oC_Udp_TurnOn, oC_Udp_ReservePort, oC_Udp_Packet_New

Definition at line 642 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_TurnOff ( void  )

The function is for turning off ICMP module. The module has to be turned off before usage and turned off when is not needed.

Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet UDP module is not turned on. Please call oC_Udp_TurnOn first
oC_ErrorCode_ReleaseError Cannot release memory
See also
oC_Icmp_TurnOn

Definition at line 165 of file oc_icmp.c.

oC_ErrorCode_t oC_Icmp_TurnOn ( void  )

The function is for turning on ICMP module. The module has to be turned on before usage.

Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleIsTurnedOn UDP module is already turned on.
oC_ErrorCode_AllocationError Cannot allocate memory
See also
oC_Icmp_TurnOff

Definition at line 109 of file oc_icmp.c.