You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/01/07 15:42:51 UTC

[1/3] incubator-mynewt-core git commit: nimble/sm: Remove not needed stack variables

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 0442a1e1e -> 4a287aa01


nimble/sm: Remove not needed stack variables

Remove prev stack variable for ble_sm_proc_find if caller makes no
use of it.


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

Branch: refs/heads/develop
Commit: eece2d74d099f05259e751592c140b69f8570e18
Parents: f50818b
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Tue Jan 3 11:03:31 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Wed Jan 4 15:27:52 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c    | 39 ++++++++++--------------------------
 net/nimble/host/src/ble_sm_sc.c |  6 ++----
 2 files changed, 13 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eece2d74/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 fa16433..9058e58 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1243,7 +1243,6 @@ ble_sm_random_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_pair_random cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_PAIR_RANDOM_SZ);
     if (res->app_status != 0) {
@@ -1256,7 +1255,7 @@ ble_sm_random_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     BLE_SM_LOG_CMD(0, "random", conn_handle, ble_sm_pair_random_log, &cmd);
 
     ble_hs_lock();
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_RANDOM, -1, &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_RANDOM, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
     } else {
@@ -1292,7 +1291,6 @@ ble_sm_confirm_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_pair_confirm cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
     uint8_t ioact;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_PAIR_CONFIRM_SZ);
@@ -1306,7 +1304,7 @@ ble_sm_confirm_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     BLE_SM_LOG_CMD(0, "confirm", conn_handle, ble_sm_pair_confirm_log, &cmd);
 
     ble_hs_lock();
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_CONFIRM, -1, &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_CONFIRM, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
     } else {
@@ -1513,7 +1511,6 @@ ble_sm_pair_rsp_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_pair_cmd rsp;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
     uint8_t ioact;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_PAIR_CMD_SZ);
@@ -1526,7 +1523,7 @@ ble_sm_pair_rsp_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     BLE_SM_LOG_CMD(0, "pair rsp", conn_handle, ble_sm_pair_cmd_log, &rsp);
 
     ble_hs_lock();
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_PAIR, 1, &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_PAIR, 1, NULL);
     if (proc != NULL) {
         proc->pair_rsp = rsp;
         if (rsp.max_enc_key_size < BLE_SM_PAIR_KEY_SZ_MIN) {
@@ -1799,7 +1796,6 @@ ble_sm_enc_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_enc_info cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_ENC_INFO_SZ);
     if (res->app_status != 0) {
@@ -1813,8 +1809,7 @@ ble_sm_enc_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
 
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1,
-                            &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -1835,7 +1830,6 @@ ble_sm_master_id_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_master_id cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_MASTER_ID_SZ);
     if (res->app_status != 0) {
@@ -1849,8 +1843,7 @@ ble_sm_master_id_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
 
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1,
-                            &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -1872,7 +1865,6 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_id_info cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_ID_INFO_SZ);
     if (res->app_status != 0) {
@@ -1886,8 +1878,7 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
 
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1,
-                            &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -1909,7 +1900,6 @@ ble_sm_id_addr_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_id_addr_info cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_ID_ADDR_INFO_SZ);
     if (res->app_status != 0) {
@@ -1924,8 +1914,7 @@ ble_sm_id_addr_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
 
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1,
-                            &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -1947,7 +1936,6 @@ ble_sm_sign_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_sign_info cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_SIGN_INFO_SZ);
     if (res->app_status != 0) {
@@ -1961,8 +1949,7 @@ ble_sm_sign_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
 
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1,
-                            &prev);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_KEY_EXCH, -1, NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -2086,8 +2073,7 @@ ble_sm_slave_initiate(uint16_t conn_handle)
     ble_hs_lock();
 
     /* Make sure a procedure isn't already in progress for this connection. */
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE,
-                                  -1, NULL);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
     if (proc != NULL) {
         res.app_status = BLE_HS_EALREADY;
 
@@ -2130,8 +2116,7 @@ ble_sm_enc_initiate(uint16_t conn_handle, const uint8_t *ltk, uint16_t ediv,
 
     /* Make sure a procedure isn't already in progress for this connection. */
     ble_hs_lock();
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE,
-                            -1, NULL);
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
     if (proc != NULL) {
         res.app_status = BLE_HS_EALREADY;
 
@@ -2241,15 +2226,13 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
 {
     struct ble_sm_result res;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
     int rc;
 
     memset(&res, 0, sizeof res);
 
     ble_hs_lock();
 
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, &prev);
-
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
     if (proc == NULL) {
         rc = BLE_HS_ENOENT;
     } else if (proc->flags & BLE_SM_PROC_F_IO_INJECTED) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eece2d74/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 6471607..2ab3f8a 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -519,7 +519,6 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_public_key cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
     uint8_t ioact;
     int rc;
 
@@ -541,7 +540,7 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_PUBLIC_KEY, -1,
-                            &prev);
+                            NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -723,7 +722,6 @@ ble_sm_sc_dhkey_check_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 {
     struct ble_sm_dhkey_check cmd;
     struct ble_sm_proc *proc;
-    struct ble_sm_proc *prev;
 
     res->app_status = ble_hs_mbuf_pullup_base(om, BLE_SM_DHKEY_CHECK_SZ);
     if (res->app_status != 0) {
@@ -738,7 +736,7 @@ ble_sm_sc_dhkey_check_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 
     ble_hs_lock();
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_DHKEY_CHECK, -1,
-                            &prev);
+                            NULL);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
     } else {


[3/3] incubator-mynewt-core git commit: This closes #156.

Posted by cc...@apache.org.
This closes #156.

Merge remote-tracking branch 'sjanc/sm' into develop

* sjanc/sm:
  nimble/sm: Remove not needed stack variables
  nimble/sm: Add support for rejecting pairing with disabled SM


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

Branch: refs/heads/develop
Commit: 4a287aa01906e98a2f512ab7faff008e443f8243
Parents: 0442a1e eece2d7
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Jan 7 07:36:35 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Jan 7 07:36:35 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_conn.c |   6 +-
 net/nimble/host/src/ble_sm.c      | 105 ++++++++++++++++++---------------
 net/nimble/host/src/ble_sm_priv.h |   5 +-
 net/nimble/host/src/ble_sm_sc.c   |   6 +-
 4 files changed, 65 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4a287aa0/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4a287aa0/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------


[2/3] incubator-mynewt-core git commit: nimble/sm: Add support for rejecting pairing with disabled SM

Posted by cc...@apache.org.
nimble/sm: Add support for rejecting pairing with disabled SM

If pairing is not supported host shall response to Pairing Request
or Security Request with Pairing Failed PDU and set reason to
"Pairing not supported".

< ACL Data TX: Handle 76 flags 0x00 dlen 11
      SMP: Pairing Request (0x01) len 6
        IO capability: DisplayYesNo (0x01)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, MITM, SC, No Keypresses (0x0d)
        Max encryption key size: 16
        Initiator key distribution: EncKey Sign LinkKey (0x0d)
        Responder key distribution: EncKey IdKey Sign LinkKey (0x0f)
> ACL Data RX: Handle 76 flags 0x02 dlen 6
      SMP: Pairing Failed (0x05) len 1
        Reason: Pairing not supported (0x05)


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

Branch: refs/heads/develop
Commit: f50818b2ad5fa8af2d9fd5c5f5a19e1e54ee550a
Parents: 257381d
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Tue Jan 3 17:37:21 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Wed Jan 4 15:27:52 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_conn.c |  6 ++--
 net/nimble/host/src/ble_sm.c      | 66 ++++++++++++++++++++++++----------
 net/nimble/host/src/ble_sm_priv.h |  5 ++-
 3 files changed, 52 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f50818b2/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index e92f9e5..ebf65aa 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -138,10 +138,9 @@ ble_hs_conn_alloc(void)
         goto err;
     }
 
-    /* XXX: We should create the SM channel even if not configured.  We need it
-     * to reject SM messages.
+    /* Create the SM channel even if not configured. We need it to reject SM
+     * messages.
      */
-#if NIMBLE_BLE_SM
     chan = ble_sm_create_chan();
     if (chan == NULL) {
         goto err;
@@ -150,7 +149,6 @@ ble_hs_conn_alloc(void)
     if (rc != 0) {
         goto err;
     }
-#endif
 
     rc = ble_gatts_conn_init(&conn->bhc_gatt_svr);
     if (rc != 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f50818b2/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 a49c3d2..fa16433 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2236,24 +2236,6 @@ ble_sm_rx(uint16_t conn_handle, struct os_mbuf **om)
     return rc;
 }
 
-struct ble_l2cap_chan *
-ble_sm_create_chan(void)
-{
-    struct ble_l2cap_chan *chan;
-
-    chan = ble_l2cap_chan_alloc();
-    if (chan == NULL) {
-        return NULL;
-    }
-
-    chan->blc_cid = BLE_L2CAP_CID_SM;
-    chan->blc_my_mtu = BLE_SM_MTU;
-    chan->blc_default_mtu = BLE_SM_MTU;
-    chan->blc_rx_fn = ble_sm_rx;
-
-    return chan;
-}
-
 int
 ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
 {
@@ -2378,5 +2360,53 @@ ble_sm_init(void)
 
     return 0;
 }
+#else
+/* if pairing is not supported it is only needed to reply with Pairing
+ * Failed with 'Pairing not Supported' reason so this function can be very
+ * simple
+ */
+static int
+ble_sm_rx(uint16_t handle, struct os_mbuf **om)
+{
+    struct ble_l2cap_chan *chan;
+    struct ble_hs_conn *conn;
+    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, BLE_SM_HDR_SZ + BLE_SM_PAIR_FAIL_SZ);
+    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);
+
+    return ble_l2cap_tx(conn, chan, txom);
+}
 #endif
+
+struct ble_l2cap_chan *
+ble_sm_create_chan(void)
+{
+    struct ble_l2cap_chan *chan;
+
+    chan = ble_l2cap_chan_alloc();
+    if (chan == NULL) {
+        return NULL;
+    }
+
+    chan->blc_cid = BLE_L2CAP_CID_SM;
+    chan->blc_my_mtu = BLE_SM_MTU;
+    chan->blc_default_mtu = BLE_SM_MTU;
+    chan->blc_rx_fn = ble_sm_rx;
+
+    return chan;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f50818b2/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 d75d475..e802d8d 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -302,8 +302,6 @@ int ble_sm_dbg_num_procs(void);
 
 uint8_t ble_sm_build_authreq(void);
 
-struct ble_l2cap_chan *ble_sm_create_chan(void);
-
 void ble_sm_pair_cmd_parse(void *payload, int len,
                            struct ble_sm_pair_cmd *cmd);
 int ble_sm_pair_cmd_is_valid(struct ble_sm_pair_cmd *cmd);
@@ -478,7 +476,6 @@ int ble_sm_init(void);
 #else
 
 #define ble_sm_dbg_num_procs() 0
-#define ble_sm_create_chan() NULL
 #define ble_sm_enc_change_rx(evt) ((void)(evt))
 #define ble_sm_ltk_req_rx(evt) ((void)(evt))
 #define ble_sm_enc_key_refresh_rx(evt) ((void)(evt))
@@ -494,6 +491,8 @@ int ble_sm_init(void);
 
 #endif
 
+struct ble_l2cap_chan *ble_sm_create_chan(void);
+
 #ifdef __cplusplus
 }
 #endif