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 Sep 19 13:26:14 2013 +0000
Revision:
68:0847e35d08a6
Child:
70:cd218dd180e5
Imported from masterbranch, again

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