Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing conn_id check in bluetooth_proxy disconnect event #6590

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions esphome/components/bluetooth_proxy/bluetooth_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga

switch (event) {
case ESP_GATTC_DISCONNECT_EVT: {
this->proxy_->send_device_connection(this->address_, false, 0, param->disconnect.reason);
this->set_address(0);
this->proxy_->send_connections_free();
if (param->disconnect.conn_id != this->conn_id_)
break;
this->handle_connection_close_(param->disconnect.reason);
break;
}
case ESP_GATTC_OPEN_EVT: {
if (param->open.conn_id != this->conn_id_)
break;
if (param->open.status != ESP_GATT_OK && param->open.status != ESP_GATT_ALREADY_OPEN) {
this->proxy_->send_device_connection(this->address_, false, 0, param->open.status);
this->set_address(0);
this->proxy_->send_connections_free();
this->handle_connection_close_(param->open.status);
} else if (this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE) {
this->proxy_->send_device_connection(this->address_, true, this->mtu_);
this->proxy_->send_connections_free();
Expand Down Expand Up @@ -151,6 +149,12 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga
return true;
}

void BluetoothConnection::handle_connection_close_(esp_err_t error) {
this->proxy_->send_device_connection(this->address_, false, 0, error);
this->set_address(0);
this->proxy_->send_connections_free();
}

void BluetoothConnection::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
BLEClientBase::gap_event_handler(event, param);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BluetoothConnection : public esp32_ble_client::BLEClientBase {
protected:
friend class BluetoothProxy;
bool seen_mtu_or_services_{false};
void handle_connection_close_(esp_err_t error);

int16_t send_service_{-2};
BluetoothProxy *proxy_;
Expand Down