Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

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