1 /*
2  * Copyright (C) 2022 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 I_BLE_SCAN_FILTER_H
17 #define I_BLE_SCAN_FILTER_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 
23 #include "bt_uuid.h"
24 #include "btstack.h"
25 
26 namespace OHOS {
27 namespace bluetooth {
28 static const uint16_t FILTER_FLAG_ADDRESS = 0x0001;
29 static const uint16_t FILTER_FLAG_SERVICE_UUID = 0x0002;
30 static const uint16_t FILTER_FLAG_SOLICIT_UUID = 0x0004;
31 static const uint16_t FILTER_FLAG_NAME = 0x0008;
32 static const uint16_t FILTER_FLAG_MANUFACTURER_DATA = 0x0010;
33 static const uint16_t FILTER_FLAG_SERVICE_DATA = 0x0020;
34 
35 static const uint8_t BLE_SCAN_FILTER_FINISHED = 0;
36 static const uint8_t BLE_SCAN_FILTER_FAILD = 1;
37 
38 static const uint8_t BT_DEVICE_ADDRESS_TYPE_ALL = 0x02;
39 
40 struct BleScanFilterParam {
41     BtAddr address;
42     Uuid serviceUuid;
43     Uuid serviceUuidMask;
44     Uuid solicitationUuid;
45     Uuid solicitationUuidMask;
46     std::string name;
47     uint16_t manufacturerId = 0;
48     uint16_t manufacturerIdMask = 0xFFFF;
49     std::vector<uint8_t> manufacturerData;
50     std::vector<uint8_t> manufacturerDataMask;
51     std::vector<uint8_t> serviceData;
52     std::vector<uint8_t> serviceDataMask;
53     uint16_t filterFlag = 0;
54     uint8_t filtIndex = 0;
55 };
56 
57 struct BleScanFilterCallback {
58     void (*addBleScanFilterResult)(uint8_t result, void *context) = nullptr;
59     void (*deleteBleScanFilterResult)(uint8_t result, void *context) = nullptr;
60     void (*startBleScanFilterResult)(uint8_t result, void *context) = nullptr;
61     void (*stopBleScanFilterResult)(uint8_t result, void *context) = nullptr;
62     void *context = nullptr;
63 };
64 
65 class IBleScanFilter {
66 public:
67     virtual ~IBleScanFilter() = default;
68     virtual uint8_t GetMaxFilterNumber() = 0;
69     virtual int AddBleScanFilter(BleScanFilterParam filter, BleScanFilterCallback callback) = 0;
70     virtual int DeleteBleScanFilter(BleScanFilterParam filter, BleScanFilterCallback callback) = 0;
71     virtual int StartBleScanFilter(BleScanFilterCallback callback) = 0;
72     virtual int StopBleScanFilter(BleScanFilterCallback callback) = 0;
73 };
74 
75 using createBleScanFilter = IBleScanFilter* (*)(void);
76 using destroyBleScanFilter = void (*)(IBleScanFilter* p);
77 }  // namespace bluetooth
78 }  // namespace OHOS
79 #endif  // I_BLE_SCAN_FILTER_H
80