Casey Dahlin | 3122cdf | 2016-06-23 14:19:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Yang | f44871a | 2018-11-16 22:47:31 -0800 | [diff] [blame] | 20 | #include <android-base/macros.h> |
| 21 | |
Joshua Duong | 77b8ff3 | 2020-04-16 15:58:19 -0700 | [diff] [blame^] | 22 | // 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 Yang | f44871a | 2018-11-16 22:47:31 -0800 | [diff] [blame] | 30 | |
Lingfeng Yang | 9f4fff3 | 2018-11-26 17:31:39 -0800 | [diff] [blame] | 31 | const int kADBTransportServiceRefIndex = 0; |
| 32 | const int kADBSecurePairingServiceRefIndex = 1; |
| 33 | const int kADBSecureConnectServiceRefIndex = 2; |
| 34 | |
Lingfeng Yang | 48bdec7 | 2019-10-24 22:30:11 -0700 | [diff] [blame] | 35 | // 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 | |
| 74 | const char* kADBSecurePairingServiceTxtRecord = |
| 75 | ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ADB_SECURE_SERVICE_VERSION); |
| 76 | const char* kADBSecureConnectServiceTxtRecord = |
| 77 | ADB_SECURE_SERVICE_VERSION_TXT_RECORD(ADB_SECURE_SERVICE_VERSION); |
| 78 | |
Joshua Duong | 77b8ff3 | 2020-04-16 15:58:19 -0700 | [diff] [blame^] | 79 | #define ADB_FULL_MDNS_SERVICE_TYPE(atype) ("_" atype "._tcp") |
| 80 | const 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 Yang | f44871a | 2018-11-16 22:47:31 -0800 | [diff] [blame] | 83 | |
Lingfeng Yang | 48bdec7 | 2019-10-24 22:30:11 -0700 | [diff] [blame] | 84 | const char* kADBDNSServiceTxtRecords[] = { |
| 85 | nullptr, |
| 86 | kADBSecurePairingServiceTxtRecord, |
| 87 | kADBSecureConnectServiceTxtRecord, |
| 88 | }; |
| 89 | |
Lingfeng Yang | f44871a | 2018-11-16 22:47:31 -0800 | [diff] [blame] | 90 | const int kNumADBDNSServices = arraysize(kADBDNSServices); |
Casey Dahlin | 3122cdf | 2016-06-23 14:19:37 -0700 | [diff] [blame] | 91 | |
| 92 | #endif |