Skip to content

Commit

Permalink
OTA-Requestor software version check (#13742)
Browse files Browse the repository at this point in the history
* ota-requerstor software version check.

* Apply suggestions from code review

Co-authored-by: Damian Królik <[email protected]>

* addressed review comments

Co-authored-by: Damian Królik <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 11, 2023
1 parent fe11172 commit e7eec0c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,27 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse
return;
}

MutableByteSpan updateToken(requestorCore->mUpdateTokenBuffer);
CopySpanToMutableSpan(update.updateToken, updateToken);
requestorCore->mTargetVersion = update.softwareVersion;
requestorCore->mUpdateToken = updateToken;
if (update.softwareVersion > requestorCore->mCurrentVersion)
{
ChipLogDetail(SoftwareUpdate, "Update available from %" PRIu32 " to %" PRIu32 " version",
requestorCore->mCurrentVersion, update.softwareVersion);
MutableByteSpan updateToken(requestorCore->mUpdateTokenBuffer);
CopySpanToMutableSpan(update.updateToken, updateToken);
requestorCore->mTargetVersion = update.softwareVersion;
requestorCore->mUpdateToken = updateToken;

requestorCore->mOtaRequestorDriver->UpdateAvailable(update,
System::Clock::Seconds32(response.delayedActionTime.ValueOr(0)));
}
else
{
ChipLogDetail(SoftwareUpdate, "Version %" PRIu32 " is older or same than current version %" PRIu32 ", not updating",
update.softwareVersion, requestorCore->mCurrentVersion);

requestorCore->mOtaRequestorDriver->UpdateNotFound(UpdateNotFoundReason::UpToDate,
System::Clock::Seconds32(response.delayedActionTime.ValueOr(0)));
}

requestorCore->mOtaRequestorDriver->UpdateAvailable(update,
System::Clock::Seconds32(response.delayedActionTime.ValueOr(0)));
break;
}
case OTAQueryStatus::kBusy:
Expand Down Expand Up @@ -536,6 +550,8 @@ CHIP_ERROR OTARequestor::ExtractUpdateDescription(const QueryImageResponseDecoda
update.softwareVersion = response.softwareVersion.Value();

VerifyOrReturnError(response.updateToken.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(response.updateToken.Value().size() >= 8 && response.updateToken.Value().size() <= 32,
CHIP_ERROR_INVALID_ARGUMENT);
update.updateToken = response.updateToken.Value();

update.userConsentNeeded = response.userConsentNeeded.ValueOr(false);
Expand Down

0 comments on commit e7eec0c

Please sign in to comment.