• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 1999-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  this file contains the main Bluetooth Manager (BTM) internal
22  *  definitions.
23  *
24  ******************************************************************************/
25 #ifndef BTM_INT_H
26 #define BTM_INT_H
27 
28 #include "bt_target.h"
29 #include "gki.h"
30 #include "hcidefs.h"
31 
32 #include "rfcdefs.h"
33 
34 #include "btm_api.h"
35 
36 #if (BLE_INCLUDED == TRUE)
37 #include "btm_ble_int.h"
38 #if (SMP_INCLUDED == TRUE)
39 #include "smp_api.h"
40 #endif
41 #endif
42 
43 #if BTM_MAX_LOC_BD_NAME_LEN > 0
44 typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1];
45 #endif
46 
47 #define  BTM_ACL_IS_CONNECTED(bda)   (btm_bda_to_acl (bda, BT_TRANSPORT_BR_EDR) != NULL)
48 
49 /* Definitions for Server Channel Number (SCN) management
50 */
51 #define BTM_MAX_SCN      PORT_MAX_RFC_PORTS
52 
53 /* Define masks for supported and exception 2.0 ACL packet types
54 */
55 #define BTM_ACL_SUPPORTED_PKTS_MASK      (HCI_PKT_TYPES_MASK_DM1        | \
56                                           HCI_PKT_TYPES_MASK_DH1        | \
57                                           HCI_PKT_TYPES_MASK_DM3        | \
58                                           HCI_PKT_TYPES_MASK_DH3        | \
59                                           HCI_PKT_TYPES_MASK_DM5        | \
60                                           HCI_PKT_TYPES_MASK_DH5)
61 
62 #define BTM_ACL_EXCEPTION_PKTS_MASK      (HCI_PKT_TYPES_MASK_NO_2_DH1   | \
63                                           HCI_PKT_TYPES_MASK_NO_3_DH1   | \
64                                           HCI_PKT_TYPES_MASK_NO_2_DH3   | \
65                                           HCI_PKT_TYPES_MASK_NO_3_DH3   | \
66                                           HCI_PKT_TYPES_MASK_NO_2_DH5   | \
67                                           HCI_PKT_TYPES_MASK_NO_3_DH5)
68 
69 #define BTM_EPR_AVAILABLE(p) ((HCI_ATOMIC_ENCRYPT_SUPPORTED((p)->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) && \
70                                HCI_ATOMIC_ENCRYPT_SUPPORTED(controller_get_interface()->get_features_classic(0)->as_array)) \
71                                ? TRUE : FALSE)
72 
73 #define BTM_IS_BRCM_CONTROLLER() (controller_get_interface()->get_bt_version()->manufacturer == LMP_COMPID_BROADCOM)
74 
75 /* Define the ACL Management control structure
76 */
77 typedef struct
78 {
79     UINT16          hci_handle;
80     UINT16          pkt_types_mask;
81     UINT16          clock_offset;
82     BD_ADDR         remote_addr;
83     DEV_CLASS       remote_dc;
84     BD_NAME         remote_name;
85 
86     UINT16          manufacturer;
87     UINT16          lmp_subversion;
88     UINT16          link_super_tout;
89     BD_FEATURES     peer_lmp_features[HCI_EXT_FEATURES_PAGE_MAX + 1];    /* Peer LMP Extended features mask table for the device */
90     UINT8           num_read_pages;
91     UINT8           lmp_version;
92 
93     BOOLEAN         in_use;
94     UINT8           link_role;
95     BOOLEAN         link_up_issued;     /* True if busy_level link up has been issued */
96 
97 #define BTM_ACL_SWKEY_STATE_IDLE                0
98 #define BTM_ACL_SWKEY_STATE_MODE_CHANGE         1
99 #define BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF      2
100 #define BTM_ACL_SWKEY_STATE_SWITCHING           3
101 #define BTM_ACL_SWKEY_STATE_ENCRYPTION_ON       4
102 #define BTM_ACL_SWKEY_STATE_IN_PROGRESS         5
103     UINT8           switch_role_state;
104 
105 #define BTM_ACL_ENCRYPT_STATE_IDLE              0
106 #define BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF       1   /* encryption turning off */
107 #define BTM_ACL_ENCRYPT_STATE_TEMP_FUNC         2   /* temporarily off for change link key or role switch */
108 #define BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON        3   /* encryption turning on */
109     UINT8           encrypt_state;                  /* overall BTM encryption state */
110 
111 #if BLE_INCLUDED == TRUE
112     tBT_TRANSPORT   transport;
113     BD_ADDR         conn_addr;              /* local device address used for this connection */
114     UINT8           conn_addr_type;         /* local device address type for this connection */
115     BD_ADDR         active_remote_addr;     /* remote address used on this connection */
116     UINT8           active_remote_addr_type;         /* local device address type for this connection */
117     BD_FEATURES     peer_le_features;       /* Peer LE Used features mask for the device */
118 
119 #endif
120 
121 } tACL_CONN;
122 
123 /*****************************************************
124 ** TIMER Definitions
125 ******************************************************/
126 #define TT_DEV_RESET     1
127 #define TT_DEV_RLN       2
128 #define TT_DEV_RLNKP     4              /* Read Link Policy Settings */
129 
130 /* Define the Device Management control structure
131 */
132 typedef struct
133 {
134     tBTM_DEV_STATUS_CB  *p_dev_status_cb;   /* Device status change callback        */
135     tBTM_VS_EVT_CB      *p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS];     /* Register for vendor specific events  */
136 
137     tBTM_CMPL_CB        *p_stored_link_key_cmpl_cb;   /* Read/Write/Delete stored link key    */
138 
139     TIMER_LIST_ENT       reset_timer;
140 
141     TIMER_LIST_ENT       rln_timer;
142     tBTM_CMPL_CB        *p_rln_cmpl_cb;     /* Callback function to be called when  */
143                                             /* read local name function complete    */
144     TIMER_LIST_ENT       rssi_timer;
145     tBTM_CMPL_CB        *p_rssi_cmpl_cb;    /* Callback function to be called when  */
146                                             /* read rssi function completes         */
147     TIMER_LIST_ENT       lnk_quality_timer;
148     tBTM_CMPL_CB        *p_lnk_qual_cmpl_cb;/* Callback function to be called when  */
149                                             /* read link quality function completes */
150     TIMER_LIST_ENT       txpwer_timer;
151     tBTM_CMPL_CB        *p_txpwer_cmpl_cb;    /* Callback function to be called when  */
152                                             /* read inq tx power function completes  */
153 
154     TIMER_LIST_ENT       qossu_timer;
155     tBTM_CMPL_CB        *p_qossu_cmpl_cb;   /* Callback function to be called when  */
156                                             /* qos setup function completes         */
157 
158     tBTM_ROLE_SWITCH_CMPL switch_role_ref_data;
159     tBTM_CMPL_CB        *p_switch_role_cb;  /* Callback function to be called when  */
160                                             /* requested switch role is completed   */
161 
162     TIMER_LIST_ENT       tx_power_timer;
163     tBTM_CMPL_CB        *p_tx_power_cmpl_cb;/* Callback function to be called       */
164 
165     DEV_CLASS            dev_class;         /* Local device class                   */
166 
167 #if BLE_INCLUDED == TRUE
168 
169     tBTM_CMPL_CB        *p_le_test_cmd_cmpl_cb;   /* Callback function to be called when
170                                                   LE test mode command has been sent successfully */
171 
172     BD_ADDR                 read_tx_pwr_addr;   /* read TX power target address     */
173 
174 #define BTM_LE_SUPPORT_STATE_SIZE   8
175 UINT8                   le_supported_states[BTM_LE_SUPPORT_STATE_SIZE];
176 
177 tBTM_BLE_LOCAL_ID_KEYS id_keys; /* local BLE ID keys */
178 BT_OCTET16 ble_encryption_key_value; /* BLE encryption key */
179 
180 #if BTM_BLE_CONFORMANCE_TESTING == TRUE
181     BOOLEAN                 no_disc_if_pair_fail;
182     BOOLEAN                 enable_test_mac_val;
183     BT_OCTET8               test_mac;
184     BOOLEAN                 enable_test_local_sign_cntr;
185     UINT32                  test_local_sign_cntr;
186 #endif
187 
188 #endif  /* BLE_INCLUDED */
189 
190     tBTM_IO_CAP          loc_io_caps;       /* IO capability of the local device */
191     tBTM_AUTH_REQ        loc_auth_req;      /* the auth_req flag  */
192     BOOLEAN              secure_connections_only;    /* Rejects service level 0 connections if */
193                                                      /* itself or peer device doesn't support */
194                                                      /* secure connections */
195 } tBTM_DEVCB;
196 
197 
198 /* Define the structures and constants used for inquiry
199 */
200 
201 /* Definitions of limits for inquiries */
202 #define BTM_PER_INQ_MIN_MAX_PERIOD      HCI_PER_INQ_MIN_MAX_PERIOD
203 #define BTM_PER_INQ_MAX_MAX_PERIOD      HCI_PER_INQ_MAX_MAX_PERIOD
204 #define BTM_PER_INQ_MIN_MIN_PERIOD      HCI_PER_INQ_MIN_MIN_PERIOD
205 #define BTM_PER_INQ_MAX_MIN_PERIOD      HCI_PER_INQ_MAX_MIN_PERIOD
206 #define BTM_MAX_INQUIRY_LENGTH          HCI_MAX_INQUIRY_LENGTH
207 #define BTM_MIN_INQUIRY_LEN             0x01
208 
209 #define BTM_MIN_INQ_TX_POWER    -70
210 #define BTM_MAX_INQ_TX_POWER    20
211 
212 typedef struct
213 {
214     UINT32          inq_count;          /* Used for determining if a response has already been      */
215                                         /* received for the current inquiry operation. (We do not   */
216                                         /* want to flood the caller with multiple responses from    */
217                                         /* the same device.                                         */
218     BD_ADDR         bd_addr;
219 } tINQ_BDADDR;
220 
221 typedef struct
222 {
223     UINT32          time_of_resp;
224     UINT32          inq_count;          /* "timestamps" the entry with a particular inquiry count   */
225                                         /* Used for determining if a response has already been      */
226                                         /* received for the current inquiry operation. (We do not   */
227                                         /* want to flood the caller with multiple responses from    */
228                                         /* the same device.                                         */
229     tBTM_INQ_INFO   inq_info;
230     BOOLEAN         in_use;
231 
232 #if (BLE_INCLUDED == TRUE)
233     BOOLEAN         scan_rsp;
234 #endif
235 } tINQ_DB_ENT;
236 
237 
238 enum
239 {
240     INQ_NONE,
241     INQ_LE_OBSERVE,
242     INQ_GENERAL
243 };
244 typedef UINT8 tBTM_INQ_TYPE;
245 
246 typedef struct
247 {
248     tBTM_CMPL_CB *p_remname_cmpl_cb;
249 
250 #define BTM_EXT_RMT_NAME_TIMEOUT    40
251 
252 
253     TIMER_LIST_ENT  rmt_name_timer_ent;
254 
255     UINT16           discoverable_mode;
256     UINT16           connectable_mode;
257     UINT16           page_scan_window;
258     UINT16           page_scan_period;
259     UINT16           inq_scan_window;
260     UINT16           inq_scan_period;
261     UINT16           inq_scan_type;
262     UINT16           page_scan_type;        /* current page scan type */
263     tBTM_INQ_TYPE    scan_type;
264 
265     BD_ADDR          remname_bda;           /* Name of bd addr for active remote name request */
266 #define BTM_RMT_NAME_INACTIVE       0
267 #define BTM_RMT_NAME_EXT            0x1     /* Initiated through API */
268 #define BTM_RMT_NAME_SEC            0x2     /* Initiated internally by security manager */
269 #define BTM_RMT_NAME_INQ            0x4     /* Remote name initiated internally by inquiry */
270     BOOLEAN          remname_active;        /* State of a remote name request by external API */
271 
272     tBTM_CMPL_CB    *p_inq_cmpl_cb;
273     tBTM_INQ_RESULTS_CB *p_inq_results_cb;
274     tBTM_CMPL_CB    *p_inq_ble_cmpl_cb;     /*completion callback exclusively for LE Observe*/
275     tBTM_INQ_RESULTS_CB *p_inq_ble_results_cb;/*results callback exclusively for LE observe*/
276     tBTM_CMPL_CB    *p_inqfilter_cmpl_cb;   /* Called (if not NULL) after inquiry filter completed */
277     UINT32           inq_counter;           /* Counter incremented each time an inquiry completes */
278                                             /* Used for determining whether or not duplicate devices */
279                                             /* have responded to the same inquiry */
280     TIMER_LIST_ENT   inq_timer_ent;
281     tINQ_BDADDR     *p_bd_db;               /* Pointer to memory that holds bdaddrs */
282     UINT16           num_bd_entries;        /* Number of entries in database */
283     UINT16           max_bd_entries;        /* Maximum number of entries that can be stored */
284     tINQ_DB_ENT      inq_db[BTM_INQ_DB_SIZE];
285     tBTM_INQ_PARMS   inqparms;              /* Contains the parameters for the current inquiry */
286     tBTM_INQUIRY_CMPL inq_cmpl_info;        /* Status and number of responses from the last inquiry */
287 
288     UINT16           per_min_delay;         /* Current periodic minimum delay */
289     UINT16           per_max_delay;         /* Current periodic maximum delay */
290     BOOLEAN          inqfilt_active;
291     UINT8            pending_filt_complete_event; /* to take care of btm_event_filter_complete corresponding to */
292                                                   /* inquiry that has been cancelled*/
293     UINT8            inqfilt_type;          /* Contains the inquiry filter type (BD ADDR, COD, or Clear) */
294 
295 #define BTM_INQ_INACTIVE_STATE      0
296 #define BTM_INQ_CLR_FILT_STATE      1   /* Currently clearing the inquiry filter preceeding the inquiry request */
297                                         /* (bypassed if filtering is not used)                                  */
298 #define BTM_INQ_SET_FILT_STATE      2   /* Sets the new filter (or turns off filtering) in this state */
299 #define BTM_INQ_ACTIVE_STATE        3   /* Actual inquiry or periodic inquiry is in progress */
300 #define BTM_INQ_REMNAME_STATE       4   /* Remote name requests are active  */
301 
302     UINT8            state;             /* Current state that the inquiry process is in */
303     UINT8            inq_active;        /* Bit Mask indicating type of inquiry is active */
304     BOOLEAN          no_inc_ssp;        /* TRUE, to stop inquiry on incoming SSP */
305 #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
306     btm_inq_state    next_state;        /*interleaving state to determine next mode to be inquired*/
307 #endif
308 } tBTM_INQUIRY_VAR_ST;
309 
310 /* The MSB of the clock offset field indicates that the offset is valid if TRUE */
311 #define BTM_CLOCK_OFFSET_VALID      0x8000
312 
313 /* Define the structures needed by security management
314 */
315 
316 #define BTM_SEC_INVALID_HANDLE  0xFFFF
317 
318 typedef UINT8 *BTM_BD_NAME_PTR;                        /* Pointer to Device name */
319 
320 /* Security callback is called by this unit when security
321 **   procedures are completed.  Parameters are
322 **              BD Address of remote
323 **              Result of the operation
324 */
325 typedef tBTM_SEC_CBACK tBTM_SEC_CALLBACK;
326 
327 typedef void (tBTM_SCO_IND_CBACK) (UINT16 sco_inx) ;
328 
329 /* MACROs to convert from SCO packet types mask to ESCO and back */
330 #define BTM_SCO_PKT_TYPE_MASK   (   HCI_PKT_TYPES_MASK_HV1      \
331                                  |  HCI_PKT_TYPES_MASK_HV2      \
332                                  |  HCI_PKT_TYPES_MASK_HV3)
333 
334 /* Mask defining only the SCO types of an esco packet type */
335 #define BTM_ESCO_PKT_TYPE_MASK  (   HCI_ESCO_PKT_TYPES_MASK_HV1 \
336                                  |  HCI_ESCO_PKT_TYPES_MASK_HV2 \
337                                  |  HCI_ESCO_PKT_TYPES_MASK_HV3)
338 
339 #define BTM_SCO_2_ESCO(scotype)  ((UINT16)(((scotype) & BTM_SCO_PKT_TYPE_MASK) >> 5))
340 #define BTM_ESCO_2_SCO(escotype) ((UINT16)(((escotype) & BTM_ESCO_PKT_TYPE_MASK) << 5))
341 
342 /* Define masks for supported and exception 2.0 SCO packet types
343 */
344 #define BTM_SCO_SUPPORTED_PKTS_MASK      (HCI_ESCO_PKT_TYPES_MASK_HV1       | \
345                                           HCI_ESCO_PKT_TYPES_MASK_HV2       | \
346                                           HCI_ESCO_PKT_TYPES_MASK_HV3       | \
347                                           HCI_ESCO_PKT_TYPES_MASK_EV3       | \
348                                           HCI_ESCO_PKT_TYPES_MASK_EV4       | \
349                                           HCI_ESCO_PKT_TYPES_MASK_EV5)
350 
351 #define BTM_SCO_EXCEPTION_PKTS_MASK      (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3  | \
352                                           HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3  | \
353                                           HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5  | \
354                                           HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5)
355 
356 
357 #define BTM_SCO_ROUTE_UNKNOWN       0xff
358 
359 /* Define the structure that contains (e)SCO data */
360 typedef struct
361 {
362     tBTM_ESCO_CBACK    *p_esco_cback;   /* Callback for eSCO events     */
363     tBTM_ESCO_PARAMS    setup;
364     tBTM_ESCO_DATA      data;           /* Connection complete information */
365     UINT8               hci_status;
366 } tBTM_ESCO_INFO;
367 
368 /* Define the structure used for SCO Management
369 */
370 typedef struct
371 {
372     tBTM_ESCO_INFO   esco;              /* Current settings             */
373 #if BTM_SCO_HCI_INCLUDED == TRUE
374     BUFFER_Q         xmit_data_q;       /* SCO data transmitting queue  */
375 #endif
376     tBTM_SCO_CB     *p_conn_cb;         /* Callback for when connected  */
377     tBTM_SCO_CB     *p_disc_cb;         /* Callback for when disconnect */
378     UINT16           state;             /* The state of the SCO link    */
379     UINT16           hci_handle;        /* HCI Handle                   */
380     BOOLEAN          is_orig;           /* TRUE if the originator       */
381     BOOLEAN          rem_bd_known;      /* TRUE if remote BD addr known */
382 
383 } tSCO_CONN;
384 
385 /* SCO Management control block */
386 typedef struct
387 {
388     tBTM_SCO_IND_CBACK  *app_sco_ind_cb;
389 #if BTM_SCO_HCI_INCLUDED == TRUE
390     tBTM_SCO_DATA_CB     *p_data_cb;        /* Callback for SCO data over HCI */
391     UINT32               xmit_window_size; /* Total SCO window in bytes  */
392 #endif
393     tSCO_CONN            sco_db[BTM_MAX_SCO_LINKS];
394     tBTM_ESCO_PARAMS     def_esco_parms;
395     BD_ADDR              xfer_addr;
396     UINT16               sco_disc_reason;
397     BOOLEAN              esco_supported;    /* TRUE if 1.2 cntlr AND supports eSCO links */
398     tBTM_SCO_TYPE        desired_sco_mode;
399     tBTM_SCO_TYPE        xfer_sco_type;
400     tBTM_SCO_PCM_PARAM   sco_pcm_param;
401     tBTM_SCO_CODEC_TYPE  codec_in_use;      /* None, CVSD, MSBC, etc. */
402 #if BTM_SCO_HCI_INCLUDED == TRUE
403     tBTM_SCO_ROUTE_TYPE  sco_path;
404 #endif
405 
406 } tSCO_CB;
407 
408 
409 #if BTM_SCO_INCLUDED == TRUE
410 extern void     btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb );
411 extern void     btm_accept_sco_link(UINT16 sco_inx, tBTM_ESCO_PARAMS *p_setup,
412                                     tBTM_SCO_CB *p_conn_cb, tBTM_SCO_CB *p_disc_cb);
413 extern void     btm_reject_sco_link(UINT16 sco_inx );
414 extern void btm_sco_chk_pend_rolechange (UINT16 hci_handle);
415 #else
416 #define btm_accept_sco_link(sco_inx, p_setup, p_conn_cb, p_disc_cb)
417 #define btm_reject_sco_link(sco_inx)
418 #define btm_set_sco_ind_cback(sco_ind_cb)
419 #define btm_sco_chk_pend_rolechange(hci_handle)
420 #endif  /* BTM_SCO_INCLUDED */
421 
422 /*
423 ** Define structure for Security Service Record.
424 ** A record exists for each service registered with the Security Manager
425 */
426 typedef struct
427 {
428     UINT32          mx_proto_id;        /* Service runs over this multiplexer protocol */
429     UINT32          orig_mx_chan_id;    /* Channel on the multiplexer protocol    */
430     UINT32          term_mx_chan_id;    /* Channel on the multiplexer protocol    */
431     UINT16          psm;                /* L2CAP PSM value */
432     UINT16          security_flags;     /* Bitmap of required security features */
433     UINT8           service_id;         /* Passed in authorization callback */
434 #if (L2CAP_UCD_INCLUDED == TRUE)
435     UINT16          ucd_security_flags; /* Bitmap of required security features for UCD */
436 #endif
437 #if BTM_SEC_SERVICE_NAME_LEN > 0
438     UINT8           orig_service_name[BTM_SEC_SERVICE_NAME_LEN + 1];
439     UINT8           term_service_name[BTM_SEC_SERVICE_NAME_LEN + 1];
440 #endif
441 } tBTM_SEC_SERV_REC;
442 
443 #if BLE_INCLUDED == TRUE
444 /* LE Security information of device in Slave Role */
445 typedef struct
446 {
447     BT_OCTET16          irk;            /* peer diverified identity root */
448     BT_OCTET16          pltk;           /* peer long term key */
449     BT_OCTET16          pcsrk;          /* peer SRK peer device used to secured sign local data  */
450 
451     BT_OCTET16          lltk;           /* local long term key */
452     BT_OCTET16          lcsrk;          /* local SRK peer device used to secured sign local data  */
453 
454     BT_OCTET8           rand;           /* random vector for LTK generation */
455     UINT16              ediv;           /* LTK diversifier of this slave device */
456     UINT16              div;            /* local DIV  to generate local LTK=d1(ER,DIV,0) and CSRK=d1(ER,DIV,1)  */
457     UINT8               sec_level;      /* local pairing security level */
458     UINT8               key_size;       /* key size of the LTK delivered to peer device */
459     UINT8               srk_sec_level;  /* security property of peer SRK for this device */
460     UINT8               local_csrk_sec_level;  /* security property of local CSRK for this device */
461 
462     UINT32              counter;        /* peer sign counter for verifying rcv signed cmd */
463     UINT32              local_counter;  /* local sign counter for sending signed write cmd*/
464 }tBTM_SEC_BLE_KEYS;
465 
466 typedef struct
467 {
468     BD_ADDR pseudo_addr; /* LE pseudo address of the device if different from device address  */
469     tBLE_ADDR_TYPE      ble_addr_type;  /* LE device type: public or random address */
470     tBLE_ADDR_TYPE      static_addr_type;   /* static address type */
471     BD_ADDR             static_addr;    /* static address */
472 
473 #define BTM_WHITE_LIST_BIT          0x01
474 #define BTM_RESOLVING_LIST_BIT      0x02
475     UINT8               in_controller_list;   /* in controller resolving list or not */
476     UINT8               resolving_list_index;
477 #if BLE_PRIVACY_SPT == TRUE
478     BD_ADDR             cur_rand_addr;  /* current random address */
479 
480 #define BTM_BLE_ADDR_PSEUDO         0   /* address index device record */
481 #define BTM_BLE_ADDR_RRA            1   /* cur_rand_addr */
482 #define BTM_BLE_ADDR_STATIC         2   /* static_addr  */
483     UINT8               active_addr_type;
484 #endif
485 
486 #if SMP_INCLUDED == TRUE
487     tBTM_LE_KEY_TYPE    key_type;       /* bit mask of valid key types in record */
488     tBTM_SEC_BLE_KEYS   keys;           /* LE device security info in slave rode */
489 #endif
490 } tBTM_SEC_BLE;
491 
492 
493 #endif  /* BLE_INCLUDED */
494 
495 /* Peering bond type */
496 enum
497 {
498     BOND_TYPE_UNKNOWN,
499     BOND_TYPE_PERSISTENT,
500     BOND_TYPE_TEMPORARY
501 };
502 typedef UINT8 tBTM_BOND_TYPE;
503 
504 /*
505 ** Define structure for Security Device Record.
506 ** A record exists for each device authenticated with this device
507 */
508 typedef struct
509 {
510     tBTM_SEC_SERV_REC   *p_cur_service;
511     tBTM_SEC_CALLBACK   *p_callback;
512     void                *p_ref_data;
513     UINT32               timestamp;         /* Timestamp of the last connection   */
514     UINT32               trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE];  /* Bitwise OR of trusted services     */
515     UINT16               hci_handle;        /* Handle to connection when exists   */
516     UINT16               clock_offset;      /* Latest known clock offset          */
517     BD_ADDR              bd_addr;           /* BD_ADDR of the device              */
518     DEV_CLASS            dev_class;         /* DEV_CLASS of the device            */
519     LINK_KEY             link_key;          /* Device link key                    */
520     UINT8                pin_code_length;   /* Length of the pin_code used for paring */
521 
522 #define BTM_SEC_AUTHORIZED      BTM_SEC_FLAG_AUTHORIZED     /* 0x01 */
523 #define BTM_SEC_AUTHENTICATED   BTM_SEC_FLAG_AUTHENTICATED  /* 0x02 */
524 #define BTM_SEC_ENCRYPTED       BTM_SEC_FLAG_ENCRYPTED      /* 0x04 */
525 #define BTM_SEC_NAME_KNOWN      0x08
526 #define BTM_SEC_LINK_KEY_KNOWN  BTM_SEC_FLAG_LKEY_KNOWN /* 0x10 */
527 #define BTM_SEC_LINK_KEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED    /* 0x20 */
528 #define BTM_SEC_ROLE_SWITCHED   0x40
529 #define BTM_SEC_IN_USE          0x80
530     /* LE link security flag */
531 #define BTM_SEC_LE_AUTHENTICATED   0x0200   /* LE link is encrypted after pairing with MITM */
532 #define BTM_SEC_LE_ENCRYPTED       0x0400   /* LE link is encrypted */
533 #define BTM_SEC_LE_NAME_KNOWN      0x0800   /* not used */
534 #define BTM_SEC_LE_LINK_KEY_KNOWN  0x1000   /* bonded with peer (peer LTK and/or SRK is saved) */
535 #define BTM_SEC_LE_LINK_KEY_AUTHED 0x2000   /* pairing is done with MITM */
536 #define BTM_SEC_16_DIGIT_PIN_AUTHED 0x4000   /* pairing is done with 16 digit pin */
537 
538     UINT16           sec_flags;          /* Current device security state      */
539 
540     tBTM_BD_NAME    sec_bd_name;        /* User friendly name of the device. (may be truncated to save space in dev_rec table) */
541     BD_FEATURES     features[HCI_EXT_FEATURES_PAGE_MAX + 1];           /* Features supported by the device */
542     UINT8           num_read_pages;
543 
544 #define BTM_SEC_STATE_IDLE               0
545 #define BTM_SEC_STATE_AUTHENTICATING     1
546 #define BTM_SEC_STATE_ENCRYPTING         2
547 #define BTM_SEC_STATE_GETTING_NAME       3
548 #define BTM_SEC_STATE_AUTHORIZING        4
549 #define BTM_SEC_STATE_SWITCHING_ROLE     5
550 #define BTM_SEC_STATE_DISCONNECTING      6 /* disconnecting BR/EDR */
551 #define BTM_SEC_STATE_DELAY_FOR_ENC      7 /* delay to check for encryption to work around */
552                                            /* controller problems */
553 #define BTM_SEC_STATE_DISCONNECTING_BLE  8 /* disconnecting BLE */
554 #define BTM_SEC_STATE_DISCONNECTING_BOTH 9 /* disconnecting BR/EDR and BLE */
555 
556     UINT8       sec_state;              /* Operating state                    */
557     BOOLEAN     is_originator;          /* TRUE if device is originating connection */
558 #if (L2CAP_UCD_INCLUDED == TRUE)
559     BOOLEAN     is_ucd;                 /* TRUE if device is sending or receiving UCD */
560                                         /* if incoming security failed, received UCD will be discarded */
561 #endif
562     BOOLEAN     role_master;            /* TRUE if current mode is master     */
563     UINT16      security_required;      /* Security required for connection   */
564     BOOLEAN     link_key_not_sent;      /* link key notification has not been sent waiting for name */
565     UINT8       link_key_type;          /* Type of key used in pairing   */
566     BOOLEAN     link_key_changed;       /* Changed link key during current connection */
567 
568 #define BTM_MAX_PRE_SM4_LKEY_TYPE   BTM_LKEY_TYPE_REMOTE_UNIT /* the link key type used by legacy pairing */
569 
570 #define BTM_SM4_UNKNOWN     0x00
571 #define BTM_SM4_KNOWN       0x10
572 #define BTM_SM4_TRUE        0x11
573 #define BTM_SM4_REQ_PEND    0x08        /* set this bit when getting remote features */
574 #define BTM_SM4_UPGRADE     0x04        /* set this bit when upgrading link key */
575 #define BTM_SM4_RETRY       0x02        /* set this bit to retry on HCI_ERR_KEY_MISSING or HCI_ERR_LMP_ERR_TRANS_COLLISION */
576 #define BTM_SM4_DD_ACP      0x20        /* set this bit to indicate peer initiated dedicated bonding */
577 #define BTM_SM4_CONN_PEND   0x40        /* set this bit to indicate accepting acl conn; to be cleared on btm_acl_created */
578     UINT8       sm4;                    /* BTM_SM4_TRUE, if the peer supports SM4 */
579     tBTM_IO_CAP rmt_io_caps;            /* IO capability of the peer device */
580     tBTM_AUTH_REQ rmt_auth_req;         /* the auth_req flag as in the IO caps rsp evt */
581     BOOLEAN     remote_supports_secure_connections;
582     BOOLEAN     remote_features_needed; /* set to true if the local device is in */
583                                         /* "Secure Connections Only" mode and it receives */
584                                         /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */
585                                         /* it knows peer's support for Secure Connections */
586 
587     UINT16              ble_hci_handle;         /* use in DUMO connection */
588     UINT8               enc_key_size;           /* current link encryption key size */
589     tBT_DEVICE_TYPE     device_type;
590     BOOLEAN             new_encryption_key_is_p256; /* Set to TRUE when the newly generated LK
591                                                     ** is generated from P-256.
592                                                     ** Link encrypted with such LK can be used
593                                                     ** for SM over BR/EDR.
594                                                     */
595     BOOLEAN no_smp_on_br;       /* if set to TRUE then SMP on BR/EDR doesn't */
596                                 /* work, i.e. link keys crosspairing */
597                                 /* SC BR/EDR->SC LE doesn't happen */
598     tBTM_BOND_TYPE bond_type;   /* peering bond type */
599 
600 #if BLE_INCLUDED == TRUE
601     tBTM_SEC_BLE        ble;
602     tBTM_LE_CONN_PRAMS  conn_params;
603 #endif
604 
605 // btla-specific ++
606 #if BTM_DISC_DURING_RS == TRUE
607 #define BTM_SEC_RS_NOT_PENDING          0           /* Role Switch not in progress */
608 #define BTM_SEC_RS_PENDING              1           /* Role Switch in progress */
609 #define BTM_SEC_DISC_PENDING            2           /* Disconnect is pending */
610     UINT8           rs_disc_pending;
611 #endif
612 // btla-specific --
613 #define BTM_SEC_NO_LAST_SERVICE_ID      0
614     UINT8           last_author_service_id;         /* ID of last serviced authorized: Reset after each l2cap connection */
615 
616 } tBTM_SEC_DEV_REC;
617 
618 #define BTM_SEC_IS_SM4(sm) ((BOOLEAN)(BTM_SM4_TRUE == ((sm)&BTM_SM4_TRUE)))
619 #define BTM_SEC_IS_SM4_LEGACY(sm) ((BOOLEAN)(BTM_SM4_KNOWN == ((sm)&BTM_SM4_TRUE)))
620 #define BTM_SEC_IS_SM4_UNKNOWN(sm) ((BOOLEAN)(BTM_SM4_UNKNOWN == ((sm)&BTM_SM4_TRUE)))
621 
622 #define BTM_SEC_LE_MASK    (BTM_SEC_LE_AUTHENTICATED|BTM_SEC_LE_ENCRYPTED|BTM_SEC_LE_LINK_KEY_KNOWN|BTM_SEC_LE_LINK_KEY_AUTHED)
623 
624 /*
625 ** Define device configuration structure
626 */
627 typedef struct
628 {
629 #if BTM_MAX_LOC_BD_NAME_LEN > 0
630     tBTM_LOC_BD_NAME bd_name;                    /* local Bluetooth device name */
631 #endif
632     BOOLEAN          pin_type;                   /* TRUE if PIN type is fixed */
633     UINT8            pin_code_len;               /* Bonding information */
634     PIN_CODE         pin_code;                   /* PIN CODE if pin type is fixed */
635     BOOLEAN          connectable;                /* If TRUE page scan should be enabled */
636     UINT8            def_inq_scan_mode;          /* ??? limited/general/none */
637 } tBTM_CFG;
638 
639 enum
640 {
641     BTM_PM_ST_ACTIVE  = BTM_PM_STS_ACTIVE,
642     BTM_PM_ST_HOLD    = BTM_PM_STS_HOLD,
643     BTM_PM_ST_SNIFF   = BTM_PM_STS_SNIFF,
644     BTM_PM_ST_PARK    = BTM_PM_STS_PARK,
645     BTM_PM_ST_PENDING = BTM_PM_STS_PENDING
646 };
647 typedef UINT8 tBTM_PM_STATE;
648 
649 enum
650 {
651     BTM_PM_SET_MODE_EVT,    /* Set power mode API is called. */
652     BTM_PM_UPDATE_EVT,
653     BTM_PM_RD_MODE_EVT     /* Read power mode API is called. */
654 };
655 typedef UINT8 tBTM_PM_EVENT;
656 
657 typedef struct
658 {
659     UINT16          event;
660     UINT16          len;
661     UINT8           link_ind;
662 } tBTM_PM_MSG_DATA;
663 
664 typedef struct
665 {
666     UINT8 hci_status;
667     UINT8 mode;
668     UINT16 interval;
669 } tBTM_PM_MD_CHG_DATA;
670 
671 typedef struct
672 {
673     UINT8          pm_id;      /* the entity that calls SetPowerMode API */
674     tBTM_PM_PWR_MD *p_pmd;
675 } tBTM_PM_SET_MD_DATA;
676 
677 typedef struct
678 {
679     void        *p_data;
680     UINT8        link_ind;
681 } tBTM_PM_SM_DATA;
682 
683 typedef struct
684 {
685     tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS+1]; /* the desired mode and parameters of the connection*/
686     tBTM_PM_PWR_MD set_mode;  /* the mode and parameters sent down to the host controller. */
687     UINT16         interval;  /* the interval from last mode change event. */
688 #if (BTM_SSR_INCLUDED == TRUE)
689     UINT16         max_lat;   /* stored SSR maximum latency */
690     UINT16         min_rmt_to;/* stored SSR minimum remote timeout */
691     UINT16         min_loc_to;/* stored SSR minimum local timeout */
692 #endif
693     tBTM_PM_STATE  state;     /* contains the current mode of the connection */
694     BOOLEAN        chg_ind;   /* a request change indication */
695 } tBTM_PM_MCB;
696 
697 #define BTM_PM_REC_NOT_USED 0
698 typedef struct
699 {
700     tBTM_PM_STATUS_CBACK *cback;/* to notify the registered party of mode change event */
701     UINT8                 mask; /* registered request mask. 0, if this entry is not used */
702 } tBTM_PM_RCB;
703 
704 enum
705 {
706     BTM_BLI_ACL_UP_EVT,
707     BTM_BLI_ACL_DOWN_EVT,
708     BTM_BLI_PAGE_EVT,
709     BTM_BLI_PAGE_DONE_EVT,
710     BTM_BLI_INQ_EVT,
711     BTM_BLI_INQ_CANCEL_EVT,
712     BTM_BLI_INQ_DONE_EVT
713 };
714 typedef UINT8 tBTM_BLI_EVENT;
715 
716 /* Pairing State */
717 enum
718 {
719     BTM_PAIR_STATE_IDLE,                        /* Idle                                         */
720     BTM_PAIR_STATE_GET_REM_NAME,                /* Getting the remote name (to check for SM4)   */
721     BTM_PAIR_STATE_WAIT_PIN_REQ,                /* Started authentication, waiting for PIN req (PIN is pre-fetched) */
722     BTM_PAIR_STATE_WAIT_LOCAL_PIN,              /* Waiting for local PIN code                   */
723     BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM,        /* Waiting user 'yes' to numeric confirmation   */
724     BTM_PAIR_STATE_KEY_ENTRY,                   /* Key entry state (we are a keyboard)          */
725     BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP,          /* Waiting for local response to peer OOB data  */
726     BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS,           /* Waiting for local IO capabilities and OOB data */
727     BTM_PAIR_STATE_INCOMING_SSP,                /* Incoming SSP (got peer IO caps when idle)    */
728     BTM_PAIR_STATE_WAIT_AUTH_COMPLETE,          /* All done, waiting authentication cpmplete    */
729     BTM_PAIR_STATE_WAIT_DISCONNECT              /* Waiting to disconnect the ACL                */
730 };
731 typedef UINT8 tBTM_PAIRING_STATE;
732 
733 #define BTM_PAIR_FLAGS_WE_STARTED_DD    0x01    /* We want to do dedicated bonding              */
734 #define BTM_PAIR_FLAGS_PEER_STARTED_DD  0x02    /* Peer initiated dedicated bonding             */
735 #define BTM_PAIR_FLAGS_DISC_WHEN_DONE   0x04    /* Disconnect when done     */
736 #define BTM_PAIR_FLAGS_PIN_REQD         0x08    /* set this bit when pin_callback is called     */
737 #define BTM_PAIR_FLAGS_PRE_FETCH_PIN    0x10    /* set this bit when pre-fetch pin     */
738 #define BTM_PAIR_FLAGS_REJECTED_CONNECT 0x20    /* set this bit when rejected incoming connection  */
739 #define BTM_PAIR_FLAGS_WE_CANCEL_DD     0x40    /* set this bit when cancelling a bonding procedure */
740 #define BTM_PAIR_FLAGS_LE_ACTIVE        0x80    /* use this bit when SMP pairing is active */
741 
742 
743 typedef struct
744 {
745     BOOLEAN             is_mux;
746     BD_ADDR             bd_addr;
747     UINT16              psm;
748     BOOLEAN             is_orig;
749     tBTM_SEC_CALLBACK   *p_callback;
750     void                *p_ref_data;
751     UINT32              mx_proto_id;
752     UINT32              mx_chan_id;
753     tBT_TRANSPORT       transport;
754 } tBTM_SEC_QUEUE_ENTRY;
755 
756 #if (L2CAP_UCD_INCLUDED == TRUE)
757 
758 #define CONN_ORIENT_TERM                0x00    /* incoming connection oriented */
759 #define CONN_ORIENT_ORIG                0x01    /* outgoing connection oriented */
760 #define CONNLESS_TERM                   0x02    /* incoming connectionless      */
761 #define CONNLESS_ORIG                   0x03    /* outgoing connectionless      */
762 #define CONNECTION_TYPE_ORIG_MASK       0x01    /* mask for direction           */
763 #define CONNECTION_TYPE_CONNLESS_MASK   0x02    /* mask for connectionless or not */
764 typedef UINT8 CONNECTION_TYPE;
765 
766 #else
767 
768 #define CONN_ORIENT_TERM                FALSE
769 #define CONN_ORIENT_ORIG                TRUE
770 typedef BOOLEAN CONNECTION_TYPE;
771 
772 #endif /* (L2CAP_UCD_INCLUDED == TRUE) */
773 
774 /* Define a structure to hold all the BTM data
775 */
776 
777 #define BTM_STATE_BUFFER_SIZE  5                  /* size of state buffer */
778 
779 typedef struct
780 {
781     tBTM_CFG    cfg;                        /* Device configuration */
782 
783     /****************************************************
784     **      ACL Management
785     ****************************************************/
786     tACL_CONN   acl_db[MAX_L2CAP_LINKS];
787     UINT8       btm_scn[BTM_MAX_SCN];        /* current SCNs: TRUE if SCN is in use */
788     UINT16      btm_def_link_policy;
789     UINT16      btm_def_link_super_tout;
790 
791     tBTM_BL_EVENT_MASK     bl_evt_mask;
792     tBTM_BL_CHANGE_CB     *p_bl_changed_cb;    /* Callback for when Busy Level changed */
793 
794     /****************************************************
795     **      Power Management
796     ****************************************************/
797     tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS];   /* per ACL link */
798     tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS+1]; /* per application/module */
799     UINT8       pm_pend_link;  /* the index of acl_db, which has a pending PM cmd */
800     UINT8       pm_pend_id;    /* the id pf the module, which has a pending PM cmd */
801 
802     /*****************************************************
803     **      Device control
804     *****************************************************/
805     tBTM_DEVCB  devcb;
806 
807     /*****************************************************
808     **      BLE Device controllers
809     *****************************************************/
810 #if (BLE_INCLUDED == TRUE)
811     tBTM_BLE_CB             ble_ctr_cb;
812 
813     UINT16                  enc_handle;
814     BT_OCTET8               enc_rand;   /* received rand value from LTK request*/
815     UINT16                  ediv;       /* received ediv value from LTK request */
816     UINT8                   key_size;
817     tBTM_BLE_VSC_CB         cmn_ble_vsc_cb;
818 #endif
819 
820                                             /* Packet types supported by the local device */
821     UINT16      btm_acl_pkt_types_supported;
822     UINT16      btm_sco_pkt_types_supported;
823 
824 
825     /*****************************************************
826     **      Inquiry
827     *****************************************************/
828     tBTM_INQUIRY_VAR_ST     btm_inq_vars;
829 
830     /*****************************************************
831     **      SCO Management
832     *****************************************************/
833 #if BTM_SCO_INCLUDED == TRUE
834     tSCO_CB             sco_cb;
835 #endif
836 
837     /*****************************************************
838     **      Security Management
839     *****************************************************/
840     tBTM_APPL_INFO          api;
841 
842 #define BTM_SEC_MAX_RMT_NAME_CALLBACKS  2
843     tBTM_RMT_NAME_CALLBACK  *p_rmt_name_callback[BTM_SEC_MAX_RMT_NAME_CALLBACKS];
844 
845     tBTM_SEC_DEV_REC        *p_collided_dev_rec;
846     TIMER_LIST_ENT           sec_collision_tle;
847     UINT32                   collision_start_time;
848     UINT32                   max_collision_delay;
849     UINT32                   dev_rec_count;      /* Counter used for device record timestamp */
850     UINT8                    security_mode;
851     BOOLEAN                  pairing_disabled;
852     BOOLEAN                  connect_only_paired;
853     BOOLEAN                  security_mode_changed;  /* mode changed during bonding */
854     BOOLEAN                  pin_type_changed;       /* pin type changed during bonding */
855     BOOLEAN                  sec_req_pending;       /*   TRUE if a request is pending */
856 
857     UINT8                    pin_code_len;  /* for legacy devices */
858     PIN_CODE                 pin_code;      /* for legacy devices */
859     tBTM_PAIRING_STATE       pairing_state; /* The current pairing state    */
860     UINT8                    pairing_flags; /* The current pairing flags    */
861     BD_ADDR                  pairing_bda;   /* The device currently pairing */
862     TIMER_LIST_ENT           pairing_tle;   /* Timer for pairing process    */
863     UINT16                   disc_handle;   /* for legacy devices */
864     UINT8                    disc_reason;   /* for legacy devices */
865     tBTM_SEC_SERV_REC        sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS];
866     tBTM_SEC_DEV_REC         sec_dev_rec[BTM_SEC_MAX_DEVICE_RECORDS];
867     tBTM_SEC_SERV_REC       *p_out_serv;
868     tBTM_MKEY_CALLBACK      *mkey_cback;
869 
870     BD_ADDR                  connecting_bda;
871     DEV_CLASS                connecting_dc;
872 
873     UINT8                   acl_disc_reason;
874     UINT8                   trace_level;
875     UINT8                   busy_level; /* the current busy level */
876     BOOLEAN                 is_paging;  /* TRUE, if paging is in progess */
877     BOOLEAN                 is_inquiry; /* TRUE, if inquiry is in progess */
878     BUFFER_Q                page_queue;
879     BOOLEAN                 paging;
880     BOOLEAN                 discing;
881     BUFFER_Q                sec_pending_q;  /* pending sequrity requests in tBTM_SEC_QUEUE_ENTRY format */
882 
883 #if  (!defined(BT_TRACE_VERBOSE) || (BT_TRACE_VERBOSE == FALSE))
884     char state_temp_buffer[BTM_STATE_BUFFER_SIZE];
885 #endif
886 } tBTM_CB;
887 
888 
889 #ifdef __cplusplus
890 extern "C"
891 {
892 #endif
893 
894 #if BTM_DYNAMIC_MEMORY == FALSE
895 extern tBTM_CB  btm_cb;
896 #else
897 extern tBTM_CB *btm_cb_ptr;
898 #define btm_cb (*btm_cb_ptr)
899 #endif
900 
901 /* Internal functions provided by btm_main.c
902 ********************************************
903 */
904 extern void         btm_init (void);
905 
906 /* Internal functions provided by btm_inq.c
907 *******************************************
908 */
909 extern tBTM_STATUS  btm_initiate_rem_name (BD_ADDR remote_bda,
910                                            tBTM_INQ_INFO *p_cur,
911                                            UINT8 origin, UINT32 timeout,
912                                            tBTM_CMPL_CB *p_cb);
913 
914 extern void         btm_process_remote_name (BD_ADDR bda, BD_NAME name, UINT16 evt_len,
915                                              UINT8 hci_status);
916 extern void         btm_inq_rmt_name_failed(void);
917 
918 /* Inquiry related functions */
919 extern void         btm_clr_inq_db (BD_ADDR p_bda);
920 extern void         btm_inq_db_init (void);
921 extern void         btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode);
922 extern void         btm_process_inq_complete (UINT8 status, UINT8 mode);
923 extern void         btm_process_cancel_complete(UINT8 status, UINT8 mode);
924 extern void         btm_event_filter_complete (UINT8 *p);
925 extern void         btm_inq_stop_on_ssp(void);
926 extern void         btm_inq_clear_ssp(void);
927 extern tINQ_DB_ENT *btm_inq_db_find (BD_ADDR p_bda);
928 extern BOOLEAN      btm_inq_find_bdaddr (BD_ADDR p_bda);
929 
930 extern BOOLEAN btm_lookup_eir(BD_ADDR_PTR p_rem_addr);
931 
932 /* Internal functions provided by btm_acl.c
933 ********************************************
934 */
935 extern void         btm_acl_init (void);
936 extern void         btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
937                                      UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport);
938 extern void         btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport);
939 extern void         btm_acl_device_down (void);
940 extern void         btm_acl_update_busy_level (tBTM_BLI_EVENT event);
941 
942 extern void         btm_cont_rswitch (tACL_CONN *p,
943                                       tBTM_SEC_DEV_REC *p_dev_rec,
944                                       UINT8 hci_status);
945 
946 extern UINT8        btm_handle_to_acl_index (UINT16 hci_handle);
947 extern void         btm_read_link_policy_complete (UINT8 *p);
948 extern void         btm_read_rssi_complete (UINT8 *p);
949 extern void         btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble);
950 extern void         btm_read_link_quality_complete (UINT8 *p);
951 extern tBTM_STATUS  btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types);
952 extern void         btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset);
953 extern void         btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role);
954 extern void         btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable);
955 extern UINT16       btm_get_acl_disc_reason_code (void);
956 extern tBTM_STATUS  btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport);
957 extern void         btm_read_remote_features_complete (UINT8 *p);
958 extern void         btm_read_remote_ext_features_complete (UINT8 *p);
959 extern void         btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle);
960 extern void         btm_read_remote_version_complete (UINT8 *p);
961 extern void         btm_establish_continue (tACL_CONN *p_acl_cb);
962 
963 // btla-specific ++
964 extern void         btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type);
965 // btla-specific --
966 /* Read maximum data packet that can be sent over current connection */
967 extern UINT16 btm_get_max_packet_size (BD_ADDR addr);
968 extern tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport);
969 extern BOOLEAN    btm_acl_notif_conn_collision (BD_ADDR bda);
970 
971 extern void btm_pm_reset(void);
972 extern void btm_pm_sm_alloc(UINT8 ind);
973 extern void btm_pm_proc_cmd_status(UINT8 status);
974 extern void btm_pm_proc_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode,
975                                      UINT16 interval);
976 extern void btm_pm_proc_ssr_evt (UINT8 *p, UINT16 evt_len);
977 #if BTM_SCO_INCLUDED == TRUE
978 extern void btm_sco_chk_pend_unpark (UINT8 hci_status, UINT16 hci_handle);
979 #else
980 #define btm_sco_chk_pend_unpark(hci_status, hci_handle)
981 #endif /* BTM_SCO_INCLUDED */
982 extern void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow);
983 
984 
985 /* Internal functions provided by btm_sco.c
986 ********************************************
987 */
988 extern void btm_sco_init (void);
989 extern void btm_sco_connected (UINT8 hci_status, BD_ADDR bda, UINT16 hci_handle,
990                                tBTM_ESCO_DATA *p_esco_data);
991 extern void btm_esco_proc_conn_chg (UINT8 status, UINT16 handle, UINT8 tx_interval,
992                                     UINT8 retrans_window, UINT16 rx_pkt_len,
993                                     UINT16 tx_pkt_len);
994 extern void btm_sco_conn_req (BD_ADDR bda,  DEV_CLASS dev_class, UINT8 link_type);
995 extern void btm_sco_removed (UINT16 hci_handle, UINT8 reason);
996 extern void btm_sco_acl_removed (BD_ADDR bda);
997 extern void btm_route_sco_data (BT_HDR *p_msg);
998 extern BOOLEAN btm_is_sco_active (UINT16 handle);
999 extern void btm_remove_sco_links (BD_ADDR bda);
1000 extern BOOLEAN btm_is_sco_active_by_bdaddr (BD_ADDR remote_bda);
1001 
1002 extern tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms);
1003 extern UINT16  btm_find_scb_by_handle (UINT16 handle);
1004 extern void btm_sco_flush_sco_data(UINT16 sco_inx);
1005 
1006 /* Internal functions provided by btm_devctl.c
1007 **********************************************
1008 */
1009 extern void btm_dev_init (void);
1010 extern void btm_dev_timeout (TIMER_LIST_ENT *p_tle);
1011 extern void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len);
1012 
1013 #if (BLE_INCLUDED == TRUE)
1014 extern void btm_ble_add_2_white_list_complete(UINT8 status);
1015 extern void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len);
1016 extern void btm_ble_clear_white_list_complete(UINT8 *p, UINT16 evt_len);
1017 extern BOOLEAN btm_ble_addr_resolvable(BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec);
1018 extern tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec);
1019 extern BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec);
1020 extern void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec);
1021 #endif  /* BLE_INCLUDED */
1022 
1023 /* Vendor Specific Command complete evt handler */
1024 extern void btm_vsc_complete (UINT8 *p, UINT16 cc_opcode, UINT16 evt_len,
1025                               tBTM_CMPL_CB *p_vsc_cplt_cback);
1026 extern void btm_inq_db_reset (void);
1027 extern void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len);
1028 extern void btm_delete_stored_link_key_complete (UINT8 *p);
1029 extern void btm_report_device_status (tBTM_DEV_STATUS status);
1030 
1031 
1032 /* Internal functions provided by btm_dev.c
1033 **********************************************
1034 */
1035 extern BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr);
1036 
1037 extern tBTM_SEC_DEV_REC  *btm_sec_alloc_dev (BD_ADDR bd_addr);
1038 extern void               btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec);
1039 extern tBTM_SEC_DEV_REC  *btm_find_dev (BD_ADDR bd_addr);
1040 extern tBTM_SEC_DEV_REC  *btm_find_or_alloc_dev (BD_ADDR bd_addr);
1041 extern tBTM_SEC_DEV_REC  *btm_find_dev_by_handle (UINT16 handle);
1042 extern tBTM_BOND_TYPE     btm_get_bond_type_dev(BD_ADDR bd_addr);
1043 extern BOOLEAN            btm_set_bond_type_dev(BD_ADDR bd_addr,
1044                                                 tBTM_BOND_TYPE bond_type);
1045 
1046 /* Internal functions provided by btm_sec.c
1047 **********************************************
1048 */
1049 extern BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr);
1050 extern tBTM_STATUS  btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm,
1051                                        UINT16 handle, CONNECTION_TYPE conn_type,
1052                                        tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
1053 extern tBTM_STATUS  btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator,
1054                                         UINT32 mx_proto_id, UINT32 mx_chan_id,
1055                                         tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
1056 extern void  btm_sec_conn_req (UINT8 *bda, UINT8 *dc);
1057 extern void btm_create_conn_cancel_complete (UINT8 *p);
1058 extern void btm_read_linq_tx_power_complete (UINT8 *p);
1059 
1060 extern void  btm_sec_init (UINT8 sec_mode);
1061 extern void  btm_sec_dev_reset (void);
1062 extern void  btm_sec_abort_access_req (BD_ADDR bd_addr);
1063 extern void  btm_sec_auth_complete (UINT16 handle, UINT8 status);
1064 extern void  btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable);
1065 extern void  btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode);
1066 extern tBTM_STATUS btm_sec_disconnect (UINT16 handle, UINT8 reason);
1067 extern void  btm_sec_disconnected (UINT16 handle, UINT8 reason);
1068 extern void  btm_sec_rmt_name_request_complete (UINT8 *bd_addr, UINT8 *bd_name, UINT8 status);
1069 extern void  btm_sec_rmt_host_support_feat_evt (UINT8 *p);
1070 extern void  btm_io_capabilities_req (UINT8 *p);
1071 extern void  btm_io_capabilities_rsp (UINT8 *p);
1072 extern void  btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p);
1073 extern void  btm_keypress_notif_evt (UINT8 *p);
1074 extern void  btm_simple_pair_complete (UINT8 *p);
1075 extern void  btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_type);
1076 extern void  btm_sec_link_key_request (UINT8 *p_bda);
1077 extern void  btm_sec_pin_code_request (UINT8 *p_bda);
1078 extern void  btm_sec_update_clock_offset (UINT16 handle, UINT16 clock_offset);
1079 extern void  btm_sec_dev_rec_cback_event (tBTM_SEC_DEV_REC *p_dev_rec, UINT8 res, BOOLEAN is_le_trasnport);
1080 extern void btm_sec_set_peer_sec_caps (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec);
1081 
1082 #if BLE_INCLUDED == TRUE
1083 extern void  btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC  *p_dev_rec);
1084 extern  BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec);
1085 extern BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda);
1086 extern void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec);
1087 extern BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda);
1088 extern BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr);
1089 #endif /* BLE_INCLUDED */
1090 
1091 extern tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda);
1092 
1093 #if BTM_OOB_INCLUDED == TRUE
1094 extern void  btm_rem_oob_req (UINT8 *p);
1095 extern void  btm_read_local_oob_complete (UINT8 *p);
1096 #else
1097 #define btm_rem_oob_req(p)
1098 #define btm_read_local_oob_complete(p)
1099 #endif
1100 
1101 extern void  btm_acl_resubmit_page (void);
1102 extern void  btm_acl_reset_paging (void);
1103 extern void  btm_acl_paging (BT_HDR *p, BD_ADDR dest);
1104 extern UINT8 btm_sec_clr_service_by_psm (UINT16 psm);
1105 extern void  btm_sec_clr_temp_auth_service (BD_ADDR bda);
1106 
1107 #ifdef __cplusplus
1108 }
1109 #endif
1110 
1111 #endif
1112