2 Dhcp6 internal data structure and definition declaration.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
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.
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.
16 #ifndef __EFI_DHCP6_IMPL_H__
17 #define __EFI_DHCP6_IMPL_H__
22 #include <Protocol/Dhcp6.h>
23 #include <Protocol/Udp6.h>
24 #include <Protocol/ServiceBinding.h>
25 #include <Protocol/DriverBinding.h>
27 #include <Library/UdpIoLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/NetLib.h>
38 typedef struct _DHCP6_IA_CB DHCP6_IA_CB
;
39 typedef struct _DHCP6_INF_CB DHCP6_INF_CB
;
40 typedef struct _DHCP6_TX_CB DHCP6_TX_CB
;
41 typedef struct _DHCP6_SERVICE DHCP6_SERVICE
;
42 typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE
;
44 #include "Dhcp6Utility.h"
46 #include "Dhcp6Driver.h"
48 #define DHCP6_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'S')
49 #define DHCP6_INSTANCE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'I')
52 // Transmit parameters of solicit message, refers to section-5.5 of rfc-3315.
54 #define DHCP6_SOL_MAX_DELAY 1
55 #define DHCP6_SOL_IRT 1
56 #define DHCP6_SOL_MRC 0
57 #define DHCP6_SOL_MRT 120
58 #define DHCP6_SOL_MRD 0
60 // Transmit parameters of request message, refers to section-5.5 of rfc-3315.
62 #define DHCP6_REQ_IRT 1
63 #define DHCP6_REQ_MRC 10
64 #define DHCP6_REQ_MRT 30
65 #define DHCP6_REQ_MRD 0
67 // Transmit parameters of confirm message, refers to section-5.5 of rfc-3315.
69 #define DHCP6_CNF_MAX_DELAY 1
70 #define DHCP6_CNF_IRT 1
71 #define DHCP6_CNF_MRC 0
72 #define DHCP6_CNF_MRT 4
73 #define DHCP6_CNF_MRD 10
75 // Transmit parameters of renew message, refers to section-5.5 of rfc-3315.
77 #define DHCP6_REN_IRT 10
78 #define DHCP6_REN_MRC 0
79 #define DHCP6_REN_MRT 600
80 #define DHCP6_REN_MRD 0
82 // Transmit parameters of rebind message, refers to section-5.5 of rfc-3315.
84 #define DHCP6_REB_IRT 10
85 #define DHCP6_REB_MRC 0
86 #define DHCP6_REB_MRT 600
87 #define DHCP6_REB_MRD 0
89 // Transmit parameters of information request message, refers to section-5.5 of rfc-3315.
91 #define DHCP6_INF_MAX_DELAY 1
92 #define DHCP6_INF_IRT 1
93 #define DHCP6_INF_MRC 0
94 #define DHCP6_INF_MRT 120
95 #define DHCP6_INF_MRD 0
97 // Transmit parameters of release message, refers to section-5.5 of rfc-3315.
99 #define DHCP6_REL_IRT 1
100 #define DHCP6_REL_MRC 5
101 #define DHCP6_REL_MRT 0
102 #define DHCP6_REL_MRD 0
104 // Transmit parameters of decline message, refers to section-5.5 of rfc-3315.
106 #define DHCP6_DEC_IRT 1
107 #define DHCP6_DEC_MRC 5
108 #define DHCP6_DEC_MRT 0
109 #define DHCP6_DEC_MRD 0
111 #define DHCP6_PACKET_ALL 0
112 #define DHCP6_PACKET_STATEFUL 1
113 #define DHCP6_PACKET_STATELESS 2
115 #define DHCP6_BASE_PACKET_SIZE 1024
117 #define DHCP6_PORT_CLIENT 546
118 #define DHCP6_PORT_SERVER 547
120 #define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
121 #define DHCP6_SERVICE_FROM_THIS(Service) CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
123 extern EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress
;
124 extern EFI_IPv6_ADDRESS mAllDhcpServersAddress
;
125 extern EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
;
128 // Enumeration of Dhcp6 message type, refers to section-5.3 of rfc-3315.
132 Dhcp6MsgAdvertise
= 2,
140 Dhcp6MsgReconfigure
= 10,
141 Dhcp6MsgInfoRequest
= 11
145 // Enumeration of option code in Dhcp6 packet, refers to section-24.3 of rfc-3315.
148 Dhcp6OptClientId
= 1,
149 Dhcp6OptServerId
= 2,
153 Dhcp6OptRequestOption
= 6,
154 Dhcp6OptPreference
= 7,
155 Dhcp6OptElapsedTime
= 8,
156 Dhcp6OptReplayMessage
= 9,
157 Dhcp6OptAuthentication
= 11,
158 Dhcp6OptServerUnicast
= 12,
159 Dhcp6OptStatusCode
= 13,
160 Dhcp6OptRapidCommit
= 14,
161 Dhcp6OptUserClass
= 15,
162 Dhcp6OptVendorClass
= 16,
163 Dhcp6OptVendorInfo
= 17,
164 Dhcp6OptInterfaceId
= 18,
165 Dhcp6OptReconfigMessage
= 19,
166 Dhcp6OptReconfigureAccept
= 20
170 // Enumeration of status code recorded by IANA, refers to section-24.4 of rfc-3315.
174 Dhcp6StsUnspecFail
= 1,
175 Dhcp6StsNoAddrsAvail
= 2,
176 Dhcp6StsNoBinding
= 3,
177 Dhcp6StsNotOnLink
= 4,
178 Dhcp6StsUseMulticast
= 5
182 // Enumeration of Duid type recorded by IANA, refers to section-24.5 of rfc-3315.
185 Dhcp6DuidTypeLlt
= 1,
188 Dhcp6DuidTypeUuid
= 4
192 // Control block for each IA.
194 struct _DHCP6_IA_CB
{
198 UINT32 AllExpireTime
;
203 // Control block for each transmitted message.
205 struct _DHCP6_TX_CB
{
208 EFI_DHCP6_PACKET
*TxPacket
;
209 EFI_DHCP6_RETRANSMISSION RetryCtl
;
215 BOOLEAN SolicitRetry
;
219 // Control block for each info-request message.
221 struct _DHCP6_INF_CB
{
224 EFI_DHCP6_INFO_CALLBACK ReplyCallback
;
225 VOID
*CallbackContext
;
226 EFI_EVENT TimeoutEvent
;
230 // Control block for Dhcp6 instance, it's per configuration data.
232 struct _DHCP6_INSTANCE
{
235 DHCP6_SERVICE
*Service
;
237 EFI_DHCP6_PROTOCOL Dhcp6
;
239 EFI_DHCP6_CONFIG_DATA
*Config
;
240 EFI_DHCP6_IA
*CacheIa
;
244 EFI_DHCP6_PACKET
*AdSelect
;
246 EFI_IPv6_ADDRESS
*Unicast
;
249 BOOLEAN MediaPresent
;
254 // Control block for Dhcp6 service, it's per Nic handle.
256 struct _DHCP6_SERVICE
{
258 EFI_HANDLE Controller
;
260 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
261 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
262 EFI_DHCP6_DUID
*ClientId
;
271 Starts the DHCPv6 standard S.A.R.R. process.
273 The Start() function starts the DHCPv6 standard process. This function can
274 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
275 If the DHCP process completes successfully, the state of the Dhcp6 instance
276 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
278 Refer to rfc-3315 for precise state transitions during this process. At the
279 time when each event occurs in this process, the callback function that was set
280 by EFI_DHCP6_PROTOCOL.Configure() will be called and the user can take this
281 opportunity to control the process.
283 @param[in] This The pointer to Dhcp6 protocol.
285 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it
286 completed when CompletionEvent was NULL.
287 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
288 @retval EFI_INVALID_PARAMETER This is NULL.
289 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
290 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
291 response was received from the server within the
292 specified timeout value.
293 @retval EFI_ABORTED The user aborted the DHCPv6 process.
294 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
296 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
302 IN EFI_DHCP6_PROTOCOL
*This
306 Stops the DHCPv6 standard S.A.R.R. process.
308 The Stop() function is used to stop the DHCPv6 standard process. After this
309 function is called successfully, the state of Dhcp6 instance is transferred
310 into the Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
311 before DHCPv6 standard process can be started again. This function can be
312 called when the Dhcp6 instance is in any state.
314 @param[in] This The pointer to the Dhcp6 protocol.
316 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
317 @retval EFI_INVALID_PARAMETER This is NULL.
323 IN EFI_DHCP6_PROTOCOL
*This
327 Returns the current operating mode data for the Dhcp6 instance.
329 The GetModeData() function returns the current operating mode and
330 cached data packet for the Dhcp6 instance.
332 @param[in] This The pointer to the Dhcp6 protocol.
333 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
334 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
336 @retval EFI_SUCCESS The mode data was returned.
337 @retval EFI_INVALID_PARAMETER This is NULL.
338 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance has not
339 been configured when Dhcp6ConfigData is
344 EfiDhcp6GetModeData (
345 IN EFI_DHCP6_PROTOCOL
*This
,
346 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
347 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
351 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
353 The Configure() function is used to initialize or clean up the configuration
354 data of the Dhcp6 instance:
355 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
356 configuration data will be initialized in the Dhcp6 instance and the state
357 of the configured IA will be transferred into Dhcp6Init.
358 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
359 configuration data will be cleaned up and no IA will be associated with
361 To update the configuration data for an Dhcp6 instance, the original data
362 must be cleaned up before setting the new configuration data.
364 @param[in] This The pointer to the Dhcp6 protocol
365 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
367 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
368 Dhcp6Init state, or cleaned up the original
369 configuration setting.
370 @retval EFI_ACCESS_DENIED The Dhcp6 instance has been already configured
371 when Dhcp6CfgData is not NULL.
372 The Dhcp6 instance has already started the
373 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
374 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
375 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
376 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
382 IN EFI_DHCP6_PROTOCOL
*This
,
383 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
387 Request configuration information without the assignment of any
388 Ia addresses of the client.
390 The InfoRequest() function is used to request configuration information
391 without the assignment of any IPv6 address of the client. Client sends
392 out Information Request packet to obtain the required configuration
393 information, and DHCPv6 server responds with Reply packet containing
394 the information for the client. The received Reply packet will be passed
395 to the user by ReplyCallback function. If user returns EFI_NOT_READY from
396 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
397 packets unless timeout according to the Retransmission parameter.
398 Otherwise, the Information Request exchange process will be finished
399 successfully if user returns EFI_SUCCESS from ReplyCallback.
401 @param[in] This The pointer to the Dhcp6 protocol.
402 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
403 Identifier option and include it into Information Request
404 packet. Otherwise, Client Identifier option will not be included.
405 @param[in] OptionRequest The pointer to the buffer of option request options.
406 @param[in] OptionCount The option number in the OptionList.
407 @param[in] OptionList The list of appended options.
408 @param[in] Retransmission The pointer to the retransmission of the message.
409 @param[in] TimeoutEvent The event of timeout.
410 @param[in] ReplyCallback The callback function when a reply was received.
411 @param[in] CallbackContext The pointer to the parameter passed to the callback.
413 @retval EFI_SUCCESS The DHCPv6 information request exchange process
414 completed when TimeoutEvent is NULL. Information
415 Request packet has been sent to DHCPv6 server when
416 TimeoutEvent is not NULL.
417 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
418 because of no response, or not all requested-options
419 are responded to by DHCPv6 servers when Timeout happened.
420 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
422 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
423 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
424 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
429 EfiDhcp6InfoRequest (
430 IN EFI_DHCP6_PROTOCOL
*This
,
431 IN BOOLEAN SendClientId
,
432 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
433 IN UINT32 OptionCount
,
434 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
435 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
436 IN EFI_EVENT TimeoutEvent OPTIONAL
,
437 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
438 IN VOID
*CallbackContext OPTIONAL
442 Manually extend the valid and preferred lifetimes for the IPv6 addresses
443 of the configured IA and update other configuration parameters by sending
444 Renew or Rebind packet.
446 The RenewRebind() function is used to manually extend the valid and preferred
447 lifetimes for the IPv6 addresses of the configured IA and update other
448 configuration parameters by sending a Renew or Rebind packet.
449 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
450 it will send Renew packet to the previously DHCPv6 server and transfer the
451 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
452 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
453 If fails, the state transfers to Dhcp6Bound but the timer continues.
454 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
455 it will send a Rebind packet. If a valid Reply packet is received, the state transfers
456 to Dhcp6Bound, and the valid and preferred timer restarts. If it fails, the state
457 transfers to Dhcp6Init, and the IA can't be used.
459 @param[in] This The pointer to the Dhcp6 protocol.
460 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
461 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
463 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process
464 completed and at least one IPv6 address of the
465 configured IA was bound again when
466 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
467 The EFI DHCPv6 Protocol instance has sent Renew
468 or Rebind packet when
469 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
470 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
471 state of the configured IA is not in Dhcp6Bound.
472 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
473 Dhcp6Renewing when RebindRequest is FALSE.
474 The state of the configured IA has already entered
475 Dhcp6Rebinding when RebindRequest is TRUE.
476 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
478 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
479 because of no response.
480 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
481 IA after the DHCPv6 renew/rebind exchange process.
482 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
483 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
488 EfiDhcp6RenewRebind (
489 IN EFI_DHCP6_PROTOCOL
*This
,
490 IN BOOLEAN RebindRequest
494 Inform that one or more addresses assigned by a server are already
495 in use by another node.
497 The Decline() function is used to manually decline the assignment of
498 IPv6 addresses, which have been already used by another node. If all
499 IPv6 addresses of the configured IA are declined through this function,
500 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
501 Otherwise, the state of the IA will restore to Dhcp6Bound after the
502 declining process. The Decline() can only be called when the IA is in
503 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
504 this function is a blocking operation. It will return after the
505 declining process finishes, or aborted by user.
507 @param[in] This The pointer to the Dhcp6 protocol.
508 @param[in] AddressCount The number of declining addresses.
509 @param[in] Addresses The pointer to the buffer stored the declining
512 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
513 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
514 The Dhcp6 instance has sent Decline packet when
515 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
516 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
517 state of the configured IA is not in Dhcp6Bound.
518 @retval EFI_ABORTED The DHCPv6 decline exchange process was aborted by the user.
519 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
520 the configured IA for this instance.
521 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
522 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
528 IN EFI_DHCP6_PROTOCOL
*This
,
529 IN UINT32 AddressCount
,
530 IN EFI_IPv6_ADDRESS
*Addresses
534 Release one or more addresses associated with the configured Ia
535 for the current instance.
537 The Release() function is used to manually release the one or more
538 IPv6 address. If AddressCount is zero, it will release all IPv6
539 addresses of the configured IA. If all IPv6 addresses of the IA are
540 released through this function, the state of the IA will switch
541 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
542 IA will restore to Dhcp6Bound after the releasing process.
543 The Release() can only be called when the IA is in a Dhcp6Bound state.
544 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
545 a blocking operation. It will return after the releasing process
546 finishes, or aborted by user.
548 @param[in] This The pointer to the Dhcp6 protocol.
549 @param[in] AddressCount The number of releasing addresses.
550 @param[in] Addresses The pointer to the buffer stored the releasing
552 @retval EFI_SUCCESS The DHCPv6 release exchange process has
553 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
554 is NULL. The Dhcp6 instance has sent Release
555 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
557 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
558 state of the configured IA is not in Dhcp6Bound.
559 @retval EFI_ABORTED The DHCPv6 release exchange process was aborted by the user.
560 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
561 the configured IA for this instance.
562 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
563 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
569 IN EFI_DHCP6_PROTOCOL
*This
,
570 IN UINT32 AddressCount
,
571 IN EFI_IPv6_ADDRESS
*Addresses
575 Parse the option data in the Dhcp6 packet.
577 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
579 @param[in] This The pointer to the Dhcp6 protocol.
580 @param[in] Packet The pointer to the Dhcp6 packet.
581 @param[in, out] OptionCount The number of option in the packet.
582 @param[out] PacketOptionList The array of pointers to the each option in the packet.
584 @retval EFI_SUCCESS The packet was successfully parsed.
585 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
586 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
587 that were found in the Packet.
593 IN EFI_DHCP6_PROTOCOL
*This
,
594 IN EFI_DHCP6_PACKET
*Packet
,
595 IN OUT UINT32
*OptionCount
,
596 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL