blob: 31112485b1eb22da8c951c3b70cd89cfc464b7ec [file] [log] [blame]
Casey Dahlin3122cdf2016-06-23 14:19:37 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ADB_MDNS_H_
18#define _ADB_MDNS_H_
19
Lingfeng Yangf44871a2018-11-16 22:47:31 -080020#include <android-base/macros.h>
21
Joshua Duong77b8ff32020-04-16 15:58:19 -070022// The rules for Service Names [RFC6335] state that they may be no more
23// than fifteen characters long (not counting the mandatory underscore),
24// consisting of only letters, digits, and hyphens, must begin and end
25// with a letter or digit, must not contain consecutive hyphens, and
26// must contain at least one letter.
27#define ADB_MDNS_SERVICE_TYPE "adb"
28#define ADB_MDNS_TLS_PAIRING_TYPE "adb-tls-pairing"
29#define ADB_MDNS_TLS_CONNECT_TYPE "adb-tls-connect"
Lingfeng Yangf44871a2018-11-16 22:47:31 -080030
Lingfeng Yang9f4fff32018-11-26 17:31:39 -080031const int kADBTransportServiceRefIndex = 0;
32const int kADBSecurePairingServiceRefIndex = 1;
33const int kADBSecureConnectServiceRefIndex = 2;
34
Lingfeng Yang48bdec72019-10-24 22:30:11 -070035// Each ADB Secure service advertises with a TXT record indicating the version
36// using a key/value pair per RFC 6763 (https://tools.ietf.org/html/rfc6763).
37//
38// The first key/value pair is always the version of the protocol.
39// There may be more key/value pairs added after.
40//
41// The version is purposely represented as the single letter "v" due to the
42// need to minimize DNS traffic. The version starts at 1. With each breaking
43// protocol change, the version is incremented by 1.
44//
45// Newer adb clients/daemons need to recognize and either reject
46// or be backward-compatible with older verseions if there is a mismatch.
47//
48// Relevant sections:
49//
50// """
51// 6.4. Rules for Keys in DNS-SD Key/Value Pairs
52//
53// The key MUST be at least one character. DNS-SD TXT record strings
54// beginning with an '=' character (i.e., the key is missing) MUST be
55// silently ignored.
56//
57// ...
58//
59// 6.5. Rules for Values in DNS-SD Key/Value Pairs
60//
61// If there is an '=' in a DNS-SD TXT record string, then everything
62// after the first '=' to the end of the string is the value. The value
63// can contain any eight-bit values including '='.
64// """
65
66#define ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ver) ("v=" #ver)
67
68// Client/service versions are initially defined to be matching,
69// but may go out of sync as different clients and services
70// try to talk to each other.
71#define ADB_SECURE_SERVICE_VERSION 1
72#define ADB_SECURE_CLIENT_VERSION ADB_SECURE_SERVICE_VERSION
73
74const char* kADBSecurePairingServiceTxtRecord =
75 ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ADB_SECURE_SERVICE_VERSION);
76const char* kADBSecureConnectServiceTxtRecord =
77 ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ADB_SECURE_SERVICE_VERSION);
78
Joshua Duong77b8ff32020-04-16 15:58:19 -070079#define ADB_FULL_MDNS_SERVICE_TYPE(atype) ("_" atype "._tcp")
80const char* kADBDNSServices[] = {ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_SERVICE_TYPE),
81 ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_TLS_PAIRING_TYPE),
82 ADB_FULL_MDNS_SERVICE_TYPE(ADB_MDNS_TLS_CONNECT_TYPE)};
Lingfeng Yangf44871a2018-11-16 22:47:31 -080083
Lingfeng Yang48bdec72019-10-24 22:30:11 -070084const char* kADBDNSServiceTxtRecords[] = {
85 nullptr,
86 kADBSecurePairingServiceTxtRecord,
87 kADBSecureConnectServiceTxtRecord,
88};
89
Lingfeng Yangf44871a2018-11-16 22:47:31 -080090const int kNumADBDNSServices = arraysize(kADBDNSServices);
Casey Dahlin3122cdf2016-06-23 14:19:37 -070091
92#endif