TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

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