Skip to content

Commit

Permalink
Fix example code using stale peer fabric index after CommissioningCom…
Browse files Browse the repository at this point in the history
…plete (#15549)
  • Loading branch information
yufengwangca authored and pull[bot] committed Oct 20, 2023
1 parent 062970b commit 2663565
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
8 changes: 7 additions & 1 deletion examples/tv-casting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#pragma once
#include <stdint.h>

#include <lib/core/DataModelTypes.h>

namespace chip {
namespace DeviceLayer {
namespace DeviceEventType {
Expand Down Expand Up @@ -441,6 +443,7 @@ struct ChipDeviceEvent final
{
CHIP_ERROR Status;
uint64_t PeerNodeId;
FabricIndex PeerFabricIndex;
} CommissioningComplete;

struct
Expand Down
7 changes: 1 addition & 6 deletions src/include/platform/DeviceControlServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/platform/DeviceControlServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 2663565

Please sign in to comment.