Skip to content

Commit

Permalink
[OTA] Add a command line option to disable sending of NotifyUpdateApp…
Browse files Browse the repository at this point in the history
…lied command (#24575)
  • Loading branch information
carol-apple authored and pull[bot] committed Oct 23, 2023
1 parent 9af70af commit 1078354
Show file tree
Hide file tree
Showing 5 changed files with 25 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 @@ -416,6 +416,7 @@ diffsyms
dimmable
dirname
dirs
disableNotifyUpdateApplied
disambiguated
discoverable
DispatchEvent
Expand Down
4 changes: 3 additions & 1 deletion examples/ota-requestor-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux out/debug

In addition to the general options available to all Linux applications, the
following command line options are available for the OTA Requestor application.
Note that these options are for testing purposes.

| Command Line Option | Description |
| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -a, --autoApplyImage | If supplied, apply the image immediately after download. Otherwise, the OTA update is complete after image download. |
| -c, --requestorCanConsent \<true \| false\> | Value for the RequestorCanConsent field in the QueryImage command. If not supplied, the value is determined by the driver. |
| -d, --disableNotifyUpdateApplied | If supplied, disable sending of the NotifyUpdateApplied command. Otherwise, after successfully loading into the updated image, send the NotifyUpdateApplied command. |
| -f, --otaDownloadPath \<file path\> | If supplied, the OTA image is downloaded to the given fully-qualified file-path. Otherwise, the default location for the downloaded image is at /tmp/test.bin |
| -p, --periodicQueryTimeout \<time in seconds\> | The periodic time interval to wait before attempting to query a provider from the default OTA provider list. If none or zero is supplied, the value is determined by the driver. |
| -u, --userConsentState \<granted \| denied \| deferred\> | Represents the current user consent status when the OTA Requestor is acting as a user consent delegate. This value is only applicable if value of the UserConsentNeeded field in the QueryImageResponse is set to true. This value is used for the first attempt to download. For all subsequent queries, the value of granted will be used.<li> granted: Authorize OTA requestor to download an OTA image <li> denied: Forbid OTA requestor to download an OTA image <li> deferred: Defer obtaining user consent |
Expand Down Expand Up @@ -246,7 +248,7 @@ out/chip-tool pairing onnetwork-long 0x1234567890 20202021 18
**Issue the AnnounceOTAProvider command**

```
out/chip-tool otasoftwareupdaterequestor announce-ota-provider 0xDEADBEEF 0 0 0 0x1234567890 0
out/chip-tool otasoftwareupdaterequestor announce-otaprovider 0xDEADBEEF 0 0 0 0x1234567890 0
```

The OTA Requestor application with node ID 0x1234567890 will process this
Expand Down
12 changes: 12 additions & 0 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,

constexpr uint16_t kOptionAutoApplyImage = 'a';
constexpr uint16_t kOptionRequestorCanConsent = 'c';
constexpr uint16_t kOptionDisableNotify = 'd';
constexpr uint16_t kOptionOtaDownloadPath = 'f';
constexpr uint16_t kOptionPeriodicQueryTimeout = 'p';
constexpr uint16_t kOptionUserConsentState = 'u';
Expand All @@ -81,17 +82,20 @@ uint32_t gWatchdogTimeoutSec = 0;
chip::Optional<bool> gRequestorCanConsent;
static char gOtaDownloadPath[kMaxFilePathSize] = "/tmp/test.bin";
bool gAutoApplyImage = false;
bool gSendNotifyUpdateApplied = true;

OptionDef cmdLineOptionsDef[] = {
{ "autoApplyImage", chip::ArgParser::kNoArgument, kOptionAutoApplyImage },
{ "requestorCanConsent", chip::ArgParser::kArgumentRequired, kOptionRequestorCanConsent },
{ "disableNotifyUpdateApplied", chip::ArgParser::kNoArgument, kOptionDisableNotify },
{ "otaDownloadPath", chip::ArgParser::kArgumentRequired, kOptionOtaDownloadPath },
{ "periodicQueryTimeout", chip::ArgParser::kArgumentRequired, kOptionPeriodicQueryTimeout },
{ "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
{ "watchdogTimeout", chip::ArgParser::kArgumentRequired, kOptionWatchdogTimeout },
{},
};

// Options for various test scenarios
OptionSet cmdLineOptions = {
HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS",
" -a, --autoApplyImage\n"
Expand All @@ -100,6 +104,9 @@ OptionSet cmdLineOptions = {
" -c, --requestorCanConsent <true | false>\n"
" Value for the RequestorCanConsent field in the QueryImage command.\n"
" If not supplied, the value is determined by the driver.\n"
" -d, --disableNotifyUpdateApplied\n"
" If supplied, disable sending of the NotifyUpdateApplied command.\n"
" Otherwise, after successfully loading into the updated image, send the NotifyUpdateApplied command.\n"
" -f, --otaDownloadPath <file path>\n"
" If supplied, the OTA image is downloaded to the given fully-qualified file-path.\n"
" Otherwise, the default location for the downloaded image is at /tmp/test.bin\n"
Expand Down Expand Up @@ -181,6 +188,7 @@ static void InitOTARequestor(void)

// Watchdog timeout can be set any time before a query image is sent
gRequestorUser.SetWatchdogTimeout(gWatchdogTimeoutSec);
gRequestorUser.SetSendNotifyUpdateApplied(gSendNotifyUpdateApplied);

gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
Expand Down Expand Up @@ -313,6 +321,10 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kOptionWatchdogTimeout:
gWatchdogTimeoutSec = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
break;
case kOptionDisableNotify:
// By default, NotifyUpdateApplied should always be sent. In the presence of this option, disable sending of the command.
gSendNotifyUpdateApplied = false;
break;
default:
ChipLogError(SoftwareUpdate, "%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
5 changes: 4 additions & 1 deletion src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ void DefaultOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImage
return;
}

mRequestor->NotifyUpdateApplied();
if (mSendNotifyUpdateApplied)
{
mRequestor->NotifyUpdateApplied();
}
});
}
else if ((mRequestor->GetCurrentUpdateState() != OTAUpdateStateEnum::kIdle))
Expand Down
5 changes: 5 additions & 0 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
}
}

// Specify whether to send notify update applied after successful update
void SetSendNotifyUpdateApplied(bool sendNotify) { mSendNotifyUpdateApplied = sendNotify; }

// Restart the periodic query timer
void RekickPeriodicQueryTimer(void);

Expand Down Expand Up @@ -116,6 +119,8 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
uint8_t mProviderRetryCount = 0;
// Track query image retry count on invalid session error
uint8_t mInvalidSessionRetryCount = 0;
// Track whether to send notify update applied after successful update
bool mSendNotifyUpdateApplied = true;
};

} // namespace DeviceLayer
Expand Down

0 comments on commit 1078354

Please sign in to comment.