]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpDxe/HttpDriver.c
NetworkPkg: Clean up source files
[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 gBS->UninstallMultipleProtocolInterfaces (
234 ImageHandle,
235 &gEfiDriverBindingProtocolGuid,
236 &gHttpDxeIp4DriverBinding,
237 &gEfiComponentName2ProtocolGuid,
238 &gHttpDxeComponentName2,
239 &gEfiComponentNameProtocolGuid,
240 &gHttpDxeComponentName,
241 NULL
242 );
243 }
244 return Status;
245 }
246
247 /**
248 Callback function which provided by user to remove one node in NetDestroyLinkList process.
249
250 @param[in] Entry The entry to be removed.
251 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
252
253 @retval EFI_INVALID_PARAMETER Any input parameter is NULL.
254 @retval EFI_SUCCESS The entry has been removed successfully.
255 @retval Others Fail to remove the entry.
256
257 **/
258 EFI_STATUS
259 EFIAPI
260 HttpDestroyChildEntryInHandleBuffer (
261 IN LIST_ENTRY *Entry,
262 IN VOID *Context
263 )
264 {
265 HTTP_PROTOCOL *HttpInstance;
266 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
267 UINTN NumberOfChildren;
268 EFI_HANDLE *ChildHandleBuffer;
269
270 if (Entry == NULL || Context == NULL) {
271 return EFI_INVALID_PARAMETER;
272 }
273
274 HttpInstance = NET_LIST_USER_STRUCT_S (Entry, HTTP_PROTOCOL, Link, HTTP_PROTOCOL_SIGNATURE);
275 ServiceBinding = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
276 NumberOfChildren = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
277 ChildHandleBuffer = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
278
279 if (!NetIsInHandleBuffer (HttpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) {
280 return EFI_SUCCESS;
281 }
282
283 return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);
284 }
285
286 /**
287 Test to see if this driver supports ControllerHandle. This is the worker function for
288 HttpDxeIp4(6)DriverBindingSupported.
289
290 @param[in] This The pointer to the driver binding protocol.
291 @param[in] ControllerHandle The handle of device to be tested.
292 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
293 device to be started.
294 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
295
296 @retval EFI_SUCCESS This driver supports this device.
297 @retval EFI_UNSUPPORTED This driver does not support this device.
298
299 **/
300 EFI_STATUS
301 EFIAPI
302 HttpDxeSupported (
303 IN EFI_DRIVER_BINDING_PROTOCOL *This,
304 IN EFI_HANDLE ControllerHandle,
305 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
306 IN UINT8 IpVersion
307 )
308 {
309 EFI_STATUS Status;
310 EFI_GUID *TcpServiceBindingProtocolGuid;
311
312 if (IpVersion == IP_VERSION_4) {
313 TcpServiceBindingProtocolGuid = &gEfiTcp4ServiceBindingProtocolGuid;
314 } else {
315 TcpServiceBindingProtocolGuid = &gEfiTcp6ServiceBindingProtocolGuid;
316 }
317
318 Status = gBS->OpenProtocol (
319 ControllerHandle,
320 TcpServiceBindingProtocolGuid,
321 NULL,
322 This->DriverBindingHandle,
323 ControllerHandle,
324 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
325 );
326
327 if (EFI_ERROR (Status)) {
328 return EFI_UNSUPPORTED;
329 }
330
331 return EFI_SUCCESS;
332 }
333
334 /**
335 Start this driver on ControllerHandle. This is the worker function for
336 HttpDxeIp4(6)DriverBindingStart.
337
338 @param[in] This The pointer to the driver binding protocol.
339 @param[in] ControllerHandle The handle of device to be started.
340 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
341 device to be started.
342 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
343
344
345 @retval EFI_SUCCESS This driver is installed to ControllerHandle.
346 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
347 @retval other This driver does not support this device.
348
349 **/
350 EFI_STATUS
351 EFIAPI
352 HttpDxeStart (
353 IN EFI_DRIVER_BINDING_PROTOCOL *This,
354 IN EFI_HANDLE ControllerHandle,
355 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
356 IN UINT8 IpVersion
357 )
358 {
359 EFI_STATUS Status;
360 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
361 HTTP_SERVICE *HttpService;
362 VOID *Interface;
363 BOOLEAN UsingIpv6;
364
365 UsingIpv6 = FALSE;
366
367 //
368 // Test for the Http service binding protocol
369 //
370 Status = gBS->OpenProtocol (
371 ControllerHandle,
372 &gEfiHttpServiceBindingProtocolGuid,
373 (VOID **) &ServiceBinding,
374 This->DriverBindingHandle,
375 ControllerHandle,
376 EFI_OPEN_PROTOCOL_GET_PROTOCOL
377 );
378
379 if (!EFI_ERROR (Status)) {
380 HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
381 } else {
382 Status = HttpCreateService (ControllerHandle, &HttpService);
383 if (EFI_ERROR (Status)) {
384 return Status;
385 }
386
387 ASSERT (HttpService != NULL);
388
389 //
390 // Install the HttpServiceBinding Protocol onto Controller
391 //
392 Status = gBS->InstallMultipleProtocolInterfaces (
393 &ControllerHandle,
394 &gEfiHttpServiceBindingProtocolGuid,
395 &HttpService->ServiceBinding,
396 NULL
397 );
398
399 if (EFI_ERROR (Status)) {
400 goto ON_ERROR;
401 }
402 }
403
404 if (IpVersion == IP_VERSION_4) {
405 HttpService->Ip4DriverBindingHandle = This->DriverBindingHandle;
406
407 if (HttpService->Tcp4ChildHandle == NULL) {
408 //
409 // Create a TCP4 child instance, but do not configure it. This will establish the parent-child relationship.
410 //
411 Status = NetLibCreateServiceChild (
412 ControllerHandle,
413 This->DriverBindingHandle,
414 &gEfiTcp4ServiceBindingProtocolGuid,
415 &HttpService->Tcp4ChildHandle
416 );
417
418 if (EFI_ERROR (Status)) {
419 goto ON_ERROR;
420 }
421
422 Status = gBS->OpenProtocol (
423 HttpService->Tcp4ChildHandle,
424 &gEfiTcp4ProtocolGuid,
425 &Interface,
426 This->DriverBindingHandle,
427 ControllerHandle,
428 EFI_OPEN_PROTOCOL_BY_DRIVER
429 );
430
431 if (EFI_ERROR (Status)) {
432 goto ON_ERROR;
433 }
434
435 } else {
436 return EFI_ALREADY_STARTED;
437 }
438
439 } else {
440 UsingIpv6 = TRUE;
441 HttpService->Ip6DriverBindingHandle = This->DriverBindingHandle;
442
443 if (HttpService->Tcp6ChildHandle == NULL) {
444 //
445 // Create a TCP6 child instance, but do not configure it. This will establish the parent-child relationship.
446 //
447 Status = NetLibCreateServiceChild (
448 ControllerHandle,
449 This->DriverBindingHandle,
450 &gEfiTcp6ServiceBindingProtocolGuid,
451 &HttpService->Tcp6ChildHandle
452 );
453
454 if (EFI_ERROR (Status)) {
455 goto ON_ERROR;
456 }
457
458 Status = gBS->OpenProtocol (
459 HttpService->Tcp6ChildHandle,
460 &gEfiTcp6ProtocolGuid,
461 &Interface,
462 This->DriverBindingHandle,
463 ControllerHandle,
464 EFI_OPEN_PROTOCOL_BY_DRIVER
465 );
466
467 if (EFI_ERROR (Status)) {
468 goto ON_ERROR;
469 }
470
471 } else {
472 return EFI_ALREADY_STARTED;
473 }
474
475 }
476
477 return EFI_SUCCESS;
478
479 ON_ERROR:
480
481 if (HttpService != NULL) {
482 HttpCleanService (HttpService, UsingIpv6);
483 if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {
484 FreePool (HttpService);
485 }
486 }
487
488 return Status;
489
490
491 }
492
493 /**
494 Stop this driver on ControllerHandle. This is the worker function for
495 HttpDxeIp4(6)DriverBindingStop.
496
497 @param[in] This Protocol instance pointer.
498 @param[in] ControllerHandle Handle of device to stop driver on.
499 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
500 children is zero stop the entire bus driver.
501 @param[in] ChildHandleBuffer List of Child Handles to Stop.
502 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
503
504 @retval EFI_SUCCESS This driver was removed ControllerHandle.
505 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
506 @retval Others This driver was not removed from this device
507
508 **/
509 EFI_STATUS
510 EFIAPI
511 HttpDxeStop (
512 IN EFI_DRIVER_BINDING_PROTOCOL *This,
513 IN EFI_HANDLE ControllerHandle,
514 IN UINTN NumberOfChildren,
515 IN EFI_HANDLE *ChildHandleBuffer,
516 IN UINT8 IpVersion
517 )
518 {
519 EFI_HANDLE NicHandle;
520 EFI_STATUS Status;
521 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
522 HTTP_SERVICE *HttpService;
523 LIST_ENTRY *List;
524 HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
525 BOOLEAN UsingIpv6;
526
527 //
528 // HTTP driver opens TCP4(6) child, So, Controller is a TCP4(6)
529 // child handle. Locate the Nic handle first. Then get the
530 // HTTP private data back.
531 //
532 if (IpVersion == IP_VERSION_4) {
533 UsingIpv6 = FALSE;
534 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
535 } else {
536 UsingIpv6 = TRUE;
537 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);
538 }
539
540 if (NicHandle == NULL) {
541 return EFI_SUCCESS;
542 }
543
544 Status = gBS->OpenProtocol (
545 NicHandle,
546 &gEfiHttpServiceBindingProtocolGuid,
547 (VOID **) &ServiceBinding,
548 This->DriverBindingHandle,
549 NicHandle,
550 EFI_OPEN_PROTOCOL_GET_PROTOCOL
551 );
552
553 if (!EFI_ERROR (Status)) {
554
555 HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
556
557 if (NumberOfChildren != 0) {
558 //
559 // Destroy the HTTP child instance in ChildHandleBuffer.
560 //
561 List = &HttpService->ChildrenList;
562 Context.ServiceBinding = ServiceBinding;
563 Context.NumberOfChildren = NumberOfChildren;
564 Context.ChildHandleBuffer = ChildHandleBuffer;
565 Status = NetDestroyLinkList (
566 List,
567 HttpDestroyChildEntryInHandleBuffer,
568 &Context,
569 NULL
570 );
571 } else {
572
573 HttpCleanService (HttpService, UsingIpv6);
574
575 if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {
576 gBS->UninstallProtocolInterface (
577 NicHandle,
578 &gEfiHttpServiceBindingProtocolGuid,
579 ServiceBinding
580 );
581 FreePool (HttpService);
582 }
583 Status = EFI_SUCCESS;
584 }
585 }
586
587 return Status;
588
589 }
590
591 /**
592 Tests to see if this driver supports a given controller. If a child device is provided,
593 it further tests to see if this driver supports creating a handle for the specified child device.
594
595 This function checks to see if the driver specified by This supports the device specified by
596 ControllerHandle. Drivers will typically use the device path attached to
597 ControllerHandle and/or the services from the bus I/O abstraction attached to
598 ControllerHandle to determine if the driver supports ControllerHandle. This function
599 may be called many times during platform initialization. In order to reduce boot times, the tests
600 performed by this function must be very small, and take as little time as possible to execute. This
601 function must not change the state of any hardware devices, and this function must be aware that the
602 device specified by ControllerHandle may already be managed by the same driver or a
603 different driver. This function must match its calls to AllocatePages() with FreePages(),
604 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
605 Because ControllerHandle may have been previously started by the same driver, if a protocol is
606 already in the opened state, then it must not be closed with CloseProtocol(). This is required
607 to guarantee the state of ControllerHandle is not modified by this function.
608
609 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
610 @param[in] ControllerHandle The handle of the controller to test. This handle
611 must support a protocol interface that supplies
612 an I/O abstraction to the driver.
613 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
614 parameter is ignored by device drivers, and is optional for bus
615 drivers. For bus drivers, if this parameter is not NULL, then
616 the bus driver must determine if the bus controller specified
617 by ControllerHandle and the child controller specified
618 by RemainingDevicePath are both supported by this
619 bus driver.
620
621 @retval EFI_SUCCESS The device specified by ControllerHandle and
622 RemainingDevicePath is supported by the driver specified by This.
623 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
624 RemainingDevicePath is already being managed by the driver
625 specified by This.
626 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
627 RemainingDevicePath is already being managed by a different
628 driver or an application that requires exclusive access.
629 Currently not implemented.
630 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
631 RemainingDevicePath is not supported by the driver specified by This.
632 **/
633 EFI_STATUS
634 EFIAPI
635 HttpDxeIp4DriverBindingSupported (
636 IN EFI_DRIVER_BINDING_PROTOCOL *This,
637 IN EFI_HANDLE ControllerHandle,
638 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
639 )
640 {
641 return HttpDxeSupported (
642 This,
643 ControllerHandle,
644 RemainingDevicePath,
645 IP_VERSION_4
646 );
647 }
648
649 /**
650 Starts a device controller or a bus controller.
651
652 The Start() function is designed to be invoked from the EFI boot service ConnectController().
653 As a result, much of the error checking on the parameters to Start() has been moved into this
654 common boot service. It is legal to call Start() from other locations,
655 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
656 1. ControllerHandle must be a valid EFI_HANDLE.
657 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
658 EFI_DEVICE_PATH_PROTOCOL.
659 3. Prior to calling Start(), the Supported() function for the driver specified by This must
660 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
661
662 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
663 @param[in] ControllerHandle The handle of the controller to start. This handle
664 must support a protocol interface that supplies
665 an I/O abstraction to the driver.
666 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
667 parameter is ignored by device drivers, and is optional for bus
668 drivers. For a bus driver, if this parameter is NULL, then handles
669 for all the children of Controller are created by this driver.
670 If this parameter is not NULL and the first Device Path Node is
671 not the End of Device Path Node, then only the handle for the
672 child device specified by the first Device Path Node of
673 RemainingDevicePath is created by this driver.
674 If the first Device Path Node of RemainingDevicePath is
675 the End of Device Path Node, no child handle is created by this
676 driver.
677
678 @retval EFI_SUCCESS The device was started.
679 @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.
680 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
681 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
682 @retval Others The driver failded to start the device.
683
684 **/
685 EFI_STATUS
686 EFIAPI
687 HttpDxeIp4DriverBindingStart (
688 IN EFI_DRIVER_BINDING_PROTOCOL *This,
689 IN EFI_HANDLE ControllerHandle,
690 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
691 )
692 {
693 return HttpDxeStart (
694 This,
695 ControllerHandle,
696 RemainingDevicePath,
697 IP_VERSION_4
698 );
699 }
700
701 /**
702 Stops a device controller or a bus controller.
703
704 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
705 As a result, much of the error checking on the parameters to Stop() has been moved
706 into this common boot service. It is legal to call Stop() from other locations,
707 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
708 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
709 same driver's Start() function.
710 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
711 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
712 Start() function, and the Start() function must have called OpenProtocol() on
713 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
714
715 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
716 @param[in] ControllerHandle A handle to the device being stopped. The handle must
717 support a bus specific I/O protocol for the driver
718 to use to stop the device.
719 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
720 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
721 if NumberOfChildren is 0.
722
723 @retval EFI_SUCCESS The device was stopped.
724 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
725
726 **/
727 EFI_STATUS
728 EFIAPI
729 HttpDxeIp4DriverBindingStop (
730 IN EFI_DRIVER_BINDING_PROTOCOL *This,
731 IN EFI_HANDLE ControllerHandle,
732 IN UINTN NumberOfChildren,
733 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
734 )
735 {
736 return HttpDxeStop (
737 This,
738 ControllerHandle,
739 NumberOfChildren,
740 ChildHandleBuffer,
741 IP_VERSION_4
742 );
743 }
744
745 /**
746 Tests to see if this driver supports a given controller. If a child device is provided,
747 it further tests to see if this driver supports creating a handle for the specified child device.
748
749 This function checks to see if the driver specified by This supports the device specified by
750 ControllerHandle. Drivers will typically use the device path attached to
751 ControllerHandle and/or the services from the bus I/O abstraction attached to
752 ControllerHandle to determine if the driver supports ControllerHandle. This function
753 may be called many times during platform initialization. In order to reduce boot times, the tests
754 performed by this function must be very small, and take as little time as possible to execute. This
755 function must not change the state of any hardware devices, and this function must be aware that the
756 device specified by ControllerHandle may already be managed by the same driver or a
757 different driver. This function must match its calls to AllocatePages() with FreePages(),
758 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
759 Because ControllerHandle may have been previously started by the same driver, if a protocol is
760 already in the opened state, then it must not be closed with CloseProtocol(). This is required
761 to guarantee the state of ControllerHandle is not modified by this function.
762
763 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
764 @param[in] ControllerHandle The handle of the controller to test. This handle
765 must support a protocol interface that supplies
766 an I/O abstraction to the driver.
767 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
768 parameter is ignored by device drivers, and is optional for bus
769 drivers. For bus drivers, if this parameter is not NULL, then
770 the bus driver must determine if the bus controller specified
771 by ControllerHandle and the child controller specified
772 by RemainingDevicePath are both supported by this
773 bus driver.
774
775 @retval EFI_SUCCESS The device specified by ControllerHandle and
776 RemainingDevicePath is supported by the driver specified by This.
777 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
778 RemainingDevicePath is already being managed by the driver
779 specified by This.
780 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
781 RemainingDevicePath is already being managed by a different
782 driver or an application that requires exclusive access.
783 Currently not implemented.
784 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
785 RemainingDevicePath is not supported by the driver specified by This.
786 **/
787 EFI_STATUS
788 EFIAPI
789 HttpDxeIp6DriverBindingSupported (
790 IN EFI_DRIVER_BINDING_PROTOCOL *This,
791 IN EFI_HANDLE ControllerHandle,
792 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
793 )
794 {
795 return HttpDxeSupported (
796 This,
797 ControllerHandle,
798 RemainingDevicePath,
799 IP_VERSION_6
800 );
801
802 }
803
804 /**
805 Starts a device controller or a bus controller.
806
807 The Start() function is designed to be invoked from the EFI boot service ConnectController().
808 As a result, much of the error checking on the parameters to Start() has been moved into this
809 common boot service. It is legal to call Start() from other locations,
810 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
811 1. ControllerHandle must be a valid EFI_HANDLE.
812 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
813 EFI_DEVICE_PATH_PROTOCOL.
814 3. Prior to calling Start(), the Supported() function for the driver specified by This must
815 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
816
817 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
818 @param[in] ControllerHandle The handle of the controller to start. This handle
819 must support a protocol interface that supplies
820 an I/O abstraction to the driver.
821 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
822 parameter is ignored by device drivers, and is optional for bus
823 drivers. For a bus driver, if this parameter is NULL, then handles
824 for all the children of Controller are created by this driver.
825 If this parameter is not NULL and the first Device Path Node is
826 not the End of Device Path Node, then only the handle for the
827 child device specified by the first Device Path Node of
828 RemainingDevicePath is created by this driver.
829 If the first Device Path Node of RemainingDevicePath is
830 the End of Device Path Node, no child handle is created by this
831 driver.
832
833 @retval EFI_SUCCESS The device was started.
834 @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.
835 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
836 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
837 @retval Others The driver failded to start the device.
838
839 **/
840 EFI_STATUS
841 EFIAPI
842 HttpDxeIp6DriverBindingStart (
843 IN EFI_DRIVER_BINDING_PROTOCOL *This,
844 IN EFI_HANDLE ControllerHandle,
845 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
846 )
847 {
848 return HttpDxeStart (
849 This,
850 ControllerHandle,
851 RemainingDevicePath,
852 IP_VERSION_6
853 );
854 }
855
856 /**
857 Stops a device controller or a bus controller.
858
859 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
860 As a result, much of the error checking on the parameters to Stop() has been moved
861 into this common boot service. It is legal to call Stop() from other locations,
862 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
863 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
864 same driver's Start() function.
865 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
866 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
867 Start() function, and the Start() function must have called OpenProtocol() on
868 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
869
870 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
871 @param[in] ControllerHandle A handle to the device being stopped. The handle must
872 support a bus specific I/O protocol for the driver
873 to use to stop the device.
874 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
875 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
876 if NumberOfChildren is 0.
877
878 @retval EFI_SUCCESS The device was stopped.
879 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
880
881 **/
882 EFI_STATUS
883 EFIAPI
884 HttpDxeIp6DriverBindingStop (
885 IN EFI_DRIVER_BINDING_PROTOCOL *This,
886 IN EFI_HANDLE ControllerHandle,
887 IN UINTN NumberOfChildren,
888 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
889 )
890 {
891 return HttpDxeStop (
892 This,
893 ControllerHandle,
894 NumberOfChildren,
895 ChildHandleBuffer,
896 IP_VERSION_6
897 );
898 }
899 /**
900 Creates a child handle and installs a protocol.
901
902 The CreateChild() function installs a protocol on ChildHandle.
903 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
904 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
905
906 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
907 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
908 then a new handle is created. If it is a pointer to an existing UEFI handle,
909 then the protocol is added to the existing UEFI handle.
910
911 @retval EFI_SUCCES The protocol was added to ChildHandle.
912 @retval EFI_INVALID_PARAMETER This is NULL, or ChildHandle is NULL.
913 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
914 the child.
915 @retval other The child handle was not created.
916
917 **/
918 EFI_STATUS
919 EFIAPI
920 HttpServiceBindingCreateChild (
921 IN EFI_SERVICE_BINDING_PROTOCOL *This,
922 IN OUT EFI_HANDLE *ChildHandle
923 )
924 {
925 HTTP_SERVICE *HttpService;
926 HTTP_PROTOCOL *HttpInstance;
927 EFI_STATUS Status;
928 EFI_TPL OldTpl;
929
930 if ((This == NULL) || (ChildHandle == NULL)) {
931 return EFI_INVALID_PARAMETER;
932 }
933
934 HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
935 HttpInstance = AllocateZeroPool (sizeof (HTTP_PROTOCOL));
936 if (HttpInstance == NULL) {
937 return EFI_OUT_OF_RESOURCES;
938 }
939
940 HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;
941 HttpInstance->Service = HttpService;
942 HttpInstance->Method = HttpMethodMax;
943
944 CopyMem (&HttpInstance->Http, &mEfiHttpTemplate, sizeof (HttpInstance->Http));
945 NetMapInit (&HttpInstance->TxTokens);
946 NetMapInit (&HttpInstance->RxTokens);
947
948 //
949 // Install HTTP protocol onto ChildHandle
950 //
951 Status = gBS->InstallMultipleProtocolInterfaces (
952 ChildHandle,
953 &gEfiHttpProtocolGuid,
954 &HttpInstance->Http,
955 NULL
956 );
957
958 if (EFI_ERROR (Status)) {
959 goto ON_ERROR;
960 }
961
962 HttpInstance->Handle = *ChildHandle;
963
964 //
965 // Add it to the HTTP service's child list.
966 //
967 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
968
969 InsertTailList (&HttpService->ChildrenList, &HttpInstance->Link);
970 HttpService->ChildrenNumber++;
971
972 gBS->RestoreTPL (OldTpl);
973
974 return EFI_SUCCESS;
975
976 ON_ERROR:
977
978 NetMapClean (&HttpInstance->TxTokens);
979 NetMapClean (&HttpInstance->RxTokens);
980 FreePool (HttpInstance);
981
982 return Status;
983 }
984
985 /**
986 Destroys a child handle with a protocol installed on it.
987
988 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
989 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
990 last protocol on ChildHandle, then ChildHandle is destroyed.
991
992 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
993 @param ChildHandle Handle of the child to destroy
994
995 @retval EFI_SUCCES The protocol was removed from ChildHandle.
996 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
997 @retval EFI_INVALID_PARAMETER Child handle is NULL.
998 @retval other The child handle was not destroyed
999
1000 **/
1001 EFI_STATUS
1002 EFIAPI
1003 HttpServiceBindingDestroyChild (
1004 IN EFI_SERVICE_BINDING_PROTOCOL *This,
1005 IN EFI_HANDLE ChildHandle
1006 )
1007 {
1008 HTTP_SERVICE *HttpService;
1009 HTTP_PROTOCOL *HttpInstance;
1010 EFI_HTTP_PROTOCOL *Http;
1011 EFI_STATUS Status;
1012 EFI_TPL OldTpl;
1013
1014 if ((This == NULL) || (ChildHandle == NULL)) {
1015 return EFI_INVALID_PARAMETER;
1016 }
1017
1018 HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
1019 Status = gBS->OpenProtocol (
1020 ChildHandle,
1021 &gEfiHttpProtocolGuid,
1022 (VOID **) &Http,
1023 NULL,
1024 NULL,
1025 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1026 );
1027 if (EFI_ERROR (Status)) {
1028 return EFI_UNSUPPORTED;
1029 }
1030
1031 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (Http);
1032 if (HttpInstance->Service != HttpService) {
1033 return EFI_INVALID_PARAMETER;
1034 }
1035
1036 if (HttpInstance->InDestroy) {
1037 return EFI_SUCCESS;
1038 }
1039
1040 HttpInstance->InDestroy = TRUE;
1041
1042 //
1043 // Uninstall the HTTP protocol.
1044 //
1045 Status = gBS->UninstallProtocolInterface (
1046 ChildHandle,
1047 &gEfiHttpProtocolGuid,
1048 Http
1049 );
1050
1051 if (EFI_ERROR (Status)) {
1052 HttpInstance->InDestroy = FALSE;
1053 return Status;
1054 }
1055
1056 HttpCleanProtocol (HttpInstance);
1057
1058 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1059
1060 RemoveEntryList (&HttpInstance->Link);
1061 HttpService->ChildrenNumber--;
1062
1063 gBS->RestoreTPL (OldTpl);
1064
1065 FreePool (HttpInstance);
1066 return EFI_SUCCESS;
1067 }