2 The implementation of EFI IPv6 Configuration Protocol.
4 Copyright (c) 2009 - 2018, 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.
18 LIST_ENTRY mIp6ConfigInstanceList
= {&mIp6ConfigInstanceList
, &mIp6ConfigInstanceList
};
21 The event process routine when the DHCPv6 service binding protocol is installed
24 @param[in] Event Not used.
25 @param[in] Context Pointer to the IP6 config instance data.
30 Ip6ConfigOnDhcp6SbInstalled (
36 Update the current policy to NewPolicy. During the transition
37 period, the default router list, on-link prefix list, autonomous prefix list
38 and address list in all interfaces will be released.
40 @param[in] IpSb The IP6 service binding instance.
41 @param[in] NewPolicy The new policy to be updated to.
45 Ip6ConfigOnPolicyChanged (
47 IN EFI_IP6_CONFIG_POLICY NewPolicy
54 IP6_DAD_ENTRY
*DadEntry
;
55 IP6_DELAY_JOIN_LIST
*DelayNode
;
56 IP6_ADDRESS_INFO
*AddrInfo
;
57 IP6_PROTOCOL
*Instance
;
63 // Currently there are only two policies: Manual and Automatic. Regardless of
64 // what transition is going on, i.e., Manual -> Automatic and Automatic ->
65 // Manual, we have to free default router list, on-link prefix list, autonomous
66 // prefix list, address list in all the interfaces and destroy any IPv6 child
67 // instance whose local IP is neither 0 nor the link-local address.
69 Ip6CleanDefaultRouterList (IpSb
);
70 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
71 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
74 // It's tricky... If the LinkLocal address is O.K., add back the link-local
75 // prefix to the on-link prefix table.
77 if (IpSb
->LinkLocalOk
) {
78 Ip6CreatePrefixListEntry (
81 (UINT32
) IP6_INFINIT_LIFETIME
,
82 (UINT32
) IP6_INFINIT_LIFETIME
,
83 IP6_LINK_LOCAL_PREFIX_LENGTH
,
88 if (!IsListEmpty (&IpSb
->DefaultInterface
->AddressList
) && IpSb
->DefaultInterface
->AddressCount
> 0) {
90 // If any IPv6 children (Instance) in configured state and use global unicast address, it will be
91 // destroyed in Ip6RemoveAddr() function later. Then, the upper layer driver's Stop() function will be
92 // called, which may break the upper layer network stacks. So, the driver should take the responsibility
93 // for the recovery by using ConnectController() after Ip6RemoveAddr().
94 // Here, just check whether need to recover the upper layer network stacks later.
96 NET_LIST_FOR_EACH (Entry
, &IpSb
->DefaultInterface
->AddressList
) {
97 AddrInfo
= NET_LIST_USER_STRUCT_S (Entry
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
98 if (!IsListEmpty (&IpSb
->Children
)) {
99 NET_LIST_FOR_EACH (Entry2
, &IpSb
->Children
) {
100 Instance
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
101 if ((Instance
->State
== IP6_STATE_CONFIGED
) && EFI_IP6_EQUAL (&Instance
->ConfigData
.StationAddress
, &AddrInfo
->Address
)) {
110 // All IPv6 children that use global unicast address as it's source address
111 // should be destroyed now. The survivers are those use the link-local address
112 // or the unspecified address as the source address.
113 // TODO: Conduct a check here.
116 &IpSb
->DefaultInterface
->AddressList
,
117 &IpSb
->DefaultInterface
->AddressCount
,
122 if (IpSb
->Controller
!= NULL
&& Recovery
) {
124 // ConnectController() to recover the upper layer network stacks.
126 gBS
->ConnectController (IpSb
->Controller
, NULL
, NULL
, TRUE
);
131 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
133 // remove all pending delay node and DAD entries for the global addresses.
135 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
137 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DelayJoinList
) {
138 DelayNode
= NET_LIST_USER_STRUCT (Entry2
, IP6_DELAY_JOIN_LIST
, Link
);
139 if (!NetIp6IsLinkLocalAddr (&DelayNode
->AddressInfo
->Address
)) {
140 RemoveEntryList (&DelayNode
->Link
);
141 FreePool (DelayNode
);
145 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DupAddrDetectList
) {
146 DadEntry
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_DAD_ENTRY
, Link
, IP6_DAD_ENTRY_SIGNATURE
);
148 if (!NetIp6IsLinkLocalAddr (&DadEntry
->AddressInfo
->Address
)) {
150 // Fail this DAD entry if the address is not link-local.
152 Ip6OnDADFinished (FALSE
, IpIf
, DadEntry
);
157 if (NewPolicy
== Ip6ConfigPolicyAutomatic
) {
159 // Set parameters to trigger router solicitation sending in timer handler.
161 IpSb
->RouterAdvertiseReceived
= FALSE
;
162 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
166 IpSb
->Ticks
= (UINT32
) IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS
);
171 The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.
173 @param[in] Instance Pointer to the IP6 config instance data.
174 @param[in] OtherInfoOnly If FALSE, get stateful address and other information
175 via DHCPv6. Otherwise, only get the other information.
177 @retval EFI_SUCCESS The operation finished successfully.
178 @retval EFI_UNSUPPORTED The DHCP6 driver is not available.
182 Ip6ConfigStartStatefulAutoConfig (
183 IN IP6_CONFIG_INSTANCE
*Instance
,
184 IN BOOLEAN OtherInfoOnly
189 EFI_DHCP6_CONFIG_DATA Dhcp6CfgData
;
190 EFI_DHCP6_PROTOCOL
*Dhcp6
;
191 EFI_DHCP6_PACKET_OPTION
*OptList
[1];
193 EFI_DHCP6_PACKET_OPTION
*Oro
;
194 EFI_DHCP6_RETRANSMISSION InfoReqReXmit
;
197 // A host must not invoke stateful address configuration if it is already
198 // participating in the statuful protocol as a result of an earlier advertisement.
200 if (Instance
->Dhcp6Handle
!= NULL
) {
204 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
206 Instance
->OtherInfoOnly
= OtherInfoOnly
;
208 Status
= NetLibCreateServiceChild (
211 &gEfiDhcp6ServiceBindingProtocolGuid
,
212 &Instance
->Dhcp6Handle
215 if (Status
== EFI_UNSUPPORTED
) {
217 // No DHCPv6 Service Binding protocol, register a notify.
219 if (Instance
->Dhcp6SbNotifyEvent
== NULL
) {
220 Instance
->Dhcp6SbNotifyEvent
= EfiCreateProtocolNotifyEvent (
221 &gEfiDhcp6ServiceBindingProtocolGuid
,
223 Ip6ConfigOnDhcp6SbInstalled
,
225 &Instance
->Registration
230 if (EFI_ERROR (Status
)) {
234 if (Instance
->Dhcp6SbNotifyEvent
!= NULL
) {
235 gBS
->CloseEvent (Instance
->Dhcp6SbNotifyEvent
);
238 Status
= gBS
->OpenProtocol (
239 Instance
->Dhcp6Handle
,
240 &gEfiDhcp6ProtocolGuid
,
241 (VOID
**) &Instance
->Dhcp6
,
244 EFI_OPEN_PROTOCOL_BY_DRIVER
246 ASSERT_EFI_ERROR (Status
);
248 Dhcp6
= Instance
->Dhcp6
;
249 Dhcp6
->Configure (Dhcp6
, NULL
);
252 // Set the exta options to send. Here we only want the option request option
255 Oro
= (EFI_DHCP6_PACKET_OPTION
*) OptBuf
;
256 Oro
->OpCode
= HTONS (DHCP6_OPT_ORO
);
257 Oro
->OpLen
= HTONS (2);
258 *((UINT16
*) &Oro
->Data
[0]) = HTONS (DHCP6_OPT_DNS_SERVERS
);
261 Status
= EFI_SUCCESS
;
263 if (!OtherInfoOnly
) {
265 // Get stateful address and other information via DHCPv6.
267 Dhcp6CfgData
.Dhcp6Callback
= NULL
;
268 Dhcp6CfgData
.CallbackContext
= NULL
;
269 Dhcp6CfgData
.OptionCount
= 1;
270 Dhcp6CfgData
.OptionList
= &OptList
[0];
271 Dhcp6CfgData
.IaDescriptor
.Type
= EFI_DHCP6_IA_TYPE_NA
;
272 Dhcp6CfgData
.IaDescriptor
.IaId
= Instance
->IaId
;
273 Dhcp6CfgData
.IaInfoEvent
= Instance
->Dhcp6Event
;
274 Dhcp6CfgData
.ReconfigureAccept
= FALSE
;
275 Dhcp6CfgData
.RapidCommit
= FALSE
;
276 Dhcp6CfgData
.SolicitRetransmission
= NULL
;
278 Status
= Dhcp6
->Configure (Dhcp6
, &Dhcp6CfgData
);
280 if (!EFI_ERROR (Status
)) {
282 if (IpSb
->LinkLocalOk
) {
283 Status
= Dhcp6
->Start (Dhcp6
);
285 IpSb
->Dhcp6NeedStart
= TRUE
;
291 // Only get other information via DHCPv6, this doesn't require a config
294 InfoReqReXmit
.Irt
= 4;
295 InfoReqReXmit
.Mrc
= 64;
296 InfoReqReXmit
.Mrt
= 60;
297 InfoReqReXmit
.Mrd
= 0;
299 if (IpSb
->LinkLocalOk
) {
300 Status
= Dhcp6
->InfoRequest (
307 Instance
->Dhcp6Event
,
308 Ip6ConfigOnDhcp6Reply
,
312 IpSb
->Dhcp6NeedInfoRequest
= TRUE
;
321 Signal the registered event. It is the callback routine for NetMapIterate.
323 @param[in] Map Points to the list of registered event.
324 @param[in] Item The registered event.
325 @param[in] Arg Not used.
330 Ip6ConfigSignalEvent (
332 IN NET_MAP_ITEM
*Item
,
336 gBS
->SignalEvent ((EFI_EVENT
) Item
->Key
);
342 Read the configuration data from variable storage according to the VarName and
343 gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
344 data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
345 configuration data to IP6_CONFIG_INSTANCE.
347 @param[in] VarName The pointer to the variable name
348 @param[in, out] Instance The pointer to the IP6 config instance data.
350 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
351 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
352 @retval EFI_SUCCESS The configuration data was retrieved successfully.
356 Ip6ConfigReadConfigData (
358 IN OUT IP6_CONFIG_INSTANCE
*Instance
363 IP6_CONFIG_VARIABLE
*Variable
;
364 IP6_CONFIG_DATA_ITEM
*DataItem
;
366 IP6_CONFIG_DATA_RECORD DataRecord
;
370 // Try to read the configuration variable.
373 Status
= gRT
->GetVariable (
375 &gEfiIp6ConfigProtocolGuid
,
381 if (Status
== EFI_BUFFER_TOO_SMALL
) {
383 // Allocate buffer and read the config variable.
385 Variable
= AllocatePool (VarSize
);
386 if (Variable
== NULL
) {
387 return EFI_OUT_OF_RESOURCES
;
390 Status
= gRT
->GetVariable (
392 &gEfiIp6ConfigProtocolGuid
,
397 if (EFI_ERROR (Status
) || (UINT16
) (~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
)) != 0) {
399 // GetVariable still error or the variable is corrupted.
400 // Fall back to the default value.
405 // Remove the problematic variable and return EFI_NOT_FOUND, a new
406 // variable will be set again.
410 &gEfiIp6ConfigProtocolGuid
,
411 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
416 return EFI_NOT_FOUND
;
420 // Get the IAID we use.
422 Instance
->IaId
= Variable
->IaId
;
424 for (Index
= 0; Index
< Variable
->DataRecordCount
; Index
++) {
426 CopyMem (&DataRecord
, &Variable
->DataRecord
[Index
], sizeof (DataRecord
));
428 DataItem
= &Instance
->DataItem
[DataRecord
.DataType
];
429 if (DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
) &&
430 (DataItem
->DataSize
!= DataRecord
.DataSize
)
433 // Perhaps a corrupted data record...
438 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
440 // This data item has variable length data.
442 DataItem
->Data
.Ptr
= AllocatePool (DataRecord
.DataSize
);
443 if (DataItem
->Data
.Ptr
== NULL
) {
445 // no memory resource
451 Data
= (CHAR8
*) Variable
+ DataRecord
.Offset
;
452 CopyMem (DataItem
->Data
.Ptr
, Data
, DataRecord
.DataSize
);
454 DataItem
->DataSize
= DataRecord
.DataSize
;
455 DataItem
->Status
= EFI_SUCCESS
;
466 Write the configuration data from IP6_CONFIG_INSTANCE to variable storage.
468 @param[in] VarName The pointer to the variable name.
469 @param[in] Instance The pointer to the IP6 configuration instance data.
471 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
472 @retval EFI_SUCCESS The configuration data is written successfully.
476 Ip6ConfigWriteConfigData (
478 IN IP6_CONFIG_INSTANCE
*Instance
483 IP6_CONFIG_DATA_ITEM
*DataItem
;
484 IP6_CONFIG_VARIABLE
*Variable
;
485 IP6_CONFIG_DATA_RECORD
*DataRecord
;
489 VarSize
= sizeof (IP6_CONFIG_VARIABLE
) - sizeof (IP6_CONFIG_DATA_RECORD
);
491 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
493 DataItem
= &Instance
->DataItem
[Index
];
494 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
496 VarSize
+= sizeof (IP6_CONFIG_DATA_RECORD
) + DataItem
->DataSize
;
500 Variable
= AllocatePool (VarSize
);
501 if (Variable
== NULL
) {
502 return EFI_OUT_OF_RESOURCES
;
505 Variable
->IaId
= Instance
->IaId
;
506 Heap
= (CHAR8
*) Variable
+ VarSize
;
507 Variable
->DataRecordCount
= 0;
509 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
511 DataItem
= &Instance
->DataItem
[Index
];
512 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
514 Heap
-= DataItem
->DataSize
;
515 CopyMem (Heap
, DataItem
->Data
.Ptr
, DataItem
->DataSize
);
517 DataRecord
= &Variable
->DataRecord
[Variable
->DataRecordCount
];
518 DataRecord
->DataType
= (EFI_IP6_CONFIG_DATA_TYPE
) Index
;
519 DataRecord
->DataSize
= (UINT32
) DataItem
->DataSize
;
520 DataRecord
->Offset
= (UINT16
) (Heap
- (CHAR8
*) Variable
);
522 Variable
->DataRecordCount
++;
526 Variable
->Checksum
= 0;
527 Variable
->Checksum
= (UINT16
) ~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
);
529 Status
= gRT
->SetVariable (
531 &gEfiIp6ConfigProtocolGuid
,
532 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
543 The work function for EfiIp6ConfigGetData() to get the interface information
544 of the communication device this IP6Config instance manages.
546 @param[in] Instance Pointer to the IP6 config instance data.
547 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
548 bytes, the size of buffer required to store the specified
550 @param[in] Data The data buffer in which the configuration data is returned.
551 Ignored if DataSize is ZERO.
553 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
554 configuration data, and the required size is
555 returned in DataSize.
556 @retval EFI_SUCCESS The specified configuration data was obtained.
561 IN IP6_CONFIG_INSTANCE
*Instance
,
562 IN OUT UINTN
*DataSize
,
563 IN VOID
*Data OPTIONAL
568 IP6_CONFIG_DATA_ITEM
*Item
;
569 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
573 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
574 Length
= sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
);
577 // Calculate the required length, add the buffer size for AddressInfo and
580 Ip6BuildEfiAddressList (IpSb
, &AddressCount
, NULL
);
581 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &RouteCount
, NULL
);
583 Length
+= AddressCount
* sizeof (EFI_IP6_ADDRESS_INFO
) + RouteCount
* sizeof (EFI_IP6_ROUTE_TABLE
);
585 if (*DataSize
< Length
) {
587 return EFI_BUFFER_TOO_SMALL
;
591 // Copy the fixed size part of the interface info.
593 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
594 IfInfo
= (EFI_IP6_CONFIG_INTERFACE_INFO
*) Data
;
595 CopyMem (IfInfo
, Item
->Data
.Ptr
, sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
));
600 IfInfo
->AddressInfo
= (EFI_IP6_ADDRESS_INFO
*) (IfInfo
+ 1);
601 Ip6BuildEfiAddressList (IpSb
, &IfInfo
->AddressInfoCount
, &IfInfo
->AddressInfo
);
606 IfInfo
->RouteTable
= (EFI_IP6_ROUTE_TABLE
*) (IfInfo
->AddressInfo
+ IfInfo
->AddressInfoCount
);
607 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &IfInfo
->RouteCount
, &IfInfo
->RouteTable
);
609 if (IfInfo
->AddressInfoCount
== 0) {
610 IfInfo
->AddressInfo
= NULL
;
613 if (IfInfo
->RouteCount
== 0) {
614 IfInfo
->RouteTable
= NULL
;
621 The work function for EfiIp6ConfigSetData() to set the alternative inteface ID
622 for the communication device managed by this IP6Config instance, if the link local
623 IPv6 addresses generated from the interface ID based on the default source the
624 EFI IPv6 Protocol uses is a duplicate address.
626 @param[in] Instance Pointer to the IP6 configuration instance data.
627 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
628 @param[in] Data The data buffer to set.
630 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
632 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
633 network stack was set.
637 Ip6ConfigSetAltIfId (
638 IN IP6_CONFIG_INSTANCE
*Instance
,
643 EFI_IP6_CONFIG_INTERFACE_ID
*OldIfId
;
644 EFI_IP6_CONFIG_INTERFACE_ID
*NewIfId
;
645 IP6_CONFIG_DATA_ITEM
*DataItem
;
647 if (DataSize
!= sizeof (EFI_IP6_CONFIG_INTERFACE_ID
)) {
648 return EFI_BAD_BUFFER_SIZE
;
651 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
652 OldIfId
= DataItem
->Data
.AltIfId
;
653 NewIfId
= (EFI_IP6_CONFIG_INTERFACE_ID
*) Data
;
655 CopyMem (OldIfId
, NewIfId
, DataSize
);
656 DataItem
->Status
= EFI_SUCCESS
;
662 The work function for EfiIp6ConfigSetData() to set the general configuration
663 policy for the EFI IPv6 network stack that is running on the communication device
664 managed by this IP6Config instance. The policy will affect other configuration settings.
666 @param[in] Instance Pointer to the IP6 config instance data.
667 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
668 @param[in] Data The data buffer to set.
670 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
671 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
672 @retval EFI_ABORTED The new policy equals the current policy.
673 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
674 network stack was set.
679 IN IP6_CONFIG_INSTANCE
*Instance
,
684 EFI_IP6_CONFIG_POLICY NewPolicy
;
685 IP6_CONFIG_DATA_ITEM
*DataItem
;
688 if (DataSize
!= sizeof (EFI_IP6_CONFIG_POLICY
)) {
689 return EFI_BAD_BUFFER_SIZE
;
692 NewPolicy
= *((EFI_IP6_CONFIG_POLICY
*) Data
);
694 if (NewPolicy
> Ip6ConfigPolicyAutomatic
) {
695 return EFI_INVALID_PARAMETER
;
698 if (NewPolicy
== Instance
->Policy
) {
703 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
704 // data size, and fire up all the related events.
706 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
707 if (DataItem
->Data
.Ptr
!= NULL
) {
708 FreePool (DataItem
->Data
.Ptr
);
710 DataItem
->Data
.Ptr
= NULL
;
711 DataItem
->DataSize
= 0;
712 DataItem
->Status
= EFI_NOT_FOUND
;
713 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
715 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
716 if (DataItem
->Data
.Ptr
!= NULL
) {
717 FreePool (DataItem
->Data
.Ptr
);
719 DataItem
->Data
.Ptr
= NULL
;
720 DataItem
->DataSize
= 0;
721 DataItem
->Status
= EFI_NOT_FOUND
;
722 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
724 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
725 DataItem
->Data
.Ptr
= NULL
;
726 DataItem
->DataSize
= 0;
727 DataItem
->Status
= EFI_NOT_FOUND
;
728 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
730 if (NewPolicy
== Ip6ConfigPolicyManual
) {
732 // The policy is changed from automatic to manual. Stop the DHCPv6 process
733 // and destroy the DHCPv6 child.
735 if (Instance
->Dhcp6Handle
!= NULL
) {
736 Ip6ConfigDestroyDhcp6 (Instance
);
740 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
741 Ip6ConfigOnPolicyChanged (IpSb
, NewPolicy
);
743 Instance
->Policy
= NewPolicy
;
750 The work function for EfiIp6ConfigSetData() to set the number of consecutive
751 Neighbor Solicitation messages sent while performing Duplicate Address Detection
752 on a tentative address. A value of ZERO indicates that Duplicate Address Detection
753 will not be performed on a tentative address.
755 @param[in] Instance The Instance Pointer to the IP6 config instance data.
756 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
757 @param[in] Data The data buffer to set.
759 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
760 @retval EFI_ABORTED The new transmit count equals the current configuration.
761 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
762 network stack was set.
766 Ip6ConfigSetDadXmits (
767 IN IP6_CONFIG_INSTANCE
*Instance
,
772 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
*OldDadXmits
;
774 if (DataSize
!= sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
)) {
775 return EFI_BAD_BUFFER_SIZE
;
778 OldDadXmits
= Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
].Data
.DadXmits
;
780 if ((*(UINT32
*) Data
) == OldDadXmits
->DupAddrDetectTransmits
) {
785 OldDadXmits
->DupAddrDetectTransmits
= *((UINT32
*) Data
);
791 The callback function for Ip6SetAddr. The prototype is defined
792 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
793 for the manual address set by Ip6ConfigSetManualAddress.
795 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passed.
796 @param[in] TargetAddress The tentative IPv6 address to be checked.
797 @param[in] Context Pointer to the IP6 configuration instance data.
801 Ip6ManualAddrDadCallback (
802 IN BOOLEAN IsDadPassed
,
803 IN EFI_IPv6_ADDRESS
*TargetAddress
,
807 IP6_CONFIG_INSTANCE
*Instance
;
809 IP6_CONFIG_DATA_ITEM
*Item
;
810 EFI_IP6_CONFIG_MANUAL_ADDRESS
*ManualAddr
;
811 EFI_IP6_CONFIG_MANUAL_ADDRESS
*PassedAddr
;
816 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
817 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
818 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
821 if (Item
->DataSize
== 0) {
825 for (Index
= 0; Index
< Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
); Index
++) {
827 // Find the original tag used to place into the NET_MAP.
829 ManualAddr
= Item
->Data
.ManualAddress
+ Index
;
830 if (EFI_IP6_EQUAL (TargetAddress
, &ManualAddr
->Address
)) {
835 ASSERT (Index
!= Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
838 NetMapInsertTail (&Instance
->DadPassedMap
, ManualAddr
, NULL
);
840 NetMapInsertTail (&Instance
->DadFailedMap
, ManualAddr
, NULL
);
843 DadPassCount
= NetMapGetCount (&Instance
->DadPassedMap
);
844 DadFailCount
= NetMapGetCount (&Instance
->DadFailedMap
);
846 if ((DadPassCount
+ DadFailCount
) == (Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
))) {
848 // All addresses have finished the configuration process.
850 if (DadFailCount
!= 0) {
852 // There is at least one duplicate address.
854 FreePool (Item
->Data
.Ptr
);
856 Item
->DataSize
= DadPassCount
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
857 if (Item
->DataSize
== 0) {
859 // All failed, bad luck.
861 Item
->Data
.Ptr
= NULL
;
862 Item
->Status
= EFI_NOT_FOUND
;
865 // Part of addresses are detected to be duplicates, so update the
866 // data with those passed.
868 PassedAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) AllocatePool (Item
->DataSize
);
869 ASSERT (PassedAddr
!= NULL
);
871 Item
->Data
.Ptr
= PassedAddr
;
872 Item
->Status
= EFI_SUCCESS
;
874 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
875 ManualAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
876 CopyMem (PassedAddr
, ManualAddr
, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
881 ASSERT ((UINTN
) PassedAddr
- (UINTN
) Item
->Data
.Ptr
== Item
->DataSize
);
885 // All addresses are valid.
887 Item
->Status
= EFI_SUCCESS
;
891 // Remove the tags we put in the NET_MAPs.
893 while (!NetMapIsEmpty (&Instance
->DadFailedMap
)) {
894 NetMapRemoveHead (&Instance
->DadFailedMap
, NULL
);
897 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
898 NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
902 // Signal the waiting events.
904 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
905 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
906 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
911 The work function for EfiIp6ConfigSetData() to set the station addresses manually
912 for the EFI IPv6 network stack. It is only configurable when the policy is
913 Ip6ConfigPolicyManual.
915 @param[in] Instance Pointer to the IP6 configuration instance data.
916 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
917 @param[in] Data The data buffer to set.
919 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
920 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
921 under the current policy.
922 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
923 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
924 @retval EFI_NOT_READY An asynchrous process is invoked to set the specified
925 configuration data, and the process is not finished.
926 @retval EFI_ABORTED The manual addresses to be set equal current
928 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
929 network stack was set.
933 Ip6ConfigSetManualAddress (
934 IN IP6_CONFIG_INSTANCE
*Instance
,
939 EFI_IP6_CONFIG_MANUAL_ADDRESS
*NewAddress
;
940 EFI_IP6_CONFIG_MANUAL_ADDRESS
*TmpAddress
;
941 IP6_CONFIG_DATA_ITEM
*DataItem
;
942 UINTN NewAddressCount
;
946 IP6_ADDRESS_INFO
*CurrentAddrInfo
;
947 IP6_ADDRESS_INFO
*Copy
;
948 LIST_ENTRY CurrentSourceList
;
949 UINT32 CurrentSourceCount
;
953 IP6_PREFIX_LIST_ENTRY
*PrefixEntry
;
957 IP6_DAD_ENTRY
*DadEntry
;
958 IP6_DELAY_JOIN_LIST
*DelayNode
;
962 CurrentAddrInfo
= NULL
;
971 Status
= EFI_SUCCESS
;
973 ASSERT (Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
].Status
!= EFI_NOT_READY
);
975 if ((DataSize
!= 0) && ((DataSize
% sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
)) != 0)) {
976 return EFI_BAD_BUFFER_SIZE
;
979 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
980 return EFI_WRITE_PROTECTED
;
983 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
985 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
987 if (Data
!= NULL
&& DataSize
!= 0) {
988 NewAddressCount
= DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
989 NewAddress
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) Data
;
991 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
993 if (NetIp6IsLinkLocalAddr (&NewAddress
->Address
) ||
994 !NetIp6IsValidUnicast (&NewAddress
->Address
) ||
995 (NewAddress
->PrefixLength
> 128)
998 // make sure the IPv6 address is unicast and not link-local address &&
999 // the prefix length is valid.
1001 return EFI_INVALID_PARAMETER
;
1004 TmpAddress
= NewAddress
+ 1;
1005 for (Index2
= Index1
+ 1; Index2
< NewAddressCount
; Index2
++, TmpAddress
++) {
1007 // Any two addresses in the array can't be equal.
1009 if (EFI_IP6_EQUAL (&TmpAddress
->Address
, &NewAddress
->Address
)) {
1011 return EFI_INVALID_PARAMETER
;
1017 // Build the current source address list.
1019 InitializeListHead (&CurrentSourceList
);
1020 CurrentSourceCount
= 0;
1022 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1023 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
1025 NET_LIST_FOR_EACH (Entry2
, &IpIf
->AddressList
) {
1026 CurrentAddrInfo
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
1028 Copy
= AllocateCopyPool (sizeof (IP6_ADDRESS_INFO
), CurrentAddrInfo
);
1033 InsertTailList (&CurrentSourceList
, &Copy
->Link
);
1034 CurrentSourceCount
++;
1039 // Update the value... a long journey starts
1041 NewAddress
= AllocateCopyPool (DataSize
, Data
);
1042 if (NewAddress
== NULL
) {
1043 Ip6RemoveAddr (NULL
, &CurrentSourceList
, &CurrentSourceCount
, NULL
, 0);
1045 return EFI_OUT_OF_RESOURCES
;
1049 // Store the new data, and init the DataItem status to EFI_NOT_READY because
1050 // we may have an asynchronous configuration process.
1052 if (DataItem
->Data
.Ptr
!= NULL
) {
1053 FreePool (DataItem
->Data
.Ptr
);
1055 DataItem
->Data
.Ptr
= NewAddress
;
1056 DataItem
->DataSize
= DataSize
;
1057 DataItem
->Status
= EFI_NOT_READY
;
1060 // Trigger DAD, it's an asynchronous process.
1064 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
1065 if (Ip6IsOneOfSetAddress (IpSb
, &NewAddress
->Address
, NULL
, &CurrentAddrInfo
)) {
1066 ASSERT (CurrentAddrInfo
!= NULL
);
1068 // Remove this already existing source address from the CurrentSourceList
1074 &CurrentSourceCount
,
1075 &CurrentAddrInfo
->Address
,
1080 // If the new address's prefix length is not specified, just use the previous configured
1081 // prefix length for this address.
1083 if (NewAddress
->PrefixLength
== 0) {
1084 NewAddress
->PrefixLength
= CurrentAddrInfo
->PrefixLength
;
1088 // This manual address is already in use, see whether prefix length is changed.
1090 if (NewAddress
->PrefixLength
!= CurrentAddrInfo
->PrefixLength
) {
1092 // Remove the on-link prefix table, the route entry will be removed
1095 PrefixEntry
= Ip6FindPrefixListEntry (
1098 CurrentAddrInfo
->PrefixLength
,
1099 &CurrentAddrInfo
->Address
1101 if (PrefixEntry
!= NULL
) {
1102 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1106 // Save the prefix length.
1108 CurrentAddrInfo
->PrefixLength
= NewAddress
->PrefixLength
;
1113 // create a new on-link prefix entry.
1115 PrefixEntry
= Ip6FindPrefixListEntry (
1118 NewAddress
->PrefixLength
,
1119 &NewAddress
->Address
1121 if (PrefixEntry
== NULL
) {
1122 Ip6CreatePrefixListEntry (
1125 (UINT32
) IP6_INFINIT_LIFETIME
,
1126 (UINT32
) IP6_INFINIT_LIFETIME
,
1127 NewAddress
->PrefixLength
,
1128 &NewAddress
->Address
1132 CurrentAddrInfo
->IsAnycast
= NewAddress
->IsAnycast
;
1134 // Artificially mark this address passed DAD be'coz it is already in use.
1136 Ip6ManualAddrDadCallback (TRUE
, &NewAddress
->Address
, Instance
);
1144 // Set the new address, this will trigger DAD and activate the address if
1148 IpSb
->DefaultInterface
,
1149 &NewAddress
->Address
,
1150 NewAddress
->IsAnycast
,
1151 NewAddress
->PrefixLength
,
1152 (UINT32
) IP6_INFINIT_LIFETIME
,
1153 (UINT32
) IP6_INFINIT_LIFETIME
,
1154 Ip6ManualAddrDadCallback
,
1161 // Check the CurrentSourceList, it now contains those addresses currently in
1162 // use and will be removed.
1164 IpIf
= IpSb
->DefaultInterface
;
1166 while (!IsListEmpty (&CurrentSourceList
)) {
1169 CurrentAddrInfo
= NET_LIST_HEAD (&CurrentSourceList
, IP6_ADDRESS_INFO
, Link
);
1172 // This local address is going to be removed, the IP instances that are
1173 // currently using it will be destroyed.
1178 &IpIf
->AddressCount
,
1179 &CurrentAddrInfo
->Address
,
1184 // Remove the on-link prefix table, the route entry will be removed
1187 PrefixEntry
= Ip6FindPrefixListEntry (
1190 CurrentAddrInfo
->PrefixLength
,
1191 &CurrentAddrInfo
->Address
1193 if (PrefixEntry
!= NULL
) {
1194 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1197 RemoveEntryList (&CurrentAddrInfo
->Link
);
1198 FreePool (CurrentAddrInfo
);
1202 if (DataItem
->Status
== EFI_NOT_READY
) {
1204 // If DAD is disabled on this interface, the configuration process is
1205 // actually synchronous, and the data item's status will be changed to
1206 // the final status before we reach here, just check it.
1208 Status
= EFI_NOT_READY
;
1210 Status
= EFI_SUCCESS
;
1214 // No update is taken, reset the status to success and return EFI_ABORTED.
1216 DataItem
->Status
= EFI_SUCCESS
;
1217 Status
= EFI_ABORTED
;
1221 // DataSize is 0 and Data is NULL, clean up the manual address.
1223 if (DataItem
->Data
.Ptr
!= NULL
) {
1224 FreePool (DataItem
->Data
.Ptr
);
1226 DataItem
->Data
.Ptr
= NULL
;
1227 DataItem
->DataSize
= 0;
1228 DataItem
->Status
= EFI_NOT_FOUND
;
1230 Ip6CleanDefaultRouterList (IpSb
);
1231 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
1232 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
1233 Ip6CleanAssembleTable (&IpSb
->Assemble
);
1235 if (IpSb
->LinkLocalOk
) {
1236 Ip6CreatePrefixListEntry (
1239 (UINT32
) IP6_INFINIT_LIFETIME
,
1240 (UINT32
) IP6_INFINIT_LIFETIME
,
1241 IP6_LINK_LOCAL_PREFIX_LENGTH
,
1242 &IpSb
->LinkLocalAddr
1248 &IpSb
->DefaultInterface
->AddressList
,
1249 &IpSb
->DefaultInterface
->AddressCount
,
1254 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1256 // Remove all pending delay node and DAD entries for the global addresses.
1258 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
1260 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DelayJoinList
) {
1261 DelayNode
= NET_LIST_USER_STRUCT (Entry2
, IP6_DELAY_JOIN_LIST
, Link
);
1262 if (!NetIp6IsLinkLocalAddr (&DelayNode
->AddressInfo
->Address
)) {
1263 RemoveEntryList (&DelayNode
->Link
);
1264 FreePool (DelayNode
);
1268 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DupAddrDetectList
) {
1269 DadEntry
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_DAD_ENTRY
, Link
, IP6_DAD_ENTRY_SIGNATURE
);
1271 if (!NetIp6IsLinkLocalAddr (&DadEntry
->AddressInfo
->Address
)) {
1273 // Fail this DAD entry if the address is not link-local.
1275 Ip6OnDADFinished (FALSE
, IpIf
, DadEntry
);
1285 The work function for EfiIp6ConfigSetData() to set the gateway addresses manually
1286 for the EFI IPv6 network stack that is running on the communication device that
1287 this EFI IPv6 Configuration Protocol manages. It is not configurable when the policy is
1288 Ip6ConfigPolicyAutomatic. The gateway addresses must be unicast IPv6 addresses.
1290 @param[in] Instance The pointer to the IP6 config instance data.
1291 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1292 @param[in] Data The data buffer to set. This points to an array of
1293 EFI_IPv6_ADDRESS instances.
1295 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1296 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1297 under the current policy.
1298 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1299 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1300 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1301 current configuration.
1302 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1303 network stack was set.
1307 Ip6ConfigSetGateway (
1308 IN IP6_CONFIG_INSTANCE
*Instance
,
1315 EFI_IPv6_ADDRESS
*OldGateway
;
1316 EFI_IPv6_ADDRESS
*NewGateway
;
1317 UINTN OldGatewayCount
;
1318 UINTN NewGatewayCount
;
1319 IP6_CONFIG_DATA_ITEM
*Item
;
1323 IP6_DEFAULT_ROUTER
*DefaultRouter
;
1329 DefaultRouter
= NULL
;
1334 if ((DataSize
!= 0) && (DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0)) {
1335 return EFI_BAD_BUFFER_SIZE
;
1338 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1339 return EFI_WRITE_PROTECTED
;
1342 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1343 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
1344 OldGateway
= Item
->Data
.Gateway
;
1345 OldGatewayCount
= Item
->DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1347 for (Index1
= 0; Index1
< OldGatewayCount
; Index1
++) {
1349 // Remove this default router.
1351 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, OldGateway
+ Index1
);
1352 if (DefaultRouter
!= NULL
) {
1353 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
1358 if (Data
!= NULL
&& DataSize
!= 0) {
1359 NewGateway
= (EFI_IPv6_ADDRESS
*) Data
;
1360 NewGatewayCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1361 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1363 if (!NetIp6IsValidUnicast (NewGateway
+ Index1
)) {
1365 return EFI_INVALID_PARAMETER
;
1368 for (Index2
= Index1
+ 1; Index2
< NewGatewayCount
; Index2
++) {
1369 if (EFI_IP6_EQUAL (NewGateway
+ Index1
, NewGateway
+ Index2
)) {
1370 return EFI_INVALID_PARAMETER
;
1375 if (NewGatewayCount
!= OldGatewayCount
) {
1376 Tmp
= AllocatePool (DataSize
);
1378 return EFI_OUT_OF_RESOURCES
;
1384 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1386 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, NewGateway
+ Index1
);
1387 if (DefaultRouter
== NULL
) {
1388 Ip6CreateDefaultRouter (IpSb
, NewGateway
+ Index1
, IP6_INF_ROUTER_LIFETIME
);
1393 if (!OneRemoved
&& !OneAdded
) {
1394 Item
->Status
= EFI_SUCCESS
;
1399 if (Item
->Data
.Ptr
!= NULL
) {
1400 FreePool (Item
->Data
.Ptr
);
1402 Item
->Data
.Ptr
= Tmp
;
1405 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1406 Item
->DataSize
= DataSize
;
1407 Item
->Status
= EFI_SUCCESS
;
1412 // DataSize is 0 and Data is NULL, clean up the Gateway address.
1414 if (Item
->Data
.Ptr
!= NULL
) {
1415 FreePool (Item
->Data
.Ptr
);
1417 Item
->Data
.Ptr
= NULL
;
1419 Item
->Status
= EFI_NOT_FOUND
;
1426 The work function for EfiIp6ConfigSetData() to set the DNS server list for the
1427 EFI IPv6 network stack running on the communication device that this EFI IPv6
1428 Configuration Protocol manages. It is not configurable when the policy is
1429 Ip6ConfigPolicyAutomatic. The DNS server addresses must be unicast IPv6 addresses.
1431 @param[in] Instance The pointer to the IP6 config instance data.
1432 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1433 @param[in] Data The data buffer to set, points to an array of
1434 EFI_IPv6_ADDRESS instances.
1436 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1437 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1438 under the current policy.
1439 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1440 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1441 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1443 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1444 network stack was set.
1448 Ip6ConfigSetDnsServer (
1449 IN IP6_CONFIG_INSTANCE
*Instance
,
1456 EFI_IPv6_ADDRESS
*OldDns
;
1457 EFI_IPv6_ADDRESS
*NewDns
;
1460 IP6_CONFIG_DATA_ITEM
*Item
;
1469 if ((DataSize
!= 0) && (DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0)) {
1470 return EFI_BAD_BUFFER_SIZE
;
1473 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1474 return EFI_WRITE_PROTECTED
;
1477 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1479 if (Data
!= NULL
&& DataSize
!= 0) {
1480 NewDns
= (EFI_IPv6_ADDRESS
*) Data
;
1481 OldDns
= Item
->Data
.DnsServers
;
1482 NewDnsCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1483 OldDnsCount
= Item
->DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1486 if (NewDnsCount
!= OldDnsCount
) {
1487 Tmp
= AllocatePool (DataSize
);
1489 return EFI_OUT_OF_RESOURCES
;
1495 for (NewIndex
= 0; NewIndex
< NewDnsCount
; NewIndex
++) {
1497 if (!NetIp6IsValidUnicast (NewDns
+ NewIndex
)) {
1499 // The dns server address must be unicast.
1504 return EFI_INVALID_PARAMETER
;
1509 // If any address in the new setting is not in the old settings, skip the
1510 // comparision below.
1515 for (OldIndex
= 0; OldIndex
< OldDnsCount
; OldIndex
++) {
1516 if (EFI_IP6_EQUAL (NewDns
+ NewIndex
, OldDns
+ OldIndex
)) {
1518 // If found break out.
1524 if (OldIndex
== OldDnsCount
) {
1529 if (!OneAdded
&& (DataSize
== Item
->DataSize
)) {
1531 // No new item is added and the size is the same.
1533 Item
->Status
= EFI_SUCCESS
;
1537 if (Item
->Data
.Ptr
!= NULL
) {
1538 FreePool (Item
->Data
.Ptr
);
1540 Item
->Data
.Ptr
= Tmp
;
1543 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1544 Item
->DataSize
= DataSize
;
1545 Item
->Status
= EFI_SUCCESS
;
1549 // DataSize is 0 and Data is NULL, clean up the DnsServer address.
1551 if (Item
->Data
.Ptr
!= NULL
) {
1552 FreePool (Item
->Data
.Ptr
);
1554 Item
->Data
.Ptr
= NULL
;
1556 Item
->Status
= EFI_NOT_FOUND
;
1563 Generate the operational state of the interface this IP6 config instance manages
1564 and output in EFI_IP6_CONFIG_INTERFACE_INFO.
1566 @param[in] IpSb The pointer to the IP6 service binding instance.
1567 @param[out] IfInfo The pointer to the IP6 configuration interface information structure.
1571 Ip6ConfigInitIfInfo (
1572 IN IP6_SERVICE
*IpSb
,
1573 OUT EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
1578 sizeof (IfInfo
->Name
),
1580 IpSb
->Ip6ConfigInstance
.IfIndex
1583 IfInfo
->IfType
= IpSb
->SnpMode
.IfType
;
1584 IfInfo
->HwAddressSize
= IpSb
->SnpMode
.HwAddressSize
;
1585 CopyMem (&IfInfo
->HwAddress
, &IpSb
->SnpMode
.CurrentAddress
, IfInfo
->HwAddressSize
);
1589 Parse DHCPv6 reply packet to get the DNS server list.
1590 It is the work function for Ip6ConfigOnDhcp6Reply and Ip6ConfigOnDhcp6Event.
1592 @param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL instance.
1593 @param[in, out] Instance The pointer to the IP6 configuration instance data.
1594 @param[in] Reply The pointer to the DHCPv6 reply packet.
1596 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1597 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1598 the DNS server address is not valid.
1602 Ip6ConfigParseDhcpReply (
1603 IN EFI_DHCP6_PROTOCOL
*Dhcp6
,
1604 IN OUT IP6_CONFIG_INSTANCE
*Instance
,
1605 IN EFI_DHCP6_PACKET
*Reply
1610 EFI_DHCP6_PACKET_OPTION
**OptList
;
1615 EFI_IPv6_ADDRESS
*DnsServer
;
1616 IP6_CONFIG_DATA_ITEM
*Item
;
1619 // A DHCPv6 reply packet is received as the response to our InfoRequest
1623 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, NULL
);
1624 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1625 return EFI_NOT_READY
;
1628 OptList
= AllocatePool (OptCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*));
1629 if (OptList
== NULL
) {
1630 return EFI_NOT_READY
;
1633 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, OptList
);
1634 if (EFI_ERROR (Status
)) {
1635 Status
= EFI_NOT_READY
;
1639 Status
= EFI_SUCCESS
;
1641 for (Index
= 0; Index
< OptCount
; Index
++) {
1643 // Go through all the options to check the ones we are interested in.
1644 // The OpCode and Length are in network byte-order and may not be naturally
1647 CopyMem (&OpCode
, &OptList
[Index
]->OpCode
, sizeof (OpCode
));
1648 OpCode
= NTOHS (OpCode
);
1650 if (OpCode
== DHCP6_OPT_DNS_SERVERS
) {
1651 CopyMem (&Length
, &OptList
[Index
]->OpLen
, sizeof (Length
));
1652 Length
= NTOHS (Length
);
1654 if ((Length
== 0) || ((Length
% sizeof (EFI_IPv6_ADDRESS
)) != 0)) {
1656 // The length should be a multiple of 16 bytes.
1658 Status
= EFI_NOT_READY
;
1663 // Validate the DnsServers: whether they are unicast addresses.
1665 DnsServer
= (EFI_IPv6_ADDRESS
*) OptList
[Index
]->Data
;
1666 for (Index2
= 0; Index2
< Length
/ sizeof (EFI_IPv6_ADDRESS
); Index2
++) {
1667 if (!NetIp6IsValidUnicast (DnsServer
)) {
1668 Status
= EFI_NOT_READY
;
1675 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1677 if (Item
->DataSize
!= Length
) {
1678 if (Item
->Data
.Ptr
!= NULL
) {
1679 FreePool (Item
->Data
.Ptr
);
1682 Item
->Data
.Ptr
= AllocatePool (Length
);
1683 ASSERT (Item
->Data
.Ptr
!= NULL
);
1686 CopyMem (Item
->Data
.Ptr
, OptList
[Index
]->Data
, Length
);
1687 Item
->DataSize
= Length
;
1688 Item
->Status
= EFI_SUCCESS
;
1691 // Signal the waiting events.
1693 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
1706 The callback function for Ip6SetAddr. The prototype is defined
1707 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
1708 on the tentative address by DHCPv6 in Ip6ConfigOnDhcp6Event().
1710 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passes.
1711 @param[in] TargetAddress The tentative IPv6 address to be checked.
1712 @param[in] Context Pointer to the IP6 configuration instance data.
1716 Ip6ConfigSetStatefulAddrCallback (
1717 IN BOOLEAN IsDadPassed
,
1718 IN EFI_IPv6_ADDRESS
*TargetAddress
,
1722 IP6_CONFIG_INSTANCE
*Instance
;
1724 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1725 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
1728 // We should record the addresses that fail the DAD, and DECLINE them.
1732 // Decrease the count, no interests in those passed DAD.
1734 if (Instance
->FailedIaAddressCount
> 0 ) {
1735 Instance
->FailedIaAddressCount
--;
1741 IP6_COPY_ADDRESS (Instance
->DeclineAddress
+ Instance
->DeclineAddressCount
, TargetAddress
);
1742 Instance
->DeclineAddressCount
++;
1745 if (Instance
->FailedIaAddressCount
== Instance
->DeclineAddressCount
) {
1747 // The checking on all addresses are finished.
1749 if (Instance
->DeclineAddressCount
!= 0) {
1751 // Decline those duplicates.
1753 if (Instance
->Dhcp6
!= NULL
) {
1754 Instance
->Dhcp6
->Decline (
1756 Instance
->DeclineAddressCount
,
1757 Instance
->DeclineAddress
1762 if (Instance
->DeclineAddress
!= NULL
) {
1763 FreePool (Instance
->DeclineAddress
);
1765 Instance
->DeclineAddress
= NULL
;
1766 Instance
->DeclineAddressCount
= 0;
1771 The event handle routine when DHCPv6 process is finished or is updated.
1773 @param[in] Event Not used.
1774 @param[in] Context The pointer to the IP6 configuration instance data.
1779 Ip6ConfigOnDhcp6Event (
1784 IP6_CONFIG_INSTANCE
*Instance
;
1785 EFI_DHCP6_PROTOCOL
*Dhcp6
;
1787 EFI_DHCP6_MODE_DATA Dhcp6ModeData
;
1789 EFI_DHCP6_IA_ADDRESS
*IaAddr
;
1792 IP6_ADDRESS_INFO
*AddrInfo
;
1793 IP6_INTERFACE
*IpIf
;
1795 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1797 if ((Instance
->Policy
!= Ip6ConfigPolicyAutomatic
) || Instance
->OtherInfoOnly
) {
1799 // IPv6 is not operating in the automatic policy now or
1800 // the DHCPv6 information request message exchange is aborted.
1806 // The stateful address autoconfiguration is done or updated.
1808 Dhcp6
= Instance
->Dhcp6
;
1810 Status
= Dhcp6
->GetModeData (Dhcp6
, &Dhcp6ModeData
, NULL
);
1811 if (EFI_ERROR (Status
)) {
1815 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1816 IpIf
= IpSb
->DefaultInterface
;
1817 Ia
= Dhcp6ModeData
.Ia
;
1818 IaAddr
= Ia
->IaAddress
;
1820 if (Instance
->DeclineAddress
!= NULL
) {
1821 FreePool (Instance
->DeclineAddress
);
1824 Instance
->DeclineAddress
= (EFI_IPv6_ADDRESS
*) AllocatePool (Ia
->IaAddressCount
* sizeof (EFI_IPv6_ADDRESS
));
1825 if (Instance
->DeclineAddress
== NULL
) {
1829 Instance
->FailedIaAddressCount
= Ia
->IaAddressCount
;
1830 Instance
->DeclineAddressCount
= 0;
1832 for (Index
= 0; Index
< Ia
->IaAddressCount
; Index
++, IaAddr
++) {
1833 if (Ia
->IaAddress
[Index
].ValidLifetime
!= 0 && Ia
->State
== Dhcp6Bound
) {
1835 // Set this address, either it's a new address or with updated lifetimes.
1836 // An appropriate prefix length will be set.
1843 IaAddr
->ValidLifetime
,
1844 IaAddr
->PreferredLifetime
,
1845 Ip6ConfigSetStatefulAddrCallback
,
1850 // discard this address, artificially decrease the count as if this address
1853 if (Ip6IsOneOfSetAddress (IpSb
, &IaAddr
->IpAddress
, NULL
, &AddrInfo
)) {
1854 ASSERT (AddrInfo
!= NULL
);
1858 &IpIf
->AddressCount
,
1860 AddrInfo
->PrefixLength
1864 if (Instance
->FailedIaAddressCount
> 0) {
1865 Instance
->FailedIaAddressCount
--;
1871 // Parse the Reply packet to get the options we need.
1873 if (Dhcp6ModeData
.Ia
->ReplyPacket
!= NULL
) {
1874 Ip6ConfigParseDhcpReply (Dhcp6
, Instance
, Dhcp6ModeData
.Ia
->ReplyPacket
);
1879 FreePool (Dhcp6ModeData
.ClientId
);
1880 FreePool (Dhcp6ModeData
.Ia
);
1884 The event process routine when the DHCPv6 server is answered with a reply packet
1885 for an information request.
1887 @param[in] This Points to the EFI_DHCP6_PROTOCOL.
1888 @param[in] Context The pointer to the IP6 configuration instance data.
1889 @param[in] Packet The DHCPv6 reply packet.
1891 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1892 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1893 the DNS server address is not valid.
1898 Ip6ConfigOnDhcp6Reply (
1899 IN EFI_DHCP6_PROTOCOL
*This
,
1901 IN EFI_DHCP6_PACKET
*Packet
1904 return Ip6ConfigParseDhcpReply (This
, (IP6_CONFIG_INSTANCE
*) Context
, Packet
);
1908 The event process routine when the DHCPv6 service binding protocol is installed
1911 @param[in] Event Not used.
1912 @param[in] Context The pointer to the IP6 config instance data.
1917 Ip6ConfigOnDhcp6SbInstalled (
1922 IP6_CONFIG_INSTANCE
*Instance
;
1924 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1926 if ((Instance
->Dhcp6Handle
!= NULL
) || (Instance
->Policy
!= Ip6ConfigPolicyAutomatic
)) {
1928 // The DHCP6 child is already created or the policy is no longer AUTOMATIC.
1933 Ip6ConfigStartStatefulAutoConfig (Instance
, Instance
->OtherInfoOnly
);
1937 Set the configuration for the EFI IPv6 network stack running on the communication
1938 device this EFI IPv6 Configuration Protocol instance manages.
1940 This function is used to set the configuration data of type DataType for the EFI
1941 IPv6 network stack that is running on the communication device that this EFI IPv6
1942 Configuration Protocol instance manages.
1944 DataSize is used to calculate the count of structure instances in the Data for
1945 a DataType in which multiple structure instances are allowed.
1947 This function is always non-blocking. When setting some type of configuration data,
1948 an asynchronous process is invoked to check the correctness of the data, such as
1949 performing Duplicate Address Detection on the manually set local IPv6 addresses.
1950 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1951 is invoked, and the process is not finished yet. The caller wanting to get the result
1952 of the asynchronous process is required to call RegisterDataNotify() to register an
1953 event on the specified configuration data. Once the event is signaled, the caller
1954 can call GetData() to obtain the configuration data and know the result.
1955 For other types of configuration data that do not require an asynchronous configuration
1956 process, the result of the operation is immediately returned.
1958 @param[in] This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1959 @param[in] DataType The type of data to set.
1960 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1961 @param[in] Data The data buffer to set. The type of the data buffer is
1962 associated with the DataType.
1964 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1965 network stack was set successfully.
1966 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1968 - One or more fields in Data and DataSizedo not match the
1969 requirement of the data type indicated by DataType.
1970 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1971 configuration data cannot be set under the current policy.
1972 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1973 data is already in process.
1974 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1975 configuration data, and the process is not finished yet.
1976 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1977 indicated by DataType.
1978 @retval EFI_UNSUPPORTED This DataType is not supported.
1979 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1980 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1985 EfiIp6ConfigSetData (
1986 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
1987 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
1994 IP6_CONFIG_INSTANCE
*Instance
;
1997 if ((This
== NULL
) || (Data
== NULL
&& DataSize
!= 0) || (Data
!= NULL
&& DataSize
== 0)) {
1998 return EFI_INVALID_PARAMETER
;
2001 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2002 return EFI_UNSUPPORTED
;
2005 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2006 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2007 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
2009 if (IpSb
->LinkLocalDadFail
) {
2010 return EFI_DEVICE_ERROR
;
2013 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2015 Status
= Instance
->DataItem
[DataType
].Status
;
2016 if (Status
!= EFI_NOT_READY
) {
2018 if (Instance
->DataItem
[DataType
].SetData
== NULL
) {
2020 // This type of data is readonly.
2022 Status
= EFI_WRITE_PROTECTED
;
2025 Status
= Instance
->DataItem
[DataType
].SetData (Instance
, DataSize
, Data
);
2026 if (!EFI_ERROR (Status
)) {
2028 // Fire up the events registered with this type of data.
2030 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
2031 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
2032 } else if (Status
== EFI_ABORTED
) {
2034 // The SetData is aborted because the data to set is the same with
2035 // the one maintained.
2037 Status
= EFI_SUCCESS
;
2038 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
2043 // Another asynchornous process is on the way.
2045 Status
= EFI_ACCESS_DENIED
;
2048 gBS
->RestoreTPL (OldTpl
);
2054 Get the configuration data for the EFI IPv6 network stack running on the communication
2055 device that this EFI IPv6 Configuration Protocol instance manages.
2057 This function returns the configuration data of type DataType for the EFI IPv6 network
2058 stack running on the communication device that this EFI IPv6 Configuration Protocol instance
2061 The caller is responsible for allocating the buffer used to return the specified
2062 configuration data. The required size will be returned to the caller if the size of
2063 the buffer is too small.
2065 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
2066 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
2067 to register an event on the specified configuration data. Once the asynchronous configuration
2068 process is finished, the event will be signaled, and a subsequent GetData() call will return
2069 the specified configuration data.
2071 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2072 @param[in] DataType The type of data to get.
2073 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
2074 size of buffer required to store the specified configuration data.
2075 @param[in] Data The data buffer in which the configuration data is returned. The
2076 type of the data buffer is associated with the DataType.
2077 This is an optional parameter that may be NULL.
2079 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
2080 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
2083 - Data is NULL if *DataSize is not zero.
2084 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
2085 and the required size is returned in DataSize.
2086 @retval EFI_NOT_READY The specified configuration data is not ready due to an
2087 asynchronous configuration process already in progress.
2088 @retval EFI_NOT_FOUND The specified configuration data is not found.
2093 EfiIp6ConfigGetData (
2094 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2095 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2096 IN OUT UINTN
*DataSize
,
2097 IN VOID
*Data OPTIONAL
2102 IP6_CONFIG_INSTANCE
*Instance
;
2103 IP6_CONFIG_DATA_ITEM
*DataItem
;
2105 if ((This
== NULL
) || (DataSize
== NULL
) || ((*DataSize
!= 0) && (Data
== NULL
))) {
2106 return EFI_INVALID_PARAMETER
;
2109 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2110 return EFI_NOT_FOUND
;
2113 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2115 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2116 DataItem
= &Instance
->DataItem
[DataType
];
2118 Status
= Instance
->DataItem
[DataType
].Status
;
2119 if (!EFI_ERROR (Status
)) {
2121 if (DataItem
->GetData
!= NULL
) {
2123 Status
= DataItem
->GetData (Instance
, DataSize
, Data
);
2124 } else if (*DataSize
< Instance
->DataItem
[DataType
].DataSize
) {
2126 // Update the buffer length.
2128 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
2129 Status
= EFI_BUFFER_TOO_SMALL
;
2132 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
2133 CopyMem (Data
, Instance
->DataItem
[DataType
].Data
.Ptr
, *DataSize
);
2137 gBS
->RestoreTPL (OldTpl
);
2143 Register an event that is signaled whenever a configuration process on the specified
2144 configuration data is done.
2146 This function registers an event that is to be signaled whenever a configuration
2147 process on the specified configuration data is performed. An event can be registered
2148 for a different DataType simultaneously. The caller is responsible for determining
2149 which type of configuration data causes the signaling of the event in such an event.
2151 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2152 @param[in] DataType The type of data to unregister the event for.
2153 @param[in] Event The event to register.
2155 @retval EFI_SUCCESS The notification event for the specified configuration data is
2157 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2158 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
2160 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2161 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
2166 EfiIp6ConfigRegisterDataNotify (
2167 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2168 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2174 IP6_CONFIG_INSTANCE
*Instance
;
2178 if ((This
== NULL
) || (Event
== NULL
)) {
2179 return EFI_INVALID_PARAMETER
;
2182 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2183 return EFI_UNSUPPORTED
;
2186 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2188 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2189 EventMap
= &Instance
->DataItem
[DataType
].EventMap
;
2192 // Check whether this event is already registered for this DataType.
2194 Item
= NetMapFindKey (EventMap
, Event
);
2197 Status
= NetMapInsertTail (EventMap
, Event
, NULL
);
2199 if (EFI_ERROR (Status
)) {
2201 Status
= EFI_OUT_OF_RESOURCES
;
2206 Status
= EFI_ACCESS_DENIED
;
2209 gBS
->RestoreTPL (OldTpl
);
2215 Remove a previously registered event for the specified configuration data.
2217 @param This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2218 @param DataType The type of data to remove from the previously
2220 @param Event The event to be unregistered.
2222 @retval EFI_SUCCESS The event registered for the specified
2223 configuration data was removed.
2224 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2225 @retval EFI_NOT_FOUND The Event has not been registered for the
2231 EfiIp6ConfigUnregisterDataNotify (
2232 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2233 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2239 IP6_CONFIG_INSTANCE
*Instance
;
2242 if ((This
== NULL
) || (Event
== NULL
)) {
2243 return EFI_INVALID_PARAMETER
;
2246 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2247 return EFI_NOT_FOUND
;
2250 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2252 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2254 Item
= NetMapFindKey (&Instance
->DataItem
[DataType
].EventMap
, Event
);
2257 NetMapRemoveItem (&Instance
->DataItem
[DataType
].EventMap
, Item
, NULL
);
2258 Status
= EFI_SUCCESS
;
2261 Status
= EFI_NOT_FOUND
;
2264 gBS
->RestoreTPL (OldTpl
);
2270 Initialize an IP6_CONFIG_INSTANCE.
2272 @param[out] Instance The buffer of IP6_CONFIG_INSTANCE to be initialized.
2274 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
2275 @retval EFI_SUCCESS The IP6_CONFIG_INSTANCE initialized successfully.
2279 Ip6ConfigInitInstance (
2280 OUT IP6_CONFIG_INSTANCE
*Instance
2284 IP6_CONFIG_INSTANCE
*TmpInstance
;
2289 IP6_CONFIG_DATA_ITEM
*DataItem
;
2291 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2293 Instance
->Signature
= IP6_CONFIG_INSTANCE_SIGNATURE
;
2296 // Determine the index of this interface.
2299 NET_LIST_FOR_EACH (Entry
, &mIp6ConfigInstanceList
) {
2300 TmpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_CONFIG_INSTANCE
, Link
, IP6_CONFIG_INSTANCE_SIGNATURE
);
2302 if (TmpInstance
->IfIndex
> IfIndex
) {
2304 // There is a sequence hole because some interface is down.
2312 Instance
->IfIndex
= IfIndex
;
2313 NetListInsertBefore (Entry
, &Instance
->Link
);
2315 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2317 // Initialize the event map for each data item.
2319 NetMapInit (&Instance
->DataItem
[Index
].EventMap
);
2323 // Initialize the NET_MAPs used for DAD on manually configured source addresses.
2325 NetMapInit (&Instance
->DadFailedMap
);
2326 NetMapInit (&Instance
->DadPassedMap
);
2329 // Initialize each data type: associate storage and set data size for the
2330 // fixed size data types, hook the SetData function, set the data attribute.
2332 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
2333 DataItem
->GetData
= Ip6ConfigGetIfInfo
;
2334 DataItem
->Data
.Ptr
= &Instance
->InterfaceInfo
;
2335 DataItem
->DataSize
= sizeof (Instance
->InterfaceInfo
);
2336 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
| DATA_ATTRIB_VOLATILE
);
2337 Ip6ConfigInitIfInfo (IpSb
, &Instance
->InterfaceInfo
);
2339 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
2340 DataItem
->SetData
= Ip6ConfigSetAltIfId
;
2341 DataItem
->Data
.Ptr
= &Instance
->AltIfId
;
2342 DataItem
->DataSize
= sizeof (Instance
->AltIfId
);
2343 DataItem
->Status
= EFI_NOT_FOUND
;
2344 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2346 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypePolicy
];
2347 DataItem
->SetData
= Ip6ConfigSetPolicy
;
2348 DataItem
->Data
.Ptr
= &Instance
->Policy
;
2349 DataItem
->DataSize
= sizeof (Instance
->Policy
);
2350 Instance
->Policy
= Ip6ConfigPolicyManual
;
2351 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2353 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
];
2354 DataItem
->SetData
= Ip6ConfigSetDadXmits
;
2355 DataItem
->Data
.Ptr
= &Instance
->DadXmits
;
2356 DataItem
->DataSize
= sizeof (Instance
->DadXmits
);
2357 Instance
->DadXmits
.DupAddrDetectTransmits
= IP6_CONFIG_DEFAULT_DAD_XMITS
;
2358 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2360 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
2361 DataItem
->SetData
= Ip6ConfigSetManualAddress
;
2362 DataItem
->Status
= EFI_NOT_FOUND
;
2364 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
2365 DataItem
->SetData
= Ip6ConfigSetGateway
;
2366 DataItem
->Status
= EFI_NOT_FOUND
;
2368 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
2369 DataItem
->SetData
= Ip6ConfigSetDnsServer
;
2370 DataItem
->Status
= EFI_NOT_FOUND
;
2373 // Create the event used for DHCP.
2375 Status
= gBS
->CreateEvent (
2378 Ip6ConfigOnDhcp6Event
,
2380 &Instance
->Dhcp6Event
2382 ASSERT_EFI_ERROR (Status
);
2384 Instance
->Configured
= TRUE
;
2387 // Try to read the config data from NV variable.
2389 Status
= Ip6ConfigReadConfigData (IpSb
->MacString
, Instance
);
2390 if (Status
== EFI_NOT_FOUND
) {
2392 // The NV variable is not set, so generate a random IAID, and write down the
2393 // fresh new configuration as the NV variable now.
2395 Instance
->IaId
= NET_RANDOM (NetRandomInitSeed ());
2397 for (Index
= 0; Index
< IpSb
->SnpMode
.HwAddressSize
; Index
++) {
2398 Instance
->IaId
|= (IpSb
->SnpMode
.CurrentAddress
.Addr
[Index
] << ((Index
<< 3) & 31));
2401 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
2402 } else if (EFI_ERROR (Status
)) {
2406 Instance
->Ip6Config
.SetData
= EfiIp6ConfigSetData
;
2407 Instance
->Ip6Config
.GetData
= EfiIp6ConfigGetData
;
2408 Instance
->Ip6Config
.RegisterDataNotify
= EfiIp6ConfigRegisterDataNotify
;
2409 Instance
->Ip6Config
.UnregisterDataNotify
= EfiIp6ConfigUnregisterDataNotify
;
2413 // Publish the IP6 configuration form
2415 return Ip6ConfigFormInit (Instance
);
2419 Release an IP6_CONFIG_INSTANCE.
2421 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2425 Ip6ConfigCleanInstance (
2426 IN OUT IP6_CONFIG_INSTANCE
*Instance
2430 IP6_CONFIG_DATA_ITEM
*DataItem
;
2432 if (Instance
->DeclineAddress
!= NULL
) {
2433 FreePool (Instance
->DeclineAddress
);
2436 if (!Instance
->Configured
) {
2440 if (Instance
->Dhcp6Handle
!= NULL
) {
2442 Ip6ConfigDestroyDhcp6 (Instance
);
2448 if (Instance
->Dhcp6Event
!= NULL
) {
2449 gBS
->CloseEvent (Instance
->Dhcp6Event
);
2452 NetMapClean (&Instance
->DadPassedMap
);
2453 NetMapClean (&Instance
->DadFailedMap
);
2455 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2457 DataItem
= &Instance
->DataItem
[Index
];
2459 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
2460 if (DataItem
->Data
.Ptr
!= NULL
) {
2461 FreePool (DataItem
->Data
.Ptr
);
2463 DataItem
->Data
.Ptr
= NULL
;
2464 DataItem
->DataSize
= 0;
2467 NetMapClean (&Instance
->DataItem
[Index
].EventMap
);
2470 Ip6ConfigFormUnload (Instance
);
2472 RemoveEntryList (&Instance
->Link
);
2476 Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.
2478 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2480 @retval EFI_SUCCESS The child was successfully destroyed.
2481 @retval Others Failed to destroy the child.
2485 Ip6ConfigDestroyDhcp6 (
2486 IN OUT IP6_CONFIG_INSTANCE
*Instance
2491 EFI_DHCP6_PROTOCOL
*Dhcp6
;
2493 Dhcp6
= Instance
->Dhcp6
;
2494 ASSERT (Dhcp6
!= NULL
);
2496 Dhcp6
->Stop (Dhcp6
);
2497 Dhcp6
->Configure (Dhcp6
, NULL
);
2498 Instance
->Dhcp6
= NULL
;
2500 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2503 // Close DHCPv6 protocol and destroy the child.
2505 Status
= gBS
->CloseProtocol (
2506 Instance
->Dhcp6Handle
,
2507 &gEfiDhcp6ProtocolGuid
,
2511 if (EFI_ERROR (Status
)) {
2515 Status
= NetLibDestroyServiceChild (
2518 &gEfiDhcp6ServiceBindingProtocolGuid
,
2519 Instance
->Dhcp6Handle
2522 Instance
->Dhcp6Handle
= NULL
;