Skip to content

Commit

Permalink
Issue #11758 [ota-provider-app] Support for error/timeout in response…
Browse files Browse the repository at this point in the history
… to QueryImage command (#15427)

* Issue#11758 - Support for error/timeout in response to QueryImage command.

* OTA-P sends error response on first ignore.  On second QueryImage, success.

* OTA-P doesn't send QueryImage response followed by a succcessful QueryImage works.

* Change CLI argument from b to x.

* restyle-diff.sh changes

* Update description for -x CLI arguement.
Add description for -x CLI argument in OTA provider readme file.

* Add ignoreQuerymage to wordlist for Spellchecker.

* Code review changes. Moved ignore condition up to reduce  indentation changes.
  • Loading branch information
isiu-apple authored and pull[bot] committed Jan 24, 2024
1 parent 5bbfffd commit 2952813
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ idx
ifdef
ifdefs
IGMP
ignoreQueryImage
ihex
IlluminanceMeasurement
IM
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 |
| -x/--ignoreQueryImage <num_times_to_ignore> | The number of times to ignore the QueryImage Command and not send a response |
| -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 |
Expand Down
9 changes: 9 additions & 0 deletions examples/ota-provider-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ constexpr chip::EndpointId kOtaProviderEndpoint = 0;
constexpr uint16_t kOptionFilepath = 'f';
constexpr uint16_t kOptionOtaImageList = 'o';
constexpr uint16_t kOptionQueryImageStatus = 'q';
constexpr uint16_t kOptionIgnoreQueryImage = 'x';
constexpr uint16_t kOptionUserConsentState = 'u';
constexpr uint16_t kOptionUpdateAction = 'a';
constexpr uint16_t kOptionDelayedActionTimeSec = 't';
Expand All @@ -66,6 +67,7 @@ static chip::ota::UserConsentState gUserConsentState = chip::ot
static bool gUserConsentNeeded = false;
static chip::Optional<uint32_t> gSoftwareVersion;
static const char * gSoftwareVersionString = nullptr;
static uint32_t gIgnoreQueryImageCount = 0;

// Parses the JSON filepath and extracts DeviceSoftwareVersionModel parameters
static bool ParseJsonFileAndPopulateCandidates(const char * filepath,
Expand Down Expand Up @@ -186,6 +188,9 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
retval = false;
}
break;
case kOptionIgnoreQueryImage:
gIgnoreQueryImageCount = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
break;
case kOptionUpdateAction:
if (aValue == NULL)
{
Expand Down Expand Up @@ -272,6 +277,7 @@ OptionDef cmdLineOptionsDef[] = {
{ "filepath", chip::ArgParser::kArgumentRequired, kOptionFilepath },
{ "otaImageList", chip::ArgParser::kArgumentRequired, kOptionOtaImageList },
{ "queryImageStatus", chip::ArgParser::kArgumentRequired, kOptionQueryImageStatus },
{ "ignoreQueryImage", chip::ArgParser::kArgumentRequired, kOptionIgnoreQueryImage },
{ "applyUpdateAction", chip::ArgParser::kArgumentRequired, kOptionUpdateAction },
{ "delayedActionTimeSec", chip::ArgParser::kArgumentRequired, kOptionDelayedActionTimeSec },
{ "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
Expand All @@ -288,6 +294,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"
" -x/--ignoreQueryImage <num_times_to_ignore>\n"
" The number of times to ignore the QueryImage Command and not send a response.\n"
" -a/--applyUpdateAction <proceed | awaitNextAction | discontinue>\n"
" Value for the Action field in the ApplyUpdateResponse\n"
" -t/--delayedActionTimeSec <time>\n"
Expand Down Expand Up @@ -333,6 +341,7 @@ void ApplicationInit()
}

gOtaProvider.SetQueryImageBehavior(gQueryImageBehavior);
gOtaProvider.SetIgnoreQueryImageCount(gIgnoreQueryImageCount);
gOtaProvider.SetApplyUpdateAction(gOptionUpdateAction);
gOtaProvider.SetDelayedActionTimeSec(gDelayedActionTimeSec);
if (gSoftwareVersion.HasValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
bool requestorCanConsent = commandData.requestorCanConsent.ValueOr(false);
QueryImageResponse::Type response;

if (mIgnoreQueryImageCount > 0)
{
ChipLogDetail(SoftwareUpdate, "Skip HandleQueryImage response. mIgnoreQueryImageCount %" PRIu32, mIgnoreQueryImageCount);
mIgnoreQueryImageCount--;
return EMBER_ZCL_STATUS_SUCCESS;
}

switch (mQueryImageBehavior)
{
case kRespondWithUnknown:
Expand Down Expand Up @@ -242,8 +249,8 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
GetUpdateTokenString(ByteSpan(updateToken), strBuf, kUpdateTokenStrLen);
ChipLogDetail(SoftwareUpdate, "generated updateToken: %s", strBuf);

// TODO: This uses the current node as the provider to supply the OTA image. This can be configurable such that the provider
// supplying the response is not the provider supplying the OTA image.
// TODO: This uses the current node as the provider to supply the OTA image. This can be configurable such that the
// provider supplying the response is not the provider supplying the OTA image.
FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex();
FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex);
NodeId nodeId = fabricInfo->GetPeerId().GetNodeId();
Expand Down Expand Up @@ -288,6 +295,7 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
}

VerifyOrReturnError(commandObj->AddResponseData(commandPath, response) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);

return EMBER_ZCL_STATUS_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
} DeviceSoftwareVersionModel;
void SetOTACandidates(std::vector<OTAProviderExample::DeviceSoftwareVersionModel> candidates);
void SetQueryImageBehavior(QueryImageBehaviorType behavior) { mQueryImageBehavior = behavior; }
void SetIgnoreQueryImageCount(uint32_t count) { mIgnoreQueryImageCount = count; }
void SetApplyUpdateAction(chip::app::Clusters::OtaSoftwareUpdateProvider::OTAApplyUpdateAction action)
{
mUpdateAction = action;
Expand All @@ -86,6 +87,7 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate
static constexpr size_t kFilepathBufLen = 256;
char mOTAFilePath[kFilepathBufLen]; // null-terminated
QueryImageBehaviorType mQueryImageBehavior;
uint32_t mIgnoreQueryImageCount = 0;
chip::app::Clusters::OtaSoftwareUpdateProvider::OTAApplyUpdateAction mUpdateAction;
uint32_t mDelayedActionTimeSec;
bool SelectOTACandidate(const uint16_t requestorVendorID, const uint16_t requestorProductID,
Expand Down

0 comments on commit 2952813

Please sign in to comment.