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:
Fri Sep 27 12:43:36 2013 +0000
Parent:
72:887bc44746ff
Child:
74:c146c4e346c4
Commit message:
Import from master branch.

Changed in this revision

include/pico_constants.h Show annotated file Show diff for this revision Revisions of this file
include/pico_frame.h Show annotated file Show diff for this revision Revisions of this file
include/pico_socket.h Show annotated file Show diff for this revision Revisions of this file
include/pico_stack.h Show annotated file Show diff for this revision Revisions of this file
modules/pico_dhcp_client.c 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_http_client.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_http_server.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_icmp4.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_icmp4.h 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.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_nat.c 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_udp.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_arp.c Show annotated file Show diff for this revision Revisions of this file
stack/pico_device.c Show annotated file Show diff for this revision Revisions of this file
stack/pico_frame.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
stack/pico_stack.c Show annotated file Show diff for this revision Revisions of this file
--- a/include/pico_constants.h	Fri Sep 27 06:27:23 2013 +0000
+++ b/include/pico_constants.h	Fri Sep 27 12:43:36 2013 +0000
@@ -8,7 +8,7 @@
 /* Included from pico_config.h */
 /** Endian-dependant constants **/
 
-extern volatile uint64_t pico_tick;
+extern volatile unsigned long pico_tick;
 
 #ifdef PICO_BIGENDIAN
 
--- a/include/pico_frame.h	Fri Sep 27 06:27:23 2013 +0000
+++ b/include/pico_frame.h	Fri Sep 27 12:43:36 2013 +0000
@@ -47,7 +47,7 @@
    */
   struct pico_device *dev;
 
-  uint64_t timestamp;
+  uint32_t timestamp;
 
   /* Failures due to bad datalink addressing. */
   uint16_t failure_count;
--- a/include/pico_socket.h	Fri Sep 27 06:27:23 2013 +0000
+++ b/include/pico_socket.h	Fri Sep 27 12:43:36 2013 +0000
@@ -1,3 +1,5 @@
+#define MBED
+
 /*********************************************************************
 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
 See LICENSE and COPYING for usage.
@@ -10,8 +12,11 @@
 #include "pico_config.h"
 #include "pico_protocol.h"
 
-//#define PICO_DEFAULT_SOCKETQ (128 * 1024)
-#define PICO_DEFAULT_SOCKETQ (4 * 1024)
+#ifndef MBED
+	#define PICO_DEFAULT_SOCKETQ (128 * 1024)
+#else
+	#define PICO_DEFAULT_SOCKETQ (4 * 1024)
+#endif
 
 #define PICO_SHUT_RD   1
 #define PICO_SHUT_WR   2
--- a/include/pico_stack.h	Fri Sep 27 06:27:23 2013 +0000
+++ b/include/pico_stack.h	Fri Sep 27 12:43:36 2013 +0000
@@ -62,7 +62,7 @@
 int pico_source_is_local(struct pico_frame *f);
 int pico_destination_is_local(struct pico_frame *f);
 void pico_store_network_origin(void *src, struct pico_frame *f);
-struct pico_timer *pico_timer_add(uint64_t expire, void (*timer)(uint64_t, void *), void *arg);
+struct pico_timer *pico_timer_add(uint32_t expire, void (*timer)(uint32_t, void *), void *arg);
 void pico_timer_cancel(struct pico_timer *t);
 uint32_t pico_rand(void);
 void pico_rand_feed(uint32_t feed);
--- a/modules/pico_dhcp_client.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_dhcp_client.c	Fri Sep 27 12:43:36 2013 +0000
@@ -67,7 +67,7 @@
   uint32_t *uid;
   enum dhcp_client_state state;
   void (*cb)(void* dhcpc, int code);
-  uint64_t init_timestamp;
+  uint32_t init_timestamp;
   struct pico_socket *s;
   struct pico_ip4 address;
   struct pico_ip4 netmask;
@@ -156,7 +156,7 @@
     return NULL;
 }
 
-static void pico_dhcp_client_init_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_init_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -178,7 +178,7 @@
   return;
 }
 
-static void pico_dhcp_client_requesting_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_requesting_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -198,7 +198,7 @@
   return;
 }
 
-static void pico_dhcp_client_renewing_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_renewing_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -213,7 +213,7 @@
   return;
 }
 
-static void pico_dhcp_client_rebinding_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_rebinding_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -228,7 +228,7 @@
   return;
 }
 
-static void pico_dhcp_client_T1_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_T1_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -242,7 +242,7 @@
   return;
 }
 
-static void pico_dhcp_client_T2_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_T2_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -257,7 +257,7 @@
   return;
 }
 
-static void pico_dhcp_client_lease_timer(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_lease_timer(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -272,7 +272,7 @@
   return;
 }
 
-static void pico_dhcp_client_reinit(uint64_t __attribute__((unused)) now, void *arg)
+static void pico_dhcp_client_reinit(uint32_t __attribute__((unused)) now, void *arg)
 {
   struct pico_dhcp_client_cookie *dhcpc = (struct pico_dhcp_client_cookie *)arg;
 
@@ -575,7 +575,8 @@
   /* RFC2131 ch 4.3.2 ... The client SHOULD use the parameters in the DHCPACK message for configuration */
   if (dhcpc->state == DHCP_CLIENT_STATE_REQUESTING)
     dhcpc->address.addr = hdr->yiaddr;
-    
+
+
   /* close the socket used for address (re)acquisition */
   pico_socket_close(dhcpc->s);
   /* delete the link with address 0.0.0.0, add new link with acquired address */
@@ -812,7 +813,7 @@
       optlen = PICO_DHCP_OPTLEN_MSGTYPE + PICO_DHCP_OPTLEN_MAXMSGSIZE + PICO_DHCP_OPTLEN_PARAMLIST + PICO_DHCP_OPTLEN_END;
       hdr = pico_zalloc((size_t)(sizeof(struct pico_dhcp_hdr) + optlen));
       /* specific options */
-      offset += pico_dhcp_opt_maxmsgsize(&hdr->options[offset], DHCP_CLIENT_MAXMSGZISE);
+      offset = (uint16_t)(offset + pico_dhcp_opt_maxmsgsize(&hdr->options[offset], DHCP_CLIENT_MAXMSGZISE));
       break;
 
     case PICO_DHCP_MSG_REQUEST:
@@ -821,10 +822,10 @@
               + PICO_DHCP_OPTLEN_END;
       hdr = pico_zalloc(sizeof(struct pico_dhcp_hdr) + optlen);
       /* specific options */
-      offset += pico_dhcp_opt_maxmsgsize(&hdr->options[offset], DHCP_CLIENT_MAXMSGZISE);
+      offset = (uint16_t)(offset+pico_dhcp_opt_maxmsgsize(&hdr->options[offset], DHCP_CLIENT_MAXMSGZISE));
       if (dhcpc->state == DHCP_CLIENT_STATE_REQUESTING) {
-        offset += pico_dhcp_opt_reqip(&hdr->options[offset], &dhcpc->address);
-        offset += pico_dhcp_opt_serverid(&hdr->options[offset], &dhcpc->server_id);
+        offset = (uint16_t)(offset+pico_dhcp_opt_reqip(&hdr->options[offset], &dhcpc->address));
+        offset = (uint16_t)(offset+pico_dhcp_opt_serverid(&hdr->options[offset], &dhcpc->server_id));
       }
       break;
 
@@ -833,9 +834,9 @@
   }
 
   /* common options */
-  offset += pico_dhcp_opt_msgtype(&hdr->options[offset], msg_type);
-  offset += pico_dhcp_opt_paramlist(&hdr->options[offset]);
-  offset += pico_dhcp_opt_end(&hdr->options[offset]);
+  offset = (uint16_t)(offset+pico_dhcp_opt_msgtype(&hdr->options[offset], msg_type));
+  offset = (uint16_t)(offset+pico_dhcp_opt_paramlist(&hdr->options[offset]));
+  offset = (uint16_t)(offset+pico_dhcp_opt_end(&hdr->options[offset]));
 
   switch (dhcpc->state)
   {
--- a/modules/pico_dns_client.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_dns_client.c	Fri Sep 27 12:43:36 2013 +0000
@@ -73,7 +73,7 @@
 #define PICO_DNS_IPV4_ADDR_LEN 16
 
 static void pico_dns_client_callback(uint16_t ev, struct pico_socket *s);
-static void pico_dns_client_retransmission(uint64_t now, void *arg);
+static void pico_dns_client_retransmission(uint32_t now, void *arg);
 
 /* RFC 1035 section 4. MESSAGES */
 struct __attribute__((packed)) pico_dns_name
@@ -516,7 +516,7 @@
   return 0;
 }
 
-static void pico_dns_client_retransmission(uint64_t now, void *arg)
+static void pico_dns_client_retransmission(uint32_t now, void *arg)
 {
   struct pico_dns_query *q = NULL;
   struct pico_dns_query dummy;
--- a/modules/pico_http_client.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_http_client.c	Fri Sep 27 12:43:36 2013 +0000
@@ -357,7 +357,7 @@
 
 					if(tmpLenRead > 0)
 					{
-						client->header->contentLengthOrChunk -= tmpLenRead;
+						client->header->contentLengthOrChunk = client->header->contentLengthOrChunk - (uint32_t)tmpLenRead;
 					}
 					else if(tmpLenRead < 0)
 					{
@@ -387,7 +387,7 @@
 			lenRead = pico_socket_read(client->sck,(void *)data,size);
 
 			if(lenRead)
-				client->header->contentLengthOrChunk -= lenRead;
+				client->header->contentLengthOrChunk = client->header->contentLengthOrChunk - (uint32_t)lenRead;
 		}
 
 		return lenRead;
@@ -504,7 +504,7 @@
 	}
 
 	//
-	headerSize += (uint16_t)strlen(uriData->host) + (uint16_t)strlen(uriData->resource) + pico_itoa(uriData->port,port) + 4u; // 3 = size(CRLF + \0)
+	headerSize = (uint16_t)(headerSize + strlen(uriData->host) + strlen(uriData->resource) + pico_itoa(uriData->port,port) + 4u); // 3 = size(CRLF + \0)
 	header = pico_zalloc(headerSize);
 
 	if(!header)
--- a/modules/pico_http_server.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_http_server.c	Fri Sep 27 12:43:36 2013 +0000
@@ -583,7 +583,7 @@
 	while( client->bufferSent < client->bufferSize &&
 	(length = (uint16_t)pico_socket_write(client->sck,client->buffer+client->bufferSent,client->bufferSize-client->bufferSent)) > 0 )
 	{
-		client->bufferSent += length;
+		client->bufferSent = (uint16_t)(client->bufferSent + length);
 		server.wakeup(EV_HTTP_PROGRESS,client->connectionID);
 	}
 
--- a/modules/pico_icmp4.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_icmp4.c	Fri Sep 27 12:43:36 2013 +0000
@@ -158,7 +158,7 @@
   uint16_t seq;
   uint16_t size;
   int count;
-  uint64_t timestamp;
+  uint32_t timestamp;
   int interval;
   int timeout;
   void (*cb)(struct pico_icmp4_stats*);
@@ -198,7 +198,7 @@
 }
 
 
-static void ping_timeout(uint64_t now, void *arg)
+static void ping_timeout(uint32_t now, void *arg)
 {
   struct pico_icmp4_ping_cookie *cookie = (struct pico_icmp4_ping_cookie *)arg;
   IGNORE_PARAMETER(now);
@@ -220,7 +220,7 @@
   }
 }
 
-static void next_ping(uint64_t now, void *arg);
+static void next_ping(uint32_t now, void *arg);
 static inline void send_ping(struct pico_icmp4_ping_cookie *cookie)
 {
   pico_icmp4_send_echo(cookie);
@@ -230,7 +230,7 @@
     pico_timer_add((long unsigned int)cookie->interval, next_ping, cookie);
 }
 
-static void next_ping(uint64_t now, void *arg)
+static void next_ping(uint32_t now, void *arg)
 {
   struct pico_icmp4_ping_cookie *newcookie, *cookie = (struct pico_icmp4_ping_cookie *)arg;
   IGNORE_PARAMETER(now);
--- a/modules/pico_icmp4.h	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_icmp4.h	Fri Sep 27 12:43:36 2013 +0000
@@ -129,7 +129,7 @@
   struct pico_ip4 dst;
   unsigned long size;
   unsigned long seq;
-  uint64_t time;
+  uint32_t time;
   unsigned long ttl;
   int err;
 };
--- a/modules/pico_igmp.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_igmp.c	Fri Sep 27 12:43:36 2013 +0000
@@ -129,8 +129,8 @@
 struct igmp_timer {
   uint8_t type;
   uint8_t stopped;
-  uint64_t start;
-  uint64_t delay;
+  uint32_t start;
+  uint32_t delay;
   struct pico_ip4 mcast_link;
   struct pico_ip4 mcast_group;
   struct pico_frame *f;
@@ -212,7 +212,7 @@
   return 0;
 }
 
-static void pico_igmp_timer_expired(uint64_t now, void *arg)
+static void pico_igmp_timer_expired(uint32_t now, void *arg)
 {
   struct igmp_timer *t = NULL, *timer = NULL, test = {0};
 
@@ -619,9 +619,9 @@
         report_type = IGMP_TYPE_LEAVE_GROUP;
 
       p->f = pico_proto_ipv4.alloc(&pico_proto_ipv4, IP_OPTION_ROUTER_ALERT_LEN + sizeof(struct igmp_message));
-      p->f->net_len += IP_OPTION_ROUTER_ALERT_LEN;
+      p->f->net_len = (uint16_t)(p->f->net_len + IP_OPTION_ROUTER_ALERT_LEN);
       p->f->transport_hdr += IP_OPTION_ROUTER_ALERT_LEN;
-      p->f->transport_len -= IP_OPTION_ROUTER_ALERT_LEN;
+      p->f->transport_len = (uint16_t)(p->f->transport_len - IP_OPTION_ROUTER_ALERT_LEN);
       p->f->dev = pico_ipv4_link_find(&p->mcast_link);
       /* p->f->len is correctly set by alloc */
 
@@ -821,9 +821,9 @@
 
       len = (uint16_t)(sizeof(struct igmpv3_report) + sizeof(struct igmpv3_group_record) + (sources * sizeof(struct pico_ip4)));
       p->f = pico_proto_ipv4.alloc(&pico_proto_ipv4, (uint16_t)(IP_OPTION_ROUTER_ALERT_LEN + len));
-      p->f->net_len += IP_OPTION_ROUTER_ALERT_LEN;
+      p->f->net_len = (uint16_t)(p->f->net_len + IP_OPTION_ROUTER_ALERT_LEN);
       p->f->transport_hdr += IP_OPTION_ROUTER_ALERT_LEN;
-      p->f->transport_len -= IP_OPTION_ROUTER_ALERT_LEN;
+      p->f->transport_len = (uint16_t)(p->f->transport_len - IP_OPTION_ROUTER_ALERT_LEN);
       p->f->dev = pico_ipv4_link_find(&p->mcast_link);
       /* p->f->len is correctly set by alloc */
 
@@ -1068,7 +1068,7 @@
 static int rtimrtct(struct igmp_parameters *p)
 {
   struct igmp_timer *t = NULL;
-  uint64_t time_to_run = 0;
+  uint32_t time_to_run = 0;
 
   igmp_dbg("IGMP: event = query received | action = reset timer if max response time < current timer\n");
 
--- a/modules/pico_ipv4.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_ipv4.c	Fri Sep 27 12:43:36 2013 +0000
@@ -297,7 +297,7 @@
       frag.dst.addr = long_be(hdr->dst.addr);
       pfrag = pico_tree_findKey(&pico_ipv4_fragmented_tree, &frag);
       if (pfrag) {
-        pfrag->total_len += (short_be(hdr->len) - (*f)->net_len);
+        pfrag->total_len = (uint16_t)(pfrag->total_len + (short_be(hdr->len) - (*f)->net_len));
         pico_tree_insert(pfrag->t, *f);
         return 0;
       } else {
@@ -314,7 +314,7 @@
     frag.dst.addr = long_be(hdr->dst.addr);
     pfrag = pico_tree_findKey(&pico_ipv4_fragmented_tree, &frag);
     if (pfrag) {
-      pfrag->total_len += (short_be(hdr->len) - (*f)->net_len);
+      pfrag->total_len = (uint16_t)(pfrag->total_len + (short_be(hdr->len) - (*f)->net_len));
       reassembly_dbg("REASSEMBLY: fragmented packet in tree, reassemble packet of %u data bytes\n", pfrag->total_len);
       f_new = self->alloc(self, pfrag->total_len);
 
@@ -344,7 +344,7 @@
           pico_ipv4_fragmented_cleanup(pfrag);
           return -1;
         }
-        running_offset += (data_len / 8);
+        running_offset = (uint16_t)(running_offset + (data_len / 8));
         pico_tree_delete(pfrag->t, f_frag);
         pico_frame_discard(f_frag);
         reassembly_dbg("REASSEMBLY: reassembled intermediate packet of %u data bytes, offset = %u next expected offset = %u\n", data_len, offset, running_offset);
@@ -1240,7 +1240,7 @@
   {
     route = index->keyValue;
     if (link == route->link)
-      pico_ipv4_route_del(route->dest, route->netmask, route->metric);
+      pico_ipv4_route_del(route->dest, route->netmask, (int)route->metric);
   }
   return 0;
 }
@@ -1368,7 +1368,7 @@
   }
 
   f->dev = rt->link->dev;
-  hdr->ttl-=1;
+  hdr->ttl= (uint8_t)(hdr->ttl - 1);
   if (hdr->ttl < 1) {
     pico_notify_ttl_expired(f);
     return -1;
--- a/modules/pico_nat.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_nat.c	Fri Sep 27 12:43:36 2013 +0000
@@ -268,7 +268,7 @@
   return 0;
 }
 
-static void pico_ipv4_nat_table_cleanup(uint64_t now, void *_unused)
+static void pico_ipv4_nat_table_cleanup(uint32_t now, void *_unused)
 {
   struct pico_tree_node *index = NULL, *_tmp = NULL;
   struct pico_nat_tuple *t = NULL;
--- a/modules/pico_tcp.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_tcp.c	Fri Sep 27 12:43:36 2013 +0000
@@ -353,7 +353,7 @@
 
 static void tcp_add_options(struct pico_socket_tcp *ts, struct pico_frame *f, uint16_t flags, uint16_t optsiz)
 {
-  uint64_t tsval = long_long_be(pico_tick);
+  uint32_t tsval = long_be(pico_tick);
   uint32_t tsecr = long_be(ts->ts_nxt);
   uint32_t i = 0;
   f->start = f->transport_hdr + PICO_SIZE_TCPHDR;
@@ -395,7 +395,7 @@
         ts->sacks = sb->next;
         memcpy(f->start + i, sb, 2 * sizeof(uint32_t));
         i += (2 * sizeof(uint32_t));
-        f->start[len_off] += (2 * sizeof(uint32_t));
+        f->start[len_off] = (uint8_t)(f->start[len_off] + (2 * sizeof(uint32_t)));
         pico_free(sb);
       }
     }
@@ -441,17 +441,17 @@
   } else {
 
    /* Always update window scale. */
-    size += PICO_TCPOPTLEN_WS;
+    size = (uint16_t)(size + PICO_TCPOPTLEN_WS);
 
     if (t->ts_ok)
-      size += PICO_TCPOPTLEN_TIMESTAMP;
+      size = (uint16_t)(size + PICO_TCPOPTLEN_TIMESTAMP);
 
-    size+= PICO_TCPOPTLEN_END;
+    size= (uint16_t)(size + PICO_TCPOPTLEN_END);
   }
   if ((flags & PICO_TCP_ACK) && (t->sack_ok && sb)) {
-    size += 2u;
+    size = (uint16_t)(size + 2);
     while(sb) {
-      size += (2 * sizeof(uint32_t));
+      size = (uint16_t)(size + (2 * sizeof(uint32_t)));
       sb = sb->next;
     }
   }
@@ -559,7 +559,7 @@
       case PICO_TCP_OPTION_WS:
         if (len != PICO_TCPOPTLEN_WS) {
           tcp_dbg_options("TCP Window scale: bad len received (%d).\n", len);
-          i += len - 2;
+          i = i + len - 2;
           break;
         }
         t->recv_wnd_scale = opt[i++];
@@ -568,7 +568,7 @@
       case PICO_TCP_OPTION_SACK_OK:
         if (len != PICO_TCPOPTLEN_SACK_OK) {
           tcp_dbg_options("TCP option sack: bad len received.\n");
-          i += len - 2;
+          i = i + len - 2;
           break;
         }
         t->sack_ok = 1;
@@ -577,7 +577,7 @@
         uint16_t mss;
         if (len != PICO_TCPOPTLEN_MSS) {
           tcp_dbg_options("TCP option mss: bad len received.\n");
-          i += len - 2;
+          i = i + len - 2;
           break;
         }
         t->mss_ok = 1;
@@ -591,7 +591,7 @@
         uint32_t tsval, tsecr;
         if (len != PICO_TCPOPTLEN_TIMESTAMP) {
           tcp_dbg_options("TCP option timestamp: bad len received.\n");
-          i += len - 2;
+          i = i + len - 2;
           break;
         }
         t->ts_ok = 1;
@@ -606,12 +606,12 @@
       case PICO_TCP_OPTION_SACK:
       {
         tcp_rcv_sack(t, opt + i, len - 2);
-        i += len - 2;
+        i = i + len - 2;
         break;
       }
       default:
         tcp_dbg_options("TCP: received unsupported option %u\n", type);
-        i += len - 2;
+        i = i + len - 2;
     }
   }
 }
@@ -666,7 +666,7 @@
 //#define PICO_TCP_SUPPORT_SOCKET_STATS
 
 #ifdef PICO_TCP_SUPPORT_SOCKET_STATS
-static void sock_stats(uint64_t when, void *arg)
+static void sock_stats(uint32_t when, void *arg)
 {
   struct pico_socket_tcp *t = (struct pico_socket_tcp *)arg;
   tcp_dbg("STATISTIC> [%lu] socket state: %02x --> local port:%d remote port: %d queue size: %d snd_una: %08x snd_nxt: %08x timer: %d cwnd: %d\n",
@@ -693,7 +693,7 @@
   /* disable Nagle by default */
   //t->sock.opt_flags |= (1 << PICO_SOCKET_OPT_TCPNODELAY);
   /* Nagle is enabled by default */
-  t->sock.opt_flags &= ~(1 << PICO_SOCKET_OPT_TCPNODELAY);
+  t->sock.opt_flags &= (uint16_t)~(1 << PICO_SOCKET_OPT_TCPNODELAY);
 
 #ifdef PICO_TCP_SUPPORT_SOCKET_STATS
   pico_timer_add(2000, sock_stats, t);
@@ -757,7 +757,7 @@
 }
 
 int pico_tcp_initconn(struct pico_socket *s);
-static void initconn_retry(uint64_t when, void *arg)
+static void initconn_retry(uint32_t when, void *arg)
 {
   struct pico_socket_tcp *t = (struct pico_socket_tcp *)arg;
   IGNORE_PARAMETER(when);
@@ -1189,12 +1189,12 @@
   return ret;
 }
 
-static uint32_t time_diff(uint64_t a, uint64_t b)
+static uint16_t time_diff(uint32_t a, uint32_t b)
 {
   if (a >= b)
-    return (uint32_t)(a - b);
+    return (uint16_t)(a - b);
   else
-    return (uint32_t)(b - a);
+    return (uint16_t)(b - a);
 }
 
 static void tcp_rtt(struct pico_socket_tcp *t, uint32_t rtt)
@@ -1260,12 +1260,12 @@
   tcp_dbg("TCP_CWND, %lu, %u, %u, %u\n", pico_tick, t->cwnd, t->ssthresh, t->in_flight);
 }
 
-static void add_retransmission_timer(struct pico_socket_tcp *t, uint64_t next_ts);
-static void tcp_retrans_timeout(uint64_t val, void *sock)
+static void add_retransmission_timer(struct pico_socket_tcp *t, uint32_t next_ts);
+static void tcp_retrans_timeout(uint32_t val, void *sock)
 {
   struct pico_socket_tcp *t = (struct pico_socket_tcp *) sock;
   struct pico_frame *f = NULL;
-  uint64_t limit = val - t->rto;
+  uint32_t limit = val - t->rto;
   if( t->sock.net && ((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_ESTABLISHED
   		|| (t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT) )
   {
@@ -1312,7 +1312,7 @@
 	}
 }
 
-static void add_retransmission_timer(struct pico_socket_tcp *t, uint64_t next_ts)
+static void add_retransmission_timer(struct pico_socket_tcp *t, uint32_t next_ts)
 {
   struct pico_tree_node * index;
 
@@ -1567,7 +1567,7 @@
   return 0;
 }
 
-static void tcp_deltcb(uint64_t when, void *arg)
+static void tcp_deltcb(uint32_t when, void *arg)
 {
   struct pico_socket_tcp *t = (struct pico_socket_tcp *)arg;
   IGNORE_PARAMETER(when);
@@ -1942,7 +1942,7 @@
   f->sock = s;
   s->timestamp = PICO_TIME_MS();
   /* Those are not supported at this time. */
-  flags &= ~(PICO_TCP_CWR | PICO_TCP_URG | PICO_TCP_ECN);
+  flags &= (uint8_t)~(PICO_TCP_CWR | PICO_TCP_URG | PICO_TCP_ECN);
   if (flags == PICO_TCP_SYN) {
     if (action->syn)
       action->syn(s,f);
@@ -1980,7 +1980,7 @@
   return ret;
 }
 
-static void tcp_send_keepalive(uint64_t when, void *_t)
+static void tcp_send_keepalive(uint32_t when, void *_t)
 {
   struct pico_socket_tcp *t = (struct pico_socket_tcp *)_t;
   IGNORE_PARAMETER(when);
@@ -2099,7 +2099,7 @@
 
   /* check till total_len <= MSS */
   while ((f_temp != NULL) && ((total_len+f_temp->payload_len) <= PICO_TCP_DEFAULT_MSS)) {
-    total_len += f_temp->payload_len;
+    total_len = (uint16_t)(total_len + f_temp->payload_len);
     f_temp = next_segment(&t->tcpq_hold, f_temp);
     if (f_temp == NULL)
       break;
@@ -2114,7 +2114,7 @@
   hdr = (struct pico_tcp_hdr *) f_new->transport_hdr;
   /* init new frame */
   f_new->payload += off;
-  f_new->payload_len -= off;
+  f_new->payload_len = (uint16_t)(f_new->payload_len - off);
   f_new->sock = s;
 
   f_temp = first_segment(&t->tcpq_hold);
@@ -2127,7 +2127,7 @@
     /* cpy data and discard frame */
     test++;
     memcpy(f_new->payload + total_payload_len, f_temp->payload, f_temp->payload_len);
-    total_payload_len += f_temp->payload_len;
+    total_payload_len = (uint16_t)(total_payload_len + f_temp->payload_len);
     pico_discard_segment(&t->tcpq_hold, f_temp);
     f_temp = first_segment(&t->tcpq_hold);
   }
--- a/modules/pico_udp.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_udp.c	Fri Sep 27 12:43:36 2013 +0000
@@ -163,7 +163,7 @@
     if (f->payload_len > len) {
       memcpy(buf, f->payload, len);
       f->payload += len;
-      f->payload_len -= len;
+      f->payload_len = (uint16_t)(f->payload_len - len);
       return len;
     } else {
       uint16_t ret = f->payload_len;
--- a/modules/pico_zmq.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/modules/pico_zmq.c	Fri Sep 27 12:43:36 2013 +0000
@@ -172,7 +172,7 @@
     //dbg("Received invalid signature: [0]!=0xFF\n");
     zmq_connector_del(zc);
   }
-  zc->bytes_received += ret;
+  zc->bytes_received = (uint8_t)(zc->bytes_received + ret);
   if (zc->bytes_received < 14) {
     //dbg("Waiting for the rest of the sig - got %u bytes\n",zc->bytes_received);
     return;
--- a/stack/pico_arp.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/stack/pico_arp.c	Fri Sep 27 12:43:36 2013 +0000
@@ -28,7 +28,7 @@
 static struct pico_queue pending;
 static int pending_timer_on = 0;
 
-void check_pending(uint64_t now, void *_unused)
+void check_pending(uint32_t now, void *_unused)
 {
   struct pico_frame *f = pico_dequeue(&pending);
   IGNORE_PARAMETER(now);
@@ -68,7 +68,7 @@
   struct pico_eth eth;
   struct pico_ip4 ipv4;
   int    arp_status;
-  uint64_t timestamp;
+  uint32_t timestamp;
   struct pico_device *dev;
 };
 
@@ -172,7 +172,7 @@
 }
 #endif
 
-void arp_expire(uint64_t now, void *_stale)
+void arp_expire(uint32_t now, void *_stale)
 {
   struct pico_arp *stale = (struct pico_arp *) _stale;
   IGNORE_PARAMETER(now);
@@ -268,7 +268,7 @@
     memcpy(eh->saddr, f->dev->eth->mac.addr, PICO_SIZE_ETH);
     f->start = f->datalink_hdr;
     f->len = PICO_SIZE_ETHHDR + PICO_SIZE_ARPHDR;
-    f->dev->send(f->dev, f->start, f->len);
+    f->dev->send(f->dev, f->start, (int)f->len);
   }
 
 #ifdef DEBUG_ARG
@@ -286,7 +286,7 @@
   struct pico_eth_hdr *eh;
   struct pico_arp_hdr *ah;
   struct pico_ip4 *src;
-  uint32_t ret;
+  int ret;
 
   src = pico_ipv4_source_find(dst);
   if (!src)
@@ -314,7 +314,7 @@
   ah->src.addr = src->addr;
   ah->dst.addr = dst->addr;
   arp_dbg("Sending arp query.\n");
-  ret = dev->send(dev, q->start, q->len);
+  ret = dev->send(dev, q->start,(int) q->len);
   pico_frame_discard(q);
-  return (int32_t)ret;
+  return ret;
 }
--- a/stack/pico_device.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/stack/pico_device.c	Fri Sep 27 12:43:36 2013 +0000
@@ -113,7 +113,7 @@
             continue;
           }
         } else {
-          dev->send(dev, f->start, f->len);
+          dev->send(dev, f->start, (int)f->len);
         }
         pico_frame_discard(f);
         loop_score--;
@@ -233,12 +233,12 @@
 			if(!copy)
 				return -1;
 			copy->dev = dev;
-			copy->dev->send(copy->dev, copy->start, copy->len);
+			copy->dev->send(copy->dev, copy->start, (int)copy->len);
 			pico_frame_discard(copy);
 		}
 		else
 		{
-			ret = (int32_t)f->dev->send(f->dev, f->start, f->len);
+			ret = (int32_t)f->dev->send(f->dev, f->start, (int)f->len);
 		}
 	}
 
--- a/stack/pico_frame.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/stack/pico_frame.c	Fri Sep 27 12:43:36 2013 +0000
@@ -155,7 +155,7 @@
       sum += b1[i];
     } else {
       tmp = b1[i];
-      sum += (tmp << 8);
+      sum = sum +(uint32_t)(tmp << 8);
     }
     j++;
   }
@@ -166,7 +166,7 @@
       sum += b2[i];
     } else {
       tmp = b2[i];
-      sum += (tmp << 8);
+      sum = sum +(uint32_t)(tmp << 8);
     }
     j++;
   }
--- a/stack/pico_socket.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/stack/pico_socket.c	Fri Sep 27 12:43:36 2013 +0000
@@ -608,7 +608,7 @@
     pico_tcp_cleanup_queues(sock);
 }
 
-static void socket_garbage_collect(uint64_t now, void *arg)
+static void socket_garbage_collect(uint32_t now, void *arg)
 {
   struct pico_socket *s = (struct pico_socket *) arg;
   IGNORE_PARAMETER(now);
@@ -696,7 +696,7 @@
   }
 
   s->state |= more_states;
-  s->state &= (~less_states);
+  s->state = (uint16_t)(s->state & (~less_states));
   if (tcp_state) {
     s->state &= 0x00FF;
     s->state |= tcp_state;
@@ -1147,7 +1147,7 @@
       return -1;
     }
     f->payload += header_offset;
-    f->payload_len -= header_offset;
+    f->payload_len = (uint16_t)(f->payload_len - header_offset);
     f->sock = s;
     if (remote_duple) {
       f->info = pico_zalloc(sizeof(struct pico_remote_duple));
@@ -1166,7 +1166,7 @@
       } else {
         /* no transport header in fragmented IP */
         f->payload = f->transport_hdr;
-        f->payload_len += header_offset;
+        f->payload_len = (uint16_t)(f->payload_len + header_offset);
         /* set offset in octets */
         f->frag = short_be((uint16_t)((total_payload_written + header_offset) / 8));
         if (total_payload_written + f->payload_len < len) {
@@ -1479,7 +1479,7 @@
 #endif
 
 #define PICO_SOCKET_SETOPT_EN(socket,index)  (socket->opt_flags |=  (1 << index))
-#define PICO_SOCKET_SETOPT_DIS(socket,index) (socket->opt_flags &= ~(1 << index))
+#define PICO_SOCKET_SETOPT_DIS(socket,index) (socket->opt_flags &= (uint16_t)~(1 << index))
 
 int pico_socket_setoption(struct pico_socket *s, int option, void *value) // XXX no check against proto (vs setsockopt) or implicit by socket?
 {
--- a/stack/pico_stack.c	Fri Sep 27 06:27:23 2013 +0000
+++ b/stack/pico_stack.c	Fri Sep 27 12:43:36 2013 +0000
@@ -34,7 +34,7 @@
   const uint8_t PICO_ETHADDR_MCAST[6] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0x00};
 #endif
 
-volatile uint64_t pico_tick;
+volatile unsigned long pico_tick;
 volatile pico_err_t pico_err;
 
 static uint32_t _rand_seed;
@@ -371,7 +371,7 @@
       }else if(IS_LIMITED_BCAST(f)){
         ret = pico_device_broadcast(f);
       }else {
-        ret = (int32_t)f->dev->send(f->dev, f->start, f->len);
+        ret = (int32_t)f->dev->send(f->dev, f->start,(int) f->len);
         /* Frame is discarded after this return by the caller */
       }
 
@@ -464,14 +464,14 @@
 
 struct pico_timer
 {
-  uint64_t expire;
+  uint32_t expire;
   void *arg;
-  void (*timer)(uint64_t timestamp, void *arg);
+  void (*timer)(uint32_t timestamp, void *arg);
 };
 
 struct pico_timer_ref
 {
-  uint64_t expire;
+  uint32_t expire;
   struct pico_timer *tmr;
 };
 
@@ -706,7 +706,7 @@
   }
 }
 
-struct pico_timer *pico_timer_add(uint64_t expire, void (*timer)(uint64_t, void *), void *arg)
+struct pico_timer *pico_timer_add(uint32_t expire, void (*timer)(uint32_t, void *), void *arg)
 {
   struct pico_timer *t = pico_zalloc(sizeof(struct pico_timer));
   struct pico_timer_ref tref;