[PATCH] NetworkPkg: Add HTTP Additional Event Notifications


Heng Luo
 

https://bugzilla.tianocore.org/show_bug.cgi?id=3D3496

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@...>
Cc: Maciej Rabeda <maciej.rabeda@...>
Cc: Jiaxin Wu <jiaxin.wu@...>
Cc: Siyuan Fu <siyuan.fu@...>
---
NetworkPkg/HttpDxe/HttpDriver.h | 3 ++-
NetworkPkg/HttpDxe/HttpDxe.inf | 3 ++-
NetworkPkg/HttpDxe/HttpImpl.c | 4 +++-
NetworkPkg/HttpDxe/HttpProto.c | 58 ++++++++++++++++++++++++++=
+++++++++++++++++++++++++++++++-
NetworkPkg/HttpDxe/HttpProto.h | 15 ++++++++++++++-
NetworkPkg/Include/Protocol/HttpCallback.h | 81 ++++++++++++++++++++++++++=
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
NetworkPkg/NetworkPkg.dec | 3 +++
7 files changed, 162 insertions(+), 5 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpDriver.h b/NetworkPkg/HttpDxe/HttpDrive=
r.h
index 5fe8c5b5e9..b701b80858 100644
--- a/NetworkPkg/HttpDxe/HttpDriver.h
+++ b/NetworkPkg/HttpDxe/HttpDriver.h
@@ -1,7 +1,7 @@
/** @file=0D
The header files of the driver binding and service binding protocol for =
HttpDxe driver.=0D
=0D
- Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=0D
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>=0D
=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
@@ -47,6 +47,7 @@
#include <Protocol/Ip6Config.h>=0D
#include <Protocol/Tls.h>=0D
#include <Protocol/TlsConfig.h>=0D
+#include <Protocol/HttpCallback.h>=0D
=0D
#include <Guid/ImageAuthentication.h>=0D
//=0D
diff --git a/NetworkPkg/HttpDxe/HttpDxe.inf b/NetworkPkg/HttpDxe/HttpDxe.inf
index 35fe31af18..23fb9ec394 100644
--- a/NetworkPkg/HttpDxe/HttpDxe.inf
+++ b/NetworkPkg/HttpDxe/HttpDxe.inf
@@ -1,7 +1,7 @@
## @file=0D
# Implementation of EFI HTTP protocol interfaces.=0D
#=0D
-# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=
=0D
+# Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=
=0D
#=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
@@ -65,6 +65,7 @@
gEfiTlsServiceBindingProtocolGuid ## SOMETIMES_CONSUMES=0D
gEfiTlsProtocolGuid ## SOMETIMES_CONSUMES=0D
gEfiTlsConfigurationProtocolGuid ## SOMETIMES_CONSUMES=0D
+ gEdkiiHttpCallbackProtocolGuid ## SOMETIMES_CONSUMES=0D
=0D
[Guids]=0D
gEfiTlsCaCertificateGuid ## SOMETIMES_CONSUMES =
## Variable:L"TlsCaCertificate"=0D
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index 5a6ecbc9d9..97f15d229f 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -1,7 +1,7 @@
/** @file=0D
Implementation of EFI_HTTP_PROTOCOL protocol interfaces.=0D
=0D
- Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=0D
(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>=0D
=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
@@ -527,6 +527,7 @@ EfiHttpRequest (
} else {=0D
Status =3D HttpDns6 (HttpInstance, HostNameStr, &HttpInstance->Rem=
oteIpv6Addr);=0D
}=0D
+ HttpNotify (HttpEventDns, Status);=0D
=0D
FreePool (HostNameStr);=0D
if (EFI_ERROR (Status)) {=0D
@@ -588,6 +589,7 @@ EfiHttpRequest (
Configure || ReConfigure,=0D
TlsConfigure=0D
);=0D
+ HttpNotify (HttpEventInitSession, Status);=0D
if (EFI_ERROR (Status)) {=0D
goto Error2;=0D
}=0D
diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index afc7db5a72..affa916bd6 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -1,7 +1,7 @@
/** @file=0D
Miscellaneous routines for HttpDxe driver.=0D
=0D
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=0D
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
@@ -966,6 +966,7 @@ HttpCreateConnection (
HttpInstance->IsTcp4ConnDone =3D FALSE;=0D
HttpInstance->Tcp4ConnToken.CompletionToken.Status =3D EFI_NOT_READY;=
=0D
Status =3D HttpInstance->Tcp4->Connect (HttpInstance->Tcp4, &HttpInsta=
nce->Tcp4ConnToken);=0D
+ HttpNotify (HttpEventConnectTcp, Status);=0D
if (EFI_ERROR (Status)) {=0D
DEBUG ((EFI_D_ERROR, "HttpCreateConnection: Tcp4->Connect() =3D %r\n=
", Status));=0D
return Status;=0D
@@ -981,6 +982,7 @@ HttpCreateConnection (
HttpInstance->IsTcp6ConnDone =3D FALSE;=0D
HttpInstance->Tcp6ConnToken.CompletionToken.Status =3D EFI_NOT_READY;=
=0D
Status =3D HttpInstance->Tcp6->Connect (HttpInstance->Tcp6, &HttpInsta=
nce->Tcp6ConnToken);=0D
+ HttpNotify (HttpEventConnectTcp, Status);=0D
if (EFI_ERROR (Status)) {=0D
DEBUG ((EFI_D_ERROR, "HttpCreateConnection: Tcp6->Connect() =3D %r\n=
", Status));=0D
return Status;=0D
@@ -1277,6 +1279,7 @@ HttpConnectTcp4 (
}=0D
=0D
Status =3D TlsConnectSession (HttpInstance, HttpInstance->TimeoutEvent=
);=0D
+ HttpNotify (HttpEventTlsConnectSession, Status);=0D
=0D
gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);=0D
=0D
@@ -1369,6 +1372,7 @@ HttpConnectTcp6 (
}=0D
=0D
Status =3D TlsConnectSession (HttpInstance, HttpInstance->TimeoutEvent=
);=0D
+ HttpNotify (HttpEventTlsConnectSession, Status);=0D
=0D
gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);=0D
=0D
@@ -2195,3 +2199,55 @@ HttpTcpTokenCleanup (
}=0D
=0D
}=0D
+=0D
+/**=0D
+ Send Events via EDKII_HTTP_CALLBACK_PROTOCOL.=0D
+=0D
+ @param[in] Event The event that occurs in the current sta=
te.=0D
+ @param[in] EventStatus The Status of Event, EFI_SUCCESS or othe=
r errors.=0D
+=0D
+**/=0D
+VOID=0D
+HttpNotify (=0D
+ IN EDKII_HTTP_CALLBACK_EVENT Event,=0D
+ IN EFI_STATUS EventStatus=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ EFI_HANDLE *Handles;=0D
+ UINTN Index;=0D
+ UINTN HandleCount;=0D
+ EFI_HANDLE Handle;=0D
+ EDKII_HTTP_CALLBACK_PROTOCOL *HttpCallback;=0D
+=0D
+ DEBUG ((DEBUG_INFO, "HttpNotify: Event - %d, EventStatus - %r\n", Event,=
EventStatus));=0D
+=0D
+ Handles =3D NULL;=0D
+ HandleCount =3D 0;=0D
+ Status =3D gBS->LocateHandleBuffer (=0D
+ ByProtocol,=0D
+ &gEdkiiHttpCallbackProtocolGuid,=0D
+ NULL,=0D
+ &HandleCount,=0D
+ &Handles=0D
+ );=0D
+ if (Status =3D=3D EFI_SUCCESS) {=0D
+ for (Index =3D 0; Index < HandleCount; Index++) {=0D
+ Handle =3D Handles[Index];=0D
+ Status =3D gBS->HandleProtocol (=0D
+ Handle,=0D
+ &gEdkiiHttpCallbackProtocolGuid,=0D
+ (VOID **) &HttpCallback=0D
+ );=0D
+ if (Status =3D=3D EFI_SUCCESS) {=0D
+ DEBUG ((DEBUG_INFO, "HttpNotify: Notifying %p\n", HttpCallback));=
=0D
+ HttpCallback->Callback (=0D
+ HttpCallback,=0D
+ Event,=0D
+ EventStatus=0D
+ );=0D
+ }=0D
+ }=0D
+ FreePool (Handles);=0D
+ }=0D
+}=0D
diff --git a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h
index 00ba26aca4..5b90a6b074 100644
--- a/NetworkPkg/HttpDxe/HttpProto.h
+++ b/NetworkPkg/HttpDxe/HttpProto.h
@@ -1,7 +1,7 @@
/** @file=0D
The header files of miscellaneous routines for HttpDxe driver.=0D
=0D
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=0D
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
@@ -609,4 +609,17 @@ HttpResponseWorker (
IN HTTP_TOKEN_WRAP *Wrap=0D
);=0D
=0D
+/**=0D
+ Send Events via EDKII_HTTP_CALLBACK_PROTOCOL.=0D
+=0D
+ @param[in] Event The event that occurs in the current sta=
te.=0D
+ @param[in] EventStatus The Status of Event, EFI_SUCCESS or othe=
r errors.=0D
+=0D
+**/=0D
+VOID=0D
+HttpNotify (=0D
+ IN EDKII_HTTP_CALLBACK_EVENT Event,=0D
+ IN EFI_STATUS EventStatus=0D
+ );=0D
+=0D
#endif=0D
diff --git a/NetworkPkg/Include/Protocol/HttpCallback.h b/NetworkPkg/Includ=
e/Protocol/HttpCallback.h
new file mode 100644
index 0000000000..483498430a
--- /dev/null
+++ b/NetworkPkg/Include/Protocol/HttpCallback.h
@@ -0,0 +1,81 @@
+/** @file=0D
+ This file defines the EDKII HTTP Callback Protocol interface.=0D
+=0D
+ Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+**/=0D
+=0D
+#ifndef __EDKII_HTTP_CALLBACK_H__=0D
+#define __EDKII_HTTP_CALLBACK_H__=0D
+=0D
+#define EDKII_HTTP_CALLBACK_PROTOCOL_GUID \=0D
+ { \=0D
+ 0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2,=
0x40} \=0D
+ }=0D
+=0D
+typedef struct _EDKII_HTTP_CALLBACK_PROTOCOL EDKII_HTTP_CALLBACK_PROTOCOL=
;=0D
+=0D
+///=0D
+/// EDKII_HTTP_CALLBACK_EVENT=0D
+///=0D
+typedef enum {=0D
+ ///=0D
+ /// Retrieve the host address, EventStatus:=0D
+ /// EFI_SUCCESS Operation succeeded.=0D
+ /// EFI_OUT_OF_RESOURCES Failed to allocate needed resources.=0D
+ /// EFI_DEVICE_ERROR An unexpected network error occurred.=0D
+ /// Others Other errors as indicated.=0D
+ ///=0D
+ HttpEventDns,=0D
+=0D
+ ///=0D
+ /// Initiate a nonblocking TCP connection request, EventStatus:=0D
+ /// EFI_SUCCESS The connection request is successfully initia=
ted.=0D
+ /// EFI_NOT_STARTED This EFI TCP Protocol instance has not been c=
onfigured.=0D
+ /// EFI_DEVICE_ERROR An unexpected system or network error occurre=
d.=0D
+ /// Others Other errors as indicated.=0D
+ ///=0D
+ HttpEventConnectTcp,=0D
+=0D
+ ///=0D
+ /// Connect one TLS session by finishing the TLS handshake process, Even=
tStatus:=0D
+ /// EFI_SUCCESS The TLS session is established.=0D
+ /// EFI_OUT_OF_RESOURCES Can't allocate memory resources.=0D
+ /// EFI_ABORTED TLS session state is incorrect.=0D
+ /// Others Other error as indicated.=0D
+ ///=0D
+ HttpEventTlsConnectSession,=0D
+=0D
+ ///=0D
+ /// Initialize Http session=0D
+ /// EFI_SUCCESS The initialization of session is done.=0D
+ /// Others Other error as indicated.=0D
+ ///=0D
+ HttpEventInitSession=0D
+} EDKII_HTTP_CALLBACK_EVENT;=0D
+=0D
+/**=0D
+ Callback function that is invoked when HTTP event occurs.=0D
+=0D
+ @param[in] This Pointer to the EDKII_HTTP_CALLBACK_PROTO=
COL instance.=0D
+ @param[in] Event The event that occurs in the current sta=
te.=0D
+ @param[in] EventStatus The Status of Event, EFI_SUCCESS or othe=
r errors.=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI * EDKII_HTTP_CALLBACK) (=0D
+ IN EDKII_HTTP_CALLBACK_PROTOCOL *This,=0D
+ IN EDKII_HTTP_CALLBACK_EVENT Event,=0D
+ IN EFI_STATUS EventStatus=0D
+ );=0D
+=0D
+///=0D
+/// EFI HTTP Callback Protocol is invoked when HTTP event occurs.=0D
+///=0D
+struct _EDKII_HTTP_CALLBACK_PROTOCOL {=0D
+ EDKII_HTTP_CALLBACK Callback;=0D
+};=0D
+=0D
+extern EFI_GUID gEdkiiHttpCallbackProtocolGuid;=0D
+=0D
+#endif=0D
diff --git a/NetworkPkg/NetworkPkg.dec b/NetworkPkg/NetworkPkg.dec
index b81f10ef6e..0f9f7bb15e 100644
--- a/NetworkPkg/NetworkPkg.dec
+++ b/NetworkPkg/NetworkPkg.dec
@@ -88,6 +88,9 @@
## Include/Protocol/Dpc.h=0D
gEfiDpcProtocolGuid =3D {0x480f8ae9, 0xc46, 0x4aa9, { 0xbc, 0=
x89, 0xdb, 0x9f, 0xba, 0x61, 0x98, 0x6 }}=0D
=0D
+ ## Include/Protocol/HttpCallback.h=0D
+ gEdkiiHttpCallbackProtocolGuid =3D {0x611114f1, 0xa37b, 0x4468, {0xa4, =
0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40}}=0D
+=0D
[PcdsFixedAtBuild]=0D
## The max attempt number will be created by iSCSI driver.=0D
# @Prompt Max attempt number.=0D
--=20
2.31.1.windows.1


Wu, Jiaxin
 

For the below EDKII_HTTP_CALLBACK_EVENT definition:

All event is to retrieve the event Status, so the comments should be made clearly and align with code returned status, for example,

+ /// Retrieve the host address, EventStatus:
There might be the misunderstanding you want the host address, but actually, you only want the status. It's better to be:

+ /// The Status of DNS Event to retrieve the host address.
The same to all event.


With above changes, the patch is good to me.



Thanks,
Jiaxin





+///

+/// EDKII_HTTP_CALLBACK_EVENT

+///

+typedef enum {

+ ///

+ /// Retrieve the host address, EventStatus:

+ /// EFI_SUCCESS Operation succeeded.

+ /// EFI_OUT_OF_RESOURCES Failed to allocate needed resources.

+ /// EFI_DEVICE_ERROR An unexpected network error occurred.

+ /// Others Other errors as indicated.

+ ///

+ HttpEventDns,

+

+ ///

+ /// Initiate a nonblocking TCP connection request, EventStatus:

+ /// EFI_SUCCESS The connection request is successfully initiated.

+ /// EFI_NOT_STARTED This EFI TCP Protocol instance has not been
configured.

+ /// EFI_DEVICE_ERROR An unexpected system or network error
occurred.

+ /// Others Other errors as indicated.

+ ///

+ HttpEventConnectTcp,

+

+ ///

+ /// Connect one TLS session by finishing the TLS handshake process,
EventStatus:

+ /// EFI_SUCCESS The TLS session is established.

+ /// EFI_OUT_OF_RESOURCES Can't allocate memory resources.

+ /// EFI_ABORTED TLS session state is incorrect.

+ /// Others Other error as indicated.

+ ///

+ HttpEventTlsConnectSession,

+

+ ///

+ /// Initialize Http session

+ /// EFI_SUCCESS The initialization of session is done.

+ /// Others Other error as indicated.

+ ///

+ HttpEventInitSession

+} EDKII_HTTP_CALLBACK_EVENT;

+


Heng Luo
 

Thank Jiaxin, the patch V2 is sent out following Jiaxin's comment.

-----Original Message-----
From: Wu, Jiaxin <jiaxin.wu@...>
Sent: Tuesday, July 20, 2021 9:45 AM
To: Luo, Heng <heng.luo@...>; devel@edk2.groups.io
Cc: Maciej Rabeda <maciej.rabeda@...>; Fu, Siyuan
<siyuan.fu@...>
Subject: RE: [PATCH] NetworkPkg: Add HTTP Additional Event Notifications

For the below EDKII_HTTP_CALLBACK_EVENT definition:

All event is to retrieve the event Status, so the comments should be made clearly
and align with code returned status, for example,

+ /// Retrieve the host address, EventStatus:
There might be the misunderstanding you want the host address, but actually,
you only want the status. It's better to be:

+ /// The Status of DNS Event to retrieve the host address.
The same to all event.


With above changes, the patch is good to me.



Thanks,
Jiaxin





+///

+/// EDKII_HTTP_CALLBACK_EVENT

+///

+typedef enum {

+ ///

+ /// Retrieve the host address, EventStatus:

+ /// EFI_SUCCESS Operation succeeded.

+ /// EFI_OUT_OF_RESOURCES Failed to allocate needed resources.

+ /// EFI_DEVICE_ERROR An unexpected network error occurred.

+ /// Others Other errors as indicated.

+ ///

+ HttpEventDns,

+

+ ///

+ /// Initiate a nonblocking TCP connection request, EventStatus:

+ /// EFI_SUCCESS The connection request is successfully initiated.

+ /// EFI_NOT_STARTED This EFI TCP Protocol instance has not been
configured.

+ /// EFI_DEVICE_ERROR An unexpected system or network error
occurred.

+ /// Others Other errors as indicated.

+ ///

+ HttpEventConnectTcp,

+

+ ///

+ /// Connect one TLS session by finishing the TLS handshake process,
EventStatus:

+ /// EFI_SUCCESS The TLS session is established.

+ /// EFI_OUT_OF_RESOURCES Can't allocate memory resources.

+ /// EFI_ABORTED TLS session state is incorrect.

+ /// Others Other error as indicated.

+ ///

+ HttpEventTlsConnectSession,

+

+ ///

+ /// Initialize Http session

+ /// EFI_SUCCESS The initialization of session is done.

+ /// Others Other error as indicated.

+ ///

+ HttpEventInitSession

+} EDKII_HTTP_CALLBACK_EVENT;

+