4 #ifndef __LWIP_DHCP_H__
\r
5 #define __LWIP_DHCP_H__
\r
7 #include "lwip/opt.h"
\r
9 #if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
\r
11 #include "lwip/netif.h"
\r
12 #include "lwip/udp.h"
\r
18 /** period (in seconds) of the application calling dhcp_coarse_tmr() */
\r
19 #define DHCP_COARSE_TIMER_SECS 60
\r
20 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
\r
21 #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS*1000)
\r
22 /** period (in milliseconds) of the application calling dhcp_fine_tmr() */
\r
23 #define DHCP_FINE_TIMER_MSECS 500
\r
27 /** current DHCP state machine state */
\r
29 /** retries of current request */
\r
31 /** transaction identifier of last sent request */
\r
33 /** our connection to the DHCP server */
\r
34 struct udp_pcb *pcb;
\r
35 /** (first) pbuf of incoming msg */
\r
38 struct dhcp_msg *msg_in;
\r
39 /** incoming msg options */
\r
40 struct dhcp_msg *options_in;
\r
41 /** ingoing msg options length */
\r
42 u16_t options_in_len;
\r
44 struct pbuf *p_out; /* pbuf of outcoming msg */
\r
45 struct dhcp_msg *msg_out; /* outgoing msg */
\r
46 u16_t options_out_len; /* outgoing msg options length */
\r
47 u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
\r
48 u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
\r
49 u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
\r
50 struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
\r
51 struct ip_addr offered_ip_addr;
\r
52 struct ip_addr offered_sn_mask;
\r
53 struct ip_addr offered_gw_addr;
\r
54 struct ip_addr offered_bc_addr;
\r
55 #define DHCP_MAX_DNS 2
\r
56 u32_t dns_count; /* actual number of DNS servers obtained */
\r
57 struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */
\r
59 u32_t offered_t0_lease; /* lease period (in seconds) */
\r
60 u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
\r
61 u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
\r
62 #if LWIP_DHCP_AUTOIP_COOP
\r
63 u8_t autoip_coop_state;
\r
66 * TODO: See dhcp.c "TODO"s
\r
69 struct ip_addr offered_si_addr;
\r
70 u8_t *boot_file_name;
\r
74 /* MUST be compiled with "pack structs" or equivalent! */
\r
75 #ifdef PACK_STRUCT_USE_INCLUDES
\r
76 # include "arch/bpstruct.h"
\r
79 #if (defined(__MWERKS__) || defined(__CWCC__))
\r
80 #pragma options align= packed
\r
82 /** minimum set of fields of any DHCP message */
\r
85 PACK_STRUCT_FIELD(u8_t op);
\r
86 PACK_STRUCT_FIELD(u8_t htype);
\r
87 PACK_STRUCT_FIELD(u8_t hlen);
\r
88 PACK_STRUCT_FIELD(u8_t hops);
\r
89 PACK_STRUCT_FIELD(u32_t xid);
\r
90 PACK_STRUCT_FIELD(u16_t secs);
\r
91 PACK_STRUCT_FIELD(u16_t flags);
\r
92 PACK_STRUCT_FIELD(struct ip_addr ciaddr);
\r
93 PACK_STRUCT_FIELD(struct ip_addr yiaddr);
\r
94 PACK_STRUCT_FIELD(struct ip_addr siaddr);
\r
95 PACK_STRUCT_FIELD(struct ip_addr giaddr);
\r
96 #define DHCP_CHADDR_LEN 16U
\r
97 PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
\r
98 #define DHCP_SNAME_LEN 64U
\r
99 PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
\r
100 #define DHCP_FILE_LEN 128U
\r
101 PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
\r
102 PACK_STRUCT_FIELD(u32_t cookie);
\r
103 #define DHCP_MIN_OPTIONS_LEN 68U
\r
104 /** make sure user does not configure this too small */
\r
105 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
\r
106 # undef DHCP_OPTIONS_LEN
\r
108 /** allow this to be configured in lwipopts.h, but not too small */
\r
109 #if (!defined(DHCP_OPTIONS_LEN))
\r
110 /** set this to be sufficient for your options in outgoing DHCP msgs */
\r
111 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
\r
113 PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
\r
114 } PACK_STRUCT_STRUCT;
\r
116 #ifdef PACK_STRUCT_USE_INCLUDES
\r
117 # include "arch/epstruct.h"
\r
120 /** start DHCP configuration */
\r
121 err_t dhcp_start(struct netif *netif);
\r
122 /** enforce early lease renewal (not needed normally)*/
\r
123 err_t dhcp_renew(struct netif *netif);
\r
124 /** release the DHCP lease, usually called before dhcp_stop()*/
\r
125 err_t dhcp_release(struct netif *netif);
\r
126 /** stop DHCP configuration */
\r
127 void dhcp_stop(struct netif *netif);
\r
128 /** inform server of our manual IP address */
\r
129 void dhcp_inform(struct netif *netif);
\r
131 /** if enabled, check whether the offered IP address is not in use, using ARP */
\r
132 #if DHCP_DOES_ARP_CHECK
\r
133 void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
\r
136 /** to be called every minute */
\r
137 void dhcp_coarse_tmr(void);
\r
138 /** to be called every half second */
\r
139 void dhcp_fine_tmr(void);
\r
141 /** DHCP message item offsets and length */
\r
142 #define DHCP_MSG_OFS (UDP_DATA_OFS)
\r
143 #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
\r
144 #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
\r
145 #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
\r
146 #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
\r
147 #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
\r
148 #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
\r
149 #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
\r
150 #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
\r
151 #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
\r
152 #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
\r
153 #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
\r
154 #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
\r
155 #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
\r
156 #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
\r
157 #define DHCP_MSG_LEN 236
\r
159 #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
\r
160 #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
\r
162 #define DHCP_CLIENT_PORT 68
\r
163 #define DHCP_SERVER_PORT 67
\r
165 /** DHCP client states */
\r
166 #define DHCP_REQUESTING 1
\r
167 #define DHCP_INIT 2
\r
168 #define DHCP_REBOOTING 3
\r
169 #define DHCP_REBINDING 4
\r
170 #define DHCP_RENEWING 5
\r
171 #define DHCP_SELECTING 6
\r
172 #define DHCP_INFORMING 7
\r
173 #define DHCP_CHECKING 8
\r
174 #define DHCP_PERMANENT 9
\r
175 #define DHCP_BOUND 10
\r
176 /** not yet implemented #define DHCP_RELEASING 11 */
\r
177 #define DHCP_BACKING_OFF 12
\r
178 #define DHCP_OFF 13
\r
180 /** AUTOIP cooperatation flags */
\r
181 #define DHCP_AUTOIP_COOP_STATE_OFF 0
\r
182 #define DHCP_AUTOIP_COOP_STATE_ON 1
\r
184 #define DHCP_BOOTREQUEST 1
\r
185 #define DHCP_BOOTREPLY 2
\r
187 #define DHCP_DISCOVER 1
\r
188 #define DHCP_OFFER 2
\r
189 #define DHCP_REQUEST 3
\r
190 #define DHCP_DECLINE 4
\r
193 #define DHCP_RELEASE 7
\r
194 #define DHCP_INFORM 8
\r
196 #define DHCP_HTYPE_ETH 1
\r
198 #define DHCP_HLEN_ETH 6
\r
200 #define DHCP_BROADCAST_FLAG 15
\r
201 #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
\r
203 /** BootP options */
\r
204 #define DHCP_OPTION_PAD 0
\r
205 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
\r
206 #define DHCP_OPTION_ROUTER 3
\r
207 #define DHCP_OPTION_DNS_SERVER 6
\r
208 #define DHCP_OPTION_HOSTNAME 12
\r
209 #define DHCP_OPTION_IP_TTL 23
\r
210 #define DHCP_OPTION_MTU 26
\r
211 #define DHCP_OPTION_BROADCAST 28
\r
212 #define DHCP_OPTION_TCP_TTL 37
\r
213 #define DHCP_OPTION_END 255
\r
215 /** DHCP options */
\r
216 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
\r
217 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
\r
218 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
\r
220 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
\r
221 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
\r
224 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
\r
225 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
\r
227 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
\r
228 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
\r
230 #define DHCP_OPTION_T1 58 /* T1 renewal time */
\r
231 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
\r
232 #define DHCP_OPTION_US 60
\r
233 #define DHCP_OPTION_CLIENT_ID 61
\r
234 #define DHCP_OPTION_TFTP_SERVERNAME 66
\r
235 #define DHCP_OPTION_BOOTFILE 67
\r
237 /** possible combinations of overloading the file and sname fields with options */
\r
238 #define DHCP_OVERLOAD_NONE 0
\r
239 #define DHCP_OVERLOAD_FILE 1
\r
240 #define DHCP_OVERLOAD_SNAME 2
\r
241 #define DHCP_OVERLOAD_SNAME_FILE 3
\r
247 #endif /* LWIP_DHCP */
\r
249 #endif /*__LWIP_DHCP_H__*/
\r