Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix in ATSAME5x network interface. Incorrect detection of ICMP #1194

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
static uint8_t ucLLMNR_MAC_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
#endif

/* Check if the raw Ethernet frame is ICMP */
static BaseType_t isICMP( const NetworkBufferDescriptor_t * pxDescriptor );

/* Receive task refresh time */
#define RECEIVE_BLOCK_TIME_MS 100

Expand Down Expand Up @@ -272,14 +275,41 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface
return xATSAM5x_PHYGetLinkStatus( NULL );
}

/* Check if the raw Ethernet frame is ICMP */
static BaseType_t isICMP( const NetworkBufferDescriptor_t * pxDescriptor )
{
BaseType_t xReturn = pdFALSE;

const IPPacket_t * pkt = ( const IPPacket_t * ) pxDescriptor->pucEthernetBuffer;

if( pkt->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE )
{
if( pkt->xIPHeader.ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP )
{
xReturn = pdTRUE;
}
}

#if ipconfigUSE_IPv6 != 0
else if( pkt->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE )
{
ICMPPacket_IPv6_t * icmp6 = ( ICMPPacket_IPv6_t * ) pxDescriptor->pucEthernetBuffer;

if( icmp6->xIPHeader.ucNextHeader == ipPROTOCOL_ICMP_IPv6 )
{
xReturn = pdTRUE;
}
}
#endif
return xReturn;
}

static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
{
NetworkBufferDescriptor_t * pxBufferDescriptor;
size_t xBytesReceived = 0, xBytesRead = 0;

uint16_t xICMPChecksumResult = ipCORRECT_CRC;
const IPPacket_t * pxIPPacket;


/* Used to indicate that xSendEventStructToIPTask() is being called because
Expand Down Expand Up @@ -336,15 +366,13 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
{
/* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets.
* It must therefore be implemented in software. */
pxIPPacket = ( IPPacket_t const * ) pxBufferDescriptor->pucEthernetBuffer;

if( pxIPPacket->xIPHeader.ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP )
if( isICMP( pxBufferDescriptor ) == pdTRUE )
{
xICMPChecksumResult = usGenerateProtocolChecksum( pxBufferDescriptor->pucEthernetBuffer, pxBufferDescriptor->xDataLength, pdFALSE );
}
else
{
xICMPChecksumResult = ipCORRECT_CRC; /* Reset the result value in case this is not an ICMP packet. */
xICMPChecksumResult = ipCORRECT_CRC; /* Checksum already verified by GMAC */
}
}
#endif /* if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 ) */
Expand Down Expand Up @@ -440,9 +468,7 @@ BaseType_t xATSAM5x_NetworkInterfaceOutput( NetworkInterface_t * pxInterface,
{
/* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets.
* It must therefore be implemented in software. */
const IPPacket_t * pxIPPacket = ( IPPacket_t const * ) pxDescriptor->pucEthernetBuffer;

if( pxIPPacket->xIPHeader.ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP )
if( isICMP( pxDescriptor ) == pdTRUE )
{
( void ) usGenerateProtocolChecksum( pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, pdTRUE );
}
Expand Down
Loading