Skip to content

Commit

Permalink
Add ND Timer event implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Aug 1, 2024
1 parent c43498d commit e5827d5
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 97 deletions.
18 changes: 10 additions & 8 deletions source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void prvIPTask_CheckPendingEvents( void );
/*-----------------------------------------------------------*/

/** @brief The pointer to buffer with packet waiting for resolution. */
NetworkBufferDescriptor_t * pxResolutionWaitingNetworkBuffer = NULL;
NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL;

/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -293,16 +293,18 @@ static void prvProcessIPEventsAndTimers( void )
prvForwardTxPacket( ( ( NetworkBufferDescriptor_t * ) xReceivedEvent.pvData ), pdTRUE );
break;

case eResolutionTimerEvent:
/* The Resolution timer has expired, process the cache. */
#if ( ipconfigUSE_IPv4 != 0 )
case eARPTimerEvent:
/* The ARP Resolution timer has expired, process the cache. */
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
vARPAgeCache();
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
break;

#if ( ipconfigUSE_IPv6 != 0 )
case eNDTimerEvent:
/* The ND Resolution timer has expired, process the cache. */
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
vNDAgeCache();
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

break;

case eSocketBindEvent:
Expand Down Expand Up @@ -1733,9 +1735,9 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor

case eWaitingResolution:

if( pxResolutionWaitingNetworkBuffer == NULL )
if( pxARPWaitingNetworkBuffer == NULL )
{
pxResolutionWaitingNetworkBuffer = pxNetworkBuffer;
pxARPWaitingNetworkBuffer = pxNetworkBuffer;
vIPTimerStartResolution( ipADDR_RES_MAX_DELAY );

iptraceDELAYED_RESOLUTION_REQUEST_STARTED();
Expand Down
218 changes: 168 additions & 50 deletions source/FreeRTOS_IP_Timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,22 @@ static void prvIPTimerReload( IPTimer_t * pxTimer,
* regular basis
*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
/** @brief Timer to limit the maximum time a packet should be stored while
* awaiting an ARP resolution. */
static IPTimer_t xARPResolutionTimer;
static IPTimer_t xARPResolutionTimer;

/** @brief ARP timer, to check its table entries. */
static IPTimer_t xARPTimer;

static IPTimer_t xARPTimer;
#endif
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
/** @brief Timer to limit the maximum time a packet should be stored while
* awaiting an ND resolution. */
static IPTimer_t xNDResolutionTimer;
static IPTimer_t xNDResolutionTimer;

/** @brief ND timer, to check its table entries. */
static IPTimer_t xNDTimer;

static IPTimer_t xNDTimer;
#endif
#if ( ipconfigUSE_TCP != 0 )
/** @brief TCP timer, to check for timeouts, resends. */
static IPTimer_t xTCPTimer;
Expand Down Expand Up @@ -142,13 +144,25 @@ TickType_t xCalculateSleepTime( void )
* time in any other timers that are active. */
uxMaximumSleepTime = ipconfigMAX_IP_TASK_SLEEP_TIME;

if( xARPTimer.bActive != pdFALSE_UNSIGNED )
{
if( xARPTimer.ulRemainingTime < uxMaximumSleepTime )
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
if( xARPTimer.bActive != pdFALSE_UNSIGNED )
{
uxMaximumSleepTime = xARPTimer.ulRemainingTime;
if( xARPTimer.ulRemainingTime < uxMaximumSleepTime )
{
uxMaximumSleepTime = xARPTimer.ulRemainingTime;
}
}
}
#endif

#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
if( xNDTimer.bActive != pdFALSE_UNSIGNED )
{
if( xNDTimer.ulRemainingTime < uxMaximumSleepTime )
{
uxMaximumSleepTime = xNDTimer.ulRemainingTime;
}
}
#endif

#if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 )
{
Expand Down Expand Up @@ -198,7 +212,7 @@ TickType_t xCalculateSleepTime( void )
/*-----------------------------------------------------------*/

/**
* @brief Check the network timers (ARP/DHCP/DNS/TCP) and if they are
* @brief Check the network timers (ARP/ND/DHCP/DNS/TCP) and if they are
* expired, send an event to the IP-Task.
*/
/* MISRA Ref 8.9.1 [File scoped variables] */
Expand All @@ -209,30 +223,59 @@ void vCheckNetworkTimers( void )
{
NetworkInterface_t * pxInterface;

/* Is it time for ARP processing? */
if( prvIPTimerCheck( &xARPTimer ) != pdFALSE )
{
( void ) xSendEventToIPTask( eARPTimerEvent );
}
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
/* Is it time for ARP processing? */
if( prvIPTimerCheck( &xARPTimer ) != pdFALSE )
{
( void ) xSendEventToIPTask( eARPTimerEvent );
}

/* Is the ARP resolution timer expired? */
if( prvIPTimerCheck( &xARPResolutionTimer ) != pdFALSE )
{
if( pxARPWaitingNetworkBuffer != NULL )
/* Is the ARP resolution timer expired? */
if( prvIPTimerCheck( &xARPResolutionTimer ) != pdFALSE )
{
/* Disable the ARP resolution timer. */
vIPSetARPResolutionTimerEnableState( pdFALSE );
if( pxARPWaitingNetworkBuffer != NULL )
{
/* Disable the ARP resolution timer. */
vIPSetARPResolutionTimerEnableState( pdFALSE );

/* We have waited long enough for the ARP response. Now, free the network
* buffer. */
vReleaseNetworkBufferAndDescriptor( pxARPWaitingNetworkBuffer );
/* We have waited long enough for the ARP response. Now, free the network
* buffer. */
vReleaseNetworkBufferAndDescriptor( pxARPWaitingNetworkBuffer );

/* Clear the pointer. */
pxARPWaitingNetworkBuffer = NULL;
/* Clear the pointer. */
pxARPWaitingNetworkBuffer = NULL;

iptraceDELAYED_ARP_TIMER_EXPIRED();
iptraceDELAYED_ARP_TIMER_EXPIRED();
}
}
#endif

#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
/* Is it time for ND processing? */
if( prvIPTimerCheck( &xNDTimer ) != pdFALSE )
{
( void ) xSendEventToIPTask( eNDTimerEvent );
}
}

/* Is the ND resolution timer expired? */
if( prvIPTimerCheck( &xNDResolutionTimer ) != pdFALSE )
{
if( pxNDWaitingNetworkBuffer != NULL )
{
/* Disable the ND resolution timer. */
vIPSetNDResolutionTimerEnableState( pdFALSE );

/* We have waited long enough for the ND response. Now, free the network
* buffer. */
vReleaseNetworkBufferAndDescriptor( pxNDWaitingNetworkBuffer );

/* Clear the pointer. */
pxNDWaitingNetworkBuffer = NULL;

iptraceDELAYED_ND_TIMER_EXPIRED();
}
}
#endif

#if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 )
{
Expand Down Expand Up @@ -365,15 +408,32 @@ static void prvIPTimerStart( IPTimer_t * pxTimer,
}
/*-----------------------------------------------------------*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )

/**
* @brief Start an ARP Resolution timer.
*
* @param[in] xTime Time to be loaded into the ARP Resolution timer.
*/
void vIPTimerStartARPResolution( TickType_t xTime )
{
prvIPTimerStart( &( xARPResolutionTimer ), xTime );
}
void vIPTimerStartARPResolution( TickType_t xTime )
{
prvIPTimerStart( &( xARPResolutionTimer ), xTime );
}
#endif
/*-----------------------------------------------------------*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )

/**
* @brief Start an ND Resolution timer.
*
* @param[in] xTime Time to be loaded into the ND Resolution timer.
*/
void vIPTimerStartNDResolution( TickType_t xTime )
{
prvIPTimerStart( &( xNDResolutionTimer ), xTime );
}
#endif
/*-----------------------------------------------------------*/

/**
Expand Down Expand Up @@ -404,6 +464,8 @@ static void prvIPTimerReload( IPTimer_t * pxTimer,
#endif
/*-----------------------------------------------------------*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )

/**
* @brief Sets the reload time of the ARP timer and restarts it.
*
Expand All @@ -413,7 +475,21 @@ void vARPTimerReload( TickType_t xTime )
{
prvIPTimerReload( &xARPTimer, xTime );
}
#endif
/*-----------------------------------------------------------*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )

/**
* @brief Sets the reload time of the ND timer and restarts it.
*
* @param[in] xTime Time to be reloaded into the ND timer.
*/
void vNDTimerReload( TickType_t xTime )
{
prvIPTimerReload( &xNDTimer, xTime );
}
#endif
/*-----------------------------------------------------------*/

#if ( ipconfigDNS_USE_CALLBACKS != 0 )
Expand Down Expand Up @@ -525,40 +601,82 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer )
#endif /* if ( ipconfigUSE_TCP == 1 ) */
/*-----------------------------------------------------------*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )

/**
* @brief Enable/disable the ARP timer.
*
* @param[in] xEnableState pdTRUE - enable timer; pdFALSE - disable timer.
*/
void vIPSetARPTimerEnableState( BaseType_t xEnableState )
{
if( xEnableState != pdFALSE )
void vIPSetARPTimerEnableState( BaseType_t xEnableState )
{
xARPTimer.bActive = pdTRUE_UNSIGNED;
if( xEnableState != pdFALSE )
{
xARPTimer.bActive = pdTRUE_UNSIGNED;
}
else
{
xARPTimer.bActive = pdFALSE_UNSIGNED;
}
}
else
/*-----------------------------------------------------------*/

/**
* @brief Enable or disable the ARP resolution timer.
*
* @param[in] xEnableState pdTRUE if the timer must be enabled, pdFALSE otherwise.
*/
void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState )
{
xARPTimer.bActive = pdFALSE_UNSIGNED;
if( xEnableState != pdFALSE )
{
xARPResolutionTimer.bActive = pdTRUE_UNSIGNED;
}
else
{
xARPResolutionTimer.bActive = pdFALSE_UNSIGNED;
}
}
}
#endif
/*-----------------------------------------------------------*/

#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )

/**
* @brief Enable or disable the ARP resolution timer.
* @brief Enable/disable the ND timer.
*
* @param[in] xEnableState pdTRUE if the timer must be enabled, pdFALSE otherwise.
* @param[in] xEnableState pdTRUE - enable timer; pdFALSE - disable timer.
*/
void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState )
{
if( xEnableState != pdFALSE )
void vIPSetNDTimerEnableState( BaseType_t xEnableState )
{
xARPResolutionTimer.bActive = pdTRUE_UNSIGNED;
if( xEnableState != pdFALSE )
{
xNDTimer.bActive = pdTRUE_UNSIGNED;
}
else
{
xNDTimer.bActive = pdFALSE_UNSIGNED;
}
}
else
/*-----------------------------------------------------------*/

/**
* @brief Enable or disable the ND resolution timer.
*
* @param[in] xEnableState pdTRUE if the timer must be enabled, pdFALSE otherwise.
*/
void vIPSetNDResolutionTimerEnableState( BaseType_t xEnableState )
{
xARPResolutionTimer.bActive = pdFALSE_UNSIGNED;
if( xEnableState != pdFALSE )
{
xNDResolutionTimer.bActive = pdTRUE_UNSIGNED;
}
else
{
xNDResolutionTimer.bActive = pdFALSE_UNSIGNED;
}
}
}
#endif
/*-----------------------------------------------------------*/

#if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) || ( ipconfigUSE_DHCPv6 == 1 )
Expand Down
16 changes: 16 additions & 0 deletions source/FreeRTOS_ND.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,5 +1395,21 @@

return xNeedsNDResolution;
}

/*-----------------------------------------------------------*/

/**
* @brief Send an unsolicited ND packet to allow this node to announce the IP-MAC
* mapping to the entire network.
*/
void vNDSendUnsolicited( void )
{
/* Setting xLastUnsolicitedNDTime to 0 will force an unsolicited ND the next
* time vNDAgeCache() is called. */
xLastUnsolicitedNDTime = ( TickType_t ) 0;

/* Let the IP-task call vARPAgeCache(). */
( void ) xSendEventToIPTask( eNDTimerEvent );
}
/*-----------------------------------------------------------*/
#endif /* ipconfigUSE_IPv6 */
9 changes: 5 additions & 4 deletions source/include/FreeRTOS_IP.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,11 @@ BaseType_t xIsNetworkDownEventPending( void );
* be defined in a user module. */
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber );

/** @brief The pointer to buffer with packet waiting for resolution. This variable
* is defined in FreeRTOS_IP.c.
* This pointer is for internal use only. */
extern NetworkBufferDescriptor_t * pxResolutionWaitingNetworkBuffer;
/** @brief The pointers to buffers with packet waiting for resolution. These variables
* are defined in FreeRTOS_IP.c.
* These pointers are for internal use only. */
extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer;
extern NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer;

#if ( ipconfigENABLE_BACKWARD_COMPATIBILITY == 1 )
#define xIPStackEvent_t IPStackEvent_t
Expand Down
Loading

0 comments on commit e5827d5

Please sign in to comment.