Skip to content

Commit

Permalink
Integrate ExampleOTARequestor class with the Linux OTA Requestor app (#…
Browse files Browse the repository at this point in the history
…11010)

* Make a QueryImage command from OTA Requestor to OTA Provider

* Make ota-provider-app and ota-requestor-app compilable on Mac
* Remove self commissioning code from ota-requestor-app
* Add a parameter for IP address for OTA Requestor to use for creating secure session
* Add a parameter for fabric index for OTA Requestor to use for creating secure session
* Add a parameter for time to wait for OTA Requestor to initiate a QueryImage command from startup

* Address code review comments

- Avoid multiple calls to Server::GetInstance()
- Update parts of README
- Add TODO for workarounds to be removed later
- Remove usage of __FUNCTION__

* Integrate ExampleOTARequestor class with the Linux OTA Requestor app

Add mConnectToProviderCallback function pointer member ExampleOTARequestor that can be set by the Requestor app implementation. If the callback is set then the reception of the Announce OTA Provider message triggers the Requestor to establish a session with the Provider and initiate the BDX download.

* Add a log message to HandleAnnounceOTAProvider

* Restyled by clang-format

* Replace NULL with nullptr

Co-authored-by: Carol Yang <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed May 16, 2022
1 parent 2da0c27 commit 6084046
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
10 changes: 6 additions & 4 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
};

0 comments on commit 6084046

Please sign in to comment.