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

Issue #10592 [ota-provider-app] Make various values to ApplyUpdateResponse Command configurable #15208

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ApplicationBasic
ApplicationId
ApplicationIdentifier
ApplicationLauncher
applyUpdateAction
ApplyUpdateRequest
ApplyUpdateResponse
approver
Expand Down
1 change: 1 addition & 0 deletions examples/ota-provider-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/debug c
| -f/--filepath <file> | Path to a file containing an OTA image |
| -o/--otaImageList <file> | Path to a file containing a list of OTA images |
| -q/--queryImageStatus <updateAvailable \| busy \| updateNotAvailable> | Value for the Status field in the QueryImageResponse |
| -a/--applyUpdateAction <proceed \| awaitNextAction \| discontinue> | Value for the Action field in the ApplyUpdateResponse |
| -t/--delayedActionTimeSec <time> | Value in seconds for the DelayedActionTime field in the QueryImageResponse and ApplyUpdateResponse |
| -u/--userConsentState <granted \| denied \| deferred> | Current user consent state which results in various values for Status field in QueryImageResponse <br> Note that -q/--queryImageStatus overrides this option <li> granted: Status field in QueryImageResponse is set to updateAvailable <li> denied: Status field in QueryImageResponse is set to updateNotAvailable <li> deferred: Status field in QueryImageResponse is set to busy |
| -s/--softwareVersion <version> | Value for the SoftwareVersion field in the QueryImageResponse <br> Note that -o/--otaImageList overrides this option |
Expand Down
31 changes: 31 additions & 0 deletions examples/ota-provider-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ using chip::ArgParser::OptionSet;
using chip::ArgParser::PrintArgError;
using chip::bdx::TransferControlFlags;
using chip::Messaging::ExchangeManager;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider;

// TODO: this should probably be done dynamically
constexpr chip::EndpointId kOtaProviderEndpoint = 0;
Expand All @@ -46,6 +47,7 @@ constexpr uint16_t kOptionFilepath = 'f';
constexpr uint16_t kOptionOtaImageList = 'o';
constexpr uint16_t kOptionQueryImageStatus = 'q';
constexpr uint16_t kOptionUserConsentState = 'u';
constexpr uint16_t kOptionUpdateAction = 'a';
constexpr uint16_t kOptionDelayedActionTimeSec = 't';
constexpr uint16_t kOptionSoftwareVersion = 's';
constexpr uint16_t kOptionSoftwareVersionStr = 'S';
Expand All @@ -56,6 +58,7 @@ chip::ota::DefaultUserConsentProvider gUserConsentProvider;

// Global variables used for passing the CLI arguments to the OTAProviderExample object
static OTAProviderExample::QueryImageBehaviorType gQueryImageBehavior = OTAProviderExample::kRespondWithUnknown;
static OTAApplyUpdateAction gOptionUpdateAction = OTAApplyUpdateAction::kProceed;
static uint32_t gDelayedActionTimeSec = 0;
static const char * gOtaFilepath = nullptr;
static const char * gOtaImageListFilepath = nullptr;
Expand Down Expand Up @@ -183,6 +186,30 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
retval = false;
}
break;
case kOptionUpdateAction:
if (aValue == NULL)
{
PrintArgError("%s: ERROR: NULL applyUpdateAction parameter\n", aProgram);
retval = false;
}
else if (strcmp(aValue, "proceed") == 0)
{
gOptionUpdateAction = OTAApplyUpdateAction::kProceed;
}
else if (strcmp(aValue, "awaitNextAction") == 0)
{
gOptionUpdateAction = OTAApplyUpdateAction::kAwaitNextAction;
}
else if (strcmp(aValue, "discontinue") == 0)
{
gOptionUpdateAction = OTAApplyUpdateAction::kDiscontinue;
}
else
{
PrintArgError("%s: ERROR: Invalid applyUpdateAction parameter: %s\n", aProgram, aValue);
retval = false;
}
break;
case kOptionDelayedActionTimeSec:
gDelayedActionTimeSec = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
break;
Expand Down Expand Up @@ -245,6 +272,7 @@ OptionDef cmdLineOptionsDef[] = {
{ "filepath", chip::ArgParser::kArgumentRequired, kOptionFilepath },
{ "otaImageList", chip::ArgParser::kArgumentRequired, kOptionOtaImageList },
{ "queryImageStatus", chip::ArgParser::kArgumentRequired, kOptionQueryImageStatus },
{ "applyUpdateAction", chip::ArgParser::kArgumentRequired, kOptionUpdateAction },
{ "delayedActionTimeSec", chip::ArgParser::kArgumentRequired, kOptionDelayedActionTimeSec },
{ "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
{ "softwareVersion", chip::ArgParser::kArgumentRequired, kOptionSoftwareVersion },
Expand All @@ -260,6 +288,8 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
" Path to a file containing a list of OTA images\n"
" -q/--queryImageStatus <updateAvailable | busy | updateNotAvailable>\n"
" Value for the Status field in the QueryImageResponse\n"
" -a/--applyUpdateAction <proceed | awaitNextAction | discontinue>\n"
" Value for the Action field in the ApplyUpdateResponse\n"
" -t/--delayedActionTimeSec <time>\n"
" Value in seconds for the DelayedActionTime field in the QueryImageResponse\n"
" and ApplyUpdateResponse\n"
Expand Down Expand Up @@ -303,6 +333,7 @@ void ApplicationInit()
}

gOtaProvider.SetQueryImageBehavior(gQueryImageBehavior);
gOtaProvider.SetApplyUpdateAction(gOptionUpdateAction);
gOtaProvider.SetDelayedActionTimeSec(gDelayedActionTimeSec);
if (gSoftwareVersion.HasValue())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ EmberAfStatus OTAProviderExample::HandleApplyUpdateRequest(chip::app::CommandHan
const ApplyUpdateRequest::DecodableType & commandData)
{
// TODO: handle multiple transfers by tracking updateTokens

OTAApplyUpdateAction updateAction = OTAApplyUpdateAction::kProceed; // For now, just allow any update request
char tokenBuf[kUpdateTokenStrLen] = { 0 };

GetUpdateTokenString(commandData.updateToken, tokenBuf, kUpdateTokenStrLen);
Expand All @@ -312,7 +310,7 @@ EmberAfStatus OTAProviderExample::HandleApplyUpdateRequest(chip::app::CommandHan
VerifyOrReturnError(commandObj != nullptr, EMBER_ZCL_STATUS_INVALID_VALUE);

ApplyUpdateResponse::Type response;
response.action = updateAction;
response.action = mUpdateAction;
response.delayedActionTime = mDelayedActionTimeSec;
VerifyOrReturnError(commandObj->AddResponseData(commandPath, response) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/CommandHandler.h>
#include <app/clusters/ota-provider/ota-provider-delegate.h>
#include <ota-provider-common/BdxOtaSender.h>
Expand Down Expand Up @@ -69,6 +70,10 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
} DeviceSoftwareVersionModel;
void SetOTACandidates(std::vector<OTAProviderExample::DeviceSoftwareVersionModel> candidates);
void SetQueryImageBehavior(QueryImageBehaviorType behavior) { mQueryImageBehavior = behavior; }
void SetApplyUpdateAction(chip::app::Clusters::OtaSoftwareUpdateProvider::OTAApplyUpdateAction action)
{
mUpdateAction = action;
}
void SetDelayedActionTimeSec(uint32_t time) { mDelayedActionTimeSec = time; }
void SetUserConsentDelegate(chip::ota::UserConsentDelegate * delegate) { mUserConsentDelegate = delegate; }
void SetSoftwareVersion(uint32_t softwareVersion) { mSoftwareVersion.SetValue(softwareVersion); }
Expand All @@ -81,6 +86,7 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
static constexpr size_t kFilepathBufLen = 256;
char mOTAFilePath[kFilepathBufLen]; // null-terminated
QueryImageBehaviorType mQueryImageBehavior;
chip::app::Clusters::OtaSoftwareUpdateProvider::OTAApplyUpdateAction mUpdateAction;
uint32_t mDelayedActionTimeSec;
bool SelectOTACandidate(const uint16_t requestorVendorID, const uint16_t requestorProductID,
const uint32_t requestorSoftwareVersion,
Expand Down