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 Authors: Frederik Van Slycken
daniele 3:b4047e8a0123 8 *********************************************************************/
daniele 3:b4047e8a0123 9
daniele 3:b4047e8a0123 10 #include "pico_config.h"
daniele 3:b4047e8a0123 11 #include "pico_stack.h"
daniele 3:b4047e8a0123 12 #include "pico_dhcp_common.h"
daniele 3:b4047e8a0123 13
daniele 3:b4047e8a0123 14 #if defined (PICO_SUPPORT_DHCPC) || defined (PICO_SUPPORT_DHCPD)
tass 51:ab4529a384a6 15 /* pico_dhcp_are_options_valid needs to be called first to prevent illegal memory access */
tass 51:ab4529a384a6 16 /* The argument pointer is moved forward to the next option */
tass 51:ab4529a384a6 17 struct pico_dhcp_opt *pico_dhcp_next_option(struct pico_dhcp_opt **ptr)
daniele 3:b4047e8a0123 18 {
tass 51:ab4529a384a6 19 uint8_t **p = (uint8_t **)ptr;
tass 51:ab4529a384a6 20 struct pico_dhcp_opt *opt = *ptr;
tass 51:ab4529a384a6 21
tass 51:ab4529a384a6 22 if (opt->code == PICO_DHCP_OPT_END)
tass 51:ab4529a384a6 23 return NULL;
tass 51:ab4529a384a6 24 if (opt->code == PICO_DHCP_OPT_PAD) {
tass 51:ab4529a384a6 25 *p += 1;
tass 51:ab4529a384a6 26 return *ptr;
tass 51:ab4529a384a6 27 }
tass 51:ab4529a384a6 28
tass 51:ab4529a384a6 29 *p += (opt->len + 2); /* (len + 2) to account for code and len octet */
tass 51:ab4529a384a6 30 return *ptr;
tass 51:ab4529a384a6 31 }
daniele 3:b4047e8a0123 32
tass 51:ab4529a384a6 33 int pico_dhcp_are_options_valid(void *ptr, int len)
tass 51:ab4529a384a6 34 {
tass 51:ab4529a384a6 35 uint8_t optlen = 0, *p = ptr;
tass 51:ab4529a384a6 36
tass 51:ab4529a384a6 37 while (len > 0) {
tass 51:ab4529a384a6 38 switch (*p)
tass 51:ab4529a384a6 39 {
tass 51:ab4529a384a6 40 case PICO_DHCP_OPT_END:
tass 51:ab4529a384a6 41 return 1;
tass 51:ab4529a384a6 42
tass 51:ab4529a384a6 43 case PICO_DHCP_OPT_PAD:
tass 51:ab4529a384a6 44 p++;
tass 51:ab4529a384a6 45 len--;
tass 51:ab4529a384a6 46 break;
daniele 3:b4047e8a0123 47
tass 51:ab4529a384a6 48 default:
tass 51:ab4529a384a6 49 p++; /* move pointer from code octet to len octet */
tass 51:ab4529a384a6 50 if ((--len <= 0) || (len - (*p + 1) < 0)) /* (*p + 1) to account for len octet */
tass 51:ab4529a384a6 51 return 0;
tass 51:ab4529a384a6 52 optlen = *p;
tass 51:ab4529a384a6 53 p += optlen + 1;
tass 51:ab4529a384a6 54 len -= optlen;
tass 51:ab4529a384a6 55 break;
daniele 3:b4047e8a0123 56 }
tass 51:ab4529a384a6 57 }
tass 51:ab4529a384a6 58 return 0;
tass 51:ab4529a384a6 59 }
tass 51:ab4529a384a6 60
tass 51:ab4529a384a6 61 int pico_dhcp_opt_netmask(void *ptr, struct pico_ip4 *ip)
tass 51:ab4529a384a6 62 {
tass 51:ab4529a384a6 63 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 64
tass 51:ab4529a384a6 65 /* option: netmask */
tass 51:ab4529a384a6 66 opt->code = PICO_DHCP_OPT_NETMASK;
tass 51:ab4529a384a6 67 opt->len = PICO_DHCP_OPTLEN_NETMASK - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 68 opt->ext.netmask.ip = *ip;
tass 51:ab4529a384a6 69 return PICO_DHCP_OPTLEN_NETMASK;
tass 51:ab4529a384a6 70 }
tass 51:ab4529a384a6 71
tass 51:ab4529a384a6 72 int pico_dhcp_opt_router(void *ptr, struct pico_ip4 *ip)
tass 51:ab4529a384a6 73 {
tass 51:ab4529a384a6 74 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 75
tass 51:ab4529a384a6 76 /* option: router */
tass 51:ab4529a384a6 77 opt->code = PICO_DHCP_OPT_ROUTER;
tass 51:ab4529a384a6 78 opt->len = PICO_DHCP_OPTLEN_ROUTER - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 79 opt->ext.router.ip = *ip;
tass 51:ab4529a384a6 80 return PICO_DHCP_OPTLEN_ROUTER;
tass 51:ab4529a384a6 81 }
tass 51:ab4529a384a6 82
tass 51:ab4529a384a6 83 int pico_dhcp_opt_dns(void *ptr, struct pico_ip4 *ip)
tass 51:ab4529a384a6 84 {
tass 51:ab4529a384a6 85 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 86
tass 51:ab4529a384a6 87 /* option: dns */
tass 51:ab4529a384a6 88 opt->code = PICO_DHCP_OPT_DNS;
tass 51:ab4529a384a6 89 opt->len = PICO_DHCP_OPTLEN_DNS - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 90 opt->ext.dns.ip = *ip;
tass 51:ab4529a384a6 91 return PICO_DHCP_OPTLEN_DNS;
daniele 3:b4047e8a0123 92 }
daniele 3:b4047e8a0123 93
tass 51:ab4529a384a6 94 int pico_dhcp_opt_broadcast(void *ptr, struct pico_ip4 *ip)
tass 51:ab4529a384a6 95 {
tass 51:ab4529a384a6 96 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 97
tass 51:ab4529a384a6 98 /* option: broadcast */
tass 51:ab4529a384a6 99 opt->code = PICO_DHCP_OPT_BROADCAST;
tass 51:ab4529a384a6 100 opt->len = PICO_DHCP_OPTLEN_BROADCAST - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 101 opt->ext.broadcast.ip = *ip;
tass 51:ab4529a384a6 102 return PICO_DHCP_OPTLEN_BROADCAST;
tass 51:ab4529a384a6 103 }
tass 51:ab4529a384a6 104
tass 51:ab4529a384a6 105 int pico_dhcp_opt_reqip(void *ptr, struct pico_ip4 *ip)
tass 51:ab4529a384a6 106 {
tass 51:ab4529a384a6 107 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 108
tass 51:ab4529a384a6 109 /* option: request IP address */
tass 51:ab4529a384a6 110 opt->code = PICO_DHCP_OPT_REQIP;
tass 51:ab4529a384a6 111 opt->len = PICO_DHCP_OPTLEN_REQIP - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 112 opt->ext.req_ip.ip = *ip;
tass 51:ab4529a384a6 113 return PICO_DHCP_OPTLEN_REQIP;
tass 51:ab4529a384a6 114 }
tass 51:ab4529a384a6 115
tass 51:ab4529a384a6 116 int pico_dhcp_opt_leasetime(void *ptr, uint32_t time)
tass 51:ab4529a384a6 117 {
tass 51:ab4529a384a6 118 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 119
tass 51:ab4529a384a6 120 /* option: lease time */
tass 51:ab4529a384a6 121 opt->code = PICO_DHCP_OPT_LEASETIME;
tass 51:ab4529a384a6 122 opt->len = PICO_DHCP_OPTLEN_LEASETIME - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 123 opt->ext.lease_time.time = time;
tass 51:ab4529a384a6 124 return PICO_DHCP_OPTLEN_LEASETIME;
tass 51:ab4529a384a6 125 }
tass 51:ab4529a384a6 126
tass 51:ab4529a384a6 127 int pico_dhcp_opt_msgtype(void *ptr, uint8_t type)
daniele 3:b4047e8a0123 128 {
tass 51:ab4529a384a6 129 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 130
tass 51:ab4529a384a6 131 /* option: message type */
tass 51:ab4529a384a6 132 opt->code = PICO_DHCP_OPT_MSGTYPE;
tass 51:ab4529a384a6 133 opt->len = PICO_DHCP_OPTLEN_MSGTYPE - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 134 opt->ext.msg_type.type = type;
tass 51:ab4529a384a6 135 return PICO_DHCP_OPTLEN_MSGTYPE;
tass 51:ab4529a384a6 136 }
tass 51:ab4529a384a6 137
tass 51:ab4529a384a6 138 int pico_dhcp_opt_serverid(void *ptr, struct pico_ip4 *ip)
tass 51:ab4529a384a6 139 {
tass 51:ab4529a384a6 140 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 141
tass 51:ab4529a384a6 142 /* option: server identifier */
tass 51:ab4529a384a6 143 opt->code = PICO_DHCP_OPT_SERVERID;
tass 51:ab4529a384a6 144 opt->len = PICO_DHCP_OPTLEN_SERVERID - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 145 opt->ext.server_id.ip = *ip;
tass 51:ab4529a384a6 146 return PICO_DHCP_OPTLEN_SERVERID;
tass 51:ab4529a384a6 147 }
tass 51:ab4529a384a6 148
tass 51:ab4529a384a6 149 int pico_dhcp_opt_paramlist(void *ptr)
tass 51:ab4529a384a6 150 {
tass 51:ab4529a384a6 151 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 152
tass 51:ab4529a384a6 153 /* option: parameter list */
tass 51:ab4529a384a6 154 opt->code = PICO_DHCP_OPT_PARAMLIST;
tass 51:ab4529a384a6 155 opt->len = PICO_DHCP_OPTLEN_PARAMLIST - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 156 opt->ext.param_list.code[0] = PICO_DHCP_OPT_NETMASK;
tass 51:ab4529a384a6 157 opt->ext.param_list.code[1] = PICO_DHCP_OPT_TIME;
tass 51:ab4529a384a6 158 opt->ext.param_list.code[2] = PICO_DHCP_OPT_ROUTER;
tass 51:ab4529a384a6 159 opt->ext.param_list.code[3] = PICO_DHCP_OPT_HOSTNAME;
tass 51:ab4529a384a6 160 opt->ext.param_list.code[4] = PICO_DHCP_OPT_RENEWALTIME;
tass 51:ab4529a384a6 161 opt->ext.param_list.code[5] = PICO_DHCP_OPT_REBINDINGTIME;
tass 51:ab4529a384a6 162 return PICO_DHCP_OPTLEN_PARAMLIST;
tass 51:ab4529a384a6 163 }
tass 51:ab4529a384a6 164
tass 51:ab4529a384a6 165 int pico_dhcp_opt_maxmsgsize(void *ptr, uint16_t size)
tass 51:ab4529a384a6 166 {
tass 51:ab4529a384a6 167 struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr;
tass 51:ab4529a384a6 168
tass 51:ab4529a384a6 169 /* option: maximum message size */
tass 51:ab4529a384a6 170 opt->code = PICO_DHCP_OPT_MAXMSGSIZE;
tass 51:ab4529a384a6 171 opt->len = PICO_DHCP_OPTLEN_MAXMSGSIZE - PICO_DHCP_OPTLEN_HDR;
tass 51:ab4529a384a6 172 opt->ext.max_msg_size.size = short_be(size);
tass 51:ab4529a384a6 173 return PICO_DHCP_OPTLEN_MAXMSGSIZE;
tass 51:ab4529a384a6 174 }
tass 51:ab4529a384a6 175
tass 51:ab4529a384a6 176 int pico_dhcp_opt_end(void *ptr)
tass 51:ab4529a384a6 177 {
tass 51:ab4529a384a6 178 uint8_t *opt = (uint8_t *)ptr;
tass 51:ab4529a384a6 179
tass 51:ab4529a384a6 180 /* option: end of options */
tass 51:ab4529a384a6 181 *opt = PICO_DHCP_OPT_END;
tass 51:ab4529a384a6 182 return PICO_DHCP_OPTLEN_END;
daniele 3:b4047e8a0123 183 }
daniele 3:b4047e8a0123 184
daniele 3:b4047e8a0123 185 #endif