147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/** @file
247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  The driver binding and service binding protocol for HttpDxe driver.
347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
4c2adf51f004d2085df0cfa175d2ca95e140999a2Giri P Mudusuru  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5d8293d31416242468323ef30c6fa2a5bf6267996Nagaraj Hegde  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  This program and the accompanying materials
847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  are licensed and made available under the terms and conditions of the BSD License
947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  which accompanies this distribution.  The full text of the license may be found at
1047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  http://opensource.org/licenses/bsd-license.php.
1147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
1247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
1347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
1447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
1547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
1647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
1747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting#include "HttpDriver.h"
1847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
195ca29abe529794c1c2a2663378b0719e902c1077Jiaxin WuEFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;
205ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
2147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting///
2247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/// Driver Binding Protocol instance
2347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting///
24b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp4DriverBinding = {
25b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp4DriverBindingSupported,
26b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp4DriverBindingStart,
27b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp4DriverBindingStop,
2847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_DRIVER_VERSION,
2947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  NULL,
3047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  NULL
3147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting};
3247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
33b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp6DriverBinding = {
34b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp6DriverBindingSupported,
35b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp6DriverBindingStart,
36b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp6DriverBindingStop,
37b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HTTP_DRIVER_VERSION,
38b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  NULL,
39b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  NULL
40b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo};
41b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
42b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
4347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
4447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Create a HTTP driver service binding private instance.
4547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
4647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  Controller         The controller that has TCP4 service binding
4747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                 installed.
4847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  ImageHandle        The HTTP driver's image handle.
4947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[out] ServiceData        Point to HTTP driver private instance.
5047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
5147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_OUT_OF_RESOURCES   Failed to allocate some resources.
5247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCESS            A new HTTP driver private instance is created.
5347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
5447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
5547f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
5647f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingHttpCreateService (
5747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN  EFI_HANDLE            Controller,
5847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN  EFI_HANDLE            ImageHandle,
5947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  OUT HTTP_SERVICE          **ServiceData
6047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
6147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
6247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_SERVICE     *HttpService;
6347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
6447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  ASSERT (ServiceData != NULL);
6547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  *ServiceData = NULL;
6647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
6747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService = AllocateZeroPool (sizeof (HTTP_SERVICE));
6847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (HttpService == NULL) {
6947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_OUT_OF_RESOURCES;
7047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
7147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
7247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->Signature = HTTP_SERVICE_SIGNATURE;
7347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ServiceBinding.CreateChild = HttpServiceBindingCreateChild;
7447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ServiceBinding.DestroyChild = HttpServiceBindingDestroyChild;
7547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ImageHandle = ImageHandle;
7647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ControllerHandle = Controller;
7747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ChildrenNumber = 0;
7847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  InitializeListHead (&HttpService->ChildrenList);
7947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
8047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  *ServiceData = HttpService;
8147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  return EFI_SUCCESS;
8247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
8347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
8447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
8547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Release all the resource used the HTTP service binding instance.
8647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
87b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  HttpService        The HTTP private instance.
88b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  UsingIpv6          Indicate use TCP4 protocol or TCP6 protocol.
89b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                 if TRUE, use Tcp6 protocol.
90b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                 if FALSE, use Tcp4 protocl.
9147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
9247f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingVOID
9347f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingHttpCleanService (
94b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN HTTP_SERVICE     *HttpService,
95b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN BOOLEAN          UsingIpv6
9647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
97b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
98b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
993fd7bd08f438130f9fcbcc1ab4392dea1a859c14fanwang  if (HttpService == NULL) {
10047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return ;
10147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
102b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (!UsingIpv6) {
103b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (HttpService->Tcp4ChildHandle != NULL) {
104b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      gBS->CloseProtocol (
105b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             HttpService->Tcp4ChildHandle,
106b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gEfiTcp4ProtocolGuid,
107b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             HttpService->ImageHandle,
108b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             HttpService->ControllerHandle
109b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             );
110b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
111b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      NetLibDestroyServiceChild (
112b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        HttpService->ControllerHandle,
113b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        HttpService->ImageHandle,
114b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        &gEfiTcp4ServiceBindingProtocolGuid,
115b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        HttpService->Tcp4ChildHandle
116b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        );
117b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
118b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      HttpService->Tcp4ChildHandle = NULL;
119b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
120b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  } else {
121b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (HttpService->Tcp6ChildHandle != NULL) {
122b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      gBS->CloseProtocol (
123b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             HttpService->Tcp6ChildHandle,
124b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gEfiTcp6ProtocolGuid,
125b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             HttpService->ImageHandle,
126b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             HttpService->ControllerHandle
127b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             );
128b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
129b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      NetLibDestroyServiceChild (
130b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        HttpService->ControllerHandle,
131b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        HttpService->ImageHandle,
132b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        &gEfiTcp6ServiceBindingProtocolGuid,
133b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        HttpService->Tcp6ChildHandle
134b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        );
135b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
136b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      HttpService->Tcp6ChildHandle = NULL;
137b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
13847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
139b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
14047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
14147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
14247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
1435ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  The event process routine when the http utilities protocol is installed
1445ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  in the system.
1455ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
1465ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  @param[in]     Event         Not used.
147b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]     Context       The pointer to the IP4 config2 instance data or IP6 Config instance data.
1485ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
1495ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu**/
1505ca29abe529794c1c2a2663378b0719e902c1077Jiaxin WuVOID
1515ca29abe529794c1c2a2663378b0719e902c1077Jiaxin WuEFIAPI
1525ca29abe529794c1c2a2663378b0719e902c1077Jiaxin WuHttpUtilitiesInstalledCallback (
1535ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  IN EFI_EVENT  Event,
1545ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  IN VOID       *Context
1555ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  )
1565ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu{
1575ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  gBS->LocateProtocol (
1585ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         &gEfiHttpUtilitiesProtocolGuid,
1595ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         NULL,
1605ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         (VOID **) &mHttpUtilities
1615ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         );
162b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
1635ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  //
1645ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  // Close the event if Http utilities protocol is loacted.
1655ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  //
1665ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  if (mHttpUtilities != NULL && Event != NULL) {
1675ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu     gBS->CloseEvent (Event);
1685ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  }
1695ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu}
1705ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
1715ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu/**
17247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  This is the declaration of an EFI image entry point. This entry point is
17347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
17447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  both device drivers and bus drivers.
17547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
17647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param  ImageHandle           The firmware allocated handle for the UEFI image.
17747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param  SystemTable           A pointer to the EFI System Table.
17847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
17947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCESS           The operation completed successfully.
18047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval Others                An unexpected error occurred.
18147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
18247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
18347f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
18447f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
18547f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingHttpDxeDriverEntryPoint (
18647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_HANDLE        ImageHandle,
18747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_SYSTEM_TABLE  *SystemTable
18847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
1895ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu{
190b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_STATUS     Status;
1915ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  VOID           *Registration;
1925ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
1935ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  gBS->LocateProtocol (
1945ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         &gEfiHttpUtilitiesProtocolGuid,
1955ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         NULL,
1965ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         (VOID **) &mHttpUtilities
1975ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu         );
1985ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
1995ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  if (mHttpUtilities == NULL) {
2005ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu    //
2015ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu    // No Http utilities protocol, register a notify.
2025ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu    //
2035ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu    EfiCreateProtocolNotifyEvent (
2045ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu      &gEfiHttpUtilitiesProtocolGuid,
2055ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu      TPL_CALLBACK,
2065ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu      HttpUtilitiesInstalledCallback,
2075ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu      NULL,
2085ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu      &Registration
2095ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu      );
2105ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu  }
2115ca29abe529794c1c2a2663378b0719e902c1077Jiaxin Wu
21247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
21347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  // Install UEFI Driver Model protocol(s).
21447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
215b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Status = EfiLibInstallDriverBindingComponentName2 (
216b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             ImageHandle,
217b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             SystemTable,
218b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gHttpDxeIp4DriverBinding,
219b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             ImageHandle,
220b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gHttpDxeComponentName,
221b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gHttpDxeComponentName2
222b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             );
223b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (EFI_ERROR (Status)) {
224b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    return Status;
225b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
226b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
227b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Status = EfiLibInstallDriverBindingComponentName2 (
228b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             ImageHandle,
229b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             SystemTable,
230b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gHttpDxeIp6DriverBinding,
231b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             NULL,
232b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gHttpDxeComponentName,
233b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             &gHttpDxeComponentName2
234b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo             );
235b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (EFI_ERROR (Status)) {
236b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    gBS->UninstallMultipleProtocolInterfaces (
23747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting           ImageHandle,
238b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           &gEfiDriverBindingProtocolGuid,
239b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           &gHttpDxeIp4DriverBinding,
240b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           &gEfiComponentName2ProtocolGuid,
241b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           &gHttpDxeComponentName2,
242b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           &gEfiComponentNameProtocolGuid,
24347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting           &gHttpDxeComponentName,
244b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           NULL
24547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting           );
246b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
247b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return Status;
24847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
24947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
25047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
25147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Callback function which provided by user to remove one node in NetDestroyLinkList process.
25247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
25347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]    Entry           The entry to be removed.
25447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]    Context         Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
25547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
25647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_INVALID_PARAMETER Any input parameter is NULL.
25747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCESS           The entry has been removed successfully.
25847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval Others                Fail to remove the entry.
25947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
26047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
26147f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
26247f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
26347f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingHttpDestroyChildEntryInHandleBuffer (
26447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN LIST_ENTRY         *Entry,
26547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN VOID               *Context
26647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
26747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
26847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_PROTOCOL                 *HttpInstance;
26947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;
27047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  UINTN                         NumberOfChildren;
27147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_HANDLE                    *ChildHandleBuffer;
27247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
27347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (Entry == NULL || Context == NULL) {
27447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_INVALID_PARAMETER;
27547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
27647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
27747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpInstance = NET_LIST_USER_STRUCT_S (Entry, HTTP_PROTOCOL, Link, HTTP_PROTOCOL_SIGNATURE);
27847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  ServiceBinding    = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
27947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  NumberOfChildren  = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
28047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  ChildHandleBuffer = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
28147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
28247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (!NetIsInHandleBuffer (HttpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) {
28347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_SUCCESS;
28447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
28547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
28647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);
28747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
28847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
28947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
290b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Test to see if this driver supports ControllerHandle. This is the worker function for
291b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp4(6)DriverBindingSupported.
292b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
293b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  This                The pointer to the driver binding protocol.
294b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ControllerHandle    The handle of device to be tested.
295b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  RemainingDevicePath Optional parameter used to pick a specific child
296b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                  device to be started.
297b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  IpVersion           IP_VERSION_4 or IP_VERSION_6.
298b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
299b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_SUCCESS         This driver supports this device.
300b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_UNSUPPORTED     This driver does not support this device.
301b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
302b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo**/
303b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_STATUS
304b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFIAPI
305b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeSupported (
306b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
307b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   ControllerHandle,
308b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL,
309b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN UINT8                        IpVersion
310b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  )
311b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
312b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_STATUS                      Status;
313b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_GUID                        *TcpServiceBindingProtocolGuid;
314b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
315b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (IpVersion == IP_VERSION_4) {
316b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    TcpServiceBindingProtocolGuid = &gEfiTcp4ServiceBindingProtocolGuid;
317b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  } else {
318b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    TcpServiceBindingProtocolGuid = &gEfiTcp6ServiceBindingProtocolGuid;
319b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
320b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
321b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Status = gBS->OpenProtocol (
322b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                ControllerHandle,
323b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                TcpServiceBindingProtocolGuid,
324b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                NULL,
325b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                This->DriverBindingHandle,
326b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                ControllerHandle,
327b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                EFI_OPEN_PROTOCOL_TEST_PROTOCOL
328b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                );
329b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
330b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (EFI_ERROR (Status)) {
331b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    return EFI_UNSUPPORTED;
332b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
333b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
334b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return EFI_SUCCESS;
335b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo}
336b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
337b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo/**
338b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Start this driver on ControllerHandle. This is the worker function for
339b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp4(6)DriverBindingStart.
340b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
341b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  This                 The pointer to the driver binding protocol.
342b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ControllerHandle     The handle of device to be started.
343b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  RemainingDevicePath  Optional parameter used to pick a specific child
344b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   device to be started.
345b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  IpVersion            IP_VERSION_4 or IP_VERSION_6.
346b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
347b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
348b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_SUCCESS          This driver is installed to ControllerHandle.
349b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle.
350b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval other                This driver does not support this device.
351b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
352b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo**/
353b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_STATUS
354b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFIAPI
355b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeStart (
356b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
357b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   ControllerHandle,
358b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL,
359b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN UINT8                        IpVersion
360b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  )
361b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
362b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_STATUS                      Status;
363b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_SERVICE_BINDING_PROTOCOL    *ServiceBinding;
364b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HTTP_SERVICE                    *HttpService;
365b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  VOID                            *Interface;
366b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  BOOLEAN                         UsingIpv6;
367b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
368b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  UsingIpv6 = FALSE;
369b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
370b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  //
371b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  // Test for the Http service binding protocol
372b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  //
373b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Status = gBS->OpenProtocol (
374b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  ControllerHandle,
375b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  &gEfiHttpServiceBindingProtocolGuid,
376b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  (VOID **) &ServiceBinding,
377b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  This->DriverBindingHandle,
378b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  ControllerHandle,
379b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
380b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  );
381b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
382b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (!EFI_ERROR (Status)) {
383b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
384b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  } else {
385b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    Status = HttpCreateService (ControllerHandle, This->DriverBindingHandle, &HttpService);
386b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (EFI_ERROR (Status)) {
387b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      return Status;
388b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
389b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
390b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    ASSERT (HttpService != NULL);
391b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
392b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    //
393b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    // Install the HttpServiceBinding Protocol onto Controller
394b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    //
395b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    Status = gBS->InstallMultipleProtocolInterfaces (
396b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                    &ControllerHandle,
397b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                    &gEfiHttpServiceBindingProtocolGuid,
398b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                    &HttpService->ServiceBinding,
399b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                    NULL
400b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                    );
401b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
402b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (EFI_ERROR (Status)) {
403b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      goto ON_ERROR;
404b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
405b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
406b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
407b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (IpVersion == IP_VERSION_4) {
408b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
409b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (HttpService->Tcp4ChildHandle == NULL) {
410b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      //
411b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      // Create a TCP4 child instance, but do not configure it. This will establish the parent-child relationship.
412b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      //
413b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Status = NetLibCreateServiceChild (
414b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 ControllerHandle,
415b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 This->DriverBindingHandle,
416b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 &gEfiTcp4ServiceBindingProtocolGuid,
417b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 &HttpService->Tcp4ChildHandle
418b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 );
419b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
420b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      if (EFI_ERROR (Status)) {
421b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        goto ON_ERROR;
422b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      }
423b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
424b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Status = gBS->OpenProtocol (
425b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      HttpService->Tcp4ChildHandle,
426b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      &gEfiTcp4ProtocolGuid,
427b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      &Interface,
428b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      This->DriverBindingHandle,
429b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      ControllerHandle,
430b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      EFI_OPEN_PROTOCOL_BY_DRIVER
431b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      );
432b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
433b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      if (EFI_ERROR (Status)) {
434b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        goto ON_ERROR;
435b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      }
436b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
437b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    } else {
438b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      return EFI_ALREADY_STARTED;
439b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
440b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
441b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  } else {
442b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    UsingIpv6 = TRUE;
443b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
444b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (HttpService->Tcp6ChildHandle == NULL) {
445b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      //
446b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      // Create a TCP6 child instance, but do not configure it. This will establish the parent-child relationship.
447b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      //
448b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Status = NetLibCreateServiceChild (
449b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 ControllerHandle,
450b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 This->DriverBindingHandle,
451b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 &gEfiTcp6ServiceBindingProtocolGuid,
452b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 &HttpService->Tcp6ChildHandle
453b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 );
454b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
455b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      if (EFI_ERROR (Status)) {
456b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        goto ON_ERROR;
457b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      }
458b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
459b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Status = gBS->OpenProtocol (
460b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      HttpService->Tcp6ChildHandle,
461b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      &gEfiTcp6ProtocolGuid,
462b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      &Interface,
463b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      This->DriverBindingHandle,
464b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      ControllerHandle,
465b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      EFI_OPEN_PROTOCOL_BY_DRIVER
466b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                      );
467b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
468b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      if (EFI_ERROR (Status)) {
469b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        goto ON_ERROR;
470b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      }
471b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
472b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    } else {
473b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      return EFI_ALREADY_STARTED;
474b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
475b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
476b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
477b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
478b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return EFI_SUCCESS;
479b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
480b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboON_ERROR:
481b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
482b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (HttpService != NULL) {
483b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    HttpCleanService (HttpService, UsingIpv6);
484b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {
485b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      FreePool (HttpService);
486b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
487b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
488b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
489b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return Status;
490b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
491b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
492b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo}
493b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
494b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo/**
495b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Stop this driver on ControllerHandle. This is the worker function for
496b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpDxeIp4(6)DriverBindingStop.
497b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
498b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  This              Protocol instance pointer.
499b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ControllerHandle  Handle of device to stop driver on.
500b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of
501b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                children is zero stop the entire bus driver.
502b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ChildHandleBuffer List of Child Handles to Stop.
503b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  IpVersion         IP_VERSION_4 or IP_VERSION_6.
504b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
505b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_SUCCESS           This driver was removed ControllerHandle.
506b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.
507b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval Others                This driver was not removed from this device
508b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
509b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo**/
510b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_STATUS
511b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFIAPI
512b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeStop (
513b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
514b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   ControllerHandle,
515b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN UINTN                        NumberOfChildren,
516b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   *ChildHandleBuffer,
517b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN UINT8                        IpVersion
518b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  )
519b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
520b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_HANDLE                                 NicHandle;
521b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_STATUS                                 Status;
522b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  EFI_SERVICE_BINDING_PROTOCOL               *ServiceBinding;
523b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HTTP_SERVICE                               *HttpService;
524b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  LIST_ENTRY                                 *List;
525b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT   Context;
526b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  BOOLEAN                                    UsingIpv6;
527b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
528b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  //
529b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  // HTTP driver opens TCP4(6) child, So, Controller is a TCP4(6)
530b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  // child handle. Locate the Nic handle first. Then get the
531b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  // HTTP private data back.
532b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  //
533b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (IpVersion == IP_VERSION_4) {
534b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    UsingIpv6 = FALSE;
535b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
536b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  } else {
537b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    UsingIpv6 = TRUE;
538b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);
539b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
540b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
541b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (NicHandle == NULL) {
542b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    return EFI_SUCCESS;
543b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
544b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
545b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Status = gBS->OpenProtocol (
546b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  NicHandle,
547b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  &gEfiHttpServiceBindingProtocolGuid,
548b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  (VOID **) &ServiceBinding,
549b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  This->DriverBindingHandle,
550b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  NicHandle,
551b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
552b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  );
553b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
554b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  if (!EFI_ERROR (Status)) {
555b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
556b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);
557b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
558b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    if (NumberOfChildren != 0) {
559b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      //
560b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      // Destroy the HTTP child instance in ChildHandleBuffer.
561b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      //
562b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      List = &HttpService->ChildrenList;
563b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Context.ServiceBinding    = ServiceBinding;
564b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Context.NumberOfChildren  = NumberOfChildren;
565b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Context.ChildHandleBuffer = ChildHandleBuffer;
566b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Status = NetDestroyLinkList (
567b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 List,
568b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 HttpDestroyChildEntryInHandleBuffer,
569b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 &Context,
570b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 NULL
571b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                 );
572b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    } else {
573b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
574b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      HttpCleanService (HttpService, UsingIpv6);
575b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
576b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {
577b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        gBS->UninstallProtocolInterface (
578b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo               NicHandle,
579b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo               &gEfiHttpServiceBindingProtocolGuid,
580b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo               ServiceBinding
581b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo               );
582b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo        FreePool (HttpService);
583b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      }
584b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo      Status = EFI_SUCCESS;
585b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo    }
586b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  }
587b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
588b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return Status;
589b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
590b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo}
591b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
592b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo/**
59347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Tests to see if this driver supports a given controller. If a child device is provided,
59447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  it further tests to see if this driver supports creating a handle for the specified child device.
59547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
59647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  This function checks to see if the driver specified by This supports the device specified by
59747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  ControllerHandle. Drivers will typically use the device path attached to
59847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  ControllerHandle and/or the services from the bus I/O abstraction attached to
59947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  ControllerHandle to determine if the driver supports ControllerHandle. This function
60047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  may be called many times during platform initialization. In order to reduce boot times, the tests
60147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  performed by this function must be very small, and take as little time as possible to execute. This
60247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  function must not change the state of any hardware devices, and this function must be aware that the
60347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  device specified by ControllerHandle may already be managed by the same driver or a
60447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  different driver. This function must match its calls to AllocatePages() with FreePages(),
60547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
60647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Because ControllerHandle may have been previously started by the same driver, if a protocol is
60747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  already in the opened state, then it must not be closed with CloseProtocol(). This is required
60847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  to guarantee the state of ControllerHandle is not modified by this function.
60947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
61047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
61147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  ControllerHandle     The handle of the controller to test. This handle
61247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   must support a protocol interface that supplies
61347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   an I/O abstraction to the driver.
61447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
61547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   parameter is ignored by device drivers, and is optional for bus
61647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   drivers. For bus drivers, if this parameter is not NULL, then
61747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   the bus driver must determine if the bus controller specified
61847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   by ControllerHandle and the child controller specified
61947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   by RemainingDevicePath are both supported by this
62047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   bus driver.
62147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
62247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCESS              The device specified by ControllerHandle and
62347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   RemainingDevicePath is supported by the driver specified by This.
62447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and
62547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   RemainingDevicePath is already being managed by the driver
62647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   specified by This.
62747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and
62847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   RemainingDevicePath is already being managed by a different
62947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   driver or an application that requires exclusive access.
63047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   Currently not implemented.
63147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and
63247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   RemainingDevicePath is not supported by the driver specified by This.
63347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
63447f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
63547f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
636b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeIp4DriverBindingSupported (
63747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
63847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_HANDLE                   ControllerHandle,
63947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
64047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
64147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
642b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return HttpDxeSupported (
643b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           This,
644b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ControllerHandle,
645b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           RemainingDevicePath,
646b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           IP_VERSION_4
647b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           );
64847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
64947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
65047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
65147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Starts a device controller or a bus controller.
65247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
65347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  The Start() function is designed to be invoked from the EFI boot service ConnectController().
65447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  As a result, much of the error checking on the parameters to Start() has been moved into this
65547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  common boot service. It is legal to call Start() from other locations,
65647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  but the following calling restrictions must be followed, or the system behavior will not be deterministic.
65747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  1. ControllerHandle must be a valid EFI_HANDLE.
65847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
65947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting     EFI_DEVICE_PATH_PROTOCOL.
66047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  3. Prior to calling Start(), the Supported() function for the driver specified by This must
66147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
66247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
66347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
66447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  ControllerHandle     The handle of the controller to start. This handle
66547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   must support a protocol interface that supplies
66647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   an I/O abstraction to the driver.
66747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
66847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   parameter is ignored by device drivers, and is optional for bus
66947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   drivers. For a bus driver, if this parameter is NULL, then handles
67047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   for all the children of Controller are created by this driver.
67147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   If this parameter is not NULL and the first Device Path Node is
67247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   not the End of Device Path Node, then only the handle for the
67347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   child device specified by the first Device Path Node of
67447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   RemainingDevicePath is created by this driver.
67547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   If the first Device Path Node of RemainingDevicePath is
67647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   the End of Device Path Node, no child handle is created by this
67747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                   driver.
67847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
67947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCESS              The device was started.
68047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_ALREADY_STARTED      This device is already running on ControllerHandle.
68147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.
68247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.
68347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval Others                   The driver failded to start the device.
68447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
68547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
68647f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
68747f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
688b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeIp4DriverBindingStart (
68947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
69047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_HANDLE                   ControllerHandle,
69147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
69247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
69347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
694b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return HttpDxeStart (
695b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           This,
696b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ControllerHandle,
697b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           RemainingDevicePath,
698b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           IP_VERSION_4
699b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           );
700b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo}
701b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
702b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo/**
703b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Stops a device controller or a bus controller.
70447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
705b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
706b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  As a result, much of the error checking on the parameters to Stop() has been moved
707b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  into this common boot service. It is legal to call Stop() from other locations,
708b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  but the following calling restrictions must be followed, or the system behavior will not be deterministic.
709b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
710b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo     same driver's Start() function.
711b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
712b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo     EFI_HANDLE. In addition, all of these handles must have been created in this driver's
713b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo     Start() function, and the Start() function must have called OpenProtocol() on
714b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
715b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
716b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
717b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
718b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                support a bus specific I/O protocol for the driver
719b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                to use to stop the device.
720b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
721b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
722b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                if NumberOfChildren is 0.
72347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
724b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_SUCCESS           The device was stopped.
725b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
72647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
727b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo**/
728b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_STATUS
729b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFIAPI
730b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeIp4DriverBindingStop (
731b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
732b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   ControllerHandle,
733b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN UINTN                        NumberOfChildren,
734b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL
735b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  )
736b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
737b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return HttpDxeStop (
738b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           This,
739b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ControllerHandle,
740b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           NumberOfChildren,
741b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ChildHandleBuffer,
742b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           IP_VERSION_4
743b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           );
744b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo}
74547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
746b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo/**
747b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Tests to see if this driver supports a given controller. If a child device is provided,
748b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  it further tests to see if this driver supports creating a handle for the specified child device.
74947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
750b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  This function checks to see if the driver specified by This supports the device specified by
751b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  ControllerHandle. Drivers will typically use the device path attached to
752b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  ControllerHandle and/or the services from the bus I/O abstraction attached to
753b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  ControllerHandle to determine if the driver supports ControllerHandle. This function
754b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  may be called many times during platform initialization. In order to reduce boot times, the tests
755b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  performed by this function must be very small, and take as little time as possible to execute. This
756b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  function must not change the state of any hardware devices, and this function must be aware that the
757b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  device specified by ControllerHandle may already be managed by the same driver or a
758b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  different driver. This function must match its calls to AllocatePages() with FreePages(),
759b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
760b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Because ControllerHandle may have been previously started by the same driver, if a protocol is
761b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  already in the opened state, then it must not be closed with CloseProtocol(). This is required
762b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  to guarantee the state of ControllerHandle is not modified by this function.
76347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
764b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
765b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ControllerHandle     The handle of the controller to test. This handle
766b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   must support a protocol interface that supplies
767b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   an I/O abstraction to the driver.
768b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
769b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   parameter is ignored by device drivers, and is optional for bus
770b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   drivers. For bus drivers, if this parameter is not NULL, then
771b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   the bus driver must determine if the bus controller specified
772b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   by ControllerHandle and the child controller specified
773b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   by RemainingDevicePath are both supported by this
774b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   bus driver.
77547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
776b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_SUCCESS              The device specified by ControllerHandle and
777b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   RemainingDevicePath is supported by the driver specified by This.
778b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and
779b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   RemainingDevicePath is already being managed by the driver
780b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   specified by This.
781b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and
782b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   RemainingDevicePath is already being managed by a different
783b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   driver or an application that requires exclusive access.
784b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   Currently not implemented.
785b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and
786b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   RemainingDevicePath is not supported by the driver specified by This.
787b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo**/
788b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_STATUS
789b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFIAPI
790b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeIp6DriverBindingSupported (
791b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
792b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   ControllerHandle,
793b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
794b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  )
795b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
796b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return HttpDxeSupported (
797b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           This,
798b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ControllerHandle,
799b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           RemainingDevicePath,
800b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           IP_VERSION_6
801b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           );
80247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
803b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo}
80447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
805b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo/**
806b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  Starts a device controller or a bus controller.
80747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
808b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  The Start() function is designed to be invoked from the EFI boot service ConnectController().
809b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  As a result, much of the error checking on the parameters to Start() has been moved into this
810b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  common boot service. It is legal to call Start() from other locations,
811b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  but the following calling restrictions must be followed, or the system behavior will not be deterministic.
812b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  1. ControllerHandle must be a valid EFI_HANDLE.
813b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
814b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo     EFI_DEVICE_PATH_PROTOCOL.
815b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  3. Prior to calling Start(), the Supported() function for the driver specified by This must
816b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
81747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
818b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
819b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  ControllerHandle     The handle of the controller to start. This handle
820b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   must support a protocol interface that supplies
821b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   an I/O abstraction to the driver.
822b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
823b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   parameter is ignored by device drivers, and is optional for bus
824b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   drivers. For a bus driver, if this parameter is NULL, then handles
825b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   for all the children of Controller are created by this driver.
826b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   If this parameter is not NULL and the first Device Path Node is
827b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   not the End of Device Path Node, then only the handle for the
828b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   child device specified by the first Device Path Node of
829b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   RemainingDevicePath is created by this driver.
830b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   If the first Device Path Node of RemainingDevicePath is
831b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   the End of Device Path Node, no child handle is created by this
832b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                                   driver.
83347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
834b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_SUCCESS              The device was started.
835b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_ALREADY_STARTED      This device is already running on ControllerHandle.
836b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.
837b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.
838b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  @retval Others                   The driver failded to start the device.
839b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
840b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo**/
841b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFI_STATUS
842b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboEFIAPI
843b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeIp6DriverBindingStart (
844b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
845b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_HANDLE                   ControllerHandle,
846b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
847b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  )
848b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo{
849b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return HttpDxeStart (
850b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           This,
851b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ControllerHandle,
852b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           RemainingDevicePath,
853b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           IP_VERSION_6
854b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           );
85547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
85647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
85747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
85847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Stops a device controller or a bus controller.
85947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
86047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
86147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  As a result, much of the error checking on the parameters to Stop() has been moved
86247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  into this common boot service. It is legal to call Stop() from other locations,
86347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  but the following calling restrictions must be followed, or the system behavior will not be deterministic.
86447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
86547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting     same driver's Start() function.
86647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
86747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting     EFI_HANDLE. In addition, all of these handles must have been created in this driver's
86847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting     Start() function, and the Start() function must have called OpenProtocol() on
86947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
87047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
87147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
87247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
87347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                support a bus specific I/O protocol for the driver
87447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                to use to stop the device.
87547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
87647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
87747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                if NumberOfChildren is 0.
87847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
87947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCESS           The device was stopped.
88047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
88147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
88247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
88347f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
88447f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
885b659408b933f40765960e877de3e1f8ceaab52cbZhang LuboHttpDxeIp6DriverBindingStop (
88647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
88747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_HANDLE                   ControllerHandle,
88847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN UINTN                        NumberOfChildren,
88947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL
89047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
89147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
892b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  return HttpDxeStop (
893b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           This,
894b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ControllerHandle,
895b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           NumberOfChildren,
896b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           ChildHandleBuffer,
897b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo           IP_VERSION_6
89847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting           );
89947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
90047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
90147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Creates a child handle and installs a protocol.
90247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
90347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  The CreateChild() function installs a protocol on ChildHandle.
90447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
90547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
90647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
90747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param  This        Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
90847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param  ChildHandle Pointer to the handle of the child to create. If it is NULL,
90947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                      then a new handle is created. If it is a pointer to an existing UEFI handle,
91047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                      then the protocol is added to the existing UEFI handle.
91147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
91247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCES            The protocol was added to ChildHandle.
91347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_INVALID_PARAMETER This is NULL, or ChildHandle is NULL.
914c2adf51f004d2085df0cfa175d2ca95e140999a2Giri P Mudusuru  @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to create
91547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                                the child.
91647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval other                 The child handle was not created.
91747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
91847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
91947f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
92047f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
92147f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingHttpServiceBindingCreateChild (
92247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_SERVICE_BINDING_PROTOCOL  *This,
92347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN OUT EFI_HANDLE                *ChildHandle
92447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
92547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
92647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_SERVICE         *HttpService;
92747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_PROTOCOL        *HttpInstance;
92847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_STATUS           Status;
92947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_TPL              OldTpl;
93047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
93147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if ((This == NULL) || (ChildHandle == NULL)) {
93247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_INVALID_PARAMETER;
93347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
93447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
93547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService  = HTTP_SERVICE_FROM_PROTOCOL (This);
93647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpInstance = AllocateZeroPool (sizeof (HTTP_PROTOCOL));
93747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (HttpInstance == NULL) {
93847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_OUT_OF_RESOURCES;
93947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
940b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
941b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;
942b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpInstance->Service   = HttpService;
943d8293d31416242468323ef30c6fa2a5bf6267996Nagaraj Hegde  HttpInstance->Method = HttpMethodMax;
944d8293d31416242468323ef30c6fa2a5bf6267996Nagaraj Hegde
945b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  CopyMem (&HttpInstance->Http, &mEfiHttpTemplate, sizeof (HttpInstance->Http));
946b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  NetMapInit (&HttpInstance->TxTokens);
947b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  NetMapInit (&HttpInstance->RxTokens);
94847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
94947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
95047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  // Install HTTP protocol onto ChildHandle
95147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
95247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Status = gBS->InstallMultipleProtocolInterfaces (
95347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  ChildHandle,
95447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  &gEfiHttpProtocolGuid,
95547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  &HttpInstance->Http,
95647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  NULL
95747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  );
95847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
95947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (EFI_ERROR (Status)) {
96047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    goto ON_ERROR;
96147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
96247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
963b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  HttpInstance->Handle    = *ChildHandle;
96447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
96547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
96647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  // Add it to the HTTP service's child list.
96747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
96847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
96947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
97047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  InsertTailList (&HttpService->ChildrenList, &HttpInstance->Link);
97147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ChildrenNumber++;
97247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
97347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  gBS->RestoreTPL (OldTpl);
97447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
97547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  return EFI_SUCCESS;
97647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
97747f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingON_ERROR:
978b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
979b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  NetMapClean (&HttpInstance->TxTokens);
980b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  NetMapClean (&HttpInstance->RxTokens);
98147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  FreePool (HttpInstance);
98247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
98347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  return Status;
98447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
98547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
98647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting/**
98747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Destroys a child handle with a protocol installed on it.
98847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
98947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
99047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  that was installed by CreateChild() from ChildHandle. If the removed protocol is the
99147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  last protocol on ChildHandle, then ChildHandle is destroyed.
99247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
99347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param  This        Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
99447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @param  ChildHandle Handle of the child to destroy
99547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
99647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_SUCCES            The protocol was removed from ChildHandle.
99747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_UNSUPPORTED       ChildHandle does not support the protocol that is being removed.
99847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval EFI_INVALID_PARAMETER Child handle is NULL.
99947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  @retval other                 The child handle was not destroyed
100047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
100147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting**/
100247f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFI_STATUS
100347f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingEFIAPI
100447f51a064fbb3d3226304380674b2bec3cb33ba1Ye TingHttpServiceBindingDestroyChild (
100547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_SERVICE_BINDING_PROTOCOL  *This,
100647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  IN EFI_HANDLE                    ChildHandle
100747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  )
100847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting{
100947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_SERVICE             *HttpService;
101047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HTTP_PROTOCOL            *HttpInstance;
101147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_HTTP_PROTOCOL        *Http;
101247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_STATUS                Status;
101347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  EFI_TPL                   OldTpl;
101447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
101547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if ((This == NULL) || (ChildHandle == NULL)) {
101647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_INVALID_PARAMETER;
101747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
101847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
101947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);
102047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Status = gBS->OpenProtocol (
102147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  ChildHandle,
102247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  &gEfiHttpProtocolGuid,
102347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  (VOID **) &Http,
1024b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  NULL,
1025b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo                  NULL,
102647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
102747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  );
102847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (EFI_ERROR (Status)) {
102947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_UNSUPPORTED;
103047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
103147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
103247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (Http);
103347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (HttpInstance->Service != HttpService) {
103447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_INVALID_PARAMETER;
103547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
103647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
103747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (HttpInstance->InDestroy) {
103847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return EFI_SUCCESS;
103947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
104047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
104147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpInstance->InDestroy = TRUE;
104247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
104347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
104447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  // Uninstall the HTTP protocol.
104547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  //
104647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  Status = gBS->UninstallProtocolInterface (
104747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  ChildHandle,
104847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  &gEfiHttpProtocolGuid,
104947f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  Http
105047f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting                  );
105147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
105247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  if (EFI_ERROR (Status)) {
105347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    HttpInstance->InDestroy = FALSE;
105447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting    return Status;
105547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  }
1056b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
105747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpCleanProtocol (HttpInstance);
1058b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
1059b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1060b659408b933f40765960e877de3e1f8ceaab52cbZhang Lubo
106147f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  RemoveEntryList (&HttpInstance->Link);
106247f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  HttpService->ChildrenNumber--;
106347f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
106447f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  gBS->RestoreTPL (OldTpl);
106547f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting
106647f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  FreePool (HttpInstance);
106747f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting  return EFI_SUCCESS;
106847f51a064fbb3d3226304380674b2bec3cb33ba1Ye Ting}
1069