2 Driver Binding Protocol for IPsec Driver.
4 Copyright (c) 2009 - 2010, 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.
16 #include <Library/UdpIoLib.h>
17 #include "IpSecConfigImpl.h"
18 #include "IpSecDebug.h"
21 Test to see if this driver supports ControllerHandle.
23 @param[in] This Protocol instance pointer.
24 @param[in] ControllerHandle Handle of device to test.
25 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
28 @retval EFI_SUCCES This driver supports this device.
29 @retval EFI_ALREADY_STARTED This driver is already running on this device.
30 @retval other This driver does not support this device.
35 IpSecDriverBindingSupported (
36 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
37 IN EFI_HANDLE ControllerHandle
,
38 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
42 //TODO: Add Udp4Protocol and Udp6Protocol testing.
44 return EFI_UNSUPPORTED
;
48 Start this driver on ControllerHandle.
50 @param[in] This Protocol instance pointer.
51 @param[in] ControllerHandle Handle of device to bind driver to.
52 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
55 @retval EFI_SUCCES This driver is added to ControllerHandle
56 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
57 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
58 Currently not implemented.
59 @retval other This driver does not support this device
64 IpSecDriverBindingStart (
65 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
66 IN EFI_HANDLE ControllerHandle
,
67 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
71 //TODO: Add Udp4Io and Udp6Io creation for the IKE.
77 Stop this driver on ControllerHandle.
79 @param[in] This Protocol instance pointer.
80 @param[in] ControllerHandle Handle of a device to stop the driver on.
81 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If the number of
82 children is zero, stop the entire bus driver.
83 @param[in] ChildHandleBuffer List of Child Handles to Stop.
85 @retval EFI_SUCCES This driver removed ControllerHandle.
86 @retval other This driver was not removed from this device.
91 IpSecDriverBindingStop (
92 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
93 IN EFI_HANDLE ControllerHandle
,
94 IN UINTN NumberOfChildren
,
95 IN EFI_HANDLE
*ChildHandleBuffer
99 //TODO: Add UdpIo4 and UdpIo6 destruction when the Udp driver unload or stop.
101 return EFI_UNSUPPORTED
;
104 EFI_DRIVER_BINDING_PROTOCOL gIpSecDriverBinding
= {
105 IpSecDriverBindingSupported
,
106 IpSecDriverBindingStart
,
107 IpSecDriverBindingStop
,
114 This is a callback function when the mIpSecInstance.DisabledEvent is signaled.
116 @param[in] Event Event whose notification function is being invoked.
117 @param[in] Context Pointer to the notification function's context.
127 IPSEC_PRIVATE_DATA
*Private
;
131 Private
= (IPSEC_PRIVATE_DATA
*) Context
;
134 // Set the Status Variable
136 Value
= IPSEC_STATUS_DISABLED
;
137 Status
= gRT
->SetVariable (
138 IPSECCONFIG_STATUS_NAME
,
139 &gEfiIpSecConfigProtocolGuid
,
140 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
144 if (!EFI_ERROR (Status
)) {
145 Private
->IpSec
.DisabledFlag
= TRUE
;
151 This is the declaration of an EFI image entry point. This entry point is
152 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including
153 both device drivers and bus drivers.
155 The entry point for IPsec driver which installs the driver binding,
156 component name protocol, IPsec Config protcolon, and IPsec protocol in
159 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
160 @param[in] SystemTable A pointer to the EFI System Table.
162 @retval EFI_SUCCESS The operation completed successfully.
163 @retval EFI_ALREADY_STARTED The IPsec driver has been already loaded.
164 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
165 @retval Others The operation is failed.
170 IpSecDriverEntryPoint (
171 IN EFI_HANDLE ImageHandle
,
172 IN EFI_SYSTEM_TABLE
*SystemTable
176 IPSEC_PRIVATE_DATA
*Private
;
177 EFI_IPSEC2_PROTOCOL
*IpSec
;
180 // Check whether ipsec protocol has already been installed.
182 Status
= gBS
->LocateProtocol (&gEfiIpSecProtocolGuid
, NULL
, (VOID
**) &IpSec
);
184 if (!EFI_ERROR (Status
)) {
185 DEBUG ((DEBUG_WARN
, "_ModuleEntryPoint: IpSec has been already loaded\n"));
186 Status
= EFI_ALREADY_STARTED
;
190 Status
= gBS
->LocateProtocol (&gEfiDpcProtocolGuid
, NULL
, (VOID
**) &mDpc
);
192 if (EFI_ERROR (Status
)) {
193 DEBUG ((DEBUG_ERROR
, "_ModuleEntryPoint: Failed to locate EfiDpcProtocol\n"));
197 Private
= AllocateZeroPool (sizeof (IPSEC_PRIVATE_DATA
));
199 if (Private
== NULL
) {
200 DEBUG ((DEBUG_ERROR
, "_ModuleEntryPoint: Failed to allocate private data\n"));
201 Status
= EFI_OUT_OF_RESOURCES
;
205 // Create disable event to cleanup all sa when ipsec disabled by user.
207 Status
= gBS
->CreateEvent (
212 &mIpSecInstance
.DisabledEvent
214 if (EFI_ERROR (Status
)) {
215 DEBUG ((DEBUG_ERROR
, "_ModuleEntryPoint: Failed to create disable event\n"));
216 goto ON_FREE_PRIVATE
;
219 Private
->Signature
= IPSEC_PRIVATE_DATA_SIGNATURE
;
220 Private
->ImageHandle
= ImageHandle
;
221 CopyMem (&Private
->IpSec
, &mIpSecInstance
, sizeof (EFI_IPSEC2_PROTOCOL
));
224 // Initilize Private's members. Thess members is used for IKE.
226 InitializeListHead (&Private
->Udp4List
);
227 InitializeListHead (&Private
->Udp6List
);
228 InitializeListHead (&Private
->Ikev1SessionList
);
229 InitializeListHead (&Private
->Ikev1EstablishedList
);
230 InitializeListHead (&Private
->Ikev2SessionList
);
231 InitializeListHead (&Private
->Ikev2EstablishedList
);
234 // Initialize the ipsec config data and restore it from variable.
236 Status
= IpSecConfigInitialize (Private
);
237 if (EFI_ERROR (Status
)) {
238 DEBUG ((DEBUG_ERROR
, "_ModuleEntryPoint: Failed to initialize IpSecConfig\n"));
242 // Install ipsec protocol which is used by ip driver to process ipsec header.
244 Status
= gBS
->InstallMultipleProtocolInterfaces (
246 &gEfiIpSecProtocolGuid
,
250 if (EFI_ERROR (Status
)) {
251 goto ON_UNINSTALL_CONFIG
;
254 Status
= EfiLibInstallDriverBindingComponentName2 (
257 &gIpSecDriverBinding
,
259 &gIpSecComponentName
,
260 &gIpSecComponentName2
262 if (EFI_ERROR (Status
)) {
263 goto ON_UNINSTALL_CONFIG
;
269 gBS
->UninstallProtocolInterface (
271 &gEfiIpSecConfigProtocolGuid
,
272 &Private
->IpSecConfig
275 gBS
->CloseEvent (mIpSecInstance
.DisabledEvent
);
276 mIpSecInstance
.DisabledEvent
= NULL
;