Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

dhcp.h

Go to the documentation of this file.
00001 
00004 #ifndef __LWIP_DHCP_H__
00005 #define __LWIP_DHCP_H__
00006 
00007 #include "lwip/opt.h"
00008 #include "lwip/netif.h"
00009 #include "lwip/udp.h"
00010 
00012 #define DHCP_COARSE_TIMER_SECS 60 
00013 
00014 #define DHCP_FINE_TIMER_MSECS 500 
00015 
00016 struct dhcp
00017 {
00019   u8_t state;
00021   u8_t tries;
00023   u32_t xid;
00025   struct udp_pcb *pcb;
00027   struct pbuf *p;
00029   struct dhcp_msg *msg_in;
00031   struct dhcp_msg *options_in; 
00033   u16_t options_in_len;
00034 
00035   struct pbuf *p_out; /* pbuf of outcoming msg */
00036   struct dhcp_msg *msg_out; /* outgoing msg */
00037   u16_t options_out_len; /* outgoing msg options length */
00038   u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
00039   u16_t t1_timeout;     /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
00040   u16_t t2_timeout;     /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
00041   struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
00042   struct ip_addr offered_ip_addr;
00043   struct ip_addr offered_sn_mask;
00044   struct ip_addr offered_gw_addr;
00045   struct ip_addr offered_bc_addr;
00046   u32_t offered_t0_lease; /* lease period (in seconds) */
00047   u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
00048   u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period)     */
00049 };
00050 
00051 /* MUST be compiled with "pack structs" or equivalent! */
00052 #ifdef PACK_STRUCT_USE_INCLUDES
00053 #  include "arch/bpstruct.h"
00054 #endif
00055 PACK_STRUCT_BEGIN
00057 struct dhcp_msg
00058 {
00059   PACK_STRUCT_FIELD(u8_t op);
00060   PACK_STRUCT_FIELD(u8_t htype);
00061   PACK_STRUCT_FIELD(u8_t hlen);
00062   PACK_STRUCT_FIELD(u8_t hops);
00063   PACK_STRUCT_FIELD(u32_t xid);
00064   PACK_STRUCT_FIELD(u16_t secs);
00065   PACK_STRUCT_FIELD(u16_t flags);
00066   PACK_STRUCT_FIELD(u32_t ciaddr);
00067   PACK_STRUCT_FIELD(u32_t yiaddr);
00068   PACK_STRUCT_FIELD(u32_t siaddr);
00069   PACK_STRUCT_FIELD(u32_t giaddr);
00070 #define DHCP_CHADDR_LEN 16U
00071   PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
00072 #define DHCP_SNAME_LEN 64U
00073   PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
00074 #define DHCP_FILE_LEN 128U
00075   PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
00076   PACK_STRUCT_FIELD(u32_t cookie);
00077 #define DHCP_MIN_OPTIONS_LEN 68U
00078 
00079 #if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
00080 
00081 #  define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
00082 #endif
00083   PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
00084 } PACK_STRUCT_STRUCT;
00085 PACK_STRUCT_END
00086 #ifdef PACK_STRUCT_USE_INCLUDES
00087 #  include "arch/epstruct.h"
00088 #endif
00089 
00091 err_t dhcp_start(struct netif *netif);
00093 void dhcp_stop(struct netif *netif);
00095 err_t dhcp_renew(struct netif *netif);
00097 void dhcp_inform(struct netif *netif);
00098 
00100 #if DHCP_DOES_ARP_CHECK
00101 void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
00102 #endif
00103 
00105 void dhcp_coarse_tmr(void);
00107 void dhcp_fine_tmr(void);
00108  
00110 #define DHCP_MSG_OFS (UDP_DATA_OFS)  
00111   #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
00112   #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
00113   #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
00114   #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
00115   #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
00116   #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
00117   #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
00118   #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
00119   #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
00120   #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
00121   #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
00122   #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
00123   #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
00124   #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
00125 #define DHCP_MSG_LEN 236
00126 
00127 #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
00128 #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
00129 
00130 #define DHCP_CLIENT_PORT 68     
00131 #define DHCP_SERVER_PORT 67
00132 
00134 #define DHCP_REQUESTING 1
00135 #define DHCP_INIT 2
00136 #define DHCP_REBOOTING 3
00137 #define DHCP_REBINDING 4
00138 #define DHCP_RENEWING 5
00139 #define DHCP_SELECTING 6
00140 #define DHCP_INFORMING 7
00141 #define DHCP_CHECKING 8
00142 #define DHCP_PERMANENT 9
00143 #define DHCP_BOUND 10
00144 
00145 #define DHCP_BACKING_OFF 12
00146 #define DHCP_OFF 13
00147  
00148 #define DHCP_BOOTREQUEST 1
00149 #define DHCP_BOOTREPLY 2
00150 
00151 #define DHCP_DISCOVER 1
00152 #define DHCP_OFFER 2
00153 #define DHCP_REQUEST 3
00154 #define DHCP_DECLINE 4
00155 #define DHCP_ACK 5
00156 #define DHCP_NAK 6
00157 #define DHCP_RELEASE 7
00158 #define DHCP_INFORM 8
00159 
00160 #define DHCP_HTYPE_ETH 1
00161 
00162 #define DHCP_HLEN_ETH 6
00163 
00164 #define DHCP_BROADCAST_FLAG 15
00165 #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
00166 
00168 #define DHCP_OPTION_PAD 0
00169 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
00170 #define DHCP_OPTION_ROUTER 3 
00171 #define DHCP_OPTION_HOSTNAME 12
00172 #define DHCP_OPTION_IP_TTL 23
00173 #define DHCP_OPTION_MTU 26
00174 #define DHCP_OPTION_BROADCAST 28
00175 #define DHCP_OPTION_TCP_TTL 37
00176 #define DHCP_OPTION_END 255
00177 
00179 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
00180 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
00181 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
00182 
00183 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
00184 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
00185 
00186 
00187 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2131 9.7, server IP address */
00188 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2131 9.8, requested option types */
00189 
00190 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2131 9.10, message size accepted >= 576 */
00191 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
00192 
00193 #define DHCP_OPTION_T1 58 /* T1 renewal time */
00194 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
00195 #define DHCP_OPTION_CLIENT_ID 61
00196 #define DHCP_OPTION_TFTP_SERVERNAME 66
00197 #define DHCP_OPTION_BOOTFILE 67
00198 
00200 #define DHCP_OVERLOAD_NONE 0
00201 #define DHCP_OVERLOAD_FILE 1
00202 #define DHCP_OVERLOAD_SNAME     2
00203 #define DHCP_OVERLOAD_SNAME_FILE 3
00204 
00205 #endif /*__LWIP_DHCP_H__*/

Generated on Wed Jan 14 12:58:56 2004 for RTL-lwIP-0.4 by doxygen 1.3.4