Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DiagnosticLogs] Allow TransferFileDesignator or size 0 #32267

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
1 change: 0 additions & 1 deletion src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/protocols/bdx/StatusCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading