Skip to content

Commit d5f99e0

Browse files
committed
Fix IPv4/6 preprocessor logic in Zynq/Ultrascale port
1 parent 0253c34 commit d5f99e0

File tree

2 files changed

+59
-41
lines changed

2 files changed

+59
-41
lines changed

source/portable/NetworkInterface/Zynq/NetworkInterface.c

+30-20
Original file line numberDiff line numberDiff line change
@@ -254,35 +254,39 @@ static BaseType_t xZynqNetworkInterfaceInitialise( NetworkInterface_t * pxInterf
254254
/* Initialize the mac and set the MAC address at position 1. */
255255
XEmacPs_SetMacAddress( pxEMAC_PS, ( void * ) pxEndPoint->xMACAddress.ucBytes, 1 );
256256

257-
#if ( ipconfigUSE_LLMNR == 1 )
257+
#if ( ipconfigIS_ENABLED( ipconfigUSE_LLMNR ) )
258258
{
259-
#if ( ipconfigUSE_IPv6 == 0 )
259+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) )
260260
{
261261
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xLLMNR_MacAddress.ucBytes );
262262
}
263-
#else
263+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
264+
265+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
264266
{
265267
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xLLMNR_MacAddressIPv6.ucBytes );
266268
}
267-
#endif /* if ( ipconfigUSE_IPv6 == 0 ) */
269+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
268270
}
269-
#endif /* ipconfigUSE_LLMNR == 1 */
271+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_LLMNR ) ) */
270272

271-
#if ( ipconfigUSE_MDNS == 1 )
273+
#if ( ipconfigIS_ENABLED( ipconfigUSE_MDNS) )
272274
{
273-
#if ( ipconfigUSE_IPv6 == 0 )
275+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) )
274276
{
275277
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddress.ucBytes );
276278
}
277-
#else
279+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
280+
281+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
278282
{
279283
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddressIPv6.ucBytes );
280284
}
281-
#endif /* if ( ipconfigUSE_IPv6 == 0 ) */
285+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
282286
}
283-
#endif /* ( ipconfigUSE_MDNS == 1 ) */
287+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_MDNS) ) */
284288

285-
#if ( ipconfigUSE_IPv6 != 0 )
289+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
286290
{
287291
/* set the solicited-node multicast address */
288292
for( NetworkEndPoint_t * pxEndPointIter = FreeRTOS_FirstEndPoint( pxInterface );
@@ -299,7 +303,7 @@ static BaseType_t xZynqNetworkInterfaceInitialise( NetworkInterface_t * pxInterf
299303
}
300304
}
301305
}
302-
#endif /* if ( ipconfigUSE_IPv6 == 0 ) */
306+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
303307

304308
pxEndPoint = FreeRTOS_NextEndPoint( pxInterface, pxEndPoint );
305309

@@ -388,7 +392,8 @@ static BaseType_t xZynqNetworkInterfaceOutput( NetworkInterface_t * pxInterface,
388392
* the protocol checksum to have a value of zero. */
389393
pxPacket = ( ProtocolPacket_t * ) ( pxBuffer->pucEthernetBuffer );
390394

391-
#if ( ipconfigUSE_IPv6 != 0 )
395+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
396+
{
392397
ICMPPacket_IPv6_t * pxICMPPacket = ( ICMPPacket_IPv6_t * ) pxBuffer->pucEthernetBuffer;
393398

394399
if( ( pxPacket->xICMPPacket.xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE ) &&
@@ -399,16 +404,21 @@ static BaseType_t xZynqNetworkInterfaceOutput( NetworkInterface_t * pxInterface,
399404
* so for ICMP and other protocols it must be done manually. */
400405
usGenerateProtocolChecksum( pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength, pdTRUE );
401406
}
402-
#endif
407+
}
408+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
403409

404-
if( ( pxPacket->xICMPPacket.xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) &&
405-
( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP ) )
410+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) )
406411
{
407-
/* The EMAC will calculate the checksum of the IP-header.
408-
* It can only calculate protocol checksums of UDP and TCP,
409-
* so for ICMP and other protocols it must be done manually. */
410-
usGenerateProtocolChecksum( pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength, pdTRUE );
412+
if( ( pxPacket->xICMPPacket.xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) &&
413+
( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP ) )
414+
{
415+
/* The EMAC will calculate the checksum of the IP-header.
416+
* It can only calculate protocol checksums of UDP and TCP,
417+
* so for ICMP and other protocols it must be done manually. */
418+
usGenerateProtocolChecksum( pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength, pdTRUE );
419+
}
411420
}
421+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) ) */
412422
}
413423
#endif /* ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM */
414424

source/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c

+29-21
Original file line numberDiff line numberDiff line change
@@ -319,35 +319,39 @@ static BaseType_t xUltrascaleNetworkInterfaceInitialise( NetworkInterface_t * px
319319
/* Initialize the mac and set the MAC address at position 1. */
320320
XEmacPs_SetMacAddress( pxEMAC_PS, ( void * ) pxEndPoint->xMACAddress.ucBytes, 1 );
321321

322-
#if ( ipconfigUSE_LLMNR == 1 )
322+
#if ( ipconfigIS_ENABLED( ipconfigUSE_LLMNR ) )
323323
{
324-
#if ( ipconfigUSE_IPv6 == 0 )
324+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) )
325325
{
326326
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xLLMNR_MacAddress.ucBytes );
327327
}
328-
#else
328+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
329+
330+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
329331
{
330332
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xLLMNR_MacAddressIPv6.ucBytes );
331333
}
332-
#endif /* if ( ipconfigUSE_IPv6 == 0 ) */
334+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
333335
}
334-
#endif /* ipconfigUSE_LLMNR == 1 */
336+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_LLMNR ) ) */
335337

336-
#if ( ipconfigUSE_MDNS == 1 )
338+
#if ( ipconfigIS_ENABLED( ipconfigUSE_MDNS) )
337339
{
338-
#if ( ipconfigUSE_IPv6 == 0 )
340+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) )
339341
{
340342
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddress.ucBytes );
341343
}
342-
#else
344+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
345+
346+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
343347
{
344-
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MACAddressIPv6.ucBytes );
348+
XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddressIPv6.ucBytes );
345349
}
346-
#endif /* if ( ipconfigUSE_IPv6 == 0 ) */
350+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
347351
}
348-
#endif /* ( ipconfigUSE_MDNS == 1 ) */
352+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_MDNS) ) */
349353

350-
#if ( ipconfigUSE_IPv6 != 0 )
354+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
351355
{
352356
/* set the solicited-node multicast address */
353357
for( NetworkEndPoint_t * pxEndPointIter = FreeRTOS_FirstEndPoint( pxInterface );
@@ -364,7 +368,7 @@ static BaseType_t xUltrascaleNetworkInterfaceInitialise( NetworkInterface_t * px
364368
}
365369
}
366370
}
367-
#endif /* if ( ipconfigUSE_IPv6 == 0 ) */
371+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
368372

369373
/* allow reception of multicast addresses programmed into hash (LLMNR or mDNS) */
370374
XEmacPs_SetOptions( pxEMAC_PS, XEMACPS_MULTICAST_OPTION );
@@ -504,7 +508,7 @@ static BaseType_t xUltrascaleNetworkInterfaceOutput( NetworkInterface_t * pxInte
504508
* the protocol checksum to have a value of zero. */
505509
pxPacket = ( ProtocolPacket_t * ) ( pxBuffer->pucEthernetBuffer );
506510

507-
#if ( ipconfigUSE_IPv6 != 0 )
511+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) )
508512
ICMPPacket_IPv6_t * pxICMPPacket = ( ICMPPacket_IPv6_t * ) pxBuffer->pucEthernetBuffer;
509513

510514
if( ( pxPacket->xICMPPacket.xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE ) &&
@@ -515,16 +519,20 @@ static BaseType_t xUltrascaleNetworkInterfaceOutput( NetworkInterface_t * pxInte
515519
* so for ICMP and other protocols it must be done manually. */
516520
usGenerateProtocolChecksum( pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength, pdTRUE );
517521
}
518-
#endif /* ipconfigUSE_IPv6 */
522+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */
519523

520-
if( ( pxPacket->xICMPPacket.xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) &&
521-
( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP ) )
524+
#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) )
522525
{
523-
/* The EMAC will calculate the checksum of the IP-header.
524-
* It can only calculate protocol checksums of UDP and TCP,
525-
* so for ICMP and other protocols it must be done manually. */
526-
usGenerateProtocolChecksum( pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength, pdTRUE );
526+
if( ( pxPacket->xICMPPacket.xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) &&
527+
( pxPacket->xICMPPacket.xIPHeader.ucProtocol == ipPROTOCOL_ICMP ) )
528+
{
529+
/* The EMAC will calculate the checksum of the IP-header.
530+
* It can only calculate protocol checksums of UDP and TCP,
531+
* so for ICMP and other protocols it must be done manually. */
532+
usGenerateProtocolChecksum( pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength, pdTRUE );
533+
}
527534
}
535+
#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
528536
}
529537
#endif /* ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM */
530538

0 commit comments

Comments
 (0)