OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [ethernet/] [lwIP_130/] [src/] [include/] [lwip/] [dhcp.h] - Blame information for rev 606

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.