btm_main.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2002-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. * This file contains the definition of the btm control block when
  21. * BTM_DYNAMIC_MEMORY is used.
  22. *
  23. ******************************************************************************/
  24. #include "stack/bt_types.h"
  25. #include "common/bt_target.h"
  26. #include <string.h>
  27. #include "btm_int.h"
  28. #include "osi/allocator.h"
  29. /* Global BTM control block structure
  30. */
  31. #if BTM_DYNAMIC_MEMORY == FALSE
  32. tBTM_CB btm_cb;
  33. #else
  34. tBTM_CB *btm_cb_ptr;
  35. #endif
  36. #if (BLE_50_FEATURE_SUPPORT == TRUE)
  37. extern void btm_ble_extendadvcb_init(void);
  38. extern void btm_ble_advrecod_init(void);
  39. #endif
  40. /*******************************************************************************
  41. **
  42. ** Function btm_init
  43. **
  44. ** Description This function is called at BTM startup to allocate the
  45. ** control block (if using dynamic memory), and initializes the
  46. ** tracing level. It then initializes the various components of
  47. ** btm.
  48. **
  49. ** Returns void
  50. **
  51. *******************************************************************************/
  52. void btm_init (void)
  53. {
  54. #if BTM_DYNAMIC_MEMORY
  55. btm_cb_ptr = (tBTM_CB *)osi_malloc(sizeof(tBTM_CB));
  56. #endif /* #if BTM_DYNAMIC_MEMORY */
  57. /* All fields are cleared; nonzero fields are reinitialized in appropriate function */
  58. memset(&btm_cb, 0, sizeof(tBTM_CB));
  59. btm_cb.page_queue = fixed_queue_new(QUEUE_SIZE_MAX);
  60. btm_cb.sec_pending_q = fixed_queue_new(QUEUE_SIZE_MAX);
  61. #if defined(BTM_INITIAL_TRACE_LEVEL)
  62. btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL;
  63. #else
  64. btm_cb.trace_level = BT_TRACE_LEVEL_NONE;
  65. #endif
  66. /* Initialize BTM component structures */
  67. btm_inq_db_init(); /* Inquiry Database and Structures */
  68. btm_acl_init(); /* ACL Database and Structures */
  69. #if (SMP_INCLUDED == TRUE)
  70. btm_sec_init(BTM_SEC_MODE_SP); /* Security Manager Database and Structures */
  71. #endif ///SMP_INCLUDED == TRUE
  72. #if BTM_SCO_INCLUDED == TRUE
  73. btm_sco_init(); /* SCO Database and Structures (If included) */
  74. #endif
  75. btm_dev_init(); /* Device Manager Structures & HCI_Reset */
  76. #if BLE_INCLUDED == TRUE
  77. btm_ble_lock_init();
  78. btm_ble_sem_init();
  79. #endif
  80. btm_sec_dev_init();
  81. #if (BLE_50_FEATURE_SUPPORT == TRUE)
  82. btm_ble_extendadvcb_init();
  83. btm_ble_advrecod_init();
  84. #endif
  85. }
  86. /*******************************************************************************
  87. **
  88. ** Function btm_free
  89. **
  90. ** Description This function is called at btu core free the fixed queue
  91. **
  92. ** Returns void
  93. **
  94. *******************************************************************************/
  95. void btm_free(void)
  96. {
  97. fixed_queue_free(btm_cb.page_queue, osi_free_func);
  98. fixed_queue_free(btm_cb.sec_pending_q, osi_free_func);
  99. btm_acl_free();
  100. btm_sec_dev_free();
  101. #if BTM_DYNAMIC_MEMORY
  102. FREE_AND_RESET(btm_cb_ptr);
  103. #endif
  104. #if BLE_INCLUDED == TRUE
  105. btm_ble_lock_free();
  106. btm_ble_sem_free();
  107. #endif
  108. }