|
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,19 +275,33 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface |
272 | 275 | return xATSAM5x_PHYGetLinkStatus( NULL ); |
273 | 276 | } |
274 | 277 |
|
275 | | -/* Check if the raw ethernet frame is ICMP */ |
276 | | -static inline BaseType_t isICMP(const NetworkBufferDescriptor_t * pxDescriptor) { |
277 | | - const IPPacket_t * pkt = (const IPPacket_t *) pxDescriptor->pucEthernetBuffer; |
278 | | - if (pkt->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE) { |
279 | | - return pkt->xIPHeader.ucProtocol == (uint8_t) ipPROTOCOL_ICMP; |
280 | | - } |
281 | | - #if ipconfigUSE_IPv6 != 0 |
282 | | - else if (pkt->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE) { |
283 | | - ICMPPacket_IPv6_t * icmp6 = (ICMPPacket_IPv6_t *) pxDescriptor->pucEthernetBuffer; |
284 | | - return icmp6->xIPHeader.ucNextHeader == ipPROTOCOL_ICMP_IPv6; |
285 | | - } |
286 | | - #endif |
287 | | - return pdFALSE; |
| 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; |
288 | 305 | } |
289 | 306 |
|
290 | 307 | static void prvEMACDeferredInterruptHandlerTask( void * pvParameters ) |
@@ -348,11 +365,13 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters ) |
348 | 365 | #if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 ) |
349 | 366 | { |
350 | 367 | /* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets. |
351 | | - * It must therefore be implemented in software. */ |
352 | | - if ( isICMP(pxBufferDescriptor) ) { |
| 368 | + * It must therefore be implemented in software. */ |
| 369 | + if( isICMP( pxBufferDescriptor ) == pdTRUE ) |
| 370 | + { |
353 | 371 | xICMPChecksumResult = usGenerateProtocolChecksum( pxBufferDescriptor->pucEthernetBuffer, pxBufferDescriptor->xDataLength, pdFALSE ); |
354 | 372 | } |
355 | | - else { |
| 373 | + else |
| 374 | + { |
356 | 375 | xICMPChecksumResult = ipCORRECT_CRC; /* Checksum already verified by GMAC */ |
357 | 376 | } |
358 | 377 | } |
@@ -449,9 +468,10 @@ BaseType_t xATSAM5x_NetworkInterfaceOutput( NetworkInterface_t * pxInterface, |
449 | 468 | { |
450 | 469 | /* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets. |
451 | 470 | * It must therefore be implemented in software. */ |
452 | | - if ( isICMP(pxDescriptor) ) { |
453 | | - usGenerateProtocolChecksum( pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, pdTRUE ); |
454 | | - } |
| 471 | + if( isICMP( pxDescriptor ) == pdTRUE ) |
| 472 | + { |
| 473 | + ( void ) usGenerateProtocolChecksum( pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength, pdTRUE ); |
| 474 | + } |
455 | 475 | } |
456 | 476 | #endif /* if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) */ |
457 | 477 |
|
|
0 commit comments