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

[v1.3 cherry-pick] cherrypick #32747 and #33206 #33438

Merged
merged 2 commits into from
May 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void emberAfLocalizationConfigurationClusterServerInitCallback(EndpointId endpoi

it->Release();

if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND && validLocaleCached)
{
// If initial value is not one of the allowed values, write the valid value it.
status = ActiveLocale::Set(endpoint, validLocale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class AutoReleaseIterator

TimeFormatLocalizationAttrAccess gAttrAccess;

bool HasFeature(EndpointId endpoint, Feature feature)
{
uint32_t featureMap;
return FeatureMap::Get(endpoint, &featureMap) == Status::Success ? (featureMap & to_underlying(feature)) : false;
}

CHIP_ERROR TimeFormatLocalizationAttrAccess::ReadSupportedCalendarTypes(AttributeValueEncoder & aEncoder)
{
DeviceLayer::DeviceInfoProvider * provider = DeviceLayer::GetDeviceInfoProvider();
Expand Down Expand Up @@ -202,6 +208,10 @@ Protocols::InteractionModel::Status MatterTimeFormatLocalizationClusterServerPre

void emberAfTimeFormatLocalizationClusterServerInitCallback(EndpointId endpoint)
{
if (!HasFeature(endpoint, Feature::kCalendarFormat))
{
return;
}
CalendarTypeEnum calendarType;
CalendarTypeEnum validType;
Status status = ActiveCalendarType::Get(endpoint, &calendarType);
Expand Down
35 changes: 18 additions & 17 deletions src/platform/ESP32/ESP32EndpointQueueFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
}
// Drop the mDNS packets which don't contain 'matter' or '<device-hostname>'.
const uint8_t matterBytes[] = { 'm', 'a', 't', 't', 'e', 'r' };
if (PayloadContains(pktPayload, ByteSpan(matterBytes)) || PayloadContainsHostNameCaseInsensitive(pktPayload))
if (PayloadContainsCaseInsensitive(pktPayload, ByteSpan(matterBytes)) ||
PayloadContainsCaseInsensitive(pktPayload, ByteSpan(mHostNameBuffer)))
{
return FilterOutcome::kAllowPacket;
}
Expand Down Expand Up @@ -79,34 +80,34 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
return false;
}

static bool PayloadContains(const chip::System::PacketBufferHandle & payload, const chip::ByteSpan & byteSpan)
static bool BytesCaseInsensitiveCompare(const uint8_t * buf1, const uint8_t * buf2, size_t size)
{
if (payload->HasChainedBuffer() || payload->TotalLength() < byteSpan.size())
{
return false;
}
for (size_t i = 0; i <= payload->TotalLength() - byteSpan.size(); ++i)
for (size_t i = 0; i < size; ++i)
{
if (memcmp(payload->Start() + i, byteSpan.data(), byteSpan.size()) == 0)
uint8_t byte1 = (buf1[i] >= 'A' && buf1[i] <= 'Z') ? buf1[i] - 'A' + 'a' : buf1[i];
uint8_t byte2 = (buf2[i] >= 'A' && buf2[i] <= 'Z') ? buf2[i] - 'A' + 'a' : buf2[i];
if (byte1 != byte2)
{
return true;
return false;
}
}
return false;
return true;
}

bool PayloadContainsHostNameCaseInsensitive(const chip::System::PacketBufferHandle & payload)
static bool PayloadContainsCaseInsensitive(const chip::System::PacketBufferHandle & payload, const chip::ByteSpan & byteSpan)
{
uint8_t hostNameLowerCase[12];
memcpy(hostNameLowerCase, mHostNameBuffer, sizeof(mHostNameBuffer));
for (size_t i = 0; i < sizeof(hostNameLowerCase); ++i)
if (payload->HasChainedBuffer() || payload->TotalLength() < byteSpan.size())
{
return false;
}
for (size_t i = 0; i <= payload->TotalLength() - byteSpan.size(); ++i)
{
if (hostNameLowerCase[i] <= 'F' && hostNameLowerCase[i] >= 'A')
if (BytesCaseInsensitiveCompare(payload->Start() + i, byteSpan.data(), byteSpan.size()))
{
hostNameLowerCase[i] = static_cast<uint8_t>('a' + hostNameLowerCase[i] - 'A');
return true;
}
}
return PayloadContains(payload, ByteSpan(mHostNameBuffer)) || PayloadContains(payload, ByteSpan(hostNameLowerCase));
return false;
}

static bool IsValidMdnsHostName(const chip::CharSpan & hostName)
Expand Down
Loading