From 9f252c7befa9175d3c8ae899cbad13c2231d6ce2 Mon Sep 17 00:00:00 2001 From: jhchun Date: Tue, 21 Apr 2026 16:54:51 +0900 Subject: [PATCH] =?UTF-8?q?BLE=20=EC=97=B0=EA=B2=B0=20=ED=95=B4=EC=A0=9C?= =?UTF-8?q?=20=ED=97=AC=ED=8D=BC=20=ED=95=A8=EC=88=98=20=EB=B0=8F=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EB=B3=84=20=EB=B6=84=EA=B8=B0=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/security/ble_quick_security.c | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/project/ble_peripheral/ble_app_bladder_patch/system/security/ble_quick_security.c b/project/ble_peripheral/ble_app_bladder_patch/system/security/ble_quick_security.c index 07ed623..9eed181 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/system/security/ble_quick_security.c +++ b/project/ble_peripheral/ble_app_bladder_patch/system/security/ble_quick_security.c @@ -20,6 +20,22 @@ static struct { bool bonds_delete_pending; } m_state = {0}; +static const char * sec_error_name(pm_sec_error_code_t error) +{ + switch (error) { + case PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING: + return "PIN_OR_KEY_MISSING"; + case PM_CONN_SEC_ERROR_MIC_FAILURE: + return "MIC_FAILURE"; + case PM_CONN_SEC_ERROR_DISCONNECT: + return "DISCONNECT"; + case PM_CONN_SEC_ERROR_SMP_TIMEOUT: + return "SMP_TIMEOUT"; + default: + return "UNKNOWN"; + } +} + /** * @brief Initialize BLE security */ @@ -102,8 +118,9 @@ void ble_security_quick_pm_handler(pm_evt_t const *p_evt) // DEV mode: do not forward security failure events to SDK handler (prevent disconnect) if (m_state.dev_mode && p_evt->evt_id == PM_EVT_CONN_SEC_FAILED) { - DBG_PRINTF("Security failed: error=%d\r\n", - p_evt->params.conn_sec_failed.error); + DBG_PRINTF("Security failed: error=%d (%s)\r\n", + p_evt->params.conn_sec_failed.error, + sec_error_name(p_evt->params.conn_sec_failed.error)); DBG_PRINTF("DEV: Ignoring sec failure, keeping connection\r\n"); return; } @@ -129,8 +146,9 @@ void ble_security_quick_pm_handler(pm_evt_t const *p_evt) break; case PM_EVT_CONN_SEC_FAILED: - DBG_PRINTF("Security failed: error=%d\r\n", - p_evt->params.conn_sec_failed.error); + DBG_PRINTF("Security failed: error=%d (%s)\r\n", + p_evt->params.conn_sec_failed.error, + sec_error_name(p_evt->params.conn_sec_failed.error)); if (m_state.dev_mode) { // DEV mode: ignore security failure, keep connection @@ -138,6 +156,20 @@ void ble_security_quick_pm_handler(pm_evt_t const *p_evt) break; } + if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_DISCONNECT) { + // The peer/link already disconnected before security finished. + // There is no live connection to repair; BLE_GAP_EVT_DISCONNECTED + // will restart advertising. + DBG_PRINTF("Security ended by disconnect; waiting for reconnect\r\n"); + break; + } + + if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_SMP_TIMEOUT) { + // The SDK cannot start another SMP procedure on this link. + pm_handler_disconnect_on_sec_failure(p_evt); + break; + } + if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING) { // Key missing: attempt re-pairing, fall back to disconnect on failure err_code = pm_conn_secure(p_evt->conn_handle, true);