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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR bd_addr;
    323 } tBTA_DM_API_SET_ENCRYPTION;
    324 
    325 typedef struct {
    326   BT_HDR hdr;
    327   BD_ADDR 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   BD_ADDR 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   BD_ADDR bd_addr;
    344   bool accept;
    345   uint32_t passkey;
    346 } tBTA_DM_API_PASSKEY_REPLY;
    347 
    348 typedef struct {
    349   BT_HDR hdr;
    350   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR 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   BD_ADDR bd_addr;
    425   bool remove_dev;
    426   tBTA_TRANSPORT transport;
    427 
    428 } tBTA_DM_API_REMOVE_ACL;
    429 
    430 /* data type for BTA_DM_API_REMOVE_ALL_ACL_EVT */
    431 typedef struct {
    432   BT_HDR hdr;
    433   tBTA_DM_LINK_TYPE link_type;
    434 
    435 } tBTA_DM_API_REMOVE_ALL_ACL;
    436 typedef struct {
    437   BT_HDR hdr;
    438   BD_ADDR bd_addr;
    439   uint16_t min_int;
    440   uint16_t max_int;
    441   uint16_t latency;
    442   uint16_t timeout;
    443 } tBTA_DM_API_UPDATE_CONN_PARAM;
    444 
    445 /* union of all data types */
    446 typedef union {
    447   /* GKI event buffer header */
    448   BT_HDR hdr;
    449   tBTA_DM_API_ENABLE enable;
    450 
    451   tBTA_DM_API_SET_NAME set_name;
    452 
    453   tBTA_DM_API_SET_VISIBILITY set_visibility;
    454 
    455   tBTA_DM_API_ADD_DEVICE add_dev;
    456 
    457   tBTA_DM_API_REMOVE_DEVICE remove_dev;
    458 
    459   tBTA_DM_API_SEARCH search;
    460 
    461   tBTA_DM_API_DISCOVER discover;
    462 
    463   tBTA_DM_API_BOND bond;
    464 
    465   tBTA_DM_API_BOND_CANCEL bond_cancel;
    466 
    467   tBTA_DM_API_PIN_REPLY pin_reply;
    468 
    469   tBTA_DM_API_LOC_OOB loc_oob;
    470   tBTA_DM_API_CONFIRM confirm;
    471   tBTA_DM_CI_IO_REQ ci_io_req;
    472   tBTA_DM_CI_RMT_OOB ci_rmt_oob;
    473 
    474   tBTA_DM_REM_NAME rem_name;
    475 
    476   tBTA_DM_DISC_RESULT disc_result;
    477 
    478   tBTA_DM_INQUIRY_CMPL inq_cmpl;
    479 
    480   tBTA_DM_SDP_RESULT sdp_event;
    481 
    482   tBTA_DM_ACL_CHANGE acl_change;
    483 
    484   tBTA_DM_PM_BTM_STATUS pm_status;
    485 
    486   tBTA_DM_PM_TIMER pm_timer;
    487 
    488   tBTA_DM_API_DI_DISC di_disc;
    489 
    490   tBTA_DM_API_EXECUTE_CBACK exec_cback;
    491 
    492   tBTA_DM_API_SET_ENCRYPTION set_encryption;
    493 
    494   tBTA_DM_API_ADD_BLEKEY add_ble_key;
    495   tBTA_DM_API_ADD_BLE_DEVICE add_ble_device;
    496   tBTA_DM_API_PASSKEY_REPLY ble_passkey_reply;
    497   tBTA_DM_API_BLE_SEC_GRANT ble_sec_grant;
    498   tBTA_DM_API_BLE_CONN_PARAMS ble_set_conn_params;
    499   tBTA_DM_API_BLE_CONN_SCAN_PARAMS ble_set_conn_scan_params;
    500   tBTA_DM_API_BLE_OBSERVE ble_observe;
    501   tBTA_DM_API_ENABLE_PRIVACY ble_remote_privacy;
    502   tBTA_DM_API_LOCAL_PRIVACY ble_local_privacy;
    503   tBTA_DM_API_UPDATE_CONN_PARAM ble_update_conn_params;
    504   tBTA_DM_API_BLE_SET_DATA_LENGTH ble_set_data_length;
    505 
    506   tBTA_DM_API_ENERGY_INFO ble_energy_info;
    507 
    508   tBTA_DM_API_REMOVE_ACL remove_acl;
    509   tBTA_DM_API_REMOVE_ALL_ACL remove_all_acl;
    510 
    511 } tBTA_DM_MSG;
    512 
    513 #define BTA_DM_NUM_PEER_DEVICE 7
    514 
    515 #define BTA_DM_NOT_CONNECTED 0
    516 #define BTA_DM_CONNECTED 1
    517 #define BTA_DM_UNPAIRING 2
    518 typedef uint8_t tBTA_DM_CONN_STATE;
    519 
    520 #define BTA_DM_DI_NONE 0x00 /* nothing special */
    521 #define BTA_DM_DI_USE_SSR \
    522   0x10 /* set this bit if ssr is supported for this link */
    523 #define BTA_DM_DI_AV_ACTIVE \
    524   0x20 /* set this bit if AV is active for this link */
    525 #define BTA_DM_DI_SET_SNIFF \
    526   0x01 /* set this bit if call BTM_SetPowerMode(sniff) */
    527 #define BTA_DM_DI_INT_SNIFF \
    528   0x02 /* set this bit if call BTM_SetPowerMode(sniff) & enter sniff mode */
    529 #define BTA_DM_DI_ACP_SNIFF 0x04 /* set this bit if peer init sniff */
    530 typedef uint8_t tBTA_DM_DEV_INFO;
    531 
    532 /* set power mode request type */
    533 #define BTA_DM_PM_RESTART 1
    534 #define BTA_DM_PM_NEW_REQ 2
    535 #define BTA_DM_PM_EXECUTE 3
    536 typedef uint8_t tBTA_DM_PM_REQ;
    537 
    538 typedef struct {
    539   BD_ADDR peer_bdaddr;
    540   uint16_t link_policy;
    541   tBTA_DM_CONN_STATE conn_state;
    542   tBTA_PREF_ROLES pref_role;
    543   bool in_use;
    544   tBTA_DM_DEV_INFO info;
    545   tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
    546 #if (BTM_SSR_INCLUDED == TRUE)
    547   tBTM_PM_STATUS prev_low; /* previous low power mode used */
    548 #endif
    549   tBTA_DM_PM_ACTION pm_mode_attempted;
    550   tBTA_DM_PM_ACTION pm_mode_failed;
    551   bool remove_dev_pending;
    552   uint16_t conn_handle;
    553   tBT_TRANSPORT transport;
    554 } tBTA_DM_PEER_DEVICE;
    555 
    556 /* structure to store list of
    557   active connections */
    558 typedef struct {
    559   tBTA_DM_PEER_DEVICE peer_device[BTA_DM_NUM_PEER_DEVICE];
    560   uint8_t count;
    561   uint8_t le_count;
    562 } tBTA_DM_ACTIVE_LINK;
    563 
    564 typedef struct {
    565   BD_ADDR peer_bdaddr;
    566   tBTA_SYS_ID id;
    567   uint8_t app_id;
    568   tBTA_SYS_CONN_STATUS state;
    569   bool new_request;
    570 
    571 } tBTA_DM_SRVCS;
    572 
    573 #ifndef BTA_DM_NUM_CONN_SRVS
    574 #define BTA_DM_NUM_CONN_SRVS 10
    575 #endif
    576 
    577 typedef struct {
    578   uint8_t count;
    579   tBTA_DM_SRVCS conn_srvc[BTA_DM_NUM_CONN_SRVS];
    580 
    581 } tBTA_DM_CONNECTED_SRVCS;
    582 
    583 typedef struct {
    584 #define BTA_DM_PM_SNIFF_TIMER_IDX 0
    585 #define BTA_DM_PM_PARK_TIMER_IDX 1
    586 #define BTA_DM_PM_SUSPEND_TIMER_IDX 2
    587 #define BTA_DM_PM_MODE_TIMER_MAX 3
    588   /*
    589    * Keep three different timers for PARK, SNIFF and SUSPEND if TBFC is
    590    * supported.
    591    */
    592   alarm_t* timer[BTA_DM_PM_MODE_TIMER_MAX];
    593 
    594   uint8_t srvc_id[BTA_DM_PM_MODE_TIMER_MAX];
    595   uint8_t pm_action[BTA_DM_PM_MODE_TIMER_MAX];
    596   uint8_t active; /* number of active timer */
    597 
    598   BD_ADDR peer_bdaddr;
    599   bool in_use;
    600 } tBTA_PM_TIMER;
    601 
    602 extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
    603 
    604 #define BTA_DM_NUM_PM_TIMER 7
    605 
    606 /* DM control block */
    607 typedef struct {
    608   bool is_bta_dm_active;
    609   tBTA_DM_ACTIVE_LINK device_list;
    610   tBTA_DM_SEC_CBACK* p_sec_cback;
    611   tBTA_BLE_ENERGY_INFO_CBACK* p_energy_info_cback;
    612   uint16_t state;
    613   bool disabling;
    614   alarm_t* disable_timer;
    615   uint32_t wbt_sdp_handle; /* WIDCOMM Extensions SDP record handle */
    616   uint8_t wbt_scn;         /* WIDCOMM Extensions SCN */
    617   uint8_t num_master_only;
    618   uint8_t pm_id;
    619   tBTA_PM_TIMER pm_timer[BTA_DM_NUM_PM_TIMER];
    620   uint32_t
    621       role_policy_mask;   /* the bits set indicates the modules that wants to
    622                              remove role switch from the default link policy */
    623   uint16_t cur_policy;    /* current default link policy */
    624   uint16_t rs_event;      /* the event waiting for role switch */
    625   uint8_t cur_av_count;   /* current AV connecions */
    626   bool disable_pair_mode; /* disable pair mode or not */
    627   bool conn_paired_only;  /* allow connectable to paired device only or not */
    628   tBTA_DM_API_SEARCH search_msg;
    629   uint16_t page_scan_interval;
    630   uint16_t page_scan_window;
    631   uint16_t inquiry_scan_interval;
    632   uint16_t inquiry_scan_window;
    633 
    634   /* Storage for pin code request parameters */
    635   BD_ADDR pin_bd_addr;
    636   DEV_CLASS pin_dev_class;
    637   tBTA_DM_SEC_EVT pin_evt;
    638   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
    639                        show this number to UI */
    640   bool just_works;  /* true, if "Just Works" association model */
    641 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
    642   /* store UUID list for EIR */
    643   uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
    644 #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
    645   tBT_UUID custom_uuid[BTA_EIR_SERVER_NUM_CUSTOM_UUID];
    646 #endif
    647 
    648 #endif
    649 
    650   tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
    651   alarm_t* switch_delay_timer;
    652 
    653 } tBTA_DM_CB;
    654 
    655 /* DM search control block */
    656 typedef struct {
    657   tBTA_DM_SEARCH_CBACK* p_search_cback;
    658   tBTM_INQ_INFO* p_btm_inq_info;
    659   tBTA_SERVICE_MASK services;
    660   tBTA_SERVICE_MASK services_to_search;
    661   tBTA_SERVICE_MASK services_found;
    662   tSDP_DISCOVERY_DB* p_sdp_db;
    663   uint16_t state;
    664   BD_ADDR peer_bdaddr;
    665   bool name_discover_done;
    666   BD_NAME peer_name;
    667   alarm_t* search_timer;
    668   uint8_t service_index;
    669   tBTA_DM_MSG* p_search_queue; /* search or discover commands during search
    670                                   cancel stored here */
    671   bool wait_disc;
    672   bool sdp_results;
    673   tSDP_UUID uuid;
    674   uint8_t peer_scn;
    675   bool sdp_search;
    676   bool cancel_pending; /* inquiry cancel is pending */
    677   tBTA_TRANSPORT transport;
    678   tBTA_DM_SEARCH_CBACK* p_scan_cback;
    679   tBTA_GATTC_IF client_if;
    680   uint8_t num_uuid;
    681   tBT_UUID* p_srvc_uuid;
    682   uint8_t uuid_to_search;
    683   bool gatt_disc_active;
    684   uint16_t conn_id;
    685   uint8_t* p_ble_rawdata;
    686   uint32_t ble_raw_size;
    687   uint32_t ble_raw_used;
    688   alarm_t* gatt_close_timer; /* GATT channel close delay timer */
    689   BD_ADDR pending_close_bda; /* pending GATT channel remote device address */
    690 
    691 } tBTA_DM_SEARCH_CB;
    692 
    693 /* DI control block */
    694 typedef struct {
    695   tSDP_DISCOVERY_DB* p_di_db;         /* pointer to the DI discovery database */
    696   uint8_t di_num;                     /* total local DI record number */
    697   uint32_t di_handle[BTA_DI_NUM_MAX]; /* local DI record handle, the first one
    698                                          is primary record */
    699 } tBTA_DM_DI_CB;
    700 
    701 /* DM search state */
    702 enum {
    703 
    704   BTA_DM_SEARCH_IDLE,
    705   BTA_DM_SEARCH_ACTIVE,
    706   BTA_DM_SEARCH_CANCELLING,
    707   BTA_DM_DISCOVER_ACTIVE
    708 
    709 };
    710 
    711 typedef struct {
    712   DEV_CLASS dev_class; /* local device class */
    713   uint16_t
    714       policy_settings;   /* link policy setting hold, sniff, park, MS switch */
    715   uint16_t page_timeout; /* timeout for page in slots */
    716   uint16_t link_timeout; /* link supervision timeout in slots */
    717   bool avoid_scatter; /* true to avoid scatternet when av is streaming (be the
    718                          master) */
    719 
    720 } tBTA_DM_CFG;
    721 
    722 extern const uint32_t bta_service_id_to_btm_srv_id_lkup_tbl[];
    723 
    724 typedef struct {
    725   uint8_t id;
    726   uint8_t app_id;
    727   uint8_t cfg;
    728 
    729 } tBTA_DM_RM;
    730 
    731 extern tBTA_DM_CFG* p_bta_dm_cfg;
    732 extern tBTA_DM_RM* p_bta_dm_rm_cfg;
    733 
    734 typedef struct {
    735   uint8_t id;
    736   uint8_t app_id;
    737   uint8_t spec_idx; /* index of spec table to use */
    738 
    739 } tBTA_DM_PM_CFG;
    740 
    741 typedef struct {
    742   tBTA_DM_PM_ACTION power_mode;
    743   uint16_t timeout;
    744 
    745 } tBTA_DM_PM_ACTN;
    746 
    747 typedef struct {
    748   uint8_t allow_mask; /* mask of sniff/hold/park modes to allow */
    749 #if (BTM_SSR_INCLUDED == TRUE)
    750   uint8_t ssr; /* set SSR on conn open/unpark */
    751 #endif
    752   tBTA_DM_PM_ACTN actn_tbl[BTA_DM_PM_NUM_EVTS][2];
    753 
    754 } tBTA_DM_PM_SPEC;
    755 
    756 typedef struct {
    757   uint16_t max_lat;
    758   uint16_t min_rmt_to;
    759   uint16_t min_loc_to;
    760 } tBTA_DM_SSR_SPEC;
    761 
    762 typedef struct {
    763   uint16_t manufacturer;
    764   uint16_t lmp_sub_version;
    765   uint8_t lmp_version;
    766 } tBTA_DM_LMP_VER_INFO;
    767 
    768 extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
    769 
    770 extern tBTA_DM_PM_CFG* p_bta_dm_pm_cfg;
    771 extern tBTA_DM_PM_SPEC* p_bta_dm_pm_spec;
    772 extern tBTM_PM_PWR_MD* p_bta_dm_pm_md;
    773 #if (BTM_SSR_INCLUDED == TRUE)
    774 extern tBTA_DM_SSR_SPEC* p_bta_dm_ssr_spec;
    775 #endif
    776 
    777 /* update dynamic BRCM Aware EIR data */
    778 extern const tBTA_DM_EIR_CONF bta_dm_eir_cfg;
    779 extern tBTA_DM_EIR_CONF* p_bta_dm_eir_cfg;
    780 
    781 /* DM control block */
    782 extern tBTA_DM_CB bta_dm_cb;
    783 
    784 /* DM search control block */
    785 extern tBTA_DM_SEARCH_CB bta_dm_search_cb;
    786 
    787 /* DI control block */
    788 extern tBTA_DM_DI_CB bta_dm_di_cb;
    789 
    790 extern bool bta_dm_sm_execute(BT_HDR* p_msg);
    791 extern void bta_dm_sm_disable(void);
    792 extern bool bta_dm_search_sm_execute(BT_HDR* p_msg);
    793 extern void bta_dm_search_sm_disable(void);
    794 
    795 extern void bta_dm_enable(tBTA_DM_MSG* p_data);
    796 extern void bta_dm_disable(tBTA_DM_MSG* p_data);
    797 extern void bta_dm_init_cb(void);
    798 extern void bta_dm_set_dev_name(tBTA_DM_MSG* p_data);
    799 extern void bta_dm_set_visibility(tBTA_DM_MSG* p_data);
    800 
    801 extern void bta_dm_set_scan_config(tBTA_DM_MSG* p_data);
    802 extern void bta_dm_vendor_spec_command(tBTA_DM_MSG* p_data);
    803 extern void bta_dm_bond(tBTA_DM_MSG* p_data);
    804 extern void bta_dm_bond_cancel(tBTA_DM_MSG* p_data);
    805 extern void bta_dm_pin_reply(tBTA_DM_MSG* p_data);
    806 extern void bta_dm_acl_change(tBTA_DM_MSG* p_data);
    807 extern void bta_dm_add_device(tBTA_DM_MSG* p_data);
    808 extern void bta_dm_remove_device(tBTA_DM_MSG* p_data);
    809 extern void bta_dm_close_acl(tBTA_DM_MSG* p_data);
    810 
    811 extern void bta_dm_pm_btm_status(tBTA_DM_MSG* p_data);
    812 extern void bta_dm_pm_timer(tBTA_DM_MSG* p_data);
    813 extern void bta_dm_add_ampkey(tBTA_DM_MSG* p_data);
    814 
    815 extern void bta_dm_add_blekey(tBTA_DM_MSG* p_data);
    816 extern void bta_dm_add_ble_device(tBTA_DM_MSG* p_data);
    817 extern void bta_dm_ble_passkey_reply(tBTA_DM_MSG* p_data);
    818 extern void bta_dm_ble_confirm_reply(tBTA_DM_MSG* p_data);
    819 extern void bta_dm_security_grant(tBTA_DM_MSG* p_data);
    820 extern void bta_dm_ble_set_bg_conn_type(tBTA_DM_MSG* p_data);
    821 extern void bta_dm_ble_set_conn_params(tBTA_DM_MSG* p_data);
    822 extern void bta_dm_ble_set_conn_scan_params(tBTA_DM_MSG* p_data);
    823 extern void bta_dm_close_gatt_conn(tBTA_DM_MSG* p_data);
    824 extern void bta_dm_ble_observe(tBTA_DM_MSG* p_data);
    825 extern void bta_dm_ble_update_conn_params(tBTA_DM_MSG* p_data);
    826 extern void bta_dm_ble_config_local_privacy(tBTA_DM_MSG* p_data);
    827 extern void bta_dm_ble_set_adv_params(uint16_t adv_int_min,
    828                                       uint16_t adv_int_max,
    829                                       tBLE_BD_ADDR* p_dir_bda);
    830 
    831 extern void bta_dm_ble_set_data_length(tBTA_DM_MSG* p_data);
    832 
    833 extern void bta_dm_ble_get_energy_info(tBTA_DM_MSG* p_data);
    834 
    835 extern void bta_dm_set_encryption(tBTA_DM_MSG* p_data);
    836 extern void bta_dm_confirm(tBTA_DM_MSG* p_data);
    837 extern void bta_dm_loc_oob(tBTA_DM_MSG* p_data);
    838 extern void bta_dm_ci_io_req_act(tBTA_DM_MSG* p_data);
    839 extern void bta_dm_ci_rmt_oob_act(tBTA_DM_MSG* p_data);
    840 
    841 extern void bta_dm_init_pm(void);
    842 extern void bta_dm_disable_pm(void);
    843 
    844 extern uint8_t bta_dm_get_av_count(void);
    845 extern void bta_dm_search_start(tBTA_DM_MSG* p_data);
    846 extern void bta_dm_search_cancel(tBTA_DM_MSG* p_data);
    847 extern void bta_dm_discover(tBTA_DM_MSG* p_data);
    848 extern void bta_dm_di_disc(tBTA_DM_MSG* p_data);
    849 extern void bta_dm_inq_cmpl(tBTA_DM_MSG* p_data);
    850 extern void bta_dm_rmt_name(tBTA_DM_MSG* p_data);
    851 extern void bta_dm_sdp_result(tBTA_DM_MSG* p_data);
    852 extern void bta_dm_search_cmpl(tBTA_DM_MSG* p_data);
    853 extern void bta_dm_free_sdp_db(tBTA_DM_MSG* p_data);
    854 extern void bta_dm_disc_result(tBTA_DM_MSG* p_data);
    855 extern void bta_dm_search_result(tBTA_DM_MSG* p_data);
    856 extern void bta_dm_discovery_cmpl(tBTA_DM_MSG* p_data);
    857 extern void bta_dm_queue_search(tBTA_DM_MSG* p_data);
    858 extern void bta_dm_queue_disc(tBTA_DM_MSG* p_data);
    859 extern void bta_dm_search_clear_queue(tBTA_DM_MSG* p_data);
    860 extern void bta_dm_search_cancel_cmpl(tBTA_DM_MSG* p_data);
    861 extern void bta_dm_search_cancel_notify(tBTA_DM_MSG* p_data);
    862 extern void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG* p_data);
    863 extern void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data);
    864 extern tBTA_DM_PEER_DEVICE* bta_dm_find_peer_device(const BD_ADDR 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