Skip to content

Commit

Permalink
[OTA] Send more useful StatusReport errors during download failures (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored and pull[bot] committed Sep 5, 2023
1 parent f98592a commit 1019948
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
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);
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

0 comments on commit 1019948

Please sign in to comment.