OSDN Git Service

Fix a security issue in sdp_server.cc am: d7573f4fa9 am: 97abd549aa
[android-x86/system-bt.git] / bta / sys / bta_sys_main.cc
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 #define LOG_TAG "bt_bta_sys_main"
26
27 #include <base/bind.h>
28 #include <base/logging.h>
29 #include <base/threading/thread.h>
30 #include <pthread.h>
31 #include <string.h>
32
33 #include "bt_common.h"
34 #include "bta_api.h"
35 #include "bta_sys.h"
36 #include "bta_sys_int.h"
37 #include "btm_api.h"
38 #include "btu.h"
39 #include "osi/include/alarm.h"
40 #include "osi/include/fixed_queue.h"
41 #include "osi/include/log.h"
42 #include "osi/include/osi.h"
43 #include "osi/include/thread.h"
44 #include "utl.h"
45
46 #if (defined BTA_AR_INCLUDED) && (BTA_AR_INCLUDED == true)
47 #include "bta_ar_api.h"
48 #endif
49
50 /* system manager control block definition */
51 tBTA_SYS_CB bta_sys_cb;
52
53 extern thread_t* bt_workqueue_thread;
54
55 /* trace level */
56 /* TODO Hard-coded trace levels -  Needs to be configurable */
57 uint8_t appl_trace_level = BT_TRACE_LEVEL_WARNING;  // APPL_INITIAL_TRACE_LEVEL;
58 uint8_t btif_trace_level = BT_TRACE_LEVEL_WARNING;
59
60 static const tBTA_SYS_REG bta_sys_hw_reg = {bta_sys_sm_execute, NULL};
61
62 /* type for action functions */
63 typedef void (*tBTA_SYS_ACTION)(tBTA_SYS_HW_MSG* p_data);
64
65 /* action function list */
66 const tBTA_SYS_ACTION bta_sys_action[] = {
67     /* device manager local device API events - cf bta_sys.h for events */
68     bta_sys_hw_api_enable,        /* 0  BTA_SYS_HW_API_ENABLE_EVT    */
69     bta_sys_hw_evt_enabled,       /* 1  BTA_SYS_HW_EVT_ENABLED_EVT */
70     bta_sys_hw_evt_stack_enabled, /* 2  BTA_SYS_HW_EVT_STACK_ENABLED_EVT */
71     bta_sys_hw_api_disable,       /* 3  BTA_SYS_HW_API_DISABLE_EVT     */
72     bta_sys_hw_evt_disabled,      /* 4  BTA_SYS_HW_EVT_DISABLED_EVT  */
73     bta_sys_hw_error              /* 5   BTA_SYS_HW_ERROR_EVT  */
74 };
75
76 /* state machine action enumeration list */
77 enum {
78   /* device manager local device API events */
79   BTA_SYS_HW_API_ENABLE,
80   BTA_SYS_HW_EVT_ENABLED,
81   BTA_SYS_HW_EVT_STACK_ENABLED,
82   BTA_SYS_HW_API_DISABLE,
83   BTA_SYS_HW_EVT_DISABLED,
84   BTA_SYS_HW_ERROR
85 };
86
87 #define BTA_SYS_NUM_ACTIONS (BTA_SYS_MAX_EVT & 0x00ff)
88 #define BTA_SYS_IGNORE BTA_SYS_NUM_ACTIONS
89
90 /* state table information */
91 #define BTA_SYS_ACTIONS 2    /* number of actions */
92 #define BTA_SYS_NEXT_STATE 2 /* position of next state */
93 #define BTA_SYS_NUM_COLS 3   /* number of columns in state tables */
94
95 /* state table for OFF state */
96 const uint8_t bta_sys_hw_off[][BTA_SYS_NUM_COLS] = {
97     /* Event                    Action 1               Action 2
98        Next State */
99     /* API_ENABLE    */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE,
100                          BTA_SYS_HW_STARTING},
101     /* EVT_ENABLED   */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
102     /* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
103     /* API_DISABLE   */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE,
104                          BTA_SYS_HW_OFF},
105     /* EVT_DISABLED  */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
106     /* EVT_ERROR     */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF}};
107
108 const uint8_t bta_sys_hw_starting[][BTA_SYS_NUM_COLS] = {
109     /* Event                    Action 1                   Action 2
110        Next State */
111     /* API_ENABLE    */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE,
112                          BTA_SYS_HW_STARTING}, /* wait for completion event */
113     /* EVT_ENABLED   */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE,
114                          BTA_SYS_HW_STARTING},
115     /* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_IGNORE,
116                          BTA_SYS_HW_ON},
117     /* API_DISABLE   */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE,
118                          BTA_SYS_HW_STOPPING}, /* successive disable/enable:
119                                                   change state wait for
120                                                   completion to disable */
121     /* EVT_DISABLED  */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_HW_API_ENABLE,
122                          BTA_SYS_HW_STARTING}, /* successive enable/disable:
123                                                   notify, then restart HW */
124     /* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}};
125
126 const uint8_t bta_sys_hw_on[][BTA_SYS_NUM_COLS] = {
127     /* Event                    Action 1                   Action 2
128        Next State */
129     /* API_ENABLE    */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
130     /* EVT_ENABLED   */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
131     /* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
132     /* API_DISABLE   */
133     {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE,
134      BTA_SYS_HW_ON}, /* don't change the state here, as some
135                         other modules might be active */
136     /* EVT_DISABLED */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
137     /* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}};
138
139 const uint8_t bta_sys_hw_stopping[][BTA_SYS_NUM_COLS] = {
140     /* Event                    Action 1                   Action 2
141        Next State */
142     /* API_ENABLE    */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE,
143                          BTA_SYS_HW_STARTING}, /* change state, and wait for
144                                                   completion event to enable */
145     /* EVT_ENABLED   */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE,
146                          BTA_SYS_HW_STOPPING}, /* successive enable/disable:
147                                                   finish the enable before
148                                                   disabling */
149     /* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_HW_API_DISABLE,
150                          BTA_SYS_HW_STOPPING}, /* successive enable/disable:
151                                                   notify, then stop */
152     /* API_DISABLE   */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE,
153                          BTA_SYS_HW_STOPPING}, /* wait for completion event */
154     /* EVT_DISABLED  */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE,
155                          BTA_SYS_HW_OFF},
156     /* EVT_ERROR     */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE,
157                          BTA_SYS_HW_STOPPING}};
158
159 typedef const uint8_t (*tBTA_SYS_ST_TBL)[BTA_SYS_NUM_COLS];
160
161 /* state table */
162 const tBTA_SYS_ST_TBL bta_sys_st_tbl[] = {bta_sys_hw_off, bta_sys_hw_starting,
163                                           bta_sys_hw_on, bta_sys_hw_stopping};
164
165 /*******************************************************************************
166  *
167  * Function         bta_sys_init
168  *
169  * Description      BTA initialization; called from task initialization.
170  *
171  *
172  * Returns          void
173  *
174  ******************************************************************************/
175 void bta_sys_init(void) {
176   memset(&bta_sys_cb, 0, sizeof(tBTA_SYS_CB));
177
178   appl_trace_level = APPL_INITIAL_TRACE_LEVEL;
179
180   /* register BTA SYS message handler */
181   bta_sys_register(BTA_ID_SYS, &bta_sys_hw_reg);
182
183   /* register for BTM notifications */
184   BTM_RegisterForDeviceStatusNotif((tBTM_DEV_STATUS_CB*)&bta_sys_hw_btm_cback);
185
186 #if (defined BTA_AR_INCLUDED) && (BTA_AR_INCLUDED == true)
187   bta_ar_init();
188 #endif
189 }
190
191 void bta_sys_free(void) {
192 }
193
194 /*******************************************************************************
195  *
196  * Function         bta_dm_sm_execute
197  *
198  * Description      State machine event handling function for DM
199  *
200  *
201  * Returns          void
202  *
203  ******************************************************************************/
204 bool bta_sys_sm_execute(BT_HDR* p_msg) {
205   bool freebuf = true;
206   tBTA_SYS_ST_TBL state_table;
207   uint8_t action;
208   int i;
209
210   APPL_TRACE_EVENT("bta_sys_sm_execute state:%d, event:0x%x", bta_sys_cb.state,
211                    p_msg->event);
212
213   /* look up the state table for the current state */
214   state_table = bta_sys_st_tbl[bta_sys_cb.state];
215   /* update state */
216   bta_sys_cb.state = state_table[p_msg->event & 0x00ff][BTA_SYS_NEXT_STATE];
217
218   /* execute action functions */
219   for (i = 0; i < BTA_SYS_ACTIONS; i++) {
220     action = state_table[p_msg->event & 0x00ff][i];
221     if (action != BTA_SYS_IGNORE) {
222       (*bta_sys_action[action])((tBTA_SYS_HW_MSG*)p_msg);
223     } else {
224       break;
225     }
226   }
227   return freebuf;
228 }
229
230 void bta_sys_hw_register(tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK* cback) {
231   bta_sys_cb.sys_hw_cback[module] = cback;
232 }
233
234 void bta_sys_hw_unregister(tBTA_SYS_HW_MODULE module) {
235   bta_sys_cb.sys_hw_cback[module] = NULL;
236 }
237
238 /*******************************************************************************
239  *
240  * Function         bta_sys_hw_btm_cback
241  *
242  * Description     This function is registered by BTA SYS to BTM in order to get
243  *                 status notifications
244  *
245  *
246  * Returns
247  *
248  ******************************************************************************/
249 void bta_sys_hw_btm_cback(tBTM_DEV_STATUS status) {
250   tBTA_SYS_HW_MSG* sys_event =
251       (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG));
252
253   APPL_TRACE_DEBUG("%s was called with parameter: %i", __func__, status);
254
255   /* send a message to BTA SYS */
256   if (status == BTM_DEV_STATUS_UP) {
257     sys_event->hdr.event = BTA_SYS_EVT_STACK_ENABLED_EVT;
258   } else if (status == BTM_DEV_STATUS_DOWN) {
259     sys_event->hdr.event = BTA_SYS_ERROR_EVT;
260   } else {
261     /* BTM_DEV_STATUS_CMD_TOUT is ignored for now. */
262     osi_free_and_reset((void**)&sys_event);
263   }
264
265   if (sys_event) bta_sys_sendmsg(sys_event);
266 }
267
268 /*******************************************************************************
269  *
270  * Function         bta_sys_hw_error
271  *
272  * Description     In case the HW device stops answering... Try to turn it off,
273  *                 then re-enable all
274  *                      previously active SW modules.
275  *
276  * Returns          success or failure
277  *
278  ******************************************************************************/
279 void bta_sys_hw_error(UNUSED_ATTR tBTA_SYS_HW_MSG* p_sys_hw_msg) {
280   uint8_t module_index;
281
282   APPL_TRACE_DEBUG("%s", __func__);
283
284   for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES;
285        module_index++) {
286     if (bta_sys_cb.sys_hw_module_active & ((uint32_t)1 << module_index)) {
287       switch (module_index) {
288         case BTA_SYS_HW_BLUETOOTH:
289           /* Send BTA_SYS_HW_ERROR_EVT to DM */
290           if (bta_sys_cb.sys_hw_cback[module_index] != NULL)
291             bta_sys_cb.sys_hw_cback[module_index](BTA_SYS_HW_ERROR_EVT);
292           break;
293         default:
294           /* not yet supported */
295           break;
296       }
297     }
298   }
299 }
300
301 /*******************************************************************************
302  *
303  * Function         bta_sys_hw_enable
304  *
305  * Description     this function is called after API enable and HW has been
306  *                 turned on
307  *
308  *
309  * Returns          success or failure
310  *
311  ******************************************************************************/
312
313 void bta_sys_hw_api_enable(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
314   if ((!bta_sys_cb.sys_hw_module_active) &&
315       (bta_sys_cb.state != BTA_SYS_HW_ON)) {
316     /* register which HW module was turned on */
317     bta_sys_cb.sys_hw_module_active |= ((uint32_t)1 << p_sys_hw_msg->hw_module);
318
319     tBTA_SYS_HW_MSG* p_msg =
320         (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG));
321     p_msg->hdr.event = BTA_SYS_EVT_ENABLED_EVT;
322     p_msg->hw_module = p_sys_hw_msg->hw_module;
323
324     bta_sys_sendmsg(p_msg);
325   } else {
326     /* register which HW module was turned on */
327     bta_sys_cb.sys_hw_module_active |= ((uint32_t)1 << p_sys_hw_msg->hw_module);
328
329     /* HW already in use, so directly notify the caller */
330     if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module] != NULL)
331       bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module](BTA_SYS_HW_ON_EVT);
332   }
333
334   APPL_TRACE_EVENT("bta_sys_hw_api_enable for %d, active modules 0x%04X",
335                    p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active);
336 }
337
338 /*******************************************************************************
339  *
340  * Function         bta_sys_hw_disable
341  *
342  * Description     if no other module is using the HW, this function will call
343  *                 (if defined) a user-macro to turn off the HW
344  *
345  *
346  * Returns          success or failure
347  *
348  ******************************************************************************/
349 void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
350   APPL_TRACE_DEBUG("bta_sys_hw_api_disable for %d, active modules: 0x%04X",
351                    p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active);
352
353   /* make sure the related SW blocks were stopped */
354   bta_sys_disable(p_sys_hw_msg->hw_module);
355
356   /* register which module we turn off */
357   bta_sys_cb.sys_hw_module_active &= ~((uint32_t)1 << p_sys_hw_msg->hw_module);
358
359   /* if there are still some SW modules using the HW, just provide an answer to
360    * the calling */
361   if (bta_sys_cb.sys_hw_module_active != 0) {
362     /*  if there are still some SW modules using the HW,  directly notify the
363      * caller */
364     if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module] != NULL)
365       bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module](BTA_SYS_HW_OFF_EVT);
366   } else {
367     /* manually update the state of our system */
368     bta_sys_cb.state = BTA_SYS_HW_STOPPING;
369
370     tBTA_SYS_HW_MSG* p_msg =
371         (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG));
372     p_msg->hdr.event = BTA_SYS_EVT_DISABLED_EVT;
373     p_msg->hw_module = p_sys_hw_msg->hw_module;
374
375     bta_sys_sendmsg(p_msg);
376   }
377 }
378
379 /*******************************************************************************
380  *
381  * Function         bta_sys_hw_event_enabled
382  *
383  * Description
384  *
385  *
386  * Returns          success or failure
387  *
388  ******************************************************************************/
389 void bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
390   APPL_TRACE_EVENT("bta_sys_hw_evt_enabled for %i", p_sys_hw_msg->hw_module);
391   BTM_DeviceReset(NULL);
392 }
393
394 /*******************************************************************************
395  *
396  * Function         bta_sys_hw_event_disabled
397  *
398  * Description
399  *
400  *
401  * Returns          success or failure
402  *
403  ******************************************************************************/
404 void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG* p_sys_hw_msg) {
405   uint8_t hw_module_index;
406
407   APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X",
408                    p_sys_hw_msg->hw_module);
409
410   for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES;
411        hw_module_index++) {
412     if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
413       bta_sys_cb.sys_hw_cback[hw_module_index](BTA_SYS_HW_OFF_EVT);
414   }
415 }
416
417 /*******************************************************************************
418  *
419  * Function         bta_sys_hw_event_stack_enabled
420  *
421  * Description     we receive this event once the SW side is ready (stack, FW
422  *                 download,... ), i.e. we can really start using the device. So
423  *                 notify the app.
424  *
425  * Returns          success or failure
426  *
427  ******************************************************************************/
428 void bta_sys_hw_evt_stack_enabled(UNUSED_ATTR tBTA_SYS_HW_MSG* p_sys_hw_msg) {
429   uint8_t hw_module_index;
430
431   APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers");
432
433   for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES;
434        hw_module_index++) {
435     if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
436       bta_sys_cb.sys_hw_cback[hw_module_index](BTA_SYS_HW_ON_EVT);
437   }
438 }
439
440 /*******************************************************************************
441  *
442  * Function         bta_sys_event
443  *
444  * Description      BTA event handler; called from task event handler.
445  *
446  *
447  * Returns          void
448  *
449  ******************************************************************************/
450 void bta_sys_event(BT_HDR* p_msg) {
451   uint8_t id;
452   bool freebuf = true;
453
454   APPL_TRACE_EVENT("%s: Event 0x%x", __func__, p_msg->event);
455
456   /* get subsystem id from event */
457   id = (uint8_t)(p_msg->event >> 8);
458
459   /* verify id and call subsystem event handler */
460   if ((id < BTA_ID_MAX) && (bta_sys_cb.reg[id] != NULL)) {
461     freebuf = (*bta_sys_cb.reg[id]->evt_hdlr)(p_msg);
462   } else {
463     APPL_TRACE_WARNING("%s: Received unregistered event id %d", __func__, id);
464   }
465
466   if (freebuf) {
467     osi_free(p_msg);
468   }
469 }
470
471 /*******************************************************************************
472  *
473  * Function         bta_sys_register
474  *
475  * Description      Called by other BTA subsystems to register their event
476  *                  handler.
477  *
478  *
479  * Returns          void
480  *
481  ******************************************************************************/
482 void bta_sys_register(uint8_t id, const tBTA_SYS_REG* p_reg) {
483   bta_sys_cb.reg[id] = (tBTA_SYS_REG*)p_reg;
484   bta_sys_cb.is_reg[id] = true;
485 }
486
487 /*******************************************************************************
488  *
489  * Function         bta_sys_deregister
490  *
491  * Description      Called by other BTA subsystems to de-register
492  *                  handler.
493  *
494  *
495  * Returns          void
496  *
497  ******************************************************************************/
498 void bta_sys_deregister(uint8_t id) { bta_sys_cb.is_reg[id] = false; }
499
500 /*******************************************************************************
501  *
502  * Function         bta_sys_is_register
503  *
504  * Description      Called by other BTA subsystems to get registeration
505  *                  status.
506  *
507  *
508  * Returns          void
509  *
510  ******************************************************************************/
511 bool bta_sys_is_register(uint8_t id) { return bta_sys_cb.is_reg[id]; }
512
513 /*******************************************************************************
514  *
515  * Function         bta_sys_sendmsg
516  *
517  * Description      Send a GKI message to BTA.  This function is designed to
518  *                  optimize sending of messages to BTA.  It is called by BTA
519  *                  API functions and call-in functions.
520  *
521  *                  TODO (apanicke): Add location object as parameter for easier
522  *                  future debugging when doing alarm refactor
523  *
524  *
525  * Returns          void
526  *
527  ******************************************************************************/
528 void bta_sys_sendmsg(void* p_msg) {
529   base::MessageLoop* bta_message_loop = get_message_loop();
530
531   if (!bta_message_loop || !bta_message_loop->task_runner().get()) {
532     APPL_TRACE_ERROR("%s: MessageLooper not initialized", __func__);
533     return;
534   }
535
536   bta_message_loop->task_runner()->PostTask(
537       FROM_HERE, base::Bind(&bta_sys_event, static_cast<BT_HDR*>(p_msg)));
538 }
539
540 /*******************************************************************************
541  *
542  * Function         do_in_bta_thread
543  *
544  * Description      Post a closure to be ran in the bta thread
545  *
546  * Returns          void
547  *
548  ******************************************************************************/
549 void do_in_bta_thread(const tracked_objects::Location& from_here,
550                       const base::Closure& task) {
551   base::MessageLoop* bta_message_loop = get_message_loop();
552
553   if (!bta_message_loop || !bta_message_loop->task_runner().get()) {
554     APPL_TRACE_ERROR("%s: MessageLooper not initialized", __func__);
555     return;
556   }
557
558   bta_message_loop->task_runner()->PostTask(from_here, task);
559 }
560
561 /*******************************************************************************
562  *
563  * Function         bta_sys_start_timer
564  *
565  * Description      Start a protocol timer for the specified amount
566  *                  of time in milliseconds.
567  *
568  * Returns          void
569  *
570  ******************************************************************************/
571 void bta_sys_start_timer(alarm_t* alarm, period_ms_t interval, uint16_t event,
572                          uint16_t layer_specific) {
573   BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
574
575   p_buf->event = event;
576   p_buf->layer_specific = layer_specific;
577
578   alarm_set_on_mloop(alarm, interval, bta_sys_sendmsg, p_buf);
579 }
580
581 /*******************************************************************************
582  *
583  * Function         bta_sys_disable
584  *
585  * Description      For each registered subsystem execute its disable function.
586  *
587  * Returns          void
588  *
589  ******************************************************************************/
590 void bta_sys_disable(tBTA_SYS_HW_MODULE module) {
591   int bta_id = 0;
592   int bta_id_max = 0;
593
594   APPL_TRACE_DEBUG("bta_sys_disable: module %i", module);
595
596   switch (module) {
597     case BTA_SYS_HW_BLUETOOTH:
598       bta_id = BTA_ID_DM;
599       bta_id_max = BTA_ID_BLUETOOTH_MAX;
600       break;
601     default:
602       APPL_TRACE_WARNING("bta_sys_disable: unkown module");
603       return;
604   }
605
606   for (; bta_id <= bta_id_max; bta_id++) {
607     if (bta_sys_cb.reg[bta_id] != NULL) {
608       if (bta_sys_cb.is_reg[bta_id] == true &&
609           bta_sys_cb.reg[bta_id]->disable != NULL) {
610         (*bta_sys_cb.reg[bta_id]->disable)();
611       }
612     }
613   }
614 }
615
616 /*******************************************************************************
617  *
618  * Function         bta_sys_set_trace_level
619  *
620  * Description      Set trace level for BTA
621  *
622  * Returns          void
623  *
624  ******************************************************************************/
625 void bta_sys_set_trace_level(uint8_t level) { appl_trace_level = level; }
626
627 /*******************************************************************************
628  *
629  * Function         bta_sys_get_sys_features
630  *
631  * Description      Returns sys_features to other BTA modules.
632  *
633  * Returns          sys_features
634  *
635  ******************************************************************************/
636 uint16_t bta_sys_get_sys_features(void) { return bta_sys_cb.sys_features; }