diff --git a/scripts/tests/ota_test.sh b/scripts/tests/ota_test.sh index 96698b57937538..2838c106b7e11b 100755 --- a/scripts/tests/ota_test.sh +++ b/scripts/tests/ota_test.sh @@ -9,12 +9,18 @@ FIRMWARE_BIN="my-firmware.bin" FIRMWARE_OTA="my-firmware.ota" OTA_PROVIDER_APP="chip-ota-provider-app" +OTA_PROVIDER_FOLDER="out/ota_provider_debug" OTA_REQUESTOR_APP="chip-ota-requestor-app" +OTA_REQUESTOR_FOLDER="out/ota_requestor_debug" +CHIP_TOOL_APP="chip-tool" +CHIP_TOOL_FOLDER="out" killall -e "$OTA_PROVIDER_APP" "$OTA_REQUESTOR_APP" rm -f "$FIRMWARE_OTA" "$FIRMWARE_BIN" "$OTA_DOWNLOAD_PATH" -scripts/examples/gn_build_example.sh examples/chip-tool out/ +scripts/examples/gn_build_example.sh examples/chip-tool "$CHIP_TOOL_FOLDER" +scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux "$OTA_REQUESTOR_FOLDER" chip_config_network_layer_ble=false +scripts/examples/gn_build_example.sh examples/ota-provider-app/linux "$OTA_PROVIDER_FOLDER" chip_config_network_layer_ble=false echo "Test" >"$FIRMWARE_BIN" @@ -26,24 +32,24 @@ if [ ! -f "$FIRMWARE_OTA" ]; then exit 1 fi -./out/ota_provider_debug/"$OTA_PROVIDER_APP" -f "$FIRMWARE_OTA" | tee /tmp/ota/provider-log.txt & +./"$OTA_PROVIDER_FOLDER"/"$OTA_PROVIDER_APP" -f "$FIRMWARE_OTA" | tee /tmp/ota/provider-log.txt & echo "Commissioning Provider" -./out/chip-tool pairing onnetwork 1 "$PASSCODE" | tee /tmp/ota/chip-tool-commission-provider.txt +./"$CHIP_TOOL_FOLDER"/"$CHIP_TOOL_APP" pairing onnetwork 1 "$PASSCODE" | tee /tmp/ota/chip-tool-commission-provider.txt if grep "Device commissioning completed with success" /tmp/ota/chip-tool-commission-provider.txt; then echo Provider Commissioned else echo Provider not commissioned properly fi -./out/chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": null, "targets": null}]' 1 0 +./"$CHIP_TOOL_FOLDER"/"$CHIP_TOOL_APP" accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": null, "targets": null}]' 1 0 -stdbuf -o0 ./out/ota_requestor_debug/"$OTA_REQUESTOR_APP" --discriminator "$DISCRIMINATOR" --secured-device-port "$UDP_PORT" --KVS /tmp/chip_kvs_requestor --otaDownloadPath "$OTA_DOWNLOAD_PATH" | tee /tmp/ota/requestor-log.txt & +stdbuf -o0 ./"$OTA_REQUESTOR_FOLDER"/"$OTA_REQUESTOR_APP" --discriminator "$DISCRIMINATOR" --secured-device-port "$UDP_PORT" --KVS /tmp/chip_kvs_requestor --otaDownloadPath "$OTA_DOWNLOAD_PATH" | tee /tmp/ota/requestor-log.txt & echo "Commissioning Requestor" -./out/chip-tool pairing onnetwork-long 2 "$PASSCODE" "$DISCRIMINATOR" | tee /tmp/ota/chip-tool-commission-requestor.txt +./"$CHIP_TOOL_FOLDER"/"$CHIP_TOOL_APP" pairing onnetwork-long 2 "$PASSCODE" "$DISCRIMINATOR" | tee /tmp/ota/chip-tool-commission-requestor.txt if grep "Device commissioning completed with success" /tmp/ota/chip-tool-commission-requestor.txt; then echo Requestor Commissioned @@ -53,7 +59,7 @@ fi echo "Sending announce-ota-provider" -./out/chip-tool otasoftwareupdaterequestor announce-ota-provider 1 0 0 0 2 0 | tee /tmp/ota/chip-tool-announce-ota.txt +./"$CHIP_TOOL_FOLDER"/"$CHIP_TOOL_APP" otasoftwareupdaterequestor announce-ota-provider 1 0 0 0 2 0 | tee /tmp/ota/chip-tool-announce-ota.txt timeout 30 grep -q "OTA image downloaded to" <(tail -n0 -f /tmp/ota/requestor-log.txt) diff --git a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp index a3b152a992773a..cce1b2f7bbda10 100644 --- a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp @@ -68,9 +68,17 @@ void ExtendedOTARequestorDriver::PollUserConsentState() CHIP_ERROR ExtendedOTARequestorDriver::GetUserConsentSubject(chip::ota::UserConsentSubject & subject, const UpdateDescription & update) { - // mLastUsedProvider has the provider fabric index and endpoint id - subject.fabricIndex = mLastUsedProvider.fabricIndex; - subject.providerEndpointId = mLastUsedProvider.endpoint; + if (mLastUsedProvider.HasValue()) + { + // mLastUsedProvider has the provider fabric index and endpoint id + subject.fabricIndex = mLastUsedProvider.Value().fabricIndex; + subject.providerEndpointId = mLastUsedProvider.Value().endpoint; + } + else + { + ChipLogError(SoftwareUpdate, "mLastProvider is empty"); + return CHIP_ERROR_INTERNAL; + } // TODO: As we cannot use the src/app/Server.h in here so, figure out a way to get the node id. diff --git a/src/app/clusters/ota-requestor/GenericOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/GenericOTARequestorDriver.cpp index 09015ff34b2a35..df842d80ee4678 100644 --- a/src/app/clusters/ota-requestor/GenericOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/GenericOTARequestorDriver.cpp @@ -121,7 +121,8 @@ void GenericOTARequestorDriver::UpdateNotFound(UpdateNotFoundReason reason, Syst case UpdateNotFoundReason::NotAvailable: // IMPLEMENTATION CHOICE: // This implementation schedules a query only if a different provider is available - if ((DetermineProviderLocation(providerLocation) != true) || ProviderLocationsEqual(providerLocation, mLastUsedProvider)) + if ((DetermineProviderLocation(providerLocation) != true) || + (mLastUsedProvider.HasValue() && ProviderLocationsEqual(providerLocation, mLastUsedProvider.Value()))) { willTryAnotherQuery = false; } @@ -130,7 +131,7 @@ void GenericOTARequestorDriver::UpdateNotFound(UpdateNotFoundReason reason, Syst willTryAnotherQuery = true; } mRequestor->SetCurrentProviderLocation(providerLocation); - mLastUsedProvider = providerLocation; + mLastUsedProvider.SetValue(providerLocation); break; default: @@ -258,7 +259,7 @@ void GenericOTARequestorDriver::ProcessAnnounceOTAProviders( // Point the OTARequestor to the announced provider mRequestor->SetCurrentProviderLocation(providerLocation); - mLastUsedProvider = providerLocation; + mLastUsedProvider.SetValue(providerLocation); ScheduleDelayedAction(System::Clock::Seconds32(secToStart), StartDelayTimerHandler, this); } @@ -290,7 +291,7 @@ void GenericOTARequestorDriver::DefaultProviderTimerHandler(System::Layer * syst } mRequestor->SetCurrentProviderLocation(providerLocation); - mLastUsedProvider = providerLocation; + mLastUsedProvider.SetValue(providerLocation); SendQueryImage(); } @@ -320,17 +321,39 @@ void GenericOTARequestorDriver::StopDefaultProviderTimer() this); } -// Returns the next available Provider location +/** + * Returns the next available Provider location. The algorithm is to simply loop through the list of DefaultOtaProviders and return + * the next value (based on the last used provider). If no suitable candidate is found, FALSE is returned. + */ + bool GenericOTARequestorDriver::DetermineProviderLocation(ProviderLocation::Type & providerLocation) { + // Iterate through the default providers list and find the last used provider. If found, return the provider after it auto iterator = mRequestor->GetDefaultOTAProviderListIterator(); - while (iterator.Next()) + while (mLastUsedProvider.HasValue() && iterator.Next()) + { + if (ProviderLocationsEqual(iterator.GetValue(), mLastUsedProvider.Value())) + { + if (iterator.Next()) + { + providerLocation = iterator.GetValue(); + return true; + } + } + } + + // If no suitable candidate found, return the first element of the default providers list or an error + iterator = mRequestor->GetDefaultOTAProviderListIterator(); + if (iterator.Next()) { - // For now, just return the first one providerLocation = iterator.GetValue(); return true; } - + else + { + ChipLogError(SoftwareUpdate, "No suitable OTA Provider candidate found"); + return false; + } return false; } diff --git a/src/app/clusters/ota-requestor/GenericOTARequestorDriver.h b/src/app/clusters/ota-requestor/GenericOTARequestorDriver.h index 3bae012e9074f5..c4a65520504000 100644 --- a/src/app/clusters/ota-requestor/GenericOTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/GenericOTARequestorDriver.h @@ -87,7 +87,7 @@ class GenericOTARequestorDriver : public OTARequestorDriver uint32_t mPeriodicQueryTimeInterval = (24 * 60 * 60); // Timeout for querying providers on the default OTA provider list using ProviderLocationType = app::Clusters::OtaSoftwareUpdateRequestor::Structs::ProviderLocation::Type; - ProviderLocationType mLastUsedProvider; // Provider location used for the last query or update + Optional mLastUsedProvider; // Provider location used for the last query or update }; } // namespace DeviceLayer