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>
39 typedef struct _DHCP6_IA_CB DHCP6_IA_CB
;
40 typedef struct _DHCP6_INF_CB DHCP6_INF_CB
;
41 typedef struct _DHCP6_TX_CB DHCP6_TX_CB
;
42 typedef struct _DHCP6_SERVICE DHCP6_SERVICE
;
43 typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE
;
45 #include "Dhcp6Utility.h"
47 #include "Dhcp6Driver.h"
49 #define DHCP6_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'S')
50 #define DHCP6_INSTANCE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'I')
53 // Transmit parameters of solicit message, refers to section-5.5 of rfc-3315.
55 #define DHCP6_SOL_MAX_DELAY 1
56 #define DHCP6_SOL_IRT 1
57 #define DHCP6_SOL_MRC 0
58 #define DHCP6_SOL_MRT 120
59 #define DHCP6_SOL_MRD 0
61 // Transmit parameters of request message, refers to section-5.5 of rfc-3315.
63 #define DHCP6_REQ_IRT 1
64 #define DHCP6_REQ_MRC 10
65 #define DHCP6_REQ_MRT 30
66 #define DHCP6_REQ_MRD 0
68 // Transmit parameters of confirm message, refers to section-5.5 of rfc-3315.
70 #define DHCP6_CNF_MAX_DELAY 1
71 #define DHCP6_CNF_IRT 1
72 #define DHCP6_CNF_MRC 0
73 #define DHCP6_CNF_MRT 4
74 #define DHCP6_CNF_MRD 10
76 // Transmit parameters of renew message, refers to section-5.5 of rfc-3315.
78 #define DHCP6_REN_IRT 10
79 #define DHCP6_REN_MRC 0
80 #define DHCP6_REN_MRT 600
81 #define DHCP6_REN_MRD 0
83 // Transmit parameters of rebind message, refers to section-5.5 of rfc-3315.
85 #define DHCP6_REB_IRT 10
86 #define DHCP6_REB_MRC 0
87 #define DHCP6_REB_MRT 600
88 #define DHCP6_REB_MRD 0
90 // Transmit parameters of information request message, refers to section-5.5 of rfc-3315.
92 #define DHCP6_INF_MAX_DELAY 1
93 #define DHCP6_INF_IRT 1
94 #define DHCP6_INF_MRC 0
95 #define DHCP6_INF_MRT 120
96 #define DHCP6_INF_MRD 0
98 // Transmit parameters of release message, refers to section-5.5 of rfc-3315.
100 #define DHCP6_REL_IRT 1
101 #define DHCP6_REL_MRC 5
102 #define DHCP6_REL_MRT 0
103 #define DHCP6_REL_MRD 0
105 // Transmit parameters of decline message, refers to section-5.5 of rfc-3315.
107 #define DHCP6_DEC_IRT 1
108 #define DHCP6_DEC_MRC 5
109 #define DHCP6_DEC_MRT 0
110 #define DHCP6_DEC_MRD 0
112 #define DHCP6_PACKET_ALL 0
113 #define DHCP6_PACKET_STATEFUL 1
114 #define DHCP6_PACKET_STATELESS 2
116 #define DHCP6_BASE_PACKET_SIZE 1024
118 #define DHCP6_PORT_CLIENT 546
119 #define DHCP6_PORT_SERVER 547
121 #define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
122 #define DHCP6_SERVICE_FROM_THIS(Service) CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
124 extern EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress
;
125 extern EFI_IPv6_ADDRESS mAllDhcpServersAddress
;
126 extern EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate
;
129 // Enumeration of Dhcp6 message type, refers to section-5.3 of rfc-3315.
133 Dhcp6MsgAdvertise
= 2,
141 Dhcp6MsgReconfigure
= 10,
142 Dhcp6MsgInfoRequest
= 11
146 // Enumeration of option code in Dhcp6 packet, refers to section-24.3 of rfc-3315.
149 Dhcp6OptClientId
= 1,
150 Dhcp6OptServerId
= 2,
154 Dhcp6OptRequestOption
= 6,
155 Dhcp6OptPreference
= 7,
156 Dhcp6OptElapsedTime
= 8,
157 Dhcp6OptReplayMessage
= 9,
158 Dhcp6OptAuthentication
= 11,
159 Dhcp6OptServerUnicast
= 12,
160 Dhcp6OptStatusCode
= 13,
161 Dhcp6OptRapidCommit
= 14,
162 Dhcp6OptUserClass
= 15,
163 Dhcp6OptVendorClass
= 16,
164 Dhcp6OptVendorInfo
= 17,
165 Dhcp6OptInterfaceId
= 18,
166 Dhcp6OptReconfigMessage
= 19,
167 Dhcp6OptReconfigureAccept
= 20
171 // Enumeration of status code recorded by IANA, refers to section-24.4 of rfc-3315.
175 Dhcp6StsUnspecFail
= 1,
176 Dhcp6StsNoAddrsAvail
= 2,
177 Dhcp6StsNoBinding
= 3,
178 Dhcp6StsNotOnLink
= 4,
179 Dhcp6StsUseMulticast
= 5
183 // Enumeration of Duid type recorded by IANA, refers to section-24.5 of rfc-3315.
186 Dhcp6DuidTypeLlt
= 1,
189 Dhcp6DuidTypeUuid
= 4
193 // Control block for each IA.
195 struct _DHCP6_IA_CB
{
199 UINT32 AllExpireTime
;
204 // Control block for each transmitted message.
206 struct _DHCP6_TX_CB
{
209 EFI_DHCP6_PACKET
*TxPacket
;
210 EFI_DHCP6_RETRANSMISSION RetryCtl
;
216 BOOLEAN SolicitRetry
;
220 // Control block for each info-request message.
222 struct _DHCP6_INF_CB
{
225 EFI_DHCP6_INFO_CALLBACK ReplyCallback
;
226 VOID
*CallbackContext
;
227 EFI_EVENT TimeoutEvent
;
231 // Control block for Dhcp6 instance, it's per configuration data.
233 struct _DHCP6_INSTANCE
{
236 DHCP6_SERVICE
*Service
;
238 EFI_DHCP6_PROTOCOL Dhcp6
;
240 EFI_DHCP6_CONFIG_DATA
*Config
;
241 EFI_DHCP6_IA
*CacheIa
;
245 EFI_DHCP6_PACKET
*AdSelect
;
247 EFI_IPv6_ADDRESS
*Unicast
;
250 BOOLEAN MediaPresent
;
255 // Control block for Dhcp6 service, it's per Nic handle.
257 struct _DHCP6_SERVICE
{
259 EFI_HANDLE Controller
;
261 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
262 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
263 EFI_IP6_CONFIG_PROTOCOL
*Ip6Cfg
;
264 EFI_DHCP6_DUID
*ClientId
;
273 Starts the DHCPv6 standard S.A.R.R. process.
275 The Start() function starts the DHCPv6 standard process. This function can
276 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
277 If the DHCP process completes successfully, the state of the Dhcp6 instance
278 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
280 Refer to rfc-3315 for precise state transitions during this process. At the
281 time when each event occurs in this process, the callback function that was set
282 by EFI_DHCP6_PROTOCOL.Configure() will be called and the user can take this
283 opportunity to control the process.
285 @param[in] This The pointer to Dhcp6 protocol.
287 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it
288 completed when CompletionEvent was NULL.
289 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
290 @retval EFI_INVALID_PARAMETER This is NULL.
291 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
292 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
293 response was received from the server within the
294 specified timeout value.
295 @retval EFI_ABORTED The user aborted the DHCPv6 process.
296 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
298 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
304 IN EFI_DHCP6_PROTOCOL
*This
308 Stops the DHCPv6 standard S.A.R.R. process.
310 The Stop() function is used to stop the DHCPv6 standard process. After this
311 function is called successfully, the state of Dhcp6 instance is transferred
312 into the Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
313 before DHCPv6 standard process can be started again. This function can be
314 called when the Dhcp6 instance is in any state.
316 @param[in] This The pointer to the Dhcp6 protocol.
318 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
319 @retval EFI_INVALID_PARAMETER This is NULL.
325 IN EFI_DHCP6_PROTOCOL
*This
329 Returns the current operating mode data for the Dhcp6 instance.
331 The GetModeData() function returns the current operating mode and
332 cached data packet for the Dhcp6 instance.
334 @param[in] This The pointer to the Dhcp6 protocol.
335 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
336 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
338 @retval EFI_SUCCESS The mode data was returned.
339 @retval EFI_INVALID_PARAMETER This is NULL.
340 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance has not
341 been configured when Dhcp6ConfigData is
346 EfiDhcp6GetModeData (
347 IN EFI_DHCP6_PROTOCOL
*This
,
348 OUT EFI_DHCP6_MODE_DATA
*Dhcp6ModeData OPTIONAL
,
349 OUT EFI_DHCP6_CONFIG_DATA
*Dhcp6ConfigData OPTIONAL
353 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
355 The Configure() function is used to initialize or clean up the configuration
356 data of the Dhcp6 instance:
357 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
358 configuration data will be initialized in the Dhcp6 instance and the state
359 of the configured IA will be transferred into Dhcp6Init.
360 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
361 configuration data will be cleaned up and no IA will be associated with
363 To update the configuration data for an Dhcp6 instance, the original data
364 must be cleaned up before setting the new configuration data.
366 @param[in] This The pointer to the Dhcp6 protocol
367 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
369 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
370 Dhcp6Init state, or cleaned up the original
371 configuration setting.
372 @retval EFI_ACCESS_DENIED The Dhcp6 instance has been already configured
373 when Dhcp6CfgData is not NULL.
374 The Dhcp6 instance has already started the
375 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
376 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
377 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
378 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
384 IN EFI_DHCP6_PROTOCOL
*This
,
385 IN EFI_DHCP6_CONFIG_DATA
*Dhcp6CfgData OPTIONAL
389 Request configuration information without the assignment of any
390 Ia addresses of the client.
392 The InfoRequest() function is used to request configuration information
393 without the assignment of any IPv6 address of the client. Client sends
394 out Information Request packet to obtain the required configuration
395 information, and DHCPv6 server responds with Reply packet containing
396 the information for the client. The received Reply packet will be passed
397 to the user by ReplyCallback function. If user returns EFI_NOT_READY from
398 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
399 packets unless timeout according to the Retransmission parameter.
400 Otherwise, the Information Request exchange process will be finished
401 successfully if user returns EFI_SUCCESS from ReplyCallback.
403 @param[in] This The pointer to the Dhcp6 protocol.
404 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
405 Identifier option and include it into Information Request
406 packet. Otherwise, Client Identifier option will not be included.
407 @param[in] OptionRequest The pointer to the buffer of option request options.
408 @param[in] OptionCount The option number in the OptionList.
409 @param[in] OptionList The list of appended options.
410 @param[in] Retransmission The pointer to the retransmission of the message.
411 @param[in] TimeoutEvent The event of timeout.
412 @param[in] ReplyCallback The callback function when a reply was received.
413 @param[in] CallbackContext The pointer to the parameter passed to the callback.
415 @retval EFI_SUCCESS The DHCPv6 information request exchange process
416 completed when TimeoutEvent is NULL. Information
417 Request packet has been sent to DHCPv6 server when
418 TimeoutEvent is not NULL.
419 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
420 because of no response, or not all requested-options
421 are responded to by DHCPv6 servers when Timeout happened.
422 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
424 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
425 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
426 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
431 EfiDhcp6InfoRequest (
432 IN EFI_DHCP6_PROTOCOL
*This
,
433 IN BOOLEAN SendClientId
,
434 IN EFI_DHCP6_PACKET_OPTION
*OptionRequest
,
435 IN UINT32 OptionCount
,
436 IN EFI_DHCP6_PACKET_OPTION
*OptionList
[] OPTIONAL
,
437 IN EFI_DHCP6_RETRANSMISSION
*Retransmission
,
438 IN EFI_EVENT TimeoutEvent OPTIONAL
,
439 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback
,
440 IN VOID
*CallbackContext OPTIONAL
444 Manually extend the valid and preferred lifetimes for the IPv6 addresses
445 of the configured IA and update other configuration parameters by sending
446 Renew or Rebind packet.
448 The RenewRebind() function is used to manually extend the valid and preferred
449 lifetimes for the IPv6 addresses of the configured IA and update other
450 configuration parameters by sending a Renew or Rebind packet.
451 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
452 it will send Renew packet to the previously DHCPv6 server and transfer the
453 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
454 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
455 If fails, the state transfers to Dhcp6Bound but the timer continues.
456 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
457 it will send a Rebind packet. If a valid Reply packet is received, the state transfers
458 to Dhcp6Bound, and the valid and preferred timer restarts. If it fails, the state
459 transfers to Dhcp6Init, and the IA can't be used.
461 @param[in] This The pointer to the Dhcp6 protocol.
462 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
463 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
465 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process
466 completed and at least one IPv6 address of the
467 configured IA was bound again when
468 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
469 The EFI DHCPv6 Protocol instance has sent Renew
470 or Rebind packet when
471 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
472 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
473 state of the configured IA is not in Dhcp6Bound.
474 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
475 Dhcp6Renewing when RebindRequest is FALSE.
476 The state of the configured IA has already entered
477 Dhcp6Rebinding when RebindRequest is TRUE.
478 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
480 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
481 because of no response.
482 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
483 IA after the DHCPv6 renew/rebind exchange process.
484 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
485 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
490 EfiDhcp6RenewRebind (
491 IN EFI_DHCP6_PROTOCOL
*This
,
492 IN BOOLEAN RebindRequest
496 Inform that one or more addresses assigned by a server are already
497 in use by another node.
499 The Decline() function is used to manually decline the assignment of
500 IPv6 addresses, which have been already used by another node. If all
501 IPv6 addresses of the configured IA are declined through this function,
502 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
503 Otherwise, the state of the IA will restore to Dhcp6Bound after the
504 declining process. The Decline() can only be called when the IA is in
505 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
506 this function is a blocking operation. It will return after the
507 declining process finishes, or aborted by user.
509 @param[in] This The pointer to the Dhcp6 protocol.
510 @param[in] AddressCount The number of declining addresses.
511 @param[in] Addresses The pointer to the buffer stored the declining
514 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
515 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
516 The Dhcp6 instance has sent Decline packet when
517 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
518 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
519 state of the configured IA is not in Dhcp6Bound.
520 @retval EFI_ABORTED The DHCPv6 decline exchange process was aborted by the user.
521 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
522 the configured IA for this instance.
523 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
524 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
530 IN EFI_DHCP6_PROTOCOL
*This
,
531 IN UINT32 AddressCount
,
532 IN EFI_IPv6_ADDRESS
*Addresses
536 Release one or more addresses associated with the configured Ia
537 for the current instance.
539 The Release() function is used to manually release the one or more
540 IPv6 address. If AddressCount is zero, it will release all IPv6
541 addresses of the configured IA. If all IPv6 addresses of the IA are
542 released through this function, the state of the IA will switch
543 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
544 IA will restore to Dhcp6Bound after the releasing process.
545 The Release() can only be called when the IA is in a Dhcp6Bound state.
546 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
547 a blocking operation. It will return after the releasing process
548 finishes, or aborted by user.
550 @param[in] This The pointer to the Dhcp6 protocol.
551 @param[in] AddressCount The number of releasing addresses.
552 @param[in] Addresses The pointer to the buffer stored the releasing
554 @retval EFI_SUCCESS The DHCPv6 release exchange process has
555 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
556 is NULL. The Dhcp6 instance has sent Release
557 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
559 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
560 state of the configured IA is not in Dhcp6Bound.
561 @retval EFI_ABORTED The DHCPv6 release exchange process was aborted by the user.
562 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
563 the configured IA for this instance.
564 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
565 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
571 IN EFI_DHCP6_PROTOCOL
*This
,
572 IN UINT32 AddressCount
,
573 IN EFI_IPv6_ADDRESS
*Addresses
577 Parse the option data in the Dhcp6 packet.
579 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
581 @param[in] This The pointer to the Dhcp6 protocol.
582 @param[in] Packet The pointer to the Dhcp6 packet.
583 @param[in, out] OptionCount The number of option in the packet.
584 @param[out] PacketOptionList The array of pointers to the each option in the packet.
586 @retval EFI_SUCCESS The packet was successfully parsed.
587 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
588 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
589 that were found in the Packet.
595 IN EFI_DHCP6_PROTOCOL
*This
,
596 IN EFI_DHCP6_PACKET
*Packet
,
597 IN OUT UINT32
*OptionCount
,
598 OUT EFI_DHCP6_PACKET_OPTION
*PacketOptionList
[] OPTIONAL