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

[OTA] Send more useful StatusReport errors during download failures #15227

Merged
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
14 changes: 12 additions & 2 deletions src/app/clusters/ota-requestor/BDXDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ void BDXDownloader::EndDownload(CHIP_ERROR reason)
{
if (mState == State::kInProgress)
{
// There's no method for a BDX receiving driver to cleanly end a transfer
mBdxTransfer.AbortTransfer(chip::bdx::StatusCode::kUnknown);
bdx::StatusCode status = bdx::StatusCode::kUnknown;
if (reason == CHIP_ERROR_INVALID_FILE_IDENTIFIER)
{
status = bdx::StatusCode::kBadMessageContents;
}
else if (reason == CHIP_ERROR_WRITE_FAILED)
{
status = bdx::StatusCode::kTransferFailedUnknownError;
}

// There is no method for a BDX receiving driver to cleanly end a transfer
mBdxTransfer.AbortTransfer(status);
if (mImageProcessor != nullptr)
{
mImageProcessor->Abort();
Expand Down
12 changes: 6 additions & 6 deletions src/platform/Linux/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)

ByteSpan block = imageProcessor->mBlock;
CHIP_ERROR error = imageProcessor->ProcessHeader(block);

if (error == CHIP_NO_ERROR &&
!imageProcessor->mOfs.write(reinterpret_cast<const char *>(block.data()), static_cast<std::streamsize>(block.size())))
if (error != CHIP_NO_ERROR)
{
error = CHIP_ERROR_WRITE_FAILED;
ChipLogError(SoftwareUpdate, "Image does not contain a valid header");
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_INVALID_FILE_IDENTIFIER);
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (error != CHIP_NO_ERROR)
if (!imageProcessor->mOfs.write(reinterpret_cast<const char *>(block.data()), static_cast<std::streamsize>(block.size())))
{
imageProcessor->mDownloader->EndDownload(error);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
return;
}

Expand Down
4 changes: 1 addition & 3 deletions src/protocols/bdx/BdxMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ enum class MessageType : uint8_t

enum class StatusCode : uint16_t
{
kNone = 0x0000,
kOverflow = 0x0011,
kLengthTooLarge = 0x0012,
kLengthTooShort = 0x0013,
kLengthMismatch = 0x0014,
kLengthRequired = 0x0015,
kBadMessageContents = 0x0016,
kBadBlockCounter = 0x0017,
kUnexpectedMessage = 0x0018,
kResponderBusy = 0x0019,
kTransferFailedUnknownError = 0x001F,
kFailureToSend = 0x0021,
kTransferMethodNotSupported = 0x0050,
kFileDesignatorUnknown = 0x0051,
kStartOffsetNotSupported = 0x0052,
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/bdx/BdxTransferSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class DLL_EXPORT TransferSession
TransferSkipData bytesToSkip;
};

OutputEvent() : EventType(OutputEventType::kNone) { statusData = { StatusCode::kNone }; }
OutputEvent(OutputEventType type) : EventType(type) { statusData = { StatusCode::kNone }; }
OutputEvent() : EventType(OutputEventType::kNone) { statusData = { StatusCode::kUnknown }; }
OutputEvent(OutputEventType type) : EventType(type) { statusData = { StatusCode::kUnknown }; }

const char * ToString(OutputEventType outputEventType);

Expand Down