]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpDxe/HttpDriver.c
NetworkPkg: Protocol Uninstallation Cleanup
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpDriver.c
1 /** @file
2 The driver binding and service binding protocol for HttpDxe driver.
3
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "HttpDriver.h"
18
19 EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;
20
21 ///
22 /// Driver Binding Protocol instance
23 ///
24 EFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp4DriverBinding = {
25 HttpDxeIp4DriverBindingSupported,
26 HttpDxeIp4DriverBindingStart,
27 HttpDxeIp4DriverBindingStop,
28 HTTP_DRIVER_VERSION,
29 NULL,
30 NULL
31 };
32
33 EFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp6DriverBinding = {
34 HttpDxeIp6DriverBindingSupported,
35 HttpDxeIp6DriverBindingStart,
36 HttpDxeIp6DriverBindingStop,
37 HTTP_DRIVER_VERSION,
38 NULL,
39 NULL
40 };
41
42
43 /**
44 Create a HTTP driver service binding private instance.
45
46 @param[in] Controller The controller that has TCP4 service binding
47 installed.
48 @param[out] ServiceData Point to HTTP driver private instance.
49
50 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
51 @retval EFI_SUCCESS A new HTTP driver private instance is created.
52
53 **/
54 EFI_STATUS
55 HttpCreateService (
56 IN EFI_HANDLE Controller,
57 OUT HTTP_SERVICE **ServiceData
58 )
59 {
60 HTTP_SERVICE *HttpService;
61
62 ASSERT (ServiceData != NULL);
63 *ServiceData = NULL;
64
65 HttpService = AllocateZeroPool (sizeof (HTTP_SERVICE));
66 if (HttpService == NULL) {
67 return EFI_OUT_OF_RESOURCES;
68 }
69
70 HttpService->Signature = HTTP_SERVICE_SIGNATURE;
71 HttpService->ServiceBinding.CreateChild = HttpServiceBindingCreateChild;
72 HttpService->ServiceBinding.DestroyChild = HttpServiceBindingDestroyChild;
73 HttpService->ControllerHandle = Controller;
74 HttpService->ChildrenNumber = 0;
75 InitializeListHead (&HttpService->ChildrenList);
76
77 *ServiceData = HttpService;
78 return EFI_SUCCESS;
79 }
80
81 /**
82 Release all the resource used the HTTP service binding instance.
83
84 @param[in] HttpService The HTTP private instance.
85 @param[in] UsingIpv6 Indicate use TCP4 protocol or TCP6 protocol.
86 if TRUE, use Tcp6 protocol.
87 if FALSE, use Tcp4 protocl.
88 **/
89 VOID
90 HttpCleanService (
91 IN HTTP_SERVICE *HttpService,
92 IN BOOLEAN UsingIpv6
93 )
94 {
95
96 if (HttpService == NULL) {
97 return ;
98 }
99 if (!UsingIpv6) {
100 if (HttpService->Tcp4ChildHandle != NULL) {
101 gBS->CloseProtocol (
102 HttpService->Tcp4ChildHandle,
103 &gEfiTcp4ProtocolGuid,
104 HttpService->Ip4DriverBindingHandle,
105 HttpService->ControllerHandle
106 );
107
108 NetLibDestroyServiceChild (
109 HttpService->ControllerHandle,
110 HttpService->Ip4DriverBindingHandle,
111 &gEfiTcp4ServiceBindingProtocolGuid,
112 HttpService->Tcp4ChildHandle
113 );
114
115 HttpService->Tcp4ChildHandle = NULL;
116 }
117 } else {
118 if (HttpService->Tcp6ChildHandle != NULL) {
119 gBS->CloseProtocol (
120 HttpService->Tcp6ChildHandle,
121 &gEfiTcp6ProtocolGuid,
122 HttpService->Ip6DriverBindingHandle,
123 HttpService->ControllerHandle
124 );
125
126 NetLibDestroyServiceChild (
127 HttpService->ControllerHandle,
128 HttpService->Ip6DriverBindingHandle,
129 &gEfiTcp6ServiceBindingProtocolGuid,
130 HttpService->Tcp6ChildHandle
131 );
132
133 HttpService->Tcp6ChildHandle = NULL;
134 }
135 }
136
137 }
138
139 /**
140 The event process routine when the http utilities protocol is installed
141 in the system.
142
143 @param[in] Event Not used.
144 @param[in] Context The pointer to the IP4 config2 instance data or IP6 Config instance data.
145
146 **/
147 VOID
148 EFIAPI
149 HttpUtilitiesInstalledCallback (
150 IN EFI_EVENT Event,
151 IN VOID *Context
152 )
153 {
154 gBS->LocateProtocol (
155 &gEfiHttpUtilitiesProtocolGuid,
156 NULL,
157 (VOID **) &mHttpUtilities
158 );
159
160 //
161 // Close the event if Http utilities protocol is loacted.
162 //
163 if (mHttpUtilities != NULL && Event != NULL) {
164 gBS->CloseEvent (Event);
165 }
166 }
167
168 /**
169 This is the declaration of an EFI image entry point. This entry point is
170 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
171 both device drivers and bus drivers.
172
173 @param ImageHandle The firmware allocated handle for the UEFI image.
174 @param SystemTable A pointer to the EFI System Table.
175
176 @retval EFI_SUCCESS The operation completed successfully.
177 @retval Others An unexpected error occurred.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 HttpDxeDriverEntryPoint (
183 IN EFI_HANDLE ImageHandle,
184 IN EFI_SYSTEM_TABLE *SystemTable
185 )
186 {
187 EFI_STATUS Status;
188 VOID *Registration;
189
190 gBS->LocateProtocol (
191 &gEfiHttpUtilitiesProtocolGuid,
192 NULL,
193 (VOID **) &mHttpUtilities
194 );
195
196 if (mHttpUtilities == NULL) {
197 //
198 // No Http utilities protocol, register a notify.
199 //
200 EfiCreateProtocolNotifyEvent (
201 &gEfiHttpUtilitiesProtocolGuid,
202 TPL_CALLBACK,
203 HttpUtilitiesInstalledCallback,
204 NULL,
205 &Registration
206 );
207 }
208
209 //
210 // Install UEFI Driver Model protocol(s).
211 //
212 Status = EfiLibInstallDriverBindingComponentName2 (
213 ImageHandle,
214 SystemTable,
215 &gHttpDxeIp4DriverBinding,
216 ImageHandle,
217 &gHttpDxeComponentName,
218 &gHttpDxeComponentName2
219 );
220 if (EFI_ERROR (Status)) {
221 return Status;
222 }
223
224 Status = EfiLibInstallDriverBindingComponentName2 (
225 ImageHandle,
226 SystemTable,
227 &gHttpDxeIp6DriverBinding,
228 NULL,
229 &gHttpDxeComponentName,
230 &gHttpDxeComponentName2
231 );
232 if (EFI_ERROR (Status)) {
233 EfiLibUninstallDriverBindingComponentName2 (
234 &gHttpDxeIp4DriverBinding,
235 &gHttpDxeComponentName,
236 &gHttpDxeComponentName2
237 );
238 }
239 return Status;
240 }
241
242 /**
243 Callback function which provided by user to remove one node in NetDestroyLinkList process.
244
245 @param[in] Entry The entry to be removed.
246 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
247
248 @retval EFI_INVALID_PARAMETER Any input parameter is NULL.
249 @retval EFI_SUCCESS The entry has been removed successfully.
250 @retval Others Fail to remove the entry.
251
252 **/
253 EFI_STATUS
254 EFIAPI
255 HttpDestroyChildEntryInHandleBuffer (
256 IN LIST_ENTRY *Entry,
257 IN VOID *Context
258 )
259 {
260 HTTP_PROTOCOL *HttpInstance;
261 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
262 UINTN NumberOfChildren;
263 EFI_HANDLE *ChildHandleBuffer;
264
265 if (Entry == NULL || Context == NULL) {
266 return EFI_INVALID_PARAMETER;
267 }
268
269 HttpInstance = NET_LIST_USER_STRUCT_S (Entry, HTTP_PROTOCOL, Link, HTTP_PROTOCOL_SIGNATURE);
270 ServiceBinding = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
271 NumberOfChildren = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
272 ChildHandleBuffer = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
273
274 if (!NetIsInHandleBuffer (HttpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) {
275 return EFI_SUCCESS;
276 }
277
278 return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);
279 }
280
281 /**
282 Test to see if this driver supports ControllerHandle. This is the worker function for
283 HttpDxeIp4(6)DriverBindingSupported.
284
285 @param[in] This The pointer to the driver binding protocol.
286 @param[in] ControllerHandle The handle of device to be tested.
287 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
288 device to be started.
289 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
290
291 @retval EFI_SUCCESS This driver supports this device.
292 @retval EFI_UNSUPPORTED This driver does not support this device.
293
294 **/
295 EFI_STATUS
296 EFIAPI
297 HttpDxeSupported (
298 IN EFI_DRIVER_BINDING_PROTOCOL *This,
299 IN EFI_HANDLE ControllerHandle,
300 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
301 IN UINT8 IpVersion
302 )
303 {
304 EFI_STATUS Status;
305 EFI_GUID *TcpServiceBindingProtocolGuid;
306
307 if (IpVersion == IP_VERSION_4) {
308 TcpServiceBindingProtocolGuid = &gEfiTcp4ServiceBindingProtocolGuid;
309 } else {
310 TcpServiceBindingProtocolGuid = &gEfiTcp6ServiceBindingProtocolGuid;
311 }
312
313 Status = gBS->OpenProtocol (
314 ControllerHandle,
315 TcpServiceBindingProtocolGuid,
316 NULL,
317 This->DriverBindingHandle,
318 ControllerHandle,
319 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
320 );
321
322 if (EFI_ERROR (Status)) {
323 return EFI_UNSUPPORTED;
324 }
325
326 return EFI_SUCCESS;
327 }
328
329 /**
330 Start this driver on ControllerHandle. This is the worker function for
331 HttpDxeIp4(6)DriverBindingStart.
332
333 @param[in] This The pointer to the driver binding protocol.
334 @param[in] ControllerHandle The handle of device to be started.
335 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
336 device to be started.
337 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
338
339
340 @retval EFI_SUCCESS This driver is installed to ControllerHandle.
341 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
342 @retval other This driver does not support this device.
343
344 **/
345 EFI_STATUS
346 EFIAPI
347 HttpDxeStart (
348 IN EFI_DRIVER_BINDING_PROTOCOL *This,
349 IN EFI_HANDLE ControllerHandle,
350 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
351 IN UINT8 IpVersion
352 )
353 {
354 EFI_STATUS Status;
355 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
356 HTTP_SERVICE *HttpService;
357 VOID *Interface;
358 BOOLEAN UsingIpv6;
359
360 UsingIpv6 = FALSE;
361
362 //
363 // Test for the Http service binding protocol
364 //
365 Status = gBS->OpenProtocol (
366 ControllerHandle,
367 &gEfiHttpServiceBindingProtocolGuid,
368 (VOID **) &ServiceBinding,
369 This->DriverBindingHandle,
370 ControllerHandle,
371 EFI_OPEN_PROTOCOL_GET_PROTOCOL
372 );
373
374 if (!EFI_ERROR (Status)) {
375 HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
376 } else {
377 Status = HttpCreateService (ControllerHandle, &HttpService);
378 if (EFI_ERROR (Status)) {
379 return Status;
380 }
381
382 ASSERT (HttpService != NULL);
383
384 //
385 // Install the HttpServiceBinding Protocol onto Controller
386 //
387 Status = gBS->InstallMultipleProtocolInterfaces (
388 &ControllerHandle,
389 &gEfiHttpServiceBindingProtocolGuid,
390 &HttpService->ServiceBinding,
391 NULL
392 );
393
394 if (EFI_ERROR (Status)) {
395 goto ON_ERROR;
396 }
397 }
398
399 if (IpVersion == IP_VERSION_4) {
400 HttpService->Ip4DriverBindingHandle = This->DriverBindingHandle;
401
402 if (HttpService->Tcp4ChildHandle == NULL) {
403 //
404 // Create a TCP4 child instance, but do not configure it. This will establish the parent-child relationship.
405 //
406 Status = NetLibCreateServiceChild (
407 ControllerHandle,
408 This->DriverBindingHandle,
409 &gEfiTcp4ServiceBindingProtocolGuid,
410 &HttpService->Tcp4ChildHandle
411 );
412
413 if (EFI_ERROR (Status)) {
414 goto ON_ERROR;
415 }
416
417 Status = gBS->OpenProtocol (
418 HttpService->Tcp4ChildHandle,
419 &gEfiTcp4ProtocolGuid,
420 &Interface,
421 This->DriverBindingHandle,
422 ControllerHandle,
423 EFI_OPEN_PROTOCOL_BY_DRIVER
424 );
425
426 if (EFI_ERROR (Status)) {
427 goto ON_ERROR;
428 }
429
430 } else {
431 return EFI_ALREADY_STARTED;
432 }
433
434 } else {
435 UsingIpv6 = TRUE;
436 HttpService->Ip6DriverBindingHandle = This->DriverBindingHandle;
437
438 if (HttpService->Tcp6ChildHandle == NULL) {
439 //
440 // Create a TCP6 child instance, but do not configure it. This will establish the parent-child relationship.
441 //
442 Status = NetLibCreateServiceChild (
443 ControllerHandle,
444 This->DriverBindingHandle,
445 &gEfiTcp6ServiceBindingProtocolGuid,
446 &HttpService->Tcp6ChildHandle
447 );
448
449 if (EFI_ERROR (Status)) {
450 goto ON_ERROR;
451 }
452
453 Status = gBS->OpenProtocol (
454 HttpService->Tcp6ChildHandle,
455 &gEfiTcp6ProtocolGuid,
456 &Interface,
457 This->DriverBindingHandle,
458 ControllerHandle,
459 EFI_OPEN_PROTOCOL_BY_DRIVER
460 );
461
462 if (EFI_ERROR (Status)) {
463 goto ON_ERROR;
464 }
465
466 } else {
467 return EFI_ALREADY_STARTED;
468 }
469
470 }
471
472 return EFI_SUCCESS;
473
474 ON_ERROR:
475
476 if (HttpService != NULL) {
477 HttpCleanService (HttpService, UsingIpv6);
478 if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {
479 FreePool (HttpService);
480 }
481 }
482
483 return Status;
484
485
486 }
487
488 /**
489 Stop this driver on ControllerHandle. This is the worker function for
490 HttpDxeIp4(6)DriverBindingStop.
491
492 @param[in] This Protocol instance pointer.
493 @param[in] ControllerHandle Handle of device to stop driver on.
494 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
495 children is zero stop the entire bus driver.
496 @param[in] ChildHandleBuffer List of Child Handles to Stop.
497 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
498
499 @retval EFI_SUCCESS This driver was removed ControllerHandle.
500 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
501 @retval Others This driver was not removed from this device
502
503 **/
504 EFI_STATUS
505 EFIAPI
506 HttpDxeStop (
507 IN EFI_DRIVER_BINDING_PROTOCOL *This,
508 IN EFI_HANDLE ControllerHandle,
509 IN UINTN NumberOfChildren,
510 IN EFI_HANDLE *ChildHandleBuffer,
511 IN UINT8 IpVersion
512 )
513 {
514 EFI_HANDLE NicHandle;
515 EFI_STATUS Status;
516 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
517 HTTP_SERVICE *HttpService;
518 LIST_ENTRY *List;
519 HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
520 BOOLEAN UsingIpv6;
521
522 //
523 // HTTP driver opens TCP4(6) child, So, Controller is a TCP4(6)
524 // child handle. Locate the Nic handle first. Then get the
525 // HTTP private data back.
526 //
527 if (IpVersion == IP_VERSION_4) {
528 UsingIpv6 = FALSE;
529 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
530 } else {
531 UsingIpv6 = TRUE;
532 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);
533 }
534
535 if (NicHandle == NULL) {
536 return EFI_SUCCESS;
537 }
538
539 Status = gBS->OpenProtocol (
540 NicHandle,
541 &gEfiHttpServiceBindingProtocolGuid,
542 (VOID **) &ServiceBinding,
543 This->DriverBindingHandle,
544 NicHandle,
545 EFI_OPEN_PROTOCOL_GET_PROTOCOL
546 );
547
548 if (!EFI_ERROR (Status)) {
549
550 HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
551
552 if (NumberOfChildren != 0) {
553 //
554 // Destroy the HTTP child instance in ChildHandleBuffer.
555 //
556 List = &HttpService->ChildrenList;
557 Context.ServiceBinding = ServiceBinding;
558 Context.NumberOfChildren = NumberOfChildren;
559 Context.ChildHandleBuffer = ChildHandleBuffer;
560 Status = NetDestroyLinkList (
561 List,
562 HttpDestroyChildEntryInHandleBuffer,
563 &Context,
564 NULL
565 );
566 } else {
567
568 HttpCleanService (HttpService, UsingIpv6);
569
570 if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {
571 gBS->UninstallProtocolInterface (
572 NicHandle,
573 &gEfiHttpServiceBindingProtocolGuid,
574 ServiceBinding
575 );
576 FreePool (HttpService);
577 }
578 Status = EFI_SUCCESS;
579 }
580 }
581
582 return Status;
583
584 }
585
586 /**
587 Tests to see if this driver supports a given controller. If a child device is provided,
588 it further tests to see if this driver supports creating a handle for the specified child device.
589
590 This function checks to see if the driver specified by This supports the device specified by
591 ControllerHandle. Drivers will typically use the device path attached to
592 ControllerHandle and/or the services from the bus I/O abstraction attached to
593 ControllerHandle to determine if the driver supports ControllerHandle. This function
594 may be called many times during platform initialization. In order to reduce boot times, the tests
595 performed by this function must be very small, and take as little time as possible to execute. This
596 function must not change the state of any hardware devices, and this function must be aware that the
597 device specified by ControllerHandle may already be managed by the same driver or a
598 different driver. This function must match its calls to AllocatePages() with FreePages(),
599 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
600 Because ControllerHandle may have been previously started by the same driver, if a protocol is
601 already in the opened state, then it must not be closed with CloseProtocol(). This is required
602 to guarantee the state of ControllerHandle is not modified by this function.
603
604 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
605 @param[in] ControllerHandle The handle of the controller to test. This handle
606 must support a protocol interface that supplies
607 an I/O abstraction to the driver.
608 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
609 parameter is ignored by device drivers, and is optional for bus
610 drivers. For bus drivers, if this parameter is not NULL, then
611 the bus driver must determine if the bus controller specified
612 by ControllerHandle and the child controller specified
613 by RemainingDevicePath are both supported by this
614 bus driver.
615
616 @retval EFI_SUCCESS The device specified by ControllerHandle and
617 RemainingDevicePath is supported by the driver specified by This.
618 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
619 RemainingDevicePath is already being managed by the driver
620 specified by This.
621 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
622 RemainingDevicePath is already being managed by a different
623 driver or an application that requires exclusive access.
624 Currently not implemented.
625 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
626 RemainingDevicePath is not supported by the driver specified by This.
627 **/
628 EFI_STATUS
629 EFIAPI
630 HttpDxeIp4DriverBindingSupported (
631 IN EFI_DRIVER_BINDING_PROTOCOL *This,
632 IN EFI_HANDLE ControllerHandle,
633 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
634 )
635 {
636 return HttpDxeSupported (
637 This,
638 ControllerHandle,
639 RemainingDevicePath,
640 IP_VERSION_4
641 );
642 }
643
644 /**
645 Starts a device controller or a bus controller.
646
647 The Start() function is designed to be invoked from the EFI boot service ConnectController().
648 As a result, much of the error checking on the parameters to Start() has been moved into this
649 common boot service. It is legal to call Start() from other locations,
650 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
651 1. ControllerHandle must be a valid EFI_HANDLE.
652 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
653 EFI_DEVICE_PATH_PROTOCOL.
654 3. Prior to calling Start(), the Supported() function for the driver specified by This must
655 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
656
657 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
658 @param[in] ControllerHandle The handle of the controller to start. This handle
659 must support a protocol interface that supplies
660 an I/O abstraction to the driver.
661 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
662 parameter is ignored by device drivers, and is optional for bus
663 drivers. For a bus driver, if this parameter is NULL, then handles
664 for all the children of Controller are created by this driver.
665 If this parameter is not NULL and the first Device Path Node is
666 not the End of Device Path Node, then only the handle for the
667 child device specified by the first Device Path Node of
668 RemainingDevicePath is created by this driver.
669 If the first Device Path Node of RemainingDevicePath is
670 the End of Device Path Node, no child handle is created by this
671 driver.
672
673 @retval EFI_SUCCESS The device was started.
674 @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.
675 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
676 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
677 @retval Others The driver failded to start the device.
678
679 **/
680 EFI_STATUS
681 EFIAPI
682 HttpDxeIp4DriverBindingStart (
683 IN EFI_DRIVER_BINDING_PROTOCOL *This,
684 IN EFI_HANDLE ControllerHandle,
685 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
686 )
687 {
688 return HttpDxeStart (
689 This,
690 ControllerHandle,
691 RemainingDevicePath,
692 IP_VERSION_4
693 );
694 }
695
696 /**
697 Stops a device controller or a bus controller.
698
699 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
700 As a result, much of the error checking on the parameters to Stop() has been moved
701 into this common boot service. It is legal to call Stop() from other locations,
702 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
703 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
704 same driver's Start() function.
705 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
706 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
707 Start() function, and the Start() function must have called OpenProtocol() on
708 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
709
710 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
711 @param[in] ControllerHandle A handle to the device being stopped. The handle must
712 support a bus specific I/O protocol for the driver
713 to use to stop the device.
714 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
715 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
716 if NumberOfChildren is 0.
717
718 @retval EFI_SUCCESS The device was stopped.
719 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
720
721 **/
722 EFI_STATUS
723 EFIAPI
724 HttpDxeIp4DriverBindingStop (
725 IN EFI_DRIVER_BINDING_PROTOCOL *This,
726 IN EFI_HANDLE ControllerHandle,
727 IN UINTN NumberOfChildren,
728 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
729 )
730 {
731 return HttpDxeStop (
732 This,
733 ControllerHandle,
734 NumberOfChildren,
735 ChildHandleBuffer,
736 IP_VERSION_4
737 );
738 }
739
740 /**
741 Tests to see if this driver supports a given controller. If a child device is provided,
742 it further tests to see if this driver supports creating a handle for the specified child device.
743
744 This function checks to see if the driver specified by This supports the device specified by
745 ControllerHandle. Drivers will typically use the device path attached to
746 ControllerHandle and/or the services from the bus I/O abstraction attached to
747 ControllerHandle to determine if the driver supports ControllerHandle. This function
748 may be called many times during platform initialization. In order to reduce boot times, the tests
749 performed by this function must be very small, and take as little time as possible to execute. This
750 function must not change the state of any hardware devices, and this function must be aware that the
751 device specified by ControllerHandle may already be managed by the same driver or a
752 different driver. This function must match its calls to AllocatePages() with FreePages(),
753 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
754 Because ControllerHandle may have been previously started by the same driver, if a protocol is
755 already in the opened state, then it must not be closed with CloseProtocol(). This is required
756 to guarantee the state of ControllerHandle is not modified by this function.
757
758 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
759 @param[in] ControllerHandle The handle of the controller to test. This handle
760 must support a protocol interface that supplies
761 an I/O abstraction to the driver.
762 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
763 parameter is ignored by device drivers, and is optional for bus
764 drivers. For bus drivers, if this parameter is not NULL, then
765 the bus driver must determine if the bus controller specified
766 by ControllerHandle and the child controller specified
767 by RemainingDevicePath are both supported by this
768 bus driver.
769
770 @retval EFI_SUCCESS The device specified by ControllerHandle and
771 RemainingDevicePath is supported by the driver specified by This.
772 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
773 RemainingDevicePath is already being managed by the driver
774 specified by This.
775 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
776 RemainingDevicePath is already being managed by a different
777 driver or an application that requires exclusive access.
778 Currently not implemented.
779 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
780 RemainingDevicePath is not supported by the driver specified by This.
781 **/
782 EFI_STATUS
783 EFIAPI
784 HttpDxeIp6DriverBindingSupported (
785 IN EFI_DRIVER_BINDING_PROTOCOL *This,
786 IN EFI_HANDLE ControllerHandle,
787 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
788 )
789 {
790 return HttpDxeSupported (
791 This,
792 ControllerHandle,
793 RemainingDevicePath,
794 IP_VERSION_6
795 );
796
797 }
798
799 /**
800 Starts a device controller or a bus controller.
801
802 The Start() function is designed to be invoked from the EFI boot service ConnectController().
803 As a result, much of the error checking on the parameters to Start() has been moved into this
804 common boot service. It is legal to call Start() from other locations,
805 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
806 1. ControllerHandle must be a valid EFI_HANDLE.
807 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
808 EFI_DEVICE_PATH_PROTOCOL.
809 3. Prior to calling Start(), the Supported() function for the driver specified by This must
810 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
811
812 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
813 @param[in] ControllerHandle The handle of the controller to start. This handle
814 must support a protocol interface that supplies
815 an I/O abstraction to the driver.
816 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
817 parameter is ignored by device drivers, and is optional for bus
818 drivers. For a bus driver, if this parameter is NULL, then handles
819 for all the children of Controller are created by this driver.
820 If this parameter is not NULL and the first Device Path Node is
821 not the End of Device Path Node, then only the handle for the
822 child device specified by the first Device Path Node of
823 RemainingDevicePath is created by this driver.
824 If the first Device Path Node of RemainingDevicePath is
825 the End of Device Path Node, no child handle is created by this
826 driver.
827
828 @retval EFI_SUCCESS The device was started.
829 @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.
830 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
831 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
832 @retval Others The driver failded to start the device.
833
834 **/
835 EFI_STATUS
836 EFIAPI
837 HttpDxeIp6DriverBindingStart (
838 IN EFI_DRIVER_BINDING_PROTOCOL *This,
839 IN EFI_HANDLE ControllerHandle,
840 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
841 )
842 {
843 return HttpDxeStart (
844 This,
845 ControllerHandle,
846 RemainingDevicePath,
847 IP_VERSION_6
848 );
849 }
850
851 /**
852 Stops a device controller or a bus controller.
853
854 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
855 As a result, much of the error checking on the parameters to Stop() has been moved
856 into this common boot service. It is legal to call Stop() from other locations,
857 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
858 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
859 same driver's Start() function.
860 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
861 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
862 Start() function, and the Start() function must have called OpenProtocol() on
863 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
864
865 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
866 @param[in] ControllerHandle A handle to the device being stopped. The handle must
867 support a bus specific I/O protocol for the driver
868 to use to stop the device.
869 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
870 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
871 if NumberOfChildren is 0.
872
873 @retval EFI_SUCCESS The device was stopped.
874 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
875
876 **/
877 EFI_STATUS
878 EFIAPI
879 HttpDxeIp6DriverBindingStop (
880 IN EFI_DRIVER_BINDING_PROTOCOL *This,
881 IN EFI_HANDLE ControllerHandle,
882 IN UINTN NumberOfChildren,
883 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
884 )
885 {
886 return HttpDxeStop (
887 This,
888 ControllerHandle,
889 NumberOfChildren,
890 ChildHandleBuffer,
891 IP_VERSION_6
892 );
893 }
894 /**
895 Creates a child handle and installs a protocol.
896
897 The CreateChild() function installs a protocol on ChildHandle.
898 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
899 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
900
901 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
902 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
903 then a new handle is created. If it is a pointer to an existing UEFI handle,
904 then the protocol is added to the existing UEFI handle.
905
906 @retval EFI_SUCCES The protocol was added to ChildHandle.
907 @retval EFI_INVALID_PARAMETER This is NULL, or ChildHandle is NULL.
908 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
909 the child.
910 @retval other The child handle was not created.
911
912 **/
913 EFI_STATUS
914 EFIAPI
915 HttpServiceBindingCreateChild (
916 IN EFI_SERVICE_BINDING_PROTOCOL *This,
917 IN OUT EFI_HANDLE *ChildHandle
918 )
919 {
920 HTTP_SERVICE *HttpService;
921 HTTP_PROTOCOL *HttpInstance;
922 EFI_STATUS Status;
923 EFI_TPL OldTpl;
924
925 if ((This == NULL) || (ChildHandle == NULL)) {
926 return EFI_INVALID_PARAMETER;
927 }
928
929 HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
930 HttpInstance = AllocateZeroPool (sizeof (HTTP_PROTOCOL));
931 if (HttpInstance == NULL) {
932 return EFI_OUT_OF_RESOURCES;
933 }
934
935 HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;
936 HttpInstance->Service = HttpService;
937 HttpInstance->Method = HttpMethodMax;
938
939 CopyMem (&HttpInstance->Http, &mEfiHttpTemplate, sizeof (HttpInstance->Http));
940 NetMapInit (&HttpInstance->TxTokens);
941 NetMapInit (&HttpInstance->RxTokens);
942
943 //
944 // Install HTTP protocol onto ChildHandle
945 //
946 Status = gBS->InstallMultipleProtocolInterfaces (
947 ChildHandle,
948 &gEfiHttpProtocolGuid,
949 &HttpInstance->Http,
950 NULL
951 );
952
953 if (EFI_ERROR (Status)) {
954 goto ON_ERROR;
955 }
956
957 HttpInstance->Handle = *ChildHandle;
958
959 //
960 // Add it to the HTTP service's child list.
961 //
962 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
963
964 InsertTailList (&HttpService->ChildrenList, &HttpInstance->Link);
965 HttpService->ChildrenNumber++;
966
967 gBS->RestoreTPL (OldTpl);
968
969 return EFI_SUCCESS;
970
971 ON_ERROR:
972
973 NetMapClean (&HttpInstance->TxTokens);
974 NetMapClean (&HttpInstance->RxTokens);
975 FreePool (HttpInstance);
976
977 return Status;
978 }
979
980 /**
981 Destroys a child handle with a protocol installed on it.
982
983 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
984 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
985 last protocol on ChildHandle, then ChildHandle is destroyed.
986
987 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
988 @param ChildHandle Handle of the child to destroy
989
990 @retval EFI_SUCCES The protocol was removed from ChildHandle.
991 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
992 @retval EFI_INVALID_PARAMETER Child handle is NULL.
993 @retval other The child handle was not destroyed
994
995 **/
996 EFI_STATUS
997 EFIAPI
998 HttpServiceBindingDestroyChild (
999 IN EFI_SERVICE_BINDING_PROTOCOL *This,
1000 IN EFI_HANDLE ChildHandle
1001 )
1002 {
1003 HTTP_SERVICE *HttpService;
1004 HTTP_PROTOCOL *HttpInstance;
1005 EFI_HTTP_PROTOCOL *Http;
1006 EFI_STATUS Status;
1007 EFI_TPL OldTpl;
1008
1009 if ((This == NULL) || (ChildHandle == NULL)) {
1010 return EFI_INVALID_PARAMETER;
1011 }
1012
1013 HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
1014 Status = gBS->OpenProtocol (
1015 ChildHandle,
1016 &gEfiHttpProtocolGuid,
1017 (VOID **) &Http,
1018 NULL,
1019 NULL,
1020 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1021 );
1022 if (EFI_ERROR (Status)) {
1023 return EFI_UNSUPPORTED;
1024 }
1025
1026 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (Http);
1027 if (HttpInstance->Service != HttpService) {
1028 return EFI_INVALID_PARAMETER;
1029 }
1030
1031 if (HttpInstance->InDestroy) {
1032 return EFI_SUCCESS;
1033 }
1034
1035 HttpInstance->InDestroy = TRUE;
1036
1037 //
1038 // Uninstall the HTTP protocol.
1039 //
1040 Status = gBS->UninstallProtocolInterface (
1041 ChildHandle,
1042 &gEfiHttpProtocolGuid,
1043 Http
1044 );
1045
1046 if (EFI_ERROR (Status)) {
1047 HttpInstance->InDestroy = FALSE;
1048 return Status;
1049 }
1050
1051 HttpCleanProtocol (HttpInstance);
1052
1053 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1054
1055 RemoveEntryList (&HttpInstance->Link);
1056 HttpService->ChildrenNumber--;
1057
1058 gBS->RestoreTPL (OldTpl);
1059
1060 FreePool (HttpInstance);
1061 return EFI_SUCCESS;
1062 }