From 0e65776e334b55c2c5a6332b7de031cefdb1365e Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Wed, 8 Dec 2021 16:31:42 -0500 Subject: [PATCH 1/9] OTA Requestor: Add several API declarations --- .../linux/LinuxOTARequestorDriver.cpp | 2 ++ .../linux/LinuxOTARequestorDriver.h | 4 +++ examples/ota-requestor-app/linux/main.cpp | 1 + .../clusters/ota-requestor/OTARequestor.cpp | 22 +++++++++---- src/app/clusters/ota-requestor/OTARequestor.h | 25 ++++++++++++--- .../ota-requestor/OTARequestorDriver.h | 32 +++++++++++++++++++ 6 files changed, 74 insertions(+), 12 deletions(-) diff --git a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp index fb971ffbdb58a6..34c870c6b3c4ae 100644 --- a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp +++ b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp @@ -22,6 +22,8 @@ #include "LinuxOTARequestorDriver.h" +using namespace chip; + // A call into the application logic to give it a chance to allow or stop the Requestor // from proceeding with actual image download. Returning TRUE will allow the download // to proceed, returning FALSE will abort the download process. diff --git a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h index c219aa5c679f05..a7734ba9f1e46a 100644 --- a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h +++ b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h @@ -21,6 +21,8 @@ */ #include "app/clusters/ota-requestor/OTARequestorDriver.h" +namespace chip { + class LinuxOTARequestorDriver : public OTARequestorDriver { @@ -36,3 +38,5 @@ class LinuxOTARequestorDriver : public OTARequestorDriver // Virtual functions from OTARequestorDriver -- end }; + +} // namespace chip diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp index fc004f357376ed..33fe374f48aa68 100644 --- a/examples/ota-requestor-app/linux/main.cpp +++ b/examples/ota-requestor-app/linux/main.cpp @@ -46,6 +46,7 @@ using chip::Callback::Callback; using chip::Inet::IPAddress; using chip::System::Layer; using chip::Transport::PeerAddress; +using namespace chip; using namespace chip::ArgParser; using namespace chip::Messaging; using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands; diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index 44927a74147412..db6181e95e12ce 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -36,6 +36,7 @@ #include #include + using chip::ByteSpan; using chip::CASESessionManager; using chip::CASESessionManagerConfig; @@ -51,10 +52,11 @@ using chip::PeerId; using chip::Server; using chip::VendorId; using chip::bdx::TransferSession; -using chip::Callback::Callback; +//using chip::Callback::Callback; using chip::System::Layer; using chip::Transport::PeerAddress; -// using namespace chip::ArgParser; + +using namespace chip; using namespace chip::Messaging; using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands; using chip::Inet::IPAddress; @@ -66,10 +68,10 @@ constexpr uint32_t kImmediateStartDelayMs = 1; // Start the timer with this valu // Callbacks for connection management void OnConnected(void * context, chip::OperationalDeviceProxy * deviceProxy); -Callback mOnConnectedCallback(OnConnected, nullptr); +chip::Callback::Callback mOnConnectedCallback(OnConnected, nullptr); void OnConnectionFailure(void * context, NodeId deviceId, CHIP_ERROR error); -Callback mOnConnectionFailureCallback(OnConnectionFailure, nullptr); +chip::Callback::Callback mOnConnectionFailureCallback(OnConnectionFailure, nullptr); void OnQueryImageResponse(void * context, const QueryImageResponse::DecodableType & response); void OnQueryImageFailure(void * context, EmberAfStatus status); @@ -405,8 +407,14 @@ void OTARequestor::mOnConnected(void * context, chip::DeviceProxy * deviceProxy) } } -void OTARequestor::TriggerImmediateQuery() +OTARequestor::OTATriggerResult OTARequestor::TriggerImmediateQuery() { - // Perhaps we don't need a separate function ConnectToProvider, revisit this - ConnectToProvider(); + + if(mProviderNodeId != kUndefinedNodeId) { + ConnectToProvider(); + return kTriggerSuccessful; + } else { + ChipLogError(SoftwareUpdate, "No OTA Providers available"); + return kNoProviderKnown; + } } diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index a0755fe74ca956..7e99eb1b4b4d0f 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -28,15 +28,21 @@ #include #include +namespace chip { + // This class implements all of the core logic of the OTA Requestor class OTARequestor : public OTARequestorInterface { public: // Application interface declarations -- start + enum OTATriggerResult { + kTriggerSuccessful = 0, + kNoProviderKnown = 1 + }; // Application directs the Requestor to start the Image Query process // and download the new image if available - void TriggerImmediateQuery(); + OTATriggerResult TriggerImmediateQuery(); // A setter for the delegate class pointer void SetOtaRequestorDriver(OTARequestorDriver * driver) { mOtaRequestorDriver = driver; } @@ -50,15 +56,22 @@ class OTARequestor : public OTARequestorInterface // the image update void AbortImageUpdate(); + // Application directs the Requestor to download the image using the suppiled parameter and without + // issuing QueryImage + OTATriggerResult ResumeImageDownload(const BdxDownloadParameters &bdxParameters) {/* NOT IMPLEMENTED YET */ + return kTriggerSuccessful;} + // Application interface declarations -- end - // Virtual functions from OTARequestorInterface start + // Virtual functions from OTARequestorInterface -- start + // Handler for the AnnounceOTAProvider command EmberAfStatus HandleAnnounceOTAProvider( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData); // Virtual functions from OTARequestorInterface -- end + void ConnectToProvider(); void mOnConnected(void * context, chip::DeviceProxy * deviceProxy); @@ -67,9 +80,9 @@ class OTARequestor : public OTARequestorInterface const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::DecodableType & response); // When the Requestor is used as a test tool (Tesm Mode) the Provider parameters may be supplied explicitly - void TestModeSetProviderParameters(chip::NodeId NodeId, chip::FabricIndex FabIndex) + void TestModeSetProviderParameters(chip::NodeId id, chip::FabricIndex FabIndex) { - mProviderNodeId = NodeId; + mProviderNodeId = id; mProviderFabricIndex = FabIndex; } @@ -155,7 +168,7 @@ class OTARequestor : public OTARequestorInterface // Variables // TODO: align on variable naming standard OTARequestorDriver * mOtaRequestorDriver; - chip::NodeId mProviderNodeId; + chip::NodeId mProviderNodeId = kUndefinedNodeId; chip::FabricIndex mProviderFabricIndex; uint32_t mOtaStartDelayMs = 0; chip::CASESessionManager * mCASESessionManager = nullptr; @@ -170,3 +183,5 @@ class OTARequestor : public OTARequestorInterface // Functions CHIP_ERROR SetupCASESessionManager(chip::FabricIndex fabricIndex); }; + +} // namespace chip diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index 098417926d922d..61c905c6f4868b 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -24,11 +24,29 @@ #pragma once +#include + +namespace chip { +// The set of parameters needed for starting a BDX download. +struct BdxDownloadParameters { + uint32_t delayedActionTime; + chip::CharSpan imageURI; + uint32_t softwareVersion; + chip::CharSpan softwareVersionString; + chip::ByteSpan updateToken; + bool userConsentNeeded; + chip::ByteSpan metadataForRequestor; +}; + + // Interface class to abstract the OTA-related business logic. Each application // must implement this interface. All calls must be non-blocking unless stated otherwise class OTARequestorDriver { public: + + // Mandatory methods, applications are required to implement these + // A call into the application logic to give it a chance to allow or stop the Requestor // from proceeding with actual image download. Returning TRUE will allow the download // to proceed, returning FALSE will abort the download process. @@ -37,6 +55,20 @@ class OTARequestorDriver // Notify the application that the download is complete and the image can be applied virtual void ImageDownloadComplete() = 0; + // Optional methods, applications may choose to implement these + + // This method informs the application of the BDX download parameters. This info can be used + // later on for diecting the Requestor to resume an interrupted download + virtual void PostBdxDownloadParameters(const BdxDownloadParameters &bdxParameters) {}; + + // Return maximum supported download block size + virtual uint16_t GetMaxDownloadBlockSize() { return 1024;} + + // Get Version of the last downloaded image, return CHIP_ERROR_NOT_FOUND if none exists + virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_INCORRECT_STATE;} + // Destructor virtual ~OTARequestorDriver() = default; }; + +} // namespace chip From 8e753749665a2d9a9488f60e42fb3aa6b96ba036 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Wed, 8 Dec 2021 19:18:26 -0500 Subject: [PATCH 2/9] Various OTA Requestor API updates --- .../linux/LinuxOTARequestorDriver.cpp | 5 ++++ .../linux/LinuxOTARequestorDriver.h | 4 +++ src/app/clusters/ota-requestor/OTARequestor.h | 17 +++++++++-- .../ota-requestor/OTARequestorDriver.h | 28 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp index 34c870c6b3c4ae..ad3d0c814525eb 100644 --- a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp +++ b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.cpp @@ -34,3 +34,8 @@ bool LinuxOTARequestorDriver::CheckImageDownloadAllowed() // Notify the application that the download is complete and the image can be applied void LinuxOTARequestorDriver::ImageDownloadComplete() {} + +UserConsentAction LinuxOTARequestorDriver::RequestUserConsent() +{ + return ImmediateYes; +} diff --git a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h index a7734ba9f1e46a..9e9ef84e486878 100644 --- a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h +++ b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h @@ -36,6 +36,10 @@ class LinuxOTARequestorDriver : public OTARequestorDriver // Notify the application that the download is complete and the image can be applied void ImageDownloadComplete(); + // Application is directed to complete user consent: either return ImmediateYes/ImmediateNo + // without blocking or return Requested and call OTARequestor::OnUserConsent() later. + virtual UserConsentAction RequestUserConsent(); + // Virtual functions from OTARequestorDriver -- end }; diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index 7e99eb1b4b4d0f..33a357a565e5f1 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -35,6 +35,8 @@ class OTARequestor : public OTARequestorInterface { public: // Application interface declarations -- start + + // Return value for various trigger-type APIs enum OTATriggerResult { kTriggerSuccessful = 0, kNoProviderKnown = 1 @@ -52,15 +54,24 @@ class OTARequestor : public OTARequestorInterface // The BDXDownloader instance should already have the ImageProcessingDelegate set. void SetBDXDownloader(chip::BDXDownloader * downloader) { mBdxDownloader = downloader; } - // Application directs the Requestor to abort any processing related to - // the image update + // Application directs the Requestor to abort the download in progress. All the Requestor state (such + // as the QueryImageResponse content) is preserved void AbortImageUpdate(); + // Application directs the Requestor to abort the download in progress. All the Requestor state is + // cleared, UploadState is reset to Idle + void AbortAndResetState(); + + // Application notifies the Requestor on the user consent action, TRUE if consent is given, + // FALSE otherwise + void OnUserConsent(bool result); + // Application directs the Requestor to download the image using the suppiled parameter and without // issuing QueryImage OTATriggerResult ResumeImageDownload(const BdxDownloadParameters &bdxParameters) {/* NOT IMPLEMENTED YET */ return kTriggerSuccessful;} + // Application interface declarations -- end // Virtual functions from OTARequestorInterface -- start @@ -174,6 +185,8 @@ class OTARequestor : public OTARequestorInterface chip::CASESessionManager * mCASESessionManager = nullptr; OnConnectedState onConnectedState = kQueryImage; chip::Messaging::ExchangeContext * exchangeCtx = nullptr; + UpdateStateEnum mUpdateState = UpdateStateEnum::Unknown; + chip::BDXDownloader * mBdxDownloader; // TODO: this should be OTADownloader BDXMessenger mBdxMessenger; // TODO: ideally this is held by the application diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index 61c905c6f4868b..161b8e69257045 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -27,6 +27,7 @@ #include namespace chip { + // The set of parameters needed for starting a BDX download. struct BdxDownloadParameters { uint32_t delayedActionTime; @@ -38,6 +39,25 @@ struct BdxDownloadParameters { chip::ByteSpan metadataForRequestor; }; +// Possible values for the UpdateState attribute +enum UpdateStateEnum { + Unknown = 0, + Idle = 1, + Querying = 2, + DelayedOnQuery = 3, + Downloading = 4, + Applying = 5, + DelayedOnApply = 6, + RollingBack = 7, + DelayedOnUserConsent = 8, + }; + +// Return type for RequestUserConsent() +enum UserConsentAction { + ImmediateYes = 1, + ImmediateNo = 2, + Requested = 3, +}; // Interface class to abstract the OTA-related business logic. Each application // must implement this interface. All calls must be non-blocking unless stated otherwise @@ -52,6 +72,10 @@ class OTARequestorDriver // to proceed, returning FALSE will abort the download process. virtual bool CheckImageDownloadAllowed() = 0; + // Application is directed to complete user consent: either return ImmediateYes/ImmediateNo + // without blocking or return Requested and call OTARequestor::OnUserConsent() later. + virtual UserConsentAction RequestUserConsent() = 0; + // Notify the application that the download is complete and the image can be applied virtual void ImageDownloadComplete() = 0; @@ -67,6 +91,10 @@ class OTARequestorDriver // Get Version of the last downloaded image, return CHIP_ERROR_NOT_FOUND if none exists virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_INCORRECT_STATE;} + // Notify application of a change in the UpdateState attribute + virtual void NotifyUpdateStateChange(chip::UpdateStateEnum state) {}; + + // Destructor virtual ~OTARequestorDriver() = default; }; From 929367df6604f355d613c5734398fa6fe774bd57 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 9 Dec 2021 00:19:05 +0000 Subject: [PATCH 3/9] Restyled by whitespace --- .../ota-requestor-app/linux/LinuxOTARequestorDriver.h | 4 ++-- src/app/clusters/ota-requestor/OTARequestor.cpp | 2 +- src/app/clusters/ota-requestor/OTARequestor.h | 8 ++++---- src/app/clusters/ota-requestor/OTARequestorDriver.h | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h index 9e9ef84e486878..d3c00709ea794b 100644 --- a/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h +++ b/examples/ota-requestor-app/linux/LinuxOTARequestorDriver.h @@ -36,8 +36,8 @@ class LinuxOTARequestorDriver : public OTARequestorDriver // Notify the application that the download is complete and the image can be applied void ImageDownloadComplete(); - // Application is directed to complete user consent: either return ImmediateYes/ImmediateNo - // without blocking or return Requested and call OTARequestor::OnUserConsent() later. + // Application is directed to complete user consent: either return ImmediateYes/ImmediateNo + // without blocking or return Requested and call OTARequestor::OnUserConsent() later. virtual UserConsentAction RequestUserConsent(); // Virtual functions from OTARequestorDriver -- end diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index db6181e95e12ce..0b194e258d011d 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -409,7 +409,7 @@ void OTARequestor::mOnConnected(void * context, chip::DeviceProxy * deviceProxy) OTARequestor::OTATriggerResult OTARequestor::TriggerImmediateQuery() { - + if(mProviderNodeId != kUndefinedNodeId) { ConnectToProvider(); return kTriggerSuccessful; diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index 33a357a565e5f1..7d1ba75c5534db 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -54,7 +54,7 @@ class OTARequestor : public OTARequestorInterface // The BDXDownloader instance should already have the ImageProcessingDelegate set. void SetBDXDownloader(chip::BDXDownloader * downloader) { mBdxDownloader = downloader; } - // Application directs the Requestor to abort the download in progress. All the Requestor state (such + // Application directs the Requestor to abort the download in progress. All the Requestor state (such // as the QueryImageResponse content) is preserved void AbortImageUpdate(); @@ -62,14 +62,14 @@ class OTARequestor : public OTARequestorInterface // cleared, UploadState is reset to Idle void AbortAndResetState(); - // Application notifies the Requestor on the user consent action, TRUE if consent is given, + // Application notifies the Requestor on the user consent action, TRUE if consent is given, // FALSE otherwise void OnUserConsent(bool result); // Application directs the Requestor to download the image using the suppiled parameter and without // issuing QueryImage - OTATriggerResult ResumeImageDownload(const BdxDownloadParameters &bdxParameters) {/* NOT IMPLEMENTED YET */ - return kTriggerSuccessful;} + OTATriggerResult ResumeImageDownload(const BdxDownloadParameters &bdxParameters) {/* NOT IMPLEMENTED YET */ + return kTriggerSuccessful;} // Application interface declarations -- end diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index 161b8e69257045..350ab06df47b58 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -72,8 +72,8 @@ class OTARequestorDriver // to proceed, returning FALSE will abort the download process. virtual bool CheckImageDownloadAllowed() = 0; - // Application is directed to complete user consent: either return ImmediateYes/ImmediateNo - // without blocking or return Requested and call OTARequestor::OnUserConsent() later. + // Application is directed to complete user consent: either return ImmediateYes/ImmediateNo + // without blocking or return Requested and call OTARequestor::OnUserConsent() later. virtual UserConsentAction RequestUserConsent() = 0; // Notify the application that the download is complete and the image can be applied @@ -81,7 +81,7 @@ class OTARequestorDriver // Optional methods, applications may choose to implement these - // This method informs the application of the BDX download parameters. This info can be used + // This method informs the application of the BDX download parameters. This info can be used // later on for diecting the Requestor to resume an interrupted download virtual void PostBdxDownloadParameters(const BdxDownloadParameters &bdxParameters) {}; @@ -91,7 +91,7 @@ class OTARequestorDriver // Get Version of the last downloaded image, return CHIP_ERROR_NOT_FOUND if none exists virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_INCORRECT_STATE;} - // Notify application of a change in the UpdateState attribute + // Notify application of a change in the UpdateState attribute virtual void NotifyUpdateStateChange(chip::UpdateStateEnum state) {}; From 7c0df4627c9ae048c9f9b6b2b30a8f8ec09abed8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 9 Dec 2021 00:19:07 +0000 Subject: [PATCH 4/9] Restyled by clang-format --- .../clusters/ota-requestor/OTARequestor.cpp | 10 +++-- src/app/clusters/ota-requestor/OTARequestor.h | 16 ++++--- .../ota-requestor/OTARequestorDriver.h | 45 ++++++++++--------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index 0b194e258d011d..6f82f72f353f64 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -36,7 +36,6 @@ #include #include - using chip::ByteSpan; using chip::CASESessionManager; using chip::CASESessionManagerConfig; @@ -52,7 +51,7 @@ using chip::PeerId; using chip::Server; using chip::VendorId; using chip::bdx::TransferSession; -//using chip::Callback::Callback; +// using chip::Callback::Callback; using chip::System::Layer; using chip::Transport::PeerAddress; @@ -410,10 +409,13 @@ void OTARequestor::mOnConnected(void * context, chip::DeviceProxy * deviceProxy) OTARequestor::OTATriggerResult OTARequestor::TriggerImmediateQuery() { - if(mProviderNodeId != kUndefinedNodeId) { + if (mProviderNodeId != kUndefinedNodeId) + { ConnectToProvider(); return kTriggerSuccessful; - } else { + } + else + { ChipLogError(SoftwareUpdate, "No OTA Providers available"); return kNoProviderKnown; } diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index 7d1ba75c5534db..2f5c63cdfa09ab 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -37,9 +37,10 @@ class OTARequestor : public OTARequestorInterface // Application interface declarations -- start // Return value for various trigger-type APIs - enum OTATriggerResult { - kTriggerSuccessful = 0, - kNoProviderKnown = 1 + enum OTATriggerResult + { + kTriggerSuccessful = 0, + kNoProviderKnown = 1 }; // Application directs the Requestor to start the Image Query process @@ -68,9 +69,10 @@ class OTARequestor : public OTARequestorInterface // Application directs the Requestor to download the image using the suppiled parameter and without // issuing QueryImage - OTATriggerResult ResumeImageDownload(const BdxDownloadParameters &bdxParameters) {/* NOT IMPLEMENTED YET */ - return kTriggerSuccessful;} - + OTATriggerResult ResumeImageDownload(const BdxDownloadParameters & bdxParameters) + { /* NOT IMPLEMENTED YET */ + return kTriggerSuccessful; + } // Application interface declarations -- end @@ -179,7 +181,7 @@ class OTARequestor : public OTARequestorInterface // Variables // TODO: align on variable naming standard OTARequestorDriver * mOtaRequestorDriver; - chip::NodeId mProviderNodeId = kUndefinedNodeId; + chip::NodeId mProviderNodeId = kUndefinedNodeId; chip::FabricIndex mProviderFabricIndex; uint32_t mOtaStartDelayMs = 0; chip::CASESessionManager * mCASESessionManager = nullptr; diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index 350ab06df47b58..15dfe108b312dd 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -29,7 +29,8 @@ namespace chip { // The set of parameters needed for starting a BDX download. -struct BdxDownloadParameters { +struct BdxDownloadParameters +{ uint32_t delayedActionTime; chip::CharSpan imageURI; uint32_t softwareVersion; @@ -40,23 +41,25 @@ struct BdxDownloadParameters { }; // Possible values for the UpdateState attribute -enum UpdateStateEnum { - Unknown = 0, - Idle = 1, - Querying = 2, - DelayedOnQuery = 3, - Downloading = 4, - Applying = 5, - DelayedOnApply = 6, - RollingBack = 7, - DelayedOnUserConsent = 8, - }; +enum UpdateStateEnum +{ + Unknown = 0, + Idle = 1, + Querying = 2, + DelayedOnQuery = 3, + Downloading = 4, + Applying = 5, + DelayedOnApply = 6, + RollingBack = 7, + DelayedOnUserConsent = 8, +}; // Return type for RequestUserConsent() -enum UserConsentAction { - ImmediateYes = 1, - ImmediateNo = 2, - Requested = 3, +enum UserConsentAction +{ + ImmediateYes = 1, + ImmediateNo = 2, + Requested = 3, }; // Interface class to abstract the OTA-related business logic. Each application @@ -64,7 +67,6 @@ enum UserConsentAction { class OTARequestorDriver { public: - // Mandatory methods, applications are required to implement these // A call into the application logic to give it a chance to allow or stop the Requestor @@ -83,17 +85,16 @@ class OTARequestorDriver // This method informs the application of the BDX download parameters. This info can be used // later on for diecting the Requestor to resume an interrupted download - virtual void PostBdxDownloadParameters(const BdxDownloadParameters &bdxParameters) {}; + virtual void PostBdxDownloadParameters(const BdxDownloadParameters & bdxParameters){}; // Return maximum supported download block size - virtual uint16_t GetMaxDownloadBlockSize() { return 1024;} + virtual uint16_t GetMaxDownloadBlockSize() { return 1024; } // Get Version of the last downloaded image, return CHIP_ERROR_NOT_FOUND if none exists - virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_INCORRECT_STATE;} + virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_INCORRECT_STATE; } // Notify application of a change in the UpdateState attribute - virtual void NotifyUpdateStateChange(chip::UpdateStateEnum state) {}; - + virtual void NotifyUpdateStateChange(chip::UpdateStateEnum state){}; // Destructor virtual ~OTARequestorDriver() = default; From 28c961ca2d69dde5e9db75131d9f0acf90598dbc Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 9 Dec 2021 10:00:54 -0500 Subject: [PATCH 5/9] Add CHIP_ERROR_NOT_FOUND and use it in the OTA Requestor API --- src/app/clusters/ota-requestor/OTARequestorDriver.h | 2 +- src/lib/core/CHIPError.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index 15dfe108b312dd..2b105c391c8aa6 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -91,7 +91,7 @@ class OTARequestorDriver virtual uint16_t GetMaxDownloadBlockSize() { return 1024; } // Get Version of the last downloaded image, return CHIP_ERROR_NOT_FOUND if none exists - virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_INCORRECT_STATE; } + virtual CHIP_ERROR GetLastDownloadedImageVersion(uint32_t & out_version) { return CHIP_ERROR_NOT_FOUND; } // Notify application of a change in the UpdateState attribute virtual void NotifyUpdateStateChange(chip::UpdateStateEnum state){}; diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index 656d8a505ebad8..b8189a997aaa36 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -2332,6 +2332,15 @@ using CHIP_ERROR = ::chip::ChipError; * the required elements */ #define CHIP_ERROR_IM_MALFORMED_DATA_VERSION_FILTER_IB CHIP_CORE_ERROR(0xd7) + +/** + * @def CHIP_ERROR_NOT_FOUND + * + * @brief + * The item referenced in the function call was not found + */ +#define CHIP_ERROR_NOT_FOUND CHIP_CORE_ERROR(0xd8) + /** * @} */ From 83a6ecfb4a0df4eb8d58293b238ffe4bcf01abac Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 9 Dec 2021 15:43:02 +0000 Subject: [PATCH 6/9] Restyled by clang-format --- src/app/clusters/ota-requestor/OTARequestor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index 70690473288801..4e815c0b09cab4 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -365,7 +365,6 @@ void OTARequestor::OnConnectionFailure(void * context, NodeId deviceId, CHIP_ERR ChipLogError(SoftwareUpdate, "Failed to connect to node 0x%" PRIX64 ": %" CHIP_ERROR_FORMAT, deviceId, error.Format()); } - CHIP_ERROR OTARequestor::BuildQueryImageRequest(QueryImageRequest & request) { constexpr EmberAfOTADownloadProtocol kProtocolsSupported[] = { EMBER_ZCL_OTA_DOWNLOAD_PROTOCOL_BDX_SYNCHRONOUS }; From 1605e8ab6f63a3ec4bf0aff705823551fc78ab49 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 9 Dec 2021 14:01:59 -0500 Subject: [PATCH 7/9] Comment out download resumption API, the functionality won't be supported in 1.0 --- src/app/clusters/ota-requestor/OTARequestor.h | 7 +++---- src/app/clusters/ota-requestor/OTARequestorDriver.h | 12 ++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index 1318fe212c7863..24917833df9526 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -78,12 +78,11 @@ class OTARequestor : public OTARequestorInterface // FALSE otherwise void OnUserConsent(bool result); + /* Commented out until the API is supported // Application directs the Requestor to download the image using the suppiled parameter and without // issuing QueryImage - OTATriggerResult ResumeImageDownload(const BdxDownloadParameters & bdxParameters) - { /* NOT IMPLEMENTED YET */ - return kTriggerSuccessful; - } + OTATriggerResult ResumeImageDownload(const BdxDownloadParameters & bdxParameters){ return kTriggerSuccessful;} + */ // Application interface declarations -- end diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index 2b105c391c8aa6..a1bcb6855801e5 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -28,17 +28,19 @@ namespace chip { +/* Commented out until the API is supported // The set of parameters needed for starting a BDX download. struct BdxDownloadParameters { - uint32_t delayedActionTime; + uint32_t delayedActionTime; // Might not be needed chip::CharSpan imageURI; uint32_t softwareVersion; - chip::CharSpan softwareVersionString; + chip::CharSpan softwareVersionString; // Might not be needed chip::ByteSpan updateToken; - bool userConsentNeeded; - chip::ByteSpan metadataForRequestor; + bool userConsentNeeded; // Might not be needed + chip::ByteSpan metadataForRequestor; // Might not be needed }; +*/ // Possible values for the UpdateState attribute enum UpdateStateEnum @@ -83,9 +85,11 @@ class OTARequestorDriver // Optional methods, applications may choose to implement these + /* Commented out until the API is supported // This method informs the application of the BDX download parameters. This info can be used // later on for diecting the Requestor to resume an interrupted download virtual void PostBdxDownloadParameters(const BdxDownloadParameters & bdxParameters){}; + */ // Return maximum supported download block size virtual uint16_t GetMaxDownloadBlockSize() { return 1024; } From 432d7265fd4af866170204d6f60f9779988e97b3 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 9 Dec 2021 15:23:26 -0500 Subject: [PATCH 8/9] Update README to account for a change from a different PR --- examples/ota-requestor-app/linux/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/ota-requestor-app/linux/README.md b/examples/ota-requestor-app/linux/README.md index 85a57db881da7d..fc006d9a423bef 100644 --- a/examples/ota-requestor-app/linux/README.md +++ b/examples/ota-requestor-app/linux/README.md @@ -30,7 +30,7 @@ In terminal 2: In terminal 3: ``` -./chip-ota-requestor-app -d ${REQUESTOR_LONG_DISCRIMINATOR} -u ${REQUESTOR_UDP_PORT} -i ${PROVIDER_IP_ADDRESS} -n ${PROVIDER_NODE_ID} -q ${DELAY_QUERY_SECONDS} +./chip-ota-requestor-app -d ${REQUESTOR_LONG_DISCRIMINATOR} -u ${REQUESTOR_UDP_PORT} -n ${PROVIDER_NODE_ID} -f ${PROVIDER_FABRIC_INDEX} -q ${DELAY_QUERY_SECONDS} ``` - `{REQUESTOR_LONG_DISCRIMINATOR}` is the long discriminator specified for the @@ -39,7 +39,10 @@ In terminal 3: for secure connections - `${PROVIDER_IP_ADDRESS}` is the IP address of the ota-provider-app that has been resolved manually -- `${PROVIDER_NODE_ID}` is the node ID of the ota-provider-app assigned above +- `${PROVIDER_NODE_ID}` is the node ID of the ota-provider-app; this is a Test + Mode parameter and should not be used in most scenarios +- `${PROVIDER_FABRIC_INDEX}` is the fabric index of the ota-provider-app; this + is a Test Mode parameter and should not be used in most scenarios - `${DELAY_QUERY_SECONDS}` is the amount of time in seconds to wait before initiating secure session establishment and query for software image From 6e81a5435f257d2f34ccb5050cb753a290e53233 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 9 Dec 2021 20:24:18 +0000 Subject: [PATCH 9/9] Restyled by prettier-markdown --- examples/ota-requestor-app/linux/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ota-requestor-app/linux/README.md b/examples/ota-requestor-app/linux/README.md index fc006d9a423bef..fed5e9462b264f 100644 --- a/examples/ota-requestor-app/linux/README.md +++ b/examples/ota-requestor-app/linux/README.md @@ -40,7 +40,7 @@ In terminal 3: - `${PROVIDER_IP_ADDRESS}` is the IP address of the ota-provider-app that has been resolved manually - `${PROVIDER_NODE_ID}` is the node ID of the ota-provider-app; this is a Test - Mode parameter and should not be used in most scenarios + Mode parameter and should not be used in most scenarios - `${PROVIDER_FABRIC_INDEX}` is the fabric index of the ota-provider-app; this is a Test Mode parameter and should not be used in most scenarios - `${DELAY_QUERY_SECONDS}` is the amount of time in seconds to wait before