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