1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_BLUETOOTH_STANDARD_BLE_FILTER_MATCHER_H 17 #define OHOS_BLUETOOTH_STANDARD_BLE_FILTER_MATCHER_H 18 19 #include "ble_service_data.h" 20 #include "bluetooth_ble_scan_result.h" 21 #include "log.h" 22 23 namespace OHOS { 24 namespace Bluetooth { 25 enum class MatchResult { 26 MATCH, 27 MISMATCH, 28 }; 29 30 class BluetoothBleFilterMatcher { 31 public: 32 BluetoothBleFilterMatcher() = default; 33 ~BluetoothBleFilterMatcher() = default; 34 static MatchResult MatchesScanFilters(const std::vector<bluetooth::BleScanFilterImpl> &bleScanFilters, 35 const BluetoothBleScanResult &result); 36 static MatchResult MatchesScanFilter(const bluetooth::BleScanFilterImpl &filter, 37 const BluetoothBleScanResult &result); 38 static MatchResult MatchesAddress(const bluetooth::BleScanFilterImpl &filter, 39 const BluetoothBleScanResult &result); 40 static MatchResult MatchesName(const bluetooth::BleScanFilterImpl &filter, 41 const BluetoothBleScanResult &result); 42 static MatchResult MatchesServiceUuids(const bluetooth::BleScanFilterImpl &filter, 43 const BluetoothBleScanResult &result); 44 static MatchResult MatchesManufacturerDatas(const bluetooth::BleScanFilterImpl &filter, 45 const BluetoothBleScanResult &result); 46 static MatchResult MatchesServiceDatas(const bluetooth::BleScanFilterImpl &filter, 47 const BluetoothBleScanResult &result); 48 static bool MatchesUuidWithMask(bluetooth::Uuid filterUuid, bluetooth::Uuid uuid, bluetooth::Uuid uuidMask); 49 static std::string ParseServiceDataUUidToString(bluetooth::Uuid uuid, std::string data); 50 static bool MatchesData(std::vector<uint8_t> fData, std::string rData, std::vector<uint8_t> dataMask); 51 }; 52 } // namespace Bluetooth 53 } // namespace OHOS 54 #endif // OHOS_BLUETOOTH_STANDARD_BLE_FILTER_MATCHER_H