The Pedigree Project  0.1
prot/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_PROT_DHCP_H
58 #define LWIP_HDR_PROT_DHCP_H
59 
60 #include "lwip/opt.h"
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #define DHCP_CLIENT_PORT 68
67 #define DHCP_SERVER_PORT 67
68 
69 
70  /* DHCP message item offsets and length */
71 #define DHCP_CHADDR_LEN 16U
72 #define DHCP_SNAME_OFS 44U
73 #define DHCP_SNAME_LEN 64U
74 #define DHCP_FILE_OFS 108U
75 #define DHCP_FILE_LEN 128U
76 #define DHCP_MSG_LEN 236U
77 #define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U) /* 4 byte: cookie */
78 
79 #ifdef PACK_STRUCT_USE_INCLUDES
80 # include "arch/bpstruct.h"
81 #endif
84 struct dhcp_msg
85 {
86  PACK_STRUCT_FLD_8(u8_t op);
87  PACK_STRUCT_FLD_8(u8_t htype);
88  PACK_STRUCT_FLD_8(u8_t hlen);
89  PACK_STRUCT_FLD_8(u8_t hops);
90  PACK_STRUCT_FIELD(u32_t xid);
91  PACK_STRUCT_FIELD(u16_t secs);
92  PACK_STRUCT_FIELD(u16_t flags);
93  PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr);
94  PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr);
95  PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr);
96  PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr);
97  PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]);
98  PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]);
99  PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]);
100  PACK_STRUCT_FIELD(u32_t cookie);
101 #define DHCP_MIN_OPTIONS_LEN 68U
102 
103 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
104 # undef DHCP_OPTIONS_LEN
105 #endif
106 
107 #if (!defined(DHCP_OPTIONS_LEN))
108 
109 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
110 #endif
111  PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]);
112 } PACK_STRUCT_STRUCT;
114 #ifdef PACK_STRUCT_USE_INCLUDES
115 # include "arch/epstruct.h"
116 #endif
117 
118 
119 /* DHCP client states */
120 typedef enum {
121  DHCP_STATE_OFF = 0,
122  DHCP_STATE_REQUESTING = 1,
123  DHCP_STATE_INIT = 2,
124  DHCP_STATE_REBOOTING = 3,
125  DHCP_STATE_REBINDING = 4,
126  DHCP_STATE_RENEWING = 5,
127  DHCP_STATE_SELECTING = 6,
128  DHCP_STATE_INFORMING = 7,
129  DHCP_STATE_CHECKING = 8,
130  DHCP_STATE_PERMANENT = 9, /* not yet implemented */
131  DHCP_STATE_BOUND = 10,
132  DHCP_STATE_RELEASING = 11, /* not yet implemented */
133  DHCP_STATE_BACKING_OFF = 12
134 } dhcp_state_enum_t;
135 
136 /* DHCP op codes */
137 #define DHCP_BOOTREQUEST 1
138 #define DHCP_BOOTREPLY 2
139 
140 /* DHCP message types */
141 #define DHCP_DISCOVER 1
142 #define DHCP_OFFER 2
143 #define DHCP_REQUEST 3
144 #define DHCP_DECLINE 4
145 #define DHCP_ACK 5
146 #define DHCP_NAK 6
147 #define DHCP_RELEASE 7
148 #define DHCP_INFORM 8
149 
151 #define DHCP_HTYPE_ETH 1
152 
153 #define DHCP_MAGIC_COOKIE 0x63825363UL
154 
155 /* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */
156 
157 /* BootP options */
158 #define DHCP_OPTION_PAD 0
159 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
160 #define DHCP_OPTION_ROUTER 3
161 #define DHCP_OPTION_DNS_SERVER 6
162 #define DHCP_OPTION_HOSTNAME 12
163 #define DHCP_OPTION_IP_TTL 23
164 #define DHCP_OPTION_MTU 26
165 #define DHCP_OPTION_BROADCAST 28
166 #define DHCP_OPTION_TCP_TTL 37
167 #define DHCP_OPTION_NTP 42
168 #define DHCP_OPTION_END 255
169 
170 /* DHCP options */
171 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
172 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
173 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
174 
175 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
176 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
177 
178 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
179 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
180 
181 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
182 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
183 
184 #define DHCP_OPTION_T1 58 /* T1 renewal time */
185 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
186 #define DHCP_OPTION_US 60
187 #define DHCP_OPTION_CLIENT_ID 61
188 #define DHCP_OPTION_TFTP_SERVERNAME 66
189 #define DHCP_OPTION_BOOTFILE 67
190 
191 /* possible combinations of overloading the file and sname fields with options */
192 #define DHCP_OVERLOAD_NONE 0
193 #define DHCP_OVERLOAD_FILE 1
194 #define DHCP_OVERLOAD_SNAME 2
195 #define DHCP_OVERLOAD_SNAME_FILE 3
196 
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif /*LWIP_HDR_PROT_DHCP_H*/
#define PACK_STRUCT_BEGIN
Definition: arch.h:261
#define DHCP_OPTIONS_LEN
Definition: prot/dhcp.h:109
#define PACK_STRUCT_END
Definition: arch.h:270