You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/03/23 07:13:29 UTC

[1/3] incubator-mynewt-core git commit: Add read supported commands and read local supported features commands

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop e233384b4 -> 8a7eb7d48


Add read supported commands and read local supported features commands


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

Branch: refs/heads/develop
Commit: 8a7eb7d4817d935feb8cf8492685d9251a7651fd
Parents: 3dc5a47
Author: wes3 <wi...@micosa.io>
Authored: Tue Mar 22 23:12:38 2016 -0700
Committer: wes3 <wi...@micosa.io>
Committed: Tue Mar 22 23:12:43 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/main.c                         |  10 +
 .../controller/include/controller/ble_ll_hci.h  |   4 +
 net/nimble/controller/src/ble_ll_hci.c          |  49 +++++
 net/nimble/controller/src/ble_ll_supp_cmd.c     | 197 +++++++++++++++++++
 net/nimble/host/include/host/host_hci.h         |   2 +
 net/nimble/host/src/host_dbg.c                  |  83 +++++---
 net/nimble/host/src/host_hci_cmd.c              |  20 ++
 net/nimble/include/nimble/hci_common.h          | 101 +++++-----
 8 files changed, 388 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 8b62c77..0863bf4 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -792,6 +792,16 @@ bletest_task_handler(void *arg)
     assert(rc == 0);
     host_hci_outstanding_opcode = 0;
 
+    /* Read local features */
+    rc = host_hci_cmd_rd_local_feat();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
+    /* Read local commands */
+    rc = host_hci_cmd_rd_local_cmd();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
     /* Read version */
     rc = host_hci_cmd_rd_local_version();
     assert(rc == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/include/controller/ble_ll_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_hci.h b/net/nimble/controller/include/controller/ble_ll_hci.h
index 3e1558f..0f80b54 100644
--- a/net/nimble/controller/include/controller/ble_ll_hci.h
+++ b/net/nimble/controller/include/controller/ble_ll_hci.h
@@ -20,6 +20,10 @@
 #ifndef H_BLE_LL_HCI_
 #define H_BLE_LL_HCI_
 
+/* For supported commands */
+#define BLE_LL_SUPP_CMD_LEN (36)
+extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
+
 /* 
  * This determines the number of outstanding commands allowed from the
  * host to the controller.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 7ac07db..e726fd3 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -123,6 +123,45 @@ ble_ll_hci_rd_local_version(uint8_t *rspbuf, uint8_t *rsplen)
 }
 
 /**
+ * Reade local supported features
+ * 
+ * @param rspbuf 
+ * @param rsplen 
+ * 
+ * @return int 
+ */
+static int
+ble_ll_hci_rd_local_supp_feat(uint8_t *rspbuf, uint8_t *rsplen)
+{
+    /* 
+     * The only two bits we set here currently are:
+     *      BR/EDR not supported        (bit 5)
+     *      LE supported (controller)   (bit 6)
+     */ 
+    memset(rspbuf, 0, BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN);
+    rspbuf[4] = 0x60;
+    *rsplen = BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN;
+    return BLE_ERR_SUCCESS;
+}
+
+/**
+ * Read local supported commands
+ * 
+ * @param rspbuf 
+ * @param rsplen 
+ * 
+ * @return int 
+ */
+static int
+ble_ll_hci_rd_local_supp_cmd(uint8_t *rspbuf, uint8_t *rsplen)
+{
+    memset(rspbuf, 0, BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN);
+    memcpy(rspbuf, g_ble_ll_supp_cmds, sizeof(g_ble_ll_supp_cmds));
+    *rsplen = BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN;
+    return BLE_ERR_SUCCESS;
+}
+
+/**
  * Called to read the public device address of the device
  * 
  * 
@@ -582,6 +621,16 @@ ble_ll_hci_info_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
             rc = ble_ll_hci_rd_local_version(rspbuf, rsplen);
         }
         break;
+    case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
+        if (len == 0) {
+            rc = ble_ll_hci_rd_local_supp_cmd(rspbuf, rsplen);
+        }
+        break;
+    case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
+        if (len == 0) {
+            rc = ble_ll_hci_rd_local_supp_feat(rspbuf, rsplen);
+        }
+        break;
     case BLE_HCI_OCF_IP_RD_BD_ADDR:
         if (len == 0) {
             rc = ble_ll_hci_rd_bd_addr(rspbuf, rsplen);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/src/ble_ll_supp_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_supp_cmd.c b/net/nimble/controller/src/ble_ll_supp_cmd.c
new file mode 100644
index 0000000..1ef5780
--- /dev/null
+++ b/net/nimble/controller/src/ble_ll_supp_cmd.c
@@ -0,0 +1,197 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include "nimble/ble.h"
+#include "nimble/nimble_opt.h"
+#include "nimble/hci_common.h"
+#include "controller/ble_ll.h"
+#include "controller/ble_ll_hci.h"
+
+/* Octet 0 */
+#define BLE_SUPP_CMD_DISCONNECT             (1 << 5)
+#define BLE_LL_SUPP_CMD_OCTET_0             (BLE_SUPP_CMD_DISCONNECT)
+
+/* Octet 5 */
+#define BLE_SUPP_CMD_SET_EVENT_MASK         (1 << 6)
+#define BLE_LL_SUPP_CMD_OCTET_5             (BLE_SUPP_CMD_SET_EVENT_MASK)
+
+/* Octet 10 */
+#define BLE_SUPP_CMD_RD_TX_PWR              (0 << 2)
+#define BLE_LL_SUPP_CMD_OCTET_10            (BLE_SUPP_CMD_RD_TX_PWR)
+
+/* Octet 14 */
+#define BLE_SUPP_CMD_RD_LOC_VER             (1 << 3)
+#define BLE_SUPP_CMD_RD_LOC_SUPP_FEAT       (1 << 5)
+#define BLE_LL_SUPP_CMD_OCTET_14            \
+(                                           \
+    BLE_SUPP_CMD_RD_LOC_VER         |       \
+    BLE_SUPP_CMD_RD_LOC_SUPP_FEAT           \
+)
+
+/* Octet 15 */
+#define BLE_SUPP_CMD_RD_BD_ADDR             (1 << 1)
+#define BLE_SUPP_CMD_RD_RSSI                (1 << 5)
+
+#define BLE_LL_SUPP_CMD_OCTET_15            \
+(                                           \
+    BLE_SUPP_CMD_RD_BD_ADDR         |       \
+    BLE_SUPP_CMD_RD_RSSI                    \
+)
+
+/* Octet 25 */
+#define BLE_SUPP_CMD_LE_SET_EV_MASK         (1 << 0)
+#define BLE_SUPP_CMD_LE_RD_BUF_SIZE         (1 << 1)
+#define BLE_SUPP_CMD_LE_RD_LOC_FEAT         (1 << 2)
+#define BLE_SUPP_CMD_LE_SET_RAND_ADDR       (1 << 4)
+#define BLE_SUPP_CMD_LE_SET_ADV_PARAMS      (1 << 5)
+#define BLE_SUPP_CMD_LE_SET_ADV_TX_PWR      (1 << 6)
+#define BLE_SUPP_CMD_LE_SET_ADV_DATA        (1 << 7)
+
+#define BLE_LL_SUPP_CMD_OCTET_25            \
+(                                           \
+    BLE_SUPP_CMD_LE_SET_EV_MASK     |       \
+    BLE_SUPP_CMD_LE_RD_BUF_SIZE     |       \
+    BLE_SUPP_CMD_LE_RD_LOC_FEAT     |       \
+    BLE_SUPP_CMD_LE_SET_RAND_ADDR   |       \
+    BLE_SUPP_CMD_LE_SET_ADV_PARAMS  |       \
+    BLE_SUPP_CMD_LE_SET_ADV_TX_PWR  |       \
+    BLE_SUPP_CMD_LE_SET_ADV_DATA            \
+)
+
+/* Octet 26 */
+#define BLE_SUPP_CMD_LE_SET_SCAN_RSP_DATA   (1 << 0)
+#define BLE_SUPP_CMD_LE_SET_ADV_ENABLE      (1 << 1)
+#define BLE_SUPP_CMD_LE_SET_SCAN_PARAMS     (1 << 2)
+#define BLE_SUPP_CMD_LE_SET_SCAN_ENABLE     (1 << 3)
+#define BLE_SUPP_CMD_LE_CREATE_CONN         (1 << 4)
+#define BLE_SUPP_CMD_LE_CREATE_CONN_CANCEL  (1 << 5)
+#define BLE_SUPP_CMD_LE_RD_WHITELIST_SIZE   (1 << 6)
+#define BLE_SUPP_CMD_LE_CLR_WHITELIST       (1 << 7)
+
+#define BLE_LL_SUPP_CMD_OCTET_26            \
+(                                           \
+    BLE_SUPP_CMD_LE_SET_SCAN_RSP_DATA   |   \
+    BLE_SUPP_CMD_LE_SET_ADV_ENABLE      |   \
+    BLE_SUPP_CMD_LE_SET_SCAN_PARAMS     |   \
+    BLE_SUPP_CMD_LE_SET_SCAN_ENABLE     |   \
+    BLE_SUPP_CMD_LE_CREATE_CONN         |   \
+    BLE_SUPP_CMD_LE_CREATE_CONN_CANCEL  |   \
+    BLE_SUPP_CMD_LE_RD_WHITELIST_SIZE   |   \
+    BLE_SUPP_CMD_LE_CLR_WHITELIST           \
+)
+
+/* Octet 27 */
+#define BLE_SUPP_CMD_LE_ADD_DEV_WHITELIST   (1 << 0)
+#define BLE_SUPP_CMD_LE_RMV_DEV_WHITELIST   (1 << 1)
+#define BLE_SUPP_CMD_LE_CONN_UPDATE         (1 << 2)
+#define BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS (1 << 3)
+#define BLE_SUPP_CMD_LE_RD_CHAN_MAP         (1 << 4)
+#define BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    (1 << 5)
+#define BLE_SUPP_CMD_LE_ENCRYPT             (0 << 6)
+#define BLE_SUPP_CMD_LE_RAND                (0 << 7)
+
+#define BLE_LL_SUPP_CMD_OCTET_27            \
+(                                           \
+    BLE_SUPP_CMD_LE_ADD_DEV_WHITELIST   |   \
+    BLE_SUPP_CMD_LE_RMV_DEV_WHITELIST   |   \
+    BLE_SUPP_CMD_LE_CONN_UPDATE         |   \
+    BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS |   \
+    BLE_SUPP_CMD_LE_RD_CHAN_MAP         |   \
+    BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    |   \
+    BLE_SUPP_CMD_LE_ENCRYPT             |   \
+    BLE_SUPP_CMD_LE_RAND                    \
+)
+
+/* Octet 28 */
+#define BLE_SUPP_CMD_LE_START_ENCRYPT       (0 << 0)
+#define BLE_SUPP_CMD_LE_LTK_REQ_REPLY       (0 << 1)
+#define BLE_SUPP_CMD_LE_LTK_REQ_NEG_REPLY   (0 << 2)
+#define BLE_SUPP_CMD_LE_READ_SUPP_STATES    (1 << 3)
+#define BLE_SUPP_CMD_LE_RX_TEST             (0 << 4)
+#define BLE_SUPP_CMD_LE_TX_TEST             (0 << 5)
+#define BLE_SUPP_CMD_LE_TEST_END            (0 << 6)
+
+#define BLE_LL_SUPP_CMD_OCTET_28            \
+(                                           \
+    BLE_SUPP_CMD_LE_START_ENCRYPT       |   \
+    BLE_SUPP_CMD_LE_LTK_REQ_REPLY       |   \
+    BLE_SUPP_CMD_LE_LTK_REQ_NEG_REPLY   |   \
+    BLE_SUPP_CMD_LE_READ_SUPP_STATES    |   \
+    BLE_SUPP_CMD_LE_RX_TEST             |   \
+    BLE_SUPP_CMD_LE_TX_TEST             |   \
+    BLE_SUPP_CMD_LE_TEST_END                \
+)
+
+/* Octet 33 */
+#define BLE_SUPP_CMD_LE_REM_CONN_PRR        (1 << 4)
+#define BLE_SUPP_CMD_LE_REM_CONN_PRNR       (1 << 5)
+#define BLE_SUPP_CMD_LE_SET_DATALEN         (0 << 6)
+#define BLE_SUPP_CMD_LE_RD_SUGG_DATALEN     (0 << 7)
+
+#define BLE_LL_SUPP_CMD_OCTET_33            \
+(                                           \
+    BLE_SUPP_CMD_LE_REM_CONN_PRR        |   \
+    BLE_SUPP_CMD_LE_REM_CONN_PRNR       |   \
+    BLE_SUPP_CMD_LE_SET_DATALEN         |   \
+    BLE_SUPP_CMD_LE_RD_SUGG_DATALEN         \
+)
+
+/* Defines the array of supported commands */
+const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN] =
+{
+    BLE_LL_SUPP_CMD_OCTET_0,            /* Octet 0 */
+    0, 
+    0, 
+    0, 
+    0, 
+    BLE_LL_SUPP_CMD_OCTET_5, 
+    0, 
+    0,
+    0,                                  /* Octet 8 */
+    0, 
+    BLE_LL_SUPP_CMD_OCTET_10, 
+    0, 
+    0, 
+    0, 
+    BLE_LL_SUPP_CMD_OCTET_14, 
+    BLE_LL_SUPP_CMD_OCTET_15, 
+    0,                                  /* Octet 16 */
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,                                 /* Octet 24 */
+    BLE_LL_SUPP_CMD_OCTET_25,
+    BLE_LL_SUPP_CMD_OCTET_26,
+    BLE_LL_SUPP_CMD_OCTET_27,
+    BLE_LL_SUPP_CMD_OCTET_28,
+    0,
+    0,
+    0,
+    0,                                  /* Octet 32 */
+    BLE_LL_SUPP_CMD_OCTET_33,
+    34,
+    35,
+};

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index f6c0d1e..d920d18 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -31,6 +31,8 @@ int host_hci_cmd_set_event_mask(uint64_t event_mask);
 int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
 int host_hci_cmd_rd_rem_version(uint16_t handle);
 int host_hci_cmd_rd_local_version(void);
+int host_hci_cmd_rd_local_feat(void);
+int host_hci_cmd_rd_local_cmd(void);
 int host_hci_cmd_rd_bd_addr(void);
 int host_hci_cmd_read_rssi(uint16_t handle);
 int host_hci_cmd_le_set_host_chan_class(uint8_t *new_chan_map);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index ae9dff0..e17ae4b 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -26,7 +26,7 @@
 #include "nimble/hci_transport.h"
 #include "ble_hs_priv.h"
 
-void
+static void
 host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
 {
     int8_t rssi;
@@ -138,7 +138,7 @@ host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
  * @param evdata 
  * @param len 
  */
-void
+static void
 host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
 {
     uint8_t status;
@@ -178,7 +178,7 @@ host_hci_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
  * @param evdata 
  * @param len 
  */
-void
+static void
 host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
 {
     uint8_t handles;
@@ -211,42 +211,70 @@ host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
     }
 }
 
-void
+static void
+host_hci_dbg_cmd_comp_info_params(uint8_t status, uint8_t ocf, uint8_t *evdata)
+{
+    int i;
+    uint8_t *dptr;
+
+    if (status != BLE_ERR_SUCCESS) {
+        return;
+    }
+
+    switch (ocf) {
+    case BLE_HCI_OCF_IP_RD_LOCAL_VER:
+        BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
+                          "lmp_subver=%u",
+                   evdata[0], le16toh(evdata + 1), evdata[3],
+                   le16toh(evdata + 4), le16toh(evdata + 6));
+        break;
+    case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
+        BLE_HS_LOG(DEBUG, "supp_cmds=");
+        dptr = evdata;
+        for (i = 0; i < 8; ++i) {
+            BLE_HS_LOG(DEBUG, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:",
+                       dptr[0], dptr[1], dptr[2], dptr[3],
+                       dptr[4], dptr[5], dptr[6], dptr[7]);
+            dptr += 8;
+        }
+        break;
+    case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
+        BLE_HS_LOG(DEBUG, "supp_feat=0x%lx%08lx",
+                   le32toh(evdata + 4), le32toh(evdata));
+        break;
+    case BLE_HCI_OCF_IP_RD_BD_ADDR:
+        BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
+                   evdata[5], evdata[4], evdata[3],
+                   evdata[2], evdata[1], evdata[0]);
+        break;
+    default:
+        break;
+    }
+}
+
+static void
 host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
 {
+    uint8_t cmd_pkts;
     uint8_t ogf;
     uint8_t ocf;
+    uint8_t status;
     uint16_t opcode;
 
+    cmd_pkts = evdata[0];
     opcode = le16toh(evdata + 1);
     ogf = BLE_HCI_OGF(opcode);
     ocf = BLE_HCI_OCF(opcode);
+    status = evdata[3];
 
     BLE_HS_LOG(DEBUG, "Command Complete: cmd_pkts=%u ogf=0x%x ocf=0x%x "
-                      "status=%u ", evdata[0], ogf, ocf, evdata[3]);
+                      "status=%u ", cmd_pkts, ogf, ocf, status);
 
     /* Display parameters based on command. */
     switch (ogf) {
     case BLE_HCI_OGF_INFO_PARAMS:
-        switch (ocf) {
-        case BLE_HCI_OCF_IP_RD_LOCAL_VER:
-            if (evdata[3] == BLE_ERR_SUCCESS) {
-                BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
-                                  "lmp_subver=%u",
-                           evdata[4], le16toh(evdata + 5), evdata[7],
-                           le16toh(evdata + 8), le16toh(evdata + 10));
-            }
-            break;
-        case BLE_HCI_OCF_IP_RD_BD_ADDR:
-            if (evdata[3] == BLE_ERR_SUCCESS) {
-                BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
-                           evdata[9], evdata[8], evdata[7],
-                           evdata[6], evdata[5], evdata[4]);
-            }
-            break;
-        default:
-            break;
-        }
+        evdata += 4;
+        host_hci_dbg_cmd_comp_info_params(status, ocf, evdata);
         break;
     case BLE_HCI_OGF_STATUS_PARAMS:
         switch (ocf) {
@@ -271,7 +299,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
                        le16toh(evdata + 8), le16toh(evdata + 10));
             break;
         case BLE_HCI_OCF_LE_RD_SUPP_STATES:
-            BLE_HS_LOG(DEBUG, "states=0x%lx%lx", le32toh(evdata + 8),
+            BLE_HS_LOG(DEBUG, "states=0x%lx%08lx", le32toh(evdata + 8),
                        le32toh(evdata + 4));
             break;
         default:
@@ -284,7 +312,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
     BLE_HS_LOG(DEBUG, "\n");
 }
 
-void
+static void
 host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
 {
     uint8_t ogf;
@@ -306,9 +334,10 @@ host_hci_dbg_event_disp(uint8_t *evbuf)
     uint8_t evcode;
     uint8_t len;
  
+    /* Extract event code and length; move pointer to event parameter data */
     evcode = evbuf[0];
     len = evbuf[1];
-    evdata = evbuf + 2;
+    evdata = evbuf + BLE_HCI_EVENT_HDR_LEN;
 
     switch (evcode) {
     case BLE_HCI_EVCODE_DISCONN_CMP:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index 8839c12..39f7784 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -238,6 +238,26 @@ host_hci_cmd_rd_local_version(void)
 }
 
 int
+host_hci_cmd_rd_local_feat(void)
+{
+    int rc;
+
+    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
+                           BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT, 0, NULL);
+    return rc;
+}
+
+int
+host_hci_cmd_rd_local_cmd(void)
+{
+    int rc;
+
+    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
+                           BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD, 0, NULL);
+    return rc;
+}
+
+int
 host_hci_cmd_rd_bd_addr(void)
 {
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 3895ac3..331a2ed 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -39,14 +39,13 @@
 #define BLE_HCI_OGF(opcode)                 (((opcode) >> 10) & 0x003F)
 #define BLE_HCI_OCF(opcode)                 ((opcode) & 0x03FF)
 
-/* Opcode Group */
+/* Opcode Group definitions (note: 0x07 not defined in spec) */
 #define BLE_HCI_OGF_LINK_CTRL               (0x01)
 #define BLE_HCI_OGF_LINK_POLICY             (0x02)
 #define BLE_HCI_OGF_CTLR_BASEBAND           (0x03)
 #define BLE_HCI_OGF_INFO_PARAMS             (0x04)
 #define BLE_HCI_OGF_STATUS_PARAMS           (0x05)
 #define BLE_HCI_OGF_TESTING                 (0x06)
-/* NOTE: 0x07 not defined in specification  */
 #define BLE_HCI_OGF_LE                      (0x08)
 
 /* 
@@ -59,51 +58,19 @@
 #define BLE_HCI_OCF_DISCONNECT_CMD          (0x0006)
 #define BLE_HCI_OCF_RD_REM_VER_INFO         (0x001D)
 
-/* Command specific definitions */
-/* Disconnect command */
-#define BLE_HCI_DISCONNECT_CMD_LEN          (3)
-
 /* List of OCF for Controller and Baseband commands (OGF=0x03) */
 #define BLE_HCI_OCF_CB_SET_EVENT_MASK       (0x0001)
 #define BLE_HCI_OCF_CB_RESET                (0x0003)
 #define BLE_HCI_OCF_CB_SET_EV_FILT          (0x0005)
 #define BLE_HCI_OCF_CB_READ_TX_PWR          (0x002D)
 
-/* Command specific definitions */
-/* Set event mask */
-#define BLE_HCI_SET_EVENT_MASK_LEN          (8)
-
 /* List of OCF for Info Param commands (OGF=0x04) */
 #define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
 #define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD      (0x0002)
+#define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT     (0x0003)
 #define BLE_HCI_OCF_IP_RD_BD_ADDR           (0x0009)
 
-/* Command specific definitions */
-/* NOTE: does not include status field in command complete event! */
-#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
-
-/* Bluetooth Assigned numbers for version information.*/
-#define BLE_HCI_VER_BCS_1_0b                (0)
-#define BLE_HCI_VER_BCS_1_1                 (1)
-#define BLE_HCI_VER_BCS_1_2                 (2)
-#define BLE_HCI_VER_BCS_2_0_EDR             (3)
-#define BLE_HCI_VER_BCS_2_1_EDR             (4)
-#define BLE_HCI_VER_BCS_3_0_HCS             (5)
-#define BLE_HCI_VER_BCS_4_0                 (6)
-#define BLE_HCI_VER_BCS_4_1                 (7)
-#define BLE_HCI_VER_BCS_4_2                 (8)
-
-#define BLE_LMP_VER_BCS_1_0b                (0)
-#define BLE_LMP_VER_BCS_1_1                 (1)
-#define BLE_LMP_VER_BCS_1_2                 (2)
-#define BLE_LMP_VER_BCS_2_0_EDR             (3)
-#define BLE_LMP_VER_BCS_2_1_EDR             (4)
-#define BLE_LMP_VER_BCS_3_0_HCS             (5)
-#define BLE_LMP_VER_BCS_4_0                 (6)
-#define BLE_LMP_VER_BCS_4_1                 (7)
-#define BLE_LMP_VER_BCS_4_2                 (8)
-
-/* List of OCD for Status parameters commands (OGF = 0x05) */
+/* List of OCF for Status parameters commands (OGF = 0x05) */
 #define BLE_HCI_OCF_RD_RSSI                 (0x0005)
 
 /* List of OCF for LE commands (OGF = 0x08) */
@@ -156,21 +123,32 @@
 #define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN      (0x002F)
 
 /* Command Specific Definitions */
+/* --- Disconnect command (OGF 0x01, OCF 0x0006) --- */
+#define BLE_HCI_DISCONNECT_CMD_LEN          (3)
+
+/* --- Set event mask (OGF 0x03, OCF 0x0001 --- */
+#define BLE_HCI_SET_EVENT_MASK_LEN          (8)
+
+/* --- Read local version information (OGF 0x04, OCF 0x0001) --- */
+/* NOTE: does not include status field in command complete event! */
+#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
+#define BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN      (64)
+
 /* --- Read RSSI (OGF 0x05, OCF 0x0005) --- */
-#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN (4)  /* Includes status byte. */
+#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN     (4)  /* Includes status byte. */
 
 /* --- LE set event mask (OCF 0x0001) --- */
-#define BLE_HCI_SET_LE_EVENT_MASK_LEN   (8)
+#define BLE_HCI_SET_LE_EVENT_MASK_LEN       (8)
 
 /* --- LE read buffer size (OCF 0x0002) --- */
-#define BLE_HCI_RD_BUF_SIZE_LEN         (0)
-#define BLE_HCI_RD_BUF_SIZE_RSPLEN      (3)
+#define BLE_HCI_RD_BUF_SIZE_LEN             (0)
+#define BLE_HCI_RD_BUF_SIZE_RSPLEN          (3)
 
 /* --- LE read local supported features (OCF 0x0003) --- */
-#define BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN (8)
+#define BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN     (8)
 
 /* --- LE set advertising parameters (OCF 0x0006) */
-#define BLE_HCI_SET_ADV_PARAM_LEN       (15)
+#define BLE_HCI_SET_ADV_PARAM_LEN           (15)
 
 /* Advertising types */
 #define BLE_HCI_ADV_TYPE_ADV_IND            (0)
@@ -181,11 +159,11 @@
 #define BLE_HCI_ADV_TYPE_MAX                (4)
 
 /* Own address types */
-#define BLE_HCI_ADV_OWN_ADDR_PUBLIC     (0)
-#define BLE_HCI_ADV_OWN_ADDR_RANDOM     (1)
-#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB   (2)
-#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND  (3)
-#define BLE_HCI_ADV_OWN_ADDR_MAX        (3)
+#define BLE_HCI_ADV_OWN_ADDR_PUBLIC         (0)
+#define BLE_HCI_ADV_OWN_ADDR_RANDOM         (1)
+#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB       (2)
+#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND      (3)
+#define BLE_HCI_ADV_OWN_ADDR_MAX            (3)
 
 /* Advertisement peer address Type */
 #define BLE_HCI_ADV_PEER_ADDR_PUBLIC        (0)
@@ -198,16 +176,16 @@
 #define BLE_HCI_ADV_CHAN_TXPWR_MAX             (10)
 
 /* --- LE set advertising data (OCF 0x0008) */
-#define BLE_HCI_MAX_ADV_DATA_LEN        (31)
+#define BLE_HCI_MAX_ADV_DATA_LEN            (31)
 
 /* --- LE set scan response data (OCF 0x0009) */
-#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN   (31)
+#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN       (31)
 
 /* --- LE set advertising enable (OCF 0x000a) */
-#define BLE_HCI_SET_ADV_ENABLE_LEN      (1)
+#define BLE_HCI_SET_ADV_ENABLE_LEN          (1)
 
 /* --- LE set scan enable (OCF 0x000c) */
-#define BLE_HCI_SET_SCAN_ENABLE_LEN     (2)
+#define BLE_HCI_SET_SCAN_ENABLE_LEN         (2)
 
 /* Connect peer address type */
 #define BLE_HCI_CONN_PEER_ADDR_PUBLIC        (0)
@@ -474,6 +452,27 @@
 /* LE data length change event (sub event 0x07) */
 #define BLE_HCI_LE_DATA_LEN_CHG_LEN         (11)
 
+/* Bluetooth Assigned numbers for version information.*/
+#define BLE_HCI_VER_BCS_1_0b                (0)
+#define BLE_HCI_VER_BCS_1_1                 (1)
+#define BLE_HCI_VER_BCS_1_2                 (2)
+#define BLE_HCI_VER_BCS_2_0_EDR             (3)
+#define BLE_HCI_VER_BCS_2_1_EDR             (4)
+#define BLE_HCI_VER_BCS_3_0_HCS             (5)
+#define BLE_HCI_VER_BCS_4_0                 (6)
+#define BLE_HCI_VER_BCS_4_1                 (7)
+#define BLE_HCI_VER_BCS_4_2                 (8)
+
+#define BLE_LMP_VER_BCS_1_0b                (0)
+#define BLE_LMP_VER_BCS_1_1                 (1)
+#define BLE_LMP_VER_BCS_1_2                 (2)
+#define BLE_LMP_VER_BCS_2_0_EDR             (3)
+#define BLE_LMP_VER_BCS_2_1_EDR             (4)
+#define BLE_LMP_VER_BCS_3_0_HCS             (5)
+#define BLE_LMP_VER_BCS_4_0                 (6)
+#define BLE_LMP_VER_BCS_4_1                 (7)
+#define BLE_LMP_VER_BCS_4_2                 (8)
+
 /*--- Shared data structures ---*/
 /* Read local version information (OGF=0x0004, OCF=0x0001) */
 struct hci_loc_ver_info


[2/3] incubator-mynewt-core git commit: MYNEWT-100: remove need for each connection to have its own empty pdu

Posted by we...@apache.org.
MYNEWT-100: remove need for each connection to have its own empty pdu


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

Branch: refs/heads/develop
Commit: 3dc5a478405b66e318b3b80b1306ce9dc4e7ebb2
Parents: d360e4f
Author: wes3 <wi...@micosa.io>
Authored: Tue Mar 22 17:01:09 2016 -0700
Committer: wes3 <wi...@micosa.io>
Committed: Tue Mar 22 23:12:43 2016 -0700

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll_conn.h |  18 +-
 net/nimble/controller/src/ble_ll_conn.c         | 303 ++++++++++---------
 net/nimble/host/src/host_hci.c                  |   2 +
 net/nimble/include/nimble/ble.h                 |  20 +-
 4 files changed, 184 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3dc5a478/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index 7670ac0..a813c81 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -77,7 +77,9 @@ union ble_ll_conn_sm_flags {
         uint16_t version_ind_sent:1;
         uint16_t rxd_version_ind:1;
         uint16_t chanmap_update_scheduled:1;
-        uint16_t reserved:3;
+        uint16_t conn_empty_pdu_txd:1;
+        uint16_t last_txd_md:1;
+        uint16_t reserved:1;
     } cfbit;
     uint16_t conn_flags;
 } __attribute__((packed));
@@ -88,7 +90,8 @@ struct ble_ll_conn_sm
     /* Connection state machine flags */
     union ble_ll_conn_sm_flags csmflags;
 
-    /* Current connection state and role */
+    /* Current connection handle, state and role */
+    uint16_t conn_handle;
     uint8_t conn_state;
     uint8_t conn_role;          /* Can possibly be 1 bit */
 
@@ -122,7 +125,6 @@ struct ble_ll_conn_sm
     /* Ack/Flow Control */
     uint8_t tx_seqnum;          /* note: can be 1 bit */
     uint8_t next_exp_seqnum;    /* note: can be 1 bit */
-    uint8_t last_txd_md;        /* note can be 1 bit */
     uint8_t cons_rxd_bad_crc;   /* note: can be 1 bit */
     uint8_t last_rxd_sn;        /* note: cant be 1 bit given current code */
     uint8_t last_rxd_hdr_byte;  /* note: possibly can make 1 bit since we
@@ -140,7 +142,6 @@ struct ble_ll_conn_sm
     uint8_t vers_nr;
     uint16_t pending_ctrl_procs;
     uint16_t event_cntr;
-    uint16_t conn_handle;
     uint16_t completed_pkts;
     uint16_t comp_id;
     uint16_t sub_vers_nr;
@@ -181,6 +182,7 @@ struct ble_ll_conn_sm
     struct os_event conn_ev_end;
 
     /* Packet transmit queue */
+    struct os_mbuf *cur_tx_pdu;
     STAILQ_HEAD(conn_txq_head, os_mbuf_pkthdr) conn_txq;
 
     /* List entry for active/free connection pools */
@@ -189,9 +191,6 @@ struct ble_ll_conn_sm
         STAILQ_ENTRY(ble_ll_conn_sm) free_stqe;
     };
 
-    /* empty pdu for connection */
-    uint32_t conn_empty_pdu[BLE_LL_EMPTY_PDU_MBUF_SIZE];
-
     /* LL control procedure response timer */
     struct os_callout_func ctrl_proc_rsp_timer;
 
@@ -212,6 +211,11 @@ struct ble_ll_conn_sm
     struct ble_ll_conn_params conn_cp;
 };
 
+/* Flags */
+#define CONN_F_UPDATE_SCHED(csm)    (csm->csmflags.cfbit.conn_update_scheduled)
+#define CONN_F_EMPTY_PDU_TXD(csm)   (csm->csmflags.cfbit.conn_empty_pdu_txd)
+#define CONN_F_LAST_TXD_MD(csm)     (csm->csmflags.cfbit.last_txd_md)
+
 /* 
  * Given a handle, returns an active connection state machine (or NULL if the
  * handle does not exist

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3dc5a478/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 79a0450..991095b 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -113,6 +113,14 @@ extern int ble_hs_rx_data(struct os_mbuf *om);
  */
 #define BLE_LL_WFR_USECS                    (BLE_LL_IFS + 40 + 32)
 
+/* This is a dummy structure we use for the empty PDU */
+struct ble_ll_empty_pdu
+{
+    struct os_mbuf om;
+    struct os_mbuf_pkthdr pkt_hdr;
+    struct ble_mbuf_hdr ble_hdr;
+};
+
 /* We cannot have more than 254 connections given our current implementation */
 #if (NIMBLE_OPT_MAX_CONNECTIONS >= 255)
     #error "Maximum # of connections is 254"
@@ -124,6 +132,7 @@ static const uint16_t g_ble_sca_ppm_tbl[8] =
     500, 250, 150, 100, 75, 50, 30, 20
 };
 
+/* Global LL connection parameters */
 struct ble_ll_conn_global_params g_ble_ll_conn_params;
 
 /* Pointer to connection state machine we are trying to create */
@@ -153,7 +162,6 @@ STATS_SECT_START(ble_ll_conn_stats)
     STATS_SECT_ENTRY(rx_data_pdu_bad_aa)
     STATS_SECT_ENTRY(slave_rxd_bad_conn_req_params)
     STATS_SECT_ENTRY(slave_ce_failures)
-    STATS_SECT_ENTRY(rx_resent_pdus)
     STATS_SECT_ENTRY(data_pdu_rx_dup)
     STATS_SECT_ENTRY(data_pdu_txg)
     STATS_SECT_ENTRY(data_pdu_txf)
@@ -183,7 +191,6 @@ STATS_NAME_START(ble_ll_conn_stats)
     STATS_NAME(ble_ll_conn_stats, rx_data_pdu_bad_aa)
     STATS_NAME(ble_ll_conn_stats, slave_rxd_bad_conn_req_params)
     STATS_NAME(ble_ll_conn_stats, slave_ce_failures)
-    STATS_NAME(ble_ll_conn_stats, rx_resent_pdus)
     STATS_NAME(ble_ll_conn_stats, data_pdu_rx_dup)
     STATS_NAME(ble_ll_conn_stats, data_pdu_txg)
     STATS_NAME(ble_ll_conn_stats, data_pdu_txf)
@@ -200,9 +207,14 @@ STATS_NAME_START(ble_ll_conn_stats)
     STATS_NAME(ble_ll_conn_stats, tx_empty_pdus)
 STATS_NAME_END(ble_ll_conn_stats)
 
-/* Some helpful macros */
-#define BLE_IS_RETRY_M(ble_hdr) ((ble_hdr)->txinfo.flags & BLE_MBUF_HDR_F_TXD)
+/* */
 
+/**
+ * Called to return the currently running connection state machine end time. 
+ * Always called when interrupts are disabled.
+ * 
+ * @return int 0: s1 is not least recently used. 1: s1 is least recently used
+ */
 int 
 ble_ll_conn_is_lru(struct ble_ll_conn_sm *s1, struct ble_ll_conn_sm *s2)
 {
@@ -631,139 +643,150 @@ static int
 ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm, int beg_transition)
 {
     int rc;
-    int tx_empty_pdu;
     uint8_t md;
     uint8_t hdr_byte;
     uint8_t end_transition;
     uint8_t cur_txlen;
     uint8_t next_txlen;
     uint8_t rem_bytes;
+    uint16_t pktlen;
     uint32_t next_event_time;
     uint32_t ticks;
     struct os_mbuf *m;
     struct ble_mbuf_hdr *ble_hdr;
     struct os_mbuf_pkthdr *pkthdr;
     struct os_mbuf_pkthdr *nextpkthdr;
+    struct ble_ll_empty_pdu empty_pdu;
     ble_phy_tx_end_func txend_func;
 
-    /*
-     * Get packet off transmit queue. If not available, send empty PDU. Set
-     * the more data bit as well. 
-     */
+    /* For compiler warnings... */
+    ble_hdr = NULL;
+    m = NULL;
     md = 0;
-    tx_empty_pdu = 0;
+    hdr_byte = BLE_LL_LLID_DATA_FRAG;
+
+    /* 
+     * We need to check if we are retrying a pdu or if there is a pdu on
+     * the transmit queue.
+     */ 
     pkthdr = STAILQ_FIRST(&connsm->conn_txq);
-    if (pkthdr) {
-        m = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
+    if (!connsm->cur_tx_pdu && !CONN_F_EMPTY_PDU_TXD(connsm) && !pkthdr) {
+        CONN_F_EMPTY_PDU_TXD(connsm) = 1;
+        goto conn_tx_pdu;
+    }
+
+    /* 
+     * If we dont have a pdu we have previously transmitted, take it off
+     * the connection transmit queue
+     */ 
+    if (!connsm->cur_tx_pdu && !CONN_F_EMPTY_PDU_TXD(connsm)) {
+        /* Take packet off queue*/
         nextpkthdr = STAILQ_NEXT(pkthdr, omp_next);
+        STAILQ_REMOVE_HEAD(&connsm->conn_txq, omp_next);
+
+        m = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
         ble_hdr = BLE_MBUF_HDR_PTR(m);
 
-        /* 
-         * This piece of code is trying to determine if there are more bytes
-         * to send in the current packet AFTER the current fragment gets sent.
-         * If this is a retry we cant change the size and we use the 
-         * current tx size. If not, we use effective max transmit bytes for the
-         * connection.
-         */
-        if (BLE_IS_RETRY_M(ble_hdr)) {
+        /* Determine packet length we will transmit */
+        cur_txlen = connsm->eff_max_tx_octets;
+        pktlen = pkthdr->omp_len;
+        rem_bytes = pktlen - ble_hdr->txinfo.offset;
+        if (cur_txlen > rem_bytes) {
+            cur_txlen = rem_bytes;
+        }
+
+        /* NOTE: header was set when first enqueued */
+        hdr_byte = ble_hdr->txinfo.hdr_byte;
+        ble_hdr->txinfo.pyld_len = cur_txlen;
+        connsm->cur_tx_pdu = m;
+    } else {
+        nextpkthdr = pkthdr;
+        if (connsm->cur_tx_pdu) {
+            m = connsm->cur_tx_pdu;
+            ble_hdr = BLE_MBUF_HDR_PTR(m);
+            pktlen = OS_MBUF_PKTLEN(m);
             cur_txlen = ble_hdr->txinfo.pyld_len;
-            hdr_byte = ble_hdr->txinfo.hdr_byte;
-            hdr_byte &= ~(BLE_LL_DATA_HDR_MD_MASK | BLE_LL_DATA_HDR_NESN_MASK);
-        } else {
-            /* Determine packet length we will transmit */
-            cur_txlen = connsm->eff_max_tx_octets;
-            rem_bytes = pkthdr->omp_len - ble_hdr->txinfo.offset;
-            if (cur_txlen > rem_bytes) {
-                cur_txlen = rem_bytes;
+            if (ble_hdr->txinfo.offset == 0) {
+                hdr_byte = ble_hdr->txinfo.hdr_byte & BLE_LL_DATA_HDR_LLID_MASK;
             }
+        } else {
+            /* NOTE: header byte gets set later */
+            pktlen = 0;
+            cur_txlen = 0;
+        }
+    }
 
-            /* 
-             * Need to set LLID correctly if this is a fragment. Note
-             * that the LLID is already set the first time it is enqueued.
-             */ 
-            if (ble_hdr->txinfo.offset != 0) {
-                hdr_byte = BLE_LL_LLID_DATA_FRAG;
+    /* 
+     * Set the more data data flag if we have more data to send and we
+     * have not been asked to terminate
+     */ 
+    if ((nextpkthdr || ((ble_hdr->txinfo.offset + cur_txlen) < pktlen)) && 
+         !connsm->csmflags.cfbit.terminate_ind_rxd) {
+        /* Get next event time */
+        next_event_time = ble_ll_conn_get_next_sched_time(connsm);
+
+        /* 
+         * Dont bother to set the MD bit if we cannot do the following:
+         *  -> wait IFS, send the current frame.
+         *  -> wait IFS, receive a maximum size frame.
+         *  -> wait IFS, send the next frame.
+         *  -> wait IFS, receive a maximum size frame.
+         * 
+         *  For slave:
+         *  -> wait IFS, send current frame.
+         *  -> wait IFS, receive maximum size frame.
+         *  -> wait IFS, send next frame.
+         */
+        if ((ble_hdr->txinfo.offset + cur_txlen) < pktlen) {
+            next_txlen = pktlen - (ble_hdr->txinfo.offset + cur_txlen);
+        } else {
+            if (nextpkthdr->omp_len > connsm->eff_max_tx_octets) {
+                next_txlen = connsm->eff_max_tx_octets;
             } else {
-                hdr_byte = ble_hdr->txinfo.hdr_byte;
+                next_txlen = nextpkthdr->omp_len;
             }
-            if (connsm->tx_seqnum) {
-                hdr_byte |= BLE_LL_DATA_HDR_SN_MASK;
-            }
-            ble_hdr->txinfo.pyld_len = cur_txlen;
         }
 
         /* 
-         * Set the more data data flag if we have more data to send and we
-         * have not been asked to terminate
+         * XXX: this calculation is based on using the current time
+         * and assuming the transmission will occur an IFS time from
+         * now. This is not the most accurate especially if we have
+         * received a frame and we are replying to it.
          */ 
-        if ((nextpkthdr || 
-             ((ble_hdr->txinfo.offset + cur_txlen) < pkthdr->omp_len)) && 
-             !connsm->csmflags.cfbit.terminate_ind_rxd) {
-            /* Get next event time */
-            next_event_time = ble_ll_conn_get_next_sched_time(connsm);
-
-            /* 
-             * Dont bother to set the MD bit if we cannot do the following:
-             *  -> wait IFS, send the current frame.
-             *  -> wait IFS, receive a maximum size frame.
-             *  -> wait IFS, send the next frame.
-             *  -> wait IFS, receive a maximum size frame.
-             * 
-             *  For slave:
-             *  -> wait IFS, send current frame.
-             *  -> wait IFS, receive maximum size frame.
-             *  -> wait IFS, send next frame.
-             */
-            if ((ble_hdr->txinfo.offset + cur_txlen) < pkthdr->omp_len) {
-                next_txlen = pkthdr->omp_len - 
-                    (ble_hdr->txinfo.offset + cur_txlen);
-            } else {
-                if (nextpkthdr->omp_len > connsm->eff_max_tx_octets) {
-                    next_txlen = connsm->eff_max_tx_octets;
-                } else {
-                    next_txlen = nextpkthdr->omp_len;
-                }
-            }
+        ticks = (BLE_LL_IFS * 3) + connsm->eff_max_rx_time +
+                BLE_TX_DUR_USECS_M(next_txlen) + 
+                BLE_TX_DUR_USECS_M(cur_txlen);
 
-            /* 
-             * XXX: this calculation is based on using the current time
-             * and assuming the transmission will occur an IFS time from
-             * now. This is not the most accurate especially if we have
-             * received a frame and we are replying to it.
-             */ 
-            ticks = (BLE_LL_IFS * 3) + connsm->eff_max_rx_time +
-                    BLE_TX_DUR_USECS_M(next_txlen) + 
-                    BLE_TX_DUR_USECS_M(cur_txlen);
+        if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
+            ticks += (BLE_LL_IFS + connsm->eff_max_rx_time); 
+        }
 
-            if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
-                ticks += (BLE_LL_IFS + connsm->eff_max_rx_time); 
-            }
+        ticks = cputime_usecs_to_ticks(ticks);
+        if ((cputime_get32() + ticks) < next_event_time) {
+            md = 1;
+        }
+     }
 
-            ticks = cputime_usecs_to_ticks(ticks);
-            if ((cputime_get32() + ticks) >= next_event_time) {
-                md = 0;
-            } else {
-                md = 1;
-            }
-         }
-    } else {
-        /* Send empty pdu. Need to reset some items since we re-use it. */
-        m = (struct os_mbuf *)&connsm->conn_empty_pdu;
-        ble_hdr = BLE_MBUF_HDR_PTR(m);
+    /* If we send an empty PDU we need to initialize the header */
+conn_tx_pdu:
+    if (CONN_F_EMPTY_PDU_TXD(connsm)) {
+        /* 
+         * This looks strange, but we dont use the data pointer in the mbuf
+         * when we have an empty pdu.
+         */
+        m = (struct os_mbuf *)&empty_pdu;
+        m->om_data = (uint8_t *)&empty_pdu;
+        m->om_data += BLE_MBUF_MEMBLOCK_OVERHEAD;
+        ble_hdr = &empty_pdu.ble_hdr;
         ble_hdr->txinfo.flags = 0;
-        pkthdr = OS_MBUF_PKTHDR(m);
-        STAILQ_INSERT_HEAD(&connsm->conn_txq, pkthdr, omp_next);
-
-        /* Set header of empty pdu */
-        hdr_byte = BLE_LL_LLID_DATA_FRAG;
-        if (connsm->tx_seqnum) {
-            hdr_byte |= BLE_LL_DATA_HDR_SN_MASK;
-        }
-        tx_empty_pdu = 1;
+        ble_hdr->txinfo.offset = 0;
+        ble_hdr->txinfo.pyld_len = 0;
     }
 
-    /* Set transmitted flag */
-    ble_hdr->txinfo.flags |= BLE_MBUF_HDR_F_TXD;
+    /* Set tx seqnum */
+    if (connsm->tx_seqnum) {
+        hdr_byte |= BLE_LL_DATA_HDR_SN_MASK;
+    }
 
     /* If we have more data, set the bit */
     if (md) {
@@ -820,10 +843,10 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm, int beg_transition)
         connsm->csmflags.cfbit.pdu_txd = 1;
 
         /* Set last transmitted MD bit */
-        connsm->last_txd_md = md;
+        CONN_F_LAST_TXD_MD(connsm) = md;
 
         /* Increment packets transmitted */
-        if (tx_empty_pdu) {
+        if (CONN_F_EMPTY_PDU_TXD(connsm)) {
             STATS_INC(ble_ll_conn_stats, tx_empty_pdus);
         } else if ((hdr_byte & BLE_LL_DATA_HDR_LLID_MASK) == BLE_LL_LLID_CTRL) {
             STATS_INC(ble_ll_conn_stats, tx_ctrl_pdus);
@@ -955,10 +978,17 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime)
         /* Get next scheduled item time */
         next_sched_time = ble_ll_conn_get_next_sched_time(connsm);
 
-        /* Check if there is a packet on the queue. */
-        pkthdr = STAILQ_FIRST(&connsm->conn_txq);
-        if (pkthdr) {
-            txpdu = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
+        txpdu = connsm->cur_tx_pdu;
+        if (!txpdu) {
+            pkthdr = STAILQ_FIRST(&connsm->conn_txq);
+            if (pkthdr) {
+                txpdu = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
+            }
+        } else {
+            pkthdr = OS_MBUF_PKTHDR(txpdu);
+        }
+
+        if (txpdu) {
             txhdr = BLE_MBUF_HDR_PTR(txpdu);
             rem_bytes = pkthdr->omp_len - txhdr->txinfo.offset;
             if (rem_bytes > connsm->eff_max_tx_octets) {
@@ -1119,9 +1149,9 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
 
     /* Initialize transmit queue and ack/flow control elements */
     STAILQ_INIT(&connsm->conn_txq);
+    connsm->cur_tx_pdu = NULL;
     connsm->tx_seqnum = 0;
     connsm->next_exp_seqnum = 0;
-    connsm->last_txd_md = 0;
     connsm->cons_rxd_bad_crc = 0;
     connsm->last_rxd_sn = 1;
     connsm->completed_pkts = 0;
@@ -1223,6 +1253,12 @@ ble_ll_conn_end(struct ble_ll_conn_sm *connsm, uint8_t ble_err)
     /* Remove from the active connection list */
     SLIST_REMOVE(&g_ble_ll_conn_active_list, connsm, ble_ll_conn_sm, act_sle);
 
+    /* Free the current transmit pdu if there is one. */
+    if (connsm->cur_tx_pdu) {
+        os_mbuf_free_chain(connsm->cur_tx_pdu);
+        connsm->cur_tx_pdu = NULL;
+    }
+
     /* Free all packets on transmit queue */
     while (1) {
         /* Get mbuf pointer from packet header pointer */
@@ -2073,7 +2109,6 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
     uint8_t reply;
     uint32_t ticks;
     struct os_mbuf *txpdu;
-    struct os_mbuf_pkthdr *pkthdr;
     struct ble_ll_conn_sm *connsm;
     struct ble_mbuf_hdr *rxhdr;
     struct ble_mbuf_hdr *txhdr;
@@ -2114,7 +2149,7 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
             reply = 0;
         } else {
             if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
-                reply = connsm->last_txd_md;
+                reply = CONN_F_LAST_TXD_MD(connsm);
             } else {
                 /* A slave always responds with a packet */
                 reply = 1;
@@ -2139,9 +2174,6 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
         conn_nesn = connsm->next_exp_seqnum;
         if ((hdr_sn && conn_nesn) || (!hdr_sn && !conn_nesn)) {
             connsm->next_exp_seqnum ^= 1;
-        } else {
-            /* Count re-sent PDUs. */
-            STATS_INC(ble_ll_conn_stats, rx_resent_pdus);
         }
 
         /* 
@@ -2159,21 +2191,25 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
                 connsm->tx_seqnum ^= 1;
                 STATS_INC(ble_ll_conn_stats, data_pdu_txg);
 
+                /* If we transmitted the empty pdu, clear flag */
+                if (CONN_F_EMPTY_PDU_TXD(connsm)) {
+                    CONN_F_EMPTY_PDU_TXD(connsm) = 0;
+                    goto chk_rx_terminate_ind;
+                }
+
                 /* 
                  * Determine if we should remove packet from queue or if there
                  * are more fragments to send.
                  */
-                pkthdr = STAILQ_FIRST(&connsm->conn_txq);
-                if (pkthdr) {
-                    txpdu = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
-                    txhdr = BLE_MBUF_HDR_PTR(txpdu);
-
+                txpdu = connsm->cur_tx_pdu;
+                if (txpdu) {
                     /* Did we transmit a TERMINATE_IND? If so, we are done */
+                    txhdr = BLE_MBUF_HDR_PTR(txpdu);
                     if (ble_ll_ctrl_is_terminate_ind(txhdr->txinfo.hdr_byte, 
                                                      txpdu->om_data[0])) {
                         connsm->csmflags.cfbit.terminate_ind_txd = 1;
-                        STAILQ_REMOVE_HEAD(&connsm->conn_txq, omp_next);
                         os_mbuf_free_chain(txpdu);
+                        connsm->cur_tx_pdu = NULL;
                         rc = -1;
                         goto conn_rx_pdu_end;
                     }
@@ -2193,9 +2229,7 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
 
                     /* Increment offset based on number of bytes sent */
                     txhdr->txinfo.offset += txhdr->txinfo.pyld_len;
-                    if (txhdr->txinfo.offset >= pkthdr->omp_len) {
-                        STAILQ_REMOVE_HEAD(&connsm->conn_txq, omp_next);
-
+                    if (txhdr->txinfo.offset >= OS_MBUF_PKTLEN(txpdu)) {
                         /* If l2cap pdu, increment # of completed packets */
                         if (ble_ll_conn_is_l2cap_pdu(txhdr)) {
 #if (BLETEST_THROUGHPUT_TEST == 1)
@@ -2205,9 +2239,7 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
                             ++connsm->completed_pkts;
                         }
                         os_mbuf_free_chain(txpdu);
-                    } else {
-                        /* More to go. Clear the TXD flag */
-                        txhdr->txinfo.flags &= ~BLE_MBUF_HDR_F_TXD;
+                        connsm->cur_tx_pdu = NULL;
                     }
                 } else {
                     /* No packet on queue? This is an error! */
@@ -2218,12 +2250,13 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
 
         /* Should we continue connection event? */
         /* If this is a TERMINATE_IND, we have to reply */
+chk_rx_terminate_ind:
         if (ble_ll_ctrl_is_terminate_ind(rxpdu->om_data[0],rxpdu->om_data[2])) {
             connsm->csmflags.cfbit.terminate_ind_rxd = 1;
             connsm->rxd_disconnect_reason = rxpdu->om_data[3];
             reply = 1;
         } else if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
-            reply = connsm->last_txd_md || (hdr_byte & BLE_LL_DATA_HDR_MD_MASK);
+            reply = CONN_F_LAST_TXD_MD(connsm) || (hdr_byte & BLE_LL_DATA_HDR_MD_MASK);
         } else {
             /* A slave always replies */
             reply = 1;
@@ -2569,7 +2602,6 @@ ble_ll_conn_module_init(void)
 {
     int rc;
     uint16_t i;
-    struct os_mbuf *m;
     struct ble_ll_conn_sm *connsm;
 
     /* Initialize list of active conections */
@@ -2583,22 +2615,11 @@ ble_ll_conn_module_init(void)
      */
     connsm = &g_ble_ll_conn_sm[0];
     for (i = 0; i < NIMBLE_OPT_MAX_CONNECTIONS; ++i) {
-        memset(connsm, 0, sizeof(struct ble_ll_conn_sm));
 
+        memset(connsm, 0, sizeof(struct ble_ll_conn_sm));
         connsm->conn_handle = i + 1;
         STAILQ_INSERT_TAIL(&g_ble_ll_conn_free_list, connsm, free_stqe);
 
-        /* Initialize empty pdu */
-        m = (struct os_mbuf *)&connsm->conn_empty_pdu;
-        m->om_data = (uint8_t *)&connsm->conn_empty_pdu[0];
-        m->om_data += BLE_MBUF_MEMBLOCK_OVERHEAD;
-        m->om_pkthdr_len = sizeof(struct ble_mbuf_hdr) + 
-            sizeof(struct os_mbuf_pkthdr);
-        m->om_omp = NULL;
-        m->om_flags = 0;
-
-        ble_ll_mbuf_init(m, 0, BLE_LL_LLID_DATA_FRAG);
-
         /* Initialize fixed schedule elements */
         connsm->conn_sch.sched_type = BLE_LL_SCHED_TYPE_CONN;
         connsm->conn_sch.cb_arg = connsm;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3dc5a478/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index 824873b..bd2f20a 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -667,11 +667,13 @@ host_hci_data_rx(struct os_mbuf *om)
 
     rc = host_hci_data_hdr_strip(om, &hci_hdr);
     if (rc == 0) {
+#if (BLETEST_THROUGHPUT_TEST == 0)
         BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=",
                    BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc), 
                    BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc), 
                    hci_hdr.hdh_len);
         ble_hs_misc_log_mbuf(om);
+#endif
 
         if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
             rc = BLE_HS_EBADDATA;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3dc5a478/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index babb3ac..c8902a2 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -54,6 +54,15 @@ struct ble_mbuf_hdr_rxinfo
     int8_t rssi;
 };
 
+/* Flag definitions for rxinfo  */
+#define BLE_MBUF_HDR_F_CRC_OK           (0x80)
+#define BLE_MBUF_HDR_F_DEVMATCH         (0x40)
+#define BLE_MBUF_HDR_F_CONN_REQ_TXD     (0x20)
+#define BLE_MBUF_HDR_F_SCAN_RSP_TXD     (0x10)
+#define BLE_MBUF_HDR_F_SCAN_RSP_CHK     (0x08)
+#define BLE_MBUF_HDR_F_RXSTATE_MASK     (0x07)      
+
+/* Transmit info. NOTE: no flags defined */
 struct ble_mbuf_hdr_txinfo
 {
     uint8_t flags;
@@ -77,17 +86,6 @@ struct ble_mbuf_hdr
  */
 #define BLE_MBUF_PAYLOAD_SIZE           (260)
 
-/* Flag definitions for rxinfo  */
-#define BLE_MBUF_HDR_F_CRC_OK           (0x80)
-#define BLE_MBUF_HDR_F_DEVMATCH         (0x40)
-#define BLE_MBUF_HDR_F_CONN_REQ_TXD     (0x20)
-#define BLE_MBUF_HDR_F_SCAN_RSP_TXD     (0x10)
-#define BLE_MBUF_HDR_F_SCAN_RSP_CHK     (0x08)
-#define BLE_MBUF_HDR_F_RXSTATE_MASK     (0x07)      
-
-/* Flag definitions for txinfo */
-#define BLE_MBUF_HDR_F_TXD              (0x01)
-
 #define BLE_MBUF_HDR_CRC_OK(hdr)    \
     ((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_CRC_OK)
 


Re: [1/3] incubator-mynewt-core git commit: Add read supported commands and read local supported features commands

Posted by will sanfilippo <wi...@runtime.io>.
Yes, I did push those changes to develop. Please given them a whirl.

Nimble Side Notes:
1) I attempted to create a controller only application. As we expected, there are two functions that are missing (the ones that the controller uses to send the host data and events). A bit unexpected was the hci command pool and associated os events. A simple (possibly) temporary fix was to move those declarations into the common hci definition (duh!). I did that and now there are only those two functions to deal with. More on that later...

2) I looked over the LE controller requirements (Vol 2 Part E 3.19). The only unsupported mandatory command is Test End. We will add that shortly as well as the other test commands (rx and tx).


> On Mar 23, 2016, at 7:05 AM, Sterling Hughes <st...@gmail.com> wrote:
> 
> Hi Will,
> 
> I think some folks were looking for these features, should they try develop branch to test them out?  
> 
> Cheers,
> Sterling 
> 
> 
> Begin forwarded message:
> 
>> From: wes3@apache.org
>> Date: March 22, 2016 at 11:13:29 PM PDT
>> To: commits@mynewt.incubator.apache.org
>> Subject: [1/3] incubator-mynewt-core git commit: Add read supported commands and read local supported features commands
>> Reply-To: dev@mynewt.incubator.apache.org
>> 
>> Repository: incubator-mynewt-core
>> Updated Branches:
>> refs/heads/develop e233384b4 -> 8a7eb7d48
>> 
>> 
>> Add read supported commands and read local supported features commands
>> 
>> 
>> 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/8a7eb7d4
>> Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8a7eb7d4
>> Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8a7eb7d4
>> 
>> Branch: refs/heads/develop
>> Commit: 8a7eb7d4817d935feb8cf8492685d9251a7651fd
>> Parents: 3dc5a47
>> Author: wes3 <wi...@micosa.io>
>> Authored: Tue Mar 22 23:12:38 2016 -0700
>> Committer: wes3 <wi...@micosa.io>
>> Committed: Tue Mar 22 23:12:43 2016 -0700
>> 
>> ----------------------------------------------------------------------
>> apps/bletest/src/main.c                         |  10 +
>> .../controller/include/controller/ble_ll_hci.h  |   4 +
>> net/nimble/controller/src/ble_ll_hci.c          |  49 +++++
>> net/nimble/controller/src/ble_ll_supp_cmd.c     | 197 +++++++++++++++++++
>> net/nimble/host/include/host/host_hci.h         |   2 +
>> net/nimble/host/src/host_dbg.c                  |  83 +++++---
>> net/nimble/host/src/host_hci_cmd.c              |  20 ++
>> net/nimble/include/nimble/hci_common.h          | 101 +++++-----
>> 8 files changed, 388 insertions(+), 78 deletions(-)
>> ----------------------------------------------------------------------
>> 
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/apps/bletest/src/main.c
>> ----------------------------------------------------------------------
>> diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
>> index 8b62c77..0863bf4 100755
>> --- a/apps/bletest/src/main.c
>> +++ b/apps/bletest/src/main.c
>> @@ -792,6 +792,16 @@ bletest_task_handler(void *arg)
>>    assert(rc == 0);
>>    host_hci_outstanding_opcode = 0;
>> 
>> +    /* Read local features */
>> +    rc = host_hci_cmd_rd_local_feat();
>> +    assert(rc == 0);
>> +    host_hci_outstanding_opcode = 0;
>> +
>> +    /* Read local commands */
>> +    rc = host_hci_cmd_rd_local_cmd();
>> +    assert(rc == 0);
>> +    host_hci_outstanding_opcode = 0;
>> +
>>    /* Read version */
>>    rc = host_hci_cmd_rd_local_version();
>>    assert(rc == 0);
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/include/controller/ble_ll_hci.h
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/controller/include/controller/ble_ll_hci.h b/net/nimble/controller/include/controller/ble_ll_hci.h
>> index 3e1558f..0f80b54 100644
>> --- a/net/nimble/controller/include/controller/ble_ll_hci.h
>> +++ b/net/nimble/controller/include/controller/ble_ll_hci.h
>> @@ -20,6 +20,10 @@
>> #ifndef H_BLE_LL_HCI_
>> #define H_BLE_LL_HCI_
>> 
>> +/* For supported commands */
>> +#define BLE_LL_SUPP_CMD_LEN (36)
>> +extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
>> +
>> /* 
>> * This determines the number of outstanding commands allowed from the
>> * host to the controller.
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/src/ble_ll_hci.c
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
>> index 7ac07db..e726fd3 100644
>> --- a/net/nimble/controller/src/ble_ll_hci.c
>> +++ b/net/nimble/controller/src/ble_ll_hci.c
>> @@ -123,6 +123,45 @@ ble_ll_hci_rd_local_version(uint8_t *rspbuf, uint8_t *rsplen)
>> }
>> 
>> /**
>> + * Reade local supported features
>> + * 
>> + * @param rspbuf 
>> + * @param rsplen 
>> + * 
>> + * @return int 
>> + */
>> +static int
>> +ble_ll_hci_rd_local_supp_feat(uint8_t *rspbuf, uint8_t *rsplen)
>> +{
>> +    /* 
>> +     * The only two bits we set here currently are:
>> +     *      BR/EDR not supported        (bit 5)
>> +     *      LE supported (controller)   (bit 6)
>> +     */ 
>> +    memset(rspbuf, 0, BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN);
>> +    rspbuf[4] = 0x60;
>> +    *rsplen = BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN;
>> +    return BLE_ERR_SUCCESS;
>> +}
>> +
>> +/**
>> + * Read local supported commands
>> + * 
>> + * @param rspbuf 
>> + * @param rsplen 
>> + * 
>> + * @return int 
>> + */
>> +static int
>> +ble_ll_hci_rd_local_supp_cmd(uint8_t *rspbuf, uint8_t *rsplen)
>> +{
>> +    memset(rspbuf, 0, BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN);
>> +    memcpy(rspbuf, g_ble_ll_supp_cmds, sizeof(g_ble_ll_supp_cmds));
>> +    *rsplen = BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN;
>> +    return BLE_ERR_SUCCESS;
>> +}
>> +
>> +/**
>> * Called to read the public device address of the device
>> * 
>> * 
>> @@ -582,6 +621,16 @@ ble_ll_hci_info_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
>>            rc = ble_ll_hci_rd_local_version(rspbuf, rsplen);
>>        }
>>        break;
>> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
>> +        if (len == 0) {
>> +            rc = ble_ll_hci_rd_local_supp_cmd(rspbuf, rsplen);
>> +        }
>> +        break;
>> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
>> +        if (len == 0) {
>> +            rc = ble_ll_hci_rd_local_supp_feat(rspbuf, rsplen);
>> +        }
>> +        break;
>>    case BLE_HCI_OCF_IP_RD_BD_ADDR:
>>        if (len == 0) {
>>            rc = ble_ll_hci_rd_bd_addr(rspbuf, rsplen);
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/src/ble_ll_supp_cmd.c
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/controller/src/ble_ll_supp_cmd.c b/net/nimble/controller/src/ble_ll_supp_cmd.c
>> new file mode 100644
>> index 0000000..1ef5780
>> --- /dev/null
>> +++ b/net/nimble/controller/src/ble_ll_supp_cmd.c
>> @@ -0,0 +1,197 @@
>> +/**
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * 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,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> + */
>> +
>> +#include <stdint.h>
>> +#include <string.h>
>> +
>> +#include "nimble/ble.h"
>> +#include "nimble/nimble_opt.h"
>> +#include "nimble/hci_common.h"
>> +#include "controller/ble_ll.h"
>> +#include "controller/ble_ll_hci.h"
>> +
>> +/* Octet 0 */
>> +#define BLE_SUPP_CMD_DISCONNECT             (1 << 5)
>> +#define BLE_LL_SUPP_CMD_OCTET_0             (BLE_SUPP_CMD_DISCONNECT)
>> +
>> +/* Octet 5 */
>> +#define BLE_SUPP_CMD_SET_EVENT_MASK         (1 << 6)
>> +#define BLE_LL_SUPP_CMD_OCTET_5             (BLE_SUPP_CMD_SET_EVENT_MASK)
>> +
>> +/* Octet 10 */
>> +#define BLE_SUPP_CMD_RD_TX_PWR              (0 << 2)
>> +#define BLE_LL_SUPP_CMD_OCTET_10            (BLE_SUPP_CMD_RD_TX_PWR)
>> +
>> +/* Octet 14 */
>> +#define BLE_SUPP_CMD_RD_LOC_VER             (1 << 3)
>> +#define BLE_SUPP_CMD_RD_LOC_SUPP_FEAT       (1 << 5)
>> +#define BLE_LL_SUPP_CMD_OCTET_14            \
>> +(                                           \
>> +    BLE_SUPP_CMD_RD_LOC_VER         |       \
>> +    BLE_SUPP_CMD_RD_LOC_SUPP_FEAT           \
>> +)
>> +
>> +/* Octet 15 */
>> +#define BLE_SUPP_CMD_RD_BD_ADDR             (1 << 1)
>> +#define BLE_SUPP_CMD_RD_RSSI                (1 << 5)
>> +
>> +#define BLE_LL_SUPP_CMD_OCTET_15            \
>> +(                                           \
>> +    BLE_SUPP_CMD_RD_BD_ADDR         |       \
>> +    BLE_SUPP_CMD_RD_RSSI                    \
>> +)
>> +
>> +/* Octet 25 */
>> +#define BLE_SUPP_CMD_LE_SET_EV_MASK         (1 << 0)
>> +#define BLE_SUPP_CMD_LE_RD_BUF_SIZE         (1 << 1)
>> +#define BLE_SUPP_CMD_LE_RD_LOC_FEAT         (1 << 2)
>> +#define BLE_SUPP_CMD_LE_SET_RAND_ADDR       (1 << 4)
>> +#define BLE_SUPP_CMD_LE_SET_ADV_PARAMS      (1 << 5)
>> +#define BLE_SUPP_CMD_LE_SET_ADV_TX_PWR      (1 << 6)
>> +#define BLE_SUPP_CMD_LE_SET_ADV_DATA        (1 << 7)
>> +
>> +#define BLE_LL_SUPP_CMD_OCTET_25            \
>> +(                                           \
>> +    BLE_SUPP_CMD_LE_SET_EV_MASK     |       \
>> +    BLE_SUPP_CMD_LE_RD_BUF_SIZE     |       \
>> +    BLE_SUPP_CMD_LE_RD_LOC_FEAT     |       \
>> +    BLE_SUPP_CMD_LE_SET_RAND_ADDR   |       \
>> +    BLE_SUPP_CMD_LE_SET_ADV_PARAMS  |       \
>> +    BLE_SUPP_CMD_LE_SET_ADV_TX_PWR  |       \
>> +    BLE_SUPP_CMD_LE_SET_ADV_DATA            \
>> +)
>> +
>> +/* Octet 26 */
>> +#define BLE_SUPP_CMD_LE_SET_SCAN_RSP_DATA   (1 << 0)
>> +#define BLE_SUPP_CMD_LE_SET_ADV_ENABLE      (1 << 1)
>> +#define BLE_SUPP_CMD_LE_SET_SCAN_PARAMS     (1 << 2)
>> +#define BLE_SUPP_CMD_LE_SET_SCAN_ENABLE     (1 << 3)
>> +#define BLE_SUPP_CMD_LE_CREATE_CONN         (1 << 4)
>> +#define BLE_SUPP_CMD_LE_CREATE_CONN_CANCEL  (1 << 5)
>> +#define BLE_SUPP_CMD_LE_RD_WHITELIST_SIZE   (1 << 6)
>> +#define BLE_SUPP_CMD_LE_CLR_WHITELIST (1 << 7)
>> +
>> +#define BLE_LL_SUPP_CMD_OCTET_26            \
>> +(                                           \
>> +    BLE_SUPP_CMD_LE_SET_SCAN_RSP_DATA   |   \
>> +    BLE_SUPP_CMD_LE_SET_ADV_ENABLE      |   \
>> +    BLE_SUPP_CMD_LE_SET_SCAN_PARAMS     |   \
>> +    BLE_SUPP_CMD_LE_SET_SCAN_ENABLE     |   \
>> +    BLE_SUPP_CMD_LE_CREATE_CONN         |   \
>> +    BLE_SUPP_CMD_LE_CREATE_CONN_CANCEL  |   \
>> +    BLE_SUPP_CMD_LE_RD_WHITELIST_SIZE   |   \
>> +    BLE_SUPP_CMD_LE_CLR_WHITELIST \
>> +)
>> +
>> +/* Octet 27 */
>> +#define BLE_SUPP_CMD_LE_ADD_DEV_WHITELIST   (1 << 0)
>> +#define BLE_SUPP_CMD_LE_RMV_DEV_WHITELIST   (1 << 1)
>> +#define BLE_SUPP_CMD_LE_CONN_UPDATE         (1 << 2)
>> +#define BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS (1 << 3)
>> +#define BLE_SUPP_CMD_LE_RD_CHAN_MAP         (1 << 4)
>> +#define BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    (1 << 5)
>> +#define BLE_SUPP_CMD_LE_ENCRYPT             (0 << 6)
>> +#define BLE_SUPP_CMD_LE_RAND                (0 << 7)
>> +
>> +#define BLE_LL_SUPP_CMD_OCTET_27            \
>> +(                                           \
>> +    BLE_SUPP_CMD_LE_ADD_DEV_WHITELIST   |   \
>> +    BLE_SUPP_CMD_LE_RMV_DEV_WHITELIST   |   \
>> +    BLE_SUPP_CMD_LE_CONN_UPDATE         |   \
>> +    BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS |   \
>> +    BLE_SUPP_CMD_LE_RD_CHAN_MAP         |   \
>> +    BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    |   \
>> +    BLE_SUPP_CMD_LE_ENCRYPT             |   \
>> +    BLE_SUPP_CMD_LE_RAND                    \
>> +)
>> +
>> +/* Octet 28 */
>> +#define BLE_SUPP_CMD_LE_START_ENCRYPT       (0 << 0)
>> +#define BLE_SUPP_CMD_LE_LTK_REQ_REPLY (0 << 1)
>> +#define BLE_SUPP_CMD_LE_LTK_REQ_NEG_REPLY   (0 << 2)
>> +#define BLE_SUPP_CMD_LE_READ_SUPP_STATES    (1 << 3)
>> +#define BLE_SUPP_CMD_LE_RX_TEST             (0 << 4)
>> +#define BLE_SUPP_CMD_LE_TX_TEST             (0 << 5)
>> +#define BLE_SUPP_CMD_LE_TEST_END            (0 << 6)
>> +
>> +#define BLE_LL_SUPP_CMD_OCTET_28            \
>> +(                                           \
>> +    BLE_SUPP_CMD_LE_START_ENCRYPT       |   \
>> +    BLE_SUPP_CMD_LE_LTK_REQ_REPLY |   \
>> +    BLE_SUPP_CMD_LE_LTK_REQ_NEG_REPLY   |   \
>> +    BLE_SUPP_CMD_LE_READ_SUPP_STATES    |   \
>> +    BLE_SUPP_CMD_LE_RX_TEST             |   \
>> +    BLE_SUPP_CMD_LE_TX_TEST             |   \
>> +    BLE_SUPP_CMD_LE_TEST_END                \
>> +)
>> +
>> +/* Octet 33 */
>> +#define BLE_SUPP_CMD_LE_REM_CONN_PRR        (1 << 4)
>> +#define BLE_SUPP_CMD_LE_REM_CONN_PRNR       (1 << 5)
>> +#define BLE_SUPP_CMD_LE_SET_DATALEN         (0 << 6)
>> +#define BLE_SUPP_CMD_LE_RD_SUGG_DATALEN     (0 << 7)
>> +
>> +#define BLE_LL_SUPP_CMD_OCTET_33            \
>> +(                                           \
>> +    BLE_SUPP_CMD_LE_REM_CONN_PRR        |   \
>> +    BLE_SUPP_CMD_LE_REM_CONN_PRNR       |   \
>> +    BLE_SUPP_CMD_LE_SET_DATALEN         |   \
>> +    BLE_SUPP_CMD_LE_RD_SUGG_DATALEN         \
>> +)
>> +
>> +/* Defines the array of supported commands */
>> +const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN] =
>> +{
>> +    BLE_LL_SUPP_CMD_OCTET_0,            /* Octet 0 */
>> +    0, 
>> +    0, 
>> +    0, 
>> +    0, 
>> +    BLE_LL_SUPP_CMD_OCTET_5, 
>> +    0, 
>> +    0,
>> +    0,                                  /* Octet 8 */
>> +    0, 
>> +    BLE_LL_SUPP_CMD_OCTET_10, 
>> +    0, 
>> +    0, 
>> +    0, 
>> +    BLE_LL_SUPP_CMD_OCTET_14, 
>> +    BLE_LL_SUPP_CMD_OCTET_15, 
>> +    0,                                  /* Octet 16 */
>> +    0,
>> +    0,
>> +    0,
>> +    0,
>> +    0,
>> +    0,
>> +    0,
>> +    0,                                 /* Octet 24 */
>> +    BLE_LL_SUPP_CMD_OCTET_25,
>> +    BLE_LL_SUPP_CMD_OCTET_26,
>> +    BLE_LL_SUPP_CMD_OCTET_27,
>> +    BLE_LL_SUPP_CMD_OCTET_28,
>> +    0,
>> +    0,
>> +    0,
>> +    0,                                  /* Octet 32 */
>> +    BLE_LL_SUPP_CMD_OCTET_33,
>> +    34,
>> +    35,
>> +};
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/include/host/host_hci.h
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
>> index f6c0d1e..d920d18 100644
>> --- a/net/nimble/host/include/host/host_hci.h
>> +++ b/net/nimble/host/include/host/host_hci.h
>> @@ -31,6 +31,8 @@ int host_hci_cmd_set_event_mask(uint64_t event_mask);
>> int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
>> int host_hci_cmd_rd_rem_version(uint16_t handle);
>> int host_hci_cmd_rd_local_version(void);
>> +int host_hci_cmd_rd_local_feat(void);
>> +int host_hci_cmd_rd_local_cmd(void);
>> int host_hci_cmd_rd_bd_addr(void);
>> int host_hci_cmd_read_rssi(uint16_t handle);
>> int host_hci_cmd_le_set_host_chan_class(uint8_t *new_chan_map);
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/src/host_dbg.c
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
>> index ae9dff0..e17ae4b 100644
>> --- a/net/nimble/host/src/host_dbg.c
>> +++ b/net/nimble/host/src/host_dbg.c
>> @@ -26,7 +26,7 @@
>> #include "nimble/hci_transport.h"
>> #include "ble_hs_priv.h"
>> 
>> -void
>> +static void
>> host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
>> {
>>    int8_t rssi;
>> @@ -138,7 +138,7 @@ host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
>> * @param evdata 
>> * @param len 
>> */
>> -void
>> +static void
>> host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
>> {
>>    uint8_t status;
>> @@ -178,7 +178,7 @@ host_hci_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
>> * @param evdata 
>> * @param len 
>> */
>> -void
>> +static void
>> host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
>> {
>>    uint8_t handles;
>> @@ -211,42 +211,70 @@ host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
>>    }
>> }
>> 
>> -void
>> +static void
>> +host_hci_dbg_cmd_comp_info_params(uint8_t status, uint8_t ocf, uint8_t *evdata)
>> +{
>> +    int i;
>> +    uint8_t *dptr;
>> +
>> +    if (status != BLE_ERR_SUCCESS) {
>> +        return;
>> +    }
>> +
>> +    switch (ocf) {
>> +    case BLE_HCI_OCF_IP_RD_LOCAL_VER:
>> +        BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
>> +                          "lmp_subver=%u",
>> +                   evdata[0], le16toh(evdata + 1), evdata[3],
>> +                   le16toh(evdata + 4), le16toh(evdata + 6));
>> +        break;
>> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
>> +        BLE_HS_LOG(DEBUG, "supp_cmds=");
>> +        dptr = evdata;
>> +        for (i = 0; i < 8; ++i) {
>> +            BLE_HS_LOG(DEBUG, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:",
>> +                       dptr[0], dptr[1], dptr[2], dptr[3],
>> +                       dptr[4], dptr[5], dptr[6], dptr[7]);
>> +            dptr += 8;
>> +        }
>> +        break;
>> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
>> +        BLE_HS_LOG(DEBUG, "supp_feat=0x%lx%08lx",
>> +                   le32toh(evdata + 4), le32toh(evdata));
>> +        break;
>> +    case BLE_HCI_OCF_IP_RD_BD_ADDR:
>> +        BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
>> +                   evdata[5], evdata[4], evdata[3],
>> +                   evdata[2], evdata[1], evdata[0]);
>> +        break;
>> +    default:
>> +        break;
>> +    }
>> +}
>> +
>> +static void
>> host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
>> {
>> +    uint8_t cmd_pkts;
>>    uint8_t ogf;
>>    uint8_t ocf;
>> +    uint8_t status;
>>    uint16_t opcode;
>> 
>> +    cmd_pkts = evdata[0];
>>    opcode = le16toh(evdata + 1);
>>    ogf = BLE_HCI_OGF(opcode);
>>    ocf = BLE_HCI_OCF(opcode);
>> +    status = evdata[3];
>> 
>>    BLE_HS_LOG(DEBUG, "Command Complete: cmd_pkts=%u ogf=0x%x ocf=0x%x "
>> -                      "status=%u ", evdata[0], ogf, ocf, evdata[3]);
>> +                      "status=%u ", cmd_pkts, ogf, ocf, status);
>> 
>>    /* Display parameters based on command. */
>>    switch (ogf) {
>>    case BLE_HCI_OGF_INFO_PARAMS:
>> -        switch (ocf) {
>> -        case BLE_HCI_OCF_IP_RD_LOCAL_VER:
>> -            if (evdata[3] == BLE_ERR_SUCCESS) {
>> -                BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
>> -                                  "lmp_subver=%u",
>> -                           evdata[4], le16toh(evdata + 5), evdata[7],
>> -                           le16toh(evdata + 8), le16toh(evdata + 10));
>> -            }
>> -            break;
>> -        case BLE_HCI_OCF_IP_RD_BD_ADDR:
>> -            if (evdata[3] == BLE_ERR_SUCCESS) {
>> -                BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
>> -                           evdata[9], evdata[8], evdata[7],
>> -                           evdata[6], evdata[5], evdata[4]);
>> -            }
>> -            break;
>> -        default:
>> -            break;
>> -        }
>> +        evdata += 4;
>> +        host_hci_dbg_cmd_comp_info_params(status, ocf, evdata);
>>        break;
>>    case BLE_HCI_OGF_STATUS_PARAMS:
>>        switch (ocf) {
>> @@ -271,7 +299,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
>>                       le16toh(evdata + 8), le16toh(evdata + 10));
>>            break;
>>        case BLE_HCI_OCF_LE_RD_SUPP_STATES:
>> -            BLE_HS_LOG(DEBUG, "states=0x%lx%lx", le32toh(evdata + 8),
>> +            BLE_HS_LOG(DEBUG, "states=0x%lx%08lx", le32toh(evdata + 8),
>>                       le32toh(evdata + 4));
>>            break;
>>        default:
>> @@ -284,7 +312,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
>>    BLE_HS_LOG(DEBUG, "\n");
>> }
>> 
>> -void
>> +static void
>> host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
>> {
>>    uint8_t ogf;
>> @@ -306,9 +334,10 @@ host_hci_dbg_event_disp(uint8_t *evbuf)
>>    uint8_t evcode;
>>    uint8_t len;
>> 
>> +    /* Extract event code and length; move pointer to event parameter data */
>>    evcode = evbuf[0];
>>    len = evbuf[1];
>> -    evdata = evbuf + 2;
>> +    evdata = evbuf + BLE_HCI_EVENT_HDR_LEN;
>> 
>>    switch (evcode) {
>>    case BLE_HCI_EVCODE_DISCONN_CMP:
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/src/host_hci_cmd.c
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
>> index 8839c12..39f7784 100644
>> --- a/net/nimble/host/src/host_hci_cmd.c
>> +++ b/net/nimble/host/src/host_hci_cmd.c
>> @@ -238,6 +238,26 @@ host_hci_cmd_rd_local_version(void)
>> }
>> 
>> int
>> +host_hci_cmd_rd_local_feat(void)
>> +{
>> +    int rc;
>> +
>> +    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
>> +                           BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT, 0, NULL);
>> +    return rc;
>> +}
>> +
>> +int
>> +host_hci_cmd_rd_local_cmd(void)
>> +{
>> +    int rc;
>> +
>> +    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
>> +                           BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD, 0, NULL);
>> +    return rc;
>> +}
>> +
>> +int
>> host_hci_cmd_rd_bd_addr(void)
>> {
>>    int rc;
>> 
>> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/include/nimble/hci_common.h
>> ----------------------------------------------------------------------
>> diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
>> index 3895ac3..331a2ed 100644
>> --- a/net/nimble/include/nimble/hci_common.h
>> +++ b/net/nimble/include/nimble/hci_common.h
>> @@ -39,14 +39,13 @@
>> #define BLE_HCI_OGF(opcode)                 (((opcode) >> 10) & 0x003F)
>> #define BLE_HCI_OCF(opcode)                 ((opcode) & 0x03FF)
>> 
>> -/* Opcode Group */
>> +/* Opcode Group definitions (note: 0x07 not defined in spec) */
>> #define BLE_HCI_OGF_LINK_CTRL               (0x01)
>> #define BLE_HCI_OGF_LINK_POLICY             (0x02)
>> #define BLE_HCI_OGF_CTLR_BASEBAND           (0x03)
>> #define BLE_HCI_OGF_INFO_PARAMS             (0x04)
>> #define BLE_HCI_OGF_STATUS_PARAMS           (0x05)
>> #define BLE_HCI_OGF_TESTING                 (0x06)
>> -/* NOTE: 0x07 not defined in specification  */
>> #define BLE_HCI_OGF_LE                      (0x08)
>> 
>> /* 
>> @@ -59,51 +58,19 @@
>> #define BLE_HCI_OCF_DISCONNECT_CMD          (0x0006)
>> #define BLE_HCI_OCF_RD_REM_VER_INFO         (0x001D)
>> 
>> -/* Command specific definitions */
>> -/* Disconnect command */
>> -#define BLE_HCI_DISCONNECT_CMD_LEN          (3)
>> -
>> /* List of OCF for Controller and Baseband commands (OGF=0x03) */
>> #define BLE_HCI_OCF_CB_SET_EVENT_MASK       (0x0001)
>> #define BLE_HCI_OCF_CB_RESET                (0x0003)
>> #define BLE_HCI_OCF_CB_SET_EV_FILT          (0x0005)
>> #define BLE_HCI_OCF_CB_READ_TX_PWR          (0x002D)
>> 
>> -/* Command specific definitions */
>> -/* Set event mask */
>> -#define BLE_HCI_SET_EVENT_MASK_LEN          (8)
>> -
>> /* List of OCF for Info Param commands (OGF=0x04) */
>> #define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
>> #define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD      (0x0002)
>> +#define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT     (0x0003)
>> #define BLE_HCI_OCF_IP_RD_BD_ADDR           (0x0009)
>> 
>> -/* Command specific definitions */
>> -/* NOTE: does not include status field in command complete event! */
>> -#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
>> -
>> -/* Bluetooth Assigned numbers for version information.*/
>> -#define BLE_HCI_VER_BCS_1_0b                (0)
>> -#define BLE_HCI_VER_BCS_1_1                 (1)
>> -#define BLE_HCI_VER_BCS_1_2                 (2)
>> -#define BLE_HCI_VER_BCS_2_0_EDR             (3)
>> -#define BLE_HCI_VER_BCS_2_1_EDR             (4)
>> -#define BLE_HCI_VER_BCS_3_0_HCS             (5)
>> -#define BLE_HCI_VER_BCS_4_0                 (6)
>> -#define BLE_HCI_VER_BCS_4_1                 (7)
>> -#define BLE_HCI_VER_BCS_4_2                 (8)
>> -
>> -#define BLE_LMP_VER_BCS_1_0b                (0)
>> -#define BLE_LMP_VER_BCS_1_1                 (1)
>> -#define BLE_LMP_VER_BCS_1_2                 (2)
>> -#define BLE_LMP_VER_BCS_2_0_EDR             (3)
>> -#define BLE_LMP_VER_BCS_2_1_EDR             (4)
>> -#define BLE_LMP_VER_BCS_3_0_HCS             (5)
>> -#define BLE_LMP_VER_BCS_4_0                 (6)
>> -#define BLE_LMP_VER_BCS_4_1                 (7)
>> -#define BLE_LMP_VER_BCS_4_2                 (8)
>> -
>> -/* List of OCD for Status parameters commands (OGF = 0x05) */
>> +/* List of OCF for Status parameters commands (OGF = 0x05) */
>> #define BLE_HCI_OCF_RD_RSSI                 (0x0005)
>> 
>> /* List of OCF for LE commands (OGF = 0x08) */
>> @@ -156,21 +123,32 @@
>> #define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN      (0x002F)
>> 
>> /* Command Specific Definitions */
>> +/* --- Disconnect command (OGF 0x01, OCF 0x0006) --- */
>> +#define BLE_HCI_DISCONNECT_CMD_LEN          (3)
>> +
>> +/* --- Set event mask (OGF 0x03, OCF 0x0001 --- */
>> +#define BLE_HCI_SET_EVENT_MASK_LEN          (8)
>> +
>> +/* --- Read local version information (OGF 0x04, OCF 0x0001) --- */
>> +/* NOTE: does not include status field in command complete event! */
>> +#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
>> +#define BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN      (64)
>> +
>> /* --- Read RSSI (OGF 0x05, OCF 0x0005) --- */
>> -#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN (4)  /* Includes status byte. */
>> +#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN     (4)  /* Includes status byte. */
>> 
>> /* --- LE set event mask (OCF 0x0001) --- */
>> -#define BLE_HCI_SET_LE_EVENT_MASK_LEN (8)
>> +#define BLE_HCI_SET_LE_EVENT_MASK_LEN (8)
>> 
>> /* --- LE read buffer size (OCF 0x0002) --- */
>> -#define BLE_HCI_RD_BUF_SIZE_LEN         (0)
>> -#define BLE_HCI_RD_BUF_SIZE_RSPLEN      (3)
>> +#define BLE_HCI_RD_BUF_SIZE_LEN             (0)
>> +#define BLE_HCI_RD_BUF_SIZE_RSPLEN          (3)
>> 
>> /* --- LE read local supported features (OCF 0x0003) --- */
>> -#define BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN (8)
>> +#define BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN     (8)
>> 
>> /* --- LE set advertising parameters (OCF 0x0006) */
>> -#define BLE_HCI_SET_ADV_PARAM_LEN       (15)
>> +#define BLE_HCI_SET_ADV_PARAM_LEN           (15)
>> 
>> /* Advertising types */
>> #define BLE_HCI_ADV_TYPE_ADV_IND            (0)
>> @@ -181,11 +159,11 @@
>> #define BLE_HCI_ADV_TYPE_MAX                (4)
>> 
>> /* Own address types */
>> -#define BLE_HCI_ADV_OWN_ADDR_PUBLIC     (0)
>> -#define BLE_HCI_ADV_OWN_ADDR_RANDOM     (1)
>> -#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB   (2)
>> -#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND  (3)
>> -#define BLE_HCI_ADV_OWN_ADDR_MAX        (3)
>> +#define BLE_HCI_ADV_OWN_ADDR_PUBLIC         (0)
>> +#define BLE_HCI_ADV_OWN_ADDR_RANDOM         (1)
>> +#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB       (2)
>> +#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND      (3)
>> +#define BLE_HCI_ADV_OWN_ADDR_MAX            (3)
>> 
>> /* Advertisement peer address Type */
>> #define BLE_HCI_ADV_PEER_ADDR_PUBLIC        (0)
>> @@ -198,16 +176,16 @@
>> #define BLE_HCI_ADV_CHAN_TXPWR_MAX             (10)
>> 
>> /* --- LE set advertising data (OCF 0x0008) */
>> -#define BLE_HCI_MAX_ADV_DATA_LEN        (31)
>> +#define BLE_HCI_MAX_ADV_DATA_LEN            (31)
>> 
>> /* --- LE set scan response data (OCF 0x0009) */
>> -#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN   (31)
>> +#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN       (31)
>> 
>> /* --- LE set advertising enable (OCF 0x000a) */
>> -#define BLE_HCI_SET_ADV_ENABLE_LEN      (1)
>> +#define BLE_HCI_SET_ADV_ENABLE_LEN          (1)
>> 
>> /* --- LE set scan enable (OCF 0x000c) */
>> -#define BLE_HCI_SET_SCAN_ENABLE_LEN     (2)
>> +#define BLE_HCI_SET_SCAN_ENABLE_LEN         (2)
>> 
>> /* Connect peer address type */
>> #define BLE_HCI_CONN_PEER_ADDR_PUBLIC        (0)
>> @@ -474,6 +452,27 @@
>> /* LE data length change event (sub event 0x07) */
>> #define BLE_HCI_LE_DATA_LEN_CHG_LEN         (11)
>> 
>> +/* Bluetooth Assigned numbers for version information.*/
>> +#define BLE_HCI_VER_BCS_1_0b                (0)
>> +#define BLE_HCI_VER_BCS_1_1                 (1)
>> +#define BLE_HCI_VER_BCS_1_2                 (2)
>> +#define BLE_HCI_VER_BCS_2_0_EDR             (3)
>> +#define BLE_HCI_VER_BCS_2_1_EDR             (4)
>> +#define BLE_HCI_VER_BCS_3_0_HCS             (5)
>> +#define BLE_HCI_VER_BCS_4_0                 (6)
>> +#define BLE_HCI_VER_BCS_4_1                 (7)
>> +#define BLE_HCI_VER_BCS_4_2                 (8)
>> +
>> +#define BLE_LMP_VER_BCS_1_0b                (0)
>> +#define BLE_LMP_VER_BCS_1_1                 (1)
>> +#define BLE_LMP_VER_BCS_1_2                 (2)
>> +#define BLE_LMP_VER_BCS_2_0_EDR             (3)
>> +#define BLE_LMP_VER_BCS_2_1_EDR             (4)
>> +#define BLE_LMP_VER_BCS_3_0_HCS             (5)
>> +#define BLE_LMP_VER_BCS_4_0                 (6)
>> +#define BLE_LMP_VER_BCS_4_1                 (7)
>> +#define BLE_LMP_VER_BCS_4_2                 (8)
>> +
>> /*--- Shared data structures ---*/
>> /* Read local version information (OGF=0x0004, OCF=0x0001) */
>> struct hci_loc_ver_info
>> 


Fwd: [1/3] incubator-mynewt-core git commit: Add read supported commands and read local supported features commands

Posted by Sterling Hughes <st...@gmail.com>.
Hi Will,

I think some folks were looking for these features, should they try develop branch to test them out?  

Cheers,
Sterling 


Begin forwarded message:

> From: wes3@apache.org
> Date: March 22, 2016 at 11:13:29 PM PDT
> To: commits@mynewt.incubator.apache.org
> Subject: [1/3] incubator-mynewt-core git commit: Add read supported commands and read local supported features commands
> Reply-To: dev@mynewt.incubator.apache.org
> 
> Repository: incubator-mynewt-core
> Updated Branches:
>  refs/heads/develop e233384b4 -> 8a7eb7d48
> 
> 
> Add read supported commands and read local supported features commands
> 
> 
> 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/8a7eb7d4
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8a7eb7d4
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8a7eb7d4
> 
> Branch: refs/heads/develop
> Commit: 8a7eb7d4817d935feb8cf8492685d9251a7651fd
> Parents: 3dc5a47
> Author: wes3 <wi...@micosa.io>
> Authored: Tue Mar 22 23:12:38 2016 -0700
> Committer: wes3 <wi...@micosa.io>
> Committed: Tue Mar 22 23:12:43 2016 -0700
> 
> ----------------------------------------------------------------------
> apps/bletest/src/main.c                         |  10 +
> .../controller/include/controller/ble_ll_hci.h  |   4 +
> net/nimble/controller/src/ble_ll_hci.c          |  49 +++++
> net/nimble/controller/src/ble_ll_supp_cmd.c     | 197 +++++++++++++++++++
> net/nimble/host/include/host/host_hci.h         |   2 +
> net/nimble/host/src/host_dbg.c                  |  83 +++++---
> net/nimble/host/src/host_hci_cmd.c              |  20 ++
> net/nimble/include/nimble/hci_common.h          | 101 +++++-----
> 8 files changed, 388 insertions(+), 78 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/apps/bletest/src/main.c
> ----------------------------------------------------------------------
> diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
> index 8b62c77..0863bf4 100755
> --- a/apps/bletest/src/main.c
> +++ b/apps/bletest/src/main.c
> @@ -792,6 +792,16 @@ bletest_task_handler(void *arg)
>     assert(rc == 0);
>     host_hci_outstanding_opcode = 0;
> 
> +    /* Read local features */
> +    rc = host_hci_cmd_rd_local_feat();
> +    assert(rc == 0);
> +    host_hci_outstanding_opcode = 0;
> +
> +    /* Read local commands */
> +    rc = host_hci_cmd_rd_local_cmd();
> +    assert(rc == 0);
> +    host_hci_outstanding_opcode = 0;
> +
>     /* Read version */
>     rc = host_hci_cmd_rd_local_version();
>     assert(rc == 0);
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/include/controller/ble_ll_hci.h
> ----------------------------------------------------------------------
> diff --git a/net/nimble/controller/include/controller/ble_ll_hci.h b/net/nimble/controller/include/controller/ble_ll_hci.h
> index 3e1558f..0f80b54 100644
> --- a/net/nimble/controller/include/controller/ble_ll_hci.h
> +++ b/net/nimble/controller/include/controller/ble_ll_hci.h
> @@ -20,6 +20,10 @@
> #ifndef H_BLE_LL_HCI_
> #define H_BLE_LL_HCI_
> 
> +/* For supported commands */
> +#define BLE_LL_SUPP_CMD_LEN (36)
> +extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
> +
> /* 
>  * This determines the number of outstanding commands allowed from the
>  * host to the controller.
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/src/ble_ll_hci.c
> ----------------------------------------------------------------------
> diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
> index 7ac07db..e726fd3 100644
> --- a/net/nimble/controller/src/ble_ll_hci.c
> +++ b/net/nimble/controller/src/ble_ll_hci.c
> @@ -123,6 +123,45 @@ ble_ll_hci_rd_local_version(uint8_t *rspbuf, uint8_t *rsplen)
> }
> 
> /**
> + * Reade local supported features
> + * 
> + * @param rspbuf 
> + * @param rsplen 
> + * 
> + * @return int 
> + */
> +static int
> +ble_ll_hci_rd_local_supp_feat(uint8_t *rspbuf, uint8_t *rsplen)
> +{
> +    /* 
> +     * The only two bits we set here currently are:
> +     *      BR/EDR not supported        (bit 5)
> +     *      LE supported (controller)   (bit 6)
> +     */ 
> +    memset(rspbuf, 0, BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN);
> +    rspbuf[4] = 0x60;
> +    *rsplen = BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN;
> +    return BLE_ERR_SUCCESS;
> +}
> +
> +/**
> + * Read local supported commands
> + * 
> + * @param rspbuf 
> + * @param rsplen 
> + * 
> + * @return int 
> + */
> +static int
> +ble_ll_hci_rd_local_supp_cmd(uint8_t *rspbuf, uint8_t *rsplen)
> +{
> +    memset(rspbuf, 0, BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN);
> +    memcpy(rspbuf, g_ble_ll_supp_cmds, sizeof(g_ble_ll_supp_cmds));
> +    *rsplen = BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN;
> +    return BLE_ERR_SUCCESS;
> +}
> +
> +/**
>  * Called to read the public device address of the device
>  * 
>  * 
> @@ -582,6 +621,16 @@ ble_ll_hci_info_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
>             rc = ble_ll_hci_rd_local_version(rspbuf, rsplen);
>         }
>         break;
> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
> +        if (len == 0) {
> +            rc = ble_ll_hci_rd_local_supp_cmd(rspbuf, rsplen);
> +        }
> +        break;
> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
> +        if (len == 0) {
> +            rc = ble_ll_hci_rd_local_supp_feat(rspbuf, rsplen);
> +        }
> +        break;
>     case BLE_HCI_OCF_IP_RD_BD_ADDR:
>         if (len == 0) {
>             rc = ble_ll_hci_rd_bd_addr(rspbuf, rsplen);
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/controller/src/ble_ll_supp_cmd.c
> ----------------------------------------------------------------------
> diff --git a/net/nimble/controller/src/ble_ll_supp_cmd.c b/net/nimble/controller/src/ble_ll_supp_cmd.c
> new file mode 100644
> index 0000000..1ef5780
> --- /dev/null
> +++ b/net/nimble/controller/src/ble_ll_supp_cmd.c
> @@ -0,0 +1,197 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * 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,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +
> +#include <stdint.h>
> +#include <string.h>
> +
> +#include "nimble/ble.h"
> +#include "nimble/nimble_opt.h"
> +#include "nimble/hci_common.h"
> +#include "controller/ble_ll.h"
> +#include "controller/ble_ll_hci.h"
> +
> +/* Octet 0 */
> +#define BLE_SUPP_CMD_DISCONNECT             (1 << 5)
> +#define BLE_LL_SUPP_CMD_OCTET_0             (BLE_SUPP_CMD_DISCONNECT)
> +
> +/* Octet 5 */
> +#define BLE_SUPP_CMD_SET_EVENT_MASK         (1 << 6)
> +#define BLE_LL_SUPP_CMD_OCTET_5             (BLE_SUPP_CMD_SET_EVENT_MASK)
> +
> +/* Octet 10 */
> +#define BLE_SUPP_CMD_RD_TX_PWR              (0 << 2)
> +#define BLE_LL_SUPP_CMD_OCTET_10            (BLE_SUPP_CMD_RD_TX_PWR)
> +
> +/* Octet 14 */
> +#define BLE_SUPP_CMD_RD_LOC_VER             (1 << 3)
> +#define BLE_SUPP_CMD_RD_LOC_SUPP_FEAT       (1 << 5)
> +#define BLE_LL_SUPP_CMD_OCTET_14            \
> +(                                           \
> +    BLE_SUPP_CMD_RD_LOC_VER         |       \
> +    BLE_SUPP_CMD_RD_LOC_SUPP_FEAT           \
> +)
> +
> +/* Octet 15 */
> +#define BLE_SUPP_CMD_RD_BD_ADDR             (1 << 1)
> +#define BLE_SUPP_CMD_RD_RSSI                (1 << 5)
> +
> +#define BLE_LL_SUPP_CMD_OCTET_15            \
> +(                                           \
> +    BLE_SUPP_CMD_RD_BD_ADDR         |       \
> +    BLE_SUPP_CMD_RD_RSSI                    \
> +)
> +
> +/* Octet 25 */
> +#define BLE_SUPP_CMD_LE_SET_EV_MASK         (1 << 0)
> +#define BLE_SUPP_CMD_LE_RD_BUF_SIZE         (1 << 1)
> +#define BLE_SUPP_CMD_LE_RD_LOC_FEAT         (1 << 2)
> +#define BLE_SUPP_CMD_LE_SET_RAND_ADDR       (1 << 4)
> +#define BLE_SUPP_CMD_LE_SET_ADV_PARAMS      (1 << 5)
> +#define BLE_SUPP_CMD_LE_SET_ADV_TX_PWR      (1 << 6)
> +#define BLE_SUPP_CMD_LE_SET_ADV_DATA        (1 << 7)
> +
> +#define BLE_LL_SUPP_CMD_OCTET_25            \
> +(                                           \
> +    BLE_SUPP_CMD_LE_SET_EV_MASK     |       \
> +    BLE_SUPP_CMD_LE_RD_BUF_SIZE     |       \
> +    BLE_SUPP_CMD_LE_RD_LOC_FEAT     |       \
> +    BLE_SUPP_CMD_LE_SET_RAND_ADDR   |       \
> +    BLE_SUPP_CMD_LE_SET_ADV_PARAMS  |       \
> +    BLE_SUPP_CMD_LE_SET_ADV_TX_PWR  |       \
> +    BLE_SUPP_CMD_LE_SET_ADV_DATA            \
> +)
> +
> +/* Octet 26 */
> +#define BLE_SUPP_CMD_LE_SET_SCAN_RSP_DATA   (1 << 0)
> +#define BLE_SUPP_CMD_LE_SET_ADV_ENABLE      (1 << 1)
> +#define BLE_SUPP_CMD_LE_SET_SCAN_PARAMS     (1 << 2)
> +#define BLE_SUPP_CMD_LE_SET_SCAN_ENABLE     (1 << 3)
> +#define BLE_SUPP_CMD_LE_CREATE_CONN         (1 << 4)
> +#define BLE_SUPP_CMD_LE_CREATE_CONN_CANCEL  (1 << 5)
> +#define BLE_SUPP_CMD_LE_RD_WHITELIST_SIZE   (1 << 6)
> +#define BLE_SUPP_CMD_LE_CLR_WHITELIST (1 << 7)
> +
> +#define BLE_LL_SUPP_CMD_OCTET_26            \
> +(                                           \
> +    BLE_SUPP_CMD_LE_SET_SCAN_RSP_DATA   |   \
> +    BLE_SUPP_CMD_LE_SET_ADV_ENABLE      |   \
> +    BLE_SUPP_CMD_LE_SET_SCAN_PARAMS     |   \
> +    BLE_SUPP_CMD_LE_SET_SCAN_ENABLE     |   \
> +    BLE_SUPP_CMD_LE_CREATE_CONN         |   \
> +    BLE_SUPP_CMD_LE_CREATE_CONN_CANCEL  |   \
> +    BLE_SUPP_CMD_LE_RD_WHITELIST_SIZE   |   \
> +    BLE_SUPP_CMD_LE_CLR_WHITELIST \
> +)
> +
> +/* Octet 27 */
> +#define BLE_SUPP_CMD_LE_ADD_DEV_WHITELIST   (1 << 0)
> +#define BLE_SUPP_CMD_LE_RMV_DEV_WHITELIST   (1 << 1)
> +#define BLE_SUPP_CMD_LE_CONN_UPDATE         (1 << 2)
> +#define BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS (1 << 3)
> +#define BLE_SUPP_CMD_LE_RD_CHAN_MAP         (1 << 4)
> +#define BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    (1 << 5)
> +#define BLE_SUPP_CMD_LE_ENCRYPT             (0 << 6)
> +#define BLE_SUPP_CMD_LE_RAND                (0 << 7)
> +
> +#define BLE_LL_SUPP_CMD_OCTET_27            \
> +(                                           \
> +    BLE_SUPP_CMD_LE_ADD_DEV_WHITELIST   |   \
> +    BLE_SUPP_CMD_LE_RMV_DEV_WHITELIST   |   \
> +    BLE_SUPP_CMD_LE_CONN_UPDATE         |   \
> +    BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS |   \
> +    BLE_SUPP_CMD_LE_RD_CHAN_MAP         |   \
> +    BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    |   \
> +    BLE_SUPP_CMD_LE_ENCRYPT             |   \
> +    BLE_SUPP_CMD_LE_RAND                    \
> +)
> +
> +/* Octet 28 */
> +#define BLE_SUPP_CMD_LE_START_ENCRYPT       (0 << 0)
> +#define BLE_SUPP_CMD_LE_LTK_REQ_REPLY (0 << 1)
> +#define BLE_SUPP_CMD_LE_LTK_REQ_NEG_REPLY   (0 << 2)
> +#define BLE_SUPP_CMD_LE_READ_SUPP_STATES    (1 << 3)
> +#define BLE_SUPP_CMD_LE_RX_TEST             (0 << 4)
> +#define BLE_SUPP_CMD_LE_TX_TEST             (0 << 5)
> +#define BLE_SUPP_CMD_LE_TEST_END            (0 << 6)
> +
> +#define BLE_LL_SUPP_CMD_OCTET_28            \
> +(                                           \
> +    BLE_SUPP_CMD_LE_START_ENCRYPT       |   \
> +    BLE_SUPP_CMD_LE_LTK_REQ_REPLY |   \
> +    BLE_SUPP_CMD_LE_LTK_REQ_NEG_REPLY   |   \
> +    BLE_SUPP_CMD_LE_READ_SUPP_STATES    |   \
> +    BLE_SUPP_CMD_LE_RX_TEST             |   \
> +    BLE_SUPP_CMD_LE_TX_TEST             |   \
> +    BLE_SUPP_CMD_LE_TEST_END                \
> +)
> +
> +/* Octet 33 */
> +#define BLE_SUPP_CMD_LE_REM_CONN_PRR        (1 << 4)
> +#define BLE_SUPP_CMD_LE_REM_CONN_PRNR       (1 << 5)
> +#define BLE_SUPP_CMD_LE_SET_DATALEN         (0 << 6)
> +#define BLE_SUPP_CMD_LE_RD_SUGG_DATALEN     (0 << 7)
> +
> +#define BLE_LL_SUPP_CMD_OCTET_33            \
> +(                                           \
> +    BLE_SUPP_CMD_LE_REM_CONN_PRR        |   \
> +    BLE_SUPP_CMD_LE_REM_CONN_PRNR       |   \
> +    BLE_SUPP_CMD_LE_SET_DATALEN         |   \
> +    BLE_SUPP_CMD_LE_RD_SUGG_DATALEN         \
> +)
> +
> +/* Defines the array of supported commands */
> +const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN] =
> +{
> +    BLE_LL_SUPP_CMD_OCTET_0,            /* Octet 0 */
> +    0, 
> +    0, 
> +    0, 
> +    0, 
> +    BLE_LL_SUPP_CMD_OCTET_5, 
> +    0, 
> +    0,
> +    0,                                  /* Octet 8 */
> +    0, 
> +    BLE_LL_SUPP_CMD_OCTET_10, 
> +    0, 
> +    0, 
> +    0, 
> +    BLE_LL_SUPP_CMD_OCTET_14, 
> +    BLE_LL_SUPP_CMD_OCTET_15, 
> +    0,                                  /* Octet 16 */
> +    0,
> +    0,
> +    0,
> +    0,
> +    0,
> +    0,
> +    0,
> +    0,                                 /* Octet 24 */
> +    BLE_LL_SUPP_CMD_OCTET_25,
> +    BLE_LL_SUPP_CMD_OCTET_26,
> +    BLE_LL_SUPP_CMD_OCTET_27,
> +    BLE_LL_SUPP_CMD_OCTET_28,
> +    0,
> +    0,
> +    0,
> +    0,                                  /* Octet 32 */
> +    BLE_LL_SUPP_CMD_OCTET_33,
> +    34,
> +    35,
> +};
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/include/host/host_hci.h
> ----------------------------------------------------------------------
> diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
> index f6c0d1e..d920d18 100644
> --- a/net/nimble/host/include/host/host_hci.h
> +++ b/net/nimble/host/include/host/host_hci.h
> @@ -31,6 +31,8 @@ int host_hci_cmd_set_event_mask(uint64_t event_mask);
> int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
> int host_hci_cmd_rd_rem_version(uint16_t handle);
> int host_hci_cmd_rd_local_version(void);
> +int host_hci_cmd_rd_local_feat(void);
> +int host_hci_cmd_rd_local_cmd(void);
> int host_hci_cmd_rd_bd_addr(void);
> int host_hci_cmd_read_rssi(uint16_t handle);
> int host_hci_cmd_le_set_host_chan_class(uint8_t *new_chan_map);
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/src/host_dbg.c
> ----------------------------------------------------------------------
> diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
> index ae9dff0..e17ae4b 100644
> --- a/net/nimble/host/src/host_dbg.c
> +++ b/net/nimble/host/src/host_dbg.c
> @@ -26,7 +26,7 @@
> #include "nimble/hci_transport.h"
> #include "ble_hs_priv.h"
> 
> -void
> +static void
> host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
> {
>     int8_t rssi;
> @@ -138,7 +138,7 @@ host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
>  * @param evdata 
>  * @param len 
>  */
> -void
> +static void
> host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
> {
>     uint8_t status;
> @@ -178,7 +178,7 @@ host_hci_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
>  * @param evdata 
>  * @param len 
>  */
> -void
> +static void
> host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
> {
>     uint8_t handles;
> @@ -211,42 +211,70 @@ host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
>     }
> }
> 
> -void
> +static void
> +host_hci_dbg_cmd_comp_info_params(uint8_t status, uint8_t ocf, uint8_t *evdata)
> +{
> +    int i;
> +    uint8_t *dptr;
> +
> +    if (status != BLE_ERR_SUCCESS) {
> +        return;
> +    }
> +
> +    switch (ocf) {
> +    case BLE_HCI_OCF_IP_RD_LOCAL_VER:
> +        BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
> +                          "lmp_subver=%u",
> +                   evdata[0], le16toh(evdata + 1), evdata[3],
> +                   le16toh(evdata + 4), le16toh(evdata + 6));
> +        break;
> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
> +        BLE_HS_LOG(DEBUG, "supp_cmds=");
> +        dptr = evdata;
> +        for (i = 0; i < 8; ++i) {
> +            BLE_HS_LOG(DEBUG, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:",
> +                       dptr[0], dptr[1], dptr[2], dptr[3],
> +                       dptr[4], dptr[5], dptr[6], dptr[7]);
> +            dptr += 8;
> +        }
> +        break;
> +    case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
> +        BLE_HS_LOG(DEBUG, "supp_feat=0x%lx%08lx",
> +                   le32toh(evdata + 4), le32toh(evdata));
> +        break;
> +    case BLE_HCI_OCF_IP_RD_BD_ADDR:
> +        BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
> +                   evdata[5], evdata[4], evdata[3],
> +                   evdata[2], evdata[1], evdata[0]);
> +        break;
> +    default:
> +        break;
> +    }
> +}
> +
> +static void
> host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
> {
> +    uint8_t cmd_pkts;
>     uint8_t ogf;
>     uint8_t ocf;
> +    uint8_t status;
>     uint16_t opcode;
> 
> +    cmd_pkts = evdata[0];
>     opcode = le16toh(evdata + 1);
>     ogf = BLE_HCI_OGF(opcode);
>     ocf = BLE_HCI_OCF(opcode);
> +    status = evdata[3];
> 
>     BLE_HS_LOG(DEBUG, "Command Complete: cmd_pkts=%u ogf=0x%x ocf=0x%x "
> -                      "status=%u ", evdata[0], ogf, ocf, evdata[3]);
> +                      "status=%u ", cmd_pkts, ogf, ocf, status);
> 
>     /* Display parameters based on command. */
>     switch (ogf) {
>     case BLE_HCI_OGF_INFO_PARAMS:
> -        switch (ocf) {
> -        case BLE_HCI_OCF_IP_RD_LOCAL_VER:
> -            if (evdata[3] == BLE_ERR_SUCCESS) {
> -                BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
> -                                  "lmp_subver=%u",
> -                           evdata[4], le16toh(evdata + 5), evdata[7],
> -                           le16toh(evdata + 8), le16toh(evdata + 10));
> -            }
> -            break;
> -        case BLE_HCI_OCF_IP_RD_BD_ADDR:
> -            if (evdata[3] == BLE_ERR_SUCCESS) {
> -                BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
> -                           evdata[9], evdata[8], evdata[7],
> -                           evdata[6], evdata[5], evdata[4]);
> -            }
> -            break;
> -        default:
> -            break;
> -        }
> +        evdata += 4;
> +        host_hci_dbg_cmd_comp_info_params(status, ocf, evdata);
>         break;
>     case BLE_HCI_OGF_STATUS_PARAMS:
>         switch (ocf) {
> @@ -271,7 +299,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
>                        le16toh(evdata + 8), le16toh(evdata + 10));
>             break;
>         case BLE_HCI_OCF_LE_RD_SUPP_STATES:
> -            BLE_HS_LOG(DEBUG, "states=0x%lx%lx", le32toh(evdata + 8),
> +            BLE_HS_LOG(DEBUG, "states=0x%lx%08lx", le32toh(evdata + 8),
>                        le32toh(evdata + 4));
>             break;
>         default:
> @@ -284,7 +312,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
>     BLE_HS_LOG(DEBUG, "\n");
> }
> 
> -void
> +static void
> host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
> {
>     uint8_t ogf;
> @@ -306,9 +334,10 @@ host_hci_dbg_event_disp(uint8_t *evbuf)
>     uint8_t evcode;
>     uint8_t len;
> 
> +    /* Extract event code and length; move pointer to event parameter data */
>     evcode = evbuf[0];
>     len = evbuf[1];
> -    evdata = evbuf + 2;
> +    evdata = evbuf + BLE_HCI_EVENT_HDR_LEN;
> 
>     switch (evcode) {
>     case BLE_HCI_EVCODE_DISCONN_CMP:
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/host/src/host_hci_cmd.c
> ----------------------------------------------------------------------
> diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
> index 8839c12..39f7784 100644
> --- a/net/nimble/host/src/host_hci_cmd.c
> +++ b/net/nimble/host/src/host_hci_cmd.c
> @@ -238,6 +238,26 @@ host_hci_cmd_rd_local_version(void)
> }
> 
> int
> +host_hci_cmd_rd_local_feat(void)
> +{
> +    int rc;
> +
> +    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
> +                           BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT, 0, NULL);
> +    return rc;
> +}
> +
> +int
> +host_hci_cmd_rd_local_cmd(void)
> +{
> +    int rc;
> +
> +    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
> +                           BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD, 0, NULL);
> +    return rc;
> +}
> +
> +int
> host_hci_cmd_rd_bd_addr(void)
> {
>     int rc;
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8a7eb7d4/net/nimble/include/nimble/hci_common.h
> ----------------------------------------------------------------------
> diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
> index 3895ac3..331a2ed 100644
> --- a/net/nimble/include/nimble/hci_common.h
> +++ b/net/nimble/include/nimble/hci_common.h
> @@ -39,14 +39,13 @@
> #define BLE_HCI_OGF(opcode)                 (((opcode) >> 10) & 0x003F)
> #define BLE_HCI_OCF(opcode)                 ((opcode) & 0x03FF)
> 
> -/* Opcode Group */
> +/* Opcode Group definitions (note: 0x07 not defined in spec) */
> #define BLE_HCI_OGF_LINK_CTRL               (0x01)
> #define BLE_HCI_OGF_LINK_POLICY             (0x02)
> #define BLE_HCI_OGF_CTLR_BASEBAND           (0x03)
> #define BLE_HCI_OGF_INFO_PARAMS             (0x04)
> #define BLE_HCI_OGF_STATUS_PARAMS           (0x05)
> #define BLE_HCI_OGF_TESTING                 (0x06)
> -/* NOTE: 0x07 not defined in specification  */
> #define BLE_HCI_OGF_LE                      (0x08)
> 
> /* 
> @@ -59,51 +58,19 @@
> #define BLE_HCI_OCF_DISCONNECT_CMD          (0x0006)
> #define BLE_HCI_OCF_RD_REM_VER_INFO         (0x001D)
> 
> -/* Command specific definitions */
> -/* Disconnect command */
> -#define BLE_HCI_DISCONNECT_CMD_LEN          (3)
> -
> /* List of OCF for Controller and Baseband commands (OGF=0x03) */
> #define BLE_HCI_OCF_CB_SET_EVENT_MASK       (0x0001)
> #define BLE_HCI_OCF_CB_RESET                (0x0003)
> #define BLE_HCI_OCF_CB_SET_EV_FILT          (0x0005)
> #define BLE_HCI_OCF_CB_READ_TX_PWR          (0x002D)
> 
> -/* Command specific definitions */
> -/* Set event mask */
> -#define BLE_HCI_SET_EVENT_MASK_LEN          (8)
> -
> /* List of OCF for Info Param commands (OGF=0x04) */
> #define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
> #define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD      (0x0002)
> +#define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT     (0x0003)
> #define BLE_HCI_OCF_IP_RD_BD_ADDR           (0x0009)
> 
> -/* Command specific definitions */
> -/* NOTE: does not include status field in command complete event! */
> -#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
> -
> -/* Bluetooth Assigned numbers for version information.*/
> -#define BLE_HCI_VER_BCS_1_0b                (0)
> -#define BLE_HCI_VER_BCS_1_1                 (1)
> -#define BLE_HCI_VER_BCS_1_2                 (2)
> -#define BLE_HCI_VER_BCS_2_0_EDR             (3)
> -#define BLE_HCI_VER_BCS_2_1_EDR             (4)
> -#define BLE_HCI_VER_BCS_3_0_HCS             (5)
> -#define BLE_HCI_VER_BCS_4_0                 (6)
> -#define BLE_HCI_VER_BCS_4_1                 (7)
> -#define BLE_HCI_VER_BCS_4_2                 (8)
> -
> -#define BLE_LMP_VER_BCS_1_0b                (0)
> -#define BLE_LMP_VER_BCS_1_1                 (1)
> -#define BLE_LMP_VER_BCS_1_2                 (2)
> -#define BLE_LMP_VER_BCS_2_0_EDR             (3)
> -#define BLE_LMP_VER_BCS_2_1_EDR             (4)
> -#define BLE_LMP_VER_BCS_3_0_HCS             (5)
> -#define BLE_LMP_VER_BCS_4_0                 (6)
> -#define BLE_LMP_VER_BCS_4_1                 (7)
> -#define BLE_LMP_VER_BCS_4_2                 (8)
> -
> -/* List of OCD for Status parameters commands (OGF = 0x05) */
> +/* List of OCF for Status parameters commands (OGF = 0x05) */
> #define BLE_HCI_OCF_RD_RSSI                 (0x0005)
> 
> /* List of OCF for LE commands (OGF = 0x08) */
> @@ -156,21 +123,32 @@
> #define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN      (0x002F)
> 
> /* Command Specific Definitions */
> +/* --- Disconnect command (OGF 0x01, OCF 0x0006) --- */
> +#define BLE_HCI_DISCONNECT_CMD_LEN          (3)
> +
> +/* --- Set event mask (OGF 0x03, OCF 0x0001 --- */
> +#define BLE_HCI_SET_EVENT_MASK_LEN          (8)
> +
> +/* --- Read local version information (OGF 0x04, OCF 0x0001) --- */
> +/* NOTE: does not include status field in command complete event! */
> +#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
> +#define BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN      (64)
> +
> /* --- Read RSSI (OGF 0x05, OCF 0x0005) --- */
> -#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN (4)  /* Includes status byte. */
> +#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN     (4)  /* Includes status byte. */
> 
> /* --- LE set event mask (OCF 0x0001) --- */
> -#define BLE_HCI_SET_LE_EVENT_MASK_LEN (8)
> +#define BLE_HCI_SET_LE_EVENT_MASK_LEN (8)
> 
> /* --- LE read buffer size (OCF 0x0002) --- */
> -#define BLE_HCI_RD_BUF_SIZE_LEN         (0)
> -#define BLE_HCI_RD_BUF_SIZE_RSPLEN      (3)
> +#define BLE_HCI_RD_BUF_SIZE_LEN             (0)
> +#define BLE_HCI_RD_BUF_SIZE_RSPLEN          (3)
> 
> /* --- LE read local supported features (OCF 0x0003) --- */
> -#define BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN (8)
> +#define BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN     (8)
> 
> /* --- LE set advertising parameters (OCF 0x0006) */
> -#define BLE_HCI_SET_ADV_PARAM_LEN       (15)
> +#define BLE_HCI_SET_ADV_PARAM_LEN           (15)
> 
> /* Advertising types */
> #define BLE_HCI_ADV_TYPE_ADV_IND            (0)
> @@ -181,11 +159,11 @@
> #define BLE_HCI_ADV_TYPE_MAX                (4)
> 
> /* Own address types */
> -#define BLE_HCI_ADV_OWN_ADDR_PUBLIC     (0)
> -#define BLE_HCI_ADV_OWN_ADDR_RANDOM     (1)
> -#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB   (2)
> -#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND  (3)
> -#define BLE_HCI_ADV_OWN_ADDR_MAX        (3)
> +#define BLE_HCI_ADV_OWN_ADDR_PUBLIC         (0)
> +#define BLE_HCI_ADV_OWN_ADDR_RANDOM         (1)
> +#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB       (2)
> +#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND      (3)
> +#define BLE_HCI_ADV_OWN_ADDR_MAX            (3)
> 
> /* Advertisement peer address Type */
> #define BLE_HCI_ADV_PEER_ADDR_PUBLIC        (0)
> @@ -198,16 +176,16 @@
> #define BLE_HCI_ADV_CHAN_TXPWR_MAX             (10)
> 
> /* --- LE set advertising data (OCF 0x0008) */
> -#define BLE_HCI_MAX_ADV_DATA_LEN        (31)
> +#define BLE_HCI_MAX_ADV_DATA_LEN            (31)
> 
> /* --- LE set scan response data (OCF 0x0009) */
> -#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN   (31)
> +#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN       (31)
> 
> /* --- LE set advertising enable (OCF 0x000a) */
> -#define BLE_HCI_SET_ADV_ENABLE_LEN      (1)
> +#define BLE_HCI_SET_ADV_ENABLE_LEN          (1)
> 
> /* --- LE set scan enable (OCF 0x000c) */
> -#define BLE_HCI_SET_SCAN_ENABLE_LEN     (2)
> +#define BLE_HCI_SET_SCAN_ENABLE_LEN         (2)
> 
> /* Connect peer address type */
> #define BLE_HCI_CONN_PEER_ADDR_PUBLIC        (0)
> @@ -474,6 +452,27 @@
> /* LE data length change event (sub event 0x07) */
> #define BLE_HCI_LE_DATA_LEN_CHG_LEN         (11)
> 
> +/* Bluetooth Assigned numbers for version information.*/
> +#define BLE_HCI_VER_BCS_1_0b                (0)
> +#define BLE_HCI_VER_BCS_1_1                 (1)
> +#define BLE_HCI_VER_BCS_1_2                 (2)
> +#define BLE_HCI_VER_BCS_2_0_EDR             (3)
> +#define BLE_HCI_VER_BCS_2_1_EDR             (4)
> +#define BLE_HCI_VER_BCS_3_0_HCS             (5)
> +#define BLE_HCI_VER_BCS_4_0                 (6)
> +#define BLE_HCI_VER_BCS_4_1                 (7)
> +#define BLE_HCI_VER_BCS_4_2                 (8)
> +
> +#define BLE_LMP_VER_BCS_1_0b                (0)
> +#define BLE_LMP_VER_BCS_1_1                 (1)
> +#define BLE_LMP_VER_BCS_1_2                 (2)
> +#define BLE_LMP_VER_BCS_2_0_EDR             (3)
> +#define BLE_LMP_VER_BCS_2_1_EDR             (4)
> +#define BLE_LMP_VER_BCS_3_0_HCS             (5)
> +#define BLE_LMP_VER_BCS_4_0                 (6)
> +#define BLE_LMP_VER_BCS_4_1                 (7)
> +#define BLE_LMP_VER_BCS_4_2                 (8)
> +
> /*--- Shared data structures ---*/
> /* Read local version information (OGF=0x0004, OCF=0x0001) */
> struct hci_loc_ver_info
> 

[3/3] incubator-mynewt-core git commit: Add the following commands to the controller: read BD address, read supported states and read maximum data length

Posted by we...@apache.org.
Add the following commands to the controller: read BD address, read supported states and read maximum data length


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

Branch: refs/heads/develop
Commit: d360e4fcd36e368b4887dbf17f0e6e40f94a94d4
Parents: e233384
Author: wes3 <wi...@micosa.io>
Authored: Tue Mar 22 16:59:05 2016 -0700
Committer: wes3 <wi...@micosa.io>
Committed: Tue Mar 22 23:12:43 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/main.c                         |  24 +++-
 .../controller/include/controller/ble_ll.h      |   3 +
 net/nimble/controller/src/ble_ll.c              | 109 ++++++++++++++++++-
 net/nimble/controller/src/ble_ll_hci.c          |  90 +++++++++++++--
 net/nimble/host/include/host/host_hci.h         |   4 +-
 net/nimble/host/src/host_dbg.c                  |  26 ++++-
 net/nimble/host/src/host_hci_cmd.c              |  38 +++++++
 net/nimble/include/nimble/hci_common.h          |   9 ++
 net/nimble/src/hci_common.c                     |   4 +-
 9 files changed, 281 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index fe017d0..8b62c77 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -114,8 +114,9 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
 #define BLETEST_CFG_CONCURRENT_CONNS    (1)
 
 /* Test configurations. One of these should be set to 1 */
-#define BLETEST_CONCURRENT_CONN_TEST    (1)
-#define BLETEST_THROUGHPUT_TEST         (0)
+#if ((BLETEST_CONCURRENT_CONN_TEST == 0) && (BLETEST_THROUGHPUT_TEST == 0))
+    #error "Target must define at least one test type!"
+#endif
 
 /* BLETEST variables */
 #undef BLETEST_ADV_PKT_NUM
@@ -630,7 +631,7 @@ bletest_execute_advertiser(void)
                 }
             }
         }
-        g_next_os_time = os_time_get() + OS_TICKS_PER_SEC/4;
+        g_next_os_time = os_time_get() + OS_TICKS_PER_SEC;
     }
 #endif
 
@@ -786,11 +787,26 @@ bletest_task_handler(void *arg)
     assert(rc == 0);
     host_hci_outstanding_opcode = 0;
 
-    /* Turn on all events */
+    /* Read device address */
+    rc = host_hci_cmd_rd_bd_addr();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
+    /* Read version */
     rc = host_hci_cmd_rd_local_version();
     assert(rc == 0);
     host_hci_outstanding_opcode = 0;
 
+    /* Read supported states */
+    rc = host_hci_cmd_le_read_supp_states();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
+    /* Read maximum data length */
+    rc = host_hci_cmd_le_read_max_datalen();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
     /* Wait some time before starting */
     os_time_delay(OS_TICKS_PER_SEC);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index f210dac..76574c0 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -338,6 +338,9 @@ void ble_ll_wfr_disable(void);
 /* Read set of features supported by the Link Layer */
 uint8_t ble_ll_read_supp_features(void);
 
+/* Read set of states supported by the Link Layer */
+uint64_t ble_ll_read_supp_states(void);
+
 /* 
  * XXX: temporary LL debug log. Will get removed once we transition to real
  * log

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index 36ec6ab..0081311 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -48,11 +48,103 @@
  */
 
 /* Configuration for supported features */
-#define BLE_LL_CFG_FEAT_DATA_LEN_EXT
+#undef  BLE_LL_CFG_FEAT_LE_ENCRYPTION
 #define BLE_LL_CFG_FEAT_CONN_PARAM_REQ
-#undef BLE_LL_CFG_FEAT_LE_ENCRYPTION
-#undef BLE_LL_CFG_FEAT_EXT_REJECT_IND
+#undef  BLE_LL_CFG_FEAT_EXT_REJECT_IND
 #define BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG
+#undef  BLE_LL_CFG_FEAT_LE_PING
+#define BLE_LL_CFG_FEAT_DATA_LEN_EXT
+#undef  BLE_LL_CFG_FEAT_LL_PRIVACY
+#undef  BLE_LL_CFG_FEAT_EXT_SCAN_FILT
+
+/* Supported states */
+#define BLE_LL_S_NCA                    (0x00000000001)
+#define BLE_LL_S_SA                     (0x00000000002)
+#define BLE_LL_S_CA                     (0x00000000004)
+#define BLE_LL_S_HDCA                   (0x00000000008)
+#define BLE_LL_S_PS                     (0x00000000010)
+#define BLE_LL_S_AS                     (0x00000000020)
+#define BLE_LL_S_INIT                   (0x00000000040)
+#define BLE_LL_S_SLAVE                  (0x00000000080)
+#define BLE_LL_S_NCA_PS                 (0x00000000100)
+#define BLE_LL_S_SA_PS                  (0x00000000200)
+#define BLE_LL_S_CA_PS                  (0x00000000400)
+#define BLE_LL_S_HDCA_PS                (0x00000000800)
+#define BLE_LL_S_NCA_AS                 (0x00000001000)
+#define BLE_LL_S_SA_AS                  (0x00000002000)
+#define BLE_LL_S_CA_AS                  (0x00000004000)
+#define BLE_LL_S_HDCA_AS                (0x00000008000)
+#define BLE_LL_S_NCA_INIT               (0x00000010000)
+#define BLE_LL_S_SA_INIT                (0x00000020000)
+#define BLE_LL_S_NCA_MASTER             (0x00000040000)
+#define BLE_LL_S_SA_MASTER              (0x00000080000)
+#define BLE_LL_S_NCA_SLAVE              (0x00000100000)
+#define BLE_LL_S_SA_SLAVE               (0x00000200000)
+#define BLE_LL_S_PS_INIT                (0x00000400000)
+#define BLE_LL_S_AS_INIT                (0x00000800000)
+#define BLE_LL_S_PS_MASTER              (0x00001000000)
+#define BLE_LL_S_AS_MASTER              (0x00002000000)
+#define BLE_LL_S_PS_SLAVE               (0x00004000000)
+#define BLE_LL_S_AS_SLAVE               (0x00008000000)
+#define BLE_LL_S_INIT_MASTER            (0x00010000000)
+#define BLE_LL_S_LDCA                   (0x00020000000)
+#define BLE_LL_S_LDCA_PS                (0x00040000000)
+#define BLE_LL_S_LDCA_AS                (0x00080000000)
+#define BLE_LL_S_CA_INIT                (0x00100000000)
+#define BLE_LL_S_HDCA_INIT              (0x00200000000)
+#define BLE_LL_S_LDCA_INIT              (0x00400000000)
+#define BLE_LL_S_CA_MASTER              (0x00800000000)
+#define BLE_LL_S_HDCA_MASTER            (0x01000000000)
+#define BLE_LL_S_LDCA_MASTER            (0x02000000000)
+#define BLE_LL_S_CA_SLAVE               (0x04000000000)
+#define BLE_LL_S_HDCA_SLAVE             (0x08000000000)
+#define BLE_LL_S_LDCA_SLAVE             (0x10000000000)
+#define BLE_LL_S_INIT_SLAVE             (0x20000000000)
+
+#define BLE_LL_SUPPORTED_STATES             \
+(                                           \
+    BLE_LL_S_NCA                    |       \
+    BLE_LL_S_SA                     |       \
+    BLE_LL_S_CA                     |       \
+    BLE_LL_S_HDCA                   |       \
+    BLE_LL_S_PS                     |       \
+    BLE_LL_S_AS                     |       \
+    BLE_LL_S_INIT                   |       \
+    BLE_LL_S_SLAVE                  |       \
+    BLE_LL_S_NCA_PS                 |       \
+    BLE_LL_S_SA_PS                  |       \
+    BLE_LL_S_CA_PS                  |       \
+    BLE_LL_S_HDCA_PS                |       \
+    BLE_LL_S_NCA_AS                 |       \
+    BLE_LL_S_SA_AS                  |       \
+    BLE_LL_S_CA_AS                  |       \
+    BLE_LL_S_HDCA_AS                |       \
+    BLE_LL_S_NCA_INIT               |       \
+    BLE_LL_S_SA_INIT                |       \
+    BLE_LL_S_NCA_MASTER             |       \
+    BLE_LL_S_SA_MASTER              |       \
+    BLE_LL_S_NCA_SLAVE              |       \
+    BLE_LL_S_SA_SLAVE               |       \
+    BLE_LL_S_PS_INIT                |       \
+    BLE_LL_S_AS_INIT                |       \
+    BLE_LL_S_PS_MASTER              |       \
+    BLE_LL_S_AS_MASTER              |       \
+    BLE_LL_S_PS_SLAVE               |       \
+    BLE_LL_S_AS_SLAVE               |       \
+    BLE_LL_S_INIT_MASTER            |       \
+    BLE_LL_S_LDCA                   |       \
+    BLE_LL_S_LDCA_PS                |       \
+    BLE_LL_S_LDCA_AS                |       \
+    BLE_LL_S_CA_INIT                |       \
+    BLE_LL_S_HDCA_INIT              |       \
+    BLE_LL_S_LDCA_INIT              |       \
+    BLE_LL_S_CA_MASTER              |       \
+    BLE_LL_S_HDCA_MASTER            |       \
+    BLE_LL_S_LDCA_MASTER            |       \
+    BLE_LL_S_CA_SLAVE               |       \
+    BLE_LL_S_HDCA_SLAVE             |       \
+    BLE_LL_S_LDCA_SLAVE             |       \
+    BLE_LL_S_INIT_SLAVE)
 
 /* The global BLE LL data object */
 struct ble_ll_obj g_ble_ll_data;
@@ -832,6 +924,17 @@ ble_ll_event_send(struct os_event *ev)
  *
  * @return uint8_t bitmask of supported features.
  */
+uint64_t
+ble_ll_read_supp_states(void)
+{
+    return BLE_LL_SUPPORTED_STATES;
+}
+
+/**
+ * Returns the features supported by the link layer
+ *
+ * @return uint8_t bitmask of supported features.
+ */
 uint8_t
 ble_ll_read_supp_features(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 9d38ba1..7ac07db 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -123,6 +123,27 @@ ble_ll_hci_rd_local_version(uint8_t *rspbuf, uint8_t *rsplen)
 }
 
 /**
+ * Called to read the public device address of the device
+ * 
+ * 
+ * @param rspbuf 
+ * @param rsplen 
+ * 
+ * @return int 
+ */
+static int
+ble_ll_hci_rd_bd_addr(uint8_t *rspbuf, uint8_t *rsplen)
+{    
+    /* 
+     * XXX: for now, assume we always have a public device address. If we
+     * dont, we should set this to zero
+     */ 
+    memcpy(rspbuf, g_dev_addr, BLE_DEV_ADDR_LEN);
+    *rsplen = BLE_DEV_ADDR_LEN;
+    return BLE_ERR_SUCCESS;
+}
+
+/**
  * ll hci set le event mask
  *  
  * Called when the LL controller receives a set LE event mask command.
@@ -161,6 +182,27 @@ ble_ll_hci_le_read_bufsize(uint8_t *rspbuf, uint8_t *rsplen)
 }
 
 /**
+ * HCI read maximum data length command. Returns the controllers max supported 
+ * rx/tx octets/times. 
+ * 
+ * @param rspbuf Pointer to response buffer
+ * @param rsplen Length of response buffer
+ * 
+ * @return int BLE error code
+ */
+static int
+ble_ll_hci_le_rd_max_data_len(uint8_t *rspbuf, uint8_t *rsplen)
+{    
+    /* Place the data packet length and number of packets in the buffer */
+    htole16(rspbuf, g_ble_ll_conn_params.supp_max_tx_octets);
+    htole16(rspbuf + 2, g_ble_ll_conn_params.supp_max_tx_time);
+    htole16(rspbuf + 4, g_ble_ll_conn_params.supp_max_rx_octets);
+    htole16(rspbuf + 6, g_ble_ll_conn_params.supp_max_rx_time);
+    *rsplen = BLE_HCI_RD_MAX_DATALEN_RSPLEN;
+    return BLE_ERR_SUCCESS;
+}
+
+/**
  * HCI read local supported features command. Returns the features 
  * supported by the controller.
  * 
@@ -180,6 +222,27 @@ ble_ll_hci_le_read_local_features(uint8_t *rspbuf, uint8_t *rsplen)
 }
 
 /**
+ * HCI read local supported states command. Returns the states 
+ * supported by the controller.
+ * 
+ * @param rspbuf Pointer to response buffer
+ * @param rsplen Length of response buffer
+ * 
+ * @return int BLE error code
+ */
+static int
+ble_ll_hci_le_read_supp_states(uint8_t *rspbuf, uint8_t *rsplen)
+{    
+    uint64_t supp_states;
+
+    /* Add list of supported states. */
+    supp_states = ble_ll_read_supp_states();
+    htole64(rspbuf, supp_states);
+    *rsplen = BLE_HCI_RD_SUPP_STATES_RSPLEN;
+    return BLE_ERR_SUCCESS;
+}
+
+/**
  * Checks to see if a LE event has been disabled by the host. 
  * 
  * @param subev Sub-event code of the LE Meta event. Note that this can 
@@ -371,12 +434,18 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
     case BLE_HCI_OCF_LE_RD_REM_FEAT:
         rc = ble_ll_conn_hci_read_rem_features(cmdbuf);
         break;
+    case BLE_HCI_OCF_LE_RD_SUPP_STATES :
+        rc = ble_ll_hci_le_read_supp_states(rspbuf, rsplen);
+        break;
     case BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR:
         rc = ble_ll_conn_hci_param_reply(cmdbuf, 0);
         break;
     case BLE_HCI_OCF_LE_REM_CONN_PARAM_RR:
         rc = ble_ll_conn_hci_param_reply(cmdbuf, 1);
         break;
+    case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
+        rc = ble_ll_hci_le_rd_max_data_len(rspbuf, rsplen);
+        break;
     default:
         rc = BLE_ERR_UNKNOWN_HCI_CMD;
         break;
@@ -513,6 +582,11 @@ ble_ll_hci_info_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
             rc = ble_ll_hci_rd_local_version(rspbuf, rsplen);
         }
         break;
+    case BLE_HCI_OCF_IP_RD_BD_ADDR:
+        if (len == 0) {
+            rc = ble_ll_hci_rd_bd_addr(rspbuf, rsplen);
+        }
+        break;
     default:
         rc = BLE_ERR_UNKNOWN_HCI_CMD;
         break;
@@ -558,6 +632,11 @@ ble_ll_hci_status_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen
     return rc;
 }
 
+/**
+ * Called to process an HCI command from the host.
+ * 
+ * @param ev Pointer to os event containing a pointer to command buffer
+ */
 void
 ble_ll_hci_cmd_proc(struct os_event *ev)
 {
@@ -670,17 +749,6 @@ ble_hci_transport_host_acl_data_send(struct os_mbuf *om)
 }
 
 /**
- * Reset the LL HCI interface.
- * 
- */
-void
-ble_ll_hci_reset(void)
-{
-    /* Only need to call the init function again */
-    ble_ll_hci_init();
-}
-
-/**
  * Initalize the LL HCI. 
  *  
  * NOTE: This function is called by the HCI RESET command so if any code 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index f141a22..f6c0d1e 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -31,6 +31,7 @@ int host_hci_cmd_set_event_mask(uint64_t event_mask);
 int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
 int host_hci_cmd_rd_rem_version(uint16_t handle);
 int host_hci_cmd_rd_local_version(void);
+int host_hci_cmd_rd_bd_addr(void);
 int host_hci_cmd_read_rssi(uint16_t handle);
 int host_hci_cmd_le_set_host_chan_class(uint8_t *new_chan_map);
 int host_hci_cmd_le_rd_chanmap(uint16_t handle);
@@ -59,7 +60,8 @@ int host_hci_cmd_le_create_conn_cancel(void);
 int host_hci_cmd_le_conn_update(struct hci_conn_update *hcu);
 int host_hci_cmd_le_conn_param_reply(struct hci_conn_param_reply *hcr);
 int host_hci_cmd_le_conn_param_neg_reply(struct hci_conn_param_neg_reply *hcn);
-
+int host_hci_cmd_le_read_supp_states(void);
+int host_hci_cmd_le_read_max_datalen(void);
 int host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts);
 
 uint16_t host_hci_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index a009a15..ae9dff0 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -223,7 +223,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
     ocf = BLE_HCI_OCF(opcode);
 
     BLE_HS_LOG(DEBUG, "Command Complete: cmd_pkts=%u ogf=0x%x ocf=0x%x "
-                      "status=%u", evdata[0], ogf, ocf, evdata[3]);
+                      "status=%u ", evdata[0], ogf, ocf, evdata[3]);
 
     /* Display parameters based on command. */
     switch (ogf) {
@@ -231,12 +231,19 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
         switch (ocf) {
         case BLE_HCI_OCF_IP_RD_LOCAL_VER:
             if (evdata[3] == BLE_ERR_SUCCESS) {
-                BLE_HS_LOG(DEBUG, " hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u"
-                                  " lmp_subver=%u",
+                BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
+                                  "lmp_subver=%u",
                            evdata[4], le16toh(evdata + 5), evdata[7],
                            le16toh(evdata + 8), le16toh(evdata + 10));
             }
             break;
+        case BLE_HCI_OCF_IP_RD_BD_ADDR:
+            if (evdata[3] == BLE_ERR_SUCCESS) {
+                BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
+                           evdata[9], evdata[8], evdata[7],
+                           evdata[6], evdata[5], evdata[4]);
+            }
+            break;
         default:
             break;
         }
@@ -244,7 +251,7 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
     case BLE_HCI_OGF_STATUS_PARAMS:
         switch (ocf) {
         case BLE_HCI_OCF_RD_RSSI:
-            BLE_HS_LOG(DEBUG, " handle=%u rssi=%d", le16toh(evdata + 4), 
+            BLE_HS_LOG(DEBUG, "handle=%u rssi=%d", le16toh(evdata + 4), 
                        (int8_t)evdata[6]);
             break;
         default:
@@ -254,10 +261,19 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
     case BLE_HCI_OGF_LE:
         switch (ocf) {
         case BLE_HCI_OCF_LE_RD_CHAN_MAP:
-            BLE_HS_LOG(DEBUG, " handle=%u chanmap=%x.%x.%x.%x.%x", 
+            BLE_HS_LOG(DEBUG, "handle=%u chanmap=%x.%x.%x.%x.%x", 
                        le16toh(evdata + 4), evdata[6], evdata[7], evdata[8],
                        evdata[9], evdata[10]);
             break;
+        case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
+            BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u rxoct=%u rxtime=%u", 
+                       le16toh(evdata + 4), le16toh(evdata + 6),
+                       le16toh(evdata + 8), le16toh(evdata + 10));
+            break;
+        case BLE_HCI_OCF_LE_RD_SUPP_STATES:
+            BLE_HS_LOG(DEBUG, "states=0x%lx%lx", le32toh(evdata + 8),
+                       le32toh(evdata + 4));
+            break;
         default:
             break;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index 526a79b..8839c12 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -238,6 +238,16 @@ host_hci_cmd_rd_local_version(void)
 }
 
 int
+host_hci_cmd_rd_bd_addr(void)
+{
+    int rc;
+
+    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
+                           BLE_HCI_OCF_IP_RD_BD_ADDR, 0, NULL);
+    return rc;
+}
+
+int
 host_hci_cmd_set_event_mask(uint64_t event_mask)
 {
     int rc;
@@ -301,6 +311,34 @@ host_hci_cmd_le_read_buffer_size(void)
 }
 
 /**
+ * Read supported states 
+ *  
+ * OGF = 0x08 (LE) 
+ * OCF = 0x001C 
+ * 
+ * @return int 
+ */
+int
+host_hci_cmd_le_read_supp_states(void)
+{
+    return host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_SUPP_STATES, 0, NULL);
+}
+
+/**
+ * Read maximum data length
+ *  
+ * OGF = 0x08 (LE) 
+ * OCF = 0x002F 
+ * 
+ * @return int 
+ */
+int
+host_hci_cmd_le_read_max_datalen(void)
+{
+    return host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_MAX_DATA_LEN, 0, NULL);
+}
+
+/**
  * OGF=LE, OCF=0x0003
  */
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 2978eb2..3895ac3 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -67,6 +67,7 @@
 #define BLE_HCI_OCF_CB_SET_EVENT_MASK       (0x0001)
 #define BLE_HCI_OCF_CB_RESET                (0x0003)
 #define BLE_HCI_OCF_CB_SET_EV_FILT          (0x0005)
+#define BLE_HCI_OCF_CB_READ_TX_PWR          (0x002D)
 
 /* Command specific definitions */
 /* Set event mask */
@@ -74,6 +75,8 @@
 
 /* List of OCF for Info Param commands (OGF=0x04) */
 #define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
+#define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD      (0x0002)
+#define BLE_HCI_OCF_IP_RD_BD_ADDR           (0x0009)
 
 /* Command specific definitions */
 /* NOTE: does not include status field in command complete event! */
@@ -314,12 +317,18 @@
 /* --- LE read remote features (OCF 0x0016) */
 #define BLE_HCI_CONN_RD_REM_FEAT_LEN        (2)
 
+/* --- LE read supported states (OCF 0x001C) --- */
+#define BLE_HCI_RD_SUPP_STATES_RSPLEN       (8)
+
 /* --- LE remote connection parameter request reply (OCF 0x0020) */
 #define BLE_HCI_CONN_PARAM_REPLY_LEN        (14)
 
 /* --- LE remote connection parameter request negative reply (OCF 0x0021) */
 #define BLE_HCI_CONN_PARAM_NEG_REPLY_LEN    (3)
 
+/* --- LE read maximum data length (OCF 0x002F) */
+#define BLE_HCI_RD_MAX_DATALEN_RSPLEN       (8)
+
 /* Event Codes */
 #define BLE_HCI_EVCODE_INQUIRY_CMP          (0x01)
 #define BLE_HCI_EVCODE_INQUIRY_RESULT       (0x02)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d360e4fc/net/nimble/src/hci_common.c
----------------------------------------------------------------------
diff --git a/net/nimble/src/hci_common.c b/net/nimble/src/hci_common.c
index e30e071..4480e10 100644
--- a/net/nimble/src/hci_common.c
+++ b/net/nimble/src/hci_common.c
@@ -56,7 +56,7 @@ const uint8_t g_ble_hci_le_cmd_len[BLE_HCI_NUM_LE_CMDS] =
     0xFF,
     0xFF,
     0xFF,
-    0xFF,
+    0,                                  /* 0x001C: read supported states */
     0xFF,
     0xFF,
     0xFF,
@@ -75,6 +75,6 @@ const uint8_t g_ble_hci_le_cmd_len[BLE_HCI_NUM_LE_CMDS] =
     0xFF,
     0xFF,
     0xFF,
-    0xFF,                               /* 0x002F: Read max data length */
+    0,                                  /* 0x002F: Read max data length */
 };