From 14116dcfb0688c437b69bdebffcf57f45c2a4804 Mon Sep 17 00:00:00 2001 From: Emil Popov Date: Mon, 1 Mar 2021 14:41:30 -0500 Subject: [PATCH 1/3] Adds an optional user hook that gets called for all unhandled Ethernet frames. --- FreeRTOS_IP.c | 24 ++++++++++++++++++++++-- include/FreeRTOSIPConfigDefaults.h | 8 ++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index ae8252f16e..1f97a4bd83 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -191,6 +191,21 @@ static void prvIPTask( void * pvParameters ); */ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ); +#if ( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES != 0 ) + +/* + * The stack will call this user hook for all Ethernet frames that it + * does not support, i.e. other than IPv4, IPv6 and ARP ( for the moment ) + * If this hook returns eReleaseBuffer or eProcessBuffer, the stack will + * release and reuse the network buffer. If this hook returns + * eReturnEthernetFrame, that means user code has reused the network buffer + * to generate a response and the stack will send that response out. + * If this hook returns eFrameConsumed, the user code has ownership of the + * network buffer and has to release it when it’s done. + */ + extern eFrameProcessingResult_t eApplicationProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer ); +#endif /* ( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES != 0 ) */ + /* * Process incoming IP packets. */ @@ -1727,8 +1742,13 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor break; default: - /* No other packet types are handled. Nothing to do. */ - eReturned = eReleaseBuffer; + #if ( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES != 0 ) + /* Custom frame handler. */ + eReturned = eApplicationProcessCustomFrameHook( pxNetworkBuffer ); + #else + /* No other packet types are handled. Nothing to do. */ + eReturned = eReleaseBuffer; + #endif break; } } diff --git a/include/FreeRTOSIPConfigDefaults.h b/include/FreeRTOSIPConfigDefaults.h index dcbabb2159..aee3624ece 100644 --- a/include/FreeRTOSIPConfigDefaults.h +++ b/include/FreeRTOSIPConfigDefaults.h @@ -633,4 +633,12 @@ #define ipconfigSELECT_USES_NOTIFY 0 #endif +/* Set to 1 if you plan on processing custom Ethernet protocols or protocols + * that are not yet supported by the FreeRTOS+TCP stack. If set to 1, + * the user must define eFrameProcessingResult_t eProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer ) + * which will be called by the stack for any frame it does not recognize. */ +#ifndef ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES + #define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 0 +#endif + #endif /* FREERTOS_DEFAULT_IP_CONFIG_H */ From dcc0c6a688a1dea5bdc25716aa330ed0f59be3b4 Mon Sep 17 00:00:00 2001 From: Emil Popov Date: Mon, 1 Mar 2021 14:48:53 -0500 Subject: [PATCH 2/3] re-wording --- include/FreeRTOSIPConfigDefaults.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/FreeRTOSIPConfigDefaults.h b/include/FreeRTOSIPConfigDefaults.h index aee3624ece..514f9f6a54 100644 --- a/include/FreeRTOSIPConfigDefaults.h +++ b/include/FreeRTOSIPConfigDefaults.h @@ -635,8 +635,8 @@ /* Set to 1 if you plan on processing custom Ethernet protocols or protocols * that are not yet supported by the FreeRTOS+TCP stack. If set to 1, - * the user must define eFrameProcessingResult_t eProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer ) - * which will be called by the stack for any frame it does not recognize. */ + * the user must define eFrameProcessingResult_t eApplicationProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer ) + * which will be called by the stack for any frame with an unsupported EtherType. */ #ifndef ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES #define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 0 #endif From 963de0d8db9ab98a8518f1f97876bcfd23db7ce7 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Tue, 2 Mar 2021 11:42:41 -0500 Subject: [PATCH 3/3] Fix spell check --- .github/lexicon.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index 98538a49fe..06dcb864aa 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -181,6 +181,7 @@ dw dword dzpq eagain +eapplicationprocesscustomframehook earpcachehit earpcachemiss earptimerevent