Damian Królik | cdcca18 | 2021-03-24 18:19:45 +0100 | [diff] [blame] | 1 | /* |
| 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 MingJie | 53dd583 | 2021-09-03 03:05:16 +0800 | [diff] [blame] | 20 | #include <lib/core/CHIPError.h> |
| 21 | #include <lib/core/PeerId.h> |
Damian Królik | 581b57a | 2021-10-19 19:09:26 +0200 | [diff] [blame] | 22 | #include <lib/dnssd/Constants.h> |
Andrei Litvin | 1ad0e12 | 2024-02-08 09:56:55 -0500 | [diff] [blame] | 23 | #include <lib/dnssd/Types.h> |
Zang MingJie | 53dd583 | 2021-09-03 03:05:16 +0800 | [diff] [blame] | 24 | #include <lib/support/Span.h> |
Damian Królik | cdcca18 | 2021-03-24 18:19:45 +0100 | [diff] [blame] | 25 | |
| 26 | #include <cstddef> |
| 27 | #include <cstdint> |
| 28 | |
| 29 | namespace chip { |
Kamil Kasperczyk | d9e02a0 | 2021-10-12 09:19:23 +0200 | [diff] [blame] | 30 | namespace Dnssd { |
Karsten Sperling | b15a6e6 | 2023-09-16 03:58:46 +1200 | [diff] [blame] | 31 | inline constexpr char kSubtypeServiceNamePart[] = "_sub"; |
| 32 | inline constexpr char kCommissionableServiceName[] = "_matterc"; |
| 33 | inline constexpr char kOperationalServiceName[] = "_matter"; |
| 34 | inline constexpr char kCommissionerServiceName[] = "_matterd"; |
| 35 | inline constexpr char kOperationalProtocol[] = "_tcp"; |
| 36 | inline constexpr char kCommissionProtocol[] = "_udp"; |
| 37 | inline constexpr char kLocalDomain[] = "local"; |
C Freeman | 4f122bc | 2021-05-31 12:08:51 -0400 | [diff] [blame] | 38 | |
| 39 | // each includes space for a null terminator, which becomes a . when the names are appended. |
Vivien Nicolas | 11e2bfa | 2021-12-01 16:50:17 +0100 | [diff] [blame] | 40 | constexpr size_t kMaxCommissionableServiceNameSize = |
Damian Królik | 581b57a | 2021-10-19 19:09:26 +0200 | [diff] [blame] | 41 | Common::kSubTypeMaxLength + 1 + sizeof(kSubtypeServiceNamePart) + sizeof(kCommissionableServiceName); |
Damian Królik | cdcca18 | 2021-03-24 18:19:45 +0100 | [diff] [blame] | 42 | |
Sharad Binjola | b2f8af0 | 2021-06-29 09:13:13 -0700 | [diff] [blame] | 43 | // each includes space for a null terminator, which becomes a . when the names are appended. |
Vivien Nicolas | 11e2bfa | 2021-12-01 16:50:17 +0100 | [diff] [blame] | 44 | constexpr size_t kMaxCommissionerServiceNameSize = |
Damian Królik | 581b57a | 2021-10-19 19:09:26 +0200 | [diff] [blame] | 45 | Common::kSubTypeMaxLength + 1 + sizeof(kSubtypeServiceNamePart) + sizeof(kCommissionerServiceName); |
Sharad Binjola | b2f8af0 | 2021-06-29 09:13:13 -0700 | [diff] [blame] | 46 | |
C Freeman | f679d45 | 2021-08-04 15:23:07 -0400 | [diff] [blame] | 47 | // + 1 for nullchar on prefix. |
| 48 | constexpr size_t kMaxOperationalServiceNameSize = |
Damian Królik | 581b57a | 2021-10-19 19:09:26 +0200 | [diff] [blame] | 49 | Operational::kInstanceNameMaxLength + 1 + sizeof(kOperationalServiceName) + sizeof(kOperationalProtocol) + sizeof(kLocalDomain); |
C Freeman | f679d45 | 2021-08-04 15:23:07 -0400 | [diff] [blame] | 50 | |
Andrei Litvin | f8043b6 | 2021-04-19 12:20:34 -0400 | [diff] [blame] | 51 | /// builds the MDNS advertising name for a given fabric + nodeid pair |
| 52 | CHIP_ERROR MakeInstanceName(char * buffer, size_t bufferLen, const PeerId & peerId); |
| 53 | |
Boris Zbarsky | 6b6c2ee | 2021-08-05 13:22:53 -0400 | [diff] [blame] | 54 | /// 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 Litvin | f8043b6 | 2021-04-19 12:20:34 -0400 | [diff] [blame] | 58 | CHIP_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) |
cecille | 551c87c | 2021-04-06 11:26:36 -0400 | [diff] [blame] | 62 | CHIP_ERROR MakeHostName(char * buffer, size_t bufferLen, const chip::ByteSpan & macOrEui64); |
Damian Królik | cdcca18 | 2021-03-24 18:19:45 +0100 | [diff] [blame] | 63 | |
cecille | 4826f70 | 2021-05-19 09:49:37 -0400 | [diff] [blame] | 64 | CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter subtype); |
| 65 | |
Sharad Binjola | b2f8af0 | 2021-06-29 09:13:13 -0700 | [diff] [blame] | 66 | CHIP_ERROR MakeServiceTypeName(char * buffer, size_t bufferLen, DiscoveryFilter nameDesc, DiscoveryType type); |
C Freeman | 2fbc3fd | 2021-06-16 11:20:20 -0400 | [diff] [blame] | 67 | |
Kamil Kasperczyk | d9e02a0 | 2021-10-12 09:19:23 +0200 | [diff] [blame] | 68 | } // namespace Dnssd |
Damian Królik | cdcca18 | 2021-03-24 18:19:45 +0100 | [diff] [blame] | 69 | } // namespace chip |