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 diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 27888162c8..4246252217 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..514f9f6a54 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 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 + #endif /* FREERTOS_DEFAULT_IP_CONFIG_H */