]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h
CryptoPkg/BaseCryptLib: Make HMAC_CTX size backward compatible
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / Dhcp6Impl.h
1 /** @file
2 Dhcp6 internal data structure and definition declaration.
3
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef __EFI_DHCP6_IMPL_H__
11 #define __EFI_DHCP6_IMPL_H__
12
13
14 #include <Uefi.h>
15
16 #include <IndustryStandard/Dhcp.h>
17
18 #include <Protocol/Dhcp6.h>
19 #include <Protocol/Udp6.h>
20 #include <Protocol/Ip6Config.h>
21 #include <Protocol/ServiceBinding.h>
22 #include <Protocol/DriverBinding.h>
23
24 #include <Library/UdpIoLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/NetLib.h>
33 #include <Library/PrintLib.h>
34 #include <Guid/ZeroGuid.h>
35
36
37 typedef struct _DHCP6_IA_CB DHCP6_IA_CB;
38 typedef struct _DHCP6_INF_CB DHCP6_INF_CB;
39 typedef struct _DHCP6_TX_CB DHCP6_TX_CB;
40 typedef struct _DHCP6_SERVICE DHCP6_SERVICE;
41 typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE;
42
43 #include "Dhcp6Utility.h"
44 #include "Dhcp6Io.h"
45 #include "Dhcp6Driver.h"
46
47 #define DHCP6_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'S')
48 #define DHCP6_INSTANCE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'I')
49
50 #define DHCP6_PACKET_ALL 0
51 #define DHCP6_PACKET_STATEFUL 1
52 #define DHCP6_PACKET_STATELESS 2
53
54 #define DHCP6_BASE_PACKET_SIZE 1024
55
56 #define DHCP6_PORT_CLIENT 546
57 #define DHCP6_PORT_SERVER 547
58
59 #define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
60
61 #define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
62 #define DHCP6_SERVICE_FROM_THIS(Service) CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
63
64 extern EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress;
65 extern EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate;
66
67 //
68 // Control block for each IA.
69 //
70 struct _DHCP6_IA_CB {
71 EFI_DHCP6_IA *Ia;
72 UINT32 T1;
73 UINT32 T2;
74 UINT32 AllExpireTime;
75 UINT32 LeaseTime;
76 };
77
78 //
79 // Control block for each transmitted message.
80 //
81 struct _DHCP6_TX_CB {
82 LIST_ENTRY Link;
83 UINT32 Xid;
84 EFI_DHCP6_PACKET *TxPacket;
85 EFI_DHCP6_RETRANSMISSION RetryCtl;
86 UINT32 RetryCnt;
87 UINT32 RetryExp;
88 UINT32 RetryLos;
89 UINT32 TickTime;
90 UINT16 *Elapsed;
91 BOOLEAN SolicitRetry;
92 };
93
94 //
95 // Control block for each info-request message.
96 //
97 struct _DHCP6_INF_CB {
98 LIST_ENTRY Link;
99 UINT32 Xid;
100 EFI_DHCP6_INFO_CALLBACK ReplyCallback;
101 VOID *CallbackContext;
102 EFI_EVENT TimeoutEvent;
103 };
104
105 //
106 // Control block for Dhcp6 instance, it's per configuration data.
107 //
108 struct _DHCP6_INSTANCE {
109 UINT32 Signature;
110 EFI_HANDLE Handle;
111 DHCP6_SERVICE *Service;
112 LIST_ENTRY Link;
113 EFI_DHCP6_PROTOCOL Dhcp6;
114 EFI_EVENT Timer;
115 EFI_DHCP6_CONFIG_DATA *Config;
116 EFI_DHCP6_IA *CacheIa;
117 DHCP6_IA_CB IaCb;
118 LIST_ENTRY TxList;
119 LIST_ENTRY InfList;
120 EFI_DHCP6_PACKET *AdSelect;
121 UINT8 AdPref;
122 EFI_IPv6_ADDRESS *Unicast;
123 volatile EFI_STATUS UdpSts;
124 BOOLEAN InDestroy;
125 BOOLEAN MediaPresent;
126 //
127 // StartTime is used to calculate the 'elapsed-time' option. Refer to RFC3315,
128 // the elapsed-time is amount of time since the client began its current DHCP transaction.
129 //
130 UINT64 StartTime;
131 };
132
133 //
134 // Control block for Dhcp6 service, it's per Nic handle.
135 //
136 struct _DHCP6_SERVICE {
137 UINT32 Signature;
138 EFI_HANDLE Controller;
139 EFI_HANDLE Image;
140 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
141 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
142 EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg;
143 EFI_DHCP6_DUID *ClientId;
144 UDP_IO *UdpIo;
145 UINT32 Xid;
146 LIST_ENTRY Child;
147 UINTN NumOfChild;
148 };
149
150 /**
151 Starts the DHCPv6 standard S.A.R.R. process.
152
153 The Start() function starts the DHCPv6 standard process. This function can
154 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
155 If the DHCP process completes successfully, the state of the Dhcp6 instance
156 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
157 Dhcp6Bound state.
158 Refer to rfc-3315 for precise state transitions during this process. At the
159 time when each event occurs in this process, the callback function that was set
160 by EFI_DHCP6_PROTOCOL.Configure() will be called and the user can take this
161 opportunity to control the process.
162
163 @param[in] This The pointer to Dhcp6 protocol.
164
165 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it
166 completed when CompletionEvent was NULL.
167 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
168 @retval EFI_INVALID_PARAMETER This is NULL.
169 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
170 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
171 response was received from the server within the
172 specified timeout value.
173 @retval EFI_ABORTED The user aborted the DHCPv6 process.
174 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
175 standard process.
176 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
177
178 **/
179 EFI_STATUS
180 EFIAPI
181 EfiDhcp6Start (
182 IN EFI_DHCP6_PROTOCOL *This
183 );
184
185 /**
186 Stops the DHCPv6 standard S.A.R.R. process.
187
188 The Stop() function is used to stop the DHCPv6 standard process. After this
189 function is called successfully, the state of Dhcp6 instance is transferred
190 into the Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
191 before DHCPv6 standard process can be started again. This function can be
192 called when the Dhcp6 instance is in any state.
193
194 @param[in] This The pointer to the Dhcp6 protocol.
195
196 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
197 @retval EFI_INVALID_PARAMETER This is NULL.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 EfiDhcp6Stop (
203 IN EFI_DHCP6_PROTOCOL *This
204 );
205
206 /**
207 Returns the current operating mode data for the Dhcp6 instance.
208
209 The GetModeData() function returns the current operating mode and
210 cached data packet for the Dhcp6 instance.
211
212 @param[in] This The pointer to the Dhcp6 protocol.
213 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
214 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
215
216 @retval EFI_SUCCESS The mode data was returned.
217 @retval EFI_INVALID_PARAMETER This is NULL.
218 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance has not
219 been configured when Dhcp6ConfigData is
220 not NULL.
221 **/
222 EFI_STATUS
223 EFIAPI
224 EfiDhcp6GetModeData (
225 IN EFI_DHCP6_PROTOCOL *This,
226 OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL,
227 OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL
228 );
229
230 /**
231 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
232
233 The Configure() function is used to initialize or clean up the configuration
234 data of the Dhcp6 instance:
235 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
236 configuration data will be initialized in the Dhcp6 instance and the state
237 of the configured IA will be transferred into Dhcp6Init.
238 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
239 configuration data will be cleaned up and no IA will be associated with
240 the Dhcp6 instance.
241 To update the configuration data for an Dhcp6 instance, the original data
242 must be cleaned up before setting the new configuration data.
243
244 @param[in] This The pointer to the Dhcp6 protocol
245 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
246
247 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
248 Dhcp6Init state, or cleaned up the original
249 configuration setting.
250 @retval EFI_ACCESS_DENIED The Dhcp6 instance has been already configured
251 when Dhcp6CfgData is not NULL.
252 The Dhcp6 instance has already started the
253 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
254 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
255 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
256 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
257
258 **/
259 EFI_STATUS
260 EFIAPI
261 EfiDhcp6Configure (
262 IN EFI_DHCP6_PROTOCOL *This,
263 IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL
264 );
265
266 /**
267 Request configuration information without the assignment of any
268 Ia addresses of the client.
269
270 The InfoRequest() function is used to request configuration information
271 without the assignment of any IPv6 address of the client. Client sends
272 out Information Request packet to obtain the required configuration
273 information, and DHCPv6 server responds with Reply packet containing
274 the information for the client. The received Reply packet will be passed
275 to the user by ReplyCallback function. If user returns EFI_NOT_READY from
276 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
277 packets unless timeout according to the Retransmission parameter.
278 Otherwise, the Information Request exchange process will be finished
279 successfully if user returns EFI_SUCCESS from ReplyCallback.
280
281 @param[in] This The pointer to the Dhcp6 protocol.
282 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
283 Identifier option and include it into Information Request
284 packet. Otherwise, Client Identifier option will not be included.
285 @param[in] OptionRequest The pointer to the buffer of option request options.
286 @param[in] OptionCount The option number in the OptionList.
287 @param[in] OptionList The list of appended options.
288 @param[in] Retransmission The pointer to the retransmission of the message.
289 @param[in] TimeoutEvent The event of timeout.
290 @param[in] ReplyCallback The callback function when a reply was received.
291 @param[in] CallbackContext The pointer to the parameter passed to the callback.
292
293 @retval EFI_SUCCESS The DHCPv6 information request exchange process
294 completed when TimeoutEvent is NULL. Information
295 Request packet has been sent to DHCPv6 server when
296 TimeoutEvent is not NULL.
297 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
298 because of no response, or not all requested-options
299 are responded to by DHCPv6 servers when Timeout happened.
300 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
301 by the user.
302 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
303 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
304 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
305
306 **/
307 EFI_STATUS
308 EFIAPI
309 EfiDhcp6InfoRequest (
310 IN EFI_DHCP6_PROTOCOL *This,
311 IN BOOLEAN SendClientId,
312 IN EFI_DHCP6_PACKET_OPTION *OptionRequest,
313 IN UINT32 OptionCount,
314 IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL,
315 IN EFI_DHCP6_RETRANSMISSION *Retransmission,
316 IN EFI_EVENT TimeoutEvent OPTIONAL,
317 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback,
318 IN VOID *CallbackContext OPTIONAL
319 );
320
321 /**
322 Manually extend the valid and preferred lifetimes for the IPv6 addresses
323 of the configured IA and update other configuration parameters by sending
324 Renew or Rebind packet.
325
326 The RenewRebind() function is used to manually extend the valid and preferred
327 lifetimes for the IPv6 addresses of the configured IA and update other
328 configuration parameters by sending a Renew or Rebind packet.
329 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
330 it will send Renew packet to the previously DHCPv6 server and transfer the
331 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
332 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
333 If fails, the state transfers to Dhcp6Bound but the timer continues.
334 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
335 it will send a Rebind packet. If a valid Reply packet is received, the state transfers
336 to Dhcp6Bound, and the valid and preferred timer restarts. If it fails, the state
337 transfers to Dhcp6Init, and the IA can't be used.
338
339 @param[in] This The pointer to the Dhcp6 protocol.
340 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
341 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
342
343 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process
344 completed and at least one IPv6 address of the
345 configured IA was bound again when
346 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
347 The EFI DHCPv6 Protocol instance has sent Renew
348 or Rebind packet when
349 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
350 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
351 state of the configured IA is not in Dhcp6Bound.
352 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
353 Dhcp6Renewing when RebindRequest is FALSE.
354 The state of the configured IA has already entered
355 Dhcp6Rebinding when RebindRequest is TRUE.
356 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
357 by user.
358 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
359 because of no response.
360 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
361 IA after the DHCPv6 renew/rebind exchange process.
362 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
363 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
364
365 **/
366 EFI_STATUS
367 EFIAPI
368 EfiDhcp6RenewRebind (
369 IN EFI_DHCP6_PROTOCOL *This,
370 IN BOOLEAN RebindRequest
371 );
372
373 /**
374 Inform that one or more addresses assigned by a server are already
375 in use by another node.
376
377 The Decline() function is used to manually decline the assignment of
378 IPv6 addresses, which have been already used by another node. If all
379 IPv6 addresses of the configured IA are declined through this function,
380 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
381 Otherwise, the state of the IA will restore to Dhcp6Bound after the
382 declining process. The Decline() can only be called when the IA is in
383 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
384 this function is a blocking operation. It will return after the
385 declining process finishes, or aborted by user.
386
387 @param[in] This The pointer to the Dhcp6 protocol.
388 @param[in] AddressCount The number of declining addresses.
389 @param[in] Addresses The pointer to the buffer stored the declining
390 addresses.
391
392 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
393 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
394 The Dhcp6 instance has sent Decline packet when
395 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
396 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
397 state of the configured IA is not in Dhcp6Bound.
398 @retval EFI_ABORTED The DHCPv6 decline exchange process was aborted by the user.
399 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
400 the configured IA for this instance.
401 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
402 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
403
404 **/
405 EFI_STATUS
406 EFIAPI
407 EfiDhcp6Decline (
408 IN EFI_DHCP6_PROTOCOL *This,
409 IN UINT32 AddressCount,
410 IN EFI_IPv6_ADDRESS *Addresses
411 );
412
413 /**
414 Release one or more addresses associated with the configured Ia
415 for the current instance.
416
417 The Release() function is used to manually release the one or more
418 IPv6 address. If AddressCount is zero, it will release all IPv6
419 addresses of the configured IA. If all IPv6 addresses of the IA are
420 released through this function, the state of the IA will switch
421 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
422 IA will restore to Dhcp6Bound after the releasing process.
423 The Release() can only be called when the IA is in a Dhcp6Bound state.
424 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
425 a blocking operation. It will return after the releasing process
426 finishes, or aborted by user.
427
428 @param[in] This The pointer to the Dhcp6 protocol.
429 @param[in] AddressCount The number of releasing addresses.
430 @param[in] Addresses The pointer to the buffer stored the releasing
431 addresses.
432 @retval EFI_SUCCESS The DHCPv6 release exchange process has
433 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
434 is NULL. The Dhcp6 instance has sent Release
435 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
436 is not NULL.
437 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
438 state of the configured IA is not in Dhcp6Bound.
439 @retval EFI_ABORTED The DHCPv6 release exchange process was aborted by the user.
440 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
441 the configured IA for this instance.
442 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
443 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
444
445 **/
446 EFI_STATUS
447 EFIAPI
448 EfiDhcp6Release (
449 IN EFI_DHCP6_PROTOCOL *This,
450 IN UINT32 AddressCount,
451 IN EFI_IPv6_ADDRESS *Addresses
452 );
453
454 /**
455 Parse the option data in the Dhcp6 packet.
456
457 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
458
459 @param[in] This The pointer to the Dhcp6 protocol.
460 @param[in] Packet The pointer to the Dhcp6 packet.
461 @param[in, out] OptionCount The number of option in the packet.
462 @param[out] PacketOptionList The array of pointers to the each option in the packet.
463
464 @retval EFI_SUCCESS The packet was successfully parsed.
465 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
466 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
467 that were found in the Packet.
468
469 **/
470 EFI_STATUS
471 EFIAPI
472 EfiDhcp6Parse (
473 IN EFI_DHCP6_PROTOCOL *This,
474 IN EFI_DHCP6_PACKET *Packet,
475 IN OUT UINT32 *OptionCount,
476 OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL
477 );
478
479 #endif