diff --git a/examples/tv-casting-app/linux/main.cpp b/examples/tv-casting-app/linux/main.cpp index 4f28d1863f825f..14b85f559fc31d 100644 --- a/examples/tv-casting-app/linux/main.cpp +++ b/examples/tv-casting-app/linux/main.cpp @@ -216,7 +216,13 @@ void DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * event, intptr_t ar { if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete) { - chip::FabricIndex peerFabricIndex = chip::DeviceLayer::DeviceControlServer::DeviceControlSvr().GetFabricIndex(); + if (event->CommissioningComplete.Status != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Commissioning is not successfully Complete"); + return; + } + + chip::FabricIndex peerFabricIndex = event->CommissioningComplete.PeerFabricIndex; Server * server = &(chip::Server::GetInstance()); chip::FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(peerFabricIndex); diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index f1ef38e7122d29..8dec6607c4fd2c 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -150,9 +150,8 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( * Once bindings are implemented, this may no longer be needed. */ SessionHandle handle = commandObj->GetExchangeContext()->GetSessionHandle(); - server->SetFabricIndex(handle->GetFabricIndex()); - CheckSuccess(server->CommissioningComplete(handle->AsSecureSession()->GetPeerNodeId()), Failure); + CheckSuccess(server->CommissioningComplete(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()), Failure); Commands::CommissioningCompleteResponse::Type response; response.errorCode = CommissioningError::kOk; diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 8e5b555224b151..b6431bc8b22e33 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -25,6 +25,8 @@ #pragma once #include +#include + namespace chip { namespace DeviceLayer { namespace DeviceEventType { @@ -441,6 +443,7 @@ struct ChipDeviceEvent final { CHIP_ERROR Status; uint64_t PeerNodeId; + FabricIndex PeerFabricIndex; } CommissioningComplete; struct diff --git a/src/include/platform/DeviceControlServer.h b/src/include/platform/DeviceControlServer.h index ef2094ef683e15..47c192681aa400 100644 --- a/src/include/platform/DeviceControlServer.h +++ b/src/include/platform/DeviceControlServer.h @@ -89,13 +89,10 @@ class DeviceControlServer final CHIP_ERROR ArmFailSafe(System::Clock::Timeout expiryLength); CHIP_ERROR DisarmFailSafe(); - CHIP_ERROR CommissioningComplete(NodeId peerNodeId); + CHIP_ERROR CommissioningComplete(NodeId peerNodeId, FabricIndex accessingFabricIndex); CHIP_ERROR SetRegulatoryConfig(uint8_t location, const CharSpan & countryCode, uint64_t breadcrumb); - CHIP_ERROR ConnectNetworkForOperational(ByteSpan networkID); - inline FabricIndex GetFabricIndex() { return mFabric; } - inline void SetFabricIndex(FabricIndex fabricId) { mFabric = fabricId; } void SetSwitchDelegate(SwitchDeviceControlDelegate * delegate) { mSwitchDelegate = delegate; } SwitchDeviceControlDelegate * GetSwitchDelegate() const { return mSwitchDelegate; } @@ -118,8 +115,6 @@ class DeviceControlServer final DeviceControlServer(const DeviceControlServer &) = delete; DeviceControlServer(const DeviceControlServer &&) = delete; DeviceControlServer & operator=(const DeviceControlServer &) = delete; - - FabricIndex mFabric = 0; }; } // namespace DeviceLayer diff --git a/src/platform/DeviceControlServer.cpp b/src/platform/DeviceControlServer.cpp index 3af1d06ff6546c..3f4d0893438876 100644 --- a/src/platform/DeviceControlServer.cpp +++ b/src/platform/DeviceControlServer.cpp @@ -64,13 +64,14 @@ CHIP_ERROR DeviceControlServer::DisarmFailSafe() return CHIP_NO_ERROR; } -CHIP_ERROR DeviceControlServer::CommissioningComplete(NodeId peerNodeId) +CHIP_ERROR DeviceControlServer::CommissioningComplete(NodeId peerNodeId, FabricIndex accessingFabricIndex) { VerifyOrReturnError(CHIP_NO_ERROR == DisarmFailSafe(), CHIP_ERROR_INTERNAL); ChipDeviceEvent event; - event.Type = DeviceEventType::kCommissioningComplete; - event.CommissioningComplete.PeerNodeId = peerNodeId; - event.CommissioningComplete.Status = CHIP_NO_ERROR; + event.Type = DeviceEventType::kCommissioningComplete; + event.CommissioningComplete.PeerNodeId = peerNodeId; + event.CommissioningComplete.PeerFabricIndex = accessingFabricIndex; + event.CommissioningComplete.Status = CHIP_NO_ERROR; return PlatformMgr().PostEvent(&event); }