1 /* 2 * Copyright (C) 2022 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 package com.android.server.nearby.common.ble.testing; 18 19 import com.android.server.nearby.util.ArrayUtils; 20 import com.android.server.nearby.util.Hex; 21 22 /** 23 * Test class to provide example to unit test. 24 */ 25 public class FastPairTestData { 26 private static final byte[] FAST_PAIR_RECORD_BIG_ENDIAN = 27 Hex.stringToBytes("02011E020AF006162CFEAABBCC"); 28 29 /** 30 * A Fast Pair frame, Note: The service UUID is FE2C, but in the 31 * packet it's 2CFE, since the core Bluetooth data types are little-endian. 32 * 33 * <p>However, the model ID is big-endian (multi-byte values in our spec are now big-endian, aka 34 * network byte order). 35 * 36 * @see {http://go/fast-pair-service-data} 37 */ getFastPairRecord()38 public static byte[] getFastPairRecord() { 39 return FAST_PAIR_RECORD_BIG_ENDIAN; 40 } 41 42 /** A Fast Pair frame, with a shared account key. */ 43 public static final byte[] FAST_PAIR_SHARED_ACCOUNT_KEY_RECORD = 44 Hex.stringToBytes("02011E020AF00C162CFE007011223344556677"); 45 46 /** Model ID in {@link #getFastPairRecord()}. */ 47 public static final byte[] FAST_PAIR_MODEL_ID = Hex.stringToBytes("AABBCC"); 48 49 /** An arbitrary BLE device address. */ 50 public static final String DEVICE_ADDRESS = "00:00:00:00:00:01"; 51 52 /** Arbitrary RSSI (Received Signal Strength Indicator). */ 53 public static final int RSSI = -72; 54 55 /** @see #getFastPairRecord() */ newFastPairRecord(byte header, byte[] modelId)56 public static byte[] newFastPairRecord(byte header, byte[] modelId) { 57 return newFastPairRecord( 58 modelId.length == 3 ? modelId : ArrayUtils.concatByteArrays(new byte[] {header}, 59 modelId)); 60 } 61 62 /** @see #getFastPairRecord() */ newFastPairRecord(byte[] serviceData)63 public static byte[] newFastPairRecord(byte[] serviceData) { 64 int length = /* length of type and service UUID = */ 3 + serviceData.length; 65 return Hex.stringToBytes( 66 String.format("02011E020AF0%02X162CFE%s", length, 67 Hex.bytesToStringUppercase(serviceData))); 68 } 69 70 // This is an example extended inquiry response for a phone with PANU 71 // and Hands-free Audio Gateway 72 public static byte[] eir_1 = { 73 0x06, // Length of this Data 74 0x09, // <<Complete Local Name>> 75 'P', 76 'h', 77 'o', 78 'n', 79 'e', 80 0x05, // Length of this Data 81 0x03, // <<Complete list of 16-bit Service UUIDs>> 82 0x15, 83 0x11, // PANU service class UUID 84 0x1F, 85 0x11, // Hands-free Audio Gateway service class UUID 86 0x01, // Length of this data 87 0x05, // <<Complete list of 32-bit Service UUIDs>> 88 0x11, // Length of this data 89 0x07, // <<Complete list of 128-bit Service UUIDs>> 90 0x01, 91 0x02, 92 0x03, 93 0x04, 94 0x05, 95 0x06, 96 0x07, 97 0x08, // Made up UUID 98 0x11, 99 0x12, 100 0x13, 101 0x14, 102 0x15, 103 0x16, 104 0x17, 105 0x18, // 106 0x00 // End of Data (Not transmitted over the air 107 }; 108 109 // This is an example of advertising data with AD types 110 public static byte[] adv_1 = { 111 0x02, // Length of this Data 112 0x01, // <<Flags>> 113 0x01, // LE Limited Discoverable Mode 114 0x0A, // Length of this Data 115 0x09, // <<Complete local name>> 116 'P', 'e', 'd', 'o', 'm', 'e', 't', 'e', 'r' 117 }; 118 119 // This is an example of advertising data with positive TX Power 120 // Level. 121 public static byte[] adv_2 = { 122 0x02, // Length of this Data 123 0x0a, // <<TX Power Level>> 124 127 // Level = 127 125 }; 126 127 // Example data including a service data block 128 public static byte[] sd1 = { 129 0x02, // Length of this Data 130 0x01, // <<Flags>> 131 0x04, // BR/EDR Not Supported. 132 0x03, // Length of this Data 133 0x02, // <<Incomplete List of 16-bit Service UUIDs>> 134 0x04, 135 0x18, // TX Power Service UUID 136 0x1e, // Length of this Data 137 (byte) 0x16, // <<Service Specific Data>> 138 // Service UUID 139 (byte) 0xe0, 140 0x00, 141 // gBeacon Header 142 0x15, 143 // Running time ENCRYPT 144 (byte) 0xd2, 145 0x77, 146 0x01, 147 0x00, 148 // Scan Freq ENCRYPT 149 0x32, 150 0x05, 151 // Time in slow mode 152 0x00, 153 0x00, 154 // Time in fast mode 155 0x7f, 156 0x17, 157 // Subset of UID 158 0x56, 159 0x00, 160 // ID Mask 161 (byte) 0xd4, 162 0x7c, 163 0x18, 164 // RFU (reserved) 165 0x00, 166 // GUID = decimal 1297482358 167 0x76, 168 0x02, 169 0x56, 170 0x4d, 171 0x00, 172 // Ranging Payload Header 173 0x24, 174 // MAC of scanning address 175 (byte) 0xa4, 176 (byte) 0xbb, 177 // NORM RX RSSI -67dBm 178 (byte) 0xb0, 179 // NORM TX POWER -77dBm, so actual TX POWER = -36dBm 180 (byte) 0xb3, 181 // Note based on the values aboves PATH LOSS = (-36) - (-67) = 31dBm 182 // Below zero padding added to test it is handled correctly 183 0x00 184 }; 185 186 // An Eddystone UID frame. go/eddystone for more info 187 public static byte[] eddystone_header_and_uuid = { 188 // BLE Flags 189 (byte) 0x02, 190 (byte) 0x01, 191 (byte) 0x06, 192 // Service UUID 193 (byte) 0x03, 194 (byte) 0x03, 195 (byte) 0xaa, 196 (byte) 0xfe, 197 // Service data header 198 (byte) 0x17, 199 (byte) 0x16, 200 (byte) 0xaa, 201 (byte) 0xfe, 202 // Eddystone frame type 203 (byte) 0x00, 204 // Ranging data 205 (byte) 0xb3, 206 // Eddystone ID namespace 207 (byte) 0x0a, 208 (byte) 0x09, 209 (byte) 0x08, 210 (byte) 0x07, 211 (byte) 0x06, 212 (byte) 0x05, 213 (byte) 0x04, 214 (byte) 0x03, 215 (byte) 0x02, 216 (byte) 0x01, 217 // Eddystone ID instance 218 (byte) 0x16, 219 (byte) 0x15, 220 (byte) 0x14, 221 (byte) 0x13, 222 (byte) 0x12, 223 (byte) 0x11, 224 // RFU 225 (byte) 0x00, 226 (byte) 0x00 227 }; 228 } 229