diff --git a/src/app/clusters/ota-provider/ota-provider.cpp b/src/app/clusters/ota-provider/ota-provider.cpp index bfe5430e06a77e..fafe93269e5b3d 100644 --- a/src/app/clusters/ota-provider/ota-provider.cpp +++ b/src/app/clusters/ota-provider/ota-provider.cpp @@ -21,7 +21,9 @@ #include #include #include +#include #include +#include #include @@ -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 @@ -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; @@ -90,7 +93,7 @@ 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; } @@ -98,14 +101,14 @@ bool emberAfOtaSoftwareUpdateProviderClusterApplyUpdateRequestCallback( 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; @@ -129,7 +132,7 @@ 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; } @@ -137,14 +140,14 @@ bool emberAfOtaSoftwareUpdateProviderClusterNotifyUpdateAppliedCallback( 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; @@ -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; }; @@ -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;