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-R] Fix retries on Query Image failure due to invalid session #18765

Merged
merged 9 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 8 additions & 4 deletions src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,20 @@ void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAC
if ((newState == OTAUpdateStateEnum::kIdle) && (mCurrentUpdateState != OTAUpdateStateEnum::kIdle))
{
IdleStateReason idleStateReason = MapErrorToIdleStateReason(error);

// Inform the driver that the core logic has entered the Idle state
// Update the new state before handling the state transition
mCurrentUpdateState = newState;
isiu-apple marked this conversation as resolved.
Show resolved Hide resolved
mOtaRequestorDriver->HandleIdleStateEnter(idleStateReason);
}
else if ((mCurrentUpdateState == OTAUpdateStateEnum::kIdle) && (newState != OTAUpdateStateEnum::kIdle))
{
// Update the new state before handling the state transition
mCurrentUpdateState = newState;
mOtaRequestorDriver->HandleIdleStateExit();
}

mCurrentUpdateState = newState;
else
{
mCurrentUpdateState = newState;
}
}

void DefaultOTARequestor::RecordErrorUpdateState(CHIP_ERROR error, OTAChangeReasonEnum reason)
Expand Down
26 changes: 21 additions & 5 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace {
using namespace app::Clusters::OtaSoftwareUpdateRequestor;
using namespace app::Clusters::OtaSoftwareUpdateRequestor::Structs;

constexpr uint8_t kMaxInvalidSessionRetries = 3; // Max # of query image retries to perform on invalid session error
isiu-apple marked this conversation as resolved.
Show resolved Hide resolved
constexpr uint32_t kDelayQueryUponCommissioningSec = 30; // Delay before sending the initial image query after commissioning
constexpr uint32_t kImmediateStartDelaySec = 1; // Delay before sending a query in response to UrgentUpdateAvailable
constexpr System::Clock::Seconds32 kDefaultDelayedActionTime = System::Clock::Seconds32(120);
Expand All @@ -58,9 +59,10 @@ DefaultOTARequestorDriver * ToDriver(void * context)

void DefaultOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImageProcessorInterface * processor)
{
mRequestor = requestor;
mImageProcessor = processor;
mProviderRetryCount = 0;
mRequestor = requestor;
mImageProcessor = processor;
mProviderRetryCount = 0;
mInvalidSessionRetryCount = 0;

if (mImageProcessor->IsFirstImageRun())
{
Expand Down Expand Up @@ -127,6 +129,11 @@ void DefaultOTARequestorDriver::HandleIdleStateExit()

void DefaultOTARequestorDriver::HandleIdleStateEnter(IdleStateReason reason)
{
if (reason != IdleStateReason::kInvalidSession)
{
mInvalidSessionRetryCount = 0;
}

switch (reason)
{
case IdleStateReason::kUnknown:
Expand All @@ -138,8 +145,17 @@ void DefaultOTARequestorDriver::HandleIdleStateEnter(IdleStateReason reason)
StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer);
break;
case IdleStateReason::kInvalidSession:
// An invalid session is detected which may be temporary so try to query the same provider again
SendQueryImage();
if (mInvalidSessionRetryCount < kMaxInvalidSessionRetries)
{
// An invalid session is detected which may be temporary so try to query the same provider again
SendQueryImage();
mInvalidSessionRetryCount++;
}
else
{
mInvalidSessionRetryCount = 0;
StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer);
}
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
uint16_t maxDownloadBlockSize = 1024;
// Maximum number of times to retry a BUSY OTA provider before moving to the next available one
static constexpr uint8_t kMaxBusyProviderRetryCount = 3;
uint8_t mProviderRetryCount; // Track retry count for the current provider
// Track retry count for the current provider
isiu-apple marked this conversation as resolved.
Show resolved Hide resolved
uint8_t mProviderRetryCount = 0;
// Track query image retry count on invalid session error
uint8_t mInvalidSessionRetryCount = 0;
isiu-apple marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace DeviceLayer
Expand Down