From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.49]) by mx.groups.io with SMTP id smtpd.web11.19155.1675242567625744928 for ; Wed, 01 Feb 2023 01:09:27 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=krcrOnBs; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.94.49, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gft3cDNDSuR2XN90brPWLWibNixCs3Hl/vvdtHTNizbHuUz0XI131ob7pqF3vZ4YEfYYAN+MDs9ozprIlTYvzZaK2Yxhh/qWbWBbOOaXDW0wA2g5K54RIJ5dDfxgBFwRc4EavC3Xz7UjZ67jl8My9MADuDYtfzsKUZFunNqtHWSY1Cbi96eqei1jdCuDoXrgb5+JJsZZMCTRhxhn9F9Kzgr030aSvm0ve1gHOG9AsUpShqqhdGCKPTXfyvD/zHBbx/BpgySQxRDBZgmkQDEafK49vaOqNO/foGRVdhv9Ulh2GiHv4pZAuN0PGPf/Bb8ARfIOBQ6OJUic+flepGi2qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pVTjxrvAR1YY/M43rYcEZnInDsaYGd3gBRo7OGITtoQ=; b=I6MYnI/ZAe6xjPfSwyWYCl4zhgsaUCSVCUH6lq5MR1mqboKofCahkhn3AHMpazX1jFlQ684EQnVG/5UQqqCLjjd0zIrBhySEZDOArBP6DSNnBvco4+kHFZXe2onkmXn9LZou/B53T6ffCnVJcdMuglzuJDwmE+bZMm4k+lIyUULi6UEmoUacSis/WUEhrxccWVtLYOrdbLmFM3sSNNqlbHcI7aqtrNl5QAsRepB/iitX487bNIZs6R5+dg9ick9+/71jr7zGRBU1b2AnwAQz/3R4bdUWGhdfbjWO+5rh7jtPh7CXcv1ETPTXkX3wT9oZeo1SJsfQqdvWpVloNP7asQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pVTjxrvAR1YY/M43rYcEZnInDsaYGd3gBRo7OGITtoQ=; b=krcrOnBstyslY+KkQWkNwbGxRNRix5Vli6J3+F9FQ25uFBvKyxqlQdFmO+vKooxORbfB6xn6q1SHrOe0kbyg/PMgpzp4o8J/uq7Q6Y1z7jufs6j2bbmmLPHdiRzZ5HAE8fMEARwEXTtznb3Vg516iqqAeGQx7Nuxcbco3146LRIJVIHhFA4nHAcKJ3lwBNwrEyngOf7JlO1XiWyUG9r4yVYckr9J4turT4GXqkHDvc4bychVTrHnI9TDbWQ2MJDRWuz2HUdBfc3xHt0vM/GHvp2J8CxJEjgo9IauNfGvTKAecD9IJ2g0bci8s50MrbIzQHme8OuKIuA0d2/M1hemSw== Received: from MW4P220CA0010.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::15) by SJ1PR12MB6050.namprd12.prod.outlook.com (2603:10b6:a03:48b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Wed, 1 Feb 2023 09:09:24 +0000 Received: from CO1NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::e2) by MW4P220CA0010.outlook.office365.com (2603:10b6:303:115::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Wed, 1 Feb 2023 09:09:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CO1NAM11FT049.mail.protection.outlook.com (10.13.175.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.36 via Frontend Transport; Wed, 1 Feb 2023 09:09:23 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Wed, 1 Feb 2023 01:09:13 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Wed, 1 Feb 2023 01:09:12 -0800 Received: from NV-CL38DL3.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Wed, 1 Feb 2023 01:09:11 -0800 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy , "Nick Ramirez" Subject: [PATCH 1/1] RedfishPkg/RedfishDebugLib: provide Redfish debug functions Date: Wed, 1 Feb 2023 17:09:11 +0800 Message-ID: <20230201090911.849-1-nicklew@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Return-Path: nicklew@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT049:EE_|SJ1PR12MB6050:EE_ X-MS-Office365-Filtering-Correlation-Id: 1690bf6a-9fd2-4847-c9d9-08db0434030d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eMbWadJlu+m96/hiyrYAH9aQIGtTjyp9eaVRR4FLVA1fQfmwz4YYiAk8MYluV4NHEZIF9SrPSnGaz0Ly1b4AcB8GMmU3bV03/liiBenumpvRmI4MWdvu0WIeth67Jjj4ZVYlJUQmlJAJg98xmIpJmDIs685+xanVbetK65top9zmOuid6NUxL8lMkNbr3Gf7pxFzkh2qtgpcaEwpuvQijrA0HgdVpNnEt2/M70vszBY82/VvSqGo+Va7BDw72OV7gHFZjtoba7/LaiR/dzFgla+GrlWdhFvLNVSOJTdv6Ey26ea6yxQATKpupyeuSpqeAvLwgVZL68fUgy0NlPybcekWxYPEtKQCnv5jtLz7+UbW4kGQVt8LzKz+zALhBet1ZOxUt7A9K2XzkWJEhHWMPGwVsB6r/VhhP+MhXXpyBr4jsyXTdmdOoVxoYpH8dgrPWf68QaBSNr2WYpaveld2DecpxzlRKOeh/ztYwmLIGuLmxsfJtdLLLm28A3ebe1ZaJfZLrCsVMm3+9HTagldCkWNO0jY+AFyQN/X+DYJH8ZFeDI3i/HaBlHEWcTjkr3ORyd7FQLopyJZYlgJw3FYw9H4ki1Z0HT/ebThNMQG5K6+UOTf63PAnUiiE8lO5B19ibxthJ0QfXJPuRuWKAYg5yaFCNfguICs6NyPA271F9UUBJH5qY2jwwHxo9gC8hjm9Tc5VTuEaMxbh5La+4GAplw== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(346002)(136003)(396003)(376002)(451199018)(46966006)(40470700004)(36840700001)(316002)(356005)(8936002)(40480700001)(7696005)(2906002)(83380400001)(478600001)(4326008)(82310400005)(30864003)(8676002)(6916009)(426003)(70206006)(70586007)(47076005)(107886003)(186003)(86362001)(26005)(54906003)(1076003)(7636003)(82740400003)(2616005)(36756003)(41300700001)(40460700003)(336012)(5660300002)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2023 09:09:23.8165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1690bf6a-9fd2-4847-c9d9-08db0434030d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6050 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Introduce RedfishDebugLib to RedfishPkg. This library provides several debugging functions for Redfish application. Redfish drivers rely on Rest Ex protocol to communicate with BMC and the communication data may be big and complicated. Use RedfishDebugLib in RedfishRestExDxe to simplify debugging process. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- RedfishPkg/RedfishPkg.dec | 5 + RedfishPkg/RedfishLibs.dsc.inc | 2 + .../RedfishDebugLib/RedfishDebugLib.inf | 38 +++ .../RedfishRestExDxe/RedfishRestExDxe.inf | 2 + RedfishPkg/Include/Library/RedfishDebugLib.h | 90 +++++++ .../RedfishRestExDxe/RedfishRestExInternal.h | 2 + .../Library/RedfishDebugLib/RedfishDebugLib.c | 229 ++++++++++++++++++ .../RedfishRestExDxe/RedfishRestExProtocol.c | 32 +-- 8 files changed, 385 insertions(+), 15 deletions(-) create mode 100644 RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf create mode 100644 RedfishPkg/Include/Library/RedfishDebugLib.h create mode 100644 RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index d2b189b13d..e1158b7050 100644 --- a/RedfishPkg/RedfishPkg.dec +++ b/RedfishPkg/RedfishPkg.dec @@ -3,6 +3,7 @@ # # Copyright (c) 2019, Intel Corporation. All rights reserved.
# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . # # SPDX-License-Identifier: BSD-2-Clause-Patent ## @@ -54,6 +55,10 @@ # RedfishContentCodingLib|Include/Library/RedfishContentCodingLib.h =20 + ## @libraryclass Redfish Debug Library + # Library provides Redfish debug functions. + RedfishDebugLib|Include/Library/RedfishDebugLib.h + [LibraryClasses.Common.Private] ## @libraryclass Provides the private C runtime library functions. # CRT library is currently used by edk2 JsonLib (open source diff --git a/RedfishPkg/RedfishLibs.dsc.inc b/RedfishPkg/RedfishLibs.dsc.in= c index 56950b711f..84f52d4b27 100644 --- a/RedfishPkg/RedfishLibs.dsc.inc +++ b/RedfishPkg/RedfishLibs.dsc.inc @@ -6,6 +6,7 @@ # of EDKII network library classes. # # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -17,5 +18,6 @@ RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf RedfishLib|RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf + RedfishDebugLib|RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf !endif =20 diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf b/Redfi= shPkg/Library/RedfishDebugLib/RedfishDebugLib.inf new file mode 100644 index 0000000000..b9d88cc70c --- /dev/null +++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf @@ -0,0 +1,38 @@ +## @file +# +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D RedfishDebugLib + FILE_GUID =3D 7F64C79F-ABD0-4446-86B5-2C1AE36168AD + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RedfishDebugLib| DXE_DRIVER UEFI_DRIV= ER + +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + RedfishDebugLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + JsonLib + MemoryAllocationLib + RedfishLib + UefiLib + +[Depex] + TRUE diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf b/RedfishPkg/= RedfishRestExDxe/RedfishRestExDxe.inf index 75437b086a..3f10fd733e 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf @@ -3,6 +3,7 @@ # # Copyright (c) 2019, Intel Corporation. All rights reserved.
# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -43,6 +44,7 @@ PrintLib MemoryAllocationLib NetLib + RedfishDebugLib UefiLib UefiBootServicesTableLib UefiDriverEntryPoint diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h b/RedfishPkg/Incl= ude/Library/RedfishDebugLib.h new file mode 100644 index 0000000000..387b06c734 --- /dev/null +++ b/RedfishPkg/Include/Library/RedfishDebugLib.h @@ -0,0 +1,90 @@ +/** @file + This file defines the Redfish debug library interface. + + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REDFISH_DEBUG_LIB_H_ +#define REDFISH_DEBUG_LIB_H_ + +#include +#include +#include + +#define DEBUG_REDFISH_NETWORK DEBUG_INFO ///< Debug error level for Red= fish networking function + +/** + + This function dump the Json string in given error level. + + @param[in] ErrorLevel DEBUG macro error level + @param[in] JsonValue Json value to dump. + + @retval EFI_SUCCESS Json string is printed. + @retval Others Errors occur. + +**/ +EFI_STATUS +DumpJsonValue ( + IN UINTN ErrorLevel, + IN EDKII_JSON_VALUE JsonValue + ); + +/** + + This function dump the status code, header and body in given + Redfish payload. + + @param[in] ErrorLevel DEBUG macro error level + @param[in] Payload Redfish payload to dump + + @retval EFI_SUCCESS Redfish payload is printed. + @retval Others Errors occur. + +**/ +EFI_STATUS +DumpRedfishPayload ( + IN UINTN ErrorLevel, + IN REDFISH_PAYLOAD Payload + ); + +/** + + This function dump the status code, header and body in given + Redfish response. + + @param[in] Message Message string + @param[in] ErrorLevel DEBUG macro error level + @param[in] Response Redfish response to dump + + @retval EFI_SUCCESS Redfish response is printed. + @retval Others Errors occur. + +**/ +EFI_STATUS +DumpRedfishResponse ( + IN CONST CHAR8 *Message, + IN UINTN ErrorLevel, + IN REDFISH_RESPONSE *Response + ); + +/** + + This function dump the HTTP status code. + + @param[in] ErrorLevel DEBUG macro error level + @param[in] HttpStatusCode HTTP status code + + @retval EFI_SUCCESS HTTP status code is printed + +**/ +EFI_STATUS +DumpHttpStatusCode ( + IN UINTN ErrorLevel, + IN EFI_HTTP_STATUS_CODE HttpStatusCode + ); + +#endif diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h b/RedfishP= kg/RedfishRestExDxe/RedfishRestExInternal.h index a687c4ddb1..bca679e2cc 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExInternal.h @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2019-2020 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c b/Redfish= Pkg/Library/RedfishDebugLib/RedfishDebugLib.c new file mode 100644 index 0000000000..de242d581b --- /dev/null +++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c @@ -0,0 +1,229 @@ +/** @file + Redfish debug library to debug Redfish application. + + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include + +#ifndef IS_EMPTY_STRING +#define IS_EMPTY_STRING(a) ((a) =3D=3D NULL || (a)[0] =3D=3D '\0') +#endif + +#define REDFISH_JSON_STRING_LENGTH 200 +#define REDFISH_JSON_OUTPUT_FORMAT (EDKII_JSON_COMPACT | EDKII_JSON_INDEN= T(2)) + +/** + + This function dump the Json string in given error level. + + @param[in] ErrorLevel DEBUG macro error level + @param[in] JsonValue Json value to dump. + + @retval EFI_SUCCESS Json string is printed. + @retval Others Errors occur. + +**/ +EFI_STATUS +DumpJsonValue ( + IN UINTN ErrorLevel, + IN EDKII_JSON_VALUE JsonValue + ) +{ + CHAR8 *String; + CHAR8 *Runner; + CHAR8 Buffer[REDFISH_JSON_STRING_LENGTH + 1]; + UINTN StrLen; + UINTN Count; + UINTN Index; + + if (JsonValue =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + String =3D JsonDumpString (JsonValue, REDFISH_JSON_OUTPUT_FORMAT); + if (String =3D=3D NULL) { + return EFI_UNSUPPORTED; + } + + StrLen =3D AsciiStrLen (String); + if (StrLen =3D=3D 0) { + return EFI_UNSUPPORTED; + } + + Count =3D StrLen / REDFISH_JSON_STRING_LENGTH; + Runner =3D String; + for (Index =3D 0; Index < Count; Index++) { + AsciiStrnCpyS (Buffer, (REDFISH_JSON_STRING_LENGTH + 1), Runner, REDFI= SH_JSON_STRING_LENGTH); + Buffer[REDFISH_JSON_STRING_LENGTH] =3D '\0'; + DEBUG ((ErrorLevel, "%a", Buffer)); + Runner +=3D REDFISH_JSON_STRING_LENGTH; + } + + Count =3D StrLen % REDFISH_JSON_STRING_LENGTH; + if (Count > 0) { + DEBUG ((ErrorLevel, "%a", Runner)); + } + + DEBUG ((ErrorLevel, "\n")); + + FreePool (String); + return EFI_SUCCESS; +} + +/** + + This function dump the status code, header and body in given + Redfish payload. + + @param[in] ErrorLevel DEBUG macro error level + @param[in] Payload Redfish payload to dump + + @retval EFI_SUCCESS Redfish payload is printed. + @retval Others Errors occur. + +**/ +EFI_STATUS +DumpRedfishPayload ( + IN UINTN ErrorLevel, + IN REDFISH_PAYLOAD Payload + ) +{ + EDKII_JSON_VALUE JsonValue; + + if (Payload =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + JsonValue =3D RedfishJsonInPayload (Payload); + if (JsonValue !=3D NULL) { + DEBUG ((ErrorLevel, "Payload:\n")); + DumpJsonValue (ErrorLevel, JsonValue); + } + + return EFI_SUCCESS; +} + +/** + + This function dump the HTTP status code. + + @param[in] ErrorLevel DEBUG macro error level + @param[in] HttpStatusCode HTTP status code + + @retval EFI_SUCCESS HTTP status code is printed + +**/ +EFI_STATUS +DumpHttpStatusCode ( + IN UINTN ErrorLevel, + IN EFI_HTTP_STATUS_CODE HttpStatusCode + ) +{ + switch (HttpStatusCode) { + case HTTP_STATUS_100_CONTINUE: + DEBUG ((ErrorLevel, "Status code: 100 CONTINUE\n")); + break; + case HTTP_STATUS_200_OK: + DEBUG ((ErrorLevel, "Status code: 200 OK\n")); + break; + case HTTP_STATUS_201_CREATED: + DEBUG ((ErrorLevel, "Status code: 201 CREATED\n")); + break; + case HTTP_STATUS_202_ACCEPTED: + DEBUG ((ErrorLevel, "Status code: 202 ACCEPTED\n")); + break; + case HTTP_STATUS_304_NOT_MODIFIED: + DEBUG ((ErrorLevel, "Status code: 304 NOT MODIFIED\n")); + break; + case HTTP_STATUS_400_BAD_REQUEST: + DEBUG ((ErrorLevel, "Status code: 400 BAD REQUEST\n")); + break; + case HTTP_STATUS_401_UNAUTHORIZED: + DEBUG ((ErrorLevel, "Status code: 401 UNAUTHORIZED\n")); + break; + case HTTP_STATUS_403_FORBIDDEN: + DEBUG ((ErrorLevel, "Status code: 403 FORBIDDEN\n")); + break; + case HTTP_STATUS_404_NOT_FOUND: + DEBUG ((ErrorLevel, "Status code: 404 NOT FOUND\n")); + break; + case HTTP_STATUS_405_METHOD_NOT_ALLOWED: + DEBUG ((ErrorLevel, "Status code: 405 METHOD NOT ALLOWED\n")); + break; + case HTTP_STATUS_500_INTERNAL_SERVER_ERROR: + DEBUG ((ErrorLevel, "Status code: 500 INTERNAL SERVER ERROR\n")); + break; + default: + DEBUG ((ErrorLevel, "Status code: 0x%x\n", HttpStatusCode)); + break; + } + + return EFI_SUCCESS; +} + +/** + + This function dump the status code, header and body in given + Redfish response. + + @param[in] Message Message string + @param[in] ErrorLevel DEBUG macro error level + @param[in] Response Redfish response to dump + + @retval EFI_SUCCESS Redfish response is printed. + @retval Others Errors occur. + +**/ +EFI_STATUS +DumpRedfishResponse ( + IN CONST CHAR8 *Message, + IN UINTN ErrorLevel, + IN REDFISH_RESPONSE *Response + ) +{ + UINTN Index; + + if (Response =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (!IS_EMPTY_STRING (Message)) { + DEBUG ((ErrorLevel, "%a\n", Message)); + } + + // + // status code + // + if (Response->StatusCode !=3D NULL) { + DumpHttpStatusCode (ErrorLevel, *(Response->StatusCode)); + } + + // + // header + // + if (Response->HeaderCount > 0) { + DEBUG ((ErrorLevel, "Header: %d\n", Response->HeaderCount)); + for (Index =3D 0; Index < Response->HeaderCount; Index++) { + DEBUG ((ErrorLevel, " %a: %a\n", Response->Headers[Index].FieldName= , Response->Headers[Index].FieldValue)); + } + } + + // + // Body + // + if (Response->Payload !=3D NULL) { + DumpRedfishPayload (ErrorLevel, Response->Payload); + } + + return EFI_SUCCESS; +} diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c b/RedfishP= kg/RedfishRestExDxe/RedfishRestExProtocol.c index 4b61fc01ad..662b69512c 100644 --- a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c +++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c @@ -3,6 +3,7 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -87,12 +88,12 @@ RedfishRestExSendReceive ( MediaPresent =3D TRUE; NetLibDetectMedia (Instance->Service->ControllerHandle, &MediaPresent); if (!MediaPresent) { - DEBUG ((DEBUG_INFO, "RedfishRestExSendReceive(): No MediaPresent.\n"))= ; + DEBUG ((DEBUG_REDFISH_NETWORK, "RedfishRestExSendReceive(): No MediaPr= esent.\n")); return EFI_NO_MEDIA; } =20 - DEBUG ((DEBUG_INFO, "\nRedfishRestExSendReceive():\n")); - DEBUG ((DEBUG_INFO, "*** Perform HTTP Request Method - %d, URL: %s\n", R= equestMessage->Data.Request->Method, RequestMessage->Data.Request->Url)); + DEBUG ((DEBUG_REDFISH_NETWORK, "\nRedfishRestExSendReceive():\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "*** Perform HTTP Request Method - %d, UR= L: %s\n", RequestMessage->Data.Request->Method, RequestMessage->Data.Reques= t->Url)); =20 // // Add header "Expect" to server, only for URL write. @@ -195,7 +196,7 @@ ReSendRequest:; goto ON_EXIT; } =20 - DEBUG ((DEBUG_INFO, "Receiving HTTP response and headers...\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "Receiving HTTP response and headers...\n= ")); Status =3D RedfishCheckHttpReceiveStatus ( Instance, HttpIoRecvResponse ( @@ -219,17 +220,17 @@ ReSendRequest:; RequestMessage->HeaderCount--; // Minus one header= count for "Expect". } =20 - DEBUG ((DEBUG_INFO, "HTTP Response StatusCode - %d:", ResponseData->Resp= onse.StatusCode)); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP Response StatusCode - %d:", Respons= eData->Response.StatusCode)); if (ResponseData->Response.StatusCode =3D=3D HTTP_STATUS_200_OK) { - DEBUG ((DEBUG_INFO, "HTTP_STATUS_200_OK\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_200_OK\n")); =20 if (SendChunkProcess =3D=3D HttpIoSendChunkHeaderZeroContent) { - DEBUG ((DEBUG_INFO, "This is chunk transfer, start to send all chunk= s.")); + DEBUG ((DEBUG_REDFISH_NETWORK, "This is chunk transfer, start to sen= d all chunks.")); SendChunkProcess++; goto ReSendRequest; } } else if (ResponseData->Response.StatusCode =3D=3D HTTP_STATUS_413_REQU= EST_ENTITY_TOO_LARGE) { - DEBUG ((DEBUG_INFO, "HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_413_REQUEST_ENTITY_TOO_LAR= GE\n")); =20 Status =3D EFI_BAD_BUFFER_SIZE; goto ON_EXIT; @@ -239,25 +240,25 @@ ReSendRequest:; Status =3D EFI_ACCESS_DENIED; goto ON_EXIT; } else if (ResponseData->Response.StatusCode =3D=3D HTTP_STATUS_400_BAD_= REQUEST) { - DEBUG ((DEBUG_INFO, "HTTP_STATUS_400_BAD_REQUEST\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_400_BAD_REQUEST\n")); if (SendChunkProcess =3D=3D HttpIoSendChunkHeaderZeroContent) { - DEBUG ((DEBUG_INFO, "Bad request may caused by zero length chunk. Tr= y to send all chunks...\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "Bad request may caused by zero lengt= h chunk. Try to send all chunks...\n")); SendChunkProcess++; goto ReSendRequest; } } else if (ResponseData->Response.StatusCode =3D=3D HTTP_STATUS_100_CONT= INUE) { - DEBUG ((DEBUG_INFO, "HTTP_STATUS_100_CONTINUE\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_100_CONTINUE\n")); if (SendChunkProcess =3D=3D HttpIoSendChunkHeaderZeroContent) { // // We get HTTP_STATUS_100_CONTINUE to send the body using chunk tran= sfer. // - DEBUG ((DEBUG_INFO, "HTTP_STATUS_100_CONTINUE for chunk transfer...\= n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_100_CONTINUE for chunk t= ransfer...\n")); SendChunkProcess++; goto ReSendRequest; } =20 if (SendNonChunkProcess =3D=3D HttpIoSendNonChunkHeaderZeroContent) { - DEBUG ((DEBUG_INFO, "HTTP_STATUS_100_CONTINUE for non chunk transfer= ...\n")); + DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_100_CONTINUE for non chu= nk transfer...\n")); SendNonChunkProcess++; goto ReSendRequest; } @@ -281,6 +282,7 @@ ReSendRequest:; } } else { DEBUG ((DEBUG_ERROR, "This HTTP Status is not handled!\n")); + DumpHttpStatusCode (DEBUG_REDFISH_NETWORK, ResponseData->Response.Stat= usCode); Status =3D EFI_UNSUPPORTED; goto ON_EXIT; } @@ -394,10 +396,10 @@ ReSendRequest:; TotalReceivedSize +=3D ResponseData->BodyLength; } =20 - DEBUG ((DEBUG_INFO, "Total of lengh of Response :%d\n", TotalReceivedS= ize)); + DEBUG ((DEBUG_REDFISH_NETWORK, "Total of lengh of Response :%d\n", Tot= alReceivedSize)); } =20 - DEBUG ((DEBUG_INFO, "RedfishRestExSendReceive()- EFI_STATUS: %r\n", Stat= us)); + DEBUG ((DEBUG_REDFISH_NETWORK, "RedfishRestExSendReceive()- EFI_STATUS: = %r\n", Status)); =20 ON_EXIT: =20 --=20 2.39.1.windows.1