*******************************************************************************/
void bta_dm_oob_reply(tBTA_DM_MSG *p_data)
{
+#if (BLE_INCLUDED)
BTM_BleOobDataReply(p_data->oob_reply.bd_addr, BTM_SUCCESS, p_data->oob_reply.len, p_data->oob_reply.value);
+#endif
}
/*******************************************************************************
NULL
#endif /* #if (BTC_GAP_BT_INCLUDED == TRUE) */
};
-tBTA_DM_EIR_CONF *const p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF *) &bta_dm_eir_cfg;
+tBTA_DM_EIR_CONF *p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF *) &bta_dm_eir_cfg;
bta_dm_update_white_list, /* BTA_DM_API_UPDATE_WHITE_LIST_EVT */
bta_dm_ble_read_adv_tx_power, /* BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT */
bta_dm_ble_read_rssi, /* BTA_DM_API_BLE_READ_RSSI_EVT */
+#if BLE_INCLUDED == TRUE
bta_dm_ble_update_duplicate_exceptional_list,/* BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT */
+#endif
};
BTA_DM_API_UPDATE_WHITE_LIST_EVT,
BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT,
BTA_DM_API_BLE_READ_RSSI_EVT,
+#if BLE_INCLUDED == TRUE
BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT,
+#endif
BTA_DM_MAX_EVT
};
// Read the size of memory space required for blob
nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, NULL, &length);
// Read previously saved blob if available
-#if (!CONFIG_BT_STACK_NO_LOG)
esp_err_t err_code = nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, attr, &length);
+#if (!CONFIG_BT_STACK_NO_LOG)
num_attr = length / sizeof(tBTA_GATTC_NV_ATTR);
#endif
status = (err_code == ESP_OK && length != 0) ? BTA_GATT_OK : BTA_GATT_ERROR;
extern void bta_sys_init(void);
extern void bta_sys_free(void);
-extern void bta_sys_event(BT_HDR *p_msg);
+extern void bta_sys_event(void * param);
extern void bta_sys_set_trace_level(UINT8 level);
extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg);
extern void bta_sys_deregister(UINT8 id);
** Returns void
**
*******************************************************************************/
-void bta_sys_event(BT_HDR *p_msg)
+void bta_sys_event(void * param)
{
+ BT_HDR *p_msg = (BT_HDR *)param;
+
UINT8 id;
BOOLEAN freebuf = TRUE;
}
#if BTC_DYNAMIC_MENDRY
+
+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
+}
+
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) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
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) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
#if (BLE_INCLUDED == TRUE)
if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
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) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
#endif ///BLE_INCLUDED == TRUE
#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) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
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) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
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) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
memset((void *)hf_client_local_param_ptr, 0, sizeof(hf_client_local_param_t));
#endif
#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
- if ((btc_rc_vb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) {
- return BT_STATUS_NOMEM;
+ if ((btc_rc_cb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) {
+ goto error_exit;
}
- memset((void *)btc_rc_vb_ptr, 0, sizeof(btc_rc_cb_t));
+ memset((void *)btc_rc_cb_ptr, 0, sizeof(btc_rc_cb_t));
if ((bta_av_co_cb_ptr = (tBTA_AV_CO_CB *)osi_malloc(sizeof(tBTA_AV_CO_CB))) == NULL) {
- return BT_STATUS_NOMEM;
+ goto error_exit;
}
memset((void *)bta_av_co_cb_ptr, 0, sizeof(tBTA_AV_CO_CB));
#endif
return BT_STATUS_SUCCESS;
-}
-
-static void btc_deinit_mem(void) {
- osi_free(btc_dm_cb_ptr);
- btc_dm_cb_ptr = NULL;
- osi_free(btc_profile_cb_tab);
- btc_profile_cb_tab = NULL;
-
- osi_free(gl_bta_adv_data_ptr);
- gl_bta_adv_data_ptr = NULL;
-
- osi_free(gl_bta_scan_rsp_data_ptr);
- gl_bta_scan_rsp_data_ptr = NULL;
-
-#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
- osi_free(btc_creat_tab_env_ptr);
- btc_creat_tab_env_ptr = NULL;
- osi_free(blufi_env_ptr);
- blufi_env_ptr = NULL;
-#endif
-
-#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
- osi_free(hf_client_local_param_ptr);
- hf_client_local_param_ptr = NULL;
-#endif
-
-#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
- osi_free(btc_rc_vb_ptr);
- btc_rc_vb_ptr = NULL;
- osi_free(bta_av_co_cb_ptr);
- bta_av_co_cb_ptr = NULL;
-#endif
+error_exit:;
+ btc_deinit_mem();
+ return BT_STATUS_NOMEM;
}
-#endif
+#endif ///BTC_DYNAMIC_MENDRY
int btc_init(void)
{
/// initialize CT-TG shared resources
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
- btc_rc_cb.rc_vol_label = MAX_LABEL;
- btc_rc_cb.rc_volume = MAX_VOLUME;
}
}
#define CHECK_ESP_RC_CONNECTED do { \
BTC_TRACE_DEBUG("## %s ##", __FUNCTION__); \
- if (btc_rc_vb.rc_connected == FALSE) { \
+ if (btc_rc_cb.rc_connected == FALSE) { \
BTC_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
return ESP_ERR_INVALID_STATE; \
} \
#ifndef __BT_USER_CONFIG_H__
#define __BT_USER_CONFIG_H__
-
-
-
/* All the configuration from SDK defined here */
#include "sdkconfig.h"
#define UC_BT_SSP_ENABLED CONFIG_BT_SSP_ENABLED
#else
#define UC_BT_SSP_ENABLED FALSE
+#endif
//BLE
#ifdef CONFIG_BT_BLE_ENABLED
//GATTS
#ifdef CONFIG_BT_GATTS_ENABLE
-#define UC_BT_GATTS_ENABLED CONFIG_BT_GATTS_ENABLE
+#define UC_BT_GATTS_ENABLE CONFIG_BT_GATTS_ENABLE
#else
-#define UC_BT_GATTS_ENABLED FALSE
+#define UC_BT_GATTS_ENABLE FALSE
#endif
//GATTC
#ifdef CONFIG_BT_GATTC_ENABLE
-#define UC_BT_GATTC_ENABLED CONFIG_BT_GATTC_ENABLE
+#define UC_BT_GATTC_ENABLE CONFIG_BT_GATTC_ENABLE
#else
-#define UC_BT_GATTC_ENABLED FALSE
+#define UC_BT_GATTC_ENABLE FALSE
#endif
//GATTC CACHE
//SMP
#ifdef CONFIG_BT_SMP_ENABLE
-#define UC_BT_SMP_ENABLED CONFIG_BT_SMP_ENABLE
+#define UC_BT_SMP_ENABLE CONFIG_BT_SMP_ENABLE
#else
-#define UC_BT_SMP_ENABLED FALSE
+#define UC_BT_SMP_ENABLE FALSE
#endif
//SMP_SLAVE_CON_PARAMS_UPD_ENABLE
#define UC_BT_LOG_BLUFI_TRACE_LEVEL UC_TRACE_LEVEL_WARNING
#endif
-
#endif /* __BT_USER_CONFIG_H__ */
#endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
// Enable adv flow control
- response = AWAIT_COMMAND(packet_factory->make_set_adv_report_flow_control(HCI_HOST_FLOW_CTRL_ADV_REPORT_ON, (uint16_t)BLE_ADV_REPORT_FLOW_CONTROL_NUM, (uint16_t)BLE_ADV_REPORT_DISCARD_THRSHOLD));
- packet_parser->parse_generic_command_complete(response);
+ response = AWAIT_COMMAND(controller_param.packet_factory->make_set_adv_report_flow_control(HCI_HOST_FLOW_CTRL_ADV_REPORT_ON, (uint16_t)BLE_ADV_REPORT_FLOW_CONTROL_NUM, (uint16_t)BLE_ADV_REPORT_DISCARD_THRSHOLD));
+ controller_param.packet_parser->parse_generic_command_complete(response);
#endif
// Tell the controller about our buffer sizes and buffer counts next
// TODO(zachoverflow): factor this out. eww l2cap contamination. And why just a hardcoded 10?
** F U N C T I O N S *
******************************************************************************/
+/*****************************************************************************
+**
+** Function BTE_DeinitStack
+**
+** Description Deinitialize control block memory for each component.
+**
+** Note: This API must be called
+** after freeing the BTU Task.
+**
+** Returns void
+**
+******************************************************************************/
+void BTE_DeinitStack(void)
+{
+ //BTA Modules
+#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
+#if GATTS_INCLUDED == TRUE
+ if (bta_gatts_cb_ptr){
+ osi_free(bta_gatts_cb_ptr);
+ bta_gatts_cb_ptr = NULL;
+ }
+#endif
+#if GATTC_INCLUDED==TRUE
+ if (bta_gattc_cb_ptr){
+ osi_free(bta_gattc_cb_ptr);
+ bta_gattc_cb_ptr = NULL;
+ }
+#endif
+#if BTA_HH_INCLUDED==TRUE
+ if (bta_hh_cb_ptr){
+ osi_free(bta_hh_cb_ptr);
+ bta_hh_cb_ptr = NULL;
+ }
+#endif
+#if BTA_AV_INCLUDED==TRUE
+ if (bta_av_cb_ptr){
+ osi_free(bta_av_cb_ptr);
+ bta_av_cb_ptr = NULL;
+ }
+ if (bta_av_sbc_ups_cb_ptr){
+ osi_free(bta_av_sbc_ups_cb_ptr);
+ bta_av_sbc_ups_cb_ptr = NULL;
+ }
+#endif
+#if BTA_AR_INCLUDED==TRUE
+ if (bta_ar_cb_ptr){
+ osi_free(bta_ar_cb_ptr);
+ bta_ar_cb_ptr = NULL;
+ }
+#endif
+#if SDP_INCLUDED == TRUE
+ if (g_disc_raw_data_buf){
+ osi_free(g_disc_raw_data_buf);
+ g_disc_raw_data_buf = NULL;
+ }
+#endif
+#if BTA_SDP_INCLUDED == TRUE
+ if (bta_sdp_cb_ptr){
+ osi_free(bta_sdp_cb_ptr);
+ bta_sdp_cb_ptr = NULL;
+ }
+#endif
+#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
+ if (bta_jv_cb_ptr){
+ osi_free(bta_jv_cb_ptr);
+ bta_jv_cb_ptr = NULL;
+ }
+#endif //JV
+#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
+ if (bta_hf_client_cb_ptr){
+ osi_free(bta_hf_client_cb_ptr);
+ bta_hf_client_cb_ptr = NULL;
+ }
+#endif
+ if (bta_dm_conn_srvcs_ptr){
+ osi_free(bta_dm_conn_srvcs_ptr);
+ bta_dm_conn_srvcs_ptr = NULL;
+ }
+ if (bta_dm_di_cb_ptr){
+ osi_free(bta_dm_di_cb_ptr);
+ bta_dm_di_cb_ptr = NULL;
+ }
+ if (bta_dm_search_cb_ptr){
+ osi_free(bta_dm_search_cb_ptr);
+ bta_dm_search_cb_ptr = NULL;
+ }
+ if (bta_dm_cb_ptr){
+ osi_free(bta_dm_cb_ptr);
+ bta_dm_cb_ptr = NULL;
+ }
+ if (bta_sys_cb_ptr){
+ osi_free(bta_sys_cb_ptr);
+ bta_sys_cb_ptr = NULL;
+ }
+#endif // BTA_INCLUDED == TRUE
+
+#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
+ GAP_Deinit();
+#endif
+
+#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
+ if (avct_cb_ptr){
+ osi_free(avct_cb_ptr);
+ avct_cb_ptr = NULL;
+ }
+#endif
+
+#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
+ if (avdt_cb_ptr){
+ osi_free(avdt_cb_ptr);
+ avdt_cb_ptr = NULL;
+ }
+#endif
+
+#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
+ AVRC_Deinit();
+#endif
+
+#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
+ A2D_Deinit();
+#endif
+
+#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
+ RFCOMM_Deinit();
+#endif
+}
+
/*****************************************************************************
**
** Function BTE_InitStack
** as long as the component's init function is called
** before accessing any of its functions.
**
-** Returns void
+** Returns status
**
******************************************************************************/
-void BTE_InitStack(void)
+bt_status_t BTE_InitStack(void)
{
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
//Initialize the optional stack components
- RFCOMM_Init();
+ if (RFCOMM_Init() != BT_STATUS_SUCCESS) {
+ goto error_exit;
+ }
#endif
//BNEP and its profiles
//AVDT and its profiles
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
- A2D_Init();
+ if (A2D_Init() != BT_STATUS_SUCCESS) {
+ goto error_exit;
+ }
#endif // AADP
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
- AVRC_Init();
+ if (AVRC_Init() != BT_STATUS_SUCCESS) {
+ goto error_exit;
+ }
#endif
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB));
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB));
#endif
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
- GAP_Init();
+ if (GAP_Init() != BT_STATUS_SUCCESS) {
+ goto error_exit;
+ }
#endif
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
//BTA Modules
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) {
- return;
+ goto error_exit;
}
if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) {
- return;
+ goto error_exit;
}
if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) {
- return;
+ goto error_exit;
}
if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
- return;
+ goto error_exit;
}
if ((bta_dm_conn_srvcs_ptr = (tBTA_DM_CONNECTED_SRVCS *)osi_malloc(sizeof(tBTA_DM_CONNECTED_SRVCS))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
memset((void *)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB));
#endif
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB));
#endif //JV
#endif
#if BTA_SDP_INCLUDED == TRUE
if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB));
#endif
#if SDP_INCLUDED == TRUE
if ((g_disc_raw_data_buf = (UINT8 *)osi_malloc(MAX_DISC_RAW_DATA_BUF)) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF);
#endif
#if BTA_AR_INCLUDED==TRUE
if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));
#endif
#if BTA_AV_INCLUDED==TRUE
if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
if ((bta_av_sbc_ups_cb_ptr = (tBTA_AV_SBC_UPS_CB *)osi_malloc(sizeof(tBTA_AV_SBC_UPS_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_av_sbc_ups_cb_ptr, 0, sizeof(tBTA_AV_SBC_UPS_CB));
#endif
#if BTA_HH_INCLUDED==TRUE
if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));
#endif
#endif
#if GATTC_INCLUDED==TRUE
if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
#endif
#if GATTS_INCLUDED == TRUE
if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) {
- return;
+ goto error_exit;
}
memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));
#endif
#endif
#endif // BTA_INCLUDED == TRUE
-}
+ return BT_STATUS_SUCCESS;
-/*****************************************************************************
-**
-** Function BTE_DeinitStack
-**
-** Description Deinitialize control block memory for each component.
-**
-** Note: This API must be called
-** after freeing the BTU Task.
-**
-** Returns void
-**
-******************************************************************************/
-void BTE_DeinitStack(void)
-{
- //BTA Modules
-#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
-#if GATTS_INCLUDED == TRUE
- osi_free(bta_gatts_cb_ptr);
- bta_gatts_cb_ptr = NULL;
-#endif
-#if GATTC_INCLUDED==TRUE
- osi_free(bta_gattc_cb_ptr);
- bta_gattc_cb_ptr = NULL;
-#endif
-#if BTA_HH_INCLUDED==TRUE
- osi_free(bta_hh_cb_ptr);
- bta_hh_cb_ptr = NULL;
-#endif
-#if BTA_AV_INCLUDED==TRUE
- osi_free(bta_av_cb_ptr);
- bta_av_cb_ptr = NULL;
- osi_free(bta_av_sbc_ups_cb_ptr);
- bta_av_sbc_ups_cb_ptr = NULL;
-#endif
-#if BTA_AR_INCLUDED==TRUE
- osi_free(bta_ar_cb_ptr);
- bta_ar_cb_ptr = NULL;
-#endif
-#if SDP_INCLUDED == TRUE
- osi_free(g_disc_raw_data_buf);
- g_disc_raw_data_buf = NULL;
-#endif
-#if BTA_SDP_INCLUDED == TRUE
- osi_free(bta_sdp_cb_ptr);
- bta_sdp_cb_ptr = NULL;
-#endif
-#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
- osi_free(bta_jv_cb_ptr);
- bta_jv_cb_ptr = NULL;
-#endif //JV
-#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
- osi_free(bta_hf_client_cb_ptr);
- bta_hf_client_cb_ptr = NULL;
-#endif
- osi_free(bta_dm_conn_srvcs_ptr);
- bta_dm_conn_srvcs_ptr = NULL;
- osi_free(bta_dm_di_cb_ptr);
- bta_dm_di_cb_ptr = NULL;
- osi_free(bta_dm_search_cb_ptr);
- bta_dm_search_cb_ptr = NULL;
- osi_free(bta_dm_cb_ptr);
- bta_dm_cb_ptr = NULL;
- osi_free(bta_sys_cb_ptr);
- bta_sys_cb_ptr = NULL;
-#endif // BTA_INCLUDED == TRUE
-
-#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
- GAP_Deinit();
-#endif
-
-#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
- osi_free(avct_cb_ptr);
- avct_cb_ptr = NULL;
-#endif
-
-#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
- osi_free(avdt_cb_ptr);
- avdt_cb_ptr = NULL;
-#endif
-
-#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
- AVRC_Deinit();
-#endif
-
-#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
- A2D_Deinit();
-#endif
-
-#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
- RFCOMM_Deinit();
-#endif
+error_exit:;
+ LOG_ERROR("%s failed due to no memory", __func__);
+ BTE_DeinitStack();
+ return BT_STATUS_NOMEM;
}
** other API functions for this layer. It is typically called
** once during the start up of the stack.
**
-** Returns void
+** Returns status
**
*******************************************************************************/
-void A2D_Init(void)
+bt_status_t A2D_Init(void)
{
#if (A2D_DYNAMIC_MEMORY)
a2d_cb_ptr = (tA2D_CB *)osi_malloc(sizeof(tA2D_CB));
+ if (!a2d_cb_ptr) {
+ return BT_STATUS_NOMEM;
+ }
#endif /* #if (A2D_DYNAMIC_MEMORY) */
memset(&a2d_cb, 0, sizeof(tA2D_CB));
#else
a2d_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif
+ return BT_STATUS_SUCCESS;
}
/*******************************************************************************
void A2D_Deinit(void)
{
#if (A2D_DYNAMIC_MEMORY)
- osi_free(a2d_cb_ptr);
- a2d_cb_ptr = NULL;
+ if (a2d_cb_ptr) {
+ osi_free(a2d_cb_ptr);
+ a2d_cb_ptr = NULL;
+ }
#endif /* #if (A2D_DYNAMIC_MEMORY) */
}
** control block (if using dynamic memory), and initializes the
** control block and tracing level.
**
-** Returns void
+** Returns status
**
*******************************************************************************/
-void AVRC_Init(void)
+bt_status_t AVRC_Init(void)
{
#if AVRC_DYNAMIC_MEMORY
avrc_cb_ptr = (tAVRC_CB *)osi_malloc(sizeof(tAVRC_CB));
+ if (!avrc_cb_ptr) {
+ return BT_STATUS_NOMEM;
+ }
#endif /* #if AVRC_DYNAMIC_MEMORY */
memset(&avrc_cb, 0, sizeof(tAVRC_CB));
#else
avrc_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif
+ return BT_STATUS_SUCCESS;
}
/*******************************************************************************
void AVRC_Deinit(void)
{
#if AVRC_DYNAMIC_MEMORY
- osi_free(avrc_cb_ptr);
- avrc_cb_ptr = NULL;
+ if (avrc_cb_ptr){
+ osi_free(avrc_cb_ptr);
+ avrc_cb_ptr = NULL;
+ }
#endif /* #if AVRC_DYNAMIC_MEMORY */
}
uint8_t scan_enable_status = 0;
uint8_t scan_param_status = 0;
-void btm_lock_init(void)
+void btm_ble_lock_init(void)
{
osi_mutex_new(&adv_enable_lock);
osi_mutex_new(&adv_data_lock);
osi_mutex_new(&scan_param_lock);
}
-void btm_lock_free(void)
+void btm_ble_lock_free(void)
{
osi_mutex_free(&adv_enable_lock);
osi_mutex_free(&adv_data_lock);
osi_mutex_free(&scan_param_lock);
}
-void btm_sem_init(void)
+void btm_ble_sem_init(void)
{
osi_sem_new(&adv_enable_sem, 1, 0);
osi_sem_new(&adv_data_sem, 1, 0);
osi_sem_new(&scan_param_sem, 1, 0);
}
-void btm_sem_free(void)
+void btm_ble_sem_free(void)
{
osi_sem_free(&adv_enable_sem);
osi_sem_free(&adv_data_sem);
void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
tBTM_CMPL_CB *p_vsc_cplt_cback)
{
+#if (BLE_INCLUDED == TRUE)
tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb;
switch(opcode) {
case HCI_VENDOR_BLE_LONG_ADV_DATA:
vcs_cplt_params.p_param_buf = p;
(*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
}
+#endif
}
/*******************************************************************************
#endif
btm_dev_init(); /* Device Manager Structures & HCI_Reset */
- btm_lock_init();
- btm_sem_init();
+#if BLE_INCLUDED == TRUE
+ btm_ble_lock_init();
+ btm_ble_sem_init();
+#endif
}
#if BTM_DYNAMIC_MEMORY
FREE_AND_RESET(btm_cb_ptr);
#endif
- btm_lock_free();
- btm_sem_free();
+#if BLE_INCLUDED == TRUE
+ btm_ble_lock_free();
+ btm_ble_sem_free();
+#endif
}
UINT8 btm_sec_clr_service_by_psm (UINT16 psm);
void btm_sec_clr_temp_auth_service (BD_ADDR bda);
-void btm_lock_init(void);
+void btm_ble_lock_init(void);
-void btm_sem_init(void);
+void btm_ble_sem_init(void);
-void btm_sem_free(void);
+void btm_ble_sem_free(void);
-void btm_lock_free(void);
+void btm_ble_lock_free(void);
/*
#ifdef __cplusplus
extern void PLATFORM_DisableHciTransport(UINT8 bDisable);
extern void btu_task_thread_handler(void *arg);
-void btu_task_start_up(void);
+void btu_task_start_up(void * param);
void btu_task_shut_down(void);
/*****************************************************************************
BTU_ShutDown();
}
+/*****************************************************************************
+**
+** Function BTU_ShutDown
+**
+** Description Deinitializes the BTU control block.
+**
+** Returns void
+**
+******************************************************************************/
void BTU_ShutDown(void)
{
#if BTU_DYNAMIC_MEMORY
//#include "bt_app_common.h"
//#endif
-extern void BTE_InitStack(void);
+extern bt_status_t BTE_InitStack(void);
extern void BTE_DeinitStack(void);
/* Define BTU storage area
/* Define a function prototype to allow a generic timeout handler */
typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle);
-static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle);
-static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle);
-static void btu_hci_msg_process(BT_HDR *p_msg);
+static void btu_l2cap_alarm_process(void *param);
+static void btu_general_alarm_process(void *param);
+static void btu_hci_msg_process(void *param);
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
-static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle);
+static void btu_bta_alarm_process(void *param);
#endif
-static void btu_hci_msg_process(BT_HDR *p_msg)
+static void btu_hci_msg_process(void *param)
{
/* Determine the input message type. */
+ BT_HDR *p_msg = (BT_HDR *)param;
+
switch (p_msg->event & BT_EVT_MASK) {
case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this
{
}
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
-static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle)
+static void btu_bta_alarm_process(void *param)
{
+ TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
// call timer callback
if (p_tle->p_cback) {
(*p_tle->p_cback)(p_tle);
}
#endif
-void btu_thread_handler(void *arg)
+bool btu_task_post(uint32_t sig, void *param, uint32_t timeout)
{
- btu_thread_evt_t *evt = (btu_thread_evt_t *)arg;
+ bool status = false;
- switch (evt->sig) {
+ switch (sig) {
case SIG_BTU_START_UP:
- btu_task_start_up();
+ status = osi_thread_post(btu_thread, btu_task_start_up, param, 0, timeout);
break;
case SIG_BTU_HCI_MSG:
- btu_hci_msg_process((BT_HDR *)evt->param);
+ status = osi_thread_post(btu_thread, btu_hci_msg_process, param, 0, timeout);
break;
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
case SIG_BTU_BTA_MSG:
- bta_sys_event((BT_HDR *)evt->param);
+ status = osi_thread_post(btu_thread, bta_sys_event, param, 0, timeout);
break;
case SIG_BTU_BTA_ALARM:
- btu_bta_alarm_process((TIMER_LIST_ENT *)evt->param);
+ status = osi_thread_post(btu_thread, btu_bta_alarm_process, param, 0, timeout);
break;
#endif
case SIG_BTU_GENERAL_ALARM:
case SIG_BTU_ONESHOT_ALARM:
- btu_general_alarm_process((TIMER_LIST_ENT *)evt->param);
+ status = osi_thread_post(btu_thread, btu_general_alarm_process, param, 0, timeout);
break;
case SIG_BTU_L2CAP_ALARM:
- btu_l2cap_alarm_process((TIMER_LIST_ENT *)evt->param);
+ status = osi_thread_post(btu_thread, btu_l2cap_alarm_process, param, 0, timeout);
break;
default:
break;
}
- osi_free(evt);
-}
-
-bool btu_task_post(uint32_t sig, void *param, uint32_t timeout)
-{
- btu_thread_evt_t *evt;
-
- evt = (btu_thread_evt_t *)osi_malloc(sizeof(btu_thread_evt_t));
- if (evt == NULL) {
- return false;
- }
-
- evt->sig = sig;
- evt->param = param;
-
- return osi_thread_post(btu_thread, btu_thread_handler, evt, 0, timeout);
+ return status;
}
-void btu_task_start_up(void)
+void btu_task_start_up(void *param)
{
+ UNUSED(param);
/* Initialize the mandatory core stack control blocks
(BTU, BTM, L2CAP, and SDP)
*/
** Returns void
**
*******************************************************************************/
-static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle)
+static void btu_general_alarm_process(void *param)
{
+ TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
assert(p_tle != NULL);
switch (p_tle->event) {
** Returns void
**
*******************************************************************************/
-static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle)
+static void btu_l2cap_alarm_process(void *param)
{
+ TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
assert(p_tle != NULL);
switch (p_tle->event) {
** This routine should not be called except once per
** stack invocation.
**
-** Returns Nothing
+** Returns status
**
*******************************************************************************/
-void GAP_Init(void)
+bt_status_t GAP_Init(void)
{
#if GAP_DYNAMIC_MEMORY == TRUE
gap_cb_ptr = (tGAP_CB *)osi_malloc(sizeof(tGAP_CB));
+ if (!gap_cb_ptr) {
+ return BT_STATUS_NOMEM;
+ }
#endif
memset (&gap_cb, 0, sizeof (tGAP_CB));
#if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
gap_attr_db_init();
#endif
+
+ return BT_STATUS_SUCCESS;
}
/*******************************************************************************
void GAP_Deinit(void)
{
#if GAP_DYNAMIC_MEMORY == TRUE
- osi_free(gap_cb_ptr);
- gap_cb_ptr = NULL;
+ if (gap_cb_ptr) {
+ osi_free(gap_cb_ptr);
+ gap_cb_ptr = NULL;
+ }
#endif
}
\ No newline at end of file
******************************************************************************/
#ifndef A2D_API_H
#define A2D_API_H
+#include "common/bt_defs.h"
#include "stack/sdp_api.h"
#if (A2D_INCLUDED == TRUE)
/*****************************************************************************
** Returns void
**
*******************************************************************************/
-extern void A2D_Init(void);
+extern bt_status_t A2D_Init(void);
extern void A2D_Deinit(void);
#endif ///A2D_INCLUDED
#endif /* A2D_API_H */
#ifndef AVRC_API_H
#define AVRC_API_H
#include "common/bt_target.h"
+#include "common/bt_defs.h"
#include "stack/avct_api.h"
#include "stack/sdp_api.h"
#include "stack/avrc_defs.h"
** control block (if using dynamic memory), and initializes the
** control block and tracing level.
**
-** Returns void
+** Returns status
**
*******************************************************************************/
-extern void AVRC_Init(void);
+extern bt_status_t AVRC_Init(void);
/*******************************************************************************
**
void BTU_StartUp(void);
void BTU_ShutDown(void);
-void btu_task_start_up(void);
+void btu_task_start_up(void *param);
void btu_task_shut_down(void);
UINT16 BTU_BleAclPktSize(void);
** This routine should not be called except once per
** stack invocation.
**
-** Returns Nothing
+** Returns status
**
*******************************************************************************/
-extern void GAP_Init(void);
+extern bt_status_t GAP_Init(void);
/*******************************************************************************
**
#define PORT_API_H
#include "common/bt_target.h"
+#include "common/bt_defs.h"
/*****************************************************************************
** Constants and Types
** Description This function is called to initialize RFCOMM layer
**
*******************************************************************************/
-extern void RFCOMM_Init (void);
+extern bt_status_t RFCOMM_Init (void);
/*******************************************************************************
**
**
** Description This function is called to initialize RFCOMM layer
**
+** Returns status
+**
*******************************************************************************/
-void RFCOMM_Init (void)
+bt_status_t RFCOMM_Init (void)
{
#if RFC_DYNAMIC_MEMORY == TRUE
rfc_cb_ptr = (tRFC_CB *)osi_malloc(sizeof(tRFC_CB));
+ if (rfc_cb_ptr == NULL) {
+ return BT_STATUS_NOMEM;
+ }
#endif /* #if (RFC_DYNAMIC_MEMORY) */
memset (&rfc_cb, 0, sizeof (tRFC_CB)); /* Init RFCOMM control block */
#endif
rfcomm_l2cap_if_init ();
+ return BT_STATUS_SUCCESS;
}
/*******************************************************************************
void RFCOMM_Deinit(void)
{
#if RFC_DYNAMIC_MEMORY == TRUE
- osi_free(rfc_cb_ptr);
- rfc_cb_ptr = NULL;
+ if (rfc_cb_ptr){
+ osi_free(rfc_cb_ptr);
+ rfc_cb_ptr = NULL;
+ }
#endif
}
tSMP_EVT_DATA evt_data = {0};
tSMP_CALLBACK *p_callback = p_cb->p_callback;
BD_ADDR pairing_bda;
- tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda);
SMP_TRACE_DEBUG ("smp_proc_pairing_cmpl \n");
evt_data.cmplt.reason = p_cb->status;
evt_data.cmplt.smp_over_br = p_cb->smp_over_br;
evt_data.cmplt.auth_mode = 0;
+#if (BLE_INCLUDED == TRUE)
+ tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda);
if (p_cb->status == SMP_SUCCESS) {
evt_data.cmplt.sec_level = p_cb->sec_level;
if (p_cb->auth_mode) { // the first encryption
evt_data.cmplt.auth_mode = p_rec->ble.auth_mode;
}
}
+#else
+ if (p_cb->status == SMP_SUCCESS) {
+ evt_data.cmplt.sec_level = p_cb->sec_level;
+ evt_data.cmplt.auth_mode = p_cb->auth_mode;
+ }
+#endif
evt_data.cmplt.is_pair_cancel = FALSE;