Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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