• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 BLE_DEFS_H
17 #define BLE_DEFS_H
18 
19 #include <string>
20 
21 #include "bt_def.h"
22 #include "bt_uuid.h"
23 #include "gap_le_if.h"
24 
25 /*
26  * @brief The bluetooth system.
27  */
28 namespace OHOS {
29 namespace bluetooth {
30 /// const
31 constexpr uint8_t BLE_IRK_HEX_ELN = 0x10;
32 constexpr uint8_t BLE_IRK_RAND_HEX_LEN = 0x03;
33 constexpr uint8_t BLE_IRK_RAND_ELN = 0x1F;
34 constexpr uint8_t BLE_IRK_RAND_LEFT_SHIFT = 0x04;
35 constexpr uint8_t SHORTENED_LOCAL_NAME = 0X08;
36 constexpr uint8_t COMPLETE_LOCAL_NAME = 0X09;
37 constexpr uint8_t MANUFACTURER_SPECIFIC_DATA = 0XFF;
38 constexpr uint8_t TX_POWER_LEVEL = 0x0A;
39 constexpr uint8_t SERVICE_DATA_16_BIT_UUID = 0X16;
40 constexpr uint8_t SERVICE_DATA_32_BIT_UUID = 0X20;
41 constexpr uint8_t SERVICE_DATA_128_BIT_UUID = 0X21;
42 constexpr uint8_t BLE_DIV_RESULT_TWO = 0x02;
43 
44 /// Maximum advertising data length that can fit in a legacy PDU.
45 constexpr uint8_t BLE_LEGACY_ADV_DATA_LEN_MAX = 0x1F;
46 constexpr uint8_t BLE_LEGACY_SCAN_RSP_DATA_LEN_MAX = 0x1F;
47 constexpr uint8_t BLE_EX_ADV_PAYLOAD_DATA_LEN = 0XBF;
48 
49 /// Batch scan params
50 constexpr uint16_t BLE_SCAN_MODE_BATCH_LOW_POWER_WINDOW_MS = 500;
51 constexpr uint16_t BLE_SCAN_MODE_BATCH_LOW_POWER_INTERVAL_MS = 45000;
52 constexpr uint16_t BLE_SCAN_MODE_BATCH_BALANCED_WINDOW_MS = 1000;
53 constexpr uint16_t BLE_SCAN_MODE_BATCH_BALANCED_INTERVAL_MS = 45000;
54 constexpr uint16_t BLE_SCAN_MODE_BATCH_LOW_LATENCY_WINDOW_MS = 1500;
55 constexpr uint16_t BLE_SCAN_MODE_BATCH_LOW_LATENCY_INTERVAL_MS = 45000;
56 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P2_60_3000_WINDOW_MS = 60;
57 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P2_60_3000_INTERVAL_MS = 3000;
58 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P10_60_600_WINDOW_MS = 60;
59 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P10_60_600_INTERVAL_MS = 600;
60 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P25_60_240_WINDOW_MS = 60;
61 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P25_60_240_INTERVAL_MS = 240;
62 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P100_1000_1000_WINDOW_MS = 1000;
63 constexpr uint16_t BLE_SCAN_MODE_BATCH_OP_P100_1000_1000_INTERVAL_MS = 1000;
64 
65 /// Invalid MAC Address
66 const std::string BLE_INVALID_MAC_ADDRESS = "00:00:00:00:00:00";
67 const std::string BLE_DEFAULT_DEVICE_NAME = "BluetoothDevice";
68 constexpr uint8_t BLE_DEFAULT_IO = 0x01;
69 const std::string BLE_DEFAULT_LOCAL_PASSKEY = "0x12346";
70 constexpr uint8_t BLE_DEFAULT_ROLES = 0x0F;
71 constexpr uint8_t BLE_DEFAULT_MODEL1_LEVEL = 0x00;
72 constexpr uint8_t BLE_DEFAULT_MODEL2_LEVEL = 0x00;
73 constexpr bool BLE_DEFAULT_SECURITY = false;
74 constexpr uint8_t BLE_DEFAULT_SCAN_MODE = 0x03;
75 
76 constexpr uint8_t BLE_NON_RES_PRI_ADDR = 0x3F;
77 constexpr uint8_t BLE_STATIC_PRI_ADDR = 0xC0;
78 
79 constexpr int BLE_THREAD_WAIT_TIMEOUT = 5;
80 
81 constexpr int BLE_CHANGE_RPA_ADDRESS_INTERVAL = 15 * 60 * 1000;
82 constexpr uint16_t GATT_UUID_GAP_DEVICE_NAME = 0x2A00;
83 
84 const Uuid::UUID128Bit DEFAULT_UUID_MASK = {
85     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
86     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
87 };
88 
89 /// Filter status
90 typedef enum {
91     BLE_SCAN_FILTER_STATUS_IDLE = 0,
92     BLE_SCAN_FILTER_STATUS_WORKING,
93     BLE_SCAN_FILTER_STATUS_BAD,
94 } FILTER_STATUS;
95 
96 /// Advertising status
97 typedef enum {
98     ADVERTISE_NOT_STARTED = -1,
99     ADVERTISE_SUCCESS = 0,
100     ADVERTISE_FAILED_DATA_TOO_LARGE,
101     ADVERTISE_FAILED_TOO_MANY_ADVERTISERS,
102     ADVERTISE_FAILED_ALREADY_STARTED,
103     ADVERTISE_FAILED_INTERNAL_ERROR,
104     ADVERTISE_FAILED_FEATURE_UNSUPPORTED
105 } ADVERTISE_STATUS;
106 
107 /// Local config
108 typedef enum {
109     BLE_CONFIG_LOCAL_NAME = 0x00,
110     BLE_CONFIG_LOCAL_ADDRESS = 0x01,
111     BLE_CONFIG_ADAPTER_BONDED_MODE = 0x02,
112 } BLE_CONFIG;
113 
114 /// ble bondable mode
115 typedef enum { BLE_BONDABLE_MODE_NONE = 0x00, BLE_BONDABLE_MODE_ON = 0x01 } BLE_BONDABLE_MODE;
116 
117 /// Scan callback type
118 typedef enum { CALLBACK_TYPE_ALL_MATCHES = 0x00, CALLBACK_TYPE_FIRST_MATCH = 0x01 } CALLBACK_TYPE;
119 
120 /// stop all adv type
121 typedef enum {
122     STOP_ADV_TYPE_SINGLE = 0x00,
123     STOP_ADV_TYPE_ALL = 0x01,
124     STOP_ADV_TYPE_RESOLVING_LIST = 0x02
125 } STOP_ALL_ADV_TYPE;
126 
127 typedef enum { STOP_SCAN_TYPE_NOR = 0x00, STOP_SCAN_TYPE_RESOLVING_LIST = 0x01 } STOP_SCAN_TYPE;
128 
129 /// Scan status
130 typedef enum {
131     SCAN_NOT_STARTED = -1,
132     SCAN_SUCCESS = 0,
133     SCAN_FAILED_ALREADY_STARTED,
134     SCAN_FAILED_APPLICATION_REGISTRATION_FAILED,
135     SCAN_FAILED_INTERNAL_ERROR,
136     SCAN_FAILED_FEATURE_UNSUPPORTED,
137     SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES
138 } SCAN_STATUS;
139 
140 typedef enum {
141     BLE_APPEARANCE_UNKNOWN = 0x0000,
142     BLE_APPEARANCE_GENERIC_PHONE = 0x0040,
143     BLE_APPEARANCE_GENERIC_COMPUTER = 0x0080,
144     BLE_APPEARANCE_GENERIC_WATCH = 0x00C0,
145     BLE_APPEARANCE_SPORTS_WATCH = 0x00C1,
146     BLE_APPEARANCE_GENERIC_CLOCK = 0x0100,
147     BLE_APPEARANCE_GENERIC_DISPLAY = 0x0140,
148     BLE_APPEARANCE_GENERIC_REMOTE = 0x0180,
149     BLE_APPEARANCE_GENERIC_EYEGLASSES = 0x01C0,
150     BLE_APPEARANCE_GENERIC_TAG = 0x0200,
151     BLE_APPEARANCE_GENERIC_KEYRING = 0x0240,
152     BLE_APPEARANCE_GENERIC_MEDIA_PLAYER = 0x0280,
153     BLE_APPEARANCE_GENERIC_BARCODE_SCANNER = 0x02C0,
154     BLE_APPEARANCE_GENERIC_THERMOMETER = 0x0300,
155     BLE_APPEARANCE_THERMOMETER_EAR = 0x0301,
156     BLE_APPEARANCE_GENERIC_HEART_RATE = 0x0340,
157     BLE_APPEARANCE_HEART_RATE_BELT = 0x0341,
158     BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE = 0x0380,
159     BLE_APPEARANCE_BLOOD_PRESSURE_ARM = 0x0381,
160     BLE_APPEARANCE_BLOOD_PRESSURE_WRIST = 0x0382,
161     BLE_APPEARANCE_GENERIC_HID = 0x03C0,
162     BLE_APPEARANCE_HID_KEYBOARD = 0x03C1,
163     BLE_APPEARANCE_HID_MOUSE = 0x03C2,
164     BLE_APPEARANCE_HID_JOYSTICK = 0x03C3,
165     BLE_APPEARANCE_HID_GAMEPAD = 0x03C4,
166     BLE_APPEARANCE_HID_DIGITIZER_TABLET = 0x03C5,
167     BLE_APPEARANCE_HID_CARD_READER = 0x03C6,
168     BLE_APPEARANCE_HID_DIGITAL_PEN = 0x03C7,
169     BLE_APPEARANCE_HID_BARCODE_SCANNER = 0x03C8,
170     BLE_APPEARANCE_GENERIC_GLUCOSE = 0x0400,
171     BLE_APPEARANCE_GENERIC_WALKING = 0x0440,
172     BLE_APPEARANCE_WALKING_IN_SHOE = 0x0441,
173     BLE_APPEARANCE_WALKING_ON_SHOE = 0x0442,
174     BLE_APPEARANCE_WALKING_ON_HIP = 0x0443,
175     BLE_APPEARANCE_GENERIC_CYCLING = 0x0480,
176     BLE_APPEARANCE_CYCLING_COMPUTER = 0x0481,
177     BLE_APPEARANCE_CYCLING_SPEED = 0x0482,
178     BLE_APPEARANCE_CYCLING_CADENCE = 0x0483,
179     BLE_APPEARANCE_CYCLING_POWER = 0x0484,
180     BLE_APPEARANCE_CYCLING_SPEED_CADENCE = 0x0485,
181     BLE_APPEARANCE_GENERIC_PULSE_OXIMETER = 0x0C40,
182     BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP = 0x0C41,
183     BLE_APPEARANCE_PULSE_OXIMETER_WRIST = 0x0C42,
184     BLE_APPEARANCE_GENERIC_WEIGHT = 0x0C80,
185     BLE_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE = 0x0CC0,
186     BLE_APPEARANCE_POWERED_WHEELCHAIR = 0x0CC1,
187     BLE_APPEARANCE_MOBILITY_SCOOTER = 0x0CC2,
188     BLE_APPEARANCE_GENERIC_CONTINUOUS_GLUCOSE_MONITOR = 0x0D00,
189     BLE_APPEARANCE_GENERIC_INSULIN_PUMP = 0x0D40,
190     BLE_APPEARANCE_INSULIN_PUMP_DURABLE_PUMP = 0x0D41,
191     BLE_APPEARANCE_INSULIN_PUMP_PATCH_PUMP = 0x0D44,
192     BLE_APPEARANCE_INSULIN_PEN = 0x0D48,
193     BLE_APPEARANCE_GENERIC_MEDICATION_DELIVERY = 0x0D80,
194     BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS = 0x1440,
195     BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION = 0x1441,
196     BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV = 0x1442,
197     BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD = 0x1443,
198     BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV = 0x1444
199 } BLE_APPEARANCE;
200 
201 /// GAP BLE callback event type
202 typedef enum {
203     BLE_GAP_ADV_DATA_SET_COMPLETE_EVT = 0,       /// advertising data set complete
204     BLE_GAP_ADV_SCAN_RSP_DATA_SET_COMPLETE_EVT,  /// scan response data set complete
205     BLE_GAP_ADV_PARAM_SET_COMPLETE_EVT,          /// advertising parameter set complete
206     BLE_GAP_ADV_READ_TXPOWER_EVT,                /// advertising read tx power
207     BLE_GAP_ADV_START_COMPLETE_EVT,              /// start advertising complete
208     BLE_GAP_ADV_STOP_COMPLETE_EVT,               /// stop adv complete
209     BLE_GAP_ADV_DATA_RAW_SET_COMPLETE_EVT,       /// raw advertising data set complete
210 
211     BLE_GAP_EX_ADV_SET_RAND_ADDR_RESULT_EVT,           /// extend advertising data set complete
212     BLE_GAP_EX_ADV_PARAM_SET_COMPLETE_EVT,             /// extend advertising parameter set complete
213     BLE_GAP_EX_ADV_DATA_SET_COMPLETE_EVT,              /// extend advertising data set complete
214     BLE_GAP_EX_ADV_SCAN_RSP_DATA_SET_COMPLETE_EVT,     /// extend scan response data set complete
215     BLE_GAP_EX_ADV_START_COMPLETE_EVT,                 /// start extend advertising complete
216     BLE_GAP_EX_ADV_STOP_COMPLETE_EVT,                  /// stop extend advertising complete
217     BLE_GAP_EX_ALL_ADV_STOP_COMPLETE_EVT,              /// stop all extend advertising complete
218     BLE_GAP_EX_RESOLVING_LIST_ADV_STOP_COMPLETE_EVT,   /// stop all resolving list extend advertising complete
219     BLE_GAP_EX_RESOLVING_LIST_ADV_START_COMPLETE_EVT,  /// start all resolving list extend advertising complete
220     BLE_GAP_EX_ADV_REMOVE_HANDLE_RESULT_EVT,           /// extend advertising remove handle complete
221     BLE_GAP_EX_ADV_CLEAR_HANDLE_RESULT_EVT,            /// extend advertising clear handle complete
222     BLE_GAP_EX_ADV_SCAN_REQUEST_RECEIVED_EVT,          /// extend advertising scan request received complete
223     BLE_GAP_EX_ADC_TERMINATED_ADV_SET_EVT,             /// extend advertising terminated adv set event
224 
225     BLE_GAP_SCAN_PARAM_SET_COMPLETE_EVT,                 /// scan parameters set complete
226     BLE_GAP_SCAN_RESULT_EVT,                             /// one scan result ready each time
227     BLE_GAP_SCAN_DELAY_REPORT_RESULT_EVT,                /// one scan result ready each time
228     BLE_GAP_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT,          /// raw scan response data set complete
229     BLE_GAP_SCAN_START_COMPLETE_EVT,                     /// start scan complete
230     BLE_GAP_SCAN_STOP_COMPLETE_EVT,                      /// stop scan complete
231     BLE_GAP_RESOLVING_LIST_ADV_SCAN_STOP_COMPLETE_EVT,   /// stop all resolvint list scan complete
232     BLE_GAP_RESOLVING_LIST_ADV_SCAN_START_COMPLETE_EVT,  /// start all resolvint list scan complete
233 
234     BLE_GAP_EX_SCAN_PARAM_SET_COMPLETE_EVT,                 /// scan parameters set complete
235     BLE_GAP_EX_SCAN_RESULT_EVT,                             /// one scan result ready each time
236     BLE_GAP_EX_SCAN_DELAY_REPORT_RESULT_EVT,                /// one scan result ready each time
237     BLE_GAP_EX_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT,          /// raw scan response data set complete
238     BLE_GAP_EX_SCAN_START_COMPLETE_EVT,                     /// start scan complete
239     BLE_GAP_EX_SCAN_STOP_COMPLETE_EVT,                      /// stop scan complete
240     BLE_GAP_EX_RESOLVING_LIST_ADV_SCAN_STOP_COMPLETE_EVT,   /// stop all resolvint list scan complete
241     BLE_GAP_EX_RESOLVING_LIST_ADV_SCAN_START_COMPLETE_EVT,  /// start all resolvint list scan complete
242 
243     BLE_GATT_DEVICE_INFO_REGISTER_STSTUS,  /// device information
244     BLE_GATT_GAP_SERVICE_REGISTER_STSTUS,  /// gap service
245 
246     BLE_GAP_ENCRYPTION_COMPLETE_EVT,
247     BLE_GAP_LE_LOCAL_ENCRYPTION_KEY_REQ_EVT,
248     BLE_GAP_LE_REMOTE_ENCRYPTION_KEY_REQ_EVT,
249     BLE_GAP_LE_SIGN_COUNTER_CHANGE_NOTIF_EVT,
250     BLE_GAP_LE_REQ_SIGNING_ALGORITHM_INFO_EVT,
251     BLE_GAP_LE_PAIR_FEATURE_REQ_EVT,
252     BLE_GAP_LE_PAIR_FEATURE_IND_EVT,
253     BLE_GAP_LE_PAIR_METHOD_NOTI_EVT,
254     BLE_GAP_LE_PAIR_KEY_PRESS_NOTI_EVT,
255     BLE_GAP_LE_PAIR_PASSKEY_REQ_EVT,
256     BLE_GAP_LE_PAIR_PASSKEY_NOTI_EVT,
257     BLE_GAP_LE_PAIR_OOB_REQ_EVT,
258     BLE_GAP_LE_PAIR_SC_OOB_REQ_EVT,
259     BLE_GAP_LE_PAIR_SC_USER_CONFIRM_REQ_EVT,
260     BLE_GAP_LE_PAIR_COMELETE_EVT,
261     BLE_GAP_LE_PAIR_KEY_NOTI_EVT,
262     BLE_GAP_LE_REQUEST_SECURITY_RESULT,
263 } BLE_GAP_CB_EVENT;
264 
265 typedef union {
266     struct EncryptionComplete {
267         uint8_t status;
268         BtAddr peerAddr;
269     } encryptionComplete_;
270 
271     struct LeLocalEncryptionKeyReqEvent {
272         BtAddr addr;
273         uint64_t rand;
274         uint16_t ediv;
275     } leLocalEncryptionKeyReqEvent_;
276 
277     struct LeRemoteEncryptionKeyReqEvent {
278         BtAddr addr;
279     } leRemoteEncryptionKeyReqEvent_;
280 
281     struct LeSignCounterChangeNotification {
282         BtAddr addr;
283         GAP_SignCounterType type;
284         uint32_t counter;
285     } leSignCounterChangeNotification_;
286 
287     struct GapRequestSigningAlgorithmInfo {
288         BtAddr addr;
289     } gapRequestSigningAlgorithmInfo_;
290 
291     struct LePairFeatureReq {
292         BtAddr peerAddr;
293         bool localPair;
294     } lePairFeatureReq_;
295 
296     struct LePairFeatureInd {
297         BtAddr addr;
298         GapLePairFeature remoteFrature;
299     } lePairFeatureInd_;
300 
301     struct LePairMethodNotify {
302         BtAddr addr;
303         uint8_t pairMethod;
304     } lePairMethodNotify_;
305 
306     struct LePairKeyPressNotification {
307         BtAddr addr;
308         uint8_t pressType;
309     } lePairKeyPressNotification_;
310 
311     struct LePairPassKeyReq {
312         BtAddr addr;
313     } lePairPassKeyReq_;
314 
315     struct LePairPassKeyNotification {
316         BtAddr addr;
317         uint32_t number;
318     } lePairPassKeyNotification_;
319 
320     struct LePairOobReq {
321         BtAddr addr;
322     } lePairOobReq_;
323 
324     struct LePairScOobReq {
325         BtAddr addr;
326     } lePairScOob_req_;
327 
328     struct LePairScUserConfirmReq {
329         BtAddr addr;
330         uint32_t number;
331     } lePairScUserConfirmReq_;
332 
333     struct LePairComplete {
334         BtAddr addr;
335         uint8_t result;
336         uint8_t keyType;
337     } lePairComplete_;
338 
339     struct LePairKeyNotify {
340         BtAddr addr;
341         LeEncKey remoteEncKey;
342         bool hasRemoteEncKey;
343         LeIdKey remoteIdKey;
344         bool hasRemoteIdKey;
345         LeSignKey remoteSignKey;
346         bool hasRemoteSignKey;
347         LeEncKey localEncKey;
348         bool hasLocalEncKey;
349         LeSignKey localSignKey;
350         bool hasLocalSignKey;
351     } lePairKeyNotify_;
352 
353     struct LeRequestSecurityResult {
354         BtAddr addr;
355         uint8_t result;
356         GAP_LeSecurityStatus status;
357     } leRequestSecurityResult_;
358 } BleGapCallbackParam;
359 
360 /// Features supported by the controller.
361 /// BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B - 4.6
362 typedef enum {
363     LE_ENCRYPTION = 0,
364     CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
365     EXTENDED_REJECT_INDICATION,
366     SLAVE_INITIATED_FEATURES_EXCHANGE,
367     LE_PING,
368     LE_DATA_PACKET_LENGTH_EXTENSION,
369     LL_PRIVACY,
370     EXTENDED_SCANNER_FILTER_POLICIES,
371     LE_2M_PHY,
372     STABLE_MODULATION_INDEX_TRANSMITTER,
373     STABLE_MODULATION_INDEX_RECEIVER,
374     LE_CODED_PHY,
375     LE_EXTENDED_ADVERTISING,
376     LE_PERIODIC_ADVERTISING,
377     CHANNEL_SELECTION_ALGORITHM_2,
378     LE_POWER_CLASS
379 } FEATURE_SUPPORTED;
380 
381 /// Ble scan type
382 typedef enum {
383     BLE_SCAN_TYPE_PASSIVE = 0x00,  /// Passive scan
384     BLE_SCAN_TYPE_ACTIVE = 0x01,   /// Active scan
385 } BLE_SCAN_TYPE;
386 
387 /// Ble scan mode
388 typedef enum {
389     BLE_SCAN_MODE_NON_DISC = 0x00,  /// Non Discoverable
390     BLE_SCAN_MODE_GENERAL = 0x01,   /// General
391     BLE_SCAN_MODE_LIMITED = 0x02,   /// Limited
392     BLE_SCAN_MODE_ALL = 0x03,       /// ALL
393 } BLE_SCAN_MODE;
394 
395 /// Ble scan filter type
396 typedef enum {
397     BLE_SCAN_FILTER_ALLOW_ALL = 0x00,  /// Accept all :
398     /// 1. advertisement packets except directed advertising packets not addressed to this device (default).
399     BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x01,  /// Accept only :
400     /// 1. advertisement packets from devices where the advertiser’s address is in the WH list.
401     /// 2. Directed advertising packets which are not addressed for this device shall be ignored.
402     BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x02,  /// Accept all :
403     /// 1. undirected advertisement packets, and
404     /// 2. directed advertising packets where the initiator address is a resolvable private address, and
405     /// 3. directed advertising packets addressed to this device.
406     BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x03,  /// Accept all :
407     /// 1. advertisement packets from devices where the advertiser’s address is in the WH list, and
408     /// 2. directed advertising packets where the initiator address is a resolvable private address, and
409     /// 3. directed advertising packets addressed to this device.
410 } BLE_SCAN_FILTER;
411 
412 /// Ble scan duplicate type
413 typedef enum {
414     BLE_SCAN_DUPLICATE_DISABLE =
415         0x00,  /// the Link Layer should generate advertising reports to the host for each packet received
416     BLE_SCAN_DUPLICATE_ENABLE = 0x01,  /// the Link Layer should filter out duplicate advertising reports to the Host
417     BLE_SCAN_DUPLICATE_MAX = 0x02,     /// 0x02 – 0xFF, Reserved for future use
418 } BLE_SCAN_DUPLICATE;
419 
420 /// Ble scan parameters
421 typedef struct {
422     BLE_SCAN_TYPE scanType;            /// Scan type
423     BLE_ADDR_TYPE ownAddrType;         /// Owner address type
424     BLE_SCAN_FILTER scanFilterPolicy;  /// Scan filter policy
425     uint16_t scanInterval;             /// Scan interval. This is defined as the time interval from
426     /// when the Controller started its last LE scan until it begins the subsequent LE scan.
427     /// Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
428     /// Time = N * 0.625 msec
429     /// Time Range: 2.5 msec to 10.24 seconds
430     uint16_t scanWindow;  /// Scan window. The duration of the LE scan. LE_Scan_Window
431     /// shall be less than or equal to LE_Scan_Interval
432     /// Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
433     /// Time = N * 0.625 msec
434     /// Time Range: 2.5 msec to 10240 msec
435     BLE_SCAN_DUPLICATE scanDuplicate;  /// The Scan_Duplicates parameter controls whether the Link Layer should filter
436     /// out duplicate advertising reports (BLE_SCAN_DUPLICATE_ENABLE) to the Host,
437     /// or if the Link Layer should generate advertising reports for each packet received
438 } BleScanParams;
439 
440 typedef enum {
441     ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,  /// Allow both scan and connection requests from anyone
442     ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY,   /// Allow both scan req from WH List devices and connection req fro anyone
443     ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST,   /// Allow both scan req from anyone and connection req from WH List devices
444     ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST,  /// Allow scan and connection requests from WH List devices
445 } BLE_ADV_FILTER;
446 
447 /// Advertising channel mask
448 typedef enum {
449     ADV_CHNL_37 = 0x01,
450     ADV_CHNL_38 = 0x02,
451     ADV_CHNL_39 = 0x04,
452     ADV_CHNL_ALL = 0x07,
453 } BLE_ADV_CHANNEL;
454 
455 /// Advertising mode
456 typedef enum {
457     ADV_TYPE_IND = 0x00,
458     ADV_TYPE_DIRECT_IND_HIGH = 0x01,
459     ADV_TYPE_SCAN_IND = 0x02,
460     ADV_TYPE_NONCONN_IND = 0x03,
461     ADV_TYPE_DIRECT_IND_LOW = 0x04,
462 } BLE_ADV_TYPE;
463 
464 /// Scan Event Type
465 typedef enum {
466     SCAN_ADV_IND = 0x00,
467     SCAN_ADV_DIRECT_IND = 0x01,
468     SCAN_ADV_SCAN_IND = 0x02,
469     SCAN_ADV_NONCONN_IND = 0x03,
470     SCAN_SCAN_RSP = 0x04,
471 } BLE_SCAN_EVENT_TYPE;
472 
473 /// Advertising parameters
474 typedef struct {
475     uint16_t advMinInterval;  /// Minimum advertising interval for
476     /// undirected and low duty cycle directed advertising.
477     /// Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
478     /// ime = N * 0.625 msec Time Range: 20 ms to 10.24 sec
479     uint16_t advMaxInterval;  /// Maximum advertising interval for
480     /// undirected and low duty cycle directed advertising.
481     /// Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
482     /// Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec Advertising max interval
483     BLE_ADV_TYPE advType;            /// Advertising type
484     BLE_ADDR_TYPE ownAddrType;       /// Owner bluetooth device address type
485     BtAddr peerAddr;                 /// Peer device bluetooth device address
486     BLE_ADDR_TYPE peerAddrType;      /// Peer device bluetooth device address type
487     BLE_ADV_CHANNEL channelMap;      /// Advertising channel map
488     BLE_ADV_FILTER advFilterPolicy;  /// Advertising filter policy
489 } BleAdvParams;
490 }  // namespace bluetooth
491 }  // namespace OHOS
492 #endif
493