btm_main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /*******************************************************************************
  37. **
  38. ** Function btm_init
  39. **
  40. ** Description This function is called at BTM startup to allocate the
  41. ** control block (if using dynamic memory), and initializes the
  42. ** tracing level. It then initializes the various components of
  43. ** btm.
  44. **
  45. ** Returns void
  46. **
  47. *******************************************************************************/
  48. void btm_init (void)
  49. {
  50. #if BTM_DYNAMIC_MEMORY
  51. btm_cb_ptr = (tBTM_CB *)osi_malloc(sizeof(tBTM_CB));
  52. #endif /* #if BTM_DYNAMIC_MEMORY */
  53. /* All fields are cleared; nonzero fields are reinitialized in appropriate function */
  54. memset(&btm_cb, 0, sizeof(tBTM_CB));
  55. btm_cb.page_queue = fixed_queue_new(QUEUE_SIZE_MAX);
  56. btm_cb.sec_pending_q = fixed_queue_new(QUEUE_SIZE_MAX);
  57. #if defined(BTM_INITIAL_TRACE_LEVEL)
  58. btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL;
  59. #else
  60. btm_cb.trace_level = BT_TRACE_LEVEL_NONE;
  61. #endif
  62. /* Initialize BTM component structures */
  63. btm_inq_db_init(); /* Inquiry Database and Structures */
  64. btm_acl_init(); /* ACL Database and Structures */
  65. #if (SMP_INCLUDED == TRUE)
  66. btm_sec_init(BTM_SEC_MODE_SP); /* Security Manager Database and Structures */
  67. #endif ///SMP_INCLUDED == TRUE
  68. #if BTM_SCO_INCLUDED == TRUE
  69. btm_sco_init(); /* SCO Database and Structures (If included) */
  70. #endif
  71. btm_dev_init(); /* Device Manager Structures & HCI_Reset */
  72. #if BLE_INCLUDED == TRUE
  73. btm_ble_lock_init();
  74. btm_ble_sem_init();
  75. #endif
  76. }
  77. /*******************************************************************************
  78. **
  79. ** Function btm_free
  80. **
  81. ** Description This function is called at btu core free the fixed queue
  82. **
  83. ** Returns void
  84. **
  85. *******************************************************************************/
  86. void btm_free(void)
  87. {
  88. fixed_queue_free(btm_cb.page_queue, osi_free_func);
  89. fixed_queue_free(btm_cb.sec_pending_q, osi_free_func);
  90. #if BTM_DYNAMIC_MEMORY
  91. FREE_AND_RESET(btm_cb_ptr);
  92. #endif
  93. #if BLE_INCLUDED == TRUE
  94. btm_ble_lock_free();
  95. btm_ble_sem_free();
  96. #endif
  97. }