2 The implementation of EFI IPv4 Configuration II Protocol.
4 Copyright (c) 2015, 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 mIp4Config2InstanceList
= {&mIp4Config2InstanceList
, &mIp4Config2InstanceList
};
21 The event process routine when the DHCPv4 service binding protocol is installed
24 @param[in] Event Not used.
25 @param[in] Context Pointer to the IP4 config2 instance data.
30 Ip4Config2OnDhcp4SbInstalled (
36 Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.
38 @param[in, out] Instance The buffer of IP4 config2 instance to be freed.
40 @retval EFI_SUCCESS The child was successfully destroyed.
41 @retval Others Failed to destroy the child.
45 Ip4Config2DestroyDhcp4 (
46 IN OUT IP4_CONFIG2_INSTANCE
*Instance
51 EFI_DHCP4_PROTOCOL
*Dhcp4
;
53 Dhcp4
= Instance
->Dhcp4
;
54 ASSERT (Dhcp4
!= NULL
);
57 Dhcp4
->Configure (Dhcp4
, NULL
);
58 Instance
->Dhcp4
= NULL
;
60 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
63 // Close DHCPv4 protocol and destroy the child.
65 Status
= gBS
->CloseProtocol (
66 Instance
->Dhcp4Handle
,
67 &gEfiDhcp4ProtocolGuid
,
71 if (EFI_ERROR (Status
)) {
75 Status
= NetLibDestroyServiceChild (
78 &gEfiDhcp4ServiceBindingProtocolGuid
,
82 Instance
->Dhcp4Handle
= NULL
;
88 Start the DHCP configuration for this IP service instance.
89 It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
92 @param[in] Instance The IP4 config2 instance to configure.
94 @retval EFI_SUCCESS The auto configuration is successfull started.
95 @retval Others Failed to start auto configuration.
100 IN IP4_CONFIG2_INSTANCE
*Instance
104 Update the current policy to NewPolicy. During the transition
105 period, the default router list
106 and address list in all interfaces will be released.
108 @param[in] IpSb The IP4 service binding instance.
109 @param[in] NewPolicy The new policy to be updated to.
113 Ip4Config2OnPolicyChanged (
114 IN IP4_SERVICE
*IpSb
,
115 IN EFI_IP4_CONFIG2_POLICY NewPolicy
119 IP4_ROUTE_TABLE
*RouteTable
;
122 // Currently there are only two policies: static and dhcp. Regardless of
123 // what transition is going on, i.e., static -> dhcp and dhcp ->
124 // static, we have to free default router table and all addresses.
127 if (IpSb
->DefaultInterface
!= NULL
) {
128 if (IpSb
->DefaultRouteTable
!= NULL
) {
129 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
130 IpSb
->DefaultRouteTable
= NULL
;
133 Ip4CancelReceive (IpSb
->DefaultInterface
);
135 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
136 IpSb
->DefaultInterface
= NULL
;
139 Ip4CleanAssembleTable (&IpSb
->Assemble
);
142 // Create new default interface and route table.
144 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
149 RouteTable
= Ip4CreateRouteTable ();
150 if (RouteTable
== NULL
) {
151 Ip4FreeInterface (IpIf
, NULL
);
155 IpSb
->DefaultInterface
= IpIf
;
156 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
157 IpSb
->DefaultRouteTable
= RouteTable
;
158 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
160 if (IpSb
->State
== IP4_SERVICE_CONFIGED
) {
161 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
165 // Start the dhcp configuration.
167 if (NewPolicy
== Ip4Config2PolicyDhcp
) {
168 Ip4StartAutoConfig (&IpSb
->Ip4Config2Instance
);
174 Signal the registered event. It is the callback routine for NetMapIterate.
176 @param[in] Map Points to the list of registered event.
177 @param[in] Item The registered event.
178 @param[in] Arg Not used.
180 @retval EFI_SUCCESS The event was signaled successfully.
184 Ip4Config2SignalEvent (
186 IN NET_MAP_ITEM
*Item
,
190 gBS
->SignalEvent ((EFI_EVENT
) Item
->Key
);
196 Read the configuration data from variable storage according to the VarName and
197 gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the
198 data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
199 configuration data to IP4_CONFIG2_INSTANCE.
201 @param[in] VarName The pointer to the variable name
202 @param[in, out] Instance The pointer to the IP4 config2 instance data.
204 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
205 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
206 @retval EFI_SUCCESS The configuration data was retrieved successfully.
210 Ip4Config2ReadConfigData (
212 IN OUT IP4_CONFIG2_INSTANCE
*Instance
217 IP4_CONFIG2_VARIABLE
*Variable
;
218 IP4_CONFIG2_DATA_ITEM
*DataItem
;
220 IP4_CONFIG2_DATA_RECORD DataRecord
;
224 // Try to read the configuration variable.
227 Status
= gRT
->GetVariable (
229 &gEfiIp4Config2ProtocolGuid
,
235 if (Status
== EFI_BUFFER_TOO_SMALL
) {
237 // Allocate buffer and read the config variable.
239 Variable
= AllocatePool (VarSize
);
240 if (Variable
== NULL
) {
241 return EFI_OUT_OF_RESOURCES
;
244 Status
= gRT
->GetVariable (
246 &gEfiIp4Config2ProtocolGuid
,
251 if (EFI_ERROR (Status
) || (UINT16
) (~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
)) != 0) {
253 // GetVariable still error or the variable is corrupted.
254 // Fall back to the default value.
259 // Remove the problematic variable and return EFI_NOT_FOUND, a new
260 // variable will be set again.
264 &gEfiIp4Config2ProtocolGuid
,
265 IP4_CONFIG2_VARIABLE_ATTRIBUTE
,
270 return EFI_NOT_FOUND
;
274 for (Index
= 0; Index
< Variable
->DataRecordCount
; Index
++) {
276 CopyMem (&DataRecord
, &Variable
->DataRecord
[Index
], sizeof (DataRecord
));
278 DataItem
= &Instance
->DataItem
[DataRecord
.DataType
];
279 if (DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
) &&
280 (DataItem
->DataSize
!= DataRecord
.DataSize
)
283 // Perhaps a corrupted data record...
288 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
290 // This data item has variable length data.
292 DataItem
->Data
.Ptr
= AllocatePool (DataRecord
.DataSize
);
293 if (DataItem
->Data
.Ptr
== NULL
) {
295 // no memory resource
301 Data
= (CHAR8
*) Variable
+ DataRecord
.Offset
;
302 CopyMem (DataItem
->Data
.Ptr
, Data
, DataRecord
.DataSize
);
304 DataItem
->DataSize
= DataRecord
.DataSize
;
305 DataItem
->Status
= EFI_SUCCESS
;
316 Write the configuration data from IP4_CONFIG2_INSTANCE to variable storage.
318 @param[in] VarName The pointer to the variable name.
319 @param[in] Instance The pointer to the IP4 config2 instance data.
321 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
322 @retval EFI_SUCCESS The configuration data is written successfully.
326 Ip4Config2WriteConfigData (
328 IN IP4_CONFIG2_INSTANCE
*Instance
333 IP4_CONFIG2_DATA_ITEM
*DataItem
;
334 IP4_CONFIG2_VARIABLE
*Variable
;
335 IP4_CONFIG2_DATA_RECORD
*DataRecord
;
339 VarSize
= sizeof (IP4_CONFIG2_VARIABLE
) - sizeof (IP4_CONFIG2_DATA_RECORD
);
341 for (Index
= 0; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
343 DataItem
= &Instance
->DataItem
[Index
];
344 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
346 VarSize
+= sizeof (IP4_CONFIG2_DATA_RECORD
) + DataItem
->DataSize
;
350 Variable
= AllocatePool (VarSize
);
351 if (Variable
== NULL
) {
352 return EFI_OUT_OF_RESOURCES
;
355 Heap
= (CHAR8
*) Variable
+ VarSize
;
356 Variable
->DataRecordCount
= 0;
358 for (Index
= 0; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
360 DataItem
= &Instance
->DataItem
[Index
];
361 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
363 Heap
-= DataItem
->DataSize
;
364 CopyMem (Heap
, DataItem
->Data
.Ptr
, DataItem
->DataSize
);
366 DataRecord
= &Variable
->DataRecord
[Variable
->DataRecordCount
];
367 DataRecord
->DataType
= (EFI_IP4_CONFIG2_DATA_TYPE
) Index
;
368 DataRecord
->DataSize
= (UINT32
) DataItem
->DataSize
;
369 DataRecord
->Offset
= (UINT16
) (Heap
- (CHAR8
*) Variable
);
371 Variable
->DataRecordCount
++;
375 Variable
->Checksum
= 0;
376 Variable
->Checksum
= (UINT16
) ~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
);
378 Status
= gRT
->SetVariable (
380 &gEfiIp4Config2ProtocolGuid
,
381 IP4_CONFIG2_VARIABLE_ATTRIBUTE
,
393 Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of GetModeData.
394 The EFI_IP4_ROUTE_TABLE is clumsy to use in the internal operation of the
397 @param[in] IpSb The IP4 service binding instance.
398 @param[out] Table The built IP4 route table.
400 @retval EFI_SUCCESS The route table is successfully build
401 @retval EFI_NOT_FOUND Failed to allocate the memory for the rotue table.
405 Ip4Config2BuildDefaultRouteTable (
406 IN IP4_SERVICE
*IpSb
,
407 OUT EFI_IP4_ROUTE_TABLE
*Table
411 IP4_ROUTE_ENTRY
*RtEntry
;
415 if (IpSb
->DefaultRouteTable
== NULL
) {
416 return EFI_NOT_FOUND
;
419 Count
= IpSb
->DefaultRouteTable
->TotalNum
;
422 return EFI_NOT_FOUND
;
426 // Copy the route entry to EFI route table. Keep the order of
427 // route entry copied from most specific to default route. That
428 // is, interlevel the route entry from the instance's route area
429 // and those from the default route table's route area.
433 for (Index
= IP4_MASK_NUM
- 1; Index
>= 0; Index
--) {
435 NET_LIST_FOR_EACH (Entry
, &(IpSb
->DefaultRouteTable
->RouteArea
[Index
])) {
436 RtEntry
= NET_LIST_USER_STRUCT (Entry
, IP4_ROUTE_ENTRY
, Link
);
438 EFI_IP4 (Table
[Count
].SubnetAddress
) = HTONL (RtEntry
->Dest
& RtEntry
->Netmask
);
439 EFI_IP4 (Table
[Count
].SubnetMask
) = HTONL (RtEntry
->Netmask
);
440 EFI_IP4 (Table
[Count
].GatewayAddress
) = HTONL (RtEntry
->NextHop
);
451 The event process routine when the DHCPv4 service binding protocol is installed
454 @param[in] Event Not used.
455 @param[in] Context The pointer to the IP4 config2 instance data.
460 Ip4Config2OnDhcp4SbInstalled (
465 IP4_CONFIG2_INSTANCE
*Instance
;
467 Instance
= (IP4_CONFIG2_INSTANCE
*) Context
;
469 if ((Instance
->Dhcp4Handle
!= NULL
) || (Instance
->Policy
!= Ip4Config2PolicyDhcp
)) {
471 // The DHCP4 child is already created or the policy is no longer DHCP.
476 Ip4StartAutoConfig (Instance
);
480 Set the station address and subnetmask for the default interface.
482 @param[in] Instance The pointer to the IP4 config2 instance data.
483 @param[in] StationAddress Ip address to be set.
484 @param[in] SubnetMask Subnet to be set.
486 @retval EFI_SUCCESS Set default address successful.
487 @retval Others Some errors occur in setting.
491 Ip4Config2SetDefaultAddr (
492 IN IP4_CONFIG2_INSTANCE
*Instance
,
493 IN IP4_ADDR StationAddress
,
494 IN IP4_ADDR SubnetMask
500 IP4_PROTOCOL
*Ip4Instance
;
501 EFI_ARP_PROTOCOL
*Arp
;
504 IP4_ROUTE_TABLE
*RouteTable
;
506 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
507 IpIf
= IpSb
->DefaultInterface
;
508 ASSERT (IpIf
!= NULL
);
510 if ((IpIf
->Ip
== StationAddress
) && (IpIf
->SubnetMask
== SubnetMask
)) {
515 // The default address is changed, free the previous interface first.
517 if (IpSb
->DefaultRouteTable
!= NULL
) {
518 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
519 IpSb
->DefaultRouteTable
= NULL
;
522 Ip4CancelReceive (IpSb
->DefaultInterface
);
523 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
524 IpSb
->DefaultInterface
= NULL
;
526 // Create new default interface and route table.
528 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
530 return EFI_OUT_OF_RESOURCES
;
533 RouteTable
= Ip4CreateRouteTable ();
534 if (RouteTable
== NULL
) {
535 Ip4FreeInterface (IpIf
, NULL
);
536 return EFI_OUT_OF_RESOURCES
;
539 IpSb
->DefaultInterface
= IpIf
;
540 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
541 IpSb
->DefaultRouteTable
= RouteTable
;
542 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
544 if (IpSb
->State
== IP4_SERVICE_CONFIGED
) {
545 IpSb
->State
= IP4_SERVICE_UNSTARTED
;
548 Status
= Ip4SetAddress (IpIf
, StationAddress
, SubnetMask
);
549 if (EFI_ERROR (Status
)) {
553 if (IpIf
->Arp
!= NULL
) {
555 // A non-NULL IpIf->Arp here means a new ARP child is created when setting default address,
556 // but some IP children may have referenced the default interface before it is configured,
557 // these IP instances also consume this ARP protocol so they need to open it BY_CHILD_CONTROLLER.
560 NET_LIST_FOR_EACH (Entry
, &IpIf
->IpInstances
) {
561 Ip4Instance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, AddrLink
, IP4_PROTOCOL_SIGNATURE
);
562 Status
= gBS
->OpenProtocol (
564 &gEfiArpProtocolGuid
,
566 gIp4DriverBinding
.DriverBindingHandle
,
568 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
570 if (EFI_ERROR (Status
)) {
577 IpSb
->DefaultRouteTable
,
584 // Add a route for the connected network.
586 Subnet
= StationAddress
& SubnetMask
;
589 IpSb
->DefaultRouteTable
,
595 IpSb
->State
= IP4_SERVICE_CONFIGED
;
600 Set the station address, subnetmask and gateway address for the default interface.
602 @param[in] Instance The pointer to the IP4 config2 instance data.
603 @param[in] StationAddress Ip address to be set.
604 @param[in] SubnetMask Subnet to be set.
605 @param[in] GatewayAddress Gateway to be set.
607 @retval EFI_SUCCESS Set default If successful.
608 @retval Others Errors occur as indicated.
612 Ip4Config2SetDefaultIf (
613 IN IP4_CONFIG2_INSTANCE
*Instance
,
614 IN IP4_ADDR StationAddress
,
615 IN IP4_ADDR SubnetMask
,
616 IN IP4_ADDR GatewayAddress
622 Status
= Ip4Config2SetDefaultAddr (Instance
, StationAddress
, SubnetMask
);
623 if (EFI_ERROR (Status
)) {
628 // Create a route if there is a default router.
630 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
631 if (GatewayAddress
!= IP4_ALLZERO_ADDRESS
) {
633 IpSb
->DefaultRouteTable
,
645 Release all the DHCP related resources.
647 @param Instance The IP4 config2 instance.
653 Ip4Config2CleanDhcp4 (
654 IN IP4_CONFIG2_INSTANCE
*Instance
659 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
661 if (Instance
->Dhcp4
!= NULL
) {
662 Instance
->Dhcp4
->Stop (Instance
->Dhcp4
);
665 Instance
->Dhcp4Handle
,
666 &gEfiDhcp4ProtocolGuid
,
671 Instance
->Dhcp4
= NULL
;
674 if (Instance
->Dhcp4Handle
!= NULL
) {
675 NetLibDestroyServiceChild (
678 &gEfiDhcp4ServiceBindingProtocolGuid
,
679 Instance
->Dhcp4Handle
682 Instance
->Dhcp4Handle
= NULL
;
685 if (Instance
->Dhcp4Event
!= NULL
) {
686 gBS
->CloseEvent (Instance
->Dhcp4Event
);
687 Instance
->Dhcp4Event
= NULL
;
693 Callback function when DHCP process finished. It will save the
694 retrieved IP configure parameter from DHCP to the NVRam.
696 @param Event The callback event
697 @param Context Opaque context to the callback
704 Ip4Config2OnDhcp4Complete (
709 IP4_CONFIG2_INSTANCE
*Instance
;
710 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
712 IP4_ADDR StationAddress
;
714 IP4_ADDR GatewayAddress
;
716 Instance
= (IP4_CONFIG2_INSTANCE
*) Context
;
717 ASSERT (Instance
->Dhcp4
!= NULL
);
720 // Get the DHCP retrieved parameters
722 Status
= Instance
->Dhcp4
->GetModeData (Instance
->Dhcp4
, &Dhcp4Mode
);
724 if (EFI_ERROR (Status
)) {
728 if (Dhcp4Mode
.State
== Dhcp4Bound
) {
729 StationAddress
= EFI_NTOHL (Dhcp4Mode
.ClientAddress
);
730 SubnetMask
= EFI_NTOHL (Dhcp4Mode
.SubnetMask
);
731 GatewayAddress
= EFI_NTOHL (Dhcp4Mode
.RouterAddress
);
733 Status
= Ip4Config2SetDefaultIf (Instance
, StationAddress
, SubnetMask
, GatewayAddress
);
734 if (EFI_ERROR (Status
)) {
738 Instance
->DhcpSuccess
= TRUE
;
742 Ip4Config2CleanDhcp4 (Instance
);
748 Start the DHCP configuration for this IP service instance.
749 It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
752 @param[in] Instance The IP4 config2 instance to configure
754 @retval EFI_SUCCESS The auto configuration is successfull started
755 @retval Others Failed to start auto configuration.
760 IN IP4_CONFIG2_INSTANCE
*Instance
764 EFI_DHCP4_PROTOCOL
*Dhcp4
;
765 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
766 EFI_DHCP4_PACKET_OPTION
*OptionList
[1];
767 IP4_CONFIG2_DHCP4_OPTION ParaList
;
771 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
773 if (IpSb
->State
> IP4_SERVICE_UNSTARTED
) {
778 // A host must not invoke DHCP configuration if it is already
779 // participating in the DHCP configuraiton process.
781 if (Instance
->Dhcp4Handle
!= NULL
) {
785 Status
= NetLibCreateServiceChild (
788 &gEfiDhcp4ServiceBindingProtocolGuid
,
789 &Instance
->Dhcp4Handle
792 if (Status
== EFI_UNSUPPORTED
) {
794 // No DHCPv4 Service Binding protocol, register a notify.
796 if (Instance
->Dhcp4SbNotifyEvent
== NULL
) {
797 Instance
->Dhcp4SbNotifyEvent
= EfiCreateProtocolNotifyEvent (
798 &gEfiDhcp4ServiceBindingProtocolGuid
,
800 Ip4Config2OnDhcp4SbInstalled
,
802 &Instance
->Registration
807 if (EFI_ERROR (Status
)) {
811 if (Instance
->Dhcp4SbNotifyEvent
!= NULL
) {
812 gBS
->CloseEvent (Instance
->Dhcp4SbNotifyEvent
);
815 Status
= gBS
->OpenProtocol (
816 Instance
->Dhcp4Handle
,
817 &gEfiDhcp4ProtocolGuid
,
818 (VOID
**) &Instance
->Dhcp4
,
821 EFI_OPEN_PROTOCOL_BY_DRIVER
823 ASSERT_EFI_ERROR (Status
);
827 // Check the current DHCP status, if the DHCP process has
828 // already finished, return now.
830 Dhcp4
= Instance
->Dhcp4
;
831 Status
= Dhcp4
->GetModeData (Dhcp4
, &Dhcp4Mode
);
833 if (Dhcp4Mode
.State
== Dhcp4Bound
) {
834 Ip4Config2OnDhcp4Complete (NULL
, Instance
);
840 // Try to start the DHCP process. Use most of the current
841 // DHCP configuration to avoid problems if some DHCP client
842 // yields the control of this DHCP service to us.
844 ParaList
.Head
.OpCode
= DHCP_TAG_PARA_LIST
;
845 ParaList
.Head
.Length
= 2;
846 ParaList
.Head
.Data
[0] = DHCP_TAG_NETMASK
;
847 ParaList
.Route
= DHCP_TAG_ROUTER
;
848 OptionList
[0] = &ParaList
.Head
;
849 Dhcp4Mode
.ConfigData
.OptionCount
= 1;
850 Dhcp4Mode
.ConfigData
.OptionList
= OptionList
;
852 Status
= Dhcp4
->Configure (Dhcp4
, &Dhcp4Mode
.ConfigData
);
854 if (EFI_ERROR (Status
)) {
859 // Start the DHCP process
861 Status
= gBS
->CreateEvent (
864 Ip4Config2OnDhcp4Complete
,
866 &Instance
->Dhcp4Event
869 if (EFI_ERROR (Status
)) {
873 Status
= Dhcp4
->Start (Dhcp4
, Instance
->Dhcp4Event
);
875 if (EFI_ERROR (Status
)) {
879 IpSb
->State
= IP4_SERVICE_STARTED
;
888 The work function is to get the interface information of the communication
889 device this IP4_CONFIG2_INSTANCE manages.
891 @param[in] Instance Pointer to the IP4 config2 instance data.
892 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
893 bytes, the size of buffer required to store the specified
895 @param[in] Data The data buffer in which the configuration data is returned.
896 Ignored if DataSize is ZERO.
898 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
899 configuration data, and the required size is
900 returned in DataSize.
901 @retval EFI_SUCCESS The specified configuration data was obtained.
905 Ip4Config2GetIfInfo (
906 IN IP4_CONFIG2_INSTANCE
*Instance
,
907 IN OUT UINTN
*DataSize
,
908 IN VOID
*Data OPTIONAL
914 IP4_CONFIG2_DATA_ITEM
*Item
;
915 EFI_IP4_CONFIG2_INTERFACE_INFO
*IfInfo
;
918 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
919 Length
= sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO
);
921 if (IpSb
->DefaultRouteTable
!= NULL
) {
922 Length
+= IpSb
->DefaultRouteTable
->TotalNum
* sizeof (EFI_IP4_ROUTE_TABLE
);
925 if (*DataSize
< Length
) {
927 return EFI_BUFFER_TOO_SMALL
;
931 // Copy the fixed size part of the interface info.
933 Item
= &Instance
->DataItem
[Ip4Config2DataTypeInterfaceInfo
];
934 IfInfo
= (EFI_IP4_CONFIG2_INTERFACE_INFO
*) Data
;
935 CopyMem (IfInfo
, Item
->Data
.Ptr
, sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO
));
938 // Update the address info.
940 if (IpSb
->DefaultInterface
!= NULL
) {
941 Address
= HTONL (IpSb
->DefaultInterface
->Ip
);
942 CopyMem (&IfInfo
->StationAddress
, &Address
, sizeof (EFI_IPv4_ADDRESS
));
943 Address
= HTONL (IpSb
->DefaultInterface
->SubnetMask
);
944 CopyMem (&IfInfo
->SubnetMask
, &Address
, sizeof (EFI_IPv4_ADDRESS
));
947 if (IpSb
->DefaultRouteTable
!= NULL
) {
948 IfInfo
->RouteTableSize
= IpSb
->DefaultRouteTable
->TotalNum
;
949 IfInfo
->RouteTable
= (EFI_IP4_ROUTE_TABLE
*) ((UINT8
*) Data
+ sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO
));
951 Ip4Config2BuildDefaultRouteTable (IpSb
, IfInfo
->RouteTable
);
958 The work function is to set the general configuration policy for the EFI IPv4 network
959 stack that is running on the communication device managed by this IP4_CONFIG2_INSTANCE.
960 The policy will affect other configuration settings.
962 @param[in] Instance Pointer to the IP4 config2 instance data.
963 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
964 @param[in] Data The data buffer to set.
966 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
967 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
968 @retval EFI_ABORTED The new policy equals the current policy.
969 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
970 network stack was set.
974 Ip4Config2SetPolicy (
975 IN IP4_CONFIG2_INSTANCE
*Instance
,
980 EFI_IP4_CONFIG2_POLICY NewPolicy
;
981 IP4_CONFIG2_DATA_ITEM
*DataItem
;
984 if (DataSize
!= sizeof (EFI_IP4_CONFIG2_POLICY
)) {
985 return EFI_BAD_BUFFER_SIZE
;
988 NewPolicy
= *((EFI_IP4_CONFIG2_POLICY
*) Data
);
990 if (NewPolicy
>= Ip4Config2PolicyMax
) {
991 return EFI_INVALID_PARAMETER
;
994 if (NewPolicy
== Instance
->Policy
) {
995 if (NewPolicy
!= Ip4Config2PolicyDhcp
|| Instance
->DhcpSuccess
) {
1000 if (NewPolicy
== Ip4Config2PolicyDhcp
) {
1002 // The policy is changed from static to dhcp:
1003 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
1004 // data size, and fire up all the related events.
1006 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeManualAddress
];
1007 if (DataItem
->Data
.Ptr
!= NULL
) {
1008 FreePool (DataItem
->Data
.Ptr
);
1010 DataItem
->Data
.Ptr
= NULL
;
1011 DataItem
->DataSize
= 0;
1012 DataItem
->Status
= EFI_NOT_FOUND
;
1013 NetMapIterate (&DataItem
->EventMap
, Ip4Config2SignalEvent
, NULL
);
1015 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeGateway
];
1016 if (DataItem
->Data
.Ptr
!= NULL
) {
1017 FreePool (DataItem
->Data
.Ptr
);
1019 DataItem
->Data
.Ptr
= NULL
;
1020 DataItem
->DataSize
= 0;
1021 DataItem
->Status
= EFI_NOT_FOUND
;
1022 NetMapIterate (&DataItem
->EventMap
, Ip4Config2SignalEvent
, NULL
);
1024 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeDnsServer
];
1025 if (DataItem
->Data
.Ptr
!= NULL
) {
1026 FreePool (DataItem
->Data
.Ptr
);
1028 DataItem
->Data
.Ptr
= NULL
;
1029 DataItem
->DataSize
= 0;
1030 DataItem
->Status
= EFI_NOT_FOUND
;
1031 NetMapIterate (&DataItem
->EventMap
, Ip4Config2SignalEvent
, NULL
);
1034 // The policy is changed from dhcp to static. Stop the DHCPv4 process
1035 // and destroy the DHCPv4 child.
1037 if (Instance
->Dhcp4Handle
!= NULL
) {
1038 Ip4Config2DestroyDhcp4 (Instance
);
1044 if (Instance
->Dhcp4Event
!= NULL
) {
1045 gBS
->CloseEvent (Instance
->Dhcp4Event
);
1050 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
1051 Ip4Config2OnPolicyChanged (IpSb
, NewPolicy
);
1053 Instance
->Policy
= NewPolicy
;
1059 The work function is to set the station addresses manually for the EFI IPv4
1060 network stack. It is only configurable when the policy is Ip4Config2PolicyStatic.
1062 @param[in] Instance Pointer to the IP4 config2 instance data.
1063 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1064 @param[in] Data The data buffer to set.
1066 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1067 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1068 under the current policy.
1069 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1070 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
1071 @retval EFI_NOT_READY An asynchrous process is invoked to set the specified
1072 configuration data, and the process is not finished.
1073 @retval EFI_ABORTED The manual addresses to be set equal current
1075 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1076 network stack was set.
1080 Ip4Config2SetMaunualAddress (
1081 IN IP4_CONFIG2_INSTANCE
*Instance
,
1086 EFI_IP4_CONFIG2_MANUAL_ADDRESS NewAddress
;
1087 IP4_CONFIG2_DATA_ITEM
*DataItem
;
1089 IP4_ADDR StationAddress
;
1090 IP4_ADDR SubnetMask
;
1093 ASSERT (Instance
->DataItem
[Ip4Config2DataTypeManualAddress
].Status
!= EFI_NOT_READY
);
1095 if (((DataSize
% sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS
)) != 0) || (DataSize
== 0)) {
1096 return EFI_BAD_BUFFER_SIZE
;
1099 if (Instance
->Policy
!= Ip4Config2PolicyStatic
) {
1100 return EFI_WRITE_PROTECTED
;
1103 NewAddress
= *((EFI_IP4_CONFIG2_MANUAL_ADDRESS
*) Data
);
1106 // Store the new data, and init the DataItem status to EFI_NOT_READY because
1107 // we may have an asynchronous configuration process.
1109 Ptr
= AllocateCopyPool (DataSize
, Data
);
1111 return EFI_OUT_OF_RESOURCES
;
1114 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeManualAddress
];
1115 if (DataItem
->Data
.Ptr
!= NULL
) {
1116 FreePool (DataItem
->Data
.Ptr
);
1119 DataItem
->Data
.Ptr
= Ptr
;
1120 DataItem
->DataSize
= DataSize
;
1121 DataItem
->Status
= EFI_NOT_READY
;
1123 StationAddress
= EFI_NTOHL (NewAddress
.Address
);
1124 SubnetMask
= EFI_NTOHL (NewAddress
.SubnetMask
);
1126 Status
= Ip4Config2SetDefaultAddr (Instance
, StationAddress
, SubnetMask
);
1127 if (EFI_ERROR (Status
)) {
1131 DataItem
->Status
= EFI_SUCCESS
;
1134 if (EFI_ERROR (DataItem
->Status
)) {
1138 DataItem
->Data
.Ptr
= NULL
;
1145 The work function is to set the gateway addresses manually for the EFI IPv4
1146 network stack that is running on the communication device that this EFI IPv4
1147 Configuration Protocol manages. It is not configurable when the policy is
1148 Ip4Config2PolicyDhcp. The gateway addresses must be unicast IPv4 addresses.
1150 @param[in] Instance The pointer to the IP4 config2 instance data.
1151 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1152 @param[in] Data The data buffer to set. This points to an array of
1153 EFI_IPv6_ADDRESS instances.
1155 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1156 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1157 under the current policy.
1158 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1159 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1160 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1161 current configuration.
1162 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1163 network stack was set.
1167 Ip4Config2SetGateway (
1168 IN IP4_CONFIG2_INSTANCE
*Instance
,
1174 IP4_CONFIG2_DATA_ITEM
*DataItem
;
1179 EFI_IPv4_ADDRESS
*OldGateway
;
1180 EFI_IPv4_ADDRESS
*NewGateway
;
1181 UINTN OldGatewayCount
;
1182 UINTN NewGatewayCount
;
1187 if ((DataSize
% sizeof (EFI_IPv4_ADDRESS
) != 0) || (DataSize
== 0)) {
1188 return EFI_BAD_BUFFER_SIZE
;
1191 if (Instance
->Policy
!= Ip4Config2PolicyStatic
) {
1192 return EFI_WRITE_PROTECTED
;
1196 NewGateway
= (EFI_IPv4_ADDRESS
*) Data
;
1197 NewGatewayCount
= DataSize
/ sizeof (EFI_IPv4_ADDRESS
);
1198 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1199 CopyMem (&Gateway
, NewGateway
+ Index1
, sizeof (IP4_ADDR
));
1201 if (!NetIp4IsUnicast (NTOHL (Gateway
), 0)) {
1203 return EFI_INVALID_PARAMETER
;
1206 for (Index2
= Index1
+ 1; Index2
< NewGatewayCount
; Index2
++) {
1207 if (EFI_IP4_EQUAL (NewGateway
+ Index1
, NewGateway
+ Index2
)) {
1208 return EFI_INVALID_PARAMETER
;
1213 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
1214 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeGateway
];
1215 OldGateway
= DataItem
->Data
.Gateway
;
1216 OldGatewayCount
= DataItem
->DataSize
/ sizeof (EFI_IPv4_ADDRESS
);
1220 if (NewGatewayCount
!= OldGatewayCount
) {
1221 Tmp
= AllocatePool (DataSize
);
1223 return EFI_OUT_OF_RESOURCES
;
1229 for (Index1
= 0; Index1
< OldGatewayCount
; Index1
++) {
1231 // Remove this route entry.
1233 CopyMem (&Gateway
, OldGateway
+ Index1
, sizeof (IP4_ADDR
));
1235 IpSb
->DefaultRouteTable
,
1236 IP4_ALLZERO_ADDRESS
,
1237 IP4_ALLZERO_ADDRESS
,
1244 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1245 CopyMem (&Gateway
, NewGateway
+ Index1
, sizeof (IP4_ADDR
));
1247 IpSb
->DefaultRouteTable
,
1248 IP4_ALLZERO_ADDRESS
,
1249 IP4_ALLZERO_ADDRESS
,
1257 if (!OneRemoved
&& !OneAdded
) {
1258 DataItem
->Status
= EFI_SUCCESS
;
1263 if (DataItem
->Data
.Ptr
!= NULL
) {
1264 FreePool (DataItem
->Data
.Ptr
);
1266 DataItem
->Data
.Ptr
= Tmp
;
1269 CopyMem (DataItem
->Data
.Ptr
, Data
, DataSize
);
1270 DataItem
->DataSize
= DataSize
;
1271 DataItem
->Status
= EFI_SUCCESS
;
1278 The work function is to set the DNS server list for the EFI IPv4 network
1279 stack running on the communication device that this EFI_IP4_CONFIG2_PROTOCOL
1280 manages. It is not configurable when the policy is Ip4Config2PolicyDhcp.
1281 The DNS server addresses must be unicast IPv4 addresses.
1283 @param[in] Instance The pointer to the IP4 config2 instance data.
1284 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1285 @param[in] Data The data buffer to set, points to an array of
1286 EFI_IPv4_ADDRESS instances.
1288 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1289 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1290 under the current policy.
1291 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1292 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1293 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1295 @retval EFI_SUCCESS The specified configuration data for the EFI IPv4
1296 network stack was set.
1300 Ip4Config2SetDnsServer (
1301 IN IP4_CONFIG2_INSTANCE
*Instance
,
1309 EFI_IPv4_ADDRESS
*OldDns
;
1310 EFI_IPv4_ADDRESS
*NewDns
;
1313 IP4_CONFIG2_DATA_ITEM
*Item
;
1316 IP4_ADDR DnsAddress
;
1318 if ((DataSize
% sizeof (EFI_IPv4_ADDRESS
) != 0) || (DataSize
== 0)) {
1319 return EFI_BAD_BUFFER_SIZE
;
1322 if (Instance
->Policy
!= Ip4Config2PolicyStatic
) {
1323 return EFI_WRITE_PROTECTED
;
1326 Item
= &Instance
->DataItem
[Ip4Config2DataTypeDnsServer
];
1327 NewDns
= (EFI_IPv4_ADDRESS
*) Data
;
1328 OldDns
= Item
->Data
.DnsServers
;
1329 NewDnsCount
= DataSize
/ sizeof (EFI_IPv4_ADDRESS
);
1330 OldDnsCount
= Item
->DataSize
/ sizeof (EFI_IPv4_ADDRESS
);
1333 if (NewDnsCount
!= OldDnsCount
) {
1334 Tmp
= AllocatePool (DataSize
);
1336 return EFI_OUT_OF_RESOURCES
;
1342 for (NewIndex
= 0; NewIndex
< NewDnsCount
; NewIndex
++) {
1343 CopyMem (&DnsAddress
, NewDns
+ NewIndex
, sizeof (IP4_ADDR
));
1345 if (!NetIp4IsUnicast (NTOHL (DnsAddress
), 0)) {
1347 // The dns server address must be unicast.
1350 return EFI_INVALID_PARAMETER
;
1353 for (Index1
= NewIndex
+ 1; Index1
< NewDnsCount
; Index1
++) {
1354 if (EFI_IP4_EQUAL (NewDns
+ NewIndex
, NewDns
+ Index1
)) {
1356 return EFI_INVALID_PARAMETER
;
1362 // If any address in the new setting is not in the old settings, skip the
1363 // comparision below.
1368 for (OldIndex
= 0; OldIndex
< OldDnsCount
; OldIndex
++) {
1369 if (EFI_IP4_EQUAL (NewDns
+ NewIndex
, OldDns
+ OldIndex
)) {
1371 // If found break out.
1377 if (OldIndex
== OldDnsCount
) {
1382 if (!OneAdded
&& (DataSize
== Item
->DataSize
)) {
1384 // No new item is added and the size is the same.
1386 Item
->Status
= EFI_SUCCESS
;
1390 if (Item
->Data
.Ptr
!= NULL
) {
1391 FreePool (Item
->Data
.Ptr
);
1393 Item
->Data
.Ptr
= Tmp
;
1396 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1397 Item
->DataSize
= DataSize
;
1398 Item
->Status
= EFI_SUCCESS
;
1405 Generate the operational state of the interface this IP4 config2 instance manages
1406 and output in EFI_IP4_CONFIG2_INTERFACE_INFO.
1408 @param[in] IpSb The pointer to the IP4 service binding instance.
1409 @param[out] IfInfo The pointer to the IP4 config2 interface information structure.
1413 Ip4Config2InitIfInfo (
1414 IN IP4_SERVICE
*IpSb
,
1415 OUT EFI_IP4_CONFIG2_INTERFACE_INFO
*IfInfo
1418 IfInfo
->Name
[0] = L
'e';
1419 IfInfo
->Name
[1] = L
't';
1420 IfInfo
->Name
[2] = L
'h';
1421 IfInfo
->Name
[3] = (CHAR16
) (L
'0' + IpSb
->Ip4Config2Instance
.IfIndex
);
1422 IfInfo
->Name
[4] = 0;
1424 IfInfo
->IfType
= IpSb
->SnpMode
.IfType
;
1425 IfInfo
->HwAddressSize
= IpSb
->SnpMode
.HwAddressSize
;
1426 CopyMem (&IfInfo
->HwAddress
, &IpSb
->SnpMode
.CurrentAddress
, IfInfo
->HwAddressSize
);
1430 The event handle routine when DHCPv4 process is finished or is updated.
1432 @param[in] Event Not used.
1433 @param[in] Context The pointer to the IP4 configuration instance data.
1438 Ip4Config2OnDhcp4Event (
1448 Set the configuration for the EFI IPv4 network stack running on the communication
1449 device this EFI_IP4_CONFIG2_PROTOCOL instance manages.
1451 This function is used to set the configuration data of type DataType for the EFI
1452 IPv4 network stack that is running on the communication device that this EFI IPv4
1453 Configuration Protocol instance manages.
1455 DataSize is used to calculate the count of structure instances in the Data for
1456 a DataType in which multiple structure instances are allowed.
1458 This function is always non-blocking. When setting some type of configuration data,
1459 an asynchronous process is invoked to check the correctness of the data, such as
1460 performing Duplicate Address Detection on the manually set local IPv4 addresses.
1461 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1462 is invoked, and the process is not finished yet. The caller wanting to get the result
1463 of the asynchronous process is required to call RegisterDataNotify() to register an
1464 event on the specified configuration data. Once the event is signaled, the caller
1465 can call GetData() to obtain the configuration data and know the result.
1466 For other types of configuration data that do not require an asynchronous configuration
1467 process, the result of the operation is immediately returned.
1469 @param[in] This The pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1470 @param[in] DataType The type of data to set.
1471 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1472 @param[in] Data The data buffer to set. The type of the data buffer is
1473 associated with the DataType.
1475 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1476 network stack was set successfully.
1477 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1480 - One or more fields in Data do not match the requirement of the
1481 data type indicated by DataType.
1482 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1483 configuration data cannot be set under the current policy.
1484 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1485 data is already in process.
1486 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1487 configuration data, and the process is not finished yet.
1488 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1489 indicated by DataType.
1490 @retval EFI_UNSUPPORTED This DataType is not supported.
1491 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1492 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1497 EfiIp4Config2SetData (
1498 IN EFI_IP4_CONFIG2_PROTOCOL
*This
,
1499 IN EFI_IP4_CONFIG2_DATA_TYPE DataType
,
1506 IP4_CONFIG2_INSTANCE
*Instance
;
1509 if ((This
== NULL
) || (Data
== NULL
)) {
1510 return EFI_INVALID_PARAMETER
;
1513 if (DataType
>= Ip4Config2DataTypeMaximum
) {
1514 return EFI_UNSUPPORTED
;
1517 Instance
= IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This
);
1518 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
1519 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
1522 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1524 Status
= Instance
->DataItem
[DataType
].Status
;
1525 if (Status
!= EFI_NOT_READY
) {
1527 if (Instance
->DataItem
[DataType
].SetData
== NULL
) {
1529 // This type of data is readonly.
1531 Status
= EFI_WRITE_PROTECTED
;
1534 Status
= Instance
->DataItem
[DataType
].SetData (Instance
, DataSize
, Data
);
1535 if (!EFI_ERROR (Status
)) {
1537 // Fire up the events registered with this type of data.
1539 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip4Config2SignalEvent
, NULL
);
1540 Ip4Config2WriteConfigData (IpSb
->MacString
, Instance
);
1541 } else if (Status
== EFI_ABORTED
) {
1543 // The SetData is aborted because the data to set is the same with
1544 // the one maintained.
1546 Status
= EFI_SUCCESS
;
1547 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip4Config2SignalEvent
, NULL
);
1552 // Another asynchornous process is on the way.
1554 Status
= EFI_ACCESS_DENIED
;
1557 gBS
->RestoreTPL (OldTpl
);
1563 Get the configuration data for the EFI IPv4 network stack running on the communication
1564 device that this EFI_IP4_CONFIG2_PROTOCOL instance manages.
1566 This function returns the configuration data of type DataType for the EFI IPv4 network
1567 stack running on the communication device that this EFI IPv4 Configuration Protocol instance
1570 The caller is responsible for allocating the buffer used to return the specified
1571 configuration data. The required size will be returned to the caller if the size of
1572 the buffer is too small.
1574 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
1575 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
1576 to register an event on the specified configuration data. Once the asynchronous configuration
1577 process is finished, the event will be signaled, and a subsequent GetData() call will return
1578 the specified configuration data.
1580 @param[in] This Pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1581 @param[in] DataType The type of data to get.
1582 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
1583 size of buffer required to store the specified configuration data.
1584 @param[in] Data The data buffer in which the configuration data is returned. The
1585 type of the data buffer is associated with the DataType.
1586 This is an optional parameter that may be NULL.
1588 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1589 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
1592 - Data is NULL if *DataSize is not zero.
1593 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
1594 and the required size is returned in DataSize.
1595 @retval EFI_NOT_READY The specified configuration data is not ready due to an
1596 asynchronous configuration process already in progress.
1597 @retval EFI_NOT_FOUND The specified configuration data is not found.
1602 EfiIp4Config2GetData (
1603 IN EFI_IP4_CONFIG2_PROTOCOL
*This
,
1604 IN EFI_IP4_CONFIG2_DATA_TYPE DataType
,
1605 IN OUT UINTN
*DataSize
,
1606 IN VOID
*Data OPTIONAL
1611 IP4_CONFIG2_INSTANCE
*Instance
;
1612 IP4_CONFIG2_DATA_ITEM
*DataItem
;
1614 if ((This
== NULL
) || (DataSize
== NULL
) || ((*DataSize
!= 0) && (Data
== NULL
))) {
1615 return EFI_INVALID_PARAMETER
;
1618 if (DataType
>= Ip4Config2DataTypeMaximum
) {
1619 return EFI_NOT_FOUND
;
1622 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1624 Instance
= IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This
);
1625 DataItem
= &Instance
->DataItem
[DataType
];
1627 Status
= Instance
->DataItem
[DataType
].Status
;
1628 if (!EFI_ERROR (Status
)) {
1630 if (DataItem
->GetData
!= NULL
) {
1632 Status
= DataItem
->GetData (Instance
, DataSize
, Data
);
1633 } else if (*DataSize
< Instance
->DataItem
[DataType
].DataSize
) {
1635 // Update the buffer length.
1637 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
1638 Status
= EFI_BUFFER_TOO_SMALL
;
1641 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
1642 CopyMem (Data
, Instance
->DataItem
[DataType
].Data
.Ptr
, *DataSize
);
1646 gBS
->RestoreTPL (OldTpl
);
1652 Register an event that is signaled whenever a configuration process on the specified
1653 configuration data is done.
1655 This function registers an event that is to be signaled whenever a configuration
1656 process on the specified configuration data is performed. An event can be registered
1657 for a different DataType simultaneously. The caller is responsible for determining
1658 which type of configuration data causes the signaling of the event in such an event.
1660 @param[in] This Pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1661 @param[in] DataType The type of data to unregister the event for.
1662 @param[in] Event The event to register.
1664 @retval EFI_SUCCESS The notification event for the specified configuration data is
1666 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
1667 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
1669 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1670 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
1675 EfiIp4Config2RegisterDataNotify (
1676 IN EFI_IP4_CONFIG2_PROTOCOL
*This
,
1677 IN EFI_IP4_CONFIG2_DATA_TYPE DataType
,
1683 IP4_CONFIG2_INSTANCE
*Instance
;
1687 if ((This
== NULL
) || (Event
== NULL
)) {
1688 return EFI_INVALID_PARAMETER
;
1691 if (DataType
>= Ip4Config2DataTypeMaximum
) {
1692 return EFI_UNSUPPORTED
;
1695 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1697 Instance
= IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This
);
1698 EventMap
= &Instance
->DataItem
[DataType
].EventMap
;
1701 // Check whether this event is already registered for this DataType.
1703 Item
= NetMapFindKey (EventMap
, Event
);
1706 Status
= NetMapInsertTail (EventMap
, Event
, NULL
);
1708 if (EFI_ERROR (Status
)) {
1710 Status
= EFI_OUT_OF_RESOURCES
;
1715 Status
= EFI_ACCESS_DENIED
;
1718 gBS
->RestoreTPL (OldTpl
);
1724 Remove a previously registered event for the specified configuration data.
1726 @param This The pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1727 @param DataType The type of data to remove from the previously
1729 @param Event The event to be unregistered.
1731 @retval EFI_SUCCESS The event registered for the specified
1732 configuration data was removed.
1733 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
1734 @retval EFI_NOT_FOUND The Event has not been registered for the
1740 EfiIp4Config2UnregisterDataNotify (
1741 IN EFI_IP4_CONFIG2_PROTOCOL
*This
,
1742 IN EFI_IP4_CONFIG2_DATA_TYPE DataType
,
1748 IP4_CONFIG2_INSTANCE
*Instance
;
1751 if ((This
== NULL
) || (Event
== NULL
)) {
1752 return EFI_INVALID_PARAMETER
;
1755 if (DataType
>= Ip4Config2DataTypeMaximum
) {
1756 return EFI_NOT_FOUND
;
1759 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1761 Instance
= IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This
);
1763 Item
= NetMapFindKey (&Instance
->DataItem
[DataType
].EventMap
, Event
);
1766 NetMapRemoveItem (&Instance
->DataItem
[DataType
].EventMap
, Item
, NULL
);
1767 Status
= EFI_SUCCESS
;
1770 Status
= EFI_NOT_FOUND
;
1773 gBS
->RestoreTPL (OldTpl
);
1779 Initialize an IP4_CONFIG2_INSTANCE.
1781 @param[out] Instance The buffer of IP4_CONFIG2_INSTANCE to be initialized.
1783 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1784 @retval EFI_SUCCESS The IP4_CONFIG2_INSTANCE initialized successfully.
1788 Ip4Config2InitInstance (
1789 OUT IP4_CONFIG2_INSTANCE
*Instance
1793 IP4_CONFIG2_INSTANCE
*TmpInstance
;
1798 IP4_CONFIG2_DATA_ITEM
*DataItem
;
1801 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
1803 Instance
->Signature
= IP4_CONFIG2_INSTANCE_SIGNATURE
;
1807 // Determine the index of this interface.
1810 NET_LIST_FOR_EACH (Entry
, &mIp4Config2InstanceList
) {
1811 TmpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_CONFIG2_INSTANCE
, Link
, IP4_CONFIG2_INSTANCE_SIGNATURE
);
1813 if (TmpInstance
->IfIndex
> IfIndex
) {
1815 // There is a sequence hole because some interface is down.
1823 Instance
->IfIndex
= IfIndex
;
1824 NetListInsertBefore (Entry
, &Instance
->Link
);
1826 for (Index
= 0; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
1828 // Initialize the event map for each data item.
1830 NetMapInit (&Instance
->DataItem
[Index
].EventMap
);
1835 // Initialize each data type: associate storage and set data size for the
1836 // fixed size data types, hook the SetData function, set the data attribute.
1838 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeInterfaceInfo
];
1839 DataItem
->GetData
= Ip4Config2GetIfInfo
;
1840 DataItem
->Data
.Ptr
= &Instance
->InterfaceInfo
;
1841 DataItem
->DataSize
= sizeof (Instance
->InterfaceInfo
);
1842 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
| DATA_ATTRIB_VOLATILE
);
1843 Ip4Config2InitIfInfo (IpSb
, &Instance
->InterfaceInfo
);
1845 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypePolicy
];
1846 DataItem
->SetData
= Ip4Config2SetPolicy
;
1847 DataItem
->Data
.Ptr
= &Instance
->Policy
;
1848 DataItem
->DataSize
= sizeof (Instance
->Policy
);
1849 Instance
->Policy
= Ip4Config2PolicyDhcp
;
1850 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
1852 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeManualAddress
];
1853 DataItem
->SetData
= Ip4Config2SetMaunualAddress
;
1854 DataItem
->Status
= EFI_NOT_FOUND
;
1856 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeGateway
];
1857 DataItem
->SetData
= Ip4Config2SetGateway
;
1858 DataItem
->Status
= EFI_NOT_FOUND
;
1860 DataItem
= &Instance
->DataItem
[Ip4Config2DataTypeDnsServer
];
1861 DataItem
->SetData
= Ip4Config2SetDnsServer
;
1862 DataItem
->Status
= EFI_NOT_FOUND
;
1865 // Create the event used for DHCP.
1867 Status
= gBS
->CreateEvent (
1870 Ip4Config2OnDhcp4Event
,
1872 &Instance
->Dhcp4Event
1874 ASSERT_EFI_ERROR (Status
);
1876 Instance
->Configured
= TRUE
;
1879 // Try to read the config data from NV variable.
1881 Status
= Ip4Config2ReadConfigData (IpSb
->MacString
, Instance
);
1882 if (Status
== EFI_NOT_FOUND
) {
1883 Status
= Ip4Config2WriteConfigData (IpSb
->MacString
, Instance
);
1886 if (EFI_ERROR (Status
)) {
1891 // Try to set the configured parameter.
1893 for (Index
= Ip4Config2DataTypePolicy
; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
1894 DataItem
= &IpSb
->Ip4Config2Instance
.DataItem
[Index
];
1895 if (DataItem
->Data
.Ptr
!= NULL
) {
1897 &IpSb
->Ip4Config2Instance
,
1904 Instance
->Ip4Config2
.SetData
= EfiIp4Config2SetData
;
1905 Instance
->Ip4Config2
.GetData
= EfiIp4Config2GetData
;
1906 Instance
->Ip4Config2
.RegisterDataNotify
= EfiIp4Config2RegisterDataNotify
;
1907 Instance
->Ip4Config2
.UnregisterDataNotify
= EfiIp4Config2UnregisterDataNotify
;
1910 // Publish the IP4 configuration form
1912 return Ip4Config2FormInit (Instance
);
1917 Release an IP4_CONFIG2_INSTANCE.
1919 @param[in, out] Instance The buffer of IP4_CONFIG2_INSTANCE to be freed.
1923 Ip4Config2CleanInstance (
1924 IN OUT IP4_CONFIG2_INSTANCE
*Instance
1928 IP4_CONFIG2_DATA_ITEM
*DataItem
;
1930 if (Instance
->DeclineAddress
!= NULL
) {
1931 FreePool (Instance
->DeclineAddress
);
1934 if (!Instance
->Configured
) {
1938 if (Instance
->Dhcp4Handle
!= NULL
) {
1940 Ip4Config2DestroyDhcp4 (Instance
);
1946 if (Instance
->Dhcp4Event
!= NULL
) {
1947 gBS
->CloseEvent (Instance
->Dhcp4Event
);
1950 for (Index
= 0; Index
< Ip4Config2DataTypeMaximum
; Index
++) {
1952 DataItem
= &Instance
->DataItem
[Index
];
1954 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
1955 if (DataItem
->Data
.Ptr
!= NULL
) {
1956 FreePool (DataItem
->Data
.Ptr
);
1958 DataItem
->Data
.Ptr
= NULL
;
1959 DataItem
->DataSize
= 0;
1962 NetMapClean (&Instance
->DataItem
[Index
].EventMap
);
1965 Ip4Config2FormUnload (Instance
);
1967 RemoveEntryList (&Instance
->Link
);