13 |
// period (in milliseconds) of the application calling dhcp_fine_tmr() |
// period (in milliseconds) of the application calling dhcp_fine_tmr() |
14 |
#define DHCP_FINE_TIMER_MSECS 500 |
#define DHCP_FINE_TIMER_MSECS 500 |
15 |
|
|
16 |
struct dhcp_state |
struct dhcp |
17 |
{ |
{ |
18 |
struct dhcp_state *next; // for linked list purposes |
/** current DHCP state machine state */ |
19 |
u8_t state; // current DHCP state (of DHCP state machine) |
u8_t state; |
20 |
u8_t tries; // retries of current request |
/** retries of current request */ |
21 |
u32_t xid; // id of last sent request |
u8_t tries; |
22 |
struct netif *netif; // interface to be configured |
/** transaction identifier of last sent request */ |
23 |
struct udp_pcb *pcb; // our connection |
u32_t xid; |
24 |
|
/** our connection to the DHCP server */ |
25 |
struct pbuf *p; // (first) pbuf of incoming msg |
struct udp_pcb *pcb; |
26 |
struct dhcp_msg *msg_in; // incoming msg |
/** (first) pbuf of incoming msg */ |
27 |
struct dhcp_msg *options_in; // incoming msg options |
struct pbuf *p; |
28 |
u16_t options_in_len; // ingoing msg options length |
/** incoming msg */ |
29 |
|
struct dhcp_msg *msg_in; |
30 |
|
/** incoming msg options */ |
31 |
|
struct dhcp_msg *options_in; |
32 |
|
** ingoing msg options length */ |
33 |
|
u16_t options_in_len; |
34 |
|
|
35 |
struct pbuf *p_out; // pbuf of outcoming msg |
struct pbuf *p_out; // pbuf of outcoming msg |
36 |
struct dhcp_msg *msg_out; // outgoing msg |
struct dhcp_msg *msg_out; // outgoing msg |
53 |
# include "arch/bpstruct.h" |
# include "arch/bpstruct.h" |
54 |
#endif |
#endif |
55 |
PACK_STRUCT_BEGIN |
PACK_STRUCT_BEGIN |
56 |
// minimum set of fields of any DHCP message |
/** minimum set of fields of any DHCP message */ |
57 |
struct dhcp_msg |
struct dhcp_msg |
58 |
{ |
{ |
59 |
PACK_STRUCT_FIELD(u8_t op); |
PACK_STRUCT_FIELD(u8_t op); |
75 |
PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]); |
PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]); |
76 |
PACK_STRUCT_FIELD(u32_t cookie); |
PACK_STRUCT_FIELD(u32_t cookie); |
77 |
#define DHCP_MIN_OPTIONS_LEN 68U |
#define DHCP_MIN_OPTIONS_LEN 68U |
78 |
// allow this to be configured in lwipopts.h, but not too small |
/** allow this to be configured in lwipopts.h, but not too small */ |
79 |
#if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) |
#if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) |
80 |
// set this to be sufficient for your options in outgoing DHCP msgs |
/** set this to be sufficient for your options in outgoing DHCP msgs */ |
81 |
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN |
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN |
82 |
#endif |
#endif |
83 |
PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]); |
PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]); |
87 |
# include "arch/epstruct.h" |
# include "arch/epstruct.h" |
88 |
#endif |
#endif |
89 |
|
|
90 |
// initialize DHCP client |
/** initialize DHCP client */ |
91 |
void dhcp_init(void); |
void dhcp_init(void); |
92 |
// start DHCP configuration |
/** start DHCP configuration */ |
93 |
struct dhcp_state *dhcp_start(struct netif *netif); |
struct dhcp_state *dhcp_start(struct netif *netif); |
94 |
// stop DHCP configuration |
/** stop DHCP configuration */ |
95 |
void dhcp_stop(struct dhcp_state *state); |
void dhcp_stop(struct netif *netif); |
96 |
// enforce lease renewal |
/** enforce lease renewal */ |
97 |
err_t dhcp_renew(struct dhcp_state *state); |
err_t dhcp_renew(struct netif *netif); |
98 |
// inform server of our IP address |
/** inform server of our IP address */ |
99 |
void dhcp_inform(struct netif *netif); |
void dhcp_inform(struct netif *netif); |
100 |
|
|
101 |
// if enabled, check whether the offered IP address is not in use, using ARP |
/** if enabled, check whether the offered IP address is not in use, using ARP */ |
102 |
#if DHCP_DOES_ARP_CHECK |
#if DHCP_DOES_ARP_CHECK |
103 |
void dhcp_arp_reply(struct ip_addr *addr); |
void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr); |
104 |
#endif |
#endif |
105 |
|
|
106 |
// to be called every minute |
/** to be called every minute */ |
107 |
void dhcp_coarse_tmr(void); |
void dhcp_coarse_tmr(void); |
108 |
// to be called every half second |
/** to be called every half second */ |
109 |
void dhcp_fine_tmr(void); |
void dhcp_fine_tmr(void); |
110 |
|
|
111 |
// DHCP message item offsets and length |
/** DHCP message item offsets and length */ |
112 |
#define DHCP_MSG_OFS (UDP_DATA_OFS) |
#define DHCP_MSG_OFS (UDP_DATA_OFS) |
113 |
#define DHCP_OP_OFS (DHCP_MSG_OFS + 0) |
#define DHCP_OP_OFS (DHCP_MSG_OFS + 0) |
114 |
#define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1) |
#define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1) |
132 |
#define DHCP_CLIENT_PORT 68 |
#define DHCP_CLIENT_PORT 68 |
133 |
#define DHCP_SERVER_PORT 67 |
#define DHCP_SERVER_PORT 67 |
134 |
|
|
135 |
// DHCP client states |
/** DHCP client states */ |
136 |
#define DHCP_REQUESTING 1 |
#define DHCP_REQUESTING 1 |
137 |
#define DHCP_INIT 2 |
#define DHCP_INIT 2 |
138 |
#define DHCP_REBOOTING 3 |
#define DHCP_REBOOTING 3 |
165 |
#define DHCP_BROADCAST_FLAG 15 |
#define DHCP_BROADCAST_FLAG 15 |
166 |
#define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST) |
#define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST) |
167 |
|
|
168 |
// BootP options |
/** BootP options */ |
169 |
#define DHCP_OPTION_PAD 0 |
#define DHCP_OPTION_PAD 0 |
170 |
#define DHCP_OPTION_SUBNET_MASK 1 // RFC 2132 3.3 |
#define DHCP_OPTION_SUBNET_MASK 1 // RFC 2132 3.3 |
171 |
#define DHCP_OPTION_ROUTER 3 |
#define DHCP_OPTION_ROUTER 3 |
176 |
#define DHCP_OPTION_TCP_TTL 37 |
#define DHCP_OPTION_TCP_TTL 37 |
177 |
#define DHCP_OPTION_END 255 |
#define DHCP_OPTION_END 255 |
178 |
|
|
179 |
// DHCP options |
/** DHCP options */ |
180 |
#define DHCP_OPTION_REQUESTED_IP 50 // RFC 2132 9.1, requested IP address |
#define DHCP_OPTION_REQUESTED_IP 50 // RFC 2132 9.1, requested IP address |
181 |
#define DHCP_OPTION_LEASE_TIME 51 // RFC 2132 9.2, time in seconds, in 4 bytes |
#define DHCP_OPTION_LEASE_TIME 51 // RFC 2132 9.2, time in seconds, in 4 bytes |
182 |
#define DHCP_OPTION_OVERLOAD 52 // RFC2132 9.3, use file and/or sname field for options |
#define DHCP_OPTION_OVERLOAD 52 // RFC2132 9.3, use file and/or sname field for options |
197 |
#define DHCP_OPTION_TFTP_SERVERNAME 66 |
#define DHCP_OPTION_TFTP_SERVERNAME 66 |
198 |
#define DHCP_OPTION_BOOTFILE 67 |
#define DHCP_OPTION_BOOTFILE 67 |
199 |
|
|
200 |
// possible combinations of overloading the file and sname fields with options |
/** possible combinations of overloading the file and sname fields with options */ |
201 |
#define DHCP_OVERLOAD_NONE 0 |
#define DHCP_OVERLOAD_NONE 0 |
202 |
#define DHCP_OVERLOAD_FILE 1 |
#define DHCP_OVERLOAD_FILE 1 |
203 |
#define DHCP_OVERLOAD_SNAME 2 |
#define DHCP_OVERLOAD_SNAME 2 |