blob: 6b373553aaa4ddf1fd0835bdaef2473ba01be841 [file] [log] [blame]
Casey Dahlin13a269e2016-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 Yangbe49d8a2018-11-16 22:47:31 -080020#include <android-base/macros.h>
21
Casey Dahlin13a269e2016-06-23 14:19:37 -070022const char* kADBServiceType = "_adb._tcp";
Lingfeng Yangbe49d8a2018-11-16 22:47:31 -080023const char* kADBSecurePairingServiceType = "_adb_secure_pairing._tcp";
24const char* kADBSecureConnectServiceType = "_adb_secure_connect._tcp";
25
Lingfeng Yangcef4ade2018-11-26 17:31:39 -080026const int kADBTransportServiceRefIndex = 0;
27const int kADBSecurePairingServiceRefIndex = 1;
28const int kADBSecureConnectServiceRefIndex = 2;
29
Lingfeng Yang39e54b82019-10-24 22:30:11 -070030// Each ADB Secure service advertises with a TXT record indicating the version
31// using a key/value pair per RFC 6763 (https://tools.ietf.org/html/rfc6763).
32//
33// The first key/value pair is always the version of the protocol.
34// There may be more key/value pairs added after.
35//
36// The version is purposely represented as the single letter "v" due to the
37// need to minimize DNS traffic. The version starts at 1. With each breaking
38// protocol change, the version is incremented by 1.
39//
40// Newer adb clients/daemons need to recognize and either reject
41// or be backward-compatible with older verseions if there is a mismatch.
42//
43// Relevant sections:
44//
45// """
46// 6.4. Rules for Keys in DNS-SD Key/Value Pairs
47//
48// The key MUST be at least one character. DNS-SD TXT record strings
49// beginning with an '=' character (i.e., the key is missing) MUST be
50// silently ignored.
51//
52// ...
53//
54// 6.5. Rules for Values in DNS-SD Key/Value Pairs
55//
56// If there is an '=' in a DNS-SD TXT record string, then everything
57// after the first '=' to the end of the string is the value. The value
58// can contain any eight-bit values including '='.
59// """
60
61#define ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ver) ("v=" #ver)
62
63// Client/service versions are initially defined to be matching,
64// but may go out of sync as different clients and services
65// try to talk to each other.
66#define ADB_SECURE_SERVICE_VERSION 1
67#define ADB_SECURE_CLIENT_VERSION ADB_SECURE_SERVICE_VERSION
68
69const char* kADBSecurePairingServiceTxtRecord =
70 ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ADB_SECURE_SERVICE_VERSION);
71const char* kADBSecureConnectServiceTxtRecord =
72 ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ADB_SECURE_SERVICE_VERSION);
73
Lingfeng Yangbe49d8a2018-11-16 22:47:31 -080074const char* kADBDNSServices[] = {
75 kADBServiceType,
76 kADBSecurePairingServiceType,
77 kADBSecureConnectServiceType,
78};
79
Lingfeng Yang39e54b82019-10-24 22:30:11 -070080const char* kADBDNSServiceTxtRecords[] = {
81 nullptr,
82 kADBSecurePairingServiceTxtRecord,
83 kADBSecureConnectServiceTxtRecord,
84};
85
Lingfeng Yangbe49d8a2018-11-16 22:47:31 -080086const int kNumADBDNSServices = arraysize(kADBDNSServices);
Casey Dahlin13a269e2016-06-23 14:19:37 -070087
88#endif