Skip to content

Commit

Permalink
Changes in FreeRTOS+TCP demo application files to add compatibility f…
Browse files Browse the repository at this point in the history
…or running EndPoint changes in the IPv4 stack. (FreeRTOS#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>
  • Loading branch information
kar-rahul-aws and aggarg committed Feb 22, 2023
1 parent cf603c6 commit 38d5e42
Show file tree
Hide file tree
Showing 13 changed files with 662 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*
*/

Expand Down Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*
*/

Expand Down Expand Up @@ -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++ )
{
Expand Down Expand Up @@ -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++ )
{
Expand Down Expand Up @@ -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++;
Expand Down
48 changes: 41 additions & 7 deletions FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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 ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* FreeRTOSConfig.h.
*
*/
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 1

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

Expand Down Expand Up @@ -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 )
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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 ) );

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*
*/

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 38d5e42

Please sign in to comment.