]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Add HTTP Additional Event Notifications
authorHeng Luo <heng.luo@intel.com>
Wed, 28 Jul 2021 11:58:05 +0000 (19:58 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 28 Jul 2021 16:19:19 +0000 (16:19 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3496

Add new EDKII_HTTP_CALLBACK_PROTOCOL in NetworkPkg,
Send HTTP Events via EDKII_HTTP_CALLBACK_PROTOCOL
when Dns/ConnectTcp/TlsConnectSession/InitSession
occurs.

Signed-off-by: Heng Luo <heng.luo@intel.com>
Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
NetworkPkg/HttpDxe/HttpDriver.h
NetworkPkg/HttpDxe/HttpDxe.inf
NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg/HttpDxe/HttpProto.c
NetworkPkg/HttpDxe/HttpProto.h
NetworkPkg/Include/Protocol/HttpCallback.h [new file with mode: 0644]
NetworkPkg/NetworkPkg.dec

index 5fe8c5b5e9b9143c74f24d1c11378e87afa4a75f..b701b808583320625bbcd18555edea21480ef7ef 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The header files of the driver binding and service binding protocol for HttpDxe driver.\r
 \r
-  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
@@ -47,6 +47,7 @@
 #include <Protocol/Ip6Config.h>\r
 #include <Protocol/Tls.h>\r
 #include <Protocol/TlsConfig.h>\r
+#include <Protocol/HttpCallback.h>\r
 \r
 #include <Guid/ImageAuthentication.h>\r
 //\r
index 8dd38387930d07f5198eb22c0f56e32cda3ae943..af681c0184686362f63cbbce81d5998d9a108f09 100644 (file)
@@ -65,6 +65,7 @@
   gEfiTlsServiceBindingProtocolGuid                ## SOMETIMES_CONSUMES\r
   gEfiTlsProtocolGuid                              ## SOMETIMES_CONSUMES\r
   gEfiTlsConfigurationProtocolGuid                 ## SOMETIMES_CONSUMES\r
+  gEdkiiHttpCallbackProtocolGuid                   ## SOMETIMES_CONSUMES\r
 \r
 [Guids]\r
   gEfiTlsCaCertificateGuid                         ## SOMETIMES_CONSUMES  ## Variable:L"TlsCaCertificate"\r
index 8790e9b4e04a6ffbda90fb47a1eeebb6a60f4e35..7285b0fbeb7d3504071a75818371a058e507c33b 100644 (file)
@@ -527,6 +527,7 @@ EfiHttpRequest (
       } else {\r
         Status = HttpDns6 (HttpInstance, HostNameStr, &HttpInstance->RemoteIpv6Addr);\r
       }\r
+      HttpNotify (HttpEventDns, Status);\r
 \r
       FreePool (HostNameStr);\r
       if (EFI_ERROR (Status)) {\r
@@ -588,6 +589,7 @@ EfiHttpRequest (
              Configure || ReConfigure,\r
              TlsConfigure\r
              );\r
+  HttpNotify (HttpEventInitSession, Status);\r
   if (EFI_ERROR (Status)) {\r
     goto Error2;\r
   }\r
index afc7db5a726f62cf85965122061a4b68e5a3fcbc..affa916bd64feb6a874b29dcb86f79a2455f860a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for HttpDxe driver.\r
 \r
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -966,6 +966,7 @@ HttpCreateConnection (
     HttpInstance->IsTcp4ConnDone = FALSE;\r
     HttpInstance->Tcp4ConnToken.CompletionToken.Status = EFI_NOT_READY;\r
     Status = HttpInstance->Tcp4->Connect (HttpInstance->Tcp4, &HttpInstance->Tcp4ConnToken);\r
+    HttpNotify (HttpEventConnectTcp, Status);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "HttpCreateConnection: Tcp4->Connect() = %r\n", Status));\r
       return Status;\r
@@ -981,6 +982,7 @@ HttpCreateConnection (
     HttpInstance->IsTcp6ConnDone = FALSE;\r
     HttpInstance->Tcp6ConnToken.CompletionToken.Status = EFI_NOT_READY;\r
     Status = HttpInstance->Tcp6->Connect (HttpInstance->Tcp6, &HttpInstance->Tcp6ConnToken);\r
+    HttpNotify (HttpEventConnectTcp, Status);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "HttpCreateConnection: Tcp6->Connect() = %r\n", Status));\r
       return Status;\r
@@ -1277,6 +1279,7 @@ HttpConnectTcp4 (
     }\r
 \r
     Status = TlsConnectSession (HttpInstance, HttpInstance->TimeoutEvent);\r
+    HttpNotify (HttpEventTlsConnectSession, Status);\r
 \r
     gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
 \r
@@ -1369,6 +1372,7 @@ HttpConnectTcp6 (
     }\r
 \r
     Status = TlsConnectSession (HttpInstance, HttpInstance->TimeoutEvent);\r
+    HttpNotify (HttpEventTlsConnectSession, Status);\r
 \r
     gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
 \r
@@ -2195,3 +2199,55 @@ HttpTcpTokenCleanup (
   }\r
 \r
 }\r
+\r
+/**\r
+  Send Events via EDKII_HTTP_CALLBACK_PROTOCOL.\r
+\r
+  @param[in]  Event               The event that occurs in the current state.\r
+  @param[in]  EventStatus         The Status of Event, EFI_SUCCESS or other errors.\r
+\r
+**/\r
+VOID\r
+HttpNotify (\r
+  IN  EDKII_HTTP_CALLBACK_EVENT         Event,\r
+  IN  EFI_STATUS                        EventStatus\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_HANDLE                      *Handles;\r
+  UINTN                           Index;\r
+  UINTN                           HandleCount;\r
+  EFI_HANDLE                      Handle;\r
+  EDKII_HTTP_CALLBACK_PROTOCOL    *HttpCallback;\r
+\r
+  DEBUG ((DEBUG_INFO, "HttpNotify: Event - %d, EventStatus - %r\n", Event, EventStatus));\r
+\r
+  Handles = NULL;\r
+  HandleCount = 0;\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEdkiiHttpCallbackProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &Handles\r
+                  );\r
+  if (Status == EFI_SUCCESS) {\r
+    for (Index = 0; Index < HandleCount; Index++) {\r
+      Handle = Handles[Index];\r
+      Status = gBS->HandleProtocol (\r
+                      Handle,\r
+                      &gEdkiiHttpCallbackProtocolGuid,\r
+                      (VOID **) &HttpCallback\r
+                      );\r
+      if (Status == EFI_SUCCESS) {\r
+        DEBUG ((DEBUG_INFO, "HttpNotify: Notifying %p\n", HttpCallback));\r
+        HttpCallback->Callback (\r
+                HttpCallback,\r
+                Event,\r
+                EventStatus\r
+                );\r
+      }\r
+    }\r
+    FreePool (Handles);\r
+  }\r
+}\r
index 6b3e49090e6a7d2de2b88c56a299394c0e7965a4..637d35053993fc9e685809e191bef30b0ab907ed 100644 (file)
@@ -608,4 +608,17 @@ HttpResponseWorker (
   IN  HTTP_TOKEN_WRAP           *Wrap\r
   );\r
 \r
+/**\r
+  Send Events via EDKII_HTTP_CALLBACK_PROTOCOL.\r
+\r
+  @param[in]  Event               The event that occurs in the current state.\r
+  @param[in]  EventStatus         The Status of Event, EFI_SUCCESS or other errors.\r
+\r
+**/\r
+VOID\r
+HttpNotify (\r
+  IN  EDKII_HTTP_CALLBACK_EVENT         Event,\r
+  IN  EFI_STATUS                        EventStatus\r
+  );\r
+\r
 #endif\r
diff --git a/NetworkPkg/Include/Protocol/HttpCallback.h b/NetworkPkg/Include/Protocol/HttpCallback.h
new file mode 100644 (file)
index 0000000..7e3f82a
--- /dev/null
@@ -0,0 +1,85 @@
+/** @file\r
+  This file defines the EDKII HTTP Callback Protocol interface.\r
+\r
+  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#ifndef EDKII_HTTP_CALLBACK_H_\r
+#define EDKII_HTTP_CALLBACK_H_\r
+\r
+#define EDKII_HTTP_CALLBACK_PROTOCOL_GUID \\r
+  { \\r
+    0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40} \\r
+  }\r
+\r
+typedef struct _EDKII_HTTP_CALLBACK_PROTOCOL  EDKII_HTTP_CALLBACK_PROTOCOL;\r
+\r
+///\r
+/// EDKII_HTTP_CALLBACK_EVENT\r
+///\r
+typedef enum {\r
+  ///\r
+  /// The Status of DNS Event to retrieve the host address.\r
+  /// EventStatus:\r
+  /// EFI_SUCCESS             Operation succeeded.\r
+  /// EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
+  /// EFI_DEVICE_ERROR        An unexpected network error occurred.\r
+  /// Others                  Other errors as indicated.\r
+  ///\r
+  HttpEventDns,\r
+\r
+  ///\r
+  /// The Status of Event to initiate a nonblocking TCP connection request.\r
+  /// EventStatus:\r
+  /// EFI_SUCCESS            The connection request is successfully initiated.\r
+  /// EFI_NOT_STARTED        This EFI TCP Protocol instance has not been configured.\r
+  /// EFI_DEVICE_ERROR       An unexpected system or network error occurred.\r
+  /// Others                 Other errors as indicated.\r
+  ///\r
+  HttpEventConnectTcp,\r
+\r
+  ///\r
+  /// The Status of Event to connect one TLS session by finishing the TLS handshake process.\r
+  /// EventStatus:\r
+  /// EFI_SUCCESS            The TLS session is established.\r
+  /// EFI_OUT_OF_RESOURCES   Can't allocate memory resources.\r
+  /// EFI_ABORTED            TLS session state is incorrect.\r
+  /// Others                 Other error as indicated.\r
+  ///\r
+  HttpEventTlsConnectSession,\r
+\r
+  ///\r
+  /// The Status of Event to initialize Http session\r
+  /// EventStatus:\r
+  /// EFI_SUCCESS            The initialization of session is done.\r
+  /// Others                 Other error as indicated.\r
+  ///\r
+  HttpEventInitSession\r
+} EDKII_HTTP_CALLBACK_EVENT;\r
+\r
+/**\r
+  Callback function that is invoked when HTTP event occurs.\r
+\r
+  @param[in]  This                Pointer to the EDKII_HTTP_CALLBACK_PROTOCOL instance.\r
+  @param[in]  Event               The event that occurs in the current state.\r
+  @param[in]  EventStatus         The Status of Event, EFI_SUCCESS or other errors.\r
+**/\r
+typedef\r
+VOID\r
+(EFIAPI * EDKII_HTTP_CALLBACK) (\r
+  IN EDKII_HTTP_CALLBACK_PROTOCOL     *This,\r
+  IN EDKII_HTTP_CALLBACK_EVENT        Event,\r
+  IN EFI_STATUS                       EventStatus\r
+ );\r
+\r
+///\r
+/// EFI HTTP Callback Protocol is invoked when HTTP event occurs.\r
+///\r
+struct _EDKII_HTTP_CALLBACK_PROTOCOL {\r
+  EDKII_HTTP_CALLBACK Callback;\r
+};\r
+\r
+extern EFI_GUID gEdkiiHttpCallbackProtocolGuid;\r
+\r
+#endif /* EDKII_HTTP_CALLBACK_H_ */\r
index 3e1f5c101d5b8fa31e8b21332453f85d9178b54f..928e84fec4387e1a639e4bffc72fc005325c904f 100644 (file)
@@ -88,6 +88,9 @@
   ## Include/Protocol/Dpc.h\r
   gEfiDpcProtocolGuid           = {0x480f8ae9, 0xc46, 0x4aa9,  { 0xbc, 0x89, 0xdb, 0x9f, 0xba, 0x61, 0x98, 0x6 }}\r
 \r
+  ## Include/Protocol/HttpCallback.h\r
+  gEdkiiHttpCallbackProtocolGuid  = {0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40}}\r
+\r
 [PcdsFixedAtBuild]\r
   ## The max attempt number will be created by iSCSI driver.\r
   # @Prompt Max attempt number.\r