Home | History | Annotate | Download | only in sys
      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  *  Routes connection status callbacks from various sub systems to DM
     22  *
     23  ******************************************************************************/
     24 
     25 #include <stddef.h>
     26 
     27 #include "bt_common.h"
     28 #include "bta_api.h"
     29 #include "bta_sys.h"
     30 #include "bta_sys_int.h"
     31 #include "osi/include/osi.h"
     32 #include "utl.h"
     33 
     34 /*******************************************************************************
     35  *
     36  * Function         bta_sys_rm_register
     37  *
     38  * Description      Called by BTA DM to register role management callbacks
     39  *
     40  *
     41  * Returns          void
     42  *
     43  ******************************************************************************/
     44 void bta_sys_rm_register(tBTA_SYS_CONN_CBACK* p_cback) {
     45   bta_sys_cb.prm_cb = p_cback;
     46 }
     47 
     48 /*******************************************************************************
     49  *
     50  * Function         bta_sys_policy_register
     51  *
     52  * Description      Called by BTA DM to register link policy change callbacks
     53  *
     54  *
     55  * Returns          void
     56  *
     57  ******************************************************************************/
     58 void bta_sys_policy_register(tBTA_SYS_CONN_CBACK* p_cback) {
     59   bta_sys_cb.p_policy_cb = p_cback;
     60 }
     61 
     62 /*******************************************************************************
     63  *
     64  * Function         bta_sys_role_chg_register
     65  *
     66  * Description      Called by BTA AV to register role change callbacks
     67  *
     68  *
     69  * Returns          void
     70  *
     71  ******************************************************************************/
     72 void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK* p_cback) {
     73   bta_sys_cb.p_role_cb = p_cback;
     74 }
     75 /*******************************************************************************
     76  *
     77  * Function         bta_sys_ssr_cfg_register
     78  *
     79  * Description      Called by BTA DM to register SSR configuration callback
     80  *
     81  *
     82  * Returns          void
     83  *
     84  ******************************************************************************/
     85 #if (BTM_SSR_INCLUDED == TRUE)
     86 void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK* p_cback) {
     87   bta_sys_cb.p_ssr_cb = p_cback;
     88 }
     89 #endif
     90 /*******************************************************************************
     91  *
     92  * Function         bta_sys_role_chg_register
     93  *
     94  * Description      Called by BTA AV to register role change callbacks
     95  *
     96  *
     97  * Returns          void
     98  *
     99  ******************************************************************************/
    100 void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, uint8_t new_role,
    101                              uint8_t hci_status) {
    102   if (bta_sys_cb.p_role_cb) {
    103     bta_sys_cb.p_role_cb(BTA_SYS_ROLE_CHANGE, new_role, hci_status, p_bda);
    104   }
    105 }
    106 
    107 /*******************************************************************************
    108  *
    109  * Function         bta_sys_collision_register
    110  *
    111  * Description      Called by any BTA module to register for collision event.
    112  *
    113  *
    114  * Returns          void
    115  *
    116  ******************************************************************************/
    117 void bta_sys_collision_register(uint8_t bta_id, tBTA_SYS_CONN_CBACK* p_cback) {
    118   uint8_t index;
    119 
    120   for (index = 0; index < MAX_COLLISION_REG; index++) {
    121     if ((bta_sys_cb.colli_reg.id[index] == bta_id) ||
    122         (bta_sys_cb.colli_reg.id[index] == 0)) {
    123       bta_sys_cb.colli_reg.id[index] = bta_id;
    124       bta_sys_cb.colli_reg.p_coll_cback[index] = p_cback;
    125       return;
    126     }
    127   }
    128 }
    129 
    130 /*******************************************************************************
    131  *
    132  * Function         bta_sys_notify_collision
    133  *
    134  * Description      Called by BTA DM to notify collision event.
    135  *
    136  *
    137  * Returns          void
    138  *
    139  ******************************************************************************/
    140 void bta_sys_notify_collision(BD_ADDR_PTR p_bda) {
    141   uint8_t index;
    142 
    143   for (index = 0; index < MAX_COLLISION_REG; index++) {
    144     if ((bta_sys_cb.colli_reg.id[index] != 0) &&
    145         (bta_sys_cb.colli_reg.p_coll_cback[index] != NULL)) {
    146       bta_sys_cb.colli_reg.p_coll_cback[index](0, BTA_ID_SYS, 0, p_bda);
    147     }
    148   }
    149 }
    150 
    151 /*******************************************************************************
    152  *
    153  * Function         bta_sys_sco_register
    154  *
    155  * Description      Called by BTA AV to register sco connection change callbacks
    156  *
    157  *
    158  * Returns          void
    159  *
    160  ******************************************************************************/
    161 void bta_sys_sco_register(tBTA_SYS_CONN_CBACK* p_cback) {
    162   bta_sys_cb.p_sco_cb = p_cback;
    163 }
    164 
    165 /*******************************************************************************
    166  *
    167  * Function         bta_sys_pm_register
    168  *
    169  * Description      Called by BTA DM to register power management callbacks
    170  *
    171  *
    172  * Returns          void
    173  *
    174  ******************************************************************************/
    175 void bta_sys_pm_register(tBTA_SYS_CONN_CBACK* p_cback) {
    176   bta_sys_cb.ppm_cb = p_cback;
    177 }
    178 
    179 /*******************************************************************************
    180  *
    181  * Function         bta_sys_conn_open
    182  *
    183  * Description      Called by BTA subsystems when a connection is made to
    184  *                  the service
    185  *
    186  *
    187  * Returns          void
    188  *
    189  ******************************************************************************/
    190 void bta_sys_conn_open(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    191   if (bta_sys_cb.prm_cb) {
    192     bta_sys_cb.prm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
    193   }
    194 
    195   if (bta_sys_cb.ppm_cb) {
    196     bta_sys_cb.ppm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
    197   }
    198 }
    199 
    200 /*******************************************************************************
    201  *
    202  * Function         bta_sys_conn_close
    203  *
    204  * Description      Called by BTA subsystems when a connection to the service
    205  *                  is closed
    206  *
    207  *
    208  * Returns          void
    209  *
    210  ******************************************************************************/
    211 void bta_sys_conn_close(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    212   if (bta_sys_cb.prm_cb) {
    213     bta_sys_cb.prm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
    214   }
    215 
    216   if (bta_sys_cb.ppm_cb) {
    217     bta_sys_cb.ppm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
    218   }
    219 }
    220 
    221 /*******************************************************************************
    222  *
    223  * Function         bta_sys_app_open
    224  *
    225  * Description      Called by BTA subsystems when application initiates
    226  *                  connection to a peer device
    227  *
    228  *
    229  * Returns          void
    230  *
    231  ******************************************************************************/
    232 void bta_sys_app_open(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    233   if (bta_sys_cb.ppm_cb) {
    234     bta_sys_cb.ppm_cb(BTA_SYS_APP_OPEN, id, app_id, peer_addr);
    235   }
    236 }
    237 
    238 /*******************************************************************************
    239  *
    240  * Function         bta_sys_app_close
    241  *
    242  * Description      Called by BTA subsystems when application initiates close
    243  *                  of connection to peer device
    244  *
    245  * Returns          void
    246  *
    247  ******************************************************************************/
    248 void bta_sys_app_close(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    249   if (bta_sys_cb.ppm_cb) {
    250     bta_sys_cb.ppm_cb(BTA_SYS_APP_CLOSE, id, app_id, peer_addr);
    251   }
    252 }
    253 
    254 /*******************************************************************************
    255  *
    256  * Function         bta_sys_sco_open
    257  *
    258  * Description      Called by BTA subsystems when sco connection for that
    259  *                  service is open
    260  *
    261  * Returns          void
    262  *
    263  ******************************************************************************/
    264 void bta_sys_sco_open(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    265   /* AG triggers p_sco_cb by bta_sys_sco_use. */
    266   if ((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb)) {
    267     /* without querying BTM_GetNumScoLinks() */
    268     bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
    269   }
    270 
    271   if (bta_sys_cb.ppm_cb) {
    272     bta_sys_cb.ppm_cb(BTA_SYS_SCO_OPEN, id, app_id, peer_addr);
    273   }
    274 }
    275 
    276 /*******************************************************************************
    277  *
    278  * Function         bta_sys_sco_close
    279  *
    280  * Description      Called by BTA subsystems when sco connection for that
    281  *                  service is closed
    282  *
    283  * Returns          void
    284  *
    285  ******************************************************************************/
    286 void bta_sys_sco_close(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    287   uint8_t num_sco_links;
    288 
    289   if ((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb)) {
    290     num_sco_links = BTM_GetNumScoLinks();
    291     bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
    292   }
    293 
    294   if (bta_sys_cb.ppm_cb) {
    295     bta_sys_cb.ppm_cb(BTA_SYS_SCO_CLOSE, id, app_id, peer_addr);
    296   }
    297 }
    298 
    299 /*******************************************************************************
    300  *
    301  * Function         bta_sys_sco_use
    302  *
    303  * Description      Called by BTA subsystems when that service needs to use sco.
    304  *
    305  *
    306  * Returns          void
    307  *
    308  ******************************************************************************/
    309 void bta_sys_sco_use(UNUSED_ATTR uint8_t id, uint8_t app_id,
    310                      BD_ADDR peer_addr) {
    311   /* AV streaming need to be suspended before SCO is connected. */
    312   if (bta_sys_cb.p_sco_cb) {
    313     /* without querying BTM_GetNumScoLinks() */
    314     bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
    315   }
    316 }
    317 
    318 /*******************************************************************************
    319  *
    320  * Function         bta_sys_sco_unuse
    321  *
    322  * Description      Called by BTA subsystems when sco connection for that
    323  *                  service is no longer needed.
    324  *
    325  * Returns          void
    326  *
    327  ******************************************************************************/
    328 void bta_sys_sco_unuse(UNUSED_ATTR uint8_t id, uint8_t app_id,
    329                        BD_ADDR peer_addr) {
    330   uint8_t num_sco_links;
    331 
    332   if ((bta_sys_cb.p_sco_cb)) {
    333     num_sco_links = BTM_GetNumScoLinks();
    334     bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
    335   }
    336 }
    337 /*******************************************************************************
    338  *
    339  * Function         bta_sys_chg_ssr_config
    340  *
    341  * Description      Called by BTA subsystems to indicate that the given app SSR
    342  *                  setting needs to be changed.
    343  *
    344  * Returns          void
    345  *
    346  ******************************************************************************/
    347 #if (BTM_SSR_INCLUDED == TRUE)
    348 void bta_sys_chg_ssr_config(uint8_t id, uint8_t app_id, uint16_t max_latency,
    349                             uint16_t min_tout) {
    350   if (bta_sys_cb.p_ssr_cb) {
    351     bta_sys_cb.p_ssr_cb(id, app_id, max_latency, min_tout);
    352   }
    353 }
    354 #endif
    355 /*******************************************************************************
    356  *
    357  * Function         bta_sys_set_policy
    358  *
    359  * Description      Called by BTA subsystems to indicate that the given link
    360  *                  policy to peer device should be set
    361  *
    362  * Returns          void
    363  *
    364  ******************************************************************************/
    365 void bta_sys_set_policy(uint8_t id, uint8_t policy, BD_ADDR peer_addr) {
    366   if (bta_sys_cb.p_policy_cb) {
    367     bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_SET, id, policy, peer_addr);
    368   }
    369 }
    370 
    371 /*******************************************************************************
    372  *
    373  * Function         bta_sys_clear_policy
    374  *
    375  * Description      Called by BTA subsystems to indicate that the given link
    376  *                  policy to peer device should be clear
    377  *
    378  * Returns          void
    379  *
    380  ******************************************************************************/
    381 void bta_sys_clear_policy(uint8_t id, uint8_t policy, BD_ADDR peer_addr) {
    382   if (bta_sys_cb.p_policy_cb) {
    383     bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_CLR, id, policy, peer_addr);
    384   }
    385 }
    386 
    387 /*******************************************************************************
    388  *
    389  * Function         bta_sys_set_default_policy
    390  *
    391  * Description      Called by BTA subsystems to indicate that the given default
    392  *                  link policy should be set
    393  *
    394  * Returns          void
    395  *
    396  ******************************************************************************/
    397 void bta_sys_set_default_policy(uint8_t id, uint8_t policy) {
    398   if (bta_sys_cb.p_policy_cb) {
    399     bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_SET, id, policy, NULL);
    400   }
    401 }
    402 
    403 /*******************************************************************************
    404  *
    405  * Function         bta_sys_clear_default_policy
    406  *
    407  * Description      Called by BTA subsystems to indicate that the given default
    408  *                  link policy should be clear
    409  *
    410  * Returns          void
    411  *
    412  ******************************************************************************/
    413 void bta_sys_clear_default_policy(uint8_t id, uint8_t policy) {
    414   if (bta_sys_cb.p_policy_cb) {
    415     bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_CLR, id, policy, NULL);
    416   }
    417 }
    418 
    419 /*******************************************************************************
    420  *
    421  * Function         bta_sys_idle
    422  *
    423  * Description      Called by BTA subsystems to indicate that the connection to
    424  *                  peer device is idle
    425  *
    426  * Returns          void
    427  *
    428  ******************************************************************************/
    429 void bta_sys_idle(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    430   if (bta_sys_cb.prm_cb) {
    431     bta_sys_cb.prm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
    432   }
    433 
    434   if (bta_sys_cb.ppm_cb) {
    435     bta_sys_cb.ppm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
    436   }
    437 }
    438 
    439 /*******************************************************************************
    440  *
    441  * Function         bta_sys_busy
    442  *
    443  * Description      Called by BTA subsystems to indicate that the connection to
    444  *                  peer device is busy
    445  *
    446  * Returns          void
    447  *
    448  ******************************************************************************/
    449 void bta_sys_busy(uint8_t id, uint8_t app_id, BD_ADDR peer_addr) {
    450   if (bta_sys_cb.prm_cb) {
    451     bta_sys_cb.prm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
    452   }
    453 
    454   if (bta_sys_cb.ppm_cb) {
    455     bta_sys_cb.ppm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
    456   }
    457 }
    458 
    459 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
    460 /*******************************************************************************
    461  *
    462  * Function         bta_sys_eir_register
    463  *
    464  * Description      Called by BTA DM to register EIR utility function that can
    465  *                  be used by the other BTA modules to add/remove UUID.
    466  *
    467  * Returns          void
    468  *
    469  ******************************************************************************/
    470 void bta_sys_eir_register(tBTA_SYS_EIR_CBACK* p_cback) {
    471   bta_sys_cb.eir_cb = p_cback;
    472 }
    473 
    474 /*******************************************************************************
    475  *
    476  * Function         bta_sys_add_uuid
    477  *
    478  * Description      Called by BTA subsystems to indicate to DM that new service
    479  *                  class UUID is added.
    480  *
    481  * Returns          void
    482  *
    483  ******************************************************************************/
    484 void bta_sys_add_uuid(uint16_t uuid16) {
    485   if (bta_sys_cb.eir_cb) {
    486     bta_sys_cb.eir_cb(uuid16, true);
    487   }
    488 }
    489 
    490 /*******************************************************************************
    491  *
    492  * Function         bta_sys_remove_uuid
    493  *
    494  * Description      Called by BTA subsystems to indicate to DM that the service
    495  *                  class UUID is removed.
    496  *
    497  * Returns          void
    498  *
    499  ******************************************************************************/
    500 void bta_sys_remove_uuid(uint16_t uuid16) {
    501   if (bta_sys_cb.eir_cb) {
    502     bta_sys_cb.eir_cb(uuid16, false);
    503   }
    504 }
    505 #endif
    506