My fork of the HTTPServer (working)
Embed:
(wiki syntax)
Show/hide line numbers
dhcp.h
Go to the documentation of this file.
00001 /** @file 00002 */ 00003 00004 #ifndef __LWIP_DHCP_H__ 00005 #define __LWIP_DHCP_H__ 00006 00007 #include "lwip/opt.h" 00008 00009 #if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */ 00010 00011 #include "lwip/netif.h" 00012 #include "lwip/udp.h" 00013 00014 #ifdef __cplusplus 00015 extern "C" { 00016 #endif 00017 00018 /** period (in seconds) of the application calling dhcp_coarse_tmr() */ 00019 #define DHCP_COARSE_TIMER_SECS 60 00020 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */ 00021 #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL) 00022 /** period (in milliseconds) of the application calling dhcp_fine_tmr() */ 00023 #define DHCP_FINE_TIMER_MSECS 500 00024 00025 struct dhcp 00026 { 00027 /** current DHCP state machine state */ 00028 u8_t state; 00029 /** retries of current request */ 00030 u8_t tries; 00031 /** transaction identifier of last sent request */ 00032 u32_t xid; 00033 /** our connection to the DHCP server */ 00034 struct udp_pcb *pcb; 00035 /** (first) pbuf of incoming msg */ 00036 struct pbuf *p; 00037 /** incoming msg */ 00038 struct dhcp_msg *msg_in; 00039 /** incoming msg options */ 00040 struct dhcp_msg *options_in; 00041 /** ingoing msg options length */ 00042 u16_t options_in_len; 00043 00044 struct pbuf *p_out; /* pbuf of outcoming msg */ 00045 struct dhcp_msg *msg_out; /* outgoing msg */ 00046 u16_t options_out_len; /* outgoing msg options length */ 00047 u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */ 00048 u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */ 00049 u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */ 00050 struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */ 00051 struct ip_addr offered_ip_addr; 00052 struct ip_addr offered_sn_mask; 00053 struct ip_addr offered_gw_addr; 00054 struct ip_addr offered_bc_addr; 00055 #define DHCP_MAX_DNS 2 00056 u32_t dns_count; /* actual number of DNS servers obtained */ 00057 struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */ 00058 00059 u32_t offered_t0_lease; /* lease period (in seconds) */ 00060 u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */ 00061 u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */ 00062 #if LWIP_DHCP_AUTOIP_COOP 00063 u8_t autoip_coop_state; 00064 #endif 00065 /** Patch #1308 00066 * TODO: See dhcp.c "TODO"s 00067 */ 00068 #if 0 00069 struct ip_addr offered_si_addr; 00070 u8_t *boot_file_name; 00071 #endif 00072 }; 00073 00074 /* MUST be compiled with "pack structs" or equivalent! */ 00075 #ifdef PACK_STRUCT_USE_INCLUDES 00076 # include "arch/bpstruct.h" 00077 #endif 00078 PACK_STRUCT_BEGIN 00079 /** minimum set of fields of any DHCP message */ 00080 struct dhcp_msg 00081 { 00082 PACK_STRUCT_FIELD(u8_t op); 00083 PACK_STRUCT_FIELD(u8_t htype); 00084 PACK_STRUCT_FIELD(u8_t hlen); 00085 PACK_STRUCT_FIELD(u8_t hops); 00086 PACK_STRUCT_FIELD(u32_t xid); 00087 PACK_STRUCT_FIELD(u16_t secs); 00088 PACK_STRUCT_FIELD(u16_t flags); 00089 PACK_STRUCT_FIELD(struct ip_addr ciaddr); 00090 PACK_STRUCT_FIELD(struct ip_addr yiaddr); 00091 PACK_STRUCT_FIELD(struct ip_addr siaddr); 00092 PACK_STRUCT_FIELD(struct ip_addr giaddr); 00093 #define DHCP_CHADDR_LEN 16U 00094 PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]); 00095 #define DHCP_SNAME_LEN 64U 00096 PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]); 00097 #define DHCP_FILE_LEN 128U 00098 PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]); 00099 PACK_STRUCT_FIELD(u32_t cookie); 00100 #define DHCP_MIN_OPTIONS_LEN 68U 00101 /** make sure user does not configure this too small */ 00102 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) 00103 # undef DHCP_OPTIONS_LEN 00104 #endif 00105 /** allow this to be configured in lwipopts.h, but not too small */ 00106 #if (!defined(DHCP_OPTIONS_LEN)) 00107 /** set this to be sufficient for your options in outgoing DHCP msgs */ 00108 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN 00109 #endif 00110 PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]); 00111 } PACK_STRUCT_STRUCT; 00112 PACK_STRUCT_END 00113 #ifdef PACK_STRUCT_USE_INCLUDES 00114 # include "arch/epstruct.h" 00115 #endif 00116 00117 /** start DHCP configuration */ 00118 err_t dhcp_start(struct netif *netif); 00119 /** enforce early lease renewal (not needed normally)*/ 00120 err_t dhcp_renew(struct netif *netif); 00121 /** release the DHCP lease, usually called before dhcp_stop()*/ 00122 err_t dhcp_release(struct netif *netif); 00123 /** stop DHCP configuration */ 00124 void dhcp_stop(struct netif *netif); 00125 /** inform server of our manual IP address */ 00126 void dhcp_inform(struct netif *netif); 00127 00128 /** if enabled, check whether the offered IP address is not in use, using ARP */ 00129 #if DHCP_DOES_ARP_CHECK 00130 void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr); 00131 #endif 00132 00133 /** to be called every minute */ 00134 void dhcp_coarse_tmr(void); 00135 /** to be called every half second */ 00136 void dhcp_fine_tmr(void); 00137 00138 /** DHCP message item offsets and length */ 00139 #define DHCP_MSG_OFS (UDP_DATA_OFS) 00140 #define DHCP_OP_OFS (DHCP_MSG_OFS + 0) 00141 #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1) 00142 #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2) 00143 #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3) 00144 #define DHCP_XID_OFS (DHCP_MSG_OFS + 4) 00145 #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8) 00146 #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10) 00147 #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12) 00148 #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16) 00149 #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20) 00150 #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24) 00151 #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28) 00152 #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44) 00153 #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108) 00154 #define DHCP_MSG_LEN 236 00155 00156 #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN) 00157 #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4) 00158 00159 #define DHCP_CLIENT_PORT 68 00160 #define DHCP_SERVER_PORT 67 00161 00162 /** DHCP client states */ 00163 #define DHCP_REQUESTING 1 00164 #define DHCP_INIT 2 00165 #define DHCP_REBOOTING 3 00166 #define DHCP_REBINDING 4 00167 #define DHCP_RENEWING 5 00168 #define DHCP_SELECTING 6 00169 #define DHCP_INFORMING 7 00170 #define DHCP_CHECKING 8 00171 #define DHCP_PERMANENT 9 00172 #define DHCP_BOUND 10 00173 /** not yet implemented #define DHCP_RELEASING 11 */ 00174 #define DHCP_BACKING_OFF 12 00175 #define DHCP_OFF 13 00176 00177 /** AUTOIP cooperatation flags */ 00178 #define DHCP_AUTOIP_COOP_STATE_OFF 0 00179 #define DHCP_AUTOIP_COOP_STATE_ON 1 00180 00181 #define DHCP_BOOTREQUEST 1 00182 #define DHCP_BOOTREPLY 2 00183 00184 #define DHCP_DISCOVER 1 00185 #define DHCP_OFFER 2 00186 #define DHCP_REQUEST 3 00187 #define DHCP_DECLINE 4 00188 #define DHCP_ACK 5 00189 #define DHCP_NAK 6 00190 #define DHCP_RELEASE 7 00191 #define DHCP_INFORM 8 00192 00193 #define DHCP_HTYPE_ETH 1 00194 00195 #define DHCP_HLEN_ETH 6 00196 00197 #define DHCP_BROADCAST_FLAG 15 00198 #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST) 00199 00200 /** BootP options */ 00201 #define DHCP_OPTION_PAD 0 00202 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ 00203 #define DHCP_OPTION_ROUTER 3 00204 #define DHCP_OPTION_DNS_SERVER 6 00205 #define DHCP_OPTION_HOSTNAME 12 00206 #define DHCP_OPTION_IP_TTL 23 00207 #define DHCP_OPTION_MTU 26 00208 #define DHCP_OPTION_BROADCAST 28 00209 #define DHCP_OPTION_TCP_TTL 37 00210 #define DHCP_OPTION_END 255 00211 00212 /** DHCP options */ 00213 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */ 00214 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */ 00215 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */ 00216 00217 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */ 00218 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1 00219 00220 00221 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */ 00222 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */ 00223 00224 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */ 00225 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2 00226 00227 #define DHCP_OPTION_T1 58 /* T1 renewal time */ 00228 #define DHCP_OPTION_T2 59 /* T2 rebinding time */ 00229 #define DHCP_OPTION_US 60 00230 #define DHCP_OPTION_CLIENT_ID 61 00231 #define DHCP_OPTION_TFTP_SERVERNAME 66 00232 #define DHCP_OPTION_BOOTFILE 67 00233 00234 /** possible combinations of overloading the file and sname fields with options */ 00235 #define DHCP_OVERLOAD_NONE 0 00236 #define DHCP_OVERLOAD_FILE 1 00237 #define DHCP_OVERLOAD_SNAME 2 00238 #define DHCP_OVERLOAD_SNAME_FILE 3 00239 00240 #ifdef __cplusplus 00241 } 00242 #endif 00243 00244 #endif /* LWIP_DHCP */ 00245 00246 #endif /*__LWIP_DHCP_H__*/
Generated on Tue Jul 12 2022 19:24:05 by 1.7.2