From f06c93a1a2f37d349812a43dbd25f0c8277efc18 Mon Sep 17 00:00:00 2001 From: Arto Kinnunen Date: Tue, 18 Feb 2020 14:40:58 +0200 Subject: [PATCH 1/2] Update STM32 EMAC driver - limit RX frame length DISCO_F769NI EMAC driver may return ethernet packet with illegal length when driver is under heavy load. In one case, the received bytes indicate frame length of 53 bytes but advertised data length was 65518 bytes. In another case EMAC driver variable `EthHandle.RxFrameInfos.length` contained value 0xFFFF FFFC. As a work-around accept only 1-1500 bytes long ethernet packets. --- features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp diff --git a/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp b/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp old mode 100644 new mode 100755 index a13e4d124c..55f82b16cb --- a/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp +++ b/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp @@ -546,7 +546,7 @@ int STM32_EMAC::low_level_input(emac_mem_buf_t **buf) dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc; - if (len > 0) { + if (len > 0 && EthHandle.RxFrameInfos.length <= 1500) { /* Allocate a memory buffer chain from buffer pool */ *buf = memory_manager->alloc_pool(len, 0); } From c4fe17cc911a1e32745ff3c69dd4f30c44f6587a Mon Sep 17 00:00:00 2001 From: Arto Kinnunen Date: Thu, 20 Feb 2020 15:49:58 +0200 Subject: [PATCH 2/2] Update STM32 EMAC driver based on review -Fix len type -Use ETH_RX_BUF_SIZE instead of hard-coded value 1500 --- features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp b/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp index 55f82b16cb..6935b157ef 100755 --- a/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp +++ b/features/netsocket/emac-drivers/TARGET_STM/stm32xx_emac.cpp @@ -526,7 +526,7 @@ error: int STM32_EMAC::low_level_input(emac_mem_buf_t **buf) #ifndef ETH_IP_VERSION_V2 { - uint16_t len = 0; + uint32_t len = 0; uint8_t *buffer; __IO ETH_DMADescTypeDef *dmarxdesc; uint32_t bufferoffset = 0; @@ -546,7 +546,7 @@ int STM32_EMAC::low_level_input(emac_mem_buf_t **buf) dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc; - if (len > 0 && EthHandle.RxFrameInfos.length <= 1500) { + if (len > 0 && len <= ETH_RX_BUF_SIZE) { /* Allocate a memory buffer chain from buffer pool */ *buf = memory_manager->alloc_pool(len, 0); }