Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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