• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 SOFTBUS_ADAPTER_BLE_GATT_H
17 #define SOFTBUS_ADAPTER_BLE_GATT_H
18 
19 #include "softbus_adapter_bt_common.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 // Bluetooth scan duty cycle, unit: ms
28 #define SOFTBUS_BLE_SCAN_INTERVAL_P2 3000
29 #define SOFTBUS_BLE_SCAN_INTERVAL_P10 600
30 #define SOFTBUS_BLE_SCAN_INTERVAL_P25 240
31 #define SOFTBUS_BLE_SCAN_INTERVAL_P100 1000
32 #define SOFTBUS_BLE_SCAN_WINDOW_P2 60
33 #define SOFTBUS_BLE_SCAN_WINDOW_P10 60
34 #define SOFTBUS_BLE_SCAN_WINDOW_P25 60
35 #define SOFTBUS_BLE_SCAN_WINDOW_P100 1000
36 
37 typedef enum {
38     SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00,
39     SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
40     SOFTBUS_BLE_EVT_CONNECTABLE = 0x01,
41     SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05,
42     SOFTBUS_BLE_EVT_SCANNABLE = 0x02,
43     SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED = 0x06,
44     SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE = 0x10,
45     SOFTBUS_BLE_EVT_LEGACY_SCANNABLE = 0x12,
46     SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE = 0x13,
47     SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15,
48     SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A,
49     SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B
50 } SoftBusBleScanResultEvtType;
51 
52 typedef enum {
53     SOFTBUS_BLE_PUBLIC_DEVICE_ADDRESS = 0x00,
54     SOFTBUS_BLE_RANDOM_DEVICE_ADDRESS = 0x01,
55     SOFTBUS_BLE_PUBLIC_IDENTITY_ADDRESS = 0x02,
56     SOFTBUS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03,
57     SOFTBUS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE,
58     SOFTBUS_BLE_NO_ADDRESS = 0xFF,
59 } SoftBusBleScanResultAddrType;
60 
61 typedef enum {
62     SOFTBUS_BLE_SCAN_TYPE_PASSIVE = 0x00,
63     SOFTBUS_BLE_SCAN_TYPE_ACTIVE,
64 } SoftBusBleScanType;
65 
66 typedef enum {
67     SOFTBUS_BLE_SCAN_PHY_NO_PACKET = 0x00,
68     SOFTBUS_BLE_SCAN_PHY_1M = 0x01,
69     SOFTBUS_BLE_SCAN_PHY_2M = 0x02,
70     SOFTBUS_BLE_SCAN_PHY_CODED = 0x03
71 } SoftBusBleScanResultPhyType;
72 
73 typedef enum {
74     SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00,
75     SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST,
76     SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA,
77     SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA
78 } SoftBusBleScanFilterPolicy;
79 
80 typedef enum {
81     SOFTBUS_BLE_ADV_IND = 0x00,
82     SOFTBUS_BLE_ADV_DIRECT_IND_HIGH = 0x01,
83     SOFTBUS_BLE_ADV_SCAN_IND = 0x02,
84     SOFTBUS_BLE_ADV_NONCONN_IND = 0x03,
85     SOFTBUS_BLE_ADV_DIRECT_IND_LOW  = 0x04,
86 } SoftBusBleAdvType;
87 
88 typedef enum {
89     SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
90     SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01,
91     SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02,
92     SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03,
93 } SoftBusBleAdvFilter;
94 
95 typedef struct {
96     unsigned short scanInterval;
97     unsigned short scanWindow;
98     unsigned char scanType;
99     unsigned char scanPhy;
100     unsigned char scanFilterPolicy;
101 } SoftBusBleScanParams;
102 
103 typedef struct {
104     char *address;
105     char *deviceName;
106     unsigned int serviceUuidLength;
107     unsigned char *serviceUuid;
108     unsigned char *serviceUuidMask;
109     unsigned int serviceDataLength;
110     unsigned char *serviceData;
111     unsigned char *serviceDataMask;
112     unsigned int manufactureDataLength;
113     unsigned char *manufactureData;
114     unsigned char *manufactureDataMask;
115     unsigned short manufactureId;
116 } SoftBusBleScanFilter;
117 
118 typedef enum {
119     SOFTBUS_BLE_DATA_COMPLETE = 0x00,
120     SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME = 0x01,
121     SOFTBUS_BLE_DATA_INCOMPLETE_TRUNCATED = 0x02,
122 } SoftBusScanResultDataStatus;
123 
124 typedef struct {
125     unsigned char eventType;
126     unsigned char dataStatus;
127     unsigned char addrType;
128     SoftBusBtAddr addr;
129     unsigned char primaryPhy;
130     unsigned char secondaryPhy;
131     unsigned char advSid;
132     char txPower;
133     char rssi;
134     unsigned short periodicAdvInterval;
135     unsigned char directAddrType;
136     SoftBusBtAddr directAddr;
137     unsigned char advLen;
138     unsigned char *advData;
139 } SoftBusBleScanResult;
140 
141 typedef struct {
142     void (*OnScanStart)(int listenerId, int status);
143     void (*OnScanStop)(int listenerId, int status);
144     void (*OnScanResult)(int listenerId, const SoftBusBleScanResult *scanResultdata);
145 } SoftBusScanListener;
146 
147 typedef struct {
148     unsigned short advLength;
149     char *advData;
150     unsigned short scanRspLength;
151     char *scanRspData;
152 } SoftBusBleAdvData;
153 
154 typedef struct {
155     int minInterval;
156     int maxInterval;
157     unsigned char advType;
158     unsigned char ownAddrType;
159     unsigned char peerAddrType;
160     SoftBusBtAddr peerAddr;
161     int channelMap;
162     unsigned char advFilterPolicy;
163     int txPower;
164     int duration;
165 } SoftBusBleAdvParams;
166 
167 typedef struct {
168     void (*AdvEnableCallback)(int advId, int status);
169     void (*AdvDisableCallback)(int advId, int status);
170     void (*AdvDataCallback)(int advId, int status);
171     void (*AdvUpdateCallback)(int advId, int status);
172 } SoftBusAdvCallback;
173 
174 int BleGattLockInit(void);
175 
176 int SoftBusAddScanListener(const SoftBusScanListener *listener);
177 
178 int SoftBusRemoveScanListener(int listenerId);
179 
180 int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize);
181 
182 int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param);
183 
184 int SoftBusStopScan(int listenerId);
185 
186 int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback);
187 
188 int SoftBusReleaseAdvChannel(int advId);
189 
190 int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data);
191 
192 int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param);
193 
194 int SoftBusStopAdv(int advId);
195 
196 int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param);
197 
198 int SoftBusReplaceAdvertisingAdv(int advId, const SoftBusBleAdvData *data);
199 
200 #ifdef __cplusplus
201 #if __cplusplus
202 }
203 #endif /* __cplusplus */
204 #endif /* __cplusplus */
205 #endif