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