Skip to content

Commit

Permalink
dns-sd: S sub 4-bit number. (#8887)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille authored and pull[bot] committed Aug 17, 2021
1 parent c71469f commit 2790867
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/mdns/ServiceNaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter s
switch (subtype.type)
{
case DiscoveryFilterType::kShort:
// 8-bit number
if (subtype.code >= 1 << 8)
// 4-bit number
if (subtype.code >= 1 << 4)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mdns/minimal/tests/TestAdvertiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TxtResourceRecord txtOperational2 = TxtResourceRecord(kInstanceName2, kTxt
// Commissionable node records and queries.
const QNamePart kMatterCommissionableNodeQueryParts[3] = { "_matterc", "_udp", "local" };
const QNamePart kLongSubPartsFullLen[] = { "_L4094", "_sub", "_matterc", "_udp", "local" };
const QNamePart kShortSubPartsFullLen[] = { "_S254", "_sub", "_matterc", "_udp", "local" };
const QNamePart kShortSubPartsFullLen[] = { "_S15", "_sub", "_matterc", "_udp", "local" };
const QNamePart kCmSubParts0[] = { "_C0", "_sub", "_matterc", "_udp", "local" };
const QNamePart kLongSubParts[] = { "_L22", "_sub", "_matterc", "_udp", "local" };
const QNamePart kShortSubParts[] = { "_S2", "_sub", "_matterc", "_udp", "local" };
Expand Down Expand Up @@ -129,7 +129,7 @@ CommissionAdvertisingParameters commissionableNodeParamsSmall =
.SetCommissionAdvertiseMode(CommssionAdvertiseMode::kCommissionableNode)
.SetMac(ByteSpan(kMac))
.SetLongDiscriminator(0xFFE)
.SetShortDiscriminator(0xFE)
.SetShortDiscriminator(0xF)
.SetCommissioningMode(false, false);
const QNamePart txtCommissionableNodeParamsSmallParts[] = { "CM=0", "D=4094" };
FullQName txtCommissionableNodeParamsSmallName = FullQName(txtCommissionableNodeParamsSmallParts);
Expand Down
13 changes: 6 additions & 7 deletions src/lib/mdns/tests/TestServiceNaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ void TestMakeServiceNameSubtype(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S3") == 0);

filter.code = (1 << 8) - 1;
filter.code = (1 << 4) - 1;
NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S255") == 0);
NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S15") == 0);

filter.code = 1 << 8;
filter.code = 1 << 4;
NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) != CHIP_NO_ERROR);

// Vendor tests
Expand Down Expand Up @@ -202,15 +202,14 @@ void TestMakeServiceTypeName(nlTestSuite * inSuite, void * inContext)
filter.code = 3;
NL_TEST_ASSERT(inSuite,
MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
printf("buffer: %s\n", buffer);
NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S3._sub._matterc") == 0);

filter.code = (1 << 8) - 1;
filter.code = (1 << 4) - 1;
NL_TEST_ASSERT(inSuite,
MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S255._sub._matterc") == 0);
NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S15._sub._matterc") == 0);

filter.code = 1 << 8;
filter.code = 1 << 4;
NL_TEST_ASSERT(inSuite,
MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) != CHIP_NO_ERROR);

Expand Down

0 comments on commit 2790867

Please sign in to comment.