#include "net/uip_arp.h"\r
#include "net/uip_arch.h"\r
\r
-#if !UIP_CONF_IPV6 /* If UIP_CONF_IPV6 is defined, we compile the\r
- uip6.c file instead of this one. Therefore\r
- this #ifndef removes the entire compilation\r
- output of the uip.c file */\r
+/* If UIP_CONF_IPV6 is defined, we compile the uip6.c file instead of this one.\r
+Therefore this #ifndef removes the entire compilation output of the uip.c file */\r
+#if !UIP_CONF_IPV6\r
\r
#if UIP_CONF_IPV6\r
-#include "net/uip-neighbor.h"\r
+ #include "net/uip-neighbor.h"\r
#endif /* UIP_CONF_IPV6 */\r
\r
#include <string.h>\r
\r
/* Variable definitions. */\r
\r
-/* The IP address of this host. If it is defined to be fixed (by\r
- setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set\r
- here. Otherwise, the address */\r
+/* The IP address of this host. If it is defined to be fixed (by setting\r
+UIP_FIXEDADDR to 1 in uipopt.h), the address is set here. Otherwise, the address */\r
#if UIP_FIXEDADDR > 0\r
-const uip_ipaddr_t uip_hostaddr = { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };\r
-const uip_ipaddr_t uip_draddr = { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };\r
-const uip_ipaddr_t uip_netmask = { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };\r
+ const uip_ipaddr_t uip_hostaddr = { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };\r
+ const uip_ipaddr_t uip_draddr = { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };\r
+ const uip_ipaddr_t uip_netmask = { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };\r
#else\r
-uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;\r
+ uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;\r
#endif /* UIP_FIXEDADDR */\r
\r
const uip_ipaddr_t uip_broadcast_addr =\r
#if UIP_CONF_IPV6\r
-{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };\r
+ { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };\r
#else /* UIP_CONF_IPV6 */\r
-{\r
- {\r
- 0xff, 0xff, 0xff, 0xff\r
- }\r
-};\r
+ { { 0xff, 0xff, 0xff, 0xff } };\r
#endif /* UIP_CONF_IPV6 */\r
-const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };\r
+\r
+const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };\r
\r
#if UIP_FIXEDETHADDR\r
-const struct uip_eth_addr uip_ethaddr = { { UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5 } };\r
+ const struct uip_eth_addr uip_ethaddr = { { UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5 } };\r
#else\r
-struct uip_eth_addr uip_ethaddr = { { 0, 0, 0, 0, 0, 0 } };\r
+ struct uip_eth_addr uip_ethaddr = { { 0, 0, 0, 0, 0, 0 } };\r
#endif\r
+\r
#ifndef UIP_CONF_EXTERNAL_BUFFER\r
-u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains\r
- incoming packets. */\r
+ /* The packet buffer that contains incoming packets. */\r
+ u8_t uip_buf[ UIP_BUFSIZE + 2 ];\r
#endif /* UIP_CONF_EXTERNAL_BUFFER */\r
\r
-void *uip_appdata; /* The uip_appdata pointer points to\r
- application data. */\r
-void *uip_sappdata; /* The uip_appdata pointer points to\r
- the application data which is to\r
- be sent. */\r
+/* The uip_appdata pointer points to application data. */\r
+void *uip_appdata;\r
+\r
+/* The uip_appdata pointer points to the application data which is to be sent. */\r
+void *uip_sappdata;\r
+\r
#if UIP_URGDATA > 0\r
-void *uip_urgdata; /* The uip_urgdata pointer points to\r
- urgent data (out-of-band data), if\r
- present. */\r
-u16_t uip_urglen, uip_surglen;\r
+ /* The uip_urgdata pointer points to urgent data (out-of-band data), if\r
+ present. */\r
+ void *uip_urgdata;\r
+ u16_t uip_urglen, uip_surglen;\r
#endif /* UIP_URGDATA > 0 */\r
\r
-u16_t uip_len, uip_slen;\r
+/* The uip_len is either 8 or 16 bits, depending on the maximum packet size. */\r
+u16_t uip_len, uip_slen;\r
\r
-/* The uip_len is either 8 or 16 bits,\r
- depending on the maximum packet\r
- size. */\r
-u8_t uip_flags; /* The uip_flags variable is used for\r
- communication between the TCP/IP stack\r
- and the application program. */\r
-struct uip_conn *uip_conn; /* uip_conn always points to the current\r
- connection. */\r
+/* The uip_flags variable is used for communication between the TCP/IP stack\r
+and the application program. */\r
+u8_t uip_flags;\r
\r
-struct uip_conn uip_conns[UIP_CONNS];\r
+/* uip_conn always points to the current connection. */\r
+struct uip_conn *uip_conn;\r
+struct uip_conn uip_conns[ UIP_CONNS ];\r
\r
-/* The uip_conns array holds all TCP\r
- connections. */\r
-u16_t uip_listenports[UIP_LISTENPORTS];\r
+/* The uip_conns array holds all TCP connections. */\r
+u16_t uip_listenports[UIP_LISTENPORTS];\r
\r
-/* The uip_listenports list all currently\r
- listning ports. */\r
+/* The uip_listenports list all currently listning ports. */\r
#if UIP_UDP\r
-struct uip_udp_conn *uip_udp_conn;\r
-struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];\r
+ struct uip_udp_conn *uip_udp_conn;\r
+ struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];\r
#endif /* UIP_UDP */\r
\r
-static u16_t ipid; /* Ths ipid variable is an increasing\r
- number that is used for the IP ID\r
- field. */\r
+/* Ths ipid variable is an increasing number that is used for the IP ID field. */\r
+static u16_t ipid;\r
\r
void uip_setipid( u16_t id )\r
{\r
ipid = id;\r
}\r
\r
-static u8_t iss[4]; /* The iss variable is used for the TCP\r
- initial sequence number. */\r
+/* The iss variable is used for the TCP initial sequence number. */\r
+static u8_t iss[ 4 ];\r
\r
#if UIP_ACTIVE_OPEN\r
-static u16_t lastport; /* Keeps track of the last port used for\r
- a new connection. */\r
+ /* Keeps track of the last port used for a new connection. */\r
+ static u16_t lastport;\r
#endif /* UIP_ACTIVE_OPEN */\r
\r
/* Temporary variables. */\r
-u8_t uip_acc32[4];\r
-static u8_t c, opt;\r
-static u16_t tmp16;\r
+u8_t uip_acc32[ 4 ];\r
+static u8_t c, opt;\r
+static u16_t tmp16;\r
\r
/* Structures and definitions. */\r
#define TCP_FIN 0x01\r
#define FBUF ( ( struct uip_tcpip_hdr * ) &uip_reassbuf[0] )\r
#define ICMPBUF ( ( struct uip_icmpip_hdr * ) &uip_buf[UIP_LLH_LEN] )\r
#define UDPBUF ( ( struct uip_udpip_hdr * ) &uip_buf[UIP_LLH_LEN] )\r
+\r
#if UIP_STATISTICS == 1\r
-struct uip_stats uip_stat;\r
-#define UIP_STAT( s ) s\r
+ struct uip_stats uip_stat;\r
+ #define UIP_STAT( s ) s\r
#else\r
-#define UIP_STAT( s )\r
+ #define UIP_STAT( s )\r
#endif /* UIP_STATISTICS == 1 */\r
\r
#if UIP_LOGGING == 1\r
-#include <stdio.h>\r
-void uip_log( char *msg );\r
-#define UIP_LOG( m ) uip_log( m )\r
+ #include <stdio.h>\r
+ void uip_log( char *msg );\r
+ #define UIP_LOG( m ) uip_log( m )\r
#else\r
-#define UIP_LOG( m )\r
+ #define UIP_LOG( m )\r
#endif /* UIP_LOGGING == 1 */\r
\r
#if !UIP_ARCH_ADD32\r
-void uip_add32( u8_t *op32, u16_t op16 )\r
-{\r
- uip_acc32[3] = op32[3] + ( op16 & 0xff );\r
- uip_acc32[2] = op32[2] + ( op16 >> 8 );\r
- uip_acc32[1] = op32[1];\r
- uip_acc32[0] = op32[0];\r
-\r
- if( uip_acc32[2] < (op16 >> 8) )\r
+ void uip_add32( u8_t *op32, u16_t op16 )\r
{\r
- ++uip_acc32[1];\r
- if( uip_acc32[1] == 0 )\r
- {\r
- ++uip_acc32[0];\r
- }\r
- }\r
+ uip_acc32[3] = op32[3] + ( op16 & 0xff );\r
+ uip_acc32[2] = op32[2] + ( op16 >> 8 );\r
+ uip_acc32[1] = op32[1];\r
+ uip_acc32[0] = op32[0];\r
\r
- if( uip_acc32[3] < (op16 & 0xff) )\r
- {\r
- ++uip_acc32[2];\r
- if( uip_acc32[2] == 0 )\r
+ if( uip_acc32[2] < (op16 >> 8) )\r
{\r
++uip_acc32[1];\r
if( uip_acc32[1] == 0 )\r
++uip_acc32[0];\r
}\r
}\r
- }\r
-}\r
\r
+ if( uip_acc32[3] < (op16 & 0xff) )\r
+ {\r
+ ++uip_acc32[2];\r
+ if( uip_acc32[2] == 0 )\r
+ {\r
+ ++uip_acc32[1];\r
+ if( uip_acc32[1] == 0 )\r
+ {\r
+ ++uip_acc32[0];\r
+ }\r
+ }\r
+ }\r
+ }\r
+/*---------------------------------------------------------------------------*/\r
#endif /* UIP_ARCH_ADD32 */\r
\r
#if !UIP_ARCH_CHKSUM\r
\r
-/*---------------------------------------------------------------------------*/\r
-static u16_t chksum( u16_t sum, const u8_t *data, u16_t len )\r
-{\r
- u16_t t;\r
- const u8_t *dataptr;\r
- const u8_t *last_byte;\r
-\r
- dataptr = data;\r
- last_byte = data + len - 1;\r
-\r
- while( dataptr < last_byte )\r
- { /* At least two more bytes */\r
- t = ( dataptr[0] << 8 ) + dataptr[1];\r
- sum += t;\r
- if( sum < t )\r
- {\r
- sum++; /* carry */\r
- }\r
+ static u16_t chksum( u16_t sum, const u8_t *data, u16_t len )\r
+ {\r
+ u16_t t;\r
+ const u8_t *dataptr;\r
+ const u8_t *last_byte;\r
\r
- dataptr += 2;\r
- }\r
+ dataptr = data;\r
+ last_byte = data + len - 1;\r
\r
- if( dataptr == last_byte )\r
- {\r
- t = ( dataptr[0] << 8 ) + 0;\r
- sum += t;\r
- if( sum < t )\r
+ while( dataptr < last_byte )\r
{\r
- sum++; /* carry */\r
- }\r
- }\r
+ /* At least two more bytes */\r
+ t = ( dataptr[ 0 ] << 8 ) + dataptr[ 1 ];\r
+ sum += t;\r
+ if( sum < t )\r
+ {\r
+ sum++; /* carry */\r
+ }\r
\r
- /* Return sum in host byte order. */\r
- return sum;\r
-}\r
+ dataptr += 2;\r
+ }\r
\r
-/*---------------------------------------------------------------------------*/\r
-u16_t uip_chksum( u16_t *data, u16_t len )\r
-{\r
- return htons( chksum(0, ( u8_t * ) data, len) );\r
-}\r
+ if( dataptr == last_byte )\r
+ {\r
+ t = ( dataptr[ 0 ] << 8 ) + 0;\r
+ sum += t;\r
+ if( sum < t )\r
+ {\r
+ sum++; /* carry */\r
+ }\r
+ }\r
\r
-/*---------------------------------------------------------------------------*/\r
-#ifndef UIP_ARCH_IPCHKSUM\r
-u16_t uip_ipchksum( void )\r
-{\r
- u16_t sum;\r
+ /* Return sum in host byte order. */\r
+ return sum;\r
+ }\r
+ /*---------------------------------------------------------------------------*/\r
\r
- sum = chksum( 0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN );\r
+ u16_t uip_chksum( u16_t *data, u16_t len )\r
+ {\r
+ return htons( chksum( 0, ( u8_t * ) data, len ) );\r
+ }\r
+ /*---------------------------------------------------------------------------*/\r
\r
- //DEBUG_PRINTF( "uip_ipchksum: sum 0x%04x\n", sum );\r
- return( sum == 0 ) ? 0xffff : htons( sum );\r
-}\r
+ #ifndef UIP_ARCH_IPCHKSUM\r
+ u16_t uip_ipchksum( void )\r
+ {\r
+ u16_t sum;\r
\r
-#endif\r
+ sum = chksum( 0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN );\r
\r
-/*---------------------------------------------------------------------------*/\r
-static u16_t upper_layer_chksum( u8_t proto )\r
-{\r
- u16_t upper_layer_len;\r
- u16_t sum;\r
+ //DEBUG_PRINTF( "uip_ipchksum: sum 0x%04x\n", sum );\r
+ return( sum == 0 ) ? 0xffff : htons( sum );\r
+ }\r
+ #endif\r
+ /*---------------------------------------------------------------------------*/\r
\r
-#if UIP_CONF_IPV6\r
- upper_layer_len = ( ((u16_t) (BUF->len[0]) << 8) + BUF->len[1] );\r
-#else /* UIP_CONF_IPV6 */\r
- upper_layer_len = ( ((u16_t) (BUF->len[0]) << 8) + BUF->len[1] ) - UIP_IPH_LEN;\r
-#endif /* UIP_CONF_IPV6 */\r
+ static u16_t upper_layer_chksum( u8_t proto )\r
+ {\r
+ u16_t upper_layer_len;\r
+ u16_t sum;\r
\r
- /* First sum pseudoheader. */\r
+ #if UIP_CONF_IPV6\r
+ upper_layer_len = ( ((u16_t) (BUF->len[ 0 ]) << 8) + BUF->len[ 1 ] );\r
+ #else /* UIP_CONF_IPV6 */\r
+ upper_layer_len = ( ((u16_t) (BUF->len[ 0 ]) << 8) + BUF->len[ 1 ] ) - UIP_IPH_LEN;\r
+ #endif /* UIP_CONF_IPV6 */\r
\r
- /* IP protocol and length fields. This addition cannot carry. */\r
- sum = upper_layer_len + proto;\r
+ /* First sum pseudoheader. */\r
\r
- /* Sum IP source and destination addresses. */\r
- sum = chksum( sum, ( u8_t * ) &BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t) );\r
+ /* IP protocol and length fields. This addition cannot carry. */\r
+ sum = upper_layer_len + proto;\r
\r
- /* Sum TCP header and data. */\r
- sum = chksum( sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_len );\r
+ /* Sum IP source and destination addresses. */\r
+ sum = chksum( sum, ( u8_t * ) &BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t) );\r
\r
- return( sum == 0 ) ? 0xffff : htons( sum );\r
-}\r
+ /* Sum TCP header and data. */\r
+ sum = chksum( sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_len );\r
\r
-/*---------------------------------------------------------------------------*/\r
-#if UIP_CONF_IPV6\r
-u16_t uip_icmp6chksum( void )\r
-{\r
- return upper_layer_chksum( UIP_PROTO_ICMP6 );\r
-}\r
+ return( sum == 0 ) ? 0xffff : htons( sum );\r
+ }\r
+ /*---------------------------------------------------------------------------*/\r
\r
-#endif /* UIP_CONF_IPV6 */\r
+ #if UIP_CONF_IPV6\r
+ u16_t uip_icmp6chksum( void )\r
+ {\r
+ return upper_layer_chksum( UIP_PROTO_ICMP6 );\r
+ }\r
+ #endif /* UIP_CONF_IPV6 */\r
+ /*---------------------------------------------------------------------------*/\r
\r
-/*---------------------------------------------------------------------------*/\r
-u16_t uip_tcpchksum( void )\r
-{\r
- return upper_layer_chksum( UIP_PROTO_TCP );\r
-}\r
+ u16_t uip_tcpchksum( void )\r
+ {\r
+ return upper_layer_chksum( UIP_PROTO_TCP );\r
+ }\r
+ /*---------------------------------------------------------------------------*/\r
\r
-/*---------------------------------------------------------------------------*/\r
-#if UIP_UDP_CHECKSUMS\r
-u16_t uip_udpchksum( void )\r
-{\r
- return upper_layer_chksum( UIP_PROTO_UDP );\r
-}\r
+ #if UIP_UDP_CHECKSUMS\r
+ u16_t uip_udpchksum( void )\r
+ {\r
+ return upper_layer_chksum( UIP_PROTO_UDP );\r
+ }\r
+ #endif /* UIP_UDP_CHECKSUMS */\r
\r
-#endif /* UIP_UDP_CHECKSUMS */\r
#endif /* UIP_ARCH_CHKSUM */\r
-\r
/*---------------------------------------------------------------------------*/\r
+\r
void uip_init( void )\r
{\r
for( c = 0; c < UIP_LISTENPORTS; ++c )\r
{\r
- uip_listenports[c] = 0;\r
+ uip_listenports[ c ] = 0;\r
}\r
\r
for( c = 0; c < UIP_CONNS; ++c )\r
{\r
- uip_conns[c].tcpstateflags = UIP_CLOSED;\r
+ uip_conns[ c ].tcpstateflags = UIP_CLOSED;\r
}\r
\r
-#if UIP_ACTIVE_OPEN\r
- lastport = 1024;\r
-#endif /* UIP_ACTIVE_OPEN */\r
-\r
-#if UIP_UDP\r
- for( c = 0; c < UIP_UDP_CONNS; ++c )\r
- {\r
- uip_udp_conns[c].lport = 0;\r
- }\r
+ #if UIP_ACTIVE_OPEN\r
+ lastport = 1024;\r
+ #endif /* UIP_ACTIVE_OPEN */\r
\r
-#endif /* UIP_UDP */\r
+ #if UIP_UDP\r
+ for( c = 0; c < UIP_UDP_CONNS; ++c )\r
+ {\r
+ uip_udp_conns[ c ].lport = 0;\r
+ }\r
+ #endif /* UIP_UDP */\r
\r
/* IPv4 initialization. */\r
-#if UIP_FIXEDADDR == 0\r
- /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/\r
-#endif /* UIP_FIXEDADDR */\r
+ #if UIP_FIXEDADDR == 0\r
+ /* uip_hostaddr[ 0 ] = uip_hostaddr[ 1 ] = 0;*/\r
+ #endif /* UIP_FIXEDADDR */\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
-#if UIP_ACTIVE_OPEN\r
-struct uip_conn *uip_connect( uip_ipaddr_t *ripaddr, u16_t rport )\r
-{\r
- register struct uip_conn *conn, *cconn;\r
\r
- /* Find an unused local port. */\r
-again:\r
- ++lastport;\r
-\r
- if( lastport >= 32000 )\r
+#if UIP_ACTIVE_OPEN\r
+ struct uip_conn *uip_connect( uip_ipaddr_t *ripaddr, u16_t rport )\r
{\r
- lastport = 4096;\r
- }\r
+ register struct uip_conn *conn, *cconn;\r
\r
- /* Check if this port is already in use, and if so try to find\r
- another one. */\r
- for( c = 0; c < UIP_CONNS; ++c )\r
- {\r
- conn = &uip_conns[c];\r
- if( conn->tcpstateflags != UIP_CLOSED && conn->lport == htons(lastport) )\r
+ /* Find an unused local port. */\r
+ again:\r
+ ++lastport;\r
+\r
+ if( lastport >= 32000 )\r
{\r
- goto again;\r
+ lastport = 4096;\r
}\r
- }\r
\r
- conn = 0;\r
- for( c = 0; c < UIP_CONNS; ++c )\r
- {\r
- cconn = &uip_conns[c];\r
- if( cconn->tcpstateflags == UIP_CLOSED )\r
+ /* Check if this port is already in use, and if so try to find\r
+ another one. */\r
+ for( c = 0; c < UIP_CONNS; ++c )\r
{\r
- conn = cconn;\r
- break;\r
+ conn = &uip_conns[ c ];\r
+ if( conn->tcpstateflags != UIP_CLOSED && conn->lport == htons(lastport) )\r
+ {\r
+ goto again;\r
+ }\r
}\r
\r
- if( cconn->tcpstateflags == UIP_TIME_WAIT )\r
+ conn = 0;\r
+ for( c = 0; c < UIP_CONNS; ++c )\r
{\r
- if( conn == 0 || cconn->timer > conn->timer )\r
+ cconn = &uip_conns[ c ];\r
+ if( cconn->tcpstateflags == UIP_CLOSED )\r
{\r
conn = cconn;\r
+ break;\r
}\r
- }\r
- }\r
\r
- if( conn == 0 )\r
- {\r
- return 0;\r
- }\r
+ if( cconn->tcpstateflags == UIP_TIME_WAIT )\r
+ {\r
+ if( conn == 0 || cconn->timer > conn->timer )\r
+ {\r
+ conn = cconn;\r
+ }\r
+ }\r
+ }\r
\r
- conn->tcpstateflags = UIP_SYN_SENT;\r
+ if( conn == 0 )\r
+ {\r
+ return 0;\r
+ }\r
\r
- conn->snd_nxt[0] = iss[0];\r
- conn->snd_nxt[1] = iss[1];\r
- conn->snd_nxt[2] = iss[2];\r
- conn->snd_nxt[3] = iss[3];\r
+ conn->tcpstateflags = UIP_SYN_SENT;\r
\r
- conn->initialmss = conn->mss = UIP_TCP_MSS;\r
+ conn->snd_nxt[ 0 ] = iss[ 0 ];\r
+ conn->snd_nxt[ 1 ] = iss[ 1 ];\r
+ conn->snd_nxt[ 2 ] = iss[ 2 ];\r
+ conn->snd_nxt[ 3 ] = iss[ 3 ];\r
\r
- conn->len = 1; /* TCP length of the SYN is one. */\r
- conn->nrtx = 0;\r
- conn->timer = 1; /* Send the SYN next time around. */\r
- conn->rto = UIP_RTO;\r
- conn->sa = 0;\r
- conn->sv = 16; /* Initial value of the RTT variance. */\r
- conn->lport = htons( lastport );\r
- conn->rport = rport;\r
- uip_ipaddr_copy( &conn->ripaddr, ripaddr );\r
+ conn->initialmss = conn->mss = UIP_TCP_MSS;\r
\r
- return conn;\r
-}\r
+ conn->len = 1; /* TCP length of the SYN is one. */\r
+ conn->nrtx = 0;\r
+ conn->timer = 1; /* Send the SYN next time around. */\r
+ conn->rto = UIP_RTO;\r
+ conn->sa = 0;\r
+ conn->sv = 16; /* Initial value of the RTT variance. */\r
+ conn->lport = htons( lastport );\r
+ conn->rport = rport;\r
+ uip_ipaddr_copy( &conn->ripaddr, ripaddr );\r
\r
+ return conn;\r
+ }\r
+/*---------------------------------------------------------------------------*/\r
#endif /* UIP_ACTIVE_OPEN */\r
\r
-/*---------------------------------------------------------------------------*/\r
#if UIP_UDP\r
-struct uip_udp_conn *uip_udp_new( const uip_ipaddr_t *ripaddr, u16_t rport )\r
-{\r
- register struct uip_udp_conn *conn;\r
-\r
- /* Find an unused local port. */\r
-again:\r
- ++lastport;\r
-\r
- if( lastport >= 32000 )\r
+ struct uip_udp_conn *uip_udp_new( const uip_ipaddr_t *ripaddr, u16_t rport )\r
{\r
- lastport = 4096;\r
- }\r
+ register struct uip_udp_conn *conn;\r
\r
- for( c = 0; c < UIP_UDP_CONNS; ++c )\r
- {\r
- if( uip_udp_conns[c].lport == htons(lastport) )\r
+ /* Find an unused local port. */\r
+ again:\r
+ ++lastport;\r
+\r
+ if( lastport >= 32000 )\r
{\r
- goto again;\r
+ lastport = 4096;\r
}\r
- }\r
\r
- conn = 0;\r
- for( c = 0; c < UIP_UDP_CONNS; ++c )\r
- {\r
- if( uip_udp_conns[c].lport == 0 )\r
+ for( c = 0; c < UIP_UDP_CONNS; ++c )\r
{\r
- conn = &uip_udp_conns[c];\r
- break;\r
+ if( uip_udp_conns[ c ].lport == htons(lastport) )\r
+ {\r
+ goto again;\r
+ }\r
}\r
- }\r
\r
- if( conn == 0 )\r
- {\r
- return 0;\r
- }\r
+ conn = 0;\r
+ for( c = 0; c < UIP_UDP_CONNS; ++c )\r
+ {\r
+ if( uip_udp_conns[ c ].lport == 0 )\r
+ {\r
+ conn = &uip_udp_conns[ c ];\r
+ break;\r
+ }\r
+ }\r
\r
- conn->lport = HTONS( lastport );\r
- conn->rport = rport;\r
- if( ripaddr == NULL )\r
- {\r
- memset( &conn->ripaddr, 0, sizeof(uip_ipaddr_t) );\r
- }\r
- else\r
- {\r
- uip_ipaddr_copy( &conn->ripaddr, ripaddr );\r
- }\r
+ if( conn == 0 )\r
+ {\r
+ return 0;\r
+ }\r
\r
- conn->ttl = UIP_TTL;\r
+ conn->lport = HTONS( lastport );\r
+ conn->rport = rport;\r
+ if( ripaddr == NULL )\r
+ {\r
+ memset( &conn->ripaddr, 0, sizeof(uip_ipaddr_t) );\r
+ }\r
+ else\r
+ {\r
+ uip_ipaddr_copy( &conn->ripaddr, ripaddr );\r
+ }\r
\r
- return conn;\r
-}\r
+ conn->ttl = UIP_TTL;\r
\r
+ return conn;\r
+ }\r
+/*---------------------------------------------------------------------------*/\r
#endif /* UIP_UDP */\r
\r
-/*---------------------------------------------------------------------------*/\r
void uip_unlisten( u16_t port )\r
{\r
for( c = 0; c < UIP_LISTENPORTS; ++c )\r
{\r
- if( uip_listenports[c] == port )\r
+ if( uip_listenports[ c ] == port )\r
{\r
- uip_listenports[c] = 0;\r
+ uip_listenports[ c ] = 0;\r
return;\r
}\r
}\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
+\r
void uip_listen( u16_t port )\r
{\r
for( c = 0; c < UIP_LISTENPORTS; ++c )\r
{\r
- if( uip_listenports[c] == 0 )\r
+ if( uip_listenports[ c ] == 0 )\r
{\r
- uip_listenports[c] = port;\r
+ uip_listenports[ c ] = port;\r
return;\r
}\r
}\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
\r
/* XXX: IP fragment reassembly: not well-tested. */\r
#if UIP_REASSEMBLY && !UIP_CONF_IPV6\r
-#define UIP_REASS_BUFSIZE ( UIP_BUFSIZE - UIP_LLH_LEN )\r
-static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];\r
-static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / ( 8 * 8 )];\r
-static const u8_t bitmap_bits[8] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };\r
-static u16_t uip_reasslen;\r
-static u8_t uip_reassflags;\r
-#define UIP_REASS_FLAG_LASTFRAG 0x01\r
-static u8_t uip_reasstmr;\r
-\r
-#define IP_MF 0x20\r
-\r
-static u8_t uip_reass( void )\r
-{\r
- u16_t offset, len;\r
- u16_t i;\r
-\r
- /* If ip_reasstmr is zero, no packet is present in the buffer, so we\r
- write the IP header of the fragment into the reassembly\r
- buffer. The timer is updated with the maximum age. */\r
- if( uip_reasstmr == 0 )\r
- {\r
- memcpy( uip_reassbuf, &BUF->vhl, UIP_IPH_LEN );\r
- uip_reasstmr = UIP_REASS_MAXAGE;\r
- uip_reassflags = 0;\r
-\r
- /* Clear the bitmap. */\r
- memset( uip_reassbitmap, 0, sizeof(uip_reassbitmap) );\r
- }\r
-\r
- /* Check if the incoming fragment matches the one currently present\r
- in the reasembly buffer. If so, we proceed with copying the\r
- fragment into the buffer. */\r
- if\r
- (\r
- BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&\r
- BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&\r
- BUF->destipaddr[0] == FBUF->destipaddr[0] &&\r
- BUF->destipaddr[1] == FBUF->destipaddr[1] &&\r
- BUF->ipid[0] == FBUF->ipid[0] &&\r
- BUF->ipid[1] == FBUF->ipid[1]\r
- )\r
+ #define UIP_REASS_BUFSIZE ( UIP_BUFSIZE - UIP_LLH_LEN )\r
+ static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];\r
+ static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / ( 8 * 8 )];\r
+ static const u8_t bitmap_bits[8] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };\r
+ static u16_t uip_reasslen;\r
+ static u8_t uip_reassflags;\r
+ #define UIP_REASS_FLAG_LASTFRAG 0x01\r
+ static u8_t uip_reasstmr;\r
+\r
+ #define IP_MF 0x20\r
+\r
+ static u8_t uip_reass( void )\r
{\r
- len = ( BUF->len[0] << 8 ) + BUF->len[1] - ( BUF->vhl & 0x0f ) * 4;\r
- offset = ( ((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1] ) * 8;\r
+ u16_t offset, len;\r
+ u16_t i;\r
\r
- /* If the offset or the offset + fragment length overflows the\r
- reassembly buffer, we discard the entire packet. */\r
- if( offset > UIP_REASS_BUFSIZE || offset + len > UIP_REASS_BUFSIZE )\r
+ /* If ip_reasstmr is zero, no packet is present in the buffer, so we\r
+ write the IP header of the fragment into the reassembly\r
+ buffer. The timer is updated with the maximum age. */\r
+ if( uip_reasstmr == 0 )\r
{\r
- uip_reasstmr = 0;\r
- goto nullreturn;\r
- }\r
-\r
- /* Copy the fragment into the reassembly buffer, at the right\r
- offset. */\r
- memcpy( &uip_reassbuf[UIP_IPH_LEN + offset], ( char * ) BUF + ( int ) ((BUF->vhl & 0x0f) * 4), len );\r
+ memcpy( uip_reassbuf, &BUF->vhl, UIP_IPH_LEN );\r
+ uip_reasstmr = UIP_REASS_MAXAGE;\r
+ uip_reassflags = 0;\r
\r
- /* Update the bitmap. */\r
- if( offset / (8 * 8) == (offset + len) / (8 * 8) )\r
- {\r
- /* If the two endpoints are in the same byte, we only update\r
- that byte. */\r
- uip_reassbitmap[offset / ( 8 * 8 )] |= bitmap_bits[( offset / 8 ) & 7] &~bitmap_bits[( (offset + len) / 8 ) & 7];\r
+ /* Clear the bitmap. */\r
+ memset( uip_reassbitmap, 0, sizeof(uip_reassbitmap) );\r
}\r
- else\r
+\r
+ /* Check if the incoming fragment matches the one currently present\r
+ in the reasembly buffer. If so, we proceed with copying the\r
+ fragment into the buffer. */\r
+ if\r
+ (\r
+ BUF->srcipaddr[ 0 ] == FBUF->srcipaddr[ 0 ] &&\r
+ BUF->srcipaddr[ 1 ] == FBUF->srcipaddr[ 1 ] &&\r
+ BUF->destipaddr[ 0 ] == FBUF->destipaddr[ 0 ] &&\r
+ BUF->destipaddr[ 1 ] == FBUF->destipaddr[ 1 ] &&\r
+ BUF->ipid[ 0 ] == FBUF->ipid[ 0 ] &&\r
+ BUF->ipid[ 1 ] == FBUF->ipid[ 1 ]\r
+ )\r
{\r
- /* If the two endpoints are in different bytes, we update the\r
- bytes in the endpoints and fill the stuff inbetween with\r
- 0xff. */\r
- uip_reassbitmap[offset / ( 8 * 8 )] |= bitmap_bits[( offset / 8 ) & 7];\r
- for( i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i )\r
+ len = ( BUF->len[ 0 ] << 8 ) + BUF->len[ 1 ] - ( BUF->vhl & 0x0f ) * 4;\r
+ offset = ( ((BUF->ipoffset[ 0 ] & 0x3f) << 8) + BUF->ipoffset[ 1 ] ) * 8;\r
+\r
+ /* If the offset or the offset + fragment length overflows the\r
+ reassembly buffer, we discard the entire packet. */\r
+ if( offset > UIP_REASS_BUFSIZE || offset + len > UIP_REASS_BUFSIZE )\r
{\r
- uip_reassbitmap[i] = 0xff;\r
+ uip_reasstmr = 0;\r
+ goto nullreturn;\r
}\r
\r
- uip_reassbitmap[( offset + len ) / ( 8 * 8 )] |= ~bitmap_bits[( (offset + len) / 8 ) & 7];\r
- }\r
+ /* Copy the fragment into the reassembly buffer, at the right\r
+ offset. */\r
+ memcpy( &uip_reassbuf[UIP_IPH_LEN + offset], ( char * ) BUF + ( int ) ((BUF->vhl & 0x0f) * 4), len );\r
\r
- /* If this fragment has the More Fragments flag set to zero, we\r
- know that this is the last fragment, so we can calculate the\r
- size of the entire packet. We also set the\r
- IP_REASS_FLAG_LASTFRAG flag to indicate that we have received\r
- the final fragment. */\r
- if( (BUF->ipoffset[0] & IP_MF) == 0 )\r
- {\r
- uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;\r
- uip_reasslen = offset + len;\r
- }\r
-\r
- /* Finally, we check if we have a full packet in the buffer. We do\r
- this by checking if we have the last fragment and if all bits\r
- in the bitmap are set. */\r
- if( uip_reassflags & UIP_REASS_FLAG_LASTFRAG )\r
- {\r
- /* Check all bytes up to and including all but the last byte in\r
- the bitmap. */\r
- for( i = 0; i < uip_reasslen / (8 * 8) - 1; ++i )\r
+ /* Update the bitmap. */\r
+ if( offset / (8 * 8) == (offset + len) / (8 * 8) )\r
{\r
- if( uip_reassbitmap[i] != 0xff )\r
+ /* If the two endpoints are in the same byte, we only update\r
+ that byte. */\r
+ uip_reassbitmap[offset / ( 8 * 8 )] |= bitmap_bits[( offset / 8 ) & 7] &~bitmap_bits[( (offset + len) / 8 ) & 7];\r
+ }\r
+ else\r
+ {\r
+ /* If the two endpoints are in different bytes, we update the\r
+ bytes in the endpoints and fill the stuff inbetween with\r
+ 0xff. */\r
+ uip_reassbitmap[offset / ( 8 * 8 )] |= bitmap_bits[( offset / 8 ) & 7];\r
+ for( i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i )\r
{\r
- goto nullreturn;\r
+ uip_reassbitmap[i] = 0xff;\r
}\r
+\r
+ uip_reassbitmap[( offset + len ) / ( 8 * 8 )] |= ~bitmap_bits[( (offset + len) / 8 ) & 7];\r
}\r
\r
- /* Check the last byte in the bitmap. It should contain just the\r
- right amount of bits. */\r
- if( uip_reassbitmap[uip_reasslen / (8 * 8)] != (u8_t)~bitmap_bits[uip_reasslen / 8 & 7] )\r
+ /* If this fragment has the More Fragments flag set to zero, we\r
+ know that this is the last fragment, so we can calculate the\r
+ size of the entire packet. We also set the\r
+ IP_REASS_FLAG_LASTFRAG flag to indicate that we have received\r
+ the final fragment. */\r
+ if( (BUF->ipoffset[ 0 ] & IP_MF) == 0 )\r
{\r
- goto nullreturn;\r
+ uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;\r
+ uip_reasslen = offset + len;\r
}\r
\r
- /* If we have come this far, we have a full packet in the\r
- buffer, so we allocate a pbuf and copy the packet into it. We\r
- also reset the timer. */\r
- uip_reasstmr = 0;\r
- memcpy( BUF, FBUF, uip_reasslen );\r
-\r
- /* Pretend to be a "normal" (i.e., not fragmented) IP packet\r
- from now on. */\r
- BUF->ipoffset[0] = BUF->ipoffset[1] = 0;\r
- BUF->len[0] = uip_reasslen >> 8;\r
- BUF->len[1] = uip_reasslen & 0xff;\r
- BUF->ipchksum = 0;\r
- BUF->ipchksum = ~( uip_ipchksum() );\r
-\r
- return uip_reasslen;\r
+ /* Finally, we check if we have a full packet in the buffer. We do\r
+ this by checking if we have the last fragment and if all bits\r
+ in the bitmap are set. */\r
+ if( uip_reassflags & UIP_REASS_FLAG_LASTFRAG )\r
+ {\r
+ /* Check all bytes up to and including all but the last byte in\r
+ the bitmap. */\r
+ for( i = 0; i < uip_reasslen / (8 * 8) - 1; ++i )\r
+ {\r
+ if( uip_reassbitmap[i] != 0xff )\r
+ {\r
+ goto nullreturn;\r
+ }\r
+ }\r
+\r
+ /* Check the last byte in the bitmap. It should contain just the\r
+ right amount of bits. */\r
+ if( uip_reassbitmap[uip_reasslen / (8 * 8)] != (u8_t)~bitmap_bits[uip_reasslen / 8 & 7] )\r
+ {\r
+ goto nullreturn;\r
+ }\r
+\r
+ /* If we have come this far, we have a full packet in the\r
+ buffer, so we allocate a pbuf and copy the packet into it. We\r
+ also reset the timer. */\r
+ uip_reasstmr = 0;\r
+ memcpy( BUF, FBUF, uip_reasslen );\r
+\r
+ /* Pretend to be a "normal" (i.e., not fragmented) IP packet\r
+ from now on. */\r
+ BUF->ipoffset[ 0 ] = BUF->ipoffset[ 1 ] = 0;\r
+ BUF->len[ 0 ] = uip_reasslen >> 8;\r
+ BUF->len[ 1 ] = uip_reasslen & 0xff;\r
+ BUF->ipchksum = 0;\r
+ BUF->ipchksum = ~( uip_ipchksum() );\r
+\r
+ return uip_reasslen;\r
+ }\r
}\r
- }\r
\r
-nullreturn:\r
- return 0;\r
-}\r
+ nullreturn:\r
\r
+ return 0;\r
+ }\r
+/*---------------------------------------------------------------------------*/\r
#endif /* UIP_REASSEMBLY */\r
\r
-/*---------------------------------------------------------------------------*/\r
+\r
static void uip_add_rcv_nxt( u16_t n )\r
{\r
uip_add32( uip_conn->rcv_nxt, n );\r
- uip_conn->rcv_nxt[0] = uip_acc32[0];\r
- uip_conn->rcv_nxt[1] = uip_acc32[1];\r
- uip_conn->rcv_nxt[2] = uip_acc32[2];\r
- uip_conn->rcv_nxt[3] = uip_acc32[3];\r
+ uip_conn->rcv_nxt[ 0 ] = uip_acc32[ 0 ];\r
+ uip_conn->rcv_nxt[ 1 ] = uip_acc32[ 1 ];\r
+ uip_conn->rcv_nxt[ 2 ] = uip_acc32[ 2 ];\r
+ uip_conn->rcv_nxt[ 3 ] = uip_acc32[ 3 ];\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
+\r
void uip_process( u8_t flag )\r
{\r
register struct uip_conn *uip_connr = uip_conn;\r
\r
-#if UIP_UDP\r
- if( flag == UIP_UDP_SEND_CONN )\r
- {\r
- goto udp_send;\r
- }\r
-\r
-#endif /* UIP_UDP */\r
+ #if UIP_UDP\r
+ if( flag == UIP_UDP_SEND_CONN )\r
+ {\r
+ goto udp_send;\r
+ }\r
+ #endif /* UIP_UDP */\r
\r
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];\r
\r
}\r
else if( flag == UIP_TIMER )\r
{\r
-#if UIP_REASSEMBLY\r
- if( uip_reasstmr != 0 )\r
- {\r
- --uip_reasstmr;\r
- }\r
-\r
-#endif /* UIP_REASSEMBLY */\r
+ #if UIP_REASSEMBLY\r
+ if( uip_reasstmr != 0 )\r
+ {\r
+ --uip_reasstmr;\r
+ }\r
+ #endif /* UIP_REASSEMBLY */\r
\r
/* Increase the initial sequence number. */\r
- if( ++iss[3] == 0 )\r
+ if( ++iss[ 3 ] == 0 )\r
{\r
- if( ++iss[2] == 0 )\r
+ if( ++iss[ 2 ] == 0 )\r
{\r
- if( ++iss[1] == 0 )\r
+ if( ++iss[ 1 ] == 0 )\r
{\r
- ++iss[0];\r
+ ++iss[ 0 ];\r
}\r
}\r
}\r
/* If the connection has outstanding data, we increase the\r
connection's timer and see if it has reached the RTO value\r
in which case we retransmit. */\r
- if( uip_outstanding(uip_connr) )\r
+ if( uip_outstanding(uip_connr) )\r
{\r
if( uip_connr->timer-- == 0 )\r
{\r
/* We call UIP_APPCALL() with uip_flags set to\r
UIP_TIMEDOUT to inform the application that the\r
connection has timed out. */\r
- uip_flags = UIP_TIMEDOUT;\r
+ uip_flags = UIP_TIMEDOUT;\r
UIP_APPCALL();\r
\r
/* We also send a reset packet to the remote host. */\r
SYNACK. */\r
goto tcp_send_synack;\r
\r
- #if UIP_ACTIVE_OPEN\r
-\r
- case UIP_SYN_SENT:\r
- /* In the SYN_SENT state, we retransmit out SYN. */\r
- BUF->flags = 0;\r
- goto tcp_send_syn;\r
- #endif /* UIP_ACTIVE_OPEN */\r
+ #if UIP_ACTIVE_OPEN\r
+ case UIP_SYN_SENT:\r
+ /* In the SYN_SENT state, we retransmit out SYN. */\r
+ BUF->flags = 0;\r
+ goto tcp_send_syn;\r
+ #endif /* UIP_ACTIVE_OPEN */\r
\r
case UIP_ESTABLISHED:\r
/* In the ESTABLISHED state, we call upon the application\r
goto drop;\r
}\r
\r
-#if UIP_UDP\r
- if( flag == UIP_UDP_TIMER )\r
- {\r
- if( uip_udp_conn->lport != 0 )\r
+ #if UIP_UDP\r
+ if( flag == UIP_UDP_TIMER )\r
{\r
- uip_conn = NULL;\r
- uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
- uip_len = uip_slen = 0;\r
- uip_flags = UIP_POLL;\r
- UIP_UDP_APPCALL();\r
- goto udp_send;\r
- }\r
- else\r
- {\r
- goto drop;\r
+ if( uip_udp_conn->lport != 0 )\r
+ {\r
+ uip_conn = NULL;\r
+ uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+ uip_len = uip_slen = 0;\r
+ uip_flags = UIP_POLL;\r
+ UIP_UDP_APPCALL();\r
+ goto udp_send;\r
+ }\r
+ else\r
+ {\r
+ goto drop;\r
+ }\r
}\r
- }\r
-\r
-#endif\r
+ #endif\r
\r
/* This is where the input processing starts. */\r
UIP_STAT( ++uip_stat.ip.recv );\r
\r
/* Start of IP input header processing code. */\r
-#if UIP_CONF_IPV6\r
- /* Check validity of the IP header. */\r
- if( (BUF->vtc & 0xf0) != 0x60 )\r
- { /* IP version and header length. */\r
- UIP_STAT( ++uip_stat.ip.drop );\r
- UIP_STAT( ++uip_stat.ip.vhlerr );\r
- UIP_LOG( "ipv6: invalid version." );\r
- goto drop;\r
- }\r
+ #if UIP_CONF_IPV6\r
+ /* Check validity of the IP header. */\r
+ if( (BUF->vtc & 0xf0) != 0x60 )\r
+ { /* IP version and header length. */\r
+ UIP_STAT( ++uip_stat.ip.drop );\r
+ UIP_STAT( ++uip_stat.ip.vhlerr );\r
+ UIP_LOG( "ipv6: invalid version." );\r
+ goto drop;\r
+ }\r
\r
-#else /* UIP_CONF_IPV6 */\r
- /* Check validity of the IP header. */\r
- if( BUF->vhl != 0x45 )\r
- { /* IP version and header length. */\r
- UIP_STAT( ++uip_stat.ip.drop );\r
- UIP_STAT( ++uip_stat.ip.vhlerr );\r
- UIP_LOG( "ip: invalid version or header length." );\r
- goto drop;\r
- }\r
+ #else /* UIP_CONF_IPV6 */\r
+ /* Check validity of the IP header. */\r
+ if( BUF->vhl != 0x45 )\r
+ { /* IP version and header length. */\r
+ UIP_STAT( ++uip_stat.ip.drop );\r
+ UIP_STAT( ++uip_stat.ip.vhlerr );\r
+ UIP_LOG( "ip: invalid version or header length." );\r
+ goto drop;\r
+ }\r
\r
-#endif /* UIP_CONF_IPV6 */\r
+ #endif /* UIP_CONF_IPV6 */\r
\r
/* Check the size of the packet. If the size reported to us in\r
uip_len is smaller the size reported in the IP header, we assume\r
uip_len is larger than the size reported in the IP packet header,\r
the packet has been padded and we set uip_len to the correct\r
value.. */\r
- if( (BUF->len[0] << 8) + BUF->len[1] <= uip_len )\r
+ if( (BUF->len[ 0 ] << 8) + BUF->len[ 1 ] <= uip_len )\r
{\r
- uip_len = ( BUF->len[0] << 8 ) + BUF->len[1];\r
-#if UIP_CONF_IPV6\r
- uip_len += 40; /* The length reported in the IPv6 header is the\r
- length of the payload that follows the\r
- header. However, uIP uses the uip_len variable\r
- for holding the size of the entire packet,\r
- including the IP header. For IPv4 this is not a\r
- problem as the length field in the IPv4 header\r
- contains the length of the entire packet. But\r
- for IPv6 we need to add the size of the IPv6\r
- header (40 bytes). */\r
-#endif /* UIP_CONF_IPV6 */\r
+ uip_len = ( BUF->len[ 0 ] << 8 ) + BUF->len[ 1 ];\r
+ #if UIP_CONF_IPV6\r
+ /* The length reported in the IPv6 header is the\r
+ length of the payload that follows the\r
+ header. However, uIP uses the uip_len variable\r
+ for holding the size of the entire packet,\r
+ including the IP header. For IPv4 this is not a\r
+ problem as the length field in the IPv4 header\r
+ contains the length of the entire packet. But\r
+ for IPv6 we need to add the size of the IPv6\r
+ header (40 bytes). */\r
+ uip_len += 40;\r
+ #endif /* UIP_CONF_IPV6 */\r
}\r
else\r
{\r
goto drop;\r
}\r
\r
-#if !UIP_CONF_IPV6\r
- /* Check the fragment flag. */\r
- if( (BUF->ipoffset[0] & 0x3f) != 0 || BUF->ipoffset[1] != 0 )\r
- {\r
-#if UIP_REASSEMBLY\r
- uip_len = uip_reass();\r
- if( uip_len == 0 )\r
+ #if !UIP_CONF_IPV6\r
+ /* Check the fragment flag. */\r
+ if( (BUF->ipoffset[ 0 ] & 0x3f) != 0 || BUF->ipoffset[ 1 ] != 0 )\r
{\r
- goto drop;\r
+ #if UIP_REASSEMBLY\r
+ uip_len = uip_reass();\r
+ if( uip_len == 0 )\r
+ {\r
+ goto drop;\r
+ }\r
+ #else /* UIP_REASSEMBLY */\r
+ UIP_STAT( ++uip_stat.ip.drop );\r
+ UIP_STAT( ++uip_stat.ip.fragerr );\r
+ UIP_LOG( "ip: fragment dropped." );\r
+ goto drop;\r
+ #endif /* UIP_REASSEMBLY */\r
}\r
-\r
-#else /* UIP_REASSEMBLY */\r
- UIP_STAT( ++uip_stat.ip.drop );\r
- UIP_STAT( ++uip_stat.ip.fragerr );\r
- UIP_LOG( "ip: fragment dropped." );\r
- goto drop;\r
-#endif /* UIP_REASSEMBLY */\r
- }\r
-\r
-#endif /* UIP_CONF_IPV6 */\r
+ #endif /* UIP_CONF_IPV6 */\r
\r
if( uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) )\r
{\r
/* If we are configured to use ping IP address configuration and\r
- hasn't been assigned an IP address yet, we accept all ICMP\r
- packets. */\r
-#if UIP_PINGADDRCONF && !UIP_CONF_IPV6\r
- if( BUF->proto == UIP_PROTO_ICMP )\r
- {\r
- UIP_LOG( "ip: possible ping config packet received." );\r
- goto icmp_input;\r
- }\r
- else\r
- {\r
- UIP_LOG( "ip: packet dropped since no address assigned." );\r
- goto drop;\r
- }\r
-\r
-#endif /* UIP_PINGADDRCONF */\r
+ hasn't been assigned an IP address yet, we accept all ICMP\r
+ packets. */\r
+ #if UIP_PINGADDRCONF && !UIP_CONF_IPV6\r
+ if( BUF->proto == UIP_PROTO_ICMP )\r
+ {\r
+ UIP_LOG( "ip: possible ping config packet received." );\r
+ goto icmp_input;\r
+ }\r
+ else\r
+ {\r
+ UIP_LOG( "ip: packet dropped since no address assigned." );\r
+ goto drop;\r
+ }\r
+ #endif /* UIP_PINGADDRCONF */\r
}\r
else\r
{\r
/* If IP broadcast support is configured, we check for a broadcast\r
- UDP packet, which may be destined to us. */\r
-#if UIP_BROADCAST\r
- //DEBUG_PRINTF( "UDP IP checksum 0x%04x\n", uip_ipchksum() );\r
- if( BUF->proto == UIP_PROTO_UDP && uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) /*&&\r
- uip_ipchksum() == 0xffff*/ )\r
- {\r
- goto udp_input;\r
- }\r
-\r
-#endif /* UIP_BROADCAST */\r
+ UDP packet, which may be destined to us. */\r
+ #if UIP_BROADCAST\r
+ //DEBUG_PRINTF( "UDP IP checksum 0x%04x\n", uip_ipchksum() );\r
+ if( BUF->proto == UIP_PROTO_UDP && uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) /*&& uip_ipchksum() == 0xffff*/ )\r
+ {\r
+ goto udp_input;\r
+ }\r
+ #endif /* UIP_BROADCAST */\r
\r
/* Check if the packet is destined for our IP address. */\r
-#if !UIP_CONF_IPV6\r
- if( !uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) )\r
+ #if !UIP_CONF_IPV6\r
+ if( !uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) )\r
+ {\r
+ UIP_STAT( ++uip_stat.ip.drop );\r
+ goto drop;\r
+ }\r
+ #else /* UIP_CONF_IPV6 */\r
+ /* For IPv6, packet reception is a little trickier as we need to\r
+ make sure that we listen to certain multicast addresses (all\r
+ hosts multicast address, and the solicited-node multicast\r
+ address) as well. However, we will cheat here and accept all\r
+ multicast packets that are sent to the ff02::/16 addresses. */\r
+ if( !uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) && BUF->destipaddr.u16[ 0 ] != HTONS(0xff02) )\r
+ {\r
+ UIP_STAT( ++uip_stat.ip.drop );\r
+ goto drop;\r
+ }\r
+ #endif /* UIP_CONF_IPV6 */\r
+ }\r
+\r
+ #if !UIP_CONF_IPV6\r
+ if( uip_ipchksum() != 0xffff )\r
{\r
+ /* Compute and check the IP header checksum. */\r
UIP_STAT( ++uip_stat.ip.drop );\r
+ UIP_STAT( ++uip_stat.ip.chkerr );\r
+ UIP_LOG( "ip: bad checksum." );\r
goto drop;\r
}\r
+ #endif /* UIP_CONF_IPV6 */\r
\r
-#else /* UIP_CONF_IPV6 */\r
- /* For IPv6, packet reception is a little trickier as we need to\r
- make sure that we listen to certain multicast addresses (all\r
- hosts multicast address, and the solicited-node multicast\r
- address) as well. However, we will cheat here and accept all\r
- multicast packets that are sent to the ff02::/16 addresses. */\r
- if( !uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) && BUF->destipaddr.u16[0] != HTONS(0xff02) )\r
+ if( BUF->proto == UIP_PROTO_TCP )\r
+ {\r
+ /* Check for TCP packet. If so, proceed with TCP input processing. */\r
+ goto tcp_input;\r
+ }\r
+\r
+ #if UIP_UDP\r
+ if( BUF->proto == UIP_PROTO_UDP )\r
{\r
+ goto udp_input;\r
+ }\r
+ #endif /* UIP_UDP */\r
+\r
+ #if !UIP_CONF_IPV6\r
+ /* ICMPv4 processing code follows. */\r
+ if( BUF->proto != UIP_PROTO_ICMP )\r
+ {\r
+ /* We only allow ICMP packets from here. */\r
UIP_STAT( ++uip_stat.ip.drop );\r
+ UIP_STAT( ++uip_stat.ip.protoerr );\r
+ UIP_LOG( "ip: neither tcp nor icmp." );\r
goto drop;\r
}\r
\r
-#endif /* UIP_CONF_IPV6 */\r
- }\r
+ #if UIP_PINGADDRCONF\r
+ icmp_input :\r
+ #endif /* UIP_PINGADDRCONF */\r
\r
-#if !UIP_CONF_IPV6\r
- if( uip_ipchksum() != 0xffff )\r
- { /* Compute and check the IP header\r
- checksum. */\r
- UIP_STAT( ++uip_stat.ip.drop );\r
- UIP_STAT( ++uip_stat.ip.chkerr );\r
- UIP_LOG( "ip: bad checksum." );\r
- goto drop;\r
- }\r
+ UIP_STAT( ++uip_stat.icmp.recv );\r
\r
-#endif /* UIP_CONF_IPV6 */\r
+ /* ICMP echo (i.e., ping) processing. This is simple, we only change\r
+ the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP\r
+ checksum before we return the packet. */\r
+ if( ICMPBUF->type != ICMP_ECHO )\r
+ {\r
+ UIP_STAT( ++uip_stat.icmp.drop );\r
+ UIP_STAT( ++uip_stat.icmp.typeerr );\r
+ UIP_LOG( "icmp: not icmp echo." );\r
+ goto drop;\r
+ }\r
\r
- if( BUF->proto == UIP_PROTO_TCP )\r
- { /* Check for TCP packet. If so,\r
- proceed with TCP input\r
- processing. */\r
- goto tcp_input;\r
- }\r
+ /* If we are configured to use ping IP address assignment, we use\r
+ the destination IP address of this ping packet and assign it to\r
+ ourself. */\r
+ #if UIP_PINGADDRCONF\r
+ if( uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) )\r
+ {\r
+ uip_hostaddr = BUF->destipaddr;\r
+ }\r
+ #endif /* UIP_PINGADDRCONF */\r
\r
-#if UIP_UDP\r
- if( BUF->proto == UIP_PROTO_UDP )\r
- {\r
- goto udp_input;\r
- }\r
+ ICMPBUF->type = ICMP_ECHO_REPLY;\r
\r
-#endif /* UIP_UDP */\r
+ if( ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8)) )\r
+ {\r
+ ICMPBUF->icmpchksum += HTONS( ICMP_ECHO << 8 ) + 1;\r
+ }\r
+ else\r
+ {\r
+ ICMPBUF->icmpchksum += HTONS( ICMP_ECHO << 8 );\r
+ }\r
\r
-#if !UIP_CONF_IPV6\r
- /* ICMPv4 processing code follows. */\r
- if( BUF->proto != UIP_PROTO_ICMP )\r
- { /* We only allow ICMP packets from\r
- here. */\r
- UIP_STAT( ++uip_stat.ip.drop );\r
- UIP_STAT( ++uip_stat.ip.protoerr );\r
- UIP_LOG( "ip: neither tcp nor icmp." );\r
- goto drop;\r
- }\r
+ /* Swap IP addresses. */\r
+ uip_ipaddr_copy( &BUF->destipaddr, &BUF->srcipaddr );\r
+ uip_ipaddr_copy( &BUF->srcipaddr, &uip_hostaddr );\r
\r
-#if UIP_PINGADDRCONF\r
- icmp_input :\r
-#endif /* UIP_PINGADDRCONF */\r
- UIP_STAT( ++uip_stat.icmp.recv );\r
+ UIP_STAT( ++uip_stat.icmp.sent );\r
+ BUF->ttl = UIP_TTL;\r
+ goto ip_send_nolen;\r
\r
- /* ICMP echo (i.e., ping) processing. This is simple, we only change\r
- the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP\r
- checksum before we return the packet. */\r
- if( ICMPBUF->type != ICMP_ECHO )\r
- {\r
- UIP_STAT( ++uip_stat.icmp.drop );\r
- UIP_STAT( ++uip_stat.icmp.typeerr );\r
- UIP_LOG( "icmp: not icmp echo." );\r
- goto drop;\r
- }\r
+ /* End of IPv4 input header processing code. */\r
\r
- /* If we are configured to use ping IP address assignment, we use\r
- the destination IP address of this ping packet and assign it to\r
- ourself. */\r
-#if UIP_PINGADDRCONF\r
- if( uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) )\r
- {\r
- uip_hostaddr = BUF->destipaddr;\r
- }\r
+ #else /* !UIP_CONF_IPV6 */\r
\r
-#endif /* UIP_PINGADDRCONF */\r
+ /* This is IPv6 ICMPv6 processing code. */\r
\r
- ICMPBUF->type = ICMP_ECHO_REPLY;\r
+ //DEBUG_PRINTF( "icmp6_input: length %d\n", uip_len );\r
+ if( BUF->proto != UIP_PROTO_ICMP6 )\r
+ {\r
+ /* We only allow ICMPv6 packets from here. */\r
+ UIP_STAT( ++uip_stat.ip.drop );\r
+ UIP_STAT( ++uip_stat.ip.protoerr );\r
+ UIP_LOG( "ip: neither tcp nor icmp6." );\r
+ goto drop;\r
+ }\r
\r
- if( ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8)) )\r
- {\r
- ICMPBUF->icmpchksum += HTONS( ICMP_ECHO << 8 ) + 1;\r
- }\r
- else\r
- {\r
- ICMPBUF->icmpchksum += HTONS( ICMP_ECHO << 8 );\r
- }\r
+ UIP_STAT( ++uip_stat.icmp.recv );\r
\r
- /* Swap IP addresses. */\r
- uip_ipaddr_copy( &BUF->destipaddr, &BUF->srcipaddr );\r
- uip_ipaddr_copy( &BUF->srcipaddr, &uip_hostaddr );\r
+ /* If we get a neighbor solicitation for our address we should send\r
+ a neighbor advertisement message back. */\r
+ if( ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION )\r
+ {\r
+ if( uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr) )\r
+ {\r
+ if( ICMPBUF->options[ 0 ] == ICMP6_OPTION_SOURCE_LINK_ADDRESS )\r
+ {\r
+ /* Save the sender's address in our neighbor list. */\r
+ uip_neighbor_add( &ICMPBUF->srcipaddr, &(ICMPBUF->options[ 2 ]) );\r
+ }\r
\r
- UIP_STAT( ++uip_stat.icmp.sent );\r
- BUF->ttl = UIP_TTL;\r
- goto ip_send_nolen;\r
-\r
- /* End of IPv4 input header processing code. */\r
-#else /* !UIP_CONF_IPV6 */\r
- /* This is IPv6 ICMPv6 processing code. */\r
-\r
- //DEBUG_PRINTF( "icmp6_input: length %d\n", uip_len );\r
- if( BUF->proto != UIP_PROTO_ICMP6 )\r
- { /* We only allow ICMPv6 packets from\r
- here. */\r
- UIP_STAT( ++uip_stat.ip.drop );\r
- UIP_STAT( ++uip_stat.ip.protoerr );\r
- UIP_LOG( "ip: neither tcp nor icmp6." );\r
- goto drop;\r
- }\r
+ /* We should now send a neighbor advertisement back to where the\r
+ neighbor solicication came from. */\r
+ ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;\r
+ ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */\r
\r
- UIP_STAT( ++uip_stat.icmp.recv );\r
+ ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;\r
\r
- /* If we get a neighbor solicitation for our address we should send\r
- a neighbor advertisement message back. */\r
- if( ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION )\r
- {\r
- if( uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr) )\r
- {\r
- if( ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS )\r
- {\r
- /* Save the sender's address in our neighbor list. */\r
- uip_neighbor_add( &ICMPBUF->srcipaddr, &(ICMPBUF->options[2]) );\r
- }\r
+ uip_ipaddr_copy( &ICMPBUF->destipaddr, &ICMPBUF->srcipaddr );\r
+ uip_ipaddr_copy( &ICMPBUF->srcipaddr, &uip_hostaddr );\r
+ ICMPBUF->options[ 0 ] = ICMP6_OPTION_TARGET_LINK_ADDRESS;\r
+ ICMPBUF->options[ 1 ] = 1; /* Options length, 1 = 8 bytes. */\r
+ memcpy( &(ICMPBUF->options[ 2 ]), &uip_ethaddr, sizeof(uip_ethaddr) );\r
+ ICMPBUF->icmpchksum = 0;\r
+ ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
\r
- /* We should now send a neighbor advertisement back to where the\r
- neighbor solicication came from. */\r
- ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;\r
- ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */\r
+ goto send;\r
+ }\r
\r
- ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;\r
+ goto drop;\r
+ }\r
+ else if( ICMPBUF->type == ICMP6_ECHO )\r
+ {\r
+ /* ICMP echo (i.e., ping) processing. This is simple, we only\r
+ change the ICMP type from ECHO to ECHO_REPLY and update the\r
+ ICMP checksum before we return the packet. */\r
+ ICMPBUF->type = ICMP6_ECHO_REPLY;\r
\r
- uip_ipaddr_copy( &ICMPBUF->destipaddr, &ICMPBUF->srcipaddr );\r
- uip_ipaddr_copy( &ICMPBUF->srcipaddr, &uip_hostaddr );\r
- ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;\r
- ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */\r
- memcpy( &(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr) );\r
+ uip_ipaddr_copy( &BUF->destipaddr, &BUF->srcipaddr );\r
+ uip_ipaddr_copy( &BUF->srcipaddr, &uip_hostaddr );\r
ICMPBUF->icmpchksum = 0;\r
ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
\r
+ UIP_STAT( ++uip_stat.icmp.sent );\r
goto send;\r
}\r
+ else\r
+ {\r
+ //DEBUG_PRINTF( "Unknown icmp6 message type %d\n", ICMPBUF->type );\r
+ UIP_STAT( ++uip_stat.icmp.drop );\r
+ UIP_STAT( ++uip_stat.icmp.typeerr );\r
+ UIP_LOG( "icmp: unknown ICMP message." );\r
+ goto drop;\r
+ }\r
\r
- goto drop;\r
- }\r
- else if( ICMPBUF->type == ICMP6_ECHO )\r
- {\r
- /* ICMP echo (i.e., ping) processing. This is simple, we only\r
- change the ICMP type from ECHO to ECHO_REPLY and update the\r
- ICMP checksum before we return the packet. */\r
- ICMPBUF->type = ICMP6_ECHO_REPLY;\r
-\r
- uip_ipaddr_copy( &BUF->destipaddr, &BUF->srcipaddr );\r
- uip_ipaddr_copy( &BUF->srcipaddr, &uip_hostaddr );\r
- ICMPBUF->icmpchksum = 0;\r
- ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
-\r
- UIP_STAT( ++uip_stat.icmp.sent );\r
- goto send;\r
- }\r
- else\r
- {\r
- //DEBUG_PRINTF( "Unknown icmp6 message type %d\n", ICMPBUF->type );\r
- UIP_STAT( ++uip_stat.icmp.drop );\r
- UIP_STAT( ++uip_stat.icmp.typeerr );\r
- UIP_LOG( "icmp: unknown ICMP message." );\r
- goto drop;\r
- }\r
-\r
- /* End of IPv6 ICMP processing. */\r
-#endif /* !UIP_CONF_IPV6 */\r
-\r
-#if UIP_UDP\r
- /* UDP input processing. */\r
- udp_input :\r
- /* UDP processing is really just a hack. We don't do anything to the\r
- UDP/IP headers, but let the UDP application do all the hard\r
- work. If the application sets uip_slen, it has a packet to\r
- send. */\r
-#if UIP_UDP_CHECKSUMS\r
- uip_len = uip_len - UIP_IPUDPH_LEN;\r
- uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
- if( UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff )\r
- {\r
- UIP_STAT( ++uip_stat.udp.drop );\r
- UIP_STAT( ++uip_stat.udp.chkerr );\r
- UIP_LOG( "udp: bad checksum." );\r
- goto drop;\r
- }\r
+ /* End of IPv6 ICMP processing. */\r
+ #endif /* !UIP_CONF_IPV6 */\r
+\r
+ #if UIP_UDP\r
+ /* UDP input processing. */\r
+ udp_input :\r
+ /* UDP processing is really just a hack. We don't do anything to the\r
+ UDP/IP headers, but let the UDP application do all the hard\r
+ work. If the application sets uip_slen, it has a packet to\r
+ send. */\r
+ #if UIP_UDP_CHECKSUMS\r
+ uip_len = uip_len - UIP_IPUDPH_LEN;\r
+ uip_appdata = &uip_buf[ UIP_LLH_LEN + UIP_IPUDPH_LEN ];\r
+ if( UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff )\r
+ {\r
+ UIP_STAT( ++uip_stat.udp.drop );\r
+ UIP_STAT( ++uip_stat.udp.chkerr );\r
+ UIP_LOG( "udp: bad checksum." );\r
+ goto drop;\r
+ }\r
\r
-#else /* UIP_UDP_CHECKSUMS */\r
- uip_len = uip_len - UIP_IPUDPH_LEN;\r
-#endif /* UIP_UDP_CHECKSUMS */\r
+ #else /* UIP_UDP_CHECKSUMS */\r
+ uip_len = uip_len - UIP_IPUDPH_LEN;\r
+ #endif /* UIP_UDP_CHECKSUMS */\r
\r
- /* Demultiplex this UDP packet between the UDP "connections". */\r
- for( uip_udp_conn = &uip_udp_conns[0]; uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS]; ++uip_udp_conn )\r
- {\r
- /* If the local UDP port is non-zero, the connection is considered\r
- to be used. If so, the local port number is checked against the\r
- destination port number in the received packet. If the two port\r
- numbers match, the remote port number is checked if the\r
- connection is bound to a remote port. Finally, if the\r
- connection is bound to a remote IP address, the source IP\r
- address of the packet is checked. */\r
- if\r
- (\r
- uip_udp_conn->lport != 0 &&\r
- UDPBUF->destport == uip_udp_conn->lport &&\r
- (uip_udp_conn->rport == 0 || UDPBUF->srcport == uip_udp_conn->rport) &&\r
+ /* Demultiplex this UDP packet between the UDP "connections". */\r
+ for( uip_udp_conn = &uip_udp_conns[ 0 ]; uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS]; ++uip_udp_conn )\r
+ {\r
+ /* If the local UDP port is non-zero, the connection is considered\r
+ to be used. If so, the local port number is checked against the\r
+ destination port number in the received packet. If the two port\r
+ numbers match, the remote port number is checked if the\r
+ connection is bound to a remote port. Finally, if the\r
+ connection is bound to a remote IP address, the source IP\r
+ address of the packet is checked. */\r
+ if\r
(\r
- uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||\r
- uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||\r
- uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr)\r
+ uip_udp_conn->lport != 0 &&\r
+ UDPBUF->destport == uip_udp_conn->lport &&\r
+ (uip_udp_conn->rport == 0 || UDPBUF->srcport == uip_udp_conn->rport) &&\r
+ (\r
+ uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||\r
+ uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||\r
+ uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr)\r
+ )\r
)\r
- )\r
- {\r
- goto udp_found;\r
+ {\r
+ goto udp_found;\r
+ }\r
}\r
- }\r
\r
- UIP_LOG( "udp: no matching connection found" );\r
-#if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6\r
- /* Copy fields from packet header into payload of this ICMP packet. */\r
- memcpy( &(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8 );\r
+ UIP_LOG( "udp: no matching connection found" );\r
\r
- /* Set the ICMP type and code. */\r
- ICMPBUF->type = ICMP_DEST_UNREACHABLE;\r
- ICMPBUF->icode = ICMP_PORT_UNREACHABLE;\r
+ #if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6\r
\r
- /* Calculate the ICMP checksum. */\r
- ICMPBUF->icmpchksum = 0;\r
- ICMPBUF->icmpchksum = ~uip_chksum( ( u16_t * ) &(ICMPBUF->type), 36 );\r
+ /* Copy fields from packet header into payload of this ICMP packet. */\r
+ memcpy( &(ICMPBUF->payload[ 0 ]), ICMPBUF, UIP_IPH_LEN + 8 );\r
\r
- /* Set the IP destination address to be the source address of the\r
- original packet. */\r
- uip_ipaddr_copy( &BUF->destipaddr, &BUF->srcipaddr );\r
+ /* Set the ICMP type and code. */\r
+ ICMPBUF->type = ICMP_DEST_UNREACHABLE;\r
+ ICMPBUF->icode = ICMP_PORT_UNREACHABLE;\r
\r
- /* Set our IP address as the source address. */\r
- uip_ipaddr_copy( &BUF->srcipaddr, &uip_hostaddr );\r
+ /* Calculate the ICMP checksum. */\r
+ ICMPBUF->icmpchksum = 0;\r
+ ICMPBUF->icmpchksum = ~uip_chksum( ( u16_t * ) &(ICMPBUF->type), 36 );\r
\r
- /* The size of the ICMP destination unreachable packet is 36 + the\r
- size of the IP header (20) = 56. */\r
- uip_len = 36 + UIP_IPH_LEN;\r
- ICMPBUF->len[0] = 0;\r
- ICMPBUF->len[1] = ( u8_t ) uip_len;\r
- ICMPBUF->ttl = UIP_TTL;\r
- ICMPBUF->proto = UIP_PROTO_ICMP;\r
+ /* Set the IP destination address to be the source address of the\r
+ original packet. */\r
+ uip_ipaddr_copy( &BUF->destipaddr, &BUF->srcipaddr );\r
\r
- goto ip_send_nolen;\r
-#else /* UIP_CONF_ICMP_DEST_UNREACH */\r
- goto drop;\r
-#endif /* UIP_CONF_ICMP_DEST_UNREACH */\r
+ /* Set our IP address as the source address. */\r
+ uip_ipaddr_copy( &BUF->srcipaddr, &uip_hostaddr );\r
+\r
+ /* The size of the ICMP destination unreachable packet is 36 + the\r
+ size of the IP header (20) = 56. */\r
+ uip_len = 36 + UIP_IPH_LEN;\r
+ ICMPBUF->len[ 0 ] = 0;\r
+ ICMPBUF->len[ 1 ] = ( u8_t ) uip_len;\r
+ ICMPBUF->ttl = UIP_TTL;\r
+ ICMPBUF->proto = UIP_PROTO_ICMP;\r
+\r
+ goto ip_send_nolen;\r
+ #else /* UIP_CONF_ICMP_DEST_UNREACH */\r
+ goto drop;\r
+ #endif /* UIP_CONF_ICMP_DEST_UNREACH */\r
\r
udp_found : uip_conn = NULL;\r
uip_flags = UIP_NEWDATA;\r
\r
uip_len = uip_slen + UIP_IPUDPH_LEN;\r
\r
-#if UIP_CONF_IPV6\r
- /* For IPv6, the IP length field does not include the IPv6 IP header\r
- length. */\r
- BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );\r
- BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );\r
-#else /* UIP_CONF_IPV6 */\r
- BUF->len[0] = ( uip_len >> 8 );\r
- BUF->len[1] = ( uip_len & 0xff );\r
-#endif /* UIP_CONF_IPV6 */\r
+ #if UIP_CONF_IPV6\r
+ /* For IPv6, the IP length field does not include the IPv6 IP header\r
+ length. */\r
+ BUF->len[ 0 ] = ( (uip_len - UIP_IPH_LEN) >> 8 );\r
+ BUF->len[ 1 ] = ( (uip_len - UIP_IPH_LEN) & 0xff );\r
+ #else /* UIP_CONF_IPV6 */\r
+ BUF->len[ 0 ] = ( uip_len >> 8 );\r
+ BUF->len[ 1 ] = ( uip_len & 0xff );\r
+ #endif /* UIP_CONF_IPV6 */\r
\r
BUF->ttl = uip_udp_conn->ttl;\r
BUF->proto = UIP_PROTO_UDP;\r
\r
uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];\r
\r
-#if UIP_UDP_CHECKSUMS\r
- /* Calculate UDP checksum. */\r
- UDPBUF->udpchksum = ~( uip_udpchksum() );\r
- if( UDPBUF->udpchksum == 0 )\r
- {\r
- UDPBUF->udpchksum = 0xffff;\r
- }\r
-\r
-#endif /* UIP_UDP_CHECKSUMS */\r
-\r
- goto ip_send_nolen;\r
-#endif /* UIP_UDP */\r
+ #if UIP_UDP_CHECKSUMS\r
+ /* Calculate UDP checksum. */\r
+ UDPBUF->udpchksum = ~( uip_udpchksum() );\r
+ if( UDPBUF->udpchksum == 0 )\r
+ {\r
+ UDPBUF->udpchksum = 0xffff;\r
+ }\r
+ #endif /* UIP_UDP_CHECKSUMS */\r
+ goto ip_send_nolen;\r
+ #endif /* UIP_UDP */\r
\r
/* TCP input processing. */\r
tcp_input : UIP_STAT( ++uip_stat.tcp.recv );\r
\r
/* Start of TCP input header processing code. */\r
if( uip_tcpchksum() != 0xffff )\r
- { /* Compute and check the TCP\r
- checksum. */\r
+ {\r
+ /* Compute and check the TCP checksum. */\r
UIP_STAT( ++uip_stat.tcp.drop );\r
UIP_STAT( ++uip_stat.tcp.chkerr );\r
UIP_LOG( "tcp: bad checksum." );\r
/* Demultiplex this segment. */\r
\r
/* First check any active connections. */\r
- for( uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1]; ++uip_connr )\r
+ for( uip_connr = &uip_conns[ 0 ]; uip_connr <= &uip_conns[UIP_CONNS - 1]; ++uip_connr )\r
{\r
if\r
(\r
/* Next, check listening connections. */\r
for( c = 0; c < UIP_LISTENPORTS; ++c )\r
{\r
- if( tmp16 == uip_listenports[c] )\r
+ if( tmp16 == uip_listenports[ c ] )\r
{\r
goto found_listen;\r
}\r
BUF->tcpoffset = 5 << 4;\r
\r
/* Flip the seqno and ackno fields in the TCP header. */\r
- c = BUF->seqno[3];\r
- BUF->seqno[3] = BUF->ackno[3];\r
- BUF->ackno[3] = c;\r
+ c = BUF->seqno[ 3 ];\r
+ BUF->seqno[ 3 ] = BUF->ackno[ 3 ];\r
+ BUF->ackno[ 3 ] = c;\r
\r
- c = BUF->seqno[2];\r
- BUF->seqno[2] = BUF->ackno[2];\r
- BUF->ackno[2] = c;\r
+ c = BUF->seqno[ 2 ];\r
+ BUF->seqno[ 2 ] = BUF->ackno[ 2 ];\r
+ BUF->ackno[ 2 ] = c;\r
\r
- c = BUF->seqno[1];\r
- BUF->seqno[1] = BUF->ackno[1];\r
- BUF->ackno[1] = c;\r
+ c = BUF->seqno[ 1 ];\r
+ BUF->seqno[ 1 ] = BUF->ackno[ 1 ];\r
+ BUF->ackno[ 1 ] = c;\r
\r
- c = BUF->seqno[0];\r
- BUF->seqno[0] = BUF->ackno[0];\r
- BUF->ackno[0] = c;\r
+ c = BUF->seqno[ 0 ];\r
+ BUF->seqno[ 0 ] = BUF->ackno[ 0 ];\r
+ BUF->ackno[ 0 ] = c;\r
\r
/* We also have to increase the sequence number we are\r
acknowledging. If the least significant byte overflowed, we need\r
to propagate the carry to the other bytes as well. */\r
- if( ++BUF->ackno[3] == 0 )\r
+ if( ++BUF->ackno[ 3 ] == 0 )\r
{\r
- if( ++BUF->ackno[2] == 0 )\r
+ if( ++BUF->ackno[ 2 ] == 0 )\r
{\r
- if( ++BUF->ackno[1] == 0 )\r
+ if( ++BUF->ackno[ 1 ] == 0 )\r
{\r
- ++BUF->ackno[0];\r
+ ++BUF->ackno[ 0 ];\r
}\r
}\r
}\r
uip_connr = 0;\r
for( c = 0; c < UIP_CONNS; ++c )\r
{\r
- if( uip_conns[c].tcpstateflags == UIP_CLOSED )\r
+ if( uip_conns[ c ].tcpstateflags == UIP_CLOSED )\r
{\r
- uip_connr = &uip_conns[c];\r
+ uip_connr = &uip_conns[ c ];\r
break;\r
}\r
\r
- if( uip_conns[c].tcpstateflags == UIP_TIME_WAIT )\r
+ if( uip_conns[ c ].tcpstateflags == UIP_TIME_WAIT )\r
{\r
- if( uip_connr == 0 || uip_conns[c].timer > uip_connr->timer )\r
+ if( uip_connr == 0 || uip_conns[ c ].timer > uip_connr->timer )\r
{\r
- uip_connr = &uip_conns[c];\r
+ uip_connr = &uip_conns[ c ];\r
}\r
}\r
}\r
if( uip_connr == 0 )\r
{\r
/* All connections are used already, we drop packet and hope that\r
- the remote end will retransmit the packet at a time when we\r
- have more spare connections. */\r
+ the remote end will retransmit the packet at a time when we\r
+ have more spare connections. */\r
UIP_STAT( ++uip_stat.tcp.syndrop );\r
UIP_LOG( "tcp: found no unused connections." );\r
goto drop;\r
uip_ipaddr_copy( &uip_connr->ripaddr, &BUF->srcipaddr );\r
uip_connr->tcpstateflags = UIP_SYN_RCVD;\r
\r
- uip_connr->snd_nxt[0] = iss[0];\r
- uip_connr->snd_nxt[1] = iss[1];\r
- uip_connr->snd_nxt[2] = iss[2];\r
- uip_connr->snd_nxt[3] = iss[3];\r
+ uip_connr->snd_nxt[ 0 ] = iss[ 0 ];\r
+ uip_connr->snd_nxt[ 1 ] = iss[ 1 ];\r
+ uip_connr->snd_nxt[ 2 ] = iss[ 2 ];\r
+ uip_connr->snd_nxt[ 3 ] = iss[ 3 ];\r
uip_connr->len = 1;\r
\r
/* rcv_nxt should be the seqno from the incoming packet + 1. */\r
- uip_connr->rcv_nxt[3] = BUF->seqno[3];\r
- uip_connr->rcv_nxt[2] = BUF->seqno[2];\r
- uip_connr->rcv_nxt[1] = BUF->seqno[1];\r
- uip_connr->rcv_nxt[0] = BUF->seqno[0];\r
+ uip_connr->rcv_nxt[ 3 ] = BUF->seqno[ 3 ];\r
+ uip_connr->rcv_nxt[ 2 ] = BUF->seqno[ 2 ];\r
+ uip_connr->rcv_nxt[ 1 ] = BUF->seqno[ 1 ];\r
+ uip_connr->rcv_nxt[ 0 ] = BUF->seqno[ 0 ];\r
uip_add_rcv_nxt( 1 );\r
\r
/* Parse the TCP MSS option, if present. */\r
else\r
{\r
/* All other options have a length field, so that we easily\r
- can skip past them. */\r
+ can skip past them. */\r
if( uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0 )\r
{\r
/* If the length field is zero, the options are malformed\r
- and we don't process them further. */\r
+ and we don't process them further. */\r
break;\r
}\r
\r
}\r
\r
/* Our response will be a SYNACK. */\r
-#if UIP_ACTIVE_OPEN\r
- tcp_send_synack : BUF->flags = TCP_ACK;\r
-\r
+ #if UIP_ACTIVE_OPEN\r
+ tcp_send_synack : BUF->flags = TCP_ACK;\r
tcp_send_syn:\r
- BUF->flags |= TCP_SYN;\r
-#else /* UIP_ACTIVE_OPEN */\r
- tcp_send_synack : BUF->flags = TCP_SYN | TCP_ACK;\r
-#endif /* UIP_ACTIVE_OPEN */\r
+ BUF->flags |= TCP_SYN;\r
+ #else /* UIP_ACTIVE_OPEN */\r
+ tcp_send_synack : BUF->flags = TCP_SYN | TCP_ACK;\r
+ #endif /* UIP_ACTIVE_OPEN */\r
\r
/* We send out the TCP Maximum Segment Size option with our\r
- SYNACK. */\r
- BUF->optdata[0] = TCP_OPT_MSS;\r
- BUF->optdata[1] = TCP_OPT_MSS_LEN;\r
- BUF->optdata[2] = ( UIP_TCP_MSS ) / 256;\r
- BUF->optdata[3] = ( UIP_TCP_MSS ) & 255;\r
+ SYNACK. */\r
+ BUF->optdata[ 0 ] = TCP_OPT_MSS;\r
+ BUF->optdata[ 1 ] = TCP_OPT_MSS_LEN;\r
+ BUF->optdata[ 2 ] = ( UIP_TCP_MSS ) / 256;\r
+ BUF->optdata[ 3 ] = ( UIP_TCP_MSS ) & 255;\r
uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;\r
BUF->tcpoffset = ( (UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4 ) << 4;\r
goto tcp_send;\r
uip_flags = 0;\r
\r
/* We do a very naive form of TCP reset processing; we just accept\r
- any RST and kill our connection. We should in fact check if the\r
- sequence number of this reset is wihtin our advertised window\r
- before we accept the reset. */\r
+ any RST and kill our connection. We should in fact check if the\r
+ sequence number of this reset is wihtin our advertised window\r
+ before we accept the reset. */\r
if( BUF->flags & TCP_RST )\r
{\r
uip_connr->tcpstateflags = UIP_CLOSED;\r
}\r
\r
/* Calculate the length of the data, if the application has sent\r
- any data to us. */\r
+ any data to us. */\r
c = ( BUF->tcpoffset >> 4 ) << 2;\r
\r
/* uip_len will contain the length of the actual TCP data. This is\r
- calculated by subtracing the length of the TCP header (in\r
- c) and the length of the IP header (20 bytes). */\r
+ calculated by subtracing the length of the TCP header (in\r
+ c) and the length of the IP header (20 bytes). */\r
uip_len = uip_len - c - UIP_IPH_LEN;\r
\r
/* First, check if the sequence number of the incoming packet is\r
- what we're expecting next. If not, we send out an ACK with the\r
- correct numbers in. */\r
+ what we're expecting next. If not, we send out an ACK with the\r
+ correct numbers in. */\r
if( !(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) )\r
{\r
if\r
(\r
(uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&\r
(\r
- BUF->seqno[0] != uip_connr->rcv_nxt[0] ||\r
- BUF->seqno[1] != uip_connr->rcv_nxt[1] ||\r
- BUF->seqno[2] != uip_connr->rcv_nxt[2] ||\r
- BUF->seqno[3] != uip_connr->rcv_nxt[3]\r
+ BUF->seqno[ 0 ] != uip_connr->rcv_nxt[ 0 ] ||\r
+ BUF->seqno[ 1 ] != uip_connr->rcv_nxt[ 1 ] ||\r
+ BUF->seqno[ 2 ] != uip_connr->rcv_nxt[ 2 ] ||\r
+ BUF->seqno[ 3 ] != uip_connr->rcv_nxt[ 3 ]\r
)\r
)\r
{\r
}\r
\r
/* Next, check if the incoming segment acknowledges any outstanding\r
- data. If so, we update the sequence number, reset the length of\r
- the outstanding data, calculate RTT estimations, and reset the\r
- retransmission timer. */\r
+ data. If so, we update the sequence number, reset the length of\r
+ the outstanding data, calculate RTT estimations, and reset the\r
+ retransmission timer. */\r
if( (BUF->flags & TCP_ACK) && uip_outstanding(uip_connr) )\r
{\r
uip_add32( uip_connr->snd_nxt, uip_connr->len );\r
\r
if\r
(\r
- BUF->ackno[0] == uip_acc32[0] &&\r
- BUF->ackno[1] == uip_acc32[1] &&\r
- BUF->ackno[2] == uip_acc32[2] &&\r
- BUF->ackno[3] == uip_acc32[3]\r
+ BUF->ackno[ 0 ] == uip_acc32[ 0 ] &&\r
+ BUF->ackno[ 1 ] == uip_acc32[ 1 ] &&\r
+ BUF->ackno[ 2 ] == uip_acc32[ 2 ] &&\r
+ BUF->ackno[ 3 ] == uip_acc32[ 3 ]\r
)\r
{\r
/* Update sequence number. */\r
- uip_connr->snd_nxt[0] = uip_acc32[0];\r
- uip_connr->snd_nxt[1] = uip_acc32[1];\r
- uip_connr->snd_nxt[2] = uip_acc32[2];\r
- uip_connr->snd_nxt[3] = uip_acc32[3];\r
+ uip_connr->snd_nxt[ 0 ] = uip_acc32[ 0 ];\r
+ uip_connr->snd_nxt[ 1 ] = uip_acc32[ 1 ];\r
+ uip_connr->snd_nxt[ 2 ] = uip_acc32[ 2 ];\r
+ uip_connr->snd_nxt[ 3 ] = uip_acc32[ 3 ];\r
\r
/* Do RTT estimation, unless we have done retransmissions. */\r
if( uip_connr->nrtx == 0 )\r
}\r
\r
goto drop;\r
- #if UIP_ACTIVE_OPEN\r
\r
- case UIP_SYN_SENT:\r
- /* In SYN_SENT, we wait for a SYNACK that is sent in response to\r
- our SYN. The rcv_nxt is set to sequence number in the SYNACK\r
- plus one, and we send an ACK. We move into the ESTABLISHED\r
- state. */\r
- if( (uip_flags & UIP_ACKDATA) && (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK) )\r
- {\r
- /* Parse the TCP MSS option, if present. */\r
- if( (BUF->tcpoffset & 0xf0) > 0x50 )\r
+ #if UIP_ACTIVE_OPEN\r
+ case UIP_SYN_SENT:\r
+ /* In SYN_SENT, we wait for a SYNACK that is sent in response to\r
+ our SYN. The rcv_nxt is set to sequence number in the SYNACK\r
+ plus one, and we send an ACK. We move into the ESTABLISHED\r
+ state. */\r
+ if( (uip_flags & UIP_ACKDATA) && (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK) )\r
{\r
- for( c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2; )\r
+ /* Parse the TCP MSS option, if present. */\r
+ if( (BUF->tcpoffset & 0xf0) > 0x50 )\r
{\r
- opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];\r
- if( opt == TCP_OPT_END )\r
- {\r
- /* End of options. */\r
- break;\r
- }\r
- else if( opt == TCP_OPT_NOOP )\r
- {\r
- ++c;\r
-\r
- /* NOP option. */\r
- }\r
- else if( opt == TCP_OPT_MSS && uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN )\r
- {\r
- /* An MSS option with the right option length. */\r
- tmp16 = ( uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8 ) | uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];\r
- uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS ? UIP_TCP_MSS : tmp16;\r
-\r
- /* And we are done processing options. */\r
- break;\r
- }\r
- else\r
+ for( c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2; )\r
{\r
- /* All other options have a length field, so that we easily\r
- can skip past them. */\r
- if( uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0 )\r
+ opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];\r
+ if( opt == TCP_OPT_END )\r
{\r
- /* If the length field is zero, the options are malformed\r
- and we don't process them further. */\r
+ /* End of options. */\r
break;\r
}\r
+ else if( opt == TCP_OPT_NOOP )\r
+ {\r
+ ++c;\r
\r
- c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];\r
+ /* NOP option. */\r
+ }\r
+ else if( opt == TCP_OPT_MSS && uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN )\r
+ {\r
+ /* An MSS option with the right option length. */\r
+ tmp16 = ( uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8 ) | uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];\r
+ uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS ? UIP_TCP_MSS : tmp16;\r
+\r
+ /* And we are done processing options. */\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ /* All other options have a length field, so that we easily\r
+ can skip past them. */\r
+ if( uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0 )\r
+ {\r
+ /* If the length field is zero, the options are malformed\r
+ and we don't process them further. */\r
+ break;\r
+ }\r
+\r
+ c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];\r
+ }\r
}\r
}\r
+\r
+ uip_connr->tcpstateflags = UIP_ESTABLISHED;\r
+ uip_connr->rcv_nxt[ 0 ] = BUF->seqno[ 0 ];\r
+ uip_connr->rcv_nxt[ 1 ] = BUF->seqno[ 1 ];\r
+ uip_connr->rcv_nxt[ 2 ] = BUF->seqno[ 2 ];\r
+ uip_connr->rcv_nxt[ 3 ] = BUF->seqno[ 3 ];\r
+ uip_add_rcv_nxt( 1 );\r
+ uip_flags = UIP_CONNECTED | UIP_NEWDATA;\r
+ uip_connr->len = 0;\r
+ uip_len = 0;\r
+ uip_slen = 0;\r
+ UIP_APPCALL();\r
+ goto appsend;\r
}\r
\r
- uip_connr->tcpstateflags = UIP_ESTABLISHED;\r
- uip_connr->rcv_nxt[0] = BUF->seqno[0];\r
- uip_connr->rcv_nxt[1] = BUF->seqno[1];\r
- uip_connr->rcv_nxt[2] = BUF->seqno[2];\r
- uip_connr->rcv_nxt[3] = BUF->seqno[3];\r
- uip_add_rcv_nxt( 1 );\r
- uip_flags = UIP_CONNECTED | UIP_NEWDATA;\r
- uip_connr->len = 0;\r
- uip_len = 0;\r
- uip_slen = 0;\r
+ /* Inform the application that the connection failed */\r
+ uip_flags = UIP_ABORT;\r
UIP_APPCALL();\r
- goto appsend;\r
- }\r
-\r
- /* Inform the application that the connection failed */\r
- uip_flags = UIP_ABORT;\r
- UIP_APPCALL();\r
\r
- /* The connection is closed after we send the RST */\r
- uip_conn->tcpstateflags = UIP_CLOSED;\r
- goto reset;\r
- #endif /* UIP_ACTIVE_OPEN */\r
+ /* The connection is closed after we send the RST */\r
+ uip_conn->tcpstateflags = UIP_CLOSED;\r
+ goto reset;\r
+ #endif /* UIP_ACTIVE_OPEN */\r
\r
case UIP_ESTABLISHED:\r
/* In the ESTABLISHED state, we call upon the application to feed\r
this side as well, and we send out a FIN and enter the LAST_ACK\r
state. We require that there is no outstanding data; otherwise the\r
sequence numbers will be screwed up. */\r
- if( BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED) )\r
+ if( BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED) )\r
{\r
if( uip_outstanding(uip_connr) )\r
{\r
data that we must pass to the application. */\r
if( (BUF->flags & TCP_URG) != 0 )\r
{\r
- #if UIP_URGDATA > 0\r
- uip_urglen = ( BUF->urgp[0] << 8 ) | BUF->urgp[1];\r
- if( uip_urglen > uip_len )\r
- {\r
- /* There is more urgent data in the next segment to come. */\r
- uip_urglen = uip_len;\r
- }\r
+ #if UIP_URGDATA > 0\r
+ uip_urglen = ( BUF->urgp[ 0 ] << 8 ) | BUF->urgp[ 1 ];\r
+ if( uip_urglen > uip_len )\r
+ {\r
+ /* There is more urgent data in the next segment to come. */\r
+ uip_urglen = uip_len;\r
+ }\r
\r
- uip_add_rcv_nxt( uip_urglen );\r
- uip_len -= uip_urglen;\r
- uip_urgdata = uip_appdata;\r
- uip_appdata += uip_urglen;\r
- }\r
- else\r
- {\r
- uip_urglen = 0;\r
- #else /* UIP_URGDATA > 0 */\r
- uip_appdata = ( ( char * ) uip_appdata ) + ( (BUF->urgp[0] << 8) | BUF->urgp[1] );\r
- uip_len -= ( BUF->urgp[0] << 8 ) | BUF->urgp[1];\r
- #endif /* UIP_URGDATA > 0 */\r
+ uip_add_rcv_nxt( uip_urglen );\r
+ uip_len -= uip_urglen;\r
+ uip_urgdata = uip_appdata;\r
+ uip_appdata += uip_urglen;\r
+ }\r
+ else\r
+ {\r
+ uip_urglen = 0;\r
+ #else /* UIP_URGDATA > 0 */\r
+ uip_appdata = ( ( char * ) uip_appdata ) + ( (BUF->urgp[ 0 ] << 8) | BUF->urgp[ 1 ] );\r
+ uip_len -= ( BUF->urgp[ 0 ] << 8 ) | BUF->urgp[ 1 ];\r
+ #endif /* UIP_URGDATA > 0 */\r
}\r
\r
/* If uip_len > 0 we have TCP data in the packet, and we flag this\r
we acknowledge. If the application has stopped the dataflow\r
using uip_stop(), we must not accept any data packets from the\r
remote host. */\r
- if( uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED) )\r
+ if( uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED) )\r
{\r
uip_flags |= UIP_NEWDATA;\r
uip_add_rcv_nxt( uip_len );\r
and the application will retransmit it. This is called the\r
"persistent timer" and uses the retransmission mechanim.\r
*/\r
- tmp16 = ( (u16_t) BUF->wnd[0] << 8 ) + ( u16_t ) BUF->wnd[1];\r
+ tmp16 = ( (u16_t) BUF->wnd[ 0 ] << 8 ) + ( u16_t ) BUF->wnd[ 1 ];\r
if( tmp16 > uip_connr->initialmss || tmp16 == 0 )\r
{\r
tmp16 = uip_connr->initialmss;\r
put into the uip_appdata and the length of the data should be\r
put into uip_len. If the application don't have any data to\r
send, uip_len must be set to 0. */\r
- if( uip_flags & (UIP_NEWDATA | UIP_ACKDATA) )\r
+ if( uip_flags & (UIP_NEWDATA | UIP_ACKDATA) )\r
{\r
uip_slen = 0;\r
UIP_APPCALL();\r
\r
- appsend:\r
+appsend:\r
if( uip_flags & UIP_ABORT )\r
{\r
uip_slen = 0;\r
}\r
\r
uip_connr->nrtx = 0;\r
- apprexmit:\r
+apprexmit:\r
uip_appdata = uip_sappdata;\r
\r
/* If the application has data to be sent, or if the incoming\r
}\r
\r
/* If there is no data to send, just send out a pure ACK if\r
- there is newdata. */\r
+ there is newdata. */\r
if( uip_flags & UIP_NEWDATA )\r
{\r
uip_len = UIP_TCPIP_HLEN;\r
\r
case UIP_LAST_ACK:\r
/* We can close this connection if the peer has acknowledged our\r
- FIN. This is indicated by the UIP_ACKDATA flag. */\r
+ FIN. This is indicated by the UIP_ACKDATA flag. */\r
if( uip_flags & UIP_ACKDATA )\r
{\r
uip_connr->tcpstateflags = UIP_CLOSED;\r
\r
case UIP_FIN_WAIT_1:\r
/* The application has closed the connection, but the remote host\r
- hasn't closed its end yet. Thus we do nothing but wait for a\r
- FIN from the other side. */\r
+ hasn't closed its end yet. Thus we do nothing but wait for a\r
+ FIN from the other side. */\r
if( uip_len > 0 )\r
{\r
uip_add_rcv_nxt( uip_len );\r
headers before calculating the checksum and finally send the\r
packet. */\r
tcp_send:\r
- BUF->ackno[0] = uip_connr->rcv_nxt[0];\r
- BUF->ackno[1] = uip_connr->rcv_nxt[1];\r
- BUF->ackno[2] = uip_connr->rcv_nxt[2];\r
- BUF->ackno[3] = uip_connr->rcv_nxt[3];\r
+ BUF->ackno[ 0 ] = uip_connr->rcv_nxt[ 0 ];\r
+ BUF->ackno[ 1 ] = uip_connr->rcv_nxt[ 1 ];\r
+ BUF->ackno[ 2 ] = uip_connr->rcv_nxt[ 2 ];\r
+ BUF->ackno[ 3 ] = uip_connr->rcv_nxt[ 3 ];\r
\r
- BUF->seqno[0] = uip_connr->snd_nxt[0];\r
- BUF->seqno[1] = uip_connr->snd_nxt[1];\r
- BUF->seqno[2] = uip_connr->snd_nxt[2];\r
- BUF->seqno[3] = uip_connr->snd_nxt[3];\r
+ BUF->seqno[ 0 ] = uip_connr->snd_nxt[ 0 ];\r
+ BUF->seqno[ 1 ] = uip_connr->snd_nxt[ 1 ];\r
+ BUF->seqno[ 2 ] = uip_connr->snd_nxt[ 2 ];\r
+ BUF->seqno[ 3 ] = uip_connr->snd_nxt[ 3 ];\r
\r
BUF->proto = UIP_PROTO_TCP;\r
\r
if( uip_connr->tcpstateflags & UIP_STOPPED )\r
{\r
/* If the connection has issued uip_stop(), we advertise a zero\r
- window so that the remote host will stop sending data. */\r
- BUF->wnd[0] = BUF->wnd[1] = 0;\r
+ window so that the remote host will stop sending data. */\r
+ BUF->wnd[ 0 ] = BUF->wnd[ 1 ] = 0;\r
}\r
else\r
{\r
- BUF->wnd[0] = ( (UIP_RECEIVE_WINDOW) >> 8 );\r
- BUF->wnd[1] = ( (UIP_RECEIVE_WINDOW) & 0xff );\r
+ BUF->wnd[ 0 ] = ( (UIP_RECEIVE_WINDOW) >> 8 );\r
+ BUF->wnd[ 1 ] = ( (UIP_RECEIVE_WINDOW) & 0xff );\r
}\r
\r
tcp_send_noconn:\r
+\r
BUF->ttl = UIP_TTL;\r
-#if UIP_CONF_IPV6\r
- /* For IPv6, the IP length field does not include the IPv6 IP header\r
- length. */\r
- BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );\r
- BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );\r
-#else /* UIP_CONF_IPV6 */\r
- BUF->len[0] = ( uip_len >> 8 );\r
- BUF->len[1] = ( uip_len & 0xff );\r
-#endif /* UIP_CONF_IPV6 */\r
\r
- BUF->urgp[0] = BUF->urgp[1] = 0;\r
+ #if UIP_CONF_IPV6\r
+ /* For IPv6, the IP length field does not include the IPv6 IP header\r
+ length. */\r
+ BUF->len[ 0 ] = ( (uip_len - UIP_IPH_LEN) >> 8 );\r
+ BUF->len[ 1 ] = ( (uip_len - UIP_IPH_LEN) & 0xff );\r
+ #else /* UIP_CONF_IPV6 */\r
+ BUF->len[ 0 ] = ( uip_len >> 8 );\r
+ BUF->len[ 1 ] = ( uip_len & 0xff );\r
+ #endif /* UIP_CONF_IPV6 */\r
+\r
+ BUF->urgp[ 0 ] = BUF->urgp[ 1 ] = 0;\r
\r
/* Calculate TCP checksum. */\r
BUF->tcpchksum = 0;\r
BUF->tcpchksum = ~( uip_tcpchksum() );\r
\r
ip_send_nolen:\r
-#if UIP_CONF_IPV6\r
- BUF->vtc = 0x60;\r
- BUF->tcflow = 0x00;\r
- BUF->flow = 0x00;\r
-#else /* UIP_CONF_IPV6 */\r
- BUF->vhl = 0x45;\r
- BUF->tos = 0;\r
- BUF->ipoffset[0] = BUF->ipoffset[1] = 0;\r
- ++ipid;\r
- BUF->ipid[0] = ipid >> 8;\r
- BUF->ipid[1] = ipid & 0xff;\r
-\r
- /* Calculate IP checksum. */\r
- BUF->ipchksum = 0;\r
- BUF->ipchksum = ~( uip_ipchksum() );\r
-\r
- //DEBUG_PRINTF( "uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum() );\r
-#endif /* UIP_CONF_IPV6 */\r
+ #if UIP_CONF_IPV6\r
+ BUF->vtc = 0x60;\r
+ BUF->tcflow = 0x00;\r
+ BUF->flow = 0x00;\r
+ #else /* UIP_CONF_IPV6 */\r
+ BUF->vhl = 0x45;\r
+ BUF->tos = 0;\r
+ BUF->ipoffset[ 0 ] = BUF->ipoffset[ 1 ] = 0;\r
+ ++ipid;\r
+ BUF->ipid[ 0 ] = ipid >> 8;\r
+ BUF->ipid[ 1 ] = ipid & 0xff;\r
+\r
+ /* Calculate IP checksum. */\r
+ BUF->ipchksum = 0;\r
+ BUF->ipchksum = ~( uip_ipchksum() );\r
+\r
+ //DEBUG_PRINTF( "uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum() );\r
+ #endif /* UIP_CONF_IPV6 */\r
+\r
UIP_STAT( ++uip_stat.tcp.sent );\r
-#if UIP_CONF_IPV6\r
- send :\r
-#endif /* UIP_CONF_IPV6 */\r
\r
- //DEBUG_PRINTF( "Sending packet with length %d (%d)\n", uip_len, (BUF->len[0] << 8) | BUF->len[1] );\r
+ #if UIP_CONF_IPV6\r
+send :\r
+ #endif /* UIP_CONF_IPV6 */\r
+\r
+ //DEBUG_PRINTF( "Sending packet with length %d (%d)\n", uip_len, (BUF->len[ 0 ] << 8) | BUF->len[ 1 ] );\r
UIP_STAT( ++uip_stat.ip.sent );\r
\r
/* Return and let the caller do the actual transmission. */\r
uip_flags = 0;\r
return;\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
+\r
u16_t htons( u16_t val )\r
{\r
return HTONS( val );\r
{\r
return HTONL( val );\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
+\r
void uip_send( const void *data, int len )\r
{\r
int copylen;\r
-#define MIN( a, b ) ( (a) < (b) ? (a) : (b) )\r
+\r
+ #define MIN( a, b ) ( (a) < (b) ? (a) : (b) )\r
+\r
copylen = MIN( len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN - ( int )\r
(( char * ) uip_sappdata - ( char * ) &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]) );\r
if( copylen > 0 )\r
}\r
}\r
}\r
-\r
/*---------------------------------------------------------------------------*/\r
\r
/** @} */\r