code that uses Watchdog to reset Mbed every 30seconds. After 30-60mins, the ethernet interface fails to setup() after WatchDog reset.

Dependencies:   mbed

Committer:
eqon
Date:
Thu Jun 07 05:44:29 2012 +0000
Revision:
0:0ce833f21e63

        

Who changed what in which revision?

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