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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 21 additions & 15 deletions source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,27 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface
return xATSAM5x_PHYGetLinkStatus( NULL );
}

/* Check if the raw ethernet frame is ICMP */
static inline BaseType_t isICMP(const NetworkBufferDescriptor_t * pxDescriptor) {
const IPPacket_t * pkt = (const IPPacket_t *) pxDescriptor->pucEthernetBuffer;
if (pkt->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE) {
return pkt->xIPHeader.ucProtocol == (uint8_t) ipPROTOCOL_ICMP;
}
#if ipconfigUSE_IPv6 != 0
else if (pkt->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE) {
ICMPPacket_IPv6_t * icmp6 = (ICMPPacket_IPv6_t *) pxDescriptor->pucEthernetBuffer;
return icmp6->xIPHeader.ucNextHeader == ipPROTOCOL_ICMP_IPv6;
}
#endif
return pdFALSE;
}

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 @@ -335,16 +348,12 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
#if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 )
{
/* 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 )
{
* It must therefore be implemented in software. */
if ( isICMP(pxBufferDescriptor) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if statement expects a boolean value. The function isICMP() returns an integer value. The only way to satisfy the compiler is as follows:

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. */
else {
xICMPChecksumResult = ipCORRECT_CRC; /* Checksum already verified by GMAC */
}
}
#endif /* if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 ) */
Expand Down Expand Up @@ -440,12 +449,9 @@ 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 )
{
( void ) usGenerateProtocolChecksum( pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, pdTRUE );
}
if ( isICMP(pxDescriptor) ) {
usGenerateProtocolChecksum( pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, pdTRUE );
}
}
#endif /* if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) */

Expand Down