Some re-formatting of uip.c.

pull/1/head
Richard Barry 15 years ago
parent 904e22b667
commit 2641267c85

@ -75,10 +75,9 @@
#include "net/uip_arp.h"
#include "net/uip_arch.h"
#if !UIP_CONF_IPV6 /* If UIP_CONF_IPV6 is defined, we compile the
uip6.c file instead of this one. Therefore
this #ifndef removes the entire compilation
output of the uip.c file */
/* If UIP_CONF_IPV6 is defined, we compile the uip6.c file instead of this one.
Therefore this #ifndef removes the entire compilation output of the uip.c file */
#if !UIP_CONF_IPV6
#if UIP_CONF_IPV6
#include "net/uip-neighbor.h"
@ -90,9 +89,8 @@
/* Variable definitions. */
/* The IP address of this host. If it is defined to be fixed (by
setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set
here. Otherwise, the address */
/* The IP address of this host. If it is defined to be fixed (by setting
UIP_FIXEDADDR to 1 in uipopt.h), the address is set here. Otherwise, the address */
#if UIP_FIXEDADDR > 0
const uip_ipaddr_t uip_hostaddr = { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
const uip_ipaddr_t uip_draddr = { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
@ -105,12 +103,9 @@ const uip_ipaddr_t uip_broadcast_addr =
#if UIP_CONF_IPV6
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
#else /* UIP_CONF_IPV6 */
{
{
0xff, 0xff, 0xff, 0xff
}
};
{ { 0xff, 0xff, 0xff, 0xff } };
#endif /* UIP_CONF_IPV6 */
const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
#if UIP_FIXEDETHADDR
@ -118,62 +113,59 @@ const struct uip_eth_addr uip_ethaddr = { { UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHA
#else
struct uip_eth_addr uip_ethaddr = { { 0, 0, 0, 0, 0, 0 } };
#endif
#ifndef UIP_CONF_EXTERNAL_BUFFER
u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
incoming packets. */
/* The packet buffer that contains incoming packets. */
u8_t uip_buf[ UIP_BUFSIZE + 2 ];
#endif /* UIP_CONF_EXTERNAL_BUFFER */
void *uip_appdata; /* The uip_appdata pointer points to
application data. */
void *uip_sappdata; /* The uip_appdata pointer points to
the application data which is to
be sent. */
/* The uip_appdata pointer points to application data. */
void *uip_appdata;
/* The uip_appdata pointer points to the application data which is to be sent. */
void *uip_sappdata;
#if UIP_URGDATA > 0
void *uip_urgdata; /* The uip_urgdata pointer points to
urgent data (out-of-band data), if
/* The uip_urgdata pointer points to urgent data (out-of-band data), if
present. */
void *uip_urgdata;
u16_t uip_urglen, uip_surglen;
#endif /* UIP_URGDATA > 0 */
/* The uip_len is either 8 or 16 bits, depending on the maximum packet size. */
u16_t uip_len, uip_slen;
/* The uip_len is either 8 or 16 bits,
depending on the maximum packet
size. */
u8_t uip_flags; /* The uip_flags variable is used for
communication between the TCP/IP stack
/* The uip_flags variable is used for communication between the TCP/IP stack
and the application program. */
struct uip_conn *uip_conn; /* uip_conn always points to the current
connection. */
u8_t uip_flags;
/* uip_conn always points to the current connection. */
struct uip_conn *uip_conn;
struct uip_conn uip_conns[ UIP_CONNS ];
/* The uip_conns array holds all TCP
connections. */
/* The uip_conns array holds all TCP connections. */
u16_t uip_listenports[UIP_LISTENPORTS];
/* The uip_listenports list all currently
listning ports. */
/* The uip_listenports list all currently listning ports. */
#if UIP_UDP
struct uip_udp_conn *uip_udp_conn;
struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
#endif /* UIP_UDP */
static u16_t ipid; /* Ths ipid variable is an increasing
number that is used for the IP ID
field. */
/* Ths ipid variable is an increasing number that is used for the IP ID field. */
static u16_t ipid;
void uip_setipid( u16_t id )
{
ipid = id;
}
static u8_t iss[4]; /* The iss variable is used for the TCP
initial sequence number. */
/* The iss variable is used for the TCP initial sequence number. */
static u8_t iss[ 4 ];
#if UIP_ACTIVE_OPEN
static u16_t lastport; /* Keeps track of the last port used for
a new connection. */
/* Keeps track of the last port used for a new connection. */
static u16_t lastport;
#endif /* UIP_ACTIVE_OPEN */
/* Temporary variables. */
@ -216,6 +208,7 @@ static u16_t tmp16;
#define FBUF ( ( struct uip_tcpip_hdr * ) &uip_reassbuf[0] )
#define ICMPBUF ( ( struct uip_icmpip_hdr * ) &uip_buf[UIP_LLH_LEN] )
#define UDPBUF ( ( struct uip_udpip_hdr * ) &uip_buf[UIP_LLH_LEN] )
#if UIP_STATISTICS == 1
struct uip_stats uip_stat;
#define UIP_STAT( s ) s
@ -261,12 +254,11 @@ void uip_add32( u8_t *op32, u16_t op16 )
}
}
}
/*---------------------------------------------------------------------------*/
#endif /* UIP_ARCH_ADD32 */
#if !UIP_ARCH_CHKSUM
/*---------------------------------------------------------------------------*/
static u16_t chksum( u16_t sum, const u8_t *data, u16_t len )
{
u16_t t;
@ -277,7 +269,8 @@ static u16_t chksum( u16_t sum, const u8_t *data, u16_t len )
last_byte = data + len - 1;
while( dataptr < last_byte )
{ /* At least two more bytes */
{
/* At least two more bytes */
t = ( dataptr[ 0 ] << 8 ) + dataptr[ 1 ];
sum += t;
if( sum < t )
@ -301,14 +294,14 @@ static u16_t chksum( u16_t sum, const u8_t *data, u16_t len )
/* Return sum in host byte order. */
return sum;
}
/*---------------------------------------------------------------------------*/
u16_t uip_chksum( u16_t *data, u16_t len )
{
return htons( chksum( 0, ( u8_t * ) data, len ) );
}
/*---------------------------------------------------------------------------*/
#ifndef UIP_ARCH_IPCHKSUM
u16_t uip_ipchksum( void )
{
@ -319,10 +312,9 @@ u16_t uip_ipchksum( void )
//DEBUG_PRINTF( "uip_ipchksum: sum 0x%04x\n", sum );
return( sum == 0 ) ? 0xffff : htons( sum );
}
#endif
/*---------------------------------------------------------------------------*/
static u16_t upper_layer_chksum( u8_t proto )
{
u16_t upper_layer_len;
@ -347,33 +339,32 @@ static u16_t upper_layer_chksum( u8_t proto )
return( sum == 0 ) ? 0xffff : htons( sum );
}
/*---------------------------------------------------------------------------*/
#if UIP_CONF_IPV6
u16_t uip_icmp6chksum( void )
{
return upper_layer_chksum( UIP_PROTO_ICMP6 );
}
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/
u16_t uip_tcpchksum( void )
{
return upper_layer_chksum( UIP_PROTO_TCP );
}
/*---------------------------------------------------------------------------*/
#if UIP_UDP_CHECKSUMS
u16_t uip_udpchksum( void )
{
return upper_layer_chksum( UIP_PROTO_UDP );
}
#endif /* UIP_UDP_CHECKSUMS */
#endif /* UIP_ARCH_CHKSUM */
#endif /* UIP_ARCH_CHKSUM */
/*---------------------------------------------------------------------------*/
void uip_init( void )
{
for( c = 0; c < UIP_LISTENPORTS; ++c )
@ -395,7 +386,6 @@ void uip_init( void )
{
uip_udp_conns[ c ].lport = 0;
}
#endif /* UIP_UDP */
/* IPv4 initialization. */
@ -403,8 +393,8 @@ void uip_init( void )
/* uip_hostaddr[ 0 ] = uip_hostaddr[ 1 ] = 0;*/
#endif /* UIP_FIXEDADDR */
}
/*---------------------------------------------------------------------------*/
#if UIP_ACTIVE_OPEN
struct uip_conn *uip_connect( uip_ipaddr_t *ripaddr, u16_t rport )
{
@ -475,10 +465,9 @@ again:
return conn;
}
/*---------------------------------------------------------------------------*/
#endif /* UIP_ACTIVE_OPEN */
/*---------------------------------------------------------------------------*/
#if UIP_UDP
struct uip_udp_conn *uip_udp_new( const uip_ipaddr_t *ripaddr, u16_t rport )
{
@ -531,10 +520,9 @@ again:
return conn;
}
/*---------------------------------------------------------------------------*/
#endif /* UIP_UDP */
/*---------------------------------------------------------------------------*/
void uip_unlisten( u16_t port )
{
for( c = 0; c < UIP_LISTENPORTS; ++c )
@ -546,8 +534,8 @@ void uip_unlisten( u16_t port )
}
}
}
/*---------------------------------------------------------------------------*/
void uip_listen( u16_t port )
{
for( c = 0; c < UIP_LISTENPORTS; ++c )
@ -559,7 +547,6 @@ void uip_listen( u16_t port )
}
}
}
/*---------------------------------------------------------------------------*/
/* XXX: IP fragment reassembly: not well-tested. */
@ -694,12 +681,13 @@ static u8_t uip_reass( void )
}
nullreturn:
return 0;
}
/*---------------------------------------------------------------------------*/
#endif /* UIP_REASSEMBLY */
/*---------------------------------------------------------------------------*/
static void uip_add_rcv_nxt( u16_t n )
{
uip_add32( uip_conn->rcv_nxt, n );
@ -708,8 +696,8 @@ static void uip_add_rcv_nxt( u16_t n )
uip_conn->rcv_nxt[ 2 ] = uip_acc32[ 2 ];
uip_conn->rcv_nxt[ 3 ] = uip_acc32[ 3 ];
}
/*---------------------------------------------------------------------------*/
void uip_process( u8_t flag )
{
register struct uip_conn *uip_connr = uip_conn;
@ -719,7 +707,6 @@ void uip_process( u8_t flag )
{
goto udp_send;
}
#endif /* UIP_UDP */
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
@ -746,7 +733,6 @@ void uip_process( u8_t flag )
{
--uip_reasstmr;
}
#endif /* UIP_REASSEMBLY */
/* Increase the initial sequence number. */
@ -827,7 +813,6 @@ void uip_process( u8_t flag )
goto tcp_send_synack;
#if UIP_ACTIVE_OPEN
case UIP_SYN_SENT:
/* In the SYN_SENT state, we retransmit out SYN. */
BUF->flags = 0;
@ -881,7 +866,6 @@ void uip_process( u8_t flag )
goto drop;
}
}
#endif
/* This is where the input processing starts. */
@ -920,7 +904,7 @@ void uip_process( u8_t flag )
{
uip_len = ( BUF->len[ 0 ] << 8 ) + BUF->len[ 1 ];
#if UIP_CONF_IPV6
uip_len += 40; /* The length reported in the IPv6 header is the
/* The length reported in the IPv6 header is the
length of the payload that follows the
header. However, uIP uses the uip_len variable
for holding the size of the entire packet,
@ -929,6 +913,7 @@ void uip_process( u8_t flag )
contains the length of the entire packet. But
for IPv6 we need to add the size of the IPv6
header (40 bytes). */
uip_len += 40;
#endif /* UIP_CONF_IPV6 */
}
else
@ -947,7 +932,6 @@ void uip_process( u8_t flag )
{
goto drop;
}
#else /* UIP_REASSEMBLY */
UIP_STAT( ++uip_stat.ip.drop );
UIP_STAT( ++uip_stat.ip.fragerr );
@ -955,7 +939,6 @@ void uip_process( u8_t flag )
goto drop;
#endif /* UIP_REASSEMBLY */
}
#endif /* UIP_CONF_IPV6 */
if( uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) )
@ -974,7 +957,6 @@ void uip_process( u8_t flag )
UIP_LOG( "ip: packet dropped since no address assigned." );
goto drop;
}
#endif /* UIP_PINGADDRCONF */
}
else
@ -983,12 +965,10 @@ void uip_process( u8_t flag )
UDP packet, which may be destined to us. */
#if UIP_BROADCAST
//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*/ )
if( BUF->proto == UIP_PROTO_UDP && uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) /*&& uip_ipchksum() == 0xffff*/ )
{
goto udp_input;
}
#endif /* UIP_BROADCAST */
/* Check if the packet is destined for our IP address. */
@ -998,7 +978,6 @@ void uip_process( u8_t flag )
UIP_STAT( ++uip_stat.ip.drop );
goto drop;
}
#else /* UIP_CONF_IPV6 */
/* For IPv6, packet reception is a little trickier as we need to
make sure that we listen to certain multicast addresses (all
@ -1010,26 +989,23 @@ void uip_process( u8_t flag )
UIP_STAT( ++uip_stat.ip.drop );
goto drop;
}
#endif /* UIP_CONF_IPV6 */
}
#if !UIP_CONF_IPV6
if( uip_ipchksum() != 0xffff )
{ /* Compute and check the IP header
checksum. */
{
/* Compute and check the IP header checksum. */
UIP_STAT( ++uip_stat.ip.drop );
UIP_STAT( ++uip_stat.ip.chkerr );
UIP_LOG( "ip: bad checksum." );
goto drop;
}
#endif /* UIP_CONF_IPV6 */
if( BUF->proto == UIP_PROTO_TCP )
{ /* Check for TCP packet. If so,
proceed with TCP input
processing. */
{
/* Check for TCP packet. If so, proceed with TCP input processing. */
goto tcp_input;
}
@ -1038,14 +1014,13 @@ void uip_process( u8_t flag )
{
goto udp_input;
}
#endif /* UIP_UDP */
#if !UIP_CONF_IPV6
/* ICMPv4 processing code follows. */
if( BUF->proto != UIP_PROTO_ICMP )
{ /* We only allow ICMP packets from
here. */
{
/* We only allow ICMP packets from here. */
UIP_STAT( ++uip_stat.ip.drop );
UIP_STAT( ++uip_stat.ip.protoerr );
UIP_LOG( "ip: neither tcp nor icmp." );
@ -1055,6 +1030,7 @@ void uip_process( u8_t flag )
#if UIP_PINGADDRCONF
icmp_input :
#endif /* UIP_PINGADDRCONF */
UIP_STAT( ++uip_stat.icmp.recv );
/* ICMP echo (i.e., ping) processing. This is simple, we only change
@ -1076,7 +1052,6 @@ void uip_process( u8_t flag )
{
uip_hostaddr = BUF->destipaddr;
}
#endif /* UIP_PINGADDRCONF */
ICMPBUF->type = ICMP_ECHO_REPLY;
@ -1099,13 +1074,15 @@ void uip_process( u8_t flag )
goto ip_send_nolen;
/* End of IPv4 input header processing code. */
#else /* !UIP_CONF_IPV6 */
/* This is IPv6 ICMPv6 processing code. */
//DEBUG_PRINTF( "icmp6_input: length %d\n", uip_len );
if( BUF->proto != UIP_PROTO_ICMP6 )
{ /* We only allow ICMPv6 packets from
here. */
{
/* We only allow ICMPv6 packets from here. */
UIP_STAT( ++uip_stat.ip.drop );
UIP_STAT( ++uip_stat.ip.protoerr );
UIP_LOG( "ip: neither tcp nor icmp6." );
@ -1222,7 +1199,9 @@ void uip_process( u8_t flag )
}
UIP_LOG( "udp: no matching connection found" );
#if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6
/* Copy fields from packet header into payload of this ICMP packet. */
memcpy( &(ICMPBUF->payload[ 0 ]), ICMPBUF, UIP_IPH_LEN + 8 );
@ -1299,9 +1278,7 @@ udp_send:
{
UDPBUF->udpchksum = 0xffff;
}
#endif /* UIP_UDP_CHECKSUMS */
goto ip_send_nolen;
#endif /* UIP_UDP */
@ -1310,8 +1287,8 @@ udp_send:
/* Start of TCP input header processing code. */
if( uip_tcpchksum() != 0xffff )
{ /* Compute and check the TCP
checksum. */
{
/* Compute and check the TCP checksum. */
UIP_STAT( ++uip_stat.tcp.drop );
UIP_STAT( ++uip_stat.tcp.chkerr );
UIP_LOG( "tcp: bad checksum." );
@ -1522,7 +1499,6 @@ found_listen:
/* Our response will be a SYNACK. */
#if UIP_ACTIVE_OPEN
tcp_send_synack : BUF->flags = TCP_ACK;
tcp_send_syn:
BUF->flags |= TCP_SYN;
#else /* UIP_ACTIVE_OPEN */
@ -1667,8 +1643,8 @@ found:
}
goto drop;
#if UIP_ACTIVE_OPEN
#if UIP_ACTIVE_OPEN
case UIP_SYN_SENT:
/* In SYN_SENT, we wait for a SYNACK that is sent in response to
our SYN. The rcv_nxt is set to sequence number in the SYNACK
@ -2074,7 +2050,9 @@ tcp_send:
}
tcp_send_noconn:
BUF->ttl = UIP_TTL;
#if UIP_CONF_IPV6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
@ -2110,7 +2088,9 @@ ip_send_nolen:
//DEBUG_PRINTF( "uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */
UIP_STAT( ++uip_stat.tcp.sent );
#if UIP_CONF_IPV6
send :
#endif /* UIP_CONF_IPV6 */
@ -2127,8 +2107,8 @@ drop:
uip_flags = 0;
return;
}
/*---------------------------------------------------------------------------*/
u16_t htons( u16_t val )
{
return HTONS( val );
@ -2138,12 +2118,14 @@ u32_t htonl( u32_t val )
{
return HTONL( val );
}
/*---------------------------------------------------------------------------*/
void uip_send( const void *data, int len )
{
int copylen;
#define MIN( a, b ) ( (a) < (b) ? (a) : (b) )
copylen = MIN( len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN - ( int )
(( char * ) uip_sappdata - ( char * ) &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]) );
if( copylen > 0 )
@ -2155,7 +2137,6 @@ void uip_send( const void *data, int len )
}
}
}
/*---------------------------------------------------------------------------*/
/** @} */

Loading…
Cancel
Save