From a49ce7a714ed9a12cc62949f6e7b021104c5624a Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:39:40 +0800 Subject: [PATCH] minimal_mdns: Fix filter for Compressed Fabric Id when browsing operational nodes (#35063) * minimal_mdns: Fix filter for Compressed Fabric Id when browsing operational nodes * Add check for subtype number --- src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 12 +++++++++++- src/lib/shell/commands/Dns.cpp | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 8b2b30e3184291..8e913f2addb1c1 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -544,7 +544,17 @@ CHIP_ERROR MinMdnsResolver::BuildQuery(QueryBuilder & builder, const ActiveResol switch (data.type) { case DiscoveryType::kOperational: - qname = CheckAndAllocateQName(kOperationalServiceName, kOperationalProtocol, kLocalDomain); + if (data.filter.type == DiscoveryFilterType::kCompressedFabricId) + { + char subtypeStr[Common::kSubTypeMaxLength + 1]; + ReturnErrorOnFailure(MakeServiceSubtype(subtypeStr, sizeof(subtypeStr), data.filter)); + qname = CheckAndAllocateQName(subtypeStr, kSubtypeServiceNamePart, kOperationalServiceName, kOperationalProtocol, + kLocalDomain); + } + else + { + qname = CheckAndAllocateQName(kOperationalServiceName, kOperationalProtocol, kLocalDomain); + } break; case DiscoveryType::kCommissionableNode: if (data.filter.type == DiscoveryFilterType::kNone) diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 18e0841dccce83..917f94f849d865 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -214,13 +214,23 @@ bool ParseSubType(int argc, char ** argv, Dnssd::DiscoveryFilter & filter) case 'C': filterType = Dnssd::DiscoveryFilterType::kCommissioningMode; break; + case 'I': + filterType = Dnssd::DiscoveryFilterType::kCompressedFabricId; + break; default: return false; } - uint16_t code; - VerifyOrReturnError(ArgParser::ParseInt(subtype + 2, code), false); - + uint64_t code = 0; + if (filterType == Dnssd::DiscoveryFilterType::kCompressedFabricId) + { + VerifyOrReturnError(ArgParser::ParseInt(subtype + 2, code, 16), false); + VerifyOrReturnValue(code != 0, false); + } + else + { + VerifyOrReturnError(ArgParser::ParseInt(subtype + 2, code), false); + } filter = Dnssd::DiscoveryFilter(filterType, code); return true; }