SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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