From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=dGKY1BzA; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0621f7b516=abner.chang@hpe.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id; s=pps0720; bh=1ExCQLZDUNC6MeKlY8fTA6qqVUzNdSB8Q15YFDMnar4=; b=dGKY1BzABooyntMn2l6UrE0wf5k3TMlTxjjW2K2Jp6t0r0jXv0X89m1RemgT2uyYcKxx qWI/XJaOMoY95o3DNBENJlNx/ROdsaBPcImPJdVxK5oxUr5+yjgxinsS4KbiFO7H1FK2 f2+K0GD0ClciBmbbmr9aE9+OTqVLxpvieM+bQLNdYGRPkjyNlP5/Fqhjv1J/PbN9vjOx t0llc9rFiGdbqUkEWjDtZ5YIGXDTc3JFXci0mZQmDOF5y2wpVY0d0YH4uo5qTc0IHoKy YwBmpXoJ8YcrgVRmITECaeFUmiHC0QL3cLyVr7hn26BnQFrIZRee1MhCSEPQ9CM/i1Uu eg== 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 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) 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: [PATCH v2] RedfishPkg/DxeRestExLib: DxeRestExLib Date: Fri, 18 Dec 2020 08:22:20 +0800 Message-Id: <20201218002220.11748-1-abner.chang@hpe.com> X-Mailer: git-send-email 2.17.1 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2020-12-18_08:2020-12-18,2020-12-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 adultscore=0 mlxlogscore=858 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180089 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 --- 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 + ## @libraryclass The helper routines to access REST EX service. + # This library is only intended to be used by UEFI network stack modules. + RestExLib|Include/Library/RestExLib.h + [Protocols] ## Include/Protocol/RedfishDiscover.h gEfiRedfishDiscoverProtocolGuid = { 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) == TRUE + RestExLib|RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf !endif 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/PlatformHostInterfaceLibNull.inf RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.inf + RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf !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 = 0x0001001b + BASE_NAME = DxeRestExLib + FILE_GUID = E9CBF727-8AF3-4602-9DBD-A3942869B5AE + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = RestExLib | DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER + +# +# VALID_ARCHITECTURES = 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/Library/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 child 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/Library/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 child 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 == NULL || + AccessMode >= EfiRestExServiceModeMax || + ConfigType >= EfiRestExConfigTypeMax || + ServiceType >= EfiRestExServiceTypeMax || + ChildInstanceHandle == NULL + ) { + return EFI_INVALID_PARAMETER; + } + + *ChildInstanceHandle = NULL; + // + // Locate all REST EX binding service. + // + Handle = NULL; + NoBuffer = 0; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiRestExServiceBindingProtocolGuid, + NULL, + &NoBuffer, + &Handle + ); + if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) { + return Status; + } + Handle = (EFI_HANDLE *)AllocateZeroPool (sizeof(EFI_HANDLE) * NoBuffer); + if (Handle == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiRestExServiceBindingProtocolGuid, + NULL, + &NoBuffer, + &Handle + ); + if (EFI_ERROR (Status)) { + FreePool (Handle); + return Status; + } + + // + // Search for the proper REST EX instance. + // + while (NoBuffer != 0) { + ChildHandle = NULL; + Status = NetLibCreateServiceChild ( + *(Handle + (NoBuffer - 1)), + Image, + &gEfiRestExServiceBindingProtocolGuid, + &ChildHandle + ); + if (!EFI_ERROR (Status)) { + Status = 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 = RestEx->GetService ( + RestEx, + &RestExServiceInfo + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + // + // Check REST EX property. + // + switch (ConfigType) { + case EfiRestExConfigHttp: + LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA); + break; + + case EfiRestExConfigUnspecific: + LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN; + break; + + default: + goto ON_ERROR; + } + if (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode || + RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType || + RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType || + ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig))) { + goto ON_ERROR; + } + } + // + // This is proper REST EX instance. + // + *ChildInstanceHandle = ChildHandle; + FreePool (Handle); + return EFI_SUCCESS; + +ON_ERROR:; + NetLibDestroyServiceChild ( + *(Handle + (NoBuffer - 1)), + Image, + &gEfiRestExServiceBindingProtocolGuid, + ChildHandle + ); + NoBuffer --; + }; + FreePool (Handle); + return EFI_NOT_FOUND; +} -- 2.17.1