Skip to content

Commit d41ebd3

Browse files
committed
Add ND Timer event implementation
1 parent c43498d commit d41ebd3

File tree

18 files changed

+440
-199
lines changed

18 files changed

+440
-199
lines changed

source/FreeRTOS_IP.c

Lines changed: 99 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,50 @@
6464
#ifndef ipINITIALISATION_RETRY_DELAY
6565
#define ipINITIALISATION_RETRY_DELAY ( pdMS_TO_TICKS( 3000U ) )
6666
#endif
67+
6768
#if ( ipconfigUSE_TCP_MEM_STATS != 0 )
6869
#include "tcp_mem_stats.h"
6970
#endif
7071

71-
/** @brief Maximum time to wait for a resolution while holding a packet. */
72-
#ifndef ipADDR_RES_MAX_DELAY
73-
#define ipADDR_RES_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) )
72+
/** @brief Maximum time to wait for an ARP resolution while holding a packet. */
73+
#ifndef ipARP_RESOLUTION_MAX_DELAY
74+
#define ipARP_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) )
7475
#endif
7576

76-
#ifndef iptraceIP_TASK_STARTING
77-
#define iptraceIP_TASK_STARTING() do {} while( ipFALSE_BOOL ) /**< Empty definition in case iptraceIP_TASK_STARTING is not defined. */
77+
/** @brief Maximum time to wait for a ND resolution while holding a packet. */
78+
#ifndef ipND_RESOLUTION_MAX_DELAY
79+
#define ipND_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) )
7880
#endif
7981

80-
#if ( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) )
81-
/** @brief When initialising the TCP timer, give it an initial time-out of 1 second. */
82-
#define ipTCP_TIMER_PERIOD_MS ( 1000U )
82+
/** @brief Defines how often the ARP resolution timer callback function is executed. The time is
83+
* shorter in the Windows simulator as simulated time is not real time. */
84+
#ifndef ipARP_TIMER_PERIOD_MS
85+
#ifdef _WINDOWS_
86+
#define ipARP_TIMER_PERIOD_MS ( 500U ) /* For windows simulator builds. */
87+
#else
88+
#define ipARP_TIMER_PERIOD_MS ( 10000U )
89+
#endif
8390
#endif
8491

85-
/** @brief Defines how often the resolution timer callback function is executed. The time is
92+
/** @brief Defines how often the ND resolution timer callback function is executed. The time is
8693
* shorter in the Windows simulator as simulated time is not real time. */
87-
#ifndef ipADDR_RES_TIMER_PERIOD_MS
94+
#ifndef ipND_TIMER_PERIOD_MS
8895
#ifdef _WINDOWS_
89-
#define ipADDR_RES_TIMER_PERIOD_MS ( 500U ) /* For windows simulator builds. */
96+
#define ipND_TIMER_PERIOD_MS ( 500U ) /* For windows simulator builds. */
9097
#else
91-
#define ipADDR_RES_TIMER_PERIOD_MS ( 10000U )
98+
#define ipND_TIMER_PERIOD_MS ( 10000U )
9299
#endif
93100
#endif
94101

102+
#if ( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) )
103+
/** @brief When initialising the TCP timer, give it an initial time-out of 1 second. */
104+
#define ipTCP_TIMER_PERIOD_MS ( 1000U )
105+
#endif
106+
107+
#ifndef iptraceIP_TASK_STARTING
108+
#define iptraceIP_TASK_STARTING() do {} while( ipFALSE_BOOL ) /**< Empty definition in case iptraceIP_TASK_STARTING is not defined. */
109+
#endif
110+
95111
/** @brief The frame type field in the Ethernet header must have a value greater than 0x0600.
96112
* If the configuration option ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is enabled, the stack
97113
* will discard packets with a frame type value less than or equal to 0x0600.
@@ -106,8 +122,15 @@ static void prvIPTask_CheckPendingEvents( void );
106122

107123
/*-----------------------------------------------------------*/
108124

109-
/** @brief The pointer to buffer with packet waiting for resolution. */
110-
NetworkBufferDescriptor_t * pxResolutionWaitingNetworkBuffer = NULL;
125+
/** @brief The pointer to buffer with packet waiting for ARP resolution. */
126+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
127+
NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL;
128+
#endif
129+
130+
/** @brief The pointer to buffer with packet waiting for ND resolution. */
131+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
132+
NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer = NULL;
133+
#endif
111134

112135
/*-----------------------------------------------------------*/
113136

@@ -293,16 +316,18 @@ static void prvProcessIPEventsAndTimers( void )
293316
prvForwardTxPacket( ( ( NetworkBufferDescriptor_t * ) xReceivedEvent.pvData ), pdTRUE );
294317
break;
295318

296-
case eResolutionTimerEvent:
297-
/* The Resolution timer has expired, process the cache. */
298-
#if ( ipconfigUSE_IPv4 != 0 )
319+
case eARPTimerEvent:
320+
/* The ARP Resolution timer has expired, process the cache. */
321+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
299322
vARPAgeCache();
300323
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
324+
break;
301325

302-
#if ( ipconfigUSE_IPv6 != 0 )
326+
case eNDTimerEvent:
327+
/* The ND Resolution timer has expired, process the cache. */
328+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
303329
vNDAgeCache();
304330
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
305-
306331
break;
307332

308333
case eSocketBindEvent:
@@ -493,8 +518,15 @@ static void prvIPTask_Initialise( void )
493518
}
494519
#endif
495520

496-
/* Mark the timer as inactive since we are not waiting on any resolution as of now. */
497-
vIPSetResolutionTimerEnableState( pdFALSE );
521+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
522+
/* Mark the ARP timer as inactive since we are not waiting on any resolution as of now. */
523+
vIPSetARPResolutionTimerEnableState( pdFALSE );
524+
#endif
525+
526+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
527+
/* Mark the ND timer as inactive since we are not waiting on any resolution as of now. */
528+
vIPSetNDResolutionTimerEnableState( pdFALSE );
529+
#endif
498530

499531
#if ( ( ipconfigDNS_USE_CALLBACKS != 0 ) && ( ipconfigUSE_DNS != 0 ) )
500532
{
@@ -648,7 +680,13 @@ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint )
648680
#endif /* ipconfigDNS_USE_CALLBACKS != 0 */
649681

650682
/* Set remaining time to 0 so it will become active immediately. */
651-
vResolutionTimerReload( pdMS_TO_TICKS( ipADDR_RES_TIMER_PERIOD_MS ) );
683+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
684+
vARPTimerReload( pdMS_TO_TICKS( ipARP_TIMER_PERIOD_MS ) );
685+
#endif
686+
687+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
688+
vNDTimerReload( pdMS_TO_TICKS( ipND_TIMER_PERIOD_MS ) );
689+
#endif
652690
}
653691
/*-----------------------------------------------------------*/
654692

@@ -1733,20 +1771,47 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
17331771

17341772
case eWaitingResolution:
17351773

1736-
if( pxResolutionWaitingNetworkBuffer == NULL )
1737-
{
1738-
pxResolutionWaitingNetworkBuffer = pxNetworkBuffer;
1739-
vIPTimerStartResolution( ipADDR_RES_MAX_DELAY );
1774+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
1775+
if( pxEthernetHeader->usFrameType == ipIPv4_FRAME_TYPE )
1776+
{
1777+
if( pxARPWaitingNetworkBuffer == NULL )
1778+
{
1779+
pxARPWaitingNetworkBuffer = pxNetworkBuffer;
1780+
vIPTimerStartARPResolution( ipARP_RESOLUTION_MAX_DELAY );
17401781

1741-
iptraceDELAYED_RESOLUTION_REQUEST_STARTED();
1742-
}
1743-
else
1744-
{
1745-
/* We are already waiting on one resolution. This frame will be dropped. */
1746-
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
1782+
iptraceDELAYED_ARP_REQUEST_STARTED();
1783+
}
1784+
else
1785+
{
1786+
/* We are already waiting on one resolution. This frame will be dropped. */
1787+
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
17471788

1748-
iptraceDELAYED_RESOLUTION_BUFFER_FULL();
1749-
}
1789+
iptraceDELAYED_ARP_BUFFER_FULL();
1790+
}
1791+
break;
1792+
}
1793+
#endif
1794+
1795+
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
1796+
if( pxEthernetHeader->usFrameType == ipIPv6_FRAME_TYPE )
1797+
{
1798+
if( pxNDWaitingNetworkBuffer == NULL )
1799+
{
1800+
pxNDWaitingNetworkBuffer = pxNetworkBuffer;
1801+
vIPTimerStartNDResolution( ipND_RESOLUTION_MAX_DELAY );
1802+
1803+
iptraceDELAYED_ND_REQUEST_STARTED();
1804+
}
1805+
else
1806+
{
1807+
/* We are already waiting on one resolution. This frame will be dropped. */
1808+
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
1809+
1810+
iptraceDELAYED_ND_BUFFER_FULL();
1811+
}
1812+
break;
1813+
}
1814+
#endif
17501815

17511816
break;
17521817

0 commit comments

Comments
 (0)