From 1f6b0b35f83d1d3f3615c5aeee21f452ea43875d Mon Sep 17 00:00:00 2001 From: buxtronix Date: Wed, 30 Sep 2020 22:21:59 +1000 Subject: [PATCH] Have BLECLient gattc event handlers verify conn_id (#4064) Co-authored-by: Me No Dev --- libraries/BLE/src/BLEClient.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/BLE/src/BLEClient.cpp b/libraries/BLE/src/BLEClient.cpp index e13b8d62..06bbc1d6 100644 --- a/libraries/BLE/src/BLEClient.cpp +++ b/libraries/BLE/src/BLEClient.cpp @@ -178,8 +178,7 @@ void BLEClient::gattClientEventHandler( // - uint16_t conn_id // - esp_bd_addr_t remote_bda case ESP_GATTC_DISCONNECT_EVT: { - if (evtParam->disconnect.conn_id != m_conn_id) - break; + if (evtParam->disconnect.conn_id != getConnId()) break; // If we receive a disconnect event, set the class flag that indicates that we are // no longer connected. m_isConnected = false; @@ -229,6 +228,7 @@ void BLEClient::gattClientEventHandler( } // ESP_GATTC_REG_EVT case ESP_GATTC_CFG_MTU_EVT: + if (evtParam->cfg_mtu.conn_id != getConnId()) break; if(evtParam->cfg_mtu.status != ESP_GATT_OK) { log_e("Config mtu failed"); } @@ -236,6 +236,7 @@ void BLEClient::gattClientEventHandler( break; case ESP_GATTC_CONNECT_EVT: { + if (evtParam->connect.conn_id != getConnId()) break; BLEDevice::updatePeerDevice(this, true, m_gattc_if); esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id); if (errRc != ESP_OK) { @@ -257,6 +258,7 @@ void BLEClient::gattClientEventHandler( // - uint16_t conn_id // case ESP_GATTC_SEARCH_CMPL_EVT: { + if (evtParam->search_cmpl.conn_id != getConnId()) break; esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam; if (p_data->search_cmpl.status != ESP_GATT_OK){ log_e("search service failed, error status = %x", p_data->search_cmpl.status); @@ -287,6 +289,7 @@ void BLEClient::gattClientEventHandler( // - esp_gatt_id_t srvc_id // case ESP_GATTC_SEARCH_RES_EVT: { + if (evtParam->search_res.conn_id != getConnId()) break; BLEUUID uuid = BLEUUID(evtParam->search_res.srvc_id); BLERemoteService* pRemoteService = new BLERemoteService( evtParam->search_res.srvc_id,