Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a simple DetermineProviderLocation #15979

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions scripts/tests/ota_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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)

Expand Down
14 changes: 11 additions & 3 deletions src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
39 changes: 31 additions & 8 deletions src/app/clusters/ota-requestor/GenericOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -130,7 +131,7 @@ void GenericOTARequestorDriver::UpdateNotFound(UpdateNotFoundReason reason, Syst
willTryAnotherQuery = true;
}
mRequestor->SetCurrentProviderLocation(providerLocation);
mLastUsedProvider = providerLocation;
mLastUsedProvider.SetValue(providerLocation);
break;

default:
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -290,7 +291,7 @@ void GenericOTARequestorDriver::DefaultProviderTimerHandler(System::Layer * syst
}

mRequestor->SetCurrentProviderLocation(providerLocation);
mLastUsedProvider = providerLocation;
mLastUsedProvider.SetValue(providerLocation);

SendQueryImage();
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/GenericOTARequestorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProviderLocationType> mLastUsedProvider; // Provider location used for the last query or update
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace DeviceLayer
Expand Down