RetroArch
dhcp.h
Go to the documentation of this file.
1 
4 #ifndef __LWIP_DHCP_H__
5 #define __LWIP_DHCP_H__
6 
7 #include "lwip/opt.h"
8 #include "lwip/netif.h"
9 #include "lwip/udp.h"
10 
12 #define DHCP_COARSE_TIMER_SECS 60
13 
14 #define DHCP_FINE_TIMER_MSECS 500
15 
16 struct dhcp
17 {
25  struct udp_pcb *pcb;
27  struct pbuf *p;
29  struct dhcp_msg *msg_in;
34 
35  struct pbuf *p_out; /* pbuf of outcoming msg */
36  struct dhcp_msg *msg_out; /* outgoing msg */
37  u16_t options_out_len; /* outgoing msg options length */
38  u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
39  u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
40  u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
41  struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
46 #define DHCP_MAX_DNS 2
47  u32_t dns_count; /* actual number of DNS servers obtained */
48  struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */
49 
50  u32_t offered_t0_lease; /* lease period (in seconds) */
51  u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
52  u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
56 #if 0
57  struct ip_addr offered_si_addr;
58  u8_t *boot_file_name;
59 #endif
60 };
61 
62 /* MUST be compiled with "pack structs" or equivalent! */
63 #ifdef PACK_STRUCT_USE_INCLUDES
64 # include "arch/bpstruct.h"
65 #endif
68 struct dhcp_msg
69 {
71  PACK_STRUCT_FIELD(u8_t htype);
72  PACK_STRUCT_FIELD(u8_t hlen);
73  PACK_STRUCT_FIELD(u8_t hops);
77  PACK_STRUCT_FIELD(struct ip_addr ciaddr);
78  PACK_STRUCT_FIELD(struct ip_addr yiaddr);
79  PACK_STRUCT_FIELD(struct ip_addr siaddr);
80  PACK_STRUCT_FIELD(struct ip_addr giaddr);
81 #define DHCP_CHADDR_LEN 16U
83 #define DHCP_SNAME_LEN 64U
85 #define DHCP_FILE_LEN 128U
87  PACK_STRUCT_FIELD(u32_t cookie);
88 #define DHCP_MIN_OPTIONS_LEN 68U
89 
90 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
91 # undef DHCP_OPTIONS_LEN
92 #endif
93 
94 #if (!defined(DHCP_OPTIONS_LEN))
95 
96 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
97 #endif
101 #ifdef PACK_STRUCT_USE_INCLUDES
102 # include "arch/epstruct.h"
103 #endif
104 
106 err_t dhcp_start(struct netif *netif);
108 err_t dhcp_renew(struct netif *netif);
110 err_t dhcp_release(struct netif *netif);
112 void dhcp_stop(struct netif *netif);
114 void dhcp_inform(struct netif *netif);
115 
117 #if DHCP_DOES_ARP_CHECK
118 void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
119 #endif
120 
122 void dhcp_coarse_tmr(void);
124 void dhcp_fine_tmr(void);
125 
127 #define DHCP_MSG_OFS (UDP_DATA_OFS)
128  #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
129  #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
130  #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
131  #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
132  #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
133  #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
134  #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
135  #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
136  #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
137  #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
138  #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
139  #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
140  #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
141  #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
142 #define DHCP_MSG_LEN 236
143 
144 #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
145 #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
146 
147 #define DHCP_CLIENT_PORT 68
148 #define DHCP_SERVER_PORT 67
149 
151 #define DHCP_REQUESTING 1
152 #define DHCP_INIT 2
153 #define DHCP_REBOOTING 3
154 #define DHCP_REBINDING 4
155 #define DHCP_RENEWING 5
156 #define DHCP_SELECTING 6
157 #define DHCP_INFORMING 7
158 #define DHCP_CHECKING 8
159 #define DHCP_PERMANENT 9
160 #define DHCP_BOUND 10
161 
162 #define DHCP_BACKING_OFF 12
163 #define DHCP_OFF 13
164 
165 #define DHCP_BOOTREQUEST 1
166 #define DHCP_BOOTREPLY 2
167 
168 #define DHCP_DISCOVER 1
169 #define DHCP_OFFER 2
170 #define DHCP_REQUEST 3
171 #define DHCP_DECLINE 4
172 #define DHCP_ACK 5
173 #define DHCP_NAK 6
174 #define DHCP_RELEASE 7
175 #define DHCP_INFORM 8
176 
177 #define DHCP_HTYPE_ETH 1
178 
179 #define DHCP_HLEN_ETH 6
180 
181 #define DHCP_BROADCAST_FLAG 15
182 #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
183 
185 #define DHCP_OPTION_PAD 0
186 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
187 #define DHCP_OPTION_ROUTER 3
188 #define DHCP_OPTION_DNS_SERVER 6
189 #define DHCP_OPTION_HOSTNAME 12
190 #define DHCP_OPTION_IP_TTL 23
191 #define DHCP_OPTION_MTU 26
192 #define DHCP_OPTION_BROADCAST 28
193 #define DHCP_OPTION_TCP_TTL 37
194 #define DHCP_OPTION_END 255
195 
197 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
198 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
199 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
200 
201 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
202 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
203 
204 
205 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
206 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
207 
208 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
209 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
210 
211 #define DHCP_OPTION_T1 58 /* T1 renewal time */
212 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
213 #define DHCP_OPTION_CLIENT_ID 61
214 #define DHCP_OPTION_TFTP_SERVERNAME 66
215 #define DHCP_OPTION_BOOTFILE 67
216 
218 #define DHCP_OVERLOAD_NONE 0
219 #define DHCP_OVERLOAD_FILE 1
220 #define DHCP_OVERLOAD_SNAME 2
221 #define DHCP_OVERLOAD_SNAME_FILE 3
222 
223 #endif /*__LWIP_DHCP_H__*/
s8_t err_t
Definition: err.h:39
set set set set set set set macro pixldst1 op
Definition: pixman-arm-neon-asm.h:54
Definition: ip_addr.h:41
u8_t tries
Definition: dhcp.h:21
struct pbuf * p
Definition: dhcp.h:27
#define PACK_STRUCT_BEGIN
Definition: arch.h:46
Definition: dhcp.h:16
Definition: udp.h:54
#define DHCP_SNAME_LEN
Definition: dhcp.h:83
u32_t xid
Definition: dhcp.h:23
#define DHCP_CHADDR_LEN
Definition: dhcp.h:81
Definition: netif.h:72
PACK_STRUCT_BEGIN struct dhcp_msg PACK_STRUCT_STRUCT
u16_t request_timeout
Definition: dhcp.h:38
struct dhcp_msg * msg_in
Definition: dhcp.h:29
struct ip_addr server_ip_addr
Definition: dhcp.h:41
struct ip_addr offered_gw_addr
Definition: dhcp.h:44
Definition: dhcp.h:68
struct ip_addr offered_sn_mask
Definition: dhcp.h:43
GLenum const GLvoid * addr
Definition: glext.h:10528
err_t dhcp_renew(struct netif *netif)
struct pbuf * p_out
Definition: dhcp.h:35
err_t dhcp_release(struct netif *netif)
u32_t dns_count
Definition: dhcp.h:47
u32_t offered_t0_lease
Definition: dhcp.h:50
struct ip_addr offered_bc_addr
Definition: dhcp.h:45
void dhcp_coarse_tmr(void)
#define PACK_STRUCT_END
Definition: arch.h:50
u8 u8_t
Definition: cc.h:43
struct ip_addr offered_dns_addr[DHCP_MAX_DNS]
Definition: dhcp.h:48
struct dhcp_msg * options_in
Definition: dhcp.h:31
PACK_STRUCT_FIELD(u8_t op)
void dhcp_fine_tmr(void)
u16_t t1_timeout
Definition: dhcp.h:39
void dhcp_inform(struct netif *netif)
#define DHCP_FILE_LEN
Definition: dhcp.h:85
u32_t offered_t2_rebind
Definition: dhcp.h:52
#define DHCP_OPTIONS_LEN
Definition: dhcp.h:96
struct dhcp_msg * msg_out
Definition: dhcp.h:36
u32_t offered_t1_renew
Definition: dhcp.h:51
u32 u32_t
Definition: cc.h:47
u16_t options_out_len
Definition: dhcp.h:37
struct ip_addr offered_ip_addr
Definition: dhcp.h:42
PACK_STRUCT_END err_t dhcp_start(struct netif *netif)
u16_t t2_timeout
Definition: dhcp.h:40
void dhcp_stop(struct netif *netif)
Definition: civetweb.c:1024
GLbitfield flags
Definition: glext.h:7828
struct udp_pcb * pcb
Definition: dhcp.h:25
u8_t state
Definition: dhcp.h:19
bf_uint8_t options
Definition: connect_ps4.c:78
u16_t options_in_len
Definition: dhcp.h:33
u16 u16_t
Definition: cc.h:45
Definition: pbuf.h:66
#define DHCP_MAX_DNS
Definition: dhcp.h:46