Free (GPLv2) TCP/IP stack developed by TASS Belgium

Dependents:   lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more

PicoTCP. Copyright (c) 2013 TASS Belgium NV.

Released under the GNU General Public License, version 2.

Different licensing models may exist, at the sole discretion of the Copyright holders.

Official homepage: http://www.picotcp.com

Bug tracker: https://github.com/tass-belgium/picotcp/issues

Development steps:

  • initial integration with mbed RTOS
  • generic mbed Ethernet driver
  • high performance NXP LPC1768 specific Ethernet driver
  • Multi-threading support for mbed RTOS
  • Berkeley sockets and integration with the New Socket API
  • Fork of the apps running on top of the New Socket API
  • Scheduling optimizations
  • Debugging/benchmarking/testing

Demo application (measuring TCP sender performance):

Import programlpc1768-picotcp-demo

A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.

Revision:
49:4b404dd2c97a
Parent:
48:40fc4462265c
Child:
51:ab4529a384a6
--- a/modules/pico_tcp.c	Fri Aug 02 07:28:05 2013 +0000
+++ b/modules/pico_tcp.c	Mon Aug 05 12:58:56 2013 +0000
@@ -16,6 +16,7 @@
 #include "pico_queue.h"
 #include "pico_tree.h"
 
+#define TCP_STATE(s) (s->state & PICO_SOCKET_STATE_TCP)
 #define TCP_SOCK(s) ((struct pico_socket_tcp *)s)
 #define SEQN(f) (f?(long_be(((struct pico_tcp_hdr *)(f->transport_hdr))->seq)):0)
 #define ACKN(f) (f?(long_be(((struct pico_tcp_hdr *)(f->transport_hdr))->ack)):0)
@@ -51,6 +52,11 @@
 #define tcp_dbg(...) do{}while(0)
 //#define tcp_dbg dbg
 
+struct tcp_port_pair
+{
+    uint16_t local;
+    uint16_t remote;
+};
 
 #ifdef PICO_SUPPORT_MUTEX
 static void * Mutex = NULL;
@@ -1956,7 +1962,7 @@
         action->ack(s,f);
       }
     }
-    if (f->payload_len > 0) {
+    if (f->payload_len > 0 && !(s->state & PICO_SOCKET_STATE_CLOSED)) {
       ret = f->payload_len;
       if (action->data)
         action->data(s,f);
@@ -2002,15 +2008,20 @@
 
 void zombie_timer(unsigned long time, void *param)
 {
-    struct pico_socket_tcp * t = (struct pico_socket_tcp *)param;
-    if(pico_sockets_find(param) && ((t->sock.state & PICO_SOCKET_STATE_TCP ) == PICO_SOCKET_STATE_TCP_LAST_ACK) )
+    struct tcp_port_pair * ports = (struct tcp_port_pair *)param;
+    if(ports)
     {
-        (t->sock).state &= 0x00FFU;
-        (t->sock).state |= PICO_SOCKET_STATE_TCP_CLOSED;
-        (t->sock).state &= 0xFF00U;
-        (t->sock).state |= PICO_SOCKET_STATE_CLOSED;
-        tcp_dbg("Deleting zombie socket %p\n",param);
-        pico_socket_del(&t->sock);
+        struct pico_socket_tcp * t = (struct pico_socket_tcp *)pico_sockets_find(ports->local,ports->remote);
+        if(t)
+        {
+            (t->sock).state &= 0x00FFU;
+            (t->sock).state |= PICO_SOCKET_STATE_TCP_CLOSED;
+            (t->sock).state &= 0xFF00U;
+            (t->sock).state |= PICO_SOCKET_STATE_CLOSED;
+            tcp_dbg("Deleting zombie socket %p\n",param);
+            pico_socket_del(&t->sock);
+        }
+        pico_free(ports);
     }
 }
 
@@ -2083,6 +2094,9 @@
       s->state &= 0x00FFU;
       s->state |= PICO_SOCKET_STATE_TCP_FIN_WAIT1;
     } else if ((s->state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT) {
+        struct tcp_port_pair *pair = (struct tcp_port_pair *)pico_zalloc(sizeof(struct tcp_port_pair));
+        pair->local = s->local_port;
+        pair->remote = s->remote_port;
       /* send fin if queue empty and in state shut local (write) */
       tcp_send_fin(t);
       /* change tcp state to LAST_ACK */
@@ -2090,7 +2104,7 @@
       s->state |= PICO_SOCKET_STATE_TCP_LAST_ACK;
       tcp_dbg("TCP> STATE: LAST_ACK.\n");
       // start zombie timer
-      pico_timer_add(PICO_TCP_ZOMBIE_TO,&zombie_timer,(void *)t);
+      pico_timer_add(PICO_TCP_ZOMBIE_TO,&zombie_timer,(void *)pair);
     }
   }
   return loop_score;