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