You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/28 02:14:24 UTC

[25/50] [abbrv] incubator-mynewt-core git commit: ble host - fix SM bug; r1/r2 misordered on master.

ble host - fix SM bug; r1/r2 misordered on master.


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/3befe370
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3befe370
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3befe370

Branch: refs/heads/master
Commit: 3befe370a84d50281001f695983f10f04774764e
Parents: 151139c
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Apr 20 13:55:31 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 20 16:11:45 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sm.c | 36 +++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3befe370/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c b/net/nimble/host/src/ble_l2cap_sm.c
index e052f2e..99f7d64 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -57,8 +57,8 @@ struct ble_l2cap_sm_proc {
     struct ble_l2cap_sm_pair_cmd pair_rsp;
     uint8_t tk[16];
     uint8_t confirm_their[16];
-    uint8_t rand_our[16];
-    uint8_t rand_their[16];
+    uint8_t randm[16];
+    uint8_t rands[16];
     uint8_t ltk[16];
 };
 
@@ -228,7 +228,7 @@ ble_l2cap_sm_gen_key(struct ble_l2cap_sm_proc *proc)
     uint8_t key[16];
     int rc;
 
-    rc = ble_l2cap_sm_alg_s1(proc->tk, proc->rand_our, proc->rand_their, key);
+    rc = ble_l2cap_sm_alg_s1(proc->tk, proc->rands, proc->randm, key);
     if (rc != 0) {
         return rc;
     }
@@ -528,13 +528,33 @@ ble_l2cap_sm_lt_key_req_handle(struct ble_l2cap_sm_proc *proc,
  * $random                                                                   *
  *****************************************************************************/
 
+static uint8_t *
+ble_l2cap_sm_our_pair_rand(struct ble_l2cap_sm_proc *proc)
+{
+    if (proc->flags & BLE_L2CAP_SM_PROC_F_INITIATOR) {
+        return proc->randm;
+    } else {
+        return proc->rands;
+    }
+}
+
+static uint8_t *
+ble_l2cap_sm_their_pair_rand(struct ble_l2cap_sm_proc *proc)
+{
+    if (proc->flags & BLE_L2CAP_SM_PROC_F_INITIATOR) {
+        return proc->rands;
+    } else {
+        return proc->randm;
+    }
+}
+
 static int
 ble_l2cap_sm_random_go(struct ble_l2cap_sm_proc *proc)
 {
     struct ble_l2cap_sm_pair_random cmd;
     int rc;
 
-    memcpy(cmd.value, proc->rand_our, 16);
+    memcpy(cmd.value, ble_l2cap_sm_our_pair_rand(proc), 16);
     rc = ble_l2cap_sm_pair_random_tx(proc->conn_handle, &cmd);
     if (rc != 0) {
         return rc;
@@ -582,7 +602,7 @@ ble_l2cap_sm_random_handle(struct ble_l2cap_sm_proc *proc,
         return rc;
     }
 
-    memcpy(proc->rand_their, cmd->value, 16);
+    memcpy(ble_l2cap_sm_their_pair_rand(proc), cmd->value, 16);
 
     /* Generate the key. */
     rc = ble_l2cap_sm_gen_key(proc);
@@ -677,8 +697,8 @@ ble_l2cap_sm_confirm_go(struct ble_l2cap_sm_proc *proc)
         return rc;
     }
 
-    rc = ble_l2cap_sm_alg_c1(k, proc->rand_our, preq, pres, iat, rat,
-                             ia, ra, cmd.value);
+    rc = ble_l2cap_sm_alg_c1(k, ble_l2cap_sm_our_pair_rand(proc), preq, pres,
+                             iat, rat, ia, ra, cmd.value);
     if (rc != 0) {
         return rc;
     }
@@ -764,7 +784,7 @@ ble_l2cap_sm_pair_go(struct ble_l2cap_sm_proc *proc)
         proc->pair_rsp = cmd;
     }
 
-    rc = ble_l2cap_sm_gen_pair_rand(proc->rand_our);
+    rc = ble_l2cap_sm_gen_pair_rand(ble_l2cap_sm_our_pair_rand(proc));
     if (rc != 0) {
         return rc;
     }