You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/28 02:14:37 UTC

[38/50] [abbrv] incubator-mynewt-core git commit: Modify bletest for new host

Modify bletest for new host


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

Branch: refs/heads/master
Commit: 6d8a3a76f173913e6ab5cd442d130abab644cea5
Parents: ddcd177
Author: William San Filippo <wi...@runtime.io>
Authored: Fri Apr 22 13:56:59 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Fri Apr 22 13:57:08 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/bletest_hci.c          | 543 ++++++++++++++++++++++++++
 apps/bletest/src/bletest_priv.h         |  62 +++
 apps/bletest/src/main.c                 | 151 +++-----
 net/nimble/host/include/host/host_hci.h |  32 --
 net/nimble/host/src/host_hci_cmd.c      | 559 +--------------------------
 net/nimble/include/nimble/hci_common.h  |   1 +
 6 files changed, 667 insertions(+), 681 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6d8a3a76/apps/bletest/src/bletest_hci.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c
new file mode 100755
index 0000000..785edd9
--- /dev/null
+++ b/apps/bletest/src/bletest_hci.c
@@ -0,0 +1,543 @@
+/**
+ * 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 <assert.h>
+#include <string.h>
+#include "os/os.h"
+#include "bsp/bsp.h"
+
+/* BLE */
+#include "nimble/ble.h"
+#include "nimble/hci_transport.h"
+#include "nimble/hci_common.h"
+#include "host/host_hci.h"
+#include "host/ble_hs.h"
+#include "controller/ble_ll.h"
+#include "controller/ble_ll_hci.h"
+#include "controller/ble_ll_conn.h"
+#include "controller/ble_ll_scan.h"
+#include "controller/ble_ll_adv.h"
+
+/* XXX: An app should not include private headers from a library.  The bletest
+ * app uses some of nimble's internal details for logging.
+ */
+#include "../src/ble_hci_util_priv.h"
+#include "../src/ble_hs_priv.h"
+#include "bletest_priv.h"
+
+void
+bletest_send_conn_update(uint16_t handle)
+{
+    int rc;
+    struct hci_conn_update hcu;
+
+    hcu.conn_latency = 4;
+    hcu.supervision_timeout = 2000;
+    hcu.conn_itvl_min = 1000;
+    hcu.conn_itvl_max = 1000;
+    hcu.handle = handle;
+    hcu.min_ce_len = 4;
+    hcu.max_ce_len = 4;
+
+    rc = host_hci_cmd_le_conn_update(&hcu);
+    assert(rc == 0);
+}
+
+#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+void
+bletest_ltk_req_reply(uint16_t handle)
+{
+    g_bletest_ltk_reply_handle = handle;
+}
+
+void
+bletest_send_ltk_req_neg_reply(uint16_t handle)
+{
+    host_hci_cmd_le_lt_key_req_neg_reply(handle);
+}
+
+void
+bletest_send_ltk_req_reply(uint16_t handle)
+{
+    struct hci_lt_key_req_reply hkr;
+
+    hkr.conn_handle = handle;
+    swap_buf(hkr.long_term_key, (uint8_t *)g_bletest_LTK, 16);
+    host_hci_cmd_le_lt_key_req_reply(&hkr);
+}
+#endif
+
+int
+bletest_hci_reset_ctlr(void)
+{
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+
+    host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET, 0, buf);
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_rd_bd_addr(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_DEV_ADDR_LEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR, 0,
+                       buf);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_DEV_ADDR_LEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_DEV_ADDR_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    return rc;
+}
+
+#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+int
+bletest_hci_le_encrypt(uint8_t *key, uint8_t *pt)
+{
+    int rc;
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_ENCRYPT_LEN];
+    uint8_t rspbuf[16];
+    uint8_t rsplen;
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ENCRYPT,
+                       BLE_HCI_LE_ENCRYPT_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    swap_buf(dst, key, BLE_ENC_BLOCK_SIZE);
+    swap_buf(dst + BLE_ENC_BLOCK_SIZE, pt, BLE_ENC_BLOCK_SIZE);
+    rc = ble_hci_cmd_tx(buf, rspbuf, 16, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != 16) {
+        return BLE_HS_ECONTROLLER;
+    }
+    return rc;
+}
+#endif
+
+int
+bletest_hci_le_set_datalen(uint16_t handle, uint16_t txoctets, uint16_t txtime)
+{
+    int rc;
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN];
+    uint8_t rspbuf[2];
+    uint8_t rsplen;
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN,
+                       BLE_HCI_SET_DATALEN_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    htole16(dst, handle);
+    htole16(dst + 2, txoctets);
+    htole16(dst + 4, txtime);
+    rc = ble_hci_cmd_tx(buf, rspbuf, 2, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != 2) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    return rc;
+}
+
+int
+bletest_hci_le_write_sugg_datalen(uint16_t txoctets, uint16_t txtime)
+{
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_WR_SUGG_DATALEN_LEN];
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN,
+                       BLE_HCI_WR_SUGG_DATALEN_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    htole16(dst, txoctets);
+    htole16(dst + 2, txtime);
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_le_rd_sugg_datalen(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_SUGG_DATALEN_RSPLEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN, 0,
+                       buf);
+
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_SUGG_DATALEN_RSPLEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_SUGG_DATALEN_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    return 0;
+}
+
+int
+bletest_hci_rd_local_version(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_LOC_VER_INFO_RSPLEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOCAL_VER, 0,
+                       buf);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_VER_INFO_RSPLEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_LOC_VER_INFO_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+    return rc;
+}
+
+int
+bletest_hci_rd_local_feat(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT,
+                       0, buf);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+    return rc;
+}
+
+int
+bletest_hci_rd_local_supp_cmd(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD,
+                       0, buf);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+    return rc;
+}
+
+/**
+ * Read supported states
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x001C
+ *
+ * @return int
+ */
+int
+bletest_hci_le_read_supp_states(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_SUPP_STATES_RSPLEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_SUPP_STATES, 0, buf);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_SUPP_STATES_RSPLEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_SUPP_STATES_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+    return rc;
+}
+
+int
+bletest_hci_le_rd_max_datalen(void)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_MAX_DATALEN_RSPLEN];
+    uint8_t rsplen;
+
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_MAX_DATA_LEN, 0, buf);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_MAX_DATALEN_RSPLEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_MAX_DATALEN_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+    return rc;
+}
+
+int
+bletest_hci_le_set_adv_data(uint8_t *data, uint8_t len)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_DATA_LEN];
+
+    rc = host_hci_cmd_build_le_set_adv_data(data, len, buf, sizeof buf);
+    assert(rc == 0);
+    return ble_hci_cmd_tx_empty_ack(buf);
+}
+
+#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+int
+bletest_hci_le_start_encrypt(struct hci_start_encrypt *cmd)
+{
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN];
+
+    host_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
+    return ble_hci_cmd_tx_empty_ack(buf);
+}
+#endif
+
+int
+bletest_hci_le_read_rem_used_feat(uint16_t handle)
+{
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_RD_REM_FEAT_LEN];
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_REM_FEAT,
+                       BLE_HCI_CONN_RD_REM_FEAT_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    htole16(dst, handle);
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_le_set_adv_params(struct hci_adv_params *adv)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_PARAM_LEN];
+
+    rc = host_hci_cmd_build_le_set_adv_params(adv, buf, sizeof buf);
+    if (!rc) {
+        rc = ble_hci_cmd_tx_empty_ack(buf);
+    }
+    return rc;
+}
+
+int
+bletest_hci_le_set_rand_addr(uint8_t *addr)
+{
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN];
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RAND_ADDR,
+                       BLE_DEV_ADDR_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    memcpy(dst, addr, BLE_DEV_ADDR_LEN);
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_rd_rem_version(uint16_t handle)
+{
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + sizeof(uint16_t)];
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_RD_REM_VER_INFO,
+                       sizeof(uint16_t), dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    htole16(dst, handle);
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_le_set_host_chan_class(uint8_t *chanmap)
+{
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_HOST_CHAN_CLASS_LEN];
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS,
+                       BLE_HCI_SET_HOST_CHAN_CLASS_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    memcpy(dst, chanmap, BLE_HCI_SET_HOST_CHAN_CLASS_LEN);
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_le_rd_chanmap(uint16_t handle)
+{
+    int rc;
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_CHANMAP_LEN];
+    uint8_t rspbuf[BLE_HCI_RD_CHANMAP_RSP_LEN];
+    uint8_t rsplen;
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_CHAN_MAP,
+                       BLE_HCI_RD_CHANMAP_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    htole16(dst, handle);
+    rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_CHANMAP_RSP_LEN, &rsplen);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (rsplen != BLE_HCI_RD_CHANMAP_RSP_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    return rc;
+}
+
+int
+bletest_hci_le_set_adv_enable(uint8_t enable)
+{
+    uint8_t *dst;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_ENABLE_LEN];
+
+    dst = buf;
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_ENABLE,
+                       BLE_HCI_SET_ADV_ENABLE_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    dst[0] = enable;
+    return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+}
+
+int
+bletest_hci_le_set_event_mask(uint64_t event_mask)
+{
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN];
+
+    host_hci_cmd_build_le_set_event_mask(event_mask, buf, sizeof buf);
+    return ble_hci_cmd_tx_empty_ack(buf);
+}
+
+int
+bletest_hci_set_event_mask(uint64_t event_mask)
+{
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN];
+
+    host_hci_cmd_build_set_event_mask(event_mask, buf, sizeof buf);
+    return ble_hci_cmd_tx_empty_ack(buf);
+}
+
+int
+bletest_hci_le_set_scan_rsp_data(uint8_t *data, uint8_t len)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN];
+
+    rc = host_hci_cmd_build_le_set_scan_rsp_data(data, len, buf, sizeof buf);
+    assert(rc == 0);
+    return ble_hci_cmd_tx_empty_ack(buf);
+}
+
+int
+bletest_hci_cmd_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
+                                   uint16_t scan_window, uint8_t own_addr_type,
+                                   uint8_t filter_policy) {
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN];
+
+    rc = host_hci_cmd_build_le_set_scan_params(scan_type, scan_itvl,
+                                               scan_window, own_addr_type,
+                                               filter_policy, buf, sizeof buf);
+    if (!rc) {
+        rc = ble_hci_cmd_tx_empty_ack(buf);
+    }
+    return rc;
+}
+
+int
+bletest_hci_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN];
+
+    rc = host_hci_cmd_build_le_add_to_whitelist(addr, addr_type, buf,
+                                                sizeof buf);
+    if (!rc) {
+        rc = ble_hci_cmd_tx_empty_ack(buf);
+    }
+    return rc;
+}
+
+int
+bletest_hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dups)
+{
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_ENABLE_LEN];
+
+    host_hci_cmd_build_le_set_scan_enable(enable, filter_dups, buf, sizeof buf);
+    return ble_hci_cmd_tx_empty_ack(buf);
+}
+
+int
+bletest_hci_le_create_connection(struct hci_create_conn *hcc)
+{
+    int rc;
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CREATE_CONN_LEN];
+
+    rc = host_hci_cmd_build_le_create_connection(hcc, buf, sizeof buf);
+    if (!rc) {
+        rc = ble_hci_cmd_tx_empty_ack(buf);
+    }
+    return rc;
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6d8a3a76/apps/bletest/src/bletest_priv.h
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_priv.h b/apps/bletest/src/bletest_priv.h
new file mode 100644
index 0000000..d44dcfe
--- /dev/null
+++ b/apps/bletest/src/bletest_priv.h
@@ -0,0 +1,62 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLETEST_PRIV_
+#define H_BLETEST_PRIV_
+
+void bletest_send_conn_update(uint16_t handle);
+
+#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+void bletest_ltk_req_reply(uint16_t handle);
+void bletest_send_ltk_req_neg_reply(uint16_t handle);
+void bletest_send_ltk_req_reply(uint16_t handle);
+int bletest_hci_le_start_encrypt(struct hci_start_encrypt *cmd);
+int bletest_hci_le_encrypt(uint8_t *key, uint8_t *pt);
+#endif
+
+int bletest_hci_reset_ctlr(void);
+int bletest_hci_rd_bd_addr(void);
+int bletest_hci_le_set_datalen(uint16_t handle, uint16_t txoctets,
+                               uint16_t txtime);
+int bletest_hci_le_write_sugg_datalen(uint16_t txoctets, uint16_t txtime);
+int bletest_hci_le_rd_sugg_datalen(void);
+int bletest_hci_rd_local_version(void);
+int bletest_hci_rd_local_feat(void);
+int bletest_hci_rd_local_supp_cmd(void);
+int bletest_hci_le_read_supp_states(void);
+int bletest_hci_le_rd_max_datalen(void);
+int bletest_hci_le_set_adv_data(uint8_t *data, uint8_t len);
+int bletest_hci_le_set_adv_params(struct hci_adv_params *adv);
+int bletest_hci_le_read_rem_used_feat(uint16_t handle);
+int bletest_hci_le_set_rand_addr(uint8_t *addr);
+int bletest_hci_rd_rem_version(uint16_t handle);
+int bletest_hci_le_set_host_chan_class(uint8_t *chanmap);
+int bletest_hci_le_rd_chanmap(uint16_t handle);
+int bletest_hci_le_set_adv_enable(uint8_t enable);
+int bletest_hci_le_set_event_mask(uint64_t event_mask);
+int bletest_hci_set_event_mask(uint64_t event_mask);
+int bletest_hci_le_set_scan_rsp_data(uint8_t *data, uint8_t len);
+int bletest_hci_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type);
+int bletest_hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
+int bletest_hci_le_create_connection(struct hci_create_conn *hcc);
+int bletest_hci_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
+                                   uint16_t scan_window, uint8_t own_addr_type,
+                                   uint8_t filter_policy);
+
+#endif  /* H_BLETEST_PRIV_*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6d8a3a76/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index d66a91a..aa713ac 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -45,6 +45,13 @@
 #include "controller/ble_ll_scan.h"
 #include "controller/ble_ll_adv.h"
 
+/* XXX: An app should not include private headers from a library.  The bletest
+ * app uses some of nimble's internal details for logging.
+ */
+#include "../src/ble_hci_util_priv.h"
+#include "../src/ble_hs_priv.h"
+#include "bletest_priv.h"
+
 /* Task priorities */
 #define BLE_LL_TASK_PRI     (OS_TASK_PRI_HIGHEST)
 #define HOST_TASK_PRIO      (OS_TASK_PRI_HIGHEST + 1)
@@ -221,54 +228,12 @@ bletest_inc_adv_pkt_num(void)
             }
         }
 
-        rc = host_hci_cmd_le_set_adv_data(g_host_adv_data, g_host_adv_len);
+        rc = bletest_hci_le_set_adv_data(g_host_adv_data, g_host_adv_len);
         assert(rc == 0);
     }
 }
 #endif
 
-void
-bletest_send_conn_update(uint16_t handle)
-{
-    int rc;
-    struct hci_conn_update hcu;
-
-    hcu.conn_latency = 4;
-    hcu.supervision_timeout = 2000;
-    hcu.conn_itvl_min = 1000;
-    hcu.conn_itvl_max = 1000;
-    hcu.handle = handle;
-    hcu.min_ce_len = 4;
-    hcu.max_ce_len = 4;
-
-    rc = host_hci_cmd_le_conn_update(&hcu);
-    assert(rc == 0);
-}
-
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
-void
-bletest_ltk_req_reply(uint16_t handle)
-{
-    g_bletest_ltk_reply_handle = handle;
-}
-
-void
-bletest_send_ltk_req_neg_reply(uint16_t handle)
-{
-    host_hci_cmd_le_lt_key_req_neg_reply(handle);
-}
-
-void
-bletest_send_ltk_req_reply(uint16_t handle)
-{
-    struct hci_lt_key_req_reply hkr;
-
-    hkr.conn_handle = handle;
-    swap_buf(hkr.long_term_key, (uint8_t *)g_bletest_LTK, 16);
-    host_hci_cmd_le_lt_key_req_reply(&hkr);
-}
-#endif
-
 /**
  * Sets the advertising data to be sent in advertising pdu's which contain
  * advertising data.
@@ -362,24 +327,24 @@ bletest_init_advertising(void)
     }
 
     /* Set the advertising parameters */
-    rc = host_hci_cmd_le_set_adv_params(&adv);
+    rc = bletest_hci_le_set_adv_params(&adv);
     assert(rc == 0);
 
     /* If we are using a random address, we need to set it */
     if (adv.own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
         memcpy(rand_addr, g_dev_addr, BLE_DEV_ADDR_LEN);
         rand_addr[5] |= 0xc0;
-        rc = host_hci_cmd_le_set_rand_addr(rand_addr);
+        rc = bletest_hci_le_set_rand_addr(rand_addr);
         assert(rc == 0);
     }
 
     /* Set advertising data */
     if (adv_len != 0) {
-        rc = host_hci_cmd_le_set_adv_data(&g_host_adv_data[0], adv_len);
+        rc = bletest_hci_le_set_adv_data(&g_host_adv_data[0], adv_len);
         assert(rc == 0);
 
         /* Set scan response data */
-        rc = host_hci_cmd_le_set_scan_rsp_data(&g_host_adv_data[0], adv_len);
+        rc = bletest_hci_le_set_scan_rsp_data(&g_host_adv_data[0], adv_len);
         assert(rc == 0);
     }
 }
@@ -394,11 +359,11 @@ bletest_init_scanner(void)
     uint8_t filter_policy;
 
     /* Set scanning parameters */
-    rc = host_hci_cmd_le_set_scan_params(BLETEST_CFG_SCAN_TYPE,
-                                         BLETEST_CFG_SCAN_ITVL,
-                                         BLETEST_CFG_SCAN_WINDOW,
-                                         BLE_HCI_ADV_OWN_ADDR_PUBLIC,
-                                         BLETEST_CFG_SCAN_FILT_POLICY);
+    rc = bletest_hci_le_set_scan_params(BLETEST_CFG_SCAN_TYPE,
+                                        BLETEST_CFG_SCAN_ITVL,
+                                        BLETEST_CFG_SCAN_WINDOW,
+                                        BLE_HCI_ADV_OWN_ADDR_PUBLIC,
+                                        BLETEST_CFG_SCAN_FILT_POLICY);
     assert(rc == 0);
 
     filter_policy = BLETEST_CFG_SCAN_FILT_POLICY;
@@ -410,7 +375,7 @@ bletest_init_scanner(void)
         dev_addr[3] = 0x88;
         dev_addr[4] = 0x88;
         dev_addr[5] = 0x08;
-        rc = host_hci_cmd_le_add_to_whitelist(dev_addr, BLE_ADDR_TYPE_PUBLIC);
+        rc = bletest_hci_le_add_to_whitelist(dev_addr, BLE_ADDR_TYPE_PUBLIC);
         assert(rc == 0);
     }
 }
@@ -423,11 +388,11 @@ bletest_execute_scanner(void)
     /* Enable scanning */
     if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
         if (g_bletest_state) {
-            rc = host_hci_cmd_le_set_scan_enable(0, BLETEST_CFG_FILT_DUP_ADV);
+            rc = bletest_hci_le_set_scan_enable(0, BLETEST_CFG_FILT_DUP_ADV);
             assert(rc == 0);
             g_bletest_state = 0;
         } else {
-            rc = host_hci_cmd_le_set_scan_enable(1, BLETEST_CFG_FILT_DUP_ADV);
+            rc = bletest_hci_le_set_scan_enable(1, BLETEST_CFG_FILT_DUP_ADV);
             assert(rc == 0);
             g_bletest_state = 1;
         }
@@ -471,11 +436,11 @@ bletest_init_initiator(void)
     if (hcc->own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
         memcpy(rand_addr, g_dev_addr, BLE_DEV_ADDR_LEN);
         rand_addr[5] |= 0xc0;
-        rc = host_hci_cmd_le_set_rand_addr(rand_addr);
+        rc = bletest_hci_le_set_rand_addr(rand_addr);
         assert(rc == 0);
     }
 
-    rc = host_hci_cmd_le_create_connection(hcc);
+    rc = bletest_hci_le_create_connection(hcc);
     assert(rc == 0);
 }
 
@@ -484,6 +449,7 @@ bletest_execute_initiator(void)
 {
     int i;
     int rc;
+    int8_t rssi;
     uint16_t handle;
     uint8_t new_chan_map[5];
 
@@ -498,10 +464,10 @@ bletest_execute_initiator(void)
             g_bletest_led_rate = OS_TICKS_PER_SEC;
 
             /* Ask for version information */
-            rc = host_hci_cmd_rd_rem_version(handle);
+            rc = bletest_hci_rd_rem_version(handle);
 
             /* Ask for remote used features */
-            rc = host_hci_cmd_le_read_rem_used_feat(handle);
+            rc = bletest_hci_le_read_rem_used_feat(handle);
 
             /* Scanning better be stopped! */
             assert(ble_ll_scan_enabled() == 0);
@@ -524,7 +490,7 @@ bletest_execute_initiator(void)
             if ((g_bletest_state == 1) || (g_bletest_state == 3)) {
                 for (i = 0; i < g_bletest_current_conns; ++i) {
                     if (ble_ll_conn_find_active_conn(i + 1)) {
-                        host_hci_cmd_le_rd_chanmap(i+1);
+                        bletest_hci_le_rd_chanmap(i+1);
                     }
                 }
             } else if (g_bletest_state == 2) {
@@ -533,7 +499,7 @@ bletest_execute_initiator(void)
                 new_chan_map[2] = 0;
                 new_chan_map[3] = 0x1F;
                 new_chan_map[4] = 0;
-                host_hci_cmd_le_set_host_chan_class(new_chan_map);
+                bletest_hci_le_set_host_chan_class(new_chan_map);
             } else if (g_bletest_state == 4) {
 #ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
                 struct hci_start_encrypt hsle;
@@ -544,20 +510,19 @@ bletest_execute_initiator(void)
                         hsle.random_number = g_bletest_RAND;
                         swap_buf(hsle.long_term_key, (uint8_t *)g_bletest_LTK,
                                  16);
-                        host_hci_cmd_le_start_encrypt(&hsle);
+                        bletest_hci_le_start_encrypt(&hsle);
                     }
                 }
 #endif
             } else {
                 for (i = 0; i < g_bletest_current_conns; ++i) {
                     if (ble_ll_conn_find_active_conn(i + 1)) {
-                        host_hci_cmd_read_rssi(i+1);
+                        ble_hci_util_read_rssi(i+1, &rssi);
                     }
                 }
             }
             if (g_bletest_state < 5) {
                 ++g_bletest_state;
-            } else {
             }
             g_next_os_time = os_time_get() + OS_TICKS_PER_SEC * 3;
         }
@@ -618,13 +583,13 @@ bletest_execute_advertiser(void)
             assert(ble_ll_adv_enabled() == 0);
 
             /* Send the remote used features command */
-            rc = host_hci_cmd_le_read_rem_used_feat(handle);
+            rc = bletest_hci_le_read_rem_used_feat(handle);
             if (rc) {
                 return;
             }
 
             /* Send the remote read version command */
-            rc = host_hci_cmd_rd_rem_version(handle);
+            rc = bletest_hci_rd_rem_version(handle);
             if (rc) {
                 return;
             }
@@ -642,7 +607,7 @@ bletest_execute_advertiser(void)
                 g_bletest_cur_peer_addr[5] += 1;
                 g_dev_addr[5] += 1;
                 bletest_init_advertising();
-                rc = host_hci_cmd_le_set_adv_enable(1);
+                rc = bletest_hci_le_set_adv_enable(1);
             }
         }
     }
@@ -816,6 +781,7 @@ void
 bletest_task_handler(void *arg)
 {
     int rc;
+    uint64_t rand64;
     uint64_t event_mask;
     struct os_event *ev;
     struct os_callout_func *cf;
@@ -826,16 +792,12 @@ bletest_task_handler(void *arg)
     /* Wait one second before starting test task */
     os_time_delay(OS_TICKS_PER_SEC);
 
-    /* Initialize eventq */
-    os_eventq_init(&g_bletest_evq);
-
     /* Initialize the host timer */
     os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
                          NULL);
 
     /* Send the reset command first */
-    rc = host_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
-                           0, NULL);
+    rc = bletest_hci_reset_ctlr();
     assert(rc == 0);
 
 #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
@@ -858,65 +820,65 @@ bletest_task_handler(void *arg)
 
     /* Set the event mask we want to display */
     event_mask = 0x7FF;
-    rc = host_hci_cmd_le_set_event_mask(event_mask);
+    rc = bletest_hci_le_set_event_mask(event_mask);
     assert(rc == 0);
 
     /* Turn on all events */
     event_mask = 0xffffffffffffffff;
-    rc = host_hci_cmd_set_event_mask(event_mask);
+    rc = bletest_hci_set_event_mask(event_mask);
     assert(rc == 0);
 
     /* Read device address */
-    rc = host_hci_cmd_rd_bd_addr();
+    rc = bletest_hci_rd_bd_addr();
     assert(rc == 0);
 
     /* Read local features */
-    rc = host_hci_cmd_rd_local_feat();
+    rc = bletest_hci_rd_local_feat();
     assert(rc == 0);
 
     /* Read local commands */
-    rc = host_hci_cmd_rd_local_cmd();
+    rc = bletest_hci_rd_local_supp_cmd();
     assert(rc == 0);
 
     /* Read version */
-    rc = host_hci_cmd_rd_local_version();
+    rc = bletest_hci_rd_local_version();
     assert(rc == 0);
 
     /* Read supported states */
-    rc = host_hci_cmd_le_read_supp_states();
+    rc = bletest_hci_le_read_supp_states();
     assert(rc == 0);
 
     /* Read maximum data length */
-    rc = host_hci_cmd_le_read_max_datalen();
+    rc = bletest_hci_le_rd_max_datalen();
     assert(rc == 0);
 
     /* Read suggested data length */
-    rc = host_hci_cmd_le_read_sugg_datalen();
+    rc = bletest_hci_le_rd_sugg_datalen();
     assert(rc == 0);
 
     /* write suggested default data length */
-    rc = host_hci_cmd_le_write_sugg_datalen(BLETEST_CFG_SUGG_DEF_TXOCTETS,
-                                            BLETEST_CFG_SUGG_DEF_TXTIME);
+    rc = bletest_hci_le_write_sugg_datalen(BLETEST_CFG_SUGG_DEF_TXOCTETS,
+                                           BLETEST_CFG_SUGG_DEF_TXTIME);
     assert(rc == 0);
 
     /* Read suggested data length */
-    rc = host_hci_cmd_le_read_sugg_datalen();
+    rc = bletest_hci_le_rd_sugg_datalen();
     assert(rc == 0);
 
     /* Set data length (note: we know there is no connection; just a test) */
-    rc = host_hci_cmd_le_set_datalen(0x1234,
-                                     BLETEST_CFG_SUGG_DEF_TXOCTETS,
-                                     BLETEST_CFG_SUGG_DEF_TXTIME);
-    assert(rc == 0);
-
+    rc = bletest_hci_le_set_datalen(0x1234, BLETEST_CFG_SUGG_DEF_TXOCTETS,
+                                    BLETEST_CFG_SUGG_DEF_TXTIME);
+    assert(rc != 0);
 
     /* Encrypt a block */
-    rc = host_hci_cmd_le_encrypt((uint8_t *)g_ble_ll_encrypt_test_key,
-                                 (uint8_t *)g_ble_ll_encrypt_test_plain_text);
+#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+    rc = bletest_hci_le_encrypt((uint8_t *)g_ble_ll_encrypt_test_key,
+                                (uint8_t *)g_ble_ll_encrypt_test_plain_text);
     assert(rc == 0);
+#endif
 
     /* Get a random number */
-    rc = host_hci_cmd_le_rand();
+    rc = ble_hci_util_rand(&rand64, 8);
     assert(rc == 0);
 
     /* Wait some time before starting */
@@ -927,7 +889,7 @@ bletest_task_handler(void *arg)
 
     /* Begin advertising if we are an advertiser */
 #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
-    rc = host_hci_cmd_le_set_adv_enable(1);
+    rc = bletest_hci_le_set_adv_enable(1);
     assert(rc == 0);
 #endif
 
@@ -1072,6 +1034,9 @@ main(void)
     rc = stats_module_init();
     assert(rc == 0);
 
+    /* Initialize eventq for bletest task */
+    os_eventq_init(&g_bletest_evq);
+
     /* Initialize the BLE LL */
     rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
     assert(rc == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6d8a3a76/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 8011f79..e8fab80 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -32,37 +32,22 @@ int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata);
 int host_hci_cmd_send_buf(void *cmddata);
 void host_hci_cmd_build_set_event_mask(uint64_t event_mask,
                                        uint8_t *dst, int dst_len);
-int host_hci_cmd_set_event_mask(uint64_t event_mask);
 void host_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
                                    uint8_t *dst, int dst_len);
 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);
 void host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len);
 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);
 int host_hci_cmd_build_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
                                             uint8_t *dst, int dst_len);
-int host_hci_cmd_le_set_scan_rsp_data(uint8_t *data, uint8_t len);
 int host_hci_cmd_build_le_set_adv_data(uint8_t *data, uint8_t len,
                                        uint8_t *dst, int dst_len);
-int host_hci_cmd_le_set_adv_data(uint8_t *data, uint8_t len);
 int host_hci_cmd_build_le_set_adv_params(struct hci_adv_params *adv,
                                          uint8_t *dst, int dst_len);
-int host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv);
-int host_hci_cmd_le_set_rand_addr(uint8_t *addr);
 void host_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
                                           uint8_t *dst, int dst_len);
-int host_hci_cmd_le_set_event_mask(uint64_t event_mask);
 void host_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len);
 int host_hci_cmd_le_read_buffer_size(void);
 void host_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len);
-int host_hci_cmd_le_read_loc_supp_feat(void);
-int host_hci_cmd_le_read_rem_used_feat(uint16_t handle);
 void host_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
                                           int dst_len);
 int host_hci_cmd_le_set_adv_enable(uint8_t enable);
@@ -72,10 +57,6 @@ int host_hci_cmd_build_le_set_scan_params(uint8_t scan_type,
                                           uint8_t own_addr_type,
                                           uint8_t filter_policy,
                                           uint8_t *cmd, int cmd_len);
-int host_hci_cmd_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
-                                    uint16_t scan_window,
-                                    uint8_t own_addr_type,
-                                    uint8_t filter_policy);
 void host_hci_cmd_build_le_set_scan_enable(uint8_t enable,
                                            uint8_t filter_dups,
                                            uint8_t *dst, uint8_t dst_len);
@@ -84,12 +65,8 @@ int host_hci_cmd_build_le_create_connection(struct hci_create_conn *hcc,
                                             uint8_t *cmd, int cmd_len);
 int host_hci_cmd_le_create_connection(struct hci_create_conn *hcc);
 void host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len);
-int host_hci_cmd_le_clear_whitelist(void);
-int host_hci_cmd_le_read_whitelist(void);
 int host_hci_cmd_build_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type,
                                            uint8_t *dst, int dst_len);
-int host_hci_cmd_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type);
-int host_hci_cmd_le_rmv_from_whitelist(uint8_t *addr, uint8_t addr_type);
 void host_hci_cmd_build_reset(uint8_t *dst, int dst_len);
 int host_hci_cmd_reset(void);
 void host_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len);
@@ -109,18 +86,9 @@ int host_hci_cmd_le_conn_param_reply(struct hci_conn_param_reply *hcr);
 void host_hci_cmd_build_le_conn_param_neg_reply(
     struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len);
 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_cmd_le_read_sugg_datalen(void);
-int host_hci_cmd_le_write_sugg_datalen(uint16_t txoctets, uint16_t txtime);
-int host_hci_cmd_le_set_datalen(uint16_t handle, uint16_t txoctets,
-                                uint16_t txtime);
-int host_hci_cmd_le_encrypt(uint8_t *key, uint8_t *pt);
 void host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len);
-int host_hci_cmd_le_rand(void);
 void host_hci_cmd_build_le_start_encrypt(struct hci_start_encrypt *cmd,
                                          uint8_t *dst, int dst_len);
-int host_hci_cmd_le_start_encrypt(struct hci_start_encrypt *cmd);
 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/6d8a3a76/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 c8c79f1..8a923ae 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -137,25 +137,6 @@ host_hci_cmd_body_le_whitelist_chg(uint8_t *addr, uint8_t addr_type,
 }
 
 static int
-host_hci_cmd_le_whitelist_chg(uint8_t *addr, uint8_t addr_type, uint8_t ocf)
-{
-    uint8_t cmd[BLE_HCI_CHG_WHITE_LIST_LEN];
-    int rc;
-
-    rc = host_hci_cmd_body_le_whitelist_chg(addr, addr_type, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = host_hci_le_cmd_send(ocf, BLE_HCI_CHG_WHITE_LIST_LEN, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-static int
 host_hci_cmd_body_le_set_adv_params(struct hci_adv_params *adv, uint8_t *dst)
 {
     uint16_t itvl;
@@ -223,26 +204,6 @@ host_hci_cmd_build_le_set_adv_params(struct hci_adv_params *adv, uint8_t *dst,
     return 0;
 }
 
-int
-host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_ADV_PARAM_LEN];
-
-    rc = host_hci_cmd_body_le_set_adv_params(adv, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_ADV_PARAMS,
-                              BLE_HCI_SET_ADV_PARAM_LEN, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
 /**
  * Set advertising data
  *
@@ -303,37 +264,6 @@ host_hci_cmd_build_le_set_adv_data(uint8_t *data, uint8_t len, uint8_t *dst,
     return 0;
 }
 
-/**
- * Set advertising data
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0008
- *
- * @param data
- * @param len
- *
- * @return int
- */
-int
-host_hci_cmd_le_set_adv_data(uint8_t *data, uint8_t len)
-{
-    uint8_t cmd[BLE_HCI_SET_ADV_DATA_LEN];
-    int rc;
-
-    rc = host_hci_cmd_body_le_set_adv_data(data, len, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_ADV_DATA,
-                              BLE_HCI_SET_ADV_DATA_LEN, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
 static int
 host_hci_cmd_body_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
                                        uint8_t *dst)
@@ -372,90 +302,6 @@ host_hci_cmd_build_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
     return 0;
 }
 
-int
-host_hci_cmd_le_set_scan_rsp_data(uint8_t *data, uint8_t len)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_SCAN_RSP_DATA_LEN];
-
-    rc = host_hci_cmd_body_le_set_scan_rsp_data(data, len, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA,
-                              BLE_HCI_SET_SCAN_RSP_DATA_LEN, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/**
- * ble host hci cmd le set rand addr
- *
- * Sets the random address to be used in advertisements.
- *
- * @param addr Pointer to the random address to send to device
- *
- * @return int
- */
-int
-host_hci_cmd_le_set_rand_addr(uint8_t *addr)
-{
-    int rc;
-
-    /* Check for valid parameters */
-    rc = -1;
-    if (addr) {
-        rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_RAND_ADDR,
-                                  BLE_DEV_ADDR_LEN, addr);
-    }
-
-    return rc;
-}
-
-int
-host_hci_cmd_rd_local_version(void)
-{
-    int rc;
-
-    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
-                           BLE_HCI_OCF_IP_RD_LOCAL_VER, 0, NULL);
-    return rc;
-}
-
-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;
-
-    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
-                           BLE_HCI_OCF_IP_RD_BD_ADDR, 0, NULL);
-    return rc;
-}
-
 static void
 host_hci_cmd_body_set_event_mask(uint64_t event_mask, uint8_t *dst)
 {
@@ -477,20 +323,6 @@ host_hci_cmd_build_set_event_mask(uint64_t event_mask,
     host_hci_cmd_body_set_event_mask(event_mask, dst);
 }
 
-int
-host_hci_cmd_set_event_mask(uint64_t event_mask)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_EVENT_MASK_LEN];
-
-    host_hci_cmd_body_set_event_mask(event_mask, cmd);
-    rc = host_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND,
-                           BLE_HCI_OCF_CB_SET_EVENT_MASK,
-                           BLE_HCI_SET_EVENT_MASK_LEN,
-                           cmd);
-    return rc;
-}
-
 static void
 host_hci_cmd_body_disconnect(uint16_t handle, uint8_t reason, uint8_t *dst)
 {
@@ -526,18 +358,6 @@ host_hci_cmd_disconnect(uint16_t handle, uint8_t reason)
     return rc;
 }
 
-int
-host_hci_cmd_rd_rem_version(uint16_t handle)
-{
-    int rc;
-    uint8_t cmd[sizeof(uint16_t)];
-
-    htole16(cmd, handle);
-    rc = host_hci_cmd_send(BLE_HCI_OGF_LINK_CTRL,
-                           BLE_HCI_OCF_RD_REM_VER_INFO, sizeof(uint16_t), cmd);
-    return rc;
-}
-
 static void
 host_hci_cmd_body_le_set_event_mask(uint64_t event_mask, uint8_t *dst)
 {
@@ -559,20 +379,6 @@ host_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
     host_hci_cmd_body_le_set_event_mask(event_mask, dst);
 }
 
-int
-host_hci_cmd_le_set_event_mask(uint64_t event_mask)
-{
-    uint8_t cmd[BLE_HCI_SET_LE_EVENT_MASK_LEN];
-
-    int rc;
-
-    host_hci_cmd_body_le_set_event_mask(event_mask, cmd);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_EVENT_MASK, sizeof(uint64_t),
-                              cmd);
-
-    return rc;
-}
-
 /**
  * LE Read buffer size
  *
@@ -590,103 +396,18 @@ host_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len)
 
 /**
  * LE Read buffer size
- *  
- * OGF = 0x08 (LE) 
- * OCF = 0x0002 
- * 
- * @return int 
- */
-int
-host_hci_cmd_le_read_buffer_size(void)
-{
-    int rc;
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, NULL);
-    return rc;
-}
-
-/**
- * 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);
-}
-
-/**
- * Set data length command
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0022
- *
- * @return int
- */
-int
-host_hci_cmd_le_set_datalen(uint16_t handle, uint16_t txoctets, uint16_t txtime)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_DATALEN_LEN];
-
-    htole16(cmd, handle);
-    htole16(cmd + 2, txoctets);
-    htole16(cmd + 4, txtime);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_DATA_LEN,
-                              BLE_HCI_SET_DATALEN_LEN, cmd);
-    return rc;
-}
-
-/**
- * Read suggested default data length
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0023
- *
- * @return int
- */
-int
-host_hci_cmd_le_read_sugg_datalen(void)
-{
-    return host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN, 0, NULL);
-}
-
-/**
- * write suggested default data length
  *
  * OGF = 0x08 (LE)
- * OCF = 0x0024
+ * OCF = 0x0002
  *
  * @return int
  */
 int
-host_hci_cmd_le_write_sugg_datalen(uint16_t txoctets, uint16_t txtime)
+host_hci_cmd_le_read_buffer_size(void)
 {
     int rc;
-    uint8_t cmd[BLE_HCI_WR_SUGG_DATALEN_LEN];
 
-    htole16(cmd, txoctets);
-    htole16(cmd + 2, txtime);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN,
-                              BLE_HCI_WR_SUGG_DATALEN_LEN, cmd);
+    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, NULL);
     return rc;
 }
 
@@ -701,34 +422,6 @@ host_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len)
                        0, dst);
 }
 
-/**
- * OGF=LE, OCF=0x0003
- */
-int
-host_hci_cmd_le_read_loc_supp_feat(void)
-{
-    int rc;
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT, 0, NULL);
-    return rc;
-}
-
-/**
- * OGF=LE, OCF=0x0016
- */
-int
-host_hci_cmd_le_read_rem_used_feat(uint16_t handle)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_CONN_RD_REM_FEAT_LEN];
-
-    htole16(cmd, handle);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_REM_FEAT,
-                              BLE_HCI_CONN_RD_REM_FEAT_LEN,
-                              cmd);
-    return rc;
-}
-
 static void
 host_hci_cmd_body_le_set_adv_enable(uint8_t enable, uint8_t *dst)
 {
@@ -749,19 +442,6 @@ host_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
     host_hci_cmd_body_le_set_adv_enable(enable, dst);
 }
 
-int
-host_hci_cmd_le_set_adv_enable(uint8_t enable)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_ADV_ENABLE_LEN];
-
-    host_hci_cmd_body_le_set_adv_enable(enable, cmd);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_ADV_ENABLE,
-                              BLE_HCI_SET_ADV_ENABLE_LEN, cmd);
-
-    return rc;
-}
-
 static int
 host_hci_cmd_body_le_set_scan_params(
     uint8_t scan_type, uint16_t scan_itvl, uint16_t scan_window,
@@ -827,26 +507,6 @@ host_hci_cmd_build_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
     return 0;
 }
 
-int
-host_hci_cmd_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
-                                uint16_t scan_window, uint8_t own_addr_type,
-                                uint8_t filter_policy) {
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_SCAN_PARAM_LEN];
-
-    rc = host_hci_cmd_body_le_set_scan_params(scan_type, scan_itvl,
-                                              scan_window, own_addr_type,
-                                              filter_policy, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_SCAN_PARAMS,
-                              BLE_HCI_SET_SCAN_PARAM_LEN, cmd);
-
-    return rc;
-}
-
 static void
 host_hci_cmd_body_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
                                      uint8_t *dst)
@@ -869,19 +529,6 @@ host_hci_cmd_build_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
                                          dst + BLE_HCI_CMD_HDR_LEN);
 }
 
-int
-host_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_SET_SCAN_ENABLE_LEN];
-
-    host_hci_cmd_body_le_set_scan_enable(enable, filter_dups, cmd);
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_SCAN_ENABLE,
-                              BLE_HCI_SET_SCAN_ENABLE_LEN, cmd);
-    return rc;
-}
-
 static int
 host_hci_cmd_body_le_create_connection(struct hci_create_conn *hcc,
                                        uint8_t *cmd)
@@ -977,26 +624,6 @@ host_hci_cmd_build_le_create_connection(struct hci_create_conn *hcc,
     return 0;
 }
 
-int
-host_hci_cmd_le_create_connection(struct hci_create_conn *hcc)
-{
-    uint8_t cmd[BLE_HCI_CREATE_CONN_LEN];
-    int rc;
-
-    rc = host_hci_cmd_body_le_create_connection(hcc, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_CREATE_CONN,
-                              BLE_HCI_CREATE_CONN_LEN, cmd);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
 void
 host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len)
 {
@@ -1005,36 +632,6 @@ host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len)
                        0, dst);
 }
 
-/**
- * Clear the whitelist.
- *
- * @return int
- */
-int
-host_hci_cmd_le_clear_whitelist(void)
-{
-    int rc;
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_CLEAR_WHITE_LIST, 0, NULL);
-    return rc;
-}
-
-/**
- * Read the whitelist size. Note that this is not how many elements have
- * been added to the whitelist; rather it is the number of whitelist entries
- * allowed by the controller.
- *
- * @return int
- */
-int
-host_hci_cmd_le_read_whitelist(void)
-{
-    int rc;
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_WHITE_LIST_SIZE, 0, NULL);
-    return rc;
-}
-
 int
 host_hci_cmd_build_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type,
                                        uint8_t *dst, int dst_len)
@@ -1056,43 +653,6 @@ host_hci_cmd_build_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type,
     return 0;
 }
 
-/**
- * Add a device to the whitelist.
- *
- * @param addr
- * @param addr_type
- *
- * @return int
- */
-int
-host_hci_cmd_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type)
-{
-    int rc;
-
-    rc = host_hci_cmd_le_whitelist_chg(addr, addr_type,
-                                       BLE_HCI_OCF_LE_ADD_WHITE_LIST);
-
-    return rc;
-}
-
-/**
- * Remove a device from the whitelist.
- *
- * @param addr
- * @param addr_type
- *
- * @return int
- */
-int
-host_hci_cmd_le_rmv_from_whitelist(uint8_t *addr, uint8_t addr_type)
-{
-    int rc;
-
-    rc = host_hci_cmd_le_whitelist_chg(addr, addr_type,
-                                       BLE_HCI_OCF_LE_RMV_WHITE_LIST);
-    return rc;
-}
-
 void
 host_hci_cmd_build_reset(uint8_t *dst, int dst_len)
 {
@@ -1370,66 +930,6 @@ host_hci_cmd_le_conn_param_neg_reply(struct hci_conn_param_neg_reply *hcn)
 }
 
 /**
- * Read the channel map for a given connection.
- *
- * @param handle
- *
- * @return int
- */
-int
-host_hci_cmd_le_rd_chanmap(uint16_t handle)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_RD_CHANMAP_LEN];
-
-    htole16(cmd, handle);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_CHAN_MAP,
-                              BLE_HCI_RD_CHANMAP_LEN, cmd);
-    return rc;
-}
-
-/**
- * Set the channel map in the controller
- *
- * @param chanmap
- *
- * @return int
- */
-int
-host_hci_cmd_le_set_host_chan_class(uint8_t *chanmap)
-{
-    int rc;
-
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS,
-                              BLE_HCI_SET_HOST_CHAN_CLASS_LEN, chanmap);
-    return rc;
-}
-
-/**
- * Encrypt a block.
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0017
- *
- * @param key
- * @param pt
- *
- * @return int
- */
-int
-host_hci_cmd_le_encrypt(uint8_t *key, uint8_t *pt)
-{
-    int rc;
-    uint8_t cmd[BLE_HCI_LE_ENCRYPT_LEN];
-
-    swap_buf(cmd, key, BLE_ENC_BLOCK_SIZE);
-    swap_buf(cmd + BLE_ENC_BLOCK_SIZE, pt, BLE_ENC_BLOCK_SIZE);
-    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_ENCRYPT, BLE_HCI_LE_ENCRYPT_LEN,
-                              cmd);
-    return rc;
-}
-
-/**
  * Get random data
  *
  * OGF = 0x08 (LE)
@@ -1444,20 +944,6 @@ host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len)
     host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RAND, 0, dst);
 }
 
-/**
- * Get random data
- *  
- * OGF = 0x08 (LE) 
- * OCF = 0x0018
- *
- * @return int
- */
-int
-host_hci_cmd_le_rand(void)
-{
-    return host_hci_le_cmd_send(BLE_HCI_OCF_LE_RAND, 0, NULL);
-}
-
 static void
 host_hci_cmd_body_le_start_encrypt(struct hci_start_encrypt *cmd, uint8_t *dst)
 {
@@ -1482,24 +968,6 @@ host_hci_cmd_build_le_start_encrypt(struct hci_start_encrypt *cmd,
 }
 
 /**
- * Enables encryption on a connection.
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0019
- *
- * @return int
- */
-int
-host_hci_cmd_le_start_encrypt(struct hci_start_encrypt *cmd)
-{
-    uint8_t buf[BLE_HCI_LE_START_ENCRYPT_LEN];
-
-    host_hci_cmd_body_le_start_encrypt(cmd, buf);
-
-    return host_hci_le_cmd_send(BLE_HCI_OCF_LE_START_ENCRYPT, sizeof buf, buf);
-}
-
-/**
  * Read the RSSI for a given connection handle
  *
  * NOTE: OGF=0x05 OCF=0x0005
@@ -1526,24 +994,3 @@ host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len)
 
     host_hci_cmd_body_read_rssi(handle, dst);
 }
-
-/**
- * Read the RSSI for a given connection handle
- *
- * NOTE: OGF=0x05 OCF=0x0005
- *
- * @param handle
- *
- * @return int
- */
-int
-host_hci_cmd_read_rssi(uint16_t handle)
-{
-    uint8_t cmd[BLE_HCI_READ_RSSI_LEN];
-    int rc;
-
-    htole16(cmd, handle);
-    rc = host_hci_cmd_send(BLE_HCI_OGF_STATUS_PARAMS, BLE_HCI_OCF_RD_RSSI,
-                           BLE_HCI_READ_RSSI_LEN, cmd);
-    return rc;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6d8a3a76/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 499a898..50d6142 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -294,6 +294,7 @@
 
 /* --- LE read channel map command (OCF 0x0015) */
 #define BLE_HCI_RD_CHANMAP_LEN              (2)
+#define BLE_HCI_RD_CHANMAP_RSP_LEN          (7)
 
 /* --- LE read remote features (OCF 0x0016) */
 #define BLE_HCI_CONN_RD_REM_FEAT_LEN        (2)