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 NetLibInstallAllDriverProtocolsWithUnload (
91 &gIp4ConfigDriverBinding
,
93 &gIp4ConfigComponentName
,
102 Test to see if this driver supports ControllerHandle.
104 @param This Protocol instance pointer.
105 @param ControllerHandle Handle of device to test
106 @param RemainingDevicePath Optional parameter use to pick a specific child
109 @retval EFI_SUCCES This driver supports this device
110 @retval EFI_ALREADY_STARTED This driver is already running on this device
111 @retval other This driver does not support this device
116 Ip4ConfigDriverBindingSupported (
117 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
118 IN EFI_HANDLE ControllerHandle
,
119 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
124 Status
= gBS
->OpenProtocol (
126 &gEfiManagedNetworkServiceBindingProtocolGuid
,
128 This
->DriverBindingHandle
,
130 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
138 Start this driver on ControllerHandle.
140 @param This Protocol instance pointer.
141 @param ControllerHandle Handle of device to bind driver to
142 @param RemainingDevicePath Optional parameter use to pick a specific child
145 @retval EFI_SUCCES This driver is added to ControllerHandle
146 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
147 @retval other This driver does not support this device
152 Ip4ConfigDriverBindingStart (
153 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
154 IN EFI_HANDLE ControllerHandle
,
155 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
158 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
159 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
160 EFI_HANDLE MnpHandle
;
161 IP4_CONFIG_INSTANCE
*Instance
;
162 EFI_SIMPLE_NETWORK_MODE SnpMode
;
163 IP4_CONFIG_VARIABLE
*Variable
;
164 NIC_IP4_CONFIG_INFO
*NicConfig
;
165 IP4_CONFIG_VARIABLE
*NewVariable
;
170 // Check for multiple start.
172 Status
= gBS
->OpenProtocol (
174 &gEfiIp4ConfigProtocolGuid
,
175 (VOID
**) &Ip4Config
,
176 This
->DriverBindingHandle
,
178 EFI_OPEN_PROTOCOL_GET_PROTOCOL
181 if (!EFI_ERROR (Status
)) {
182 return EFI_ALREADY_STARTED
;
186 // Create a MNP child
192 Status
= NetLibCreateServiceChild (
194 This
->DriverBindingHandle
,
195 &gEfiManagedNetworkServiceBindingProtocolGuid
,
199 if (EFI_ERROR (Status
)) {
203 Status
= gBS
->OpenProtocol (
205 &gEfiManagedNetworkProtocolGuid
,
207 This
->DriverBindingHandle
,
209 EFI_OPEN_PROTOCOL_BY_DRIVER
212 if (EFI_ERROR (Status
)) {
217 // Allocate an instance then initialize it
219 Instance
= NetAllocatePool (sizeof (IP4_CONFIG_INSTANCE
));
221 if (Instance
== NULL
) {
222 Status
= EFI_OUT_OF_RESOURCES
;
226 Instance
->Signature
= IP4_CONFIG_INSTANCE_SIGNATURE
;
227 Instance
->Controller
= ControllerHandle
;
228 Instance
->Image
= This
->DriverBindingHandle
;
230 Instance
->Ip4ConfigProtocol
= mIp4ConfigProtocolTemplate
;
231 Instance
->NicIp4Protocol
= mNicIp4ConfigProtocolTemplate
;
233 Instance
->State
= IP4_CONFIG_STATE_IDLE
;
235 Instance
->MnpHandle
= MnpHandle
;
237 Instance
->DoneEvent
= NULL
;
238 Instance
->ReconfigEvent
= NULL
;
239 Instance
->Result
= EFI_NOT_READY
;
240 Instance
->NicConfig
= NULL
;
242 Instance
->Dhcp4
= NULL
;
243 Instance
->Dhcp4Handle
= NULL
;
244 Instance
->Dhcp4Event
= NULL
;
246 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
248 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
252 Instance
->NicAddr
.Type
= (UINT16
) SnpMode
.IfType
;
253 Instance
->NicAddr
.Len
= (UINT8
) SnpMode
.HwAddressSize
;
254 CopyMem (&Instance
->NicAddr
.MacAddr
, &SnpMode
.CurrentAddress
, sizeof (EFI_MAC_ADDRESS
));
257 // Add it to the global list, and compose the name
259 for (Index
= 0; Index
< MAX_IP4_CONFIG_IN_VARIABLE
; Index
++) {
260 if (mIp4ConfigNicList
[Index
] == NULL
) {
261 mIp4ConfigNicList
[Index
] = Instance
;
262 Instance
->NicIndex
= Index
;
264 if (Instance
->NicAddr
.Type
== NET_IFTYPE_ETHERNET
) {
265 Instance
->NicName
[0] = 'e';
266 Instance
->NicName
[1] = 't';
267 Instance
->NicName
[2] = 'h';
268 Instance
->NicName
[3] = (UINT16
) ('0' + Index
);
269 Instance
->NicName
[4] = 0;
271 Instance
->NicName
[0] = 'u';
272 Instance
->NicName
[1] = 'n';
273 Instance
->NicName
[2] = 'k';
274 Instance
->NicName
[3] = (UINT16
) ('0' + Index
);
275 Instance
->NicName
[4] = 0;
282 if (Index
== MAX_IP4_CONFIG_IN_VARIABLE
) {
283 Status
= EFI_OUT_OF_RESOURCES
;
288 // Install the IP4_CONFIG and NIC_IP4CONFIG protocols
290 Status
= gBS
->InstallMultipleProtocolInterfaces (
292 &gEfiIp4ConfigProtocolGuid
,
293 &Instance
->Ip4ConfigProtocol
,
294 &gEfiNicIp4ConfigProtocolGuid
,
295 &Instance
->NicIp4Protocol
,
299 if (EFI_ERROR (Status
)) {
300 mIp4ConfigNicList
[Index
] = NULL
;
305 // Get the previous configure parameters. If an error happend here,
306 // just ignore it because the driver should be able to operate.
308 Variable
= Ip4ConfigReadVariable ();
310 if (Variable
== NULL
) {
314 NicConfig
= Ip4ConfigFindNicVariable (Variable
, &Instance
->NicAddr
);
316 if (NicConfig
== NULL
) {
321 // Don't modify the permant static configuration
323 if (NicConfig
->Perment
&& (NicConfig
->Source
== IP4_CONFIG_SOURCE_STATIC
)) {
328 // Delete the non-permant configuration and remove the previous
329 // acquired DHCP parameters. Only doing DHCP itself is permant
333 if (!NicConfig
->Perment
) {
334 NewVariable
= Ip4ConfigModifyVariable (Variable
, &Instance
->NicAddr
, NULL
);
336 } else if (NicConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
337 NetZeroMem (&NicConfig
->Ip4Info
, sizeof (EFI_IP4_IPCONFIG_DATA
));
338 NewVariable
= Ip4ConfigModifyVariable (Variable
, &Instance
->NicAddr
, NicConfig
);
342 Ip4ConfigWriteVariable (NewVariable
);
344 if (NewVariable
!= NULL
) {
345 NetFreePool (NewVariable
);
349 NetFreePool (Variable
);
351 if (NicConfig
!= NULL
) {
352 NetFreePool (NicConfig
);
358 if (Instance
!= NULL
) {
359 NetFreePool (Instance
);
365 &gEfiManagedNetworkProtocolGuid
,
366 This
->DriverBindingHandle
,
371 NetLibDestroyServiceChild (
373 This
->DriverBindingHandle
,
374 &gEfiManagedNetworkProtocolGuid
,
383 Stop this driver on ControllerHandle.
385 @param This Protocol instance pointer.
386 @param ControllerHandle Handle of device to stop driver on
387 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
388 children is zero stop the entire bus driver.
389 @param ChildHandleBuffer List of Child Handles to Stop.
391 @retval EFI_SUCCES This driver is removed ControllerHandle
392 @retval other This driver was not removed from this device
397 Ip4ConfigDriverBindingStop (
398 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
399 IN EFI_HANDLE ControllerHandle
,
400 IN UINTN NumberOfChildren
,
401 IN EFI_HANDLE
*ChildHandleBuffer
404 IP4_CONFIG_INSTANCE
*Instance
;
405 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
406 EFI_HANDLE NicHandle
;
410 // IP4_CONFIG instance opens an MNP child. It may also create and open
411 // a DHCP child. If this is the DHCP handle, stop the DHCP process. If
412 // it is the MNP child, stop the whole driver.
415 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
417 if (NicHandle
!= NULL
) {
419 // Get our context back then clean the DHCP up. Notify the user if necessary.
421 Status
= gBS
->OpenProtocol (
423 &gEfiIp4ConfigProtocolGuid
,
424 (VOID
**) &Ip4Config
,
425 This
->DriverBindingHandle
,
427 EFI_OPEN_PROTOCOL_GET_PROTOCOL
430 if (EFI_ERROR (Status
)) {
434 Instance
= IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config
);
435 ASSERT (ControllerHandle
== Instance
->Dhcp4Handle
);
437 Ip4ConfigCleanDhcp4 (Instance
);
439 Instance
->State
= IP4_CONFIG_STATE_CONFIGURED
;
440 Instance
->Result
= EFI_DEVICE_ERROR
;
442 if (Instance
->DoneEvent
!= NULL
) {
443 gBS
->SignalEvent (Instance
->DoneEvent
);
450 // This is a MNP handle, stop the whole driver
452 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiManagedNetworkProtocolGuid
);
454 if (NicHandle
== NULL
) {
459 // Get our context back.
461 Status
= gBS
->OpenProtocol (
463 &gEfiIp4ConfigProtocolGuid
,
464 (VOID
**) &Ip4Config
,
465 This
->DriverBindingHandle
,
467 EFI_OPEN_PROTOCOL_GET_PROTOCOL
470 if (EFI_ERROR (Status
)) {
474 Instance
= IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (Ip4Config
);
477 // Unload the protocols first to inform the top drivers
479 Status
= gBS
->UninstallMultipleProtocolInterfaces (
481 &gEfiIp4ConfigProtocolGuid
,
482 &Instance
->Ip4ConfigProtocol
,
483 &gEfiNicIp4ConfigProtocolGuid
,
484 &Instance
->NicIp4Protocol
,
488 if (EFI_ERROR (Status
)) {
493 // Release all the resources
495 if (Instance
->MnpHandle
!= NULL
) {
498 &gEfiManagedNetworkProtocolGuid
,
499 This
->DriverBindingHandle
,
503 NetLibDestroyServiceChild (
506 &gEfiManagedNetworkServiceBindingProtocolGuid
,
510 Instance
->Mnp
= NULL
;
511 Instance
->MnpHandle
= NULL
;
514 Ip4ConfigCleanConfig (Instance
);
515 mIp4ConfigNicList
[Instance
->NicIndex
] = NULL
;
516 NetFreePool (Instance
);
521 EFI_DRIVER_BINDING_PROTOCOL gIp4ConfigDriverBinding
= {
522 Ip4ConfigDriverBindingSupported
,
523 Ip4ConfigDriverBindingStart
,
524 Ip4ConfigDriverBindingStop
,