3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The driver binding for IP4 CONFIG protocol.
24 #include "Ip4Config.h"
28 Stop all the auto configuration when the IP4 configure driver is
31 @param ImageHandle The driver that is being unloaded
33 @retval EFI_SUCCESS The driver has been ready for unload.
39 IN EFI_HANDLE ImageHandle
45 // Stop all the IP4_CONFIG instances
47 for (Index
= 0; Index
< MAX_IP4_CONFIG_IN_VARIABLE
; Index
++) {
48 if (mIp4ConfigNicList
[Index
] == NULL
) {
52 gIp4ConfigDriverBinding
.Stop (
53 &gIp4ConfigDriverBinding
,
54 mIp4ConfigNicList
[Index
]->MnpHandle
,
60 return NetLibDefaultUnload (ImageHandle
);
65 Ip4ConfigDriverEntryPoint (
66 IN EFI_HANDLE ImageHandle
,
67 IN EFI_SYSTEM_TABLE
*SystemTable
73 The entry point for IP4 config driver which install the driver
74 binding and component name protocol on its image.
78 ImageHandle - The Image handle of the driver
79 SystemTable - The system table
83 EFI_SUCCESS - All the related protocols are installed on the driver
84 Others - Failed to install the protocol
88 return EfiLibInstallAllDriverProtocols (
91 &gIp4ConfigDriverBinding
,
93 &gIp4ConfigComponentName
,
101 Test to see if this driver supports ControllerHandle.
103 @param This Protocol instance pointer.
104 @param ControllerHandle Handle of device to test
105 @param RemainingDevicePath Optional parameter use to pick a specific child
108 @retval EFI_SUCCES This driver supports this device
109 @retval EFI_ALREADY_STARTED This driver is already running on this device
110 @retval other This driver does not support this device
115 Ip4ConfigDriverBindingSupported (
116 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
117 IN EFI_HANDLE ControllerHandle
,
118 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
123 Status
= gBS
->OpenProtocol (
125 &gEfiManagedNetworkServiceBindingProtocolGuid
,
127 This
->DriverBindingHandle
,
129 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
137 Start this driver on ControllerHandle.
139 @param This Protocol instance pointer.
140 @param ControllerHandle Handle of device to bind driver to
141 @param RemainingDevicePath Optional parameter use to pick a specific child
144 @retval EFI_SUCCES This driver is added to ControllerHandle
145 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
146 @retval other This driver does not support this device
151 Ip4ConfigDriverBindingStart (
152 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
153 IN EFI_HANDLE ControllerHandle
,
154 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
157 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
158 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
159 EFI_HANDLE MnpHandle
;
160 IP4_CONFIG_INSTANCE
*Instance
;
161 EFI_SIMPLE_NETWORK_MODE SnpMode
;
162 IP4_CONFIG_VARIABLE
*Variable
;
163 NIC_IP4_CONFIG_INFO
*NicConfig
;
164 IP4_CONFIG_VARIABLE
*NewVariable
;
169 // Check for multiple start.
171 Status
= gBS
->OpenProtocol (
173 &gEfiIp4ConfigProtocolGuid
,
174 (VOID
**) &Ip4Config
,
175 This
->DriverBindingHandle
,
177 EFI_OPEN_PROTOCOL_GET_PROTOCOL
180 if (!EFI_ERROR (Status
)) {
181 return EFI_ALREADY_STARTED
;
185 // Create a MNP child
191 Status
= NetLibCreateServiceChild (
193 This
->DriverBindingHandle
,
194 &gEfiManagedNetworkServiceBindingProtocolGuid
,
198 if (EFI_ERROR (Status
)) {
202 Status
= gBS
->OpenProtocol (
204 &gEfiManagedNetworkProtocolGuid
,
206 This
->DriverBindingHandle
,
208 EFI_OPEN_PROTOCOL_BY_DRIVER
211 if (EFI_ERROR (Status
)) {
216 // Allocate an instance then initialize it
218 Instance
= NetAllocatePool (sizeof (IP4_CONFIG_INSTANCE
));
220 if (Instance
== NULL
) {
221 Status
= EFI_OUT_OF_RESOURCES
;
225 Instance
->Signature
= IP4_CONFIG_INSTANCE_SIGNATURE
;
226 Instance
->Controller
= ControllerHandle
;
227 Instance
->Image
= This
->DriverBindingHandle
;
229 Instance
->Ip4ConfigProtocol
= mIp4ConfigProtocolTemplate
;
230 Instance
->NicIp4Protocol
= mNicIp4ConfigProtocolTemplate
;
232 Instance
->State
= IP4_CONFIG_STATE_IDLE
;
234 Instance
->MnpHandle
= MnpHandle
;
236 Instance
->DoneEvent
= NULL
;
237 Instance
->ReconfigEvent
= NULL
;
238 Instance
->Result
= EFI_NOT_READY
;
239 Instance
->NicConfig
= NULL
;
241 Instance
->Dhcp4
= NULL
;
242 Instance
->Dhcp4Handle
= NULL
;
243 Instance
->Dhcp4Event
= NULL
;
245 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
247 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
251 Instance
->NicAddr
.Type
= (UINT16
) SnpMode
.IfType
;
252 Instance
->NicAddr
.Len
= (UINT8
) SnpMode
.HwAddressSize
;
253 CopyMem (&Instance
->NicAddr
.MacAddr
, &SnpMode
.CurrentAddress
, sizeof (Instance
->NicAddr
.MacAddr
));
256 // Add it to the global list, and compose the name
258 for (Index
= 0; Index
< MAX_IP4_CONFIG_IN_VARIABLE
; Index
++) {
259 if (mIp4ConfigNicList
[Index
] == NULL
) {
260 mIp4ConfigNicList
[Index
] = Instance
;
261 Instance
->NicIndex
= Index
;
263 if (Instance
->NicAddr
.Type
== NET_IFTYPE_ETHERNET
) {
264 Instance
->NicName
[0] = 'e';
265 Instance
->NicName
[1] = 't';
266 Instance
->NicName
[2] = 'h';
267 Instance
->NicName
[3] = (UINT16
) ('0' + Index
);
268 Instance
->NicName
[4] = 0;
270 Instance
->NicName
[0] = 'u';
271 Instance
->NicName
[1] = 'n';
272 Instance
->NicName
[2] = 'k';
273 Instance
->NicName
[3] = (UINT16
) ('0' + Index
);
274 Instance
->NicName
[4] = 0;
281 if (Index
== MAX_IP4_CONFIG_IN_VARIABLE
) {
282 Status
= EFI_OUT_OF_RESOURCES
;
287 // Install the IP4_CONFIG and NIC_IP4CONFIG protocols
289 Status
= gBS
->InstallMultipleProtocolInterfaces (
291 &gEfiIp4ConfigProtocolGuid
,
292 &Instance
->Ip4ConfigProtocol
,
293 &gEfiNicIp4ConfigProtocolGuid
,
294 &Instance
->NicIp4Protocol
,
298 if (EFI_ERROR (Status
)) {
299 mIp4ConfigNicList
[Index
] = NULL
;
304 // Get the previous configure parameters. If an error happend here,
305 // just ignore it because the driver should be able to operate.
307 Variable
= Ip4ConfigReadVariable ();
309 if (Variable
== NULL
) {
313 NicConfig
= Ip4ConfigFindNicVariable (Variable
, &Instance
->NicAddr
);
315 if (NicConfig
== NULL
) {
320 // Don't modify the permant static configuration
322 if (NicConfig
->Perment
&& (NicConfig
->Source
== IP4_CONFIG_SOURCE_STATIC
)) {
327 // Delete the non-permant configuration and remove the previous
328 // acquired DHCP parameters. Only doing DHCP itself is permant
332 if (!NicConfig
->Perment
) {
333 NewVariable
= Ip4ConfigModifyVariable (Variable
, &Instance
->NicAddr
, NULL
);
335 } else if (NicConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
336 NetZeroMem (&NicConfig
->Ip4Info
, sizeof (EFI_IP4_IPCONFIG_DATA
));
337 NewVariable
= Ip4ConfigModifyVariable (Variable
, &Instance
->NicAddr
, NicConfig
);
341 Ip4ConfigWriteVariable (NewVariable
);
343 if (NewVariable
!= NULL
) {
344 NetFreePool (NewVariable
);
348 NetFreePool (Variable
);
350 if (NicConfig
!= NULL
) {
351 NetFreePool (NicConfig
);
357 if (Instance
!= NULL
) {
358 NetFreePool (Instance
);
364 &gEfiManagedNetworkProtocolGuid
,
365 This
->DriverBindingHandle
,
370 NetLibDestroyServiceChild (
372 This
->DriverBindingHandle
,
373 &gEfiManagedNetworkProtocolGuid
,
382 Stop this driver on ControllerHandle.
384 @param This Protocol instance pointer.
385 @param ControllerHandle Handle of device to stop driver on
386 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
387 children is zero stop the entire bus driver.
388 @param ChildHandleBuffer List of Child Handles to Stop.
390 @retval EFI_SUCCES This driver is removed ControllerHandle
391 @retval other This driver was not removed from this device
396 Ip4ConfigDriverBindingStop (
397 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
398 IN EFI_HANDLE ControllerHandle
,
399 IN UINTN NumberOfChildren
,
400 IN EFI_HANDLE
*ChildHandleBuffer
403 IP4_CONFIG_INSTANCE
*Instance
;
404 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
405 EFI_HANDLE NicHandle
;
409 // IP4_CONFIG instance opens an MNP child. It may also create and open
410 // a DHCP child. If this is the DHCP handle, stop the DHCP process. If
411 // it is the MNP child, stop the whole driver.
414 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
416 if (NicHandle
!= NULL
) {
418 // Get our context back then clean the DHCP up. Notify the user if necessary.
420 Status
= gBS
->OpenProtocol (
422 &gEfiIp4ConfigProtocolGuid
,
423 (VOID
**) &Ip4Config
,
424 This
->DriverBindingHandle
,
426 EFI_OPEN_PROTOCOL_GET_PROTOCOL
429 if (EFI_ERROR (Status
)) {
433 Instance
= IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config
);
434 ASSERT (ControllerHandle
== Instance
->Dhcp4Handle
);
436 Ip4ConfigCleanDhcp4 (Instance
);
438 Instance
->State
= IP4_CONFIG_STATE_CONFIGURED
;
439 Instance
->Result
= EFI_DEVICE_ERROR
;
441 if (Instance
->DoneEvent
!= NULL
) {
442 gBS
->SignalEvent (Instance
->DoneEvent
);
449 // This is a MNP handle, stop the whole driver
451 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
453 if (NicHandle
== NULL
) {
458 // Get our context back.
460 Status
= gBS
->OpenProtocol (
462 &gEfiIp4ConfigProtocolGuid
,
463 (VOID
**) &Ip4Config
,
464 This
->DriverBindingHandle
,
466 EFI_OPEN_PROTOCOL_GET_PROTOCOL
469 if (EFI_ERROR (Status
)) {
473 Instance
= IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config
);
476 // Unload the protocols first to inform the top drivers
478 Status
= gBS
->UninstallMultipleProtocolInterfaces (
480 &gEfiIp4ConfigProtocolGuid
,
481 &Instance
->Ip4ConfigProtocol
,
482 &gEfiNicIp4ConfigProtocolGuid
,
483 &Instance
->NicIp4Protocol
,
487 if (EFI_ERROR (Status
)) {
492 // Release all the resources
494 if (Instance
->MnpHandle
!= NULL
) {
497 &gEfiManagedNetworkProtocolGuid
,
498 This
->DriverBindingHandle
,
502 NetLibDestroyServiceChild (
505 &gEfiManagedNetworkServiceBindingProtocolGuid
,
509 Instance
->Mnp
= NULL
;
510 Instance
->MnpHandle
= NULL
;
513 Ip4ConfigCleanConfig (Instance
);
514 mIp4ConfigNicList
[Instance
->NicIndex
] = NULL
;
515 NetFreePool (Instance
);
520 EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding
= {
521 Ip4ConfigDriverBindingSupported
,
522 Ip4ConfigDriverBindingStart
,
523 Ip4ConfigDriverBindingStop
,