blob: 1ea1105522fab9e9508da46d0a905333946a323a [file] [log] [blame]
Damian Królikcdcca182021-03-24 18:19:45 +01001/*
2 *
3 * Copyright (c) 2021 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
Zang MingJie53dd5832021-09-03 03:05:16 +080020#include <lib/core/CHIPError.h>
21#include <lib/core/PeerId.h>
Damian Królik581b57a2021-10-19 19:09:26 +020022#include <lib/dnssd/Constants.h>
Andrei Litvin1ad0e122024-02-08 09:56:55 -050023#include <lib/dnssd/Types.h>
Zang MingJie53dd5832021-09-03 03:05:16 +080024#include <lib/support/Span.h>
Damian Królikcdcca182021-03-24 18:19:45 +010025
26#include <cstddef>
27#include <cstdint>
28
29namespace chip {
Kamil Kasperczykd9e02a02021-10-12 09:19:23 +020030namespace Dnssd {
Karsten Sperlingb15a6e62023-09-16 03:58:46 +120031inline constexpr char kSubtypeServiceNamePart[] = "_sub";
32inline constexpr char kCommissionableServiceName[] = "_matterc";
33inline constexpr char kOperationalServiceName[] = "_matter";
34inline constexpr char kCommissionerServiceName[] = "_matterd";
35inline constexpr char kOperationalProtocol[] = "_tcp";
36inline constexpr char kCommissionProtocol[] = "_udp";
37inline constexpr char kLocalDomain[] = "local";
C Freeman4f122bc2021-05-31 12:08:51 -040038
39// each includes space for a null terminator, which becomes a . when the names are appended.
Vivien Nicolas11e2bfa2021-12-01 16:50:17 +010040constexpr size_t kMaxCommissionableServiceNameSize =
Damian Królik581b57a2021-10-19 19:09:26 +020041 Common::kSubTypeMaxLength + 1 + sizeof(kSubtypeServiceNamePart) + sizeof(kCommissionableServiceName);
Damian Królikcdcca182021-03-24 18:19:45 +010042
Sharad Binjolab2f8af02021-06-29 09:13:13 -070043// each includes space for a null terminator, which becomes a . when the names are appended.
Vivien Nicolas11e2bfa2021-12-01 16:50:17 +010044constexpr size_t kMaxCommissionerServiceNameSize =
Damian Królik581b57a2021-10-19 19:09:26 +020045 Common::kSubTypeMaxLength + 1 + sizeof(kSubtypeServiceNamePart) + sizeof(kCommissionerServiceName);
Sharad Binjolab2f8af02021-06-29 09:13:13 -070046
C Freemanf679d452021-08-04 15:23:07 -040047// + 1 for nullchar on prefix.
48constexpr size_t kMaxOperationalServiceNameSize =
Damian Królik581b57a2021-10-19 19:09:26 +020049 Operational::kInstanceNameMaxLength + 1 + sizeof(kOperationalServiceName) + sizeof(kOperationalProtocol) + sizeof(kLocalDomain);
C Freemanf679d452021-08-04 15:23:07 -040050
Andrei Litvinf8043b62021-04-19 12:20:34 -040051/// builds the MDNS advertising name for a given fabric + nodeid pair
52CHIP_ERROR MakeInstanceName(char * buffer, size_t bufferLen, const PeerId & peerId);
53
Boris Zbarsky6b6c2ee2021-08-05 13:22:53 -040054/// Inverse of MakeInstanceName. Will return errors on non-spec-compliant ids,
55/// _except_ for allowing lowercase hex, not just the spec-defined uppercase
56/// hex. The part of "name" up to the first '.' (or end of string, whichever
57/// comes first) is parsed as a FABRICID-NODEID.
Andrei Litvinf8043b62021-04-19 12:20:34 -040058CHIP_ERROR ExtractIdFromInstanceName(const char * name, PeerId * peerId);
59
60/// Generates the host name that a CHIP device is to use for a given unique
61/// identifier (MAC address or EUI64)
cecille551c87c2021-04-06 11:26:36 -040062CHIP_ERROR MakeHostName(char * buffer, size_t bufferLen, const chip::ByteSpan & macOrEui64);
Damian Królikcdcca182021-03-24 18:19:45 +010063
cecille4826f702021-05-19 09:49:37 -040064CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter subtype);
65
Sharad Binjolab2f8af02021-06-29 09:13:13 -070066CHIP_ERROR MakeServiceTypeName(char * buffer, size_t bufferLen, DiscoveryFilter nameDesc, DiscoveryType type);
C Freeman2fbc3fd2021-06-16 11:20:20 -040067
Kamil Kasperczykd9e02a02021-10-12 09:19:23 +020068} // namespace Dnssd
Damian Królikcdcca182021-03-24 18:19:45 +010069} // namespace chip