Skip to content

Commit

Permalink
[OTA] Tear down CASE session during a timeout error (#15939)
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored and pull[bot] committed Apr 5, 2022
1 parent 0928d1e commit c93c67f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
36 changes: 35 additions & 1 deletion src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,14 @@ void OTARequestor::OnQueryImageFailure(void * context, CHIP_ERROR error)
OTARequestor * requestorCore = static_cast<OTARequestor *>(context);
VerifyOrDie(requestorCore != nullptr);

ChipLogDetail(SoftwareUpdate, "QueryImage failure response %" CHIP_ERROR_FORMAT, error.Format());
ChipLogError(SoftwareUpdate, "Received QueryImage failure response: %" CHIP_ERROR_FORMAT, error.Format());

if (error == CHIP_ERROR_TIMEOUT)
{
ChipLogError(SoftwareUpdate, "CASE session may be invalid, tear down session");
requestorCore->DisconnectFromProvider();
}

requestorCore->RecordErrorUpdateState(UpdateFailureState::kQuerying, error);
}

Expand Down Expand Up @@ -305,6 +312,33 @@ void OTARequestor::ConnectToProvider(OnConnectedAction onConnectedAction)
}
}

void OTARequestor::DisconnectFromProvider()
{
if (mServer == nullptr)
{
ChipLogError(SoftwareUpdate, "Server not set");
RecordErrorUpdateState(UpdateFailureState::kUnknown, CHIP_ERROR_INCORRECT_STATE);
return;
}

if (!mProviderLocation.HasValue())
{
ChipLogError(SoftwareUpdate, "Provider location not set");
RecordErrorUpdateState(UpdateFailureState::kUnknown, CHIP_ERROR_INCORRECT_STATE);
return;
}

FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex);
if (fabricInfo == nullptr)
{
ChipLogError(SoftwareUpdate, "Cannot find fabric");
RecordErrorUpdateState(UpdateFailureState::kUnknown, CHIP_ERROR_INCORRECT_STATE);
return;
}

mCASESessionManager->ReleaseSession(fabricInfo->GetPeerIdForNode(mProviderLocation.Value().providerNodeID));
}

// Requestor is directed to cancel image update in progress. All the Requestor state is
// cleared, UpdateState is reset to Idle
void OTARequestor::CancelImageUpdate()
Expand Down
7 changes: 6 additions & 1 deletion src/app/clusters/ota-requestor/OTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,17 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe
};

/**
* Called to establish a session to mProviderLocation.
* Called to establish a session to provider indicated by mProviderLocation
*
* @param onConnectedAction The action to take once session to provider has been established
*/
void ConnectToProvider(OnConnectedAction onConnectedAction);

/**
* Called to tear down a session to provider indicated by mProviderLocation
*/
void DisconnectFromProvider();

/**
* Start download of the software image returned in QueryImageResponse
*/
Expand Down

0 comments on commit c93c67f

Please sign in to comment.