--- /dev/null
+/** @file\r
+ The driver binding and service binding protocol for HttpDxe driver.\r
+\r
+ Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "HttpDriver.h"\r
+\r
+///\r
+/// Driver Binding Protocol instance\r
+///\r
+EFI_DRIVER_BINDING_PROTOCOL gHttpDxeDriverBinding = {\r
+ HttpDxeDriverBindingSupported,\r
+ HttpDxeDriverBindingStart,\r
+ HttpDxeDriverBindingStop,\r
+ HTTP_DRIVER_VERSION,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+/**\r
+ Create a HTTP driver service binding private instance.\r
+\r
+ @param[in] Controller The controller that has TCP4 service binding\r
+ installed.\r
+ @param[in] ImageHandle The HTTP driver's image handle.\r
+ @param[out] ServiceData Point to HTTP driver private instance.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r
+ @retval EFI_SUCCESS A new HTTP driver private instance is created.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpCreateService (\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_HANDLE ImageHandle,\r
+ OUT HTTP_SERVICE **ServiceData\r
+ )\r
+{\r
+ HTTP_SERVICE *HttpService;\r
+\r
+ ASSERT (ServiceData != NULL);\r
+ *ServiceData = NULL;\r
+\r
+ HttpService = AllocateZeroPool (sizeof (HTTP_SERVICE));\r
+ if (HttpService == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ HttpService->Signature = HTTP_SERVICE_SIGNATURE;\r
+ HttpService->ServiceBinding.CreateChild = HttpServiceBindingCreateChild;\r
+ HttpService->ServiceBinding.DestroyChild = HttpServiceBindingDestroyChild;\r
+ HttpService->ImageHandle = ImageHandle;\r
+ HttpService->ControllerHandle = Controller;\r
+ HttpService->ChildrenNumber = 0;\r
+ InitializeListHead (&HttpService->ChildrenList);\r
+ \r
+ *ServiceData = HttpService;\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Release all the resource used the HTTP service binding instance.\r
+\r
+ @param HttpService The HTTP private instance.\r
+\r
+**/\r
+VOID\r
+HttpCleanService (\r
+ IN HTTP_SERVICE *HttpService\r
+ )\r
+{\r
+ if (HttpService != NULL) {\r
+ return ;\r
+ }\r
+\r
+ if (HttpService->TcpChildHandle != NULL) {\r
+ gBS->CloseProtocol (\r
+ HttpService->TcpChildHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ HttpService->ImageHandle,\r
+ HttpService->ControllerHandle\r
+ );\r
+\r
+ NetLibDestroyServiceChild (\r
+ HttpService->ControllerHandle,\r
+ HttpService->ImageHandle,\r
+ &gEfiTcp4ServiceBindingProtocolGuid,\r
+ HttpService->TcpChildHandle\r
+ );\r
+ }\r
+}\r
+\r
+/**\r
+ This is the declaration of an EFI image entry point. This entry point is\r
+ the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
+ both device drivers and bus drivers.\r
+\r
+ @param ImageHandle The firmware allocated handle for the UEFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The operation completed successfully.\r
+ @retval Others An unexpected error occurred.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeDriverEntryPoint (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ //\r
+ // Install UEFI Driver Model protocol(s).\r
+ //\r
+ return EfiLibInstallDriverBindingComponentName2 (\r
+ ImageHandle,\r
+ SystemTable,\r
+ &gHttpDxeDriverBinding,\r
+ ImageHandle,\r
+ &gHttpDxeComponentName,\r
+ &gHttpDxeComponentName2\r
+ );\r
+}\r
+\r
+/**\r
+ Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
+ \r
+ @param[in] Entry The entry to be removed.\r
+ @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
+\r
+ @retval EFI_INVALID_PARAMETER Any input parameter is NULL.\r
+ @retval EFI_SUCCESS The entry has been removed successfully.\r
+ @retval Others Fail to remove the entry.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDestroyChildEntryInHandleBuffer (\r
+ IN LIST_ENTRY *Entry,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ HTTP_PROTOCOL *HttpInstance;\r
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
+ UINTN NumberOfChildren;\r
+ EFI_HANDLE *ChildHandleBuffer;\r
+\r
+ if (Entry == NULL || Context == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ HttpInstance = NET_LIST_USER_STRUCT_S (Entry, HTTP_PROTOCOL, Link, HTTP_PROTOCOL_SIGNATURE);\r
+ ServiceBinding = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;\r
+ NumberOfChildren = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;\r
+ ChildHandleBuffer = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;\r
+\r
+ if (!NetIsInHandleBuffer (HttpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);\r
+}\r
+\r
+/**\r
+ Tests to see if this driver supports a given controller. If a child device is provided, \r
+ it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+ This function checks to see if the driver specified by This supports the device specified by \r
+ ControllerHandle. Drivers will typically use the device path attached to \r
+ ControllerHandle and/or the services from the bus I/O abstraction attached to \r
+ ControllerHandle to determine if the driver supports ControllerHandle. This function \r
+ may be called many times during platform initialization. In order to reduce boot times, the tests \r
+ performed by this function must be very small, and take as little time as possible to execute. This \r
+ function must not change the state of any hardware devices, and this function must be aware that the \r
+ device specified by ControllerHandle may already be managed by the same driver or a \r
+ different driver. This function must match its calls to AllocatePages() with FreePages(), \r
+ AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). \r
+ Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
+ already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+ to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+ @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+ @param[in] ControllerHandle The handle of the controller to test. This handle \r
+ must support a protocol interface that supplies \r
+ an I/O abstraction to the driver.\r
+ @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
+ parameter is ignored by device drivers, and is optional for bus \r
+ drivers. For bus drivers, if this parameter is not NULL, then \r
+ the bus driver must determine if the bus controller specified \r
+ by ControllerHandle and the child controller specified \r
+ by RemainingDevicePath are both supported by this \r
+ bus driver.\r
+\r
+ @retval EFI_SUCCESS The device specified by ControllerHandle and\r
+ RemainingDevicePath is supported by the driver specified by This.\r
+ @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
+ RemainingDevicePath is already being managed by the driver\r
+ specified by This.\r
+ @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
+ RemainingDevicePath is already being managed by a different\r
+ driver or an application that requires exclusive access.\r
+ Currently not implemented.\r
+ @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
+ RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeDriverBindingSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Test for the HttpServiceBinding protocol.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiHttpServiceBindingProtocolGuid,\r
+ NULL,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ return EFI_ALREADY_STARTED;\r
+ }\r
+\r
+ //\r
+ // Test for the Tcp4 Protocol\r
+ //\r
+ return gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiTcp4ServiceBindingProtocolGuid,\r
+ NULL,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+ );\r
+ \r
+}\r
+\r
+/**\r
+ Starts a device controller or a bus controller.\r
+\r
+ The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+ As a result, much of the error checking on the parameters to Start() has been moved into this \r
+ common boot service. It is legal to call Start() from other locations, \r
+ but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+ 1. ControllerHandle must be a valid EFI_HANDLE.\r
+ 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+ EFI_DEVICE_PATH_PROTOCOL.\r
+ 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+ have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r
+\r
+ @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+ @param[in] ControllerHandle The handle of the controller to start. This handle \r
+ must support a protocol interface that supplies \r
+ an I/O abstraction to the driver.\r
+ @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
+ parameter is ignored by device drivers, and is optional for bus \r
+ drivers. For a bus driver, if this parameter is NULL, then handles \r
+ for all the children of Controller are created by this driver. \r
+ If this parameter is not NULL and the first Device Path Node is \r
+ not the End of Device Path Node, then only the handle for the \r
+ child device specified by the first Device Path Node of \r
+ RemainingDevicePath is created by this driver.\r
+ If the first Device Path Node of RemainingDevicePath is \r
+ the End of Device Path Node, no child handle is created by this\r
+ driver.\r
+\r
+ @retval EFI_SUCCESS The device was started.\r
+ @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.\r
+ @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
+ @retval Others The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeDriverBindingStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ HTTP_SERVICE *HttpService;\r
+ VOID *Interface;\r
+ \r
+ //\r
+ // Test for the Http service binding protocol\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiHttpServiceBindingProtocolGuid,\r
+ NULL,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+ );\r
+\r
+ if (Status == EFI_SUCCESS) {\r
+ return EFI_ALREADY_STARTED;\r
+ }\r
+\r
+ Status = HttpCreateService (ControllerHandle, This->DriverBindingHandle, &HttpService);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ ASSERT (HttpService != NULL);\r
+\r
+ //\r
+ // Create a TCP child instance, but do not configure it. This will establish the parent-child relationship.\r
+ //\r
+ Status = NetLibCreateServiceChild (\r
+ ControllerHandle,\r
+ This->DriverBindingHandle,\r
+ &gEfiTcp4ServiceBindingProtocolGuid,\r
+ &HttpService->TcpChildHandle\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ HttpService->TcpChildHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ &Interface,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ \r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ //\r
+ // Install the HttpServiceBinding Protocol onto Controller\r
+ //\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &ControllerHandle,\r
+ &gEfiHttpServiceBindingProtocolGuid,\r
+ &HttpService->ServiceBinding,\r
+ NULL\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+\r
+ON_ERROR:\r
+\r
+ if (HttpService != NULL) {\r
+ HttpCleanService (HttpService);\r
+ FreePool (HttpService);\r
+ }\r
+ \r
+ return Status;\r
+}\r
+\r
+/**\r
+ Stops a device controller or a bus controller.\r
+ \r
+ The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
+ As a result, much of the error checking on the parameters to Stop() has been moved \r
+ into this common boot service. It is legal to call Stop() from other locations, \r
+ but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+ 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+ same driver's Start() function.\r
+ 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+ EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+ Start() function, and the Start() function must have called OpenProtocol() on\r
+ ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+ \r
+ @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+ @param[in] ControllerHandle A handle to the device being stopped. The handle must \r
+ support a bus specific I/O protocol for the driver \r
+ to use to stop the device.\r
+ @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
+ @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+ if NumberOfChildren is 0.\r
+\r
+ @retval EFI_SUCCESS The device was stopped.\r
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeDriverBindingStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
+ )\r
+{\r
+ EFI_HANDLE NicHandle;\r
+ EFI_STATUS Status;\r
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
+ HTTP_SERVICE *HttpService;\r
+ LIST_ENTRY *List;\r
+ HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r
+ \r
+ //\r
+ // HTTP driver opens TCP child, So, Controller is a TCP\r
+ // child handle. Locate the Nic handle first. Then get the\r
+ // HTTP private data back.\r
+ //\r
+ NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
+ if (NicHandle == NULL) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ NicHandle,\r
+ &gEfiHttpServiceBindingProtocolGuid,\r
+ (VOID **) &ServiceBinding,\r
+ This->DriverBindingHandle,\r
+ NicHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);\r
+\r
+ if (!IsListEmpty (&HttpService->ChildrenList)) {\r
+ //\r
+ // Destroy the HTTP child instance in ChildHandleBuffer.\r
+ //\r
+ List = &HttpService->ChildrenList;\r
+ Context.ServiceBinding = ServiceBinding;\r
+ Context.NumberOfChildren = NumberOfChildren;\r
+ Context.ChildHandleBuffer = ChildHandleBuffer;\r
+ Status = NetDestroyLinkList (\r
+ List,\r
+ HttpDestroyChildEntryInHandleBuffer,\r
+ &Context,\r
+ NULL\r
+ );\r
+ }\r
+\r
+ if (NumberOfChildren == 0 && IsListEmpty (&HttpService->ChildrenList)) {\r
+ gBS->UninstallProtocolInterface (\r
+ NicHandle,\r
+ &gEfiHttpServiceBindingProtocolGuid,\r
+ ServiceBinding\r
+ );\r
+\r
+ HttpCleanService (HttpService);\r
+ \r
+ FreePool (HttpService);\r
+\r
+ Status = EFI_SUCCESS;\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Creates a child handle and installs a protocol.\r
+\r
+ The CreateChild() function installs a protocol on ChildHandle.\r
+ If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r
+ If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r
+\r
+ @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
+ @param ChildHandle Pointer to the handle of the child to create. If it is NULL,\r
+ then a new handle is created. If it is a pointer to an existing UEFI handle,\r
+ then the protocol is added to the existing UEFI handle.\r
+\r
+ @retval EFI_SUCCES The protocol was added to ChildHandle.\r
+ @retval EFI_INVALID_PARAMETER This is NULL, or ChildHandle is NULL.\r
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create\r
+ the child.\r
+ @retval other The child handle was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpServiceBindingCreateChild (\r
+ IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
+ IN OUT EFI_HANDLE *ChildHandle\r
+ )\r
+{\r
+ HTTP_SERVICE *HttpService;\r
+ HTTP_PROTOCOL *HttpInstance;\r
+ EFI_STATUS Status;\r
+ VOID *Interface;\r
+ EFI_TPL OldTpl;\r
+\r
+ if ((This == NULL) || (ChildHandle == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);\r
+ HttpInstance = AllocateZeroPool (sizeof (HTTP_PROTOCOL));\r
+ if (HttpInstance == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // Install HTTP protocol onto ChildHandle\r
+ //\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ ChildHandle,\r
+ &gEfiHttpProtocolGuid,\r
+ &HttpInstance->Http,\r
+ NULL\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ HttpInstance->Handle = *ChildHandle;\r
+\r
+ Status = HttpInitProtocol (HttpService, HttpInstance);\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ //\r
+ // Open the default Tcp4 protocol by child.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ HttpService->TcpChildHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ (VOID **) &Interface,\r
+ gHttpDxeDriverBinding.DriverBindingHandle,\r
+ HttpInstance->Handle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ //\r
+ // Add it to the HTTP service's child list.\r
+ //\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+ InsertTailList (&HttpService->ChildrenList, &HttpInstance->Link);\r
+ HttpService->ChildrenNumber++;\r
+\r
+ gBS->RestoreTPL (OldTpl);\r
+\r
+ return EFI_SUCCESS;\r
+ \r
+ON_ERROR:\r
+\r
+ HttpCleanProtocol (HttpInstance);\r
+ FreePool (HttpInstance);\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Destroys a child handle with a protocol installed on it.\r
+\r
+ The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r
+ that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r
+ last protocol on ChildHandle, then ChildHandle is destroyed.\r
+\r
+ @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
+ @param ChildHandle Handle of the child to destroy\r
+\r
+ @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
+ @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
+ @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
+ @retval other The child handle was not destroyed\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpServiceBindingDestroyChild (\r
+ IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ChildHandle\r
+ )\r
+{\r
+ HTTP_SERVICE *HttpService;\r
+ HTTP_PROTOCOL *HttpInstance;\r
+ EFI_HTTP_PROTOCOL *Http;\r
+ EFI_STATUS Status;\r
+ EFI_TPL OldTpl;\r
+ \r
+ if ((This == NULL) || (ChildHandle == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);\r
+ Status = gBS->OpenProtocol (\r
+ ChildHandle,\r
+ &gEfiHttpProtocolGuid,\r
+ (VOID **) &Http,\r
+ gHttpDxeDriverBinding.DriverBindingHandle,\r
+ ChildHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ \r
+ HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (Http);\r
+ if (HttpInstance->Service != HttpService) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (HttpInstance->InDestroy) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Close the Tcp4 protocol.\r
+ //\r
+ gBS->CloseProtocol (\r
+ HttpService->TcpChildHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ gHttpDxeDriverBinding.DriverBindingHandle,\r
+ ChildHandle\r
+ );\r
+ \r
+ HttpInstance->InDestroy = TRUE;\r
+\r
+ //\r
+ // Uninstall the HTTP protocol.\r
+ //\r
+ Status = gBS->UninstallProtocolInterface (\r
+ ChildHandle,\r
+ &gEfiHttpProtocolGuid,\r
+ Http\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ HttpInstance->InDestroy = FALSE;\r
+ return Status;\r
+ }\r
+\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+ HttpCleanProtocol (HttpInstance);\r
+\r
+ RemoveEntryList (&HttpInstance->Link);\r
+ HttpService->ChildrenNumber--;\r
+\r
+ gBS->RestoreTPL (OldTpl);\r
+ \r
+ FreePool (HttpInstance);\r
+ return EFI_SUCCESS;\r
+}\r