diff --git a/examples/ota-provider-app/linux/main.cpp b/examples/ota-provider-app/linux/main.cpp index 2c8a2b26e09289..3fc2e425d8db82 100644 --- a/examples/ota-provider-app/linux/main.cpp +++ b/examples/ota-provider-app/linux/main.cpp @@ -57,6 +57,7 @@ constexpr uint16_t kOptionUserConsentState = 'u'; constexpr uint16_t kOptionDelayedActionTimeSec = 't'; constexpr uint16_t kOptionDiscriminator = 'd'; constexpr uint16_t kOptionSoftwareVersion = 's'; +constexpr uint16_t kOptionSoftwareVersionStr = 'S'; constexpr uint16_t kOptionUserConsentNeeded = 'c'; static constexpr uint16_t kMaximumDiscriminatorValue = 0xFFF; @@ -70,6 +71,7 @@ static chip::ota::UserConsentState gUserConsentState = chip::ot static bool gUserConsentNeeded = false; static chip::Optional gSetupDiscriminator; static chip::Optional gSoftwareVersion; +static const char * gSoftwareVersionString = nullptr; // Parses the JSON filepath and extracts DeviceSoftwareVersionModel parameters static bool ParseJsonFileAndPopulateCandidates(const char * filepath, @@ -233,6 +235,22 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, case kOptionUserConsentNeeded: gUserConsentNeeded = true; break; + case kOptionSoftwareVersionStr: + if (aValue == NULL) + { + PrintArgError("%s: ERROR: NULL SoftwareVersionStr parameter\n", aProgram); + retval = false; + } + else if ((strlen(aValue) < 1 || strlen(aValue) > 64)) + { + PrintArgError("%s: ERROR: SoftwareVersionStr parameter length is out of range \n", aProgram); + retval = false; + } + else + { + gSoftwareVersionString = aValue; + } + break; default: PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName); retval = false; @@ -250,6 +268,7 @@ OptionDef cmdLineOptionsDef[] = { { "UserConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState }, { "discriminator", chip::ArgParser::kArgumentRequired, kOptionDiscriminator }, { "softwareVersion", chip::ArgParser::kArgumentRequired, kOptionSoftwareVersion }, + { "softwareVersionStr", chip::ArgParser::kArgumentRequired, kOptionSoftwareVersionStr }, { "UserConsentNeeded", chip::ArgParser::kNoArgument, kOptionUserConsentNeeded }, {}, }; @@ -277,6 +296,11 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " If ota image list is present along with this option\n" " then value from ota image list is used.\n" " Otherwise, this value will be used is then value from that will be used\n" + " -S/--softwareVersionStr \n" + " Value of SoftwareVersionString in the Query Image Response\n" + " If ota image list is present along with this option\n" + " then value from ota image list is used.\n" + " Otherwise, this value will be used is then value from that will be used\n" " -c/--UserConsentNeeded\n" " If provided, value of UserConsentNeeded in the Query Image Response is set to true\n" }; @@ -349,6 +373,10 @@ int main(int argc, char * argv[]) { otaProvider.SetSoftwareVersion(gSoftwareVersion.Value()); } + if (gSoftwareVersionString) + { + otaProvider.SetSoftwareVersionString(gSoftwareVersionString); + } if (gUserConsentState != chip::ota::UserConsentState::kUnknown) { diff --git a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp index 3b3de5fea0b9c2..5044a6624f653d 100644 --- a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp +++ b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp @@ -180,9 +180,16 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c newSoftwareVersion = mSoftwareVersion.Value(); } + // If software version string is provided using command line then use it. + // Otherwise, use default string. newSoftwareVersionString = "Example-Image-V0.1"; - otaFilePath = mOTAFilePath; - queryStatus = OTAQueryStatus::kUpdateAvailable; + if (mSoftwareVersionString) + { + newSoftwareVersionString = mSoftwareVersionString; + } + + otaFilePath = mOTAFilePath; + queryStatus = OTAQueryStatus::kUpdateAvailable; } else if (!mCandidates.empty()) // If list of OTA candidates is supplied instead { diff --git a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h index 0b6efc6b12ee03..a2db9297adebc4 100644 --- a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h +++ b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h @@ -72,6 +72,7 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate void SetDelayedActionTimeSec(uint32_t time) { mDelayedActionTimeSec = time; } void SetUserConsentDelegate(chip::ota::UserConsentDelegate * delegate) { mUserConsentDelegate = delegate; } void SetSoftwareVersion(uint32_t softwareVersion) { mSoftwareVersion.SetValue(softwareVersion); } + void SetSoftwareVersionString(const char * versionString) { mSoftwareVersionString = versionString; } void SetUserConsentNeeded(bool needed) { mUserConsentNeeded = needed; } private: @@ -91,5 +92,6 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::DecodableType & commandData, uint32_t targetVersion); chip::Optional mSoftwareVersion; - bool mUserConsentNeeded = false; + const char * mSoftwareVersionString = nullptr; + bool mUserConsentNeeded = false; };