Skip to content

Commit

Permalink
Use correct node ID for requesting OTA updates (#11608)
Browse files Browse the repository at this point in the history
* Use correct node ID for requesting OTA updates

* use correct fabric index

* address review comments
  • Loading branch information
pan-apple authored and pull[bot] committed Jan 7, 2022
1 parent 4b7cd59 commit 1235688
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 17 additions & 5 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Controller::DeviceControllerInteractionModelDelegate>(),
};

chip::OperationalDeviceProxy * operationalDeviceProxy =
new chip::OperationalDeviceProxy(initParams, PeerId().SetNodeId(providerNodeId));
chip::Platform::New<chip::OperationalDeviceProxy>(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
Expand All @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions src/transport/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 1235688

Please sign in to comment.