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:
63:97f481e33cb2
Parent:
51:ab4529a384a6
Child:
66:71a2ef45a035
--- a/stack/pico_socket.c	Mon Sep 16 12:07:35 2013 +0000
+++ b/stack/pico_socket.c	Thu Sep 19 12:38:53 2013 +0000
@@ -24,10 +24,6 @@
 #if defined (PICO_SUPPORT_TCP) || defined (PICO_SUPPORT_UDP)
 
 
-#define PROTO(s) ((s)->proto->proto_number)
-#define PICO_SOCKET4_MTU 1480 /* Ethernet MTU(1500) - IP header size(20) */
-#define PICO_SOCKET6_MTU 1460 /* Ethernet MTU(1500) - IP header size(40) */
-
 #ifdef PICO_SUPPORT_MUTEX
 static void * Mutex = NULL;
 #define LOCK(x) {\
@@ -461,7 +457,7 @@
 
   /* IPv4 */
 #ifdef PICO_SUPPORT_NAT
-  if (pico_ipv4_nat_find(port, NULL, 0, proto)) {
+  if (pico_ipv4_nat_find(port,NULL, 0,proto) == 0) {
     dbg("In use by nat....\n");
     return 0;
   }
@@ -516,28 +512,6 @@
   return -1;
 }
 
-struct pico_socket* pico_sockets_find(uint16_t local,uint16_t remote)
-{
-	struct pico_socket * sock = NULL;
-	struct pico_tree_node *index = NULL;
-	struct pico_sockport *sp = NULL;
-
-	sp = pico_get_sockport(PICO_PROTO_TCP,local);
-	if(sp)
-	{
-		pico_tree_foreach(index,&sp->socks)
-		{
-			if( ((struct pico_socket *)index->keyValue)->remote_port == remote)
-			{
-				sock = (struct pico_socket *)index->keyValue;
-				break;
-			}
-		}
-	}
-
-	return sock;
-}
-
 
 int pico_socket_add(struct pico_socket *s)
 {
@@ -587,7 +561,6 @@
 static void socket_garbage_collect(unsigned long now, void *arg)
 {
   struct pico_socket *s = (struct pico_socket *) arg;
-  IGNORE_PARAMETER(now);
   pico_free(s);
 }
 
@@ -999,7 +972,6 @@
 {
   struct pico_frame *f;
   struct pico_remote_duple *remote_duple = NULL;
-  int socket_mtu = PICO_SOCKET4_MTU;
   int header_offset = 0;
   int total_payload_written = 0;
 #ifdef PICO_SUPPORT_IPV4
@@ -1035,7 +1007,6 @@
 
 #ifdef PICO_SUPPORT_IPV4
   if (IS_SOCK_IPV4(s)) {
-    socket_mtu = PICO_SOCKET4_MTU;
     if ((s->state & PICO_SOCKET_STATE_CONNECTED)) {
       if  (s->remote_addr.ip4.addr != ((struct pico_ip4 *)dst)->addr ) {
         pico_err = PICO_ERR_EADDRNOTAVAIL;
@@ -1058,10 +1029,11 @@
       }
 #     endif
     }
-    #endif
-  } else if (IS_SOCK_IPV6(s)) {
-    socket_mtu = PICO_SOCKET6_MTU;
-    #ifdef PICO_SUPPORT_IPV6
+  }
+#endif
+
+#ifdef PICO_SUPPORT_IPV6
+  if (IS_SOCK_IPV6(s)) {
     if (s->state & PICO_SOCKET_STATE_CONNECTED) {
       if (memcmp(&s->remote_addr, dst, PICO_SIZE_IP6))
         return -1;
@@ -1081,8 +1053,8 @@
       }
 #     endif
     }
+  }
 #endif
-  }
 
   if ((s->state & PICO_SOCKET_STATE_BOUND) == 0) {
     s->local_port = pico_socket_high_port(s->proto->proto_number);
@@ -1107,9 +1079,9 @@
 
   while (total_payload_written < len) {
     int transport_len = (len - total_payload_written) + header_offset; 
-    if (transport_len > socket_mtu)
-      transport_len = socket_mtu;
-    #ifdef PICO_SUPPORT_IPFRAG
+    if (transport_len > PICO_SOCKET_MTU)
+      transport_len = PICO_SOCKET_MTU;
+#ifdef PICO_SUPPORT_IPFRAG
     else {
       if (total_payload_written)
         transport_len -= header_offset; /* last fragment, do not allocate memory for transport header */
@@ -1129,9 +1101,9 @@
       memcpy(f->info, remote_duple, sizeof(struct pico_remote_duple));
     }
 
-    #ifdef PICO_SUPPORT_IPFRAG
-    #ifdef PICO_SUPPORT_UDP
-    if (PROTO(s) == PICO_PROTO_UDP && ((len + header_offset) > socket_mtu)) {
+#ifdef PICO_SUPPORT_IPFRAG
+#  ifdef PICO_SUPPORT_UDP
+    if (PROTO(s) == PICO_PROTO_UDP && ((len + header_offset) > PICO_SOCKET_MTU)) {
       /* hacking way to identify fragmentation frames: payload != transport_hdr -> first frame */
       if (!total_payload_written) {
         frag_dbg("FRAG: first fragmented frame %p | len = %u offset = 0\n", f, f->payload_len);
@@ -2017,7 +1989,7 @@
     if (mode & PICO_SHUT_RDWR)
       pico_socket_alter_state(s, PICO_SOCKET_STATE_CLOSED, PICO_SOCKET_STATE_CLOSING |PICO_SOCKET_STATE_BOUND | PICO_SOCKET_STATE_CONNECTED, 0);
     else if (mode & PICO_SHUT_RD)
-      pico_socket_alter_state(s, 0, PICO_SOCKET_STATE_BOUND, 0);
+      pico_socket_alter_state(s, PICO_SOCKET_STATE_BOUND, 0, 0);
   }
 #endif
 #ifdef PICO_SUPPORT_TCP
@@ -2080,8 +2052,7 @@
 #else
 static inline int pico_transport_crc_check(struct pico_frame *f)
 {
-	IGNORE_PARAMETER(f);
-	return 1;
+  return 1;
 }
 #endif /* PICO_SUPPORT_CRC */
 
@@ -2179,7 +2150,7 @@
   start = sp_tcp;
 
   while (loop_score > SL_LOOP_MIN && sp_tcp != NULL) {
-    struct pico_tree_node * index = NULL;
+    struct pico_tree_node * index;
     pico_tree_foreach(index, &sp_tcp->socks){
       s = index->keyValue;
       loop_score = pico_tcp_output(s, loop_score);
@@ -2193,7 +2164,7 @@
     }
 
     /* check if RB_FOREACH ended, if not, break to keep the cur sp_tcp */
-    if (index && index->keyValue)
+    if (s != NULL)
       break;
 
     index_tcp = pico_tree_next(index_tcp);