Skip to content

Commit 9924308

Browse files
authored
[OTA] Allow explicit values to be set for RequestorCanConsent (project-chip#17021)
1 parent 976d7c7 commit 9924308

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

examples/ota-requestor-app/linux/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux out/debug
1717
In addition to the general options available to all Linux applications, the
1818
following command line options are available for the OTA Requestor application.
1919

20-
| Command Line Option | Description |
21-
| -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22-
| -a, --autoApplyImage | If supplied, apply the image immediately after download. Otherwise, the OTA update is complete after image download. |
23-
| -c, --requestorCanConsent | If supplied, the RequestorCanConsent field of the QueryImage command is set to true. Otherwise, the value is determined by the driver. |
24-
| -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 |
25-
| -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. |
26-
| -u, --userConsentState \<granted \| denied \| deferred\> | The user consent state for the first QueryImage command. For all subsequent commands, 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 |
27-
| -w, --watchdogTimeout \<time in seconds\> | Maximum amount of time allowed for an OTA download before the process is cancelled and state reset to idle. If none or zero is supplied, the value is determined by the driver. |
20+
| Command Line Option | Description |
21+
| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22+
| -a, --autoApplyImage | If supplied, apply the image immediately after download. Otherwise, the OTA update is complete after image download. |
23+
| -c, --requestorCanConsent \<true \| false\> | Value for the RequestorCanConsent field in the QueryImage command. If not supplied, the value is determined by the driver. |
24+
| -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 |
25+
| -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. |
26+
| -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 |
27+
| -w, --watchdogTimeout \<time in seconds\> | Maximum amount of time allowed for an OTA download before the process is cancelled and state reset to idle. If none or zero is supplied, the value is determined by the driver. |
2828

2929
## Software Image Version
3030

examples/ota-requestor-app/linux/main.cpp

+25-17
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool gAutoApplyImage = false;
8080

8181
OptionDef cmdLineOptionsDef[] = {
8282
{ "autoApplyImage", chip::ArgParser::kNoArgument, kOptionAutoApplyImage },
83-
{ "requestorCanConsent", chip::ArgParser::kNoArgument, kOptionRequestorCanConsent },
83+
{ "requestorCanConsent", chip::ArgParser::kArgumentRequired, kOptionRequestorCanConsent },
8484
{ "otaDownloadPath", chip::ArgParser::kArgumentRequired, kOptionOtaDownloadPath },
8585
{ "periodicQueryTimeout", chip::ArgParser::kArgumentRequired, kOptionPeriodicQueryTimeout },
8686
{ "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState },
@@ -93,22 +93,23 @@ OptionSet cmdLineOptions = {
9393
" -a, --autoApplyImage\n"
9494
" If supplied, apply the image immediately after download.\n"
9595
" Otherwise, the OTA update is complete after image download.\n"
96-
" -c, --requestorCanConsent\n"
97-
" If supplied, the RequestorCanConsent field of the QueryImage command is set to "
98-
"true.\n"
99-
" Otherwise, the value is determined by the driver.\n"
96+
" -c, --requestorCanConsent <true | false>\n"
97+
" Value for the RequestorCanConsent field in the QueryImage command.\n"
98+
" If not supplied, the value is determined by the driver.\n"
10099
" -f, --otaDownloadPath <file path>\n"
101100
" If supplied, the OTA image is downloaded to the given fully-qualified file-path.\n"
102101
" Otherwise, the default location for the downloaded image is at /tmp/test.bin\n"
103102
" -p, --periodicQueryTimeout <time in seconds>\n"
104103
" The periodic time interval to wait before attempting to query a provider from the default OTA provider list.\n"
105104
" If none or zero is supplied, the timeout is determined by the driver.\n"
106105
" -u, --userConsentState <granted | denied | deferred>\n"
107-
" The user consent state for the first QueryImage command. For all\n"
108-
" subsequent commands, the value of granted will be used.\n"
106+
" Represents the current user consent status when the OTA Requestor is acting as a user consent\n"
107+
" delegate. This value is only applicable if value of the UserConsentNeeded field in the\n"
108+
" QueryImageResponse is set to true. This value is used for the first attempt to\n"
109+
" download. For all subsequent queries, the value of granted will be used.\n"
109110
" granted: Authorize OTA requestor to download an OTA image\n"
110111
" denied: Forbid OTA requestor to download an OTA image\n"
111-
" deferred: Defer obtaining user consent \n"
112+
" deferred: Defer obtaining user consent\n"
112113
" -w, --watchdogTimeout <time in seconds>\n"
113114
" Maximum amount of time allowed for an OTA download before the process is cancelled and state reset to idle.\n"
114115
" If none or zero is supplied, the timeout is determined by the driver.\n"
@@ -173,18 +174,25 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
173174
gPeriodicQueryTimeoutSec = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
174175
break;
175176
case kOptionRequestorCanConsent:
176-
gRequestorCanConsent.SetValue(true);
177+
if (strcmp(aValue, "true") == 0)
178+
{
179+
gRequestorCanConsent.SetValue(true);
180+
}
181+
else if (strcmp(aValue, "false") == 0)
182+
{
183+
gRequestorCanConsent.SetValue(false);
184+
}
185+
else
186+
{
187+
ChipLogError(SoftwareUpdate, "%s: ERROR: Invalid requestorCanConsent parameter: %s\n", aProgram, aValue);
188+
retval = false;
189+
}
177190
break;
178191
case kOptionOtaDownloadPath:
179192
chip::Platform::CopyString(gOtaDownloadPath, aValue);
180193
break;
181194
case kOptionUserConsentState:
182-
if (aValue == NULL)
183-
{
184-
PrintArgError("%s: ERROR: NULL UserConsent parameter\n", aProgram);
185-
retval = false;
186-
}
187-
else if (strcmp(aValue, "granted") == 0)
195+
if (strcmp(aValue, "granted") == 0)
188196
{
189197
gUserConsentState = chip::ota::UserConsentState::kGranted;
190198
}
@@ -198,7 +206,7 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
198206
}
199207
else
200208
{
201-
PrintArgError("%s: ERROR: Invalid UserConsent parameter: %s\n", aProgram, aValue);
209+
ChipLogError(SoftwareUpdate, "%s: ERROR: Invalid UserConsent parameter: %s\n", aProgram, aValue);
202210
retval = false;
203211
}
204212
break;
@@ -209,7 +217,7 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
209217
gWatchdogTimeoutSec = static_cast<uint32_t>(strtoul(aValue, NULL, 0));
210218
break;
211219
default:
212-
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
220+
ChipLogError(SoftwareUpdate, "%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
213221
retval = false;
214222
break;
215223
}

src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ bool ExtendedOTARequestorDriver::CanConsent()
3232
{
3333
bool localConfigDisabled = false;
3434
VerifyOrdo(DeviceLayer::ConfigurationMgr().GetLocalConfigDisabled(localConfigDisabled) == CHIP_NO_ERROR,
35-
ChipLogProgress(SoftwareUpdate, "Failed to get local config disabled, using as false"));
35+
ChipLogProgress(SoftwareUpdate, "Failed to get local config disabled, assuming not disabled"));
3636

37-
// If local config is disabled, we can't consent.
37+
// User consent delegation SHALL NOT be used if a Node is configured with the LocalConfigDisabled attribute set to True
3838
return localConfigDisabled == false;
3939
}
4040

0 commit comments

Comments
 (0)