btc_task.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "btc/btc_task.h"
  9. #include "osi/thread.h"
  10. #include "esp_log.h"
  11. #include "bt_common.h"
  12. #include "osi/allocator.h"
  13. #include "btc/btc_alarm.h"
  14. #include "btc/btc_manage.h"
  15. #include "btc_blufi_prf.h"
  16. #include "blufi_int.h"
  17. #ifdef CONFIG_BT_BLUEDROID_ENABLED
  18. #include "common/bt_target.h"
  19. #include "btc/btc_main.h"
  20. #include "btc/btc_dev.h"
  21. #include "btc_gatts.h"
  22. #include "btc_gattc.h"
  23. #include "btc_gatt_common.h"
  24. #include "btc_gap_ble.h"
  25. #include "btc/btc_dm.h"
  26. #include "bta/bta_gatt_api.h"
  27. #if CLASSIC_BT_INCLUDED
  28. #include "btc/btc_profile_queue.h"
  29. #if (BTC_GAP_BT_INCLUDED == TRUE)
  30. #include "btc_gap_bt.h"
  31. #endif /* BTC_GAP_BT_INCLUDED == TRUE */
  32. #if BTC_AV_INCLUDED
  33. #include "btc_av.h"
  34. #include "btc_avrc.h"
  35. #include "btc_av_co.h"
  36. #endif /* #if BTC_AV_INCLUDED */
  37. #if (BTC_SPP_INCLUDED == TRUE)
  38. #include "btc_spp.h"
  39. #endif /* #if (BTC_SPP_INCLUDED == TRUE) */
  40. #if (BTC_L2CAP_INCLUDED == TRUE)
  41. #include "btc_l2cap.h"
  42. #endif /* #if (BTC_L2CAP_INCLUDED == TRUE) */
  43. #if (BTC_SDP_INCLUDED == TRUE)
  44. #include "btc_sdp.h"
  45. #endif /* #if (BTC_SDP_INCLUDED == TRUE) */
  46. #if BTC_HF_INCLUDED
  47. #include "btc_hf_ag.h"
  48. #endif/* #if BTC_HF_INCLUDED */
  49. #if BTC_HF_CLIENT_INCLUDED
  50. #include "btc_hf_client.h"
  51. #endif /* #if BTC_HF_CLIENT_INCLUDED */
  52. #if BTC_HD_INCLUDED == TRUE
  53. #include "btc_hd.h"
  54. #endif /* BTC_HD_INCLUDED */
  55. #if BTC_HH_INCLUDED == TRUE
  56. #include "btc_hh.h"
  57. #endif /* BTC_HH_INCLUDED */
  58. #endif /* #if CLASSIC_BT_INCLUDED */
  59. #endif
  60. #if (BLE_INCLUDED == TRUE)
  61. #include "btc_gap_ble.h"
  62. #endif
  63. #if CONFIG_BLE_MESH
  64. #include "btc_ble_mesh_ble.h"
  65. #include "btc_ble_mesh_prov.h"
  66. #include "btc_ble_mesh_health_model.h"
  67. #include "btc_ble_mesh_config_model.h"
  68. #include "btc_ble_mesh_generic_model.h"
  69. #include "btc_ble_mesh_lighting_model.h"
  70. #include "btc_ble_mesh_sensor_model.h"
  71. #include "btc_ble_mesh_time_scene_model.h"
  72. #endif /* #if CONFIG_BLE_MESH */
  73. #define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
  74. #define BTC_TASK_STACK_SIZE (BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig
  75. #define BTC_TASK_NAME "BTC_TASK"
  76. #define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6)
  77. #define BTC_TASK_WORKQUEUE_NUM (2)
  78. #define BTC_TASK_WORKQUEUE0_LEN (0)
  79. #define BTC_TASK_WORKQUEUE1_LEN (5)
  80. osi_thread_t *btc_thread;
  81. static const btc_func_t profile_tab[BTC_PID_NUM] = {
  82. #ifdef CONFIG_BT_BLUEDROID_ENABLED
  83. [BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
  84. [BTC_PID_DEV] = {btc_dev_call_handler, NULL },
  85. #if (GATTS_INCLUDED == TRUE)
  86. [BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
  87. #endif ///GATTS_INCLUDED == TRUE
  88. #if (GATTC_INCLUDED == TRUE)
  89. [BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
  90. #endif ///GATTC_INCLUDED == TRUE
  91. #if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE)
  92. [BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler, NULL },
  93. #endif //GATTC_INCLUDED == TRUE || GATTS_INCLUDED == TRUE
  94. #if (BLE_INCLUDED == TRUE)
  95. [BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
  96. #else
  97. [BTC_PID_GAP_BLE] = {NULL, NULL},
  98. #endif ///BLE_INCLUDED == TRUE
  99. [BTC_PID_BLE_HID] = {NULL, NULL},
  100. [BTC_PID_SPPLIKE] = {NULL, NULL},
  101. [BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
  102. #endif
  103. #if (BLUFI_INCLUDED == TRUE)
  104. [BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
  105. #endif ///BLUFI_INCLUDED == TRUE
  106. [BTC_PID_ALARM] = {btc_alarm_handler, NULL },
  107. #ifdef CONFIG_BT_BLUEDROID_ENABLED
  108. #if CLASSIC_BT_INCLUDED
  109. #if (BTC_GAP_BT_INCLUDED == TRUE)
  110. [BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
  111. #endif /* (BTC_GAP_BT_INCLUDED == TRUE) */
  112. [BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL },
  113. #if BTC_AV_INCLUDED
  114. [BTC_PID_A2DP] = {btc_a2dp_call_handler, btc_a2dp_cb_handler },
  115. [BTC_PID_AVRC_CT] = {btc_avrc_ct_call_handler, NULL },
  116. [BTC_PID_AVRC_TG] = {btc_avrc_tg_call_handler, NULL },
  117. #endif /* #if BTC_AV_INCLUDED */
  118. #if (BTC_SPP_INCLUDED == TRUE)
  119. [BTC_PID_SPP] = {btc_spp_call_handler, btc_spp_cb_handler },
  120. #endif /* #if (BTC_SPP_INCLUDED == TRUE) */
  121. #if (BTC_L2CAP_INCLUDED == TRUE)
  122. [BTC_PID_L2CAP] = {btc_l2cap_call_handler, btc_l2cap_cb_handler },
  123. #endif /* #if (BTC_L2CAP_INCLUDED == TRUE) */
  124. #if (BTC_SDP_INCLUDED == TRUE)
  125. [BTC_PID_SDP] = {btc_sdp_call_handler, btc_sdp_cb_handler },
  126. #endif /* #if (BTC_SDP_INCLUDED == TRUE) */
  127. #if BTC_HF_INCLUDED
  128. [BTC_PID_HF] = {btc_hf_call_handler, btc_hf_cb_handler},
  129. #endif /* #if BTC_HF_INCLUDED */
  130. #if BTC_HF_CLIENT_INCLUDED
  131. [BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler},
  132. #endif /* #if BTC_HF_CLIENT_INCLUDED */
  133. #if BTC_HD_INCLUDED
  134. [BTC_PID_HD] = {btc_hd_call_handler, btc_hd_cb_handler },
  135. #endif
  136. #if BTC_HH_INCLUDED
  137. [BTC_PID_HH] = {btc_hh_call_handler, btc_hh_cb_handler },
  138. #endif
  139. #endif /* #if CLASSIC_BT_INCLUDED */
  140. #endif
  141. #if CONFIG_BLE_MESH
  142. [BTC_PID_PROV] = {btc_ble_mesh_prov_call_handler, btc_ble_mesh_prov_cb_handler },
  143. [BTC_PID_MODEL] = {btc_ble_mesh_model_call_handler, btc_ble_mesh_model_cb_handler },
  144. #if CONFIG_BLE_MESH_HEALTH_CLI
  145. [BTC_PID_HEALTH_CLIENT] = {btc_ble_mesh_health_client_call_handler, btc_ble_mesh_health_client_cb_handler },
  146. #endif /* CONFIG_BLE_MESH_HEALTH_CLI */
  147. #if CONFIG_BLE_MESH_HEALTH_SRV
  148. [BTC_PID_HEALTH_SERVER] = {btc_ble_mesh_health_server_call_handler, btc_ble_mesh_health_server_cb_handler },
  149. #endif /* CONFIG_BLE_MESH_HEALTH_SRV */
  150. #if CONFIG_BLE_MESH_CFG_CLI
  151. [BTC_PID_CONFIG_CLIENT] = {btc_ble_mesh_config_client_call_handler, btc_ble_mesh_config_client_cb_handler },
  152. #endif /* CONFIG_BLE_MESH_CFG_CLI */
  153. [BTC_PID_CONFIG_SERVER] = {NULL, btc_ble_mesh_config_server_cb_handler },
  154. #if CONFIG_BLE_MESH_GENERIC_CLIENT
  155. [BTC_PID_GENERIC_CLIENT] = {btc_ble_mesh_generic_client_call_handler, btc_ble_mesh_generic_client_cb_handler },
  156. #endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
  157. #if CONFIG_BLE_MESH_LIGHTING_CLIENT
  158. [BTC_PID_LIGHTING_CLIENT] = {btc_ble_mesh_lighting_client_call_handler, btc_ble_mesh_lighting_client_cb_handler },
  159. #endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
  160. #if CONFIG_BLE_MESH_SENSOR_CLI
  161. [BTC_PID_SENSOR_CLIENT] = {btc_ble_mesh_sensor_client_call_handler, btc_ble_mesh_sensor_client_cb_handler },
  162. #endif /* CONFIG_BLE_MESH_SENSOR_CLI */
  163. #if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
  164. [BTC_PID_TIME_SCENE_CLIENT] = {btc_ble_mesh_time_scene_client_call_handler, btc_ble_mesh_time_scene_client_cb_handler},
  165. #endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
  166. #if CONFIG_BLE_MESH_GENERIC_SERVER
  167. [BTC_PID_GENERIC_SERVER] = {NULL, btc_ble_mesh_generic_server_cb_handler },
  168. #endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
  169. #if CONFIG_BLE_MESH_LIGHTING_SERVER
  170. [BTC_PID_LIGHTING_SERVER] = {NULL, btc_ble_mesh_lighting_server_cb_handler },
  171. #endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
  172. #if CONFIG_BLE_MESH_SENSOR_SERVER
  173. [BTC_PID_SENSOR_SERVER] = {NULL, btc_ble_mesh_sensor_server_cb_handler },
  174. #endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
  175. #if CONFIG_BLE_MESH_TIME_SCENE_SERVER
  176. [BTC_PID_TIME_SCENE_SERVER] = {NULL, btc_ble_mesh_time_scene_server_cb_handler},
  177. #endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
  178. #if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
  179. [BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
  180. #endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
  181. #endif /* #if CONFIG_BLE_MESH */
  182. };
  183. /*****************************************************************************
  184. **
  185. ** Function btc_task
  186. **
  187. ** Description Process profile Task Thread.
  188. ******************************************************************************/
  189. static void btc_thread_handler(void *arg)
  190. {
  191. btc_msg_t *msg = (btc_msg_t *)arg;
  192. BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, msg->arg);
  193. switch (msg->sig) {
  194. case BTC_SIG_API_CALL:
  195. profile_tab[msg->pid].btc_call(msg);
  196. break;
  197. case BTC_SIG_API_CB:
  198. profile_tab[msg->pid].btc_cb(msg);
  199. break;
  200. default:
  201. break;
  202. }
  203. if (msg->arg) {
  204. osi_free(msg->arg);
  205. }
  206. osi_free(msg);
  207. }
  208. static bt_status_t btc_task_post(btc_msg_t *msg, uint32_t timeout)
  209. {
  210. if (osi_thread_post(btc_thread, btc_thread_handler, msg, 0, timeout) == false) {
  211. return BT_STATUS_BUSY;
  212. }
  213. return BT_STATUS_SUCCESS;
  214. }
  215. /**
  216. * transfer an message to another module in the different task.
  217. * @param msg message
  218. * @param arg paramter
  219. * @param arg_len length of paramter
  220. * @param copy_func deep copy function
  221. * @return BT_STATUS_SUCCESS: success
  222. * others: fail
  223. */
  224. bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func)
  225. {
  226. btc_msg_t* lmsg;
  227. // arg XOR arg_len
  228. if ((msg == NULL) || ((arg == NULL) == !(arg_len == 0))) {
  229. return BT_STATUS_PARM_INVALID;
  230. }
  231. BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, arg);
  232. lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t));
  233. if (lmsg == NULL) {
  234. return BT_STATUS_NOMEM;
  235. }
  236. memcpy(lmsg, msg, sizeof(btc_msg_t));
  237. if (arg) {
  238. lmsg->arg = (void *)osi_malloc(arg_len);
  239. if (lmsg->arg == NULL) {
  240. osi_free(lmsg);
  241. return BT_STATUS_NOMEM;
  242. }
  243. memset(lmsg->arg, 0x00, arg_len); //important, avoid arg which have no length
  244. memcpy(lmsg->arg, arg, arg_len);
  245. if (copy_func) {
  246. copy_func(lmsg, lmsg->arg, arg);
  247. }
  248. } else {
  249. lmsg->arg = NULL;
  250. }
  251. return btc_task_post(lmsg, OSI_THREAD_MAX_TIMEOUT);
  252. }
  253. /**
  254. * transfer an message to another module in tha same task.
  255. * @param msg message
  256. * @param arg paramter
  257. * @return BT_STATUS_SUCCESS: success
  258. * others: fail
  259. */
  260. bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg)
  261. {
  262. if (msg == NULL) {
  263. return BT_STATUS_PARM_INVALID;
  264. }
  265. msg->arg = arg;
  266. switch (msg->sig) {
  267. case BTC_SIG_API_CALL:
  268. profile_tab[msg->pid].btc_call(msg);
  269. break;
  270. case BTC_SIG_API_CB:
  271. profile_tab[msg->pid].btc_cb(msg);
  272. break;
  273. default:
  274. break;
  275. }
  276. return BT_STATUS_SUCCESS;
  277. }
  278. #if BTC_DYNAMIC_MEMORY
  279. static void btc_deinit_mem(void) {
  280. if (btc_dm_cb_ptr) {
  281. osi_free(btc_dm_cb_ptr);
  282. btc_dm_cb_ptr = NULL;
  283. }
  284. if (btc_profile_cb_tab) {
  285. osi_free(btc_profile_cb_tab);
  286. btc_profile_cb_tab = NULL;
  287. }
  288. #if (BLE_INCLUDED == TRUE)
  289. if (gl_bta_adv_data_ptr) {
  290. osi_free(gl_bta_adv_data_ptr);
  291. gl_bta_adv_data_ptr = NULL;
  292. }
  293. if (gl_bta_scan_rsp_data_ptr) {
  294. osi_free(gl_bta_scan_rsp_data_ptr);
  295. gl_bta_scan_rsp_data_ptr = NULL;
  296. }
  297. #endif ///BLE_INCLUDED == TRUE
  298. #if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
  299. if (btc_creat_tab_env_ptr) {
  300. osi_free(btc_creat_tab_env_ptr);
  301. btc_creat_tab_env_ptr = NULL;
  302. }
  303. #if (BLUFI_INCLUDED == TRUE)
  304. if (blufi_env_ptr) {
  305. osi_free(blufi_env_ptr);
  306. blufi_env_ptr = NULL;
  307. }
  308. #endif
  309. #endif
  310. #if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
  311. if (hf_client_local_param_ptr) {
  312. osi_free(hf_client_local_param_ptr);
  313. hf_client_local_param_ptr = NULL;
  314. }
  315. #endif
  316. #if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
  317. if (btc_rc_cb_ptr) {
  318. osi_free(btc_rc_cb_ptr);
  319. btc_rc_cb_ptr = NULL;
  320. }
  321. if (bta_av_co_cb_ptr) {
  322. osi_free(bta_av_co_cb_ptr);
  323. bta_av_co_cb_ptr = NULL;
  324. }
  325. #endif
  326. }
  327. static bt_status_t btc_init_mem(void) {
  328. if ((btc_dm_cb_ptr = (btc_dm_cb_t *)osi_malloc(sizeof(btc_dm_cb_t))) == NULL) {
  329. goto error_exit;
  330. }
  331. memset((void *)btc_dm_cb_ptr, 0, sizeof(btc_dm_cb_t));
  332. if ((btc_profile_cb_tab = (void **)osi_malloc(sizeof(void *) * BTC_PID_NUM)) == NULL) {
  333. goto error_exit;
  334. }
  335. memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
  336. #if (BLE_INCLUDED == TRUE)
  337. if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
  338. goto error_exit;
  339. }
  340. memset((void *)gl_bta_adv_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
  341. if ((gl_bta_scan_rsp_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
  342. goto error_exit;
  343. }
  344. memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
  345. #endif ///BLE_INCLUDED == TRUE
  346. #if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
  347. if ((btc_creat_tab_env_ptr = (esp_btc_creat_tab_t *)osi_malloc(sizeof(esp_btc_creat_tab_t))) == NULL) {
  348. goto error_exit;
  349. }
  350. memset((void *)btc_creat_tab_env_ptr, 0, sizeof(esp_btc_creat_tab_t));
  351. #if (BLUFI_INCLUDED == TRUE)
  352. if ((blufi_env_ptr = (tBLUFI_ENV *)osi_malloc(sizeof(tBLUFI_ENV))) == NULL) {
  353. goto error_exit;
  354. }
  355. memset((void *)blufi_env_ptr, 0, sizeof(tBLUFI_ENV));
  356. #endif
  357. #endif
  358. #if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
  359. if ((hf_client_local_param_ptr = (hf_client_local_param_t *)osi_malloc(sizeof(hf_client_local_param_t))) == NULL) {
  360. goto error_exit;
  361. }
  362. memset((void *)hf_client_local_param_ptr, 0, sizeof(hf_client_local_param_t));
  363. #endif
  364. #if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
  365. if ((btc_rc_cb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) {
  366. goto error_exit;
  367. }
  368. memset((void *)btc_rc_cb_ptr, 0, sizeof(btc_rc_cb_t));
  369. if ((bta_av_co_cb_ptr = (tBTA_AV_CO_CB *)osi_malloc(sizeof(tBTA_AV_CO_CB))) == NULL) {
  370. goto error_exit;
  371. }
  372. memset((void *)bta_av_co_cb_ptr, 0, sizeof(tBTA_AV_CO_CB));
  373. #endif
  374. return BT_STATUS_SUCCESS;
  375. error_exit:;
  376. btc_deinit_mem();
  377. return BT_STATUS_NOMEM;
  378. }
  379. #endif ///BTC_DYNAMIC_MEMORY
  380. bt_status_t btc_init(void)
  381. {
  382. const size_t workqueue_len[] = {BTC_TASK_WORKQUEUE0_LEN, BTC_TASK_WORKQUEUE1_LEN};
  383. btc_thread = osi_thread_create(BTC_TASK_NAME, BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE,
  384. BTC_TASK_WORKQUEUE_NUM, workqueue_len);
  385. if (btc_thread == NULL) {
  386. return BT_STATUS_NOMEM;
  387. }
  388. #if BTC_DYNAMIC_MEMORY
  389. if (btc_init_mem() != BT_STATUS_SUCCESS){
  390. return BT_STATUS_NOMEM;
  391. }
  392. #endif
  393. #if (BLE_INCLUDED == TRUE)
  394. btc_gap_callback_init();
  395. btc_gap_ble_init();
  396. #endif ///BLE_INCLUDED == TRUE
  397. #if SCAN_QUEUE_CONGEST_CHECK
  398. btc_adv_list_init();
  399. #endif
  400. /* TODO: initial the profile_tab */
  401. return BT_STATUS_SUCCESS;
  402. }
  403. void btc_deinit(void)
  404. {
  405. #if BTC_DYNAMIC_MEMORY
  406. btc_deinit_mem();
  407. #endif
  408. osi_thread_free(btc_thread);
  409. btc_thread = NULL;
  410. #if (BLE_INCLUDED == TRUE)
  411. btc_gap_ble_deinit();
  412. #endif ///BLE_INCLUDED == TRUE
  413. #if SCAN_QUEUE_CONGEST_CHECK
  414. btc_adv_list_deinit();
  415. #endif
  416. }
  417. bool btc_check_queue_is_congest(void)
  418. {
  419. if (osi_thread_queue_wait_size(btc_thread, 0) >= BT_QUEUE_CONGEST_SIZE) {
  420. return true;
  421. }
  422. return false;
  423. }
  424. int get_btc_work_queue_size(void)
  425. {
  426. return osi_thread_queue_wait_size(btc_thread, 0);
  427. }
  428. osi_thread_t *btc_get_current_thread(void)
  429. {
  430. return btc_thread;
  431. }