Skip to content

Commit

Permalink
[Matter.framework] Invalidate the CASE session if something calls Tri…
Browse files Browse the repository at this point in the history
…ggerResubscriptionWithReason and it has not been established yet
  • Loading branch information
vivien-apple committed Oct 30, 2024
1 parent f99a2c3 commit ec2ff36
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNode
peerId, MakeOptional(Transport::SecureSession::Type::kCASE), transportPayloadCapability);
}

void CASESessionManager::ReleaseSession(const ScopedNodeId & peerId)
{
auto * session = mConfig.sessionSetupPool->FindSessionSetup(peerId, false);
ReleaseSession(session);
}

void CASESessionManager::ReleaseSession(OperationalSessionSetup * session)
{
if (session != nullptr)
Expand Down
1 change: 1 addition & 0 deletions src/app/CASESessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CASESessionManager : public OperationalSessionReleaseDelegate, public Sess
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
TransportPayloadCapability transportPayloadCapability = TransportPayloadCapability::kMRPPayload);

void ReleaseSession(const ScopedNodeId & peerId);
void ReleaseSessionsForFabric(FabricIndex fabricIndex);

void ReleaseAllSessions();
Expand Down
10 changes: 10 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
return nullptr;
}

CASESessionManager * CASESessionMgr()
{
if (mSystemState)
{
return mSystemState->CASESessionMgr();
}

return nullptr;
}

Messaging::ExchangeManager * ExchangeMgr()
{
if (mSystemState != nullptr)
Expand Down
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)invalidateCASESessionForNode:(NSNumber *)nodeID;

/**
* Invalidate the CASE session establishment for the specified node ID.
* Must not be called on the Matter event queue.
*/
- (void)invalidateCASESessionEstablishmentForNode:(NSNumber *)nodeID;

/**
* Download log of the desired type from the device.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,17 @@ - (void)invalidateCASESessionForNode:(NSNumber *)nodeID;
[self syncRunOnWorkQueue:block error:nil];
}

- (void)invalidateCASESessionEstablishmentForNode:(NSNumber *)nodeID;
{
auto block = ^{
auto caseSessionMgr = self->_cppCommissioner->CASESessionMgr();
VerifyOrDie(caseSessionMgr != nullptr);
caseSessionMgr->ReleaseSession(self->_cppCommissioner->GetPeerScopedId(nodeID.unsignedLongLongValue));
};

[self syncRunOnWorkQueue:block error:nil];
}

- (void)operationalInstanceAdded:(NSNumber *)nodeID
{
// Don't use deviceForNodeID here, because we don't want to create the
Expand Down
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,12 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
subscriptionCallback->ResetResubscriptionBackoff();
}
readClientToResubscribe->TriggerResubscribeIfScheduled(reason.UTF8String);
} else if (_internalDeviceState == MTRInternalDeviceStateSubscribing && nodeLikelyReachable) {
// If we have reason to suspect that the node is now reachable and we haven’t established a
// CASE session yet, let’s consider it to be stalled and invalidate the pairing session.
dispatch_async(self.queue, ^{
[[self _concreteController] invalidateCASESessionEstablishmentForNode:self->_nodeID];
});
}
}

Expand Down

0 comments on commit ec2ff36

Please sign in to comment.