LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Fri May 25 08:56:35 2012 +0000
Revision:
2:1a87f74b8e3b
Parent:
0:8e01dca41002
Removed compilation of EMAC driver when using PPP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:8e01dca41002 1 /** @file
donatien 0:8e01dca41002 2 */
donatien 0:8e01dca41002 3
donatien 0:8e01dca41002 4 #ifndef __LWIP_DHCP_H__
donatien 0:8e01dca41002 5 #define __LWIP_DHCP_H__
donatien 0:8e01dca41002 6
donatien 0:8e01dca41002 7 #include "lwip/opt.h"
donatien 0:8e01dca41002 8
donatien 0:8e01dca41002 9 #if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
donatien 0:8e01dca41002 10
donatien 0:8e01dca41002 11 #include "lwip/netif.h"
donatien 0:8e01dca41002 12 #include "lwip/udp.h"
donatien 0:8e01dca41002 13
donatien 0:8e01dca41002 14 #ifdef __cplusplus
donatien 0:8e01dca41002 15 extern "C" {
donatien 0:8e01dca41002 16 #endif
donatien 0:8e01dca41002 17
donatien 0:8e01dca41002 18 /** period (in seconds) of the application calling dhcp_coarse_tmr() */
donatien 0:8e01dca41002 19 #define DHCP_COARSE_TIMER_SECS 60
donatien 0:8e01dca41002 20 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
donatien 0:8e01dca41002 21 #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
donatien 0:8e01dca41002 22 /** period (in milliseconds) of the application calling dhcp_fine_tmr() */
donatien 0:8e01dca41002 23 #define DHCP_FINE_TIMER_MSECS 500
donatien 0:8e01dca41002 24
donatien 0:8e01dca41002 25 #define DHCP_CHADDR_LEN 16U
donatien 0:8e01dca41002 26 #define DHCP_SNAME_LEN 64U
donatien 0:8e01dca41002 27 #define DHCP_FILE_LEN 128U
donatien 0:8e01dca41002 28
donatien 0:8e01dca41002 29 struct dhcp
donatien 0:8e01dca41002 30 {
donatien 0:8e01dca41002 31 /** transaction identifier of last sent request */
donatien 0:8e01dca41002 32 u32_t xid;
donatien 0:8e01dca41002 33 /** our connection to the DHCP server */
donatien 0:8e01dca41002 34 struct udp_pcb *pcb;
donatien 0:8e01dca41002 35 /** incoming msg */
donatien 0:8e01dca41002 36 struct dhcp_msg *msg_in;
donatien 0:8e01dca41002 37 /** current DHCP state machine state */
donatien 0:8e01dca41002 38 u8_t state;
donatien 0:8e01dca41002 39 /** retries of current request */
donatien 0:8e01dca41002 40 u8_t tries;
donatien 0:8e01dca41002 41 #if LWIP_DHCP_AUTOIP_COOP
donatien 0:8e01dca41002 42 u8_t autoip_coop_state;
donatien 0:8e01dca41002 43 #endif
donatien 0:8e01dca41002 44 u8_t subnet_mask_given;
donatien 0:8e01dca41002 45
donatien 0:8e01dca41002 46 struct pbuf *p_out; /* pbuf of outcoming msg */
donatien 0:8e01dca41002 47 struct dhcp_msg *msg_out; /* outgoing msg */
donatien 0:8e01dca41002 48 u16_t options_out_len; /* outgoing msg options length */
donatien 0:8e01dca41002 49 u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
donatien 0:8e01dca41002 50 u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
donatien 0:8e01dca41002 51 u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
donatien 0:8e01dca41002 52 ip_addr_t server_ip_addr; /* dhcp server address that offered this lease */
donatien 0:8e01dca41002 53 ip_addr_t offered_ip_addr;
donatien 0:8e01dca41002 54 ip_addr_t offered_sn_mask;
donatien 0:8e01dca41002 55 ip_addr_t offered_gw_addr;
donatien 0:8e01dca41002 56
donatien 0:8e01dca41002 57 u32_t offered_t0_lease; /* lease period (in seconds) */
donatien 0:8e01dca41002 58 u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
donatien 0:8e01dca41002 59 u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
donatien 0:8e01dca41002 60 /* @todo: LWIP_DHCP_BOOTP_FILE configuration option?
donatien 0:8e01dca41002 61 integrate with possible TFTP-client for booting? */
donatien 0:8e01dca41002 62 #if LWIP_DHCP_BOOTP_FILE
donatien 0:8e01dca41002 63 ip_addr_t offered_si_addr;
donatien 0:8e01dca41002 64 char boot_file_name[DHCP_FILE_LEN];
donatien 0:8e01dca41002 65 #endif /* LWIP_DHCP_BOOTPFILE */
donatien 0:8e01dca41002 66 };
donatien 0:8e01dca41002 67
donatien 0:8e01dca41002 68 /* MUST be compiled with "pack structs" or equivalent! */
donatien 0:8e01dca41002 69 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:8e01dca41002 70 # include "arch/bpstruct.h"
donatien 0:8e01dca41002 71 #endif
donatien 0:8e01dca41002 72 PACK_STRUCT_BEGIN
donatien 0:8e01dca41002 73 /** minimum set of fields of any DHCP message */
donatien 0:8e01dca41002 74 struct dhcp_msg
donatien 0:8e01dca41002 75 {
donatien 0:8e01dca41002 76 PACK_STRUCT_FIELD(u8_t op);
donatien 0:8e01dca41002 77 PACK_STRUCT_FIELD(u8_t htype);
donatien 0:8e01dca41002 78 PACK_STRUCT_FIELD(u8_t hlen);
donatien 0:8e01dca41002 79 PACK_STRUCT_FIELD(u8_t hops);
donatien 0:8e01dca41002 80 PACK_STRUCT_FIELD(u32_t xid);
donatien 0:8e01dca41002 81 PACK_STRUCT_FIELD(u16_t secs);
donatien 0:8e01dca41002 82 PACK_STRUCT_FIELD(u16_t flags);
donatien 0:8e01dca41002 83 PACK_STRUCT_FIELD(ip_addr_p_t ciaddr);
donatien 0:8e01dca41002 84 PACK_STRUCT_FIELD(ip_addr_p_t yiaddr);
donatien 0:8e01dca41002 85 PACK_STRUCT_FIELD(ip_addr_p_t siaddr);
donatien 0:8e01dca41002 86 PACK_STRUCT_FIELD(ip_addr_p_t giaddr);
donatien 0:8e01dca41002 87 PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
donatien 0:8e01dca41002 88 PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
donatien 0:8e01dca41002 89 PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
donatien 0:8e01dca41002 90 PACK_STRUCT_FIELD(u32_t cookie);
donatien 0:8e01dca41002 91 #define DHCP_MIN_OPTIONS_LEN 68U
donatien 0:8e01dca41002 92 /** make sure user does not configure this too small */
donatien 0:8e01dca41002 93 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
donatien 0:8e01dca41002 94 # undef DHCP_OPTIONS_LEN
donatien 0:8e01dca41002 95 #endif
donatien 0:8e01dca41002 96 /** allow this to be configured in lwipopts.h, but not too small */
donatien 0:8e01dca41002 97 #if (!defined(DHCP_OPTIONS_LEN))
donatien 0:8e01dca41002 98 /** set this to be sufficient for your options in outgoing DHCP msgs */
donatien 0:8e01dca41002 99 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
donatien 0:8e01dca41002 100 #endif
donatien 0:8e01dca41002 101 PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
donatien 0:8e01dca41002 102 } PACK_STRUCT_STRUCT;
donatien 0:8e01dca41002 103 PACK_STRUCT_END
donatien 0:8e01dca41002 104 #ifdef PACK_STRUCT_USE_INCLUDES
donatien 0:8e01dca41002 105 # include "arch/epstruct.h"
donatien 0:8e01dca41002 106 #endif
donatien 0:8e01dca41002 107
donatien 0:8e01dca41002 108 void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
donatien 0:8e01dca41002 109 /** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */
donatien 0:8e01dca41002 110 #define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0)
donatien 0:8e01dca41002 111 void dhcp_cleanup(struct netif *netif);
donatien 0:8e01dca41002 112 /** start DHCP configuration */
donatien 0:8e01dca41002 113 err_t dhcp_start(struct netif *netif);
donatien 0:8e01dca41002 114 /** enforce early lease renewal (not needed normally)*/
donatien 0:8e01dca41002 115 err_t dhcp_renew(struct netif *netif);
donatien 0:8e01dca41002 116 /** release the DHCP lease, usually called before dhcp_stop()*/
donatien 0:8e01dca41002 117 err_t dhcp_release(struct netif *netif);
donatien 0:8e01dca41002 118 /** stop DHCP configuration */
donatien 0:8e01dca41002 119 void dhcp_stop(struct netif *netif);
donatien 0:8e01dca41002 120 /** inform server of our manual IP address */
donatien 0:8e01dca41002 121 void dhcp_inform(struct netif *netif);
donatien 0:8e01dca41002 122 /** Handle a possible change in the network configuration */
donatien 0:8e01dca41002 123 void dhcp_network_changed(struct netif *netif);
donatien 0:8e01dca41002 124
donatien 0:8e01dca41002 125 /** if enabled, check whether the offered IP address is not in use, using ARP */
donatien 0:8e01dca41002 126 #if DHCP_DOES_ARP_CHECK
donatien 0:8e01dca41002 127 void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr);
donatien 0:8e01dca41002 128 #endif
donatien 0:8e01dca41002 129
donatien 0:8e01dca41002 130 /** to be called every minute */
donatien 0:8e01dca41002 131 void dhcp_coarse_tmr(void);
donatien 0:8e01dca41002 132 /** to be called every half second */
donatien 0:8e01dca41002 133 void dhcp_fine_tmr(void);
donatien 0:8e01dca41002 134
donatien 0:8e01dca41002 135 /** DHCP message item offsets and length */
donatien 0:8e01dca41002 136 #define DHCP_OP_OFS 0
donatien 0:8e01dca41002 137 #define DHCP_HTYPE_OFS 1
donatien 0:8e01dca41002 138 #define DHCP_HLEN_OFS 2
donatien 0:8e01dca41002 139 #define DHCP_HOPS_OFS 3
donatien 0:8e01dca41002 140 #define DHCP_XID_OFS 4
donatien 0:8e01dca41002 141 #define DHCP_SECS_OFS 8
donatien 0:8e01dca41002 142 #define DHCP_FLAGS_OFS 10
donatien 0:8e01dca41002 143 #define DHCP_CIADDR_OFS 12
donatien 0:8e01dca41002 144 #define DHCP_YIADDR_OFS 16
donatien 0:8e01dca41002 145 #define DHCP_SIADDR_OFS 20
donatien 0:8e01dca41002 146 #define DHCP_GIADDR_OFS 24
donatien 0:8e01dca41002 147 #define DHCP_CHADDR_OFS 28
donatien 0:8e01dca41002 148 #define DHCP_SNAME_OFS 44
donatien 0:8e01dca41002 149 #define DHCP_FILE_OFS 108
donatien 0:8e01dca41002 150 #define DHCP_MSG_LEN 236
donatien 0:8e01dca41002 151
donatien 0:8e01dca41002 152 #define DHCP_COOKIE_OFS DHCP_MSG_LEN
donatien 0:8e01dca41002 153 #define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4)
donatien 0:8e01dca41002 154
donatien 0:8e01dca41002 155 #define DHCP_CLIENT_PORT 68
donatien 0:8e01dca41002 156 #define DHCP_SERVER_PORT 67
donatien 0:8e01dca41002 157
donatien 0:8e01dca41002 158 /** DHCP client states */
donatien 0:8e01dca41002 159 #define DHCP_OFF 0
donatien 0:8e01dca41002 160 #define DHCP_REQUESTING 1
donatien 0:8e01dca41002 161 #define DHCP_INIT 2
donatien 0:8e01dca41002 162 #define DHCP_REBOOTING 3
donatien 0:8e01dca41002 163 #define DHCP_REBINDING 4
donatien 0:8e01dca41002 164 #define DHCP_RENEWING 5
donatien 0:8e01dca41002 165 #define DHCP_SELECTING 6
donatien 0:8e01dca41002 166 #define DHCP_INFORMING 7
donatien 0:8e01dca41002 167 #define DHCP_CHECKING 8
donatien 0:8e01dca41002 168 #define DHCP_PERMANENT 9
donatien 0:8e01dca41002 169 #define DHCP_BOUND 10
donatien 0:8e01dca41002 170 /** not yet implemented #define DHCP_RELEASING 11 */
donatien 0:8e01dca41002 171 #define DHCP_BACKING_OFF 12
donatien 0:8e01dca41002 172
donatien 0:8e01dca41002 173 /** AUTOIP cooperatation flags */
donatien 0:8e01dca41002 174 #define DHCP_AUTOIP_COOP_STATE_OFF 0
donatien 0:8e01dca41002 175 #define DHCP_AUTOIP_COOP_STATE_ON 1
donatien 0:8e01dca41002 176
donatien 0:8e01dca41002 177 #define DHCP_BOOTREQUEST 1
donatien 0:8e01dca41002 178 #define DHCP_BOOTREPLY 2
donatien 0:8e01dca41002 179
donatien 0:8e01dca41002 180 /** DHCP message types */
donatien 0:8e01dca41002 181 #define DHCP_DISCOVER 1
donatien 0:8e01dca41002 182 #define DHCP_OFFER 2
donatien 0:8e01dca41002 183 #define DHCP_REQUEST 3
donatien 0:8e01dca41002 184 #define DHCP_DECLINE 4
donatien 0:8e01dca41002 185 #define DHCP_ACK 5
donatien 0:8e01dca41002 186 #define DHCP_NAK 6
donatien 0:8e01dca41002 187 #define DHCP_RELEASE 7
donatien 0:8e01dca41002 188 #define DHCP_INFORM 8
donatien 0:8e01dca41002 189
donatien 0:8e01dca41002 190 /** DHCP hardware type, currently only ethernet is supported */
donatien 0:8e01dca41002 191 #define DHCP_HTYPE_ETH 1
donatien 0:8e01dca41002 192
donatien 0:8e01dca41002 193 #define DHCP_MAGIC_COOKIE 0x63825363UL
donatien 0:8e01dca41002 194
donatien 0:8e01dca41002 195 /* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */
donatien 0:8e01dca41002 196
donatien 0:8e01dca41002 197 /** BootP options */
donatien 0:8e01dca41002 198 #define DHCP_OPTION_PAD 0
donatien 0:8e01dca41002 199 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
donatien 0:8e01dca41002 200 #define DHCP_OPTION_ROUTER 3
donatien 0:8e01dca41002 201 #define DHCP_OPTION_DNS_SERVER 6
donatien 0:8e01dca41002 202 #define DHCP_OPTION_HOSTNAME 12
donatien 0:8e01dca41002 203 #define DHCP_OPTION_IP_TTL 23
donatien 0:8e01dca41002 204 #define DHCP_OPTION_MTU 26
donatien 0:8e01dca41002 205 #define DHCP_OPTION_BROADCAST 28
donatien 0:8e01dca41002 206 #define DHCP_OPTION_TCP_TTL 37
donatien 0:8e01dca41002 207 #define DHCP_OPTION_END 255
donatien 0:8e01dca41002 208
donatien 0:8e01dca41002 209 /** DHCP options */
donatien 0:8e01dca41002 210 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
donatien 0:8e01dca41002 211 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
donatien 0:8e01dca41002 212 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
donatien 0:8e01dca41002 213
donatien 0:8e01dca41002 214 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
donatien 0:8e01dca41002 215 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
donatien 0:8e01dca41002 216
donatien 0:8e01dca41002 217 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
donatien 0:8e01dca41002 218 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
donatien 0:8e01dca41002 219
donatien 0:8e01dca41002 220 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
donatien 0:8e01dca41002 221 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
donatien 0:8e01dca41002 222
donatien 0:8e01dca41002 223 #define DHCP_OPTION_T1 58 /* T1 renewal time */
donatien 0:8e01dca41002 224 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
donatien 0:8e01dca41002 225 #define DHCP_OPTION_US 60
donatien 0:8e01dca41002 226 #define DHCP_OPTION_CLIENT_ID 61
donatien 0:8e01dca41002 227 #define DHCP_OPTION_TFTP_SERVERNAME 66
donatien 0:8e01dca41002 228 #define DHCP_OPTION_BOOTFILE 67
donatien 0:8e01dca41002 229
donatien 0:8e01dca41002 230 /** possible combinations of overloading the file and sname fields with options */
donatien 0:8e01dca41002 231 #define DHCP_OVERLOAD_NONE 0
donatien 0:8e01dca41002 232 #define DHCP_OVERLOAD_FILE 1
donatien 0:8e01dca41002 233 #define DHCP_OVERLOAD_SNAME 2
donatien 0:8e01dca41002 234 #define DHCP_OVERLOAD_SNAME_FILE 3
donatien 0:8e01dca41002 235
donatien 0:8e01dca41002 236 #ifdef __cplusplus
donatien 0:8e01dca41002 237 }
donatien 0:8e01dca41002 238 #endif
donatien 0:8e01dca41002 239
donatien 0:8e01dca41002 240 #endif /* LWIP_DHCP */
donatien 0:8e01dca41002 241
donatien 0:8e01dca41002 242 #endif /*__LWIP_DHCP_H__*/