Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


uIP (FreeTCP/IP) Broadcast Support broken

Posted by sjackerman on March 6, 2014

Trying to use uIP for the Art-Net protocol. In development I found that the UDP support for receiving broadcast datagrams is broken - someone else has found the same uIP issue:


Here's a fix:

/---------------------------------------------------------------------------/ // see: https://list.sics.se/sympa/arc/uip-users/2009-09/msg00022.html static bool uipipaddrtestaddr(uipipaddrt *addr) { //addr1 is the external address, addr2 is the address to match uipipaddr_t masked, masked1;

//are the addresses equal?
if (uip_ipaddr_cmp(addr, &uip_hostaddr)) return true;

//broadcast to ?
if (uip_ipaddr_cmp(addr, &uip_broadcast_addr)) return true;

//broadcast to ?
if (uip_ipaddr_cmp(addr, &uip_all_zeroes_addr)) return true;

//Test if the address is a broadcast to a subnet
masked.u16[0]=addr->u16[0] & uip_netmask.u16[0];
masked.u16[1]=addr->u16[1] & uip_netmask.u16[1];

masked1.u16[0]=uip_hostaddr.u16[0] & uip_netmask.u16[0];
masked1.u16[1]=uip_hostaddr.u16[1] & uip_netmask.u16[1];

//Check wether the masked IP addresses are correct (same subnet)
if (!uip_ipaddr_cmp(&masked, &masked1)) return false;      

//same subnet, now test whether the remaining bits are all set to 1
masked.u16[0]=addr->u16[0] | uip_netmask.u16[0];
masked.u16[1]=addr->u16[1] | uip_netmask.u16[1];

//If masked is all_ones, then a message was sent to subnet.allones 
if (uip_ipaddr_cmp(&masked, &uip_broadcast_addr)) return true;

return false;


and this new function must be called from two places in uip.c - when checking for a broadcast address match:

	/* If IP broadcast support is configured, we check for a broadcast
	UDP packet, which may be destined to us. */
		//DEBUG_PRINTF( "UDP IP checksum 0x%04x\n", uip_ipchksum() );
		if( 	BUF->proto == UIP_PROTO_UDP 
			// &&	uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) /*&& uip_ipchksum() == 0xffff*/ )
			&&	uip_ipaddr_test_addr(&BUF->destipaddr) /*&& uip_ipchksum() == 0xffff*/ )
			goto udp_input;
	#endif /* UIP_BROADCAST */

and also when demultiplexing the datagram to the connections:

	/* Demultiplex this UDP packet between the UDP "connections". */
	for( uip_udp_conn = &uip_udp_conns[ 0 ]; uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS]; ++uip_udp_conn )
		/* If the local UDP port is non-zero, the connection is considered
	   to be used. If so, the local port number is checked against the
	   destination port number in the received packet. If the two port
	   numbers match, the remote port number is checked if the
	   connection is bound to a remote port. Finally, if the
	   connection is bound to a remote IP address, the source IP
	   address of the packet is checked. */
			uip_udp_conn->lport != 0 &&
			UDPBUF->destport == uip_udp_conn->lport &&
			(uip_udp_conn->rport == 0 || UDPBUF->srcport == uip_udp_conn->rport) &&
				uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||
				uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||
				// uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr)
			goto udp_found;

The RX62N Ethernet driver sends each packet twice to circumvent the TCP/IP delayed ACK problem. This results in the UDP datagrams being sent twice as well.

I need to fix the Ethernet driver to only send the packet once, and then send TCP packets twice and UDP packets once.

Steven J. Ackerman Consultant ACS, Sarasota, FL http://www.acscontrol.com

uIP (FreeTCP/IP) Broadcast Support broken

Posted by rtel on March 6, 2014

Thanks for taking the time to point this out. We will look into it and update as appropriate.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner