bte_main.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009-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. * Filename: bte_main.c
  21. *
  22. * Description: Contains BTE core stack initialization and shutdown code
  23. *
  24. ******************************************************************************/
  25. #include "common/bt_defs.h"
  26. #include "common/bt_common_types.h"
  27. #include "common/bte.h"
  28. #include "stack/btu.h"
  29. #include "common/bt_trace.h"
  30. #include "osi/osi.h"
  31. #include "osi/alarm.h"
  32. #include "osi/hash_map.h"
  33. #include "osi/hash_functions.h"
  34. #include "device/controller.h"
  35. #include "hci/hci_layer.h"
  36. #include "bta/bta_api.h"
  37. /*******************************************************************************
  38. ** Constants & Macros
  39. *******************************************************************************/
  40. /******************************************************************************
  41. ** Variables
  42. ******************************************************************************/
  43. /*******************************************************************************
  44. ** Static variables
  45. *******************************************************************************/
  46. static const hci_t *hci;
  47. /*******************************************************************************
  48. ** Static functions
  49. *******************************************************************************/
  50. static void bte_main_disable(void);
  51. static void bte_main_enable(void);
  52. /*******************************************************************************
  53. ** Externs
  54. *******************************************************************************/
  55. bluedroid_init_done_cb_t bluedroid_init_done_cb;
  56. extern void osi_mem_dbg_init(void);
  57. /******************************************************************************
  58. **
  59. ** Function bte_main_boot_entry
  60. **
  61. ** Description BTE MAIN API - Entry point for BTE chip/stack initialization
  62. **
  63. ** Returns None
  64. **
  65. ******************************************************************************/
  66. int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
  67. {
  68. hci = hci_layer_get_interface();
  69. if (!hci) {
  70. APPL_TRACE_ERROR("%s could not get hci layer interface.\n", __func__);
  71. return -2;
  72. }
  73. bluedroid_init_done_cb = cb;
  74. osi_init();
  75. //Enbale HCI
  76. bte_main_enable();
  77. return 0;
  78. }
  79. /******************************************************************************
  80. **
  81. ** Function bte_main_shutdown
  82. **
  83. ** Description BTE MAIN API - Shutdown code for BTE chip/stack
  84. **
  85. ** Returns None
  86. **
  87. ******************************************************************************/
  88. void bte_main_shutdown(void)
  89. {
  90. #if (BLE_INCLUDED == TRUE)
  91. BTA_VendorCleanup();
  92. #endif
  93. bte_main_disable();
  94. osi_deinit();
  95. }
  96. /******************************************************************************
  97. **
  98. ** Function bte_main_enable
  99. **
  100. ** Description BTE MAIN API - Creates all the BTE tasks. Should be called
  101. ** part of the Bluetooth stack enable sequence
  102. **
  103. ** Returns None
  104. **
  105. ******************************************************************************/
  106. static void bte_main_enable(void)
  107. {
  108. APPL_TRACE_DEBUG("Enable HCI\n");
  109. if (hci_start_up()) {
  110. APPL_TRACE_ERROR("Start HCI Host Layer Failure\n");
  111. return;
  112. }
  113. //Now Test Case Not Supported BTU
  114. BTU_StartUp();
  115. }
  116. /******************************************************************************
  117. **
  118. ** Function bte_main_disable
  119. **
  120. ** Description BTE MAIN API - Destroys all the BTE tasks. Should be called
  121. ** part of the Bluetooth stack disable sequence
  122. **
  123. ** Returns None
  124. **
  125. ******************************************************************************/
  126. static void bte_main_disable(void)
  127. {
  128. /*
  129. APPL_TRACE_DEBUG("%s", __FUNCTION__);
  130. module_shut_down(get_module(HCI_MODULE));
  131. module_shut_down(get_module(BTSNOOP_MODULE));
  132. */
  133. hci_shut_down();
  134. BTU_ShutDown();
  135. }
  136. /******************************************************************************
  137. **
  138. ** Function bte_main_postload_cfg
  139. **
  140. ** Description BTE MAIN API - Stack postload configuration
  141. **
  142. ** Returns None
  143. **
  144. ******************************************************************************/
  145. void bte_main_postload_cfg(void)
  146. {
  147. hci->do_postload();
  148. }
  149. #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
  150. /******************************************************************************
  151. **
  152. ** Function bte_main_enable_lpm
  153. **
  154. ** Description BTE MAIN API - Enable/Disable low power mode operation
  155. **
  156. ** Returns None
  157. **
  158. ******************************************************************************/
  159. void bte_main_enable_lpm(BOOLEAN enable)
  160. {
  161. /*Enable Low power ?*/
  162. //hci->send_low_power_command(enable ? LPM_ENABLE : LPM_DISABLE);
  163. }
  164. /******************************************************************************
  165. **
  166. ** Function bte_main_lpm_allow_bt_device_sleep
  167. **
  168. ** Description BTE MAIN API - Allow BT controller goest to sleep
  169. **
  170. ** Returns None
  171. **
  172. ******************************************************************************/
  173. void bte_main_lpm_allow_bt_device_sleep(void)
  174. {
  175. /**/
  176. //hci->send_low_power_command(LPM_WAKE_DEASSERT);
  177. }
  178. /******************************************************************************
  179. **
  180. ** Function bte_main_lpm_wake_bt_device
  181. **
  182. ** Description BTE MAIN API - Wake BT controller up if it is in sleep mode
  183. **
  184. ** Returns None
  185. **
  186. ******************************************************************************/
  187. void bte_main_lpm_wake_bt_device(void)
  188. {
  189. //hci->send_low_power_command(LPM_WAKE_ASSERT);
  190. }
  191. #endif // HCILP_INCLUDED
  192. /******************************************************************************
  193. **
  194. ** Function bte_main_hci_send
  195. **
  196. ** Description BTE MAIN API - This function is called by the upper stack to
  197. ** send an HCI message. The function displays a protocol trace
  198. ** message (if enabled), and then calls the 'transmit' function
  199. ** associated with the currently selected HCI transport
  200. **
  201. ** Returns None
  202. **
  203. ******************************************************************************/
  204. void bte_main_hci_send (BT_HDR *p_msg, UINT16 event)
  205. {
  206. UINT16 sub_event = event & BT_SUB_EVT_MASK; /* local controller ID */
  207. p_msg->event = event;
  208. //counter_add("main.tx.packets", 1);
  209. //counter_add("main.tx.bytes", p_msg->len);
  210. if ((sub_event == LOCAL_BR_EDR_CONTROLLER_ID) || \
  211. (sub_event == LOCAL_BLE_CONTROLLER_ID)) {
  212. hci->transmit_downward(event, p_msg);
  213. } else {
  214. //APPL_TRACE_ERROR("Invalid Controller ID. Discarding message.");
  215. osi_free(p_msg);
  216. }
  217. }