mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [07/18] incubator-mynewt-core git commit: nimble/sm: Use packed structures for pairing failed
Date Fri, 27 Jan 2017 18:45:34 GMT
nimble/sm: Use packed structures for pairing failed


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

Branch: refs/heads/develop
Commit: 19d27a1606849752317b1bb08fa202770037fb28
Parents: 09431b8
Author: Szymon Janc <szymon.janc@codecoup.pl>
Authored: Tue Jan 17 19:24:31 2017 +0100
Committer: Szymon Janc <szymon.janc@codecoup.pl>
Committed: Wed Jan 25 15:44:15 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c                | 45 +++++++++++++-----------
 net/nimble/host/src/ble_sm_cmd.c            |  9 +++--
 net/nimble/host/src/ble_sm_priv.h           |  8 ++---
 net/nimble/host/test/src/ble_sm_test_util.c |  2 +-
 4 files changed, 32 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19d27a16/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 b57edfc..b6738b0 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -743,6 +743,20 @@ ble_sm_exec(struct ble_sm_proc *proc, struct ble_sm_result *res, void
*arg)
     }
 }
 
+static void pair_fail_tx(uint16_t conn_handle, uint8_t reason)
+{
+    struct ble_sm_pair_fail *cmd;
+    struct os_mbuf *txom;
+
+    BLE_HS_DBG_ASSERT(reason > 0 && reason < BLE_SM_ERR_MAX_PLUS_1);
+
+    cmd = ble_sm_cmd_get(BLE_SM_OP_PAIR_FAIL, sizeof(*cmd), &txom);
+    if (cmd) {
+        cmd->reason = reason;
+        ble_sm_tx(conn_handle, txom);
+    }
+}
+
 void
 ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
 {
@@ -778,7 +792,7 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
         }
 
         if (res->sm_err != 0) {
-            ble_sm_pair_fail_tx(conn_handle, res->sm_err);
+            pair_fail_tx(conn_handle, res->sm_err);
         }
 
         ble_hs_unlock();
@@ -2014,16 +2028,16 @@ static void
 ble_sm_fail_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
                struct ble_sm_result *res)
 {
-    struct ble_sm_pair_fail cmd;
+    struct ble_sm_pair_fail *cmd;
 
     res->enc_cb = 1;
 
-    res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_PAIR_FAIL_SZ);
+    res->app_status = ble_hs_mbuf_pullup_base(om, sizeof(*cmd));
     if (res->app_status == 0) {
-        ble_sm_pair_fail_parse((*om)->om_data, (*om)->om_len, &cmd);
-        BLE_SM_LOG_CMD(0, "fail", conn_handle, ble_sm_pair_fail_log, &cmd);
+        cmd = (struct ble_sm_pair_fail *)(*om)->om_data;
+        BLE_SM_LOG_CMD(0, "fail", conn_handle, ble_sm_pair_fail_log, cmd);
 
-        res->app_status = BLE_HS_SM_PEER_ERR(cmd.reason);
+        res->app_status = BLE_HS_SM_PEER_ERR(cmd->reason);
     }
 }
 
@@ -2392,28 +2406,17 @@ ble_sm_init(void)
 static int
 ble_sm_rx(uint16_t handle, struct os_mbuf **om)
 {
-    struct ble_l2cap_chan *chan;
-    struct ble_hs_conn *conn;
+    struct ble_sm_pair_fail *cmd;
     struct os_mbuf *txom;
-    uint8_t *cmd;
 
-    txom = ble_hs_mbuf_l2cap_pkt();
-    if (txom == NULL) {
-        return BLE_HS_ENOMEM;
-    }
-
-    cmd = os_mbuf_extend(txom, sizeof(struct ble_sm_hdr) + BLE_SM_PAIR_FAIL_SZ);
+    cmd = ble_sm_cmd_get(BLE_SM_OP_PAIR_FAIL, sizeof(*cmd), &txom);
     if (cmd == NULL) {
-        os_mbuf_free_chain(txom);
         return BLE_HS_ENOMEM;
     }
 
-    cmd[0] = BLE_SM_OP_PAIR_FAIL;
-    cmd[1] = BLE_SM_ERR_PAIR_NOT_SUPP;
-
-    ble_hs_misc_conn_chan_find_reqd(handle, BLE_L2CAP_CID_SM, &conn, &chan);
+    cmd->reason = BLE_SM_ERR_PAIR_NOT_SUPP;
 
-    return ble_l2cap_tx(conn, chan, txom);
+    return ble_sm_tx(handle, txom);
 }
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19d27a16/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 12ffe09..bca2ef0 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -25,8 +25,6 @@
 #include "host/ble_sm.h"
 #include "ble_hs_priv.h"
 
-#if NIMBLE_BLE_SM
-
 void *
 ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom)
 {
@@ -65,6 +63,7 @@ ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
     return ble_l2cap_tx(conn, chan, txom);
 }
 
+#if NIMBLE_BLE_SM
 static int
 ble_sm_init_req(uint16_t initial_sz, struct os_mbuf **out_txom)
 {
@@ -268,7 +267,7 @@ ble_sm_pair_fail_parse(void *payload, int len, struct ble_sm_pair_fail
*cmd)
 {
     uint8_t *u8ptr;
 
-    BLE_HS_DBG_ASSERT(len >= BLE_SM_PAIR_FAIL_SZ);
+    BLE_HS_DBG_ASSERT(len >= sizeof(struct ble_sm_pair_fail));
 
     u8ptr = payload;
     cmd->reason = u8ptr[0];
@@ -279,7 +278,7 @@ ble_sm_pair_fail_write(void *payload, int len, struct ble_sm_pair_fail
*cmd)
 {
     uint8_t *u8ptr;
 
-    BLE_HS_DBG_ASSERT(len >= sizeof(struct ble_sm_hdr) + BLE_SM_PAIR_FAIL_SZ);
+    BLE_HS_DBG_ASSERT(len >= sizeof(struct ble_sm_hdr) + sizeof(struct ble_sm_pair_fail));
 
     u8ptr = payload;
 
@@ -297,7 +296,7 @@ ble_sm_pair_fail_tx(uint16_t conn_handle, uint8_t reason)
 
     BLE_HS_DBG_ASSERT(reason > 0 && reason < BLE_SM_ERR_MAX_PLUS_1);
 
-    rc = ble_sm_init_req(BLE_SM_PAIR_FAIL_SZ, &txom);
+    rc = ble_sm_init_req(sizeof(struct ble_sm_pair_fail), &txom);
     if (rc != 0) {
         return BLE_HS_ENOMEM;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19d27a16/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index e20ce1a..80a2294 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -103,10 +103,9 @@ struct ble_sm_pair_random {
  * | (Code=0x05)                        | 1                 |
  * | Reason                             | 1                 |
  */
-#define BLE_SM_PAIR_FAIL_SZ         1
 struct ble_sm_pair_fail {
     uint8_t reason;
-};
+} __attribute__((packed));
 
 /**
  * | Parameter                          | Size (octets)     |
@@ -303,9 +302,6 @@ void ble_sm_dbg_set_sc_keys(uint8_t *pubkey, uint8_t *privkey);
 int ble_sm_dbg_num_procs(void);
 #endif
 
-void *ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom);
-int ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom);
-
 uint8_t ble_sm_build_authreq(void);
 
 void ble_sm_pair_cmd_parse(void *payload, int len,
@@ -497,6 +493,8 @@ int ble_sm_init(void);
 #endif
 
 struct ble_l2cap_chan *ble_sm_create_chan(void);
+void *ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom);
+int ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19d27a16/net/nimble/host/test/src/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_sm_test_util.c b/net/nimble/host/test/src/ble_sm_test_util.c
index 4ebced2..490fe35 100644
--- a/net/nimble/host/test/src/ble_sm_test_util.c
+++ b/net/nimble/host/test/src/ble_sm_test_util.c
@@ -828,7 +828,7 @@ ble_sm_test_util_verify_tx_pair_fail(
     struct os_mbuf *om;
 
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_FAIL,
-                                        BLE_SM_PAIR_FAIL_SZ);
+                                        sizeof(struct ble_sm_pair_fail));
     ble_sm_pair_fail_parse(om->om_data, om->om_len, &cmd);
 
     TEST_ASSERT(cmd.reason == exp_cmd->reason);


Mime
View raw message