diff --git a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UDP-Related-CLI-commands.c b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UDP-Related-CLI-commands.c index 7441b077c8..2f47b2918f 100644 --- a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UDP-Related-CLI-commands.c +++ b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_CLI_Demos/UDP-Related-CLI-commands.c @@ -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++; diff --git a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/CLICommands/CLI-commands.c b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/CLICommands/CLI-commands.c index a013f44f7f..444597cc13 100644 --- a/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/CLICommands/CLI-commands.c +++ b/FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/CLICommands/CLI-commands.c @@ -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++; diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main_networking.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main_networking.c index 6a58fd01e6..4685172e0c 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main_networking.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main_networking.c @@ -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 ) ); diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c index 55a7ff1b38..5a4d1e2b59 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c @@ -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 ) ); diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/DemoTasks/SimpleUDPClientAndServer.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/DemoTasks/SimpleUDPClientAndServer.c index 341f567f67..f7472a15bd 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/DemoTasks/SimpleUDPClientAndServer.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/DemoTasks/SimpleUDPClientAndServer.c @@ -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 ); diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/main.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/main.c index 13bac0756f..4a28257055 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/main.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/main.c @@ -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 +/*-----------------------------------------------------------*/ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/CLI-commands.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/CLI-commands.c index d74e437d19..798f3a53a9 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/CLI-commands.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/CLI-commands.c @@ -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++; diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/SimpleClientAndServer.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/SimpleClientAndServer.c index 322838aef1..229b699c6f 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/SimpleClientAndServer.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/SimpleClientAndServer.c @@ -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 ); diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/TwoEchoClients.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/TwoEchoClients.c index 96284002b2..e51e43dda1 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/TwoEchoClients.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/DemoTasks/TwoEchoClients.c @@ -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 ) { diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/main.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/main.c index 83bad6ade5..bb05f8fef1 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/main.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_UDP_Mode_CLI_Windows_Simulator/main.c @@ -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 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; + /* 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; - - case eInvalidChecksum : - FreeRTOS_debug_printf( ( ( char * ) pcInvalidChecksum ) ); - 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; - } + switch( eStatus ) + { + case eSuccess: + FreeRTOS_debug_printf( ( ( char * ) pcSuccess ) ); + break; + + case eInvalidChecksum: + FreeRTOS_debug_printf( ( ( char * ) pcInvalidChecksum ) ); + 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; + } - 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 ) */ /*-----------------------------------------------------------*/ - diff --git a/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/NetworkInterface_WinPCap.c b/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/NetworkInterface_WinPCap.c index d27976a141..fe4b12f5e2 100644 --- a/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/NetworkInterface_WinPCap.c +++ b/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/NetworkInterface_WinPCap.c @@ -39,6 +39,9 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_IP_Private.h" #include "NetworkBufferManagement.h" +#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) + #include "FreeRTOS_Routing.h" +#endif /* Thread-safe circular buffers are being used to pass data to and from the PCAP * access functions. */ @@ -150,9 +153,31 @@ static StreamBuffer_t * xRecvBuffer = NULL; /* Logs the number of WinPCAP send failures, for viewing in the debugger only. */ static volatile uint32_t ulWinPCAPSendFailures = 0; +#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) +/* + * A pointer to the network interface is needed later when receiving packets. + */ + static NetworkInterface_t * pxMyInterface; + + extern NetworkEndPoint_t * pxGetEndpoint( BaseType_t xIPType ); + + static BaseType_t xWinPcap_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface ); + static BaseType_t xWinPcap_NetworkInterfaceOutput( NetworkInterface_t * pxInterface, + NetworkBufferDescriptor_t * const pxNetworkBuffer, + BaseType_t bReleaseAfterSend ); + static BaseType_t xWinPcap_GetPhyLinkStatus( NetworkInterface_t * pxInterface ); + + NetworkInterface_t * pxWinPcap_FillInterfaceDescriptor( BaseType_t xEMACIndex, + NetworkInterface_t * pxInterface ); +#endif + /*-----------------------------------------------------------*/ -BaseType_t xNetworkInterfaceInitialise( void ) +#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) + static BaseType_t xWinPcap_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface ) +#else + BaseType_t xNetworkInterfaceInitialise( void ) +#endif { BaseType_t xReturn = pdFALSE; pcap_if_t * pxAllNetworkInterfaces; @@ -257,8 +282,14 @@ static size_t prvStreamBufferAdd( StreamBuffer_t * pxBuffer, /*-----------------------------------------------------------*/ -BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, - BaseType_t bReleaseAfterSend ) +#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) + static BaseType_t xWinPcap_NetworkInterfaceOutput( NetworkInterface_t * pxInterface, + NetworkBufferDescriptor_t * const pxNetworkBuffer, + BaseType_t bReleaseAfterSend ) +#else + BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, + BaseType_t bReleaseAfterSend ) +#endif { size_t xSpace; @@ -298,6 +329,51 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB } /*-----------------------------------------------------------*/ +#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) + + static BaseType_t xWinPcap_GetPhyLinkStatus( NetworkInterface_t * pxInterface ) + { + BaseType_t xResult = pdFALSE; + + ( void ) pxInterface; + + if( pxOpenedInterfaceHandle != NULL ) + { + xResult = pdTRUE; + } + + return xResult; + } + + /*-----------------------------------------------------------*/ + + NetworkInterface_t * pxWinPcap_FillInterfaceDescriptor( BaseType_t xEMACIndex, + NetworkInterface_t * pxInterface ) + { + static char pcName[ 17 ]; + + /* This function pxWinPcap_FillInterfaceDescriptor() adds a network-interface. + * Make sure that the object pointed to by 'pxInterface' + * is declared static or global, and that it will continue to exist. */ + + pxMyInterface = pxInterface; + + snprintf( pcName, sizeof( pcName ), "eth%ld", xEMACIndex ); + + memset( pxInterface, '\0', sizeof( *pxInterface ) ); + pxInterface->pcName = pcName; /* Just for logging, debugging. */ + pxInterface->pvArgument = ( void * ) xEMACIndex; /* Has only meaning for the driver functions. */ + pxInterface->pfInitialise = xWinPcap_NetworkInterfaceInitialise; + pxInterface->pfOutput = xWinPcap_NetworkInterfaceOutput; + pxInterface->pfGetPhyLinkStatus = xWinPcap_GetPhyLinkStatus; + + FreeRTOS_AddNetworkInterface( pxInterface ); + + return pxInterface; + } +#endif +/*-----------------------------------------------------------*/ + static pcap_if_t * prvPrintAvailableNetworkInterfaces( void ) { pcap_if_t * pxAllNetworkInterfaces = NULL, * xInterface; @@ -321,7 +397,7 @@ static pcap_if_t * prvPrintAvailableNetworkInterfaces( void ) { /* Print out the list of network interfaces. The first in the list * is interface '1', not interface '0'. */ - for(xInterface = pxAllNetworkInterfaces; xInterface != NULL; xInterface = xInterface->next) + for( xInterface = pxAllNetworkInterfaces; xInterface != NULL; xInterface = xInterface->next ) { /* The descriptions of the devices can be full of spaces, clean them * a little. printf() can only be used here because the network is not @@ -416,7 +492,7 @@ static void prvOpenSelectedNetworkInterface( pcap_if_t * pxAllNetworkInterfaces /* Walk the list of devices until the selected device is located. */ pxInterface = pxAllNetworkInterfaces; - for(x = 0L; x < ( xConfigNetworkInterfaceToUse - 1L ); x++) + for( x = 0L; x < ( xConfigNetworkInterfaceToUse - 1L ); x++ ) { pxInterface = pxInterface->next; } @@ -592,26 +668,69 @@ DWORD WINAPI prvWinPcapSendThread( void * pvParam ) } /*-----------------------------------------------------------*/ -static BaseType_t xPacketBouncedBack( const uint8_t * pucBuffer ) -{ - EthernetHeader_t * pxEtherHeader; - BaseType_t xResult; - - pxEtherHeader = ( EthernetHeader_t * ) pucBuffer; +#if defined ( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) - /* Sometimes, packets are bounced back by the driver and we need not process them. Check - * whether this packet is one such packet. */ - if( memcmp( ipLOCAL_MAC_ADDRESS, pxEtherHeader->xSourceAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) + static BaseType_t xPacketBouncedBack( const uint8_t * pucBuffer ) { - xResult = pdTRUE; + static BaseType_t xHasWarned = pdFALSE; + EthernetHeader_t * pxEtherHeader; + NetworkEndPoint_t * pxEndPoint; + BaseType_t xResult = pdFALSE; + + pxEtherHeader = ( EthernetHeader_t * ) pucBuffer; + + /* Sometimes, packets are bounced back by the driver and we need not process them. Check + * whether this packet is one such packet. */ + for( pxEndPoint = FreeRTOS_FirstEndPoint( NULL ); + pxEndPoint != NULL; + pxEndPoint = FreeRTOS_NextEndPoint( NULL, pxEndPoint ) ) + { + if( memcmp( pxEndPoint->xMACAddress.ucBytes, pxEtherHeader->xSourceAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) + { + if( xHasWarned == pdFALSE ) + { + xHasWarned = pdTRUE; + FreeRTOS_printf( ( "Bounced back by WinPCAP interface: %02x:%02x:%02x:%02x:%02x:%02x\n", + pxEndPoint->xMACAddress.ucBytes[ 0 ], + pxEndPoint->xMACAddress.ucBytes[ 1 ], + pxEndPoint->xMACAddress.ucBytes[ 2 ], + pxEndPoint->xMACAddress.ucBytes[ 3 ], + pxEndPoint->xMACAddress.ucBytes[ 4 ], + pxEndPoint->xMACAddress.ucBytes[ 5 ] ) ); + } + + xResult = pdTRUE; + break; + } + } + + return xResult; } - else + +#else + + static BaseType_t xPacketBouncedBack( const uint8_t * pucBuffer ) { - xResult = pdFALSE; + EthernetHeader_t * pxEtherHeader; + BaseType_t xResult = pdFALSE; + + pxEtherHeader = ( EthernetHeader_t * ) pucBuffer; + + /* Sometimes, packets are bounced back by the driver and we need not process them. Check + * whether this packet is one such packet. */ + if( memcmp( ipLOCAL_MAC_ADDRESS, pxEtherHeader->xSourceAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) + { + xResult = pdTRUE; + } + else + { + xResult = pdFALSE; + } + + return xResult; } - return xResult; -} +#endif /*-----------------------------------------------------------*/ static void prvInterruptSimulatorTask( void * pvParameters ) @@ -684,6 +803,117 @@ static void prvInterruptSimulatorTask( void * pvParameters ) if( pxNetworkBuffer != NULL ) { xRxEvent.pvData = ( void * ) pxNetworkBuffer; + #if defined ( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) + pxNetworkBuffer->pxInterface = pxMyInterface; + pxNetworkBuffer->pxEndPoint = FreeRTOS_MatchingEndpoint( pxMyInterface, pxNetworkBuffer->pucEthernetBuffer ); + + { + char pcDescription[ 129 ] = "unknown"; + const EthernetHeader_t * pxEthernetHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + uint8_t ucType = ipTYPE_IPv4; + + switch( pxEthernetHeader->usFrameType ) + { + case ipARP_FRAME_TYPE: + { + const ProtocolPacket_t * pxPacket = ( ( const ProtocolPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + snprintf( pcDescription, sizeof pcDescription, "ARP frame for %xip", + FreeRTOS_ntohl( pxPacket->xARPPacket.xARPHeader.ulTargetProtocolAddress ) ); + } + break; + + case ipPROTOCOL_ICMP: + snprintf( pcDescription, sizeof pcDescription, "ICMP frame" ); + break; + + case ipIPv4_FRAME_TYPE: + { + const IPPacket_t * pxIPPacket; + uint8_t ucProtocol; + pxIPPacket = ( const IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; + ucProtocol = pxIPPacket->xIPHeader.ucProtocol; + + if( ucProtocol == ( uint8_t ) ipPROTOCOL_TCP ) + { + const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); + uint32_t ulLocalIP, ulRemoteIP; + uint16_t usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort ); + uint16_t usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); + const IPHeader_t * pxIPHeader; + pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); + ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); + ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); + + snprintf( pcDescription, sizeof pcDescription, "TCP v4 packet %xip port%u to %xip: port %u", + ulRemoteIP, usRemotePort, ulLocalIP, usLocalPort ); + } + else if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP ) + { + snprintf( pcDescription, sizeof pcDescription, "UDP v4 packet" ); + const UDPPacket_t * pxUDPPacket = ( ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + + if( pxUDPPacket->xIPHeader.ulSourceIPAddress == 0x642c6276U ) + { + FreeRTOS_printf( ( "Received UDP packet from %xip\n", + ( unsigned ) ( FreeRTOS_htonl( pxUDPPacket->xIPHeader.ulSourceIPAddress ) ) ) ); + } + } + else + { + snprintf( pcDescription, sizeof pcDescription, "v4 packet protocol %02X", ucProtocol ); + } + } + break; + + case ipIPv6_FRAME_TYPE: + { + const IPHeader_IPv6_t * pxIPHeader_IPv6; + uint8_t ucProtocol; + + ucType = ipTYPE_IPv6; + pxIPHeader_IPv6 = ( const IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ); + + ucProtocol = pxIPHeader_IPv6->ucNextHeader; + + if( ucProtocol == ( uint8_t ) ipPROTOCOL_TCP ) + { + snprintf( pcDescription, sizeof pcDescription, "TCP v6 packet" ); + } + else if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP ) + { + snprintf( pcDescription, sizeof pcDescription, "UDP v6 packet" ); + } + else if( ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP_IPv6 ) + { + snprintf( pcDescription, sizeof pcDescription, "ICMP v6 packet" ); + } + else + { + snprintf( pcDescription, sizeof pcDescription, "v6 packet protocol %02X", ucProtocol ); + } + } + break; + + default: + snprintf( pcDescription, sizeof pcDescription, "Unknown frame %04x", pxEthernetHeader->usFrameType ); + break; + } + + if( pxNetworkBuffer->pxEndPoint == NULL ) + { + pxNetworkBuffer->pxEndPoint = pxGetEndpoint( ucType ); + + if( strncasecmp( "ARP", pcDescription, 3 ) != 0 ) + { + FreeRTOS_printf( ( "No end-point for \"%s\". Using 0x%p type IPv%d\n", + pcDescription, + pxNetworkBuffer->pxEndPoint, + ucType == ipTYPE_IPv6 ? 6 : 4 ) ); + } + } + } + #endif /* Data was received and stored. Send a message to * the IP task to let it know. */ @@ -757,6 +987,7 @@ static const char * prvRemoveSpaces( char * pcBuffer, return pcBuffer; } +/*-----------------------------------------------------------*/ #define BUFFER_SIZE ( ipTOTAL_ETHERNET_FRAME_SIZE + ipBUFFER_PADDING ) #define BUFFER_SIZE_ROUNDED_UP ( ( BUFFER_SIZE + 7 ) & ~0x07UL ) @@ -778,7 +1009,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB } else { - for(uxIndex = 0; uxIndex < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; uxIndex++) + for( uxIndex = 0; uxIndex < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; uxIndex++ ) { size_t uxOffset = uxIndex * BUFFER_SIZE_ROUNDED_UP; NetworkBufferDescriptor_t ** ppDescriptor; @@ -795,3 +1026,4 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB } } } +/*-----------------------------------------------------------*/ diff --git a/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c b/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c index 563ec92016..941b051de5 100644 --- a/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c +++ b/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c @@ -37,6 +37,20 @@ /*-----------------------------------------------------------*/ +#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 ) */ + +/*-----------------------------------------------------------*/ + #if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) const char * pcApplicationHostnameHook( void ) @@ -122,7 +136,12 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) { /* Print out the network configuration, which may have come from a DHCP * server. */ + #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 /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */ + FreeRTOS_inet_ntoa( ulIPAddress, cBuffer ); FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) ); @@ -165,7 +184,28 @@ void vPlatformInitIpStack( void ) ucIPAddress[ 2 ] = ( ( uxRandomNumber >> 16 ) & 0xFF ); ucIPAddress[ 3 ] = ( ( uxRandomNumber >> 24 ) & 0xFF ); + /* 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, ucNullAddress, ucNullAddress, 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 ) ); + xResult = FreeRTOS_IPStart(); +#else + /* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */ xResult = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucNullAddress, ucNullAddress, ucMACAddress ); +#endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */ + configASSERT( xResult == pdTRUE ); } @@ -177,3 +217,15 @@ BaseType_t xPlatformIsNetworkUp( void ) } /*-----------------------------------------------------------*/ + +#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 +/*-----------------------------------------------------------*/ \ No newline at end of file diff --git a/lexicon.txt b/lexicon.txt index 49a2d31e71..047589b57f 100644 --- a/lexicon.txt +++ b/lexicon.txt @@ -178,6 +178,7 @@ burtcmodeem busfault buttonisr bvic +bwantdhcp bytesreceived bytessent bytestorecv @@ -2139,6 +2140,7 @@ puxstackbuffer pv pvalue pvargs +pvargument pvbuffer pvcontext pvctx @@ -2179,6 +2181,7 @@ pxdptr pxecdsacontext pxecparams pxecparamsptr +pxendpoint pxexpiredtimer pxfilesize pxftpclient @@ -2188,6 +2191,7 @@ pxhigherprioritytaskwoken pxincomingpacket pxincomingpublishcallback pxindex +pxinterface pxisrfunction pxknownmessage pxlist @@ -2195,6 +2199,7 @@ pxmbedpkcontext pxmbedtlspkctx pxmetrics pxmqttcontext +pxmyinterface pxnetif pxnetworkbuffer pxnetworkcontext @@ -2297,6 +2302,7 @@ readme readonly readtotaltimeoutconstant readtotaltimeoutmultiplier +realtek reblocked receiveloop receivetimeout @@ -2600,6 +2606,7 @@ stm stor str strcasecmp +strcasestr strin stringification strintrx @@ -3373,8 +3380,10 @@ xdoremove xe xeb xechoserveraddress +xemacindex xemaclite xend +xendpoints xerrorcount xerrordetected xerrorline