diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index e094c55875226f..5224dd45229845 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -321,10 +321,34 @@ CHIP_ERROR DeviceController::DisconnectDevice(NodeId nodeId) void DeviceController::OnFirstMessageDeliveryFailed(const SessionHandle & session) { - VerifyOrReturn(mState == State::Initialized, - ChipLogError(Controller, "OnFirstMessageDeliveryFailed was called in incorrect state")); - VerifyOrReturn(session->GetSessionType() == Transport::Session::SessionType::kSecure); - CHIP_ERROR err = UpdateDevice(session->AsSecureSession()->GetPeerNodeId()); + if (session->GetSessionType() != Session::SessionType::kSecure) + { + // Definitely not a CASE session. + return; + } + + auto * secureSession = session->AsSecureSession(); + if (secureSession->GetSecureSessionType() != SecureSession::Type::kCASE) + { + // Still not CASE. + return; + } + + FabricIndex ourIndex; + CHIP_ERROR err = GetFabricIndex(&ourIndex); + if (err != CHIP_NO_ERROR) + { + // We can't really do CASE, now can we? + return; + } + + if (ourIndex != session->GetFabricIndex()) + { + // Not one of our sessions. + return; + } + + err = UpdateDevice(secureSession->GetPeerNodeId()); if (err != CHIP_NO_ERROR) { ChipLogError(Controller, diff --git a/src/transport/SessionDelegate.h b/src/transport/SessionDelegate.h index 162bc1f93c0531..eca796a972b91a 100644 --- a/src/transport/SessionDelegate.h +++ b/src/transport/SessionDelegate.h @@ -42,7 +42,8 @@ class DLL_EXPORT SessionRecoveryDelegate * Called when the first message delivery in a session failed, * so actions aiming to recover connection can be performed. * - * @param session The handle to the secure session + * @param session The handle to the session. This may be any session type + * that supports MRP. */ virtual void OnFirstMessageDeliveryFailed(const SessionHandle & session) = 0; };