mikroSDK Reference Manual
dhcpv6_common.h
Go to the documentation of this file.
1
31#ifndef _DHCPV6_COMMON_H
32#define _DHCPV6_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36#include "core/ethernet.h"
37#include "ipv6/ipv6.h"
38
39//UDP ports used by DHCPv6 clients and servers
40#define DHCPV6_CLIENT_PORT 546
41#define DHCPV6_SERVER_PORT 547
42
43//Maximum DHCPv6 message size
44#define DHCPV6_MAX_MSG_SIZE 1232
45//Maximum DUID size (128 octets not including the type code)
46#define DHCPV6_MAX_DUID_SIZE 130
47
48//Maximum hop count in a relay-forward message
49#define DHCPV6_HOP_COUNT_LIMIT 8
50//Highest server preference value
51#define DHCPV6_MAX_SERVER_PREFERENCE 255
52//Infinite lifetime representation
53#define DHCPV6_INFINITE_TIME 0xFFFFFFFF
54
55//C++ guard
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60
65typedef enum
66{
67 DHCPV6_DUID_LLT = 1,
68 DHCPV6_DUID_EN = 2,
69 DHCPV6_DUID_LL = 3
71
72
77typedef enum
78{
79 DHCPV6_HARDWARE_TYPE_ETH = 1,
80 DHCPV6_HARDWARE_TYPE_EUI64 = 27
82
83
88typedef enum
89{
90 DHCPV6_MSG_TYPE_SOLICIT = 1,
91 DHCPV6_MSG_TYPE_ADVERTISE = 2,
92 DHCPV6_MSG_TYPE_REQUEST = 3,
93 DHCPV6_MSG_TYPE_CONFIRM = 4,
94 DHCPV6_MSG_TYPE_RENEW = 5,
95 DHCPV6_MSG_TYPE_REBIND = 6,
96 DHCPV6_MSG_TYPE_REPLY = 7,
97 DHCPV6_MSG_TYPE_RELEASE = 8,
98 DHCPV6_MSG_TYPE_DECLINE = 9,
99 DHCPV6_MSG_TYPE_RECONFIGURE = 10,
100 DHCPV6_MSG_TYPE_INFO_REQUEST = 11,
101 DHCPV6_MSG_TYPE_RELAY_FORW = 12,
102 DHCPV6_MSG_TYPE_RELAY_REPL = 13
104
105
110typedef enum
111{
112 DHCPV6_OPT_CLIENT_ID = 1,
113 DHCPV6_OPT_SERVER_ID = 2,
114 DHCPV6_OPT_IA_NA = 3,
115 DHCPV6_OPT_IA_TA = 4,
116 DHCPV6_OPT_IA_ADDR = 5,
117 DHCPV6_OPT_ORO = 6,
118 DHCPV6_OPT_PREFERENCE = 7,
119 DHCPV6_OPT_ELAPSED_TIME = 8,
120 DHCPV6_OPT_RELAY_MSG = 9,
121 DHCPV6_OPT_AUTH = 11,
122 DHCPV6_OPT_UNICAST = 12,
123 DHCPV6_OPT_STATUS_CODE = 13,
124 DHCPV6_OPT_RAPID_COMMIT = 14,
125 DHCPV6_OPT_USER_CLASS = 15,
126 DHCPV6_OPT_VENDOR_CLASS = 16,
127 DHCPV6_OPT_VENDOR_OPTS = 17,
128 DHCPV6_OPT_INTERFACE_ID = 18,
129 DHCPV6_OPT_RECONF_MSG = 19,
130 DHCPV6_OPT_RECONF_ACCEPT = 20,
131 DHCPV6_OPT_DNS_SERVERS = 23,
132 DHCPV6_OPT_DOMAIN_LIST = 24,
133 DHCPV6_OPT_IA_PD = 25,
134 DHCPV6_OPT_IA_PREFIX = 26,
135 DHCPV6_OPT_INFO_REFRESH_TIME = 32,
136 DHCPV6_OPT_FQDN = 39,
137 DHCPV6_OPT_CAPTIVE_PORTAL = 103
139
140
145typedef enum
146{
147 DHCPV6_STATUS_SUCCESS = 0,
148 DHCPV6_STATUS_UNSPEC_FAILURE = 1,
149 DHCPV6_STATUS_NO_ADDRS_AVAILABLE = 2,
150 DHCPV6_STATUS_NO_BINDING = 3,
151 DHCPV6_STATUS_NOT_ON_LINK = 4,
152 DHCPV6_STATUS_USE_MULTICAST = 5
154
155
156//CodeWarrior or Win32 compiler?
157#if defined(__CWCC__) || defined(_WIN32)
158 #pragma pack(push, 1)
159#endif
160
161
167{
168 uint16_t type; //0-1
169 uint16_t hardwareType; //2-3
170 uint32_t time; //4-7
171 MacAddr linkLayerAddr; //8-13
172} Dhcpv6DuidLlt;
173
174
179typedef __packed_struct
180{
181 uint16_t type; //0-1
182 uint32_t enterpriseNumber; //2-5
183 uint8_t identifier[]; //6
184} Dhcpv6DuidEn;
185
186
191typedef __packed_struct
192{
193 uint16_t type; //0-1
194 uint16_t hardwareType; //2-3
195#if (ETH_SUPPORT == ENABLED)
196 MacAddr linkLayerAddr; //4-9
197#else
198 Eui64 linkLayerAddr; //4-11
199#endif
200} Dhcpv6DuidLl;
201
202
207typedef __packed_struct
208{
209 uint8_t msgType; //0
210 uint8_t transactionId[3]; //1-3
211 uint8_t options[]; //4
212} Dhcpv6Message;
213
214
219typedef __packed_struct
220{
221 uint8_t msgType; //0
222 uint8_t hopCount; //1
223 Ipv6Addr linkAddress; //2-17
224 Ipv6Addr peerAddress; //18-33
225 uint8_t options[]; //34
226} Dhcpv6RelayMessage;
227
228
233typedef __packed_struct
234{
235 uint16_t code; //0-1
236 uint16_t length; //2-3
237 uint8_t value[]; //4
238} Dhcpv6Option;
239
240
245typedef __packed_struct
246{
247 uint32_t iaId; //0-3
248 uint32_t t1; //4-7
249 uint32_t t2; //8-11
250 uint8_t options[]; //12
251} Dhcpv6IaNaOption;
252
253
258typedef __packed_struct
259{
260 uint32_t iaId; //0-3
261 uint8_t options[]; //4
262} Dhcpv6IaTaOption;
263
264
269typedef __packed_struct
270{
271 Ipv6Addr address; //0-15
272 uint32_t preferredLifetime; //16-19
273 uint32_t validLifetime; //20-23
274 uint8_t options[]; //24
275} Dhcpv6IaAddrOption;
276
277
282typedef __packed_struct
283{
284 uint16_t requestedOption[1]; //0-1
285} Dhcpv6OroOption;
286
287
292typedef __packed_struct
293{
294 uint8_t value; //0
295} Dhcpv6PreferenceOption;
296
297
302typedef __packed_struct
303{
304 uint16_t value; //0-1
305} Dhcpv6ElapsedTimeOption;
306
307
312typedef __packed_struct
313{
314 uint8_t protocol; //0
315 uint8_t algorithm; //1
316 uint8_t rdm; //2
317 uint8_t replayDetection[8]; //3-10
318 uint8_t authInfo[]; //11
319} Dhcpv6AuthOption;
320
321
326typedef __packed_struct
327{
328 Ipv6Addr serverAddr; //0-15
329} Dhcpv6ServerUnicastOption;
330
331
336typedef __packed_struct
337{
338 uint16_t statusCode; //0-1
339 char_t statusMessage[]; //2
340} Dhcpv6StatusCodeOption;
341
342
347typedef __packed_struct
348{
349 uint8_t msgType; //0
350} Dhcpv6ReconfMessageOption;
351
352
357typedef __packed_struct
358{
359 Ipv6Addr address[1]; //0-15
360} Dhcpv6DnsServersOption;
361
362
367typedef __packed_struct
368{
369 uint8_t searchList[1]; //0
370} Dhcpv6DomainListOption;
371
372
377typedef __packed_struct
378{
379 uint32_t iaId; //0-3
380 uint32_t t1; //4-7
381 uint32_t t2; //8-11
382 uint8_t options[]; //12
383} Dhcpv6IaPdOption;
384
385
390typedef __packed_struct
391{
392 uint32_t preferredLifetime; //0-3
393 uint32_t validLifetime; //4-7
394 uint8_t prefixLen; //8
395 Ipv6Addr prefix; //9-24
396 uint8_t options[]; //25
397} Dhcpv6IaPrefixOption;
398
399
404typedef __packed_struct
405{
406#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
407 uint8_t mbz : 5; //0
408 uint8_t n : 1;
409 uint8_t o : 1;
410 uint8_t s : 1;
411#else
412 uint8_t s : 1; //0
413 uint8_t o : 1;
414 uint8_t n : 1;
415 uint8_t mbz : 5;
416#endif
417 uint8_t domainName[]; //1
418} Dhcpv6FqdnOption;
419
420
421//CodeWarrior or Win32 compiler?
422#if defined(__CWCC__) || defined(_WIN32)
423 #pragma pack(pop)
424#endif
425
426//DHCPv6 related constants
427extern const Ipv6Addr DHCPV6_ALL_RELAY_AGENTS_AND_SERVERS_ADDR;
428extern const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR;
429
430//DHCPv6 related functions
431Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length);
432
433Dhcpv6Option *dhcpv6AddOption(void *message, size_t *messageLen,
434 uint16_t optionCode, const void *optionValue, size_t optionLen);
435
436Dhcpv6Option *dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen,
437 uint16_t optionCode, const void *optionValue, size_t optionLen);
438
439Dhcpv6Option *dhcpv6GetOption(const uint8_t *options,
440 size_t optionsLength, uint16_t optionCode);
441
442//C++ guard
443#ifdef __cplusplus
444}
445#endif
446
447#endif
Dhcpv6HardwareType
Hardware types.
Definition dhcpv6_common.h:78
Dhcpv6DuidType
DUID types.
Definition dhcpv6_common.h:66
typedef __packed_struct
DUID-LLT structure.
Definition dhcpv6_common.h:167
Dhcpv6OptionCode
DHCPv6 option codes.
Definition dhcpv6_common.h:111
Dhcpv6StatusCode
Status code.
Definition dhcpv6_common.h:146
Dhcpv6MessageType
DHCPv6 message types.
Definition dhcpv6_common.h:89
Ethernet.
IPv6 (Internet Protocol Version 6)
TCP/IP stack core.