nimble/sm: Store encryption key size in link security state

Encryption key size is stored in link security state so it can be
accessed in other code (e.g. ATT).


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a9deae13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a9deae13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a9deae13

Branch: refs/heads/develop
Commit: a9deae139837af5089582c60f9464ba01cb6dc83
Parents: 8f6e37f
Author: Andrzej Kaczmarek <[email protected]>
Authored: Tue Jan 3 15:22:54 2017 +0100
Committer: Andrzej Kaczmarek <[email protected]>
Committed: Wed Jan 4 14:14:24 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h |  1 +
 net/nimble/host/src/ble_sm.c           | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9deae13/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h 
b/net/nimble/host/include/host/ble_gap.h
index 7ff86af..08d4a8a 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -131,6 +131,7 @@ struct ble_gap_sec_state {
     unsigned encrypted:1;
     unsigned authenticated:1;
     unsigned bonded:1;
+    unsigned key_size:5;
 };
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9deae13/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index dbdc7de..4c717c6 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -416,7 +416,7 @@ ble_sm_proc_remove(struct ble_sm_proc *proc,
 
 static void
 ble_sm_update_sec_state(uint16_t conn_handle, int encrypted,
-                        int authenticated, int bonded)
+                        int authenticated, int bonded, int key_size)
 {
     struct ble_hs_conn *conn;
 
@@ -431,6 +431,10 @@ ble_sm_update_sec_state(uint16_t conn_handle, int 
encrypted,
         if (bonded) {
             conn->bhc_sec_state.bonded = 1;
         }
+
+        if (key_size) {
+            conn->bhc_sec_state.key_size = key_size;
+        }
     }
 }
 
@@ -892,12 +896,14 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t 
evt_status, int encrypted)
     struct ble_sm_proc *proc;
     int authenticated;
     int bonded;
+    int key_size;
 
     memset(&res, 0, sizeof res);
 
     /* Assume no change in authenticated and bonded statuses. */
     authenticated = 0;
     bonded = 0;
+    key_size = 0;
 
     ble_hs_lock();
 
@@ -918,6 +924,8 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t 
evt_status, int encrypted)
 
                     res.execute = 1;
                 }
+
+                key_size = proc->key_size;
             } else {
                 /* Failure or no keys to exchange; procedure is complete. */
                 proc->state = BLE_SM_PROC_STATE_NONE;
@@ -939,6 +947,8 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t 
evt_status, int encrypted)
             }
             bonded = 1;
             res.restore = 1;
+
+            key_size = proc->key_size;
             break;
 
         default:
@@ -956,7 +966,8 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t 
evt_status, int encrypted)
         /* Set the encrypted state of the connection as indicated in the
          * event.
          */
-        ble_sm_update_sec_state(conn_handle, encrypted, authenticated, bonded);
+        ble_sm_update_sec_state(conn_handle, encrypted, authenticated, bonded,
+                                key_size);
     }
 
     /* Unless keys need to be exchanged, notify the application of the security
@@ -1656,7 +1667,7 @@ ble_sm_key_exch_success(struct ble_sm_proc *proc, struct 
ble_sm_result *res)
     /* The procedure is now complete.  Update connection bonded state and
      * terminate procedure.
      */
-    ble_sm_update_sec_state(proc->conn_handle, 1, 0, 1);
+    ble_sm_update_sec_state(proc->conn_handle, 1, 0, 1, proc->key_size);
     proc->state = BLE_SM_PROC_STATE_NONE;
 
     res->app_status = 0;

Reply via email to