Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


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 ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists