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