@@ -44,7 +44,8 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
44
44
}
45
45
// Drop the mDNS packets which don't contain 'matter' or '<device-hostname>'.
46
46
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 )))
48
49
{
49
50
return FilterOutcome::kAllowPacket ;
50
51
}
@@ -79,34 +80,34 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
79
80
return false ;
80
81
}
81
82
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 )
83
84
{
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)
89
86
{
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)
91
90
{
92
- return true ;
91
+ return false ;
93
92
}
94
93
}
95
- return false ;
94
+ return true ;
96
95
}
97
96
98
- bool PayloadContainsHostNameCaseInsensitive (const chip::System::PacketBufferHandle & payload)
97
+ static bool PayloadContainsCaseInsensitive (const chip::System::PacketBufferHandle & payload, const chip::ByteSpan & byteSpan )
99
98
{
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)
103
104
{
104
- if (hostNameLowerCase[i] <= ' F ' && hostNameLowerCase[i] >= ' A ' )
105
+ if (BytesCaseInsensitiveCompare (payload-> Start () + i, byteSpan. data (), byteSpan. size ()) )
105
106
{
106
- hostNameLowerCase[i] = static_cast < uint8_t >( ' a ' + hostNameLowerCase[i] - ' A ' ) ;
107
+ return true ;
107
108
}
108
109
}
109
- return PayloadContains (payload, ByteSpan ( mHostNameBuffer )) || PayloadContains (payload, ByteSpan (hostNameLowerCase)) ;
110
+ return false ;
110
111
}
111
112
112
113
static bool IsValidMdnsHostName (const chip::CharSpan & hostName)
0 commit comments