]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IpSecDxe/IpSecDriver.c
Bug fix: IpSec driver treats BOOLEAN as EFI_STATUS in error handling code.
[mirror_edk2.git] / NetworkPkg / IpSecDxe / IpSecDriver.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 Driver Binding Protocol for IPsec Driver.\r
3\r
6879581d 4 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
9166f840 16#include <Library/BaseCryptLib.h>\r
17\r
a3bcde70 18#include "IpSecConfigImpl.h"\r
9166f840 19#include "IkeService.h"\r
a3bcde70
HT
20#include "IpSecDebug.h"\r
21\r
22/**\r
6879581d 23 Test to see if this driver supports ControllerHandle. This is the worker function\r
24 for IpSec4(6)DriverbindingSupported.\r
a3bcde70
HT
25\r
26 @param[in] This Protocol instance pointer.\r
27 @param[in] ControllerHandle Handle of device to test.\r
28 @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r
29 device to start.\r
6879581d 30 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
31 \r
a3bcde70
HT
32 @retval EFI_SUCCES This driver supports this device.\r
33 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
34 @retval other This driver does not support this device.\r
35\r
36**/\r
37EFI_STATUS\r
38EFIAPI\r
6879581d 39IpSecSupported (\r
a3bcde70
HT
40 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
41 IN EFI_HANDLE ControllerHandle,\r
6879581d 42 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,\r
43 IN UINT8 IpVersion\r
a3bcde70
HT
44 )\r
45{\r
6879581d 46 EFI_STATUS Status;\r
47 EFI_GUID *UdpServiceBindingGuid;\r
48 \r
49 if (IpVersion == IP_VERSION_4) {\r
50 UdpServiceBindingGuid = &gEfiUdp4ServiceBindingProtocolGuid;\r
51 } else {\r
52 UdpServiceBindingGuid = &gEfiUdp6ServiceBindingProtocolGuid;\r
9166f840 53 }\r
54\r
6879581d 55 Status = gBS->OpenProtocol (\r
56 ControllerHandle,\r
57 UdpServiceBindingGuid,\r
58 NULL,\r
59 This->DriverBindingHandle,\r
60 ControllerHandle,\r
61 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
62 );\r
63 if (EFI_ERROR (Status)) {\r
64 return EFI_UNSUPPORTED;\r
65 }\r
66 return EFI_SUCCESS;\r
a3bcde70
HT
67}\r
68\r
69/**\r
6879581d 70 Start this driver on ControllerHandle. This is the worker function\r
71 for IpSec4(6)DriverbindingStart.\r
a3bcde70
HT
72\r
73 @param[in] This Protocol instance pointer.\r
74 @param[in] ControllerHandle Handle of device to bind driver to.\r
75 @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r
76 device to start.\r
6879581d 77 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
a3bcde70
HT
78\r
79 @retval EFI_SUCCES This driver is added to ControllerHandle\r
80 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
6cf9230f 81 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
a3bcde70
HT
82 Currently not implemented.\r
83 @retval other This driver does not support this device\r
84\r
85**/\r
86EFI_STATUS\r
87EFIAPI\r
6879581d 88IpSecStart (\r
a3bcde70
HT
89 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
90 IN EFI_HANDLE ControllerHandle,\r
6879581d 91 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,\r
92 IN UINT8 IpVersion\r
a3bcde70
HT
93 )\r
94{\r
0a7294f7 95 EFI_IPSEC2_PROTOCOL *IpSec;\r
9166f840 96 EFI_STATUS Status;\r
9166f840 97 IPSEC_PRIVATE_DATA *Private;\r
98\r
a3bcde70 99 //\r
9166f840 100 // Ipsec protocol should be installed when load image.\r
a3bcde70 101 //\r
0a7294f7 102 Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **) &IpSec);\r
9166f840 103\r
104 if (EFI_ERROR (Status)) {\r
105 return Status;\r
106 }\r
107\r
108 Private = IPSEC_PRIVATE_DATA_FROM_IPSEC (IpSec);\r
109\r
6879581d 110 if (IpVersion == IP_VERSION_4) {\r
111 //\r
112 // Try to open a udp4 io for input.\r
113 //\r
114 Status = gBS->OpenProtocol (\r
115 ControllerHandle,\r
116 &gEfiUdp4ServiceBindingProtocolGuid,\r
117 NULL,\r
118 This->DriverBindingHandle,\r
119 ControllerHandle,\r
120 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
121 );\r
122\r
123 if (!EFI_ERROR (Status)) {\r
124 Status = IkeOpenInputUdp4 (Private, ControllerHandle, This->DriverBindingHandle);\r
125 }\r
126 } else {\r
127 //\r
128 // Try to open a udp6 io for input.\r
129 //\r
130 Status = gBS->OpenProtocol (\r
131 ControllerHandle,\r
132 &gEfiUdp6ServiceBindingProtocolGuid,\r
133 NULL,\r
134 This->DriverBindingHandle,\r
135 ControllerHandle,\r
136 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
137 );\r
138\r
139 if (!EFI_ERROR (Status)) {\r
140 Status = IkeOpenInputUdp6 (Private, ControllerHandle, This->DriverBindingHandle);\r
141 }\r
9166f840 142 }\r
143\r
6879581d 144 if (EFI_ERROR (Status)) {\r
145 return EFI_DEVICE_ERROR;\r
9166f840 146 }\r
6879581d 147 return EFI_SUCCESS;\r
a3bcde70
HT
148}\r
149\r
150/**\r
6879581d 151 Stop this driver on ControllerHandle. This is the worker function\r
152 for IpSec4(6)DriverbindingStop.\r
a3bcde70
HT
153\r
154 @param[in] This Protocol instance pointer.\r
155 @param[in] ControllerHandle Handle of a device to stop the driver on.\r
156 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If the number of\r
157 children is zero, stop the entire bus driver.\r
158 @param[in] ChildHandleBuffer List of Child Handles to Stop.\r
6879581d 159 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
a3bcde70
HT
160\r
161 @retval EFI_SUCCES This driver removed ControllerHandle.\r
162 @retval other This driver was not removed from this device.\r
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
6879581d 167IpSecStop (\r
a3bcde70
HT
168 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
169 IN EFI_HANDLE ControllerHandle,\r
170 IN UINTN NumberOfChildren,\r
6879581d 171 IN EFI_HANDLE *ChildHandleBuffer,\r
172 IN UINT8 IpVersion\r
a3bcde70
HT
173 )\r
174{\r
0a7294f7 175 EFI_IPSEC2_PROTOCOL *IpSec;\r
9166f840 176 EFI_STATUS Status;\r
177 IPSEC_PRIVATE_DATA *Private;\r
178 IKE_UDP_SERVICE *UdpSrv;\r
179 LIST_ENTRY *Entry;\r
180 LIST_ENTRY *Next;\r
181\r
a3bcde70 182 //\r
9166f840 183 // Locate ipsec protocol to get private data.\r
a3bcde70 184 //\r
0a7294f7 185 Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **) &IpSec);\r
9166f840 186\r
187 if (EFI_ERROR (Status)) {\r
188 return Status;\r
189 }\r
190\r
191 Private = IPSEC_PRIVATE_DATA_FROM_IPSEC (IpSec);\r
192\r
6cf9230f 193 //\r
6879581d 194 // The SAs are shared by both IP4 and IP6 stack. So we skip the cleanup\r
195 // and leave the SAs unchanged if the other IP stack is still running.\r
9166f840 196 //\r
6879581d 197 if ((IpVersion == IP_VERSION_4 && Private->Udp6Num ==0) ||\r
198 (IpVersion == IP_VERSION_6 && Private->Udp4Num ==0)) {\r
199 IkeDeleteAllSas (Private, FALSE);\r
200 }\r
9166f840 201\r
6879581d 202 if (IpVersion == IP_VERSION_4) {\r
9166f840 203 //\r
6879581d 204 // If has udp4 io opened on the controller, close and free it.\r
9166f840 205 //\r
6879581d 206 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Private->Udp4List) {\r
207\r
208 UdpSrv = IPSEC_UDP_SERVICE_FROM_LIST (Entry);\r
209 //\r
210 // Find the right udp service which installed on the appointed nic handle.\r
211 //\r
212 if (UdpSrv->Input != NULL && ControllerHandle == UdpSrv->Input->UdpHandle) {\r
213 UdpIoFreeIo (UdpSrv->Input);\r
214 UdpSrv->Input = NULL;\r
215 }\r
216\r
217 if (UdpSrv->Output != NULL && ControllerHandle == UdpSrv->Output->UdpHandle) {\r
218 UdpIoFreeIo (UdpSrv->Output);\r
219 UdpSrv->Output = NULL;\r
220 }\r
221\r
222 if (UdpSrv->Input == NULL && UdpSrv->Output == NULL) {\r
223 RemoveEntryList (&UdpSrv->List);\r
224 FreePool (UdpSrv);\r
225 ASSERT (Private->Udp4Num > 0);\r
226 Private->Udp4Num--;\r
227 }\r
9166f840 228 }\r
6879581d 229 } else {\r
9166f840 230 //\r
6879581d 231 // If has udp6 io opened on the controller, close and free it.\r
9166f840 232 //\r
6879581d 233 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Private->Udp6List) {\r
234\r
235 UdpSrv = IPSEC_UDP_SERVICE_FROM_LIST (Entry);\r
236 //\r
237 // Find the right udp service which installed on the appointed nic handle.\r
238 //\r
239 if (UdpSrv->Input != NULL && ControllerHandle == UdpSrv->Input->UdpHandle) {\r
240 UdpIoFreeIo (UdpSrv->Input);\r
241 UdpSrv->Input = NULL;\r
242 }\r
243\r
244 if (UdpSrv->Output != NULL && ControllerHandle == UdpSrv->Output->UdpHandle) {\r
245 UdpIoFreeIo (UdpSrv->Output);\r
246 UdpSrv->Output = NULL;\r
247 }\r
248\r
249 if (UdpSrv->Input == NULL && UdpSrv->Output == NULL) {\r
250 RemoveEntryList (&UdpSrv->List);\r
251 FreePool (UdpSrv);\r
252 ASSERT (Private->Udp6Num > 0);\r
253 Private->Udp6Num--;\r
254 }\r
9166f840 255 }\r
256 }\r
257\r
258 return EFI_SUCCESS;\r
a3bcde70
HT
259}\r
260\r
6879581d 261/**\r
262 Test to see if this driver supports ControllerHandle.\r
263\r
264 @param[in] This Protocol instance pointer.\r
265 @param[in] ControllerHandle Handle of device to test.\r
266 @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r
267 device to start.\r
268\r
269 @retval EFI_SUCCES This driver supports this device.\r
270 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
271 @retval other This driver does not support this device.\r
272\r
273**/\r
274EFI_STATUS\r
275EFIAPI\r
276IpSec4DriverBindingSupported (\r
277 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
278 IN EFI_HANDLE ControllerHandle,\r
279 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
280 )\r
281{\r
282 return IpSecSupported (\r
283 This,\r
284 ControllerHandle,\r
285 RemainingDevicePath,\r
286 IP_VERSION_4\r
287 );\r
288}\r
289\r
290/**\r
291 Start this driver on ControllerHandle.\r
292\r
293 @param[in] This Protocol instance pointer.\r
294 @param[in] ControllerHandle Handle of device to bind driver to.\r
295 @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r
296 device to start.\r
297\r
298 @retval EFI_SUCCES This driver is added to ControllerHandle\r
299 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
300 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
301 Currently not implemented.\r
302 @retval other This driver does not support this device\r
303\r
304**/\r
305EFI_STATUS\r
306EFIAPI\r
307IpSec4DriverBindingStart (\r
308 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
309 IN EFI_HANDLE ControllerHandle,\r
310 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
311 )\r
312{\r
313 return IpSecStart (\r
314 This,\r
315 ControllerHandle,\r
316 RemainingDevicePath,\r
317 IP_VERSION_4\r
318 );\r
319}\r
320\r
321/**\r
322 Stop this driver on ControllerHandle.\r
323\r
324 @param[in] This Protocol instance pointer.\r
325 @param[in] ControllerHandle Handle of a device to stop the driver on.\r
326 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If the number of\r
327 children is zero, stop the entire bus driver.\r
328 @param[in] ChildHandleBuffer List of Child Handles to Stop.\r
329\r
330 @retval EFI_SUCCES This driver removed ControllerHandle.\r
331 @retval other This driver was not removed from this device.\r
332\r
333**/\r
334EFI_STATUS\r
335EFIAPI\r
336IpSec4DriverBindingStop (\r
337 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
338 IN EFI_HANDLE ControllerHandle,\r
339 IN UINTN NumberOfChildren,\r
340 IN EFI_HANDLE *ChildHandleBuffer\r
341 )\r
342{\r
343 return IpSecStop (\r
344 This,\r
345 ControllerHandle,\r
346 NumberOfChildren,\r
347 ChildHandleBuffer,\r
348 IP_VERSION_4\r
349 );\r
350}\r
351\r
352/**\r
353 Test to see if this driver supports ControllerHandle.\r
354\r
355 @param[in] This Protocol instance pointer.\r
356 @param[in] ControllerHandle Handle of device to test.\r
357 @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r
358 device to start.\r
359\r
360 @retval EFI_SUCCES This driver supports this device.\r
361 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
362 @retval other This driver does not support this device.\r
363\r
364**/\r
365EFI_STATUS\r
366EFIAPI\r
367IpSec6DriverBindingSupported (\r
368 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
369 IN EFI_HANDLE ControllerHandle,\r
370 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
371 )\r
372{\r
373 return IpSecSupported (\r
374 This,\r
375 ControllerHandle,\r
376 RemainingDevicePath,\r
377 IP_VERSION_6\r
378 );\r
379}\r
380\r
381/**\r
382 Start this driver on ControllerHandle.\r
383\r
384 @param[in] This Protocol instance pointer.\r
385 @param[in] ControllerHandle Handle of device to bind driver to.\r
386 @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r
387 device to start.\r
388\r
389 @retval EFI_SUCCES This driver is added to ControllerHandle\r
390 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
391 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
392 Currently not implemented.\r
393 @retval other This driver does not support this device\r
394\r
395**/\r
396EFI_STATUS\r
397EFIAPI\r
398IpSec6DriverBindingStart (\r
399 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
400 IN EFI_HANDLE ControllerHandle,\r
401 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
402 )\r
403{\r
404 return IpSecStart (\r
405 This,\r
406 ControllerHandle,\r
407 RemainingDevicePath,\r
408 IP_VERSION_6\r
409 );\r
410}\r
411\r
412/**\r
413 Stop this driver on ControllerHandle.\r
414\r
415 @param[in] This Protocol instance pointer.\r
416 @param[in] ControllerHandle Handle of a device to stop the driver on.\r
417 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If the number of\r
418 children is zero, stop the entire bus driver.\r
419 @param[in] ChildHandleBuffer List of Child Handles to Stop.\r
420\r
421 @retval EFI_SUCCES This driver removed ControllerHandle.\r
422 @retval other This driver was not removed from this device.\r
423\r
424**/\r
425EFI_STATUS\r
426EFIAPI\r
427IpSec6DriverBindingStop (\r
428 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
429 IN EFI_HANDLE ControllerHandle,\r
430 IN UINTN NumberOfChildren,\r
431 IN EFI_HANDLE *ChildHandleBuffer\r
432 )\r
433{\r
434 return IpSecStop (\r
435 This,\r
436 ControllerHandle,\r
437 NumberOfChildren,\r
438 ChildHandleBuffer,\r
439 IP_VERSION_6\r
440 );\r
441}\r
442\r
443EFI_DRIVER_BINDING_PROTOCOL gIpSec4DriverBinding = {\r
444 IpSec4DriverBindingSupported,\r
445 IpSec4DriverBindingStart,\r
446 IpSec4DriverBindingStop,\r
447 0xa,\r
448 NULL,\r
449 NULL\r
450};\r
451\r
452EFI_DRIVER_BINDING_PROTOCOL gIpSec6DriverBinding = {\r
453 IpSec6DriverBindingSupported,\r
454 IpSec6DriverBindingStart,\r
455 IpSec6DriverBindingStop,\r
a3bcde70
HT
456 0xa,\r
457 NULL,\r
458 NULL\r
459};\r
460\r
461/**\r
462 This is a callback function when the mIpSecInstance.DisabledEvent is signaled.\r
6cf9230f 463\r
a3bcde70 464 @param[in] Event Event whose notification function is being invoked.\r
6cf9230f 465 @param[in] Context Pointer to the notification function's context.\r
a3bcde70
HT
466\r
467**/\r
468VOID\r
469EFIAPI\r
470IpSecCleanupAllSa (\r
471 IN EFI_EVENT Event,\r
472 IN VOID *Context\r
473 )\r
474{\r
475 IPSEC_PRIVATE_DATA *Private;\r
9166f840 476 Private = (IPSEC_PRIVATE_DATA *) Context;\r
477 Private->IsIPsecDisabling = TRUE;\r
6cf9230f 478 IkeDeleteAllSas (Private, TRUE);\r
a3bcde70
HT
479}\r
480\r
481/**\r
482 This is the declaration of an EFI image entry point. This entry point is\r
483 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including\r
484 both device drivers and bus drivers.\r
6cf9230f 485\r
486 The entry point for IPsec driver which installs the driver binding,\r
a3bcde70
HT
487 component name protocol, IPsec Config protcolon, and IPsec protocol in\r
488 its ImageHandle.\r
489\r
490 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
491 @param[in] SystemTable A pointer to the EFI System Table.\r
492\r
493 @retval EFI_SUCCESS The operation completed successfully.\r
494 @retval EFI_ALREADY_STARTED The IPsec driver has been already loaded.\r
495 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
6cf9230f 496 @retval Others The operation is failed.\r
a3bcde70
HT
497\r
498**/\r
499EFI_STATUS\r
500EFIAPI\r
501IpSecDriverEntryPoint (\r
502 IN EFI_HANDLE ImageHandle,\r
503 IN EFI_SYSTEM_TABLE *SystemTable\r
504 )\r
505{\r
506 EFI_STATUS Status;\r
507 IPSEC_PRIVATE_DATA *Private;\r
0a7294f7 508 EFI_IPSEC2_PROTOCOL *IpSec;\r
a3bcde70
HT
509\r
510 //\r
511 // Check whether ipsec protocol has already been installed.\r
512 //\r
0a7294f7 513 Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **) &IpSec);\r
a3bcde70
HT
514\r
515 if (!EFI_ERROR (Status)) {\r
516 DEBUG ((DEBUG_WARN, "_ModuleEntryPoint: IpSec has been already loaded\n"));\r
517 Status = EFI_ALREADY_STARTED;\r
518 goto ON_EXIT;\r
519 }\r
520\r
521 Status = gBS->LocateProtocol (&gEfiDpcProtocolGuid, NULL, (VOID **) &mDpc);\r
522\r
523 if (EFI_ERROR (Status)) {\r
524 DEBUG ((DEBUG_ERROR, "_ModuleEntryPoint: Failed to locate EfiDpcProtocol\n"));\r
525 goto ON_EXIT;\r
526 }\r
527\r
528 Private = AllocateZeroPool (sizeof (IPSEC_PRIVATE_DATA));\r
529\r
530 if (Private == NULL) {\r
531 DEBUG ((DEBUG_ERROR, "_ModuleEntryPoint: Failed to allocate private data\n"));\r
532 Status = EFI_OUT_OF_RESOURCES;\r
533 goto ON_EXIT;\r
534 }\r
535 //\r
9166f840 536 // Create disable event to cleanup all SA when ipsec disabled by user.\r
a3bcde70
HT
537 //\r
538 Status = gBS->CreateEvent (\r
539 EVT_NOTIFY_SIGNAL,\r
540 TPL_CALLBACK,\r
541 IpSecCleanupAllSa,\r
542 Private,\r
543 &mIpSecInstance.DisabledEvent\r
544 );\r
545 if (EFI_ERROR (Status)) {\r
546 DEBUG ((DEBUG_ERROR, "_ModuleEntryPoint: Failed to create disable event\n"));\r
547 goto ON_FREE_PRIVATE;\r
548 }\r
549\r
550 Private->Signature = IPSEC_PRIVATE_DATA_SIGNATURE;\r
551 Private->ImageHandle = ImageHandle;\r
0a7294f7 552 CopyMem (&Private->IpSec, &mIpSecInstance, sizeof (EFI_IPSEC2_PROTOCOL));\r
6cf9230f 553\r
a3bcde70
HT
554 //\r
555 // Initilize Private's members. Thess members is used for IKE.\r
556 //\r
557 InitializeListHead (&Private->Udp4List);\r
558 InitializeListHead (&Private->Udp6List);\r
559 InitializeListHead (&Private->Ikev1SessionList);\r
560 InitializeListHead (&Private->Ikev1EstablishedList);\r
561 InitializeListHead (&Private->Ikev2SessionList);\r
562 InitializeListHead (&Private->Ikev2EstablishedList);\r
6cf9230f 563\r
9166f840 564 RandomSeed (NULL, 0);\r
a3bcde70
HT
565 //\r
566 // Initialize the ipsec config data and restore it from variable.\r
567 //\r
568 Status = IpSecConfigInitialize (Private);\r
569 if (EFI_ERROR (Status)) {\r
570 DEBUG ((DEBUG_ERROR, "_ModuleEntryPoint: Failed to initialize IpSecConfig\n"));\r
571 goto ON_CLOSE_EVENT;\r
572 }\r
573 //\r
574 // Install ipsec protocol which is used by ip driver to process ipsec header.\r
575 //\r
576 Status = gBS->InstallMultipleProtocolInterfaces (\r
577 &Private->Handle,\r
0a7294f7 578 &gEfiIpSec2ProtocolGuid,\r
a3bcde70
HT
579 &Private->IpSec,\r
580 NULL\r
581 );\r
582 if (EFI_ERROR (Status)) {\r
583 goto ON_UNINSTALL_CONFIG;\r
584 }\r
585\r
586 Status = EfiLibInstallDriverBindingComponentName2 (\r
587 ImageHandle,\r
588 SystemTable,\r
6879581d 589 &gIpSec4DriverBinding,\r
a3bcde70
HT
590 ImageHandle,\r
591 &gIpSecComponentName,\r
592 &gIpSecComponentName2\r
593 );\r
594 if (EFI_ERROR (Status)) {\r
9166f840 595 goto ON_UNINSTALL_IPSEC;\r
a3bcde70 596 }\r
6cf9230f 597\r
6879581d 598 Status = EfiLibInstallDriverBindingComponentName2 (\r
599 ImageHandle,\r
600 SystemTable,\r
601 &gIpSec6DriverBinding,\r
602 NULL,\r
603 &gIpSecComponentName,\r
604 &gIpSecComponentName2\r
605 );\r
606 if (EFI_ERROR (Status)) {\r
607 goto ON_UNINSTALL_IPSEC4_DB;\r
608 }\r
609\r
a3bcde70
HT
610 return Status;\r
611\r
6879581d 612ON_UNINSTALL_IPSEC4_DB:\r
613 gBS->UninstallMultipleProtocolInterfaces (\r
614 ImageHandle,\r
615 &gEfiDriverBindingProtocolGuid,\r
616 &gIpSec4DriverBinding,\r
617 &gEfiComponentName2ProtocolGuid,\r
618 &gIpSecComponentName2,\r
619 &gEfiComponentNameProtocolGuid,\r
620 &gIpSecComponentName,\r
621 NULL\r
622 );\r
623\r
9166f840 624ON_UNINSTALL_IPSEC:\r
625 gBS->UninstallProtocolInterface (\r
626 Private->Handle,\r
0a7294f7 627 &gEfiIpSec2ProtocolGuid,\r
9166f840 628 &Private->IpSec\r
629 );\r
a3bcde70
HT
630ON_UNINSTALL_CONFIG:\r
631 gBS->UninstallProtocolInterface (\r
632 Private->Handle,\r
633 &gEfiIpSecConfigProtocolGuid,\r
634 &Private->IpSecConfig\r
635 );\r
636ON_CLOSE_EVENT:\r
637 gBS->CloseEvent (mIpSecInstance.DisabledEvent);\r
638 mIpSecInstance.DisabledEvent = NULL;\r
639ON_FREE_PRIVATE:\r
640 FreePool (Private);\r
641ON_EXIT:\r
642 return Status;\r
643}\r
644\r