]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpDxe/HttpDriver.c
bd1d04e78cc430acbba194d78f2e5eb9e9b8a5a3
[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, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "HttpDriver.h"
17
18 EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;
19
20 ///
21 /// Driver Binding Protocol instance
22 ///
23 EFI_DRIVER_BINDING_PROTOCOL gHttpDxeDriverBinding = {
24 HttpDxeDriverBindingSupported,
25 HttpDxeDriverBindingStart,
26 HttpDxeDriverBindingStop,
27 HTTP_DRIVER_VERSION,
28 NULL,
29 NULL
30 };
31
32 /**
33 Create a HTTP driver service binding private instance.
34
35 @param[in] Controller The controller that has TCP4 service binding
36 installed.
37 @param[in] ImageHandle The HTTP driver's image handle.
38 @param[out] ServiceData Point to HTTP driver private instance.
39
40 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
41 @retval EFI_SUCCESS A new HTTP driver private instance is created.
42
43 **/
44 EFI_STATUS
45 HttpCreateService (
46 IN EFI_HANDLE Controller,
47 IN EFI_HANDLE ImageHandle,
48 OUT HTTP_SERVICE **ServiceData
49 )
50 {
51 HTTP_SERVICE *HttpService;
52
53 ASSERT (ServiceData != NULL);
54 *ServiceData = NULL;
55
56 HttpService = AllocateZeroPool (sizeof (HTTP_SERVICE));
57 if (HttpService == NULL) {
58 return EFI_OUT_OF_RESOURCES;
59 }
60
61 HttpService->Signature = HTTP_SERVICE_SIGNATURE;
62 HttpService->ServiceBinding.CreateChild = HttpServiceBindingCreateChild;
63 HttpService->ServiceBinding.DestroyChild = HttpServiceBindingDestroyChild;
64 HttpService->ImageHandle = ImageHandle;
65 HttpService->ControllerHandle = Controller;
66 HttpService->ChildrenNumber = 0;
67 InitializeListHead (&HttpService->ChildrenList);
68
69 *ServiceData = HttpService;
70 return EFI_SUCCESS;
71 }
72
73 /**
74 Release all the resource used the HTTP service binding instance.
75
76 @param HttpService The HTTP private instance.
77
78 **/
79 VOID
80 HttpCleanService (
81 IN HTTP_SERVICE *HttpService
82 )
83 {
84 if (HttpService == NULL) {
85 return ;
86 }
87
88 if (HttpService->TcpChildHandle != NULL) {
89 gBS->CloseProtocol (
90 HttpService->TcpChildHandle,
91 &gEfiTcp4ProtocolGuid,
92 HttpService->ImageHandle,
93 HttpService->ControllerHandle
94 );
95
96 NetLibDestroyServiceChild (
97 HttpService->ControllerHandle,
98 HttpService->ImageHandle,
99 &gEfiTcp4ServiceBindingProtocolGuid,
100 HttpService->TcpChildHandle
101 );
102 }
103 }
104
105 /**
106 The event process routine when the http utilities protocol is installed
107 in the system.
108
109 @param[in] Event Not used.
110 @param[in] Context The pointer to the IP4 config2 instance data.
111
112 **/
113 VOID
114 EFIAPI
115 HttpUtilitiesInstalledCallback (
116 IN EFI_EVENT Event,
117 IN VOID *Context
118 )
119 {
120 gBS->LocateProtocol (
121 &gEfiHttpUtilitiesProtocolGuid,
122 NULL,
123 (VOID **) &mHttpUtilities
124 );
125
126 //
127 // Close the event if Http utilities protocol is loacted.
128 //
129 if (mHttpUtilities != NULL && Event != NULL) {
130 gBS->CloseEvent (Event);
131 }
132 }
133
134 /**
135 This is the declaration of an EFI image entry point. This entry point is
136 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
137 both device drivers and bus drivers.
138
139 @param ImageHandle The firmware allocated handle for the UEFI image.
140 @param SystemTable A pointer to the EFI System Table.
141
142 @retval EFI_SUCCESS The operation completed successfully.
143 @retval Others An unexpected error occurred.
144
145 **/
146 EFI_STATUS
147 EFIAPI
148 HttpDxeDriverEntryPoint (
149 IN EFI_HANDLE ImageHandle,
150 IN EFI_SYSTEM_TABLE *SystemTable
151 )
152 {
153 VOID *Registration;
154
155 gBS->LocateProtocol (
156 &gEfiHttpUtilitiesProtocolGuid,
157 NULL,
158 (VOID **) &mHttpUtilities
159 );
160
161 if (mHttpUtilities == NULL) {
162 //
163 // No Http utilities protocol, register a notify.
164 //
165 EfiCreateProtocolNotifyEvent (
166 &gEfiHttpUtilitiesProtocolGuid,
167 TPL_CALLBACK,
168 HttpUtilitiesInstalledCallback,
169 NULL,
170 &Registration
171 );
172 }
173
174 //
175 // Install UEFI Driver Model protocol(s).
176 //
177 return EfiLibInstallDriverBindingComponentName2 (
178 ImageHandle,
179 SystemTable,
180 &gHttpDxeDriverBinding,
181 ImageHandle,
182 &gHttpDxeComponentName,
183 &gHttpDxeComponentName2
184 );
185 }
186
187 /**
188 Callback function which provided by user to remove one node in NetDestroyLinkList process.
189
190 @param[in] Entry The entry to be removed.
191 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
192
193 @retval EFI_INVALID_PARAMETER Any input parameter is NULL.
194 @retval EFI_SUCCESS The entry has been removed successfully.
195 @retval Others Fail to remove the entry.
196
197 **/
198 EFI_STATUS
199 EFIAPI
200 HttpDestroyChildEntryInHandleBuffer (
201 IN LIST_ENTRY *Entry,
202 IN VOID *Context
203 )
204 {
205 HTTP_PROTOCOL *HttpInstance;
206 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
207 UINTN NumberOfChildren;
208 EFI_HANDLE *ChildHandleBuffer;
209
210 if (Entry == NULL || Context == NULL) {
211 return EFI_INVALID_PARAMETER;
212 }
213
214 HttpInstance = NET_LIST_USER_STRUCT_S (Entry, HTTP_PROTOCOL, Link, HTTP_PROTOCOL_SIGNATURE);
215 ServiceBinding = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
216 NumberOfChildren = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
217 ChildHandleBuffer = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
218
219 if (!NetIsInHandleBuffer (HttpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) {
220 return EFI_SUCCESS;
221 }
222
223 return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);
224 }
225
226 /**
227 Tests to see if this driver supports a given controller. If a child device is provided,
228 it further tests to see if this driver supports creating a handle for the specified child device.
229
230 This function checks to see if the driver specified by This supports the device specified by
231 ControllerHandle. Drivers will typically use the device path attached to
232 ControllerHandle and/or the services from the bus I/O abstraction attached to
233 ControllerHandle to determine if the driver supports ControllerHandle. This function
234 may be called many times during platform initialization. In order to reduce boot times, the tests
235 performed by this function must be very small, and take as little time as possible to execute. This
236 function must not change the state of any hardware devices, and this function must be aware that the
237 device specified by ControllerHandle may already be managed by the same driver or a
238 different driver. This function must match its calls to AllocatePages() with FreePages(),
239 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
240 Because ControllerHandle may have been previously started by the same driver, if a protocol is
241 already in the opened state, then it must not be closed with CloseProtocol(). This is required
242 to guarantee the state of ControllerHandle is not modified by this function.
243
244 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
245 @param[in] ControllerHandle The handle of the controller to test. This handle
246 must support a protocol interface that supplies
247 an I/O abstraction to the driver.
248 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
249 parameter is ignored by device drivers, and is optional for bus
250 drivers. For bus drivers, if this parameter is not NULL, then
251 the bus driver must determine if the bus controller specified
252 by ControllerHandle and the child controller specified
253 by RemainingDevicePath are both supported by this
254 bus driver.
255
256 @retval EFI_SUCCESS The device specified by ControllerHandle and
257 RemainingDevicePath is supported by the driver specified by This.
258 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
259 RemainingDevicePath is already being managed by the driver
260 specified by This.
261 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
262 RemainingDevicePath is already being managed by a different
263 driver or an application that requires exclusive access.
264 Currently not implemented.
265 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
266 RemainingDevicePath is not supported by the driver specified by This.
267 **/
268 EFI_STATUS
269 EFIAPI
270 HttpDxeDriverBindingSupported (
271 IN EFI_DRIVER_BINDING_PROTOCOL *This,
272 IN EFI_HANDLE ControllerHandle,
273 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
274 )
275 {
276 EFI_STATUS Status;
277
278 //
279 // Test for the HttpServiceBinding protocol.
280 //
281 Status = gBS->OpenProtocol (
282 ControllerHandle,
283 &gEfiHttpServiceBindingProtocolGuid,
284 NULL,
285 This->DriverBindingHandle,
286 ControllerHandle,
287 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
288 );
289 if (!EFI_ERROR (Status)) {
290 return EFI_ALREADY_STARTED;
291 }
292
293 //
294 // Test for the Tcp4 Protocol
295 //
296 return gBS->OpenProtocol (
297 ControllerHandle,
298 &gEfiTcp4ServiceBindingProtocolGuid,
299 NULL,
300 This->DriverBindingHandle,
301 ControllerHandle,
302 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
303 );
304
305 }
306
307 /**
308 Starts a device controller or a bus controller.
309
310 The Start() function is designed to be invoked from the EFI boot service ConnectController().
311 As a result, much of the error checking on the parameters to Start() has been moved into this
312 common boot service. It is legal to call Start() from other locations,
313 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
314 1. ControllerHandle must be a valid EFI_HANDLE.
315 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
316 EFI_DEVICE_PATH_PROTOCOL.
317 3. Prior to calling Start(), the Supported() function for the driver specified by This must
318 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
319
320 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
321 @param[in] ControllerHandle The handle of the controller to start. This handle
322 must support a protocol interface that supplies
323 an I/O abstraction to the driver.
324 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
325 parameter is ignored by device drivers, and is optional for bus
326 drivers. For a bus driver, if this parameter is NULL, then handles
327 for all the children of Controller are created by this driver.
328 If this parameter is not NULL and the first Device Path Node is
329 not the End of Device Path Node, then only the handle for the
330 child device specified by the first Device Path Node of
331 RemainingDevicePath is created by this driver.
332 If the first Device Path Node of RemainingDevicePath is
333 the End of Device Path Node, no child handle is created by this
334 driver.
335
336 @retval EFI_SUCCESS The device was started.
337 @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.
338 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
339 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
340 @retval Others The driver failded to start the device.
341
342 **/
343 EFI_STATUS
344 EFIAPI
345 HttpDxeDriverBindingStart (
346 IN EFI_DRIVER_BINDING_PROTOCOL *This,
347 IN EFI_HANDLE ControllerHandle,
348 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
349 )
350 {
351 EFI_STATUS Status;
352 HTTP_SERVICE *HttpService;
353 VOID *Interface;
354
355 //
356 // Test for the Http service binding protocol
357 //
358 Status = gBS->OpenProtocol (
359 ControllerHandle,
360 &gEfiHttpServiceBindingProtocolGuid,
361 NULL,
362 This->DriverBindingHandle,
363 ControllerHandle,
364 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
365 );
366
367 if (Status == EFI_SUCCESS) {
368 return EFI_ALREADY_STARTED;
369 }
370
371 Status = HttpCreateService (ControllerHandle, This->DriverBindingHandle, &HttpService);
372 if (EFI_ERROR (Status)) {
373 return Status;
374 }
375
376 ASSERT (HttpService != NULL);
377
378 //
379 // Create a TCP child instance, but do not configure it. This will establish the parent-child relationship.
380 //
381 Status = NetLibCreateServiceChild (
382 ControllerHandle,
383 This->DriverBindingHandle,
384 &gEfiTcp4ServiceBindingProtocolGuid,
385 &HttpService->TcpChildHandle
386 );
387
388 if (EFI_ERROR (Status)) {
389 goto ON_ERROR;
390 }
391
392 Status = gBS->OpenProtocol (
393 HttpService->TcpChildHandle,
394 &gEfiTcp4ProtocolGuid,
395 &Interface,
396 This->DriverBindingHandle,
397 ControllerHandle,
398 EFI_OPEN_PROTOCOL_BY_DRIVER
399 );
400
401 if (EFI_ERROR (Status)) {
402 goto ON_ERROR;
403 }
404
405 //
406 // Install the HttpServiceBinding Protocol onto Controller
407 //
408 Status = gBS->InstallMultipleProtocolInterfaces (
409 &ControllerHandle,
410 &gEfiHttpServiceBindingProtocolGuid,
411 &HttpService->ServiceBinding,
412 NULL
413 );
414
415 if (EFI_ERROR (Status)) {
416 goto ON_ERROR;
417 }
418
419 return EFI_SUCCESS;
420
421 ON_ERROR:
422
423 if (HttpService != NULL) {
424 HttpCleanService (HttpService);
425 FreePool (HttpService);
426 }
427
428 return Status;
429 }
430
431 /**
432 Stops a device controller or a bus controller.
433
434 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
435 As a result, much of the error checking on the parameters to Stop() has been moved
436 into this common boot service. It is legal to call Stop() from other locations,
437 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
438 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
439 same driver's Start() function.
440 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
441 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
442 Start() function, and the Start() function must have called OpenProtocol() on
443 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
444
445 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
446 @param[in] ControllerHandle A handle to the device being stopped. The handle must
447 support a bus specific I/O protocol for the driver
448 to use to stop the device.
449 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
450 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
451 if NumberOfChildren is 0.
452
453 @retval EFI_SUCCESS The device was stopped.
454 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
455
456 **/
457 EFI_STATUS
458 EFIAPI
459 HttpDxeDriverBindingStop (
460 IN EFI_DRIVER_BINDING_PROTOCOL *This,
461 IN EFI_HANDLE ControllerHandle,
462 IN UINTN NumberOfChildren,
463 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
464 )
465 {
466 EFI_HANDLE NicHandle;
467 EFI_STATUS Status;
468 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
469 HTTP_SERVICE *HttpService;
470 LIST_ENTRY *List;
471 HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
472
473 //
474 // HTTP driver opens TCP child, So, Controller is a TCP
475 // child handle. Locate the Nic handle first. Then get the
476 // HTTP private data back.
477 //
478 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
479 if (NicHandle == NULL) {
480 return EFI_SUCCESS;
481 }
482
483 Status = gBS->OpenProtocol (
484 NicHandle,
485 &gEfiHttpServiceBindingProtocolGuid,
486 (VOID **) &ServiceBinding,
487 This->DriverBindingHandle,
488 NicHandle,
489 EFI_OPEN_PROTOCOL_GET_PROTOCOL
490 );
491
492 if (EFI_ERROR (Status)) {
493 return EFI_DEVICE_ERROR;
494 }
495
496 HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
497
498 if (!IsListEmpty (&HttpService->ChildrenList)) {
499 //
500 // Destroy the HTTP child instance in ChildHandleBuffer.
501 //
502 List = &HttpService->ChildrenList;
503 Context.ServiceBinding = ServiceBinding;
504 Context.NumberOfChildren = NumberOfChildren;
505 Context.ChildHandleBuffer = ChildHandleBuffer;
506 Status = NetDestroyLinkList (
507 List,
508 HttpDestroyChildEntryInHandleBuffer,
509 &Context,
510 NULL
511 );
512 }
513
514 if (NumberOfChildren == 0 && IsListEmpty (&HttpService->ChildrenList)) {
515 gBS->UninstallProtocolInterface (
516 NicHandle,
517 &gEfiHttpServiceBindingProtocolGuid,
518 ServiceBinding
519 );
520
521 HttpCleanService (HttpService);
522
523 FreePool (HttpService);
524
525 Status = EFI_SUCCESS;
526 }
527
528 return Status;
529 }
530
531 /**
532 Creates a child handle and installs a protocol.
533
534 The CreateChild() function installs a protocol on ChildHandle.
535 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
536 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
537
538 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
539 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
540 then a new handle is created. If it is a pointer to an existing UEFI handle,
541 then the protocol is added to the existing UEFI handle.
542
543 @retval EFI_SUCCES The protocol was added to ChildHandle.
544 @retval EFI_INVALID_PARAMETER This is NULL, or ChildHandle is NULL.
545 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
546 the child.
547 @retval other The child handle was not created.
548
549 **/
550 EFI_STATUS
551 EFIAPI
552 HttpServiceBindingCreateChild (
553 IN EFI_SERVICE_BINDING_PROTOCOL *This,
554 IN OUT EFI_HANDLE *ChildHandle
555 )
556 {
557 HTTP_SERVICE *HttpService;
558 HTTP_PROTOCOL *HttpInstance;
559 EFI_STATUS Status;
560 VOID *Interface;
561 EFI_TPL OldTpl;
562
563 if ((This == NULL) || (ChildHandle == NULL)) {
564 return EFI_INVALID_PARAMETER;
565 }
566
567 HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
568 HttpInstance = AllocateZeroPool (sizeof (HTTP_PROTOCOL));
569 if (HttpInstance == NULL) {
570 return EFI_OUT_OF_RESOURCES;
571 }
572
573 //
574 // Install HTTP protocol onto ChildHandle
575 //
576 Status = gBS->InstallMultipleProtocolInterfaces (
577 ChildHandle,
578 &gEfiHttpProtocolGuid,
579 &HttpInstance->Http,
580 NULL
581 );
582
583 if (EFI_ERROR (Status)) {
584 goto ON_ERROR;
585 }
586
587 HttpInstance->Handle = *ChildHandle;
588
589 Status = HttpInitProtocol (HttpService, HttpInstance);
590 if (EFI_ERROR (Status)) {
591 goto ON_ERROR;
592 }
593
594 //
595 // Open the default Tcp4 protocol by child.
596 //
597 Status = gBS->OpenProtocol (
598 HttpService->TcpChildHandle,
599 &gEfiTcp4ProtocolGuid,
600 (VOID **) &Interface,
601 gHttpDxeDriverBinding.DriverBindingHandle,
602 HttpInstance->Handle,
603 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
604 );
605 if (EFI_ERROR (Status)) {
606 goto ON_ERROR;
607 }
608
609 //
610 // Add it to the HTTP service's child list.
611 //
612 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
613
614 InsertTailList (&HttpService->ChildrenList, &HttpInstance->Link);
615 HttpService->ChildrenNumber++;
616
617 gBS->RestoreTPL (OldTpl);
618
619 return EFI_SUCCESS;
620
621 ON_ERROR:
622
623 HttpCleanProtocol (HttpInstance);
624 FreePool (HttpInstance);
625
626 return Status;
627 }
628
629 /**
630 Destroys a child handle with a protocol installed on it.
631
632 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
633 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
634 last protocol on ChildHandle, then ChildHandle is destroyed.
635
636 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
637 @param ChildHandle Handle of the child to destroy
638
639 @retval EFI_SUCCES The protocol was removed from ChildHandle.
640 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
641 @retval EFI_INVALID_PARAMETER Child handle is NULL.
642 @retval other The child handle was not destroyed
643
644 **/
645 EFI_STATUS
646 EFIAPI
647 HttpServiceBindingDestroyChild (
648 IN EFI_SERVICE_BINDING_PROTOCOL *This,
649 IN EFI_HANDLE ChildHandle
650 )
651 {
652 HTTP_SERVICE *HttpService;
653 HTTP_PROTOCOL *HttpInstance;
654 EFI_HTTP_PROTOCOL *Http;
655 EFI_STATUS Status;
656 EFI_TPL OldTpl;
657
658 if ((This == NULL) || (ChildHandle == NULL)) {
659 return EFI_INVALID_PARAMETER;
660 }
661
662 HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
663 Status = gBS->OpenProtocol (
664 ChildHandle,
665 &gEfiHttpProtocolGuid,
666 (VOID **) &Http,
667 gHttpDxeDriverBinding.DriverBindingHandle,
668 ChildHandle,
669 EFI_OPEN_PROTOCOL_GET_PROTOCOL
670 );
671 if (EFI_ERROR (Status)) {
672 return EFI_UNSUPPORTED;
673 }
674
675 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (Http);
676 if (HttpInstance->Service != HttpService) {
677 return EFI_INVALID_PARAMETER;
678 }
679
680 if (HttpInstance->InDestroy) {
681 return EFI_SUCCESS;
682 }
683
684 //
685 // Close the Tcp4 protocol.
686 //
687 gBS->CloseProtocol (
688 HttpService->TcpChildHandle,
689 &gEfiTcp4ProtocolGuid,
690 gHttpDxeDriverBinding.DriverBindingHandle,
691 ChildHandle
692 );
693
694 HttpInstance->InDestroy = TRUE;
695
696 //
697 // Uninstall the HTTP protocol.
698 //
699 Status = gBS->UninstallProtocolInterface (
700 ChildHandle,
701 &gEfiHttpProtocolGuid,
702 Http
703 );
704
705 if (EFI_ERROR (Status)) {
706 HttpInstance->InDestroy = FALSE;
707 return Status;
708 }
709
710 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
711
712 HttpCleanProtocol (HttpInstance);
713
714 RemoveEntryList (&HttpInstance->Link);
715 HttpService->ChildrenNumber--;
716
717 gBS->RestoreTPL (OldTpl);
718
719 FreePool (HttpInstance);
720 return EFI_SUCCESS;
721 }