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:
Thu Nov 21 09:48:05 2013 +0000
Revision:
122:5b1e9de8bf7f
Parent:
70:cd218dd180e5
Child:
131:4758606c9316
Update from masterbranch.

Who changed what in which revision?

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