mbed OS5

Fork of UIPEthernet by Zoltan Hudak

Revision:
8:4acb22344932
Parent:
4:d774541a34da
diff -r 1bc7e6120801 -r 4acb22344932 utility/uip.c
--- a/utility/uip.c	Tue Apr 26 18:37:14 2016 +0000
+++ b/utility/uip.c	Fri Jun 30 19:51:28 2017 +0000
@@ -1,21 +1,21 @@
 #define DEBUG_PRINTF(...)   /*printf(__VA_ARGS__)*/
 
 /**
- * \defgroup uip The uIP TCP/IP stack
+ * \defgroup uip The UIP TCP/IP stack
  * @{
  *
- * uIP is an implementation of the TCP/IP protocol stack intended for
+ * UIP is an implementation of the TCP/IP protocol stack intended for
  * small 8-bit and 16-bit microcontrollers.
  *
- * uIP provides the necessary protocols for Internet communication,
- * with a very small code footprint and RAM requirements - the uIP
+ * UIP provides the necessary protocols for Internet communication,
+ * with a very small code footprint and RAM requirements - the UIP
  * code size is on the order of a few kilobytes and RAM usage is on
  * the order of a few hundred bytes.
  */
 
 /**
  * \file
- * The uIP TCP/IP stack code.
+ * The UIP TCP/IP stack code.
  * \author Adam Dunkels <adam@dunkels.com>
  */
 /*
@@ -46,13 +46,13 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * This file is part of the uIP TCP/IP stack.
+ * This file is part of the UIP TCP/IP stack.
  *
  * $Id: uip.c,v 1.65 2006/06/11 21:46:39 adam Exp $
  *
  */
 /*
- * uIP is a small implementation of the IP, UDP and TCP protocols (as
+ * UIP is a small implementation of the IP, UDP and TCP protocols (as
  * well as some basic ICMP stuff). The implementation couples the IP,
  * UDP, TCP and the application layers very tightly. To keep the size
  * of the compiled code down, this code frequently uses the goto
@@ -81,7 +81,7 @@
 #include "uip_arch.h"
 
 #if UIP_CONF_IPV6
-    #include "uip-neighbor.h"
+#include "uip-neighbor.h"
 #endif /* UIP_CONF_IPV6 */
 
 #include <string.h>
@@ -185,7 +185,6 @@
  * @param
  * @retval
  */
-
 void uip_setipid(u16_t id) {
     ipid = id;
 }
@@ -242,17 +241,17 @@
 #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
+#define UIP_STAT(s) s
 #else
-    #define UIP_STAT(s)
+#define UIP_STAT(s)
 #endif /* UIP_STATISTICS == 1 */
 
 #if UIP_LOGGING == 1
-    #include <stdio.h>
+#include <stdio.h>
 void    uip_log(char* msg);
-    #define UIP_LOG(m)  uip_log(m)
+#define UIP_LOG(m)  uip_log(m)
 #else
-    #define UIP_LOG(m)
+#define UIP_LOG(m)
 #endif /* UIP_LOGGING == 1 */
 
 #if !UIP_ARCH_ADD32
@@ -269,18 +268,18 @@
     uip_acc32[1] = op32[1];
     uip_acc32[0] = op32[0];
 
-    if(uip_acc32[2] < (op16 >> 8)) {
+    if (uip_acc32[2] < (op16 >> 8)) {
         ++uip_acc32[1];
-        if(uip_acc32[1] == 0) {
+        if (uip_acc32[1] == 0) {
             ++uip_acc32[0];
         }
     }
 
-    if(uip_acc32[3] < (op16 & 0xff)) {
+    if (uip_acc32[3] < (op16 & 0xff)) {
         ++uip_acc32[2];
-        if(uip_acc32[2] == 0) {
+        if (uip_acc32[2] == 0) {
             ++uip_acc32[1];
-            if(uip_acc32[1] == 0) {
+            if (uip_acc32[1] == 0) {
                 ++uip_acc32[0];
             }
         }
@@ -299,22 +298,22 @@
     dataptr = data;
     last_byte = data + len - 1;
 
-    while(dataptr < last_byte) {
+    while (dataptr < last_byte) {
 
         /* At least two more bytes */
         t = (dataptr[0] << 8) + dataptr[1];
         sum += t;
-        if(sum < t) {
+        if (sum < t) {
             sum++;  /* carry */
         }
 
         dataptr += 2;
     }
 
-    if(dataptr == last_byte) {
+    if (dataptr == last_byte) {
         t = (dataptr[0] << 8) + 0;
         sum += t;
-        if(sum < t) {
+        if (sum < t) {
             sum++;  /* carry */
         }
     }
@@ -329,7 +328,7 @@
 }
 
 /*---------------------------------------------------------------------------*/
-    #ifndef UIP_ARCH_IPCHKSUM
+#ifndef UIP_ARCH_IPCHKSUM
 
 /**
  * @brief
@@ -344,18 +343,18 @@
     DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
     return(sum == 0) ? 0xffff : htons(sum);
 }
-    #endif
+#endif
 
 /*---------------------------------------------------------------------------*/
 static u16_t upper_layer_chksum(u8_t proto) {
     u16_t   upper_layer_len;
     u16_t   sum;
 
-    #if UIP_CONF_IPV6
+#if UIP_CONF_IPV6
     upper_layer_len = (((u16_t) (BUF->len[0]) << 8) + BUF->len[1]);
-    #else /* UIP_CONF_IPV6 */
+#else /* UIP_CONF_IPV6 */
     upper_layer_len = (((u16_t) (BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
-    #endif /* UIP_CONF_IPV6 */
+#endif /* UIP_CONF_IPV6 */
 
     /* First sum pseudoheader. */
 
@@ -372,7 +371,7 @@
 }
 
 /*---------------------------------------------------------------------------*/
-    #if UIP_CONF_IPV6
+#if UIP_CONF_IPV6
 
 /**
  * @brief
@@ -383,7 +382,7 @@
 u16_t uip_icmp6chksum(void) {
     return upper_layer_chksum(UIP_PROTO_ICMP6);
 }
-    #endif /* UIP_CONF_IPV6 */
+#endif /* UIP_CONF_IPV6 */
 
 /*---------------------------------------------------------------------------*/
 u16_t uip_tcpchksum(void) {
@@ -391,7 +390,7 @@
 }
 
 /*---------------------------------------------------------------------------*/
-    #if UIP_UDP_CHECKSUMS
+#if UIP_UDP_CHECKSUMS
 
 /**
  * @brief
@@ -402,16 +401,16 @@
 u16_t uip_udpchksum(void) {
     return upper_layer_chksum(UIP_PROTO_UDP);
 }
-    #endif /* UIP_UDP_CHECKSUMS */
+#endif /* UIP_UDP_CHECKSUMS */
 #endif /* UIP_ARCH_CHKSUM */
 
 /*---------------------------------------------------------------------------*/
 void uip_init(void) {
-    for(c = 0; c < UIP_LISTENPORTS; ++c) {
+    for (c = 0; c < UIP_LISTENPORTS; ++c) {
         uip_listenports[c] = 0;
     }
 
-    for(c = 0; c < UIP_CONNS; ++c) {
+    for (c = 0; c < UIP_CONNS; ++c) {
         uip_conns[c].tcpstateflags = UIP_CLOSED;
     }
 
@@ -420,7 +419,7 @@
 #endif /* UIP_ACTIVE_OPEN */
 
 #if UIP_UDP
-    for(c = 0; c < UIP_UDP_CONNS; ++c) {
+    for (c = 0; c < UIP_UDP_CONNS; ++c) {
         uip_udp_conns[c].lport = 0;
     }
 #endif /* UIP_UDP */
@@ -449,35 +448,35 @@
 again:
     ++lastport;
 
-    if(lastport >= 32000) {
+    if (lastport >= 32000) {
         lastport = 4096;
     }
 
     /* Check if this port is already in use, and if so try to find
      another one. */
-    for(c = 0; c < UIP_CONNS; ++c) {
+    for (c = 0; c < UIP_CONNS; ++c) {
         conn = &uip_conns[c];
-        if(conn->tcpstateflags != UIP_CLOSED && conn->lport == htons(lastport)) {
+        if (conn->tcpstateflags != UIP_CLOSED && conn->lport == htons(lastport)) {
             goto again;
         }
     }
 
     conn = 0;
-    for(c = 0; c < UIP_CONNS; ++c) {
+    for (c = 0; c < UIP_CONNS; ++c) {
         cconn = &uip_conns[c];
-        if(cconn->tcpstateflags == UIP_CLOSED) {
+        if (cconn->tcpstateflags == UIP_CLOSED) {
             conn = cconn;
             break;
         }
 
-        if(cconn->tcpstateflags == UIP_TIME_WAIT) {
-            if(conn == 0 || cconn->timer > conn->timer) {
+        if (cconn->tcpstateflags == UIP_TIME_WAIT) {
+            if (conn == 0 || cconn->timer > conn->timer) {
                 conn = cconn;
             }
         }
     }
 
-    if(conn == 0) {
+    if (conn == 0) {
         return 0;
     }
 
@@ -522,31 +521,31 @@
 again:
     ++lastport;
 
-    if(lastport >= 32000) {
+    if (lastport >= 32000) {
         lastport = 4096;
     }
 
-    for(c = 0; c < UIP_UDP_CONNS; ++c) {
-        if(uip_udp_conns[c].lport == htons(lastport)) {
+    for (c = 0; c < UIP_UDP_CONNS; ++c) {
+        if (uip_udp_conns[c].lport == htons(lastport)) {
             goto again;
         }
     }
 
     conn = 0;
-    for(c = 0; c < UIP_UDP_CONNS; ++c) {
-        if(uip_udp_conns[c].lport == 0) {
+    for (c = 0; c < UIP_UDP_CONNS; ++c) {
+        if (uip_udp_conns[c].lport == 0) {
             conn = &uip_udp_conns[c];
             break;
         }
     }
 
-    if(conn == 0) {
+    if (conn == 0) {
         return 0;
     }
 
     conn->lport = HTONS(lastport);
     conn->rport = rport;
-    if(ripaddr == NULL) {
+    if (ripaddr == NULL) {
         memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t));
     }
     else {
@@ -561,8 +560,8 @@
 
 /*---------------------------------------------------------------------------*/
 void uip_unlisten(u16_t port) {
-    for(c = 0; c < UIP_LISTENPORTS; ++c) {
-        if(uip_listenports[c] == port) {
+    for (c = 0; c < UIP_LISTENPORTS; ++c) {
+        if (uip_listenports[c] == port) {
             uip_listenports[c] = 0;
             return;
         }
@@ -571,8 +570,8 @@
 
 /*---------------------------------------------------------------------------*/
 void uip_listen(u16_t port) {
-    for(c = 0; c < UIP_LISTENPORTS; ++c) {
-        if(uip_listenports[c] == 0) {
+    for (c = 0; c < UIP_LISTENPORTS; ++c) {
+        if (uip_listenports[c] == 0) {
             uip_listenports[c] = port;
             return;
         }
@@ -582,16 +581,16 @@
 /*---------------------------------------------------------------------------*/
 /* XXX: IP fragment reassembly: not well-tested. */
 #if UIP_REASSEMBLY && !UIP_CONF_IPV6
-    #define UIP_REASS_BUFSIZE   (UIP_BUFSIZE - UIP_LLH_LEN)
+#define UIP_REASS_BUFSIZE   (UIP_BUFSIZE - UIP_LLH_LEN)
 static u8_t         uip_reassbuf[UIP_REASS_BUFSIZE];
 static u8_t         uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
 static const u8_t   bitmap_bits[8] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
 static u16_t        uip_reasslen;
 static u8_t         uip_reassflags;
-    #define UIP_REASS_FLAG_LASTFRAG 0x01
+#define UIP_REASS_FLAG_LASTFRAG 0x01
 static u8_t         uip_reasstmr;
 
-    #define IP_MF   0x20
+#define IP_MF   0x20
 
 /**
  * @brief
@@ -599,7 +598,6 @@
  * @param
  * @retval
  */
-
 static u8_t uip_reass(void) {
     u16_t   offset, len;
     u16_t   i;
@@ -608,7 +606,7 @@
      write the IP header of the fragment into the reassembly
      buffer. The timer is updated with the maximum age. */
 
-    if(uip_reasstmr == 0) {
+    if (uip_reasstmr == 0) {
         memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);
         uip_reasstmr = UIP_REASS_MAXAGE;
         uip_reassflags = 0;
@@ -634,7 +632,7 @@
 
         /* If the offset or the offset + fragment length overflows the
        reassembly buffer, we discard the entire packet. */
-        if(offset > UIP_REASS_BUFSIZE || offset + len > UIP_REASS_BUFSIZE) {
+        if (offset > UIP_REASS_BUFSIZE || offset + len > UIP_REASS_BUFSIZE) {
             uip_reasstmr = 0;
             goto nullreturn;
         }
@@ -644,7 +642,7 @@
         memcpy(&uip_reassbuf[UIP_IPH_LEN + offset], (char*)BUF + (int)((BUF->vhl & 0x0f) * 4), len);
 
         /* Update the bitmap. */
-        if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
+        if (offset / (8 * 8) == (offset + len) / (8 * 8)) {
 
             /* If the two endpoints are in the same byte, we only update
      that byte. */
@@ -656,7 +654,7 @@
      bytes in the endpoints and fill the stuff inbetween with
      0xff. */
             uip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7];
-            for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
+            for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
                 uip_reassbitmap[i] = 0xff;
             }
 
@@ -668,7 +666,7 @@
        size of the entire packet. We also set the
        IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
        the final fragment. */
-        if((BUF->ipoffset[0] & IP_MF) == 0) {
+        if ((BUF->ipoffset[0] & IP_MF) == 0) {
             uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
             uip_reasslen = offset + len;
         }
@@ -676,19 +674,19 @@
         /* Finally, we check if we have a full packet in the buffer. We do
        this by checking if we have the last fragment and if all bits
        in the bitmap are set. */
-        if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
+        if (uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
 
             /* Check all bytes up to and including all but the last byte in
      the bitmap. */
-            for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
-                if(uip_reassbitmap[i] != 0xff) {
+            for (i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
+                if (uip_reassbitmap[i] != 0xff) {
                     goto nullreturn;
                 }
             }
 
             /* Check the last byte in the bitmap. It should contain just the
      right amount of bits. */
-            if(uip_reassbitmap[uip_reasslen / (8 * 8)] != (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
+            if (uip_reassbitmap[uip_reasslen / (8 * 8)] != (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
                 goto nullreturn;
             }
 
@@ -729,7 +727,7 @@
     register struct uip_conn*   uip_connr = uip_conn;
 
 #if UIP_UDP
-    if(flag == UIP_UDP_SEND_CONN) {
+    if (flag == UIP_UDP_SEND_CONN) {
         goto udp_send;
     }
 #endif /* UIP_UDP */
@@ -738,8 +736,8 @@
 
     /* Check if we were invoked because of a poll request for a
      particular connection. */
-    if(flag == UIP_POLL_REQUEST) {
-        if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED && !uip_outstanding(uip_connr)) {
+    if (flag == UIP_POLL_REQUEST) {
+        if ((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED && !uip_outstanding(uip_connr)) {
             uip_flags = UIP_POLL;
             UIP_APPCALL();
             goto appsend;
@@ -750,19 +748,19 @@
         /* Check if we were invoked because of the perodic timer fireing. */
     }
     else
-    if(flag == UIP_TIMER)
+    if (flag == UIP_TIMER)
     {
 #if UIP_REASSEMBLY
-        if(uip_reasstmr != 0) {
+        if (uip_reasstmr != 0) {
             --uip_reasstmr;
         }
 #endif /* UIP_REASSEMBLY */
 
         /* Increase the initial sequence number. */
 
-        if(++iss[3] == 0) {
-            if(++iss[2] == 0) {
-                if(++iss[1] == 0) {
+        if (++iss[3] == 0) {
+            if (++iss[2] == 0) {
+                if (++iss[1] == 0) {
                     ++iss[0];
                 }
             }
@@ -776,20 +774,20 @@
        for the connection to time out. If so, we increase the
        connection's timer and remove the connection if it times
        out. */
-        if(uip_connr->tcpstateflags == UIP_TIME_WAIT || uip_connr->tcpstateflags == UIP_FIN_WAIT_2) {
+        if (uip_connr->tcpstateflags == UIP_TIME_WAIT || uip_connr->tcpstateflags == UIP_FIN_WAIT_2) {
             ++(uip_connr->timer);
-            if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
+            if (uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
                 uip_connr->tcpstateflags = UIP_CLOSED;
             }
         }
         else
-        if(uip_connr->tcpstateflags != UIP_CLOSED) {
+        if (uip_connr->tcpstateflags != UIP_CLOSED) {
 
             /* If the connection has outstanding data, we increase the
      connection's timer and see if it has reached the RTO value
      in which case we retransmit. */
-            if(uip_outstanding(uip_connr)) {
-                if(uip_connr->timer-- == 0) {
+            if (uip_outstanding(uip_connr)) {
+                if (uip_connr->timer-- == 0) {
                     if
                     (
                         uip_connr->nrtx == UIP_MAXRTX
@@ -822,39 +820,39 @@
          SYNACK that we sent earlier and in LAST_ACK we have to
          retransmit our FINACK. */
                     UIP_STAT(++uip_stat.tcp.rexmit);
-                    switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
-                    case UIP_SYN_RCVD:
-                        /* In the SYN_RCVD state, we should retransmit our
+                    switch (uip_connr->tcpstateflags & UIP_TS_MASK) {
+                        case UIP_SYN_RCVD:
+                            /* In the SYN_RCVD state, we should retransmit our
                SYNACK. */
-                        goto tcp_send_synack;
+                            goto tcp_send_synack;
 
-#if UIP_ACTIVE_OPEN
+    #if UIP_ACTIVE_OPEN
 
-                    case UIP_SYN_SENT:
-                        /* In the SYN_SENT state, we retransmit out SYN. */
-                        BUF->flags = 0;
-                        goto tcp_send_syn;
-#endif /* UIP_ACTIVE_OPEN */
+                        case UIP_SYN_SENT:
+                            /* In the SYN_SENT state, we retransmit out SYN. */
+                            BUF->flags = 0;
+                            goto tcp_send_syn;
+    #endif /* UIP_ACTIVE_OPEN */
 
-                    case UIP_ESTABLISHED:
-                        /* In the ESTABLISHED state, we call upon the application
+                        case UIP_ESTABLISHED:
+                            /* In the ESTABLISHED state, we call upon the application
                to do the actual retransmit after which we jump into
                the code for sending out the packet (the apprexmit
                label). */
-                        uip_flags = UIP_REXMIT;
-                        UIP_APPCALL();
-                        goto apprexmit;
+                            uip_flags = UIP_REXMIT;
+                            UIP_APPCALL();
+                            goto apprexmit;
 
-                    case UIP_FIN_WAIT_1:
-                    case UIP_CLOSING:
-                    case UIP_LAST_ACK:
-                        /* In all these states we should retransmit a FINACK. */
-                        goto tcp_send_finack;
+                        case UIP_FIN_WAIT_1:
+                        case UIP_CLOSING:
+                        case UIP_LAST_ACK:
+                            /* In all these states we should retransmit a FINACK. */
+                            goto tcp_send_finack;
                     }
                 }
             }
             else
-            if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
+            if ((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
 
                 /* If there was no need for a retransmission, we poll the
            application for new data. */
@@ -868,8 +866,8 @@
     }
 
 #if UIP_UDP
-    if(flag == UIP_UDP_TIMER) {
-        if(uip_udp_conn->lport != 0) {
+    if (flag == UIP_UDP_TIMER) {
+        if (uip_udp_conn->lport != 0) {
             uip_conn = NULL;
             uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
             uip_len = uip_slen = 0;
@@ -890,7 +888,7 @@
 #if UIP_CONF_IPV6
     /* Check validity of the IP header. */
 
-    if((BUF->vtc & 0xf0) != 0x60) {
+    if ((BUF->vtc & 0xf0) != 0x60) {
 
         /* IP version and header length. */
         UIP_STAT(++uip_stat.ip.drop);
@@ -902,7 +900,7 @@
 #else /* UIP_CONF_IPV6 */
     /* Check validity of the IP header. */
 
-    if(BUF->vhl != 0x45) {
+    if (BUF->vhl != 0x45) {
 
         /* IP version and header length. */
         UIP_STAT(++uip_stat.ip.drop);
@@ -919,12 +917,12 @@
      the packet has been padded and we set uip_len to the correct
      value.. */
 
-    if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {
+    if ((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {
         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
               length of the payload that follows the
-              header. However, uIP uses the uip_len variable
+              header. However, UIP uses the uip_len variable
               for holding the size of the entire packet,
               including the IP header. For IPv4 this is not a
               problem as the length field in the IPv4 header
@@ -941,30 +939,30 @@
 #if !UIP_CONF_IPV6
     /* Check the fragment flag. */
 
-    if((BUF->ipoffset[0] & 0x3f) != 0 || BUF->ipoffset[1] != 0)
+    if ((BUF->ipoffset[0] & 0x3f) != 0 || BUF->ipoffset[1] != 0)
     {
-    #if UIP_REASSEMBLY
+#if UIP_REASSEMBLY
         uip_len = uip_reass();
-        if(uip_len == 0) {
+        if (uip_len == 0) {
             goto drop;
         }
 
-    #else /* UIP_REASSEMBLY */
+#else /* UIP_REASSEMBLY */
         UIP_STAT(++uip_stat.ip.drop);
         UIP_STAT(++uip_stat.ip.fragerr);
         UIP_LOG("ip: fragment dropped.");
         goto drop;
-    #endif /* UIP_REASSEMBLY */
+#endif /* UIP_REASSEMBLY */
     }
 #endif /* UIP_CONF_IPV6 */
 
-    if(uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr))
+    if (uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr))
     {
         /* If we are configured to use ping IP address configuration and
        hasn't been assigned an IP address yet, we accept all ICMP
        packets. */
 #if UIP_PINGADDRCONF && !UIP_CONF_IPV6
-        if(BUF->proto == UIP_PROTO_ICMP) {
+        if (BUF->proto == UIP_PROTO_ICMP) {
             UIP_LOG("ip: possible ping config packet received.");
             goto icmp_input;
         }
@@ -993,7 +991,7 @@
         /* Check if the packet is destined for our IP address. */
 
 #if !UIP_CONF_IPV6
-        if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {
+        if (!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {
             UIP_STAT(++uip_stat.ip.drop);
             goto drop;
         }
@@ -1005,7 +1003,7 @@
        address) as well. However, we will cheat here and accept all
        multicast packets that are sent to the ff02::/16 addresses. */
 
-        if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) && BUF->destipaddr[0] != HTONS(0xff02)) {
+        if (!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) && BUF->destipaddr[0] != HTONS(0xff02)) {
             UIP_STAT(++uip_stat.ip.drop);
             goto drop;
         }
@@ -1013,7 +1011,7 @@
     }
 
 #if !UIP_CONF_IPV6
-    if(uip_ipchksum() != 0xffff) {
+    if (uip_ipchksum() != 0xffff) {
 
         /* Compute and check the IP header
                     checksum. */
@@ -1024,7 +1022,7 @@
     }
 #endif /* UIP_CONF_IPV6 */
 
-    if(BUF->proto == UIP_PROTO_TCP) {
+    if (BUF->proto == UIP_PROTO_TCP) {
 
         /* Check for TCP packet. If so,
                        proceed with TCP input
@@ -1033,7 +1031,7 @@
     }
 
 #if UIP_UDP
-    if(BUF->proto == UIP_PROTO_UDP) {
+    if (BUF->proto == UIP_PROTO_UDP) {
         goto udp_input;
     }
 #endif /* UIP_UDP */
@@ -1041,7 +1039,7 @@
 #if !UIP_CONF_IPV6
     /* ICMPv4 processing code follows. */
 
-    if(BUF->proto != UIP_PROTO_ICMP) {
+    if (BUF->proto != UIP_PROTO_ICMP) {
 
         /* We only allow ICMP packets from
                     here. */
@@ -1051,16 +1049,16 @@
         goto drop;
     }
 
-    #if UIP_PINGADDRCONF
+#if UIP_PINGADDRCONF
     icmp_input :
-    #endif /* UIP_PINGADDRCONF */
+#endif /* UIP_PINGADDRCONF */
 
     UIP_STAT(++uip_stat.icmp.recv);
 
     /* ICMP echo (i.e., ping) processing. This is simple, we only change
      the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP
      checksum before we return the packet. */
-    if(ICMPBUF->type != ICMP_ECHO) {
+    if (ICMPBUF->type != ICMP_ECHO) {
         UIP_STAT(++uip_stat.icmp.drop);
         UIP_STAT(++uip_stat.icmp.typeerr);
         UIP_LOG("icmp: not icmp echo.");
@@ -1070,16 +1068,16 @@
     /* If we are configured to use ping IP address assignment, we use
      the destination IP address of this ping packet and assign it to
      ourself. */
-    #if UIP_PINGADDRCONF
-    if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
+#if UIP_PINGADDRCONF
+    if ((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
         uip_hostaddr[0] = BUF->destipaddr[0];
         uip_hostaddr[1] = BUF->destipaddr[1];
     }
-    #endif /* UIP_PINGADDRCONF */
+#endif /* UIP_PINGADDRCONF */
 
     ICMPBUF->type = ICMP_ECHO_REPLY;
 
-    if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
+    if (ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
         ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
     }
     else {
@@ -1099,7 +1097,7 @@
 
     DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);
 
-    if(BUF->proto != UIP_PROTO_ICMP6) {
+    if (BUF->proto != UIP_PROTO_ICMP6) {
 
         /* We only allow ICMPv6 packets from
                      here. */
@@ -1113,9 +1111,9 @@
 
     /* If we get a neighbor solicitation for our address we should send
      a neighbor advertisement message back. */
-    if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
-        if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
-            if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
+    if (ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
+        if (uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
+            if (ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
 
                 /* Save the sender's address in our neighbor list. */
                 uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
@@ -1141,7 +1139,7 @@
         goto drop;
     }
     else
-    if(ICMPBUF->type == ICMP6_ECHO) {
+    if (ICMPBUF->type == ICMP6_ECHO) {
 
         /* ICMP echo (i.e., ping) processing. This is simple, we only
        change the ICMP type from ECHO to ECHO_REPLY and update the
@@ -1175,23 +1173,23 @@
      UDP/IP headers, but let the UDP application do all the hard
      work. If the application sets uip_slen, it has a packet to
      send. */
-    #if UIP_UDP_CHECKSUMS
+#if UIP_UDP_CHECKSUMS
     uip_len = uip_len - UIP_IPUDPH_LEN;
     uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
-    if(UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
+    if (UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
         UIP_STAT(++uip_stat.udp.drop);
         UIP_STAT(++uip_stat.udp.chkerr);
         UIP_LOG("udp: bad checksum.");
         goto drop;
     }
 
-    #else /* UIP_UDP_CHECKSUMS */
+#else /* UIP_UDP_CHECKSUMS */
     uip_len = uip_len - UIP_IPUDPH_LEN;
-    #endif /* UIP_UDP_CHECKSUMS */
+#endif /* UIP_UDP_CHECKSUMS */
 
     /* Demultiplex this UDP packet between the UDP "connections". */
 
-    for(uip_udp_conn = &uip_udp_conns[0]; uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS]; ++uip_udp_conn) {
+    for (uip_udp_conn = &uip_udp_conns[0]; uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS]; ++uip_udp_conn) {
 
         /* If the local UDP port is non-zero, the connection is considered
        to be used. If so, the local port number is checked against the
@@ -1225,22 +1223,22 @@
     uip_slen = 0;
     UIP_UDP_APPCALL();
 udp_send:
-    if(uip_slen == 0) {
+    if (uip_slen == 0) {
         goto drop;
     }
 
     uip_len = uip_slen + UIP_IPUDPH_LEN;
 
-    #if UIP_CONF_IPV6
+#if UIP_CONF_IPV6
     /* For IPv6, the IP length field does not include the IPv6 IP header
      length. */
 
     BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
     BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-    #else /* UIP_CONF_IPV6 */
+#else /* UIP_CONF_IPV6 */
     BUF->len[0] = (uip_len >> 8);
     BUF->len[1] = (uip_len & 0xff);
-    #endif /* UIP_CONF_IPV6 */
+#endif /* UIP_CONF_IPV6 */
 
     BUF->ttl = uip_udp_conn->ttl;
     BUF->proto = UIP_PROTO_UDP;
@@ -1256,14 +1254,14 @@
 
     uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
 
-    #if UIP_UDP_CHECKSUMS
+#if UIP_UDP_CHECKSUMS
     /* Calculate UDP checksum. */
 
     UDPBUF->udpchksum = ~(uip_udpchksum());
-    if(UDPBUF->udpchksum == 0) {
+    if (UDPBUF->udpchksum == 0) {
         UDPBUF->udpchksum = 0xffff;
     }
-    #endif /* UIP_UDP_CHECKSUMS */
+#endif /* UIP_UDP_CHECKSUMS */
 
     goto ip_send_nolen;
 #endif /* UIP_UDP */
@@ -1273,7 +1271,7 @@
     tcp_input : UIP_STAT(++uip_stat.tcp.recv);
 
     /* Start of TCP input header processing code. */
-    if(uip_tcpchksum() != 0xffff) {
+    if (uip_tcpchksum() != 0xffff) {
 
         /* Compute and check the TCP
                        checksum. */
@@ -1285,7 +1283,7 @@
 
     /* Demultiplex this segment. */
     /* First check any active connections. */
-    for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1]; ++uip_connr) {
+    for (uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1]; ++uip_connr) {
         if
         (
             uip_connr->tcpstateflags != UIP_CLOSED
@@ -1301,15 +1299,15 @@
      either this packet is an old duplicate, or this is a SYN packet
      destined for a connection in LISTEN. If the SYN flag isn't set,
      it is an old packet and we send a RST. */
-    if((BUF->flags & TCP_CTL) != TCP_SYN) {
+    if ((BUF->flags & TCP_CTL) != TCP_SYN) {
         goto reset;
     }
 
     tmp16 = BUF->destport;
 
     /* Next, check listening connections. */
-    for(c = 0; c < UIP_LISTENPORTS; ++c) {
-        if(tmp16 == uip_listenports[c])
+    for (c = 0; c < UIP_LISTENPORTS; ++c) {
+        if (tmp16 == uip_listenports[c])
             goto found_listen;
     }
 
@@ -1317,7 +1315,7 @@
     UIP_STAT(++uip_stat.tcp.synrst);
 reset:
     /* We do not send resets in response to resets. */
-    if(BUF->flags & TCP_RST) {
+    if (BUF->flags & TCP_RST) {
         goto drop;
     }
 
@@ -1347,9 +1345,9 @@
     /* We also have to increase the sequence number we are
      acknowledging. If the least significant byte overflowed, we need
      to propagate the carry to the other bytes as well. */
-    if(++BUF->ackno[3] == 0) {
-        if(++BUF->ackno[2] == 0) {
-            if(++BUF->ackno[1] == 0) {
+    if (++BUF->ackno[3] == 0) {
+        if (++BUF->ackno[2] == 0) {
+            if (++BUF->ackno[1] == 0) {
                 ++BUF->ackno[0];
             }
         }
@@ -1378,20 +1376,20 @@
      CLOSED connections are found. Thanks to Eddie C. Dost for a very
      nice algorithm for the TIME_WAIT search. */
     uip_connr = 0;
-    for(c = 0; c < UIP_CONNS; ++c) {
-        if(uip_conns[c].tcpstateflags == UIP_CLOSED) {
+    for (c = 0; c < UIP_CONNS; ++c) {
+        if (uip_conns[c].tcpstateflags == UIP_CLOSED) {
             uip_connr = &uip_conns[c];
             break;
         }
 
-        if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {
-            if(uip_connr == 0 || uip_conns[c].timer > uip_connr->timer) {
+        if (uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {
+            if (uip_connr == 0 || uip_conns[c].timer > uip_connr->timer) {
                 uip_connr = &uip_conns[c];
             }
         }
     }
 
-    if(uip_connr == 0) {
+    if (uip_connr == 0) {
 
         /* All connections are used already, we drop packet and hope that
        the remote end will retransmit the packet at a time when we
@@ -1427,22 +1425,22 @@
     uip_add_rcv_nxt(1);
 
     /* Parse the TCP MSS option, if present. */
-    if((BUF->tcpoffset & 0xf0) > 0x50) {
-        for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2;) {
+    if ((BUF->tcpoffset & 0xf0) > 0x50) {
+        for (c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2;) {
             opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
-            if(opt == TCP_OPT_END) {
+            if (opt == TCP_OPT_END) {
 
                 /* End of options. */
                 break;
             }
             else
-            if(opt == TCP_OPT_NOOP) {
+            if (opt == TCP_OPT_NOOP) {
                 ++c;
 
                 /* NOP option. */
             }
             else
-            if(opt == TCP_OPT_MSS && uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
+            if (opt == TCP_OPT_MSS && uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
 
                 /* An MSS option with the right option length. */
                 tmp16 = ((u16_t) uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | (u16_t) uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
@@ -1455,7 +1453,7 @@
 
                 /* All other options have a length field, so that we easily
        can skip past them. */
-                if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
+                if (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
 
                     /* If the length field is zero, the options are malformed
          and we don't process them further. */
@@ -1497,7 +1495,7 @@
      any RST and kill our connection. We should in fact check if the
      sequence number of this reset is wihtin our advertised window
      before we accept the reset. */
-    if(BUF->flags & TCP_RST) {
+    if (BUF->flags & TCP_RST) {
         uip_connr->tcpstateflags = UIP_CLOSED;
         UIP_LOG("tcp: got reset, aborting connection.");
         uip_flags = UIP_ABORT;
@@ -1517,7 +1515,12 @@
     /* First, check if the sequence number of the incoming packet is
      what we're expecting next. If not, we send out an ACK with the
      correct numbers in. */
-    if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
+    if
+    (
+        !(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT)
+        &&  ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))
+        )
+    ) {
         if
         (
             (uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0))
@@ -1536,7 +1539,7 @@
      data. If so, we update the sequence number, reset the length of
      the outstanding data, calculate RTT estimations, and reset the
      retransmission timer. */
-    if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
+    if ((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
         uip_add32(uip_connr->snd_nxt, uip_connr->len);
 
         if
@@ -1554,14 +1557,14 @@
             uip_connr->snd_nxt[3] = uip_acc32[3];
 
             /* Do RTT estimation, unless we have done retransmissions. */
-            if(uip_connr->nrtx == 0) {
+            if (uip_connr->nrtx == 0) {
                 signed char m;
                 m = uip_connr->rto - uip_connr->timer;
 
                 /* This is taken directly from VJs original code in his paper */
                 m = m - (uip_connr->sa >> 3);
                 uip_connr->sa += m;
-                if(m < 0) {
+                if (m < 0) {
                     m = -m;
                 }
 
@@ -1582,106 +1585,106 @@
     }
 
     /* Do different things depending on in what state the connection is. */
-    switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
-    /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
+    switch (uip_connr->tcpstateflags & UIP_TS_MASK) {
+        /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
     implemented, since we force the application to close when the
     peer sends a FIN (hence the application goes directly from
     ESTABLISHED to LAST_ACK). */
-    case UIP_SYN_RCVD:
-        /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and
+        case UIP_SYN_RCVD:
+            /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and
        we are waiting for an ACK that acknowledges the data we sent
        out the last time. Therefore, we want to have the UIP_ACKDATA
        flag set. If so, we enter the ESTABLISHED state. */
-        if(uip_flags & UIP_ACKDATA) {
-            uip_connr->tcpstateflags = UIP_ESTABLISHED;
-            uip_flags = UIP_CONNECTED;
-            uip_connr->len = 0;
-            if(uip_len > 0) {
-                uip_flags |= UIP_NEWDATA;
-                uip_add_rcv_nxt(uip_len);
+            if (uip_flags & UIP_ACKDATA) {
+                uip_connr->tcpstateflags = UIP_ESTABLISHED;
+                uip_flags = UIP_CONNECTED;
+                uip_connr->len = 0;
+                if (uip_len > 0) {
+                    uip_flags |= UIP_NEWDATA;
+                    uip_add_rcv_nxt(uip_len);
+                }
+
+                uip_slen = 0;
+                UIP_APPCALL();
+                goto appsend;
             }
 
-            uip_slen = 0;
-            UIP_APPCALL();
-            goto appsend;
-        }
+            goto drop;
+    #if UIP_ACTIVE_OPEN
 
-        goto drop;
-#if UIP_ACTIVE_OPEN
-
-    case UIP_SYN_SENT:
-        /* In SYN_SENT, we wait for a SYNACK that is sent in response to
+        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
        plus one, and we send an ACK. We move into the ESTABLISHED
        state. */
-        if((uip_flags & UIP_ACKDATA) && (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
+            if ((uip_flags & UIP_ACKDATA) && (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
 
-            /* Parse the TCP MSS option, if present. */
-            if((BUF->tcpoffset & 0xf0) > 0x50) {
-                for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2;) {
-                    opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
-                    if(opt == TCP_OPT_END) {
-
-                        /* End of options. */
-                        break;
-                    }
-                    else
-                    if(opt == TCP_OPT_NOOP) {
-                        ++c;
+                /* Parse the TCP MSS option, if present. */
+                if ((BUF->tcpoffset & 0xf0) > 0x50) {
+                    for (c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2;) {
+                        opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
+                        if (opt == TCP_OPT_END) {
 
-                        /* NOP option. */
-                    }
-                    else
-                    if(opt == TCP_OPT_MSS && uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
-
-                        /* An MSS option with the right option length. */
-                        tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
-                        uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS ? UIP_TCP_MSS : tmp16;
+                            /* End of options. */
+                            break;
+                        }
+                        else
+                        if (opt == TCP_OPT_NOOP) {
+                            ++c;
 
-                        /* And we are done processing options. */
-                        break;
-                    }
-                    else {
+                            /* NOP option. */
+                        }
+                        else
+                        if (opt == TCP_OPT_MSS && uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
 
-                        /* All other options have a length field, so that we easily
-           can skip past them. */
-                        if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
+                            /* An MSS option with the right option length. */
+                            tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
+                            uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS ? UIP_TCP_MSS : tmp16;
 
-                            /* If the length field is zero, the options are malformed
-         and we don't process them further. */
+                            /* And we are done processing options. */
                             break;
                         }
+                        else {
 
-                        c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
+                            /* All other options have a length field, so that we easily
+           can skip past them. */
+                            if (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
+
+                                /* If the length field is zero, the options are malformed
+         and we don't process them further. */
+                                break;
+                            }
+
+                            c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
+                        }
                     }
                 }
+
+                uip_connr->tcpstateflags = UIP_ESTABLISHED;
+                uip_connr->rcv_nxt[0] = BUF->seqno[0];
+                uip_connr->rcv_nxt[1] = BUF->seqno[1];
+                uip_connr->rcv_nxt[2] = BUF->seqno[2];
+                uip_connr->rcv_nxt[3] = BUF->seqno[3];
+                uip_add_rcv_nxt(1);
+                uip_flags = UIP_CONNECTED | UIP_NEWDATA;
+                uip_connr->len = 0;
+                uip_len = 0;
+                uip_slen = 0;
+                UIP_APPCALL();
+                goto appsend;
             }
 
-            uip_connr->tcpstateflags = UIP_ESTABLISHED;
-            uip_connr->rcv_nxt[0] = BUF->seqno[0];
-            uip_connr->rcv_nxt[1] = BUF->seqno[1];
-            uip_connr->rcv_nxt[2] = BUF->seqno[2];
-            uip_connr->rcv_nxt[3] = BUF->seqno[3];
-            uip_add_rcv_nxt(1);
-            uip_flags = UIP_CONNECTED | UIP_NEWDATA;
-            uip_connr->len = 0;
-            uip_len = 0;
-            uip_slen = 0;
+            /* Inform the application that the connection failed */
+            uip_flags = UIP_ABORT;
             UIP_APPCALL();
-            goto appsend;
-        }
-
-        /* Inform the application that the connection failed */
-        uip_flags = UIP_ABORT;
-        UIP_APPCALL();
 
-        /* The connection is closed after we send the RST */
-        uip_conn->tcpstateflags = UIP_CLOSED;
-        goto reset;
-#endif /* UIP_ACTIVE_OPEN */
+            /* The connection is closed after we send the RST */
+            uip_conn->tcpstateflags = UIP_CLOSED;
+            goto reset;
+    #endif /* UIP_ACTIVE_OPEN */
 
-    case UIP_ESTABLISHED:
-        /* In the ESTABLISHED state, we call upon the application to feed
+        case UIP_ESTABLISHED:
+            /* In the ESTABLISHED state, we call upon the application to feed
     data into the uip_buf. If the UIP_ACKDATA flag is set, the
     application should put new data into the buffer, otherwise we are
     retransmitting an old segment, and the application should put that
@@ -1691,62 +1694,62 @@
     this side as well, and we send out a FIN and enter the LAST_ACK
     state. We require that there is no outstanding data; otherwise the
     sequence numbers will be screwed up. */
-        if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
-            if(uip_outstanding(uip_connr)) {
-                goto drop;
-            }
+            if (BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
+                if (uip_outstanding(uip_connr)) {
+                    goto drop;
+                }
 
-            uip_add_rcv_nxt(1 + uip_len);
-            uip_flags |= UIP_CLOSE;
-            if(uip_len > 0) {
-                uip_flags |= UIP_NEWDATA;
+                uip_add_rcv_nxt(1 + uip_len);
+                uip_flags |= UIP_CLOSE;
+                if (uip_len > 0) {
+                    uip_flags |= UIP_NEWDATA;
+                }
+
+                UIP_APPCALL();
+                uip_connr->len = 1;
+                uip_connr->tcpstateflags = UIP_LAST_ACK;
+                uip_connr->nrtx = 0;
+    tcp_send_finack:
+                BUF->flags = TCP_FIN | TCP_ACK;
+                goto tcp_send_nodata;
             }
 
-            UIP_APPCALL();
-            uip_connr->len = 1;
-            uip_connr->tcpstateflags = UIP_LAST_ACK;
-            uip_connr->nrtx = 0;
-tcp_send_finack:
-            BUF->flags = TCP_FIN | TCP_ACK;
-            goto tcp_send_nodata;
-        }
+            /* Check the URG flag. If this is set, the segment carries urgent
+       data that we must pass to the application. */
+            if ((BUF->flags & TCP_URG) != 0)
+            {
+    #if UIP_URGDATA > 0
+                uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
+                if (uip_urglen > uip_len) {
+
+                    /* There is more urgent data in the next segment to come. */
+                    uip_urglen = uip_len;
+                }
 
-        /* Check the URG flag. If this is set, the segment carries urgent
-       data that we must pass to the application. */
-        if((BUF->flags & TCP_URG) != 0)
-        {
-#if UIP_URGDATA > 0
-            uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
-            if(uip_urglen > uip_len) {
-
-                /* There is more urgent data in the next segment to come. */
-                uip_urglen = uip_len;
+                uip_add_rcv_nxt(uip_urglen);
+                uip_len -= uip_urglen;
+                uip_urgdata = uip_appdata;
+                uip_appdata += uip_urglen;
+            }
+            else {
+                uip_urglen = 0;
+    #else /* UIP_URGDATA > 0 */
+                uip_appdata = ((char*)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]);
+                uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
+    #endif /* UIP_URGDATA > 0 */
             }
 
-            uip_add_rcv_nxt(uip_urglen);
-            uip_len -= uip_urglen;
-            uip_urgdata = uip_appdata;
-            uip_appdata += uip_urglen;
-        }
-        else {
-            uip_urglen = 0;
-#else /* UIP_URGDATA > 0 */
-            uip_appdata = ((char*)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]);
-            uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
-#endif /* UIP_URGDATA > 0 */
-        }
-
-        /* If uip_len > 0 we have TCP data in the packet, and we flag this
+            /* If uip_len > 0 we have TCP data in the packet, and we flag this
        by setting the UIP_NEWDATA flag and update the sequence number
        we acknowledge. If the application has stopped the dataflow
        using uip_stop(), we must not accept any data packets from the
        remote host. */
-        if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
-            uip_flags |= UIP_NEWDATA;
-            uip_add_rcv_nxt(uip_len);
-        }
+            if (uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
+                uip_flags |= UIP_NEWDATA;
+                uip_add_rcv_nxt(uip_len);
+            }
 
-        /* Check if the available buffer space advertised by the other end
+            /* Check if the available buffer space advertised by the other end
        is smaller than the initial MSS for this connection. If so, we
        set the current MSS to the window size to ensure that the
        application does not send more data than the other end can
@@ -1758,14 +1761,14 @@
        and the application will retransmit it. This is called the
        "persistent timer" and uses the retransmission mechanim.
     */
-        tmp16 = ((u16_t) BUF->wnd[0] << 8) + (u16_t) BUF->wnd[1];
-        if(tmp16 > uip_connr->initialmss || tmp16 == 0) {
-            tmp16 = uip_connr->initialmss;
-        }
+            tmp16 = ((u16_t) BUF->wnd[0] << 8) + (u16_t) BUF->wnd[1];
+            if (tmp16 > uip_connr->initialmss || tmp16 == 0) {
+                tmp16 = uip_connr->initialmss;
+            }
 
-        uip_connr->mss = tmp16;
+            uip_connr->mss = tmp16;
 
-        /* If this packet constitutes an ACK for outstanding data (flagged
+            /* If this packet constitutes an ACK for outstanding data (flagged
        by the UIP_ACKDATA flag, we should call the application since it
        might want to send more data. If the incoming packet had data
        from the peer (as flagged by the UIP_NEWDATA flag), the
@@ -1781,164 +1784,164 @@
        put into the uip_appdata and the length of the data should be
        put into uip_len. If the application don't have any data to
        send, uip_len must be set to 0. */
-        if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
-            uip_slen = 0;
-            UIP_APPCALL();
-
-appsend:
-            if(uip_flags & UIP_ABORT) {
-                uip_slen = 0;
-                uip_connr->tcpstateflags = UIP_CLOSED;
-                BUF->flags = TCP_RST | TCP_ACK;
-                goto tcp_send_nodata;
-            }
-
-            if(uip_flags & UIP_CLOSE) {
+            if (uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
                 uip_slen = 0;
-                uip_connr->len = 1;
-                uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
-                uip_connr->nrtx = 0;
-                BUF->flags = TCP_FIN | TCP_ACK;
-                goto tcp_send_nodata;
-            }
+                UIP_APPCALL();
 
-            /* If uip_slen > 0, the application has data to be sent. */
-            if(uip_slen > 0) {
+    appsend:
+                if (uip_flags & UIP_ABORT) {
+                    uip_slen = 0;
+                    uip_connr->tcpstateflags = UIP_CLOSED;
+                    BUF->flags = TCP_RST | TCP_ACK;
+                    goto tcp_send_nodata;
+                }
 
-                /* If the connection has acknowledged data, the contents of
-       the ->len variable should be discarded. */
-                if((uip_flags & UIP_ACKDATA) != 0) {
-                    uip_connr->len = 0;
+                if (uip_flags & UIP_CLOSE) {
+                    uip_slen = 0;
+                    uip_connr->len = 1;
+                    uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
+                    uip_connr->nrtx = 0;
+                    BUF->flags = TCP_FIN | TCP_ACK;
+                    goto tcp_send_nodata;
                 }
 
-                /* If the ->len variable is non-zero the connection has
+                /* If uip_slen > 0, the application has data to be sent. */
+                if (uip_slen > 0) {
+
+                    /* If the connection has acknowledged data, the contents of
+       the ->len variable should be discarded. */
+                    if ((uip_flags & UIP_ACKDATA) != 0) {
+                        uip_connr->len = 0;
+                    }
+
+                    /* If the ->len variable is non-zero the connection has
        already data in transit and cannot send anymore right
        now. */
-                if(uip_connr->len == 0) {
+                    if (uip_connr->len == 0) {
 
-                    /* The application cannot send more than what is allowed by
+                        /* The application cannot send more than what is allowed by
          the mss (the minumum of the MSS and the available
          window). */
-                    if(uip_slen > uip_connr->mss) {
-                        uip_slen = uip_connr->mss;
-                    }
+                        if (uip_slen > uip_connr->mss) {
+                            uip_slen = uip_connr->mss;
+                        }
 
-                    /* Remember how much data we send out now so that we know
+                        /* Remember how much data we send out now so that we know
          when everything has been acknowledged. */
-                    uip_connr->len = uip_slen;
-                }
-                else {
+                        uip_connr->len = uip_slen;
+                    }
+                    else {
 
-                    /* If the application already had unacknowledged data, we
+                        /* If the application already had unacknowledged data, we
          make sure that the application does not send (i.e.,
          retransmit) out more than it previously sent out. */
-                    uip_slen = uip_connr->len;
+                        uip_slen = uip_connr->len;
+                    }
+                }
+
+                uip_connr->nrtx = 0;
+    apprexmit:
+                uip_appdata = uip_sappdata;
+
+                /* If the application has data to be sent, or if the incoming
+         packet had new data in it, we must send out a packet. */
+                if (uip_slen > 0 && uip_connr->len > 0) {
+
+                    /* Add the length of the IP and TCP headers. */
+                    uip_len = uip_connr->len + UIP_TCPIP_HLEN;
+
+                    /* We always set the ACK flag in response packets. */
+                    BUF->flags = TCP_ACK | TCP_PSH;
+
+                    /* Send the packet. */
+                    goto tcp_send_noopts;
+                }
+
+                /* If there is no data to send, just send out a pure ACK if
+     there is newdata. */
+                if (uip_flags & UIP_NEWDATA) {
+                    uip_len = UIP_TCPIP_HLEN;
+                    BUF->flags = TCP_ACK;
+                    goto tcp_send_noopts;
                 }
             }
 
-            uip_connr->nrtx = 0;
-apprexmit:
-            uip_appdata = uip_sappdata;
-
-            /* If the application has data to be sent, or if the incoming
-         packet had new data in it, we must send out a packet. */
-            if(uip_slen > 0 && uip_connr->len > 0) {
+            goto drop;
 
-                /* Add the length of the IP and TCP headers. */
-                uip_len = uip_connr->len + UIP_TCPIP_HLEN;
+        case UIP_LAST_ACK:
+            /* We can close this connection if the peer has acknowledged our
+       FIN. This is indicated by the UIP_ACKDATA flag. */
+            if (uip_flags & UIP_ACKDATA) {
+                uip_connr->tcpstateflags = UIP_CLOSED;
+                uip_flags = UIP_CLOSE;
+                UIP_APPCALL();
+            }
+            break;
 
-                /* We always set the ACK flag in response packets. */
-                BUF->flags = TCP_ACK | TCP_PSH;
-
-                /* Send the packet. */
-                goto tcp_send_noopts;
+        case UIP_FIN_WAIT_1:
+            /* The application has closed the connection, but the remote host
+       hasn't closed its end yet. Thus we do nothing but wait for a
+       FIN from the other side. */
+            if (uip_len > 0) {
+                uip_add_rcv_nxt(uip_len);
             }
 
-            /* If there is no data to send, just send out a pure ACK if
-     there is newdata. */
-            if(uip_flags & UIP_NEWDATA) {
-                uip_len = UIP_TCPIP_HLEN;
-                BUF->flags = TCP_ACK;
-                goto tcp_send_noopts;
-            }
-        }
-
-        goto drop;
+            if (BUF->flags & TCP_FIN) {
+                if (uip_flags & UIP_ACKDATA) {
+                    uip_connr->tcpstateflags = UIP_TIME_WAIT;
+                    uip_connr->timer = 0;
+                    uip_connr->len = 0;
+                }
+                else {
+                    uip_connr->tcpstateflags = UIP_CLOSING;
+                }
 
-    case UIP_LAST_ACK:
-        /* We can close this connection if the peer has acknowledged our
-       FIN. This is indicated by the UIP_ACKDATA flag. */
-        if(uip_flags & UIP_ACKDATA) {
-            uip_connr->tcpstateflags = UIP_CLOSED;
-            uip_flags = UIP_CLOSE;
-            UIP_APPCALL();
-        }
-        break;
+                uip_add_rcv_nxt(1);
+                uip_flags = UIP_CLOSE;
+                UIP_APPCALL();
+                goto tcp_send_ack;
+            }
+            else
+            if (uip_flags & UIP_ACKDATA) {
+                uip_connr->tcpstateflags = UIP_FIN_WAIT_2;
+                uip_connr->len = 0;
+                goto drop;
+            }
 
-    case UIP_FIN_WAIT_1:
-        /* The application has closed the connection, but the remote host
-       hasn't closed its end yet. Thus we do nothing but wait for a
-       FIN from the other side. */
-        if(uip_len > 0) {
-            uip_add_rcv_nxt(uip_len);
-        }
+            if (uip_len > 0) {
+                goto tcp_send_ack;
+            }
+
+            goto drop;
 
-        if(BUF->flags & TCP_FIN) {
-            if(uip_flags & UIP_ACKDATA) {
+        case UIP_FIN_WAIT_2:
+            if (uip_len > 0) {
+                uip_add_rcv_nxt(uip_len);
+            }
+
+            if (BUF->flags & TCP_FIN) {
                 uip_connr->tcpstateflags = UIP_TIME_WAIT;
                 uip_connr->timer = 0;
-                uip_connr->len = 0;
+                uip_add_rcv_nxt(1);
+                uip_flags = UIP_CLOSE;
+                UIP_APPCALL();
+                goto tcp_send_ack;
             }
-            else {
-                uip_connr->tcpstateflags = UIP_CLOSING;
+
+            if (uip_len > 0) {
+                goto tcp_send_ack;
             }
 
-            uip_add_rcv_nxt(1);
-            uip_flags = UIP_CLOSE;
-            UIP_APPCALL();
+            goto drop;
+
+        case UIP_TIME_WAIT:
             goto tcp_send_ack;
-        }
-        else
-        if(uip_flags & UIP_ACKDATA) {
-            uip_connr->tcpstateflags = UIP_FIN_WAIT_2;
-            uip_connr->len = 0;
-            goto drop;
-        }
-
-        if(uip_len > 0) {
-            goto tcp_send_ack;
-        }
-
-        goto drop;
-
-    case UIP_FIN_WAIT_2:
-        if(uip_len > 0) {
-            uip_add_rcv_nxt(uip_len);
-        }
 
-        if(BUF->flags & TCP_FIN) {
-            uip_connr->tcpstateflags = UIP_TIME_WAIT;
-            uip_connr->timer = 0;
-            uip_add_rcv_nxt(1);
-            uip_flags = UIP_CLOSE;
-            UIP_APPCALL();
-            goto tcp_send_ack;
-        }
-
-        if(uip_len > 0) {
-            goto tcp_send_ack;
-        }
-
-        goto drop;
-
-    case UIP_TIME_WAIT:
-        goto tcp_send_ack;
-
-    case UIP_CLOSING:
-        if(uip_flags & UIP_ACKDATA) {
-            uip_connr->tcpstateflags = UIP_TIME_WAIT;
-            uip_connr->timer = 0;
-        }
+        case UIP_CLOSING:
+            if (uip_flags & UIP_ACKDATA) {
+                uip_connr->tcpstateflags = UIP_TIME_WAIT;
+                uip_connr->timer = 0;
+            }
     }
 
     goto drop;
@@ -1974,7 +1977,7 @@
     uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
     uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr);
 
-    if(uip_connr->tcpstateflags & UIP_STOPPED) {
+    if (uip_connr->tcpstateflags & UIP_STOPPED) {
 
         /* If the connection has issued uip_stop(), we advertise a zero
        window so that the remote host will stop sending data. */
@@ -2046,8 +2049,8 @@
 /*---------------------------------------------------------------------------*/
 void uip_send(const void* data, int len) {
     uip_slen = len;
-    if(len > 0) {
-        if(data != uip_sappdata) {
+    if (len > 0) {
+        if (data != uip_sappdata) {
             memcpy(uip_sappdata, (data), uip_slen);
         }
     }