Skip to content

Commit

Permalink
minimal_mdns: Fix filter for Compressed Fabric Id when browsing opera…
Browse files Browse the repository at this point in the history
…tional nodes (project-chip#35063)

* minimal_mdns: Fix filter for Compressed Fabric Id when browsing operational nodes

* Add check for subtype number
  • Loading branch information
wqx6 authored and PeterC1965 committed Aug 28, 2024
1 parent 2d25404 commit a49ce7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/lib/dnssd/Resolver_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions src/lib/shell/commands/Dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a49ce7a

Please sign in to comment.