1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __ME_API__H__
6 #define __ME_API__H__
7 
8 #include "bluetooth.h"
9 
10 typedef uint8_t btif_event_type_t;
11 
12 #if defined(BTIF_HCI_HOST_FLOW_CONTROL) && defined (__IAG_BLE_INCLUDE__)
13 #define BTIF_BTEVENT_CONNECT_CPMPLETE       1
14 #endif /*  */
15 
16 #define BTIF_BTEVENT_INQUIRY_RESULT       1
17 
18 #define BTIF_BTEVENT_INQUIRY_COMPLETE     2
19 
20 #define BTIF_BTEVENT_INQUIRY_CANCELED     3
21 
22 #define BTIF_BTEVENT_LINK_CONNECT_IND     4
23 
24 #define BTIF_BTEVENT_SCO_CONNECT_IND      5
25 
26 #define BTIF_BTEVENT_LINK_DISCONNECT      6
27 
28 #define BTIF_BTEVENT_LINK_CONNECT_CNF     7
29 
30 #define BTIF_BTEVENT_LINK_CON_RESTRICT    8
31 
32 #define BTIF_BTEVENT_MODE_CHANGE          9
33 
34 #define BTIF_BTEVENT_ACCESSIBLE_CHANGE   10
35 
36 #define BTIF_BTEVENT_AUTHENTICATED       11
37 
38 #define BTIF_BTEVENT_ENCRYPTION_CHANGE   12
39 
40 #define BTIF_BTEVENT_SECURITY_CHANGE     13
41 
42 #define BTIF_BTEVENT_ROLE_CHANGE         14
43 
44 #define BTIF_BTEVENT_SCO_DISCONNECT      15
45 
46 #define BTIF_BTEVENT_SCO_CONNECT_CNF     16
47 
48 #define BTIF_BTEVENT_SIMPLE_PAIRING_COMPLETE       17
49 
50 #define BTIF_BTEVENT_REMOTE_FEATURES               18
51 
52 #define BTIF_BTEVENT_REM_HOST_FEATURES             19
53 
54 #define BTIF_BTEVENT_LINK_SUPERV_TIMEOUT_CHANGED   20
55 
56 #define BTIF_BTEVENT_SET_SNIFF_SUBRATING_PARMS_CNF 21
57 
58 #define BTIF_BTEVENT_SNIFF_SUBRATE_INFO            22
59 
60 #define BTIF_BTEVENT_SET_INQUIRY_MODE_CNF          23
61 
62 #define BTIF_BTEVENT_SET_INQ_TX_PWR_LVL_CNF        24
63 
64 #define BTIF_BTEVENT_SET_EXT_INQUIRY_RESP_CNF      25
65 
66 #define BTIF_BTEVENT_SET_ERR_DATA_REPORTING_CNF    26
67 
68 #define BTIF_BTEVENT_KEY_PRESSED                   27
69 
70 #define BTIF_BTEVENT_QOS_SETUP_COMPLETE            28
71 
72 #ifdef __TWS_RECONNECT_USE_BLE__
73 #define BTIF_BTEVENT_TWS_BLE_ADV_REPORT_EVENT      29
74 #endif /*  */
75 
76 /**  an ACL connection has received an internal data transmit
77  *  request while it is in hold, park or sniff mode. The data will still be
78  *  passed to the radio in park and sniff modes. However, hold mode will
79  *  block data transmit. It may be necessary to return the ACL to active
80  *  mode to restore normal data transfer.
81  */
82 #define BTIF_BTEVENT_ACL_DATA_NOT_ACTIVE 99
83 
84 /*
85 Indicate that an ACL connection is sending or receiving data
86 while it is in active mode. Then, keep resetting the sniff timer.
87 */
88 #define BTIF_BTEVENT_ACL_DATA_ACTIVE 98
89 /** Indicates that the HCI failed to initialize.
90  */
91 #define BTIF_BTEVENT_HCI_INIT_ERROR      100
92 
93 #define BTIF_BTEVENT_HCI_INITIALIZED     101
94 /** Indicates that a fatal error has occurred in the radio or the HCI transport.
95  */
96 #define BTIF_BTEVENT_HCI_FATAL_ERROR     102
97 
98 /** Indicates that the HCI has been deinitialized.
99  */
100 #define BTIF_BTEVENT_HCI_DEINITIALIZED   103
101 
102 /** Indicates that the HCI cannot be initialized.
103  */
104 #define BTIF_BTEVENT_HCI_FAILED          104
105 
106 #define BTIF_BTEVENT_HCI_COMMAND_SENT    105
107 
108 /** Indicates the name of a remote device or cancellation of a name request.
109  */
110 #define BTIF_BTEVENT_NAME_RESULT         30
111 
112 #define BTIF_BTEVENT_SCO_DATA_IND        31
113 
114 /** Outgoing SCO data has been sent and the packet is free for re-use by
115  *  the application.
116  */
117 #define BTIF_BTEVENT_SCO_DATA_CNF        32
118 
119 #define BTIF_BTEVENT_LINK_CONNECT_REQ    33
120 
121 /** Incoming link accept complete.  */
122 #define BTIF_BTEVENT_LINK_ACCEPT_RSP     34
123 
124 /** Incoming link reject complete. . */
125 #define BTEVENT_LINK_REJECT_RSP     35
126 
127 #define BTIF_BTEVENT_COMMAND_COMPLETE    36
128 
129 #define BTIF_BTEVENT_SCO_CONNECT_REQ     37
130 
131 /** Set Audio/Voice settings complete.  */
132 #define BTIF_BTEVENT_SCO_VSET_COMPLETE   38
133 
134 /** SCO link connection process started. */
135 #define BTIF_BTEVENT_SCO_STARTED         39
136 
137 /** Select Device operation complete, "p.select" is valid. */
138 #define BTIF_BTEVENT_DEVICE_SELECTED     40
139 
140 /** The eSCO connection has changed. "p.scoConnect" is valid.
141  */
142 #define BTIF_BTEVENT_SCO_CONN_CHNG       41
143 
144 /* Group: Security-related events. */
145 
146 /** Indicates access request is successful. "p.secToken" is valid. */
147 #define BTIF_BTEVENT_ACCESS_APPROVED     50
148 
149 /** Indicates access request failed. "p.secToken" is valid. */
150 #define BTIF_BTEVENT_ACCESS_DENIED       51
151 
152 /** Request authorization when "errCode" is BEC_NO_ERROR.
153  *  "p.remDev" is valid.
154  */
155 #define BTIF_BTEVENT_AUTHORIZATION_REQ   52
156 
157 /** Request a Pin for pairing when "errCode" is BEC_NO_ERROR.
158  *  "p.pinReq" is valid. If p.pinReq.pinLen is > 0 then SEC_SetPin()
159  *  must be called in response to this event with a pin length >=
160  *  p.pinReq.pinLen.
161  */
162 #define BTIF_BTEVENT_PIN_REQ             53
163 
164 /** Pairing operation is complete.
165  */
166 #define BTIF_BTEVENT_PAIRING_COMPLETE    54
167 
168 /** Authentication operation complete. "p.remDev" is valid. */
169 #define BTIF_BTEVENT_AUTHENTICATE_CNF    55
170 
171 /** Encryption operation complete. "p.remDev" is valid. */
172 #define BTIF_BTEVENT_ENCRYPT_COMPLETE    56
173 
174 /** Security mode 3 operation complete. "p.secMode" is valid. */
175 #define BTIF_BTIF_BTEVENT_SECURITY3_COMPLETE  57
176 
177 /** A link key is returned. "p.bdLinkKey" is valid.  */
178 #define BTIF_BTEVENT_RETURN_LINK_KEYS    58
179 
180 /** Out of Band data has been received from the host controller. */
181 #define BTIF_BTEVENT_LOCAL_OOB_DATA      59
182 
183 /** Request a Pass Key for simple pairing when "errCode" is BEC_NO_ERROR. The
184  *  application should call SEC_SetPassKey() to provide the passkey or reject
185  *  the request, and optionally save the link key.
186  */
187 #define BTIF_BTEVENT_PASS_KEY_REQ        60
188 
189 /** Request a User Confirmation for simple pairing when "errCode" is
190  *  BEC_NO_ERROR.
191  */
192 #define BTIF_BTEVENT_CONFIRM_NUMERIC_REQ            61
193 
194 #define BTIF_BTEVENT_DISPLAY_NUMERIC_IND            62
195 
196 #define BTIF_BTEVENT_CONN_PACKET_TYPE_CHNG          63
197 
198 #define BTIF_SDEVENT_QUERY_RSP                      70
199 
200 #define BTIF_SDEVENT_QUERY_ERR                      71
201 
202 #define BTIF_SDEVENT_QUERY_FAILED                   72
203 
204 #define BTIF_BTEVENT_SELECT_DEVICE_REQ              80
205 
206 #define BTIF_BTEVENT_DEVICE_ADDED                   81
207 
208 #define BTIF_BTEVENT_DEVICE_DELETED                 82
209 
210 #define BTIF_BTEVENT_MAX_SLOT_CHANGED               83
211 
212 #define BTIF_BTEVENT_SNIFFER_CONTROL_DONE           84
213 
214 #define BTIF_BTEVENT_LINK_POLICY_CHANGED            85
215 
216 #define BTIF_BTEVENT_DEFAULT_LINK_POLICY_CHANGED    86
217 
218 #define BTIF_BTEVENT_BES_AUD_CONNECTED              200
219 
220 #define BTIF_BTEVENT_BES_AUD_DISCONNECTED           201
221 
222 #define BTIF_STACK_LINK_DISCONNECT_COMPLETE         220
223 
224 typedef uint32_t btif_event_mask_t;
225 
226 #define BTIF_BEM_NO_EVENTS                    0x00000000
227 #define BTIF_BEM_INQUIRY_RESULT               0x00000001
228 #define BTIF_BEM_INQUIRY_COMPLETE             0x00000002
229 #define BTIF_BEM_INQUIRY_CANCELED             0x00000004
230 #define BTIF_BEM_LINK_CONNECT_IND             0x00000008
231 #define BTIF_BEM_SCO_CONNECT_IND              0x00000010
232 #define BTIF_BEM_LINK_DISCONNECT              0x00000020
233 #define BTIF_BEM_LINK_CONNECT_CNF             0x00000040
234 #define BTIF_BEM_LINK_CON_RESTRICT            0x00000080
235 #define BTIF_BEM_MODE_CHANGE                  0x00000100
236 #define BTIF_BEM_ACCESSIBLE_CHANGE            0x00000200
237 #define BTIF_BEM_AUTHENTICATED                0x00000400
238 #define BTIF_BEM_ENCRYPTION_CHANGE            0x00000800
239 #define BTIF_BEM_SECURITY_CHANGE              0x00001000
240 #define BTIF_BEM_ROLE_CHANGE                  0x00002000
241 #define BTIF_BEM_SCO_DISCONNECT               0x00004000
242 #define BTIF_BEM_SCO_CONNECT_CNF              0x00008000
243 #define BTIF_BEM_SIMPLE_PAIRING_COMPLETE      0x00010000
244 #define BTIF_BEM_REMOTE_FEATURES              0x00020000
245 #define BTIF_BEM_REM_HOST_FEATURES            0x00040000
246 #define BTIF_BEM_LINK_SUPERV_TIMEOUT_CHANGED  0x00080000
247 #define BTIF_BEM_SET_SNIFF_SUBR_PARMS         0x00100000
248 #define BTIF_BEM_SNIFF_SUBRATE_INFO           0x00200000
249 #define BTIF_BEM_SET_INQ_MODE                 0x00400000
250 #define BTIF_BEM_SET_INQ_RSP_TX_PWR           0x00800000
251 #define BTIF_BEM_SET_EXT_INQ_RESP             0x01000000
252 #define BTIF_BEM_SET_ERR_DATA_REP             0x02000000
253 #define BTIF_BEM_KEY_PRESSED                  0x04000000
254 #define BTIF_BEM_CONN_PACKET_TYPE_CHNG        0x08000000
255 #define BTIF_BEM_QOS_SETUP_COMPLETE           0x10000000
256 #define BTIF_BEM_MAX_SLOT_CHANGED             0x20000000
257 #define BTIF_BEM_SNIFFER_CONTROL_DONE         0x40000000
258 #define BTIF_BEM_LINK_POLICY_CHANGED             0x80000000
259 #define BTIF_BEM_ALL_EVENTS                   0xffffffff
260 
261 typedef uint8_t btif_error_code_t;
262 
263 #define BTIF_BEC_NO_ERROR             0x00
264 #define  BTIF_BEC_UNKNOWN_HCI_CMD      0x01
265 #define  BTIF_BEC_NO_CONNECTION        0x02
266 #define  BTIF_BEC_HARDWARE_FAILURE     0x03
267 #define  BTIF_BEC_PAGE_TIMEOUT         0x04
268 #define  BTIF_BEC_AUTHENTICATE_FAILURE 0x05
269 #define  BTIF_BEC_MISSING_KEY          0x06
270 #define  BTIF_BEC_MEMORY_FULL          0x07
271 #define BTIF_BEC_CONNECTION_TIMEOUT   0x08
272 #define BTIF_BEC_MAX_CONNECTIONS      0x09
273 #define BTIF_BEC_MAX_SCO_CONNECTIONS  0x0a
274 #define BTIF_BEC_ACL_ALREADY_EXISTS   0x0b
275 #define BTIF_BEC_COMMAND_DISALLOWED   0x0c
276 #define BTIF_BEC_LIMITED_RESOURCE     0x0d
277 #define BTIF_BEC_SECURITY_ERROR       0x0e
278 #define BTIF_BEC_PERSONAL_DEVICE      0x0f
279 #define BTIF_BEC_HOST_TIMEOUT         0x10
280 #define BTIF_BEC_UNSUPPORTED_FEATURE  0x11
281 #define BTIF_BEC_INVALID_HCI_PARM     0x12
282 #define BTIF_BEC_USER_TERMINATED      0x13
283 #define BTIF_BEC_LOW_RESOURCES        0x14
284 #define BTIF_BEC_POWER_OFF            0x15
285 #define BTIF_BEC_LOCAL_TERMINATED     0x16
286 #define BTIF_BEC_REPEATED_ATTEMPTS    0x17
287 #define BTIF_BEC_PAIRING_NOT_ALLOWED  0x18
288 #define BTIF_BEC_UNKNOWN_LMP_PDU      0x19
289 #define BTIF_BEC_UNSUPPORTED_REMOTE   0x1a
290 #define  BTIF_BEC_SCO_OFFSET_REJECT    0x1b
291 #define BTIF_BEC_SCO_INTERVAL_REJECT  0x1c
292 #define BTIF_BEC_SCO_AIR_MODE_REJECT  0x1d
293 #define BTIF_BEC_INVALID_LMP_PARM     0x1e
294 #define BTIF_BEC_UNSPECIFIED_ERR      0x1f
295 #define BTIF_BEC_UNSUPPORTED_LMP_PARM 0x20
296 #define BTIF_BEC_ROLE_CHG_NOT_ALLOWED 0x21
297 #define BTIF_BEC_LMP_RESPONSE_TIMEOUT 0x22
298 #define BTIF_BEC_LMP_TRANS_COLLISION  0x23
299 #define BTIF_BEC_LMP_PDU_NOT_ALLOWED  0x24
300 #define BTIF_BEC_ENCRYP_MODE_NOT_ACC  0x25
301 #define BTIF_BEC_UNIT_KEY_USED        0x26
302 #define BTIF_BEC_QOS_NOT_SUPPORTED    0x27
303 #define BTIF_BEC_INSTANT_PASSED       0x28
304 #define BTIF_BEC_PAIR_UNITKEY_NO_SUPP 0x29
305 #define BTIF_BEC_NOT_FOUND            0xf1
306 #define BTIF_BEC_REQUEST_CANCELLED    0xf2
307 
308 #define BTIF_BEC_INVALID_SDP_PDU      0xd1
309 #define BTIF_BEC_SDP_DISCONNECT       0xd2
310 #define BTIF_BEC_SDP_NO_RESOURCES     0xd3
311 #define BTIF_BEC_SDP_INTERNAL_ERR     0xd4
312 
313 #define BTIF_BEC_STORE_LINK_KEY_ERR   0xe0
314 
315 typedef uint32_t btif_iac_t;
316 
317 #define BTIF_BT_IAC_GIAC 0x9E8B33   /* General/Unlimited Inquiry Access Code */
318 #define BTIF_BT_IAC_LIAC 0x9E8B00   /* Limited Dedicated Inquiry Access Code */
319 
320 typedef uint8_t btif_link_type_t;
321 
322 #define BTIF_BLT_SCO   0x00
323 #define BTIF_BLT_ACL   0x01
324 #define BTIF_BLT_ESCO  0x02
325 
326 typedef U16 btif_acl_packet;
327 
328 #define BTIF_BAPT_NO_2_DH1  0x0002
329 #define BTIF_BAPT_NO_3_DH1  0x0004
330 #define BTIF_BAPT_DM1       0x0008
331 #define BTIF_BAPT_DH1       0x0010
332 #define BTIF_BAPT_NO_2_DH3  0x0100
333 #define BTIF_BAPT_NO_3_DH3  0x0200
334 #define BTIF_BAPT_DM3       0x0400
335 #define BTIF_BAPT_DH3       0x0800
336 #define BTIF_BAPT_NO_2_DH5  0x1000
337 #define BTIF_BAPT_NO_3_DH5  0x2000
338 #define BTIF_BAPT_DM5       0x4000
339 #define BTIF_BAPT_DH5       0x8000
340 
341 #define BTIF_2M_PACKET     (BTIF_BAPT_DM1|BTIF_BAPT_DH1|BTIF_BAPT_NO_3_DH1|BTIF_BAPT_NO_3_DH3|BTIF_BAPT_DM3|BTIF_BAPT_DH3|BTIF_BAPT_NO_3_DH5)
342 #define BTIF_3M_PACKET     (BTIF_BAPT_DM1|BTIF_BAPT_DH1|BTIF_BAPT_DM3|BTIF_BAPT_DH3|BTIF_BAPT_DM5|BTIF_BAPT_DH5)
343 #define BTIF_1_SLOT_PACKET (BTIF_BAPT_DM1|BTIF_BAPT_DH1|BTIF_BAPT_NO_3_DH1|BTIF_BAPT_NO_2_DH3|BTIF_BAPT_NO_3_DH3|BTIF_BAPT_NO_2_DH5|BTIF_BAPT_NO_3_DH5)
344 #define BTIF_3_SLOT_PACKET (BTIF_BAPT_DM1|BTIF_BAPT_NO_3_DH3|BTIF_BAPT_NO_2_DH5|BTIF_BAPT_NO_3_DH5)
345 
346 typedef uint16_t btif_link_policy_t;
347 
348 #define BTIF_BLP_DISABLE_ALL         0x0000
349 #define BTIF_BLP_MASTER_SLAVE_SWITCH 0x0001
350 #define BTIF_BLP_HOLD_MODE           0x0002
351 #define BTIF_BLP_SNIFF_MODE          0x0004
352 #define BTIF_BLP_PARK_MODE           0x0008
353 #define BTIF_BLP_SCATTER_MODE        0x0010
354 
355 /* Mask must be updated if new policy values are added */
356 #define BLP_MASK                0xfff0  /* Disables ScatterNet bit */
357 #define BLP_SCATTER_MASK        0xffe0  /* Enables ScatterNet bit */
358 
359 typedef uint8_t btif_accessible_mode_t;
360 
361 #define BTIF_BAM_NOT_ACCESSIBLE     0x00    /* Non-discoverable or connectable */
362 #define BTIF_BAM_GENERAL_ACCESSIBLE 0x03    /* General discoverable and connectable */
363 #define BTIF_BAM_LIMITED_ACCESSIBLE 0x13    /* Limited discoverable and connectable */
364 #define BTIF_BAM_CONNECTABLE_ONLY   0x02    /* Connectable but not discoverable */
365 #define BTIF_BAM_DISCOVERABLE_ONLY  0x01    /* Discoverable but not connectable */
366 #define BTIF_BT_DEFAULT_ACCESS_MODE_PAIR       BTIF_BAM_GENERAL_ACCESSIBLE
367 #define BTIF_BAM_INVALID_ACCESS_MODE    0xFF
368 
369 /* End of BtAccessibleMode */
370 
371 typedef uint8_t btif_oob_data_present_t;
372 
373 #define BTIF_OOB_DATA_NOT_PRESENT  0    /* No Out of Band Data is present */
374 #define BTIF_OOB_DATA_PRESENT      1    /* Out of Band Data is present    */
375 
376 typedef uint8_t btif_auth_requirements_t;
377 
378 #define BTIF_MITM_PROTECT_NOT_REQUIRED  0x00    /* No Man in the Middle protection  */
379 #define BTIF_MITM_PROTECT_REQUIRED      0x01    /* Man in the Middle protection req */
380 
381 typedef uint8_t btif_link_mode_t;
382 
383 #define BTIF_BLM_ACTIVE_MODE     0x00
384 #define BTIF_BLM_HOLD_MODE       0x01
385 #define BTIF_BLM_SNIFF_MODE      0x02
386 #define BTIF_BLM_PARK_MODE       0x03
387 #define BTIF_BLM_SCATTER_MODE    0x04
388 
389 typedef uint8_t btif_link_key_type_t;
390 
391 #define BTIF_COMBINATION_KEY          0x00
392 #define BTIF_LOCAL_UNIT_KEY           0x01
393 #define BTIF_REMOTE_UNIT_KEY          0x02
394 #define BTIF_DEBUG_COMBINATION_KEY    0x03
395 #define BTIF_UNAUTH_COMBINATION_KEY   0x04
396 #define BTIF_AUTH_COMBINATION_KEY     0x05
397 #define BTIF_CHANGED_COMBINATION_KEY  0x06
398 #define BTIF_IBRT_STORE_ADDR_ONLY     0x07
399 
400 typedef uint8_t btif_connection_role_t;
401 
402 #define BTIF_BCR_MASTER   0x00
403 #define BTIF_BCR_SLAVE    0x01
404 #define BTIF_BCR_ANY      0x02
405 #define BTIF_BCR_UNKNOWN  0x03
406 #define BTIF_BCR_PSLAVE   0x04
407 #define BTIF_BCR_PMASTER  0x05
408 
409 typedef uint8_t btif_stack_state_t;
410 
411 /* The stack has completed initialization of the radio hardware. */
412 #define BTIF_BTSS_NOT_INITIALIZED 0
413 
414 /* The stack is initialized. */
415 #define BTIF_BTSS_INITIALIZED     1
416 
417 /* The stack has encountered an error while initializing the radio hardware. */
418 #define BTIF_BTSS_INITIALIZE_ERR  2
419 
420 /* The stack is deinitializing. */
421 #define BTIF_BTSS_DEINITIALIZE    3
422 
423 /* End of BtStackState */
424 typedef void btif_remote_device_t;
425 
426 
427 typedef void btif_BtDeviceContext;
428 
429 
430 /* Forward declaration of the callback parameters */
431 typedef void btif_event_t;
432 
433 typedef void (*btif_callback) (const void *);
434 typedef void (*ibrt_cmd_status_callback)(const uint8_t *para);
435 typedef void (*ibrt_cmd_complete_callback)(const uint8_t *para);
436 typedef uint8_t (*btif_callback_ext) (const void *);
437 typedef uint8_t (*btif_callback_ext2) (void);
438 typedef void (*btif_callback_ext3) (void);
439 
440 typedef uint8_t btif_inquiry_mode_t;
441 
442 #define BTIF_INQ_MODE_NORMAL    0   /* Normal Inquiry Response format           */
443 #define BTIF_INQ_MODE_RSSI      1   /* RSSI Inquiry Response format             */
444 #define BTIF_INQ_INVALID_RSSI   127   /* RSSI Inquiry Response format             */
445 #define BTIF_INQ_MODE_EXTENDED  2   /* Extended or RSSI Inquiry Response format */
446 
447 typedef uint8_t btif_rem_dev_state_t;
448 
449 #define BTIF_BDS_DISCONNECTED  0x00
450 #define BTIF_BDS_OUT_CON       0x01 /* Starting an out going connection */
451 #define BTIF_BDS_IN_CON        0x02 /* In process of incoming connection */
452 #define BTIF_BDS_CONNECTED     0x03 /* Connected */
453 #define BTIF_BDS_OUT_DISC      0x04 /* Starting an out going disconnect */
454 #define BTIF_BDS_OUT_DISC2     0x05 /* Disconnect status received */
455 #define BTIF_BDS_OUT_CON2      0x06 /* In SCO, used when connection request has
456                                        been sent */
457 
458 typedef uint8_t btif_eir_data_type_t;
459 
460 #define BTIF_EIR_FLAGS                0x01
461 #define BTIF_EIR_SRV_CLASS_16_PART    0x02
462 #define BTIF_EIR_SRV_CLASS_16_WHOLE   0x03
463 #define BTIF_EIR_SRV_CLASS_32_PART    0x04
464 #define BTIF_EIR_SRV_CLASS_32_WHOLE   0x05
465 #define BTIF_EIR_SRV_CLASS_128_PART   0x06
466 #define BTIF_EIR_SRV_CLASS_128_WHOLE  0x07
467 #define BTIF_EIR_REM_NAME_PART        0x08
468 #define BTIF_EIR_REM_NAME_WHOLE       0x09
469 #define BTIF_EIR_TX_POWER             0x0A
470 #define BTIF_EIR_MAN_SPECIFIC         0xFF
471 
472 
473 #define CONN_AUTO_ACCEPT_DISABLE                      0x01
474 
475 #define CONN_AUTO_ACCEPT_ENABLE_WITH_MSS_DISABLE      0x02
476 
477 #define CONN_AUTO_ACCEPT_ENABLE_WITH_MSS_ENABLE       0x03
478 /*---------------------------------------------------------------------------
479  * btif_class_of_device_t type
480  *
481  *     Bit pattern representing the class of device along with the
482  *     supported services. There can be more than one supported service.
483  *     Service classes can be ORed together. The Device Class is composed
484  *     of a major device class plus a minor device class. ORing together
485  *     each service class plus one major device class plus one minor device
486  *     class creates the class of device value. The minor device class is
487  *     interpreted in the context of the major device class.
488  */
489 
490 typedef uint32_t btif_class_of_device_t;
491 
492 /* Group: Major Service Classes. Can be ORed together */
493 #define BTIF_COD_LIMITED_DISCOVERABLE_MODE 0x00002000
494 #define BTIF_COD_POSITIONING               0x00010000
495 #define BTIF_COD_NETWORKING                0x00020000
496 #define BTIF_COD_RENDERING                 0x00040000
497 #define BTIF_COD_CAPTURING                 0x00080000
498 #define BTIF_COD_OBJECT_TRANSFER           0x00100000
499 #define BTIF_COD_AUDIO                     0x00200000
500 #define BTIF_COD_TELEPHONY                 0x00400000
501 #define BTIF_COD_INFORMATION               0x00800000
502 
503 /* Group: Major Device Classes (Select one) */
504 #define BTIF_COD_MAJOR_MISCELLANEOUS       0x00000000
505 #define BTIF_COD_MAJOR_COMPUTER            0x00000100
506 #define BTIF_COD_MAJOR_PHONE               0x00000200
507 #define BTIF_COD_MAJOR_LAN_ACCESS_POINT    0x00000300
508 #define BTIF_COD_MAJOR_AUDIO               0x00000400
509 #define BTIF_COD_MAJOR_PERIPHERAL          0x00000500
510 #define BTIF_COD_MAJOR_IMAGING             0x00000600
511 #define BTIF_COD_MAJOR_UNCLASSIFIED        0x00001F00
512 
513 /* Group: Minor Device Class - Computer Major class */
514 #define BTIF_COD_MINOR_COMP_UNCLASSIFIED   0x00000000
515 #define BTIF_COD_MINOR_COMP_DESKTOP        0x00000004
516 #define BTIF_COD_MINOR_COMP_SERVER         0x00000008
517 #define BTIF_COD_MINOR_COMP_LAPTOP         0x0000000C
518 #define BTIF_COD_MINOR_COMP_HANDHELD       0x00000010
519 #define BTIF_COD_MINOR_COMP_PALM           0x00000014
520 #define BTIF_COD_MINOR_COMP_WEARABLE       0x00000018
521 
522 /* Group: Minor Device Class - Phone Major class */
523 #define BTIF_COD_MINOR_PHONE_UNCLASSIFIED  0x00000000
524 #define BTIF_COD_MINOR_PHONE_CELLULAR      0x00000004
525 #define BTIF_COD_MINOR_PHONE_CORDLESS      0x00000008
526 #define BTIF_COD_MINOR_PHONE_SMART         0x0000000C
527 #define BTIF_COD_MINOR_PHONE_MODEM         0x00000010
528 #define BTIF_COD_MINOR_PHONE_ISDN          0x00000014
529 
530 /* Group: Minor Device Class - LAN Access Point Major class */
531 #define BTIF_COD_MINOR_LAN_0               0x00000000   /* fully available */
532 #define BTIF_COD_MINOR_LAN_17              0x00000020   /* 1-17% utilized */
533 #define BTIF_COD_MINOR_LAN_33              0x00000040   /* 17-33% utilized */
534 #define BTIF_COD_MINOR_LAN_50              0x00000060   /* 33-50% utilized */
535 #define BTIF_COD_MINOR_LAN_67              0x00000080   /* 50-67% utilized */
536 #define BTIF_COD_MINOR_LAN_83              0x000000A0   /* 67-83% utilized */
537 #define BTIF_COD_MINOR_LAN_99              0x000000C0   /* 83-99% utilized */
538 #define BTIF_COD_MINOR_LAN_NO_SERVICE      0x000000E0   /* 100% utilized */
539 
540 /* Group: Minor Device Class - Audio Major class */
541 #define BTIF_COD_MINOR_AUDIO_UNCLASSIFIED  0x00000000
542 #define BTIF_COD_MINOR_AUDIO_HEADSET       0x00000004
543 #define BTIF_COD_MINOR_AUDIO_HANDSFREE     0x00000008
544 #define BTIF_COD_MINOR_AUDIO_MICROPHONE    0x00000010
545 #define BTIF_COD_MINOR_AUDIO_LOUDSPEAKER   0x00000014
546 #define BTIF_COD_MINOR_AUDIO_HEADPHONES    0x00000018
547 #define BTIF_COD_MINOR_AUDIO_PORTABLEAUDIO 0x0000001C
548 #define BTIF_COD_MINOR_AUDIO_CARAUDIO      0x00000020
549 #define BTIF_COD_MINOR_AUDIO_SETTOPBOX     0x00000024
550 #define BTIF_COD_MINOR_AUDIO_HIFIAUDIO     0x00000028
551 #define BTIF_COD_MINOR_AUDIO_VCR           0x0000002C
552 #define BTIF_COD_MINOR_AUDIO_VIDEOCAMERA   0x00000030
553 #define BTIF_COD_MINOR_AUDIO_CAMCORDER     0x00000034
554 #define BTIF_COD_MINOR_AUDIO_VIDEOMONITOR  0x00000038
555 #define BTIF_COD_MINOR_AUDIO_VIDEOSPEAKER  0x0000003C
556 #define BTIF_COD_MINOR_AUDIO_CONFERENCING  0x00000040
557 #define BTIF_COD_MINOR_AUDIO_GAMING        0x00000048
558 
559 /* Group: Minor Device Class - Peripheral Major class */
560 #define BTIF_COD_MINOR_PERIPH_KEYBOARD     0x00000040
561 #define BTIF_COD_MINOR_PERIPH_POINTING     0x00000080
562 #define BTIF_COD_MINOR_PERIPH_COMBOKEY     0x000000C0
563 /* Group: Minor Device Class - ORed with Peripheral Minor Device class */
564 #define BTIF_COD_MINOR_PERIPH_UNCLASSIFIED 0x00000000
565 #define BTIF_COD_MINOR_PERIPH_JOYSTICK     0x00000004
566 #define BTIF_COD_MINOR_PERIPH_GAMEPAD      0x00000008
567 #define BTIF_COD_MINOR_PERIPH_REMOTECTRL   0x0000000C
568 #define BTIF_COD_MINOR_PERIPH_SENSING      0x00000010
569 #define BTIF_COD_MINOR_PERIPH_DIGITIZER    0x00000014
570 #define BTIF_COD_MINOR_PERIPH_CARD_RDR     0x00000018
571 
572 /* Group: Minor Device Class - Imaging Major class */
573 #define BTIF_COD_MINOR_IMAGE_UNCLASSIFIED  0x00000000
574 #define BTIF_COD_MINOR_IMAGE_DISPLAY       0x00000010
575 #define BTIF_COD_MINOR_IMAGE_CAMERA        0x00000020
576 #define BTIF_COD_MINOR_IMAGE_SCANNER       0x00000040
577 #define BTIF_COD_MINOR_IMAGE_PRINTER       0x00000080
578 
579 /* Group: Masks used to isolate the class of device components */
580 #define BTIF_COD_SERVICE_MASK              0x00ffC000   /* Less LIAC bit */
581 #define BTIF_COD_MAJOR_MASK                0x00001F00
582 #define BTIF_COD_MINOR_MASK                0x000000FC
583 #define BTIF_COD_LIMITED_DISC_MASK         0x00002000   /* LIAC bit */
584 
585 /* End of btif_class_of_device_t */
586 
587 //when report_format=0,data_format will set the interval(unit:slot)
588 //when report_format=1,data_format will set the packet total num
589 //when report_format=2,data_format has no meaning
590 #define FLAG_RESET_DATA    2
591 #define FLAG_START_DATA    1
592 #define FLAG_GET_DATA        0
593 
594 #define REP_FORMAT_TIME     0
595 #define REP_FORMAT_PACKET  1
596 #define REP_FORMAT_STOP_GET  2
597 
598 
599 //Vendor defined error code
600 #define  BTIF_EVT_ERROR_SCO_UNKNOWN       (0xE8)
601 #define  BTIF_EVT_ERROR_ACL_UNKNOWN       (0xE9)
602 
603 
604 typedef struct {
605     list_entry_t node;
606     uint8_t opType;
607 } btif_operation_t;
608 
609 typedef struct {
610 
611     /* the mandatory sniff interval range for controllers is between 0x0006 and 0x0540.
612      * The value is expressed in 0.625 ms increments (0x0006 = 3.75 ms).
613      *
614      * The actual interval selected by the radio will be returned in
615      * a BTEVENT_MODE_CHANGE event.
616      */
617 
618     uint16_t maxInterval;
619 
620     /* Minimum acceptable interval between each consecutive sniff period.
621      * Must be an even number between 0x0002 and 0xFFFE, and be less than
622      * "maxInterval". Like maxInterval this value is expressed in
623      * 0.625 ms increments.
624      */
625     uint16_t minInterval;
626 
627     /* The number of master-to-slave transmission slots during which
628      * a device should listen for traffic (sniff attempt).
629      * Expressed in 0.625 ms increments. May be between 0x0001 and 0x7FFF.
630      */
631     uint16_t attempt;
632 
633     /* The amount of time before a sniff timeout occurs. Expressed in
634      * 1.25 ms increments. May be between 0x0000 and 0x7FFF, but the mandatory
635      * range for controllers is 0x0000 to 0x0028.
636      */
637     uint16_t timeout;
638 } btif_sniff_info_t;
639 
640 typedef struct {
641 
642     /*  May be any number between 0x0000 and 0xFFFE.  The value is expressed in 0.625 ms
643      * increments.
644      */
645     uint16_t maxLatency;
646 
647     /*  any number between 0x0000 and 0xFFFE.  The value is expressed in
648      * 0.625 ms increments.
649      */
650     uint16_t minRemoteTimeout;
651 
652     /* Minimum base sniff subrate timeout that the local device may use.
653      * May be any number between 0x0000 and 0xFFFE.  The value is expressed in
654      * 0.625 ms increments.
655      */
656     uint16_t minLocalTimeout;
657 } btif_sniff_subrate_parms_t;
658 
659 typedef struct {
660     uint16_t inqInterval;            /* Inquiry scan interval */
661     uint16_t inqWindow;              /* Inquiry scan Window */
662     uint16_t pageInterval;           /* Page scan interval */
663     uint16_t pageWindow;             /* Page scan window */
664 } btif_access_mode_info_t;
665 
666 typedef struct {
667     list_entry_t node;          /* For internal stack use only. */
668     btif_callback callback;  /* Pointer to callback function */
669     btif_event_mask_t emask; /* For internal stack use only. */
670 } btif_handler;
671 
672 /* Internal types required for BtRemoteDevice structure */
673 typedef uint8_t btif_auth_state_t;
674 
675 typedef uint8_t btif_encrypt_state_t;
676 
677 typedef uint8_t btif_authorize_state_t;
678 
679 typedef uint8_t btif_sec_access_state_t;
680 
681 typedef uint8_t btif_link_rx_state_t;
682 
683 typedef uint8_t btif_op_type_t;
684 
685 typedef struct {
686 
687     /* Reserved */
688     uint8_t flags;
689 
690     /* Service Type: 0 = No Traffic, 1 = Best Effort, 2 Guaranteed */
691     uint8_t serviceType;
692 
693     /* Token Rate in octets per second */
694     uint32_t tokenRate;
695 
696     /* Peak Bandwidth in octets per second */
697     uint32_t peakBandwidth;
698 
699     /* Latency in microseconds */
700     uint32_t latency;
701 
702     /* Delay Variation in microseconds */
703     uint32_t delayVariation;
704 } btif_qos_info_t;
705 
706 typedef struct {
707     bt_bdaddr_t bdAddr;
708     BOOL trusted;
709     uint8_t linkKey[16];
710     btif_link_key_type_t keyType;
711 
712     uint8_t pinLen;
713 } btif_device_record_t;
714 
715 typedef struct {
716     btif_operation_t op;
717     uint8_t len;
718     uint8_t data[31];
719 } btif_write_adv_data_op_t;
720 
721 typedef struct {
722     uint16_t interval_min;
723     uint16_t interval_max;
724     uint8_t adv_type;
725     uint8_t own_addr_type;
726     uint8_t peer_addr_type;
727     bt_bdaddr_t bd_addr;
728     uint8_t adv_chanmap;
729     uint8_t adv_filter_policy;
730 } btif_adv_para_struct_t;
731 
732 typedef struct {
733     btif_operation_t op;
734     btif_adv_para_struct_t adv_para;
735 } btif_write_adv_para_op_t;
736 
737 typedef struct {
738     btif_operation_t op;
739     uint8_t en;
740 } btif_write_adv_en_op_t;
741 
742 #define BLE_ADV_REPORT_MAX_LEN 31
743 
744 typedef struct {
745     uint8_t type;
746     uint8_t addr_type;
747     bt_bdaddr_t addr;
748     uint8_t data_len;
749     uint8_t data[BLE_ADV_REPORT_MAX_LEN];
750     int8_t rssi;
751 } btif_ble_adv_report;
752 
753 typedef struct {
754     uint8_t scan_type;
755     uint16_t scan_interval;
756     uint16_t scan_window;
757     uint8_t own_addr_type;
758     uint8_t scan_filter_policy;
759 } __attribute__ ((packed)) btif_scan_para_struct_t;
760 
761 typedef struct {
762     btif_operation_t op;
763     btif_scan_para_struct_t scan_para;
764 } btif_write_scan_para_op_t;
765 
766 typedef struct {
767     btif_operation_t op;
768     uint8_t scan_en;
769     uint32_t filter_duplicat;
770 } btif_write_scan_en_op_t;
771 
772 typedef struct
773 {
774     bt_bdaddr_t bdAddr;           /* Device Address */
775     uint8_t     linkKey[16];
776 } btif_dev_linkkey;
777 
778 typedef struct
779 {
780     U8   psRepMode;
781     U8   psMode;
782     U16  clockOffset;
783 } bt_page_scanInfo_t;
784 
785 typedef struct
786 {
787     bt_bdaddr_t bdAddr;           /* Device Address */
788     bt_page_scanInfo_t  psi;              /* Page scan info used for connecting */
789     U8              psPeriodMode;
790     U32     classOfDevice;
791 
792     /* RSSI in dBm (-127 to +20). Only valid when controller reports RSSI with
793      * in inquiry results (also see ME_SetInquiryMode). Otherwise it will be
794      * set to BT_INVALID_RSSI.
795      */
796     S8              rssi;
797 
798     /* Extended Inquiry response.  Only valid when controller reports an
799      * extended inquiry (also see ME_SetInquiryMode).  Otherwise it will be
800      * set to all 0's.
801      */
802     U8              extInqResp[240];
803 
804     /* Describes the format of the current inquiry result */
805     U8   inqMode;
806 
807 } bt_Inquiry_result_t;
808 
809 typedef struct
810 {
811     /* Event causing callback. Always valid.*/
812     uint8_t   eType;
813 
814     /* Error code. See BtEventType for guidance on whether errCode is valid. */
815     uint8_t   errCode;
816 
817     /* Pointer to handler. Only valid for events directed to BtHandlers. */
818     btif_handler   *handler;
819 
820     /* Parameters */
821     union
822     {
823         btif_accessible_mode_t   aMode;      /* New access mode */
824         void    *remDev;     /* Pointer to remote device */
825         bt_bdaddr_t bdAddr;     /* Device Address */
826         void    *meToken;    /* Me command token */
827         U8                 pMode;      /* Simple Pairing Mode */
828 
829 #ifdef __TWS_RECONNECT_USE_BLE__
830         struct
831         {
832             U8          *data;
833             U16         len;
834         } twsBleReport;
835 #endif
836         bt_Inquiry_result_t    inqResult;
837 
838         void  *secToken;   /* Security Token */
839         void    *token;
840 
841         /* Information for BTEVENT_PAIRING_COMPLETE */
842         struct
843         {
844             void *remDev;
845             btif_link_key_type_t   keyType;
846         } pairingInfo;
847 
848         /* Information for BTEVENT_PIN_REQ */
849         struct
850         {
851             void *remDev;
852 
853             /* If > 0 then the pin length returned in SEC_SetPin must be >= pinLen */
854             U8              pinLen;
855         } pinReq;
856 
857         /* Information for BTEVENT_SET_INQUIRY_MODE_CNF */
858         btif_inquiry_mode_t      inqMode;
859 
860         /* Information for BTEVENT_SET_INQ_TX_PWR_LVL_CNF */
861         S8       inqTxPwr;
862 
863         /* Information for BTEVENT_REMOTE_FEATURES */
864         struct
865         {
866             bt_bdaddr_t  bdAddr;
867             U8      features[8];
868         } remoteFeatures;
869 
870         /* Information for BTEVENT_REM_HOST_FEATURES */
871         struct
872         {
873             bt_bdaddr_t bdAddr;
874             U8      features[8];
875         } remHostFeatures;
876 
877         /* Information for BTEVENT_LINK_SUPERV_TIMEOUT_CHANGED */
878         struct
879         {
880             void *remDev;
881             U16             timeout;
882         } linkSupervision;
883 
884         /* Information for BTEVENT_MAX_SLOT_CHANGED */
885         struct
886         {
887             U16             connHandle;
888             U8              maxSlot;
889         } maxSlotChanged;
890 
891         /* Information for BTEVENT_QOS_SETUP_COMPLETE */
892         struct
893         {
894 
895             /* Reserved */
896             U8 flags;
897 
898             /* Service Type: 0 = No Traffic, 1 = Best Effort, 2 Guaranteed */
899             U8  serviceType;
900 
901             /* Token Rate in octets per second */
902             U32 tokenRate;
903 
904             /* Peak Bandwidth in octets per second */
905             U32 peakBandwidth;
906 
907             /* Latency in microseconds */
908             U32 latency;
909 
910             /* Delay Variation in microseconds */
911             U32 delayVariation;
912         } qos;
913 
914         /* Result for BTEVENT_SET_SNIFF_SUBRATING_PARMS_CNF */
915         btif_sniff_subrate_parms_t *sniffSubrateParms;
916 
917         /* Information for BTEVENT_SNIFF_SUBRATE_INFO */
918         struct
919         {
920             /* Pointer to the remote device */
921             void *remDev;
922 
923             /* Maximum latency for data being transmitted from the local
924              * device to the remote device.
925              */
926             U16 maxTxLatency;
927 
928             /* Maximum latency for data being received by the local
929              * device from the remote device.
930              */
931             U16 maxRxLatency;
932 
933             /* The base sniff subrate timeout in baseband slots that the
934              * remote device shall use.
935              */
936             U16 minRemoteTimeout;
937 
938             /* The base sniff subrate timeout in baseband slots that the
939              * local device will use.
940              */
941             U16 minLocalTimeout;
942         } sniffSubrateInfo;
943 
944         /* Result for BTEVENT_LOCAL_OOB_DATA */
945         struct
946         {
947             /* Simple Pairing Hash C from the local device */
948             U8 hashC[16];
949 
950             /* Simple Pairing Randomizer R the local device */
951             U8 randR[16];
952         } oobData;
953 
954         /* Information for BTEVENT_CONFIRM_NUMERIC_REQ, BTEVENT_PASS_KEY_REQ,
955          * and BTEVENT_DISPLAY_NUMERIC_IND
956          */
957         struct
958         {
959             void *remDev;      /* Pointer to the remote device */
960             U32             numeric;     /* Numeric value received from Secure
961                                           * Simple Pairing (not valid for
962                                           * BTEVENT_PASS_KEY_REQ
963                                           */
964 
965             U8   bondingMode;  /* Bonding has been requested */
966         } userIoReq;
967 
968         /* Result for BTEVENT_ENCRYPTION_CHANGE event. */
969         struct
970         {
971             void *remDev;
972             U8              mode; /* New encryption mode (uses the
973                                    * BtEncryptMode type) */
974         } encrypt;
975 
976         /* Result for BTEVENT_KEY_PRESSED */
977         struct
978         {
979             bt_bdaddr_t bdAddr; /* Address of the device sending the keypress */
980             U8  parm;   /* The value of the keypress parameter */
981         } keyPress;
982 
983         struct
984         {
985             void *remDev;
986 
987             /* If disconnection was successful, contains BEC_NO_ERROR.
988              * errCode will contain the disconnect reason.
989              *
990              * Unsuccessful disconnections will contain an error code
991              * as generated by the radio. In this case, errCode can be
992              * ignored.
993              */
994             btif_error_code_t status;
995         } disconnect;
996 
997         /* Result for the BTEVENT_SCO_DATA_CNF event */
998         struct
999         {
1000             void *remDev;     /* Pointer to remote device */
1001             void   *scoCon;     /* SCO connection */
1002             void       *scoPacket;  /* SCO Packet Handled */
1003         } scoPacketHandled;
1004 
1005         /* Result for the BTEVENT_SCO_CONNECT_CNF && BTEVENT_SCO_CONNECT_IND
1006            events.
1007          */
1008         struct
1009         {
1010             void *remDev;     /* Pointer to remote device */
1011             U16             scoHandle;  /* SCO Connection handle for HCI */
1012             void   *scoCon;     /* SCO connection */
1013             U8      scoLinkType;/* SCO link type */
1014             void   *scoTxParms; /* Pointer to eSCO TX parameters */
1015             void   *scoRxParms; /* Pointer to eSCO RX parameters */
1016         } scoConnect;
1017 
1018         /* Result for the BTEVENT_SCO_DATA_IND event */
1019         struct
1020         {
1021             void *remDev;     /* Pointer to remote device */
1022             U16     scoHandle;  /* SCO Connection handle for HCI */
1023             void   *scoCon;     /* SCO connection. */
1024             U8              len;        /* SCO data len */
1025             U8             *ptr;        /* SCO data ptr */
1026             U8   errFlags;   /* Erroneous Data Reporting */
1027         } scoDataInd;
1028 
1029         /* Result for the BTEVENT_SECURITY_CHANGE and
1030          * BTEVENT_SECURITY3_COMPLETE events
1031          */
1032         struct
1033         {
1034             U8    mode;    /* New security mode (uses the BtSecurityMode
1035                             * type). */
1036             BOOL  encrypt; /* Indicate if encryption set or not */
1037         } secMode;
1038 
1039         /* Results for the BTEVENT_MODE_CHANGE event */
1040         struct
1041         {
1042             void *remDev;
1043             uint8_t      curMode;
1044             U16             interval;
1045         } modeChange;
1046 
1047         /* Results for BTEVENT_ROLE_CHANGE */
1048         struct
1049         {
1050             void    *remDev;
1051             uint8_t   newRole;    /* New role */
1052         } roleChange;
1053 
1054         /* Results for BTEVENT_ACL_DATA_ACTIVE */
1055         struct
1056         {
1057             void    *remDev;
1058             uint16_t   dataLen;    /* ACL data length */
1059         } aclDataActive;
1060 
1061         /* Results for BTEVENT_ACL_DATA_NOT_ACTIVE */
1062         struct
1063         {
1064             void    *remDev;
1065             uint16_t   dataLen;    /* ACL data length */
1066         } aclDataNotActive;
1067         struct
1068         {
1069             uint8_t status;
1070             bt_bdaddr_t bdAddr; /* Address of the device sending the keypress */
1071         }name_rsp;
1072         struct
1073         {
1074             btif_remote_device_t *conn;
1075         }conn_req;
1076     } edata;
1077 } event_t;
1078 
1079 typedef struct
1080 {
1081     event_t  *evt;
1082     btif_event_mask_t mask;
1083 } me_event_t;
1084 typedef bool (*ibrt_io_capbility_callback)(void *bdaddr);
1085 typedef void (*ibrt_disconnect_callback)(const void *event);
1086 typedef void (*btif_cmgr_callback) (void *handler, uint8_t event, bt_status_t status);
1087 typedef void (*btif_global_handle)(const btif_event_t *Event);
1088 
1089 #ifdef __cplusplus
1090 extern "C" {
1091 #endif                          /*  */
1092     bt_status_t btif_me_get_tws_slave_mobile_rssi(uint16_t ConnHandle);
1093 
1094     void btif_me_set_sniffer_env(uint8_t sniffer_acitve, uint8_t sniffer_role,
1095                                  uint8_t * monitored_addr, uint8_t * sniffer_addr);
1096     BOOL btif_me_get_remote_device_initiator(btif_remote_device_t * rdev);
1097     uint16_t btif_me_get_remote_device_hci_handle(btif_remote_device_t * rdev);
1098     btif_remote_device_t* btif_me_get_remote_device_by_handle(uint16_t hci_handle);
1099     btif_remote_device_t* btif_me_get_remote_device_by_bdaddr(bt_bdaddr_t *bdaddr);
1100     uint8_t btif_me_get_remote_device_op_optype(btif_remote_device_t * rdev);
1101     btif_connection_role_t btif_me_get_remote_device_role(btif_remote_device_t * rdev);
1102     void btif_me_set_remote_device_role(btif_remote_device_t * rdev, uint8_t role);
1103     BOOL *btif_me_get_remote_device_new_link_key(btif_remote_device_t * rdev);
1104     void *btif_me_get_remote_device_parms(btif_remote_device_t * rdev);
1105     bt_status_t btif_me_exchange_bt_addr(uint16_t connHandle);
1106     bool btif_me_role_switch_pending(uint16_t handle);
1107     bool btif_me_is_tws_role_switch_pending();
1108     bool btif_me_is_exechange_bt_addr_pending();
1109     bool is_btif_me_current_role_bcr_master(btif_remote_device_t * device);
1110     bt_status_t btif_me_inquiry(uint32_t lap, uint8_t len, uint8_t maxResp);
1111     bt_status_t btif_me_ble_add_dev_to_whitelist(uint8_t addr_type, bt_bdaddr_t * addr);
1112     bt_status_t btif_me_ble_clear_whitelist(void);
1113     bt_status_t btif_me_ble_set_private_address(bt_bdaddr_t * addr);
1114     bt_status_t btif_me_ble_set_adv_data(uint8_t len, uint8_t * data);
1115     bt_status_t btif_me_ble_set_scan_rsp_data(U8 len, U8 * data);
1116     bt_status_t btif_me_ble_set_adv_parameters(btif_adv_para_struct_t * para);
1117     bt_status_t btif_me_ble_set_adv_en(uint8_t en);
1118     bt_status_t btif_me_ble_set_scan_parameter(btif_scan_para_struct_t * para);
1119     bt_status_t btif_me_ble_set_scan_en(uint8_t scan_en, uint8_t filter_duplicate);
1120     bt_status_t btif_me_ble_receive_adv_report(void (*cb)(const btif_ble_adv_report* report));
1121     bt_status_t btif_sec_find_device_record(const bt_bdaddr_t * bdAddr,
1122                                             btif_device_record_t * record);
1123 
1124     uint8_t btif_sec_set_io_capabilities(uint8_t ioCap);
1125     uint8_t btif_sec_set_authrequirements(uint8_t authRequirements);
1126     uint8_t btif_me_get_callback_event_type(const btif_event_t * event);
1127     uint8_t btif_me_get_callback_event_rem_dev_role(const btif_event_t * event);
1128     bt_bdaddr_t *btif_me_get_callback_event_rem_dev_bd_addr(const btif_event_t * event);
1129     bt_bdaddr_t *btif_me_get_callback_event_disconnect_rem_dev_bd_addr(const btif_event_t *
1130                                                                        event);
1131     btif_remote_device_t *btif_me_get_callback_event_disconnect_rem_dev(const btif_event_t *
1132                                                                            event);
1133     uint8_t btif_me_get_callback_event_disconnect_rem_dev_disc_reason_saved(const btif_event_t *
1134                                                                             event);
1135     uint8_t btif_me_get_callback_event_disconnect_rem_dev_disc_reason(const btif_event_t *
1136                                                                       event);
1137 
1138     uint8_t btif_me_get_pendCons(void);
1139 
1140     uint8_t btif_me_get_activeCons(void);
1141 
1142     void btif_me_set_pendCons(uint8_t pendCons);
1143 
1144     void btif_me_set_activeCons(uint8_t activeCons );
1145 
1146     btif_remote_device_t *btif_me_get_callback_event_rem_dev(const btif_event_t * event);
1147 
1148     btif_BtDeviceContext* btif_me_get_bt_device_context(const btif_event_t * event);
1149 
1150     uint16_t btif_me_get_scohdl_by_connhdl(uint16_t conn_handle);
1151     btif_remote_device_t *btif_me_get_callback_event_sco_connect_rem_dev(const btif_event_t *
1152                                                                             event);
1153     uint8_t btif_me_get_callback_event_role_change_new_role(const btif_event_t * event);
1154     bt_bdaddr_t *btif_me_get_callback_event_inq_result_bd_addr(const btif_event_t * event);
1155     uint8_t *btif_me_get_callback_event_inq_result_bd_addr_addr(const btif_event_t * event);
1156     uint8_t btif_me_get_callback_event_inq_result_inq_mode(const btif_event_t * event);
1157     uint8_t btif_me_get_callback_event_rssi(const btif_event_t *event);
1158     uint8_t *btif_me_get_callback_event_inq_result_ext_inq_resp(const btif_event_t * event);
1159     uint32_t btif_me_get_callback_event_inq_result_classofdevice(const btif_event_t *event);
1160     uint8_t btif_me_get_callback_event_err_code(const btif_event_t * event);
1161     uint8_t btif_me_get_callback_event_a_mode(const btif_event_t * event);
1162     uint16_t btif_me_get_callback_event_max_slot_changed_connHandle(const btif_event_t * event);
1163     uint8_t btif_me_get_callback_event_max_slot_changed_max_slot(const btif_event_t * event);
1164     uint8_t btif_me_get_callback_event_mode_change_curMode(const btif_event_t * event);
1165     uint16_t btif_me_get_callback_event_mode_change_interval(const btif_event_t * event);
1166 
1167     uint16_t btif_me_get_callback_event_remote_dev_name(const btif_event_t * event, uint8_t** ppName);
1168 
1169     bt_status_t btif_me_get_remote_device_name(const bt_bdaddr_t * bdAddr, btif_global_handle handler);
1170 
1171     uint8_t btif_me_get_ext_inq_data(uint8_t * eir, btif_eir_data_type_t type,
1172                                      uint8_t * outBuffer, uint8_t Length);
1173     bt_status_t btif_me_cancel_inquiry(void);
1174     bt_status_t btif_sec_delete_device_record(const bt_bdaddr_t * bdAddr);
1175     bt_status_t btif_me_cancel_create_link(btif_handler * handler,
1176                                            btif_remote_device_t * rdev);
1177     void btif_me_set_handler(void *handler, btif_callback cb);
1178     uint8_t btif_me_set_connection_role(uint8_t role);
1179     bt_status_t btif_me_disconnect_link(btif_handler * handler,
1180                                         btif_remote_device_t * rdev);
1181     bt_status_t btif_me_set_link_policy(btif_remote_device_t * rdev,
1182                                         btif_link_policy_t policy);
1183     bt_status_t btif_me_set_link_lowlayer_monitor(btif_remote_device_t * rdev, uint8_t control_flag,uint8_t report_format,
1184                                                           uint32_t data_format,uint8_t report_unit);
1185     bt_status_t btif_me_set_connection_qos_info(btif_remote_device_t * rdev,
1186                                                 btif_qos_info_t * qosInfo);
1187     void btif_me_fake_tws_disconnect(uint16_t hci_handle, uint8_t reason);
1188     void btif_me_fake_mobile_disconnect(uint16_t hci_handle, uint8_t reason);
1189     void btif_me_fake_tws_connect(uint8_t status, uint16_t hci_handle, bt_bdaddr_t * bdAddr);
1190     void btif_me_reset_bt_controller(void);
1191     void btif_me_fake_mobile_connect(uint8_t status, uint16_t hci_handle, bt_bdaddr_t *bdAddr);
1192 
1193     bt_status_t btif_me_set_lbrt_enable(uint16_t connHandle, uint8_t enable);
1194     bt_status_t btif_me_set_accessible_mode(btif_accessible_mode_t mode,
1195                                             const btif_access_mode_info_t * info);
1196     bt_status_t btif_me_write_page_timeout(uint16_t timeout);
1197     bool btif_me_is_op_in_progress(btif_remote_device_t * rdev);
1198     bt_status_t btif_me_switch_role(btif_remote_device_t * rdev);
1199     bt_status_t btif_me_register_global_handler(void *handler);
1200     void *btif_me_register_accept_handler(void *handler);
1201     bt_status_t btif_me_set_event_mask(void *handler, btif_event_mask_t mask);
1202     void *btif_me_get_bt_handler(void);
1203     bt_status_t btif_me_set_bt_address(uint8_t * btAddr);
1204     bt_status_t btif_me_set_local_device_name(const U8 *name, U8 length);
1205     bt_status_t btif_me_set_ble_bd_address(uint8_t * btAddr);
1206     bt_status_t btif_sec_add_device_record(btif_device_record_t * record);
1207     bt_status_t btif_enum_device_record(U16 dev_id, btif_device_record_t *record);
1208     bt_bdaddr_t *btif_me_get_remote_device_bdaddr(btif_remote_device_t * rdev);
1209     btif_rem_dev_state_t btif_me_get_remote_device_state(btif_remote_device_t * rdev);
1210     btif_link_mode_t btif_me_get_remote_device_mode(btif_remote_device_t * rdev);
1211     btif_authorize_state_t btif_me_get_remote_device_auth_state(btif_remote_device_t * rdev);
1212     bt_status_t btif_me_write_link_superv_timeout(uint16_t handle, uint16_t slots);
1213     btif_link_mode_t btif_me_get_current_mode(btif_remote_device_t * rdev);
1214     btif_connection_role_t btif_me_get_current_role(btif_remote_device_t * rdev);
1215 
1216     bt_status_t btif_me_start_sniff(btif_remote_device_t * rdev, btif_sniff_info_t* info);
1217 
1218     bt_status_t btif_me_stop_sniff(btif_remote_device_t * rdev);
1219 
1220     bt_status_t btif_me_accept_incoming_link(const btif_event_t *event,btif_remote_device_t * rdev, btif_connection_role_t role);
1221 
1222     bt_status_t btif_me_reject_incoming_link(btif_remote_device_t * rdev, btif_error_code_t reason);
1223 
1224     bt_status_t btif_me_start_tws_role_switch(uint16_t slaveConnHandle, uint16_t mobileConnHandle);
1225     bt_status_t btif_me_set_sco_tx_silence(uint16_t connHandle, uint8_t silence_on);
1226     void btif_me_increase_active_counts(void);
1227     bool btif_me_is_sending_data_to_peer_dev_pending(void);
1228     btif_handler *btif_me_get_me_handler(void);
1229     bt_status_t btif_me_force_disconnect_link_with_reason(btif_handler * handler,
1230                                                           btif_remote_device_t * rdev,
1231                                                           uint8_t reason, BOOL forceDisconnect);
1232 
1233     void btif_me_sec_set_io_cap_rsp_reject_ext(BOOL(*ext_fn) (void *));
1234     void btif_me_write_bt_sleep_enable(uint8_t sleep_en);
1235     void btif_me_write_bt_page_scan_type(uint8_t scan_type);
1236     void btif_me_write_bt_inquiry_scan_type(uint8_t scan_type);
1237 
1238 #if IS_USE_INTERNAL_ACL_DATA_PATH
1239     bt_status_t btif_me_send_data_to_peer_dev(uint16_t connHandle, uint8_t dataLen, uint8_t * data);
1240 #endif                          /*  */
1241     void btif_bt_call_back(const btif_event_t * event);
1242     void btif_me_init_handler(btif_handler * handler);
1243     bt_status_t btif_me_dbg_sniffer_interface(uint16_t connHandle, uint8_t subCode);
1244     bt_status_t btif_me_switch_sco(uint16_t scohandle);
1245     uint8_t *btif_me_get_remote_device_version(btif_remote_device_t * rdev);
1246     void *btif_me_get_cmgr_handler();
1247     bt_status_t btif_bind_cmgr_handler(void *cmgr_handler, bt_bdaddr_t * bdAddr,btif_cmgr_callback Callback);
1248     bt_status_t btif_create_acl_to_slave(void *cmgr_handler, bt_bdaddr_t * bdAddr,btif_cmgr_callback Callback);
1249     bt_status_t btif_register_cmgr_handle(void *cmgr_handler,btif_cmgr_callback Callback);
1250     void btif_me_update_cmgr_info(void *cmgr_handler,btif_BtDeviceContext* bt_device_context,btif_remote_device_t * rdev);
1251     void btif_me_unregister_globa_handler(btif_handler * handler);
1252     void btif_me_set_inquiry_mode(uint8_t mode);
1253     void btif_me_inquiry_result_setup(uint8_t *inquiry_buff, bool rssi,
1254                                     bool extended_mode);
1255     btif_remote_device_t *btif_me_enumerate_remote_devices(uint32_t devid);
1256 
1257     uint8_t btif_me_get_remote_sevice_encrypt_state(btif_remote_device_t* rdev);
1258 
1259    uint8_t btif_me_get_remote_device_disc_reason_saved(btif_remote_device_t * device);
1260 
1261 
1262    uint8_t btif_me_get_remote_device_disc_reason(btif_remote_device_t * device);
1263 
1264    void  btif_me_event_report(me_event_t *event);
1265    void btif_me_init_peer_headset_addr(uint8_t *p_remote_addr);
1266    bt_bdaddr_t * btif_me_get_peer_headset_addr(void);
1267    uint8_t btif_me_get_remote_device_link_mode(btif_remote_device_t* rdev);
1268    uint8_t btif_me_get_remote_device_bt_role(btif_remote_device_t* rdev);
1269    bt_status_t btif_me_change_packet_type(btif_remote_device_t *rdev, btif_acl_packet packetTypes);
1270    void btif_me_cobuf_state_dump(void);
1271    void btif_me_hcibuff_state_dump(void);
1272 
1273 #if defined(IBRT)
1274     // ibrt fast ack toggle
1275     #define IBRT_FAST_ACK_OFF                    (0)
1276     #define IBRT_FAST_ACK_ON                     (1)
1277     // ibrt fast direction
1278     #define IBRT_FAST_ACK_TX                     0
1279     #define IBRT_FAST_ACK_RX                     1
1280     // ibrt slave flow control
1281     #define IBRT_SLAVE_FLOW_CTRL_ON              IBRT_FAST_ACK_OFF
1282     #define IBRT_SLAVE_FLOW_CTRL_OFF             IBRT_FAST_ACK_ON
1283 
1284     bt_status_t btif_me_enable_fastack(uint16_t conhdl, uint8_t direction, uint8_t enable);
1285     bt_status_t btif_me_start_ibrt(U16 slaveConnHandle, U16 mobileConnHandle);
1286     bt_status_t btif_me_stop_ibrt(uint8_t enable,uint8_t reason);
1287     bt_status_t btif_me_suspend_ibrt(void);
1288     bt_status_t btif_me_ibrt_mode_init(bool enable);
1289     bt_status_t btif_me_ibrt_role_switch(uint8_t switch_op);
1290 
1291     void btif_me_set_ibrt_mobile_hci_handle(uint16_t hci_handle);
1292     uint16_t btif_me_get_ibrt_mobile_hci_handle(void);
1293 
1294     void btif_me_set_devctx_state(uint8_t ctx_idx, uint16_t state);
1295     void btif_me_set_devctx_link(uint8_t ctx_idx, btif_remote_device_t * rm_dev);
1296     bt_bdaddr_t*  btif_me_get_devctx_btaddr(uint8_t ctx_idx);
1297     btif_remote_device_t* btif_me_get_remote_device(uint8_t dev_index);
1298     void btif_me_free_tws_outgoing_dev(uint8_t *peer_tws_addr);
1299     btif_remote_device_t*  btif_me_get_devctx_remote_device(uint8_t ctx_idx);
1300     btif_remote_device_t * btif_me_avdev_ctx_get_conn_remote_device(uint8_t dev_idx);
1301 
1302     uint32_t btif_me_save_record_ctx(uint8_t *ctx_buffer, uint8_t *addr);
1303     uint32_t btif_me_set_record_ctx(uint8_t *ctx_buffer,  uint8_t *addr);
1304     uint32_t btif_me_save_me_ctx(uint8_t *ctx_buffer, uint16_t dev_id);
1305     uint32_t btif_me_set_me_ctx(uint8_t *ctx_buffer, uint16_t dev_id);
1306     uint8_t btif_me_get_mobile_avdev_index(uint16_t mobile_handle);
1307     uint8_t btif_me_get_free_avdev_index(void);
1308     uint32_t btif_me_save_avdev_ctx(uint8_t*  ctx_buffer, uint16_t dev_id);
1309     uint32_t btif_me_set_avdev_ctx(uint8_t *ctx_buffer, uint16_t dev_id, uint8_t rm_devtbl_idx);
1310     void btif_me_conn_auto_accept_enable(uint8_t *condition);
1311     uint8_t btif_me_get_callback_event_encty_mode(const btif_event_t * event);
1312     btif_dev_linkkey *btif_me_get_callback_link_key(const btif_event_t *event);
1313     void btif_me_register_ibrt_disconnect_callback(btif_callback cb);
1314     bt_status_t btif_me_set_tws_poll_interval(uint16_t conn_handle, uint16_t poll_interval);
1315     bt_status_t btif_me_resume_ibrt(uint8_t enable);
1316     void btif_me_write_scan_activity_specific(uint16_t opcode, uint16_t scan_interval, uint16_t scan_window);
1317     void btif_me_write_dbg_sniffer(const uint8_t subcode, const uint16_t connhandle);
1318     void btif_me_ibrt_simu_hci_event_disallow(uint8_t opcode1, uint8_t opcode2);
1319     void btif_me_register_conn_req_pre_treatment_callback(btif_callback cb);
1320     void btif_me_register_cmd_status_callback(btif_callback cb);
1321     void btif_me_register_cmd_complete_callback(btif_callback cb);
1322     bt_status_t btif_me_ibrt_conn_connected(bt_bdaddr_t *bt_addr, uint16_t conhdl);
1323     bt_status_t btif_me_ibrt_conn_disconnected(bt_bdaddr_t *bt_addr, uint16_t conhdl, uint8_t status, uint8_t reason);
1324     void btif_me_register_ibrt_io_capbility_callback(ibrt_io_capbility_callback cb);
1325     bt_status_t btif_me_auth_req(uint16_t conn_handle);
1326 #endif
1327 #ifdef __cplusplus
1328 }
1329 #endif                          /*  */
1330 #endif                          /* __ME_H */
1331