Skip to content

Commit

Permalink
fix formatting, guard FreeRTOS_FillEndPoint inside ipconfigUSE_IPv4 c…
Browse files Browse the repository at this point in the history
…heck
  • Loading branch information
tony-josi-aws committed Apr 30, 2023
1 parent beacad2 commit d4f8d75
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 327 deletions.
442 changes: 221 additions & 221 deletions source/FreeRTOS_ARP.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,
* As that bug has been repaired, there is not an urgent reason to warn.
* It is better though to use the advised priority scheme. */

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) && ( ipconfigUSE_IPv4 != 1 )

/* Provide backward-compatibility with the earlier FreeRTOS+TCP which only had
* single network interface. */
Expand All @@ -931,7 +931,7 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,
#endif /* ipconfigUSE_DHCP */
return FreeRTOS_IPInit_Multi();
}
#endif /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */
#endif /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) && ( ipconfigUSE_IPv4 != 1 ) */
/*-----------------------------------------------------------*/

/**
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_IP_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1745,4 +1745,4 @@ BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress )

return xReturn;
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
70 changes: 37 additions & 33 deletions source/FreeRTOS_Routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ struct xIPv6_Couple
};
/*-----------------------------------------------------------*/


#if ( ipconfigUSE_IPv4 != 1 )

/**
* @brief Configure and install a new IPv4 end-point.
*
Expand All @@ -84,47 +87,48 @@ struct xIPv6_Couple
* @param[in] ucDNSServerAddress The IP-address of a DNS server.
* @param[in] ucMACAddress The MAC address of the end-point.
*/
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 ] )
{
uint32_t ulIPAddress;
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 ] )
{
uint32_t ulIPAddress;

/* Fill in and add an end-point to a network interface.
* The user must make sure that the object pointed to by 'pxEndPoint'
* will remain to exist. */
( void ) memset( pxEndPoint, 0, sizeof( *pxEndPoint ) );
/* Fill in and add an end-point to a network interface.
* The user must make sure that the object pointed to by 'pxEndPoint'
* will remain to exist. */
( void ) memset( pxEndPoint, 0, sizeof( *pxEndPoint ) );

ulIPAddress = FreeRTOS_inet_addr_quick( ucIPAddress[ 0 ], ucIPAddress[ 1 ], ucIPAddress[ 2 ], ucIPAddress[ 3 ] );
pxEndPoint->ipv4_settings.ulNetMask = FreeRTOS_inet_addr_quick( ucNetMask[ 0 ], ucNetMask[ 1 ], ucNetMask[ 2 ], ucNetMask[ 3 ] );
pxEndPoint->ipv4_settings.ulGatewayAddress = FreeRTOS_inet_addr_quick( ucGatewayAddress[ 0 ], ucGatewayAddress[ 1 ], ucGatewayAddress[ 2 ], ucGatewayAddress[ 3 ] );
pxEndPoint->ipv4_settings.ulDNSServerAddresses[ 0 ] = FreeRTOS_inet_addr_quick( ucDNSServerAddress[ 0 ], ucDNSServerAddress[ 1 ], ucDNSServerAddress[ 2 ], ucDNSServerAddress[ 3 ] );
pxEndPoint->ipv4_settings.ulBroadcastAddress = ulIPAddress | ~( pxEndPoint->ipv4_settings.ulNetMask );
ulIPAddress = FreeRTOS_inet_addr_quick( ucIPAddress[ 0 ], ucIPAddress[ 1 ], ucIPAddress[ 2 ], ucIPAddress[ 3 ] );
pxEndPoint->ipv4_settings.ulNetMask = FreeRTOS_inet_addr_quick( ucNetMask[ 0 ], ucNetMask[ 1 ], ucNetMask[ 2 ], ucNetMask[ 3 ] );
pxEndPoint->ipv4_settings.ulGatewayAddress = FreeRTOS_inet_addr_quick( ucGatewayAddress[ 0 ], ucGatewayAddress[ 1 ], ucGatewayAddress[ 2 ], ucGatewayAddress[ 3 ] );
pxEndPoint->ipv4_settings.ulDNSServerAddresses[ 0 ] = FreeRTOS_inet_addr_quick( ucDNSServerAddress[ 0 ], ucDNSServerAddress[ 1 ], ucDNSServerAddress[ 2 ], ucDNSServerAddress[ 3 ] );
pxEndPoint->ipv4_settings.ulBroadcastAddress = ulIPAddress | ~( pxEndPoint->ipv4_settings.ulNetMask );

/* Copy the current values to the default values. */
( void ) memcpy( &( pxEndPoint->ipv4_defaults ), &( pxEndPoint->ipv4_settings ), sizeof( pxEndPoint->ipv4_defaults ) );
/* Copy the current values to the default values. */
( void ) memcpy( &( pxEndPoint->ipv4_defaults ), &( pxEndPoint->ipv4_settings ), sizeof( pxEndPoint->ipv4_defaults ) );

/* The default IP-address will be used in case DHCP is not used, or also if DHCP has failed, or
* when the user chooses to use the default IP-address. */
pxEndPoint->ipv4_defaults.ulIPAddress = ulIPAddress;
/* The default IP-address will be used in case DHCP is not used, or also if DHCP has failed, or
* when the user chooses to use the default IP-address. */
pxEndPoint->ipv4_defaults.ulIPAddress = ulIPAddress;

#if ( ipconfigUSE_DHCP != 0 )
if( pxEndPoint->bits.bWantDHCP == 0U )
#endif
{
pxEndPoint->ipv4_settings.ulIPAddress = ulIPAddress;
}
#if ( ipconfigUSE_DHCP != 0 )
if( pxEndPoint->bits.bWantDHCP == 0U )
#endif
{
pxEndPoint->ipv4_settings.ulIPAddress = ulIPAddress;
}

/* The field 'ipv4_settings.ulIPAddress' will be set later on. */
/* The field 'ipv4_settings.ulIPAddress' will be set later on. */

( void ) memcpy( pxEndPoint->xMACAddress.ucBytes, ucMACAddress, sizeof( pxEndPoint->xMACAddress ) );
( void ) FreeRTOS_AddEndPoint( pxNetworkInterface, pxEndPoint );
}
( void ) memcpy( pxEndPoint->xMACAddress.ucBytes, ucMACAddress, sizeof( pxEndPoint->xMACAddress ) );
( void ) FreeRTOS_AddEndPoint( pxNetworkInterface, pxEndPoint );
}
/*-----------------------------------------------------------*/
#endif /* ( ipconfigUSE_IPv4 != 1 ) */

#if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 )

Expand Down
2 changes: 1 addition & 1 deletion source/include/FreeRTOS_IP_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress );
/* Set the MAC-address that belongs to a given IPv4 multi-cast address. */
void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress,
MACAddress_t * pxMACAddress );

/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
Expand Down
2 changes: 1 addition & 1 deletion test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,4 +1917,4 @@ void test_xIsIPv4Multicast_IsMultiCast( void )
xReturn = xIsIPv4Multicast( ulIPAddress );

TEST_ASSERT_EQUAL( pdTRUE, xReturn );
}
}
120 changes: 52 additions & 68 deletions tools/tcp_utilities/plus_tcp_demo_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,30 +534,28 @@ static void handle_arpq( char * pcBuffer )
ulLookUpIP = ulIPAddress;
xLookupAddress = xAddress;

switch(xIPType)
switch( xIPType )
{

#if ( ipconfigUSE_IPv4 != 0 )
case ipTYPE_IPv4:
eResult = eARPGetCacheEntry( &ulLookUpIP, &xMACAddress, &pxEndPoint );
FreeRTOS_printf( ( "ARPGetCacheEntry returns \"%s\" Look for %xip. Found end-point: %s\n",
pcARPReturnType( eResult ), ( unsigned ) FreeRTOS_htonl( ulLookUpIP ), ( pxEndPoint != NULL ) ? "yes" : "no" ) );
pcARPReturnType( eResult ), ( unsigned ) FreeRTOS_htonl( ulLookUpIP ), ( pxEndPoint != NULL ) ? "yes" : "no" ) );
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

#if ( ipconfigUSE_IPv6 != 0 )
case ipTYPE_IPv6:
eResult = eNDGetCacheEntry( &( xLookupAddress.xIP_IPv6 ), &xMACAddress, &pxEndPoint );
FreeRTOS_printf( ( "ARPGetCacheEntry returns \"%s\" Look for %pip. Found end-point: %s\n",
pcARPReturnType( eResult ), xAddress.xIP_IPv6.ucBytes, ( pxEndPoint != NULL ) ? "yes" : "no" ) );
pcARPReturnType( eResult ), xAddress.xIP_IPv6.ucBytes, ( pxEndPoint != NULL ) ? "yes" : "no" ) );
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "handle_arpq: Undefined IP Type \n" ) );
break;

}

if( ( eResult == eARPCacheMiss ) && ( pxEndPoint != NULL ) )
Expand All @@ -571,13 +569,12 @@ static void handle_arpq( char * pcBuffer )

NetworkBufferDescriptor_t * pxBuffer;

switch(xIPType)
switch( xIPType )
{

#if ( ipconfigUSE_IPv4 != 0 )
case ipTYPE_IPv4:
FreeRTOS_printf( ( "handle_arpq: Looking up %xip\n",
( unsigned ) FreeRTOS_ntohl( ulLookUpIP ) ) );
( unsigned ) FreeRTOS_ntohl( ulLookUpIP ) ) );

xARPWaitResolution( ulLookUpIP, 1000U );
break;
Expand All @@ -597,8 +594,8 @@ static void handle_arpq( char * pcBuffer )
pxBuffer->pxEndPoint = pxEndPoint;
pxBuffer->pxInterface = pxBuffer->pxEndPoint->pxNetworkInterface;
FreeRTOS_printf( ( "handle_arpq: Looking up %pip with%s end-point\n",
pxBuffer->xIPAddress.xIP_IPv6.ucBytes,
( pxBuffer->pxEndPoint != NULL ) ? "" : "out" ) );
pxBuffer->xIPAddress.xIP_IPv6.ucBytes,
( pxBuffer->pxEndPoint != NULL ) ? "" : "out" ) );

vNDSendNeighbourSolicitation( pxBuffer, &( pxBuffer->xIPAddress.xIP_IPv6 ) );
}
Expand All @@ -608,21 +605,19 @@ static void handle_arpq( char * pcBuffer )
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "handle_arpq: Undefined IP Type \n" ) );
break;

}

/* Let the IP-task do its work, and wait 500 ms. */
FreeRTOS_printf( ( "... Pause ...\n" ) );
vTaskDelay( pdMS_TO_TICKS( 500U ) );

switch(xIPType)
switch( xIPType )
{

#if ( ipconfigUSE_IPv4 != 0 )
case ipTYPE_IPv4:
eResult = eARPGetCacheEntry( &ulLookUpIP, &xMACAddress, &pxEndPoint );
Expand All @@ -634,12 +629,11 @@ static void handle_arpq( char * pcBuffer )
eResult = eNDGetCacheEntry( &( xLookupAddress.xIP_IPv6 ), &xMACAddress, &pxEndPoint );
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "handle_arpq: Undefined IP Type \n" ) );
break;

}

FreeRTOS_printf( ( "handle_arpq: after lookup: \"%s\"\n",
Expand Down Expand Up @@ -1033,10 +1027,8 @@ static void handle_help( char * pcBuffer )

if( pxDNSResult != NULL )
{

switch(xOptions.xIPVersion)
switch( xOptions.xIPVersion )
{

#if ( ipconfigUSE_IPv4 != 0 )
case 4:
FreeRTOS_printf( ( "ping4 to '%s' (%xip)\n", pcHostname, ( unsigned ) FreeRTOS_ntohl( pxDNSResult->ai_addr->sin_address.ulIP_IPv4 ) ) );
Expand All @@ -1061,14 +1053,12 @@ static void handle_help( char * pcBuffer )
uxPingTimes[ 0 ] = ( TickType_t ) ullGetHighResolutionTime();
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "handle_ping: Undefined IP Type \n" ) );
break;

}

}
else
{
Expand Down Expand Up @@ -1446,9 +1436,8 @@ void xHandleTesting()

pxResult->ai_addr = &( pxResult->xPrivateStorage.sockaddr );

switch(xIPVersion)
switch( xIPVersion )
{

#if ( ipconfigUSE_IPv4 != 0 )
case 4:
#if ( ipconfigUSE_DNS_CACHE != 0 )
Expand All @@ -1475,14 +1464,12 @@ void xHandleTesting()
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "pxDNSLookup: Undefined IP Version Type \n" ) );
break;

}

}
}
#endif /* if ( ipconfigDNS_USE_CALLBACKS != 0 ) && ( ipconfigMULTI_INTERFACE != 0 ) */
Expand Down Expand Up @@ -1511,59 +1498,56 @@ void xHandleTesting()
{
FreeRTOS_printf( ( "vDNSEvent: family = %d\n", ( int ) pxAddrInfo->ai_family ) );

switch(pxAddrInfo->ai_family)
switch( pxAddrInfo->ai_family )
{

#if ( ipconfigUSE_IPv4 != 0 )
case FREERTOS_AF_INET:
{
uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4;

if( ulIPaddress == 0uL )
{
FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) );
}
}
break;
{
uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4;

if( ulIPaddress == 0uL )
{
FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) );
}
}
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

#if ( ipconfigUSE_IPv6 != 0 )
case FREERTOS_AF_INET6:
{
BaseType_t xIsEmpty = pdTRUE, xIndex;

for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ )
{
if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u )
{
xIsEmpty = pdFALSE;
break;
}
}

if( xIsEmpty )
{
FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) );
}
}
break;
{
BaseType_t xIsEmpty = pdTRUE, xIndex;

for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ )
{
if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u )
{
xIsEmpty = pdFALSE;
break;
}
}

if( xIsEmpty )
{
FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) );
}
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "vDNSEvent: Undefined Family Type \n" ) );
break;

}

}

if( xServerWorkTaskHandle != NULL )
Expand Down

0 comments on commit d4f8d75

Please sign in to comment.