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:
51:ab4529a384a6
Parent:
3:b4047e8a0123
Child:
63:97f481e33cb2
diff -r 8c79c30b48e3 -r ab4529a384a6 modules/pico_dhcp_common.h
--- a/modules/pico_dhcp_common.h	Tue Aug 06 08:04:03 2013 +0000
+++ b/modules/pico_dhcp_common.h	Mon Sep 02 08:02:21 2013 +0000
@@ -7,96 +7,177 @@
 *********************************************************************/
 #ifndef _INCLUDE_PICO_DHCP_COMMON
 #define _INCLUDE_PICO_DHCP_COMMON
-
-
-#include <stdint.h>
-
-//minimum size is 576, cfr RFC
-#define DHCPC_DATAGRAM_SIZE 576
-#define DHCPD_DATAGRAM_SIZE 576
-
+#include "pico_addressing.h"
 
 #define PICO_DHCPD_PORT (short_be(67))
 #define PICO_DHCP_CLIENT_PORT (short_be(68))
-
-#define PICO_DHCP_OP_REQUEST 1
-#define PICO_DHCP_OP_REPLY   2
+#define PICO_DHCPD_MAGIC_COOKIE (long_be(0x63825363))
+#define PICO_DHCP_HTYPE_ETH 1
 
-#define PICO_HTYPE_ETHER 1
-#define PICO_HLEN_ETHER  6
-
-#define PICO_DHCPD_MAGIC_COOKIE (long_be(0x63825363))
+/* flags */
+#define PICO_DHCP_FLAG_BROADCAST        0x8000
 
-/* DHCP OPTIONS, RFC2132 */
-#define PICO_DHCPOPT_PAD                     0x00
-#define PICO_DHCPOPT_NETMASK                 0x01
-#define PICO_DHCPOPT_TIME                    0x02
-#define PICO_DHCPOPT_ROUTER                  0x03
-#define PICO_DHCPOPT_DNS                     0x06
-#define PICO_DHCPOPT_HOSTNAME                0x0c
-#define PICO_DHCPOPT_DOMAINNAME              0x0f
-#define PICO_DHCPOPT_MTU                     0x1a
-#define PICO_DHCPOPT_BCAST                   0x1c
-#define PICO_DHCPOPT_NETBIOSNS               0x2c
-#define PICO_DHCPOPT_NETBIOSSCOPE            0x2f
+/* options */
+#define PICO_DHCP_OPT_PAD               0x00
+#define PICO_DHCP_OPT_NETMASK           0x01
+#define PICO_DHCP_OPT_TIME              0x02
+#define PICO_DHCP_OPT_ROUTER            0x03
+#define PICO_DHCP_OPT_DNS               0x06
+#define PICO_DHCP_OPT_HOSTNAME          0x0c
+#define PICO_DHCP_OPT_DOMAINNAME        0x0f
+#define PICO_DHCP_OPT_MTU               0x1a
+#define PICO_DHCP_OPT_BROADCAST         0x1c
+#define PICO_DHCP_OPT_NETBIOSNS         0x2c
+#define PICO_DHCP_OPT_NETBIOSSCOPE      0x2f
+#define PICO_DHCP_OPT_REQIP             0x32
+#define PICO_DHCP_OPT_LEASETIME         0x33
+#define PICO_DHCP_OPT_OPTOVERLOAD       0x34
+#define PICO_DHCP_OPT_MSGTYPE           0x35
+#define PICO_DHCP_OPT_SERVERID          0x36
+#define PICO_DHCP_OPT_PARAMLIST         0x37
+#define PICO_DHCP_OPT_MESSAGE           0x38
+#define PICO_DHCP_OPT_MAXMSGSIZE        0x39
+#define PICO_DHCP_OPT_RENEWALTIME       0x3a
+#define PICO_DHCP_OPT_REBINDINGTIME     0x3b
+#define PICO_DHCP_OPT_VENDORID          0x3c
+#define PICO_DHCP_OPT_CLIENTID          0x3d
+#define PICO_DHCP_OPT_DOMAINSEARCH      0x77
+#define PICO_DHCP_OPT_STATICROUTE       0x79
+#define PICO_DHCP_OPT_END               0xFF
 
-#define PICO_DHCPOPT_REQIP                   0x32
-#define PICO_DHCPOPT_LEASETIME               0x33
-#define PICO_DHCPOPT_OPTIONOVERLOAD          0x34
-#define PICO_DHCPOPT_MSGTYPE                 0x35
-#define PICO_DHCPOPT_SERVERID                0x36
-#define PICO_DHCPOPT_PARMLIST                0x37
-#define PICO_DHCPOPT_MAXMSGSIZE              0x39
-#define PICO_DHCPOPT_RENEWALTIME             0x3a
-#define PICO_DHCPOPT_REBINDINGTIME           0x3b
-#define PICO_DHCPOPT_DOMAINSEARCH            0x77
-#define PICO_DHCPOPT_STATICROUTE             0x79
-#define PICO_DHCPOPT_END                     0xFF
+/* options len */
+#define PICO_DHCP_OPTLEN_HDR            2 /* account for code and len field */
+#define PICO_DHCP_OPTLEN_NETMASK        6
+#define PICO_DHCP_OPTLEN_ROUTER         6
+#define PICO_DHCP_OPTLEN_DNS            6
+#define PICO_DHCP_OPTLEN_BROADCAST      6
+#define PICO_DHCP_OPTLEN_REQIP          6
+#define PICO_DHCP_OPTLEN_LEASETIME      6
+#define PICO_DHCP_OPTLEN_OPTOVERLOAD    3
+#define PICO_DHCP_OPTLEN_MSGTYPE        3
+#define PICO_DHCP_OPTLEN_SERVERID       6
+#define PICO_DHCP_OPTLEN_PARAMLIST      8 /* PicoTCP specific */
+#define PICO_DHCP_OPTLEN_MAXMSGSIZE     4
+#define PICO_DHCP_OPTLEN_RENEWALTIME    6
+#define PICO_DHCP_OPTLEN_REBINDINGTIME  6
+#define PICO_DHCP_OPTLEN_END            1
+
+/* op codes */
+#define PICO_DHCP_OP_REQUEST            1
+#define PICO_DHCP_OP_REPLY              2
 
-/* DHCP MESSAGE TYPE */
-#define PICO_DHCP_MSG_DISCOVER               1
-#define PICO_DHCP_MSG_OFFER                  2
-#define PICO_DHCP_MSG_REQUEST                3
-#define PICO_DHCP_MSG_DECLINE                4
-#define PICO_DHCP_MSG_ACK                    5
-#define PICO_DHCP_MSG_NAK                    6
-#define PICO_DHCP_MSG_RELEASE                7
-#define PICO_DHCP_MSG_INFORM                 8
+/* rfc message types */
+#define PICO_DHCP_MSG_DISCOVER          1
+#define PICO_DHCP_MSG_OFFER             2
+#define PICO_DHCP_MSG_REQUEST           3
+#define PICO_DHCP_MSG_DECLINE           4
+#define PICO_DHCP_MSG_ACK               5
+#define PICO_DHCP_MSG_NAK               6
+#define PICO_DHCP_MSG_RELEASE           7
+#define PICO_DHCP_MSG_INFORM            8
+
+/* custom message types */
+#define PICO_DHCP_EVENT_T1              9
+#define PICO_DHCP_EVENT_T2              10
+#define PICO_DHCP_EVENT_LEASE           11
+#define PICO_DHCP_EVENT_RETRANSMIT      12
 
-
-enum dhcp_negotiation_state {
-        DHCPSTATE_DISCOVER = 0,
-        DHCPSTATE_OFFER,
-        DHCPSTATE_REQUEST,
-        DHCPSTATE_BOUND,
-        DHCPSTATE_RENEWING
+struct __attribute__((packed)) pico_dhcp_hdr
+{
+	uint8_t op;
+	uint8_t htype;
+	uint8_t hlen;
+	uint8_t hops; //zero
+	uint32_t xid; //store this in the request
+	uint16_t secs; // ignore
+	uint16_t flags;
+	uint32_t ciaddr; // client address - if asking for renewal
+	uint32_t yiaddr; // your address (client)
+	uint32_t siaddr; // dhcp offered address
+	uint32_t giaddr; // relay agent, bootp.
+	uint8_t hwaddr[6];
+	uint8_t hwaddr_padding[10];
+	char    hostname[64];
+	char    bootp_filename[128];
+	uint32_t dhcp_magic;
+	uint8_t options[0];
 };
 
-
-struct __attribute__((packed)) pico_dhcphdr
+struct __attribute__((packed)) pico_dhcp_opt
 {
-    uint8_t op;
-    uint8_t htype;
-    uint8_t hlen;
-    uint8_t hops; //zero
-    uint32_t xid; //store this in the request
-    uint16_t secs; // ignore
-    uint16_t flags;
-    uint32_t ciaddr; // client address - if asking for renewal
-    uint32_t yiaddr; // your address (client)
-    uint32_t siaddr; // dhcp offered address
-    uint32_t giaddr; // relay agent, bootp.
-    uint8_t hwaddr[6];
-    uint8_t hwaddr_padding[10];
-    char    hostname[64];
-    char    bootp_filename[128];
-    uint32_t dhcp_magic;
-    uint8_t options[0];
+  uint8_t code;
+  uint8_t len;
+  union {
+    struct {
+      struct pico_ip4 ip;
+    } netmask;
+    struct {
+      struct pico_ip4 ip;
+    } router;
+    struct {
+      struct pico_ip4 ip;
+    } dns;
+    struct {
+      struct pico_ip4 ip;
+    } broadcast;
+    struct {
+      struct pico_ip4 ip;
+    } req_ip;
+    struct {
+      uint32_t time;
+    } lease_time;
+    struct {
+      uint8_t value;
+    } opt_overload;
+    struct {
+      char name[0];
+    } tftp_server;
+    struct {
+      char name[0];
+    } bootfile;
+    struct {
+      uint8_t type;
+    } msg_type;
+    struct {
+      struct pico_ip4 ip;
+    } server_id;
+    struct {
+      uint8_t code[0];
+    } param_list;
+    struct {
+      char error[0];
+    } message;
+    struct {
+      uint16_t size;
+    } max_msg_size;
+    struct {
+      uint32_t time;
+    } renewal_time;
+    struct {
+      uint32_t time;
+    } rebinding_time;
+    struct {
+      uint8_t id[0];
+    } vendor_id;
+    struct {
+      uint8_t id[0];
+    } client_id;
+  } ext;
 };
 
-
-//common functions for client and server
+uint8_t dhcp_get_next_option(uint8_t *begin, uint8_t *data, int *len, uint8_t **nextopt);
+struct pico_dhcp_opt *pico_dhcp_next_option(struct pico_dhcp_opt **ptr);
+int pico_dhcp_are_options_valid(void *ptr, int len); 
 
-uint8_t dhcp_get_next_option(uint8_t *begin, uint8_t *data, int *len, uint8_t **nextopt);
-int is_options_valid(uint8_t *opt_buffer, int len); 
+int pico_dhcp_opt_netmask(void *ptr, struct pico_ip4 *ip);
+int pico_dhcp_opt_router(void *ptr, struct pico_ip4 *ip);
+int pico_dhcp_opt_dns(void *ptr, struct pico_ip4 *ip);
+int pico_dhcp_opt_broadcast(void *ptr, struct pico_ip4 *ip);
+int pico_dhcp_opt_reqip(void *ptr, struct pico_ip4 *ip);
+int pico_dhcp_opt_leasetime(void *ptr, uint32_t time);
+int pico_dhcp_opt_msgtype(void *ptr, uint8_t type);
+int pico_dhcp_opt_serverid(void *ptr, struct pico_ip4 *ip);
+int pico_dhcp_opt_paramlist(void *ptr);
+int pico_dhcp_opt_maxmsgsize(void *ptr, uint16_t size);
+int pico_dhcp_opt_end(void *ptr);
 #endif