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