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 #include "chre/util/nanoapp/ble.h"
18
19 namespace chre {
20
21 using ble_constants::kGoogleEddystoneUuid;
22 using ble_constants::kGoogleNearbyFastpairUuid;
23 using ble_constants::kGoogleUuidMask;
24 using ble_constants::kNumScanFilters;
25 using ble_constants::kRssiThreshold;
26
createBleGenericFilter(uint8_t type,uint8_t len,const uint8_t * data,const uint8_t * mask)27 chreBleGenericFilter createBleGenericFilter(uint8_t type, uint8_t len,
28 const uint8_t *data,
29 const uint8_t *mask) {
30 chreBleGenericFilter filter;
31 memset(&filter, 0, sizeof(filter));
32 filter.type = type;
33 filter.len = len;
34 memcpy(filter.data, data, sizeof(uint8_t) * len);
35 memcpy(filter.dataMask, mask, sizeof(uint8_t) * len);
36 return filter;
37 }
38
createBleScanFilterForKnownBeacons(struct chreBleScanFilter & filter,chreBleGenericFilter * genericFilters,uint8_t numGenericFilters)39 bool createBleScanFilterForKnownBeacons(struct chreBleScanFilter &filter,
40 chreBleGenericFilter *genericFilters,
41 uint8_t numGenericFilters) {
42 if (numGenericFilters < kNumScanFilters) {
43 return false;
44 }
45 memset(&filter, 0, sizeof(filter));
46
47 genericFilters[0] = createBleGenericFilter(
48 CHRE_BLE_AD_TYPE_SERVICE_DATA_WITH_UUID_16_LE, kNumScanFilters,
49 kGoogleEddystoneUuid, kGoogleUuidMask);
50 genericFilters[1] = createBleGenericFilter(
51 CHRE_BLE_AD_TYPE_SERVICE_DATA_WITH_UUID_16_LE, kNumScanFilters,
52 kGoogleNearbyFastpairUuid, kGoogleUuidMask);
53
54 filter.rssiThreshold = kRssiThreshold;
55 filter.scanFilterCount = kNumScanFilters;
56 filter.scanFilters = genericFilters;
57 return true;
58 }
59
60 } // namespace chre
61