Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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