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