Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TestEventTrigger delegate for OTA query #19716

Merged
merged 7 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/util/attribute-storage.h>

#include <credentials/DeviceAttestationCredsProvider.h>
Expand Down Expand Up @@ -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,
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };

LEDWidget sStatusLED;
UnusedLedsWrapper<3> sUnusedLeds{ { DK_LED2, DK_LED3, DK_LED4 } };
k_timer sFunctionTimer;
Expand Down Expand Up @@ -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());
Expand Down
25 changes: 15 additions & 10 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -57,15 +58,17 @@ 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 };

K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent));
k_timer sFunctionTimer;
Expand Down Expand Up @@ -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());
Expand Down
11 changes: 8 additions & 3 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/door-lock-server/door-lock-server.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
Expand Down Expand Up @@ -58,7 +59,9 @@ 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 };

LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <platform/PlatformManager.h>

#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <crypto/CHIPCryptoPAL.h>
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <crypto/CHIPCryptoPAL.h>
#include <lib/core/CHIPError.h>
#include <lib/support/Base64.h>
#include <lib/support/BytesToHex.h>

#include <credentials/examples/DeviceAttestationCredsExample.h>

Expand Down Expand Up @@ -70,6 +71,7 @@ enum
kOptionCSRResponseAttestationSignatureIncorrectType = 0x101c,
kOptionCSRResponseAttestationSignatureInvalid = 0x101d,
kOptionCSRResponseCSRExistingKeyPair = 0x101e,
kDeviceOption_TestEventTriggerEnableKey = 0x101f,
};

constexpr unsigned kAppUsageLength = 64;
Expand Down Expand Up @@ -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 },
{}
};

Expand Down Expand Up @@ -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 <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<uint8_t> & outVector)
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct LinuxDeviceOptions
chip::Optional<std::string> traceStreamFilename;
chip::Credentials::DeviceAttestationCredentialsProvider * dacProvider = nullptr;
chip::CSRResponseOptions mCSRResponseOptions;
uint8_t testEventTriggerEnableKey[16] = { 0 };

static LinuxDeviceOptions & GetInstance();
};
Expand Down
10 changes: 8 additions & 2 deletions examples/pump-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 8 additions & 2 deletions examples/pump-controller-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 7 additions & 1 deletion examples/window-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/util/attribute-storage.h>

#include <credentials/DeviceAttestationCredsProvider.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 += [
Expand Down
30 changes: 25 additions & 5 deletions src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,42 @@ void DefaultOTARequestor::TriggerImmediateQueryInternal()
ConnectToProvider(kQueryImage);
}

OTARequestorInterface::OTATriggerResult DefaultOTARequestor::TriggerImmediateQuery()
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved
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");
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved
return kNoProviderKnown;
return CHIP_ERROR_INCORRECT_STATE;
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved
}

SetCurrentProviderLocation(providerLocation);

// Go through the driver as it has additional logic to execute
mOtaRequestorDriver->SendQueryImage();
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved

return kTriggerSuccessful;
return CHIP_NO_ERROR;
}

void DefaultOTARequestor::DownloadUpdate()
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/DefaultOTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions src/app/clusters/ota-requestor/OTARequestorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Loading