From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.4882.1626939553110933892 for ; Thu, 22 Jul 2021 00:39:13 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: heng.luo@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10052"; a="209689967" X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="209689967" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2021 00:39:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="495713594" Received: from hengluo-dev.ccr.corp.intel.com ([10.239.153.158]) by fmsmga004.fm.intel.com with ESMTP; 22 Jul 2021 00:39:05 -0700 From: "Heng Luo" To: devel@edk2.groups.io Cc: Maciej Rabeda , Jiaxin Wu , Siyuan Fu Subject: [Patch V2] NetworkPkg: Add HTTP Additional Event Notifications Date: Thu, 22 Jul 2021 15:38:58 +0800 Message-Id: <20210722073858.406-1-heng.luo@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: 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 Cc: Maciej Rabeda Cc: Jiaxin Wu Cc: 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 | 85 ++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ NetworkPkg/NetworkPkg.dec | 3 +++ 7 files changed, 166 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.
=0D + Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
=0D (C) Copyright 2016 Hewlett Packard Enterprise Development LP
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D @@ -47,6 +47,7 @@ #include =0D #include =0D #include =0D +#include =0D =0D #include =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.
= =0D +# Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
= =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.
=0D + Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
=0D (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
=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.
=0D +Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
=0D (C) Copyright 2016 Hewlett Packard Enterprise Development LP
=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.
=0D +Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
=0D (C) Copyright 2016 Hewlett Packard Enterprise Development LP
=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..d036a8a4be --- /dev/null +++ b/NetworkPkg/Include/Protocol/HttpCallback.h @@ -0,0 +1,85 @@ +/** @file=0D + This file defines the EDKII HTTP Callback Protocol interface.=0D +=0D + Copyright (c) 2021, Intel Corporation. All rights reserved.
=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 + /// The Status of DNS Event to retrieve the host address.=0D + /// 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 + /// The Status of Event to initiate a nonblocking TCP connection request= .=0D + /// 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 + /// The Status of Event to connect one TLS session by finishing the TLS = handshake process.=0D + /// EventStatus:=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 + /// The Status of Event to initialize Http session=0D + /// EventStatus:=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