From 03a54f41d41e399c89c1455615bc6cb27b6f7d98 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 17 Jun 2022 14:48:27 +0200 Subject: [PATCH 1/7] [ota] Add TestEventTriggerDelegate for OTA query Make it possible to use TestEventTrigger command of GeneralDiagnostics cluster to trigger OTA query on demand. The requested trigger must be 0x0100'0000'0000'01, where is fabric index of the OTA provider to query, or 00 if the OTA provider is supposed to be selected automatically. Signed-off-by: Damian Krolik --- src/app/chip_data_model.gni | 2 + .../ota-requestor/DefaultOTARequestor.cpp | 30 ++++++++++-- .../ota-requestor/DefaultOTARequestor.h | 2 +- .../ota-requestor/OTARequestorInterface.h | 13 ++---- .../OTATestEventTriggerDelegate.cpp | 46 +++++++++++++++++++ .../OTATestEventTriggerDelegate.h | 40 ++++++++++++++++ 6 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.cpp create mode 100644 src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.h diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 1c08a5e433e4f1..8c721b2ecefca0 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -133,6 +133,8 @@ template("chip_data_model") { "${_app_root}/clusters/${cluster}/DefaultOTARequestorUserConsent.h", "${_app_root}/clusters/${cluster}/ExtendedOTARequestorDriver.cpp", "${_app_root}/clusters/${cluster}/OTARequestorStorage.h", + "${_app_root}/clusters/${cluster}/OTATestEventTriggerDelegate.cpp", + "${_app_root}/clusters/${cluster}/OTATestEventTriggerDelegate.h", ] } else if (cluster == "bindings") { sources += [ diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 6cdd65f91a1a07..840ce25d0e9e12 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -522,14 +522,34 @@ void DefaultOTARequestor::TriggerImmediateQueryInternal() ConnectToProvider(kQueryImage); } -OTARequestorInterface::OTATriggerResult DefaultOTARequestor::TriggerImmediateQuery() +CHIP_ERROR DefaultOTARequestor::TriggerImmediateQuery(FabricIndex fabricIndex) { ProviderLocationType providerLocation; - bool listExhausted = false; - if (mOtaRequestorDriver->GetNextProviderLocation(providerLocation, listExhausted) != true) + bool providerFound = false; + + if (fabricIndex == kUndefinedFabricIndex) + { + bool listExhausted = false; + providerFound = mOtaRequestorDriver->GetNextProviderLocation(providerLocation, listExhausted); + } + else + { + for (auto providerIter = mDefaultOtaProviderList.Begin(); providerIter.Next();) + { + providerLocation = providerIter.GetValue(); + + if (providerLocation.GetFabricIndex() == fabricIndex) + { + providerFound = true; + break; + } + } + } + + if (!providerFound) { ChipLogError(SoftwareUpdate, "No OTA Providers available"); - return kNoProviderKnown; + return CHIP_ERROR_INCORRECT_STATE; } SetCurrentProviderLocation(providerLocation); @@ -537,7 +557,7 @@ OTARequestorInterface::OTATriggerResult DefaultOTARequestor::TriggerImmediateQue // Go through the driver as it has additional logic to execute mOtaRequestorDriver->SendQueryImage(); - return kTriggerSuccessful; + return CHIP_NO_ERROR; } void DefaultOTARequestor::DownloadUpdate() diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.h b/src/app/clusters/ota-requestor/DefaultOTARequestor.h index 5d5000f22a1e91..13c2f1bea9a504 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.h @@ -47,7 +47,7 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader:: const app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData) override; // Application API to send the QueryImage command and start the image update process with the next available Provider - OTATriggerResult TriggerImmediateQuery() override; + CHIP_ERROR TriggerImmediateQuery(FabricIndex fabricIndex) override; // Internal API meant for use by OTARequestorDriver to send the QueryImage command and start the image update process // with the Provider currently set diff --git a/src/app/clusters/ota-requestor/OTARequestorInterface.h b/src/app/clusters/ota-requestor/OTARequestorInterface.h index cb5ac8c977a6dc..f24563d36c3c79 100644 --- a/src/app/clusters/ota-requestor/OTARequestorInterface.h +++ b/src/app/clusters/ota-requestor/OTARequestorInterface.h @@ -145,14 +145,6 @@ class OTARequestorInterface using OTAUpdateStateEnum = chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum; using ProviderLocationType = app::Clusters::OtaSoftwareUpdateRequestor::Structs::ProviderLocation::Type; - // Return value for various trigger-type APIs - enum OTATriggerResult - { - kTriggerSuccessful = 0, - kNoProviderKnown = 1, - kWrongState = 2 - }; - // Reset any relevant states virtual void Reset(void) = 0; @@ -167,8 +159,9 @@ class OTARequestorInterface // Destructor virtual ~OTARequestorInterface() = default; - // Application API to send the QueryImage command and start the image update process with the next available Provider - virtual OTATriggerResult TriggerImmediateQuery() = 0; + // Application API to send the QueryImage command and start the image update process. + // The `fabricIndex` optional argument can be used to explicitly select the OTA provider. + virtual CHIP_ERROR TriggerImmediateQuery(FabricIndex fabricIndex = kUndefinedFabricIndex) = 0; // Internal API meant for use by OTARequestorDriver to send the QueryImage command and start the image update process // with the preset provider diff --git a/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.cpp b/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.cpp new file mode 100644 index 00000000000000..a879f817ed9b86 --- /dev/null +++ b/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.cpp @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OTATestEventTriggerDelegate.h" + +#include "OTARequestorInterface.h" + +#include + +namespace chip { + +bool OTATestEventTriggerDelegate::DoesEnableKeyMatch(const ByteSpan & enableKey) const +{ + return !mEnableKey.empty() && mEnableKey.data_equal(enableKey); +} + +CHIP_ERROR OTATestEventTriggerDelegate::HandleEventTrigger(uint64_t eventTrigger) +{ + if ((eventTrigger & ~kOtaQueryFabricIndexMask) == kOtaQueryTrigger) + { + OTARequestorInterface * requestor = GetRequestorInstance(); + const FabricIndex fabricIndex = eventTrigger & kOtaQueryFabricIndexMask; + + VerifyOrReturnError(requestor != nullptr, CHIP_ERROR_INCORRECT_STATE); + return requestor->TriggerImmediateQuery(fabricIndex); + } + + return CHIP_ERROR_INVALID_ARGUMENT; +} + +} // namespace chip diff --git a/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.h b/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.h new file mode 100644 index 00000000000000..6c78a16a7665ff --- /dev/null +++ b/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace chip { + +class OTATestEventTriggerDelegate : public TestEventTriggerDelegate +{ +public: + static constexpr uint64_t kOtaQueryTrigger = 0x0100'0000'0000'0100; + static constexpr uint64_t kOtaQueryFabricIndexMask = 0xff; + + explicit OTATestEventTriggerDelegate(const ByteSpan & enableKey) : mEnableKey(enableKey) {} + + bool DoesEnableKeyMatch(const ByteSpan & enableKey) const override; + CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override; + +private: + ByteSpan mEnableKey; +}; + +} // namespace chip From 8a0af6db813b0640137f4e301aed0f47dd7d9d46 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 17 Jun 2022 14:51:40 +0200 Subject: [PATCH 2/7] Use OTATestEventTriggerDelegate in nRF and Linux examples Initialize OTATestEventTriggerDelegate in nRF Connect and Linux examples. nRF Connect examples use a constant enable key "001122(..)ff" while Linux apps allow for configuring the key at runtime using "--enable-key" argument. --- .../nrfconnect/main/AppTask.cpp | 9 +++++++-- .../lighting-app/nrfconnect/main/AppTask.cpp | 7 ++++++- examples/lock-app/nrfconnect/main/AppTask.cpp | 9 +++++++-- examples/platform/linux/AppMain.cpp | 5 +++++ examples/platform/linux/Options.cpp | 18 ++++++++++++++++++ examples/platform/linux/Options.h | 1 + examples/pump-app/nrfconnect/main/AppTask.cpp | 10 ++++++++-- .../nrfconnect/main/AppTask.cpp | 10 ++++++++-- .../window-app/nrfconnect/main/AppTask.cpp | 8 +++++++- 9 files changed, 67 insertions(+), 10 deletions(-) diff --git a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp index 106c3957f4c5af..e3a28756b4a579 100644 --- a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -58,6 +59,9 @@ K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(Ap namespace { +constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + LEDWidget sStatusLED; UnusedLedsWrapper<3> sUnusedLeds{ { DK_LED2, DK_LED3, DK_LED4 } }; k_timer sFunctionTimer; @@ -182,9 +186,10 @@ CHIP_ERROR AppTask::Init() // Initialize CHIP server SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - static chip::CommonCaseDeviceServerInitParams initParams; + static CommonCaseDeviceServerInitParams initParams; + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index 46ea48cf6b1a19..e499711c70e9e0 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,8 @@ constexpr EndpointId kLightEndpointId = 1; constexpr uint32_t kIdentifyBlinkRateMs = 500; constexpr uint8_t kDefaultMinLevel = 0; constexpr uint8_t kDefaultMaxLevel = 254; +constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent)); k_timer sFunctionTimer; @@ -167,8 +170,10 @@ CHIP_ERROR AppTask::Init() // Initialize CHIP server SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - static chip::CommonCaseDeviceServerInitParams initParams; + static CommonCaseDeviceServerInitParams initParams; + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index d1b1e2266810a6..933ffaaf5b6c9b 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,8 @@ using namespace ::chip::DeviceLayer; namespace { constexpr EndpointId kLockEndpointId = 1; +constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL); K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent)); @@ -151,9 +154,11 @@ CHIP_ERROR AppTask::Init() // Initialize CHIP server SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); + static CommonCaseDeviceServerInitParams initParams; + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 15acc38f3a5c0e..18efd06436f7be 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -305,6 +306,10 @@ void ChipLinuxAppMainLoop() initParams.operationalKeystore = &LinuxDeviceOptions::GetInstance().mCSRResponseOptions.badCsrOperationalKeyStoreForTest; } + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan( + LinuxDeviceOptions::GetInstance().testEventTriggerEnableKey) }; + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; + // Init ZCL Data Model and CHIP App Server Server::GetInstance().Init(initParams); diff --git a/examples/platform/linux/Options.cpp b/examples/platform/linux/Options.cpp index 6d74aa1dcc0451..4074c155889d48 100644 --- a/examples/platform/linux/Options.cpp +++ b/examples/platform/linux/Options.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -70,6 +71,7 @@ enum kOptionCSRResponseAttestationSignatureIncorrectType = 0x101c, kOptionCSRResponseAttestationSignatureInvalid = 0x101d, kOptionCSRResponseCSRExistingKeyPair = 0x101e, + kDeviceOption_TestEventTriggerEnableKey = 0x101f, }; constexpr unsigned kAppUsageLength = 64; @@ -114,6 +116,7 @@ OptionDef sDeviceOptionDefs[] = { { "cert_error_nocsrelements_too_long", kNoArgument, kOptionCSRResponseNOCSRElementsTooLong }, { "cert_error_attestation_signature_incorrect_type", kNoArgument, kOptionCSRResponseAttestationSignatureIncorrectType }, { "cert_error_attestation_signature_invalid", kNoArgument, kOptionCSRResponseAttestationSignatureInvalid }, + { "enable-key", kArgumentRequired, kDeviceOption_TestEventTriggerEnableKey }, {} }; @@ -215,6 +218,8 @@ const char * sDeviceOptionHelp = " Configure the CSRResponse to be build with an invalid AttestationSignature type.\n" " --cert_error_attestation_signature_invalid\n" " Configure the CSRResponse to be build with an AttestationSignature that does not match what is expected.\n" + " --enable-key \n" + " A 16-byte, hex-encoded key, used to validate TestEventTrigger command of Generial Diagnostics cluster\n" "\n"; bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector & outVector) @@ -442,6 +447,19 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, case kOptionCSRResponseAttestationSignatureInvalid: LinuxDeviceOptions::GetInstance().mCSRResponseOptions.attestationSignatureInvalid = true; break; + case kDeviceOption_TestEventTriggerEnableKey: { + constexpr size_t kEnableKeyLength = sizeof(LinuxDeviceOptions::GetInstance().testEventTriggerEnableKey); + + if (Encoding::HexToBytes(aValue, strlen(aValue), LinuxDeviceOptions::GetInstance().testEventTriggerEnableKey, + kEnableKeyLength) != kEnableKeyLength) + { + + PrintArgError("%s: ERROR: invalid value specified for %s\n", aProgram, aName); + retval = false; + } + + break; + } default: PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName); diff --git a/examples/platform/linux/Options.h b/examples/platform/linux/Options.h index 56a95b772cafd8..00817f95a16378 100644 --- a/examples/platform/linux/Options.h +++ b/examples/platform/linux/Options.h @@ -59,6 +59,7 @@ struct LinuxDeviceOptions chip::Optional traceStreamFilename; chip::Credentials::DeviceAttestationCredentialsProvider * dacProvider = nullptr; chip::CSRResponseOptions mCSRResponseOptions; + uint8_t testEventTriggerEnableKey[16] = { 0 }; static LinuxDeviceOptions & GetInstance(); }; diff --git a/examples/pump-app/nrfconnect/main/AppTask.cpp b/examples/pump-app/nrfconnect/main/AppTask.cpp index b101418cad4ebf..0f266e1011637f 100644 --- a/examples/pump-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-app/nrfconnect/main/AppTask.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,9 @@ using namespace ::chip::DeviceLayer; namespace { +constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL); K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent)); k_timer sFunctionTimer; @@ -149,9 +153,11 @@ CHIP_ERROR AppTask::Init() // Initialize CHIP server SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); + static CommonCaseDeviceServerInitParams initParams; + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp index 1a0aa8202bbdfd..72049c1daafb6d 100644 --- a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,9 @@ using namespace ::chip::DeviceLayer; namespace { +constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL); K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent)); k_timer sFunctionTimer; @@ -146,9 +150,11 @@ CHIP_ERROR AppTask::Init() // Initialize CHIP server SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); + static CommonCaseDeviceServerInitParams initParams; + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/window-app/nrfconnect/main/AppTask.cpp b/examples/window-app/nrfconnect/main/AppTask.cpp index f62b096c61d878..50179fedea5781 100644 --- a/examples/window-app/nrfconnect/main/AppTask.cpp +++ b/examples/window-app/nrfconnect/main/AppTask.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,9 @@ K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(Ap namespace { +constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + LEDWidget sStatusLED; UnusedLedsWrapper<1> sUnusedLeds{ { DK_LED4 } }; k_timer sFunctionTimer; @@ -150,8 +154,10 @@ CHIP_ERROR AppTask::Init() // Initialize CHIP server SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - static chip::CommonCaseDeviceServerInitParams initParams; + static CommonCaseDeviceServerInitParams initParams; + static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); From 1ff5e9e07c2bdec9c832b4ece5e7794f206f1fe6 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 17 Jun 2022 13:12:16 +0000 Subject: [PATCH 3/7] Restyled by clang-format --- .../lighting-app/nrfconnect/main/AppTask.cpp | 18 +++++++++--------- examples/lock-app/nrfconnect/main/AppTask.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index e499711c70e9e0..d01a327d62275e 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -58,15 +58,15 @@ using namespace ::chip::DeviceLayer; namespace { -constexpr int kFactoryResetTriggerTimeout = 3000; -constexpr int kFactoryResetCancelWindowTimeout = 3000; -constexpr int kAppEventQueueSize = 10; -constexpr uint8_t kButtonPushEvent = 1; -constexpr uint8_t kButtonReleaseEvent = 0; -constexpr EndpointId kLightEndpointId = 1; -constexpr uint32_t kIdentifyBlinkRateMs = 500; -constexpr uint8_t kDefaultMinLevel = 0; -constexpr uint8_t kDefaultMaxLevel = 254; +constexpr int kFactoryResetTriggerTimeout = 3000; +constexpr int kFactoryResetCancelWindowTimeout = 3000; +constexpr int kAppEventQueueSize = 10; +constexpr uint8_t kButtonPushEvent = 1; +constexpr uint8_t kButtonReleaseEvent = 0; +constexpr EndpointId kLightEndpointId = 1; +constexpr uint32_t kIdentifyBlinkRateMs = 500; +constexpr uint8_t kDefaultMinLevel = 0; +constexpr uint8_t kDefaultMaxLevel = 254; constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index 933ffaaf5b6c9b..d56a6d4a60c4cf 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -59,7 +59,7 @@ using namespace ::chip::DeviceLayer; #define BUTTON_RELEASE_EVENT 0 namespace { -constexpr EndpointId kLockEndpointId = 1; +constexpr EndpointId kLockEndpointId = 1; constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; From cbd1d83ac96754b3727503beaa2c86d1661a67e3 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 17 Jun 2022 15:55:34 +0200 Subject: [PATCH 4/7] Fix build --- examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp | 2 +- examples/ota-requestor-app/p6/src/AppTask.cpp | 3 +-- examples/platform/linux/AppMain.cpp | 7 ++++++- examples/platform/linux/BUILD.gn | 5 +++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp index 8d120eb6c5abaa..d5f30e05b79224 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -516,7 +516,7 @@ void AppTask::OTAHandler(AppEvent * aEvent) #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR void AppTask::StartOTAQuery(intptr_t arg) { - static_cast(GetRequestorInstance())->TriggerImmediateQuery(); + GetRequestorInstance()->TriggerImmediateQuery(); } void AppTask::PostOTAResume() diff --git a/examples/ota-requestor-app/p6/src/AppTask.cpp b/examples/ota-requestor-app/p6/src/AppTask.cpp index a0507142cf0af4..0fb347d11f30d1 100644 --- a/examples/ota-requestor-app/p6/src/AppTask.cpp +++ b/examples/ota-requestor-app/p6/src/AppTask.cpp @@ -441,8 +441,7 @@ void OnTriggerUpdateTimerHandler(Layer * systemLayer, void * appState) { P6_LOG("Triggering immediate OTA update query"); - DefaultOTARequestor * req = static_cast(GetRequestorInstance()); - req->TriggerImmediateQuery(); + GetRequestorInstance()->TriggerImmediateQuery(); } void AppTask::InitOTARequestor() diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 18efd06436f7be..052000f033c1b4 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -68,6 +67,10 @@ #include "TraceHandlers.h" #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +#include +#endif + #include #include "AppMain.h" @@ -306,9 +309,11 @@ void ChipLinuxAppMainLoop() initParams.operationalKeystore = &LinuxDeviceOptions::GetInstance().mCSRResponseOptions.badCsrOperationalKeyStoreForTest; } +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan( LinuxDeviceOptions::GetInstance().testEventTriggerEnableKey) }; initParams.testEventTriggerDelegate = &testEventTriggerDelegate; +#endif // Init ZCL Data Model and CHIP App Server Server::GetInstance().Init(initParams); diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index d806ca2c6587aa..6b45bdd7e9f497 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -17,6 +17,7 @@ import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/app/common_flags.gni") import("${chip_root}/src/lib/core/core.gni") import("${chip_root}/src/lib/lib.gni") +import("${chip_root}/src/platform/device.gni") config("app-main-config") { include_dirs = [ "." ] @@ -68,6 +69,10 @@ source_set("app-main") { [ "${chip_root}/examples/common/tracing:trace_handlers_decoder" ] } + if (chip_enable_ota_requestor) { + public_deps += [ "${chip_root}/examples/ota-requestor-app/ota-requestor-common" ] + } + public_configs = [ ":app-main-config" ] } From 47fc4ab97fbdc6f9cb71f41df1e7fb0ca09bb045 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 17 Jun 2022 16:05:05 +0200 Subject: [PATCH 5/7] Address code review comments --- examples/all-clusters-app/nrfconnect/main/AppTask.cpp | 2 ++ examples/lock-app/nrfconnect/main/AppTask.cpp | 5 ++++- examples/pump-app/nrfconnect/main/AppTask.cpp | 2 ++ examples/pump-controller-app/nrfconnect/main/AppTask.cpp | 2 ++ examples/window-app/nrfconnect/main/AppTask.cpp | 2 ++ src/app/clusters/ota-requestor/DefaultOTARequestor.cpp | 7 +++++-- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp index e3a28756b4a579..0dfbac06c45396 100644 --- a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp @@ -59,6 +59,8 @@ K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(Ap namespace { +// NOTE! This key is for test/certification only and should not be available in production devices. +// Ideally, it should be a part of the factory data set. constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index d56a6d4a60c4cf..8cd120d40a283e 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -59,7 +59,10 @@ using namespace ::chip::DeviceLayer; #define BUTTON_RELEASE_EVENT 0 namespace { -constexpr EndpointId kLockEndpointId = 1; +constexpr EndpointId kLockEndpointId = 1; + +// NOTE! This key is for test/certification only and should not be available in production devices. +// Ideally, it should be a part of the factory data set. constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; diff --git a/examples/pump-app/nrfconnect/main/AppTask.cpp b/examples/pump-app/nrfconnect/main/AppTask.cpp index 0f266e1011637f..45ca1d5a06599c 100644 --- a/examples/pump-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-app/nrfconnect/main/AppTask.cpp @@ -62,6 +62,8 @@ using namespace ::chip::DeviceLayer; namespace { +// NOTE! This key is for test/certification only and should not be available in production devices. +// Ideally, it should be a part of the factory data set. constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; diff --git a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp index 72049c1daafb6d..621d4f97af16e9 100644 --- a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp @@ -59,6 +59,8 @@ using namespace ::chip::DeviceLayer; namespace { +// NOTE! This key is for test/certification only and should not be available in production devices. +// Ideally, it should be a part of the factory data set. constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; diff --git a/examples/window-app/nrfconnect/main/AppTask.cpp b/examples/window-app/nrfconnect/main/AppTask.cpp index 50179fedea5781..44c42effffef50 100644 --- a/examples/window-app/nrfconnect/main/AppTask.cpp +++ b/examples/window-app/nrfconnect/main/AppTask.cpp @@ -55,6 +55,8 @@ K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(Ap namespace { +// NOTE! This key is for test/certification only and should not be available in production devices. +// Ideally, it should be a part of the factory data set. constexpr uint8_t kTestEventTriggerEnableKey[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 840ce25d0e9e12..b34d08c646e05f 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -548,8 +548,8 @@ CHIP_ERROR DefaultOTARequestor::TriggerImmediateQuery(FabricIndex fabricIndex) if (!providerFound) { - ChipLogError(SoftwareUpdate, "No OTA Providers available"); - return CHIP_ERROR_INCORRECT_STATE; + ChipLogError(SoftwareUpdate, "No OTA Providers available for immediate query"); + return CHIP_ERROR_NOT_FOUND; } SetCurrentProviderLocation(providerLocation); @@ -557,6 +557,9 @@ CHIP_ERROR DefaultOTARequestor::TriggerImmediateQuery(FabricIndex fabricIndex) // Go through the driver as it has additional logic to execute mOtaRequestorDriver->SendQueryImage(); + ChipLogProgress(SoftwareUpdate, "Triggered immediate OTA query for fabric: 0x%x", + static_cast(providerLocation.GetFabricIndex())); + return CHIP_NO_ERROR; } From 542288c0b6c422134471d39cf09f80261bc58e8c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 17 Jun 2022 14:05:36 +0000 Subject: [PATCH 6/7] Restyled by gn --- examples/platform/linux/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index 6b45bdd7e9f497..4bb3da88d2e24c 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -70,7 +70,8 @@ source_set("app-main") { } if (chip_enable_ota_requestor) { - public_deps += [ "${chip_root}/examples/ota-requestor-app/ota-requestor-common" ] + public_deps += + [ "${chip_root}/examples/ota-requestor-app/ota-requestor-common" ] } public_configs = [ ":app-main-config" ] From 0349fde91503315c0bb0e7f0665e434970c70489 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 17 Jun 2022 16:56:11 +0200 Subject: [PATCH 7/7] Another attempt to silence GN checker --- examples/platform/linux/BUILD.gn | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index 4bb3da88d2e24c..1a2f35921095a0 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -17,12 +17,17 @@ import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/app/common_flags.gni") import("${chip_root}/src/lib/core/core.gni") import("${chip_root}/src/lib/lib.gni") -import("${chip_root}/src/platform/device.gni") config("app-main-config") { include_dirs = [ "." ] } +source_set("ota-test-event-trigger") { + sources = [ + "${chip_root}/src/app/clusters/ota-requestor/OTATestEventTriggerDelegate.h", + ] +} + source_set("app-main") { defines = [] sources = [ @@ -56,6 +61,7 @@ source_set("app-main") { } public_deps = [ + ":ota-test-event-trigger", "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/app/server", "${chip_root}/src/credentials:default_attestation_verifier", @@ -69,11 +75,6 @@ source_set("app-main") { [ "${chip_root}/examples/common/tracing:trace_handlers_decoder" ] } - if (chip_enable_ota_requestor) { - public_deps += - [ "${chip_root}/examples/ota-requestor-app/ota-requestor-common" ] - } - public_configs = [ ":app-main-config" ] }