diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp index f0c0e3902b7767..bcec4be7d50356 100644 --- a/examples/ota-requestor-app/linux/main.cpp +++ b/examples/ota-requestor-app/linux/main.cpp @@ -244,7 +244,7 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, return (retval); } -void SendQueryImageCommand() +void SendQueryImageCommand(chip::NodeId peerNodeId = providerNodeId, chip::FabricIndex peerFabricIndex = providerFabricIndex) { // Explicitly calling UpdateAddress() should not be needed once OperationalDeviceProxy can resolve IP address from node ID and // fabric index @@ -261,9 +261,8 @@ void SendQueryImageCommand() .fabricsTable = &(server->GetFabricTable()), }; - CHIP_ERROR err = CHIP_NO_ERROR; - FabricIndex peerFabricIndex = providerFabricIndex; - gOperationalDeviceProxy.Init(providerNodeId, peerFabricIndex, initParams); + CHIP_ERROR err = CHIP_NO_ERROR; + gOperationalDeviceProxy.Init(peerNodeId, peerFabricIndex, initParams); err = gOperationalDeviceProxy.Connect(&mOnConnectedCallback, &mOnConnectionFailureCallback); if (err != CHIP_NO_ERROR) { @@ -316,6 +315,9 @@ int main(int argc, char * argv[]) // Initialize device attestation config SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider()); + // This will allow ExampleOTARequestor to call SendQueryImageCommand + ExampleOTARequestor::GetInstance().SetConnectToProviderCallback(SendQueryImageCommand); + // If a delay is provided, QueryImage after the timer expires if (delayQueryTimeInSec > 0) { diff --git a/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.cpp b/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.cpp index f677afb692482b..6805e2047911e0 100644 --- a/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.cpp +++ b/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.cpp @@ -61,18 +61,18 @@ void ExampleOTARequestor::Init(chip::Controller::ControllerDeviceInitParams conn void ExampleOTARequestor::ConnectToProvider() { - FabricInfo * providerFabric = GetProviderFabricInfo(); - VerifyOrReturn(providerFabric != nullptr, - ChipLogError(SoftwareUpdate, "No Fabric found for index %" PRIu8, mProviderFabricIndex)); - - ChipLogProgress(SoftwareUpdate, - "Once #7976 is fixed, this would attempt to connect to 0x" ChipLogFormatX64 " on FabricIndex 0x%" PRIu8 - " (" ChipLogFormatX64 ")", - ChipLogValueX64(mProviderNodeId), mProviderFabricIndex, ChipLogValueX64(providerFabric->GetFabricId())); - - // TODO: uncomment and fill in after #7976 is fixed - // mProviderDevice.Init(mConnectParams, mProviderNodeId, address, mProviderFabricIndex); - // mProviderDevice.EstablishConnectivity(); + + if (mConnectToProviderCallback != nullptr) + { + ChipLogProgress(SoftwareUpdate, "Attempting to connect to 0x" ChipLogFormatX64 " on FabricIndex 0x%" PRIu8, + ChipLogValueX64(mProviderNodeId), mProviderFabricIndex); + + mConnectToProviderCallback(mProviderNodeId, mProviderFabricIndex); + } + else + { + ChipLogError(SoftwareUpdate, "ConnectToProviderCallback is not set"); + } } EmberAfStatus ExampleOTARequestor::HandleAnnounceOTAProvider( @@ -91,16 +91,8 @@ EmberAfStatus ExampleOTARequestor::HandleAnnounceOTAProvider( mProviderNodeId = providerLocation; mProviderFabricIndex = commandObj->GetExchangeContext()->GetSessionHandle().GetFabricIndex(); - FabricInfo * providerFabric = GetProviderFabricInfo(); - if (providerFabric == nullptr) - { - ChipLogError(SoftwareUpdate, "No Fabric found for index %" PRIu8, mProviderFabricIndex); - return EMBER_ZCL_STATUS_SUCCESS; - } - - ChipLogProgress(SoftwareUpdate, - "Notified of Provider at NodeID: 0x" ChipLogFormatX64 "on FabricIndex 0x%" PRIu8 " (" ChipLogFormatX64 ")", - ChipLogValueX64(mProviderNodeId), mProviderFabricIndex, ChipLogValueX64(providerFabric->GetFabricId())); + ChipLogProgress(SoftwareUpdate, "Notified of Provider at NodeID: 0x" ChipLogFormatX64 " on FabricIndex 0x%" PRIu8, + ChipLogValueX64(mProviderNodeId), mProviderFabricIndex); // If reason is URGENT_UPDATE_AVAILABLE, we start OTA immediately. Otherwise, respect the timer value set in mOtaStartDelayMs. // This is done to exemplify what a real-world OTA Requestor might do while also being configurable enough to use as a test app. diff --git a/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.h b/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.h index 5cec185c847908..4cdcc2eea2297a 100644 --- a/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.h +++ b/examples/ota-requestor-app/ota-requestor-common/ExampleOTARequestor.h @@ -39,6 +39,9 @@ class ExampleOTARequestor chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData); + // Setter for mConnectToProviderCallback + void SetConnectToProviderCallback(void (*f)(chip::NodeId, chip::FabricIndex)) { mConnectToProviderCallback = f; } + private: ExampleOTARequestor(); @@ -53,4 +56,9 @@ class ExampleOTARequestor chip::NodeId mProviderNodeId; chip::FabricIndex mProviderFabricIndex; uint32_t mOtaStartDelayMs; + + // TODO: This will be redone once the full Requestor app design is in place + // Pointer to the function that establishes a session with the Provider and initiates + // the BDX download + void (*mConnectToProviderCallback)(chip::NodeId, chip::FabricIndex); };