This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 6f8f2572e3d4101f5abae4a05a820e0672994de5
Author: Szymon Janc <[email protected]>
AuthorDate: Wed Mar 20 13:25:25 2024 +0100

    nimble/host: Connect EATT when encryption is enabled
    
    Some peers reject connection to EATT PSM if encryption is not enabled.
    Since EATT requires any PDUs to be sent only on encrypted link we
    can postpone initiating EATT connection until encryption with no real
    drawbacks.
---
 nimble/host/src/ble_eatt.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/nimble/host/src/ble_eatt.c b/nimble/host/src/ble_eatt.c
index 93ff0f5d4..21732b091 100644
--- a/nimble/host/src/ble_eatt.c
+++ b/nimble/host/src/ble_eatt.c
@@ -450,15 +450,20 @@ ble_eatt_gap_event(struct ble_gap_event *event, void *arg)
     struct ble_eatt *eatt;
 
     switch (event->type) {
-    case BLE_GAP_EVENT_CONNECT:
-        if (event->connect.status != 0) {
+    case BLE_GAP_EVENT_ENC_CHANGE:
+        if (event->enc_change.status != 0) {
             return 0;
         }
 
-        BLE_EATT_LOG_DEBUG("eatt: Device connected, waiting to write into "
-                           "client supported features\n");
+        /* don't try to connect if already connected */
+        if (ble_eatt_find_by_conn_handle(event->enc_change.conn_handle)) {
+            return 0;
+        }
+
+        BLE_EATT_LOG_DEBUG("eatt: Encryption enabled, connecting EATT 
(conn_handle=0x%04x)\n",
+                            event->enc_change.conn_handle);
 
-        ble_npl_event_set_arg(&g_read_sup_srv_feat_ev, 
UINT_TO_POINTER(event->connect.conn_handle));
+        ble_npl_event_set_arg(&g_read_sup_srv_feat_ev, 
UINT_TO_POINTER(event->enc_change.conn_handle));
         ble_npl_eventq_put(ble_hs_evq_get(), &g_read_sup_srv_feat_ev);
 
         break;

Reply via email to