diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index 0a93f1d0c..5f8fc949c 100644 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -97,6 +97,7 @@ static void hci_hal_env_init( static void hci_hal_env_deinit(void) { fixed_queue_free(hci_hal_env.rx_q, hci_hal_env.allocator->free); + hci_hal_env.rx_q = NULL; } static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) @@ -302,6 +303,10 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len) BT_HDR *pkt; size_t pkt_size; + if (hci_hal_env.rx_q == NULL) { + return 0; + } + pkt_size = BT_HDR_SIZE + len; pkt = (BT_HDR *)hci_hal_env.allocator->alloc(pkt_size); if (!pkt) { diff --git a/components/bt/bt.c b/components/bt/bt.c index b90ccc8ea..65f12a92f 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -61,9 +61,9 @@ /* not for user call, so don't put to include file */ extern void btdm_osi_funcs_register(void *osi_funcs); extern int btdm_controller_init(uint32_t config_mask, esp_bt_controller_config_t *config_opts); -extern int btdm_controller_deinit(void); +extern void btdm_controller_deinit(void); extern int btdm_controller_enable(esp_bt_mode_t mode); -extern int btdm_controller_disable(esp_bt_mode_t mode); +extern void btdm_controller_disable(void); extern uint8_t btdm_controller_get_mode(void); extern const char *btdm_controller_get_compile_version(void); extern void btdm_rf_bb_init(void); @@ -880,9 +880,7 @@ esp_err_t esp_bt_controller_deinit(void) return ESP_ERR_INVALID_STATE; } - if (btdm_controller_deinit() != 0) { - return ESP_ERR_NO_MEM; - } + btdm_controller_deinit(); periph_module_disable(PERIPH_BT_MODULE); @@ -956,6 +954,9 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) esp_modem_sleep_deregister(MODEM_BLE_MODULE); } esp_phy_rf_deinit(PHY_BT_MODULE); +#ifdef CONFIG_PM_ENABLE + esp_pm_lock_release(s_pm_lock); +#endif return ESP_ERR_INVALID_STATE; } @@ -966,8 +967,6 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) esp_err_t esp_bt_controller_disable(void) { - int ret; - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { return ESP_ERR_INVALID_STATE; } @@ -983,22 +982,17 @@ esp_err_t esp_bt_controller_disable(void) } } - ret = btdm_controller_disable(btdm_controller_get_mode()); - if (ret < 0) { - return ESP_ERR_INVALID_STATE; - } + btdm_controller_disable(); - if (ret == ESP_BT_MODE_IDLE) { - if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_NONE - || btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) { - esp_modem_sleep_deregister(MODEM_BLE_MODULE); - esp_modem_sleep_deregister(MODEM_CLASSIC_BT_MODULE); - } else if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_EVED) { - esp_modem_sleep_deregister(MODEM_BLE_MODULE); - } - esp_phy_rf_deinit(PHY_BT_MODULE); - btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; + if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_NONE + || btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) { + esp_modem_sleep_deregister(MODEM_BLE_MODULE); + esp_modem_sleep_deregister(MODEM_CLASSIC_BT_MODULE); + } else if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_EVED) { + esp_modem_sleep_deregister(MODEM_BLE_MODULE); } + esp_phy_rf_deinit(PHY_BT_MODULE); + btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; #ifdef CONFIG_PM_ENABLE esp_pm_lock_release(s_pm_lock);