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