From e3211ff4ad1ccee15ddbe270072843f8cd07a3ff Mon Sep 17 00:00:00 2001 From: marius-alex-tache Date: Wed, 8 May 2024 10:43:06 +0300 Subject: [PATCH] [k32w] Replace boolean mShouldNotApply with an enum class Signed-off-by: marius-alex-tache --- src/platform/nxp/k32w/common/OTATlvProcessor.cpp | 4 ++-- src/platform/nxp/k32w/common/OTATlvProcessor.h | 12 +++++++++--- src/platform/nxp/k32w/k32w0/OTAFirmwareProcessor.cpp | 4 ++-- src/platform/nxp/k32w/k32w1/OTAFirmwareProcessor.cpp | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/platform/nxp/k32w/common/OTATlvProcessor.cpp b/src/platform/nxp/k32w/common/OTATlvProcessor.cpp index 287049261bc402..5dc0eaebd83627 100644 --- a/src/platform/nxp/k32w/common/OTATlvProcessor.cpp +++ b/src/platform/nxp/k32w/common/OTATlvProcessor.cpp @@ -34,7 +34,7 @@ constexpr uint8_t au8Iv[] = { 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x CHIP_ERROR OTATlvProcessor::ApplyAction() { - return mShouldNotApply ? CHIP_ERROR_OTA_PROCESSOR_SHOULD_NOT_APPLY : CHIP_NO_ERROR; + return mApplyState == ApplyState::kApply ? CHIP_NO_ERROR : CHIP_ERROR_OTA_PROCESSOR_DO_NOT_APPLY; } CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block) @@ -69,7 +69,7 @@ void OTATlvProcessor::ClearInternal() mLength = 0; mProcessedLength = 0; mWasSelected = false; - mShouldNotApply = false; + mApplyState = ApplyState::kApply; #if OTA_ENCRYPTION_ENABLE mIVOffset = 0; #endif diff --git a/src/platform/nxp/k32w/common/OTATlvProcessor.h b/src/platform/nxp/k32w/common/OTATlvProcessor.h index 3e7ee0b6e43aad..f1faef7e8eecf9 100644 --- a/src/platform/nxp/k32w/common/OTATlvProcessor.h +++ b/src/platform/nxp/k32w/common/OTATlvProcessor.h @@ -40,7 +40,7 @@ namespace chip { #define CHIP_ERROR_OTA_PROCESSOR_EEPROM_OFFSET CHIP_ERROR_TLV_PROCESSOR(0x0C) #define CHIP_ERROR_OTA_PROCESSOR_EXTERNAL_STORAGE CHIP_ERROR_TLV_PROCESSOR(0x0D) #define CHIP_ERROR_OTA_PROCESSOR_START_IMAGE CHIP_ERROR_TLV_PROCESSOR(0x0E) -#define CHIP_ERROR_OTA_PROCESSOR_SHOULD_NOT_APPLY CHIP_ERROR_TLV_PROCESSOR(0x0F) +#define CHIP_ERROR_OTA_PROCESSOR_DO_NOT_APPLY CHIP_ERROR_TLV_PROCESSOR(0x0F) // Descriptor constants constexpr size_t kVersionStringSize = 64; @@ -77,6 +77,12 @@ struct OTATlvHeader class OTATlvProcessor { public: + enum class ApplyState : uint8_t + { + kApply = 0, + kDoNotApply + }; + virtual ~OTATlvProcessor() {} virtual CHIP_ERROR Init() = 0; @@ -140,13 +146,13 @@ class OTATlvProcessor * Used by the default ApplyAction implementation. * * If something goes wrong during ExitAction of the TLV processor, - * then mShouldNotApply should be set to true and the image processor + * then mApplyState should be set to kDoNotApply and the image processor * should abort. In this case, the BDX transfer was already finished * and calling CancelImageUpdate will not abort the transfer, hence * the device will reboot even though it should not have. If ApplyAction * fails during HandleApply, then the process will be aborted. */ - bool mShouldNotApply = false; + ApplyState mApplyState = ApplyState::kApply; ProcessDescriptor mCallbackProcessDescriptor = nullptr; }; diff --git a/src/platform/nxp/k32w/k32w0/OTAFirmwareProcessor.cpp b/src/platform/nxp/k32w/k32w0/OTAFirmwareProcessor.cpp index 26dd4c6cbb59a7..f63aa745378851 100644 --- a/src/platform/nxp/k32w/k32w0/OTAFirmwareProcessor.cpp +++ b/src/platform/nxp/k32w/k32w0/OTAFirmwareProcessor.cpp @@ -138,14 +138,14 @@ CHIP_ERROR OTAFirmwareProcessor::ExitAction() if (OTA_CommitImage(NULL) != gOtaSuccess_c) { ChipLogError(SoftwareUpdate, "Failed to commit firmware image."); - mShouldNotApply = true; + mApplyState = ApplyState::kDoNotApply; return CHIP_ERROR_OTA_PROCESSOR_IMG_COMMIT; } if (OTA_ImageAuthenticate() != gOtaImageAuthPass_c) { ChipLogError(SoftwareUpdate, "Failed to authenticate firmware image."); - mShouldNotApply = true; + mApplyState = ApplyState::kDoNotApply; return CHIP_ERROR_OTA_PROCESSOR_IMG_AUTH; } diff --git a/src/platform/nxp/k32w/k32w1/OTAFirmwareProcessor.cpp b/src/platform/nxp/k32w/k32w1/OTAFirmwareProcessor.cpp index d25c7b0b753ec8..ee3ff9b655c504 100644 --- a/src/platform/nxp/k32w/k32w1/OTAFirmwareProcessor.cpp +++ b/src/platform/nxp/k32w/k32w1/OTAFirmwareProcessor.cpp @@ -117,7 +117,7 @@ CHIP_ERROR OTAFirmwareProcessor::ExitAction() if (OTA_CommitImage(NULL) != gOtaSuccess_c) { ChipLogError(SoftwareUpdate, "Failed to commit firmware image."); - mShouldNotApply = true; + mApplyState = ApplyState::kDoNotApply; return CHIP_ERROR_OTA_PROCESSOR_IMG_COMMIT; }