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 RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling 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.
modules/pico_dhcp_common.c@149:5f4cb161cec3, 2014-04-09 (annotated)
- Committer:
- tass picotcp@tass.be
- Date:
- Wed Apr 09 14:31:41 2014 +0200
- Revision:
- 149:5f4cb161cec3
- Parent:
- 131:4758606c9316
- Child:
- 152:a3d286bf94e5
Update from git masterbranch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tass | 68:0847e35d08a6 | 1 | /********************************************************************* |
TASS Belgium NV |
131:4758606c9316 | 2 | PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved. |
TASS Belgium NV |
131:4758606c9316 | 3 | See LICENSE and COPYING for usage. |
tass | 68:0847e35d08a6 | 4 | |
TASS Belgium NV |
131:4758606c9316 | 5 | . |
tass | 68:0847e35d08a6 | 6 | |
TASS Belgium NV |
131:4758606c9316 | 7 | Authors: Frederik Van Slycken |
TASS Belgium NV |
131:4758606c9316 | 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 Belgium NV |
131:4758606c9316 | 19 | uint8_t **p = (uint8_t **)ptr; |
TASS Belgium NV |
131:4758606c9316 | 20 | struct pico_dhcp_opt *opt = *ptr; |
TASS Belgium NV |
131:4758606c9316 | 21 | |
TASS Belgium NV |
131:4758606c9316 | 22 | if (opt->code == PICO_DHCP_OPT_END) |
TASS Belgium NV |
131:4758606c9316 | 23 | return NULL; |
tass | 68:0847e35d08a6 | 24 | |
TASS Belgium NV |
131:4758606c9316 | 25 | if (opt->code == PICO_DHCP_OPT_PAD) { |
TASS Belgium NV |
131:4758606c9316 | 26 | *p += 1; |
TASS Belgium NV |
131:4758606c9316 | 27 | return *ptr; |
TASS Belgium NV |
131:4758606c9316 | 28 | } |
tass | 68:0847e35d08a6 | 29 | |
TASS Belgium NV |
131:4758606c9316 | 30 | *p += (opt->len + 2); /* (len + 2) to account for code and len octet */ |
TASS Belgium NV |
131:4758606c9316 | 31 | return *ptr; |
tass | 68:0847e35d08a6 | 32 | } |
tass | 68:0847e35d08a6 | 33 | |
tass | 70:cd218dd180e5 | 34 | uint8_t pico_dhcp_are_options_valid(void *ptr, int32_t len) |
tass | 68:0847e35d08a6 | 35 | { |
TASS Belgium NV |
131:4758606c9316 | 36 | uint8_t optlen = 0, *p = ptr; |
tass | 68:0847e35d08a6 | 37 | |
TASS Belgium NV |
131:4758606c9316 | 38 | while (len > 0) { |
TASS Belgium NV |
131:4758606c9316 | 39 | switch (*p) |
TASS Belgium NV |
131:4758606c9316 | 40 | { |
TASS Belgium NV |
131:4758606c9316 | 41 | case PICO_DHCP_OPT_END: |
TASS Belgium NV |
131:4758606c9316 | 42 | return 1; |
TASS Belgium NV |
131:4758606c9316 | 43 | |
TASS Belgium NV |
131:4758606c9316 | 44 | case PICO_DHCP_OPT_PAD: |
TASS Belgium NV |
131:4758606c9316 | 45 | p++; |
TASS Belgium NV |
131:4758606c9316 | 46 | len--; |
TASS Belgium NV |
131:4758606c9316 | 47 | break; |
tass | 68:0847e35d08a6 | 48 | |
TASS Belgium NV |
131:4758606c9316 | 49 | default: |
TASS Belgium NV |
131:4758606c9316 | 50 | p++; /* move pointer from code octet to len octet */ |
tass picotcp@tass.be | 149:5f4cb161cec3 | 51 | len--; |
tass picotcp@tass.be | 149:5f4cb161cec3 | 52 | if ((len <= 0) || (len - (*p + 1) < 0)) /* (*p + 1) to account for len octet */ |
TASS Belgium NV |
131:4758606c9316 | 53 | return 0; |
tass | 68:0847e35d08a6 | 54 | |
TASS Belgium NV |
131:4758606c9316 | 55 | optlen = *p; |
TASS Belgium NV |
131:4758606c9316 | 56 | p += optlen + 1; |
TASS Belgium NV |
131:4758606c9316 | 57 | len -= optlen; |
TASS Belgium NV |
131:4758606c9316 | 58 | break; |
TASS Belgium NV |
131:4758606c9316 | 59 | } |
tass | 68:0847e35d08a6 | 60 | } |
TASS Belgium NV |
131:4758606c9316 | 61 | return 0; |
tass | 68:0847e35d08a6 | 62 | } |
tass | 68:0847e35d08a6 | 63 | |
tass | 70:cd218dd180e5 | 64 | uint8_t pico_dhcp_opt_netmask(void *ptr, struct pico_ip4 *ip) |
tass | 68:0847e35d08a6 | 65 | { |
TASS Belgium NV |
131:4758606c9316 | 66 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 67 | |
TASS Belgium NV |
131:4758606c9316 | 68 | /* option: netmask */ |
TASS Belgium NV |
131:4758606c9316 | 69 | opt->code = PICO_DHCP_OPT_NETMASK; |
TASS Belgium NV |
131:4758606c9316 | 70 | opt->len = PICO_DHCP_OPTLEN_NETMASK - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 71 | opt->ext.netmask.ip = *ip; |
TASS Belgium NV |
131:4758606c9316 | 72 | return PICO_DHCP_OPTLEN_NETMASK; |
tass | 68:0847e35d08a6 | 73 | } |
tass | 68:0847e35d08a6 | 74 | |
tass | 70:cd218dd180e5 | 75 | uint8_t pico_dhcp_opt_router(void *ptr, struct pico_ip4 *ip) |
tass | 68:0847e35d08a6 | 76 | { |
TASS Belgium NV |
131:4758606c9316 | 77 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 78 | |
TASS Belgium NV |
131:4758606c9316 | 79 | /* option: router */ |
TASS Belgium NV |
131:4758606c9316 | 80 | opt->code = PICO_DHCP_OPT_ROUTER; |
TASS Belgium NV |
131:4758606c9316 | 81 | opt->len = PICO_DHCP_OPTLEN_ROUTER - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 82 | opt->ext.router.ip = *ip; |
TASS Belgium NV |
131:4758606c9316 | 83 | return PICO_DHCP_OPTLEN_ROUTER; |
tass | 68:0847e35d08a6 | 84 | } |
tass | 68:0847e35d08a6 | 85 | |
tass | 70:cd218dd180e5 | 86 | uint8_t pico_dhcp_opt_dns(void *ptr, struct pico_ip4 *ip) |
tass | 68:0847e35d08a6 | 87 | { |
TASS Belgium NV |
131:4758606c9316 | 88 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 89 | |
TASS Belgium NV |
131:4758606c9316 | 90 | /* option: dns */ |
TASS Belgium NV |
131:4758606c9316 | 91 | opt->code = PICO_DHCP_OPT_DNS; |
TASS Belgium NV |
131:4758606c9316 | 92 | opt->len = PICO_DHCP_OPTLEN_DNS - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 93 | opt->ext.dns.ip = *ip; |
TASS Belgium NV |
131:4758606c9316 | 94 | return PICO_DHCP_OPTLEN_DNS; |
tass | 68:0847e35d08a6 | 95 | } |
tass | 68:0847e35d08a6 | 96 | |
tass | 70:cd218dd180e5 | 97 | uint8_t pico_dhcp_opt_broadcast(void *ptr, struct pico_ip4 *ip) |
tass | 68:0847e35d08a6 | 98 | { |
TASS Belgium NV |
131:4758606c9316 | 99 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 100 | |
TASS Belgium NV |
131:4758606c9316 | 101 | /* option: broadcast */ |
TASS Belgium NV |
131:4758606c9316 | 102 | opt->code = PICO_DHCP_OPT_BROADCAST; |
TASS Belgium NV |
131:4758606c9316 | 103 | opt->len = PICO_DHCP_OPTLEN_BROADCAST - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 104 | opt->ext.broadcast.ip = *ip; |
TASS Belgium NV |
131:4758606c9316 | 105 | return PICO_DHCP_OPTLEN_BROADCAST; |
tass | 68:0847e35d08a6 | 106 | } |
tass | 68:0847e35d08a6 | 107 | |
tass | 70:cd218dd180e5 | 108 | uint8_t pico_dhcp_opt_reqip(void *ptr, struct pico_ip4 *ip) |
tass | 68:0847e35d08a6 | 109 | { |
TASS Belgium NV |
131:4758606c9316 | 110 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 111 | |
TASS Belgium NV |
131:4758606c9316 | 112 | /* option: request IP address */ |
TASS Belgium NV |
131:4758606c9316 | 113 | opt->code = PICO_DHCP_OPT_REQIP; |
TASS Belgium NV |
131:4758606c9316 | 114 | opt->len = PICO_DHCP_OPTLEN_REQIP - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 115 | opt->ext.req_ip.ip = *ip; |
TASS Belgium NV |
131:4758606c9316 | 116 | return PICO_DHCP_OPTLEN_REQIP; |
tass | 68:0847e35d08a6 | 117 | } |
tass | 68:0847e35d08a6 | 118 | |
tass | 70:cd218dd180e5 | 119 | uint8_t pico_dhcp_opt_leasetime(void *ptr, uint32_t time) |
tass | 68:0847e35d08a6 | 120 | { |
TASS Belgium NV |
131:4758606c9316 | 121 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 122 | |
TASS Belgium NV |
131:4758606c9316 | 123 | /* option: lease time */ |
TASS Belgium NV |
131:4758606c9316 | 124 | opt->code = PICO_DHCP_OPT_LEASETIME; |
TASS Belgium NV |
131:4758606c9316 | 125 | opt->len = PICO_DHCP_OPTLEN_LEASETIME - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 126 | opt->ext.lease_time.time = time; |
TASS Belgium NV |
131:4758606c9316 | 127 | return PICO_DHCP_OPTLEN_LEASETIME; |
tass | 68:0847e35d08a6 | 128 | } |
tass | 68:0847e35d08a6 | 129 | |
tass | 70:cd218dd180e5 | 130 | uint8_t pico_dhcp_opt_msgtype(void *ptr, uint8_t type) |
tass | 68:0847e35d08a6 | 131 | { |
TASS Belgium NV |
131:4758606c9316 | 132 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 133 | |
TASS Belgium NV |
131:4758606c9316 | 134 | /* option: message type */ |
TASS Belgium NV |
131:4758606c9316 | 135 | opt->code = PICO_DHCP_OPT_MSGTYPE; |
TASS Belgium NV |
131:4758606c9316 | 136 | opt->len = PICO_DHCP_OPTLEN_MSGTYPE - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 137 | opt->ext.msg_type.type = type; |
TASS Belgium NV |
131:4758606c9316 | 138 | return PICO_DHCP_OPTLEN_MSGTYPE; |
tass | 68:0847e35d08a6 | 139 | } |
tass | 68:0847e35d08a6 | 140 | |
tass | 70:cd218dd180e5 | 141 | uint8_t pico_dhcp_opt_serverid(void *ptr, struct pico_ip4 *ip) |
tass | 68:0847e35d08a6 | 142 | { |
TASS Belgium NV |
131:4758606c9316 | 143 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 144 | |
TASS Belgium NV |
131:4758606c9316 | 145 | /* option: server identifier */ |
TASS Belgium NV |
131:4758606c9316 | 146 | opt->code = PICO_DHCP_OPT_SERVERID; |
TASS Belgium NV |
131:4758606c9316 | 147 | opt->len = PICO_DHCP_OPTLEN_SERVERID - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 148 | opt->ext.server_id.ip = *ip; |
TASS Belgium NV |
131:4758606c9316 | 149 | return PICO_DHCP_OPTLEN_SERVERID; |
tass | 68:0847e35d08a6 | 150 | } |
tass | 68:0847e35d08a6 | 151 | |
tass | 70:cd218dd180e5 | 152 | uint8_t pico_dhcp_opt_paramlist(void *ptr) |
tass | 68:0847e35d08a6 | 153 | { |
TASS Belgium NV |
131:4758606c9316 | 154 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 155 | |
TASS Belgium NV |
131:4758606c9316 | 156 | /* option: parameter list */ |
TASS Belgium NV |
131:4758606c9316 | 157 | opt->code = PICO_DHCP_OPT_PARAMLIST; |
TASS Belgium NV |
131:4758606c9316 | 158 | opt->len = PICO_DHCP_OPTLEN_PARAMLIST - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 159 | opt->ext.param_list.code[0] = PICO_DHCP_OPT_NETMASK; |
TASS Belgium NV |
131:4758606c9316 | 160 | opt->ext.param_list.code[1] = PICO_DHCP_OPT_TIME; |
TASS Belgium NV |
131:4758606c9316 | 161 | opt->ext.param_list.code[2] = PICO_DHCP_OPT_ROUTER; |
TASS Belgium NV |
131:4758606c9316 | 162 | opt->ext.param_list.code[3] = PICO_DHCP_OPT_HOSTNAME; |
TASS Belgium NV |
131:4758606c9316 | 163 | opt->ext.param_list.code[4] = PICO_DHCP_OPT_RENEWALTIME; |
TASS Belgium NV |
131:4758606c9316 | 164 | opt->ext.param_list.code[5] = PICO_DHCP_OPT_REBINDINGTIME; |
TASS Belgium NV |
131:4758606c9316 | 165 | return PICO_DHCP_OPTLEN_PARAMLIST; |
tass | 68:0847e35d08a6 | 166 | } |
tass | 68:0847e35d08a6 | 167 | |
tass | 70:cd218dd180e5 | 168 | uint8_t pico_dhcp_opt_maxmsgsize(void *ptr, uint16_t size) |
tass | 68:0847e35d08a6 | 169 | { |
TASS Belgium NV |
131:4758606c9316 | 170 | struct pico_dhcp_opt *opt = (struct pico_dhcp_opt *)ptr; |
tass | 68:0847e35d08a6 | 171 | |
TASS Belgium NV |
131:4758606c9316 | 172 | /* option: maximum message size */ |
TASS Belgium NV |
131:4758606c9316 | 173 | opt->code = PICO_DHCP_OPT_MAXMSGSIZE; |
TASS Belgium NV |
131:4758606c9316 | 174 | opt->len = PICO_DHCP_OPTLEN_MAXMSGSIZE - PICO_DHCP_OPTLEN_HDR; |
TASS Belgium NV |
131:4758606c9316 | 175 | opt->ext.max_msg_size.size = short_be(size); |
TASS Belgium NV |
131:4758606c9316 | 176 | return PICO_DHCP_OPTLEN_MAXMSGSIZE; |
tass | 68:0847e35d08a6 | 177 | } |
tass | 68:0847e35d08a6 | 178 | |
tass | 70:cd218dd180e5 | 179 | uint8_t pico_dhcp_opt_end(void *ptr) |
tass | 68:0847e35d08a6 | 180 | { |
TASS Belgium NV |
131:4758606c9316 | 181 | uint8_t *opt = (uint8_t *)ptr; |
tass | 68:0847e35d08a6 | 182 | |
TASS Belgium NV |
131:4758606c9316 | 183 | /* option: end of options */ |
TASS Belgium NV |
131:4758606c9316 | 184 | *opt = PICO_DHCP_OPT_END; |
TASS Belgium NV |
131:4758606c9316 | 185 | return PICO_DHCP_OPTLEN_END; |
tass | 68:0847e35d08a6 | 186 | } |
tass | 68:0847e35d08a6 | 187 | |
tass | 68:0847e35d08a6 | 188 | #endif |