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