Skip to content

Commit

Permalink
Mdns: _chip* -> _matter*, remove 0's on subtypes (#7805)
Browse files Browse the repository at this point in the history
* Mdns: _chip* i-> _matter*, remove 0's on subtypes

The second ballot changed the format of the subtypes as well as
fixed the service name prefix from _chip* to _matter*.

NOTE FOR DEVs: Updating past this change will require updating the
devices and controllers as otherwise they will be unable to find
each other.

* Darwin - use local kLocalDomain var.

It includes a . and the one in the ServiceNaming doesn't.

* Trying again for Darwin.

* Fix host name.

* Fix small error on merge
  • Loading branch information
cecille authored and pull[bot] committed Sep 8, 2021
1 parent 522bd2c commit 2520836
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 89 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void AppTask::AppTaskMain(void * pvParameter)
}

EFR32_LOG("App Task started");
SetDeviceName("EFR32LightingDemo._chip._udp.local.");
SetDeviceName("EFR32LightingDemo._matter._udp.local.");

while (true)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void AppTask::AppTaskMain(void * pvParameter)
}

EFR32_LOG("App Task started");
SetDeviceName("EFR32LockDemo._chip._udp.local.");
SetDeviceName("EFR32LockDemo._matter._udp.local.");

while (true)
{
Expand Down
54 changes: 27 additions & 27 deletions examples/minimal-mdns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ which is likely to list a lot of answers.
You can customize the queries run:

```sh
/out/minimal_mdns/minimal-mdns-client -4 -q chip-mdns-demo._chip._tcp.local
/out/minimal_mdns/minimal-mdns-client -4 -q chip-mdns-demo._matter._tcp.local
```

see
Expand Down Expand Up @@ -88,64 +88,64 @@ discovery.
#### Simulated uncommisioned node

```sh
dns-sd -R DD200C20D25AE5F7 _chipc._udp,S052,L0840,V123 . 11111 D=0840 VP=123+456
dns-sd -R DD200C20D25AE5F7 _matterc._udp,S52,L840,V123 . 11111 D=840 VP=123+456
```

Will create the following records

```
_chipc._udp.local. PTR DD200C20D25AE5F7._chipc._udp.local.
S052._sub._chipc._udp.local. PTR DD200C20D25AE5F7._chipc._udp.local.
L0840._sub._chipc._udp.local. PTR DD200C20D25AE5F7._chipc._udp.local.
V123._sub._chipc._udp.local. PTR DD200C20D25AE5F7._chipc._udp.local.
DD200C20D25AE5F7._chipc._udp.local. TXT "D=0840" "VP=123+456"
DD200C20D25AE5F7._chipc._udp.local. SRV 0 0 11111 B75AFB458ECD.local.
_matterc._udp.local. PTR DD200C20D25AE5F7._matterc._udp.local.
S52._sub._matterc._udp.local. PTR DD200C20D25AE5F7._matterc._udp.local.
L840._sub._matterc._udp.local. PTR DD200C20D25AE5F7._matterc._udp.local.
V123._sub._matterc._udp.local. PTR DD200C20D25AE5F7._matterc._udp.local.
DD200C20D25AE5F7._matterc._udp.local. TXT "D=840" "VP=123+456"
DD200C20D25AE5F7._mattterc._udp.local. SRV 0 0 11111 B75AFB458ECD.local.
B75AFB458ECD.local. AAAA ba2a:b311:742e:b44c:f515:576f:9783:3f30
```

#### Simulated commisioning node

```sh
dns-sd -R DD200C20D25AE5F7 _chipd._udp,S052,L0840,V123 . 11111 D=0840 VP=123+456 PH=3
dns-sd -R DD200C20D25AE5F7 _matterd._udp,S52,L840,V123 . 11111 D=840 VP=123+456 PH=3
```

Will create the following records:

```
_chipd._udp.local. PTR DD200C20D25AE5F7._chipd._udp.local.
S052._sub._chipd._udp.local. PTR DD200C20D25AE5F7._chipd._udp.local.
V123._sub._chipd._udp.local. PTR DD200C20D25AE5F7._chipd._udp.local.
D0840._sub._chipd._udp.local. PTR DD200C20D25AE5F7._chipd._udp.local.
DD200C20D25AE5F7._chipd._udp.local. TXT "D=0840" "VP=123+456" "PH=3"
DD200C20D25AE5F7._chipd._udp.local. SRV 0 0 11111 B75AFB458ECD.local.
B75AFB458ECD.local. AAAA ba2a:b311:742e:b44c:f515:576f:9783:3f30
_matterd._udp.local. PTR DD200C20D25AE5F7._matterd._udp.local.
S52._sub._matterd._udp.local. PTR DD200C20D25AE5F7._matterd._udp.local.
V123._sub._matterd._udp.local. PTR DD200C20D25AE5F7._matterd._udp.local.
D840._sub._matterd._udp.local. PTR DD200C20D25AE5F7._matterd._udp.local.
DD200C20D25AE5F7._matterd._udp.local. TXT "D=840" "VP=123+456" "PH=3"
DD200C20D25AE5F7._matterd._udp.local. SRV 0 0 11111 B75AFB458ECD.local.
B75AFB458ECD.local. AAAA ba2a:b311:742e:b44c:f515:576f:9783:3f30
```

#### Simulated commisioned node

```sh
dns-sd -R 2906C908D115D362-8FC7772401CD0696 _chip._tcp . 22222
dns-sd -R 2906C908D115D362-8FC7772401CD0696 _matter._tcp . 22222
```

### Discovery commands

Nodes:

```sh
dns-sd -B _chipc._udp # Nodes awaiting commisioning
dns-sd -B _chipc._udp,S052 # Nodes awaiting commisioning with short discriminator 052
dns-sd -B _chipc._udp,L0840 # Nodes awaiting commisioning with long discriminator 0840
dns-sd -B _chipc._udp,V123 # Nodes awaiting commisioning with vendor id 123
dns-sd -B _matterc._udp # Nodes awaiting commisioning
dns-sd -B _matterc._udp,S52 # Nodes awaiting commisioning with short discriminator 52
dns-sd -B _matterc._udp,L840 # Nodes awaiting commisioning with long discriminator 840
dns-sd -B _matterc._udp,V123 # Nodes awaiting commisioning with vendor id 123

dns-sd -B _chipd._udp # Commisionable nodes
dns-sd -B _chipd._udp,S052 # Commisionable nodes with short discriminator 052
dns-sd -B _chipd._udp,L0840 # Commisionable nodes with long discriminator 0840
dns-sd -B _chipd._udp,V123 # Commisionable nodes with vendor id 123
dns-sd -B _matterd._udp # Commisionable nodes
dns-sd -B _matterd._udp,S52 # Commisionable nodes with short discriminator 52
dns-sd -B _matterd._udp,L840 # Commisionable nodes with long discriminator 840
dns-sd -B _matterd._udp,V123 # Commisionable nodes with vendor id 123
```

IP Address:

```sh
dns-sd -L 2906C908D115D362-8FC7772401CD0696 _chip._tcp # find server address
dns-sd -Gv6 B75AFB458ECD.local # get IPv6 address
dns-sd -L 2906C908D115D362-8FC7772401CD0696 _matter._tcp # find server address
dns-sd -Gv6 B75AFB458ECD.local # get IPv6 address
```
24 changes: 15 additions & 9 deletions examples/minimal-mdns/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <mdns/ServiceNaming.h>
#include <mdns/minimal/QueryBuilder.h>
#include <mdns/minimal/ResponseSender.h>
#include <mdns/minimal/Server.h>
Expand Down Expand Up @@ -187,17 +188,22 @@ int main(int argc, char ** args)
mdns::Minimal::Server<10 /* endpoints */> mdnsServer;
mdns::Minimal::QueryResponder<16 /* maxRecords */> queryResponder;

mdns::Minimal::QNamePart tcpServiceName[] = { "_chip", "_tcp", "local" };
mdns::Minimal::QNamePart tcpServerServiceName[] = { gOptions.instanceName, "_chip", "_tcp", "local" };
mdns::Minimal::QNamePart udpServiceName[] = { "_chip", "_udp", "local" };
mdns::Minimal::QNamePart udpServerServiceName[] = { gOptions.instanceName, "_chip", "_udp", "local" };
mdns::Minimal::QNamePart tcpServiceName[] = { kOperationalServiceName, kOperationalProtocol, kLocalDomain };
mdns::Minimal::QNamePart tcpServerServiceName[] = { gOptions.instanceName, kOperationalServiceName, kOperationalProtocol,
kLocalDomain };
mdns::Minimal::QNamePart udpServiceName[] = { kCommissionableServiceName, kCommissionProtocol, kLocalDomain };
mdns::Minimal::QNamePart udpServerServiceName[] = { gOptions.instanceName, kCommissionableServiceName, kCommissionProtocol,
kLocalDomain };

// several UDP versions for discriminators
mdns::Minimal::QNamePart udpDiscriminator1[] = { "S052", "_sub", "_chip", "_udp", "local" };
mdns::Minimal::QNamePart udpDiscriminator2[] = { "V123", "_sub", "_chip", "_udp", "local" };
mdns::Minimal::QNamePart udpDiscriminator3[] = { "L0840", "_sub", "_chip", "_udp", "local" };

mdns::Minimal::QNamePart serverName[] = { gOptions.instanceName, "local" };
mdns::Minimal::QNamePart udpDiscriminator1[] = { "S52", kSubtypeServiceNamePart, kCommissionableServiceName,
kCommissionProtocol, kLocalDomain };
mdns::Minimal::QNamePart udpDiscriminator2[] = { "V123", kSubtypeServiceNamePart, kCommissionableServiceName,
kCommissionProtocol, kLocalDomain };
mdns::Minimal::QNamePart udpDiscriminator3[] = { "L840", kSubtypeServiceNamePart, kCommissionableServiceName,
kCommissionProtocol, kLocalDomain };

mdns::Minimal::QNamePart serverName[] = { gOptions.instanceName, kLocalDomain };

mdns::Minimal::IPv4Responder ipv4Responder(serverName);
mdns::Minimal::IPv6Responder ipv6Responder(serverName);
Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void AppTask::Main(void * pvParameter)
}

EFR32_LOG("App Task started");
SetDeviceName("EFR32WindowCoverDemo._chip._udp.local.");
SetDeviceName("EFR32WindowCoverDemo._matter._udp.local.");

while (true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class OnOffClientFragment : Fragment() {
fabricIdEd.text.toString().toLong(),
deviceIdEd.text.toString().toLong()
)
serviceType = "_chip._tcp"
serviceType = "_matter._tcp"
}

// TODO: implement the common CHIP mDNS interface for Android and make CHIP stack call the resolver
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/CHIPTool/CHIPTool/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<string>Used to connect to the peripheral</string>
<key>NSBonjourServices</key>
<array>
<string>_chip._tcp</string>
<string>_matter._tcp</string>
</array>
<key>NSCameraUsageDescription</key>
<string>Used to scan QR code</string>
Expand Down
8 changes: 5 additions & 3 deletions src/lib/mdns/Advertiser_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const OperationalAdvertisingParameters &
/// need to set server name
ReturnErrorOnFailure(MakeInstanceName(nameBuffer, sizeof(nameBuffer), params.GetPeerId()));

FullQName operationalServiceName = mQueryResponderAllocator.AllocateQName("_chip", "_tcp", "local");
FullQName operationalServerName = mQueryResponderAllocator.AllocateQName(nameBuffer, "_chip", "_tcp", "local");
FullQName operationalServiceName =
mQueryResponderAllocator.AllocateQName(kOperationalServiceName, kOperationalProtocol, kLocalDomain);
FullQName operationalServerName =
mQueryResponderAllocator.AllocateQName(nameBuffer, kOperationalServiceName, kOperationalProtocol, kLocalDomain);

ReturnErrorOnFailure(MakeHostName(nameBuffer, sizeof(nameBuffer), params.GetMac()));
FullQName serverName = mQueryResponderAllocator.AllocateQName(nameBuffer, "local");
FullQName serverName = mQueryResponderAllocator.AllocateQName(nameBuffer, kLocalDomain);

if ((operationalServiceName.nameCount == 0) || (operationalServerName.nameCount == 0) || (serverName.nameCount == 0))
{
Expand Down
12 changes: 6 additions & 6 deletions src/lib/mdns/ServiceNaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,24 @@ CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter s
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
requiredSize = snprintf(buffer, bufferLen, "_S%03u", subtype.code);
requiredSize = snprintf(buffer, bufferLen, "_S%u", subtype.code);
break;
case DiscoveryFilterType::kLong:
// 12-bit number
if (subtype.code >= 1 << 12)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
requiredSize = snprintf(buffer, bufferLen, "_L%04u", subtype.code);
requiredSize = snprintf(buffer, bufferLen, "_L%u", subtype.code);
break;
case DiscoveryFilterType::kVendor:
// Vendor ID is 16-bit, so if it fits in the code, it's good.
// NOTE: size here is wrong, will be changed in upcming PR to remove leading zeros.
requiredSize = snprintf(buffer, bufferLen, "_V%03u", subtype.code);
requiredSize = snprintf(buffer, bufferLen, "_V%u", subtype.code);
break;
case DiscoveryFilterType::kDeviceType:
// TODO: Not totally clear the size required here: see spec issue #3226
requiredSize = snprintf(buffer, bufferLen, "_T%03u", subtype.code);
requiredSize = snprintf(buffer, bufferLen, "_T%u", subtype.code);
break;
case DiscoveryFilterType::kCommissioningMode:
if (subtype.code > 1)
Expand Down Expand Up @@ -187,11 +187,11 @@ CHIP_ERROR MakeServiceTypeName(char * buffer, size_t bufferLen, DiscoveryFilter
{
if (type == DiscoveryType::kCommissionableNode)
{
requiredSize = snprintf(buffer, bufferLen, "_chipc");
requiredSize = snprintf(buffer, bufferLen, kCommissionableServiceName);
}
else if (type == DiscoveryType::kCommissionerNode)
{
requiredSize = snprintf(buffer, bufferLen, "_chipd");
requiredSize = snprintf(buffer, bufferLen, kCommissionerServiceName);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/lib/mdns/ServiceNaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace chip {
namespace Mdns {
constexpr size_t kMaxSubtypeDescSize = 8; // max 5 decimal digits + _X prefix. + null character
constexpr char kSubtypeServiceNamePart[] = "_sub";
constexpr char kCommissionableServiceName[] = "_chipc";
constexpr char kOperationalServiceName[] = "_chip";
constexpr char kCommissionerServiceName[] = "_chipd";
constexpr char kCommissionableServiceName[] = "_matterc";
constexpr char kOperationalServiceName[] = "_matter";
constexpr char kCommissionerServiceName[] = "_matterd";
constexpr char kOperationalProtocol[] = "_tcp";
constexpr char kCommissionProtocol[] = "_udp";
constexpr char kLocalDomain[] = "local";
Expand Down
12 changes: 8 additions & 4 deletions src/lib/mdns/platform/Mdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@

#pragma once

#include <algorithm>
#include <stdint.h>

#include "core/CHIPError.h"
#include "inet/IPAddress.h"
#include "inet/InetInterface.h"
#include "lib/core/Optional.h"
#include "lib/mdns/ServiceNaming.h"

namespace chip {
namespace Mdns {

static constexpr uint8_t kMdnsInstanceNameMaxSize = 33; // [Node]-[Fabric] ID in hex - 16+1+16
static constexpr uint8_t kMdnsHostNameMaxSize = 16; // 64-bits in hex.
static constexpr uint8_t kMdnsProtocolTextMaxSize = 4; // "_tcp" or "_udp"
static constexpr uint8_t kMdnsTypeMaxSize = 6; // "_chip", "_chipc" or "_chipd"
// None of these sizes include an null character at the end.
static constexpr uint8_t kMdnsInstanceNameMaxSize = 33; // [Node]-[Fabric] ID in hex - 16+1+16
static constexpr uint8_t kMdnsHostNameMaxSize = 16; // 64-bits in hex.
static constexpr size_t kMdnsProtocolTextMaxSize = std::max(sizeof(kOperationalProtocol), sizeof(kCommissionProtocol)) - 1;
static constexpr size_t kMdnsTypeMaxSize =
std::max({ sizeof(kCommissionableServiceName), sizeof(kOperationalServiceName), sizeof(kCommissionerServiceName) }) - 1;
static constexpr uint8_t kMdnsTypeAndProtocolMaxSize = kMdnsTypeMaxSize + kMdnsProtocolTextMaxSize + 1; // <type>.<protocol>
static constexpr uint16_t kMdnsTextMaxSize = 64;

Expand Down
Loading

0 comments on commit 2520836

Please sign in to comment.