2 The driver binding for IP4 CONFIG protocol.
4 Copyright (c) 2006 - 2008, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at<BR>
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "Ip4Config.h"
20 Stop all the auto configuration when the IP4 configure driver is
23 @param ImageHandle The driver that is being unloaded
25 @retval EFI_SUCCESS The driver has been ready for unload.
31 IN EFI_HANDLE ImageHandle
37 // Stop all the IP4_CONFIG instances
39 for (Index
= 0; Index
< MAX_IP4_CONFIG_IN_VARIABLE
; Index
++) {
40 if (mIp4ConfigNicList
[Index
] == NULL
) {
44 gIp4ConfigDriverBinding
.Stop (
45 &gIp4ConfigDriverBinding
,
46 mIp4ConfigNicList
[Index
]->MnpHandle
,
52 return NetLibDefaultUnload (ImageHandle
);
56 The entry point for IP4 config driver which install the driver
57 binding and component name protocol on its image.
59 @param ImageHandle The image handle of the driver.
60 @param SystemTable The system table.
62 @retval EFI_SUCCES All the related protocols are installed on the driver.
63 @retval Others Failed to install protocols.
67 Ip4ConfigDriverEntryPoint (
68 IN EFI_HANDLE ImageHandle
,
69 IN EFI_SYSTEM_TABLE
*SystemTable
72 return EfiLibInstallDriverBindingComponentName2 (
75 &gIp4ConfigDriverBinding
,
77 &gIp4ConfigComponentName
,
78 &gIp4ConfigComponentName2
84 Test to see if this driver supports ControllerHandle.
86 @param This Protocol instance pointer.
87 @param ControllerHandle Handle of device to test
88 @param RemainingDevicePath Optional parameter use to pick a specific child
91 @retval EFI_SUCCES This driver supports this device
92 @retval EFI_ALREADY_STARTED This driver is already running on this device
93 @retval other This driver does not support this device
98 Ip4ConfigDriverBindingSupported (
99 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
100 IN EFI_HANDLE ControllerHandle
,
101 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
106 Status
= gBS
->OpenProtocol (
108 &gEfiManagedNetworkServiceBindingProtocolGuid
,
110 This
->DriverBindingHandle
,
112 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
120 Start this driver on ControllerHandle.
122 @param This Protocol instance pointer.
123 @param ControllerHandle Handle of device to bind driver to
124 @param RemainingDevicePath Optional parameter use to pick a specific child
127 @retval EFI_SUCCES This driver is added to ControllerHandle
128 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
129 @retval other This driver does not support this device
134 Ip4ConfigDriverBindingStart (
135 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
136 IN EFI_HANDLE ControllerHandle
,
137 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
140 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
141 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
142 EFI_HANDLE MnpHandle
;
143 IP4_CONFIG_INSTANCE
*Instance
;
144 EFI_SIMPLE_NETWORK_MODE SnpMode
;
145 IP4_CONFIG_VARIABLE
*Variable
;
146 NIC_IP4_CONFIG_INFO
*NicConfig
;
147 IP4_CONFIG_VARIABLE
*NewVariable
;
152 // Check for multiple start.
154 Status
= gBS
->OpenProtocol (
156 &gEfiIp4ConfigProtocolGuid
,
157 (VOID
**) &Ip4Config
,
158 This
->DriverBindingHandle
,
160 EFI_OPEN_PROTOCOL_GET_PROTOCOL
163 if (!EFI_ERROR (Status
)) {
164 return EFI_ALREADY_STARTED
;
168 // Create a MNP child
174 Status
= NetLibCreateServiceChild (
176 This
->DriverBindingHandle
,
177 &gEfiManagedNetworkServiceBindingProtocolGuid
,
181 if (EFI_ERROR (Status
)) {
185 Status
= gBS
->OpenProtocol (
187 &gEfiManagedNetworkProtocolGuid
,
189 This
->DriverBindingHandle
,
191 EFI_OPEN_PROTOCOL_BY_DRIVER
194 if (EFI_ERROR (Status
)) {
199 // Allocate an instance then initialize it
201 Instance
= AllocatePool (sizeof (IP4_CONFIG_INSTANCE
));
203 if (Instance
== NULL
) {
204 Status
= EFI_OUT_OF_RESOURCES
;
208 Instance
->Signature
= IP4_CONFIG_INSTANCE_SIGNATURE
;
209 Instance
->Controller
= ControllerHandle
;
210 Instance
->Image
= This
->DriverBindingHandle
;
212 CopyMem (&Instance
->Ip4ConfigProtocol
, &mIp4ConfigProtocolTemplate
, sizeof (mIp4ConfigProtocolTemplate
));
213 CopyMem (&Instance
->NicIp4Protocol
, &mNicIp4ConfigProtocolTemplate
, sizeof (mNicIp4ConfigProtocolTemplate
));
215 Instance
->State
= IP4_CONFIG_STATE_IDLE
;
217 Instance
->MnpHandle
= MnpHandle
;
219 Instance
->DoneEvent
= NULL
;
220 Instance
->ReconfigEvent
= NULL
;
221 Instance
->Result
= EFI_NOT_READY
;
222 Instance
->NicConfig
= NULL
;
224 Instance
->Dhcp4
= NULL
;
225 Instance
->Dhcp4Handle
= NULL
;
226 Instance
->Dhcp4Event
= NULL
;
228 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
230 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
234 Instance
->NicAddr
.Type
= (UINT16
) SnpMode
.IfType
;
235 Instance
->NicAddr
.Len
= (UINT8
) SnpMode
.HwAddressSize
;
236 CopyMem (&Instance
->NicAddr
.MacAddr
, &SnpMode
.CurrentAddress
, sizeof (Instance
->NicAddr
.MacAddr
));
239 // Add it to the global list, and compose the name
241 for (Index
= 0; Index
< MAX_IP4_CONFIG_IN_VARIABLE
; Index
++) {
242 if (mIp4ConfigNicList
[Index
] == NULL
) {
243 mIp4ConfigNicList
[Index
] = Instance
;
244 Instance
->NicIndex
= Index
;
246 if (Instance
->NicAddr
.Type
== NET_IFTYPE_ETHERNET
) {
247 Instance
->NicName
[0] = 'e';
248 Instance
->NicName
[1] = 't';
249 Instance
->NicName
[2] = 'h';
250 Instance
->NicName
[3] = (UINT16
) ('0' + Index
);
251 Instance
->NicName
[4] = 0;
253 Instance
->NicName
[0] = 'u';
254 Instance
->NicName
[1] = 'n';
255 Instance
->NicName
[2] = 'k';
256 Instance
->NicName
[3] = (UINT16
) ('0' + Index
);
257 Instance
->NicName
[4] = 0;
264 if (Index
== MAX_IP4_CONFIG_IN_VARIABLE
) {
265 Status
= EFI_OUT_OF_RESOURCES
;
270 // Install the IP4_CONFIG and NIC_IP4CONFIG protocols
272 Status
= gBS
->InstallMultipleProtocolInterfaces (
274 &gEfiIp4ConfigProtocolGuid
,
275 &Instance
->Ip4ConfigProtocol
,
276 &gEfiNicIp4ConfigProtocolGuid
,
277 &Instance
->NicIp4Protocol
,
281 if (EFI_ERROR (Status
)) {
282 mIp4ConfigNicList
[Index
] = NULL
;
287 // Get the previous configure parameters. If an error happend here,
288 // just ignore it because the driver should be able to operate.
290 Variable
= Ip4ConfigReadVariable ();
292 if (Variable
== NULL
) {
296 NicConfig
= Ip4ConfigFindNicVariable (Variable
, &Instance
->NicAddr
);
298 if (NicConfig
== NULL
) {
303 // Don't modify the permant static configuration
305 if (NicConfig
->Perment
&& (NicConfig
->Source
== IP4_CONFIG_SOURCE_STATIC
)) {
310 // Delete the non-permant configuration and remove the previous
311 // acquired DHCP parameters. Only doing DHCP itself is permant
315 if (!NicConfig
->Perment
) {
316 NewVariable
= Ip4ConfigModifyVariable (Variable
, &Instance
->NicAddr
, NULL
);
318 } else if (NicConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
319 ZeroMem (&NicConfig
->Ip4Info
, sizeof (EFI_IP4_IPCONFIG_DATA
));
320 NewVariable
= Ip4ConfigModifyVariable (Variable
, &Instance
->NicAddr
, NicConfig
);
324 Ip4ConfigWriteVariable (NewVariable
);
326 if (NewVariable
!= NULL
) {
327 gBS
->FreePool (NewVariable
);
331 gBS
->FreePool (Variable
);
333 if (NicConfig
!= NULL
) {
334 gBS
->FreePool (NicConfig
);
340 if (Instance
!= NULL
) {
341 gBS
->FreePool (Instance
);
347 &gEfiManagedNetworkProtocolGuid
,
348 This
->DriverBindingHandle
,
353 NetLibDestroyServiceChild (
355 This
->DriverBindingHandle
,
356 &gEfiManagedNetworkProtocolGuid
,
365 Stop this driver on ControllerHandle.
367 @param This Protocol instance pointer.
368 @param ControllerHandle Handle of device to stop driver on
369 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
370 children is zero stop the entire bus driver.
371 @param ChildHandleBuffer List of Child Handles to Stop.
373 @retval EFI_SUCCES This driver is removed ControllerHandle
374 @retval other This driver was not removed from this device
379 Ip4ConfigDriverBindingStop (
380 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
381 IN EFI_HANDLE ControllerHandle
,
382 IN UINTN NumberOfChildren
,
383 IN EFI_HANDLE
*ChildHandleBuffer
386 IP4_CONFIG_INSTANCE
*Instance
;
387 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
388 EFI_HANDLE NicHandle
;
392 // IP4_CONFIG instance opens an MNP child. It may also create and open
393 // a DHCP child. If this is the DHCP handle, stop the DHCP process. If
394 // it is the MNP child, stop the whole driver.
397 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
399 if (NicHandle
!= NULL
) {
401 // Get our context back then clean the DHCP up. Notify the user if necessary.
403 Status
= gBS
->OpenProtocol (
405 &gEfiIp4ConfigProtocolGuid
,
406 (VOID
**) &Ip4Config
,
407 This
->DriverBindingHandle
,
409 EFI_OPEN_PROTOCOL_GET_PROTOCOL
412 if (EFI_ERROR (Status
)) {
416 Instance
= IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config
);
417 ASSERT (ControllerHandle
== Instance
->Dhcp4Handle
);
419 Ip4ConfigCleanDhcp4 (Instance
);
421 Instance
->State
= IP4_CONFIG_STATE_CONFIGURED
;
422 Instance
->Result
= EFI_DEVICE_ERROR
;
424 if (Instance
->DoneEvent
!= NULL
) {
425 gBS
->SignalEvent (Instance
->DoneEvent
);
432 // This is a MNP handle, stop the whole driver
434 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
436 if (NicHandle
== NULL
) {
441 // Get our context back.
443 Status
= gBS
->OpenProtocol (
445 &gEfiIp4ConfigProtocolGuid
,
446 (VOID
**) &Ip4Config
,
447 This
->DriverBindingHandle
,
449 EFI_OPEN_PROTOCOL_GET_PROTOCOL
452 if (EFI_ERROR (Status
)) {
456 Instance
= IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config
);
459 // Unload the protocols first to inform the top drivers
461 Status
= gBS
->UninstallMultipleProtocolInterfaces (
463 &gEfiIp4ConfigProtocolGuid
,
464 &Instance
->Ip4ConfigProtocol
,
465 &gEfiNicIp4ConfigProtocolGuid
,
466 &Instance
->NicIp4Protocol
,
470 if (EFI_ERROR (Status
)) {
475 // Release all the resources
477 if (Instance
->MnpHandle
!= NULL
) {
480 &gEfiManagedNetworkProtocolGuid
,
481 This
->DriverBindingHandle
,
485 NetLibDestroyServiceChild (
488 &gEfiManagedNetworkServiceBindingProtocolGuid
,
492 Instance
->Mnp
= NULL
;
493 Instance
->MnpHandle
= NULL
;
496 Ip4ConfigCleanConfig (Instance
);
497 mIp4ConfigNicList
[Instance
->NicIndex
] = NULL
;
498 gBS
->FreePool (Instance
);
503 EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding
= {
504 Ip4ConfigDriverBindingSupported
,
505 Ip4ConfigDriverBindingStart
,
506 Ip4ConfigDriverBindingStop
,