From a3e655a29abe8abe9ee0a650cc8a10d40ceaa851 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Wed, 10 Nov 2021 12:16:04 -0800 Subject: [PATCH] Use correct node ID for requesting OTA updates (#11608) * Use correct node ID for requesting OTA updates * use correct fabric index * address review comments --- examples/ota-requestor-app/linux/main.cpp | 22 +++++++++++++++++----- src/transport/FabricTable.h | 7 +++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp index 8831810a607532..1a83052fa6ab46 100644 --- a/examples/ota-requestor-app/linux/main.cpp +++ b/examples/ota-requestor-app/linux/main.cpp @@ -254,18 +254,31 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, void SendQueryImageCommand(chip::NodeId peerNodeId = providerNodeId, chip::FabricIndex peerFabricIndex = providerFabricIndex) { - Server * server = &(Server::GetInstance()); + Server * server = &(Server::GetInstance()); + chip::FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(peerFabricIndex); + if (fabric == nullptr) + { + ChipLogError(SoftwareUpdate, "Did not find fabric for index %d", peerFabricIndex); + return; + } + chip::DeviceProxyInitParams initParams = { .sessionManager = &(server->GetSecureSessionManager()), .exchangeMgr = &(server->GetExchangeManager()), .idAllocator = &(server->GetSessionIDAllocator()), - .fabricInfo = server->GetFabricTable().FindFabricWithIndex(providerFabricIndex), + .fabricInfo = fabric, // TODO: Determine where this should be instantiated .imDelegate = chip::Platform::New(), }; chip::OperationalDeviceProxy * operationalDeviceProxy = - new chip::OperationalDeviceProxy(initParams, PeerId().SetNodeId(providerNodeId)); + chip::Platform::New(initParams, fabric->GetPeerIdForNode(peerNodeId)); + if (operationalDeviceProxy == nullptr) + { + ChipLogError(SoftwareUpdate, "Failed in creating an instance of OperationalDeviceProxy"); + return; + } + server->SetOperationalDeviceProxy(operationalDeviceProxy); // Explicitly calling UpdateDeviceData() should not be needed once OperationalDeviceProxy can resolve IP address from node ID @@ -278,8 +291,7 @@ void SendQueryImageCommand(chip::NodeId peerNodeId = providerNodeId, chip::Fabri operationalDeviceProxy->GetMRPIntervals(idleInterval, activeInterval); operationalDeviceProxy->UpdateDeviceData(addr, idleInterval, activeInterval); - CHIP_ERROR err = CHIP_NO_ERROR; - err = operationalDeviceProxy->Connect(&mOnConnectedCallback, &mOnConnectionFailureCallback); + CHIP_ERROR err = operationalDeviceProxy->Connect(&mOnConnectedCallback, &mOnConnectionFailureCallback); if (err != CHIP_NO_ERROR) { ChipLogError(SoftwareUpdate, "Cannot establish connection to peer device: %" CHIP_ERROR_FORMAT, err.Format()); diff --git a/src/transport/FabricTable.h b/src/transport/FabricTable.h index 389d9e534f0054..600e92497d560f 100644 --- a/src/transport/FabricTable.h +++ b/src/transport/FabricTable.h @@ -139,6 +139,13 @@ class DLL_EXPORT FabricInfo } PeerId GetPeerId() const { return mOperationalId; } + PeerId GetPeerIdForNode(const NodeId node) const + { + PeerId peer = mOperationalId; + peer.SetNodeId(node); + return peer; + } + FabricId GetFabricId() const { return mFabricId; } FabricIndex GetFabricIndex() const { return mFabric; } uint16_t GetVendorId() const { return mVendorId; }