Skip to content

Commit

Permalink
Ignore location param in QueryImage until Span is supported in ember (#…
Browse files Browse the repository at this point in the history
…9766)

* ignore location param until ember uses Span

* remove unused kLocationParamLength
  • Loading branch information
holbrookt authored Sep 17, 2021
1 parent f880d00 commit 3212882
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void OTAProviderExample::SetOTAFilePath(const char * path)

EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * commandObj, uint16_t vendorId, uint16_t productId,
uint16_t imageType, uint16_t hardwareVersion, uint32_t currentVersion,
uint8_t protocolsSupported, const chip::ByteSpan & location,
uint8_t protocolsSupported, const chip::Span<const char> & location,
bool clientCanConsent, const chip::ByteSpan & metadataForServer)
{
// TODO: add confiuration for returning BUSY status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OTAProviderExample : public OTAProviderDelegate
// Inherited from OTAProviderDelegate
EmberAfStatus HandleQueryImage(chip::app::CommandHandler * commandObj, uint16_t vendorId, uint16_t productId,
uint16_t imageType, uint16_t hardwareVersion, uint32_t currentVersion,
uint8_t protocolsSupported, const chip::ByteSpan & location, bool clientCanConsent,
uint8_t protocolsSupported, const chip::Span<const char> & location, bool clientCanConsent,
const chip::ByteSpan & metadataForServer) override;
EmberAfStatus HandleApplyUpdateRequest(chip::app::CommandHandler * commandObj, const chip::ByteSpan & updateToken,
uint32_t newVersion) override;
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-provider/ota-provider-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OTAProviderDelegate
// TODO(#8605): protocolsSupported should be list of OTADownloadProtocol enums, not uint8_t
virtual EmberAfStatus HandleQueryImage(CommandHandler * commandObj, uint16_t vendorId, uint16_t productId, uint16_t imageType,
uint16_t hardwareVersion, uint32_t currentVersion, uint8_t protocolsSupported,
const chip::ByteSpan & location, bool clientCanConsent,
const chip::Span<const char> & location, bool clientCanConsent,
const chip::ByteSpan & metadataForProvider) = 0;

virtual EmberAfStatus HandleApplyUpdateRequest(CommandHandler * commandObj, const chip::ByteSpan & updateToken,
Expand Down
17 changes: 6 additions & 11 deletions src/app/clusters/ota-provider/ota-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ using namespace chip;
using chip::app::clusters::OTAProviderDelegate;

namespace {
constexpr uint8_t kLocationParamLength = 2; // The expected length of the Location parameter in QueryImage
constexpr size_t kMaxMetadataLen = 512; // The maximum length of Metadata in any OTA Provider command
constexpr size_t kUpdateTokenParamLength = 32; // The expected length of the Update Token parameter used in multiple commands

Expand Down Expand Up @@ -167,21 +166,17 @@ bool emberAfOtaSoftwareUpdateProviderClusterQueryImageCallback(EndpointId endpoi

ChipLogDetail(Zcl, "OTA Provider received QueryImage");

// TODO: (#7112) change location size checking once CHAR_STRING is supported
const size_t locationLen = strlen(reinterpret_cast<char *>(location));
if (locationLen != kLocationParamLength)
{
ChipLogError(Zcl, "expected location length %" PRIu8 ", got %zu", kLocationParamLength, locationLen);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_ARGUMENT);
}
else if (metadataForProvider.size() > kMaxMetadataLen)
// TODO: (#7112) support location param and verify length once CHAR_STRING is supported
// Using location parameter is blocked by #5542 (use Span for string arguments). For now, there is no way to safely get the
// length of the location string because it is not guaranteed to be null-terminated.
Span<const char> locationSpan;

if (metadataForProvider.size() > kMaxMetadataLen)
{
ChipLogError(Zcl, "metadata size %zu exceeds max %zu", metadataForProvider.size(), kMaxMetadataLen);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_ARGUMENT);
}

ByteSpan locationSpan(location, locationLen);

status = delegate->HandleQueryImage(commandObj, vendorId, productId, imageType, hardwareVersion, currentVersion,
protocolsSupported, locationSpan, clientCanConsent, metadataForProvider);
if (status != EMBER_ZCL_STATUS_SUCCESS)
Expand Down

0 comments on commit 3212882

Please sign in to comment.