Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef __LWIP_DHCP_H__
00006 #define __LWIP_DHCP_H__
00007
00008 #include "lwip/opt.h"
00009
00010 #if LWIP_DHCP
00011
00012 #include "lwip/netif.h"
00013 #include "lwip/udp.h"
00014
00015 #ifdef __cplusplus
00016 extern "C" {
00017 #endif
00018
00019
00020 #define DHCP_COARSE_TIMER_SECS 60
00021
00022 #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
00023
00024 #define DHCP_FINE_TIMER_MSECS 500
00025
00026 struct dhcp
00027 {
00028
00029 u32_t xid;
00030
00031 struct udp_pcb *pcb;
00032
00033 struct dhcp_msg *msg_in;
00034
00035 void *options_in;
00036
00037 u16_t options_in_len;
00038
00039 u8_t state;
00040
00041 u8_t tries;
00042
00043 struct pbuf *p_out;
00044 struct dhcp_msg *msg_out;
00045 u16_t options_out_len;
00046 u16_t request_timeout;
00047 u16_t t1_timeout;
00048 u16_t t2_timeout;
00049 struct ip_addr server_ip_addr;
00050 struct ip_addr offered_ip_addr;
00051 struct ip_addr offered_sn_mask;
00052 struct ip_addr offered_gw_addr;
00053 struct ip_addr offered_bc_addr;
00054 #define DHCP_MAX_DNS 2
00055 u32_t dns_count;
00056 struct ip_addr offered_dns_addr[DHCP_MAX_DNS];
00057
00058 u32_t offered_t0_lease;
00059 u32_t offered_t1_renew;
00060 u32_t offered_t2_rebind;
00061 #if LWIP_DHCP_AUTOIP_COOP
00062 u8_t autoip_coop_state;
00063 #endif
00064
00065
00066
00067 #if 0
00068 struct ip_addr offered_si_addr;
00069 u8_t *boot_file_name;
00070 #endif
00071 };
00072
00073
00074 #ifdef PACK_STRUCT_USE_INCLUDES
00075 # include "arch/bpstruct.h"
00076 #endif
00077 PACK_STRUCT_BEGIN
00078
00079 struct dhcp_msg
00080 {
00081 PACK_STRUCT_FIELD(u8_t op);
00082 PACK_STRUCT_FIELD(u8_t htype);
00083 PACK_STRUCT_FIELD(u8_t hlen);
00084 PACK_STRUCT_FIELD(u8_t hops);
00085 PACK_STRUCT_FIELD(u32_t xid);
00086 PACK_STRUCT_FIELD(u16_t secs);
00087 PACK_STRUCT_FIELD(u16_t flags);
00088 PACK_STRUCT_FIELD(struct ip_addr ciaddr);
00089 PACK_STRUCT_FIELD(struct ip_addr yiaddr);
00090 PACK_STRUCT_FIELD(struct ip_addr siaddr);
00091 PACK_STRUCT_FIELD(struct ip_addr giaddr);
00092 #define DHCP_CHADDR_LEN 16U
00093 PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
00094 #define DHCP_SNAME_LEN 64U
00095 PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
00096 #define DHCP_FILE_LEN 128U
00097 PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
00098 PACK_STRUCT_FIELD(u32_t cookie);
00099 #define DHCP_MIN_OPTIONS_LEN 68U
00100
00101 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
00102 # undef DHCP_OPTIONS_LEN
00103 #endif
00104
00105 #if (!defined(DHCP_OPTIONS_LEN))
00106
00107 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
00108 #endif
00109 PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
00110 } PACK_STRUCT_STRUCT;
00111 PACK_STRUCT_END
00112 #ifdef PACK_STRUCT_USE_INCLUDES
00113 # include "arch/epstruct.h"
00114 #endif
00115
00116
00117 err_t dhcp_start(struct netif *netif);
00118
00119 err_t dhcp_renew(struct netif *netif);
00120
00121 err_t dhcp_release(struct netif *netif);
00122
00123 void dhcp_stop(struct netif *netif);
00124
00125 void dhcp_inform(struct netif *netif);
00126
00127 void dhcp_network_changed(struct netif *netif);
00128
00129
00130 #if DHCP_DOES_ARP_CHECK
00131 void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
00132 #endif
00133
00134
00135 void dhcp_coarse_tmr(void);
00136
00137 void dhcp_fine_tmr(void);
00138
00139
00140 #define DHCP_MSG_OFS (UDP_DATA_OFS)
00141 #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
00142 #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
00143 #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
00144 #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
00145 #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
00146 #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
00147 #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
00148 #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
00149 #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
00150 #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
00151 #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
00152 #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
00153 #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
00154 #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
00155 #define DHCP_MSG_LEN 236
00156
00157 #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
00158 #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
00159
00160 #define DHCP_CLIENT_PORT 68
00161 #define DHCP_SERVER_PORT 67
00162
00163
00164 #define DHCP_REQUESTING 1
00165 #define DHCP_INIT 2
00166 #define DHCP_REBOOTING 3
00167 #define DHCP_REBINDING 4
00168 #define DHCP_RENEWING 5
00169 #define DHCP_SELECTING 6
00170 #define DHCP_INFORMING 7
00171 #define DHCP_CHECKING 8
00172 #define DHCP_PERMANENT 9
00173 #define DHCP_BOUND 10
00174
00175 #define DHCP_BACKING_OFF 12
00176 #define DHCP_OFF 13
00177
00178
00179 #define DHCP_AUTOIP_COOP_STATE_OFF 0
00180 #define DHCP_AUTOIP_COOP_STATE_ON 1
00181
00182 #define DHCP_BOOTREQUEST 1
00183 #define DHCP_BOOTREPLY 2
00184
00185 #define DHCP_DISCOVER 1
00186 #define DHCP_OFFER 2
00187 #define DHCP_REQUEST 3
00188 #define DHCP_DECLINE 4
00189 #define DHCP_ACK 5
00190 #define DHCP_NAK 6
00191 #define DHCP_RELEASE 7
00192 #define DHCP_INFORM 8
00193
00194 #define DHCP_HTYPE_ETH 1
00195
00196 #define DHCP_HLEN_ETH 6
00197
00198 #define DHCP_BROADCAST_FLAG 15
00199 #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
00200
00201
00202 #define DHCP_OPTION_PAD 0
00203 #define DHCP_OPTION_SUBNET_MASK 1
00204 #define DHCP_OPTION_ROUTER 3
00205 #define DHCP_OPTION_DNS_SERVER 6
00206 #define DHCP_OPTION_HOSTNAME 12
00207 #define DHCP_OPTION_IP_TTL 23
00208 #define DHCP_OPTION_MTU 26
00209 #define DHCP_OPTION_BROADCAST 28
00210 #define DHCP_OPTION_TCP_TTL 37
00211 #define DHCP_OPTION_END 255
00212
00213
00214 #define DHCP_OPTION_REQUESTED_IP 50
00215 #define DHCP_OPTION_LEASE_TIME 51
00216 #define DHCP_OPTION_OVERLOAD 52
00217
00218 #define DHCP_OPTION_MESSAGE_TYPE 53
00219 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
00220
00221
00222 #define DHCP_OPTION_SERVER_ID 54
00223 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55
00224
00225 #define DHCP_OPTION_MAX_MSG_SIZE 57
00226 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
00227
00228 #define DHCP_OPTION_T1 58
00229 #define DHCP_OPTION_T2 59
00230 #define DHCP_OPTION_US 60
00231 #define DHCP_OPTION_CLIENT_ID 61
00232 #define DHCP_OPTION_TFTP_SERVERNAME 66
00233 #define DHCP_OPTION_BOOTFILE 67
00234
00235
00236 #define DHCP_OVERLOAD_NONE 0
00237 #define DHCP_OVERLOAD_FILE 1
00238 #define DHCP_OVERLOAD_SNAME 2
00239 #define DHCP_OVERLOAD_SNAME_FILE 3
00240
00241 #ifdef __cplusplus
00242 }
00243 #endif
00244
00245 #endif
00246
00247 #endif