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  *  This is the main implementation file for the BTA system manager.
     22  *
     23  ******************************************************************************/
     24 
     25 #include "btm_api.h"
     26 #include "bta_api.h"
     27 #include "bta_sys.h"
     28 #include "bta_sys_int.h"
     29 #include "bta_sys_ci.h"
     30 #include "bta_sys_co.h"
     31 #if BTA_FM_INCLUDED == TRUE
     32 #include "bta_fm_api.h"
     33 #endif
     34 #if BTA_FMTX_INCLUDED == TRUE
     35 #include "bta_fmtx_api.h"
     36 #endif
     37 #if GPS_INCLUDED == TRUE
     38 #include "bta_gps_api.h"
     39 #endif
     40 
     41 #include "gki.h"
     42 #include "ptim.h"
     43 #include <string.h>
     44 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
     45 #include "bta_ar_api.h"
     46 #endif
     47 #include "utl.h"
     48 
     49 /* protocol timer update period, in milliseconds */
     50 #ifndef BTA_SYS_TIMER_PERIOD
     51 #define BTA_SYS_TIMER_PERIOD            1000
     52 #endif
     53 
     54 /* system manager control block definition */
     55 #if BTA_DYNAMIC_MEMORY == FALSE
     56 tBTA_SYS_CB bta_sys_cb;
     57 #endif
     58 
     59 /* trace level */
     60 /* TODO Bluedroid - Hard-coded trace levels -  Needs to be configurable */
     61 UINT8 appl_trace_level = BT_TRACE_LEVEL_WARNING; //APPL_INITIAL_TRACE_LEVEL;
     62 UINT8 btif_trace_level = BT_TRACE_LEVEL_WARNING;
     63 
     64 static const tBTA_SYS_REG bta_sys_hw_reg =
     65 {
     66     bta_sys_sm_execute,
     67     NULL
     68 };
     69 
     70 
     71 /* type for action functions */
     72 typedef void (*tBTA_SYS_ACTION)(tBTA_SYS_HW_MSG *p_data);
     73 
     74 /* action function list */
     75 const tBTA_SYS_ACTION bta_sys_action[] =
     76 {
     77     /* device manager local device API events - cf bta_sys.h for events */
     78     bta_sys_hw_api_enable,             /* 0  BTA_SYS_HW_API_ENABLE_EVT    */
     79     bta_sys_hw_evt_enabled,           /* 1  BTA_SYS_HW_EVT_ENABLED_EVT */
     80     bta_sys_hw_evt_stack_enabled,       /* 2  BTA_SYS_HW_EVT_STACK_ENABLED_EVT */
     81     bta_sys_hw_api_disable,             /* 3  BTA_SYS_HW_API_DISABLE_EVT     */
     82     bta_sys_hw_evt_disabled,           /* 4  BTA_SYS_HW_EVT_DISABLED_EVT  */
     83     bta_sys_hw_error                        /* 5   BTA_SYS_HW_ERROR_EVT  */
     84 };
     85 
     86 /* state machine action enumeration list */
     87 enum
     88 {
     89     /* device manager local device API events */
     90     BTA_SYS_HW_API_ENABLE,
     91     BTA_SYS_HW_EVT_ENABLED,
     92     BTA_SYS_HW_EVT_STACK_ENABLED,
     93     BTA_SYS_HW_API_DISABLE,
     94     BTA_SYS_HW_EVT_DISABLED,
     95     BTA_SYS_HW_ERROR
     96 };
     97 
     98 #define BTA_SYS_NUM_ACTIONS  (BTA_SYS_MAX_EVT & 0x00ff)
     99 #define BTA_SYS_IGNORE       BTA_SYS_NUM_ACTIONS
    100 
    101 /* state table information */
    102 #define BTA_SYS_ACTIONS              2       /* number of actions */
    103 #define BTA_SYS_NEXT_STATE           2       /* position of next state */
    104 #define BTA_SYS_NUM_COLS             3       /* number of columns in state tables */
    105 
    106 
    107 /* state table for OFF state */
    108 const UINT8 bta_sys_hw_off[][BTA_SYS_NUM_COLS] =
    109 {
    110 /* Event                    Action 1               Action 2             Next State */
    111 /* API_ENABLE    */  {BTA_SYS_HW_API_ENABLE,    BTA_SYS_IGNORE,     BTA_SYS_HW_STARTING},
    112 /* EVT_ENABLED   */  {BTA_SYS_IGNORE,           BTA_SYS_IGNORE,     BTA_SYS_HW_STARTING},
    113 /* STACK_ENABLED */  {BTA_SYS_IGNORE,           BTA_SYS_IGNORE,     BTA_SYS_HW_ON},
    114 /* API_DISABLE   */  {BTA_SYS_HW_EVT_DISABLED,  BTA_SYS_IGNORE,     BTA_SYS_HW_OFF},
    115 /* EVT_DISABLED  */  {BTA_SYS_IGNORE,           BTA_SYS_IGNORE,     BTA_SYS_HW_OFF},
    116 /* EVT_ERROR     */  {BTA_SYS_IGNORE,           BTA_SYS_IGNORE,     BTA_SYS_HW_OFF}
    117 };
    118 
    119 const UINT8 bta_sys_hw_starting[][BTA_SYS_NUM_COLS] =
    120 {
    121 /* Event                    Action 1                   Action 2               Next State */
    122 /* API_ENABLE    */  {BTA_SYS_IGNORE,               BTA_SYS_IGNORE,         BTA_SYS_HW_STARTING}, /* wait for completion event */
    123 /* EVT_ENABLED   */  {BTA_SYS_HW_EVT_ENABLED,       BTA_SYS_IGNORE,         BTA_SYS_HW_STARTING},
    124 /* STACK_ENABLED */  {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_IGNORE,         BTA_SYS_HW_ON},
    125 /* API_DISABLE   */  {BTA_SYS_IGNORE,               BTA_SYS_IGNORE,         BTA_SYS_HW_STOPPING}, /* successive disable/enable: change state wait for completion to disable */
    126 /* EVT_DISABLED  */  {BTA_SYS_HW_EVT_DISABLED,      BTA_SYS_HW_API_ENABLE,  BTA_SYS_HW_STARTING}, /* successive enable/disable: notify, then restart HW */
    127 /* EVT_ERROR */      {BTA_SYS_HW_ERROR,             BTA_SYS_IGNORE,         BTA_SYS_HW_ON}
    128 };
    129 
    130 const UINT8 bta_sys_hw_on[][BTA_SYS_NUM_COLS] =
    131 {
    132 /* Event                    Action 1                   Action 2               Next State */
    133 /* API_ENABLE    */  {BTA_SYS_HW_API_ENABLE,        BTA_SYS_IGNORE,         BTA_SYS_HW_ON},
    134 /* EVT_ENABLED   */  {BTA_SYS_IGNORE,               BTA_SYS_IGNORE,         BTA_SYS_HW_ON},
    135 /* STACK_ENABLED */  {BTA_SYS_IGNORE,               BTA_SYS_IGNORE,         BTA_SYS_HW_ON},
    136 /* API_DISABLE   */  {BTA_SYS_HW_API_DISABLE,       BTA_SYS_IGNORE,         BTA_SYS_HW_ON}, /* don't change the state here, as some other modules might be active */
    137 /* EVT_DISABLED */   {BTA_SYS_HW_ERROR,             BTA_SYS_IGNORE,         BTA_SYS_HW_ON},
    138 /* EVT_ERROR */      {BTA_SYS_HW_ERROR,             BTA_SYS_IGNORE,         BTA_SYS_HW_ON}
    139 };
    140 
    141 const UINT8 bta_sys_hw_stopping[][BTA_SYS_NUM_COLS] =
    142 {
    143 /* Event                    Action 1                   Action 2               Next State */
    144 /* API_ENABLE    */  {BTA_SYS_IGNORE,               BTA_SYS_IGNORE,         BTA_SYS_HW_STARTING}, /* change state, and wait for completion event to enable */
    145 /* EVT_ENABLED   */  {BTA_SYS_HW_EVT_ENABLED,       BTA_SYS_IGNORE,         BTA_SYS_HW_STOPPING}, /* successive enable/disable: finish the enable before disabling */
    146 /* STACK_ENABLED */  {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_HW_API_DISABLE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: notify, then stop */
    147 /* API_DISABLE   */  {BTA_SYS_IGNORE,               BTA_SYS_IGNORE,         BTA_SYS_HW_STOPPING}, /* wait for completion event */
    148 /* EVT_DISABLED  */  {BTA_SYS_HW_EVT_DISABLED,      BTA_SYS_IGNORE,         BTA_SYS_HW_OFF},
    149 /* EVT_ERROR     */  {BTA_SYS_HW_API_DISABLE,       BTA_SYS_IGNORE,         BTA_SYS_HW_STOPPING}
    150 };
    151 
    152 typedef const UINT8 (*tBTA_SYS_ST_TBL)[BTA_SYS_NUM_COLS];
    153 
    154 /* state table */
    155 const tBTA_SYS_ST_TBL bta_sys_st_tbl[] = {
    156     bta_sys_hw_off,
    157     bta_sys_hw_starting,
    158     bta_sys_hw_on,
    159     bta_sys_hw_stopping
    160 };
    161 
    162 /*******************************************************************************
    163 **
    164 ** Function         bta_sys_init
    165 **
    166 ** Description      BTA initialization; called from task initialization.
    167 **
    168 **
    169 ** Returns          void
    170 **
    171 *******************************************************************************/
    172 BTA_API void bta_sys_init(void)
    173 {
    174     memset(&bta_sys_cb, 0, sizeof(tBTA_SYS_CB));
    175     ptim_init(&bta_sys_cb.ptim_cb, BTA_SYS_TIMER_PERIOD, p_bta_sys_cfg->timer);
    176     bta_sys_cb.task_id = GKI_get_taskid();
    177     appl_trace_level = p_bta_sys_cfg->trace_level;
    178 
    179     /* register BTA SYS message handler */
    180     bta_sys_register( BTA_ID_SYS,  &bta_sys_hw_reg);
    181 
    182     /* register for BTM notifications */
    183     BTM_RegisterForDeviceStatusNotif ((tBTM_DEV_STATUS_CB*)&bta_sys_hw_btm_cback );
    184 
    185 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
    186     bta_ar_init();
    187 #endif
    188 
    189 }
    190 
    191 /*******************************************************************************
    192 **
    193 ** Function         bta_dm_sm_execute
    194 **
    195 ** Description      State machine event handling function for DM
    196 **
    197 **
    198 ** Returns          void
    199 **
    200 *******************************************************************************/
    201 BOOLEAN bta_sys_sm_execute(BT_HDR *p_msg)
    202 {
    203     BOOLEAN freebuf = TRUE;
    204     tBTA_SYS_ST_TBL      state_table;
    205     UINT8               action;
    206     int                 i;
    207 
    208     APPL_TRACE_EVENT("bta_sys_sm_execute state:%d, event:0x%x",  bta_sys_cb.state, p_msg->event);
    209 
    210     /* look up the state table for the current state */
    211     state_table = bta_sys_st_tbl[bta_sys_cb.state];
    212     /* update state */
    213     bta_sys_cb.state = state_table[p_msg->event & 0x00ff][BTA_SYS_NEXT_STATE];
    214 
    215     /* execute action functions */
    216     for (i = 0; i < BTA_SYS_ACTIONS; i++)
    217     {
    218         if ((action = state_table[p_msg->event & 0x00ff][i]) != BTA_SYS_IGNORE)
    219         {
    220             (*bta_sys_action[action])( (tBTA_SYS_HW_MSG*) p_msg);
    221         }
    222         else
    223         {
    224             break;
    225         }
    226     }
    227     return freebuf;
    228 
    229 }
    230 
    231 
    232 void bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *cback)
    233 {
    234     bta_sys_cb.sys_hw_cback[module]=cback;
    235 }
    236 
    237 
    238 void bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module )
    239 {
    240     bta_sys_cb.sys_hw_cback[module]=NULL;
    241 }
    242 
    243 /*******************************************************************************
    244 **
    245 ** Function         bta_sys_hw_btm_cback
    246 **
    247 ** Description     This function is registered by BTA SYS to BTM in order to get status notifications
    248 **
    249 **
    250 ** Returns
    251 **
    252 *******************************************************************************/
    253 void bta_sys_hw_btm_cback( tBTM_DEV_STATUS status )
    254 {
    255 
    256     tBTA_SYS_HW_MSG *sys_event;
    257 
    258     APPL_TRACE_DEBUG(" bta_sys_hw_btm_cback was called with parameter: %i" , status );
    259 
    260     /* send a message to BTA SYS */
    261     if ((sys_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL)
    262     {
    263         if (status == BTM_DEV_STATUS_UP)
    264             sys_event->hdr.event = BTA_SYS_EVT_STACK_ENABLED_EVT;
    265         else if (status == BTM_DEV_STATUS_DOWN)
    266             sys_event->hdr.event = BTA_SYS_ERROR_EVT;
    267         else
    268         {
    269             /* BTM_DEV_STATUS_CMD_TOUT is ignored for now. */
    270             GKI_freebuf (sys_event);
    271             sys_event = NULL;
    272         }
    273 
    274         if (sys_event)
    275         {
    276             bta_sys_sendmsg(sys_event);
    277         }
    278     }
    279     else
    280     {
    281         APPL_TRACE_DEBUG("ERROR bta_sys_hw_btm_cback couldn't send msg" );
    282     }
    283 }
    284 
    285 
    286 
    287 /*******************************************************************************
    288 **
    289 ** Function         bta_sys_hw_error
    290 **
    291 ** Description     In case the HW device stops answering... Try to turn it off, then re-enable all
    292 **                      previously active SW modules.
    293 **
    294 ** Returns          success or failure
    295 **
    296 *******************************************************************************/
    297 void bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg)
    298 {
    299     UINT8 module_index;
    300     UNUSED(p_sys_hw_msg);
    301 
    302     APPL_TRACE_DEBUG("%s", __FUNCTION__);
    303 
    304     for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES; module_index++)
    305     {
    306         if( bta_sys_cb.sys_hw_module_active &  ((UINT32)1 << module_index )) {
    307             switch( module_index)
    308                 {
    309                 case BTA_SYS_HW_BLUETOOTH:
    310                    /* Send BTA_SYS_HW_ERROR_EVT to DM */
    311                    if (bta_sys_cb.sys_hw_cback[module_index] != NULL)
    312                        bta_sys_cb.sys_hw_cback[module_index] (BTA_SYS_HW_ERROR_EVT);
    313                     break;
    314                 default:
    315                     /* not yet supported */
    316                     break;
    317                 }
    318         }
    319     }
    320 }
    321 
    322 
    323 
    324 /*******************************************************************************
    325 **
    326 ** Function         bta_sys_hw_enable
    327 **
    328 ** Description     this function is called after API enable and HW has been turned on
    329 **
    330 **
    331 ** Returns          success or failure
    332 **
    333 *******************************************************************************/
    334 
    335 void bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg )
    336 {
    337     if ((!bta_sys_cb.sys_hw_module_active) && (bta_sys_cb.state != BTA_SYS_HW_ON))
    338     {
    339         /* register which HW module was turned on */
    340         bta_sys_cb.sys_hw_module_active |=  ((UINT32)1 << p_sys_hw_msg->hw_module );
    341 
    342         /* use call-out to power-up HW */
    343         bta_sys_hw_co_enable(p_sys_hw_msg->hw_module);
    344     }
    345     else
    346     {
    347         /* register which HW module was turned on */
    348         bta_sys_cb.sys_hw_module_active |=  ((UINT32)1 << p_sys_hw_msg->hw_module );
    349 
    350         /* HW already in use, so directly notify the caller */
    351         if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]!= NULL )
    352             bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ](  BTA_SYS_HW_ON_EVT   );
    353     }
    354 
    355     APPL_TRACE_EVENT ("bta_sys_hw_api_enable for %d, active modules 0x%04X",
    356                     p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active);
    357 
    358 }
    359 
    360 /*******************************************************************************
    361 **
    362 ** Function         bta_sys_hw_disable
    363 **
    364 ** Description     if no other module is using the HW, this function will call ( if defined ) a user-macro to turn off the HW
    365 **
    366 **
    367 ** Returns          success or failure
    368 **
    369 *******************************************************************************/
    370 void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg)
    371 {
    372     APPL_TRACE_DEBUG("bta_sys_hw_api_disable for %d, active modules: 0x%04X",
    373         p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active );
    374 
    375     /* make sure the related SW blocks were stopped */
    376     bta_sys_disable( p_sys_hw_msg->hw_module );
    377 
    378 
    379     /* register which module we turn off */
    380     bta_sys_cb.sys_hw_module_active &=  ~((UINT32)1 << p_sys_hw_msg->hw_module );
    381 
    382 
    383     /* if there are still some SW modules using the HW, just provide an answer to the calling */
    384     if( bta_sys_cb.sys_hw_module_active != 0  )
    385     {
    386         /*  if there are still some SW modules using the HW,  directly notify the caller */
    387         if( bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]!= NULL )
    388             bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ](  BTA_SYS_HW_OFF_EVT   );
    389     }
    390     else
    391     {
    392         /* manually update the state of our system */
    393         bta_sys_cb.state = BTA_SYS_HW_STOPPING;
    394         /* and use the call-out to disable HW */
    395         bta_sys_hw_co_disable(p_sys_hw_msg->hw_module);
    396     }
    397 
    398 }
    399 
    400 
    401 /*******************************************************************************
    402 **
    403 ** Function         bta_sys_hw_event_enabled
    404 **
    405 ** Description
    406 **
    407 **
    408 ** Returns          success or failure
    409 **
    410 *******************************************************************************/
    411 void bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
    412 {
    413     APPL_TRACE_EVENT("bta_sys_hw_evt_enabled for %i", p_sys_hw_msg->hw_module);
    414 
    415 #if ( defined BTM_AUTOMATIC_HCI_RESET && BTM_AUTOMATIC_HCI_RESET == TRUE )
    416     /* If device is already up, send a fake "BTM DEVICE UP" using BTA SYS state machine */
    417     /* If we are in the middle device initialization, BTM_DEVICE_UP will be issued      */
    418     /* by BTM once initialization is done.                                              */
    419     if (BTA_DmIsDeviceUp())
    420     {
    421         bta_sys_hw_btm_cback (BTM_DEV_STATUS_UP);
    422     }
    423 #else
    424 
    425     /* if HCI reset was not sent during stack start-up */
    426     BTM_DeviceReset( NULL );
    427 
    428 #endif
    429 }
    430 
    431 
    432 /*******************************************************************************
    433 **
    434 ** Function         bta_sys_hw_event_disabled
    435 **
    436 ** Description
    437 **
    438 **
    439 ** Returns          success or failure
    440 **
    441 *******************************************************************************/
    442 void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
    443 {
    444     UINT8 hw_module_index;
    445 
    446     APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X", p_sys_hw_msg->hw_module);
    447 
    448     for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++)
    449     {
    450         if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
    451             bta_sys_cb.sys_hw_cback[hw_module_index] (BTA_SYS_HW_OFF_EVT);
    452     }
    453 }
    454 
    455 /*******************************************************************************
    456 **
    457 ** Function         bta_sys_hw_event_stack_enabled
    458 **
    459 ** Description     we receive this event once the SW side is ready ( stack, FW download,... ),
    460 **                       i.e. we can really start using the device. So notify the app.
    461 **
    462 ** Returns          success or failure
    463 **
    464 *******************************************************************************/
    465 void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
    466 {
    467     UINT8 hw_module_index;
    468     UNUSED(p_sys_hw_msg);
    469 
    470     APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers");
    471 
    472     for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++ )
    473     {
    474         if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
    475             bta_sys_cb.sys_hw_cback[hw_module_index] (BTA_SYS_HW_ON_EVT);
    476     }
    477 }
    478 
    479 
    480 
    481 
    482 /*******************************************************************************
    483 **
    484 ** Function         bta_sys_event
    485 **
    486 ** Description      BTA event handler; called from task event handler.
    487 **
    488 **
    489 ** Returns          void
    490 **
    491 *******************************************************************************/
    492 BTA_API void bta_sys_event(BT_HDR *p_msg)
    493 {
    494     UINT8       id;
    495     BOOLEAN     freebuf = TRUE;
    496 
    497     APPL_TRACE_EVENT("BTA got event 0x%x", p_msg->event);
    498 
    499     /* get subsystem id from event */
    500     id = (UINT8) (p_msg->event >> 8);
    501 
    502     /* verify id and call subsystem event handler */
    503     if ((id < BTA_ID_MAX) && (bta_sys_cb.reg[id] != NULL))
    504     {
    505         freebuf = (*bta_sys_cb.reg[id]->evt_hdlr)(p_msg);
    506     }
    507     else
    508     {
    509         APPL_TRACE_WARNING("BTA got unregistered event id %d", id);
    510     }
    511 
    512     if (freebuf)
    513     {
    514         GKI_freebuf(p_msg);
    515     }
    516 
    517 }
    518 
    519 /*******************************************************************************
    520 **
    521 ** Function         bta_sys_timer_update
    522 **
    523 ** Description      Update the BTA timer list and handle expired timers.
    524 **
    525 ** Returns          void
    526 **
    527 *******************************************************************************/
    528 BTA_API void bta_sys_timer_update(void)
    529 {
    530     if (!bta_sys_cb.timers_disabled)
    531     {
    532         ptim_timer_update(&bta_sys_cb.ptim_cb);
    533     }
    534 }
    535 
    536 /*******************************************************************************
    537 **
    538 ** Function         bta_sys_register
    539 **
    540 ** Description      Called by other BTA subsystems to register their event
    541 **                  handler.
    542 **
    543 **
    544 ** Returns          void
    545 **
    546 *******************************************************************************/
    547 void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg)
    548 {
    549     bta_sys_cb.reg[id] = (tBTA_SYS_REG *) p_reg;
    550     bta_sys_cb.is_reg[id] = TRUE;
    551 }
    552 
    553 /*******************************************************************************
    554 **
    555 ** Function         bta_sys_deregister
    556 **
    557 ** Description      Called by other BTA subsystems to de-register
    558 **                  handler.
    559 **
    560 **
    561 ** Returns          void
    562 **
    563 *******************************************************************************/
    564 void bta_sys_deregister(UINT8 id)
    565 {
    566     bta_sys_cb.is_reg[id] = FALSE;
    567 }
    568 
    569 /*******************************************************************************
    570 **
    571 ** Function         bta_sys_is_register
    572 **
    573 ** Description      Called by other BTA subsystems to get registeration
    574 **                  status.
    575 **
    576 **
    577 ** Returns          void
    578 **
    579 *******************************************************************************/
    580 BOOLEAN bta_sys_is_register(UINT8 id)
    581 {
    582     return bta_sys_cb.is_reg[id];
    583 }
    584 
    585 /*******************************************************************************
    586 **
    587 ** Function         bta_sys_sendmsg
    588 **
    589 ** Description      Send a GKI message to BTA.  This function is designed to
    590 **                  optimize sending of messages to BTA.  It is called by BTA
    591 **                  API functions and call-in functions.
    592 **
    593 **
    594 ** Returns          void
    595 **
    596 *******************************************************************************/
    597 void bta_sys_sendmsg(void *p_msg)
    598 {
    599     GKI_send_msg(bta_sys_cb.task_id, p_bta_sys_cfg->mbox, p_msg);
    600 }
    601 
    602 /*******************************************************************************
    603 **
    604 ** Function         bta_sys_start_timer
    605 **
    606 ** Description      Start a protocol timer for the specified amount
    607 **                  of time in milliseconds.
    608 **
    609 ** Returns          void
    610 **
    611 *******************************************************************************/
    612 void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout)
    613 {
    614     ptim_start_timer(&bta_sys_cb.ptim_cb, p_tle, type, timeout);
    615 }
    616 
    617 /*******************************************************************************
    618 **
    619 ** Function         bta_sys_stop_timer
    620 **
    621 ** Description      Stop a BTA timer.
    622 **
    623 ** Returns          void
    624 **
    625 *******************************************************************************/
    626 void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle)
    627 {
    628     ptim_stop_timer(&bta_sys_cb.ptim_cb, p_tle);
    629 }
    630 
    631 /*******************************************************************************
    632 **
    633 ** Function         bta_sys_disable
    634 **
    635 ** Description      For each registered subsystem execute its disable function.
    636 **
    637 ** Returns          void
    638 **
    639 *******************************************************************************/
    640 void bta_sys_disable(tBTA_SYS_HW_MODULE module)
    641 {
    642     int bta_id = 0;
    643     int bta_id_max = 0;
    644 
    645     APPL_TRACE_DEBUG("bta_sys_disable: module %i", module);
    646 
    647     switch( module )
    648     {
    649         case BTA_SYS_HW_BLUETOOTH:
    650             bta_id = BTA_ID_DM;
    651             bta_id_max = BTA_ID_BLUETOOTH_MAX;
    652             break;
    653         case BTA_SYS_HW_FMRX:
    654             bta_id = BTA_ID_FM;
    655             bta_id_max = BTA_ID_FM;
    656             break;
    657         case BTA_SYS_HW_FMTX:
    658             bta_id = BTA_ID_FMTX;
    659             bta_id_max = BTA_ID_FMTX;
    660             break;
    661         case BTA_SYS_HW_GPS:
    662             bta_id = BTA_ID_GPS;
    663             bta_id_max = BTA_ID_GPS;
    664             break;
    665         default:
    666             APPL_TRACE_WARNING("bta_sys_disable: unkown module");
    667             return;
    668     }
    669 
    670     for ( ; bta_id <= bta_id_max; bta_id++)
    671     {
    672         if (bta_sys_cb.reg[bta_id] != NULL)
    673         {
    674             if (bta_sys_cb.is_reg[bta_id] == TRUE  &&  bta_sys_cb.reg[bta_id]->disable != NULL)
    675             {
    676                 (*bta_sys_cb.reg[bta_id]->disable)();
    677             }
    678         }
    679     }
    680 }
    681 
    682 /*******************************************************************************
    683 **
    684 ** Function         bta_sys_disable_timers
    685 **
    686 ** Description      Disable sys timer event handling
    687 **
    688 ** Returns          void
    689 **
    690 *******************************************************************************/
    691 void bta_sys_disable_timers(void)
    692 {
    693     bta_sys_cb.timers_disabled = TRUE;
    694 }
    695 
    696 /*******************************************************************************
    697 **
    698 ** Function         bta_sys_set_trace_level
    699 **
    700 ** Description      Set trace level for BTA
    701 **
    702 ** Returns          void
    703 **
    704 *******************************************************************************/
    705 void bta_sys_set_trace_level(UINT8 level)
    706 {
    707     appl_trace_level = level;
    708 }
    709 
    710 /*******************************************************************************
    711 **
    712 ** Function         bta_sys_get_sys_features
    713 **
    714 ** Description      Returns sys_features to other BTA modules.
    715 **
    716 ** Returns          sys_features
    717 **
    718 *******************************************************************************/
    719 UINT16 bta_sys_get_sys_features (void)
    720 {
    721     return bta_sys_cb.sys_features;
    722 }
    723 
    724 
    725