diff --git a/src/app/clusters/ota-requestor/BDXDownloader.cpp b/src/app/clusters/ota-requestor/BDXDownloader.cpp index 7f0be086aeed27..76c86627aa0eed 100644 --- a/src/app/clusters/ota-requestor/BDXDownloader.cpp +++ b/src/app/clusters/ota-requestor/BDXDownloader.cpp @@ -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(); diff --git a/src/platform/Linux/OTAImageProcessorImpl.cpp b/src/platform/Linux/OTAImageProcessorImpl.cpp index 6ae4dbb47faf3a..0318ff79b12cec 100644 --- a/src/platform/Linux/OTAImageProcessorImpl.cpp +++ b/src/platform/Linux/OTAImageProcessorImpl.cpp @@ -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(block.data()), static_cast(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(block.data()), static_cast(block.size()))) { - imageProcessor->mDownloader->EndDownload(error); + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } diff --git a/src/protocols/bdx/BdxMessages.h b/src/protocols/bdx/BdxMessages.h index 0fd13d73962f47..ec76d97c6b5c82 100644 --- a/src/protocols/bdx/BdxMessages.h +++ b/src/protocols/bdx/BdxMessages.h @@ -48,8 +48,6 @@ enum class MessageType : uint8_t enum class StatusCode : uint16_t { - kNone = 0x0000, - kOverflow = 0x0011, kLengthTooLarge = 0x0012, kLengthTooShort = 0x0013, kLengthMismatch = 0x0014, @@ -57,8 +55,8 @@ enum class StatusCode : uint16_t kBadMessageContents = 0x0016, kBadBlockCounter = 0x0017, kUnexpectedMessage = 0x0018, + kResponderBusy = 0x0019, kTransferFailedUnknownError = 0x001F, - kFailureToSend = 0x0021, kTransferMethodNotSupported = 0x0050, kFileDesignatorUnknown = 0x0051, kStartOffsetNotSupported = 0x0052, diff --git a/src/protocols/bdx/BdxTransferSession.h b/src/protocols/bdx/BdxTransferSession.h index de94c67fbd6a12..bb2f456bed7f6b 100644 --- a/src/protocols/bdx/BdxTransferSession.h +++ b/src/protocols/bdx/BdxTransferSession.h @@ -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);