dev

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
mbed_official
Date:
Fri Jun 22 09:25:39 2012 +0000
Revision:
0:51ac1d130fd4
Initial import from lwip-1.4.0: http://download.savannah.gnu.org/releases/lwip/lwip-1.4.0.zip

Who changed what in which revision?

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