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
*
*/
@ -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
/*-----------------------------------------------------------*/