From 28496714934b9fd8d545a0ec86508267e39a567a Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 8 Nov 2023 18:55:33 +0530 Subject: [PATCH] Initate pairing if encryption fails with reason no pin or key missing --- nimble/host/src/ble_sm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c index 7c68e0f62..cfdeb8797 100644 --- a/nimble/host/src/ble_sm.c +++ b/nimble/host/src/ble_sm.c @@ -937,6 +937,8 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res, struct ble_sm_proc *prev; struct ble_sm_proc *proc; int rm; + ble_hs_conn_flags_t conn_flags; + struct ble_hs_conn *conn; rm = 0; @@ -981,6 +983,22 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res, break; } + if (res->app_status == 518 ) { + conn = ble_hs_conn_find(conn_handle); + + conn_flags = conn->bhc_flags; + + ble_sm_proc_free(proc); + + if (conn_flags & BLE_HS_CONN_F_MASTER) { + ble_sm_pair_initiate(conn_handle); + } + else { + ble_sm_slave_initiate(conn_handle); + } + break; + } + if (res->enc_cb) { BLE_HS_DBG_ASSERT(proc == NULL || rm); ble_gap_enc_event(conn_handle, res->app_status, res->restore, res->bonded);