The Pedigree Project 0.1
dhcp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
25/*
26 * Copyright (c) 2001-2004 Leon Woestenberg <leon.woestenberg@gmx.net>
27 * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands.
28 * All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without modification,
31 * are permitted provided that the following conditions are met:
32 *
33 * 1. Redistributions of source code must retain the above copyright notice,
34 * this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright notice,
36 * this list of conditions and the following disclaimer in the documentation
37 * and/or other materials provided with the distribution.
38 * 3. The name of the author may not be used to endorse or promote products
39 * derived from this software without specific prior written permission.
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
44 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
49 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
50 * OF SUCH DAMAGE.
51 *
52 * This file is part of the lwIP TCP/IP stack.
53 *
54 * Author: Leon Woestenberg <leon.woestenberg@gmx.net>
55 *
56 */
57#ifndef LWIP_HDR_DHCP_H
58#define LWIP_HDR_DHCP_H
59
60#include "lwip/opt.h"
61
62#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
63
64#include "lwip/netif.h"
65#include "lwip/udp.h"
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
72#define DHCP_COARSE_TIMER_SECS 60
74#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
76#define DHCP_FINE_TIMER_MSECS 500
77
78#define DHCP_BOOT_FILE_LEN 128U
79
80/* AutoIP cooperation flags (struct dhcp.autoip_coop_state) */
81typedef enum {
82 DHCP_AUTOIP_COOP_STATE_OFF = 0,
83 DHCP_AUTOIP_COOP_STATE_ON = 1
84} dhcp_autoip_coop_state_enum_t;
85
86struct dhcp
87{
89 u32_t xid;
91 struct dhcp_msg *msg_in;
93 u8_t pcb_allocated;
95 u8_t state;
97 u8_t tries;
98#if LWIP_DHCP_AUTOIP_COOP
99 u8_t autoip_coop_state;
100#endif
101 u8_t subnet_mask_given;
102
103 struct pbuf *p_out; /* pbuf of outcoming msg */
104 struct dhcp_msg *msg_out; /* outgoing msg */
105 u16_t options_out_len; /* outgoing msg options length */
106 u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
107 u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
108 u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
109 u16_t t1_renew_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next renew try */
110 u16_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */
111 u16_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */
112 u16_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */
113 ip_addr_t server_ip_addr; /* dhcp server address that offered this lease (ip_addr_t because passed to UDP) */
114 ip4_addr_t offered_ip_addr;
115 ip4_addr_t offered_sn_mask;
116 ip4_addr_t offered_gw_addr;
117
118 u32_t offered_t0_lease; /* lease period (in seconds) */
119 u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
120 u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */
121#if LWIP_DHCP_BOOTP_FILE
122 ip4_addr_t offered_si_addr;
123 char boot_file_name[DHCP_BOOT_FILE_LEN];
124#endif /* LWIP_DHCP_BOOTPFILE */
125};
126
127
128void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
130#define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0)
131void dhcp_cleanup(struct netif *netif);
132err_t dhcp_start(struct netif *netif);
133err_t dhcp_renew(struct netif *netif);
134err_t dhcp_release(struct netif *netif);
135void dhcp_stop(struct netif *netif);
136void dhcp_inform(struct netif *netif);
137void dhcp_network_changed(struct netif *netif);
138#if DHCP_DOES_ARP_CHECK
139void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr);
140#endif
141u8_t dhcp_supplied_address(const struct netif *netif);
142/* to be called every minute */
143void dhcp_coarse_tmr(void);
144/* to be called every half second */
145void dhcp_fine_tmr(void);
146
147#if LWIP_DHCP_GET_NTP_SRV
151extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, const ip4_addr_t* ntp_server_addrs);
152#endif /* LWIP_DHCP_GET_NTP_SRV */
153
154#define netif_dhcp_data(netif) ((struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP))
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif /* LWIP_DHCP */
161
162#endif /*LWIP_HDR_DHCP_H*/
s8_t err_t
Definition err.h:76
Definition netif.h:244
Definition pbuf.h:161