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