1 /*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /** @file
8 * @brief DHCPv6 internal header
9 *
10 * This header should not be included by the application.
11 */
12
13 #ifndef DHCPV6_INTERNAL_H_
14 #define DHCPV6_INTERNAL_H_
15
16 #include <zephyr/net/dhcpv6.h>
17
18 #define DHCPV6_DUID_TYPE_SIZE 2
19 #define DHVPV6_DUID_LL_HW_TYPE_SIZE 2
20 #define DHCPV6_DUID_LL_HEADER_SIZE (DHCPV6_DUID_TYPE_SIZE + \
21 DHVPV6_DUID_LL_HW_TYPE_SIZE)
22
23 #define DHCPV6_MSG_TYPE_SIZE 1
24 #define DHCPV6_HEADER_SIZE (DHCPV6_MSG_TYPE_SIZE + DHCPV6_TID_SIZE)
25
26 #define DHCPV6_OPTION_CODE_SIZE 2
27 #define DHCPV6_OPTION_LENGTH_SIZE 2
28 #define DHCPV6_OPTION_HEADER_SIZE (DHCPV6_OPTION_CODE_SIZE + \
29 DHCPV6_OPTION_LENGTH_SIZE)
30
31 #define DHCPV6_OPTION_PREFERENCE_SIZE 1
32 #define DHCPV6_OPTION_ELAPSED_TIME_SIZE 2
33 #define DHCPV6_OPTION_ELAPSED_TIME_SIZE 2
34 #define DHCPV6_OPTION_IA_NA_HEADER_SIZE 12
35 #define DHCPV6_OPTION_IAADDR_HEADER_SIZE 24
36 #define DHCPV6_OPTION_IA_PD_HEADER_SIZE 12
37 #define DHCPV6_OPTION_IAPREFIX_HEADER_SIZE 25
38 #define DHCPV6_OPTION_IAADDR_HEADER_SIZE 24
39 #define DHCPV6_OPTION_IAPREFIX_HEADER_SIZE 25
40 #define DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE 2
41
42 #define DHCPV6_INFINITY UINT32_MAX
43 #define DHCPV6_MAX_SERVER_PREFERENCE 255
44
45 #define DHCPV6_HARDWARE_ETHERNET_TYPE 1
46
47 #define DHCPV6_CLIENT_PORT 546
48 #define DHCPV6_SERVER_PORT 547
49
50 /* DHCPv6 Transmission/retransmission timeouts */
51 #define DHCPV6_SOL_MAX_DELAY 1000 /* Max delay of first Solicit, milliseconds */
52 #define DHCPV6_SOL_TIMEOUT 1000 /* Initial Solicit timeout, milliseconds */
53 #define DHCPV6_SOL_MAX_RT 3600000 /* Max Solicit timeout value, milliseconds */
54 #define DHCPV6_REQ_TIMEOUT 1000 /* Initial Request timeout, milliseconds */
55 #define DHCPV6_REQ_MAX_RT 30000 /* Max Request timeout value, milliseconds */
56 #define DHCPV6_REQ_MAX_RC 10 /* Max Request retry attempts */
57 #define DHCPV6_CNF_MAX_DELAY 1000 /* Max delay of first Confirm, milliseconds */
58 #define DHCPV6_CNF_TIMEOUT 1000 /* Initial Confirm timeout, milliseconds */
59 #define DHCPV6_CNF_MAX_RT 4000 /* Max Confirm timeout, milliseconds */
60 #define DHCPV6_CNF_MAX_RD 10000 /* Max Confirm duration, milliseconds */
61 #define DHCPV6_REN_TIMEOUT 10000 /* Initial Renew timeout, milliseconds */
62 #define DHCPV6_REN_MAX_RT 600000 /* Max Renew timeout value, milliseconds */
63 #define DHCPV6_REB_TIMEOUT 10000 /* Initial Rebind timeout, milliseconds */
64 #define DHCPV6_REB_MAX_RT 600000 /* Max Rebind timeout value, milliseconds */
65
66 /* DUID structures */
67 struct dhcpv6_duid_llt {
68 uint16_t hw_type;
69 uint32_t time;
70 uint8_t ll_addr[];
71 } __packed;
72
73 struct dhcpv6_duid_en {
74 uint32_t enterprise_number;
75 uint8_t identifier[];
76 } __packed;
77
78 struct dhcpv6_duid_ll {
79 uint16_t hw_type;
80 uint8_t ll_addr[];
81 } __packed;
82
83 struct dhcpv6_duid_uuid {
84 uint8_t uuid[16];
85 } __packed;
86
87 struct dhcpv6_msg_hdr {
88 uint8_t type; /* Message type */
89 uint8_t tid[3]; /* Transaction ID */
90 } __packed;
91
92 struct dhcpv6_iaaddr {
93 uint32_t preferred_lifetime;
94 uint32_t valid_lifetime;
95 struct in6_addr addr;
96 uint16_t status;
97 };
98
99 struct dhcpv6_ia_na {
100 uint32_t iaid;
101 uint32_t t1;
102 uint32_t t2;
103 uint16_t status;
104 struct dhcpv6_iaaddr iaaddr;
105 };
106
107 struct dhcpv6_iaprefix {
108 uint32_t preferred_lifetime;
109 uint32_t valid_lifetime;
110 struct in6_addr prefix;
111 uint8_t prefix_len;
112 uint16_t status;
113 };
114
115 struct dhcpv6_ia_pd {
116 uint32_t iaid;
117 uint32_t t1;
118 uint32_t t2;
119 uint16_t status;
120 struct dhcpv6_iaprefix iaprefix;
121 };
122
123 /* DHCPv6 message types, RFC8415, ch. 7.3. */
124 enum dhcpv6_msg_type {
125 DHCPV6_MSG_TYPE_SOLICIT = 1,
126 DHCPV6_MSG_TYPE_ADVERTISE = 2,
127 DHCPV6_MSG_TYPE_REQUEST = 3,
128 DHCPV6_MSG_TYPE_CONFIRM = 4,
129 DHCPV6_MSG_TYPE_RENEW = 5,
130 DHCPV6_MSG_TYPE_REBIND = 6,
131 DHCPV6_MSG_TYPE_REPLY = 7,
132 DHCPV6_MSG_TYPE_RELEASE = 8,
133 DHCPV6_MSG_TYPE_DECLINE = 9,
134 DHCPV6_MSG_TYPE_RECONFIGURE = 10,
135 DHCPV6_MSG_TYPE_INFORMATION_REQUEST = 11,
136 DHCPV6_MSG_TYPE_RELAY_FORW = 12,
137 DHCPV6_MSG_TYPE_RELAY_REPL = 13,
138 };
139
140 /* DHCPv6 option codes, RFC8415, ch. 21. */
141 enum dhcpv6_option_code {
142 DHCPV6_OPTION_CODE_CLIENTID = 1,
143 DHCPV6_OPTION_CODE_SERVERID = 2,
144 DHCPV6_OPTION_CODE_IA_NA = 3,
145 DHCPV6_OPTION_CODE_IA_TA = 4,
146 DHCPV6_OPTION_CODE_IAADDR = 5,
147 DHCPV6_OPTION_CODE_ORO = 6,
148 DHCPV6_OPTION_CODE_PREFERENCE = 7,
149 DHCPV6_OPTION_CODE_ELAPSED_TIME = 8,
150 DHCPV6_OPTION_CODE_RELAY_MSG = 9,
151 DHCPV6_OPTION_CODE_AUTH = 11,
152 DHCPV6_OPTION_CODE_UNICAST = 12,
153 DHCPV6_OPTION_CODE_STATUS_CODE = 13,
154 DHCPV6_OPTION_CODE_RAPID_COMMIT = 14,
155 DHCPV6_OPTION_CODE_USER_CLASS = 15,
156 DHCPV6_OPTION_CODE_VENDOR_CLASS = 16,
157 DHCPV6_OPTION_CODE_VENDOR_OPTS = 17,
158 DHCPV6_OPTION_CODE_INTERFACE_ID = 18,
159 DHCPV6_OPTION_CODE_RECONF_MSG = 19,
160 DHCPV6_OPTION_CODE_RECONF_ACCEPT = 20,
161 DHCPV6_OPTION_CODE_IA_PD = 25,
162 DHCPV6_OPTION_CODE_IAPREFIX = 26,
163 DHCPV6_OPTION_CODE_INFORMATION_REFRESH_TIME = 32,
164 DHCPV6_OPTION_CODE_SOL_MAX_RT = 82,
165 DHCPV6_OPTION_CODE_INF_MAX_RT = 83,
166 };
167
168 /* DHCPv6 option codes, RFC8415, ch. 21.13. */
169 enum dhcpv6_status_code {
170 DHCPV6_STATUS_SUCCESS = 0,
171 DHCPV6_STATUS_UNSPEC_FAIL = 1,
172 DHCPV6_STATUS_NO_ADDR_AVAIL = 2,
173 DHCPV6_STATUS_NO_BINDING = 3,
174 DHCPV6_STATUS_NOT_ON_LINK = 4,
175 DHCPV6_STATUS_USE_MULTICAST = 5,
176 DHCPV6_STATUS_NO_PREFIX_AVAIL = 6,
177 };
178
179 /* DHCPv6 Unique Identifier types, RFC8415, ch. 11.1. */
180 enum dhcpv6_duid_type {
181 DHCPV6_DUID_TYPE_LLT = 1, /* Based on Link-Layer Address Plus Time */
182 DHCPV6_DUID_TYPE_EN = 2, /* Assigned by Vendor Based on Enterprise Number */
183 DHCPV6_DUID_TYPE_LL = 3, /* Based on Link-Layer Address */
184 DHCPV6_DUID_TYPE_UUID = 4, /* Based on Universally Unique Identifier */
185 };
186
187 #if defined(CONFIG_NET_DHCPV6)
188 int net_dhcpv6_init(void);
189 #else
net_dhcpv6_init(void)190 static inline int net_dhcpv6_init(void)
191 {
192 return 0;
193 }
194 #endif /* CONFIG_NET_DHCPV6 */
195
196 #endif /* DHCPV6_INTERNAL_H_ */
197