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 #ifndef CHRE_UTIL_NANOAPP_BLE_H_ 18 #define CHRE_UTIL_NANOAPP_BLE_H_ 19 20 #include <inttypes.h> 21 22 #include "chre_api/chre.h" 23 24 namespace chre { 25 26 namespace ble_constants { 27 28 /** 29 * The minimum threshold for RSSI. Used to filter out RSSI values below this. 30 */ 31 constexpr int8_t kRssiThreshold = -128; 32 33 /** 34 * The length of the UUID data at the beginning of the data in the BLE packet. 35 */ 36 constexpr uint16_t kGoogleUuidDataLength = 2; 37 38 /** 39 * The mask to get the UUID from the data in the BLE packet. 40 */ 41 constexpr uint8_t kGoogleUuidMask[kGoogleUuidDataLength] = {0xFF, 0xFF}; 42 43 /** 44 * The Google Eddystone BLE beacon UUID. 45 */ 46 constexpr uint8_t kGoogleEddystoneUuid[kGoogleUuidDataLength] = {0xAA, 0xFE}; 47 48 /** 49 * The Google Nearby Fastpair BLE beacon UUID. 50 */ 51 constexpr uint8_t kGoogleNearbyFastpairUuid[kGoogleUuidDataLength] = {0x2C, 52 0xFE}; 53 54 /** 55 * The number of generic filters (equal to the number of known beacons). 56 */ 57 constexpr uint8_t kNumScanFilters = 2; 58 } // namespace ble_constants 59 60 /** 61 * Create a BLE generic filter object. 62 * 63 * @param type the filter type. 64 * @param len the filter length. 65 * @param data the filter data. 66 * @param mask the filter mask. 67 * @return the filter. 68 */ 69 chreBleGenericFilter createBleGenericFilter(uint8_t type, uint8_t len, 70 const uint8_t *data, 71 const uint8_t *mask); 72 73 /** 74 * Creates a chreBleScanFilter that filters for the Google eddystone UUID, 75 * the Google nearby fastpair UUID, and a RSSI threshold of kRssiThreshold. 76 * 77 * @param filter (out) the output filter. 78 * @param genericFilters (out) the output generic filters 79 * array. 80 * @param numGenericFilters the size of the generic filters 81 * array. must be >= kNumScanFilters. 82 * 83 * @return true the operation was successful 84 * @return false the operation was not successful 85 */ 86 bool createBleScanFilterForKnownBeacons(struct chreBleScanFilter &filter, 87 chreBleGenericFilter *genericFilters, 88 uint8_t numGenericFilters); 89 90 } // namespace chre 91 92 #endif // CHRE_UTIL_NANOAPP_BLE_H_ 93