From nobody Tue Apr 30 05:19:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69185+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69185+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1608295117; cv=none; d=zohomail.com; s=zohoarc; b=juA77qP5bY5m1S6iPiPXx7rdOTaeuIs4oEGCSz7dLog6spUGA1kRXckf1u5jKnb59uTwngSiXpVUG5rWBas9D1QLa/7zj+H4G1VY9d4lOO91i1iHdLC0BZdpxB36GcqDEXBGQmkQ3lwPq2/o//jDDRXaFlKiBsOSPl6kC5ulBdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608295117; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=YcilVqXwv6hWezFklzhm4eLkMq/NCuUar2HiU+VMt9g=; b=CB2h15ye8xh3/KIeinZM+Vpm0riW3V6SzvJ1s6+L1fyz76q5shXEDaKPAdn+rGvfF9hxBbjAauDMe1ZngzsjNgysb86+CLMjuYvFLPxUsPXNbB1ovYReHrpgyhwfO+rsBhEM6B7b5FdOvGnddD0r05IZnSyZZ0I+6Mi0Ftgxzl0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69185+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608295117272999.7544207381865; Fri, 18 Dec 2020 04:38:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0IOLYY1788612xCtBymcnWxz; Fri, 18 Dec 2020 04:38:36 -0800 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web09.9277.1608295116213133323 for ; Fri, 18 Dec 2020 04:38:36 -0800 X-Received: from pps.filterd (m0134421.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BICZbcj031422; Fri, 18 Dec 2020 12:38:35 GMT X-Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25]) by mx0b-002e3701.pphosted.com with ESMTP id 35g9ymywr7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Dec 2020 12:38:35 +0000 X-Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 892A585; Fri, 18 Dec 2020 12:38:34 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 09ED83B; Fri, 18 Dec 2020 12:38:32 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Jiaxin Wu , Siyuan Fu , Fan Wang , Jiewen Yao , Nickle Wang , Peter O'Hanley Subject: [edk2-devel] [PATCH v2] RedfishPkg/DxeRestExLib: DxeRestExLib Date: Fri, 18 Dec 2020 08:22:20 +0800 Message-Id: <20201218002220.11748-1-abner.chang@hpe.com> X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: qiyFNAVwfJny4SBtjW6y4bRMx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608295116; bh=P0Ma7BPem2/QieLGx4gOI506OtMa7zJ9nLTi+ZURU88=; h=Cc:Date:From:Reply-To:Subject:To; b=YBOO1I6WAB9Cfzsl1WnCoXhRL8y5sKEBeZcntuK7Og1kVtM49yH4NMGbTMwLXmZsfNT ZnAsa99I19rdJfgvRy3CUaCu2La87BC0OLma3OfOpCJovmUDj78o+ambKFajUC3DfOGDK aaDv4ziUBVg/Ov7wTYH0p1rAZf3OqwsK7oo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add EFI REST EX helper library to create child instance of REST EX service. Signed-off-by: Abner Chang Cc: Jiaxin Wu Cc: Siyuan Fu Cc: Fan Wang Cc: Jiewen Yao Cc: Nickle Wang Cc: Peter O'Hanley Reviewed-by: Nickle Wang --- RedfishPkg/RedfishPkg.dec | 4 + RedfishPkg/RedfishLibs.dsc.inc | 1 + RedfishPkg/RedfishPkg.dsc | 1 + .../Library/DxeRestExLib/DxeRestExLib.inf | 44 +++++ RedfishPkg/Include/Library/RestExLib.h | 40 +++++ .../Library/DxeRestExLib/DxeRestExLib.c | 166 ++++++++++++++++++ 6 files changed, 256 insertions(+) create mode 100644 RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf create mode 100644 RedfishPkg/Include/Library/RestExLib.h create mode 100644 RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index fc56b4fefb..89a2a6de1e 100644 --- a/RedfishPkg/RedfishPkg.dec +++ b/RedfishPkg/RedfishPkg.dec @@ -25,6 +25,10 @@ # Platform implementation-specific Redfish Credential Interface. RedfishPlatformCredentialLib|Include/Library/RedfishCredentialLib.h =20 + ## @libraryclass The helper routines to access REST EX service. + # This library is only intended to be used by UEFI network stack modul= es. + RestExLib|Include/Library/RestExLib.h + [Protocols] ## Include/Protocol/RedfishDiscover.h gEfiRedfishDiscoverProtocolGuid =3D { 0x5db12509, 0x4550, 0x4347, {= 0x96, 0xb3, 0x73, 0xc0, 0xff, 0x6e, 0x86, 0x9f }} diff --git a/RedfishPkg/RedfishLibs.dsc.inc b/RedfishPkg/RedfishLibs.dsc.inc index e780b5c270..df21664f4e 100644 --- a/RedfishPkg/RedfishLibs.dsc.inc +++ b/RedfishPkg/RedfishLibs.dsc.inc @@ -11,5 +11,6 @@ # ## !if $(REDFISH_ENABLE) =3D=3D TRUE + RestExLib|RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf !endif =20 diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc index 0b5d8cdd4e..5d9476bc79 100644 --- a/RedfishPkg/RedfishPkg.dsc +++ b/RedfishPkg/RedfishPkg.dsc @@ -49,5 +49,6 @@ [Components] RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLib= Null.inf RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.i= nf + RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf =20 !include RedfishPkg/Redfish.dsc.inc diff --git a/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf b/RedfishPkg/= Library/DxeRestExLib/DxeRestExLib.inf new file mode 100644 index 0000000000..ab87224d57 --- /dev/null +++ b/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf @@ -0,0 +1,44 @@ +## @file +# Library for REST EX Protocol +# +# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D DxeRestExLib + FILE_GUID =3D E9CBF727-8AF3-4602-9DBD-A3942869B5AE + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RestExLib | DXE_DRIVER DXE_RUNTIME_DR= IVER UEFI_APPLICATION UEFI_DRIVER + +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC RISCV64 +# + +[Sources.common] + DxeRestExLib.c + +[Packages] + NetworkPkg/NetworkPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DevicePathLib + MemoryAllocationLib + NetLib + PrintLib + UefiLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + +[Protocols] + gEfiRestExServiceBindingProtocolGuid ## PROTOCOL ALWAYS_CONSUMED + gEfiRestExProtocolGuid ## PROTOCOL ALWAYS_CONSUMED + diff --git a/RedfishPkg/Include/Library/RestExLib.h b/RedfishPkg/Include/Li= brary/RestExLib.h new file mode 100644 index 0000000000..a83a43e1a1 --- /dev/null +++ b/RedfishPkg/Include/Library/RestExLib.h @@ -0,0 +1,40 @@ +/** @file + This library provides help functions for REST EX Protocol. + + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REST_EX_LIB_H_ +#define REST_EX_LIB_H_ + +/// +/// Library class public functions +/// + +/** + This function allows the caller to create child handle for specific + REST server. + + @param[in] Image The image handle used to open service. + @param[in] AccessMode Access mode of REST server. + @param[in] ConfigType Underlying configuration to communicate= with REST server. + @param[in] ServiceType REST service type. + @param[out] ChildInstanceHandle The handle to receive the create child. + + @retval EFI_SUCCESS Can't create the corresponding REST EX c= hild instance. + @retval EFI_INVALID_PARAMETERS Any of input parameters is improper. + +**/ +EFI_STATUS +RestExLibCreateChild ( + IN EFI_HANDLE Image, + IN EFI_REST_EX_SERVICE_ACCESS_MODE AccessMode, + IN EFI_REST_EX_CONFIG_TYPE ConfigType, + IN EFI_REST_EX_SERVICE_TYPE ServiceType, + OUT EFI_HANDLE *ChildInstanceHandle +); + +#endif diff --git a/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c b/RedfishPkg/Li= brary/DxeRestExLib/DxeRestExLib.c new file mode 100644 index 0000000000..05c70c213f --- /dev/null +++ b/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c @@ -0,0 +1,166 @@ +/** @file + This library provides help functions for REST EX Protocol. + + (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#define REST_EX_CONFIG_DATA_LEN_UNKNOWN 0xff + +/** + This function allows the caller to create child handle for specific + REST server. + + @param[in] Image The image handle used to open service. + @param[in] AccessMode Access mode of REST server. + @param[in] ConfigType Underlying configuration to communicate= with REST server. + @param[in] ServiceType REST service type. + @param[out] ChildInstanceHandle The handle to receive the create child. + + @retval EFI_SUCCESS Can't create the corresponding REST EX c= hild instance. + @retval EFI_INVALID_PARAMETERS Any of input parameters is improper. + +**/ +EFI_STATUS +RestExLibCreateChild ( + IN EFI_HANDLE Image, + IN EFI_REST_EX_SERVICE_ACCESS_MODE AccessMode, + IN EFI_REST_EX_CONFIG_TYPE ConfigType, + IN EFI_REST_EX_SERVICE_TYPE ServiceType, + OUT EFI_HANDLE *ChildInstanceHandle +) +{ + EFI_STATUS Status; + UINTN NoBuffer; + EFI_HANDLE *Handle; + EFI_HANDLE ChildHandle; + EFI_REST_EX_PROTOCOL *RestEx; + EFI_REST_EX_SERVICE_INFO *RestExServiceInfo; + UINT8 LenOfConfig; + + if (Image =3D=3D NULL || + AccessMode >=3D EfiRestExServiceModeMax || + ConfigType >=3D EfiRestExConfigTypeMax || + ServiceType >=3D EfiRestExServiceTypeMax || + ChildInstanceHandle =3D=3D NULL + ) { + return EFI_INVALID_PARAMETER; + } + + *ChildInstanceHandle =3D NULL; + // + // Locate all REST EX binding service. + // + Handle =3D NULL; + NoBuffer =3D 0; + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiRestExServiceBindingProtocolGuid, + NULL, + &NoBuffer, + &Handle + ); + if (EFI_ERROR (Status) && Status !=3D EFI_BUFFER_TOO_SMALL) { + return Status; + } + Handle =3D (EFI_HANDLE *)AllocateZeroPool (sizeof(EFI_HANDLE) * NoBuffer= ); + if (Handle =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiRestExServiceBindingProtocolGuid, + NULL, + &NoBuffer, + &Handle + ); + if (EFI_ERROR (Status)) { + FreePool (Handle); + return Status; + } + + // + // Search for the proper REST EX instance. + // + while (NoBuffer !=3D 0) { + ChildHandle =3D NULL; + Status =3D NetLibCreateServiceChild ( + *(Handle + (NoBuffer - 1)), + Image, + &gEfiRestExServiceBindingProtocolGuid, + &ChildHandle + ); + if (!EFI_ERROR (Status)) { + Status =3D gBS->OpenProtocol ( + ChildHandle, + &gEfiRestExProtocolGuid, + (VOID **)&RestEx, + Image, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + + // + // Get the information of REST service provided by this EFI REST EX = driver + // + Status =3D RestEx->GetService ( + RestEx, + &RestExServiceInfo + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + // + // Check REST EX property. + // + switch (ConfigType) { + case EfiRestExConfigHttp: + LenOfConfig =3D sizeof (EFI_REST_EX_HTTP_CONFIG_DATA); + break; + + case EfiRestExConfigUnspecific: + LenOfConfig =3D REST_EX_CONFIG_DATA_LEN_UNKNOWN; + break; + + default: + goto ON_ERROR; + } + if (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode= !=3D AccessMode || + RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType !=3D = ServiceType || + RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType !=3D= ConfigType || + ((LenOfConfig !=3D REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExSe= rviceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength !=3D LenOfConfig)= )) { + goto ON_ERROR; + } + } + // + // This is proper REST EX instance. + // + *ChildInstanceHandle =3D ChildHandle; + FreePool (Handle); + return EFI_SUCCESS; + +ON_ERROR:; + NetLibDestroyServiceChild ( + *(Handle + (NoBuffer - 1)), + Image, + &gEfiRestExServiceBindingProtocolGuid, + ChildHandle + ); + NoBuffer --; + }; + FreePool (Handle); + return EFI_NOT_FOUND; +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69185): https://edk2.groups.io/g/devel/message/69185 Mute This Topic: https://groups.io/mt/79059851/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-