]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpDriver.c
NetworkPkg:Enable Http Boot over Ipv6 stack
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpDriver.c
index bd1d04e78cc430acbba194d78f2e5eb9e9b8a5a3..2518f4e707b608e1726999d3b84f04ca93add447 100644 (file)
@@ -20,15 +20,25 @@ EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;
 ///\r
 /// Driver Binding Protocol instance\r
 ///\r
-EFI_DRIVER_BINDING_PROTOCOL gHttpDxeDriverBinding = {\r
-  HttpDxeDriverBindingSupported,\r
-  HttpDxeDriverBindingStart,\r
-  HttpDxeDriverBindingStop,\r
+EFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp4DriverBinding = {\r
+  HttpDxeIp4DriverBindingSupported,\r
+  HttpDxeIp4DriverBindingStart,\r
+  HttpDxeIp4DriverBindingStop,\r
   HTTP_DRIVER_VERSION,\r
   NULL,\r
   NULL\r
 };\r
 \r
+EFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp6DriverBinding = {\r
+  HttpDxeIp6DriverBindingSupported,\r
+  HttpDxeIp6DriverBindingStart,\r
+  HttpDxeIp6DriverBindingStop,\r
+  HTTP_DRIVER_VERSION,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
 /**\r
   Create a HTTP driver service binding private instance.\r
 \r
@@ -73,33 +83,59 @@ HttpCreateService (
 /**\r
   Release all the resource used the HTTP service binding instance.\r
 \r
-  @param  HttpService        The HTTP private instance.\r
-\r
+  @param[in]  HttpService        The HTTP private instance.\r
+  @param[in]  UsingIpv6          Indicate use TCP4 protocol or TCP6 protocol.\r
+                                 if TRUE, use Tcp6 protocol.\r
+                                 if FALSE, use Tcp4 protocl.\r
 **/\r
 VOID\r
 HttpCleanService (\r
-  IN HTTP_SERVICE     *HttpService\r
+  IN HTTP_SERVICE     *HttpService,\r
+  IN BOOLEAN          UsingIpv6\r
   )\r
-{\r
+{ \r
+  \r
   if (HttpService == NULL) {\r
     return ;\r
   }\r
-\r
-  if (HttpService->TcpChildHandle != NULL) {\r
-    gBS->CloseProtocol (\r
-           HttpService->TcpChildHandle,\r
-           &gEfiTcp4ProtocolGuid,\r
-           HttpService->ImageHandle,\r
-           HttpService->ControllerHandle\r
-           );\r
-\r
-    NetLibDestroyServiceChild (\r
-      HttpService->ControllerHandle,\r
-      HttpService->ImageHandle,\r
-      &gEfiTcp4ServiceBindingProtocolGuid,\r
-      HttpService->TcpChildHandle\r
-      );\r
+  if (!UsingIpv6) {\r
+    if (HttpService->Tcp4ChildHandle != NULL) {\r
+      gBS->CloseProtocol (\r
+             HttpService->Tcp4ChildHandle,\r
+             &gEfiTcp4ProtocolGuid,\r
+             HttpService->ImageHandle,\r
+             HttpService->ControllerHandle\r
+             );\r
+    \r
+      NetLibDestroyServiceChild (\r
+        HttpService->ControllerHandle,\r
+        HttpService->ImageHandle,\r
+        &gEfiTcp4ServiceBindingProtocolGuid,\r
+        HttpService->Tcp4ChildHandle\r
+        );\r
+      \r
+      HttpService->Tcp4ChildHandle = NULL;\r
+    }\r
+  } else {\r
+    if (HttpService->Tcp6ChildHandle != NULL) {\r
+      gBS->CloseProtocol (\r
+             HttpService->Tcp6ChildHandle,\r
+             &gEfiTcp6ProtocolGuid,\r
+             HttpService->ImageHandle,\r
+             HttpService->ControllerHandle\r
+             );\r
+    \r
+      NetLibDestroyServiceChild (\r
+        HttpService->ControllerHandle,\r
+        HttpService->ImageHandle,\r
+        &gEfiTcp6ServiceBindingProtocolGuid,\r
+        HttpService->Tcp6ChildHandle\r
+        );\r
+      \r
+      HttpService->Tcp6ChildHandle = NULL;\r
+    }\r
   }\r
+  \r
 }\r
 \r
 /**\r
@@ -107,7 +143,7 @@ HttpCleanService (
   in the system.\r
 \r
   @param[in]     Event         Not used.\r
-  @param[in]     Context       The pointer to the IP4 config2 instance data.\r
+  @param[in]     Context       The pointer to the IP4 config2 instance data or IP6 Config instance data.\r
 \r
 **/\r
 VOID\r
@@ -122,7 +158,7 @@ HttpUtilitiesInstalledCallback (
          NULL, \r
          (VOID **) &mHttpUtilities\r
          );\r
-                \r
\r
   //\r
   // Close the event if Http utilities protocol is loacted.\r
   //\r
@@ -150,6 +186,7 @@ HttpDxeDriverEntryPoint (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 { \r
+  EFI_STATUS     Status;\r
   VOID           *Registration;\r
 \r
   gBS->LocateProtocol (\r
@@ -174,14 +211,39 @@ HttpDxeDriverEntryPoint (
   //\r
   // Install UEFI Driver Model protocol(s).\r
   //\r
-  return EfiLibInstallDriverBindingComponentName2 (\r
-           ImageHandle,\r
-           SystemTable,\r
-           &gHttpDxeDriverBinding,\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gHttpDxeIp4DriverBinding,\r
+             ImageHandle,\r
+             &gHttpDxeComponentName,\r
+             &gHttpDxeComponentName2\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gHttpDxeIp6DriverBinding,\r
+             NULL,\r
+             &gHttpDxeComponentName,\r
+             &gHttpDxeComponentName2\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
            ImageHandle,\r
+           &gEfiDriverBindingProtocolGuid,\r
+           &gHttpDxeIp4DriverBinding,\r
+           &gEfiComponentName2ProtocolGuid,\r
+           &gHttpDxeComponentName2,\r
+           &gEfiComponentNameProtocolGuid,\r
            &gHttpDxeComponentName,\r
-           &gHttpDxeComponentName2\r
+           NULL\r
            );\r
+  }\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -223,6 +285,309 @@ HttpDestroyChildEntryInHandleBuffer (
   return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);\r
 }\r
 \r
+/**\r
+  Test to see if this driver supports ControllerHandle. This is the worker function for\r
+  HttpDxeIp4(6)DriverBindingSupported.\r
+\r
+  @param[in]  This                The pointer to the driver binding protocol.\r
+  @param[in]  ControllerHandle    The handle of device to be tested.\r
+  @param[in]  RemainingDevicePath Optional parameter used to pick a specific child\r
+                                  device to be started.\r
+  @param[in]  IpVersion           IP_VERSION_4 or IP_VERSION_6.\r
+  \r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval EFI_UNSUPPORTED     This driver does not support this device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL,\r
+  IN UINT8                        IpVersion\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_GUID                        *TcpServiceBindingProtocolGuid;\r
+\r
+  if (IpVersion == IP_VERSION_4) {\r
+    TcpServiceBindingProtocolGuid = &gEfiTcp4ServiceBindingProtocolGuid;\r
+  } else {\r
+    TcpServiceBindingProtocolGuid = &gEfiTcp6ServiceBindingProtocolGuid;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                ControllerHandle,\r
+                TcpServiceBindingProtocolGuid,\r
+                NULL,\r
+                This->DriverBindingHandle,\r
+                ControllerHandle,\r
+                EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Start this driver on ControllerHandle. This is the worker function for\r
+  HttpDxeIp4(6)DriverBindingStart.\r
+\r
+  @param[in]  This                 The pointer to the driver binding protocol.\r
+  @param[in]  ControllerHandle     The handle of device to be started.\r
+  @param[in]  RemainingDevicePath  Optional parameter used to pick a specific child\r
+                                   device to be started.\r
+  @param[in]  IpVersion            IP_VERSION_4 or IP_VERSION_6.\r
+\r
+\r
+  @retval EFI_SUCCESS          This driver is installed to ControllerHandle.\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle.\r
+  @retval other                This driver does not support this device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL,\r
+  IN UINT8                        IpVersion\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_SERVICE_BINDING_PROTOCOL    *ServiceBinding;\r
+  HTTP_SERVICE                    *HttpService;\r
+  VOID                            *Interface;\r
+  BOOLEAN                         UsingIpv6;\r
+\r
+  UsingIpv6 = FALSE;\r
+\r
+  //\r
+  // Test for the Http service binding protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiHttpServiceBindingProtocolGuid,\r
+                  (VOID **) &ServiceBinding,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);\r
+  } else {\r
+    Status = HttpCreateService (ControllerHandle, This->DriverBindingHandle, &HttpService);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    \r
+    ASSERT (HttpService != NULL);\r
+      \r
+    //\r
+    // Install the HttpServiceBinding Protocol onto Controller\r
+    //\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &ControllerHandle,\r
+                    &gEfiHttpServiceBindingProtocolGuid,\r
+                    &HttpService->ServiceBinding,\r
+                    NULL\r
+                    );\r
+    \r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_ERROR;\r
+    }\r
+  }\r
+\r
+  if (IpVersion == IP_VERSION_4) {\r
+    \r
+    if (HttpService->Tcp4ChildHandle == NULL) {\r
+      //\r
+      // Create a TCP4 child instance, but do not configure it. This will establish the parent-child relationship.\r
+      //\r
+      Status = NetLibCreateServiceChild (\r
+                 ControllerHandle,\r
+                 This->DriverBindingHandle,\r
+                 &gEfiTcp4ServiceBindingProtocolGuid,\r
+                 &HttpService->Tcp4ChildHandle\r
+                 );\r
+      \r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_ERROR;\r
+      }\r
+      \r
+      Status = gBS->OpenProtocol (\r
+                      HttpService->Tcp4ChildHandle,\r
+                      &gEfiTcp4ProtocolGuid,\r
+                      &Interface,\r
+                      This->DriverBindingHandle,\r
+                      ControllerHandle,\r
+                      EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                      );\r
+                      \r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_ERROR;\r
+      }\r
+      \r
+    } else {\r
+      return EFI_ALREADY_STARTED;\r
+    }\r
+\r
+  } else {\r
+    UsingIpv6 = TRUE;\r
+    \r
+    if (HttpService->Tcp6ChildHandle == NULL) {\r
+      //\r
+      // Create a TCP6 child instance, but do not configure it. This will establish the parent-child relationship.\r
+      //\r
+      Status = NetLibCreateServiceChild (\r
+                 ControllerHandle,\r
+                 This->DriverBindingHandle,\r
+                 &gEfiTcp6ServiceBindingProtocolGuid,\r
+                 &HttpService->Tcp6ChildHandle\r
+                 );\r
+      \r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_ERROR;\r
+      }\r
+      \r
+      Status = gBS->OpenProtocol (\r
+                      HttpService->Tcp6ChildHandle,\r
+                      &gEfiTcp6ProtocolGuid,\r
+                      &Interface,\r
+                      This->DriverBindingHandle,\r
+                      ControllerHandle,\r
+                      EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                      );\r
+                      \r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_ERROR;\r
+      }\r
+      \r
+    } else {\r
+      return EFI_ALREADY_STARTED;\r
+    }\r
+\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+  \r
+ON_ERROR:\r
+    \r
+  if (HttpService != NULL) {\r
+    HttpCleanService (HttpService, UsingIpv6);\r
+    if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {\r
+      FreePool (HttpService);\r
+    }\r
+  }\r
+      \r
+  return Status;\r
+\r
+\r
+}\r
+\r
+/**\r
+  Stop this driver on ControllerHandle. This is the worker function for\r
+  HttpDxeIp4(6)DriverBindingStop.\r
+\r
+  @param[in]  This              Protocol instance pointer.\r
+  @param[in]  ControllerHandle  Handle of device to stop driver on.\r
+  @param[in]  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                                children is zero stop the entire bus driver.\r
+  @param[in]  ChildHandleBuffer List of Child Handles to Stop.\r
+  @param[in]  IpVersion         IP_VERSION_4 or IP_VERSION_6.\r
+\r
+  @retval EFI_SUCCESS           This driver was removed ControllerHandle.\r
+  @retval EFI_DEVICE_ERROR      An unexpected system or network error occurred.\r
+  @retval Others                This driver was not removed from this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN UINTN                        NumberOfChildren,\r
+  IN EFI_HANDLE                   *ChildHandleBuffer,\r
+  IN UINT8                        IpVersion\r
+  )\r
+{\r
+  EFI_HANDLE                                 NicHandle;\r
+  EFI_STATUS                                 Status;\r
+  EFI_SERVICE_BINDING_PROTOCOL               *ServiceBinding;\r
+  HTTP_SERVICE                               *HttpService;\r
+  LIST_ENTRY                                 *List;\r
+  HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT   Context;\r
+  BOOLEAN                                    UsingIpv6;\r
+\r
+  //\r
+  // HTTP driver opens TCP4(6) child, So, Controller is a TCP4(6)\r
+  // child handle. Locate the Nic handle first. Then get the\r
+  // HTTP private data back.\r
+  //\r
+  if (IpVersion == IP_VERSION_4) {\r
+    UsingIpv6 = FALSE;\r
+    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
+  } else {\r
+    UsingIpv6 = TRUE;\r
+    NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);\r
+  }\r
+\r
+  if (NicHandle == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  NicHandle,\r
+                  &gEfiHttpServiceBindingProtocolGuid,\r
+                  (VOID **) &ServiceBinding,\r
+                  This->DriverBindingHandle,\r
+                  NicHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    \r
+    HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);\r
+    \r
+    if (NumberOfChildren != 0) {\r
+      //\r
+      // Destroy the HTTP child instance in ChildHandleBuffer.\r
+      //\r
+      List = &HttpService->ChildrenList;\r
+      Context.ServiceBinding    = ServiceBinding;\r
+      Context.NumberOfChildren  = NumberOfChildren;\r
+      Context.ChildHandleBuffer = ChildHandleBuffer;\r
+      Status = NetDestroyLinkList (\r
+                 List,\r
+                 HttpDestroyChildEntryInHandleBuffer,\r
+                 &Context,\r
+                 NULL\r
+                 );\r
+    } else {\r
+    \r
+      HttpCleanService (HttpService, UsingIpv6);\r
+      \r
+      if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {\r
+        gBS->UninstallProtocolInterface (\r
+               NicHandle,\r
+               &gEfiHttpServiceBindingProtocolGuid,\r
+               ServiceBinding\r
+               );\r
+        FreePool (HttpService);\r
+      }\r
+      Status = EFI_SUCCESS;\r
+    }  \r
+  }\r
+  \r
+  return Status;\r
+\r
+}\r
+\r
 /**\r
   Tests to see if this driver supports a given controller. If a child device is provided, \r
   it further tests to see if this driver supports creating a handle for the specified child device.\r
@@ -267,41 +632,18 @@ HttpDestroyChildEntryInHandleBuffer (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HttpDxeDriverBindingSupported (\r
+HttpDxeIp4DriverBindingSupported (\r
   IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN EFI_HANDLE                   ControllerHandle,\r
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS       Status;\r
-\r
-  //\r
-  // Test for the HttpServiceBinding protocol.\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  ControllerHandle,\r
-                  &gEfiHttpServiceBindingProtocolGuid,\r
-                  NULL,\r
-                  This->DriverBindingHandle,\r
-                  ControllerHandle,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    return EFI_ALREADY_STARTED;\r
-  }\r
-\r
-  //\r
-  // Test for the Tcp4 Protocol\r
-  //\r
-  return gBS->OpenProtocol (\r
-                ControllerHandle,\r
-                &gEfiTcp4ServiceBindingProtocolGuid,\r
-                NULL,\r
-                This->DriverBindingHandle,\r
-                ControllerHandle,\r
-                EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                );\r
-  \r
+  return HttpDxeSupported (\r
+           This,\r
+           ControllerHandle,\r
+           RemainingDevicePath,\r
+           IP_VERSION_4\r
+           );\r
 }\r
 \r
 /**\r
@@ -342,90 +684,173 @@ HttpDxeDriverBindingSupported (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HttpDxeDriverBindingStart (\r
+HttpDxeIp4DriverBindingStart (\r
   IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN EFI_HANDLE                   ControllerHandle,\r
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                      Status;\r
-  HTTP_SERVICE                    *HttpService;\r
-  VOID                            *Interface;\r
+  return HttpDxeStart (\r
+           This,\r
+           ControllerHandle,\r
+           RemainingDevicePath,\r
+           IP_VERSION_4\r
+           );\r
+}\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
   \r
-  //\r
-  // Test for the Http service binding protocol\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  ControllerHandle,\r
-                  &gEfiHttpServiceBindingProtocolGuid,\r
-                  NULL,\r
-                  This->DriverBindingHandle,\r
-                  ControllerHandle,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
+  As a result, much of the error checking on the parameters to Stop() has been moved \r
+  into this common boot service. It is legal to call Stop() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+  \r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
+                                support a bus specific I/O protocol for the driver \r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+                                if NumberOfChildren is 0.\r
 \r
-  if (Status == EFI_SUCCESS) {\r
-    return EFI_ALREADY_STARTED;\r
-  }\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
 \r
-  Status = HttpCreateService (ControllerHandle, This->DriverBindingHandle, &HttpService);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeIp4DriverBindingStop (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN UINTN                        NumberOfChildren,\r
+  IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL\r
+  )\r
+{\r
+  return HttpDxeStop (\r
+           This,\r
+           ControllerHandle,\r
+           NumberOfChildren,\r
+           ChildHandleBuffer,\r
+           IP_VERSION_4\r
+           );\r
+}\r
 \r
-  ASSERT (HttpService != NULL);\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
 \r
-  //\r
-  // Create a TCP child instance, but do not configure it. This will establish the parent-child relationship.\r
-  //\r
-  Status = NetLibCreateServiceChild (\r
-             ControllerHandle,\r
-             This->DriverBindingHandle,\r
-             &gEfiTcp4ServiceBindingProtocolGuid,\r
-             &HttpService->TcpChildHandle\r
-             );\r
+  This function checks to see if the driver specified by This supports the device specified by \r
+  ControllerHandle. Drivers will typically use the device path attached to \r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
+  may be called many times during platform initialization. In order to reduce boot times, the tests \r
+  performed by this function must be very small, and take as little time as possible to execute. This \r
+  function must not change the state of any hardware devices, and this function must be aware that the \r
+  device specified by ControllerHandle may already be managed by the same driver or a \r
+  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For bus drivers, if this parameter is not NULL, then \r
+                                   the bus driver must determine if the bus controller specified \r
+                                   by ControllerHandle and the child controller specified \r
+                                   by RemainingDevicePath are both supported by this \r
+                                   bus driver.\r
 \r
-  Status = gBS->OpenProtocol (\r
-                  HttpService->TcpChildHandle,\r
-                  &gEfiTcp4ProtocolGuid,\r
-                  &Interface,\r
-                  This->DriverBindingHandle,\r
-                  ControllerHandle,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                  );\r
-                  \r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeIp6DriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  )\r
+{  \r
+  return HttpDxeSupported (\r
+           This,\r
+           ControllerHandle,\r
+           RemainingDevicePath,\r
+           IP_VERSION_6\r
+           );\r
 \r
-  //\r
-  // Install the HttpServiceBinding Protocol onto Controller\r
-  //\r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &ControllerHandle,\r
-                  &gEfiHttpServiceBindingProtocolGuid,\r
-                  &HttpService->ServiceBinding,\r
-                  NULL\r
-                  );\r
+}\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
+/**\r
+  Starts a device controller or a bus controller.\r
 \r
-  return EFI_SUCCESS;\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this \r
+  common boot service. It is legal to call Start() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
 \r
-ON_ERROR:\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+                                   for all the children of Controller are created by this driver.  \r
+                                   If this parameter is not NULL and the first Device Path Node is \r
+                                   not the End of Device Path Node, then only the handle for the \r
+                                   child device specified by the first Device Path Node of \r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
 \r
-  if (HttpService != NULL) {\r
-    HttpCleanService (HttpService);\r
-    FreePool (HttpService);\r
-  }\r
-  \r
-  return Status;\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_ALREADY_STARTED      This device is already running on ControllerHandle.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpDxeIp6DriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  return HttpDxeStart (\r
+           This,\r
+           ControllerHandle,\r
+           RemainingDevicePath,\r
+           IP_VERSION_6\r
+           );\r
 }\r
 \r
 /**\r
@@ -456,78 +881,21 @@ ON_ERROR:
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HttpDxeDriverBindingStop (\r
+HttpDxeIp6DriverBindingStop (\r
   IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN EFI_HANDLE                   ControllerHandle,\r
   IN UINTN                        NumberOfChildren,\r
   IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL\r
   )\r
 {\r
-  EFI_HANDLE                                 NicHandle;\r
-  EFI_STATUS                                 Status;\r
-  EFI_SERVICE_BINDING_PROTOCOL               *ServiceBinding;\r
-  HTTP_SERVICE                               *HttpService;\r
-  LIST_ENTRY                                 *List;\r
-  HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT   Context;\r
-  \r
-  //\r
-  // HTTP driver opens TCP child, So, Controller is a TCP\r
-  // child handle. Locate the Nic handle first. Then get the\r
-  // HTTP private data back.\r
-  //\r
-  NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
-  if (NicHandle == NULL) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  Status = gBS->OpenProtocol (\r
-                  NicHandle,\r
-                  &gEfiHttpServiceBindingProtocolGuid,\r
-                  (VOID **) &ServiceBinding,\r
-                  This->DriverBindingHandle,\r
-                  NicHandle,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);\r
-\r
-  if (!IsListEmpty (&HttpService->ChildrenList)) {\r
-    //\r
-    // Destroy the HTTP child instance in ChildHandleBuffer.\r
-    //\r
-    List = &HttpService->ChildrenList;\r
-    Context.ServiceBinding    = ServiceBinding;\r
-    Context.NumberOfChildren  = NumberOfChildren;\r
-    Context.ChildHandleBuffer = ChildHandleBuffer;\r
-    Status = NetDestroyLinkList (\r
-               List,\r
-               HttpDestroyChildEntryInHandleBuffer,\r
-               &Context,\r
-               NULL\r
-               );\r
-  }\r
-\r
-  if (NumberOfChildren == 0 && IsListEmpty (&HttpService->ChildrenList)) {\r
-    gBS->UninstallProtocolInterface (\r
-           NicHandle,\r
-           &gEfiHttpServiceBindingProtocolGuid,\r
-           ServiceBinding\r
+  return HttpDxeStop (\r
+           This,\r
+           ControllerHandle,\r
+           NumberOfChildren,\r
+           ChildHandleBuffer,\r
+           IP_VERSION_6\r
            );\r
-\r
-    HttpCleanService (HttpService);\r
-   \r
-    FreePool (HttpService);\r
-\r
-    Status = EFI_SUCCESS;\r
-  }\r
-\r
-  return Status;\r
 }\r
-\r
 /**\r
   Creates a child handle and installs a protocol.\r
 \r
@@ -557,7 +925,6 @@ HttpServiceBindingCreateChild (
   HTTP_SERVICE         *HttpService;\r
   HTTP_PROTOCOL        *HttpInstance;\r
   EFI_STATUS           Status;\r
-  VOID                 *Interface;\r
   EFI_TPL              OldTpl;\r
 \r
   if ((This == NULL) || (ChildHandle == NULL)) {\r
@@ -569,6 +936,12 @@ HttpServiceBindingCreateChild (
   if (HttpInstance == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  \r
+  HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;\r
+  HttpInstance->Service   = HttpService;\r
+  CopyMem (&HttpInstance->Http, &mEfiHttpTemplate, sizeof (HttpInstance->Http));\r
+  NetMapInit (&HttpInstance->TxTokens);\r
+  NetMapInit (&HttpInstance->RxTokens);\r
 \r
   //\r
   // Install HTTP protocol onto ChildHandle\r
@@ -584,27 +957,7 @@ HttpServiceBindingCreateChild (
     goto ON_ERROR;\r
   }\r
 \r
-  HttpInstance->Handle = *ChildHandle;\r
-\r
-  Status = HttpInitProtocol (HttpService, HttpInstance);\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  //\r
-  // Open the default Tcp4 protocol by child.\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  HttpService->TcpChildHandle,\r
-                  &gEfiTcp4ProtocolGuid,\r
-                  (VOID **) &Interface,\r
-                  gHttpDxeDriverBinding.DriverBindingHandle,\r
-                  HttpInstance->Handle,\r
-                  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
+  HttpInstance->Handle    = *ChildHandle;\r
 \r
   //\r
   // Add it to the HTTP service's child list.\r
@@ -619,8 +972,9 @@ HttpServiceBindingCreateChild (
   return EFI_SUCCESS;\r
   \r
 ON_ERROR:\r
-\r
-  HttpCleanProtocol (HttpInstance);\r
\r
+  NetMapClean (&HttpInstance->TxTokens);\r
+  NetMapClean (&HttpInstance->RxTokens);\r
   FreePool (HttpInstance);\r
 \r
   return Status;\r
@@ -664,8 +1018,8 @@ HttpServiceBindingDestroyChild (
                   ChildHandle,\r
                   &gEfiHttpProtocolGuid,\r
                   (VOID **) &Http,\r
-                  gHttpDxeDriverBinding.DriverBindingHandle,\r
-                  ChildHandle,\r
+                  NULL,\r
+                  NULL,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
@@ -681,16 +1035,6 @@ HttpServiceBindingDestroyChild (
     return EFI_SUCCESS;\r
   }\r
 \r
-  //\r
-  // Close the Tcp4 protocol.\r
-  //\r
-  gBS->CloseProtocol (\r
-         HttpService->TcpChildHandle,\r
-         &gEfiTcp4ProtocolGuid,\r
-         gHttpDxeDriverBinding.DriverBindingHandle,\r
-         ChildHandle\r
-         );\r
-  \r
   HttpInstance->InDestroy = TRUE;\r
 \r
   //\r
@@ -706,11 +1050,11 @@ HttpServiceBindingDestroyChild (
     HttpInstance->InDestroy = FALSE;\r
     return Status;\r
   }\r
-\r
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-\r
+  \r
   HttpCleanProtocol (HttpInstance);\r
-\r
+  \r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
   RemoveEntryList (&HttpInstance->Link);\r
   HttpService->ChildrenNumber--;\r
 \r