dhcpv6_common.h
Go to the documentation of this file.
1 /**
2  * @file dhcpv6_common.h
3  * @brief Definitions common to DHCPv6 client, server and relay agent
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _DHCPV6_COMMON_H
30 #define _DHCPV6_COMMON_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "core/ethernet.h"
35 #include "ipv6/ipv6.h"
36 
37 //UDP ports used by DHCPv6 clients and servers
38 #define DHCPV6_CLIENT_PORT 546
39 #define DHCPV6_SERVER_PORT 547
40 
41 //Maximum DHCPv6 message size
42 #define DHCPV6_MAX_MSG_SIZE 1232
43 //Maximum DUID size (128 octets not including the type code)
44 #define DHCPV6_MAX_DUID_SIZE 130
45 
46 //Maximum hop count in a relay-forward message
47 #define DHCPV6_HOP_COUNT_LIMIT 32
48 //Highest server preference value
49 #define DHCPV6_MAX_SERVER_PREFERENCE 255
50 //Infinite lifetime representation
51 #define DHCPV6_INFINITE_TIME 0xFFFFFFFF
52 
53 //C++ guard
54 #ifdef __cplusplus
55  extern "C" {
56 #endif
57 
58 
59 /**
60  * @brief DUID types
61  **/
62 
63 typedef enum
64 {
69 
70 
71 /**
72  * @brief Hardware types
73  **/
74 
75 typedef enum
76 {
80 
81 
82 /**
83  * @brief DHCPv6 message types
84  **/
85 
86 typedef enum
87 {
102 
103 
104 /**
105  * @brief DHCPv6 option codes
106  **/
107 
108 typedef enum
109 {
135 
136 
137 /**
138  * @brief Status code
139  **/
140 
141 typedef enum
142 {
150 
151 
152 //CodeWarrior or Win32 compiler?
153 #if defined(__CWCC__) || defined(_WIN32)
154  #pragma pack(push, 1)
155 #endif
156 
157 
158 /**
159  * @brief DUID-LLT structure
160  **/
161 
162 typedef __start_packed struct
163 {
164  uint16_t type; //0-1
165  uint16_t hardwareType; //2-3
166  uint32_t time; //4-7
169 
170 
171 /**
172  * @brief DUID-EN structure
173  **/
174 
175 typedef __start_packed struct
176 {
177  uint16_t type; //0-1
178  uint32_t enterpriseNumber; //2-5
179  uint8_t identifier[]; //6
181 
182 
183 /**
184  * @brief DUID-LL structure
185  **/
186 
187 typedef __start_packed struct
188 {
189  uint16_t type; //0-1
190  uint16_t hardwareType; //2-3
191 #if (ETH_SUPPORT == ENABLED)
192  MacAddr linkLayerAddr; //4-9
193 #else
194  Eui64 linkLayerAddr; //4-11
195 #endif
197 
198 
199 /**
200  * @brief DHCPv6 message
201  **/
202 
203 typedef __start_packed struct
204 {
205  uint8_t msgType; //0
206  uint8_t transactionId[3]; //1-3
207  uint8_t options[]; //4
209 
210 
211 /**
212  * @brief DHCPv6 relay agent message
213  **/
214 
215 typedef __start_packed struct
216 {
217  uint8_t msgType; //0
218  uint8_t hopCount; //1
221  uint8_t options[]; //34
223 
224 
225 /**
226  * @brief DHCPv6 option
227  **/
228 
229 typedef __start_packed struct
230 {
231  uint16_t code; //0-1
232  uint16_t length; //2-3
233  uint8_t value[]; //4
235 
236 
237 /**
238  * @brief Identity Association for Non-temporary Addresses option
239  **/
240 
241 typedef __start_packed struct
242 {
243  uint32_t iaId; //0-3
244  uint32_t t1; //4-7
245  uint32_t t2; //8-11
246  uint8_t options[]; //12
248 
249 
250 /**
251  * @brief Identity Association for Temporary Addresses option
252  **/
253 
254 typedef __start_packed struct
255 {
256  uint32_t iaId; //0-3
257  uint8_t options[]; //4
259 
260 
261 /**
262  * @brief IA Address option
263  **/
264 
265 typedef __start_packed struct
266 {
268  uint32_t preferredLifetime; //16-19
269  uint32_t validLifetime; //20-23
270  uint8_t options[]; //24
272 
273 
274 /**
275  * @brief Option Request option
276  **/
277 
278 typedef __start_packed struct
279 {
280  uint16_t requestedOption[1]; //0-1
282 
283 
284 /**
285  * @brief Preference option
286  **/
287 
288 typedef __start_packed struct
289 {
290  uint8_t value; //0
292 
293 
294 /**
295  * @brief Elapsed Time option
296  **/
297 
298 typedef __start_packed struct
299 {
300  uint16_t value; //0-1
302 
303 
304 /**
305  * @brief Authentication option
306  **/
307 
308 typedef __start_packed struct
309 {
310  uint8_t protocol; //0
311  uint8_t algorithm; //1
312  uint8_t rdm; //2
313  uint8_t replayDetection[8]; //3-10
314  uint8_t authInfo[]; //11
316 
317 
318 /**
319  * @brief Server Unicast option
320  **/
321 
322 typedef __start_packed struct
323 {
326 
327 
328 /**
329  * @brief Status Code option
330  **/
331 
332 typedef __start_packed struct
333 {
334  uint16_t statusCode; //0-1
337 
338 
339 /**
340  * @brief Reconfigure Message option
341  **/
342 
343 typedef __start_packed struct
344 {
345  uint8_t msgType; //0
347 
348 
349 /**
350  * @brief DNS Recursive Name Server option
351  **/
352 
353 typedef __start_packed struct
354 {
355  Ipv6Addr address[1]; //0-15
357 
358 
359 /**
360  * @brief Domain Search List option
361  **/
362 
363 typedef __start_packed struct
364 {
365  uint8_t searchList[1]; //0
367 
368 
369 /**
370  * @brief Identity Association for Prefix Delegation Option
371  **/
372 
373 typedef __start_packed struct
374 {
375  uint32_t iaId; //0-3
376  uint32_t t1; //4-7
377  uint32_t t2; //8-11
378  uint8_t options[]; //12
380 
381 
382 /**
383  * @brief IA_PD Prefix option
384  **/
385 
386 typedef __start_packed struct
387 {
388  uint32_t preferredLifetime; //0-3
389  uint32_t validLifetime; //4-7
390  uint8_t prefixLen; //8
391  Ipv6Addr prefix; //9-24
392  uint8_t options[]; //25
394 
395 
396 /**
397  * @brief Fully Qualified Domain Name option
398  **/
399 
400 typedef __start_packed struct
401 {
402 #ifdef _CPU_BIG_ENDIAN
403  uint8_t mbz : 5; //0
404  uint8_t n : 1;
405  uint8_t o : 1;
406  uint8_t s : 1;
407 #else
408  uint8_t s : 1; //0
409  uint8_t o : 1;
410  uint8_t n : 1;
411  uint8_t mbz : 5;
412 #endif
413  uint8_t domainName[]; //1
415 
416 
417 //CodeWarrior or Win32 compiler?
418 #if defined(__CWCC__) || defined(_WIN32)
419  #pragma pack(pop)
420 #endif
421 
422 
423 //DHCPv6 related constants
425 extern const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR;
426 
427 //DHCPv6 related functions
428 Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length);
429 
430 Dhcpv6Option *dhcpv6AddOption(void *message, size_t *messageLen,
431  uint16_t optionCode, const void *optionValue, size_t optionLen);
432 
433 Dhcpv6Option *dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen,
434  uint16_t optionCode, const void *optionValue, size_t optionLen);
435 
436 Dhcpv6Option *dhcpv6GetOption(const uint8_t *options,
437  size_t optionsLength, uint16_t optionCode);
438 
439 int32_t dhcpv6Rand(int32_t value);
440 int32_t dhcpv6RandRange(int32_t min, int32_t max);
441 
442 //C++ guard
443 #ifdef __cplusplus
444  }
445 #endif
446 
447 #endif
uint16_t type
__start_packed struct @134 Dhcpv6Option
DHCPv6 option.
uint8_t mbz
uint8_t transactionId[3]
uint32_t validLifetime
char char_t
Definition: compiler_port.h:41
const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR
Definition: dhcpv6_common.c:53
Dhcpv6OptionCode
DHCPv6 option codes.
uint8_t hopCount
int32_t dhcpv6Rand(int32_t value)
Multiplication by a randomization factor.
uint32_t time
TCP/IP stack core.
Dhcpv6StatusCode
Status code.
__start_packed struct @136 Dhcpv6IaTaOption
Identity Association for Temporary Addresses option.
__start_packed struct @138 Dhcpv6OroOption
Option Request option.
uint8_t message[]
Definition: chap.h:150
Dhcpv6DuidType
DUID types.
Definition: dhcpv6_common.h:63
__start_packed struct @144 Dhcpv6ReconfMessageOption
Reconfigure Message option.
__start_packed struct @148 Dhcpv6IaPrefixOption
IA_PD Prefix option.
uint16_t statusCode
__start_packed struct @133 Dhcpv6RelayMessage
DHCPv6 relay agent message.
uint8_t options[]
__start_packed struct @183 Ipv6Addr
IPv6 network address.
char_t statusMessage[]
uint32_t enterpriseNumber
Dhcpv6HardwareType
Hardware types.
Definition: dhcpv6_common.h:75
__start_packed struct @142 Dhcpv6ServerUnicastOption
Server Unicast option.
Dhcpv6Option * dhcpv6AddOption(void *message, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add an option to a DHCPv6 message.
__start_packed struct @135 Dhcpv6IaNaOption
Identity Association for Non-temporary Addresses option.
uint8_t searchList[1]
__start_packed struct @143 Dhcpv6StatusCodeOption
Status Code option.
__start_packed struct @113 Eui64
EUI-64 identifier.
uint8_t rdm
uint8_t authInfo[]
Ethernet.
uint8_t replayDetection[8]
__start_packed struct @146 Dhcpv6DomainListOption
Domain Search List option.
Dhcpv6Option * dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add a suboption under an existing base option.
uint8_t identifier[]
__start_packed struct @130 Dhcpv6DuidEn
DUID-EN structure.
Dhcpv6Option * dhcpv6GetOption(const uint8_t *options, size_t optionsLength, uint16_t optionCode)
Find the specified option in a DHCPv6 message.
uint8_t s
uint32_t preferredLifetime
IPv6 (Internet Protocol Version 6)
__start_packed struct @147 Dhcpv6IaPdOption
Identity Association for Prefix Delegation Option.
__start_packed struct _Ipv4Header __end_packed
Ipv6Addr address
int32_t dhcpv6RandRange(int32_t min, int32_t max)
Get a random value in the specified range.
uint16_t length
Ipv6Addr prefix
__start_packed struct @129 Dhcpv6DuidLlt
DUID-LLT structure.
__start_packed struct @131 Dhcpv6DuidLl
DUID-LL structure.
__start_packed struct @140 Dhcpv6ElapsedTimeOption
Elapsed Time option.
uint16_t code
uint8_t domainName[]
__start_packed struct @112 MacAddr
MAC address.
uint32_t iaId
uint32_t t2
__start_packed struct @141 Dhcpv6AuthOption
Authentication option.
const Ipv6Addr DHCPV6_ALL_RELAY_AGENTS_AND_SERVERS_ADDR
Definition: dhcpv6_common.c:49
__start_packed struct @145 Dhcpv6DnsServersOption
DNS Recursive Name Server option.
uint8_t prefixLen
Ipv6Addr linkAddress
uint8_t msgType
uint32_t t1
uint16_t hardwareType
Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length)
Retrieve status code.
Definition: dhcpv6_common.c:68
uint16_t requestedOption[1]
Dhcpv6MessageType
DHCPv6 message types.
Definition: dhcpv6_common.h:86
__start_packed struct @149 Dhcpv6FqdnOption
Fully Qualified Domain Name option.
uint8_t value[]
uint8_t protocol
Ipv6Addr serverAddr
MacAddr linkLayerAddr
uint8_t n
__start_packed struct @139 Dhcpv6PreferenceOption
Preference option.
uint8_t o
__start_packed struct @132 Dhcpv6Message
DHCPv6 message.
uint8_t algorithm
__start_packed struct @137 Dhcpv6IaAddrOption
IA Address option.
Ipv6Addr peerAddress