Skip to content

Commit

Permalink
Stop using the immediate default response bits in OTA provider. (#15885)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 11, 2023
1 parent 588a1c7 commit 4195969
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/app/clusters/ota-provider/ota-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/util/af.h>
#include <app/util/error-mapping.h>
#include <platform/CHIPDeviceConfig.h>
#include <protocols/interaction_model/Constants.h>

#include <lib/support/Span.h>

Expand All @@ -32,6 +34,7 @@ using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider;
using chip::app::Clusters::OTAProviderDelegate;
using Protocols::InteractionModel::Status;

// EMBER_AF_OTA_PROVIDER_CLUSTER_SERVER_ENDPOINT_COUNT is only defined if the
// cluster is actually enabled in the ZAP config. To allow operation in setups
Expand All @@ -58,12 +61,12 @@ OTAProviderDelegate * GetDelegate(EndpointId endpoint)
return (ep == 0xFFFF ? NULL : gDelegateTable[ep]);
}

bool SendStatusIfDelegateNull(EndpointId endpoint)
bool SendStatusIfDelegateNull(app::CommandHandler * commandObj, const app::ConcreteCommandPath & path)
{
if (GetDelegate(endpoint) == nullptr)
if (GetDelegate(path.mEndpointId) == nullptr)
{
ChipLogError(Zcl, "No OTAProviderDelegate set for ep:%" PRIu16, endpoint);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND);
ChipLogError(Zcl, "No OTAProviderDelegate set for ep:%" PRIu16, path.mEndpointId);
commandObj->AddStatus(path, Status::UnsupportedCommand);
return true;
}
return false;
Expand All @@ -90,22 +93,22 @@ bool emberAfOtaSoftwareUpdateProviderClusterApplyUpdateRequestCallback(
ChipLogDetail(Zcl, " Update Token: %zu", commandData.updateToken.size());
ChipLogDetail(Zcl, " New Version: %" PRIu32, commandData.newVersion);

if (SendStatusIfDelegateNull(endpoint))
if (SendStatusIfDelegateNull(commandObj, commandPath))
{
return true;
}

if (updateToken.size() > kUpdateTokenMaxLength || updateToken.size() < kUpdateTokenMinLength)
{
ChipLogError(Zcl, "expected size %zu for UpdateToken, got %zu", kUpdateTokenMaxLength, updateToken.size());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}

status = delegate->HandleApplyUpdateRequest(commandObj, commandPath, commandData);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfSendImmediateDefaultResponse(status);
commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status));
}

return true;
Expand All @@ -129,22 +132,22 @@ bool emberAfOtaSoftwareUpdateProviderClusterNotifyUpdateAppliedCallback(
ChipLogDetail(Zcl, " Update Token: %zu", commandData.updateToken.size());
ChipLogDetail(Zcl, " Software Version: %" PRIu32, commandData.softwareVersion);

if (SendStatusIfDelegateNull(endpoint))
if (SendStatusIfDelegateNull(commandObj, commandPath))
{
return true;
}

if (updateToken.size() > kUpdateTokenMaxLength || updateToken.size() < kUpdateTokenMinLength)
{
ChipLogError(Zcl, "expected size %zu for UpdateToken, got %zu", kUpdateTokenMaxLength, updateToken.size());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}

status = delegate->HandleNotifyUpdateApplied(commandObj, commandPath, commandData);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfSendImmediateDefaultResponse(status);
commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status));
}

return true;
Expand Down Expand Up @@ -175,7 +178,7 @@ bool emberAfOtaSoftwareUpdateProviderClusterQueryImageCallback(app::CommandHandl
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
OTAProviderDelegate * delegate = GetDelegate(endpoint);

if (SendStatusIfDelegateNull(endpoint))
if (SendStatusIfDelegateNull(commandObj, commandPath))
{
return true;
};
Expand Down Expand Up @@ -211,21 +214,21 @@ bool emberAfOtaSoftwareUpdateProviderClusterQueryImageCallback(app::CommandHandl
if (location.HasValue() && location.Value().size() != kLocationLen)
{
ChipLogError(Zcl, "location param length %zu != expected length %zu", location.Value().size(), kLocationLen);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}

if (metadataForProvider.HasValue() && metadataForProvider.Value().size() > kMaxMetadataLen)
{
ChipLogError(Zcl, "metadata size %zu exceeds max %zu", metadataForProvider.Value().size(), kMaxMetadataLen);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}

status = delegate->HandleQueryImage(commandObj, commandPath, commandData);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfSendImmediateDefaultResponse(status);
commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status));
}

return true;
Expand Down

0 comments on commit 4195969

Please sign in to comment.