xref: /freebsd/contrib/wpa/src/common/dhcp.h (revision 29fc4075e69fd27de0cded313ac6000165d99f8b)
1 /*
2  * DHCP definitions
3  * Copyright (c) 2014-2017, Qualcomm Atheros, Inc.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef DHCP_H
10 #define DHCP_H
11 
12 #if defined(__FreeBSD__)
13 /*
14  * Translate Linux to FreeBSD
15  */
16 #define iphdr		ip
17 #define ihl		ip_hl
18 #define verson		ip_v
19 #define tos		ip_tos
20 #define tot_len		ip_len
21 #define id		ip_id
22 #define frag_off	ip_off
23 #define ttl		ip_ttl
24 #define protocol	ip_p
25 #define check		ip_sum
26 #define saddr		ip_src
27 #define daddr		ip_dst
28 #endif
29 
30 #include <netinet/ip.h>
31 #if __FAVOR_BSD
32 #include <netinet/udp.h>
33 #else
34 #define __FAVOR_BSD 1
35 #include <netinet/udp.h>
36 #undef __FAVOR_BSD
37 #endif
38 
39 #define DHCP_SERVER_PORT 67
40 #define DHCP_CLIENT_PORT 68
41 
42 struct dhcp_data {
43 	u8 op;
44 	u8 htype;
45 	u8 hlen;
46 	u8 hops;
47 	be32 xid;
48 	be16 secs;
49 	be16 flags;
50 	be32 client_ip;
51 	be32 your_ip;
52 	be32 server_ip;
53 	be32 relay_ip;
54 	u8 hw_addr[16];
55 	u8 serv_name[64];
56 	u8 boot_file[128];
57 } STRUCT_PACKED;
58 
59 struct bootp_pkt {
60 	struct ip iph;
61 	struct udphdr udph;
62 	u8 op;
63 	u8 htype;
64 	u8 hlen;
65 	u8 hops;
66 	be32 xid;
67 	be16 secs;
68 	be16 flags;
69 	be32 client_ip;
70 	be32 your_ip;
71 	be32 server_ip;
72 	be32 relay_ip;
73 	u8 hw_addr[16];
74 	u8 serv_name[64];
75 	u8 boot_file[128];
76 	u8 exten[312];
77 } STRUCT_PACKED;
78 
79 #define DHCP_MAGIC 0x63825363
80 
81 /*
82  * IANA DHCP/BOOTP registry
83  * http://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml
84 */
85 enum dhcp_options {
86 	DHCP_OPT_PAD = 0,
87 	DHCP_OPT_SUBNET_MASK = 1,
88 	DHCP_OPT_TIME_OFFSET = 2,
89 	DHCP_OPT_ROUTER = 3,
90 	DHCP_OPT_TIME_SERVER = 4,
91 	DHCP_OPT_NAME_SERVER = 5,
92 	DHCP_OPT_DOMAIN_NAME_SERVER = 6,
93 	DHCP_OPT_LOG_SERVER = 7,
94 	DHCP_OPT_QUOTES_SERVER = 8,
95 	DHCP_OPT_LPR_SERVER = 9,
96 	DHCP_OPT_IMPRESS_SERVER = 10,
97 	DHCP_OPT_RLP_SERVER = 11,
98 	DHCP_OPT_HOSTNAME = 12,
99 	DHCP_OPT_BOOT_FILE_SIZE = 13,
100 	DHCP_OPT_MERIT_DUMP_FILE = 14,
101 	DHCP_OPT_DOMAIN_NAME = 15,
102 	DHCP_OPT_SWAP_SERVER = 16,
103 	DHCP_OPT_ROOT_PATH = 17,
104 	DHCP_OPT_EXTENSION_PATH = 18,
105 	DHCP_OPT_FORWARD = 19,
106 	DHCP_OPT_SRC_RTE = 20,
107 	DHCP_OPT_POLICY_FILTER = 21,
108 	DHCP_OPT_MAX_DG_ASSEMBLY = 22,
109 	DHCP_OPT_DEFAULT_IP_TTL = 23,
110 	DHCP_OPT_MTU_TIMEOUT = 24,
111 	DHCP_OPT_MTU_PLATEAU = 25,
112 	DHCP_OPT_MTU_INTERFACE = 26,
113 	DHCP_OPT_ALL_SUBNETS_LOCAL = 27,
114 	DHCP_OPT_BROADCAST_ADDRESS = 28,
115 	DHCP_OPT_MASK_DISCOVERY = 29,
116 	DHCP_OPT_MASK_SUPPLIER = 30,
117 	DHCP_OPT_ROUTER_DISCOVERY = 31,
118 	DHCP_OPT_ROUTER_SOLICITATION_ADDRESS = 32,
119 	DHCP_OPT_STATIC_ROUTE = 33,
120 	DHCP_OPT_TRAILERS = 34,
121 	DHCP_OPT_ARP_TIMEOUT = 35,
122 	DHCP_OPT_ETHERNET = 36,
123 	DHCP_OPT_TCP_DEFAULT_TTL = 37,
124 	DHCP_OPT_TCP_KEEPALIVE_INTERVAL = 38,
125 	DHCP_OPT_TCP_KEEPALIVE_GARBAGE = 39,
126 	DHCP_OPT_NIS_DOMAIN = 40,
127 	DHCP_OPT_NIS_SERVERS = 41,
128 	DHCP_OPT_NTP_SERVERS = 42,
129 	DHCP_OPT_VENDOR_SPECIFIC = 43,
130 	DHCP_OPT_NETBIOS_NAME_SERVER = 44,
131 	DHCP_OPT_NETBIOS_DISTRIBUTION_SERVER = 45,
132 	DHCP_OPT_NETBIOS_NODE_TYPE = 46,
133 	DHCP_OPT_NETBIOS_SCOPE = 47,
134 	DHCP_OPT_FONT_SERVER = 48,
135 	DHCP_OPT_DISPLAY_MANAGER = 49,
136 	DHCP_OPT_REQUESTED_IP_ADDRESS = 50,
137 	DHCP_OPT_IP_ADDRESS_LEASE_TIME = 51,
138 	DHCP_OPT_OVERLOAD = 52,
139 	DHCP_OPT_MSG_TYPE = 53,
140 	DHCP_OPT_SERVER_ID = 54,
141 	DHCP_OPT_PARAMETER_REQ_LIST = 55,
142 	DHCP_OPT_MESSAGE = 56,
143 	DHCP_OPT_MAX_MESSAGE_SIZE = 57,
144 	DHCP_OPT_RENEWAL_TIME = 58,
145 	DHCP_OPT_REBINDING_TIME = 59,
146 	DHCP_OPT_VENDOR_CLASS_ID = 60,
147 	DHCP_OPT_CLIENT_ID = 61,
148 	DHCP_OPT_NETWARE_IP_DOMAIN = 62,
149 	DHCP_OPT_NETWARE_IP_OPTION = 63,
150 	DHCP_OPT_NIS_V3_DOMAIN = 64,
151 	DHCP_OPT_NIS_V3_SERVERS = 65,
152 	DHCP_OPT_TFTP_SERVER_NAME = 66,
153 	DHCP_OPT_BOOT_FILE_NAME = 67,
154 	DHCP_OPT_HOME_AGENT_ADDRESSES = 68,
155 	DHCP_OPT_SMTP_SERVER = 69,
156 	DHCP_OPT_POP3_SERVER = 70,
157 	DHCP_OPT_NNTP_SERVER = 71,
158 	DHCP_OPT_WWW_SERVER = 72,
159 	DHCP_OPT_FINGER_SERVER = 73,
160 	DHCP_OPT_IRC_SERVER = 74,
161 	DHCP_OPT_STREETTALK_SERVER = 75,
162 	DHCP_OPT_STDA_SERVER = 76,
163 	DHCP_OPT_USER_CLASS = 77,
164 	DHCP_OPT_DIRECTORY_AGENT = 78,
165 	DHCP_OPT_SERVICE_SCOPE = 79,
166 	DHCP_OPT_RAPID_COMMIT = 80,
167 	DHCP_OPT_CLIENT_FQDN = 81,
168 	DHCP_OPT_RELAY_AGENT_INFO = 82,
169 	DHCP_OPT_ISNS = 83,
170 	DHCP_OPT_NDS_SERVERS = 85,
171 	DHCP_OPT_NDS_TREE_NAME = 86,
172 	DHCP_OPT_NDS_CONTEXT = 87,
173 	DHCP_OPT_BCMCS_CONTROLLER_DOMAIN_NAME_LIST = 88,
174 	DHCP_OPT_BCMCS_CONTROLLER_IPV4_ADDRESS = 89,
175 	DHCP_OPT_AUTHENTICATION = 90,
176 	DHCP_OPT_CLIENT_LAST_TRANSACTION_TIME = 91,
177 	DHCP_OPT_ASSOCIATED_IP = 92,
178 	DHCP_OPT_CLIENT_SYSYEM = 93,
179 	DHCP_OPT_CLIENT_NDI = 94,
180 	DHCP_OPT_LDAP = 95,
181 	DHCP_OPT_UUID_GUID = 97,
182 	DHCP_OPT_USER_AUTH = 98,
183 	DHCP_OPT_GEOCONF_CIVIC = 99,
184 	DHCP_OPT_PCODE = 100,
185 	DHCP_OPT_TCODE = 101,
186 	DHCP_OPT_NETINFO_ADDRESS = 112,
187 	DHCP_OPT_NETINFO_TAG = 113,
188 	DHCP_OPT_URL = 114,
189 	DHCP_OPT_AUTO_CONFIG = 116,
190 	DHCP_OPT_NAME_SERVICE_SEARCH = 117,
191 	DHCP_OPT_SUBNET_SELECTION = 118,
192 	DHCP_OPT_DOMAIN_SEARCH = 119,
193 	DHCP_OPT_SIP_SERVERS_DCP = 120,
194 	DHCP_OPT_CLASSLESS_STATIC_ROUTE = 121,
195 	DHCP_OPT_CCC = 122,
196 	DHCP_OPT_GEOCONF = 123,
197 	DHCP_OPT_V_I_VENDOR_CLASS = 124,
198 	DHCP_OPT_V_I_VENDOR_SPECIFIC_INFO = 125,
199 	DHCP_OPT_PANA_AGENT = 136,
200 	DHCP_OPT_V4_LOST = 137,
201 	DHCP_OPT_CAPWAP_AC_V4 = 138,
202 	DHCP_OPT_IPV4_ADDRESS_MOS = 139,
203 	DHCP_OPT_IPV4_FQDN_MOS = 140,
204 	DHCP_OPT_SIP_UA_CONF = 141,
205 	DHCP_OPT_IPV4_ADDRESS_ANDSF = 142,
206 	DHCP_OPT_GEOLOC = 144,
207 	DHCP_OPT_FORCERENEW_NONCE_CAPABLE = 145,
208 	DHCP_OPT_RDNSS_SELECTION = 146,
209 	DHCP_OPT_TFTP_SERVER_ADDRESS = 150,
210 	DHCP_OPT_STATUS_CODE = 151,
211 	DHCP_OPT_BASE_TIME = 152,
212 	DHCP_OPT_START_TIME_OF_STATE = 153,
213 	DHCP_OPT_QUERY_START_TIME = 154,
214 	DHCP_OPT_QUERY_END_TIME = 155,
215 	DHCP_OPT_STATE = 156,
216 	DHCP_OPT_DATA_SOURCE = 157,
217 	DHCP_OPT_V4_PCP_SERVER = 158,
218 	DHCP_OPT_V4_PORTPARAMS = 159,
219 	DHCP_OPT_CAPTIVE_PORTAL = 160,
220 	DHCP_OPT_CONF_FILE = 209,
221 	DHCP_OPT_PATH_PREFIX = 210,
222 	DHCP_OPT_REBOOT_TIME = 211,
223 	DHCP_OPT_6RD = 212,
224 	DHCP_OPT_V4_ACCESS_DOMAIN = 213,
225 	DHCP_OPT_SUBNET_ALLOCATION = 220,
226 	DHCP_OPT_VSS = 221,
227 	DHCP_OPT_END = 255
228 };
229 
230 enum dhcp_message_types {
231 	DHCPDISCOVER = 1,
232 	DHCPOFFER = 2,
233 	DHCPREQUEST = 3,
234 	DHCPDECLINE = 4,
235 	DHCPACK = 5,
236 	DHCPNAK = 6,
237 	DHCPRELEASE = 7,
238 	DHCPINFORM = 8,
239 	DHCPFORCERENEW = 9,
240 	DHCPLEASEQUERY = 10,
241 	DHCPLEASEUNASSIGNED = 11,
242 	DHCPLEASEUNKNOWN = 12,
243 	DHCPLEASEACTIVE = 13,
244 	DHCPBULKLEASEQUERY = 14,
245 	DHCPLEASEQUERYDONE = 15,
246 	DHCPACTIVELEASEQUERY = 16,
247 	DHCPLEASEQUERYSTATUS = 17,
248 	DHCPTLS = 18,
249 };
250 
251 enum dhcp_relay_agent_suboptions {
252 	DHCP_RELAY_OPT_AGENT_CIRCUIT_ID = 1,
253 	DHCP_RELAY_OPT_AGENT_REMOTE_ID = 2,
254 	DHCP_RELAY_OPT_DOCSIS_DEVICE_CLASS = 4,
255 	DHCP_RELAY_OPT_LINK_SELECTION = 5,
256 	DHCP_RELAY_OPT_SUBSCRIBE_ID = 6,
257 	DHCP_RELAY_OPT_RADIUS_ATTRIBUTES = 7,
258 	DHCP_RELAY_OPT_AUTHENTICATION = 8,
259 	DHCP_RELAY_OPT_VEDOR_SPECIFIC = 9,
260 	DHCP_RELAY_OPT_RELAY_AGENT_FLAGS = 10,
261 	DHCP_RELAY_OPT_SERVER_ID_OVERRIDE = 11,
262 	DHCP_RELAY_OPT_RELAY_AGENT_ID = 12,
263 	DHCP_RELAY_OPT_ACCESS_TECHNOLOGY_TYPE = 13,
264 	DHCP_RELAY_OPT_ACCESS_NETWORK_NAME = 14,
265 	DHCP_RELAY_OPT_ACCESS_POINT_NAME = 15,
266 	DHCP_RELAY_OPT_ACCESS_POINT_BSSID = 16,
267 	DHCP_RELAY_OPT_OPERATOR_ID = 17,
268 	DHCP_RELAY_OPT_OPERATOR_REALM = 18,
269 	DHCP_RELAY_OPT_DHCPV4_VIRTUAL_SUBNET_SELECTION = 151,
270 	DHCP_RELAY_OPT_DHCPV4_VIRTUAL_SUBNET_SELECTION_CONTROL = 152,
271 };
272 
273 enum access_technology_types {
274 	ACCESS_TECHNOLOGY_VIRTUAL = 1,
275 	ACCESS_TECHNOLOGY_PPP = 2,
276 	ACCESS_TECHNOLOGY_ETHERNET = 3,
277 	ACCESS_TECHNOLOGY_WLAN = 4,
278 	ACCESS_TECHNOLOGY_WIMAX = 5,
279 };
280 
281 #endif /* DHCP_H */
282