2016-11-15 12:56:15 +00:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "common/bt_target.h"
|
|
|
|
#include "btc/btc_task.h"
|
|
|
|
#include "common/bt_trace.h"
|
|
|
|
#include "osi/thread.h"
|
|
|
|
#include "common/bt_defs.h"
|
|
|
|
#include "osi/allocator.h"
|
|
|
|
#include "btc/btc_main.h"
|
2018-11-06 07:34:38 +00:00
|
|
|
#include "btc/btc_manage.h"
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "btc/btc_dev.h"
|
2016-11-15 12:56:15 +00:00
|
|
|
#include "btc_gatts.h"
|
|
|
|
#include "btc_gattc.h"
|
2018-01-25 09:34:10 +00:00
|
|
|
#include "btc_gatt_common.h"
|
2016-11-15 12:56:15 +00:00
|
|
|
#include "btc_gap_ble.h"
|
2016-11-16 14:11:59 +00:00
|
|
|
#include "btc_blufi_prf.h"
|
2018-11-06 07:34:38 +00:00
|
|
|
#include "blufi_int.h"
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "btc/btc_dm.h"
|
|
|
|
#include "btc/btc_alarm.h"
|
|
|
|
#include "bta/bta_gatt_api.h"
|
2018-09-17 08:44:38 +00:00
|
|
|
#if CLASSIC_BT_INCLUDED
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "btc/btc_profile_queue.h"
|
2017-11-24 09:28:43 +00:00
|
|
|
#if (BTC_GAP_BT_INCLUDED == TRUE)
|
2017-03-16 14:32:27 +00:00
|
|
|
#include "btc_gap_bt.h"
|
2017-11-24 09:28:43 +00:00
|
|
|
#endif /* BTC_GAP_BT_INCLUDED == TRUE */
|
2018-01-05 08:48:29 +00:00
|
|
|
#if BTC_AV_INCLUDED
|
2017-03-01 05:49:26 +00:00
|
|
|
#include "btc_av.h"
|
2017-03-08 05:48:56 +00:00
|
|
|
#include "btc_avrc.h"
|
2018-11-06 07:34:38 +00:00
|
|
|
#include "btc_av_co.h"
|
2017-12-25 11:39:37 +00:00
|
|
|
#endif /* #if BTC_AV_INCLUDED */
|
2018-09-17 08:44:38 +00:00
|
|
|
#if (BTC_SPP_INCLUDED == TRUE)
|
2018-01-05 08:48:29 +00:00
|
|
|
#include "btc_spp.h"
|
2018-09-17 08:44:38 +00:00
|
|
|
#endif /* #if (BTC_SPP_INCLUDED == TRUE) */
|
2018-05-21 03:33:30 +00:00
|
|
|
#if BTC_HF_CLIENT_INCLUDED
|
|
|
|
#include "btc_hf_client.h"
|
|
|
|
#endif /* #if BTC_HF_CLIENT_INCLUDED */
|
2018-09-17 08:44:38 +00:00
|
|
|
#endif /* #if CLASSIC_BT_INCLUDED */
|
2019-01-07 07:16:47 +00:00
|
|
|
#if CONFIG_BLE_MESH
|
|
|
|
#include "btc_ble_mesh_prov.h"
|
|
|
|
#include "btc_ble_mesh_health_model.h"
|
|
|
|
#include "btc_ble_mesh_config_model.h"
|
|
|
|
#include "btc_ble_mesh_generic_model.h"
|
|
|
|
#include "btc_ble_mesh_lighting_model.h"
|
|
|
|
#include "btc_ble_mesh_sensor_model.h"
|
|
|
|
#include "btc_ble_mesh_time_scene_model.h"
|
|
|
|
#endif /* #if CONFIG_BLE_MESH */
|
2016-11-19 13:00:08 +00:00
|
|
|
|
2018-09-14 09:24:25 +00:00
|
|
|
#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
|
2018-09-17 08:44:38 +00:00
|
|
|
#define BTC_TASK_STACK_SIZE (BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig
|
2018-09-14 09:24:25 +00:00
|
|
|
#define BTC_TASK_NAME "btcT"
|
2018-09-17 08:44:38 +00:00
|
|
|
#define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6)
|
2016-11-15 12:56:15 +00:00
|
|
|
|
2018-10-31 09:11:54 +00:00
|
|
|
osi_thread_t *btc_thread;
|
2016-11-15 12:56:15 +00:00
|
|
|
|
2018-11-06 07:34:38 +00:00
|
|
|
static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
|
|
|
|
[BTC_PID_DEV] = {btc_dev_call_handler, NULL },
|
2017-04-20 11:18:05 +00:00
|
|
|
#if (GATTS_INCLUDED == TRUE)
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
|
2017-04-20 11:18:05 +00:00
|
|
|
#endif ///GATTS_INCLUDED == TRUE
|
2017-04-19 09:16:24 +00:00
|
|
|
#if (GATTC_INCLUDED == TRUE)
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
|
2017-04-19 09:16:24 +00:00
|
|
|
#endif ///GATTC_INCLUDED == TRUE
|
2018-01-25 09:34:10 +00:00
|
|
|
#if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE)
|
|
|
|
[BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler, NULL },
|
|
|
|
#endif //GATTC_INCLUDED == TRUE || GATTS_INCLUDED == TRUE
|
2018-11-12 03:08:19 +00:00
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
|
2018-11-12 03:08:19 +00:00
|
|
|
#else
|
|
|
|
[BTC_PID_GAP_BLE] = {NULL, NULL},
|
|
|
|
#endif ///BLE_INCLUDED == TRUE
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_BLE_HID] = {NULL, NULL},
|
|
|
|
[BTC_PID_SPPLIKE] = {NULL, NULL},
|
2017-04-20 11:18:05 +00:00
|
|
|
#if (GATTS_INCLUDED == TRUE)
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
2017-04-20 11:18:05 +00:00
|
|
|
#endif ///GATTS_INCLUDED == TRUE
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
|
|
|
[BTC_PID_ALARM] = {btc_alarm_handler, NULL },
|
2018-09-17 08:44:38 +00:00
|
|
|
#if CLASSIC_BT_INCLUDED
|
2017-11-24 09:28:43 +00:00
|
|
|
#if (BTC_GAP_BT_INCLUDED == TRUE)
|
2018-01-16 10:36:31 +00:00
|
|
|
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
|
2017-11-24 09:28:43 +00:00
|
|
|
#endif /* (BTC_GAP_BT_INCLUDED == TRUE) */
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL },
|
2018-01-05 08:48:29 +00:00
|
|
|
#if BTC_AV_INCLUDED
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_A2DP] = {btc_a2dp_call_handler, btc_a2dp_cb_handler },
|
component/bt: implement AVRCP Target APIs
1. Add more notification events to the enum according to the event list in AVRCP specification.
2. Add API and callback events for basic AVRCP target functionalities to do init, deinit, callback-registration, connection status indication.
3. Implement API to set/get supported PASSTHROUGH command on local AVRCP TG, implement callback events for remote passthrough command indication.
4. Implement API to set/get supported notification eventIDs on local AVRCP TG, implement API to send event notifications to remote CT. \
Currently supported event in TG only includes ESP_AVRC_RN_VOLUME_CHANGE(0xd), which can be extended in later commits.
5. Implement callback events for SetAbsoluteVolume command indication on TG.
6. Add limitation of event_ids supported in RegisterNotification command in CT. The supported event_ids include: \
ESP_AVRC_RN_PLAY_STATUS_CHANGE(0x1), ESP_AVRC_RN_TRACK_CHANGE(0x2), ESP_AVRC_RN_PLAY_POS_CHANGE(0x5), ESP_AVRC_RN_VOLUME_CHANGE(0xd).
7. Add feature bit mask in parameter of callback event ESP_AVRC_CT_REMOTE_FEATURES_EVT for peer feature information got from SDP.
8. Add API and callback event to AVRCP CT to retrieve remote TG's supported notification event capabilities.
9. Modify data type for parameter of callback event ESP_AVRC_CT_CHANGE_NOTIFY_EVT.
10. Change AVRCP version from 1.3 to 1.4 for compatibility cause in using AbsoluteVolume feature.
11. Modify local AVRCP device to be category 1 as CT and category 2 as TG that applies to bluetooth headphones or speakers.
12. Update the use of AVRCP APIs and events in the two examples: a2dp_sink and a2dp_gatts_coex, which include the demo of volume control and notification.
2018-12-21 09:04:21 +00:00
|
|
|
[BTC_PID_AVRC_CT] = {btc_avrc_ct_call_handler, NULL },
|
|
|
|
[BTC_PID_AVRC_TG] = {btc_avrc_tg_call_handler, NULL },
|
2018-01-05 08:48:29 +00:00
|
|
|
#endif /* #if BTC_AV_INCLUDED */
|
2018-09-17 08:44:38 +00:00
|
|
|
#if (BTC_SPP_INCLUDED == TRUE)
|
2018-01-25 09:34:10 +00:00
|
|
|
[BTC_PID_SPP] = {btc_spp_call_handler, btc_spp_cb_handler },
|
2018-09-17 08:44:38 +00:00
|
|
|
#endif /* #if (BTC_SPP_INCLUDED == TRUE) */
|
2018-05-21 03:33:30 +00:00
|
|
|
#if BTC_HF_CLIENT_INCLUDED
|
|
|
|
[BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler},
|
|
|
|
#endif /* #if BTC_HF_CLIENT_INCLUDED */
|
2018-09-17 08:44:38 +00:00
|
|
|
#endif /* #if CLASSIC_BT_INCLUDED */
|
2019-01-07 07:16:47 +00:00
|
|
|
#if CONFIG_BLE_MESH
|
|
|
|
[BTC_PID_PROV] = {btc_mesh_prov_call_handler, btc_mesh_prov_cb_handler},
|
|
|
|
[BTC_PID_MODEL] = {btc_mesh_model_call_handler, btc_mesh_model_cb_handler},
|
|
|
|
[BTC_PID_HEALTH_CLIENT] = {btc_mesh_health_client_call_handler, btc_mesh_health_client_cb_handler},
|
|
|
|
[BTC_PID_HEALTH_SERVER] = {btc_mesh_health_server_call_handler, btc_mesh_health_server_cb_handler},
|
|
|
|
[BTC_PID_CFG_CLIENT] = {btc_mesh_cfg_client_call_handler, btc_mesh_cfg_client_cb_handler},
|
|
|
|
[BTC_PID_CFG_SERVER] = {NULL , btc_mesh_cfg_server_cb_handler},
|
|
|
|
[BTC_PID_GENERIC_CLIENT] = {btc_mesh_generic_client_call_handler, btc_mesh_generic_client_cb_handler},
|
|
|
|
[BTC_PID_LIGHT_CLIENT] = {btc_mesh_light_client_call_handler, btc_mesh_light_client_cb_handler},
|
|
|
|
[BTC_PID_SENSOR_CLIENT] = {btc_mesh_sensor_client_call_handler, btc_mesh_sensor_client_cb_handler},
|
|
|
|
[BTC_PID_TIME_SCENE_CLIENT] = {btc_mesh_time_scene_client_call_handler, btc_mesh_time_scene_client_cb_handler},
|
|
|
|
#endif /* #if CONFIG_BLE_MESH */
|
2016-11-15 12:56:15 +00:00
|
|
|
};
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
**
|
|
|
|
** Function btc_task
|
|
|
|
**
|
|
|
|
** Description Process profile Task Thread.
|
|
|
|
******************************************************************************/
|
2018-09-14 09:24:25 +00:00
|
|
|
static void btc_thread_handler(void *arg)
|
2016-11-15 12:56:15 +00:00
|
|
|
{
|
2018-09-14 09:24:25 +00:00
|
|
|
btc_msg_t *msg = (btc_msg_t *)arg;
|
|
|
|
|
|
|
|
BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, msg->arg);
|
|
|
|
switch (msg->sig) {
|
|
|
|
case BTC_SIG_API_CALL:
|
|
|
|
profile_tab[msg->pid].btc_call(msg);
|
|
|
|
break;
|
|
|
|
case BTC_SIG_API_CB:
|
|
|
|
profile_tab[msg->pid].btc_cb(msg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg->arg) {
|
|
|
|
osi_free(msg->arg);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2018-09-14 09:24:25 +00:00
|
|
|
osi_free(msg);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
|
2019-04-18 03:57:28 +00:00
|
|
|
static bt_status_t btc_task_post(btc_msg_t *msg, uint32_t timeout)
|
2016-11-15 12:56:15 +00:00
|
|
|
{
|
2018-09-14 09:24:25 +00:00
|
|
|
btc_msg_t *lmsg;
|
|
|
|
|
|
|
|
lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t));
|
|
|
|
if (lmsg == NULL) {
|
|
|
|
return BT_STATUS_NOMEM;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
|
2018-09-14 09:24:25 +00:00
|
|
|
memcpy(lmsg, msg, sizeof(btc_msg_t));
|
|
|
|
|
2019-04-18 03:57:28 +00:00
|
|
|
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 2, timeout) == false) {
|
2016-11-24 18:10:15 +00:00
|
|
|
return BT_STATUS_BUSY;
|
|
|
|
}
|
2016-11-15 12:56:15 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
return BT_STATUS_SUCCESS;
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
btc_msg_t lmsg;
|
|
|
|
|
|
|
|
if (msg == NULL) {
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
}
|
|
|
|
|
2018-04-25 02:11:06 +00:00
|
|
|
BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, arg);
|
2016-11-24 18:10:15 +00:00
|
|
|
|
|
|
|
memcpy(&lmsg, msg, sizeof(btc_msg_t));
|
|
|
|
if (arg) {
|
2017-08-17 13:13:45 +00:00
|
|
|
lmsg.arg = (void *)osi_malloc(arg_len);
|
2016-11-24 18:10:15 +00:00
|
|
|
if (lmsg.arg == NULL) {
|
|
|
|
return BT_STATUS_NOMEM;
|
|
|
|
}
|
2017-04-11 06:20:20 +00:00
|
|
|
memset(lmsg.arg, 0x00, arg_len); //important, avoid arg which have no length
|
2016-11-24 18:10:15 +00:00
|
|
|
memcpy(lmsg.arg, arg, arg_len);
|
|
|
|
if (copy_func) {
|
|
|
|
copy_func(&lmsg, lmsg.arg, arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lmsg.arg = NULL;
|
|
|
|
}
|
|
|
|
|
2019-04-18 03:57:28 +00:00
|
|
|
return btc_task_post(&lmsg, OSI_THREAD_MAX_TIMEOUT);
|
2018-09-14 09:24:25 +00:00
|
|
|
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 07:34:38 +00:00
|
|
|
#if BTC_DYNAMIC_MENDRY
|
2019-06-21 03:55:45 +00:00
|
|
|
|
|
|
|
static void btc_deinit_mem(void) {
|
|
|
|
if (btc_dm_cb_ptr) {
|
|
|
|
osi_free(btc_dm_cb_ptr);
|
|
|
|
btc_dm_cb_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (btc_profile_cb_tab) {
|
|
|
|
osi_free(btc_profile_cb_tab);
|
|
|
|
btc_profile_cb_tab = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
|
|
|
if (gl_bta_adv_data_ptr) {
|
|
|
|
osi_free(gl_bta_adv_data_ptr);
|
|
|
|
gl_bta_adv_data_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_bta_scan_rsp_data_ptr) {
|
|
|
|
osi_free(gl_bta_scan_rsp_data_ptr);
|
|
|
|
gl_bta_scan_rsp_data_ptr = NULL;
|
|
|
|
}
|
|
|
|
#endif ///BLE_INCLUDED == TRUE
|
|
|
|
|
|
|
|
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
|
|
|
|
if (btc_creat_tab_env_ptr) {
|
|
|
|
osi_free(btc_creat_tab_env_ptr);
|
|
|
|
btc_creat_tab_env_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blufi_env_ptr) {
|
|
|
|
osi_free(blufi_env_ptr);
|
|
|
|
blufi_env_ptr = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
|
|
|
|
if (hf_client_local_param_ptr) {
|
|
|
|
osi_free(hf_client_local_param_ptr);
|
|
|
|
hf_client_local_param_ptr = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
|
|
|
|
if (btc_rc_cb_ptr) {
|
|
|
|
osi_free(btc_rc_cb_ptr);
|
|
|
|
btc_rc_cb_ptr = NULL;
|
|
|
|
}
|
|
|
|
if (bta_av_co_cb_ptr) {
|
|
|
|
osi_free(bta_av_co_cb_ptr);
|
|
|
|
bta_av_co_cb_ptr = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-06 07:34:38 +00:00
|
|
|
static bt_status_t btc_init_mem(void) {
|
|
|
|
if ((btc_dm_cb_ptr = (btc_dm_cb_t *)osi_malloc(sizeof(btc_dm_cb_t))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)btc_dm_cb_ptr, 0, sizeof(btc_dm_cb_t));
|
|
|
|
|
|
|
|
if ((btc_profile_cb_tab = (void **)osi_malloc(sizeof(void *) * BTC_PID_NUM)) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
|
|
|
|
|
2018-11-12 03:08:19 +00:00
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2018-11-06 07:34:38 +00:00
|
|
|
if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)gl_bta_adv_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
|
|
|
|
|
|
|
|
if ((gl_bta_scan_rsp_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
|
2018-11-12 03:08:19 +00:00
|
|
|
#endif ///BLE_INCLUDED == TRUE
|
2018-11-06 07:34:38 +00:00
|
|
|
|
|
|
|
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
|
|
|
|
if ((btc_creat_tab_env_ptr = (esp_btc_creat_tab_t *)osi_malloc(sizeof(esp_btc_creat_tab_t))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)btc_creat_tab_env_ptr, 0, sizeof(esp_btc_creat_tab_t));
|
|
|
|
|
|
|
|
if ((blufi_env_ptr = (tBLUFI_ENV *)osi_malloc(sizeof(tBLUFI_ENV))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)blufi_env_ptr, 0, sizeof(tBLUFI_ENV));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
|
|
|
|
if ((hf_client_local_param_ptr = (hf_client_local_param_t *)osi_malloc(sizeof(hf_client_local_param_t))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)hf_client_local_param_ptr, 0, sizeof(hf_client_local_param_t));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
|
2019-06-21 03:55:45 +00:00
|
|
|
if ((btc_rc_cb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) {
|
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
2019-06-21 03:55:45 +00:00
|
|
|
memset((void *)btc_rc_cb_ptr, 0, sizeof(btc_rc_cb_t));
|
2018-11-06 07:34:38 +00:00
|
|
|
if ((bta_av_co_cb_ptr = (tBTA_AV_CO_CB *)osi_malloc(sizeof(tBTA_AV_CO_CB))) == NULL) {
|
2019-06-21 03:55:45 +00:00
|
|
|
goto error_exit;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
|
|
|
memset((void *)bta_av_co_cb_ptr, 0, sizeof(tBTA_AV_CO_CB));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return BT_STATUS_SUCCESS;
|
|
|
|
|
2019-06-21 03:55:45 +00:00
|
|
|
error_exit:;
|
|
|
|
btc_deinit_mem();
|
|
|
|
return BT_STATUS_NOMEM;
|
2018-11-06 07:34:38 +00:00
|
|
|
}
|
2019-06-21 03:55:45 +00:00
|
|
|
#endif ///BTC_DYNAMIC_MENDRY
|
2016-11-15 12:56:15 +00:00
|
|
|
|
|
|
|
int btc_init(void)
|
|
|
|
{
|
2018-10-31 09:11:54 +00:00
|
|
|
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3);
|
2018-09-14 09:24:25 +00:00
|
|
|
if (btc_thread == NULL) {
|
2018-03-28 12:25:57 +00:00
|
|
|
return BT_STATUS_NOMEM;
|
|
|
|
}
|
2018-09-14 09:24:25 +00:00
|
|
|
|
2018-11-06 07:34:38 +00:00
|
|
|
#if BTC_DYNAMIC_MENDRY
|
|
|
|
if (btc_init_mem() != BT_STATUS_SUCCESS){
|
|
|
|
return BT_STATUS_NOMEM;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-12 03:08:19 +00:00
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2017-08-24 12:46:03 +00:00
|
|
|
btc_gap_callback_init();
|
2018-11-12 03:08:19 +00:00
|
|
|
#endif ///BLE_INCLUDED == TRUE
|
|
|
|
|
2018-07-02 02:59:51 +00:00
|
|
|
#if SCAN_QUEUE_CONGEST_CHECK
|
|
|
|
btc_adv_list_init();
|
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
/* TODO: initial the profile_tab */
|
|
|
|
return BT_STATUS_SUCCESS;
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void btc_deinit(void)
|
|
|
|
{
|
2018-11-06 07:34:38 +00:00
|
|
|
#if BTC_DYNAMIC_MENDRY
|
|
|
|
btc_deinit_mem();
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 09:24:25 +00:00
|
|
|
osi_thread_free(btc_thread);
|
|
|
|
btc_thread = NULL;
|
2018-11-06 07:34:38 +00:00
|
|
|
|
2018-07-02 02:59:51 +00:00
|
|
|
#if SCAN_QUEUE_CONGEST_CHECK
|
|
|
|
btc_adv_list_deinit();
|
|
|
|
#endif
|
2016-11-15 12:56:15 +00:00
|
|
|
}
|
2018-07-02 02:59:51 +00:00
|
|
|
|
|
|
|
bool btc_check_queue_is_congest(void)
|
|
|
|
{
|
2018-10-31 09:11:54 +00:00
|
|
|
if (osi_thread_queue_wait_size(btc_thread, 2) >= QUEUE_CONGEST_SIZE) {
|
2018-07-02 02:59:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-14 09:24:25 +00:00
|
|
|
|
2018-07-02 02:59:51 +00:00
|
|
|
return false;
|
|
|
|
}
|