2 Dhcp6 internal data structure and definition declaration.
4 Copyright (c) 2009 - 2012, 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/Ip6Config.h>
25 #include <Protocol/ServiceBinding.h>
26 #include <Protocol/DriverBinding.h>
28 #include <Library/UdpIoLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiRuntimeServicesTableLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseLib.h>
36 #include <Library/NetLib.h>
37 #include <Library/PrintLib.h>
40 typedef struct _DHCP6_IA_CB DHCP6_IA_CB
;
41 typedef struct _DHCP6_INF_CB DHCP6_INF_CB
;
42 typedef struct _DHCP6_TX_CB DHCP6_TX_CB
;
43 typedef struct _DHCP6_SERVICE DHCP6_SERVICE
;
44 typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE
;
46 #include "Dhcp6Utility.h"
48 #include "Dhcp6Driver.h"
50 #define DHCP6_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'S')
51 #define DHCP6_INSTANCE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'I')
54 // Transmit parameters of solicit message, refers to section-5.5 of rfc-3315.
56 #define DHCP6_SOL_MAX_DELAY 1
57 #define DHCP6_SOL_IRT 1
58 #define DHCP6_SOL_MRC 0
59 #define DHCP6_SOL_MRT 120
60 #define DHCP6_SOL_MRD 0
62 // Transmit parameters of request message, refers to section-5.5 of rfc-3315.
64 #define DHCP6_REQ_IRT 1
65 #define DHCP6_REQ_MRC 10
66 #define DHCP6_REQ_MRT 30
67 #define DHCP6_REQ_MRD 0
69 // Transmit parameters of confirm message, refers to section-5.5 of rfc-3315.
71 #define DHCP6_CNF_MAX_DELAY 1
72 #define DHCP6_CNF_IRT 1
73 #define DHCP6_CNF_MRC 0
74 #define DHCP6_CNF_MRT 4
75 #define DHCP6_CNF_MRD 10
77 // Transmit parameters of renew message, refers to section-5.5 of rfc-3315.
79 #define DHCP6_REN_IRT 10
80 #define DHCP6_REN_MRC 0
81 #define DHCP6_REN_MRT 600
82 #define DHCP6_REN_MRD 0
84 // Transmit parameters of rebind message, refers to section-5.5 of rfc-3315.
86 #define DHCP6_REB_IRT 10
87 #define DHCP6_REB_MRC 0
88 #define DHCP6_REB_MRT 600
89 #define DHCP6_REB_MRD 0
91 // Transmit parameters of information request message, refers to section-5.5 of rfc-3315.
93 #define DHCP6_INF_MAX_DELAY 1
94 #define DHCP6_INF_IRT 1
95 #define DHCP6_INF_MRC 0
96 #define DHCP6_INF_MRT 120
97 #define DHCP6_INF_MRD 0
99 // Transmit parameters of release message, refers to section-5.5 of rfc-3315.
101 #define DHCP6_REL_IRT 1
102 #define DHCP6_REL_MRC 5
103 #define DHCP6_REL_MRT 0
104 #define DHCP6_REL_MRD 0
106 // Transmit parameters of decline message, refers to section-5.5 of rfc-3315.
108 #define DHCP6_DEC_IRT 1
109 #define DHCP6_DEC_MRC 5
110 #define DHCP6_DEC_MRT 0
111 #define DHCP6_DEC_MRD 0
113 #define DHCP6_PACKET_ALL 0
114 #define DHCP6_PACKET_STATEFUL 1
115 #define DHCP6_PACKET_STATELESS 2
117 #define DHCP6_BASE_PACKET_SIZE 1024
119 #define DHCP6_PORT_CLIENT 546
120 #define DHCP6_PORT_SERVER 547
122 #define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
123 #define DHCP6_SERVICE_FROM_THIS(Service) CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
125 extern EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress
;
126 extern EFI_IPv6_ADDRESS mAllDhcpServersAddress
;
127 extern EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
;
130 // Enumeration of Dhcp6 message type, refers to section-5.3 of rfc-3315.
134 Dhcp6MsgAdvertise
= 2,
142 Dhcp6MsgReconfigure
= 10,
143 Dhcp6MsgInfoRequest
= 11
147 // Enumeration of option code in Dhcp6 packet, refers to section-24.3 of rfc-3315.
150 Dhcp6OptClientId
= 1,
151 Dhcp6OptServerId
= 2,
155 Dhcp6OptRequestOption
= 6,
156 Dhcp6OptPreference
= 7,
157 Dhcp6OptElapsedTime
= 8,
158 Dhcp6OptReplayMessage
= 9,
159 Dhcp6OptAuthentication
= 11,
160 Dhcp6OptServerUnicast
= 12,
161 Dhcp6OptStatusCode
= 13,
162 Dhcp6OptRapidCommit
= 14,
163 Dhcp6OptUserClass
= 15,
164 Dhcp6OptVendorClass
= 16,
165 Dhcp6OptVendorInfo
= 17,
166 Dhcp6OptInterfaceId
= 18,
167 Dhcp6OptReconfigMessage
= 19,
168 Dhcp6OptReconfigureAccept
= 20
172 // Enumeration of status code recorded by IANA, refers to section-24.4 of rfc-3315.
176 Dhcp6StsUnspecFail
= 1,
177 Dhcp6StsNoAddrsAvail
= 2,
178 Dhcp6StsNoBinding
= 3,
179 Dhcp6StsNotOnLink
= 4,
180 Dhcp6StsUseMulticast
= 5
184 // Enumeration of Duid type recorded by IANA, refers to section-24.5 of rfc-3315.
187 Dhcp6DuidTypeLlt
= 1,
190 Dhcp6DuidTypeUuid
= 4
194 // Control block for each IA.
196 struct _DHCP6_IA_CB
{
200 UINT32 AllExpireTime
;
205 // Control block for each transmitted message.
207 struct _DHCP6_TX_CB
{
210 EFI_DHCP6_PACKET
*TxPacket
;
211 EFI_DHCP6_RETRANSMISSION RetryCtl
;
217 BOOLEAN SolicitRetry
;
221 // Control block for each info-request message.
223 struct _DHCP6_INF_CB
{
226 EFI_DHCP6_INFO_CALLBACK ReplyCallback
;
227 VOID
*CallbackContext
;
228 EFI_EVENT TimeoutEvent
;
232 // Control block for Dhcp6 instance, it's per configuration data.
234 struct _DHCP6_INSTANCE
{
237 DHCP6_SERVICE
*Service
;
239 EFI_DHCP6_PROTOCOL Dhcp6
;
241 EFI_DHCP6_CONFIG_DATA
*Config
;
242 EFI_DHCP6_IA
*CacheIa
;
246 EFI_DHCP6_PACKET
*AdSelect
;
248 EFI_IPv6_ADDRESS
*Unicast
;
249 volatile EFI_STATUS UdpSts
;
251 BOOLEAN MediaPresent
;
253 // StartTime is used to calculate the 'elapsed-time' option. Refer to RFC3315,
254 // the elapsed-time is amount of time since the client began its current DHCP transaction.
260 // Control block for Dhcp6 service, it's per Nic handle.
262 struct _DHCP6_SERVICE
{
264 EFI_HANDLE Controller
;
266 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
267 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
268 EFI_IP6_CONFIG_PROTOCOL
*Ip6Cfg
;
269 EFI_DHCP6_DUID
*ClientId
;
277 Starts the DHCPv6 standard S.A.R.R. process.
279 The Start() function starts the DHCPv6 standard process. This function can
280 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
281 If the DHCP process completes successfully, the state of the Dhcp6 instance
282 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
284 Refer to rfc-3315 for precise state transitions during this process. At the
285 time when each event occurs in this process, the callback function that was set
286 by EFI_DHCP6_PROTOCOL.Configure() will be called and the user can take this
287 opportunity to control the process.
289 @param[in] This The pointer to Dhcp6 protocol.
291 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it
292 completed when CompletionEvent was NULL.
293 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
294 @retval EFI_INVALID_PARAMETER This is NULL.
295 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
296 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
297 response was received from the server within the
298 specified timeout value.
299 @retval EFI_ABORTED The user aborted the DHCPv6 process.
300 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
302 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
308 IN EFI_DHCP6_PROTOCOL
*This
312 Stops the DHCPv6 standard S.A.R.R. process.
314 The Stop() function is used to stop the DHCPv6 standard process. After this
315 function is called successfully, the state of Dhcp6 instance is transferred
316 into the Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
317 before DHCPv6 standard process can be started again. This function can be
318 called when the Dhcp6 instance is in any state.
320 @param[in] This The pointer to the Dhcp6 protocol.
322 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
323 @retval EFI_INVALID_PARAMETER This is NULL.
329 IN EFI_DHCP6_PROTOCOL
*This
333 Returns the current operating mode data for the Dhcp6 instance.
335 The GetModeData() function returns the current operating mode and
336 cached data packet for the Dhcp6 instance.
338 @param[in] This The pointer to the Dhcp6 protocol.
339 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
340 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
342 @retval EFI_SUCCESS The mode data was returned.
343 @retval EFI_INVALID_PARAMETER This is NULL.
344 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance has not
345 been configured when Dhcp6ConfigData is
350 EfiDhcp6GetModeData (
351 IN EFI_DHCP6_PROTOCOL
*This
,
352 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
353 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
357 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
359 The Configure() function is used to initialize or clean up the configuration
360 data of the Dhcp6 instance:
361 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
362 configuration data will be initialized in the Dhcp6 instance and the state
363 of the configured IA will be transferred into Dhcp6Init.
364 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
365 configuration data will be cleaned up and no IA will be associated with
367 To update the configuration data for an Dhcp6 instance, the original data
368 must be cleaned up before setting the new configuration data.
370 @param[in] This The pointer to the Dhcp6 protocol
371 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
373 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
374 Dhcp6Init state, or cleaned up the original
375 configuration setting.
376 @retval EFI_ACCESS_DENIED The Dhcp6 instance has been already configured
377 when Dhcp6CfgData is not NULL.
378 The Dhcp6 instance has already started the
379 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
380 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
381 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
382 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
388 IN EFI_DHCP6_PROTOCOL
*This
,
389 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
393 Request configuration information without the assignment of any
394 Ia addresses of the client.
396 The InfoRequest() function is used to request configuration information
397 without the assignment of any IPv6 address of the client. Client sends
398 out Information Request packet to obtain the required configuration
399 information, and DHCPv6 server responds with Reply packet containing
400 the information for the client. The received Reply packet will be passed
401 to the user by ReplyCallback function. If user returns EFI_NOT_READY from
402 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
403 packets unless timeout according to the Retransmission parameter.
404 Otherwise, the Information Request exchange process will be finished
405 successfully if user returns EFI_SUCCESS from ReplyCallback.
407 @param[in] This The pointer to the Dhcp6 protocol.
408 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
409 Identifier option and include it into Information Request
410 packet. Otherwise, Client Identifier option will not be included.
411 @param[in] OptionRequest The pointer to the buffer of option request options.
412 @param[in] OptionCount The option number in the OptionList.
413 @param[in] OptionList The list of appended options.
414 @param[in] Retransmission The pointer to the retransmission of the message.
415 @param[in] TimeoutEvent The event of timeout.
416 @param[in] ReplyCallback The callback function when a reply was received.
417 @param[in] CallbackContext The pointer to the parameter passed to the callback.
419 @retval EFI_SUCCESS The DHCPv6 information request exchange process
420 completed when TimeoutEvent is NULL. Information
421 Request packet has been sent to DHCPv6 server when
422 TimeoutEvent is not NULL.
423 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
424 because of no response, or not all requested-options
425 are responded to by DHCPv6 servers when Timeout happened.
426 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
428 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
429 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
430 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
435 EfiDhcp6InfoRequest (
436 IN EFI_DHCP6_PROTOCOL
*This
,
437 IN BOOLEAN SendClientId
,
438 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
439 IN UINT32 OptionCount
,
440 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
441 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
442 IN EFI_EVENT TimeoutEvent OPTIONAL
,
443 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
444 IN VOID
*CallbackContext OPTIONAL
448 Manually extend the valid and preferred lifetimes for the IPv6 addresses
449 of the configured IA and update other configuration parameters by sending
450 Renew or Rebind packet.
452 The RenewRebind() function is used to manually extend the valid and preferred
453 lifetimes for the IPv6 addresses of the configured IA and update other
454 configuration parameters by sending a Renew or Rebind packet.
455 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
456 it will send Renew packet to the previously DHCPv6 server and transfer the
457 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
458 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
459 If fails, the state transfers to Dhcp6Bound but the timer continues.
460 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
461 it will send a Rebind packet. If a valid Reply packet is received, the state transfers
462 to Dhcp6Bound, and the valid and preferred timer restarts. If it fails, the state
463 transfers to Dhcp6Init, and the IA can't be used.
465 @param[in] This The pointer to the Dhcp6 protocol.
466 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
467 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
469 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process
470 completed and at least one IPv6 address of the
471 configured IA was bound again when
472 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
473 The EFI DHCPv6 Protocol instance has sent Renew
474 or Rebind packet when
475 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
476 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
477 state of the configured IA is not in Dhcp6Bound.
478 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
479 Dhcp6Renewing when RebindRequest is FALSE.
480 The state of the configured IA has already entered
481 Dhcp6Rebinding when RebindRequest is TRUE.
482 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
484 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
485 because of no response.
486 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
487 IA after the DHCPv6 renew/rebind exchange process.
488 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
489 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
494 EfiDhcp6RenewRebind (
495 IN EFI_DHCP6_PROTOCOL
*This
,
496 IN BOOLEAN RebindRequest
500 Inform that one or more addresses assigned by a server are already
501 in use by another node.
503 The Decline() function is used to manually decline the assignment of
504 IPv6 addresses, which have been already used by another node. If all
505 IPv6 addresses of the configured IA are declined through this function,
506 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
507 Otherwise, the state of the IA will restore to Dhcp6Bound after the
508 declining process. The Decline() can only be called when the IA is in
509 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
510 this function is a blocking operation. It will return after the
511 declining process finishes, or aborted by user.
513 @param[in] This The pointer to the Dhcp6 protocol.
514 @param[in] AddressCount The number of declining addresses.
515 @param[in] Addresses The pointer to the buffer stored the declining
518 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
519 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
520 The Dhcp6 instance has sent Decline packet when
521 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
522 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
523 state of the configured IA is not in Dhcp6Bound.
524 @retval EFI_ABORTED The DHCPv6 decline exchange process was aborted by the user.
525 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
526 the configured IA for this instance.
527 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
528 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
534 IN EFI_DHCP6_PROTOCOL
*This
,
535 IN UINT32 AddressCount
,
536 IN EFI_IPv6_ADDRESS
*Addresses
540 Release one or more addresses associated with the configured Ia
541 for the current instance.
543 The Release() function is used to manually release the one or more
544 IPv6 address. If AddressCount is zero, it will release all IPv6
545 addresses of the configured IA. If all IPv6 addresses of the IA are
546 released through this function, the state of the IA will switch
547 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
548 IA will restore to Dhcp6Bound after the releasing process.
549 The Release() can only be called when the IA is in a Dhcp6Bound state.
550 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
551 a blocking operation. It will return after the releasing process
552 finishes, or aborted by user.
554 @param[in] This The pointer to the Dhcp6 protocol.
555 @param[in] AddressCount The number of releasing addresses.
556 @param[in] Addresses The pointer to the buffer stored the releasing
558 @retval EFI_SUCCESS The DHCPv6 release exchange process has
559 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
560 is NULL. The Dhcp6 instance has sent Release
561 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
563 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
564 state of the configured IA is not in Dhcp6Bound.
565 @retval EFI_ABORTED The DHCPv6 release exchange process was aborted by the user.
566 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
567 the configured IA for this instance.
568 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
569 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
575 IN EFI_DHCP6_PROTOCOL
*This
,
576 IN UINT32 AddressCount
,
577 IN EFI_IPv6_ADDRESS
*Addresses
581 Parse the option data in the Dhcp6 packet.
583 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
585 @param[in] This The pointer to the Dhcp6 protocol.
586 @param[in] Packet The pointer to the Dhcp6 packet.
587 @param[in, out] OptionCount The number of option in the packet.
588 @param[out] PacketOptionList The array of pointers to the each option in the packet.
590 @retval EFI_SUCCESS The packet was successfully parsed.
591 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
592 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
593 that were found in the Packet.
599 IN EFI_DHCP6_PROTOCOL
*This
,
600 IN EFI_DHCP6_PACKET
*Packet
,
601 IN OUT UINT32
*OptionCount
,
602 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL