Skip to content

Commit f985d72

Browse files
authored
[Matter.framework] Invalidate the CASE session if something calls TriggerResubscriptionWithReason and it has not been established yet (project-chip#36298)
1 parent c0071eb commit f985d72

6 files changed

+40
-0
lines changed

src/app/CASESessionManager.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ Optional<SessionHandle> CASESessionManager::FindExistingSession(const ScopedNode
188188
peerId, MakeOptional(Transport::SecureSession::Type::kCASE), transportPayloadCapability);
189189
}
190190

191+
void CASESessionManager::ReleaseSession(const ScopedNodeId & peerId)
192+
{
193+
auto * session = mConfig.sessionSetupPool->FindSessionSetup(peerId, false);
194+
ReleaseSession(session);
195+
}
196+
191197
void CASESessionManager::ReleaseSession(OperationalSessionSetup * session)
192198
{
193199
if (session != nullptr)

src/app/CASESessionManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class CASESessionManager : public OperationalSessionReleaseDelegate, public Sess
142142
#endif // CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES
143143
TransportPayloadCapability transportPayloadCapability = TransportPayloadCapability::kMRPPayload);
144144

145+
void ReleaseSession(const ScopedNodeId & peerId);
145146
void ReleaseSessionsForFabric(FabricIndex fabricIndex);
146147

147148
void ReleaseAllSessions();

src/controller/CHIPDeviceController.h

+10
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
204204
return nullptr;
205205
}
206206

207+
CASESessionManager * CASESessionMgr()
208+
{
209+
if (mSystemState)
210+
{
211+
return mSystemState->CASESessionMgr();
212+
}
213+
214+
return nullptr;
215+
}
216+
207217
Messaging::ExchangeManager * ExchangeMgr()
208218
{
209219
if (mSystemState != nullptr)

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h

+6
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ NS_ASSUME_NONNULL_BEGIN
178178
*/
179179
- (void)invalidateCASESessionForNode:(NSNumber *)nodeID;
180180

181+
/**
182+
* Invalidate the CASE session establishment for the specified node ID.
183+
* Must not be called on the Matter event queue.
184+
*/
185+
- (void)invalidateCASESessionEstablishmentForNode:(NSNumber *)nodeID;
186+
181187
/**
182188
* Download log of the desired type from the device.
183189
*/

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm

+11
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,17 @@ - (void)invalidateCASESessionForNode:(NSNumber *)nodeID;
16191619
[self syncRunOnWorkQueue:block error:nil];
16201620
}
16211621

1622+
- (void)invalidateCASESessionEstablishmentForNode:(NSNumber *)nodeID;
1623+
{
1624+
auto block = ^{
1625+
auto caseSessionMgr = self->_cppCommissioner->CASESessionMgr();
1626+
VerifyOrDie(caseSessionMgr != nullptr);
1627+
caseSessionMgr->ReleaseSession(self->_cppCommissioner->GetPeerScopedId(nodeID.unsignedLongLongValue));
1628+
};
1629+
1630+
[self syncRunOnWorkQueue:block error:nil];
1631+
}
1632+
16221633
- (void)operationalInstanceAdded:(NSNumber *)nodeID
16231634
{
16241635
// Don't use deviceForNodeID here, because we don't want to create the

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+6
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,12 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
898898
subscriptionCallback->ResetResubscriptionBackoff();
899899
}
900900
readClientToResubscribe->TriggerResubscribeIfScheduled(reason.UTF8String);
901+
} else if (_internalDeviceState == MTRInternalDeviceStateSubscribing && nodeLikelyReachable) {
902+
// If we have reason to suspect that the node is now reachable and we haven’t established a
903+
// CASE session yet, let’s consider it to be stalled and invalidate the pairing session.
904+
dispatch_async(self.queue, ^{
905+
[[self _concreteController] invalidateCASESessionEstablishmentForNode:self->_nodeID];
906+
});
901907
}
902908
}
903909

0 commit comments

Comments
 (0)