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