Skip to content

Commit 801c7d7

Browse files
committed
Code-style changes as suggested by @htibosch
1 parent 280ec68 commit 801c7d7

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
static uint8_t ucLLMNR_MAC_address[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0xFC };
9191
#endif
9292

93+
/* Check if the raw Ethernet frame is ICMP */
94+
static BaseType_t isICMP( const NetworkBufferDescriptor_t * pxDescriptor );
95+
9396
/* Receive task refresh time */
9497
#define RECEIVE_BLOCK_TIME_MS 100
9598

@@ -272,19 +275,33 @@ BaseType_t xATSAM5x_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface
272275
return xATSAM5x_PHYGetLinkStatus( NULL );
273276
}
274277

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;
288305
}
289306

290307
static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
@@ -348,11 +365,13 @@ static void prvEMACDeferredInterruptHandlerTask( void * pvParameters )
348365
#if ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1 )
349366
{
350367
/* 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+
{
353371
xICMPChecksumResult = usGenerateProtocolChecksum( pxBufferDescriptor->pucEthernetBuffer, pxBufferDescriptor->xDataLength, pdFALSE );
354372
}
355-
else {
373+
else
374+
{
356375
xICMPChecksumResult = ipCORRECT_CRC; /* Checksum already verified by GMAC */
357376
}
358377
}
@@ -449,9 +468,10 @@ BaseType_t xATSAM5x_NetworkInterfaceOutput( NetworkInterface_t * pxInterface,
449468
{
450469
/* the Atmel SAM GMAC peripheral does not support hardware CRC offloading for ICMP packets.
451470
* 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+
}
455475
}
456476
#endif /* if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) */
457477

0 commit comments

Comments
 (0)