]> granicus.if.org Git - esp-idf/commitdiff
components/bt: Optimization and bugfix of previous commits
authorbaohongde <baohongde@espressif.com>
Fri, 21 Jun 2019 03:55:45 +0000 (11:55 +0800)
committerbaohongde <baohongde@espressif.com>
Fri, 21 Jun 2019 03:55:45 +0000 (11:55 +0800)
29 files changed:
components/bt/bluedroid/bta/dm/bta_dm_act.c
components/bt/bluedroid/bta/dm/bta_dm_cfg.c
components/bt/bluedroid/bta/dm/bta_dm_main.c
components/bt/bluedroid/bta/dm/include/bta_dm_int.h
components/bt/bluedroid/bta/gatt/bta_gattc_co.c
components/bt/bluedroid/bta/include/bta/bta_sys.h
components/bt/bluedroid/bta/sys/bta_sys_main.c
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c
components/bt/bluedroid/btc/profile/std/include/btc_avrc.h
components/bt/bluedroid/common/include/common/bt_user_config.h
components/bt/bluedroid/device/controller.c
components/bt/bluedroid/main/bte_init.c
components/bt/bluedroid/stack/a2dp/a2d_api.c
components/bt/bluedroid/stack/avrc/avrc_sdp.c
components/bt/bluedroid/stack/btm/btm_ble_gap.c
components/bt/bluedroid/stack/btm/btm_devctl.c
components/bt/bluedroid/stack/btm/btm_main.c
components/bt/bluedroid/stack/btm/include/btm_int.h
components/bt/bluedroid/stack/btu/btu_init.c
components/bt/bluedroid/stack/btu/btu_task.c
components/bt/bluedroid/stack/gap/gap_api.c
components/bt/bluedroid/stack/include/stack/a2d_api.h
components/bt/bluedroid/stack/include/stack/avrc_api.h
components/bt/bluedroid/stack/include/stack/btu.h
components/bt/bluedroid/stack/include/stack/gap_api.h
components/bt/bluedroid/stack/include/stack/port_api.h
components/bt/bluedroid/stack/rfcomm/port_api.c
components/bt/bluedroid/stack/smp/smp_utils.c

index a6fefeacfeb281535919b3e393a67d23b2836569..acb6f6291fde31fb8a5fabd571ae9218a1c9d89d 100644 (file)
@@ -1298,7 +1298,9 @@ void bta_dm_loc_oob(tBTA_DM_MSG *p_data)
 *******************************************************************************/
 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
 }
 
 /*******************************************************************************
index 9e018de98da56d2a8f65ace8d059cb1c295b44fb..6769e7141e0c31a73f3d432d78e86c49d890a252 100644 (file)
@@ -441,4 +441,4 @@ tBTA_DM_EIR_CONF bta_dm_eir_cfg = {
     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;
index 3b9a7cc4ce510400a76c9e17e9887d32dd7421d8..d62974ea2efd3d369f4156e3c8cebe81f08e3780 100644 (file)
@@ -160,7 +160,9 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
     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
 };
 
 
index 4fc8e650ce5679eaa1ac2389bfdfe5d3809d0508..c87708e3589d1617cc08e17ff127338240c19e7f 100644 (file)
@@ -157,7 +157,9 @@ enum {
     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
 };
 
index 06c51b07e813f7e79c112f6e1a595199a3d5fbe6..a336c2314783e1f3899837a2d9fb21815cf31218 100644 (file)
@@ -269,8 +269,8 @@ tBTA_GATT_STATUS bta_gattc_co_cache_load(tBTA_GATTC_NV_ATTR *attr, UINT8 index)
     // 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;
index a58773de734d28f1a709222b168ad2e1a7ee97d9..a466028b95732e3931b67c581447269e8a428ad9 100644 (file)
@@ -215,7 +215,7 @@ extern "C" {
 
 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);
index c00abd7394273c9934ea47ee2fe956af3374b52d..1ea2ccd702ae5ebe2c8036495e2c28d8f9662dd8 100644 (file)
@@ -482,8 +482,10 @@ void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
 ** 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;
 
index cb8616d9b03d12ef563b053f829c22d9794c9828..df1e1ddfdc88e872dbc1935484c9df0926bb61e8 100644 (file)
@@ -176,95 +176,121 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
 }
 
 #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)
 {
index 841d55c3600d20fc3bbc6cfeebd4e9aaf53d5757..28ecb85e630ab81b45fcba3ccca2eed6ef2d42c6 100644 (file)
@@ -1002,8 +1002,6 @@ static void btc_avrc_ct_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;
     }
 }
 
index 7d72393d8278d3c051e637c90501f9d07a8bb927..ec98c5ee5619c4779dc0d6dfe0eb67452ef79ee4 100644 (file)
@@ -98,7 +98,7 @@ typedef enum {
 
 #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; \
         } \
index 5fdc1c2183a0bd581a4cba483b6f545b3538b207..7fa8ed5c51f98c2222bc1c2eaf08aabd8d35851f 100644 (file)
@@ -15,9 +15,6 @@
 #ifndef __BT_USER_CONFIG_H__
 #define __BT_USER_CONFIG_H__
 
-
-
-
 /* All the configuration from SDK defined here */
 
 #include "sdkconfig.h"
@@ -86,6 +83,7 @@
 #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__ */
 
 
index df6c5018f6de9d0213cbdde4d1572aa222d2c2a1..84d6f59737e342fdae77da3035c31ab9c1e1b972 100644 (file)
@@ -111,8 +111,8 @@ static void start_up(void)
 #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?
index 1d6e99429198805cda5090b391c8ffae930813fb..7f3723ae557e7a05fc82dbefeadd9a0a1cd31a43 100644 (file)
 **                          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
@@ -176,29 +305,35 @@ void BTE_InitStack(void)
 
     //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)
@@ -212,19 +347,19 @@ void BTE_InitStack(void)
     //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));
@@ -235,13 +370,13 @@ void BTE_InitStack(void)
 
 #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
@@ -250,36 +385,36 @@ void BTE_InitStack(void)
 #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
@@ -288,13 +423,13 @@ void BTE_InitStack(void)
 #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
@@ -303,97 +438,10 @@ void BTE_InitStack(void)
 #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;
 }
index 937e46b1e1df490383f453350c9e7b9cc4d73ea6..8adb200dcda29418d22f69a0995d8ae69bef40f9 100644 (file)
@@ -372,13 +372,16 @@ UINT8 A2D_BitsSet(UINT8 num)
 **                  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));
 
@@ -389,6 +392,7 @@ void A2D_Init(void)
 #else
     a2d_cb.trace_level  = BT_TRACE_LEVEL_NONE;
 #endif
+    return BT_STATUS_SUCCESS;
 }
 
 /*******************************************************************************
@@ -404,8 +408,10 @@ void A2D_Init(void)
 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) */
 }
 
index d3616f3233ba32c8176cf84a5453d62c0f514f1a..11a994d7acbb1272e0f2bc51e46c1db326a57cc3 100644 (file)
@@ -340,13 +340,16 @@ UINT8 AVRC_SetTraceLevel (UINT8 new_level)
 **                  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));
 
@@ -355,6 +358,7 @@ void AVRC_Init(void)
 #else
     avrc_cb.trace_level  = BT_TRACE_LEVEL_NONE;
 #endif
+    return BT_STATUS_SUCCESS;
 }
 
 /*******************************************************************************
@@ -371,8 +375,10 @@ void AVRC_Init(void)
 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 */
 }
 
index e7a4ba955b7a639514195e5e670f6ac771ae3e40..5a7f60da94924091b5014ec0e12e5f7f99dc748d 100644 (file)
@@ -246,7 +246,7 @@ uint8_t adv_param_status   = 0;
 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);
@@ -255,7 +255,7 @@ void btm_lock_init(void)
     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);
@@ -264,7 +264,7 @@ void btm_lock_free(void)
     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);
@@ -273,7 +273,7 @@ void btm_sem_init(void)
     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);
index 23be3eb30316575e432bcbc221219602ed942a98..437a3cd1a3bd752ad0ae2c80015c8d3976b96f94 100644 (file)
@@ -693,6 +693,7 @@ tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
 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:
@@ -721,6 +722,7 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
         vcs_cplt_params.p_param_buf = p;
         (*p_vsc_cplt_cback)(&vcs_cplt_params);  /* Call the VSC complete callback function */
     }
+#endif
 }
 
 /*******************************************************************************
index b6b853d5c609b00d9b9dc24e2a8167241bb46920..cf950f21a966dcbdd9a0852638910e2b10aa08e6 100644 (file)
@@ -75,8 +75,10 @@ void btm_init (void)
 #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
 }
 
 
@@ -96,6 +98,8 @@ void btm_free(void)
 #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
 }
index f575d8958a440aad0c32f5875b0c35b2b28cd120..4ef7285084b94b4d63200c486c1c13a770b6b710 100644 (file)
@@ -1148,13 +1148,13 @@ void  btm_acl_paging (BT_HDR *p, BD_ADDR dest);
 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
index 455cc9fe6ae15f63ae7ff0ea75ec5824edb20fc1..617bb5de6638b53744eb6f5d7b6371af45fcd29f 100644 (file)
@@ -66,7 +66,7 @@ osi_thread_t *btu_thread = NULL;
 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);
 
 /*****************************************************************************
@@ -197,6 +197,15 @@ error_exit:;
     BTU_ShutDown();
 }
 
+/*****************************************************************************
+**
+** Function         BTU_ShutDown
+**
+** Description      Deinitializes the BTU control block.
+**
+** Returns          void
+**
+******************************************************************************/
 void BTU_ShutDown(void)
 {
 #if BTU_DYNAMIC_MEMORY
index 40448357d51e16f3f290f29be4623126e046cc59..3e73cbb85ca8eeb78cb9a413388988b9e5ffbaeb 100644 (file)
@@ -90,7 +90,7 @@ typedef struct {
 //#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
@@ -119,17 +119,19 @@ extern bluedroid_init_done_cb_t bluedroid_init_done_cb;
 /* 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
       {
@@ -196,8 +198,9 @@ static void btu_hci_msg_process(BT_HDR *p_msg)
 }
 
 #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);
@@ -213,56 +216,42 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *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)
      */
@@ -305,8 +294,9 @@ void btu_task_shut_down(void)
 ** 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) {
@@ -511,8 +501,9 @@ void btu_free_timer(TIMER_LIST_ENT *p_tle)
 ** 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) {
index 69b5d9629bb872f391dda7d978d247e72d44b9af..b4e7c1b4fb2e9c1f50d13c4e2dafdfe266cb4f46 100644 (file)
@@ -57,13 +57,16 @@ UINT8 GAP_SetTraceLevel (UINT8 new_level)
 **                  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));
@@ -81,6 +84,8 @@ void GAP_Init(void)
 #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
     gap_attr_db_init();
 #endif
+
+    return BT_STATUS_SUCCESS;
 }
 
 /*******************************************************************************
@@ -96,7 +101,9 @@ void GAP_Init(void)
 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
index 7509544fb5ab5a6aba6be1976ccc0193e958a96e..466f9fad7296b9ebb2b5cec4d91942cb22e86945 100644 (file)
@@ -23,6 +23,7 @@
  ******************************************************************************/
 #ifndef A2D_API_H
 #define A2D_API_H
+#include "common/bt_defs.h"
 #include "stack/sdp_api.h"
 #if (A2D_INCLUDED == TRUE)
 /*****************************************************************************
@@ -250,7 +251,7 @@ extern UINT8 A2D_BitsSet(UINT8 num);
 ** 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 */
index 85e8db1b2ea2d59c266db74a2f12cc453160c6de..cbbb4b1c696d01ead961d3025c05b38ae1d98903 100644 (file)
@@ -24,6 +24,7 @@
 #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"
@@ -549,10 +550,10 @@ extern UINT8 AVRC_SetTraceLevel (UINT8 new_level);
 **                  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);
 
 /*******************************************************************************
 **
index b3269e2ca6aaeeffe399d4e9deda939d65d7e06f..fd5d1c989d167e616cf548cd2b76fa3005f6689e 100644 (file)
@@ -283,7 +283,7 @@ void  btu_free_core(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);
index 03af2956ce0f80f85da2635d4b1f5580c692b460..62062d2f21be20452d8509655c3310c0eef8e5eb 100644 (file)
@@ -320,10 +320,10 @@ extern UINT8 GAP_SetTraceLevel (UINT8 new_level);
 **                  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);
 
 /*******************************************************************************
 **
index 8145a177a0f79b2d53064e2414aa9be1428cd38c..145ef2288907d4f20db79ce530c2661e080eac7b 100644 (file)
@@ -25,6 +25,7 @@
 #define PORT_API_H
 
 #include "common/bt_target.h"
+#include "common/bt_defs.h"
 
 /*****************************************************************************
 **  Constants and Types
@@ -621,7 +622,7 @@ extern int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len);
 ** Description      This function is called to initialize RFCOMM layer
 **
 *******************************************************************************/
-extern void RFCOMM_Init (void);
+extern bt_status_t RFCOMM_Init (void);
 
 /*******************************************************************************
 **
index f6e0ed4d4f0d26b69722c1a8c9d7ba2c3e858f99..dacf544b9b975932f3b66ea4a5bd725c429e366b 100644 (file)
@@ -1711,11 +1711,16 @@ int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len)
 **
 ** 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 */
 
@@ -1728,6 +1733,7 @@ void RFCOMM_Init (void)
 #endif
 
     rfcomm_l2cap_if_init ();
+    return BT_STATUS_SUCCESS;
 }
 
 /*******************************************************************************
@@ -1743,8 +1749,10 @@ void RFCOMM_Init (void)
 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
 }
 
index 5edf0b8ab21643cd51f13f6049fdd1c0cde58fef..165b11a2a3353901c7e451b17819dfa4ac66bef0 100644 (file)
@@ -974,13 +974,14 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb)
     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
@@ -992,6 +993,12 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb)
             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;