Xbee test 2

Dependencies:   XBee mbed

Committer:
takashiyamanoue
Date:
Sat Jul 21 04:08:27 2012 +0000
Revision:
0:ffac63d6a7f0
xbee test 2

Who changed what in which revision?

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