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.

Files at this revision

API Documentation at this revision

Comitter:
tass
Date:
Thu Nov 21 09:48:05 2013 +0000
Parent:
121:296cd46e5e5b
Child:
123:dd26752a4538
Commit message:
Update from masterbranch.

Changed in this revision

include/pico_constants.h Show annotated file Show diff for this revision Revisions of this file
modules/pico_dhcp_common.h Show annotated file Show diff for this revision Revisions of this file
modules/pico_dns_client.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_igmp.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_ipv4.h Show annotated file Show diff for this revision Revisions of this file
modules/pico_tcp.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_zmq.c Show annotated file Show diff for this revision Revisions of this file
stack/pico_socket.c Show annotated file Show diff for this revision Revisions of this file
--- a/include/pico_constants.h	Thu Nov 21 09:35:58 2013 +0000
+++ b/include/pico_constants.h	Thu Nov 21 09:48:05 2013 +0000
@@ -51,22 +51,22 @@
 static inline uint16_t short_from(void *_p)
 {
   unsigned char *p = (unsigned char *)_p;
-  uint16_t r, p0, p1;
-  p0 = p[0];
-  p1 = p[1];
-  r = (uint16_t)((p1 << 8u) + p0);
+  uint16_t r, _p0, _p1;
+  _p0 = p[0];
+  _p1 = p[1];
+  r = (uint16_t)((_p1 << 8u) + _p0);
   return r;
 }
 
 static inline uint32_t long_from(void *_p)
 {
   unsigned char *p = (unsigned char *)_p;
-  uint32_t r, p0, p1, p2, p3;
-  p0 = p[0];
-  p1 = p[1];
-  p2 = p[2];
-  p3 = p[3];
-  r = (p3 << 24) + (p2 << 16) + (p1 << 8) + p0;
+  uint32_t r, _p0, _p1, _p2, _p3;
+  _p0 = p[0];
+  _p1 = p[1];
+  _p2 = p[2];
+  _p3 = p[3];
+  r = (_p3 << 24) + (_p2 << 16) + (_p1 << 8) + _p0;
   return r;
 }
 
--- a/modules/pico_dhcp_common.h	Thu Nov 21 09:35:58 2013 +0000
+++ b/modules/pico_dhcp_common.h	Thu Nov 21 09:48:05 2013 +0000
@@ -100,7 +100,7 @@
 	char    hostname[64];
 	char    bootp_filename[128];
 	uint32_t dhcp_magic;
-	uint8_t options[0];
+	uint8_t options[];
 };
 
 struct __attribute__((packed)) pico_dhcp_opt
@@ -130,10 +130,10 @@
       uint8_t value;
     } opt_overload;
     struct {
-      char name[0];
+      char name[1];
     } tftp_server;
     struct {
-      char name[0];
+      char name[1];
     } bootfile;
     struct {
       uint8_t type;
@@ -142,10 +142,10 @@
       struct pico_ip4 ip;
     } server_id;
     struct {
-      uint8_t code[0];
+      uint8_t code[1];
     } param_list;
     struct {
-      char error[0];
+      char error[1];
     } message;
     struct {
       uint16_t size;
@@ -157,10 +157,10 @@
       uint32_t time;
     } rebinding_time;
     struct {
-      uint8_t id[0];
+      uint8_t id[1];
     } vendor_id;
     struct {
-      uint8_t id[0];
+      uint8_t id[1];
     } client_id;
   } ext;
 };
--- a/modules/pico_dns_client.c	Thu Nov 21 09:35:58 2013 +0000
+++ b/modules/pico_dns_client.c	Thu Nov 21 09:48:05 2013 +0000
@@ -113,7 +113,7 @@
   uint16_t qclass;
   uint32_t ttl;
   uint16_t rdlength;
-  uint8_t rdata[0];
+  uint8_t rdata[];
 };
 
 struct pico_dns_ns
--- a/modules/pico_igmp.c	Thu Nov 21 09:35:58 2013 +0000
+++ b/modules/pico_igmp.c	Thu Nov 21 09:48:05 2013 +0000
@@ -94,7 +94,7 @@
   uint8_t rsq;
   uint8_t qqic;
   uint16_t sources;
-  uint32_t source_addr[0];
+  uint32_t source_addr[];
 };
 
 struct __attribute__((packed)) igmpv3_group_record {
@@ -102,7 +102,7 @@
   uint8_t aux;
   uint16_t sources;
   uint32_t mcast_group;
-  uint32_t source_addr[0];
+  uint32_t source_addr[];
 };
 
 struct __attribute__((packed)) igmpv3_report {
@@ -111,7 +111,7 @@
   uint16_t crc;
   uint16_t res1;
   uint16_t groups;
-  struct igmpv3_group_record record[0];
+  struct igmpv3_group_record record[];
 };
 
 struct igmp_parameters {
--- a/modules/pico_ipv4.h	Thu Nov 21 09:35:58 2013 +0000
+++ b/modules/pico_ipv4.h	Thu Nov 21 09:48:05 2013 +0000
@@ -37,7 +37,7 @@
   uint16_t crc;
   struct pico_ip4 src;
   struct pico_ip4 dst;
-  uint8_t options[0];
+  uint8_t options[];
 };
 
 struct __attribute__((packed)) pico_ipv4_pseudo_hdr
--- a/modules/pico_tcp.c	Thu Nov 21 09:35:58 2013 +0000
+++ b/modules/pico_tcp.c	Thu Nov 21 09:48:05 2013 +0000
@@ -21,7 +21,7 @@
 #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)
 
-#define PICO_TCP_RTO_MIN 10
+#define PICO_TCP_RTO_MIN 50
 #define PICO_TCP_RTO_MAX 120000
 #define PICO_TCP_IW 		 2
 #define PICO_TCP_SYN_TO	 1000u
@@ -854,7 +854,9 @@
 {
   struct pico_socket_tcp *t = (struct pico_socket_tcp *)arg;
   IGNORE_PARAMETER(when);
-  if (TCPSTATE(&t->sock) == PICO_SOCKET_STATE_TCP_SYN_SENT) {
+  if (TCPSTATE(&t->sock) == PICO_SOCKET_STATE_TCP_SYN_SENT
+	&& !(t->sock.state & PICO_SOCKET_STATE_SHUT_LOCAL)
+	&& !(t->sock.state & PICO_SOCKET_STATE_SHUT_REMOTE)) {
     if (t->backoff > PICO_TCP_MAX_CONNECT_RETRIES) {
       tcp_dbg("TCP> Connection timeout. \n");
       if (t->sock.wakeup)
@@ -1117,7 +1119,7 @@
     hdr->seq = 0U;
   }
 
-  hdr->ack = hdr_rcv->seq + long_be(fr->payload_len);
+  hdr->ack = long_be(SEQN(fr) + fr->payload_len);
 
   t->rcv_ackd = t->rcv_nxt;
   f->start = f->transport_hdr + PICO_SIZE_TCPHDR;
@@ -1969,7 +1971,6 @@
     /* the RST is acceptable if the ACK field acknowledges the SYN */
     if ((t->snd_nxt + 1) == ACKN(f)) {  /* valid, got to closed state */
       tcp_force_closed(s);
-      tcp_wakeup_pending(s, PICO_SOCK_EV_FIN);
       pico_err = PICO_ERR_ECONNRESET;
       tcp_wakeup_pending(s, PICO_SOCK_EV_ERR);
       pico_socket_del(&t->sock);  /* delete socket */
@@ -2418,6 +2419,13 @@
 	struct pico_socket_tcp *t=(struct pico_socket_tcp *)sck;
 	if(t->tcpq_out.frames == 0)
 	{
+	    // canceling retrans timer when closing
+		if(t->retrans_tmr)
+	    {
+		    pico_timer_cancel(t->retrans_tmr);
+		    t->retrans_tmr = NULL;
+  	    }
+
 		if(!checkLocalClosing(sck))
 			checkRemoteClosing(sck);
 	}
--- a/modules/pico_zmq.c	Thu Nov 21 09:35:58 2013 +0000
+++ b/modules/pico_zmq.c	Thu Nov 21 09:48:05 2013 +0000
@@ -33,7 +33,7 @@
 struct __attribute__((packed)) zmq_msg {
    uint8_t flags;
     uint8_t len;
-    char    txt[0];
+    char    txt[];
 };
 
 struct zmq_socket;
@@ -351,6 +351,7 @@
 {
   struct pico_ip4 ip = {0};
   struct zmq_connector *z_c;
+  uint8_t sockopts = 1;
   if (pico_string_to_ipv4(address, &ip.addr) < 0) {
     dbg("FIXME!! I need to synchronize with the dns client to get to my publisher :(\n");
     return -1;
@@ -366,6 +367,7 @@
     pico_free(z_c);
     return -1;
   }
+  pico_socket_setoption(z_c->sock, PICO_TCP_NODELAY, &sockopts);
   if (pico_socket_connect(z_c->sock, &ip, short_be(port)) < 0)
     return -1;
   zmq_connector_add(z, z_c);
@@ -376,12 +378,15 @@
 {
   struct pico_socket *s;
   struct pico_ip4 inaddr_any = {0};
+  uint8_t sockopts = 1;
   uint16_t port = short_be(_port);
   ZMQ z = NULL;
   s = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_TCP, &cb_tcp0mq);
   if (!s)
     return NULL;
  
+  pico_socket_setoption(s, PICO_TCP_NODELAY, &sockopts);
+
   dbg("zmq_publisher: BIND\n");
   if (pico_socket_bind(s, &inaddr_any, &port)!= 0) {
     dbg("zmq publisher: BIND failed\n");
--- a/stack/pico_socket.c	Thu Nov 21 09:35:58 2013 +0000
+++ b/stack/pico_socket.c	Thu Nov 21 09:48:05 2013 +0000
@@ -776,7 +776,8 @@
       pico_tcp_input(found,f);
       if ((found->ev_pending) && found->wakeup) {
         found->wakeup(found->ev_pending, found);
-        found->ev_pending = 0;
+        if(!found->parent)
+        	found->ev_pending = 0;
       }
       return 0;
     } else {
@@ -2171,7 +2172,8 @@
       loop_score = pico_tcp_output(s, loop_score);
       if ((s->ev_pending) && s->wakeup) {
         s->wakeup(s->ev_pending, s);
-        s->ev_pending = 0;
+        if(!s->parent)
+        	s->ev_pending = 0;
       }
       if (loop_score <= 0) {
         loop_score = 0;
@@ -2282,7 +2284,9 @@
             default:
               pico_err = PICO_ERR_EHOSTUNREACH;
           }
+          s->state |= PICO_SOCKET_STATE_SHUT_REMOTE;
           s->wakeup(PICO_SOCK_EV_ERR, s);
+
         }
         break;
       }