1 | /** @file
|
---|
2 | Dhcp6 support functions declaration.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #ifndef __EFI_DHCP6_UTILITY_H__
|
---|
11 | #define __EFI_DHCP6_UTILITY_H__
|
---|
12 |
|
---|
13 | #define DHCP6_10_BIT_MASK 0x3ff
|
---|
14 | #define DHCP6_DAD_ADDITIONAL_DELAY 30000000 // 3 seconds
|
---|
15 |
|
---|
16 | /**
|
---|
17 | Generate client Duid in the format of Duid-llt.
|
---|
18 |
|
---|
19 | @param[in] Mode The pointer to the mode of SNP.
|
---|
20 |
|
---|
21 | @retval NULL if failed to generate client Id.
|
---|
22 | @retval Others The pointer to the new client id.
|
---|
23 |
|
---|
24 | **/
|
---|
25 | EFI_DHCP6_DUID *
|
---|
26 | Dhcp6GenerateClientId (
|
---|
27 | IN EFI_SIMPLE_NETWORK_MODE *Mode
|
---|
28 | );
|
---|
29 |
|
---|
30 | /**
|
---|
31 | Copy the Dhcp6 configure data.
|
---|
32 |
|
---|
33 | @param[in] DstCfg The pointer to the destination configure data.
|
---|
34 | @param[in] SorCfg The pointer to the source configure data.
|
---|
35 |
|
---|
36 | @retval EFI_SUCCESS Copy the content from SorCfg from DstCfg successfully.
|
---|
37 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
|
---|
38 |
|
---|
39 | **/
|
---|
40 | EFI_STATUS
|
---|
41 | Dhcp6CopyConfigData (
|
---|
42 | IN EFI_DHCP6_CONFIG_DATA *DstCfg,
|
---|
43 | IN EFI_DHCP6_CONFIG_DATA *SorCfg
|
---|
44 | );
|
---|
45 |
|
---|
46 | /**
|
---|
47 | Clean up the configure data.
|
---|
48 |
|
---|
49 | @param[in, out] CfgData The pointer to the configure data.
|
---|
50 |
|
---|
51 | **/
|
---|
52 | VOID
|
---|
53 | Dhcp6CleanupConfigData (
|
---|
54 | IN OUT EFI_DHCP6_CONFIG_DATA *CfgData
|
---|
55 | );
|
---|
56 |
|
---|
57 | /**
|
---|
58 | Clean up the mode data.
|
---|
59 |
|
---|
60 | @param[in, out] ModeData The pointer to the mode data.
|
---|
61 |
|
---|
62 | **/
|
---|
63 | VOID
|
---|
64 | Dhcp6CleanupModeData (
|
---|
65 | IN OUT EFI_DHCP6_MODE_DATA *ModeData
|
---|
66 | );
|
---|
67 |
|
---|
68 | /**
|
---|
69 | Calculate the expire time by the algorithm defined in rfc.
|
---|
70 |
|
---|
71 | @param[in] Base The base value of the time.
|
---|
72 | @param[in] IsFirstRt If TRUE, it is the first time to calculate expire time.
|
---|
73 | @param[in] NeedSigned If TRUE, the signed factor is needed.
|
---|
74 |
|
---|
75 | @return Expire The calculated result for the new expire time.
|
---|
76 |
|
---|
77 | **/
|
---|
78 | UINT32
|
---|
79 | Dhcp6CalculateExpireTime (
|
---|
80 | IN UINT32 Base,
|
---|
81 | IN BOOLEAN IsFirstRt,
|
---|
82 | IN BOOLEAN NeedSigned
|
---|
83 | );
|
---|
84 |
|
---|
85 | /**
|
---|
86 | Calculate the lease time by the algorithm defined in rfc.
|
---|
87 |
|
---|
88 | @param[in] IaCb The pointer to the Ia control block.
|
---|
89 |
|
---|
90 | **/
|
---|
91 | VOID
|
---|
92 | Dhcp6CalculateLeaseTime (
|
---|
93 | IN DHCP6_IA_CB *IaCb
|
---|
94 | );
|
---|
95 |
|
---|
96 | /**
|
---|
97 | Check whether the addresses are all included by the configured Ia.
|
---|
98 |
|
---|
99 | @param[in] Ia The pointer to the Ia.
|
---|
100 | @param[in] AddressCount The number of addresses.
|
---|
101 | @param[in] Addresses The pointer to the addresses buffer.
|
---|
102 |
|
---|
103 | @retval EFI_SUCCESS The addresses are all included by the configured IA.
|
---|
104 | @retval EFI_NOT_FOUND The addresses are not included by the configured IA.
|
---|
105 |
|
---|
106 | **/
|
---|
107 | EFI_STATUS
|
---|
108 | Dhcp6CheckAddress (
|
---|
109 | IN EFI_DHCP6_IA *Ia,
|
---|
110 | IN UINT32 AddressCount,
|
---|
111 | IN EFI_IPv6_ADDRESS *Addresses
|
---|
112 | );
|
---|
113 |
|
---|
114 | /**
|
---|
115 | Deprive the addresses from current Ia, and generate another eliminated Ia.
|
---|
116 |
|
---|
117 | @param[in] Ia The pointer to the Ia.
|
---|
118 | @param[in] AddressCount The number of addresses.
|
---|
119 | @param[in] Addresses The pointer to the addresses buffer.
|
---|
120 |
|
---|
121 | @retval NULL If failed to generate the deprived Ia.
|
---|
122 | @retval others The pointer to the deprived Ia.
|
---|
123 |
|
---|
124 | **/
|
---|
125 | EFI_DHCP6_IA *
|
---|
126 | Dhcp6DepriveAddress (
|
---|
127 | IN EFI_DHCP6_IA *Ia,
|
---|
128 | IN UINT32 AddressCount,
|
---|
129 | IN EFI_IPv6_ADDRESS *Addresses
|
---|
130 | );
|
---|
131 |
|
---|
132 | /**
|
---|
133 | The dummy ext buffer free callback routine.
|
---|
134 |
|
---|
135 | @param[in] Arg The pointer to the parameter.
|
---|
136 |
|
---|
137 | **/
|
---|
138 | VOID
|
---|
139 | EFIAPI
|
---|
140 | Dhcp6DummyExtFree (
|
---|
141 | IN VOID *Arg
|
---|
142 | );
|
---|
143 |
|
---|
144 | /**
|
---|
145 | The callback routine once message transmitted.
|
---|
146 |
|
---|
147 | @param[in] Wrap The pointer to the received net buffer.
|
---|
148 | @param[in] EndPoint The pointer to the udp end point.
|
---|
149 | @param[in] IoStatus The return status from udp io.
|
---|
150 | @param[in] Context The opaque parameter to the function.
|
---|
151 |
|
---|
152 | **/
|
---|
153 | VOID
|
---|
154 | EFIAPI
|
---|
155 | Dhcp6OnTransmitted (
|
---|
156 | IN NET_BUF *Wrap,
|
---|
157 | IN UDP_END_POINT *EndPoint,
|
---|
158 | IN EFI_STATUS IoStatus,
|
---|
159 | IN VOID *Context
|
---|
160 | );
|
---|
161 |
|
---|
162 | /**
|
---|
163 | Append the option to Buf, update the length of packet, and move Buf to the end.
|
---|
164 |
|
---|
165 | @param[in, out] Packet A pointer to the packet, on success Packet->Length
|
---|
166 | will be updated.
|
---|
167 | @param[in, out] PacketCursor The pointer in the packet, on success PacketCursor
|
---|
168 | will be moved to the end of the option.
|
---|
169 | @param[in] OptType The option type.
|
---|
170 | @param[in] OptLen The length of option contents.
|
---|
171 | @param[in] Data The pointer to the option content.
|
---|
172 |
|
---|
173 | @retval EFI_INVALID_PARAMETER An argument provided to the function was invalid
|
---|
174 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to append the option.
|
---|
175 | @retval EFI_SUCCESS The option is appended successfully.
|
---|
176 | **/
|
---|
177 | EFI_STATUS
|
---|
178 | Dhcp6AppendOption (
|
---|
179 | IN OUT EFI_DHCP6_PACKET *Packet,
|
---|
180 | IN OUT UINT8 **PacketCursor,
|
---|
181 | IN UINT16 OptType,
|
---|
182 | IN UINT16 OptLen,
|
---|
183 | IN UINT8 *Data
|
---|
184 | );
|
---|
185 |
|
---|
186 | /**
|
---|
187 | Append the appointed Ia option to Buf, update the Ia option length, and move Buf
|
---|
188 | to the end of the option.
|
---|
189 | @param[in, out] Packet A pointer to the packet, on success Packet->Length
|
---|
190 | will be updated.
|
---|
191 | @param[in, out] PacketCursor The pointer in the packet, on success PacketCursor
|
---|
192 | will be moved to the end of the option.
|
---|
193 | @param[in] Ia The pointer to the Ia.
|
---|
194 | @param[in] T1 The time of T1.
|
---|
195 | @param[in] T2 The time of T2.
|
---|
196 | @param[in] MessageType Message type of DHCP6 package.
|
---|
197 |
|
---|
198 | @retval EFI_INVALID_PARAMETER An argument provided to the function was invalid
|
---|
199 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to append the option.
|
---|
200 | @retval EFI_SUCCESS The option is appended successfully.
|
---|
201 | **/
|
---|
202 | EFI_STATUS
|
---|
203 | Dhcp6AppendIaOption (
|
---|
204 | IN OUT EFI_DHCP6_PACKET *Packet,
|
---|
205 | IN OUT UINT8 **PacketCursor,
|
---|
206 | IN EFI_DHCP6_IA *Ia,
|
---|
207 | IN UINT32 T1,
|
---|
208 | IN UINT32 T2,
|
---|
209 | IN UINT32 MessageType
|
---|
210 | );
|
---|
211 |
|
---|
212 | /**
|
---|
213 | Append the appointed Elapsed time option to Buf, and move Buf to the end.
|
---|
214 |
|
---|
215 | @param[in, out] Packet A pointer to the packet, on success Packet->Length
|
---|
216 | @param[in, out] PacketCursor The pointer in the packet, on success PacketCursor
|
---|
217 | will be moved to the end of the option.
|
---|
218 | @param[in] Instance The pointer to the Dhcp6 instance.
|
---|
219 | @param[out] Elapsed The pointer to the elapsed time value in
|
---|
220 | the generated packet.
|
---|
221 |
|
---|
222 | @retval EFI_INVALID_PARAMETER An argument provided to the function was invalid
|
---|
223 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to append the option.
|
---|
224 | @retval EFI_SUCCESS The option is appended successfully.
|
---|
225 |
|
---|
226 | **/
|
---|
227 | EFI_STATUS
|
---|
228 | Dhcp6AppendETOption (
|
---|
229 | IN OUT EFI_DHCP6_PACKET *Packet,
|
---|
230 | IN OUT UINT8 **PacketCursor,
|
---|
231 | IN DHCP6_INSTANCE *Instance,
|
---|
232 | OUT UINT16 **Elapsed
|
---|
233 | );
|
---|
234 |
|
---|
235 | /**
|
---|
236 | Set the elapsed time based on the given instance and the pointer to the
|
---|
237 | elapsed time option.
|
---|
238 |
|
---|
239 | @retval EFI_INVALID_PARAMETER An argument provided to the function was invalid
|
---|
240 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to append the option.
|
---|
241 | @retval EFI_SUCCESS The option is appended successfully.
|
---|
242 | **/
|
---|
243 | VOID
|
---|
244 | SetElapsedTime (
|
---|
245 | IN UINT16 *Elapsed,
|
---|
246 | IN DHCP6_INSTANCE *Instance
|
---|
247 | );
|
---|
248 |
|
---|
249 | /**
|
---|
250 | Seek the address of the first byte of the option header.
|
---|
251 |
|
---|
252 | @param[in] Buf The pointer to buffer.
|
---|
253 | @param[in] SeekLen The length to seek.
|
---|
254 | @param[in] OptType The option type.
|
---|
255 |
|
---|
256 | @retval NULL If failed to seek the option.
|
---|
257 | @retval others The position to the option.
|
---|
258 |
|
---|
259 | **/
|
---|
260 | UINT8 *
|
---|
261 | Dhcp6SeekOption (
|
---|
262 | IN UINT8 *Buf,
|
---|
263 | IN UINT32 SeekLen,
|
---|
264 | IN UINT16 OptType
|
---|
265 | );
|
---|
266 |
|
---|
267 | /**
|
---|
268 | Seek the address of the first byte of the Ia option header.
|
---|
269 |
|
---|
270 | @param[in] Buf The pointer to the buffer.
|
---|
271 | @param[in] SeekLen The length to seek.
|
---|
272 | @param[in] IaDesc The pointer to the Ia descriptor.
|
---|
273 |
|
---|
274 | @retval NULL If failed to seek the Ia option.
|
---|
275 | @retval others The position to the Ia option.
|
---|
276 |
|
---|
277 | **/
|
---|
278 | UINT8 *
|
---|
279 | Dhcp6SeekIaOption (
|
---|
280 | IN UINT8 *Buf,
|
---|
281 | IN UINT32 SeekLen,
|
---|
282 | IN EFI_DHCP6_IA_DESCRIPTOR *IaDesc
|
---|
283 | );
|
---|
284 |
|
---|
285 | /**
|
---|
286 | Parse the address option and update the address info.
|
---|
287 |
|
---|
288 | @param[in] CurrentIa The pointer to the Ia Address in control block.
|
---|
289 | @param[in] IaInnerOpt The pointer to the buffer.
|
---|
290 | @param[in] IaInnerLen The length to parse.
|
---|
291 | @param[out] AddrNum The number of addresses.
|
---|
292 | @param[in, out] AddrBuf The pointer to the address buffer.
|
---|
293 |
|
---|
294 | **/
|
---|
295 | VOID
|
---|
296 | Dhcp6ParseAddrOption (
|
---|
297 | IN EFI_DHCP6_IA *CurrentIa,
|
---|
298 | IN UINT8 *IaInnerOpt,
|
---|
299 | IN UINT16 IaInnerLen,
|
---|
300 | OUT UINT32 *AddrNum,
|
---|
301 | IN OUT EFI_DHCP6_IA_ADDRESS *AddrBuf
|
---|
302 | );
|
---|
303 |
|
---|
304 | /**
|
---|
305 | Create a control block for the Ia according to the corresponding options.
|
---|
306 |
|
---|
307 | @param[in] Instance The pointer to DHCP6 Instance.
|
---|
308 | @param[in] IaInnerOpt The pointer to the inner options in the Ia option.
|
---|
309 | @param[in] IaInnerLen The length of all the inner options in the Ia option.
|
---|
310 | @param[in] T1 T1 time in the Ia option.
|
---|
311 | @param[in] T2 T2 time in the Ia option.
|
---|
312 |
|
---|
313 | @retval EFI_NOT_FOUND No valid IA option is found.
|
---|
314 | @retval EFI_SUCCESS Create an IA control block successfully.
|
---|
315 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
|
---|
316 | @retval EFI_DEVICE_ERROR An unexpected error.
|
---|
317 |
|
---|
318 | **/
|
---|
319 | EFI_STATUS
|
---|
320 | Dhcp6GenerateIaCb (
|
---|
321 | IN DHCP6_INSTANCE *Instance,
|
---|
322 | IN UINT8 *IaInnerOpt,
|
---|
323 | IN UINT16 IaInnerLen,
|
---|
324 | IN UINT32 T1,
|
---|
325 | IN UINT32 T2
|
---|
326 | );
|
---|
327 |
|
---|
328 | /**
|
---|
329 | Cache the current IA configuration information.
|
---|
330 |
|
---|
331 | @param[in] Instance The pointer to DHCP6 Instance.
|
---|
332 |
|
---|
333 | @retval EFI_SUCCESS Cache the current IA successfully.
|
---|
334 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
|
---|
335 |
|
---|
336 | **/
|
---|
337 | EFI_STATUS
|
---|
338 | Dhcp6CacheIa (
|
---|
339 | IN DHCP6_INSTANCE *Instance
|
---|
340 | );
|
---|
341 |
|
---|
342 | /**
|
---|
343 | Append CacheIa to the current IA. Meanwhile, clear CacheIa.ValidLifetime to 0.
|
---|
344 |
|
---|
345 | @param[in] Instance The pointer to DHCP6 instance.
|
---|
346 |
|
---|
347 | **/
|
---|
348 | VOID
|
---|
349 | Dhcp6AppendCacheIa (
|
---|
350 | IN DHCP6_INSTANCE *Instance
|
---|
351 | );
|
---|
352 |
|
---|
353 | /**
|
---|
354 | Calculate the Dhcp6 get mapping timeout by adding additional delay to the IP6 DAD transmits count.
|
---|
355 |
|
---|
356 | @param[in] Ip6Cfg The pointer to Ip6 config protocol.
|
---|
357 | @param[out] TimeOut The time out value in 100ns units.
|
---|
358 |
|
---|
359 | @retval EFI_INVALID_PARAMETER Input parameters are invalid.
|
---|
360 | @retval EFI_SUCCESS Calculate the time out value successfully.
|
---|
361 | **/
|
---|
362 | EFI_STATUS
|
---|
363 | Dhcp6GetMappingTimeOut (
|
---|
364 | IN EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg,
|
---|
365 | OUT UINTN *TimeOut
|
---|
366 | );
|
---|
367 |
|
---|
368 | #endif
|
---|