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
--- a/modules/pico_dhcp_common.c	Mon Sep 16 12:07:35 2013 +0000
+++ b/modules/pico_dhcp_common.c	Thu Sep 19 12:38:53 2013 +0000
@@ -12,174 +12,56 @@
 #include "pico_dhcp_common.h"
 
 #if defined (PICO_SUPPORT_DHCPC) || defined (PICO_SUPPORT_DHCPD)
-/* pico_dhcp_are_options_valid needs to be called first to prevent illegal memory access */
-/* The argument pointer is moved forward to the next option */
-struct pico_dhcp_opt *pico_dhcp_next_option(struct pico_dhcp_opt **ptr)
+//this function should only be used after you checked if the options are valid! otherwise it could read from bad memory!
+uint8_t dhcp_get_next_option(uint8_t *begin, uint8_t *data, int *len, uint8_t **nextopt)
 {
-  uint8_t **p = (uint8_t **)ptr;
-  struct pico_dhcp_opt *opt = *ptr;
+	uint8_t *p;
+	uint8_t type;
+	uint8_t opt_len;
+
+	if (!begin)
+		p = *nextopt;
+	else
+		p = begin;
 
-	if (opt->code == PICO_DHCP_OPT_END)
-    return NULL;
-  if (opt->code == PICO_DHCP_OPT_PAD) {
-    *p += 1; 
-		return *ptr;
-  }
-
-  *p += (opt->len + 2); /* (len + 2) to account for code and len octet */
-  return *ptr;
+	type = *p;
+	*nextopt = ++p;
+	if ((type == PICO_DHCPOPT_END) || (type == PICO_DHCPOPT_PAD)) {
+		memset(data, 0, *len);
+		len = 0;
+		return type;
+	}
+	opt_len = *p;
+	p++;
+	if (*len > opt_len)
+		*len = opt_len;
+	memcpy(data, p, *len);
+	*nextopt = p + opt_len;
+	return type;
 }
 
-int pico_dhcp_are_options_valid(void *ptr, int len)
+int is_options_valid(uint8_t *opt_buffer, int len)
 {
-	uint8_t optlen = 0, *p = ptr;
-
+	uint8_t *p = opt_buffer;
 	while (len > 0) {
-    switch (*p)
-    {
-      case PICO_DHCP_OPT_END:
-        return 1;
-
-      case PICO_DHCP_OPT_PAD:
-        p++;
-        len--;
-        break;
-
-      default:
-        p++; /* move pointer from code octet to len octet */
-        if ((--len <= 0) || (len - (*p + 1) < 0)) /* (*p + 1) to account for len octet */
-          return 0;
-        optlen = *p;
-        p += optlen + 1;
-        len -= optlen;
-        break;
-    }
+		if (*p == PICO_DHCPOPT_END)
+			return 1;
+		else if (*p == PICO_DHCPOPT_PAD) {
+			p++;
+			len--;
+		} else {
+			uint8_t opt_len;
+			p++;
+			len--;
+			if(len > 0) {
+				opt_len = *p;
+				p += opt_len + 1;
+				len -= opt_len;
+			}else
+				return 0;
+		}
 	}
 	return 0;
 }
 
-int pico_dhcp_opt_netmask(void *ptr, struct pico_ip4 *ip)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: netmask */
-  opt->code = PICO_DHCP_OPT_NETMASK;
-  opt->len = PICO_DHCP_OPTLEN_NETMASK - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.netmask.ip = *ip;
-  return PICO_DHCP_OPTLEN_NETMASK;
-}
-
-int pico_dhcp_opt_router(void *ptr, struct pico_ip4 *ip)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: router */
-  opt->code = PICO_DHCP_OPT_ROUTER;
-  opt->len = PICO_DHCP_OPTLEN_ROUTER - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.router.ip = *ip;
-  return PICO_DHCP_OPTLEN_ROUTER;
-}
-
-int pico_dhcp_opt_dns(void *ptr, struct pico_ip4 *ip)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: dns */
-  opt->code = PICO_DHCP_OPT_DNS;
-  opt->len = PICO_DHCP_OPTLEN_DNS - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.dns.ip = *ip;
-  return PICO_DHCP_OPTLEN_DNS;
-}
-
-int pico_dhcp_opt_broadcast(void *ptr, struct pico_ip4 *ip)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: broadcast */
-  opt->code = PICO_DHCP_OPT_BROADCAST;
-  opt->len = PICO_DHCP_OPTLEN_BROADCAST - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.broadcast.ip = *ip;
-  return PICO_DHCP_OPTLEN_BROADCAST;
-}
-
-int pico_dhcp_opt_reqip(void *ptr, struct pico_ip4 *ip)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: request IP address */
-  opt->code = PICO_DHCP_OPT_REQIP;
-  opt->len = PICO_DHCP_OPTLEN_REQIP - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.req_ip.ip = *ip;
-  return PICO_DHCP_OPTLEN_REQIP;
-}
-
-int pico_dhcp_opt_leasetime(void *ptr, uint32_t time)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: lease time */
-  opt->code = PICO_DHCP_OPT_LEASETIME;
-  opt->len = PICO_DHCP_OPTLEN_LEASETIME - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.lease_time.time = time;
-  return PICO_DHCP_OPTLEN_LEASETIME;
-}
-
-int pico_dhcp_opt_msgtype(void *ptr, uint8_t type)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: message type */
-  opt->code = PICO_DHCP_OPT_MSGTYPE;
-  opt->len = PICO_DHCP_OPTLEN_MSGTYPE - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.msg_type.type = type;
-  return PICO_DHCP_OPTLEN_MSGTYPE;
-}
-
-int pico_dhcp_opt_serverid(void *ptr, struct pico_ip4 *ip)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: server identifier */
-  opt->code = PICO_DHCP_OPT_SERVERID;
-  opt->len = PICO_DHCP_OPTLEN_SERVERID - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.server_id.ip = *ip;
-  return PICO_DHCP_OPTLEN_SERVERID;
-}
-
-int pico_dhcp_opt_paramlist(void *ptr)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: parameter list */
-  opt->code = PICO_DHCP_OPT_PARAMLIST;
-  opt->len = PICO_DHCP_OPTLEN_PARAMLIST - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.param_list.code[0] = PICO_DHCP_OPT_NETMASK;
-  opt->ext.param_list.code[1] = PICO_DHCP_OPT_TIME;
-  opt->ext.param_list.code[2] = PICO_DHCP_OPT_ROUTER;
-  opt->ext.param_list.code[3] = PICO_DHCP_OPT_HOSTNAME;
-  opt->ext.param_list.code[4] = PICO_DHCP_OPT_RENEWALTIME;
-  opt->ext.param_list.code[5] = PICO_DHCP_OPT_REBINDINGTIME;
-  return PICO_DHCP_OPTLEN_PARAMLIST;
-}
-
-int pico_dhcp_opt_maxmsgsize(void *ptr, uint16_t size)
-{
-  struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
-
-  /* option: maximum message size */
-  opt->code = PICO_DHCP_OPT_MAXMSGSIZE;
-  opt->len = PICO_DHCP_OPTLEN_MAXMSGSIZE - PICO_DHCP_OPTLEN_HDR;
-  opt->ext.max_msg_size.size = short_be(size);
-  return PICO_DHCP_OPTLEN_MAXMSGSIZE;
-}
-
-int pico_dhcp_opt_end(void *ptr)
-{
-  uint8_t *opt = (uint8_t *)ptr;
-
-  /* option: end of options */
-  *opt = PICO_DHCP_OPT_END;
-  return PICO_DHCP_OPTLEN_END;
-}
-
 #endif