|
90 | 90 | static uint8_t ucLLMNR_MAC_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
|
91 | 91 | #endif
|
92 | 92 |
|
| 93 | +/* Check if the raw Ethernet frame is ICMP */ |
| 94 | +static BaseType_t isICMP( const NetworkBufferDescriptor_t * pxDescriptor ); |
| 95 | + |
93 | 96 | /* Receive task refresh time */
|
94 | 97 | #define RECEIVE_BLOCK_TIME_MS 100
|
95 | 98 |
|
@@ -272,14 +275,41 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface
|
272 | 275 | return xATSAM5x_PHYGetLinkStatus( NULL );
|
273 | 276 | }
|
274 | 277 |
|
| 278 | +/* Check if the raw Ethernet frame is ICMP */ |
| 279 | +static BaseType_t isICMP( const NetworkBufferDescriptor_t * pxDescriptor ) |
| 280 | +{ |
| 281 | + BaseType_t xReturn = pdFALSE; |
| 282 | + |
| 283 | + const IPPacket_t * pkt = ( const IPPacket_t * ) pxDescriptor->pucEthernetBuffer; |
| 284 | + |
| 285 | + if( pkt->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) |
| 286 | + { |
| 287 | + if( pkt->xIPHeader.ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP ) |
| 288 | + { |
| 289 | + xReturn = pdTRUE; |
| 290 | + } |
| 291 | + } |
| 292 | + |
| 293 | + #if ipconfigUSE_IPv6 != 0 |
| 294 | + else if( pkt->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE ) |
| 295 | + { |
| 296 | + ICMPPacket_IPv6_t * icmp6 = ( ICMPPacket_IPv6_t * ) pxDescriptor->pucEthernetBuffer; |
| 297 | + |
| 298 | + if( icmp6->xIPHeader.ucNextHeader == ipPROTOCOL_ICMP_IPv6 ) |
| 299 | + { |
| 300 | + xReturn = pdTRUE; |
| 301 | + } |
| 302 | + } |
| 303 | + #endif |
| 304 | + return xReturn; |
| 305 | +} |
275 | 306 |
|
276 | 307 | static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
|
277 | 308 | {
|
278 | 309 | NetworkBufferDescriptor_t * pxBufferDescriptor;
|
279 | 310 | size_t xBytesReceived = 0, xBytesRead = 0;
|
280 | 311 |
|
281 | 312 | uint16_t xICMPChecksumResult = ipCORRECT_CRC;
|
282 |
| - const IPPacket_t * pxIPPacket; |
283 | 313 |
|
284 | 314 |
|
285 | 315 | /* Used to indicate that xSendEventStructToIPTask() is being called because
|
@@ -336,15 +366,13 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
|
336 | 366 | {
|
337 | 367 | /* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets.
|
338 | 368 | * It must therefore be implemented in software. */
|
339 |
| - pxIPPacket = ( IPPacket_t const * ) pxBufferDescriptor->pucEthernetBuffer; |
340 |
| - |
341 |
| - if( pxIPPacket->xIPHeader.ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP ) |
| 369 | + if( isICMP( pxBufferDescriptor ) == pdTRUE ) |
342 | 370 | {
|
343 | 371 | xICMPChecksumResult = usGenerateProtocolChecksum( pxBufferDescriptor->pucEthernetBuffer, pxBufferDescriptor->xDataLength, pdFALSE );
|
344 | 372 | }
|
345 | 373 | else
|
346 | 374 | {
|
347 |
| - xICMPChecksumResult = ipCORRECT_CRC; /* Reset the result value in case this is not an ICMP packet. */ |
| 375 | + xICMPChecksumResult = ipCORRECT_CRC; /* Checksum already verified by GMAC */ |
348 | 376 | }
|
349 | 377 | }
|
350 | 378 | #endif /* if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 ) */
|
@@ -440,9 +468,7 @@ BaseType_t xATSAM5x_NetworkInterfaceOutput( NetworkInterface_t * pxInterface,
|
440 | 468 | {
|
441 | 469 | /* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets.
|
442 | 470 | * It must therefore be implemented in software. */
|
443 |
| - const IPPacket_t * pxIPPacket = ( IPPacket_t const * ) pxDescriptor->pucEthernetBuffer; |
444 |
| - |
445 |
| - if( pxIPPacket->xIPHeader.ucProtocol == ( uint8_t ) ipPROTOCOL_ICMP ) |
| 471 | + if( isICMP( pxDescriptor ) == pdTRUE ) |
446 | 472 | {
|
447 | 473 | ( void ) usGenerateProtocolChecksum( pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, pdTRUE );
|
448 | 474 | }
|
|
0 commit comments