From ef8ee3239de27f1ca9290b51738ae407922d4c16 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Fri, 23 Feb 2024 11:19:12 +0100 Subject: [PATCH] [DiagnosticLogs] Allow TransferFileDesignator or size 0 (#32267) --- .../common/BDXDiagnosticLogsServerDelegate.cpp | 13 ++++++++++--- .../diagnostic-logs-server.cpp | 2 -- src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp | 1 - src/protocols/bdx/StatusCode.cpp | 8 ++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp b/examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp index 27260a54f57887..2a5b2d5d7c97a1 100644 --- a/examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp +++ b/examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp @@ -25,9 +25,10 @@ constexpr uint8_t kMaxFileDesignatorLen = 32; constexpr uint16_t kMaxFilePathLen = kMaxFileDesignatorLen + sizeof(kTmpDir) + 1; // For testing a few file names trigger an error depending on the current 'phase'. -constexpr char kErrorOnTransferBegin[] = "Error:OnTransferBegin"; -constexpr char kErrorOnTransferData[] = "Error:OnTransferData"; -constexpr char kErrorOnTransferEnd[] = "Error:OnTransferEnd"; +constexpr char kErrorOnTransferBegin[] = "Error:OnTransferBegin"; +constexpr char kErrorOnTransferData[] = "Error:OnTransferData"; +constexpr char kErrorOnTransferEnd[] = "Error:OnTransferEnd"; +constexpr char kErrorTransferMethodNotSupported[] = "TransferMethodNotSupported.txt"; BDXDiagnosticLogsServerDelegate BDXDiagnosticLogsServerDelegate::sInstance; @@ -136,8 +137,14 @@ CHIP_ERROR BDXDiagnosticLogsServerDelegate::OnTransferBegin(chip::bdx::BDXTransf auto fileDesignator = transfer->GetFileDesignator(); LogFileDesignator("OnTransferBegin", fileDesignator); + VerifyOrReturnError(fileDesignator.size() != 0, CHIP_ERROR_UNKNOWN_RESOURCE_ID); + chip::CharSpan phaseErrorTarget(kErrorOnTransferBegin, sizeof(kErrorOnTransferBegin) - 1); ReturnErrorOnFailure(CheckForErrorRequested(phaseErrorTarget, fileDesignator)); + + chip::CharSpan transferErrorTarget(kErrorTransferMethodNotSupported, sizeof(kErrorTransferMethodNotSupported) - 1); + VerifyOrReturnError(!transferErrorTarget.data_equal(fileDesignator), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + ReturnErrorOnFailure(CheckFileDesignatorAllowed(mFileDesignators, fileDesignator)); char outputFilePath[kMaxFilePathLen] = { 0 }; diff --git a/src/app/clusters/diagnostic-logs-server/diagnostic-logs-server.cpp b/src/app/clusters/diagnostic-logs-server/diagnostic-logs-server.cpp index 7b1b036ee4857b..83beb46484bb71 100644 --- a/src/app/clusters/diagnostic-logs-server/diagnostic-logs-server.cpp +++ b/src/app/clusters/diagnostic-logs-server/diagnostic-logs-server.cpp @@ -132,8 +132,6 @@ void DiagnosticLogsServer::HandleLogRequestForBdx(CommandHandler * commandObj, c // INVALID_COMMAND. VerifyOrReturn(transferFileDesignator.HasValue(), commandObj->AddStatus(path, Status::InvalidCommand)); - VerifyOrReturn(transferFileDesignator.Value().size() > 0, commandObj->AddStatus(path, Status::ConstraintError)); - VerifyOrReturn(transferFileDesignator.Value().size() <= kMaxFileDesignatorLen, commandObj->AddStatus(path, Status::ConstraintError)); diff --git a/src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp b/src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp index 3f8915462941fb..ba1a41376afbbe 100644 --- a/src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp +++ b/src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp @@ -33,7 +33,6 @@ CHIP_ERROR BDXTransferProxyDiagnosticLog::Init(TransferSession * transferSession uint16_t fileDesignatorLength = 0; auto fileDesignator = transferSession->GetFileDesignator(fileDesignatorLength); - VerifyOrReturnError(fileDesignatorLength > 0, CHIP_ERROR_INVALID_STRING_LENGTH); VerifyOrReturnError(fileDesignatorLength <= ArraySize(mFileDesignator), CHIP_ERROR_INVALID_STRING_LENGTH); mTransfer = transferSession; diff --git a/src/protocols/bdx/StatusCode.cpp b/src/protocols/bdx/StatusCode.cpp index 2f739b5e831de2..9ab6f8d9b442be 100644 --- a/src/protocols/bdx/StatusCode.cpp +++ b/src/protocols/bdx/StatusCode.cpp @@ -33,6 +33,14 @@ StatusCode GetBdxStatusCodeFromChipError(CHIP_ERROR error) { status = StatusCode::kBadMessageContents; } + else if (error == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) + { + status = StatusCode::kTransferMethodNotSupported; + } + else if (error == CHIP_ERROR_UNKNOWN_RESOURCE_ID) + { + status = StatusCode::kFileDesignatorUnknown; + } return status; }