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/06 14:29:19 UTC

[3/4] incubator-mynewt-core git commit: INTERIM - logging

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

Branch: refs/heads/develop
Commit: 7120ba14d012890632aa8d06a51ebad924e58cb3
Parents: 6c8d7bd
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 6 20:34:39 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jun 6 20:34:39 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c  |   4 +-
 net/nimble/host/src/ble_att_priv.h |  22 +---
 net/nimble/host/src/ble_att_svr.c  |   2 +-
 net/nimble/host/src/ble_hs_priv.h  |  17 +++
 net/nimble/host/src/ble_sm.c       |  47 +++-----
 net/nimble/host/src/ble_sm_cmd.c   | 193 ++++++++++++++++++++------------
 net/nimble/host/src/ble_sm_priv.h  |  76 +++++++------
 net/nimble/host/src/ble_sm_sc.c    |  15 +--
 8 files changed, 206 insertions(+), 170 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 a365e50..30fe813 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -152,7 +152,7 @@ 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_ATT_LOG_CMD(0, "error rsp", conn_handle, ble_att_error_rsp_log, &rsp);
 
     ble_gattc_rx_err(conn_handle, &rsp);
 
@@ -236,7 +236,7 @@ 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, &cmd);
-        BLE_ATT_LOG_CMD(0, "mtu rsp", ble_att_mtu_cmd_log, &cmd);
+        BLE_ATT_LOG_CMD(0, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, &cmd);
 
         ble_hs_lock();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 814539c..77cfc64 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -134,11 +134,6 @@ struct ble_att_svr_entry {
     void *ha_cb_arg;
 };
 
-#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)
-
 SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
 
 /*** @gen */
@@ -152,21 +147,8 @@ 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
+#define BLE_ATT_LOG_CMD(is_tx, cmd_name, conn_handle, log_cb, cmd) \
+    BLE_HS_LOG_CMD((is_tx), "att", (cmd_name), (conn_handle), (log_cb), (cmd))
 
 /*** @svr */
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 cd083d5..42e7eb5 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -595,7 +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);
+    BLE_ATT_LOG_CMD(0, "mtu req", conn_handle, 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/7120ba14/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index d119a2a..5244089 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -125,6 +125,23 @@ void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
                (addr)[0], (addr)[1], (addr)[2],         \
                (addr)[3], (addr)[4], (addr)[5])
 
+#if LOG_LEVEL <= LOG_LEVEL_DEBUG
+
+#define BLE_HS_LOG_CMD(is_tx, cmd_type, cmd_name, conn_handle,          \
+                       log_cb, cmd) do                                  \
+{                                                                       \
+    BLE_HS_LOG(DEBUG, "%sed %s command: %s; conn=%d",                   \
+               is_tx ? "tx" : "rx", cmd_type, cmd_name);                \
+    (log_cb)(cmd);                                                      \
+    BLE_HS_LOG(DEBUG, "\n");                                            \
+} while (0)
+
+#else
+
+#define BLE_HS_LOG_CMD(is_tx, cmd_type, cmd_name, conn_handle, log_cb, cmd)
+
+#endif
+
 #if BLE_HS_DEBUG
     #define BLE_HS_DBG_ASSERT(x) assert(x)
     #define BLE_HS_DBG_ASSERT_EVAL(x) assert(x)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 526ea8a..6f47967 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1237,12 +1237,10 @@ ble_sm_random_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_pair_random_parse((*om)->om_data, (*om)->om_len, &cmd);
-
-    BLE_HS_LOG(DEBUG, "rxed sm random cmd\n");
+    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, &prev);
     if (proc == NULL) {
         res->app_status = BLE_HS_ENOENT;
     } else {
@@ -1289,8 +1287,7 @@ ble_sm_confirm_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_pair_confirm_parse((*om)->om_data, (*om)->om_len, &cmd);
-
-    BLE_HS_LOG(DEBUG, "rxed sm confirm cmd\n");
+    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);
@@ -1451,12 +1448,7 @@ ble_sm_pair_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_pair_cmd_parse((*om)->om_data, (*om)->om_len, &req);
-
-    BLE_HS_LOG(DEBUG, "rxed sm pair req; io_cap=0x%02x oob_data_flag=%d "
-                      "authreq=0x%02x max_enc_key_size=%d "
-                      "init_key_dist=0x%02x resp_key_dist=0x%02x\n",
-               req.io_cap, req.oob_data_flag, req.authreq,
-               req.max_enc_key_size, req.init_key_dist, req.resp_key_dist);
+    BLE_SM_LOG_CMD(0, "pair req", conn_handle, ble_sm_pair_cmd_log, &req);
 
     ble_hs_lock();
 
@@ -1514,16 +1506,10 @@ ble_sm_pair_rsp_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_pair_cmd_parse((*om)->om_data, (*om)->om_len, &rsp);
-
-    BLE_HS_LOG(DEBUG, "rxed sm pair rsp; io_cap=0x%02x oob_data_flag=%d "
-                      "authreq=0x%02x max_enc_key_size=%d "
-                      "init_key_dist=0x%02x resp_key_dist=0x%02x\n",
-               rsp.io_cap, rsp.oob_data_flag, rsp.authreq,
-               rsp.max_enc_key_size, rsp.init_key_dist, rsp.resp_key_dist);
+    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, &prev);
     if (proc != NULL) {
         proc->pair_rsp = rsp;
         if (!ble_sm_pair_cmd_is_valid(&rsp)) {
@@ -1580,14 +1566,13 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_sec_req_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "sec req", conn_handle, ble_sm_sec_req_log, &cmd);
 
     /* XXX: Reject if:
      *     o authreq-bonded flag not set?
      *     o authreq-reserved flags set?
      */
 
-    BLE_HS_LOG(DEBUG, "rxed sm sec req; authreq=%d\n", cmd.authreq);
-
     ble_hs_lock();
 
     conn = ble_hs_conn_find(conn_handle);
@@ -1709,7 +1694,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 
         bls_hs_priv_copy_local_identity_addr(addr_info.bd_addr,
                                              &addr_info.addr_type);
-        rc = ble_sm_iden_addr_tx(proc->conn_handle, &addr_info);
+        rc = ble_sm_id_addr_info_tx(proc->conn_handle, &addr_info);
         if (rc != 0) {
             goto err;
         }
@@ -1754,8 +1739,7 @@ err:
 static void
 ble_sm_key_rxed(struct ble_sm_proc *proc, struct ble_sm_result *res)
 {
-    BLE_HS_LOG(DEBUG, "key received; rx_key_flags=0x%02x\n",
-               proc->rx_key_flags);
+    BLE_HS_LOG(DEBUG, "rx_key_flags=0x%02x\n", proc->rx_key_flags);
 
     if (proc->rx_key_flags == 0) {
         /* The peer is done sending keys.  If we are the initiator, we need to
@@ -1787,6 +1771,7 @@ ble_sm_enc_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_enc_info_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "enc info", conn_handle, ble_sm_enc_info_log, &cmd);
 
     ble_hs_lock();
 
@@ -1822,6 +1807,7 @@ ble_sm_master_id_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_master_id_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "master id", conn_handle, ble_sm_master_id_log, &cmd);
 
     ble_hs_lock();
 
@@ -1858,6 +1844,7 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_id_info_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "id info", conn_handle, ble_sm_id_info_log, &cmd);
 
     ble_hs_lock();
 
@@ -1892,7 +1879,9 @@ ble_sm_id_addr_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         return;
     }
 
-    ble_sm_iden_addr_parse((*om)->om_data, (*om)->om_len, &cmd);
+    ble_sm_id_addr_info_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "id addr info", conn_handle, ble_sm_id_addr_info_log,
+                   &cmd);
 
     ble_hs_lock();
 
@@ -1929,6 +1918,7 @@ ble_sm_sign_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_sign_info_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "sign info", conn_handle, ble_sm_sign_info_log, &cmd);
 
     ble_hs_lock();
 
@@ -1963,7 +1953,7 @@ ble_sm_fail_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_PAIR_FAIL_SZ);
     if (res->app_status == 0) {
         ble_sm_pair_fail_parse((*om)->om_data, (*om)->om_len, &cmd);
-        BLE_HS_LOG(DEBUG, "rxed sm fail cmd; reason=%d\n", cmd.reason);
+        BLE_SM_LOG_CMD(0, "fail", conn_handle, ble_sm_pair_fail_log, &cmd);
 
         res->app_status = BLE_HS_SM_THEM_ERR(cmd.reason);
     }
@@ -2135,9 +2125,6 @@ ble_sm_rx(uint16_t conn_handle, struct os_mbuf **om)
     int rc;
 
     STATS_INC(ble_l2cap_stats, sm_rx);
-    BLE_HS_LOG(DEBUG, "L2CAP - rxed security manager msg: ");
-    ble_hs_misc_log_mbuf(*om);
-    BLE_HS_LOG(DEBUG, "\n");
 
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 7f3c425..1d6ce31 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -41,9 +41,6 @@ ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
     rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SM,
                                          &conn, &chan);
     if (rc == 0) {
-        BLE_HS_LOG(DEBUG, "ble_sm_tx(): ");
-        ble_hs_misc_log_mbuf(txom);
-        BLE_HS_LOG(DEBUG, "\n");
         rc = ble_l2cap_tx(conn, chan, txom);
     }
 
@@ -149,14 +146,6 @@ ble_sm_pair_cmd_tx(uint16_t conn_handle, int is_req,
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_pair_cmd_tx(); conn_handle=%d is_req=%d "
-                      "io_cap=%d oob_data_flag=%d authreq=0x%02x "
-                      "mac_enc_key_size=%d init_key_dist=%d "
-                      "resp_key_dist=%d\n",
-               conn_handle, is_req, cmd->io_cap, cmd->oob_data_flag,
-               cmd->authreq, cmd->max_enc_key_size, cmd->init_key_dist,
-               cmd->resp_key_dist);
-
     rc = ble_sm_init_req(BLE_SM_PAIR_CMD_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -164,6 +153,8 @@ ble_sm_pair_cmd_tx(uint16_t conn_handle, int is_req,
     }
 
     ble_sm_pair_cmd_write(txom->om_data, txom->om_len, is_req, cmd);
+    BLE_SM_LOG_CMD(1, is_req ? "pair req" : "pair rsp", conn_handle,
+                   ble_sm_pair_cmd_log, cmd);
     BLE_HS_DBG_ASSERT(ble_sm_pair_cmd_is_valid(cmd));
 
     rc = ble_sm_tx(conn_handle, txom);
@@ -175,6 +166,17 @@ done:
 }
 
 void
+ble_sm_pair_cmd_log(struct ble_sm_pair_cmd *cmd)
+{
+    BLE_HS_LOG(DEBUG, "io_cap=%d oob_data_flag=%d authreq=0x%02x "
+                      "mac_enc_key_size=%d init_key_dist=%d "
+                      "resp_key_dist=%d",
+               cmd->io_cap, cmd->oob_data_flag, cmd->authreq,
+               cmd->max_enc_key_size, cmd->init_key_dist,
+               cmd->resp_key_dist);
+}
+
+void
 ble_sm_pair_confirm_parse(void *payload, int len,
                           struct ble_sm_pair_confirm *cmd)
 {
@@ -188,8 +190,7 @@ ble_sm_pair_confirm_write(void *payload, int len,
 {
     uint8_t *u8ptr;
 
-    BLE_HS_DBG_ASSERT(len >=
-                      BLE_SM_HDR_SZ + BLE_SM_PAIR_CONFIRM_SZ);
+    BLE_HS_DBG_ASSERT(len >= BLE_SM_HDR_SZ + BLE_SM_PAIR_CONFIRM_SZ);
 
     u8ptr = payload;
 
@@ -203,9 +204,6 @@ ble_sm_pair_confirm_tx(uint16_t conn_handle, struct ble_sm_pair_confirm *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_pair_confirm_tx(); conn_handle=%d value=");
-    ble_hs_misc_log_flat_buf(cmd->value, sizeof cmd->value);
-    BLE_HS_LOG(DEBUG, "\n");
 
     rc = ble_sm_init_req(BLE_SM_PAIR_CONFIRM_SZ, &txom);
     if (rc != 0) {
@@ -214,10 +212,8 @@ ble_sm_pair_confirm_tx(uint16_t conn_handle, struct ble_sm_pair_confirm *cmd)
     }
 
     ble_sm_pair_confirm_write(txom->om_data, txom->om_len, cmd);
+    BLE_SM_LOG_CMD(1, "confirm", conn_handle, ble_sm_pair_confirm_log, cmd);
 
-    BLE_HS_LOG(DEBUG, "ble_sm_pair_confirm_tx(): ");
-    ble_hs_misc_log_mbuf(txom);
-    BLE_HS_LOG(DEBUG, "\n");
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -227,6 +223,13 @@ done:
 }
 
 void
+ble_sm_pair_confirm_log(struct ble_sm_pair_confirm *cmd)
+{
+    BLE_HS_LOG(DEBUG, "value=");
+    ble_hs_misc_log_flat_buf(cmd->value, sizeof cmd->value);
+}
+
+void
 ble_sm_pair_random_parse(void *payload, int len,
                          struct ble_sm_pair_random *cmd)
 {
@@ -255,10 +258,6 @@ ble_sm_pair_random_tx(uint16_t conn_handle, struct ble_sm_pair_random *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_pair_random_tx(); conn_handle=%d value=");
-    ble_hs_misc_log_flat_buf(cmd->value, sizeof cmd->value);
-    BLE_HS_LOG(DEBUG, "\n");
-
     rc = ble_sm_init_req(BLE_SM_PAIR_RANDOM_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -266,6 +265,7 @@ ble_sm_pair_random_tx(uint16_t conn_handle, struct ble_sm_pair_random *cmd)
     }
 
     ble_sm_pair_random_write(txom->om_data, txom->om_len, cmd);
+    BLE_SM_LOG_CMD(1, "random", conn_handle, ble_sm_pair_random_log, cmd);
 
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
@@ -276,6 +276,13 @@ done:
 }
 
 void
+ble_sm_pair_random_log(struct ble_sm_pair_random *cmd)
+{
+    BLE_HS_LOG(DEBUG, "value=");
+    ble_hs_misc_log_flat_buf(cmd->value, sizeof cmd->value);
+}
+
+void
 ble_sm_pair_fail_parse(void *payload, int len, struct ble_sm_pair_fail *cmd)
 {
     uint8_t *u8ptr;
@@ -307,9 +314,6 @@ ble_sm_pair_fail_tx(uint16_t conn_handle, uint8_t reason)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_pair_fail_tx(); conn_handle=%d reason=%d\n",
-               conn_handle, 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);
@@ -319,7 +323,9 @@ ble_sm_pair_fail_tx(uint16_t conn_handle, uint8_t reason)
     }
 
     cmd.reason = reason;
+
     ble_sm_pair_fail_write(txom->om_data, txom->om_len, &cmd);
+    BLE_SM_LOG_CMD(1, "fail", conn_handle, ble_sm_pair_fail_log, &cmd);
 
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
@@ -330,6 +336,12 @@ done:
 }
 
 void
+ble_sm_pair_fail_log(struct ble_sm_pair_fail *cmd)
+{
+    BLE_HS_LOG(DEBUG, "reason=%d", cmd->reason);
+}
+
+void
 ble_sm_enc_info_parse(void *payload, int len, struct ble_sm_enc_info *cmd)
 {
     uint8_t *u8ptr = payload;
@@ -342,10 +354,6 @@ ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_enc_info_tx(); conn_handle=%d ltk=");
-    ble_hs_misc_log_flat_buf(cmd->ltk, sizeof cmd->ltk);
-    BLE_HS_LOG(DEBUG, "\n");
-
     rc = ble_sm_init_req(BLE_SM_ENC_INFO_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -354,6 +362,8 @@ ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd)
 
     txom->om_data[0] = BLE_SM_OP_ENC_INFO;
     memcpy(txom->om_data + 1, cmd->ltk, sizeof cmd->ltk);
+
+    BLE_SM_LOG_CMD(1, "enc info", conn_handle, ble_sm_enc_info_log, cmd);
     
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
@@ -364,6 +374,13 @@ done:
 }
 
 void
+ble_sm_enc_info_log(struct ble_sm_enc_info *cmd)
+{
+    BLE_HS_LOG(DEBUG, "ltk=");
+    ble_hs_misc_log_flat_buf(cmd->ltk, sizeof cmd->ltk);
+}
+
+void
 ble_sm_master_id_parse(void *payload, int len, struct ble_sm_master_id *cmd)
 {
     uint8_t *u8ptr = payload;
@@ -377,10 +394,6 @@ ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_master_id_tx(); conn_handle=%d ediv=0x%04x "
-                      "rand=0x%016llx\n", conn_handle, cmd->ediv,
-               cmd->rand_val);
-
     rc = ble_sm_init_req(BLE_SM_MASTER_ID_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -390,6 +403,9 @@ ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd)
     txom->om_data[0] = BLE_SM_OP_MASTER_ID;
     htole16(txom->om_data + 1, cmd->ediv);
     htole64(txom->om_data + 3, cmd->rand_val);
+
+    BLE_SM_LOG_CMD(1, "master id", conn_handle, ble_sm_master_id_log, cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -399,6 +415,12 @@ done:
 }
 
 void
+ble_sm_master_id_log(struct ble_sm_master_id *cmd)
+{
+    BLE_HS_LOG(DEBUG, "ediv=0x%04x rand=0x%016llx", cmd->ediv, cmd->rand_val);
+}
+
+void
 ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd)
 {
     uint8_t *u8ptr = payload;
@@ -411,10 +433,6 @@ ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_id_info_tx(); conn_handle=%d irk=");
-    ble_hs_misc_log_flat_buf(cmd->irk, sizeof cmd->irk);
-    BLE_HS_LOG(DEBUG, "\n");
-
     rc = ble_sm_init_req(BLE_SM_ID_INFO_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -423,6 +441,9 @@ ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd)
 
     txom->om_data[0] = BLE_SM_OP_IDENTITY_INFO;
     memcpy(txom->om_data + 1, cmd->irk, sizeof cmd->irk);
+
+    BLE_SM_LOG_CMD(1, "id info", conn_handle, ble_sm_id_info_log, cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -432,7 +453,14 @@ done:
 }
 
 void
-ble_sm_iden_addr_parse(void *payload, int len,
+ble_sm_id_info_log(struct ble_sm_id_info *cmd)
+{
+    BLE_HS_LOG(DEBUG, "irk=");
+    ble_hs_misc_log_flat_buf(cmd->irk, sizeof cmd->irk);
+}
+
+void
+ble_sm_id_addr_info_parse(void *payload, int len,
                        struct ble_sm_id_addr_info *cmd)
 {
     uint8_t *u8ptr = payload;
@@ -441,16 +469,11 @@ ble_sm_iden_addr_parse(void *payload, int len,
 }
 
 int
-ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd)
+ble_sm_id_addr_info_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd)
 {
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_enc_info_tx(); conn_handle=%d addr_type=%d "
-                      "addr=");
-    ble_hs_misc_log_flat_buf(cmd->bd_addr, sizeof cmd->bd_addr);
-    BLE_HS_LOG(DEBUG, "\n");
-
     rc = ble_sm_init_req(BLE_SM_ID_ADDR_INFO_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -460,6 +483,10 @@ ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd)
     txom->om_data[0] = BLE_SM_OP_IDENTITY_ADDR_INFO;
     txom->om_data[1] = cmd->addr_type;
     memcpy(txom->om_data + 2, cmd->bd_addr, sizeof cmd->bd_addr);
+
+    BLE_SM_LOG_CMD(1, "id addr info", conn_handle, ble_sm_id_addr_info_log,
+                   cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -469,6 +496,13 @@ done:
 }
 
 void
+ble_sm_id_addr_info_log(struct ble_sm_id_addr_info *cmd)
+{
+    BLE_HS_LOG(DEBUG, "addr_type=%d addr=", cmd->addr_type);
+    BLE_HS_LOG_ADDR(DEBUG, cmd->bd_addr);
+}
+
+void
 ble_sm_sign_info_parse(void *payload, int len, struct ble_sm_sign_info *cmd)
 {
     uint8_t *u8ptr = payload;
@@ -483,7 +517,6 @@ ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd)
 
     BLE_HS_LOG(DEBUG, "ble_sm_sign_info_tx(); conn_handle=%d irk=");
     ble_hs_misc_log_flat_buf(cmd->sig_key, sizeof cmd->sig_key);
-    BLE_HS_LOG(DEBUG, "\n");
 
     rc = ble_sm_init_req(BLE_SM_SIGN_INFO_SZ, &txom);
     if (rc != 0) {
@@ -493,6 +526,9 @@ ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd)
 
     txom->om_data[0] = BLE_SM_OP_SIGN_INFO;
     memcpy(txom->om_data + 1, cmd->sig_key, sizeof cmd->sig_key);
+
+    BLE_SM_LOG_CMD(1, "sign info", conn_handle, ble_sm_sign_info_log, cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -502,6 +538,13 @@ done:
 }
 
 void
+ble_sm_sign_info_log(struct ble_sm_sign_info *cmd)
+{
+    BLE_HS_LOG(DEBUG, "sig_key=");
+    ble_hs_misc_log_flat_buf(cmd->sig_key, sizeof cmd->sig_key);
+}
+
+void
 ble_sm_sec_req_parse(void *payload, int len, struct ble_sm_sec_req *cmd)
 {
     uint8_t *u8ptr;
@@ -531,9 +574,6 @@ ble_sm_sec_req_tx(uint16_t conn_handle, struct ble_sm_sec_req *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_sec_req_tx(); conn_handle=%d authreq=0x%02x\n",
-               conn_handle, cmd->authreq);
-
     rc = ble_sm_init_req(BLE_SM_SEC_REQ_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -541,6 +581,9 @@ ble_sm_sec_req_tx(uint16_t conn_handle, struct ble_sm_sec_req *cmd)
     }
 
     ble_sm_sec_req_write(txom->om_data, txom->om_len, cmd);
+
+    BLE_SM_LOG_CMD(1, "sec req", conn_handle, ble_sm_sec_req_log, cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -549,15 +592,17 @@ done:
     return rc;
 }
 
-int
+void
+ble_sm_sec_req_log(struct ble_sm_sec_req *cmd)
+{
+    BLE_HS_LOG(DEBUG, "authreq=0x%02x", cmd->authreq);
+}
+
+void
 ble_sm_public_key_parse(void *payload, int len, struct ble_sm_public_key *cmd)
 {
     uint8_t *u8ptr;
 
-    if (len < BLE_SM_PUBLIC_KEY_SZ) {
-        return BLE_HS_EBADDATA;
-    }
-
     u8ptr = payload;
 
     memcpy(cmd->x, u8ptr, sizeof cmd->x);
@@ -565,8 +610,6 @@ ble_sm_public_key_parse(void *payload, int len, struct ble_sm_public_key *cmd)
 
     memcpy(cmd->y, u8ptr, sizeof cmd->y);
     u8ptr += sizeof cmd->y;
-
-    return 0;
 }
 
 int
@@ -595,12 +638,6 @@ ble_sm_public_key_tx(uint16_t conn_handle, struct ble_sm_public_key *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_public_key_tx(); conn_handle=%d x=");
-    ble_hs_misc_log_flat_buf(cmd->x, sizeof cmd->x);
-    BLE_HS_LOG(DEBUG, "y=");
-    ble_hs_misc_log_flat_buf(cmd->y, sizeof cmd->y);
-    BLE_HS_LOG(DEBUG, "\n");
-
     rc = ble_sm_init_req(BLE_SM_PUBLIC_KEY_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -610,6 +647,8 @@ ble_sm_public_key_tx(uint16_t conn_handle, struct ble_sm_public_key *cmd)
     rc = ble_sm_public_key_write(txom->om_data, txom->om_len, cmd);
     assert(rc == 0);
 
+    BLE_SM_LOG_CMD(1, "public key", conn_handle, ble_sm_public_key_log, cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -618,17 +657,20 @@ done:
     return rc;
 }
 
-int
+void
+ble_sm_public_key_log(struct ble_sm_public_key *cmd)
+{
+    BLE_HS_LOG(DEBUG, "x=");
+    ble_hs_misc_log_flat_buf(cmd->x, sizeof cmd->x);
+    BLE_HS_LOG(DEBUG, "y=");
+    ble_hs_misc_log_flat_buf(cmd->y, sizeof cmd->y);
+}
+
+void
 ble_sm_dhkey_check_parse(void *payload, int len,
                          struct ble_sm_dhkey_check *cmd)
 {
-    if (len < BLE_SM_DHKEY_CHECK_SZ) {
-        return BLE_HS_EBADDATA;
-    }
-
     memcpy(cmd->value, payload, sizeof cmd->value);
-
-    return 0;
 }
 
 int
@@ -657,10 +699,6 @@ ble_sm_dhkey_check_tx(uint16_t conn_handle, struct ble_sm_dhkey_check *cmd)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_dhkey_check_tx(); conn_handle=%d value=");
-    ble_hs_misc_log_flat_buf(cmd->value, sizeof cmd->value);
-    BLE_HS_LOG(DEBUG, "\n");
-
     rc = ble_sm_init_req(BLE_SM_DHKEY_CHECK_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
@@ -670,6 +708,8 @@ ble_sm_dhkey_check_tx(uint16_t conn_handle, struct ble_sm_dhkey_check *cmd)
     rc = ble_sm_dhkey_check_write(txom->om_data, txom->om_len, cmd);
     assert(rc == 0);
 
+    BLE_SM_LOG_CMD(1, "dhkey check", conn_handle, ble_sm_dhkey_check_log, cmd);
+
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
 
@@ -678,4 +718,11 @@ done:
     return rc;
 }
 
+void
+ble_sm_dhkey_check_log(struct ble_sm_dhkey_check *cmd)
+{
+    BLE_HS_LOG(DEBUG, "value=");
+    ble_hs_misc_log_flat_buf(cmd->value, sizeof cmd->value);
+}
+
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 e7961e2..b4554df 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -310,72 +310,84 @@ void ble_sm_pair_cmd_write(void *payload, int len, int is_req,
                            struct ble_sm_pair_cmd *cmd);
 int ble_sm_pair_cmd_tx(uint16_t conn_handle, int is_req,
                        struct ble_sm_pair_cmd *cmd);
+void ble_sm_pair_cmd_log(struct ble_sm_pair_cmd *cmd);
 void ble_sm_pair_confirm_parse(void *payload, int len,
                                struct ble_sm_pair_confirm *cmd);
 void ble_sm_pair_confirm_write(void *payload, int len,
                                struct ble_sm_pair_confirm *cmd);
 int ble_sm_pair_confirm_tx(uint16_t conn_handle,
                            struct ble_sm_pair_confirm *cmd);
+void ble_sm_pair_confirm_log(struct ble_sm_pair_confirm *cmd);
 void ble_sm_pair_random_parse(void *payload, int len,
                               struct ble_sm_pair_random *cmd);
 void ble_sm_pair_random_write(void *payload, int len,
                               struct ble_sm_pair_random *cmd);
 int ble_sm_pair_random_tx(uint16_t conn_handle,
                           struct ble_sm_pair_random *cmd);
+void ble_sm_pair_random_log(struct ble_sm_pair_random *cmd);
 void ble_sm_pair_fail_parse(void *payload, int len,
                             struct ble_sm_pair_fail *cmd);
 void ble_sm_pair_fail_write(void *payload, int len,
                             struct ble_sm_pair_fail *cmd);
 int ble_sm_pair_fail_tx(uint16_t conn_handle, uint8_t reason);
-
-int ble_sm_alg_s1(uint8_t *k, uint8_t *r1, uint8_t *r2, uint8_t *out);
-int ble_sm_alg_c1(uint8_t *k, uint8_t *r,
-                  uint8_t *preq, uint8_t *pres,
-                  uint8_t iat, uint8_t rat,
-                  uint8_t *ia, uint8_t *ra,
-                  uint8_t *out_enc_data);
-int ble_sm_alg_f4(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t z,
-                  uint8_t *out_enc_data);
-int ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y,
-                  uint32_t *passkey);
-int ble_sm_alg_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t a1t,
-                  uint8_t *a1, uint8_t a2t, uint8_t *a2,
-                  uint8_t *mackey, uint8_t *ltk);
-int ble_sm_alg_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r,
-                  uint8_t *iocap, uint8_t a1t, uint8_t *a1,
-                  uint8_t a2t, uint8_t *a2, uint8_t *check);
-int ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
-                         uint32_t *our_priv_key, void *out_dhkey);
-int ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv);
-
+void ble_sm_pair_fail_log(struct ble_sm_pair_fail *cmd);
 void ble_sm_enc_info_parse(void *payload, int len,
                            struct ble_sm_enc_info *cmd);
 int ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd);
+void ble_sm_enc_info_log(struct ble_sm_enc_info *cmd);
 void ble_sm_master_id_parse(void *payload, int len,
                             struct ble_sm_master_id *cmd);
 int ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd);
+void ble_sm_master_id_log(struct ble_sm_master_id *cmd);
 void ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd);
 int ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd);
-void ble_sm_iden_addr_parse(void *payload, int len,
+void ble_sm_id_info_log(struct ble_sm_id_info *cmd);
+void ble_sm_id_addr_info_parse(void *payload, int len,
                             struct ble_sm_id_addr_info *cmd);
-int ble_sm_iden_addr_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd);
+int ble_sm_id_addr_info_tx(uint16_t conn_handle,
+                           struct ble_sm_id_addr_info *cmd);
+void ble_sm_id_addr_info_log(struct ble_sm_id_addr_info *cmd);
 void ble_sm_sign_info_parse(void *payload, int len,
                             struct ble_sm_sign_info *cmd);
 int ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd);
+void ble_sm_sign_info_log(struct ble_sm_sign_info *cmd);
 void ble_sm_sec_req_parse(void *payload, int len, struct ble_sm_sec_req *cmd);
 void ble_sm_sec_req_write(void *payload, int len, struct ble_sm_sec_req *cmd);
 int ble_sm_sec_req_tx(uint16_t conn_handle, struct ble_sm_sec_req *cmd);
-int ble_sm_public_key_parse(void *payload, int len,
-                            struct ble_sm_public_key *cmd);
+void ble_sm_sec_req_log(struct ble_sm_sec_req *cmd);
+void ble_sm_public_key_parse(void *payload, int len,
+                             struct ble_sm_public_key *cmd);
 int ble_sm_public_key_write(void *payload, int len,
                             struct ble_sm_public_key *cmd);
 int ble_sm_public_key_tx(uint16_t conn_handle, struct ble_sm_public_key *cmd);
-int ble_sm_dhkey_check_parse(void *payload, int len,
-                             struct ble_sm_dhkey_check *cmd);
+void ble_sm_public_key_log(struct ble_sm_public_key *cmd);
+void ble_sm_dhkey_check_parse(void *payload, int len,
+                              struct ble_sm_dhkey_check *cmd);
 int ble_sm_dhkey_check_write(void *payload, int len,
                              struct ble_sm_dhkey_check *cmd);
 int ble_sm_dhkey_check_tx(uint16_t conn_handle,
                           struct ble_sm_dhkey_check *cmd);
+void ble_sm_dhkey_check_log(struct ble_sm_dhkey_check *cmd);
+
+int ble_sm_alg_s1(uint8_t *k, uint8_t *r1, uint8_t *r2, uint8_t *out);
+int ble_sm_alg_c1(uint8_t *k, uint8_t *r,
+                  uint8_t *preq, uint8_t *pres,
+                  uint8_t iat, uint8_t rat,
+                  uint8_t *ia, uint8_t *ra,
+                  uint8_t *out_enc_data);
+int ble_sm_alg_f4(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t z,
+                  uint8_t *out_enc_data);
+int ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y,
+                  uint32_t *passkey);
+int ble_sm_alg_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t a1t,
+                  uint8_t *a1, uint8_t a2t, uint8_t *a2,
+                  uint8_t *mackey, uint8_t *ltk);
+int ble_sm_alg_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r,
+                  uint8_t *iocap, uint8_t a1t, uint8_t *a1,
+                  uint8_t a2t, uint8_t *a2, uint8_t *check);
+int ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
+                         uint32_t *our_priv_key, void *out_dhkey);
+int ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv);
 
 void ble_sm_enc_change_rx(struct hci_encrypt_change *evt);
 int ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt);
@@ -386,7 +398,7 @@ void ble_sm_lgcy_confirm_exec(struct ble_sm_proc *proc,
 void ble_sm_lgcy_random_exec(struct ble_sm_proc *proc,
                              struct ble_sm_result *res);
 void ble_sm_lgcy_random_rx(struct ble_sm_proc *proc,
-                               struct ble_sm_result *res);
+                           struct ble_sm_result *res);
 
 #if NIMBLE_OPT(SM_SC)
 int ble_sm_sc_io_action(struct ble_sm_proc *proc);
@@ -442,15 +454,13 @@ int ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk,
                         uint16_t ediv, uint64_t rand_val, int auth);
 int ble_sm_init(void);
 
+#define BLE_SM_LOG_CMD(is_tx, cmd_name, conn_handle, log_cb, cmd) \
+    BLE_HS_LOG_CMD((is_tx), "sm", (cmd_name), (conn_handle), (log_cb), (cmd))
+
 #else
 
-#ifdef BLE_HS_DEBUG
-#define ble_sm_dbg_set_next_rand(next_rand)
 #define ble_sm_dbg_num_procs() 0
-#endif
-
 #define ble_sm_create_chan() NULL
-
 #define ble_sm_enc_change_rx(evt) ((void)(evt))
 #define ble_sm_ltk_req_rx(evt) ((void)(evt))
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7120ba14/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 32c362c..7163b8d 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -485,8 +485,7 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     }
 
     ble_sm_public_key_parse((*om)->om_data, (*om)->om_len, &cmd);
-
-    BLE_HS_LOG(DEBUG, "rxed sm public key cmd\n");
+    BLE_SM_LOG_CMD(0, "public key", conn_handle, ble_sm_public_key_log, &cmd);
 
     ble_hs_lock();
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_PUBLIC_KEY, -1,
@@ -661,15 +660,9 @@ ble_sm_sc_dhkey_check_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         return;
     }
 
-    res->app_status = ble_sm_dhkey_check_parse((*om)->om_data, (*om)->om_len,
-                                               &cmd);
-    if (res->app_status != 0) {
-        res->enc_cb = 1;
-        res->sm_err = BLE_SM_ERR_UNSPECIFIED;
-        return;
-    }
-
-    BLE_HS_LOG(DEBUG, "rxed sm dhkey check cmd\n");
+    ble_sm_dhkey_check_parse((*om)->om_data, (*om)->om_len, &cmd);
+    BLE_SM_LOG_CMD(0, "dhkey check", conn_handle, ble_sm_dhkey_check_log,
+                   &cmd);
 
     ble_hs_lock();
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_DHKEY_CHECK, -1,