Skip to content

Commit ef8ee32

Browse files
authored
[DiagnosticLogs] Allow TransferFileDesignator or size 0 (#32267)
1 parent 003c478 commit ef8ee32

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ constexpr uint8_t kMaxFileDesignatorLen = 32;
2525
constexpr uint16_t kMaxFilePathLen = kMaxFileDesignatorLen + sizeof(kTmpDir) + 1;
2626

2727
// For testing a few file names trigger an error depending on the current 'phase'.
28-
constexpr char kErrorOnTransferBegin[] = "Error:OnTransferBegin";
29-
constexpr char kErrorOnTransferData[] = "Error:OnTransferData";
30-
constexpr char kErrorOnTransferEnd[] = "Error:OnTransferEnd";
28+
constexpr char kErrorOnTransferBegin[] = "Error:OnTransferBegin";
29+
constexpr char kErrorOnTransferData[] = "Error:OnTransferData";
30+
constexpr char kErrorOnTransferEnd[] = "Error:OnTransferEnd";
31+
constexpr char kErrorTransferMethodNotSupported[] = "TransferMethodNotSupported.txt";
3132

3233
BDXDiagnosticLogsServerDelegate BDXDiagnosticLogsServerDelegate::sInstance;
3334

@@ -136,8 +137,14 @@ CHIP_ERROR BDXDiagnosticLogsServerDelegate::OnTransferBegin(chip::bdx::BDXTransf
136137
auto fileDesignator = transfer->GetFileDesignator();
137138
LogFileDesignator("OnTransferBegin", fileDesignator);
138139

140+
VerifyOrReturnError(fileDesignator.size() != 0, CHIP_ERROR_UNKNOWN_RESOURCE_ID);
141+
139142
chip::CharSpan phaseErrorTarget(kErrorOnTransferBegin, sizeof(kErrorOnTransferBegin) - 1);
140143
ReturnErrorOnFailure(CheckForErrorRequested(phaseErrorTarget, fileDesignator));
144+
145+
chip::CharSpan transferErrorTarget(kErrorTransferMethodNotSupported, sizeof(kErrorTransferMethodNotSupported) - 1);
146+
VerifyOrReturnError(!transferErrorTarget.data_equal(fileDesignator), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
147+
141148
ReturnErrorOnFailure(CheckFileDesignatorAllowed(mFileDesignators, fileDesignator));
142149

143150
char outputFilePath[kMaxFilePathLen] = { 0 };

src/app/clusters/diagnostic-logs-server/diagnostic-logs-server.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ void DiagnosticLogsServer::HandleLogRequestForBdx(CommandHandler * commandObj, c
132132
// INVALID_COMMAND.
133133
VerifyOrReturn(transferFileDesignator.HasValue(), commandObj->AddStatus(path, Status::InvalidCommand));
134134

135-
VerifyOrReturn(transferFileDesignator.Value().size() > 0, commandObj->AddStatus(path, Status::ConstraintError));
136-
137135
VerifyOrReturn(transferFileDesignator.Value().size() <= kMaxFileDesignatorLen,
138136
commandObj->AddStatus(path, Status::ConstraintError));
139137

src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ CHIP_ERROR BDXTransferProxyDiagnosticLog::Init(TransferSession * transferSession
3333
uint16_t fileDesignatorLength = 0;
3434
auto fileDesignator = transferSession->GetFileDesignator(fileDesignatorLength);
3535

36-
VerifyOrReturnError(fileDesignatorLength > 0, CHIP_ERROR_INVALID_STRING_LENGTH);
3736
VerifyOrReturnError(fileDesignatorLength <= ArraySize(mFileDesignator), CHIP_ERROR_INVALID_STRING_LENGTH);
3837

3938
mTransfer = transferSession;

src/protocols/bdx/StatusCode.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ StatusCode GetBdxStatusCodeFromChipError(CHIP_ERROR error)
3333
{
3434
status = StatusCode::kBadMessageContents;
3535
}
36+
else if (error == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
37+
{
38+
status = StatusCode::kTransferMethodNotSupported;
39+
}
40+
else if (error == CHIP_ERROR_UNKNOWN_RESOURCE_ID)
41+
{
42+
status = StatusCode::kFileDesignatorUnknown;
43+
}
3644

3745
return status;
3846
}

0 commit comments

Comments
 (0)