Home | History | Annotate | Download | only in dm
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-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 is the private interface file for the BTA device manager.
     22  *
     23  ******************************************************************************/
     24 #ifndef BTA_DM_INT_H
     25 #define BTA_DM_INT_H
     26 
     27 #include <memory>
     28 #include "bt_target.h"
     29 #include "bta_sys.h"
     30 
     31 #include "bta_gatt_api.h"
     32 
     33 /*****************************************************************************
     34  *  Constants and data types
     35  ****************************************************************************/
     36 
     37 #define BTA_COPY_DEVICE_CLASS(coddst, codsrc)          \
     38   {                                                    \
     39     ((uint8_t*)(coddst))[0] = ((uint8_t*)(codsrc))[0]; \
     40     ((uint8_t*)(coddst))[1] = ((uint8_t*)(codsrc))[1]; \
     41     ((uint8_t*)(coddst))[2] = ((uint8_t*)(codsrc))[2]; \
     42   }
     43 
     44 #define BTA_DM_MSG_LEN 50
     45 
     46 #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
     47 
     48 /* DM events */
     49 enum {
     50   /* device manager local device API events */
     51   BTA_DM_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_DM),
     52   BTA_DM_API_DISABLE_EVT,
     53   BTA_DM_API_SET_NAME_EVT,
     54   BTA_DM_API_SET_VISIBILITY_EVT,
     55 
     56   BTA_DM_ACL_CHANGE_EVT,
     57   BTA_DM_API_ADD_DEVICE_EVT,
     58   BTA_DM_API_REMOVE_ACL_EVT,
     59 
     60   /* security API events */
     61   BTA_DM_API_BOND_EVT,
     62   BTA_DM_API_BOND_CANCEL_EVT,
     63   BTA_DM_API_PIN_REPLY_EVT,
     64 
     65   /* power manger events */
     66   BTA_DM_PM_BTM_STATUS_EVT,
     67   BTA_DM_PM_TIMER_EVT,
     68 
     69   /* simple pairing events */
     70   BTA_DM_API_CONFIRM_EVT,
     71 
     72   BTA_DM_API_SET_ENCRYPTION_EVT,
     73 
     74   BTA_DM_API_LOC_OOB_EVT,
     75   BTA_DM_CI_IO_REQ_EVT,
     76   BTA_DM_CI_RMT_OOB_EVT,
     77 
     78   BTA_DM_API_ADD_BLEKEY_EVT,
     79   BTA_DM_API_ADD_BLEDEVICE_EVT,
     80   BTA_DM_API_BLE_PASSKEY_REPLY_EVT,
     81   BTA_DM_API_BLE_CONFIRM_REPLY_EVT,
     82   BTA_DM_API_BLE_SEC_GRANT_EVT,
     83   BTA_DM_API_BLE_SET_BG_CONN_TYPE,
     84   BTA_DM_API_BLE_CONN_PARAM_EVT,
     85   BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT,
     86   BTA_DM_API_BLE_OBSERVE_EVT,
     87   BTA_DM_API_UPDATE_CONN_PARAM_EVT,
     88 #if (BLE_PRIVACY_SPT == TRUE)
     89   BTA_DM_API_LOCAL_PRIVACY_EVT,
     90 #endif
     91   BTA_DM_API_SET_DATA_LENGTH_EVT,
     92   BTA_DM_API_BLE_ENERGY_INFO_EVT,
     93 
     94   BTA_DM_API_ENABLE_TEST_MODE_EVT,
     95   BTA_DM_API_DISABLE_TEST_MODE_EVT,
     96   BTA_DM_API_EXECUTE_CBACK_EVT,
     97   BTA_DM_API_REMOVE_ALL_ACL_EVT,
     98   BTA_DM_API_REMOVE_DEVICE_EVT,
     99   BTA_DM_MAX_EVT
    100 };
    101 
    102 /* DM search events */
    103 enum {
    104   /* DM search API events */
    105   BTA_DM_API_SEARCH_EVT = BTA_SYS_EVT_START(BTA_ID_DM_SEARCH),
    106   BTA_DM_API_SEARCH_CANCEL_EVT,
    107   BTA_DM_API_DISCOVER_EVT,
    108   BTA_DM_INQUIRY_CMPL_EVT,
    109   BTA_DM_REMT_NAME_EVT,
    110   BTA_DM_SDP_RESULT_EVT,
    111   BTA_DM_SEARCH_CMPL_EVT,
    112   BTA_DM_DISCOVERY_RESULT_EVT,
    113   BTA_DM_API_DI_DISCOVER_EVT,
    114   BTA_DM_DISC_CLOSE_TOUT_EVT
    115 
    116 };
    117 
    118 /* data type for BTA_DM_API_ENABLE_EVT */
    119 typedef struct {
    120   BT_HDR hdr;
    121   tBTA_DM_SEC_CBACK* p_sec_cback;
    122 } tBTA_DM_API_ENABLE;
    123 
    124 /* data type for BTA_DM_API_SET_NAME_EVT */
    125 typedef struct {
    126   BT_HDR hdr;
    127   BD_NAME name; /* max 248 bytes name, plus must be Null terminated */
    128 } tBTA_DM_API_SET_NAME;
    129 
    130 /* data type for BTA_DM_API_SET_VISIBILITY_EVT */
    131 typedef struct {
    132   BT_HDR hdr;
    133   tBTA_DM_DISC disc_mode;
    134   tBTA_DM_CONN conn_mode;
    135   uint8_t pair_mode;
    136   uint8_t conn_paired_only;
    137 } tBTA_DM_API_SET_VISIBILITY;
    138 
    139 enum {
    140   BTA_DM_RS_NONE, /* straight API call */
    141   BTA_DM_RS_OK,   /* the role switch result - successful */
    142   BTA_DM_RS_FAIL  /* the role switch result - failed */
    143 };
    144 typedef uint8_t tBTA_DM_RS_RES;
    145 
    146 /* data type for BTA_DM_API_SEARCH_EVT */
    147 typedef struct {
    148   BT_HDR hdr;
    149   tBTA_DM_INQ inq_params;
    150   tBTA_SERVICE_MASK services;
    151   tBTA_DM_SEARCH_CBACK* p_cback;
    152   tBTA_DM_RS_RES rs_res;
    153   uint8_t num_uuid;
    154   tBT_UUID* p_uuid;
    155 } tBTA_DM_API_SEARCH;
    156 
    157 /* data type for BTA_DM_API_DISCOVER_EVT */
    158 typedef struct {
    159   BT_HDR hdr;
    160   RawAddress bd_addr;
    161   tBTA_SERVICE_MASK services;
    162   tBTA_DM_SEARCH_CBACK* p_cback;
    163   bool sdp_search;
    164   tBTA_TRANSPORT transport;
    165   uint8_t num_uuid;
    166   tBT_UUID* p_uuid;
    167   tSDP_UUID uuid;
    168 } tBTA_DM_API_DISCOVER;
    169 
    170 /* data type for BTA_DM_API_DI_DISC_EVT */
    171 typedef struct {
    172   BT_HDR hdr;
    173   RawAddress bd_addr;
    174   tBTA_DISCOVERY_DB* p_sdp_db;
    175   uint32_t len;
    176   tBTA_DM_SEARCH_CBACK* p_cback;
    177 } tBTA_DM_API_DI_DISC;
    178 
    179 /* data type for BTA_DM_API_BOND_EVT */
    180 typedef struct {
    181   BT_HDR hdr;
    182   RawAddress bd_addr;
    183   tBTA_TRANSPORT transport;
    184 } tBTA_DM_API_BOND;
    185 
    186 /* data type for BTA_DM_API_BOND_CANCEL_EVT */
    187 typedef struct {
    188   BT_HDR hdr;
    189   RawAddress bd_addr;
    190   tBTA_TRANSPORT transport;
    191 } tBTA_DM_API_BOND_CANCEL;
    192 
    193 /* data type for BTA_DM_API_PIN_REPLY_EVT */
    194 typedef struct {
    195   BT_HDR hdr;
    196   RawAddress bd_addr;
    197   bool accept;
    198   uint8_t pin_len;
    199   uint8_t p_pin[PIN_CODE_LEN];
    200 } tBTA_DM_API_PIN_REPLY;
    201 
    202 /* data type for BTA_DM_API_LOC_OOB_EVT */
    203 typedef struct { BT_HDR hdr; } tBTA_DM_API_LOC_OOB;
    204 
    205 /* data type for BTA_DM_API_CONFIRM_EVT */
    206 typedef struct {
    207   BT_HDR hdr;
    208   RawAddress bd_addr;
    209   bool accept;
    210 } tBTA_DM_API_CONFIRM;
    211 
    212 /* data type for BTA_DM_CI_IO_REQ_EVT */
    213 typedef struct {
    214   BT_HDR hdr;
    215   RawAddress bd_addr;
    216   tBTA_IO_CAP io_cap;
    217   tBTA_OOB_DATA oob_data;
    218   tBTA_AUTH_REQ auth_req;
    219 } tBTA_DM_CI_IO_REQ;
    220 
    221 /* data type for BTA_DM_CI_RMT_OOB_EVT */
    222 typedef struct {
    223   BT_HDR hdr;
    224   RawAddress bd_addr;
    225   BT_OCTET16 c;
    226   BT_OCTET16 r;
    227   bool accept;
    228 } tBTA_DM_CI_RMT_OOB;
    229 
    230 /* data type for BTA_DM_REMT_NAME_EVT */
    231 typedef struct {
    232   BT_HDR hdr;
    233   tBTA_DM_SEARCH result;
    234 } tBTA_DM_REM_NAME;
    235 
    236 /* data type for tBTA_DM_DISC_RESULT */
    237 typedef struct {
    238   BT_HDR hdr;
    239   tBTA_DM_SEARCH result;
    240 } tBTA_DM_DISC_RESULT;
    241 
    242 /* data type for BTA_DM_INQUIRY_CMPL_EVT */
    243 typedef struct {
    244   BT_HDR hdr;
    245   uint8_t num;
    246 } tBTA_DM_INQUIRY_CMPL;
    247 
    248 /* data type for BTA_DM_SDP_RESULT_EVT */
    249 typedef struct {
    250   BT_HDR hdr;
    251   uint16_t sdp_result;
    252 } tBTA_DM_SDP_RESULT;
    253 
    254 /* data type for BTA_DM_ACL_CHANGE_EVT */
    255 typedef struct {
    256   BT_HDR hdr;
    257   tBTM_BL_EVENT event;
    258   uint8_t busy_level;
    259   uint8_t busy_level_flags;
    260   bool is_new;
    261   uint8_t new_role;
    262   RawAddress bd_addr;
    263   uint8_t hci_status;
    264   uint16_t handle;
    265   tBT_TRANSPORT transport;
    266 } tBTA_DM_ACL_CHANGE;
    267 
    268 /* data type for BTA_DM_PM_BTM_STATUS_EVT */
    269 typedef struct {
    270   BT_HDR hdr;
    271   RawAddress bd_addr;
    272   tBTM_PM_STATUS status;
    273   uint16_t value;
    274   uint8_t hci_status;
    275 
    276 } tBTA_DM_PM_BTM_STATUS;
    277 
    278 /* data type for BTA_DM_PM_TIMER_EVT */
    279 typedef struct {
    280   BT_HDR hdr;
    281   RawAddress bd_addr;
    282   tBTA_DM_PM_ACTION pm_request;
    283 } tBTA_DM_PM_TIMER;
    284 
    285 /* data type for BTA_DM_API_ADD_DEVICE_EVT */
    286 typedef struct {
    287   BT_HDR hdr;
    288   RawAddress bd_addr;
    289   DEV_CLASS dc;
    290   LINK_KEY link_key;
    291   tBTA_SERVICE_MASK tm;
    292   bool is_trusted;
    293   uint8_t key_type;
    294   tBTA_IO_CAP io_cap;
    295   bool link_key_known;
    296   bool dc_known;
    297   BD_NAME bd_name;
    298   uint8_t
    299       features[BTA_FEATURE_BYTES_PER_PAGE * (BTA_EXT_FEATURES_PAGE_MAX + 1)];
    300   uint8_t pin_length;
    301 } tBTA_DM_API_ADD_DEVICE;
    302 
    303 /* data type for BTA_DM_API_REMOVE_ACL_EVT */
    304 typedef struct {
    305   BT_HDR hdr;
    306   RawAddress bd_addr;
    307 } tBTA_DM_API_REMOVE_DEVICE;
    308 
    309 /* data type for BTA_DM_API_EXECUTE_CBACK_EVT */
    310 typedef struct {
    311   BT_HDR hdr;
    312   void* p_param;
    313   tBTA_DM_EXEC_CBACK* p_exec_cback;
    314 } tBTA_DM_API_EXECUTE_CBACK;
    315 
    316 /* data type for tBTA_DM_API_SET_ENCRYPTION */
    317 typedef struct {
    318   BT_HDR hdr;
    319   tBTA_TRANSPORT transport;
    320   tBTA_DM_ENCRYPT_CBACK* p_callback;
    321   tBTA_DM_BLE_SEC_ACT sec_act;
    322   RawAddress bd_addr;
    323 } tBTA_DM_API_SET_ENCRYPTION;
    324 
    325 typedef struct {
    326   BT_HDR hdr;
    327   RawAddress bd_addr;
    328   tBTA_LE_KEY_VALUE blekey;
    329   tBTA_LE_KEY_TYPE key_type;
    330 
    331 } tBTA_DM_API_ADD_BLEKEY;
    332 
    333 typedef struct {
    334   BT_HDR hdr;
    335   RawAddress bd_addr;
    336   tBT_DEVICE_TYPE dev_type;
    337   tBLE_ADDR_TYPE addr_type;
    338 
    339 } tBTA_DM_API_ADD_BLE_DEVICE;
    340 
    341 typedef struct {
    342   BT_HDR hdr;
    343   RawAddress bd_addr;
    344   bool accept;
    345   uint32_t passkey;
    346 } tBTA_DM_API_PASSKEY_REPLY;
    347 
    348 typedef struct {
    349   BT_HDR hdr;
    350   RawAddress bd_addr;
    351   tBTA_DM_BLE_SEC_GRANT res;
    352 } tBTA_DM_API_BLE_SEC_GRANT;
    353 
    354 /* set prefered BLE connection parameters for a device */
    355 typedef struct {
    356   BT_HDR hdr;
    357   RawAddress peer_bda;
    358   uint16_t conn_int_min;
    359   uint16_t conn_int_max;
    360   uint16_t supervision_tout;
    361   uint16_t slave_latency;
    362 
    363 } tBTA_DM_API_BLE_CONN_PARAMS;
    364 
    365 typedef struct {
    366   BT_HDR hdr;
    367   RawAddress peer_bda;
    368   bool privacy_enable;
    369 
    370 } tBTA_DM_API_ENABLE_PRIVACY;
    371 
    372 typedef struct {
    373   BT_HDR hdr;
    374   bool privacy_enable;
    375 } tBTA_DM_API_LOCAL_PRIVACY;
    376 
    377 /* set scan parameter for BLE connections */
    378 typedef struct {
    379   BT_HDR hdr;
    380   tBTA_GATTC_IF client_if;
    381   uint32_t scan_int;
    382   uint32_t scan_window;
    383   tBLE_SCAN_MODE scan_mode;
    384   tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback;
    385 } tBTA_DM_API_BLE_SCAN_PARAMS;
    386 
    387 /* set scan parameter for BLE connections */
    388 typedef struct {
    389   BT_HDR hdr;
    390   uint16_t scan_int;
    391   uint16_t scan_window;
    392 } tBTA_DM_API_BLE_CONN_SCAN_PARAMS;
    393 
    394 /* Data type for start/stop observe */
    395 typedef struct {
    396   BT_HDR hdr;
    397   bool start;
    398   uint16_t duration;
    399   tBTA_DM_SEARCH_CBACK* p_cback;
    400 } tBTA_DM_API_BLE_OBSERVE;
    401 
    402 typedef struct {
    403   BT_HDR hdr;
    404   RawAddress remote_bda;
    405   uint16_t tx_data_length;
    406 } tBTA_DM_API_BLE_SET_DATA_LENGTH;
    407 
    408 /* set adv parameter for BLE advertising */
    409 
    410 typedef struct {
    411   BT_HDR hdr;
    412   bool enable;
    413 
    414 } tBTA_DM_API_BLE_FEATURE;
    415 
    416 typedef struct {
    417   BT_HDR hdr;
    418   tBTA_BLE_ENERGY_INFO_CBACK* p_energy_info_cback;
    419 } tBTA_DM_API_ENERGY_INFO;
    420 
    421 /* data type for BTA_DM_API_REMOVE_ACL_EVT */
    422 typedef struct {
    423   BT_HDR hdr;
    424   RawAddress bd_addr;
    425   bool remove_dev;
    426   tBTA_TRANSPORT transport;
    427 } tBTA_DM_API_REMOVE_ACL;
    428 
    429 /* data type for BTA_DM_API_REMOVE_ALL_ACL_EVT */
    430 typedef struct {
    431   BT_HDR hdr;
    432   tBTA_DM_LINK_TYPE link_type;
    433 
    434 } tBTA_DM_API_REMOVE_ALL_ACL;
    435 typedef struct {
    436   BT_HDR hdr;
    437   RawAddress bd_addr;
    438   uint16_t min_int;
    439   uint16_t max_int;
    440   uint16_t latency;
    441   uint16_t timeout;
    442 } tBTA_DM_API_UPDATE_CONN_PARAM;
    443 
    444 /* union of all data types */
    445 typedef union {
    446   /* GKI event buffer header */
    447   BT_HDR hdr;
    448   tBTA_DM_API_ENABLE enable;
    449 
    450   tBTA_DM_API_SET_NAME set_name;
    451 
    452   tBTA_DM_API_SET_VISIBILITY set_visibility;
    453 
    454   tBTA_DM_API_ADD_DEVICE add_dev;
    455 
    456   tBTA_DM_API_REMOVE_DEVICE remove_dev;
    457 
    458   tBTA_DM_API_SEARCH search;
    459 
    460   tBTA_DM_API_DISCOVER discover;
    461 
    462   tBTA_DM_API_BOND bond;
    463 
    464   tBTA_DM_API_BOND_CANCEL bond_cancel;
    465 
    466   tBTA_DM_API_PIN_REPLY pin_reply;
    467 
    468   tBTA_DM_API_LOC_OOB loc_oob;
    469   tBTA_DM_API_CONFIRM confirm;
    470   tBTA_DM_CI_IO_REQ ci_io_req;
    471   tBTA_DM_CI_RMT_OOB ci_rmt_oob;
    472 
    473   tBTA_DM_REM_NAME rem_name;
    474 
    475   tBTA_DM_DISC_RESULT disc_result;
    476 
    477   tBTA_DM_INQUIRY_CMPL inq_cmpl;
    478 
    479   tBTA_DM_SDP_RESULT sdp_event;
    480 
    481   tBTA_DM_ACL_CHANGE acl_change;
    482 
    483   tBTA_DM_PM_BTM_STATUS pm_status;
    484 
    485   tBTA_DM_PM_TIMER pm_timer;
    486 
    487   tBTA_DM_API_DI_DISC di_disc;
    488 
    489   tBTA_DM_API_EXECUTE_CBACK exec_cback;
    490 
    491   tBTA_DM_API_SET_ENCRYPTION set_encryption;
    492 
    493   tBTA_DM_API_ADD_BLEKEY add_ble_key;
    494   tBTA_DM_API_ADD_BLE_DEVICE add_ble_device;
    495   tBTA_DM_API_PASSKEY_REPLY ble_passkey_reply;
    496   tBTA_DM_API_BLE_SEC_GRANT ble_sec_grant;
    497   tBTA_DM_API_BLE_CONN_PARAMS ble_set_conn_params;
    498   tBTA_DM_API_BLE_CONN_SCAN_PARAMS ble_set_conn_scan_params;
    499   tBTA_DM_API_BLE_OBSERVE ble_observe;
    500   tBTA_DM_API_ENABLE_PRIVACY ble_remote_privacy;
    501   tBTA_DM_API_LOCAL_PRIVACY ble_local_privacy;
    502   tBTA_DM_API_UPDATE_CONN_PARAM ble_update_conn_params;
    503   tBTA_DM_API_BLE_SET_DATA_LENGTH ble_set_data_length;
    504 
    505   tBTA_DM_API_ENERGY_INFO ble_energy_info;
    506 
    507   tBTA_DM_API_REMOVE_ACL remove_acl;
    508   tBTA_DM_API_REMOVE_ALL_ACL remove_all_acl;
    509 
    510 } tBTA_DM_MSG;
    511 
    512 #define BTA_DM_NUM_PEER_DEVICE 7
    513 
    514 #define BTA_DM_NOT_CONNECTED 0
    515 #define BTA_DM_CONNECTED 1
    516 #define BTA_DM_UNPAIRING 2
    517 typedef uint8_t tBTA_DM_CONN_STATE;
    518 
    519 #define BTA_DM_DI_NONE 0x00 /* nothing special */
    520 #define BTA_DM_DI_USE_SSR \
    521   0x10 /* set this bit if ssr is supported for this link */
    522 #define BTA_DM_DI_AV_ACTIVE \
    523   0x20 /* set this bit if AV is active for this link */
    524 #define BTA_DM_DI_SET_SNIFF \
    525   0x01 /* set this bit if call BTM_SetPowerMode(sniff) */
    526 #define BTA_DM_DI_INT_SNIFF \
    527   0x02 /* set this bit if call BTM_SetPowerMode(sniff) & enter sniff mode */
    528 #define BTA_DM_DI_ACP_SNIFF 0x04 /* set this bit if peer init sniff */
    529 typedef uint8_t tBTA_DM_DEV_INFO;
    530 
    531 /* set power mode request type */
    532 #define BTA_DM_PM_RESTART 1
    533 #define BTA_DM_PM_NEW_REQ 2
    534 #define BTA_DM_PM_EXECUTE 3
    535 typedef uint8_t tBTA_DM_PM_REQ;
    536 
    537 typedef struct {
    538   RawAddress peer_bdaddr;
    539   uint16_t link_policy;
    540   tBTA_DM_CONN_STATE conn_state;
    541   tBTA_PREF_ROLES pref_role;
    542   bool in_use;
    543   tBTA_DM_DEV_INFO info;
    544   tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
    545 #if (BTM_SSR_INCLUDED == TRUE)
    546   tBTM_PM_STATUS prev_low; /* previous low power mode used */
    547 #endif
    548   tBTA_DM_PM_ACTION pm_mode_attempted;
    549   tBTA_DM_PM_ACTION pm_mode_failed;
    550   bool remove_dev_pending;
    551   uint16_t conn_handle;
    552   tBT_TRANSPORT transport;
    553 } tBTA_DM_PEER_DEVICE;
    554 
    555 /* structure to store list of
    556   active connections */
    557 typedef struct {
    558   tBTA_DM_PEER_DEVICE peer_device[BTA_DM_NUM_PEER_DEVICE];
    559   uint8_t count;
    560   uint8_t le_count;
    561 } tBTA_DM_ACTIVE_LINK;
    562 
    563 typedef struct {
    564   RawAddress peer_bdaddr;
    565   tBTA_SYS_ID id;
    566   uint8_t app_id;
    567   tBTA_SYS_CONN_STATUS state;
    568   bool new_request;
    569 
    570 } tBTA_DM_SRVCS;
    571 
    572 #ifndef BTA_DM_NUM_CONN_SRVS
    573 #define BTA_DM_NUM_CONN_SRVS 10
    574 #endif
    575 
    576 typedef struct {
    577   uint8_t count;
    578   tBTA_DM_SRVCS conn_srvc[BTA_DM_NUM_CONN_SRVS];
    579 
    580 } tBTA_DM_CONNECTED_SRVCS;
    581 
    582 typedef struct {
    583 #define BTA_DM_PM_SNIFF_TIMER_IDX 0
    584 #define BTA_DM_PM_PARK_TIMER_IDX 1
    585 #define BTA_DM_PM_SUSPEND_TIMER_IDX 2
    586 #define BTA_DM_PM_MODE_TIMER_MAX 3
    587   /*
    588    * Keep three different timers for PARK, SNIFF and SUSPEND if TBFC is
    589    * supported.
    590    */
    591   alarm_t* timer[BTA_DM_PM_MODE_TIMER_MAX];
    592 
    593   uint8_t srvc_id[BTA_DM_PM_MODE_TIMER_MAX];
    594   uint8_t pm_action[BTA_DM_PM_MODE_TIMER_MAX];
    595   uint8_t active; /* number of active timer */
    596 
    597   RawAddress peer_bdaddr;
    598   bool in_use;
    599 } tBTA_PM_TIMER;
    600 
    601 extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
    602 
    603 #define BTA_DM_NUM_PM_TIMER 7
    604 
    605 /* DM control block */
    606 typedef struct {
    607   bool is_bta_dm_active;
    608   tBTA_DM_ACTIVE_LINK device_list;
    609   tBTA_DM_SEC_CBACK* p_sec_cback;
    610   tBTA_BLE_ENERGY_INFO_CBACK* p_energy_info_cback;
    611   uint16_t state;
    612   bool disabling;
    613   alarm_t* disable_timer;
    614   uint32_t wbt_sdp_handle; /* WIDCOMM Extensions SDP record handle */
    615   uint8_t wbt_scn;         /* WIDCOMM Extensions SCN */
    616   uint8_t num_master_only;
    617   uint8_t pm_id;
    618   tBTA_PM_TIMER pm_timer[BTA_DM_NUM_PM_TIMER];
    619   uint32_t
    620       role_policy_mask;   /* the bits set indicates the modules that wants to
    621                              remove role switch from the default link policy */
    622   uint16_t cur_policy;    /* current default link policy */
    623   uint16_t rs_event;      /* the event waiting for role switch */
    624   uint8_t cur_av_count;   /* current AV connecions */
    625   bool disable_pair_mode; /* disable pair mode or not */
    626   bool conn_paired_only;  /* allow connectable to paired device only or not */
    627   tBTA_DM_API_SEARCH search_msg;
    628   uint16_t page_scan_interval;
    629   uint16_t page_scan_window;
    630   uint16_t inquiry_scan_interval;
    631   uint16_t inquiry_scan_window;
    632 
    633   /* Storage for pin code request parameters */
    634   RawAddress pin_bd_addr;
    635   DEV_CLASS pin_dev_class;
    636   tBTA_DM_SEC_EVT pin_evt;
    637   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
    638                        show this number to UI */
    639   bool just_works;  /* true, if "Just Works" association model */
    640 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
    641   /* store UUID list for EIR */
    642   uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
    643 #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
    644   tBT_UUID custom_uuid[BTA_EIR_SERVER_NUM_CUSTOM_UUID];
    645 #endif
    646 
    647 #endif
    648 
    649   tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
    650   alarm_t* switch_delay_timer;
    651 
    652 } tBTA_DM_CB;
    653 
    654 /* DM search control block */
    655 typedef struct {
    656   tBTA_DM_SEARCH_CBACK* p_search_cback;
    657   tBTM_INQ_INFO* p_btm_inq_info;
    658   tBTA_SERVICE_MASK services;
    659   tBTA_SERVICE_MASK services_to_search;
    660   tBTA_SERVICE_MASK services_found;
    661   tSDP_DISCOVERY_DB* p_sdp_db;
    662   uint16_t state;
    663   RawAddress peer_bdaddr;
    664   bool name_discover_done;
    665   BD_NAME peer_name;
    666   alarm_t* search_timer;
    667   uint8_t service_index;
    668   tBTA_DM_MSG* p_search_queue; /* search or discover commands during search
    669                                   cancel stored here */
    670   bool wait_disc;
    671   bool sdp_results;
    672   tSDP_UUID uuid;
    673   uint8_t peer_scn;
    674   bool sdp_search;
    675   bool cancel_pending; /* inquiry cancel is pending */
    676   tBTA_TRANSPORT transport;
    677   tBTA_DM_SEARCH_CBACK* p_scan_cback;
    678   tBTA_GATTC_IF client_if;
    679   uint8_t num_uuid;
    680   tBT_UUID* p_srvc_uuid;
    681   uint8_t uuid_to_search;
    682   bool gatt_disc_active;
    683   uint16_t conn_id;
    684   uint8_t* p_ble_rawdata;
    685   uint32_t ble_raw_size;
    686   uint32_t ble_raw_used;
    687   alarm_t* gatt_close_timer; /* GATT channel close delay timer */
    688   RawAddress pending_close_bda; /* pending GATT channel remote device address */
    689 
    690 } tBTA_DM_SEARCH_CB;
    691 
    692 /* DI control block */
    693 typedef struct {
    694   tSDP_DISCOVERY_DB* p_di_db;         /* pointer to the DI discovery database */
    695   uint8_t di_num;                     /* total local DI record number */
    696   uint32_t di_handle[BTA_DI_NUM_MAX]; /* local DI record handle, the first one
    697                                          is primary record */
    698 } tBTA_DM_DI_CB;
    699 
    700 /* DM search state */
    701 enum {
    702 
    703   BTA_DM_SEARCH_IDLE,
    704   BTA_DM_SEARCH_ACTIVE,
    705   BTA_DM_SEARCH_CANCELLING,
    706   BTA_DM_DISCOVER_ACTIVE
    707 
    708 };
    709 
    710 typedef struct {
    711   DEV_CLASS dev_class; /* local device class */
    712   uint16_t
    713       policy_settings;   /* link policy setting hold, sniff, park, MS switch */
    714   uint16_t page_timeout; /* timeout for page in slots */
    715   uint16_t link_timeout; /* link supervision timeout in slots */
    716   bool avoid_scatter; /* true to avoid scatternet when av is streaming (be the
    717                          master) */
    718 
    719 } tBTA_DM_CFG;
    720 
    721 extern const uint32_t bta_service_id_to_btm_srv_id_lkup_tbl[];
    722 
    723 typedef struct {
    724   uint8_t id;
    725   uint8_t app_id;
    726   uint8_t cfg;
    727 
    728 } tBTA_DM_RM;
    729 
    730 extern tBTA_DM_CFG* p_bta_dm_cfg;
    731 extern tBTA_DM_RM* p_bta_dm_rm_cfg;
    732 
    733 typedef struct {
    734   uint8_t id;
    735   uint8_t app_id;
    736   uint8_t spec_idx; /* index of spec table to use */
    737 
    738 } tBTA_DM_PM_CFG;
    739 
    740 typedef struct {
    741   tBTA_DM_PM_ACTION power_mode;
    742   uint16_t timeout;
    743 
    744 } tBTA_DM_PM_ACTN;
    745 
    746 typedef struct {
    747   uint8_t allow_mask; /* mask of sniff/hold/park modes to allow */
    748 #if (BTM_SSR_INCLUDED == TRUE)
    749   uint8_t ssr; /* set SSR on conn open/unpark */
    750 #endif
    751   tBTA_DM_PM_ACTN actn_tbl[BTA_DM_PM_NUM_EVTS][2];
    752 
    753 } tBTA_DM_PM_SPEC;
    754 
    755 typedef struct {
    756   uint16_t max_lat;
    757   uint16_t min_rmt_to;
    758   uint16_t min_loc_to;
    759 } tBTA_DM_SSR_SPEC;
    760 
    761 typedef struct {
    762   uint16_t manufacturer;
    763   uint16_t lmp_sub_version;
    764   uint8_t lmp_version;
    765 } tBTA_DM_LMP_VER_INFO;
    766 
    767 extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
    768 
    769 extern tBTA_DM_PM_CFG* p_bta_dm_pm_cfg;
    770 extern tBTA_DM_PM_SPEC* p_bta_dm_pm_spec;
    771 extern tBTM_PM_PWR_MD* p_bta_dm_pm_md;
    772 #if (BTM_SSR_INCLUDED == TRUE)
    773 extern tBTA_DM_SSR_SPEC* p_bta_dm_ssr_spec;
    774 #endif
    775 
    776 /* update dynamic BRCM Aware EIR data */
    777 extern const tBTA_DM_EIR_CONF bta_dm_eir_cfg;
    778 extern tBTA_DM_EIR_CONF* p_bta_dm_eir_cfg;
    779 
    780 /* DM control block */
    781 extern tBTA_DM_CB bta_dm_cb;
    782 
    783 /* DM search control block */
    784 extern tBTA_DM_SEARCH_CB bta_dm_search_cb;
    785 
    786 /* DI control block */
    787 extern tBTA_DM_DI_CB bta_dm_di_cb;
    788 
    789 extern bool bta_dm_sm_execute(BT_HDR* p_msg);
    790 extern void bta_dm_sm_disable(void);
    791 extern bool bta_dm_search_sm_execute(BT_HDR* p_msg);
    792 extern void bta_dm_search_sm_disable(void);
    793 
    794 extern void bta_dm_enable(tBTA_DM_MSG* p_data);
    795 extern void bta_dm_disable(tBTA_DM_MSG* p_data);
    796 extern void bta_dm_init_cb(void);
    797 extern void bta_dm_set_dev_name(tBTA_DM_MSG* p_data);
    798 extern void bta_dm_set_visibility(tBTA_DM_MSG* p_data);
    799 
    800 extern void bta_dm_set_scan_config(tBTA_DM_MSG* p_data);
    801 extern void bta_dm_vendor_spec_command(tBTA_DM_MSG* p_data);
    802 extern void bta_dm_bond(tBTA_DM_MSG* p_data);
    803 extern void bta_dm_bond_cancel(tBTA_DM_MSG* p_data);
    804 extern void bta_dm_pin_reply(tBTA_DM_MSG* p_data);
    805 extern void bta_dm_acl_change(tBTA_DM_MSG* p_data);
    806 extern void bta_dm_add_device(tBTA_DM_MSG* p_data);
    807 extern void bta_dm_remove_device(tBTA_DM_MSG* p_data);
    808 extern void bta_dm_close_acl(tBTA_DM_MSG* p_data);
    809 
    810 extern void bta_dm_pm_btm_status(tBTA_DM_MSG* p_data);
    811 extern void bta_dm_pm_timer(tBTA_DM_MSG* p_data);
    812 extern void bta_dm_add_ampkey(tBTA_DM_MSG* p_data);
    813 
    814 extern void bta_dm_add_blekey(tBTA_DM_MSG* p_data);
    815 extern void bta_dm_add_ble_device(tBTA_DM_MSG* p_data);
    816 extern void bta_dm_ble_passkey_reply(tBTA_DM_MSG* p_data);
    817 extern void bta_dm_ble_confirm_reply(tBTA_DM_MSG* p_data);
    818 extern void bta_dm_security_grant(tBTA_DM_MSG* p_data);
    819 extern void bta_dm_ble_set_bg_conn_type(tBTA_DM_MSG* p_data);
    820 extern void bta_dm_ble_set_conn_params(tBTA_DM_MSG* p_data);
    821 extern void bta_dm_ble_set_conn_scan_params(tBTA_DM_MSG* p_data);
    822 extern void bta_dm_close_gatt_conn(tBTA_DM_MSG* p_data);
    823 extern void bta_dm_ble_observe(tBTA_DM_MSG* p_data);
    824 extern void bta_dm_ble_update_conn_params(tBTA_DM_MSG* p_data);
    825 extern void bta_dm_ble_config_local_privacy(tBTA_DM_MSG* p_data);
    826 extern void bta_dm_ble_set_adv_params(uint16_t adv_int_min,
    827                                       uint16_t adv_int_max,
    828                                       tBLE_BD_ADDR* p_dir_bda);
    829 
    830 extern void bta_dm_ble_set_data_length(tBTA_DM_MSG* p_data);
    831 
    832 extern void bta_dm_ble_get_energy_info(tBTA_DM_MSG* p_data);
    833 
    834 extern void bta_dm_set_encryption(tBTA_DM_MSG* p_data);
    835 extern void bta_dm_confirm(tBTA_DM_MSG* p_data);
    836 extern void bta_dm_loc_oob(tBTA_DM_MSG* p_data);
    837 extern void bta_dm_ci_io_req_act(tBTA_DM_MSG* p_data);
    838 extern void bta_dm_ci_rmt_oob_act(tBTA_DM_MSG* p_data);
    839 
    840 extern void bta_dm_init_pm(void);
    841 extern void bta_dm_disable_pm(void);
    842 
    843 extern uint8_t bta_dm_get_av_count(void);
    844 extern void bta_dm_search_start(tBTA_DM_MSG* p_data);
    845 extern void bta_dm_search_cancel(tBTA_DM_MSG* p_data);
    846 extern void bta_dm_discover(tBTA_DM_MSG* p_data);
    847 extern void bta_dm_di_disc(tBTA_DM_MSG* p_data);
    848 extern void bta_dm_inq_cmpl(tBTA_DM_MSG* p_data);
    849 extern void bta_dm_rmt_name(tBTA_DM_MSG* p_data);
    850 extern void bta_dm_sdp_result(tBTA_DM_MSG* p_data);
    851 extern void bta_dm_search_cmpl(tBTA_DM_MSG* p_data);
    852 extern void bta_dm_free_sdp_db(tBTA_DM_MSG* p_data);
    853 extern void bta_dm_disc_result(tBTA_DM_MSG* p_data);
    854 extern void bta_dm_search_result(tBTA_DM_MSG* p_data);
    855 extern void bta_dm_discovery_cmpl(tBTA_DM_MSG* p_data);
    856 extern void bta_dm_queue_search(tBTA_DM_MSG* p_data);
    857 extern void bta_dm_queue_disc(tBTA_DM_MSG* p_data);
    858 extern void bta_dm_search_clear_queue(tBTA_DM_MSG* p_data);
    859 extern void bta_dm_search_cancel_cmpl(tBTA_DM_MSG* p_data);
    860 extern void bta_dm_search_cancel_notify(tBTA_DM_MSG* p_data);
    861 extern void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG* p_data);
    862 extern void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data);
    863 extern tBTA_DM_PEER_DEVICE* bta_dm_find_peer_device(
    864     const RawAddress& peer_addr);
    865 
    866 void bta_dm_eir_update_uuid(uint16_t uuid16, bool adding);
    867 
    868 extern void bta_dm_enable_test_mode(tBTA_DM_MSG* p_data);
    869 extern void bta_dm_disable_test_mode(tBTA_DM_MSG* p_data);
    870 extern void bta_dm_execute_callback(tBTA_DM_MSG* p_data);
    871 
    872 extern void bta_dm_remove_all_acl(tBTA_DM_MSG* p_data);
    873 #endif /* BTA_DM_INT_H */
    874