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 20 #include <android-base/macros.h> 21 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" 30 31 const int kADBTransportServiceRefIndex = 0; 32 const int kADBSecurePairingServiceRefIndex = 1; 33 const int kADBSecureConnectServiceRefIndex = 2; 34 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 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)}; 83 84 const char* kADBDNSServiceTxtRecords[] = { 85 nullptr, 86 kADBSecurePairingServiceTxtRecord, 87 kADBSecureConnectServiceTxtRecord, 88 }; 89 90 const int kNumADBDNSServices = arraysize(kADBDNSServices); 91 92 #endif 93