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 2016/06/05 22:50:44 UTC

[1/3] incubator-mynewt-core git commit: bletiny - Remove extraneous log message.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 5f74e4fd1 -> cbeee5440


bletiny - Remove extraneous log message.


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

Branch: refs/heads/develop
Commit: 8f5496704e80a21d9b6ba08e151a647d1f8e6c75
Parents: 5f74e4f
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 6 05:42:52 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jun 6 05:42:52 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/store.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8f549670/apps/bletiny/src/store.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/store.c b/apps/bletiny/src/store.c
index b16655b..c01ce06 100644
--- a/apps/bletiny/src/store.c
+++ b/apps/bletiny/src/store.c
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -29,6 +29,7 @@
 
 #include <inttypes.h>
 #include <string.h>
+#include <assert.h>
 
 #include "console/console.h"
 #include "host/ble_hs.h"
@@ -90,6 +91,34 @@ store_print_key_sec(struct ble_store_key_sec *key_sec)
     }
 }
 
+static void
+store_log_sec_lookup(int obj_type, struct ble_store_key_sec *key_sec)
+{
+    char *obj_name;
+
+    if (key_sec->peer_addr_type == BLE_STORE_ADDR_TYPE_NONE &&
+       !key_sec->ediv_rand_present) {
+
+        return;
+    }
+
+    switch (obj_type) {
+    case BLE_STORE_OBJ_TYPE_MST_SEC:
+        obj_name = "mst sec";
+        break;
+    case BLE_STORE_OBJ_TYPE_SLV_SEC:
+        obj_name = "slv sec";
+        break;
+    default:
+        assert(0);
+        return;
+    }
+
+    console_printf("looking up %s; ", obj_name);
+    store_print_key_sec(key_sec);
+    console_printf("\n");
+}
+
 static int
 store_find_sec(struct ble_store_key_sec *key_sec,
                struct ble_store_value_sec *value_secs, int num_value_secs)
@@ -322,16 +351,12 @@ store_read(int obj_type, union ble_store_key *key,
          * result.  The nimble stack will use this key if this function returns
          * success.
          */
-        console_printf("looking up mst sec; ");
-        store_print_key_sec(&key->sec);
-        console_printf("\n");
+        store_log_sec_lookup(BLE_STORE_OBJ_TYPE_MST_SEC, &key->sec);
         rc = store_read_mst_sec(&key->sec, &value->sec);
         return rc;
 
     case BLE_STORE_OBJ_TYPE_SLV_SEC:
-        console_printf("looking up slv sec; ");
-        store_print_key_sec(&key->sec);
-        console_printf("\n");
+        store_log_sec_lookup(BLE_STORE_OBJ_TYPE_SLV_SEC, &key->sec);
         rc = store_read_slv_sec(&key->sec, &value->sec);
         return rc;
 


[2/3] incubator-mynewt-core git commit: bletiny - Allow "sec restart" to find ltk in store

Posted by cc...@apache.org.
bletiny - Allow "sec restart" to find ltk in store


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

Branch: refs/heads/develop
Commit: 8e5fe79c98dcb1222f5528939202fe0844c86de2
Parents: 8f54967
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 6 06:27:40 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jun 6 06:27:40 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c  | 32 ++++++++++++++++----------------
 apps/bletiny/src/main.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e5fe79c/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index b55adb9..f64879a 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1017,27 +1017,27 @@ cmd_sec_restart(int argc, char **argv)
     }
 
     ediv = parse_arg_uint16("ediv", &rc);
-    if (rc != 0) {
-        return rc;
-    }
+    if (rc == ENOENT) {
+        rc = bletiny_sec_restart(conn_handle, NULL, 0, 0, 0);
+    } else {
+        rand_val = parse_arg_uint64("rand", &rc);
+        if (rc != 0) {
+            return rc;
+        }
 
-    rand_val = parse_arg_uint64("rand", &rc);
-    if (rc != 0) {
-        return rc;
-    }
+        auth = parse_arg_bool("auth", &rc);
+        if (rc != 0) {
+            return rc;
+        }
 
-    auth = parse_arg_bool("auth", &rc);
-    if (rc != 0) {
-        return rc;
-    }
+        rc = parse_arg_byte_stream_exact_length("ltk", ltk, 16);
+        if (rc != 0) {
+            return rc;
+        }
 
-    rc = parse_arg_byte_stream_exact_length("ltk", ltk, 16);
-    if (rc != 0) {
-        return rc;
+        rc = bletiny_sec_restart(conn_handle, ltk, ediv, rand_val, auth);
     }
 
-    rc = bletiny_sec_restart( conn_handle, ltk, ediv, rand_val, auth);
-
     if (rc != 0) {
         console_printf("error starting encryption; rc=%d\n", rc);
         return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e5fe79c/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 63a3cf1..ea988bf 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -59,7 +59,7 @@
 
 #define SHELL_TASK_PRIO         (3)
 #define SHELL_MAX_INPUT_LEN     (256)
-#define SHELL_TASK_STACK_SIZE   (OS_STACK_ALIGN(312))
+#define SHELL_TASK_STACK_SIZE   (OS_STACK_ALIGN(512))
 static bssnz_t os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
 
 /* Our global device address (public) */
@@ -1414,8 +1414,33 @@ bletiny_sec_restart(uint16_t conn_handle,
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_store_value_sec value_sec;
+    struct ble_store_key_sec key_sec;
+    struct ble_gap_conn_desc desc;
     int rc;
 
+    if (ltk == NULL) {
+        /* The user is requesting a store lookup. */
+        rc = ble_gap_find_conn(conn_handle, &desc);
+        if (rc != 0) {
+            return rc;
+        }
+
+        memset(&key_sec, 0, sizeof key_sec);
+        key_sec.peer_addr_type = desc.peer_addr_type;
+        memcpy(key_sec.peer_addr, desc.peer_addr, 6);
+
+        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        if (rc != 0) {
+            return rc;
+        }
+
+        ltk = value_sec.ltk;
+        ediv = value_sec.ediv;
+        rand_val = value_sec.rand_num;
+        auth = value_sec.authenticated;
+    }
+
     rc = ble_gap_encryption_initiate(conn_handle, ltk, ediv, rand_val, auth);
     return rc;
 }


[3/3] incubator-mynewt-core git commit: BLE Host - Clean up debug logging.

Posted by cc...@apache.org.
BLE Host - Clean up debug logging.


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

Branch: refs/heads/develop
Commit: cbeee54400def52228b67e41c6451f68f490c459
Parents: 8e5fe79
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 6 06:50:11 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jun 6 06:50:11 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      |  9 ++++++---
 net/nimble/host/src/ble_att_cmd.c      | 13 +++++++++++++
 net/nimble/host/src/ble_att_cmd_priv.h |  2 ++
 net/nimble/host/src/ble_att_priv.h     | 21 ++++++++++++++++++---
 net/nimble/host/src/ble_att_svr.c      |  1 +
 net/nimble/host/src/ble_l2cap.c        |  3 ---
 6 files changed, 40 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cbeee544/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index 548e665..a365e50 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -152,6 +152,8 @@ ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **om)
     }
 
     ble_att_error_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
+    BLE_ATT_LOG_CMD(0, "error rsp", ble_att_error_rsp_log, &rsp);
+
     ble_gattc_rx_err(conn_handle, &rsp);
 
     return 0;
@@ -224,7 +226,7 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, struct ble_att_mtu_cmd *req)
 int
 ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **om)
 {
-    struct ble_att_mtu_cmd rsp;
+    struct ble_att_mtu_cmd cmd;
     struct ble_l2cap_chan *chan;
     uint16_t mtu;
     int rc;
@@ -233,13 +235,14 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **om)
 
     rc = ble_hs_misc_pullup_base(om, BLE_ATT_MTU_CMD_SZ);
     if (rc == 0) {
-        ble_att_mtu_cmd_parse((*om)->om_data, (*om)->om_len, &rsp);
+        ble_att_mtu_cmd_parse((*om)->om_data, (*om)->om_len, &cmd);
+        BLE_ATT_LOG_CMD(0, "mtu rsp", ble_att_mtu_cmd_log, &cmd);
 
         ble_hs_lock();
 
         rc = ble_att_conn_chan_find(conn_handle, NULL, &chan);
         if (rc == 0) {
-            ble_att_set_peer_mtu(chan, rsp.bamc_mtu);
+            ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
             mtu = ble_l2cap_chan_mtu(chan);
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cbeee544/net/nimble/host/src/ble_att_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd.c b/net/nimble/host/src/ble_att_cmd.c
index 2384ce1..aad771c 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -95,6 +95,13 @@ ble_att_error_rsp_write(void *payload, int len, struct ble_att_error_rsp *src)
     ble_att_error_rsp_swap(dst, src);
 }
 
+void
+ble_att_error_rsp_log(struct ble_att_error_rsp *cmd)
+{
+    BLE_HS_LOG(DEBUG, "req_op=%d attr_handle=0x%04x error_code=%d",
+               cmd->baep_req_op, cmd->baep_handle, cmd->baep_error_code);
+}
+
 static void
 ble_att_mtu_cmd_swap(struct ble_att_mtu_cmd *dst, struct ble_att_mtu_cmd *src)
 {
@@ -131,6 +138,12 @@ ble_att_mtu_rsp_write(void *payload, int len, struct ble_att_mtu_cmd *src)
     ble_att_mtu_cmd_swap(dst, src);
 }
 
+void
+ble_att_mtu_cmd_log(struct ble_att_mtu_cmd *cmd)
+{
+    BLE_HS_LOG(DEBUG, "mtu=%d", cmd->bamc_mtu);
+}
+
 static void
 ble_att_find_info_req_swap(struct ble_att_find_info_req *dst,
                            struct ble_att_find_info_req *src)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cbeee544/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 0dd8f0c..6af2bac 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -308,12 +308,14 @@ void ble_att_error_rsp_parse(void *payload, int len,
                               struct ble_att_error_rsp *rsp);
 void ble_att_error_rsp_write(void *payload, int len,
                               struct ble_att_error_rsp *rsp);
+void ble_att_error_rsp_log(struct ble_att_error_rsp *cmd);
 void ble_att_mtu_cmd_parse(void *payload, int len,
                             struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_req_write(void *payload, int len,
                             struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_rsp_write(void *payload, int len,
                            struct ble_att_mtu_cmd *cmd);
+void ble_att_mtu_cmd_log(struct ble_att_mtu_cmd *cmd);
 void ble_att_find_info_req_parse(void *payload, int len,
                                  struct ble_att_find_info_req *req);
 void ble_att_find_info_req_write(void *payload, int len,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cbeee544/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 1135e63..814539c 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -136,8 +136,8 @@ struct ble_att_svr_entry {
 
 #define HA_OPCODE_METHOD_START (0)
 #define HA_OPCODE_METHOD_END (5)
-#define HA_OPCODE_COMMAND_FLAG (1 << 6) 
-#define HA_OPCODE_AUTH_SIG_FLAG (1 << 7) 
+#define HA_OPCODE_COMMAND_FLAG (1 << 6)
+#define HA_OPCODE_AUTH_SIG_FLAG (1 << 7)
 
 SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
 
@@ -152,6 +152,21 @@ uint16_t ble_att_mtu(uint16_t conn_handle);
 void ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu);
 int ble_att_init(void);
 
+#if LOG_LEVEL <= LOG_LEVEL_DEBUG
+
+#define BLE_ATT_LOG_CMD(is_tx, cmd_name, log_cb, cmd) do                \
+{                                                                       \
+    BLE_HS_LOG(DEBUG, "%sed att command: %s; ", is_tx ? "tx" : "rx",    \
+               cmd_name);                                               \
+    (log_cb)(cmd);                                                      \
+    BLE_HS_LOG(DEBUG, "\n");                                            \
+} while (0)
+
+#else
+
+#define BLE_ATT_LOG_CMD(is_tx, cmd_name, log_cb, cmd)
+
+#endif
 
 /*** @svr */
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cbeee544/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index ce6aa7d..cd083d5 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -595,6 +595,7 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **om)
     }
 
     ble_att_mtu_cmd_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_ATT_LOG_CMD(0, "mtu req", ble_att_mtu_cmd_log, &cmd);
 
     rc = ble_att_svr_build_mtu_rsp(conn_handle, &txom, &att_err);
     if (rc != 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cbeee544/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 87caa6e..da66bf1 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -286,9 +286,6 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
         goto err;
     }
 
-    BLE_HS_LOG(DEBUG, "ble_l2cap_tx(): ");
-    ble_hs_misc_log_mbuf(om);
-    BLE_HS_LOG(DEBUG, "\n");
     rc = host_hci_data_tx(conn, om);
     om = NULL;
     if (rc != 0) {