FreeRTOS-Plus-TCP V4.0.0
FreeRTOS TCP/IP library
 
Loading...
Searching...
No Matches
FreeRTOS_Routing.c File Reference

Implements endpoint interfaces functions and utilities. More...

#include <stdint.h>
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_Routing.h"

Data Structures

struct  xIPv6_Couple
 A util struct to list the IPv6 IP types, prefix and type bit mask. More...
 

Macros

#define rMATCH_IP_ADDR   0
 Check IP-type, IP- and MAC-address found in the network packet.
 
#define rMATCH_IPv6_TYPE   1
 
#define rMATCH_MAC_ADDR   2
 
#define rMATCH_IP_TYPE   3
 
#define rMATCH_COUNT   4
 

Functions

static NetworkEndPoint_t * FreeRTOS_AddEndPoint (NetworkInterface_t *pxInterface, NetworkEndPoint_t *pxEndPoint)
 Add an end-point to a given interface.
 
void FreeRTOS_FillEndPoint (NetworkInterface_t *pxNetworkInterface, NetworkEndPoint_t *pxEndPoint, const uint8_t ucIPAddress[ipIP_ADDRESS_LENGTH_BYTES], const uint8_t ucNetMask[ipIP_ADDRESS_LENGTH_BYTES], const uint8_t ucGatewayAddress[ipIP_ADDRESS_LENGTH_BYTES], const uint8_t ucDNSServerAddress[ipIP_ADDRESS_LENGTH_BYTES], const uint8_t ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES])
 Configure and install a new IPv4 end-point.
 
NetworkInterface_t * FreeRTOS_AddNetworkInterface (NetworkInterface_t *pxInterface)
 Add a network interface to the list of interfaces. Check if the interface was already added in an earlier call.
 
NetworkInterface_t * FreeRTOS_FirstNetworkInterface (void)
 Get the first Network Interface, or NULL if none has been added.
 
NetworkInterface_t * FreeRTOS_NextNetworkInterface (const NetworkInterface_t *pxInterface)
 Get the next interface.
 
NetworkEndPoint_t * FreeRTOS_FirstEndPoint (const NetworkInterface_t *pxInterface)
 Find the first end-point bound to a given interface.
 
NetworkEndPoint_t * FreeRTOS_NextEndPoint (const NetworkInterface_t *pxInterface, NetworkEndPoint_t *pxEndPoint)
 Get the next end-point. The parameter 'pxInterface' may be NULL, which means: don't care which interface the end-point is bound to.
 
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4 (uint32_t ulIPAddress, uint32_t ulWhere)
 Find the end-point which has a given IPv4 address.
 
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv6 (const IPv6_Address_t *pxIPAddress)
 Find the end-point which handles a given IPv6 address.
 
NetworkEndPoint_t * FreeRTOS_FindEndPointOnMAC (const MACAddress_t *pxMACAddress, const NetworkInterface_t *pxInterface)
 Find the end-point that has a certain MAC-address.
 
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask (uint32_t ulIPAddress, uint32_t ulWhere)
 Find an end-point that handles a given IPv4-address.
 
NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask (const NetworkInterface_t *pxInterface, uint32_t ulIPAddress, uint32_t ulWhere)
 Find an end-point that handles a given IPv4-address.
 
void FreeRTOS_FillEndPoint_IPv6 (NetworkInterface_t *pxNetworkInterface, NetworkEndPoint_t *pxEndPoint, const IPv6_Address_t *pxIPAddress, const IPv6_Address_t *pxNetPrefix, size_t uxPrefixLength, const IPv6_Address_t *pxGatewayAddress, const IPv6_Address_t *pxDNSServerAddress, const uint8_t ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES])
 Configure and install a new IPv6 end-point.
 
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6 (const IPv6_Address_t *pxIPv6Address)
 Find an end-point that handles a given IPv6-address.
 
NetworkEndPoint_t * pxEasyFit (const NetworkInterface_t *pxNetworkInterface, const uint16_t usFrameType, const IP_Address_t *pxIPAddressFrom, const IP_Address_t *pxIPAddressTo, const MACAddress_t *pxMACAddress)
 Find an end-point that handles an incoming packet based on its type, source/destination & MAC address.
 
NetworkEndPoint_t * FreeRTOS_MatchingEndpoint (const NetworkInterface_t *pxNetworkInterface, const uint8_t *pucEthernetBuffer)
 Find out the best matching end-point given an incoming Ethernet packet.
 
NetworkEndPoint_t * FreeRTOS_FindGateWay (BaseType_t xIPType)
 Find an end-point that defines a gateway of a certain type ( IPv4 or IPv6 ).
 
NetworkEndPoint_t * FreeRTOS_FirstEndPoint_IPv6 (const NetworkInterface_t *pxInterface)
 Find the first IPv6 end-point.
 
NetworkEndPoint_t * pxGetSocketEndpoint (ConstSocket_t xSocket)
 Get the end-point that is bound to a socket.
 
void vSetSocketEndpoint (Socket_t xSocket, NetworkEndPoint_t *pxEndPoint)
 Assign an end-point to a socket.
 
IPv6_Type_t xIPv6_GetIPType (const IPv6_Address_t *pxAddress)
 Returns the IP type of the given IPv6 address.
 
const char * pcEndpointName (const NetworkEndPoint_t *pxEndPoint, char *pcBuffer, size_t uxSize)
 Returns the string representation of the IP address of the end point.
 

Variables

struct xNetworkEndPoint * pxNetworkEndPoints = NULL
 A list of all network end-points. Each element has a next pointer.
 
struct xNetworkInterface * pxNetworkInterfaces = NULL
 A list of all network interfaces:
 

Detailed Description

Implements endpoint interfaces functions and utilities.

Macro Definition Documentation

◆ rMATCH_IP_ADDR

#define rMATCH_IP_ADDR   0

Check IP-type, IP- and MAC-address found in the network packet.

Find an endpoint with a matching IP-address.

◆ rMATCH_IPv6_TYPE

#define rMATCH_IPv6_TYPE   1

Find an endpoint with a matching IPv6 type (both global or non global).

◆ rMATCH_MAC_ADDR

#define rMATCH_MAC_ADDR   2

Find an endpoint with a matching MAC-address.

◆ rMATCH_IP_TYPE

#define rMATCH_IP_TYPE   3

Find an endpoint with a matching IP-type, v4 or v6.

◆ rMATCH_COUNT

#define rMATCH_COUNT   4

The number of methods.

Function Documentation

◆ FreeRTOS_AddEndPoint()

static NetworkEndPoint_t * FreeRTOS_AddEndPoint ( NetworkInterface_t *  pxInterface,
NetworkEndPoint_t *  pxEndPoint 
)
static

Add an end-point to a given interface.

Parameters
[in]pxInterfaceThe interface that gets a new end-point.
[in]pxEndPointThe end-point to be added.
Returns
The value of the parameter 'pxEndPoint'.

◆ FreeRTOS_FillEndPoint()

void FreeRTOS_FillEndPoint ( NetworkInterface_t *  pxNetworkInterface,
NetworkEndPoint_t *  pxEndPoint,
const uint8_t  ucIPAddress[ipIP_ADDRESS_LENGTH_BYTES],
const uint8_t  ucNetMask[ipIP_ADDRESS_LENGTH_BYTES],
const uint8_t  ucGatewayAddress[ipIP_ADDRESS_LENGTH_BYTES],
const uint8_t  ucDNSServerAddress[ipIP_ADDRESS_LENGTH_BYTES],
const uint8_t  ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES] 
)

Configure and install a new IPv4 end-point.

Parameters
[in]pxNetworkInterfaceThe interface to which it belongs.
[in]pxEndPointSpace for the new end-point. This memory is dedicated for the end-point and should not be freed or get any other purpose.
[in]ucIPAddressThe IP-address.
[in]ucNetMaskThe prefix which shall be used for this end-point.
[in]ucGatewayAddressThe IP-address of a device on the LAN which can serve as as a gateway to the Internet.
[in]ucDNSServerAddressThe IP-address of a DNS server.
[in]ucMACAddressThe MAC address of the end-point.

◆ FreeRTOS_AddNetworkInterface()

NetworkInterface_t * FreeRTOS_AddNetworkInterface ( NetworkInterface_t *  pxInterface)

Add a network interface to the list of interfaces. Check if the interface was already added in an earlier call.

Parameters
[in]pxInterfaceThe address of the new interface.
Returns
The value of the parameter 'pxInterface'.

◆ FreeRTOS_FirstNetworkInterface()

NetworkInterface_t * FreeRTOS_FirstNetworkInterface ( void  )

Get the first Network Interface, or NULL if none has been added.

Returns
The first interface, or NULL if none has been added

◆ FreeRTOS_NextNetworkInterface()

NetworkInterface_t * FreeRTOS_NextNetworkInterface ( const NetworkInterface_t *  pxInterface)

Get the next interface.

Returns
The interface that comes after 'pxInterface'. NULL when either 'pxInterface' is NULL, or when 'pxInterface' is the last interface.

◆ FreeRTOS_FirstEndPoint()

NetworkEndPoint_t * FreeRTOS_FirstEndPoint ( const NetworkInterface_t *  pxInterface)

Find the first end-point bound to a given interface.

Parameters
[in]pxInterfaceThe interface whose first end-point will be returned.
Returns
The first end-point that is found to the interface, or NULL when the interface doesn't have any end-point yet.

◆ FreeRTOS_NextEndPoint()

NetworkEndPoint_t * FreeRTOS_NextEndPoint ( const NetworkInterface_t *  pxInterface,
NetworkEndPoint_t *  pxEndPoint 
)

Get the next end-point. The parameter 'pxInterface' may be NULL, which means: don't care which interface the end-point is bound to.

Parameters
[in]pxInterfaceAn interface of interest, or NULL when iterating through all end-points.
[in]pxEndPointThis is the current end-point.
Returns
The end-point that is found, or NULL when there are no more end-points in the list.

◆ FreeRTOS_FindEndPointOnIP_IPv4()

NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4 ( uint32_t  ulIPAddress,
uint32_t  ulWhere 
)

Find the end-point which has a given IPv4 address.

Parameters
[in]ulIPAddressThe IP-address of interest, or 0 if any IPv4 end-point may be returned.
[in]ulWhereFor maintaining routing statistics ulWhere acts as an index to the data structure that keep track of the number of times 'FreeRTOS_FindEndPointOnIP_IPv4()' has been called from a particular location. Used only if ipconfigHAS_ROUTING_STATISTICS is enabled.
Returns
The end-point found or NULL.

◆ FreeRTOS_FindEndPointOnIP_IPv6()

NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv6 ( const IPv6_Address_t *  pxIPAddress)

Find the end-point which handles a given IPv6 address.

Parameters
[in]pxIPAddressThe IP-address of interest.
Returns
The end-point found or NULL.

◆ FreeRTOS_FindEndPointOnMAC()

NetworkEndPoint_t * FreeRTOS_FindEndPointOnMAC ( const MACAddress_t *  pxMACAddress,
const NetworkInterface_t *  pxInterface 
)

Find the end-point that has a certain MAC-address.

Parameters
[in]pxMACAddressThe Ethernet packet.
[in]pxInterfaceThe interface on which the packet was received, or NULL when unknown.
Returns
The end-point that has the given MAC-address.

◆ FreeRTOS_FindEndPointOnNetMask()

NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask ( uint32_t  ulIPAddress,
uint32_t  ulWhere 
)

Find an end-point that handles a given IPv4-address.

Parameters
[in]ulIPAddressThe IP-address for which an end-point is looked-up.
[in]ulWhereFor maintaining routing statistics ulWhere acts as an index to the data structure that keep track of the number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' has been called from a particular location. Used only if ipconfigHAS_ROUTING_STATISTICS is enabled.
Returns
An end-point that has the same network mask as the given IP-address.

◆ FreeRTOS_InterfaceEndPointOnNetMask()

NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask ( const NetworkInterface_t *  pxInterface,
uint32_t  ulIPAddress,
uint32_t  ulWhere 
)

Find an end-point that handles a given IPv4-address.

Parameters
[in]pxInterfaceOnly end-points that have this interface are returned, unless pxInterface is NULL.
[in]ulIPAddressThe IP-address for which an end-point is looked-up.
[in]ulWhereFor maintaining routing statistics ulWhere acts as an index to the data structure that keep track of the number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' has been called from a particular location. Used only if ipconfigHAS_ROUTING_STATISTICS is enabled.
Returns
An end-point that has the same network mask as the given IP-address.

◆ FreeRTOS_FillEndPoint_IPv6()

void FreeRTOS_FillEndPoint_IPv6 ( NetworkInterface_t *  pxNetworkInterface,
NetworkEndPoint_t *  pxEndPoint,
const IPv6_Address_t *  pxIPAddress,
const IPv6_Address_t *  pxNetPrefix,
size_t  uxPrefixLength,
const IPv6_Address_t *  pxGatewayAddress,
const IPv6_Address_t *  pxDNSServerAddress,
const uint8_t  ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES] 
)

Configure and install a new IPv6 end-point.

Parameters
[in]pxNetworkInterfaceThe interface to which it belongs.
[in]pxEndPointSpace for the new end-point. This memory is dedicated for the end-point and should not be freed or get any other purpose.
[in]pxIPAddressThe IP-address.
[in]pxNetPrefixThe prefix which shall be used for this end-point.
[in]uxPrefixLengthThe length of the above end-point.
[in]pxGatewayAddressThe IP-address of a device on the LAN which can serve as as a gateway to the Internet.
[in]pxDNSServerAddressThe IP-address of a DNS server.
[in]ucMACAddressThe MAC address of the end-point.

◆ FreeRTOS_FindEndPointOnNetMask_IPv6()

NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6 ( const IPv6_Address_t *  pxIPv6Address)

Find an end-point that handles a given IPv6-address.

Parameters
[in]pxIPv6AddressThe IP-address for which an end-point is looked-up.
Returns
An end-point that has the same network mask as the given IP-address.

◆ pxEasyFit()

NetworkEndPoint_t * pxEasyFit ( const NetworkInterface_t *  pxNetworkInterface,
const uint16_t  usFrameType,
const IP_Address_t *  pxIPAddressFrom,
const IP_Address_t *  pxIPAddressTo,
const MACAddress_t *  pxMACAddress 
)

Find an end-point that handles an incoming packet based on its type, source/destination & MAC address.

Parameters
[in]pxNetworkInterfaceThe interface via which the packet was received.
[in]usFrameTypeFrame type of the packet.
[in]pxIPAddressFromSource IP address of the packet.
[in]pxIPAddressToDestination IP address of the packet.
[in]pxMACAddressDestination MAC address of the packet.
Returns
An end-point that handles the packet.

◆ FreeRTOS_MatchingEndpoint()

NetworkEndPoint_t * FreeRTOS_MatchingEndpoint ( const NetworkInterface_t *  pxNetworkInterface,
const uint8_t *  pucEthernetBuffer 
)

Find out the best matching end-point given an incoming Ethernet packet.

Parameters
[in]pxNetworkInterfaceThe interface on which the packet was received.
[in]pucEthernetBufferThe Ethernet packet that was just received.
Returns
The end-point that should handle the incoming Ethernet packet.

◆ FreeRTOS_FindGateWay()

NetworkEndPoint_t * FreeRTOS_FindGateWay ( BaseType_t  xIPType)

Find an end-point that defines a gateway of a certain type ( IPv4 or IPv6 ).

Parameters
[in]xIPTypeThe type of Gateway to look for ( ipTYPE_IPv4 or ipTYPE_IPv6 ).
Returns
The end-point that will lead to the gateway, or NULL when no gateway was found.

◆ FreeRTOS_FirstEndPoint_IPv6()

NetworkEndPoint_t * FreeRTOS_FirstEndPoint_IPv6 ( const NetworkInterface_t *  pxInterface)

Find the first IPv6 end-point.

Parameters
[in]pxInterfaceEither NULL ( don't care ), or a specific interface.
Returns
The end-point found, or NULL when there are no end-points at all.

◆ pxGetSocketEndpoint()

NetworkEndPoint_t * pxGetSocketEndpoint ( ConstSocket_t  xSocket)

Get the end-point that is bound to a socket.

Parameters
[in]xSocketThe socket of interest.
Returns
An end-point or NULL in case the socket is not bound to an end-point.

◆ vSetSocketEndpoint()

void vSetSocketEndpoint ( Socket_t  xSocket,
NetworkEndPoint_t *  pxEndPoint 
)

Assign an end-point to a socket.

Parameters
[in]xSocketThe socket to which an end-point will be assigned.
[in]pxEndPointThe end-point to be assigned.

◆ xIPv6_GetIPType()

IPv6_Type_t xIPv6_GetIPType ( const IPv6_Address_t *  pxAddress)

Returns the IP type of the given IPv6 address.

Parameters
[in]pxAddressThe IPv6 address whose type needs to be returned.
Returns
The IP type of the given address.

◆ pcEndpointName()

const char * pcEndpointName ( const NetworkEndPoint_t *  pxEndPoint,
char *  pcBuffer,
size_t  uxSize 
)

Returns the string representation of the IP address of the end point.

Parameters
[in]pxEndPointEnd point for which IP address needs to be returned.
[in]pcBufferA char buffer of required size to which the string will be written.
[in]uxSizeSize of the char buffer - pcBuffer.
Returns
The pointer to the char buffer that contains the string representation of the end point IP address. The string will be "NULL" if the end point pointer is NULL.