Skip to content

Commit

Permalink
Merge branch 'bugfix/btdm_controller_deinit_v3.0' into 'release/v3.0'
Browse files Browse the repository at this point in the history
bt : fix bug that bluetooth controller init/disable/enable/disable may cause exception

See merge request idf/esp-idf!3149
  • Loading branch information
jack0c committed Sep 4, 2018
2 parents 7c42b55 + a9c1820 commit 405b198
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
5 changes: 5 additions & 0 deletions components/bt/bluedroid/hci/hci_hal_h4.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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)
Expand Down Expand Up @@ -260,6 +261,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) {
Expand Down
21 changes: 6 additions & 15 deletions components/bt/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,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);
Expand Down Expand Up @@ -748,9 +748,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);

Expand Down Expand Up @@ -806,21 +804,14 @@ 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;
}

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) {
esp_phy_rf_deinit();
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
}
esp_phy_rf_deinit();
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;

#ifdef CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
Expand Down
2 changes: 1 addition & 1 deletion components/bt/lib
Submodule lib updated 1 files
+ libbtdm_app.a

0 comments on commit 405b198

Please sign in to comment.