From 50fe55ca598088c604990fbbd96215562a79c34f Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Mon, 21 Jul 2025 17:10:48 +0800 Subject: [PATCH] fix(ble/bluedroid): set sec_conn only on successful pairing in ble_hid_device_demo --- .../ble/ble_hid_device_demo/main/ble_hidd_demo_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c index 9b0df3e094..0a9240fb92 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -148,7 +148,6 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true); break; case ESP_GAP_BLE_AUTH_CMPL_EVT: - sec_conn = true; esp_bd_addr_t bd_addr; memcpy(bd_addr, param->ble_security.auth_cmpl.bd_addr, sizeof(esp_bd_addr_t)); ESP_LOGI(HID_DEMO_TAG, "remote BD_ADDR: %08x%04x",\ @@ -156,8 +155,12 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param (bd_addr[4] << 8) + bd_addr[5]); ESP_LOGI(HID_DEMO_TAG, "address type = %d", param->ble_security.auth_cmpl.addr_type); ESP_LOGI(HID_DEMO_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail"); - if(!param->ble_security.auth_cmpl.success) { - ESP_LOGE(HID_DEMO_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason); + if (param->ble_security.auth_cmpl.success) { + sec_conn = true; + ESP_LOGI(HID_DEMO_TAG, "secure connection established."); + } else { + ESP_LOGE(HID_DEMO_TAG, "pairing failed, reason = 0x%x", + param->ble_security.auth_cmpl.fail_reason); } break; default: