Skip to content

Commit 1dc089c

Browse files
wqx6bzbarsky-apple
andauthored
[v1.3 cherry-pick] cherrypick #32747 and #33206 (#33438)
* esp32: service type should be case-insensitive for endpoint filter of mdns packets (#33206) * Add checks for localization-configuration cluster and time-format-localization cluster init callback (#32747) * Add checks for localization-configuration cluster and time-format-localization cluster * Update src/app/clusters/time-format-localization-server/time-format-localization-server.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent c76613c commit 1dc089c

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

src/app/clusters/localization-configuration-server/localization-configuration-server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void emberAfLocalizationConfigurationClusterServerInitCallback(EndpointId endpoi
208208

209209
it->Release();
210210

211-
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
211+
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND && validLocaleCached)
212212
{
213213
// If initial value is not one of the allowed values, write the valid value it.
214214
status = ActiveLocale::Set(endpoint, validLocale);

src/app/clusters/time-format-localization-server/time-format-localization-server.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class AutoReleaseIterator
7878

7979
TimeFormatLocalizationAttrAccess gAttrAccess;
8080

81+
bool HasFeature(EndpointId endpoint, Feature feature)
82+
{
83+
uint32_t featureMap;
84+
return FeatureMap::Get(endpoint, &featureMap) == Status::Success ? (featureMap & to_underlying(feature)) : false;
85+
}
86+
8187
CHIP_ERROR TimeFormatLocalizationAttrAccess::ReadSupportedCalendarTypes(AttributeValueEncoder & aEncoder)
8288
{
8389
DeviceLayer::DeviceInfoProvider * provider = DeviceLayer::GetDeviceInfoProvider();
@@ -202,6 +208,10 @@ Protocols::InteractionModel::Status MatterTimeFormatLocalizationClusterServerPre
202208

203209
void emberAfTimeFormatLocalizationClusterServerInitCallback(EndpointId endpoint)
204210
{
211+
if (!HasFeature(endpoint, Feature::kCalendarFormat))
212+
{
213+
return;
214+
}
205215
CalendarTypeEnum calendarType;
206216
CalendarTypeEnum validType;
207217
Status status = ActiveCalendarType::Get(endpoint, &calendarType);

src/platform/ESP32/ESP32EndpointQueueFilter.h

+18-17
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
4444
}
4545
// Drop the mDNS packets which don't contain 'matter' or '<device-hostname>'.
4646
const uint8_t matterBytes[] = { 'm', 'a', 't', 't', 'e', 'r' };
47-
if (PayloadContains(pktPayload, ByteSpan(matterBytes)) || PayloadContainsHostNameCaseInsensitive(pktPayload))
47+
if (PayloadContainsCaseInsensitive(pktPayload, ByteSpan(matterBytes)) ||
48+
PayloadContainsCaseInsensitive(pktPayload, ByteSpan(mHostNameBuffer)))
4849
{
4950
return FilterOutcome::kAllowPacket;
5051
}
@@ -79,34 +80,34 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
7980
return false;
8081
}
8182

82-
static bool PayloadContains(const chip::System::PacketBufferHandle & payload, const chip::ByteSpan & byteSpan)
83+
static bool BytesCaseInsensitiveCompare(const uint8_t * buf1, const uint8_t * buf2, size_t size)
8384
{
84-
if (payload->HasChainedBuffer() || payload->TotalLength() < byteSpan.size())
85-
{
86-
return false;
87-
}
88-
for (size_t i = 0; i <= payload->TotalLength() - byteSpan.size(); ++i)
85+
for (size_t i = 0; i < size; ++i)
8986
{
90-
if (memcmp(payload->Start() + i, byteSpan.data(), byteSpan.size()) == 0)
87+
uint8_t byte1 = (buf1[i] >= 'A' && buf1[i] <= 'Z') ? buf1[i] - 'A' + 'a' : buf1[i];
88+
uint8_t byte2 = (buf2[i] >= 'A' && buf2[i] <= 'Z') ? buf2[i] - 'A' + 'a' : buf2[i];
89+
if (byte1 != byte2)
9190
{
92-
return true;
91+
return false;
9392
}
9493
}
95-
return false;
94+
return true;
9695
}
9796

98-
bool PayloadContainsHostNameCaseInsensitive(const chip::System::PacketBufferHandle & payload)
97+
static bool PayloadContainsCaseInsensitive(const chip::System::PacketBufferHandle & payload, const chip::ByteSpan & byteSpan)
9998
{
100-
uint8_t hostNameLowerCase[12];
101-
memcpy(hostNameLowerCase, mHostNameBuffer, sizeof(mHostNameBuffer));
102-
for (size_t i = 0; i < sizeof(hostNameLowerCase); ++i)
99+
if (payload->HasChainedBuffer() || payload->TotalLength() < byteSpan.size())
100+
{
101+
return false;
102+
}
103+
for (size_t i = 0; i <= payload->TotalLength() - byteSpan.size(); ++i)
103104
{
104-
if (hostNameLowerCase[i] <= 'F' && hostNameLowerCase[i] >= 'A')
105+
if (BytesCaseInsensitiveCompare(payload->Start() + i, byteSpan.data(), byteSpan.size()))
105106
{
106-
hostNameLowerCase[i] = static_cast<uint8_t>('a' + hostNameLowerCase[i] - 'A');
107+
return true;
107108
}
108109
}
109-
return PayloadContains(payload, ByteSpan(mHostNameBuffer)) || PayloadContains(payload, ByteSpan(hostNameLowerCase));
110+
return false;
110111
}
111112

112113
static bool IsValidMdnsHostName(const chip::CharSpan & hostName)

0 commit comments

Comments
 (0)