http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c 
b/net/nimble/host/src/ble_hs_pvcy.c
index 94a5586..ad3fa0c 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -36,7 +36,7 @@ ble_hs_pvcy_set_addr_timeout(uint16_t timeout)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN];
     int rc;
 
-    rc = host_hci_cmd_build_set_resolv_priv_addr_timeout(
+    rc = ble_hs_hci_cmd_build_set_resolv_priv_addr_timeout(
             timeout, buf, sizeof(buf));
 
     return rc;
@@ -48,12 +48,12 @@ ble_hs_pvcy_set_resolve_enabled(int enable)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADDR_RESOL_ENA_LEN];
     int rc;
 
-    rc = host_hci_cmd_build_set_addr_res_en(enable, buf, sizeof(buf));
+    rc = ble_hs_hci_cmd_build_set_addr_res_en(enable, buf, sizeof(buf));
     if (rc != 0) {
         return rc;
     }
 
-    rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+    rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
     if (rc != 0) {
         return rc;
     }
@@ -67,13 +67,13 @@ ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_RMV_FROM_RESOLV_LIST_LEN];
     int rc;
 
-    rc = host_hci_cmd_build_remove_from_resolv_list(
+    rc = ble_hs_hci_cmd_build_remove_from_resolv_list(
         addr_type, addr, buf, sizeof(buf));
     if (rc != 0) {
         return rc;
     }
 
-    rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+    rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
     if (rc != 0) {
         return rc;
     }
@@ -87,12 +87,12 @@ ble_hs_pvcy_clear_entries(void)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN ];
     int rc;
 
-    rc = host_hci_cmd_build_clear_resolv_list(buf, sizeof(buf));
+    rc = ble_hs_hci_cmd_build_clear_resolv_list(buf, sizeof(buf));
     if (rc != 0) {
         return rc;
     }
 
-    rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+    rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
     if (rc != 0) {
         return rc;
     }
@@ -112,12 +112,12 @@ ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addr_type, 
uint8_t *irk)
     memcpy(add.local_irk, ble_hs_pvcy_irk, 16);
     memcpy(add.peer_irk, irk, 16);
 
-    rc = host_hci_cmd_build_add_to_resolv_list(&add, buf, sizeof(buf));
+    rc = ble_hs_hci_cmd_build_add_to_resolv_list(&add, buf, sizeof(buf));
     if (rc != 0) {
         return rc;
     }
 
-    rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+    rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c 
b/net/nimble/host/src/ble_hs_startup.c
index 1ce49a7..89cbd70 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -19,7 +19,6 @@
 
 #include <stddef.h>
 #include <string.h>
-#include "host/host_hci.h"
 #include "host/ble_hs.h"
 #include "ble_hs_priv.h"
 
@@ -31,8 +30,9 @@ ble_hs_startup_le_read_sup_f_tx(void)
     uint8_t ack_params_len;
     int rc;
 
-    host_hci_cmd_build_le_read_loc_supp_feat(buf, sizeof buf);
-    rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+    ble_hs_hci_cmd_build_le_read_loc_supp_feat(buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx(buf, ack_params, sizeof ack_params,
+                           &ack_params_len);
     if (rc != 0) {
         return rc;
     }
@@ -56,8 +56,9 @@ ble_hs_startup_le_read_buf_sz_tx(void)
     uint8_t max_pkts;
     int rc;
 
-    host_hci_cmd_build_le_read_buffer_size(buf, sizeof buf);
-    rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+    ble_hs_hci_cmd_build_le_read_buffer_size(buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx(buf, ack_params, sizeof ack_params,
+                           &ack_params_len);
     if (rc != 0) {
         return rc;
     }
@@ -69,7 +70,7 @@ ble_hs_startup_le_read_buf_sz_tx(void)
     pktlen = le16toh(ack_params + 0);
     max_pkts = ack_params[2];
 
-    rc = host_hci_set_buf_size(pktlen, max_pkts);
+    rc = ble_hs_hci_set_buf_sz(pktlen, max_pkts);
     if (rc != 0) {
         return rc;
     }
@@ -85,8 +86,9 @@ ble_hs_startup_read_bd_addr(void)
     uint8_t ack_params_len;
     int rc;
 
-    host_hci_cmd_build_read_bd_addr(buf, sizeof buf);
-    rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+    ble_hs_hci_cmd_build_read_bd_addr(buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx(buf, ack_params, sizeof ack_params,
+                           &ack_params_len);
     if (rc != 0) {
         return rc;
     }
@@ -116,8 +118,9 @@ ble_hs_startup_le_set_evmask_tx(void)
      *     0x0000000000000040 LE Data Length Change Event
      *     0x0000000000000200 LE Enhanced Connection Complete Event
      */
-    host_hci_cmd_build_le_set_event_mask(0x000000000000027f, buf, sizeof buf);
-    rc = ble_hci_cmd_tx_empty_ack(buf);
+    ble_hs_hci_cmd_build_le_set_event_mask(0x000000000000027f,
+                                           buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;
     }
@@ -173,8 +176,8 @@ ble_hs_startup_set_evmask_tx(void)
      *     0x0000800000000000 Encryption Key Refresh Complete Event
      *     0x2000000000000000 LE Meta-Event
      */
-    host_hci_cmd_build_set_event_mask(0x20009fffffffffff, buf, sizeof buf);
-    rc = ble_hci_cmd_tx_empty_ack(buf);
+    ble_hs_hci_cmd_build_set_event_mask(0x20009fffffffffff, buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;
     }
@@ -183,8 +186,8 @@ ble_hs_startup_set_evmask_tx(void)
      * Enable the following events:
      *     0x0000000000800000 Authenticated Payload Timeout Event
      */
-    host_hci_cmd_build_set_event_mask2(0x0000000000800000, buf, sizeof buf);
-    rc = ble_hci_cmd_tx_empty_ack(buf);
+    ble_hs_hci_cmd_build_set_event_mask2(0x0000000000800000, buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;
     }
@@ -198,8 +201,8 @@ ble_hs_startup_reset_tx(void)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN];
     int rc;
 
-    host_hci_cmd_build_reset(buf, sizeof buf);
-    rc = ble_hci_cmd_tx_empty_ack(buf);
+    ble_hs_hci_cmd_build_reset(buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_ibeacon.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_ibeacon.c 
b/net/nimble/host/src/ble_ibeacon.c
index 68c182f..5bdb99d 100644
--- a/net/nimble/host/src/ble_ibeacon.c
+++ b/net/nimble/host/src/ble_ibeacon.c
@@ -61,7 +61,7 @@ ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, 
uint16_t minor)
 
     /** Last byte (tx power level) filled in after HCI exchange. */
 
-    rc = ble_hci_util_read_adv_tx_pwr(&tx_pwr);
+    rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index a25c364..66bad51 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -22,7 +22,6 @@
 #include "os/os.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "host/host_hci.h"
 #include "ble_hs_priv.h"
 
 _Static_assert(sizeof (struct ble_l2cap_hdr) == BLE_L2CAP_HDR_SZ,
@@ -287,7 +286,7 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct 
ble_l2cap_chan *chan,
         return BLE_HS_ENOMEM;
     }
 
-    rc = host_hci_data_tx(conn, txom);
+    rc = ble_hs_hci_acl_tx(conn, txom);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index ae2e5f8..f2a7b5c 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -259,7 +259,7 @@ ble_sm_gen_pair_rand(uint8_t *pair_rand)
     }
 #endif
 
-    rc = ble_hci_util_rand(pair_rand, 16);
+    rc = ble_hs_hci_util_rand(pair_rand, 16);
     if (rc != 0) {
         return rc;
     }
@@ -280,7 +280,7 @@ ble_sm_gen_ediv(uint16_t *ediv)
     }
 #endif
 
-    rc = ble_hci_util_rand(ediv, sizeof *ediv);
+    rc = ble_hs_hci_util_rand(ediv, sizeof *ediv);
     if (rc != 0) {
         return rc;
     }
@@ -301,7 +301,7 @@ ble_sm_gen_master_id_rand(uint64_t *master_id_rand)
     }
 #endif
 
-    rc = ble_hci_util_rand(master_id_rand, sizeof *master_id_rand);
+    rc = ble_hs_hci_util_rand(master_id_rand, sizeof *master_id_rand);
     if (rc != 0) {
         return rc;
     }
@@ -323,7 +323,7 @@ ble_sm_gen_ltk(struct ble_sm_proc *proc, uint8_t *ltk)
     }
 #endif
 
-    rc = ble_hci_util_rand(ltk, 16);
+    rc = ble_hs_hci_util_rand(ltk, 16);
     if (rc != 0) {
         return rc;
     }
@@ -345,7 +345,7 @@ ble_sm_gen_csrk(struct ble_sm_proc *proc, uint8_t *csrk)
     }
 #endif
 
-    rc = ble_hci_util_rand(csrk, 16);
+    rc = ble_hs_hci_util_rand(csrk, 16);
     if (rc != 0) {
         return rc;
     }
@@ -875,8 +875,8 @@ ble_sm_start_encrypt_tx(struct hci_start_encrypt *cmd)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN];
     int rc;
 
-    host_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
-    rc = ble_hci_cmd_tx_empty_ack(buf);
+    ble_hs_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;
     }
@@ -1059,9 +1059,9 @@ ble_sm_ltk_req_reply_tx(uint16_t conn_handle, uint8_t 
*ltk)
     cmd.conn_handle = conn_handle;
     memcpy(cmd.long_term_key, ltk, 16);
 
-    host_hci_cmd_build_le_lt_key_req_reply(&cmd, buf, sizeof buf);
-    rc = ble_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
-                        &ack_params_len);
+    ble_hs_hci_cmd_build_le_lt_key_req_reply(&cmd, buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
+                           &ack_params_len);
     if (rc != 0) {
         return rc;
     }
@@ -1085,9 +1085,9 @@ ble_sm_ltk_req_neg_reply_tx(uint16_t conn_handle)
     uint8_t ack_params_len;
     int rc;
 
-    host_hci_cmd_build_le_lt_key_req_neg_reply(conn_handle, buf, sizeof buf);
-    rc = ble_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
-                        &ack_params_len);
+    ble_hs_hci_cmd_build_le_lt_key_req_neg_reply(conn_handle, buf, sizeof buf);
+    rc = ble_hs_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
+                           &ack_params_len);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index 3aac60d..a2b0fcf 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -410,7 +410,8 @@ ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const 
uint8_t *n2,
 }
 
 int
-ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y, uint32_t 
*passkey)
+ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y,
+              uint32_t *passkey)
 {
     uint8_t m[80], xs[16];
     int rc;
@@ -476,7 +477,7 @@ ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv)
     int rc;
 
     do {
-        rc = ble_hci_util_rand(random, sizeof random);
+        rc = ble_hs_hci_util_rand(random, sizeof random);
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 455da90..539d0f9 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -221,7 +221,7 @@ ble_sm_sc_gen_ri(struct ble_sm_proc *proc)
         return 0;
 
     case BLE_SM_PAIR_ALG_OOB:
-        rc = ble_hci_util_rand(&proc->ri, 1);
+        rc = ble_hs_hci_util_rand(&proc->ri, 1);
         return rc;
 
     default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/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
deleted file mode 100644
index f5d46a3..0000000
--- a/net/nimble/host/src/host_dbg.c
+++ /dev/null
@@ -1,503 +0,0 @@
-/**
- * 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 <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include "os/os.h"
-#include "console/console.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "ble_hs_priv.h"
-
-static void
-host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
-{
-    int8_t rssi;
-    uint8_t advlen;
-    uint8_t status;
-    int i;
-    int imax;
-    uint8_t *dptr;
-    char *adv_ptr;
-    char adv_data_buf[32];
-
-    switch (subev) {
-    case BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE:
-    case BLE_HCI_LE_SUBEV_CONN_COMPLETE:
-        status = evdata[0];
-        if (status == BLE_ERR_SUCCESS) {
-            BLE_HS_LOG(DEBUG, "LE connection complete. handle=%u role=%u "
-                              "paddrtype=%u addr=%x.%x.%x.%x.%x.%x ",
-                       le16toh(evdata + 1), evdata[3], evdata[4],
-                       evdata[10], evdata[9], evdata[8], evdata[7],
-                       evdata[6], evdata[5]);
-
-            evdata += 11;
-            if (subev == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
-                BLE_HS_LOG(DEBUG, "local_rpa=%x.%x.%x.%x.%x.%x "
-                                   "peer_rpa=%x.%x.%x.%x.%x.%x ",
-                           evdata[5], evdata[4], evdata[3], evdata[2],
-                           evdata[1], evdata[0],
-                           evdata[11], evdata[10], evdata[9], evdata[8],
-                           evdata[7], evdata[6]);
-
-                evdata += 12;
-            }
-            BLE_HS_LOG(DEBUG, "itvl=%u latency=%u spvn_tmo=%u mca=%u\n",
-                       le16toh(evdata), le16toh(evdata + 2),
-                       le16toh(evdata + 4), evdata[6]);
-        } else {
-            BLE_HS_LOG(DEBUG, "LE connection complete. FAIL (status=%u)\n",
-                       status);
-        }
-        break;
-    case BLE_HCI_LE_SUBEV_ADV_RPT:
-        advlen = evdata[9];
-        rssi = evdata[10 + advlen];
-        BLE_HS_LOG(DEBUG, "LE advertising report. len=%u num=%u evtype=%u "
-                          "addrtype=%u addr=%x.%x.%x.%x.%x.%x advlen=%u "
-                          "rssi=%d\n", len, evdata[0], evdata[1], evdata[2],
-                   evdata[8], evdata[7], evdata[6], evdata[5],
-                   evdata[4], evdata[3], advlen, rssi);
-        if (advlen) {
-            dptr = &evdata[10];
-            while (advlen > 0) {
-                memset(adv_data_buf, 0, 32);
-                imax = advlen;
-                if (imax > 8) {
-                    imax = 8;
-                }
-                adv_ptr = &adv_data_buf[0];
-                for (i = 0; i < imax; ++i) {
-                    snprintf(adv_ptr, 4, "%02x ", *dptr);
-                    adv_ptr += 3;
-                    ++dptr;
-                }
-                advlen -= imax;
-                BLE_HS_LOG(DEBUG, "%s\n", adv_data_buf);
-            }
-        }
-        break;
-    case BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE:
-        status = evdata[0];
-        if (status == BLE_ERR_SUCCESS) {
-            BLE_HS_LOG(DEBUG, "LE Connection Update Complete. handle=%u "
-                              "itvl=%u latency=%u timeout=%u\n",
-                       le16toh(evdata + 1), le16toh(evdata + 3),
-                       le16toh(evdata + 5), le16toh(evdata + 7));
-        } else {
-            BLE_HS_LOG(DEBUG, "LE Connection Update Complete. FAIL "
-                              "(status=%u)\n", status);
-        }
-        break;
-
-    case BLE_HCI_LE_SUBEV_DATA_LEN_CHG:
-        BLE_HS_LOG(DEBUG, "LE Data Length Change. handle=%u max_tx_bytes=%u "
-                          "max_tx_time=%u max_rx_bytes=%u max_rx_time=%u\n",
-                   le16toh(evdata), le16toh(evdata + 2),
-                   le16toh(evdata + 4), le16toh(evdata + 6),
-                   le16toh(evdata + 8));
-        break;
-    case BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ:
-        BLE_HS_LOG(DEBUG, "LE Remote Connection Parameter Request. handle=%u "
-                          "min_itvl=%u max_itvl=%u latency=%u timeout=%u\n",
-                   le16toh(evdata), le16toh(evdata + 2),
-                   le16toh(evdata + 4), le16toh(evdata + 6),
-                   le16toh(evdata + 8));
-        break;
-
-    case BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT:
-        status = evdata[0];
-        if (status == BLE_ERR_SUCCESS) {
-            BLE_HS_LOG(DEBUG, "LE Remote Used Features. handle=%u feat=",
-                       le16toh(evdata + 1));
-            for (i = 0; i < BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN; ++i) {
-                BLE_HS_LOG(DEBUG, "%02x ", evdata[3 + i]);
-            }
-            BLE_HS_LOG(DEBUG, "\n");
-        } else {
-            BLE_HS_LOG(DEBUG, "LE Remote Used Features. FAIL (status=%u)\n",
-                       status);
-        }
-        break;
-
-    case BLE_HCI_LE_SUBEV_LT_KEY_REQ:
-            BLE_HS_LOG(DEBUG, "LE LTK Req. handle=%u rand=%lx%lx encdiv=%u\n",
-                       le16toh(evdata), le32toh(evdata + 6),
-                       le32toh(evdata + 2), le16toh(evdata + 10));
-        break;
-
-    default:
-        BLE_HS_LOG(DEBUG, "\tUnknown LE event\n");
-        break;
-    }
-}
-
-/**
- * Display a disconnection complete command.
- *
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
-{
-    uint8_t status;
-    uint8_t reason;
-    uint16_t handle;
-
-    status = evdata[0];
-    handle = le16toh(evdata + 1);
-    /* Ignore reason if status is not success */
-    if (status != BLE_ERR_SUCCESS) {
-        reason = 0;
-    } else {
-        reason = evdata[3];
-    }
-    BLE_HS_LOG(DEBUG, "Disconnection Complete: status=%u handle=%u "
-                      "reason=%u\n", status, handle, reason);
-}
-
-/**
- * Display an encryption change event or encryption key refresh event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_encrypt_chg_disp(uint8_t *evdata, uint8_t len)
-{
-    uint8_t status;
-    uint8_t enabled;
-    uint16_t handle;
-
-    status = evdata[0];
-    handle = le16toh(evdata + 1);
-
-    /* Ignore reason if status is not success */
-    if (status != BLE_ERR_SUCCESS) {
-        enabled = 0;
-    } else {
-        enabled = evdata[3];
-    }
-    BLE_HS_LOG(DEBUG, "Encrypt change: status=%u handle=%u state=%u\n",
-               status, handle, enabled);
-}
-
-/**
- * Display an encryption encryption key refresh event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_encrypt_refresh_disp(uint8_t *evdata, uint8_t len)
-{
-    uint8_t status;
-    uint16_t handle;
-
-    status = evdata[0];
-    handle = le16toh(evdata + 1);
-
-    BLE_HS_LOG(DEBUG, "Encrypt key refresh: status=%u handle=%u\n",
-               status, handle);
-}
-
-/**
- * Display a version information event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
-{
-    BLE_HS_LOG(DEBUG, "Remote Version Info: status=%u handle=%u vers_nr=%u "
-                      "compid=%u subver=%u\n",
-               evdata[0], le16toh(evdata + 1), evdata[3],
-               le16toh(evdata + 4), le16toh(evdata + 6));
-}
-
-/**
- * Display the number of completed packets event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
-{
-    uint8_t handles;
-    uint8_t *handle_ptr;
-    uint8_t *pkt_ptr;
-    uint16_t handle;
-    uint16_t pkts;
-
-    handles = evdata[0];
-    if (len != ((handles * 4) + 1)) {
-        BLE_HS_LOG(DEBUG, "ERR: Number of Completed Packets bad length: "
-                          "num_handles=%u len=%u\n", handles, len);
-        return;
-
-    }
-
-    BLE_HS_LOG(DEBUG, "Number of Completed Packets: num_handles=%u\n",
-               handles);
-    if (handles) {
-        handle_ptr = evdata + 1;
-        pkt_ptr = handle_ptr + (2 * handles);
-        while (handles) {
-            handle = le16toh(handle_ptr);
-            handle_ptr += 2;
-            pkts = le16toh(pkt_ptr);
-            pkt_ptr += 2;
-            BLE_HS_LOG(DEBUG, "handle:%u pkts:%u\n", handle, pkts);
-            --handles;
-        }
-    }
-}
-
-/**
- * Display the authenticated payload timeout event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_auth_pyld_tmo_disp(uint8_t *evdata, uint8_t len)
-{
-    uint16_t handle;
-
-    if (len != sizeof(uint16_t)) {
-        BLE_HS_LOG(DEBUG, "ERR: AuthPyldTmoEvent bad length %u\n", len);
-        return;
-
-    }
-
-    handle = le16toh(evdata);
-    BLE_HS_LOG(DEBUG, "AuthPyldTmo: handle=%u\n", handle);
-}
-
-
-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;
-
-    if (len < 3) {
-        BLE_HS_LOG(DEBUG, "Invalid command complete: len=%d "
-                          "(expected >= 3)", len);
-        goto done;
-    }
-
-    cmd_pkts = evdata[0];
-    opcode = le16toh(evdata + 1);
-    ogf = BLE_HCI_OGF(opcode);
-    ocf = BLE_HCI_OCF(opcode);
-
-    BLE_HS_LOG(DEBUG, "Command complete: cmd_pkts=%u ogf=0x%x ocf=0x%x",
-               cmd_pkts, ogf, ocf);
-
-    if (len == 3) {
-        goto done;
-    }
-
-    status = evdata[3];
-    BLE_HS_LOG(DEBUG, " status=%u ", status);
-
-    /* Move past header and status */
-    evdata += 4;
-
-    /* Display parameters based on command. */
-    switch (ogf) {
-    case BLE_HCI_OGF_INFO_PARAMS:
-        host_hci_dbg_cmd_comp_info_params(status, ocf, evdata);
-        break;
-    case BLE_HCI_OGF_STATUS_PARAMS:
-        switch (ocf) {
-        case BLE_HCI_OCF_RD_RSSI:
-            BLE_HS_LOG(DEBUG, "handle=%u rssi=%d", le16toh(evdata),
-                       (int8_t)evdata[2]);
-            break;
-        default:
-            break;
-        }
-        break;
-    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",
-                       le16toh(evdata), evdata[2], evdata[3], evdata[4],
-                       evdata[5], evdata[6]);
-            break;
-        case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
-            BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u rxoct=%u rxtime=%u",
-                       le16toh(evdata), le16toh(evdata + 2),
-                       le16toh(evdata + 4), le16toh(evdata + 6));
-            break;
-        case BLE_HCI_OCF_LE_RD_SUPP_STATES:
-            BLE_HS_LOG(DEBUG, "states=0x%lx%08lx", le32toh(evdata + 4),
-                       le32toh(evdata));
-            break;
-        case BLE_HCI_OCF_LE_ENCRYPT:
-            BLE_HS_LOG(DEBUG, "encdata=0x%02x%02x%02x%02x%02x%02x%02x%02x",
-                       evdata[15], evdata[14], evdata[13], evdata[12],
-                       evdata[11], evdata[10], evdata[9], evdata[8]);
-            BLE_HS_LOG(DEBUG, "%02x%02x%02x%02x%02x%02x%02x%02x",
-                       evdata[7], evdata[6], evdata[5], evdata[4],
-                       evdata[3], evdata[2], evdata[1], evdata[0]);
-
-            break;
-        case BLE_HCI_OCF_LE_RAND:
-            BLE_HS_LOG(DEBUG, "rand=0x%02x%02x%02x%02x%02x%02x%02x%02x",
-                       evdata[0], evdata[1], evdata[2], evdata[3],
-                       evdata[4], evdata[5], evdata[6], evdata[7]);
-            break;
-        case BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN:
-            BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u", le16toh(evdata),
-                       le16toh(evdata + 2));
-            break;
-        case BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY:
-        case BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY:
-        case BLE_HCI_OCF_LE_SET_DATA_LEN:
-            BLE_HS_LOG(DEBUG, "handle=%u", le16toh(evdata));
-            break;
-        default:
-            break;
-        }
-        break;
-    default:
-        break;
-    }
-
-done:
-    BLE_HS_LOG(DEBUG, "\n");
-}
-
-static void
-host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
-{
-    uint8_t ogf;
-    uint8_t ocf;
-    uint16_t opcode;
-
-    opcode = le16toh(evdata + 2);
-    ogf = BLE_HCI_OGF(opcode);
-    ocf = BLE_HCI_OCF(opcode);
-
-    BLE_HS_LOG(DEBUG, "Command Status: status=%u cmd_pkts=%u ocf=0x%x "
-                      "ogf=0x%x\n", evdata[0], evdata[1], ocf, ogf);
-}
-
-void
-host_hci_dbg_event_disp(uint8_t *evbuf)
-{
-#if LOG_LEVEL > LOG_LEVEL_DEBUG
-    return;
-#endif
-
-    uint8_t *evdata;
-    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 + BLE_HCI_EVENT_HDR_LEN;
-
-    switch (evcode) {
-    case BLE_HCI_EVCODE_DISCONN_CMP:
-        host_hci_dbg_disconn_comp_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_ENC_KEY_REFRESH:
-        host_hci_dbg_encrypt_refresh_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_ENCRYPT_CHG:
-        host_hci_dbg_encrypt_chg_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP:
-        host_hci_dbg_rd_rem_ver_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_COMMAND_COMPLETE:
-        host_hci_dbg_cmd_complete_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_COMMAND_STATUS:
-        host_hci_dbg_cmd_status_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_NUM_COMP_PKTS:
-        host_hci_dbg_num_comp_pkts_disp(evdata, len);
-        break;
-    case BLE_HCI_EVCODE_LE_META:
-        host_hci_dbg_le_event_disp(evdata[0], len, evdata + 1);
-        break;
-    case BLE_HCI_EVCODE_AUTH_PYLD_TMO:
-        host_hci_dbg_auth_pyld_tmo_disp(evdata, len);
-        break;
-    default:
-        BLE_HS_LOG(DEBUG, "Unknown event 0x%x len=%u\n", evcode, len);
-        break;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/host_dbg_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg_priv.h 
b/net/nimble/host/src/host_dbg_priv.h
deleted file mode 100644
index 8d548ca..0000000
--- a/net/nimble/host/src/host_dbg_priv.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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_HOST_DBG_
-#define H_HOST_DBG_
-
-void host_hci_dbg_event_disp(uint8_t *evbuf);
-
-#endif /* H_HOST_DBG_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/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
deleted file mode 100644
index b9bdaf9..0000000
--- a/net/nimble/host/src/host_hci.c
+++ /dev/null
@@ -1,899 +0,0 @@
-/**
- * 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 <errno.h>
-#include <stdio.h>
-#include "os/os.h"
-#include "console/console.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "host/host_hci.h"
-#include "host/ble_gap.h"
-#include "ble_hs_priv.h"
-#include "host_dbg_priv.h"
-
-_Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
-               "struct hci_data_hdr must be 4 bytes");
-
-typedef int host_hci_event_fn(uint8_t event_code, uint8_t *data, int len);
-static host_hci_event_fn host_hci_rx_disconn_complete;
-static host_hci_event_fn host_hci_rx_encrypt_change;
-static host_hci_event_fn host_hci_rx_hw_error;
-static host_hci_event_fn host_hci_rx_num_completed_pkts;
-static host_hci_event_fn host_hci_rx_enc_key_refresh;
-static host_hci_event_fn host_hci_rx_le_meta;
-
-typedef int host_hci_le_event_fn(uint8_t subevent, uint8_t *data, int len);
-static host_hci_le_event_fn host_hci_rx_le_conn_complete;
-static host_hci_le_event_fn host_hci_rx_le_adv_rpt;
-static host_hci_le_event_fn host_hci_rx_le_conn_upd_complete;
-static host_hci_le_event_fn host_hci_rx_le_lt_key_req;
-static host_hci_le_event_fn host_hci_rx_le_conn_parm_req;
-static host_hci_le_event_fn host_hci_rx_le_dir_adv_rpt;
-
-static uint16_t host_hci_buffer_sz;
-static uint8_t host_hci_max_pkts;
-
-/* Statistics */
-struct host_hci_stats
-{
-    uint32_t events_rxd;
-    uint32_t good_acks_rxd;
-    uint32_t bad_acks_rxd;
-    uint32_t unknown_events_rxd;
-};
-
-#define HOST_HCI_TIMEOUT        50      /* Milliseconds. */
-
-/** Dispatch table for incoming HCI events.  Sorted by event code field. */
-struct host_hci_event_dispatch_entry {
-    uint8_t hed_event_code;
-    host_hci_event_fn *hed_fn;
-};
-
-static const struct host_hci_event_dispatch_entry host_hci_event_dispatch[] = {
-    { BLE_HCI_EVCODE_DISCONN_CMP, host_hci_rx_disconn_complete },
-    { BLE_HCI_EVCODE_ENCRYPT_CHG, host_hci_rx_encrypt_change },
-    { BLE_HCI_EVCODE_HW_ERROR, host_hci_rx_hw_error },
-    { BLE_HCI_EVCODE_NUM_COMP_PKTS, host_hci_rx_num_completed_pkts },
-    { BLE_HCI_EVCODE_ENC_KEY_REFRESH, host_hci_rx_enc_key_refresh },
-    { BLE_HCI_EVCODE_LE_META, host_hci_rx_le_meta },
-};
-
-#define HOST_HCI_EVENT_DISPATCH_SZ \
-    (sizeof host_hci_event_dispatch / sizeof host_hci_event_dispatch[0])
-
-/** Dispatch table for incoming LE meta events.  Sorted by subevent field. */
-struct host_hci_le_event_dispatch_entry {
-    uint8_t hmd_subevent;
-    host_hci_le_event_fn *hmd_fn;
-};
-
-static const struct host_hci_le_event_dispatch_entry
-        host_hci_le_event_dispatch[] = {
-    { BLE_HCI_LE_SUBEV_CONN_COMPLETE, host_hci_rx_le_conn_complete },
-    { BLE_HCI_LE_SUBEV_ADV_RPT, host_hci_rx_le_adv_rpt },
-    { BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE, host_hci_rx_le_conn_upd_complete },
-    { BLE_HCI_LE_SUBEV_LT_KEY_REQ, host_hci_rx_le_lt_key_req },
-    { BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ, host_hci_rx_le_conn_parm_req },
-    { BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE, host_hci_rx_le_conn_complete },
-    { BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT, host_hci_rx_le_dir_adv_rpt },
-};
-
-#define HOST_HCI_LE_EVENT_DISPATCH_SZ \
-    (sizeof host_hci_le_event_dispatch / sizeof host_hci_le_event_dispatch[0])
-
-uint16_t
-host_hci_opcode_join(uint8_t ogf, uint16_t ocf)
-{
-    return (ogf << 10) | ocf;
-}
-
-uint16_t
-host_hci_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc)
-{
-    BLE_HS_DBG_ASSERT(handle <= 0x0fff);
-    BLE_HS_DBG_ASSERT(pb <= 0x03);
-    BLE_HS_DBG_ASSERT(bc <= 0x03);
-
-    return (handle  << 0)   |
-           (pb      << 12)  |
-           (bc      << 14);
-}
-
-static const struct host_hci_event_dispatch_entry *
-host_hci_dispatch_entry_find(uint8_t event_code)
-{
-    const struct host_hci_event_dispatch_entry *entry;
-    int i;
-
-    for (i = 0; i < HOST_HCI_EVENT_DISPATCH_SZ; i++) {
-        entry = host_hci_event_dispatch + i;
-        if (entry->hed_event_code == event_code) {
-            return entry;
-        }
-    }
-
-    return NULL;
-}
-
-static const struct host_hci_le_event_dispatch_entry *
-host_hci_le_dispatch_entry_find(uint8_t event_code)
-{
-    const struct host_hci_le_event_dispatch_entry *entry;
-    int i;
-
-    for (i = 0; i < HOST_HCI_LE_EVENT_DISPATCH_SZ; i++) {
-        entry = host_hci_le_event_dispatch + i;
-        if (entry->hmd_subevent == event_code) {
-            return entry;
-        }
-    }
-
-    return NULL;
-}
-
-static int
-host_hci_rx_disconn_complete(uint8_t event_code, uint8_t *data, int len)
-{
-    struct hci_disconn_complete evt;
-
-    if (len < BLE_HCI_EVENT_DISCONN_COMPLETE_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.status = data[2];
-    evt.connection_handle = le16toh(data + 3);
-    evt.reason = data[5];
-
-    ble_gap_rx_disconn_complete(&evt);
-
-    return 0;
-}
-
-static int
-host_hci_rx_encrypt_change(uint8_t event_code, uint8_t *data, int len)
-{
-    struct hci_encrypt_change evt;
-
-    if (len < BLE_HCI_EVENT_ENCRYPT_CHG_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.status = data[2];
-    evt.connection_handle = le16toh(data + 3);
-    evt.encryption_enabled = data[5];
-
-    ble_sm_enc_change_rx(&evt);
-
-    return 0;
-}
-
-static int
-host_hci_rx_hw_error(uint8_t event_code, uint8_t *data, int len)
-{
-    uint8_t hw_code;
-
-    if (len < BLE_HCI_EVENT_HW_ERROR_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    hw_code = data[0];
-    ble_hs_hw_error(hw_code);
-
-    return 0;
-}
-
-static int
-host_hci_rx_enc_key_refresh(uint8_t event_code, uint8_t *data, int len)
-{
-    struct hci_encrypt_key_refresh evt;
-
-    if (len < BLE_HCI_EVENT_ENC_KEY_REFRESH_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.status = data[2];
-    evt.connection_handle = le16toh(data + 3);
-
-    ble_sm_enc_key_refresh_rx(&evt);
-
-    return 0;
-}
-
-static int
-host_hci_rx_num_completed_pkts(uint8_t event_code, uint8_t *data, int len)
-{
-    uint16_t num_pkts;
-    uint16_t handle;
-    uint8_t num_handles;
-    int off;
-    int i;
-
-    if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    off = BLE_HCI_EVENT_HDR_LEN;
-    num_handles = data[off];
-    if (len < BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN +
-              num_handles * BLE_HCI_EVENT_NUM_COMP_PKTS_ENT_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-    off++;
-
-    for (i = 0; i < num_handles; i++) {
-        handle = le16toh(data + off + 2 * i);
-        num_pkts = le16toh(data + off + 2 * num_handles + 2 * i);
-
-        /* XXX: Do something with these values. */
-        (void)handle;
-        (void)num_pkts;
-    }
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_meta(uint8_t event_code, uint8_t *data, int len)
-{
-    const struct host_hci_le_event_dispatch_entry *entry;
-    uint8_t subevent;
-    int rc;
-
-    if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_LE_MIN_LEN) {
-        /* XXX: Increment stat. */
-        return BLE_HS_ECONTROLLER;
-    }
-
-    subevent = data[2];
-    entry = host_hci_le_dispatch_entry_find(subevent);
-    if (entry != NULL) {
-        rc = entry->hmd_fn(subevent, data + BLE_HCI_EVENT_HDR_LEN,
-                           len - BLE_HCI_EVENT_HDR_LEN);
-        if (rc != 0) {
-            return rc;
-        }
-    }
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_conn_complete(uint8_t subevent, uint8_t *data, int len)
-{
-    struct hci_le_conn_complete evt;
-    int extended_offset = 0;
-    int rc;
-
-    if (len < BLE_HCI_LE_CONN_COMPLETE_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    /* this code processes two different events that are really similar */
-    if ((subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) &&
-        ( len < BLE_HCI_LE_ENH_CONN_COMPLETE_LEN)) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.subevent_code = data[0];
-    evt.status = data[1];
-    evt.connection_handle = le16toh(data + 2);
-    evt.role = data[4];
-    evt.peer_addr_type = data[5];
-    memcpy(evt.peer_addr, data + 6, BLE_DEV_ADDR_LEN);
-
-    /* enhanced connection event has the same information with these
-     * extra fields stuffed into the middle */
-    if (subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
-        memcpy(evt.local_rpa, data + 12, BLE_DEV_ADDR_LEN);
-        memcpy(evt.peer_rpa, data + 18, BLE_DEV_ADDR_LEN);
-        extended_offset = 12;
-    } else {
-        memset(evt.local_rpa, 0, BLE_DEV_ADDR_LEN);
-        memset(evt.peer_rpa, 0, BLE_DEV_ADDR_LEN);
-    }
-
-    evt.conn_itvl = le16toh(data + 12 + extended_offset);
-    evt.conn_latency = le16toh(data + 14 + extended_offset);
-    evt.supervision_timeout = le16toh(data + 16 + extended_offset);
-    evt.master_clk_acc = data[18 + extended_offset];
-
-    if (evt.status == 0) {
-        if (evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER &&
-            evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
-
-            return BLE_HS_EBADDATA;
-        }
-    }
-
-    rc = ble_gap_rx_conn_complete(&evt);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-static int
-host_hci_le_adv_rpt_first_pass(uint8_t *data, int len,
-                               uint8_t *out_num_reports, int *out_rssi_off)
-{
-    uint8_t num_reports;
-    int data_len;
-    int off;
-    int i;
-
-    if (len < BLE_HCI_LE_ADV_RPT_MIN_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    num_reports = data[1];
-    if (num_reports < BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN ||
-        num_reports > BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX) {
-
-        return BLE_HS_EBADDATA;
-    }
-
-    off = 2 +       /* Subevent code and num reports. */
-          (1 +      /* Event type. */
-           1 +      /* Address type. */
-           6        /* Address. */
-          ) * num_reports;
-    if (off + num_reports >= len) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    data_len = 0;
-    for (i = 0; i < num_reports; i++) {
-        data_len += data[off];
-        off++;
-    }
-
-    off += data_len;
-
-    /* Check if RSSI fields fit in the packet. */
-    if (off + num_reports > len) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    *out_num_reports = num_reports;
-    *out_rssi_off = off;
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
-{
-    struct ble_gap_disc_desc desc;
-    uint8_t num_reports;
-    int rssi_off;
-    int data_off;
-    int suboff;
-    int off;
-    int rc;
-    int i;
-
-    rc = host_hci_le_adv_rpt_first_pass(data, len, &num_reports, &rssi_off);
-    if (rc != 0) {
-        return rc;
-    }
-
-    /* Direct address fields not present in a standard advertising report. */
-    desc.direct_addr_type = BLE_GAP_ADDR_TYPE_NONE;
-    memset(desc.direct_addr, 0, sizeof desc.direct_addr);
-
-    data_off = 0;
-    for (i = 0; i < num_reports; i++) {
-        suboff = 0;
-
-        off = 2 + suboff * num_reports + i;
-        desc.event_type = data[off];
-        suboff++;
-
-        off = 2 + suboff * num_reports + i;
-        desc.addr_type = data[off];
-        suboff++;
-
-        off = 2 + suboff * num_reports + i * 6;
-        memcpy(desc.addr, data + off, 6);
-        suboff += 6;
-
-        off = 2 + suboff * num_reports + i;
-        desc.length_data = data[off];
-        suboff++;
-
-        off = 2 + suboff * num_reports + data_off;
-        desc.data = data + off;
-        data_off += desc.length_data;
-
-        off = rssi_off + 1 * i;
-        desc.rssi = data[off];
-
-        ble_gap_rx_adv_report(&desc);
-    }
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_dir_adv_rpt(uint8_t subevent, uint8_t *data, int len)
-{
-    struct ble_gap_disc_desc desc;
-    uint8_t num_reports;
-    int suboff;
-    int off;
-    int i;
-
-    if (len < BLE_HCI_LE_ADV_DIRECT_RPT_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    num_reports = data[1];
-    if (len != 2 + num_reports * BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    /* Data fields not present in a direct advertising report. */
-    desc.data = NULL;
-    desc.fields = NULL;
-
-    for (i = 0; i < num_reports; i++) {
-        suboff = 0;
-
-        off = 2 + suboff * num_reports + i;
-        desc.event_type = data[off];
-        suboff++;
-
-        off = 2 + suboff * num_reports + i;
-        desc.addr_type = data[off];
-        suboff++;
-
-        off = 2 + suboff * num_reports + i * 6;
-        memcpy(desc.addr, data + off, 6);
-        suboff += 6;
-
-        off = 2 + suboff * num_reports + i;
-        desc.direct_addr_type = data[off];
-        suboff++;
-
-        off = 2 + suboff * num_reports + i * 6;
-        memcpy(desc.direct_addr, data + off, 6);
-        suboff += 6;
-
-        off = 2 + suboff * num_reports + i;
-        desc.rssi = data[off];
-        suboff++;
-
-        ble_gap_rx_adv_report(&desc);
-    }
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_conn_upd_complete(uint8_t subevent, uint8_t *data, int len)
-{
-    struct hci_le_conn_upd_complete evt;
-
-    if (len < BLE_HCI_LE_CONN_UPD_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.subevent_code = data[0];
-    evt.status = data[1];
-    evt.connection_handle = le16toh(data + 2);
-    evt.conn_itvl = le16toh(data + 4);
-    evt.conn_latency = le16toh(data + 6);
-    evt.supervision_timeout = le16toh(data + 8);
-
-    if (evt.status == 0) {
-        if (evt.conn_itvl < BLE_HCI_CONN_ITVL_MIN ||
-            evt.conn_itvl > BLE_HCI_CONN_ITVL_MAX) {
-
-            return BLE_HS_EBADDATA;
-        }
-        if (evt.conn_latency < BLE_HCI_CONN_LATENCY_MIN ||
-            evt.conn_latency > BLE_HCI_CONN_LATENCY_MAX) {
-
-            return BLE_HS_EBADDATA;
-        }
-        if (evt.supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN ||
-            evt.supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX) {
-
-            return BLE_HS_EBADDATA;
-        }
-    }
-
-    ble_gap_rx_update_complete(&evt);
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_lt_key_req(uint8_t subevent, uint8_t *data, int len)
-{
-    struct hci_le_lt_key_req evt;
-
-    if (len < BLE_HCI_LE_LT_KEY_REQ_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.subevent_code = data[0];
-    evt.connection_handle = le16toh(data + 1);
-    evt.random_number = le64toh(data + 3);
-    evt.encrypted_diversifier = le16toh(data + 11);
-
-    ble_sm_ltk_req_rx(&evt);
-
-    return 0;
-}
-
-static int
-host_hci_rx_le_conn_parm_req(uint8_t subevent, uint8_t *data, int len)
-{
-    struct hci_le_conn_param_req evt;
-
-    if (len < BLE_HCI_LE_REM_CONN_PARM_REQ_LEN) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    evt.subevent_code = data[0];
-    evt.connection_handle = le16toh(data + 1);
-    evt.itvl_min = le16toh(data + 3);
-    evt.itvl_max = le16toh(data + 5);
-    evt.latency = le16toh(data + 7);
-    evt.timeout = le16toh(data + 9);
-
-    if (evt.itvl_min < BLE_HCI_CONN_ITVL_MIN ||
-        evt.itvl_max > BLE_HCI_CONN_ITVL_MAX ||
-        evt.itvl_min > evt.itvl_max) {
-
-        return BLE_HS_EBADDATA;
-    }
-    if (evt.latency < BLE_HCI_CONN_LATENCY_MIN ||
-        evt.latency > BLE_HCI_CONN_LATENCY_MAX) {
-
-        return BLE_HS_EBADDATA;
-    }
-    if (evt.timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN ||
-        evt.timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX) {
-
-        return BLE_HS_EBADDATA;
-    }
-
-    ble_gap_rx_param_req(&evt);
-
-    return 0;
-}
-
-int
-host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts)
-{
-    if (pktlen == 0 || max_pkts == 0) {
-        return BLE_HS_EINVAL;
-    }
-
-    host_hci_buffer_sz = pktlen;
-    host_hci_max_pkts = max_pkts;
-
-    return 0;
-}
-
-int
-host_hci_evt_process(uint8_t *data)
-{
-    const struct host_hci_event_dispatch_entry *entry;
-    uint8_t event_code;
-    uint8_t param_len;
-    int event_len;
-    int rc;
-
-    /* Count events received */
-    STATS_INC(ble_hs_stats, hci_event);
-
-    /* Display to console */
-    host_hci_dbg_event_disp(data);
-
-    /* Process the event */
-    event_code = data[0];
-    param_len = data[1];
-
-    event_len = param_len + 2;
-
-    entry = host_hci_dispatch_entry_find(event_code);
-    if (entry == NULL) {
-        STATS_INC(ble_hs_stats, hci_unknown_event);
-        rc = BLE_HS_ENOTSUP;
-    } else {
-        rc = entry->hed_fn(event_code, data, event_len);
-    }
-
-    ble_hci_trans_buf_free(data);
-
-    return rc;
-}
-
-int
-host_hci_evt_rx(uint8_t *hci_ev, void *arg)
-{
-    int enqueue;
-
-    BLE_HS_DBG_ASSERT(hci_ev != NULL);
-
-    switch (hci_ev[0]) {
-    case BLE_HCI_EVCODE_COMMAND_COMPLETE:
-    case BLE_HCI_EVCODE_COMMAND_STATUS:
-        if (hci_ev[3] == 0 && hci_ev[4] == 0) {
-            enqueue = 1;
-        } else {
-            ble_hci_cmd_rx_ack(hci_ev);
-            enqueue = 0;
-        }
-        break;
-
-    default:
-        enqueue = 1;
-        break;
-    }
-
-    if (enqueue) {
-        ble_hs_enqueue_hci_event(hci_ev);
-    }
-
-    return 0;
-}
-
-/**
- * Called when a data packet is received from the controller.  This function
- * consumes the supplied mbuf, regardless of the outcome.
- *
- * @param om                    The incoming data packet, beginning with the
- *                                  HCI ACL data header.
- *
- * @return                      0 on success; nonzero on failure.
- */
-int
-host_hci_acl_process(struct os_mbuf *om)
-{
-    struct hci_data_hdr hci_hdr;
-    struct ble_hs_conn *conn;
-    ble_l2cap_rx_fn *rx_cb;
-    struct os_mbuf *rx_buf;
-    uint16_t handle;
-    int rc;
-
-    rc = ble_hci_util_data_hdr_strip(om, &hci_hdr);
-    if (rc != 0) {
-        goto err;
-    }
-
-#if (BLETEST_THROUGHPUT_TEST == 0)
-    BLE_HS_LOG(DEBUG, "host_hci_acl_process(): 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_log_mbuf(om);
-    BLE_HS_LOG(DEBUG, "\n");
-#endif
-
-    if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
-        rc = BLE_HS_EBADDATA;
-        goto err;
-    }
-
-    handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
-
-    ble_hs_lock();
-
-    conn = ble_hs_conn_find(handle);
-    if (conn == NULL) {
-        rc = BLE_HS_ENOTCONN;
-    } else {
-        rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf);
-        om = NULL;
-    }
-
-    ble_hs_unlock();
-
-    switch (rc) {
-    case 0:
-        /* Final fragment received. */
-        BLE_HS_DBG_ASSERT(rx_cb != NULL);
-        BLE_HS_DBG_ASSERT(rx_buf != NULL);
-        rc = rx_cb(handle, &rx_buf);
-        os_mbuf_free_chain(rx_buf);
-        break;
-
-    case BLE_HS_EAGAIN:
-        /* More fragments on the way. */
-        break;
-
-    default:
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(om);
-    return rc;
-}
-
-static struct os_mbuf *
-host_hci_data_hdr_prepend(struct os_mbuf *om, uint16_t handle, uint8_t pb_flag)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om2;
-
-    hci_hdr.hdh_handle_pb_bc = host_hci_handle_pb_bc_join(handle, pb_flag, 0);
-    htole16(&hci_hdr.hdh_len, OS_MBUF_PKTHDR(om)->omp_len);
-
-    om2 = os_mbuf_prepend(om, sizeof hci_hdr);
-    if (om2 == NULL) {
-        return NULL;
-    }
-
-    om = om2;
-    om = os_mbuf_pullup(om, sizeof hci_hdr);
-    if (om == NULL) {
-        return NULL;
-    }
-
-    memcpy(om->om_data, &hci_hdr, sizeof hci_hdr);
-
-    BLE_HS_LOG(DEBUG, "host tx hci data; handle=%d length=%d\n", handle,
-               le16toh(&hci_hdr.hdh_len));
-
-    return om;
-}
-
-/**
- * Splits an appropriately-sized fragment from the front of an outgoing ACL
- * data packet, if necessary.  If the packet size is within the controller's
- * buffer size requirements, no splitting is performed.  The fragment data is
- * removed from the data packet mbuf.
- *
- * @param om                    The ACL data packet.
- * @param out_frag              On success, this points to the fragment to
- *                                  send.  If the entire packet can fit within
- *                                  a single fragment, this will point to the
- *                                  ACL data packet itself ('om').
- *
- * @return                      BLE_HS_EDONE: success; this is the final
- *                                  fragment.
- *                              BLE_HS_EAGAIN: success; more data remains in
- *                                  the original mbuf.
- *                              Other BLE host core return code on error.
- */
-int
-host_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
-{
-    struct os_mbuf *frag;
-    int rc;
-
-    if (OS_MBUF_PKTLEN(*om) <= host_hci_buffer_sz) {
-        /* Final fragment. */
-        *out_frag = *om;
-        *om = NULL;
-        return BLE_HS_EDONE;
-    }
-
-    frag = ble_hs_mbuf_acm_pkt();
-    if (frag == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-
-    /* Move data from the front of the packet into the fragment mbuf. */
-    rc = os_mbuf_appendfrom(frag, *om, 0, host_hci_buffer_sz);
-    if (rc != 0) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-    os_mbuf_adj(*om, host_hci_buffer_sz);
-
-    /* More fragments to follow. */
-    *out_frag = frag;
-    return BLE_HS_EAGAIN;
-
-err:
-    os_mbuf_free_chain(frag);
-    return rc;
-}
-
-/**
- * Transmits an HCI ACL data packet.  This function consumes the supplied mbuf,
- * regardless of the outcome.
- *
- * XXX: Ensure the controller has sufficient buffer capacity for the outgoing
- * fragments.
- */
-int
-host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *txom)
-{
-    struct os_mbuf *frag;
-    uint8_t pb;
-    int done;
-    int rc;
-
-    /* The first fragment uses the first-non-flush packet boundary value.
-     * After sending the first fragment, pb gets set appropriately for all
-     * subsequent fragments in this packet.
-     */
-    pb = BLE_HCI_PB_FIRST_NON_FLUSH;
-
-    /* Send fragments until the entire packet has been sent. */
-    done = 0;
-    while (!done) {
-        rc = host_hci_split_frag(&txom, &frag);
-        switch (rc) {
-        case BLE_HS_EDONE:
-            /* This is the final fragment. */
-            done = 1;
-            break;
-
-        case BLE_HS_EAGAIN:
-            /* More fragments to follow. */
-            break;
-
-        default:
-            goto err;
-        }
-
-        frag = host_hci_data_hdr_prepend(frag, connection->bhc_handle, pb);
-        if (frag == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
-        pb = BLE_HCI_PB_MIDDLE;
-
-        BLE_HS_LOG(DEBUG, "host_hci_data_tx(): ");
-        ble_hs_log_mbuf(frag);
-        BLE_HS_LOG(DEBUG, "\n");
-
-        /* XXX: Try to pullup the entire fragment.  The controller currently
-         * requires the entire fragment to fit in a single buffer.  When this
-         * restriction is removed from the controller, this operation can be
-         * removed.
-         */
-        frag = os_mbuf_pullup(frag, OS_MBUF_PKTLEN(frag));
-        if (frag == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
-
-        rc = ble_hs_tx_data(frag);
-        if (rc != 0) {
-            goto err;
-        }
-
-        connection->bhc_outstanding_pkts++;
-    }
-
-    return 0;
-
-err:
-    BLE_HS_DBG_ASSERT(rc != 0);
-
-    os_mbuf_free_chain(txom);
-    return rc;
-}

Reply via email to