VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/HttpDxe/HttpDriver.c@ 106129

Last change on this file since 106129 was 101291, checked in by vboxsync, 14 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette