Changes in FreeRTOS+TCP demo application files to add compatibility for running EndPoint changes in the IPv4 stack. (#907)

* Update main.c

* Update main.c

* Update main.c

* Update main.c

* TCP/IP Demo Changes for Sock Addr Changes

* Update SimpleClientAndServer.c

* Update TwoEchoClients.c

* Update SimpleUDPClientAndServer.c

* Update main.c

* Update main_networking.c

* Update TwoEchoClients.c

* Update SimpleClientAndServer.c

* Update TwoEchoClients.c

* Update SimpleUDPClientAndServer.c

* Update main_networking.c

* Update main_networking.c

* Update main_networking.c

* Update main.c

* Update main_networking.c

* Update main_networking.c

* Update main.c

* Update main.c

* Update main.c

* Update main_networking.c

* Update main_networking.c

* Update plus_tcp_hooks_winsim.c

* Update plus_tcp_hooks_winsim.c

* Update main.c

* Update main.c

* Update main_networking.c

* Update main_networking.c

* Update plus_tcp_hooks_winsim.c

* Update lexicon.txt

* Update lexicon.txt

* Update lexicon.txt

* Fix core header check

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* Update main_networking.c

* Update CLI-commands.c

* Update plus_tcp_hooks_winsim.c

* Code review suggestions

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* Remove incorrect spelling from lexicon

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* Fix Build issues in QEMU and UDP demo

* Lexicon spell check issue fix

* WinPcap Network Interface update

* Update Network_winPCap.c

* Adding declaration for pxMyInterface for EndPoint changed function in WinPCap.c

* Revert changes for WinPCap.c

* Update NetworkInterface_WinPCap.c

* Minor code review suggestions

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
kar-rahul-aws 2023-02-22 12:58:17 +05:30 committed by GitHub
parent cf603c60fa
commit 38d5e421eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 661 additions and 127 deletions

View file

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
* https://github.com/FreeRTOS
*
*/
@ -266,28 +266,44 @@ uint32_t ulAddress;
switch( xIndex )
{
case 0 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
#endif
sprintf( pcWriteBuffer, "\r\nIP address " );
xReturn = pdTRUE;
xIndex++;
break;
case 1 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
#endif
sprintf( pcWriteBuffer, "\r\nNet mask " );
xReturn = pdTRUE;
xIndex++;
break;
case 2 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
#endif
sprintf( pcWriteBuffer, "\r\nGateway address " );
xReturn = pdTRUE;
xIndex++;
break;
case 3 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
#endif
sprintf( pcWriteBuffer, "\r\nDNS server address " );
xReturn = pdTRUE;
xIndex++;

View file

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
* https://github.com/FreeRTOS
*
*/
@ -226,8 +226,8 @@ BaseType_t xSpacePadding;
pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the
length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of
length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of
the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{
@ -264,8 +264,8 @@ BaseType_t xSpacePadding;
pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the
length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of
length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of
the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{
@ -565,28 +565,44 @@ uint32_t ulAddress;
switch( xIndex )
{
case 0 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
#endif
sprintf( pcWriteBuffer, "\r\nIP address " );
xReturn = pdTRUE;
xIndex++;
break;
case 1 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
#endif
sprintf( pcWriteBuffer, "\r\nNet mask " );
xReturn = pdTRUE;
xIndex++;
break;
case 2 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
#endif
sprintf( pcWriteBuffer, "\r\nGateway address " );
xReturn = pdTRUE;
xIndex++;
break;
case 3 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
#endif
sprintf( pcWriteBuffer, "\r\nDNS server address " );
xReturn = pdTRUE;
xIndex++;

View file

@ -118,6 +118,19 @@ const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_
/* Use by the pseudo random number generator. */
static UBaseType_t ulNextRand;
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* In case multiple interfaces are used, define them statically. */
/* There is only 1 physical interface. */
static NetworkInterface_t xInterfaces[ 1 ];
/* It will have several end-points. */
static NetworkEndPoint_t xEndPoints[ 4 ];
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/*-----------------------------------------------------------*/
void main_tcp_echo_client_tasks( void )
@ -140,12 +153,29 @@ void main_tcp_echo_client_tasks( void )
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit( ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress );
/* Initialise the network interface.*/
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) );
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* Initialise the interface descriptor for WinPCap. */
pxFillInterfaceDescriptor( 0, &( xInterfaces[ 0 ] ) );
/* === End-point 0 === */
FreeRTOS_FillEndPoint( &( xInterfaces[ 0 ] ), &( xEndPoints [ 0 ] ), ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#if ( ipconfigUSE_DHCP != 0 )
{
/* End-point 0 wants to use DHCPv4. */
xEndPoints[ 0 ].bits.bWantDHCP = pdTRUE;
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );
FreeRTOS_IPStart();
#else
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
@ -195,7 +225,11 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
/* Print out the network configuration, which may have come from a DHCP
* server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
#endif
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );

View file

@ -64,6 +64,7 @@
* FreeRTOSConfig.h.
*
*/
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 1
/*-----------------------------------------------------------*/
@ -123,6 +124,18 @@ const uint8_t ucMACAddress[ 6 ] =
/* Use by the pseudo random number generator. */
static UBaseType_t ulNextRand;
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* In case multiple interfaces are used, define them statically. */
/* There is only 1 physical interface. */
static NetworkInterface_t xInterfaces[ 1 ];
/* It will have several end-points. */
static NetworkEndPoint_t xEndPoints[ 4 ];
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/*-----------------------------------------------------------*/
void main_tcp_echo_client_tasks( void )
@ -145,12 +158,31 @@ void main_tcp_echo_client_tasks( void )
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit( ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress );
/* Initialise the network interface.*/
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) );
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* Initialise the interface descriptor for WinPCap. */
pxMPS2_FillInterfaceDescriptor( 0, &( xInterfaces[ 0 ] ) );
/* === End-point 0 === */
FreeRTOS_FillEndPoint( &( xInterfaces[ 0 ] ), &( xEndPoints[ 0 ] ), ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#if ( ipconfigUSE_DHCP != 0 )
{
/* End-point 0 wants to use DHCPv4. */
xEndPoints[ 0 ].bits.bWantDHCP = pdTRUE;
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );
FreeRTOS_IPStart();
#else
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
@ -205,7 +237,11 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
/* Print out the network configuration, which may have come from a DHCP
* server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
#endif
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );

View file

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -20,7 +20,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
* https://github.com/FreeRTOS
*
*/
@ -104,8 +104,11 @@ const TickType_t x150ms = 150UL / portTICK_PERIOD_MS;
so the IP address can be obtained immediately. store the IP address being
used in ulIPAddress. This is done so the socket can send to a different
port on the same IP address. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
#endif
/* This test sends to itself, so data sent from here is received by a server
socket on the same IP address. Setup the freertos_sockaddr structure with
this nodes IP address, and the port number being sent to. The strange
@ -214,8 +217,11 @@ const size_t xStringLength = strlen( pcStringToSend ) + 15;
so the IP address can be obtained immediately. store the IP address being
used in ulIPAddress. This is done so the socket can send to a different
port on the same IP address. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
#endif
/* This test sends to itself, so data sent from here is received by a server
socket on the same IP address. Setup the freertos_sockaddr structure with
this nodes IP address, and the port number being sent to. The strange
@ -247,7 +253,11 @@ const size_t xStringLength = strlen( pcStringToSend ) + 15;
the do while loop is used to ensure a buffer is obtained. */
do
{
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
} while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY, ipTYPE_IPv4 ) ) == NULL );
#else
} while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY ) ) == NULL );
#endif
/* A buffer was successfully obtained. Create the string that is
sent to the server. First the string is filled with zeros as this will
@ -317,7 +327,11 @@ Socket_t xListeningSocket;
the address being bound to. The strange casting is to try and remove
compiler warnings on 32 bit machines. Note that this task is only created
after the network is up, so the IP address is valid here. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
#endif
xBindAddress.sin_addr = ulIPAddress;
xBindAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );

View file

@ -128,6 +128,18 @@ const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_
/* Use by the pseudo random number generator. */
static UBaseType_t ulNextRand;
/*-----------------------------------------------------------*/
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* In case multiple interfaces are used, define them statically. */
/* With WinPCap there is only 1 physical interface. */
static NetworkInterface_t xInterfaces[ 1 ];
/* It will have several end-points. */
static NetworkEndPoint_t xEndPoints[ 4 ];
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/*-----------------------------------------------------------*/
@ -151,8 +163,30 @@ int main( void )
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
/* Initialise the network interface.*/
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) );
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* Initialise the interface descriptor for WinPCap. */
pxWinPcap_FillInterfaceDescriptor( 0, &( xInterfaces[ 0 ] ) );
/* === End-point 0 === */
FreeRTOS_FillEndPoint( &( xInterfaces[ 0 ] ), &( xEndPoints[ 0 ] ), ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#if ( ipconfigUSE_DHCP != 0 )
{
/* End-point 0 wants to use DHCPv4. */
xEndPoints[ 0 ].bits.bWantDHCP = pdTRUE;
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );
FreeRTOS_IPStart();
#else
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\r\n" ) );
@ -225,7 +259,15 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
/* Print out the network configuration, which may have come from a DHCP
* server. */
/* Using FREERTOS_PLUS_TCP_VERSION as the substitute of the
* downward compatibility*/
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
#endif
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
@ -323,6 +365,7 @@ static void prvMiscInitialisation( void )
}
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
/*-----------------------------------------------------------*/
/*
* Callback that provides the inputs necessary to generate a randomized TCP
@ -342,6 +385,7 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
return uxRand();
}
/*-----------------------------------------------------------*/
/*
* Supply a random number to FreeRTOS+TCP stack.
@ -353,3 +397,16 @@ BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
*( pulNumber ) = uxRand();
return pdTRUE;
}
/*-----------------------------------------------------------*/
#if ( ( ipconfigUSE_TCP == 1 ) && ( ipconfigUSE_DHCP_HOOK != 0 ) )
eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
uint32_t ulIPAddress )
{
/* Provide a stub for this function. */
return eDHCPContinue;
}
#endif
/*-----------------------------------------------------------*/

View file

@ -532,28 +532,44 @@ uint32_t ulAddress;
switch( xIndex )
{
case 0 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
#endif
sprintf( ( char * ) pcWriteBuffer, "\r\nIP address " );
xReturn = pdTRUE;
xIndex++;
break;
case 1 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
#endif
sprintf( ( char * ) pcWriteBuffer, "\r\nNet mask " );
xReturn = pdTRUE;
xIndex++;
break;
case 2 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
#endif
sprintf( ( char * ) pcWriteBuffer, "\r\nGateway address " );
xReturn = pdTRUE;
xIndex++;
break;
case 3 :
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
#endif
sprintf( ( char * ) pcWriteBuffer, "\r\nDNS server address " );
xReturn = pdTRUE;
xIndex++;

View file

@ -94,7 +94,11 @@ const portTickType x150ms = 150UL / portTICK_RATE_MS;
so the IP address can be obtained immediately. store the IP address being
used in ulIPAddress. This is done so the socket can send to a different
port on the same IP address. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
#endif
/* This test sends to itself, so data sent from here is received by a server
socket on the same IP address. Setup the freertos_sockaddr structure with
@ -210,8 +214,11 @@ const size_t xStringLength = strlen( ( char * ) pucStringToSend ) + 15;
so the IP address can be obtained immediately. store the IP address being
used in ulIPAddress. This is done so the socket can send to a different
port on the same IP address. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
#endif
/* This test sends to itself, so data sent from here is received by a server
socket on the same IP address. Setup the freertos_sockaddr structure with
this nodes IP address, and the port number being sent to. The strange
@ -243,7 +250,11 @@ const size_t xStringLength = strlen( ( char * ) pucStringToSend ) + 15;
the do while loop is used to ensure a buffer is obtained. */
do
{
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
} while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY, ipTYPE_IPv4 ) ) == NULL );
#else
} while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY ) ) == NULL );
#endif
/* A buffer was successfully obtained. Create the string that is
sent to the server. First the string is filled with zeros as this will
@ -313,7 +324,11 @@ Socket_t xListeningSocket;
the address being bound to. The strange casting is to try and remove
compiler warnings on 32 bit machines. Note that this task is only created
after the network is up, so the IP address is valid here. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
#endif
xBindAddress.sin_addr = ulIPAddress;
xBindAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );

View file

@ -27,7 +27,7 @@
/******************************************************************************
*
* See the following web page for essential TwoEchoClient.c usage and
* See the following web page for essential TwoEchoClient.c usage and
* configuration details:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml
*
@ -194,7 +194,7 @@ uint32_t xAddressLength = sizeof( xEchoServerAddress );
not actually used (at the time of writing this comment, anyway) by
FreeRTOS_recvfrom(), but is set appropriately in case future
versions do use it. */
memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
lReturned = FreeRTOS_recvfrom( xSocket, /* The socket being received from. */
cRxString, /* The buffer into which the received data will be written. */
@ -295,7 +295,12 @@ const size_t xBufferLength = strlen( ( char * ) pucStringToSend ) + 15;
delay is used, the actual delay will be capped to
ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence the test to ensure a buffer
was actually obtained. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xBufferLength, portMAX_DELAY, ipTYPE_IPv4 );
#else
pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xBufferLength, portMAX_DELAY );
#endif
if( pucUDPPayloadBuffer != NULL )
{

View file

@ -44,24 +44,24 @@
#include "user_settings.h"
/* UDP command server task parameters. */
#define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainUDP_CLI_PORT_NUMBER ( 5001UL )
#define mainUDP_CLI_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
#define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainUDP_CLI_PORT_NUMBER ( 5001UL )
#define mainUDP_CLI_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
/* Simple UDP client and server task parameters. */
#define mainSIMPLE_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_CLIENT_SERVER_PORT ( 5005UL )
#define mainSIMPLE_CLIENT_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
#define mainSIMPLE_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_CLIENT_SERVER_PORT ( 5005UL )
#define mainSIMPLE_CLIENT_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
/* Echo client task parameters. */
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Set the following constants to 1 or 0 to define which tasks to include and
/* Set the following constants to 1 or 0 to define which tasks to include and
exclude. */
#define mainCREATE_UDP_CLI_TASKS 1
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 0
#define mainCREATE_UDP_ECHO_TASKS 1
#define mainCREATE_UDP_CLI_TASKS 1
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 0
#define mainCREATE_UDP_ECHO_TASKS 1
/*-----------------------------------------------------------*/
@ -108,6 +108,18 @@ const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALS
/* Used by the pseudo random number generator. */
static UBaseType_t ulNextRand;
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* In case multiple interfaces are used, define them statically. */
/* There is only 1 physical interface. */
static NetworkInterface_t xInterfaces[ 1 ];
/* It will have several end-points. */
static NetworkEndPoint_t xEndPoints[ 4 ];
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/******************************************************************************
*
* See the following web page for information on using this demo.
@ -120,43 +132,64 @@ int main( void )
{
const uint32_t ulLongTime_ms = 250UL;
/* Create a mutex that is used to guard against the console being accessed
by more than one task simultaniously. */
xConsoleMutex = xSemaphoreCreateMutex();
/* Create a mutex that is used to guard against the console being accessed
* by more than one task simultaneously. */
xConsoleMutex = xSemaphoreCreateMutex();
/* Initialise the network interface. Tasks that use the network are
created in the network event hook when the network is connected and ready
for use. The address values passed in here are used if ipconfigUSE_DHCP is
set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
contacted. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
/* Initialise the network interface. Tasks that use the network are
* created in the network event hook when the network is connected and ready
* for use. The address values passed in here are used if ipconfigUSE_DHCP is
* set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
* contacted. */
/* Initialise the logging. */
uint32_t ulLoggingIPAddress;
/* Initialise the network interface.*/
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) );
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
/* Initialise the interface descriptor for WinPCap. */
pxWinPcap_FillInterfaceDescriptor( 0, &( xInterfaces[ 0 ] ) );
/* === End-point 0 === */
FreeRTOS_FillEndPoint( &( xInterfaces[ 0 ] ), &( xEndPoints[ 0 ] ), ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#if ( ipconfigUSE_DHCP != 0 )
{
/* End-point 0 wants to use DHCPv4. */
xEndPoints[ 0 ].bits.bWantDHCP = pdTRUE;
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );
FreeRTOS_IPStart();
#else
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */
/* Initialise the logging. */
uint32_t ulLoggingIPAddress;
ulLoggingIPAddress = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
configECHO_SERVER_ADDR1,
configECHO_SERVER_ADDR2,
configECHO_SERVER_ADDR3 );
configECHO_SERVER_ADDR1,
configECHO_SERVER_ADDR2,
configECHO_SERVER_ADDR3 );
vLoggingInit( xLogToStdout, xLogToFile, xLogToUDP, ulLoggingIPAddress, configPRINT_PORT );
/* Register commands with the FreeRTOS+CLI command interpreter. */
vRegisterCLICommands();
/* Register commands with the FreeRTOS+CLI command interpreter. */
vRegisterCLICommands();
/* Start the RTOS scheduler. */
vTaskStartScheduler();
/* Start the RTOS scheduler. */
vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then
there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. See the memory management section on the
FreeRTOS web site for more details (this is standard text that is not not
really applicable to the Win32 simulator port). */
for( ;; )
{
Sleep( ulLongTime_ms );
}
/* If all is well, the scheduler will now be running, and the following
* line will never be reached. If the following line does execute, then
* there was insufficient FreeRTOS heap memory available for the idle and/or
* timer tasks to be created. See the memory management section on the
* FreeRTOS web site for more details (this is standard text that is not not
* really applicable to the Win32 simulator port). */
for( ;; )
{
Sleep( ulLongTime_ms );
}
}
/*-----------------------------------------------------------*/
@ -164,10 +197,10 @@ void vApplicationIdleHook( void )
{
const unsigned long ulMSToSleep = 5;
/* This function is called on each cycle of the idle task if
configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
load. */
Sleep( ulMSToSleep );
/* This function is called on each cycle of the idle task if
* configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
* load. */
Sleep( ulMSToSleep );
}
/*-----------------------------------------------------------*/
@ -180,46 +213,46 @@ static const uint8_t *pcInvalidData = ( uint8_t * ) "Ping reply received with in
static uint8_t cMessage[ 50 ];
switch( eStatus )
{
case eSuccess :
FreeRTOS_debug_printf( ( ( char * ) pcSuccess ) );
break;
switch( eStatus )
{
case eSuccess:
FreeRTOS_debug_printf( ( ( char * ) pcSuccess ) );
break;
case eInvalidChecksum :
FreeRTOS_debug_printf( ( ( char * ) pcInvalidChecksum ) );
break;
case eInvalidChecksum:
FreeRTOS_debug_printf( ( ( char * ) pcInvalidChecksum ) );
break;
case eInvalidData :
FreeRTOS_debug_printf( ( ( char * ) pcInvalidData ) );
break;
case eInvalidData:
FreeRTOS_debug_printf( ( ( char * ) pcInvalidData ) );
break;
default :
/* It is not possible to get here as all enums have their own
case. */
break;
}
default :
/* It is not possible to get here as all enums have their own
* case. */
break;
}
sprintf( ( char * ) cMessage, "identifier %d\r\n", ( int ) usIdentifier );
FreeRTOS_debug_printf( ( ( char * ) cMessage ) );
sprintf( ( char * ) cMessage, "identifier %d\r\n", ( int ) usIdentifier );
FreeRTOS_debug_printf( ( ( char * ) cMessage ) );
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook( void )
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
size of the heap available to pvPortMalloc() is defined by
configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
API function can be used to query the size of free heap space that remains
(although it does not provide information on how the remaining heap might
be fragmented). */
taskDISABLE_INTERRUPTS();
for( ;; );
/* vApplicationMallocFailedHook() will only be called if
* configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
* function that will get called if a call to pvPortMalloc() fails.
* pvPortMalloc() is called internally by the kernel whenever a task, queue,
* timer or semaphore is created. It is also called by various parts of the
* demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
* size of the heap available to pvPortMalloc() is defined by
* configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
* API function can be used to query the size of free heap space that remains
* (although it does not provide information on how the remaining heap might
* be fragmented). */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/
@ -263,4 +296,3 @@ void vApplicationMallocFailedHook( void )
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
/*-----------------------------------------------------------*/