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.

Committer:
tass
Date:
Mon Sep 02 08:02:21 2013 +0000
Revision:
51:ab4529a384a6
Parent:
3:b4047e8a0123
Child:
63:97f481e33cb2
Updated from masterbranch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniele 3:b4047e8a0123 1 /*********************************************************************
daniele 3:b4047e8a0123 2 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
daniele 3:b4047e8a0123 3 See LICENSE and COPYING for usage.
daniele 3:b4047e8a0123 4
daniele 3:b4047e8a0123 5 .
daniele 3:b4047e8a0123 6
daniele 3:b4047e8a0123 7 *********************************************************************/
daniele 3:b4047e8a0123 8 #ifndef _INCLUDE_PICO_DHCP_COMMON
daniele 3:b4047e8a0123 9 #define _INCLUDE_PICO_DHCP_COMMON
tass 51:ab4529a384a6 10 #include "pico_addressing.h"
daniele 3:b4047e8a0123 11
daniele 3:b4047e8a0123 12 #define PICO_DHCPD_PORT (short_be(67))
daniele 3:b4047e8a0123 13 #define PICO_DHCP_CLIENT_PORT (short_be(68))
tass 51:ab4529a384a6 14 #define PICO_DHCPD_MAGIC_COOKIE (long_be(0x63825363))
tass 51:ab4529a384a6 15 #define PICO_DHCP_HTYPE_ETH 1
daniele 3:b4047e8a0123 16
tass 51:ab4529a384a6 17 /* flags */
tass 51:ab4529a384a6 18 #define PICO_DHCP_FLAG_BROADCAST 0x8000
daniele 3:b4047e8a0123 19
tass 51:ab4529a384a6 20 /* options */
tass 51:ab4529a384a6 21 #define PICO_DHCP_OPT_PAD 0x00
tass 51:ab4529a384a6 22 #define PICO_DHCP_OPT_NETMASK 0x01
tass 51:ab4529a384a6 23 #define PICO_DHCP_OPT_TIME 0x02
tass 51:ab4529a384a6 24 #define PICO_DHCP_OPT_ROUTER 0x03
tass 51:ab4529a384a6 25 #define PICO_DHCP_OPT_DNS 0x06
tass 51:ab4529a384a6 26 #define PICO_DHCP_OPT_HOSTNAME 0x0c
tass 51:ab4529a384a6 27 #define PICO_DHCP_OPT_DOMAINNAME 0x0f
tass 51:ab4529a384a6 28 #define PICO_DHCP_OPT_MTU 0x1a
tass 51:ab4529a384a6 29 #define PICO_DHCP_OPT_BROADCAST 0x1c
tass 51:ab4529a384a6 30 #define PICO_DHCP_OPT_NETBIOSNS 0x2c
tass 51:ab4529a384a6 31 #define PICO_DHCP_OPT_NETBIOSSCOPE 0x2f
tass 51:ab4529a384a6 32 #define PICO_DHCP_OPT_REQIP 0x32
tass 51:ab4529a384a6 33 #define PICO_DHCP_OPT_LEASETIME 0x33
tass 51:ab4529a384a6 34 #define PICO_DHCP_OPT_OPTOVERLOAD 0x34
tass 51:ab4529a384a6 35 #define PICO_DHCP_OPT_MSGTYPE 0x35
tass 51:ab4529a384a6 36 #define PICO_DHCP_OPT_SERVERID 0x36
tass 51:ab4529a384a6 37 #define PICO_DHCP_OPT_PARAMLIST 0x37
tass 51:ab4529a384a6 38 #define PICO_DHCP_OPT_MESSAGE 0x38
tass 51:ab4529a384a6 39 #define PICO_DHCP_OPT_MAXMSGSIZE 0x39
tass 51:ab4529a384a6 40 #define PICO_DHCP_OPT_RENEWALTIME 0x3a
tass 51:ab4529a384a6 41 #define PICO_DHCP_OPT_REBINDINGTIME 0x3b
tass 51:ab4529a384a6 42 #define PICO_DHCP_OPT_VENDORID 0x3c
tass 51:ab4529a384a6 43 #define PICO_DHCP_OPT_CLIENTID 0x3d
tass 51:ab4529a384a6 44 #define PICO_DHCP_OPT_DOMAINSEARCH 0x77
tass 51:ab4529a384a6 45 #define PICO_DHCP_OPT_STATICROUTE 0x79
tass 51:ab4529a384a6 46 #define PICO_DHCP_OPT_END 0xFF
daniele 3:b4047e8a0123 47
tass 51:ab4529a384a6 48 /* options len */
tass 51:ab4529a384a6 49 #define PICO_DHCP_OPTLEN_HDR 2 /* account for code and len field */
tass 51:ab4529a384a6 50 #define PICO_DHCP_OPTLEN_NETMASK 6
tass 51:ab4529a384a6 51 #define PICO_DHCP_OPTLEN_ROUTER 6
tass 51:ab4529a384a6 52 #define PICO_DHCP_OPTLEN_DNS 6
tass 51:ab4529a384a6 53 #define PICO_DHCP_OPTLEN_BROADCAST 6
tass 51:ab4529a384a6 54 #define PICO_DHCP_OPTLEN_REQIP 6
tass 51:ab4529a384a6 55 #define PICO_DHCP_OPTLEN_LEASETIME 6
tass 51:ab4529a384a6 56 #define PICO_DHCP_OPTLEN_OPTOVERLOAD 3
tass 51:ab4529a384a6 57 #define PICO_DHCP_OPTLEN_MSGTYPE 3
tass 51:ab4529a384a6 58 #define PICO_DHCP_OPTLEN_SERVERID 6
tass 51:ab4529a384a6 59 #define PICO_DHCP_OPTLEN_PARAMLIST 8 /* PicoTCP specific */
tass 51:ab4529a384a6 60 #define PICO_DHCP_OPTLEN_MAXMSGSIZE 4
tass 51:ab4529a384a6 61 #define PICO_DHCP_OPTLEN_RENEWALTIME 6
tass 51:ab4529a384a6 62 #define PICO_DHCP_OPTLEN_REBINDINGTIME 6
tass 51:ab4529a384a6 63 #define PICO_DHCP_OPTLEN_END 1
tass 51:ab4529a384a6 64
tass 51:ab4529a384a6 65 /* op codes */
tass 51:ab4529a384a6 66 #define PICO_DHCP_OP_REQUEST 1
tass 51:ab4529a384a6 67 #define PICO_DHCP_OP_REPLY 2
daniele 3:b4047e8a0123 68
tass 51:ab4529a384a6 69 /* rfc message types */
tass 51:ab4529a384a6 70 #define PICO_DHCP_MSG_DISCOVER 1
tass 51:ab4529a384a6 71 #define PICO_DHCP_MSG_OFFER 2
tass 51:ab4529a384a6 72 #define PICO_DHCP_MSG_REQUEST 3
tass 51:ab4529a384a6 73 #define PICO_DHCP_MSG_DECLINE 4
tass 51:ab4529a384a6 74 #define PICO_DHCP_MSG_ACK 5
tass 51:ab4529a384a6 75 #define PICO_DHCP_MSG_NAK 6
tass 51:ab4529a384a6 76 #define PICO_DHCP_MSG_RELEASE 7
tass 51:ab4529a384a6 77 #define PICO_DHCP_MSG_INFORM 8
tass 51:ab4529a384a6 78
tass 51:ab4529a384a6 79 /* custom message types */
tass 51:ab4529a384a6 80 #define PICO_DHCP_EVENT_T1 9
tass 51:ab4529a384a6 81 #define PICO_DHCP_EVENT_T2 10
tass 51:ab4529a384a6 82 #define PICO_DHCP_EVENT_LEASE 11
tass 51:ab4529a384a6 83 #define PICO_DHCP_EVENT_RETRANSMIT 12
daniele 3:b4047e8a0123 84
tass 51:ab4529a384a6 85 struct __attribute__((packed)) pico_dhcp_hdr
tass 51:ab4529a384a6 86 {
tass 51:ab4529a384a6 87 uint8_t op;
tass 51:ab4529a384a6 88 uint8_t htype;
tass 51:ab4529a384a6 89 uint8_t hlen;
tass 51:ab4529a384a6 90 uint8_t hops; //zero
tass 51:ab4529a384a6 91 uint32_t xid; //store this in the request
tass 51:ab4529a384a6 92 uint16_t secs; // ignore
tass 51:ab4529a384a6 93 uint16_t flags;
tass 51:ab4529a384a6 94 uint32_t ciaddr; // client address - if asking for renewal
tass 51:ab4529a384a6 95 uint32_t yiaddr; // your address (client)
tass 51:ab4529a384a6 96 uint32_t siaddr; // dhcp offered address
tass 51:ab4529a384a6 97 uint32_t giaddr; // relay agent, bootp.
tass 51:ab4529a384a6 98 uint8_t hwaddr[6];
tass 51:ab4529a384a6 99 uint8_t hwaddr_padding[10];
tass 51:ab4529a384a6 100 char hostname[64];
tass 51:ab4529a384a6 101 char bootp_filename[128];
tass 51:ab4529a384a6 102 uint32_t dhcp_magic;
tass 51:ab4529a384a6 103 uint8_t options[0];
daniele 3:b4047e8a0123 104 };
daniele 3:b4047e8a0123 105
tass 51:ab4529a384a6 106 struct __attribute__((packed)) pico_dhcp_opt
daniele 3:b4047e8a0123 107 {
tass 51:ab4529a384a6 108 uint8_t code;
tass 51:ab4529a384a6 109 uint8_t len;
tass 51:ab4529a384a6 110 union {
tass 51:ab4529a384a6 111 struct {
tass 51:ab4529a384a6 112 struct pico_ip4 ip;
tass 51:ab4529a384a6 113 } netmask;
tass 51:ab4529a384a6 114 struct {
tass 51:ab4529a384a6 115 struct pico_ip4 ip;
tass 51:ab4529a384a6 116 } router;
tass 51:ab4529a384a6 117 struct {
tass 51:ab4529a384a6 118 struct pico_ip4 ip;
tass 51:ab4529a384a6 119 } dns;
tass 51:ab4529a384a6 120 struct {
tass 51:ab4529a384a6 121 struct pico_ip4 ip;
tass 51:ab4529a384a6 122 } broadcast;
tass 51:ab4529a384a6 123 struct {
tass 51:ab4529a384a6 124 struct pico_ip4 ip;
tass 51:ab4529a384a6 125 } req_ip;
tass 51:ab4529a384a6 126 struct {
tass 51:ab4529a384a6 127 uint32_t time;
tass 51:ab4529a384a6 128 } lease_time;
tass 51:ab4529a384a6 129 struct {
tass 51:ab4529a384a6 130 uint8_t value;
tass 51:ab4529a384a6 131 } opt_overload;
tass 51:ab4529a384a6 132 struct {
tass 51:ab4529a384a6 133 char name[0];
tass 51:ab4529a384a6 134 } tftp_server;
tass 51:ab4529a384a6 135 struct {
tass 51:ab4529a384a6 136 char name[0];
tass 51:ab4529a384a6 137 } bootfile;
tass 51:ab4529a384a6 138 struct {
tass 51:ab4529a384a6 139 uint8_t type;
tass 51:ab4529a384a6 140 } msg_type;
tass 51:ab4529a384a6 141 struct {
tass 51:ab4529a384a6 142 struct pico_ip4 ip;
tass 51:ab4529a384a6 143 } server_id;
tass 51:ab4529a384a6 144 struct {
tass 51:ab4529a384a6 145 uint8_t code[0];
tass 51:ab4529a384a6 146 } param_list;
tass 51:ab4529a384a6 147 struct {
tass 51:ab4529a384a6 148 char error[0];
tass 51:ab4529a384a6 149 } message;
tass 51:ab4529a384a6 150 struct {
tass 51:ab4529a384a6 151 uint16_t size;
tass 51:ab4529a384a6 152 } max_msg_size;
tass 51:ab4529a384a6 153 struct {
tass 51:ab4529a384a6 154 uint32_t time;
tass 51:ab4529a384a6 155 } renewal_time;
tass 51:ab4529a384a6 156 struct {
tass 51:ab4529a384a6 157 uint32_t time;
tass 51:ab4529a384a6 158 } rebinding_time;
tass 51:ab4529a384a6 159 struct {
tass 51:ab4529a384a6 160 uint8_t id[0];
tass 51:ab4529a384a6 161 } vendor_id;
tass 51:ab4529a384a6 162 struct {
tass 51:ab4529a384a6 163 uint8_t id[0];
tass 51:ab4529a384a6 164 } client_id;
tass 51:ab4529a384a6 165 } ext;
daniele 3:b4047e8a0123 166 };
daniele 3:b4047e8a0123 167
tass 51:ab4529a384a6 168 uint8_t dhcp_get_next_option(uint8_t *begin, uint8_t *data, int *len, uint8_t **nextopt);
tass 51:ab4529a384a6 169 struct pico_dhcp_opt *pico_dhcp_next_option(struct pico_dhcp_opt **ptr);
tass 51:ab4529a384a6 170 int pico_dhcp_are_options_valid(void *ptr, int len);
daniele 3:b4047e8a0123 171
tass 51:ab4529a384a6 172 int pico_dhcp_opt_netmask(void *ptr, struct pico_ip4 *ip);
tass 51:ab4529a384a6 173 int pico_dhcp_opt_router(void *ptr, struct pico_ip4 *ip);
tass 51:ab4529a384a6 174 int pico_dhcp_opt_dns(void *ptr, struct pico_ip4 *ip);
tass 51:ab4529a384a6 175 int pico_dhcp_opt_broadcast(void *ptr, struct pico_ip4 *ip);
tass 51:ab4529a384a6 176 int pico_dhcp_opt_reqip(void *ptr, struct pico_ip4 *ip);
tass 51:ab4529a384a6 177 int pico_dhcp_opt_leasetime(void *ptr, uint32_t time);
tass 51:ab4529a384a6 178 int pico_dhcp_opt_msgtype(void *ptr, uint8_t type);
tass 51:ab4529a384a6 179 int pico_dhcp_opt_serverid(void *ptr, struct pico_ip4 *ip);
tass 51:ab4529a384a6 180 int pico_dhcp_opt_paramlist(void *ptr);
tass 51:ab4529a384a6 181 int pico_dhcp_opt_maxmsgsize(void *ptr, uint16_t size);
tass 51:ab4529a384a6 182 int pico_dhcp_opt_end(void *ptr);
daniele 3:b4047e8a0123 183 #endif