Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/dhcp.h need to be fixed.

0001 /** @file
0002  */
0003 
0004 #ifndef __LWIP_DHCP_H__
0005 #define __LWIP_DHCP_H__
0006 
0007 #include "lwip/opt.h"
0008 
0009 #if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
0010 
0011 #include "lwip/netif.h"
0012 #include "lwip/udp.h"
0013 
0014 #ifdef __cplusplus
0015 extern "C" {
0016 #endif
0017 
0018 /** period (in seconds) of the application calling dhcp_coarse_tmr() */
0019 #define DHCP_COARSE_TIMER_SECS 60 
0020 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
0021 #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
0022 /** period (in milliseconds) of the application calling dhcp_fine_tmr() */
0023 #define DHCP_FINE_TIMER_MSECS 500 
0024 
0025 struct dhcp
0026 {
0027   /** transaction identifier of last sent request */ 
0028   u32_t xid;
0029   /** our connection to the DHCP server */ 
0030   struct udp_pcb *pcb;
0031   /** incoming msg */
0032   struct dhcp_msg *msg_in;
0033   /** incoming msg options */
0034   void *options_in; 
0035   /** ingoing msg options length */
0036   u16_t options_in_len;
0037   /** current DHCP state machine state */
0038   u8_t state;
0039   /** retries of current request */
0040   u8_t tries;
0041 
0042   struct pbuf *p_out; /* pbuf of outcoming msg */
0043   struct dhcp_msg *msg_out; /* outgoing msg */
0044   u16_t options_out_len; /* outgoing msg options length */
0045   u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
0046   u16_t t1_timeout;  /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
0047   u16_t t2_timeout;  /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
0048   struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
0049   struct ip_addr offered_ip_addr;
0050   struct ip_addr offered_sn_mask;
0051   struct ip_addr offered_gw_addr;
0052   struct ip_addr offered_bc_addr;
0053 #define DHCP_MAX_DNS 2
0054   u32_t dns_count; /* actual number of DNS servers obtained */
0055   struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */
0056  
0057   u32_t offered_t0_lease; /* lease period (in seconds) */
0058   u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
0059   u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period)  */
0060 #if LWIP_DHCP_AUTOIP_COOP
0061   u8_t autoip_coop_state;
0062 #endif
0063 /** Patch #1308
0064  *  TODO: See dhcp.c "TODO"s
0065  */
0066 #if 0
0067   struct ip_addr offered_si_addr;
0068   u8_t *boot_file_name;
0069 #endif
0070 };
0071 
0072 /* MUST be compiled with "pack structs" or equivalent! */
0073 #ifdef PACK_STRUCT_USE_INCLUDES
0074 #  include "arch/bpstruct.h"
0075 #endif
0076 PACK_STRUCT_BEGIN
0077 /** minimum set of fields of any DHCP message */
0078 struct dhcp_msg
0079 {
0080   PACK_STRUCT_FIELD(u8_t op);
0081   PACK_STRUCT_FIELD(u8_t htype);
0082   PACK_STRUCT_FIELD(u8_t hlen);
0083   PACK_STRUCT_FIELD(u8_t hops);
0084   PACK_STRUCT_FIELD(u32_t xid);
0085   PACK_STRUCT_FIELD(u16_t secs);
0086   PACK_STRUCT_FIELD(u16_t flags);
0087   PACK_STRUCT_FIELD(struct ip_addr ciaddr);
0088   PACK_STRUCT_FIELD(struct ip_addr yiaddr);
0089   PACK_STRUCT_FIELD(struct ip_addr siaddr);
0090   PACK_STRUCT_FIELD(struct ip_addr giaddr);
0091 #define DHCP_CHADDR_LEN 16U
0092   PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
0093 #define DHCP_SNAME_LEN 64U
0094   PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
0095 #define DHCP_FILE_LEN 128U
0096   PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
0097   PACK_STRUCT_FIELD(u32_t cookie);
0098 #define DHCP_MIN_OPTIONS_LEN 68U
0099 /** make sure user does not configure this too small */
0100 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
0101 #  undef DHCP_OPTIONS_LEN
0102 #endif
0103 /** allow this to be configured in lwipopts.h, but not too small */
0104 #if (!defined(DHCP_OPTIONS_LEN))
0105 /** set this to be sufficient for your options in outgoing DHCP msgs */
0106 #  define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
0107 #endif
0108   PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
0109 } PACK_STRUCT_STRUCT;
0110 PACK_STRUCT_END
0111 #ifdef PACK_STRUCT_USE_INCLUDES
0112 #  include "arch/epstruct.h"
0113 #endif
0114 
0115 /** start DHCP configuration */
0116 err_t dhcp_start(struct netif *netif);
0117 /** enforce early lease renewal (not needed normally)*/
0118 err_t dhcp_renew(struct netif *netif);
0119 /** release the DHCP lease, usually called before dhcp_stop()*/
0120 err_t dhcp_release(struct netif *netif);
0121 /** stop DHCP configuration */
0122 void dhcp_stop(struct netif *netif);
0123 /** inform server of our manual IP address */
0124 void dhcp_inform(struct netif *netif);
0125 /** Handle a possible change in the network configuration */
0126 void dhcp_network_changed(struct netif *netif);
0127 
0128 /** if enabled, check whether the offered IP address is not in use, using ARP */
0129 #if DHCP_DOES_ARP_CHECK
0130 void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
0131 #endif
0132 
0133 /** to be called every minute */
0134 void dhcp_coarse_tmr(void);
0135 /** to be called every half second */
0136 void dhcp_fine_tmr(void);
0137  
0138 /** DHCP message item offsets and length */
0139 #define DHCP_MSG_OFS (UDP_DATA_OFS)  
0140   #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
0141   #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
0142   #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
0143   #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
0144   #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
0145   #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
0146   #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
0147   #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
0148   #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
0149   #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
0150   #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
0151   #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
0152   #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
0153   #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
0154 #define DHCP_MSG_LEN 236
0155 
0156 #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
0157 #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
0158 
0159 #define DHCP_CLIENT_PORT 68  
0160 #define DHCP_SERVER_PORT 67
0161 
0162 /** DHCP client states */
0163 #define DHCP_REQUESTING 1
0164 #define DHCP_INIT 2
0165 #define DHCP_REBOOTING 3
0166 #define DHCP_REBINDING 4
0167 #define DHCP_RENEWING 5
0168 #define DHCP_SELECTING 6
0169 #define DHCP_INFORMING 7
0170 #define DHCP_CHECKING 8
0171 #define DHCP_PERMANENT 9
0172 #define DHCP_BOUND 10
0173 /** not yet implemented #define DHCP_RELEASING 11 */
0174 #define DHCP_BACKING_OFF 12
0175 #define DHCP_OFF 13
0176 
0177 /** AUTOIP cooperatation flags */
0178 #define DHCP_AUTOIP_COOP_STATE_OFF 0
0179 #define DHCP_AUTOIP_COOP_STATE_ON 1
0180  
0181 #define DHCP_BOOTREQUEST 1
0182 #define DHCP_BOOTREPLY 2
0183 
0184 #define DHCP_DISCOVER 1
0185 #define DHCP_OFFER 2
0186 #define DHCP_REQUEST 3
0187 #define DHCP_DECLINE 4
0188 #define DHCP_ACK 5
0189 #define DHCP_NAK 6
0190 #define DHCP_RELEASE 7
0191 #define DHCP_INFORM 8
0192 
0193 #define DHCP_HTYPE_ETH 1
0194 
0195 #define DHCP_HLEN_ETH 6
0196 
0197 #define DHCP_BROADCAST_FLAG 15
0198 #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
0199 
0200 /** BootP options */
0201 #define DHCP_OPTION_PAD 0
0202 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
0203 #define DHCP_OPTION_ROUTER 3
0204 #define DHCP_OPTION_DNS_SERVER 6 
0205 #define DHCP_OPTION_HOSTNAME 12
0206 #define DHCP_OPTION_IP_TTL 23
0207 #define DHCP_OPTION_MTU 26
0208 #define DHCP_OPTION_BROADCAST 28
0209 #define DHCP_OPTION_TCP_TTL 37
0210 #define DHCP_OPTION_END 255
0211 
0212 /** DHCP options */
0213 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
0214 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
0215 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
0216 
0217 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
0218 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
0219 
0220 
0221 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
0222 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
0223 
0224 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
0225 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
0226 
0227 #define DHCP_OPTION_T1 58 /* T1 renewal time */
0228 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
0229 #define DHCP_OPTION_US 60
0230 #define DHCP_OPTION_CLIENT_ID 61
0231 #define DHCP_OPTION_TFTP_SERVERNAME 66
0232 #define DHCP_OPTION_BOOTFILE 67
0233 
0234 /** possible combinations of overloading the file and sname fields with options */
0235 #define DHCP_OVERLOAD_NONE 0
0236 #define DHCP_OVERLOAD_FILE 1
0237 #define DHCP_OVERLOAD_SNAME  2
0238 #define DHCP_OVERLOAD_SNAME_FILE 3
0239 
0240 #ifdef __cplusplus
0241 }
0242 #endif
0243 
0244 #endif /* LWIP_DHCP */
0245 
0246 #endif /*__LWIP_DHCP_H__*/