You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/03/17 10:50:10 UTC

[mynewt-nimble] branch master updated (d185f62 -> f1a5658)

This is an automated email from the ASF dual-hosted git repository.

andk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git.


    from d185f62  nimble/ll: Add fake dual mode option
     new a8e4aeb  nimble/transport: Add common HCI H4 code
     new d5201cb  nimble/transport: Add common code for new HCI transport
     new bb32f04  nimble/doc: Add documentation for HCI transport
     new 83535ed  nimble/ll: Update to new transport
     new 0cb0117  nimble/host: Update to new transport
     new ef597cc  nimble/transport: Update Dialog CMAC transport
     new 33c1ece  nimble/transport: Update nRF5340 transport
     new aefb9d4  nimble/transport: Update UART transport
     new 10958b3  nimble/transport: Update USB transport
     new 74d8f03  nimble/transport: Update socket transport
     new 1311466  nimble/transport: Update emspi transport
     new 4ba36ff  nimble/transport: Remove RAM transport
     new 0e2bb74  nimble/transport: Remove da1469x transport
     new b44ec40  nimble/transport: Add internal flow control
     new f5a26ab  babblesim/edtt: Update EDTT transport
     new e9a4a4f  apps: Update to new transport
     new 1118fe2  apps/blehci: Update configuration for new transport
     new fc4b2de  apps/blehcibridge: Remove app
     new d7e5d6f  nimble/test: Update for new transport
     new fd62bd7  porting: Update for new HCI transport
     new 1b9d48d  nimble/transport: Move BLE_MONITOR to transport
     new f1a5658  targets: Update to new transport

The 22 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/advertiser/pkg.yml                            |    2 +-
 apps/blecent/pkg.yml                               |    1 -
 apps/blecsc/pkg.yml                                |    1 -
 apps/blehci/pkg.yml                                |    1 -
 apps/blehci/syscfg.yml                             |    6 +-
 apps/blehcibridge/pkg.yml                          |   34 -
 apps/blehcibridge/src/main.c                       |   69 --
 apps/blehcibridge/syscfg.yml                       |   29 -
 apps/blehr/pkg.yml                                 |    1 -
 apps/blemesh/pkg.yml                               |    1 -
 apps/blemesh_light/pkg.yml                         |    1 -
 apps/blemesh_models_example_1/pkg.yml              |    1 -
 apps/blemesh_models_example_2/pkg.yml              |    1 -
 apps/blemesh_shell/pkg.yml                         |    1 -
 apps/bleprph/pkg.yml                               |    1 -
 apps/blestress/pkg.yml                             |    1 -
 apps/btshell/pkg.yml                               |    1 -
 apps/bttester/pkg.yml                              |    1 -
 apps/central/pkg.yml                               |    1 -
 apps/ext_advertiser/pkg.yml                        |    1 -
 apps/mesh_badge/pkg.yml                            |    1 -
 apps/peripheral/pkg.yml                            |    2 -
 apps/scanner/pkg.yml                               |    1 -
 babblesim/edtt/hci_test/syscfg.yml                 |    4 +-
 babblesim/edtt/hci_transport/pkg.yml               |    5 +-
 babblesim/edtt/hci_transport/src/ble_hci_edtt.c    |  277 +----
 babblesim/edtt/hci_transport/syscfg.yml            |   21 +-
 nimble/controller/include/controller/ble_ll_hci.h  |    3 +-
 nimble/controller/pkg.yml                          |    4 +-
 nimble/controller/src/ble_ll.c                     |   29 +-
 nimble/controller/src/ble_ll_adv.c                 |    5 +-
 nimble/controller/src/ble_ll_conn.c                |   22 +-
 nimble/controller/src/ble_ll_conn_hci.c            |   13 +-
 nimble/controller/src/ble_ll_hci.c                 |    7 +-
 nimble/controller/src/ble_ll_hci_ev.c              |   37 +-
 nimble/controller/src/ble_ll_scan.c                |    9 +-
 nimble/controller/src/ble_ll_scan_aux.c            |    7 +-
 nimble/controller/src/ble_ll_sync.c                |   27 +-
 nimble/controller/syscfg.yml                       |    7 +-
 nimble/controller/test/syscfg.yml                  |    1 -
 nimble/doc/transport.md                            |  189 ++++
 nimble/host/pkg.yml                                |    7 +-
 nimble/host/src/ble_hs.c                           |   61 +-
 nimble/host/src/ble_hs_flow.c                      |   17 +-
 nimble/host/src/ble_hs_hci.c                       |   16 +-
 nimble/host/src/ble_hs_hci_cmd.c                   |   12 +-
 nimble/host/src/ble_hs_hci_evt.c                   |    6 +-
 nimble/host/src/ble_hs_hci_priv.h                  |    2 +-
 nimble/host/src/ble_hs_priv.h                      |    1 -
 nimble/host/src/ble_l2cap_sig.c                    |    1 -
 nimble/host/syscfg.yml                             |   41 +-
 nimble/host/test/pkg.yml                           |    3 +
 nimble/host/test/src/ble_hs_hci_test.c             |    4 +-
 nimble/host/test/src/ble_hs_test_util.c            |   23 +-
 nimble/host/test/src/ble_hs_test_util_hci.c        |    6 +-
 nimble/host/test/src/ble_os_test.c                 |    1 -
 nimble/host/test/syscfg.yml                        |    2 +-
 nimble/include/nimble/ble_hci_trans.h              |  192 ----
 nimble/include/nimble/hci_common.h                 |    5 +-
 .../hci_h4/include/nimble/transport/hci_h4.h}      |   45 +-
 .../transport/common/hci_h4}/pkg.yml               |    9 +-
 nimble/transport/common/hci_h4/src/hci_h4.c        |  304 +++++
 nimble/transport/da1469x/.gitignore                |    2 -
 nimble/transport/da1469x/README                    |   13 -
 .../cmac_driver/include/cmac_driver/cmac_host.h    |   37 -
 nimble/transport/da1469x/cmac_driver/pkg.yml       |   27 -
 .../da1469x/cmac_driver/scripts/build_libcmac.sh   |   51 -
 .../transport/da1469x/cmac_driver/src/cmac_host.c  |  326 ------
 nimble/transport/da1469x/cmac_driver/syscfg.yml    |   23 -
 nimble/transport/da1469x/pkg.yml                   |   38 -
 nimble/transport/da1469x/src/da1469x_ble_hci.c     |  368 ------
 nimble/transport/da1469x/syscfg.yml                |   27 -
 nimble/transport/dialog_cmac/.gitignore            |    2 -
 .../dialog_cmac/cmac_driver/diag/src/cmac_diag.c   |   46 +-
 .../cmac_driver/include/cmac_driver/cmac_shared.h  |   12 +-
 nimble/transport/dialog_cmac/cmac_driver/pkg.yml   |    5 +-
 .../dialog_cmac/cmac_driver/src/cmac_host.c        |   10 +-
 .../dialog_cmac/cmac_driver/src/cmac_mbox.c        |   26 +-
 .../dialog_cmac/cmac_driver/src/cmac_rand.c        |    2 +-
 .../dialog_cmac/cmac_driver/src/cmac_shared.c      |   24 +-
 .../transport/dialog_cmac/cmac_driver/syscfg.yml   |    2 +-
 nimble/transport/dialog_cmac/pkg.yml               |    5 +-
 .../dialog_cmac/src/ble_hci_cmac_common.c          |  202 ----
 nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c |  174 ---
 nimble/transport/dialog_cmac/src/ble_hci_cmac_ll.c |  146 ---
 .../transport/dialog_cmac/src/ble_hci_cmac_priv.h  |   29 -
 .../transport/dialog_cmac/src/ble_hci_trans_h4.c   |  332 ------
 nimble/transport/dialog_cmac/src/hci_cmac.c        |  213 ++++
 nimble/transport/dialog_cmac/syscfg.yml            |   27 -
 nimble/transport/emspi/src/ble_hci_emspi.c         |  317 +-----
 nimble/transport/emspi/syscfg.yml                  |   10 -
 .../include/nimble/transport.h}                    |   39 +-
 .../include/nimble/transport/monitor.h}            |   38 +-
 .../include/nimble/transport_impl.h}               |   38 +-
 nimble/transport/nrf5340/pkg.yml                   |    6 +-
 nimble/transport/nrf5340/src/nrf5340_ble_hci.c     |  492 ++------
 nimble/transport/nrf5340/syscfg.yml                |   20 +-
 nimble/transport/pkg.yml                           |   50 +-
 .../ram/include/transport/ram/ble_hci_ram.h        |   35 -
 nimble/transport/ram/pkg.yml                       |   36 -
 nimble/transport/ram/src/ble_hci_ram.c             |  238 ----
 nimble/transport/ram/syscfg.yml                    |   33 -
 nimble/transport/socket/src/ble_hci_socket.c       |  270 +----
 nimble/transport/socket/syscfg.yml                 |   20 -
 .../src/ble_monitor.c => transport/src/monitor.c}  |   72 +-
 .../src/monitor_priv.h}                            |    2 -
 nimble/transport/src/transport.c                   |  220 ++++
 .../transport/syscfg.defunct.yml                   |   47 +-
 nimble/transport/syscfg.monitor.yml                |   58 +
 nimble/transport/syscfg.yml                        |  156 ++-
 .../uart/include/transport/uart/ble_hci_uart.h     |   33 -
 nimble/transport/uart/pkg.yml                      |   11 +-
 nimble/transport/uart/src/ble_hci_uart.c           | 1187 --------------------
 nimble/transport/uart/src/hci_uart.c               |  247 ++++
 nimble/transport/uart/syscfg.yml                   |   62 +-
 nimble/transport/usb/pkg.yml                       |    3 -
 nimble/transport/usb/src/ble_hci_usb.c             |  218 +---
 nimble/transport/usb/syscfg.yml                    |   18 -
 porting/examples/linux/include/syscfg/syscfg.h     |  130 +--
 .../examples/linux_blemesh/include/syscfg/syscfg.h |  130 +--
 porting/examples/nuttx/include/syscfg/syscfg.h     |  130 +--
 porting/nimble/Makefile.defs                       |    2 +
 porting/nimble/include/syscfg/syscfg.h             |  130 +--
 porting/nimble/src/nimble_port.c                   |    6 +-
 porting/npl/riot/include/syscfg/syscfg.h           |  180 +--
 porting/targets/linux/syscfg.yml                   |    2 +-
 porting/targets/linux_blemesh/syscfg.yml           |    2 +-
 porting/targets/nuttx/syscfg.yml                   |    2 +-
 porting/targets/porting_default/syscfg.yml         |    2 +-
 porting/targets/riot/syscfg.yml                    |    5 +-
 targets/dialog_cmac/syscfg.yml                     |    2 +-
 targets/nordic_pca10056-blehci-usb/syscfg.yml      |    2 +-
 targets/nordic_pca10095_net-blehci/syscfg.yml      |    2 +-
 133 files changed, 2341 insertions(+), 6115 deletions(-)
 delete mode 100644 apps/blehcibridge/pkg.yml
 delete mode 100644 apps/blehcibridge/src/main.c
 delete mode 100644 apps/blehcibridge/syscfg.yml
 create mode 100644 nimble/doc/transport.md
 delete mode 100644 nimble/include/nimble/ble_hci_trans.h
 rename nimble/transport/{dialog_cmac/src/ble_hci_trans_h4.h => common/hci_h4/include/nimble/transport/hci_h4.h} (50%)
 copy {babblesim/targets/blehci => nimble/transport/common/hci_h4}/pkg.yml (88%)
 create mode 100644 nimble/transport/common/hci_h4/src/hci_h4.c
 delete mode 100644 nimble/transport/da1469x/.gitignore
 delete mode 100644 nimble/transport/da1469x/README
 delete mode 100644 nimble/transport/da1469x/cmac_driver/include/cmac_driver/cmac_host.h
 delete mode 100644 nimble/transport/da1469x/cmac_driver/pkg.yml
 delete mode 100755 nimble/transport/da1469x/cmac_driver/scripts/build_libcmac.sh
 delete mode 100644 nimble/transport/da1469x/cmac_driver/src/cmac_host.c
 delete mode 100644 nimble/transport/da1469x/cmac_driver/syscfg.yml
 delete mode 100644 nimble/transport/da1469x/pkg.yml
 delete mode 100644 nimble/transport/da1469x/src/da1469x_ble_hci.c
 delete mode 100644 nimble/transport/da1469x/syscfg.yml
 delete mode 100644 nimble/transport/dialog_cmac/.gitignore
 delete mode 100644 nimble/transport/dialog_cmac/src/ble_hci_cmac_common.c
 delete mode 100644 nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c
 delete mode 100644 nimble/transport/dialog_cmac/src/ble_hci_cmac_ll.c
 delete mode 100644 nimble/transport/dialog_cmac/src/ble_hci_cmac_priv.h
 delete mode 100644 nimble/transport/dialog_cmac/src/ble_hci_trans_h4.c
 create mode 100644 nimble/transport/dialog_cmac/src/hci_cmac.c
 delete mode 100644 nimble/transport/dialog_cmac/syscfg.yml
 copy nimble/{host/include/host/ble_hs_log.h => transport/include/nimble/transport.h} (51%)
 rename nimble/{host/include/host/ble_monitor.h => transport/include/nimble/transport/monitor.h} (60%)
 copy nimble/{host/include/host/ble_hs_log.h => transport/include/nimble/transport_impl.h} (53%)
 delete mode 100644 nimble/transport/ram/include/transport/ram/ble_hci_ram.h
 delete mode 100644 nimble/transport/ram/pkg.yml
 delete mode 100644 nimble/transport/ram/src/ble_hci_ram.c
 delete mode 100644 nimble/transport/ram/syscfg.yml
 rename nimble/{host/src/ble_monitor.c => transport/src/monitor.c} (88%)
 rename nimble/{host/src/ble_monitor_priv.h => transport/src/monitor_priv.h} (99%)
 create mode 100644 nimble/transport/src/transport.c
 copy apps/btshell/syscfg.yml => nimble/transport/syscfg.defunct.yml (55%)
 create mode 100644 nimble/transport/syscfg.monitor.yml
 delete mode 100644 nimble/transport/uart/include/transport/uart/ble_hci_uart.h
 delete mode 100644 nimble/transport/uart/src/ble_hci_uart.c
 create mode 100644 nimble/transport/uart/src/hci_uart.c

[mynewt-nimble] 11/22: nimble/transport: Update emspi transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 1311466f04ec51b675ed23feda5abd05161c086a
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 10 14:42:57 2022 +0100

    nimble/transport: Update emspi transport
---
 nimble/transport/emspi/src/ble_hci_emspi.c | 317 +++--------------------------
 nimble/transport/emspi/syscfg.yml          |  10 -
 nimble/transport/pkg.yml                   |   2 +
 nimble/transport/syscfg.yml                |   1 +
 4 files changed, 32 insertions(+), 298 deletions(-)

diff --git a/nimble/transport/emspi/src/ble_hci_emspi.c b/nimble/transport/emspi/src/ble_hci_emspi.c
index 61fe96b..e49d3d4 100644
--- a/nimble/transport/emspi/src/ble_hci_emspi.c
+++ b/nimble/transport/emspi/src/ble_hci_emspi.c
@@ -35,23 +35,12 @@
 #include "nimble/ble.h"
 #include "nimble/nimble_opt.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
+#include "nimble/transport.h"
 
 #include "transport/emspi/ble_hci_emspi.h"
 
 #include "am_mcu_apollo.h"
 
-/***
- * NOTES:
- * The emspi HCI transport doesn't use event buffer priorities.  All incoming
- * and outgoing events use buffers from the same pool.
- *
- */
-
-#define BLE_HCI_EMSPI_PKT_EVT_COUNT         \
-    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + \
-     MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
-
 #define BLE_HCI_EMSPI_PKT_NONE          0x00
 #define BLE_HCI_EMSPI_PKT_CMD           0x01
 #define BLE_HCI_EMSPI_PKT_ACL           0x02
@@ -71,46 +60,6 @@ static struct os_eventq ble_hci_emspi_evq;
 static struct os_task ble_hci_emspi_task;
 static os_stack_t ble_hci_emspi_stack[MYNEWT_VAL(BLE_HCI_EMSPI_STACK_SIZE)];
 
-static ble_hci_trans_rx_cmd_fn *ble_hci_emspi_rx_cmd_cb;
-static void *ble_hci_emspi_rx_cmd_arg;
-
-static ble_hci_trans_rx_acl_fn *ble_hci_emspi_rx_acl_cb;
-static void *ble_hci_emspi_rx_acl_arg;
-
-static struct os_mempool ble_hci_emspi_evt_hi_pool;
-static os_membuf_t ble_hci_emspi_evt_hi_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_emspi_evt_lo_pool;
-static os_membuf_t ble_hci_emspi_evt_lo_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_emspi_cmd_pool;
-static os_membuf_t ble_hci_emspi_cmd_buf[
-        OS_MEMPOOL_SIZE(1, BLE_HCI_TRANS_CMD_SZ)
-];
-
-static struct os_mbuf_pool ble_hci_emspi_acl_mbuf_pool;
-static struct os_mempool_ext ble_hci_emspi_acl_pool;
-
-/*
- * The MBUF payload size must accommodate the HCI data header size plus the
- * maximum ACL data packet length. The ACL block size is the size of the
- * mbufs we will allocate.
- */
-#define ACL_BLOCK_SIZE  OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) \
-                                 + BLE_MBUF_MEMBLOCK_OVERHEAD \
-                                 + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-
-static os_membuf_t ble_hci_emspi_acl_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                        ACL_BLOCK_SIZE)
-];
-
 /**
  * A packet to be sent over the EMSPI.  This can be a command, an event, or ACL
  * data.
@@ -124,8 +73,7 @@ STAILQ_HEAD(, ble_hci_emspi_pkt) ble_hci_emspi_tx_q;
 
 static struct os_mempool ble_hci_emspi_pkt_pool;
 static os_membuf_t ble_hci_emspi_pkt_buf[
-        OS_MEMPOOL_SIZE(BLE_HCI_EMSPI_PKT_EVT_COUNT + 1 +
-                        MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
+        OS_MEMPOOL_SIZE(1 + MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_HS_COUNT),
                         sizeof (struct ble_hci_emspi_pkt))
 ];
 
@@ -287,18 +235,6 @@ done:
 }
 
 /**
- * Allocates a buffer (mbuf) for ACL operation.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-static struct os_mbuf *
-ble_hci_trans_acl_buf_alloc(void)
-{
-    return os_mbuf_get_pkthdr(&ble_hci_emspi_acl_mbuf_pool, 0);
-}
-
-/**
  * Transmits an ACL data packet to the controller.  The caller relinquishes the
  * specified mbuf, regardless of return status.
  */
@@ -344,7 +280,7 @@ ble_hci_emspi_cmdevt_tx(uint8_t *cmd_buf, uint8_t pkt_type)
 
     pkt = os_memblock_get(&ble_hci_emspi_pkt_pool);
     if (pkt == NULL) {
-        ble_hci_trans_buf_free(cmd_buf);
+        ble_transport_free(cmd_buf);
         return BLE_ERR_MEM_CAPACITY;
     }
 
@@ -449,7 +385,7 @@ ble_hci_emspi_tx_pkt(void)
     switch (pkt->type) {
     case BLE_HCI_EMSPI_PKT_CMD:
         rc = ble_hci_emspi_tx_cmd(pkt->data);
-        ble_hci_trans_buf_free(pkt->data);
+        ble_transport_free(pkt->data);
         break;
 
     case BLE_HCI_EMSPI_PKT_ACL:
@@ -477,7 +413,7 @@ ble_hci_emspi_rx_evt(void)
     /* XXX: we should not assert if host cannot allocate an event. Need
      * to determine what to do here.
      */
-    data = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    data = ble_transport_alloc_evt(0);
     assert(data != NULL);
 
     rc = ble_hci_emspi_rx(data, sizeof(struct ble_hci_ev));
@@ -493,8 +429,7 @@ ble_hci_emspi_rx_evt(void)
         }
     }
 
-    assert(ble_hci_emspi_rx_cmd_cb != NULL);
-    ble_hci_emspi_rx_cmd_cb(data, ble_hci_emspi_rx_cmd_arg);
+    rc = ble_transport_to_hs_evt(data);
     if (rc != 0) {
         goto err;
     }
@@ -502,7 +437,7 @@ ble_hci_emspi_rx_evt(void)
     return 0;
 
 err:
-    ble_hci_trans_buf_free(data);
+    ble_transport_free(data);
     return rc;
 }
 
@@ -516,7 +451,7 @@ ble_hci_emspi_rx_acl(void)
     /* XXX: we should not assert if host cannot allocate an mbuf. Need to
      * determine what to do here.
      */
-    om = ble_hci_trans_acl_buf_alloc();
+    om = ble_transport_alloc_acl_from_ll();
     assert(om != NULL);
 
     rc = ble_hci_emspi_rx(om->om_data, BLE_HCI_DATA_HDR_SZ);
@@ -525,7 +460,7 @@ ble_hci_emspi_rx_acl(void)
     }
 
     len = get_le16(om->om_data + 2);
-    if (len > MYNEWT_VAL(BLE_ACL_BUF_SIZE)) {
+    if (len > MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE)) {
         /*
          * Data portion cannot exceed data length of acl buffer. If it does
          * this is considered to be a loss of sync.
@@ -544,8 +479,7 @@ ble_hci_emspi_rx_acl(void)
     OS_MBUF_PKTLEN(om) = BLE_HCI_DATA_HDR_SZ + len;
     om->om_len = BLE_HCI_DATA_HDR_SZ + len;
 
-    assert(ble_hci_emspi_rx_cmd_cb != NULL);
-    rc = ble_hci_emspi_rx_acl_cb(om, ble_hci_emspi_rx_acl_arg);
+    rc = ble_transport_to_hs_acl(om);
     if (rc != 0) {
         goto err;
     }
@@ -587,18 +521,6 @@ ble_hci_emspi_rx_pkt(void)
 }
 
 static void
-ble_hci_emspi_set_rx_cbs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                        void *cmd_arg,
-                        ble_hci_trans_rx_acl_fn *acl_cb,
-                        void *acl_arg)
-{
-    ble_hci_emspi_rx_cmd_cb = cmd_cb;
-    ble_hci_emspi_rx_cmd_arg = cmd_arg;
-    ble_hci_emspi_rx_acl_cb = acl_cb;
-    ble_hci_emspi_rx_acl_arg = acl_arg;
-}
-
-static void
 ble_hci_emspi_free_pkt(uint8_t type, uint8_t *cmdevt, struct os_mbuf *acl)
 {
     switch (type) {
@@ -607,7 +529,7 @@ ble_hci_emspi_free_pkt(uint8_t type, uint8_t *cmdevt, struct os_mbuf *acl)
 
     case BLE_HCI_EMSPI_PKT_CMD:
     case BLE_HCI_EMSPI_PKT_EVT:
-        ble_hci_trans_buf_free(cmdevt);
+        ble_transport_free(cmdevt);
         break;
 
     case BLE_HCI_EMSPI_PKT_ACL:
@@ -621,24 +543,6 @@ ble_hci_emspi_free_pkt(uint8_t type, uint8_t *cmdevt, struct os_mbuf *acl)
 }
 
 /**
- * Unsupported.  This is a host-only transport.
- */
-int
-ble_hci_trans_ll_evt_tx(uint8_t *cmd)
-{
-    return BLE_ERR_UNSUPPORTED;
-}
-
-/**
- * Unsupported.  This is a host-only transport.
- */
-int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
-{
-    return BLE_ERR_UNSUPPORTED;
-}
-
-/**
  * Sends an HCI command from the host to the controller.
  *
  * @param cmd                   The HCI command to send.  This buffer must be
@@ -674,134 +578,6 @@ ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
 }
 
 /**
- * Configures the HCI transport to call the specified callback upon receiving
- * HCI packets from the controller.  This function should only be called by by
- * host.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_emspi_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
-}
-
-/**
- * Configures the HCI transport to operate with a host.  The transport will
- * execute specified callbacks upon receiving HCI packets from the controller.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    /* Unsupported. */
-    assert(0);
-}
-
-/**
- * Allocates a flat buffer of the specified type.
- *
- * @param type                  The type of buffer to allocate; one of the
- *                                  BLE_HCI_TRANS_BUF_[...] constants.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        buf = os_memblock_get(&ble_hci_emspi_cmd_pool);
-        break;
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_emspi_evt_hi_pool);
-        if (buf == NULL) {
-            /* If no high-priority event buffers remain, try to grab a
-             * low-priority one.
-             */
-            buf = os_memblock_get(&ble_hci_emspi_evt_lo_pool);
-        }
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&ble_hci_emspi_evt_lo_pool);
-        break;
-
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-/**
- * Frees the specified flat buffer.  The buffer must have been allocated via
- * ble_hci_trans_buf_alloc().
- *
- * @param buf                   The buffer to free.
- */
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    if (buf != NULL) {
-        if (os_memblock_from(&ble_hci_emspi_evt_hi_pool, buf)) {
-            rc = os_memblock_put(&ble_hci_emspi_evt_hi_pool, buf);
-            assert(rc == 0);
-        } else if (os_memblock_from(&ble_hci_emspi_evt_lo_pool, buf)) {
-            rc = os_memblock_put(&ble_hci_emspi_evt_lo_pool, buf);
-            assert(rc == 0);
-        } else {
-            assert(os_memblock_from(&ble_hci_emspi_cmd_pool, buf));
-            rc = os_memblock_put(&ble_hci_emspi_cmd_pool, buf);
-            assert(rc == 0);
-        }
-    }
-}
-
-/**
- * Configures a callback to get executed whenever an ACL data packet is freed.
- * The function is called in lieu of actually freeing the packet.
- *
- * @param cb                    The callback to configure.
- *
- * @return                      0 on success.
- */
-int
-ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
-{
-    ble_hci_emspi_acl_pool.mpe_put_cb = cb;
-    ble_hci_emspi_acl_pool.mpe_put_arg = arg;
-    return 0;
-}
-
-/**
  * Resets the HCI UART transport to a clean state.  Frees all buffers and
  * reconfigures the UART.
  *
@@ -875,69 +651,22 @@ ble_hci_emspi_init_hw(void)
     hal_gpio_write(MYNEWT_VAL(BLE_HCI_EMSPI_RESET_PIN), 1);
 }
 
-/**
- * Initializes the UART HCI transport module.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
 void
-ble_hci_emspi_init(void)
+ble_transport_ll_init(void)
 {
     int rc;
 
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
-    rc = os_mempool_ext_init(&ble_hci_emspi_acl_pool,
-                             MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                             ACL_BLOCK_SIZE,
-                             ble_hci_emspi_acl_buf,
-                             "ble_hci_emspi_acl_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&ble_hci_emspi_acl_mbuf_pool,
-                           &ble_hci_emspi_acl_pool.mpe_mp,
-                           ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    /*
-     * Create memory pool of HCI command buffers. NOTE: we currently dont
-     * allow this to be configured. The controller will only allow one
-     * outstanding command. We decided to keep this a pool in case we allow
-     * allow the controller to handle more than one outstanding command.
-     */
-    rc = os_mempool_init(&ble_hci_emspi_cmd_pool,
-                         1,
-                         BLE_HCI_TRANS_CMD_SZ,
-                         ble_hci_emspi_cmd_buf,
-                         "ble_hci_emspi_cmd_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_emspi_evt_hi_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_emspi_evt_hi_buf,
-                         "ble_hci_emspi_evt_hi_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_emspi_evt_lo_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_emspi_evt_lo_buf,
-                         "ble_hci_emspi_evt_lo_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
     /*
      * Create memory pool of packet list nodes. NOTE: the number of these
-     * buffers should be, at least, the total number of event buffers (hi
-     * and lo), the number of command buffers (currently 1) and the total
-     * number of buffers that the controller could possibly hand to the host.
+     * buffers should be, at least, the number of command buffers (currently 1)
+     * and the total number of buffers that the controller could possibly hand
+     * to the host.
      */
-    rc = os_mempool_init(&ble_hci_emspi_pkt_pool,
-                         BLE_HCI_EMSPI_PKT_EVT_COUNT + 1 +
-                         MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
+    rc = os_mempool_init(&ble_hci_emspi_pkt_pool, 1 +
+                         MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_HS_COUNT),
                          sizeof (struct ble_hci_emspi_pkt),
                          ble_hci_emspi_pkt_buf,
                          "ble_hci_emspi_pkt_pool");
@@ -955,3 +684,15 @@ ble_hci_emspi_init(void)
                       MYNEWT_VAL(BLE_HCI_EMSPI_STACK_SIZE));
     SYSINIT_PANIC_ASSERT(rc == 0);
 }
+
+int
+ble_transport_to_ll_cmd(void *buf)
+{
+    return ble_hci_emspi_cmdevt_tx(buf, BLE_HCI_EMSPI_PKT_CMD);
+}
+
+int
+ble_transport_to_ll_acl(struct os_mbuf *om)
+{
+    return ble_hci_emspi_acl_tx(om);
+}
\ No newline at end of file
diff --git a/nimble/transport/emspi/syscfg.yml b/nimble/transport/emspi/syscfg.yml
index 5011754..05e6e14 100644
--- a/nimble/transport/emspi/syscfg.yml
+++ b/nimble/transport/emspi/syscfg.yml
@@ -72,13 +72,3 @@ syscfg.defs:
         description: >
             Sysinit stage for the EMSPI BLE transport.
         value: 100
-
-syscfg.vals.'!BLE_HCI_BRIDGE && BLE_EXT_ADV':
-    BLE_HCI_EVT_BUF_SIZE: 257
-
-syscfg.vals.'!BLE_HCI_BRIDGE && !BLE_EXT_ADV':
-    BLE_HCI_EVT_HI_BUF_COUNT: 2
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_ACL_BUF_COUNT: 4
-    BLE_ACL_BUF_SIZE: 255
diff --git a/nimble/transport/pkg.yml b/nimble/transport/pkg.yml
index e5dad56..bedcb16 100644
--- a/nimble/transport/pkg.yml
+++ b/nimble/transport/pkg.yml
@@ -32,6 +32,8 @@ pkg.deps.'BLE_TRANSPORT_HS == "native"':
     - nimble/host
 pkg.deps.'BLE_TRANSPORT_LL == "native"':
     - nimble/controller
+pkg.deps.'BLE_TRANSPORT_LL == "emspi"':
+    - nimble/transport/emspi
 pkg.deps.'BLE_TRANSPORT_HS == "dialog_cmac" || BLE_TRANSPORT_LL == "dialog_cmac"':
     - nimble/transport/dialog_cmac
 pkg.deps.'BLE_TRANSPORT_HS == "nrf5340" || BLE_TRANSPORT_LL == "nrf5340"':
diff --git a/nimble/transport/syscfg.yml b/nimble/transport/syscfg.yml
index cb9e07e..5f61a01 100644
--- a/nimble/transport/syscfg.yml
+++ b/nimble/transport/syscfg.yml
@@ -40,6 +40,7 @@ syscfg.defs:
         value: native
         choices:
             - native
+            - emspi
             - dialog_cmac
             - nrf5340
             - socket

[mynewt-nimble] 09/22: nimble/transport: Update USB transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 10958b3ec9ba6feeea5a68cc1dac282eac446ddd
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:06:15 2022 +0100

    nimble/transport: Update USB transport
---
 nimble/transport/nrf5340/syscfg.yml    |  38 ------
 nimble/transport/usb/pkg.yml           |   3 -
 nimble/transport/usb/src/ble_hci_usb.c | 218 ++++++---------------------------
 nimble/transport/usb/syscfg.yml        |  18 ---
 4 files changed, 35 insertions(+), 242 deletions(-)

diff --git a/nimble/transport/nrf5340/syscfg.yml b/nimble/transport/nrf5340/syscfg.yml
deleted file mode 100644
index a12e0c3..0000000
--- a/nimble/transport/nrf5340/syscfg.yml
+++ /dev/null
@@ -1,38 +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.
-#
-
-syscfg.defs:
-    BLE_TRANS_NRF5340_SYSINIT_STAGE:
-        description: >
-            Sysinit stage for the RAM BLE transport.
-        value: 100
-
-syscfg.vals.'!BLE_HCI_BRIDGE:
-    BLE_HCI_EVT_HI_BUF_COUNT: 2
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_ACL_BUF_COUNT: 4
-    BLE_ACL_BUF_SIZE: 255
-
-syscfg.vals.'!BLE_HCI_BRIDGE && !BLE_EXT_ADV':
-    BLE_HCI_EVT_BUF_SIZE: 70
-
-syscfg.vals.'!BLE_HCI_BRIDGE && BLE_EXT_ADV':
-    BLE_HCI_EVT_BUF_SIZE: 257
-    
-syscfg.restrictions:
-    - '!(BLE_HOST && BLE_CONTROLLER)'
diff --git a/nimble/transport/usb/pkg.yml b/nimble/transport/usb/pkg.yml
index c4c314c..199afe6 100644
--- a/nimble/transport/usb/pkg.yml
+++ b/nimble/transport/usb/pkg.yml
@@ -35,6 +35,3 @@ pkg.deps:
 
 pkg.apis:
     - ble_transport
-
-pkg.init:
-    ble_hci_usb_init: 'MYNEWT_VAL(BLE_TRANS_USB_SYSINIT_STAGE)'
diff --git a/nimble/transport/usb/src/ble_hci_usb.c b/nimble/transport/usb/src/ble_hci_usb.c
index 8160536..6518cd9 100644
--- a/nimble/transport/usb/src/ble_hci_usb.c
+++ b/nimble/transport/usb/src/ble_hci_usb.c
@@ -25,78 +25,20 @@
 #include "mem/mem.h"
 
 #include "nimble/ble.h"
-#include "nimble/ble_hci_trans.h"
 #include "nimble/hci_common.h"
+#include "nimble/transport.h"
 
 #include <class/bth/bth_device.h>
 
-/*
- * The MBUF payload size must accommodate the HCI data header size plus the
- * maximum ACL data packet length. The ACL block size is the size of the
- * mbufs we will allocate.
- */
-#define ACL_BLOCK_SIZE  OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) \
-                                 + BLE_MBUF_MEMBLOCK_OVERHEAD \
-                                 + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-
-struct usb_ble_hci_pool_cmd {
-    uint8_t cmd[BLE_HCI_TRANS_CMD_SZ];
-    bool allocated;
-};
-
-/* (Pseudo)pool for HCI commands */
-static struct usb_ble_hci_pool_cmd usb_ble_hci_pool_cmd;
-
-static ble_hci_trans_rx_cmd_fn *ble_hci_usb_rx_cmd_ll_cb;
-static void *ble_hci_usb_rx_cmd_ll_arg;
-
-static ble_hci_trans_rx_acl_fn *ble_hci_usb_rx_acl_ll_cb;
-static void *ble_hci_usb_rx_acl_ll_arg;
-
-static struct os_mempool ble_hci_usb_evt_hi_pool;
-static os_membuf_t ble_hci_usb_evt_hi_buf[
-    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_usb_evt_lo_pool;
-static os_membuf_t ble_hci_usb_evt_lo_buf[
-    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static uint8_t ble_hci_pool_acl_mempool_buf[
-    OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                     ACL_BLOCK_SIZE)];
-static struct os_mempool ble_hci_pool_acl_mempool;
-static struct os_mbuf_pool ble_hci_pool_acl_mbuf_pool;
-
 static struct os_mbuf *incoming_acl_data;
 
-static struct os_mbuf *
-ble_hci_trans_acl_buf_alloc(void)
-{
-    struct os_mbuf *m;
-
-    m = os_mbuf_get_pkthdr(&ble_hci_pool_acl_mbuf_pool,
-                           sizeof(struct ble_mbuf_hdr));
-    return m;
-}
+#define TX_Q_SIZE   (MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT) + \
+                     MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT) + \
+                     MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT))
 
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_usb_rx_cmd_ll_cb = cmd_cb;
-    ble_hci_usb_rx_cmd_ll_arg = cmd_arg;
-    ble_hci_usb_rx_acl_ll_cb = acl_cb;
-    ble_hci_usb_rx_acl_ll_arg = acl_arg;
-}
 
 #define BLE_HCI_USB_EVT_COUNT  \
-    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
+    (MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT))
 
 /**
  * A packet to be sent over the USB.  This can be a command, an event, or ACL
@@ -107,11 +49,9 @@ struct ble_hci_pkt {
     void *data;
 };
 
-static struct os_mempool ble_hci_pkt_pool;
-static os_membuf_t ble_hci_pkt_buf[
-    OS_MEMPOOL_SIZE(BLE_HCI_USB_EVT_COUNT + 1 +
-                    MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
-                    sizeof(struct ble_hci_pkt))];
+static struct os_mempool pool_tx_q;
+static os_membuf_t pool_tx_q_buf[ OS_MEMPOOL_SIZE(TX_Q_SIZE,
+                                                  sizeof(struct ble_hci_pkt)) ];
 
 struct tx_queue {
     STAILQ_HEAD(, ble_hci_pkt) queue;
@@ -151,7 +91,7 @@ tud_bt_acl_data_sent_cb(uint16_t sent_bytes)
         STAILQ_REMOVE_HEAD(&ble_hci_tx_acl_queue.queue, next);
         next_acl = STAILQ_FIRST(&ble_hci_tx_acl_queue.queue);
         OS_EXIT_CRITICAL(sr);
-        os_memblock_put(&ble_hci_pkt_pool, curr_acl);
+        os_memblock_put(&pool_tx_q, curr_acl);
         if (next_acl != NULL) {
             om = next_acl->data;
         }
@@ -178,13 +118,13 @@ tud_bt_event_sent_cb(uint16_t sent_bytes)
 
     assert(hci_ev != NULL && hci_ev[1] + sizeof(struct ble_hci_ev) == sent_bytes);
 
-    ble_hci_trans_buf_free(hci_ev);
+    ble_transport_free(hci_ev);
 
     OS_ENTER_CRITICAL(sr);
     STAILQ_REMOVE_HEAD(&ble_hci_tx_evt_queue.queue, next);
     next_evt = STAILQ_FIRST(&ble_hci_tx_evt_queue.queue);
     OS_EXIT_CRITICAL(sr);
-    os_memblock_put(&ble_hci_pkt_pool, curr_evt);
+    os_memblock_put(&pool_tx_q, curr_evt);
 
     if (next_evt != NULL) {
         hci_ev = next_evt->data;
@@ -201,10 +141,11 @@ tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len)
     int rc;
 
     if (om == NULL) {
-        om = ble_hci_trans_acl_buf_alloc();
+        om = ble_transport_alloc_acl_from_hs();
         assert(om != NULL);
     }
-    assert(om->om_len + data_len <= MYNEWT_VAL(BLE_ACL_BUF_SIZE) + BLE_HCI_DATA_HDR_SZ);
+    assert(om->om_len + data_len <= MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE) +
+                                    BLE_HCI_DATA_HDR_SZ);
 
     os_mbuf_append(om, acl_data, data_len);
     incoming_acl_data = om;
@@ -213,7 +154,7 @@ tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len)
         len = data[2] + (data[3] << 8) + BLE_HCI_DATA_HDR_SZ;
         if (incoming_acl_data->om_len >= len) {
             incoming_acl_data = NULL;
-            rc = ble_hci_usb_rx_acl_ll_cb(om, ble_hci_usb_rx_acl_ll_arg);
+            rc = ble_transport_to_ll_acl(om);
             (void)rc;
         }
     }
@@ -225,17 +166,14 @@ tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len)
     uint8_t *buf;
     int rc = -1;
 
-    assert(ble_hci_usb_rx_cmd_ll_cb);
-    if (ble_hci_usb_rx_cmd_ll_cb) {
-        buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-        assert(buf != NULL);
-        memcpy(buf, hci_cmd, min(cmd_len, BLE_HCI_TRANS_CMD_SZ));
+    buf = ble_transport_alloc_cmd();
+    assert(buf != NULL);
+    memcpy(buf, hci_cmd, min(cmd_len, 258));
 
-        rc = ble_hci_usb_rx_cmd_ll_cb(buf, ble_hci_usb_rx_cmd_ll_arg);
-    }
+    rc = ble_transport_to_ll_cmd(buf);
 
     if (rc != 0) {
-        ble_hci_trans_buf_free(buf);
+        ble_transport_free(buf);
     }
 }
 
@@ -252,7 +190,7 @@ ble_hci_trans_ll_tx(struct tx_queue *queue, struct os_mbuf *om)
         return 0;
     }
 
-    pkt = os_memblock_get(&ble_hci_pkt_pool);
+    pkt = os_memblock_get(&pool_tx_q);
     if (pkt == NULL) {
         os_mbuf_free_chain(om);
         return BLE_ERR_MEM_CAPACITY;
@@ -270,29 +208,24 @@ ble_hci_trans_ll_tx(struct tx_queue *queue, struct os_mbuf *om)
     return 0;
 }
 
-int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
-{
-    return ble_hci_trans_ll_tx(&ble_hci_tx_acl_queue, om);
-}
-
-int
-ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
+static int
+ble_hci_trans_ll_evt_tx(void *buf)
 {
     struct ble_hci_pkt *pkt;
+    uint8_t *hci_ev = buf;
     os_sr_t sr;
     bool first;
 
     assert(hci_ev != NULL);
 
     if (!tud_ready()) {
-        ble_hci_trans_buf_free(hci_ev);
+        ble_transport_free(hci_ev);
         return 0;
     }
 
-    pkt = os_memblock_get(&ble_hci_pkt_pool);
+    pkt = os_memblock_get(&pool_tx_q);
     if (pkt == NULL) {
-        ble_hci_trans_buf_free(hci_ev);
+        ble_transport_free(hci_ev);
         return BLE_ERR_MEM_CAPACITY;
     }
 
@@ -308,108 +241,27 @@ ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
     return 0;
 }
 
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        assert(!usb_ble_hci_pool_cmd.allocated);
-        usb_ble_hci_pool_cmd.allocated = 1;
-        buf = usb_ble_hci_pool_cmd.cmd;
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_usb_evt_hi_pool);
-        if (buf == NULL) {
-            /* If no high-priority event buffers remain, try to grab a
-             * low-priority one.
-             */
-            buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
-        }
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&ble_hci_usb_evt_lo_pool);
-        break;
-
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-void
-ble_hci_trans_buf_free(uint8_t *buf)
+int
+ble_transport_to_hs_acl(struct os_mbuf *om)
 {
-    int rc;
-
-    /* XXX: this may look a bit odd, but the controller uses the command
-     * buffer to send back the command complete/status as an immediate
-     * response to the command. This was done to insure that the controller
-     * could always send back one of these events when a command was received.
-     * Thus, we check to see which pool the buffer came from so we can free
-     * it to the appropriate pool
-     */
-    if (os_memblock_from(&ble_hci_usb_evt_hi_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_usb_evt_hi_pool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_usb_evt_lo_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_usb_evt_lo_pool, buf);
-        assert(rc == 0);
-    } else {
-        assert(usb_ble_hci_pool_cmd.allocated);
-        usb_ble_hci_pool_cmd.allocated = 0;
-    }
-    (void)rc;
+    return ble_hci_trans_ll_tx(&ble_hci_tx_acl_queue, om);
 }
 
 int
-ble_hci_trans_reset(void)
+ble_transport_to_hs_evt(void *buf)
 {
-    return 0;
+    return ble_hci_trans_ll_evt_tx(buf);
 }
 
 void
-ble_hci_usb_init(void)
+ble_transport_hs_init(void)
 {
     int rc;
 
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
-    rc = mem_init_mbuf_pool(ble_hci_pool_acl_mempool_buf, &ble_hci_pool_acl_mempool, &ble_hci_pool_acl_mbuf_pool,
-                            MYNEWT_VAL(BLE_ACL_BUF_COUNT), ACL_BLOCK_SIZE, "ble_hci_acl");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_usb_evt_hi_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_usb_evt_hi_buf,
-                         "ble_hci_usb_evt_hi_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_usb_evt_lo_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_usb_evt_lo_buf,
-                         "ble_hci_usb_evt_lo_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    /*
-     * Create memory pool of packet list nodes. NOTE: the number of these
-     * buffers should be, at least, the total number of event buffers (hi
-     * and lo), the number of command buffers (currently 1) and the total
-     * number of buffers that the controller could possibly hand to the host.
-     */
-    rc = os_mempool_init(&ble_hci_pkt_pool,
-                         BLE_HCI_USB_EVT_COUNT + 1 +
-                         MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
-                         sizeof (struct ble_hci_pkt),
-                         ble_hci_pkt_buf,
-                         "ble_hci_usb_pkt_pool");
+    rc = os_mempool_init(&pool_tx_q, TX_Q_SIZE, sizeof(struct ble_hci_pkt),
+                         pool_tx_q_buf, "ble_hci_usb_tx_q");
     SYSINIT_PANIC_ASSERT(rc == 0);
 }
diff --git a/nimble/transport/usb/syscfg.yml b/nimble/transport/usb/syscfg.yml
index 38effde..17ef649 100644
--- a/nimble/transport/usb/syscfg.yml
+++ b/nimble/transport/usb/syscfg.yml
@@ -26,21 +26,3 @@ syscfg.defs:
             number of ACL buffers that the controller tells the host it
             has.
         value: 12
-
-    BLE_TRANS_USB_SYSINIT_STAGE:
-        description: >
-            Sysinit stage for the USB BLE transport.
-        value: 500
-
-syscfg.vals.BLE_EXT_ADV:
-    BLE_HCI_EVT_BUF_SIZE: 257
-
-syscfg.vals:
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_HCI_EVT_HI_BUF_COUNT: 8
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_ACL_BUF_COUNT: 12
-    BLE_ACL_BUF_SIZE: 255
-
-syscfg.restrictions:
-    - '!BLE_HOST'

[mynewt-nimble] 14/22: nimble/transport: Add internal flow control

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit b44ec408820cb18c9d1ff4b6efac84322016d279
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Wed Mar 9 22:53:20 2022 +0100

    nimble/transport: Add internal flow control
    
    This adds support for internal flow control that can be implemented by
    transports that work on multi-core systems (e.g. nRF5340).
---
 nimble/controller/src/ble_ll_conn.c         | 14 ++++++++++++
 nimble/transport/include/nimble/transport.h |  6 ++++++
 nimble/transport/nrf5340/syscfg.yml         | 20 +++++++++++++++++
 nimble/transport/src/transport.c            | 33 ++++++++++++++++-------------
 4 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 138f928..3be8f66 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -3269,6 +3269,10 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
 
     /* Free buffer */
 conn_rx_data_pdu_end:
+#if MYNEWT_VAL(BLE_TRANSPORT_INT_FLOW_CTL)
+    ble_transport_int_flow_ctl_put();
+#endif
+
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
     /* Need to give credit back if we allocated one for this PDU */
     if (hdr->rxinfo.flags & BLE_MBUF_HDR_F_CONN_CREDIT) {
@@ -3329,6 +3333,16 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
         alloc_rxpdu = false;
     }
 
+#if MYNEWT_VAL(BLE_TRANSPORT_INT_FLOW_CTL)
+    /* Do not alloc PDU if there are no free buffers in transport. We'll nak
+     * this PDU in LL.
+     */
+    if (alloc_rxpdu && BLE_LL_LLID_IS_DATA(hdr_byte) && (rx_pyld_len > 0) &&
+        !ble_transport_int_flow_ctl_get()) {
+        alloc_rxpdu = false;
+    }
+#endif
+
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
     /*
      * If flow control is enabled, we need to have credit available for each
diff --git a/nimble/transport/include/nimble/transport.h b/nimble/transport/include/nimble/transport.h
index 98dba30..7149d87 100644
--- a/nimble/transport/include/nimble/transport.h
+++ b/nimble/transport/include/nimble/transport.h
@@ -48,6 +48,12 @@ void ble_transport_free(void *buf);
 /* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
 int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
 
+#if MYNEWT_VAL(BLE_TRANSPORT_INT_FLOW_CTL)
+/* To be implemented if transport supports internal flow control between cores */
+extern int ble_transport_int_flow_ctl_get(void);
+extern void ble_transport_int_flow_ctl_put(void);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/nimble/transport/nrf5340/syscfg.yml b/nimble/transport/nrf5340/syscfg.yml
new file mode 100644
index 0000000..e8334f2
--- /dev/null
+++ b/nimble/transport/nrf5340/syscfg.yml
@@ -0,0 +1,20 @@
+# 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.
+#
+
+syscfg.defs:
+    BLE_TRANSPORT_INT_FLOW_CTL: 1
diff --git a/nimble/transport/src/transport.c b/nimble/transport/src/transport.c
index 7c868f1..1eea5ad 100644
--- a/nimble/transport/src/transport.c
+++ b/nimble/transport/src/transport.c
@@ -152,30 +152,33 @@ ble_transport_acl_put(struct os_mempool_ext *mpe, void *data, void *arg)
 {
     struct os_mbuf *om;
     struct os_mbuf_pkthdr *pkthdr;
+    bool do_put;
+    bool from_ll;
     os_error_t err;
 
     om = data;
     pkthdr = OS_MBUF_PKTHDR(om);
 
-    switch (pkthdr->omp_flags & OMP_FLAG_FROM_MASK) {
-    case OMP_FLAG_FROM_LL:
-        if (transport_put_acl_from_ll_cb) {
-            return transport_put_acl_from_ll_cb(mpe, data, arg);
-        }
-        break;
-    case OMP_FLAG_FROM_HS:
-        break;
-    default:
-        assert(0);
-        break;
+    do_put = true;
+    from_ll = (pkthdr->omp_flags & OMP_FLAG_FROM_MASK) == OMP_FLAG_FROM_LL;
+    err = 0;
+
+    if (from_ll && transport_put_acl_from_ll_cb) {
+        err = transport_put_acl_from_ll_cb(mpe, data, arg);
+        do_put = false;
     }
 
-    err = os_memblock_put_from_cb(&mpe->mpe_mp, data);
-    if (err) {
-        return err;
+    if (do_put) {
+        err = os_memblock_put_from_cb(&mpe->mpe_mp, data);
     }
 
-    return 0;
+#if MYNEWT_VAL(BLE_TRANSPORT_INT_FLOW_CTL)
+    if (from_ll && !err) {
+        ble_transport_int_flow_ctl_put();
+    }
+#endif
+
+    return err;
 }
 
 void

[mynewt-nimble] 05/22: nimble/host: Update to new transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 0cb011790f5507676f424e6679cd522a96f42c3e
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Mar 4 15:47:34 2022 +0100

    nimble/host: Update to new transport
---
 nimble/host/pkg.yml               |  4 +---
 nimble/host/src/ble_hs.c          | 40 +++++++++++++++++++++++----------------
 nimble/host/src/ble_hs_flow.c     | 17 +++++++----------
 nimble/host/src/ble_hs_hci.c      |  8 +++-----
 nimble/host/src/ble_hs_hci_cmd.c  |  5 ++---
 nimble/host/src/ble_hs_hci_evt.c  |  5 ++---
 nimble/host/src/ble_hs_hci_priv.h |  2 +-
 nimble/host/syscfg.yml            |  3 +++
 8 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/nimble/host/pkg.yml b/nimble/host/pkg.yml
index a063a0b..b289792 100644
--- a/nimble/host/pkg.yml
+++ b/nimble/host/pkg.yml
@@ -30,6 +30,7 @@ pkg.deps:
     - "@apache-mynewt-core/sys/log/modlog"
     - "@apache-mynewt-core/util/mem"
     - nimble
+    - nimble/transport
 
 pkg.deps.BLE_SM_LEGACY:
     - "@apache-mynewt-core/crypto/tinycrypt"
@@ -48,8 +49,5 @@ pkg.req_apis:
     - console
     - stats
 
-pkg.init:
-    ble_hs_init: 'MYNEWT_VAL(BLE_HS_SYSINIT_STAGE)'
-
 pkg.down.BLE_HS_STOP_ON_SHUTDOWN:
     ble_hs_shutdown: 200
diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c
index 5e5c644..ba601b6 100644
--- a/nimble/host/src/ble_hs.c
+++ b/nimble/host/src/ble_hs.c
@@ -23,7 +23,6 @@
 #include "sysinit/sysinit.h"
 #include "syscfg/syscfg.h"
 #include "stats/stats.h"
-#include "nimble/ble_hci_trans.h"
 #include "host/ble_hs.h"
 #include "ble_hs_priv.h"
 #include "ble_monitor_priv.h"
@@ -32,9 +31,7 @@
 #include "nimble/nimble_port.h"
 #endif
 
-#define BLE_HS_HCI_EVT_COUNT                    \
-    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) +     \
-     MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
+#define BLE_HS_HCI_EVT_COUNT    MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT)
 
 static void ble_hs_event_rx_hci_ev(struct ble_npl_event *ev);
 #if NIMBLE_BLE_CONNECT
@@ -370,12 +367,6 @@ ble_hs_reset(void)
 
     ble_hs_sync_state = 0;
 
-    /* Reset transport.  Assume success; there is nothing we can do in case of
-     * failure.  If the transport failed to reset, the host will reset itself
-     * again when it fails to sync with the controller.
-     */
-    (void)ble_hci_trans_reset();
-
     ble_hs_clear_rx_queue();
 
     /* Clear adverising and scanning states. */
@@ -499,7 +490,7 @@ ble_hs_sched_start(void)
 static void
 ble_hs_event_rx_hci_ev(struct ble_npl_event *ev)
 {
-    const struct ble_hci_ev *hci_ev;
+    struct ble_hci_ev *hci_ev;
     int rc;
 
     hci_ev = ble_npl_event_get_arg(ev);
@@ -573,7 +564,7 @@ ble_hs_enqueue_hci_event(uint8_t *hci_evt)
 
     ev = os_memblock_get(&ble_hs_hci_ev_pool);
     if (ev == NULL) {
-        ble_hci_trans_buf_free(hci_evt);
+        ble_transport_free(hci_evt);
     } else {
         ble_npl_event_init(ev, ble_hs_event_rx_hci_ev, hci_evt);
         ble_npl_eventq_put(ble_hs_evq, ev);
@@ -709,7 +700,7 @@ ble_hs_tx_data(struct os_mbuf *om)
     ble_monitor_send_om(BLE_MONITOR_OPCODE_ACL_TX_PKT, om);
 #endif
 
-    return ble_hci_trans_hs_acl_tx(om);
+    return ble_transport_to_ll_acl(om);
 }
 
 void
@@ -793,9 +784,6 @@ ble_hs_init(void)
     ble_hs_evq_set(nimble_port_get_dflt_eventq());
 #endif
 
-    /* Configure the HCI transport to communicate with a host. */
-    ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL);
-
 #if BLE_MONITOR
     rc = ble_monitor_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
@@ -818,3 +806,23 @@ ble_hs_init(void)
     ble_monitor_new_index(0, (uint8_t[6]){ }, "nimble0");
 #endif
 }
+
+/* Transport APIs for HS side */
+
+int
+ble_transport_to_hs_evt(void *buf)
+{
+    return ble_hs_hci_rx_evt(buf, NULL);
+}
+
+int
+ble_transport_to_hs_acl(struct os_mbuf *om)
+{
+    return ble_hs_rx_data(om, NULL);
+}
+
+void
+ble_transport_hs_init(void)
+{
+    ble_hs_init();
+}
diff --git a/nimble/host/src/ble_hs_flow.c b/nimble/host/src/ble_hs_flow.c
index 1eabba9..acd754a 100644
--- a/nimble/host/src/ble_hs_flow.c
+++ b/nimble/host/src/ble_hs_flow.c
@@ -18,7 +18,6 @@
  */
 
 #include "syscfg/syscfg.h"
-#include "nimble/ble_hci_trans.h"
 #include "ble_hs_priv.h"
 
 #if MYNEWT_VAL(BLE_HS_FLOW_CTRL)
@@ -41,7 +40,7 @@ static ble_npl_event_fn ble_hs_flow_event_cb;
 static struct ble_npl_event ble_hs_flow_ev;
 
 /* Connection handle associated with each mbuf in ACL pool */
-static uint16_t ble_hs_flow_mbuf_conn_handle[ MYNEWT_VAL(BLE_ACL_BUF_COUNT) ];
+static uint16_t ble_hs_flow_mbuf_conn_handle[ MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT) ];
 
 static inline int
 ble_hs_flow_mbuf_index(const struct os_mbuf *om)
@@ -136,7 +135,7 @@ ble_hs_flow_inc_completed_pkts(struct ble_hs_conn *conn)
     conn->bhc_completed_pkts++;
     ble_hs_flow_num_completed_pkts++;
 
-    if (ble_hs_flow_num_completed_pkts > MYNEWT_VAL(BLE_ACL_BUF_COUNT)) {
+    if (ble_hs_flow_num_completed_pkts > MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT)) {
         ble_hs_sched_reset(BLE_HS_ECONTROLLER);
         return;
     }
@@ -144,7 +143,8 @@ ble_hs_flow_inc_completed_pkts(struct ble_hs_conn *conn)
     /* If the number of free buffers is at or below the configured threshold,
      * send an immediate number-of-copmleted-packets event.
      */
-    num_free = MYNEWT_VAL(BLE_ACL_BUF_COUNT) - ble_hs_flow_num_completed_pkts;
+    num_free = MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT) -
+               ble_hs_flow_num_completed_pkts;
     if (num_free <= MYNEWT_VAL(BLE_HS_FLOW_CTRL_THRESH)) {
         ble_npl_eventq_put(ble_hs_evq_get(), &ble_hs_flow_ev);
         ble_npl_callout_stop(&ble_hs_flow_timer);
@@ -230,16 +230,13 @@ ble_hs_flow_startup(void)
 #if MYNEWT_VAL(BLE_HS_FLOW_CTRL)
     struct ble_hci_cb_ctlr_to_host_fc_cp enable_cmd;
     struct ble_hci_cb_host_buf_size_cp buf_size_cmd = {
-            .acl_data_len = htole16(MYNEWT_VAL(BLE_ACL_BUF_SIZE)),
-            .acl_num = htole16(MYNEWT_VAL(BLE_ACL_BUF_COUNT)),
+            .acl_data_len = htole16(MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE)),
+            .acl_num = htole16(MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT)),
     };
     int rc;
 
     ble_npl_event_init(&ble_hs_flow_ev, ble_hs_flow_event_cb, NULL);
 
-    /* Assume failure. */
-    ble_hci_trans_set_acl_free_cb(NULL, NULL);
-
 #if MYNEWT_VAL(SELFTEST)
     ble_npl_callout_stop(&ble_hs_flow_timer);
 #endif
@@ -266,7 +263,7 @@ ble_hs_flow_startup(void)
 
     /* Flow control successfully enabled. */
     ble_hs_flow_num_completed_pkts = 0;
-    ble_hci_trans_set_acl_free_cb(ble_hs_flow_acl_free, NULL);
+    ble_transport_register_put_acl_from_ll_cb(ble_hs_flow_acl_free);
     ble_npl_callout_init(&ble_hs_flow_timer, ble_hs_evq_get(),
                          ble_hs_flow_event_cb, NULL);
 #endif
diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c
index 53d3647..2157610 100644
--- a/nimble/host/src/ble_hs_hci.c
+++ b/nimble/host/src/ble_hs_hci.c
@@ -22,7 +22,6 @@
 #include <stdio.h>
 #include "os/os.h"
 #include "mem/mem.h"
-#include "nimble/ble_hci_trans.h"
 #include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
 #include "ble_monitor_priv.h"
@@ -269,8 +268,7 @@ ble_hs_hci_wait_for_ack(void)
     if (ble_hs_hci_phony_ack_cb == NULL) {
         rc = BLE_HS_ETIMEOUT_HCI;
     } else {
-        ble_hs_hci_ack =
-            (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+        ble_hs_hci_ack = ble_transport_alloc_cmd();
         BLE_HS_DBG_ASSERT(ble_hs_hci_ack != NULL);
         rc = ble_hs_hci_phony_ack_cb((void *)ble_hs_hci_ack, 260);
     }
@@ -351,7 +349,7 @@ ble_hs_hci_cmd_tx(uint16_t opcode, const void *cmd, uint8_t cmd_len,
 
 done:
     if (ble_hs_hci_ack != NULL) {
-        ble_hci_trans_buf_free((uint8_t *) ble_hs_hci_ack);
+        ble_transport_free((uint8_t *) ble_hs_hci_ack);
         ble_hs_hci_ack = NULL;
     }
 
@@ -364,7 +362,7 @@ ble_hs_hci_rx_ack(uint8_t *ack_ev)
 {
     if (ble_npl_sem_get_count(&ble_hs_hci_sem) > 0) {
         /* This ack is unexpected; ignore it. */
-        ble_hci_trans_buf_free(ack_ev);
+        ble_transport_free(ack_ev);
         return;
     }
     BLE_HS_DBG_ASSERT(ble_hs_hci_ack == NULL);
diff --git a/nimble/host/src/ble_hs_hci_cmd.c b/nimble/host/src/ble_hs_hci_cmd.c
index a0fd1ce..33e1ae8 100644
--- a/nimble/host/src/ble_hs_hci_cmd.c
+++ b/nimble/host/src/ble_hs_hci_cmd.c
@@ -23,7 +23,6 @@
 #include <stdio.h>
 #include "os/os.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
 #include "ble_monitor_priv.h"
@@ -38,7 +37,7 @@ ble_hs_hci_cmd_transport(struct ble_hci_cmd *cmd)
                      cmd->length + sizeof(*cmd));
 #endif
 
-    rc = ble_hci_trans_hs_cmd_tx((uint8_t *) cmd);
+    rc = ble_transport_to_ll_cmd(cmd);
     switch (rc) {
     case 0:
         return 0;
@@ -57,7 +56,7 @@ ble_hs_hci_cmd_send(uint16_t opcode, uint8_t len, const void *cmddata)
     struct ble_hci_cmd *cmd;
     int rc;
 
-    cmd = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+    cmd = ble_transport_alloc_cmd();
     BLE_HS_DBG_ASSERT(cmd != NULL);
 
     cmd->opcode = htole16(opcode);
diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c
index 108ee64..3dba0bf 100644
--- a/nimble/host/src/ble_hs_hci_evt.c
+++ b/nimble/host/src/ble_hs_hci_evt.c
@@ -22,7 +22,6 @@
 #include <stdio.h>
 #include "os/os.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "host/ble_gap.h"
 #include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
@@ -795,7 +794,7 @@ ble_hs_hci_evt_le_phy_update_complete(uint8_t subevent, const void *data,
 #endif
 
 int
-ble_hs_hci_evt_process(const struct ble_hci_ev *ev)
+ble_hs_hci_evt_process(struct ble_hci_ev *ev)
 {
     const struct ble_hs_hci_evt_dispatch_entry *entry;
     int rc;
@@ -812,7 +811,7 @@ ble_hs_hci_evt_process(const struct ble_hci_ev *ev)
         rc = entry->cb(ev->opcode, ev->data, ev->length);
     }
 
-    ble_hci_trans_buf_free((uint8_t *) ev);
+    ble_transport_free(ev);
 
     return rc;
 }
diff --git a/nimble/host/src/ble_hs_hci_priv.h b/nimble/host/src/ble_hs_hci_priv.h
index 11e544f..47f3200 100644
--- a/nimble/host/src/ble_hs_hci_priv.h
+++ b/nimble/host/src/ble_hs_hci_priv.h
@@ -105,7 +105,7 @@ int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
                                  uint16_t tx_time);
 int ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
                                    struct hci_data_hdr *out_hdr);
-int ble_hs_hci_evt_process(const struct ble_hci_ev *ev);
+int ble_hs_hci_evt_process(struct ble_hci_ev *ev);
 
 int ble_hs_hci_cmd_send_buf(uint16_t opcode, const void *buf, uint8_t buf_len);
 int ble_hs_hci_set_buf_sz(uint16_t pktlen, uint16_t max_pkts);
diff --git a/nimble/host/syscfg.yml b/nimble/host/syscfg.yml
index c814ba5..5f67c44 100644
--- a/nimble/host/syscfg.yml
+++ b/nimble/host/syscfg.yml
@@ -497,3 +497,6 @@ syscfg.logs:
 
 syscfg.vals.BLE_MESH:
     BLE_SM_SC: 1
+
+syscfg.restrictions:
+    - BLE_TRANSPORT_HS == "native"

[mynewt-nimble] 22/22: targets: Update to new transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit f1a5658408eed1a78f8e17a83c6e44e8d25686fd
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 17 10:14:22 2022 +0100

    targets: Update to new transport
---
 targets/dialog_cmac/syscfg.yml                | 2 +-
 targets/nordic_pca10056-blehci-usb/syscfg.yml | 2 +-
 targets/nordic_pca10095_net-blehci/syscfg.yml | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/targets/dialog_cmac/syscfg.yml b/targets/dialog_cmac/syscfg.yml
index 3a8895d..71a109a 100644
--- a/targets/dialog_cmac/syscfg.yml
+++ b/targets/dialog_cmac/syscfg.yml
@@ -22,7 +22,7 @@ syscfg.vals:
     MCU_SLP_TIMER: 1
     MCU_SLP_TIMER_32K_ONLY: 1
 
-    BLE_HCI_TRANSPORT: dialog_cmac
+    BLE_TRANSPORT_HS: dialog_cmac
 
     # LL recommended settings (decreasing timing values is not recommended)
     BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL: 1
diff --git a/targets/nordic_pca10056-blehci-usb/syscfg.yml b/targets/nordic_pca10056-blehci-usb/syscfg.yml
index e664792..f2579c1 100644
--- a/targets/nordic_pca10056-blehci-usb/syscfg.yml
+++ b/targets/nordic_pca10056-blehci-usb/syscfg.yml
@@ -1,5 +1,5 @@
 syscfg.vals:
-    BLE_HCI_TRANSPORT: usb
+    BLE_TRANSPORT_HS: usb
     USBD_BTH: 1
 
     USBD_PID: 0xC01A
diff --git a/targets/nordic_pca10095_net-blehci/syscfg.yml b/targets/nordic_pca10095_net-blehci/syscfg.yml
index 4a4a1ba..b679e9a 100644
--- a/targets/nordic_pca10095_net-blehci/syscfg.yml
+++ b/targets/nordic_pca10095_net-blehci/syscfg.yml
@@ -18,7 +18,7 @@
 #
 
 syscfg.vals:
-    BLE_HCI_TRANSPORT: nrf5340
+    BLE_TRANSPORT_HS: nrf5340
 
     MSYS_1_BLOCK_COUNT: 12
     MSYS_1_BLOCK_SIZE: 292

[mynewt-nimble] 21/22: nimble/transport: Move BLE_MONITOR to transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 1b9d48d58087e8ef431934d59442673e631f066f
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 10 15:18:53 2022 +0100

    nimble/transport: Move BLE_MONITOR to transport
    
    This allows to use monitor feature without host present.
---
 nimble/controller/src/ble_ll.c                     |  4 +-
 nimble/host/pkg.yml                                |  3 -
 nimble/host/src/ble_hs.c                           | 27 +-------
 nimble/host/src/ble_hs_hci.c                       |  8 ---
 nimble/host/src/ble_hs_hci_cmd.c                   |  7 ---
 nimble/host/src/ble_hs_hci_evt.c                   |  1 -
 nimble/host/src/ble_hs_priv.h                      |  1 -
 nimble/host/src/ble_l2cap_sig.c                    |  1 -
 nimble/host/syscfg.yml                             | 38 ------------
 nimble/transport/dialog_cmac/src/hci_cmac.c        |  8 +--
 nimble/transport/emspi/src/ble_hci_emspi.c         |  4 +-
 nimble/transport/include/nimble/transport.h        | 23 +++----
 .../include/nimble/transport/monitor.h}            | 38 ++++++++++--
 .../nimble/{transport.h => transport_impl.h}       | 28 +++------
 nimble/transport/nrf5340/src/nrf5340_ble_hci.c     |  8 +--
 nimble/transport/pkg.yml                           |  6 ++
 nimble/transport/socket/src/ble_hci_socket.c       |  4 +-
 .../src/ble_monitor.c => transport/src/monitor.c}  | 72 ++++++++++++++++------
 .../src/monitor_priv.h}                            |  2 -
 nimble/transport/syscfg.monitor.yml                | 58 +++++++++++++++++
 nimble/transport/syscfg.yml                        |  3 +-
 nimble/transport/uart/src/hci_uart.c               |  4 +-
 nimble/transport/usb/src/ble_hci_usb.c             |  4 +-
 23 files changed, 189 insertions(+), 163 deletions(-)

diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 73168b4..84b8a4e 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -1968,13 +1968,13 @@ ble_ll_init(void)
 /* Transport APIs for LL side */
 
 int
-ble_transport_to_ll_cmd(void *buf)
+ble_transport_to_ll_cmd_impl(void *buf)
 {
     return ble_ll_hci_cmd_rx(buf, NULL);
 }
 
 int
-ble_transport_to_ll_acl(struct os_mbuf *om)
+ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 {
     return ble_ll_hci_acl_rx(om, NULL);
 }
diff --git a/nimble/host/pkg.yml b/nimble/host/pkg.yml
index b289792..c069283 100644
--- a/nimble/host/pkg.yml
+++ b/nimble/host/pkg.yml
@@ -38,9 +38,6 @@ pkg.deps.BLE_SM_LEGACY:
 pkg.deps.BLE_SM_SC:
     - "@apache-mynewt-core/crypto/tinycrypt"
 
-pkg.deps.BLE_MONITOR_RTT:
-    - "@apache-mynewt-core/hw/drivers/rtt"
-
 pkg.deps.BLE_MESH:
     - nimble/host/mesh
 
diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c
index ba601b6..13b6fe2 100644
--- a/nimble/host/src/ble_hs.c
+++ b/nimble/host/src/ble_hs.c
@@ -25,7 +25,6 @@
 #include "stats/stats.h"
 #include "host/ble_hs.h"
 #include "ble_hs_priv.h"
-#include "ble_monitor_priv.h"
 #include "nimble/nimble_npl.h"
 #ifndef MYNEWT
 #include "nimble/nimble_port.h"
@@ -220,10 +219,6 @@ ble_hs_process_rx_data_queue(void)
     struct os_mbuf *om;
 
     while ((om = ble_mqueue_get(&ble_hs_rx_q)) != NULL) {
-#if BLE_MONITOR
-        ble_monitor_send_om(BLE_MONITOR_OPCODE_ACL_RX_PKT, om);
-#endif
-
         ble_hs_hci_evt_acl_process(om);
     }
 }
@@ -498,11 +493,6 @@ ble_hs_event_rx_hci_ev(struct ble_npl_event *ev)
     rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);
 
-#if BLE_MONITOR
-    ble_monitor_send(BLE_MONITOR_OPCODE_EVENT_PKT, hci_ev,
-                     hci_ev->length + sizeof(*hci_ev));
-#endif
-
     ble_hs_hci_evt_process(hci_ev);
 }
 
@@ -696,10 +686,6 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
 int
 ble_hs_tx_data(struct os_mbuf *om)
 {
-#if BLE_MONITOR
-    ble_monitor_send_om(BLE_MONITOR_OPCODE_ACL_TX_PKT, om);
-#endif
-
     return ble_transport_to_ll_acl(om);
 }
 
@@ -784,11 +770,6 @@ ble_hs_init(void)
     ble_hs_evq_set(nimble_port_get_dflt_eventq());
 #endif
 
-#if BLE_MONITOR
-    rc = ble_monitor_init();
-    SYSINIT_PANIC_ASSERT(rc == 0);
-#endif
-
     /* Enqueue the start event to the default event queue.  Using the default
      * queue ensures the event won't run until the end of main().  This allows
      * the application to configure this package in the meantime.
@@ -801,22 +782,18 @@ ble_hs_init(void)
     ble_npl_eventq_put(nimble_port_get_dflt_eventq(), &ble_hs_ev_start_stage1);
 #endif
 #endif
-
-#if BLE_MONITOR
-    ble_monitor_new_index(0, (uint8_t[6]){ }, "nimble0");
-#endif
 }
 
 /* Transport APIs for HS side */
 
 int
-ble_transport_to_hs_evt(void *buf)
+ble_transport_to_hs_evt_impl(void *buf)
 {
     return ble_hs_hci_rx_evt(buf, NULL);
 }
 
 int
-ble_transport_to_hs_acl(struct os_mbuf *om)
+ble_transport_to_hs_acl_impl(struct os_mbuf *om)
 {
     return ble_hs_rx_data(om, NULL);
 }
diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c
index 2157610..0624e38 100644
--- a/nimble/host/src/ble_hs_hci.c
+++ b/nimble/host/src/ble_hs_hci.c
@@ -22,9 +22,7 @@
 #include <stdio.h>
 #include "os/os.h"
 #include "mem/mem.h"
-#include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
-#include "ble_monitor_priv.h"
 
 #define BLE_HCI_CMD_TIMEOUT_MS  2000
 
@@ -278,12 +276,6 @@ ble_hs_hci_wait_for_ack(void)
     switch (rc) {
     case 0:
         BLE_HS_DBG_ASSERT(ble_hs_hci_ack != NULL);
-
-#if BLE_MONITOR
-        ble_monitor_send(BLE_MONITOR_OPCODE_EVENT_PKT, (void *) ble_hs_hci_ack,
-                         sizeof(*ble_hs_hci_ack) + ble_hs_hci_ack->length);
-#endif
-
         break;
     case OS_TIMEOUT:
         rc = BLE_HS_ETIMEOUT_HCI;
diff --git a/nimble/host/src/ble_hs_hci_cmd.c b/nimble/host/src/ble_hs_hci_cmd.c
index 33e1ae8..689cb17 100644
--- a/nimble/host/src/ble_hs_hci_cmd.c
+++ b/nimble/host/src/ble_hs_hci_cmd.c
@@ -23,20 +23,13 @@
 #include <stdio.h>
 #include "os/os.h"
 #include "nimble/hci_common.h"
-#include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
-#include "ble_monitor_priv.h"
 
 static int
 ble_hs_hci_cmd_transport(struct ble_hci_cmd *cmd)
 {
     int rc;
 
-#if BLE_MONITOR
-    ble_monitor_send(BLE_MONITOR_OPCODE_COMMAND_PKT, cmd,
-                     cmd->length + sizeof(*cmd));
-#endif
-
     rc = ble_transport_to_ll_cmd(cmd);
     switch (rc) {
     case 0:
diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c
index 3dba0bf..62de50e 100644
--- a/nimble/host/src/ble_hs_hci_evt.c
+++ b/nimble/host/src/ble_hs_hci_evt.c
@@ -23,7 +23,6 @@
 #include "os/os.h"
 #include "nimble/hci_common.h"
 #include "host/ble_gap.h"
-#include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
 
 _Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
diff --git a/nimble/host/src/ble_hs_priv.h b/nimble/host/src/ble_hs_priv.h
index a57ec3c..044b30c 100644
--- a/nimble/host/src/ble_hs_priv.h
+++ b/nimble/host/src/ble_hs_priv.h
@@ -42,7 +42,6 @@
 #include "ble_hs_periodic_sync_priv.h"
 #include "ble_uuid_priv.h"
 #include "host/ble_hs.h"
-#include "host/ble_monitor.h"
 #include "nimble/nimble_opt.h"
 #include "stats/stats.h"
 #ifdef __cplusplus
diff --git a/nimble/host/src/ble_l2cap_sig.c b/nimble/host/src/ble_l2cap_sig.c
index 3033e05..5263852 100644
--- a/nimble/host/src/ble_l2cap_sig.c
+++ b/nimble/host/src/ble_l2cap_sig.c
@@ -45,7 +45,6 @@
 #include <string.h>
 #include <errno.h>
 #include "nimble/ble.h"
-#include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
 
 #if NIMBLE_BLE_CONNECT
diff --git a/nimble/host/syscfg.yml b/nimble/host/syscfg.yml
index 5f67c44..ce2acc4 100644
--- a/nimble/host/syscfg.yml
+++ b/nimble/host/syscfg.yml
@@ -44,44 +44,6 @@ syscfg.defs:
             simulator.
         value: 1
 
-    # Monitor interface settings
-    BLE_MONITOR_UART:
-        description: Enables monitor interface over UART
-        value: 0
-    BLE_MONITOR_UART_DEV:
-        description: Monitor interface UART device
-        value: '"uart0"'
-    BLE_MONITOR_UART_BAUDRATE:
-        description: Baudrate for monitor interface UART
-        value: 1000000
-    BLE_MONITOR_UART_BUFFER_SIZE:
-        description: >
-            Monitor interface ringbuffer size for UART.
-            This value should be a power of 2.
-        value: 64
-    BLE_MONITOR_RTT:
-        description: Enables monitor interface over RTT
-        value: 0
-    BLE_MONITOR_RTT_BUFFER_NAME:
-        description: Monitor interface upstream buffer name
-        value: '"btmonitor"'
-    BLE_MONITOR_RTT_BUFFER_SIZE:
-        description: Monitor interface upstream buffer size
-        value: 256
-    BLE_MONITOR_RTT_BUFFERED:
-        description: >
-            Enables buffering when using monitor interface over RTT. The data
-            are written to RTT once complete packet is created in intermediate
-            buffer. This allows to skip complete packet if there is not enough
-            space in RTT buffer (e.g. there is no reader connected). If disabled,
-            monitor will simply block waiting for RTT to free space in buffer.
-        value: 1
-    BLE_MONITOR_CONSOLE_BUFFER_SIZE:
-        description: >
-            Size of internal buffer for console output. Any line exceeding this
-            length value will be split.
-        value: 128
-
     # L2CAP settings.
     BLE_L2CAP_MAX_CHANS:
         description: >
diff --git a/nimble/transport/dialog_cmac/src/hci_cmac.c b/nimble/transport/dialog_cmac/src/hci_cmac.c
index 254e0db..e0702a0 100644
--- a/nimble/transport/dialog_cmac/src/hci_cmac.c
+++ b/nimble/transport/dialog_cmac/src/hci_cmac.c
@@ -165,7 +165,7 @@ ble_transport_hs_init(void)
 
 #if !MYNEWT_VAL(BLE_CONTROLLER)
 int
-ble_transport_to_ll_cmd(void *buf)
+ble_transport_to_ll_cmd_impl(void *buf)
 {
     uint8_t pkt_type = HCI_H4_CMD;
     uint8_t *cmd = buf;
@@ -179,7 +179,7 @@ ble_transport_to_ll_cmd(void *buf)
 }
 
 int
-ble_transport_to_ll_acl(struct os_mbuf *om)
+ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 {
     return hci_cmac_acl_tx(om);
 }
@@ -187,13 +187,13 @@ ble_transport_to_ll_acl(struct os_mbuf *om)
 
 #if MYNEWT_VAL(BLE_CONTROLLER)
 int
-ble_transport_to_hs_acl(struct os_mbuf *om)
+ble_transport_to_hs_acl_impl(struct os_mbuf *om)
 {
     return hci_cmac_acl_tx(om);
 }
 
 int
-ble_transport_to_hs_evt(void *buf)
+ble_transport_to_hs_evt_impl(void *buf)
 {
     uint8_t pkt_type = HCI_H4_EVT;
     uint8_t *evt = buf;
diff --git a/nimble/transport/emspi/src/ble_hci_emspi.c b/nimble/transport/emspi/src/ble_hci_emspi.c
index e49d3d4..d07820f 100644
--- a/nimble/transport/emspi/src/ble_hci_emspi.c
+++ b/nimble/transport/emspi/src/ble_hci_emspi.c
@@ -686,13 +686,13 @@ ble_transport_ll_init(void)
 }
 
 int
-ble_transport_to_ll_cmd(void *buf)
+ble_transport_to_ll_cmd_impl(void *buf)
 {
     return ble_hci_emspi_cmdevt_tx(buf, BLE_HCI_EMSPI_PKT_CMD);
 }
 
 int
-ble_transport_to_ll_acl(struct os_mbuf *om)
+ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 {
     return ble_hci_emspi_acl_tx(om);
 }
\ No newline at end of file
diff --git a/nimble/transport/include/nimble/transport.h b/nimble/transport/include/nimble/transport.h
index 7149d87..9e0eb66 100644
--- a/nimble/transport/include/nimble/transport.h
+++ b/nimble/transport/include/nimble/transport.h
@@ -24,17 +24,10 @@
 extern "C" {
 #endif
 
-struct os_mbuf;
-
-/* Init functions to be implemented for transport acting as HS/LL side */
-extern void ble_transport_ll_init(void);
-extern void ble_transport_hs_init(void);
+#include <nimble/transport_impl.h>
+#include <nimble/transport/monitor.h>
 
-/* APIs to be implemented by HS/LL side of transports */
-extern int ble_transport_to_ll_cmd(void *buf);
-extern int ble_transport_to_ll_acl(struct os_mbuf *om);
-extern int ble_transport_to_hs_evt(void *buf);
-extern int ble_transport_to_hs_acl(struct os_mbuf *om);
+struct os_mbuf;
 
 /* Allocators for supported data types */
 void *ble_transport_alloc_cmd(void);
@@ -48,11 +41,11 @@ void ble_transport_free(void *buf);
 /* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
 int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
 
-#if MYNEWT_VAL(BLE_TRANSPORT_INT_FLOW_CTL)
-/* To be implemented if transport supports internal flow control between cores */
-extern int ble_transport_int_flow_ctl_get(void);
-extern void ble_transport_int_flow_ctl_put(void);
-#endif
+/* Send data to hs/ll side */
+int ble_transport_to_ll_cmd(void *buf);
+int ble_transport_to_ll_acl(struct os_mbuf *om);
+int ble_transport_to_hs_evt(void *buf);
+int ble_transport_to_hs_acl(struct os_mbuf *om);
 
 #ifdef __cplusplus
 }
diff --git a/nimble/host/include/host/ble_monitor.h b/nimble/transport/include/nimble/transport/monitor.h
similarity index 60%
rename from nimble/host/include/host/ble_monitor.h
rename to nimble/transport/include/nimble/transport/monitor.h
index 61722f7..6b56f12 100644
--- a/nimble/host/include/host/ble_monitor.h
+++ b/nimble/transport/include/nimble/transport/monitor.h
@@ -22,16 +22,46 @@
 
 #include <syscfg/syscfg.h>
 
-#undef BLE_MONITOR
-#define BLE_MONITOR (MYNEWT_VAL(BLE_MONITOR_UART) || MYNEWT_VAL(BLE_MONITOR_RTT))
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#define BLE_MONITOR     (MYNEWT_VAL(BLE_MONITOR_RTT) || \
+                         MYNEWT_VAL(BLE_MONITOR_UART))
+
+#if BLE_MONITOR
 int ble_monitor_log(int level, const char *fmt, ...);
+#else
+static inline int
+ble_monitor_log(int level, const char *fmt, ...)
+{
+    return 0;
+}
+
+static inline int
+ble_transport_to_ll_cmd(void *buf)
+{
+    return ble_transport_to_ll_cmd_impl(buf);
+}
 
-int ble_monitor_out(int c);
+static inline int
+ble_transport_to_ll_acl(struct os_mbuf *om)
+{
+    return ble_transport_to_ll_acl_impl(om);
+}
+
+static inline int
+ble_transport_to_hs_evt(void *buf)
+{
+    return ble_transport_to_hs_evt_impl(buf);
+}
+
+static inline int
+ble_transport_to_hs_acl(struct os_mbuf *om)
+{
+    return ble_transport_to_hs_acl_impl(om);
+}
+#endif /* BLE_MONITOR */
 
 #ifdef __cplusplus
 }
diff --git a/nimble/transport/include/nimble/transport.h b/nimble/transport/include/nimble/transport_impl.h
similarity index 63%
copy from nimble/transport/include/nimble/transport.h
copy to nimble/transport/include/nimble/transport_impl.h
index 7149d87..61d8cd6 100644
--- a/nimble/transport/include/nimble/transport.h
+++ b/nimble/transport/include/nimble/transport_impl.h
@@ -17,36 +17,22 @@
  * under the License.
  */
 
-#ifndef H_NIMBLE_TRANSPORT_
-#define H_NIMBLE_TRANSPORT_
+#ifndef H_NIMBLE_TRANSPORT_IMPL_
+#define H_NIMBLE_TRANSPORT_IMPL_
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-struct os_mbuf;
-
 /* Init functions to be implemented for transport acting as HS/LL side */
 extern void ble_transport_ll_init(void);
 extern void ble_transport_hs_init(void);
 
 /* APIs to be implemented by HS/LL side of transports */
-extern int ble_transport_to_ll_cmd(void *buf);
-extern int ble_transport_to_ll_acl(struct os_mbuf *om);
-extern int ble_transport_to_hs_evt(void *buf);
-extern int ble_transport_to_hs_acl(struct os_mbuf *om);
-
-/* Allocators for supported data types */
-void *ble_transport_alloc_cmd(void);
-void *ble_transport_alloc_evt(int discardable);
-struct os_mbuf *ble_transport_alloc_acl_from_hs(void);
-struct os_mbuf *ble_transport_alloc_acl_from_ll(void);
-
-/* Generic deallocator for cmd/evt buffers */
-void ble_transport_free(void *buf);
-
-/* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
-int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
+extern int ble_transport_to_ll_cmd_impl(void *buf);
+extern int ble_transport_to_ll_acl_impl(struct os_mbuf *om);
+extern int ble_transport_to_hs_evt_impl(void *buf);
+extern int ble_transport_to_hs_acl_impl(struct os_mbuf *om);
 
 #if MYNEWT_VAL(BLE_TRANSPORT_INT_FLOW_CTL)
 /* To be implemented if transport supports internal flow control between cores */
@@ -58,4 +44,4 @@ extern void ble_transport_int_flow_ctl_put(void);
 }
 #endif
 
-#endif /* H_NIMBLE_TRANSPORT_ */
+#endif /* H_NIMBLE_TRANSPORT_IMPL_ */
diff --git a/nimble/transport/nrf5340/src/nrf5340_ble_hci.c b/nimble/transport/nrf5340/src/nrf5340_ble_hci.c
index eee27c9..111c048 100644
--- a/nimble/transport/nrf5340/src/nrf5340_ble_hci.c
+++ b/nimble/transport/nrf5340/src/nrf5340_ble_hci.c
@@ -115,7 +115,7 @@ nrf5340_ble_hci_init(void)
 
 #if MYNEWT_VAL(BLE_CONTROLLER)
 int
-ble_transport_to_hs_evt(void *buf)
+ble_transport_to_hs_evt_impl(void *buf)
 {
     uint8_t ind = HCI_H4_EVT;
     uint8_t* hci_ev = buf;
@@ -133,7 +133,7 @@ ble_transport_to_hs_evt(void *buf)
 }
 
 int
-ble_transport_to_hs_acl(struct os_mbuf *om)
+ble_transport_to_hs_acl_impl(struct os_mbuf *om)
 {
     return nrf5340_ble_hci_acl_tx(om);
 }
@@ -149,7 +149,7 @@ ble_transport_hs_init(void)
 
 #if !MYNEWT_VAL(BLE_CONTROLLER)
 int
-ble_transport_to_ll_cmd(void *buf)
+ble_transport_to_ll_cmd_impl(void *buf)
 {
     uint8_t ind = HCI_H4_CMD;
     uint8_t *cmd = buf;
@@ -167,7 +167,7 @@ ble_transport_to_ll_cmd(void *buf)
 }
 
 int
-ble_transport_to_ll_acl(struct os_mbuf *om)
+ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 {
     return nrf5340_ble_hci_acl_tx(om);
 }
diff --git a/nimble/transport/pkg.yml b/nimble/transport/pkg.yml
index bedcb16..12b9f40 100644
--- a/nimble/transport/pkg.yml
+++ b/nimble/transport/pkg.yml
@@ -45,6 +45,9 @@ pkg.deps.'BLE_TRANSPORT_HS == "uart"':
 pkg.deps.'BLE_TRANSPORT_HS == "usb"':
     - nimble/transport/usb
 
+pkg.deps.BLE_MONITOR_RTT:
+    - "@apache-mynewt-core/hw/drivers/rtt"
+
 pkg.init:
     ble_transport_init: 250
     ble_transport_hs_init:
@@ -52,3 +55,6 @@ pkg.init:
         - $before:ble_transport_ll_init
     ble_transport_ll_init:
         - $after:ble_transport_hs_init
+
+pkg.init.'BLE_MONITOR_RTT || BLE_MONITOR_UART':
+    ble_monitor_init: $before:ble_transport_init
diff --git a/nimble/transport/socket/src/ble_hci_socket.c b/nimble/transport/socket/src/ble_hci_socket.c
index ee974ec..5dd1d17 100644
--- a/nimble/transport/socket/src/ble_hci_socket.c
+++ b/nimble/transport/socket/src/ble_hci_socket.c
@@ -839,13 +839,13 @@ ble_transport_ll_init(void)
 }
 
 int
-ble_transport_to_ll_acl(struct os_mbuf *om)
+ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 {
     return ble_hci_trans_hs_acl_tx(om);
 }
 
 int
-ble_transport_to_ll_cmd(void *buf)
+ble_transport_to_ll_cmd_impl(void *buf)
 {
     return ble_hci_trans_hs_cmd_tx(buf);
 }
diff --git a/nimble/host/src/ble_monitor.c b/nimble/transport/src/monitor.c
similarity index 88%
rename from nimble/host/src/ble_monitor.c
rename to nimble/transport/src/monitor.c
index b86e777..8830914 100644
--- a/nimble/host/src/ble_monitor.c
+++ b/nimble/transport/src/monitor.c
@@ -17,13 +17,9 @@
  * under the License.
  */
 
-#include "host/ble_monitor.h"
+#include <syscfg/syscfg.h>
 
-#if BLE_MONITOR
-
-#if MYNEWT_VAL(BLE_MONITOR_UART) && MYNEWT_VAL(BLE_MONITOR_RTT)
-#error "Cannot enable monitor over UART and RTT at the same time!"
-#endif
+#if MYNEWT_VAL(BLE_MONITOR_RTT) || MYNEWT_VAL(BLE_MONITOR_UART)
 
 #ifdef BABBLESIM
 #define _GNU_SOURCE
@@ -41,8 +37,10 @@
 #if MYNEWT_VAL(BLE_MONITOR_RTT)
 #include "rtt/SEGGER_RTT.h"
 #endif
-#include "ble_hs_priv.h"
-#include "ble_monitor_priv.h"
+#include <nimble/hci_common.h>
+#include <nimble/transport.h>
+#include <nimble/nimble_npl.h>
+#include "monitor_priv.h"
 
 struct ble_npl_mutex lock;
 
@@ -297,9 +295,11 @@ drops_tmp_cb(struct ble_npl_event *ev)
 }
 #endif
 
-int
+void
 ble_monitor_init(void)
 {
+    SYSINIT_ASSERT_ACTIVE();
+
 #if MYNEWT_VAL(BLE_MONITOR_UART)
     struct uart_conf uc = {
         .uc_speed = MYNEWT_VAL(BLE_MONITOR_UART_BAUDRATE),
@@ -314,14 +314,12 @@ ble_monitor_init(void)
 
     uart = (struct uart_dev *)os_dev_open(MYNEWT_VAL(BLE_MONITOR_UART_DEV),
                                           OS_TIMEOUT_NEVER, &uc);
-    if (!uart) {
-        return -1;
-    }
+    SYSINIT_PANIC_ASSERT(uart);
 #endif
 
 #if MYNEWT_VAL(BLE_MONITOR_RTT)
 #if MYNEWT_VAL(BLE_MONITOR_RTT_BUFFERED)
-    ble_npl_callout_init(&rtt_drops.tmo, ble_hs_evq_get(), drops_tmp_cb, NULL);
+    ble_npl_callout_init(&rtt_drops.tmo, ble_npl_eventq_dflt_get(), drops_tmp_cb, NULL);
 
     /* Initialize types in header (we won't touch them later) */
     rtt_drops.drops_hdr.type_cmd = BLE_MONITOR_EXTHDR_COMMAND_DROPS;
@@ -339,14 +337,14 @@ ble_monitor_init(void)
                                          SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
 #endif
 
-    if (rtt_index < 0) {
-        return -1;
-    }
+    SYSINIT_PANIC_ASSERT(rtt_index >= 0);
 #endif
 
     ble_npl_mutex_init(&lock);
 
-    return 0;
+#if BLE_MONITOR
+    ble_monitor_new_index(0, (uint8_t[6]){ }, "nimble0");
+#endif
 }
 
 int
@@ -492,4 +490,42 @@ ble_monitor_out(int c)
     return c;
 }
 
-#endif
+int
+ble_transport_to_ll_cmd(void *buf)
+{
+    struct ble_hci_cmd *cmd = buf;
+
+    ble_monitor_send(BLE_MONITOR_OPCODE_COMMAND_PKT, buf, cmd->length +
+                                                          sizeof(*cmd));
+
+    return ble_transport_to_ll_cmd_impl(buf);
+}
+
+int
+ble_transport_to_ll_acl(struct os_mbuf *om)
+{
+    ble_monitor_send_om(BLE_MONITOR_OPCODE_ACL_TX_PKT, om);
+
+    return ble_transport_to_ll_acl_impl(om);
+}
+
+int
+ble_transport_to_hs_acl(struct os_mbuf *om)
+{
+    ble_monitor_send_om(BLE_MONITOR_OPCODE_ACL_RX_PKT, om);
+
+    return ble_transport_to_hs_acl_impl(om);
+}
+
+int
+ble_transport_to_hs_evt(void *buf)
+{
+    struct ble_hci_ev *ev = buf;
+
+    ble_monitor_send(BLE_MONITOR_OPCODE_EVENT_PKT, buf, ev->length +
+                                                        sizeof(*ev));
+
+    return ble_transport_to_hs_evt_impl(buf);
+}
+
+#endif /* MYNEWT_VAL(BLE_MONITOR_RTT) || MYNEWT_VAL(BLE_MONITOR_UART) */
diff --git a/nimble/host/src/ble_monitor_priv.h b/nimble/transport/src/monitor_priv.h
similarity index 99%
rename from nimble/host/src/ble_monitor_priv.h
rename to nimble/transport/src/monitor_priv.h
index 9357870..0fb9650 100644
--- a/nimble/host/src/ble_monitor_priv.h
+++ b/nimble/transport/src/monitor_priv.h
@@ -85,8 +85,6 @@ struct ble_monitor_user_logging {
     uint8_t  ident_len;
 } __attribute__((packed));
 
-int ble_monitor_init(void);
-
 int ble_monitor_send(uint16_t opcode, const void *data, size_t len);
 
 int ble_monitor_send_om(uint16_t opcode, const struct os_mbuf *om);
diff --git a/nimble/transport/syscfg.monitor.yml b/nimble/transport/syscfg.monitor.yml
new file mode 100644
index 0000000..7cfbc41
--- /dev/null
+++ b/nimble/transport/syscfg.monitor.yml
@@ -0,0 +1,58 @@
+# 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.
+#
+
+syscfg.defs:
+    BLE_MONITOR_UART:
+        description: Enables monitor interface over UART
+        value: 0
+    BLE_MONITOR_UART_DEV:
+        description: Monitor interface UART device
+        value: '"uart0"'
+    BLE_MONITOR_UART_BAUDRATE:
+        description: Baudrate for monitor interface UART
+        value: 1000000
+    BLE_MONITOR_UART_BUFFER_SIZE:
+        description: >
+            Monitor interface ringbuffer size for UART.
+            This value should be a power of 2.
+        value: 64
+    BLE_MONITOR_RTT:
+        description: Enables monitor interface over RTT
+        value: 0
+    BLE_MONITOR_RTT_BUFFER_NAME:
+        description: Monitor interface upstream buffer name
+        value: '"btmonitor"'
+    BLE_MONITOR_RTT_BUFFER_SIZE:
+        description: Monitor interface upstream buffer size
+        value: 256
+    BLE_MONITOR_RTT_BUFFERED:
+        description: >
+            Enables buffering when using monitor interface over RTT. The data
+            are written to RTT once complete packet is created in intermediate
+            buffer. This allows to skip complete packet if there is not enough
+            space in RTT buffer (e.g. there is no reader connected). If disabled,
+            monitor will simply block waiting for RTT to free space in buffer.
+        value: 1
+    BLE_MONITOR_CONSOLE_BUFFER_SIZE:
+        description: >
+            Size of internal buffer for console output. Any line exceeding this
+            length value will be split.
+        value: 128
+
+syscfg.restrictions:
+    - '!(BLE_MONITOR_UART && BLE_MONITOR_RTT)'
diff --git a/nimble/transport/syscfg.yml b/nimble/transport/syscfg.yml
index 5f61a01..4985250 100644
--- a/nimble/transport/syscfg.yml
+++ b/nimble/transport/syscfg.yml
@@ -86,8 +86,9 @@ syscfg.defs:
             of ACL buffers available for controller.
         value: MYNEWT_VAL(BLE_TRANSPORT_ACL_COUNT)
 
-# import defunct settings from separate file to reduce clutter in main file
+# import monitor and defunct settings from separate file to reduce clutter in main file
 $import:
+    - "@apache-mynewt-nimble/nimble/transport/syscfg.monitor.yml"
     - "@apache-mynewt-nimble/nimble/transport/syscfg.defunct.yml"
 
 syscfg.vals."BLE_EXT_ADV || BLE_LL_CFG_FEAT_LL_EXT_ADV":
diff --git a/nimble/transport/uart/src/hci_uart.c b/nimble/transport/uart/src/hci_uart.c
index 9ffcc90..f44b990 100644
--- a/nimble/transport/uart/src/hci_uart.c
+++ b/nimble/transport/uart/src/hci_uart.c
@@ -172,7 +172,7 @@ hci_uart_configure(void)
 }
 
 int
-ble_transport_to_hs_evt(void *buf)
+ble_transport_to_hs_evt_impl(void *buf)
 {
     struct hci_uart_tx *txe;
     os_sr_t sr;
@@ -200,7 +200,7 @@ ble_transport_to_hs_evt(void *buf)
 }
 
 int
-ble_transport_to_hs_acl(struct os_mbuf *om)
+ble_transport_to_hs_acl_impl(struct os_mbuf *om)
 {
     struct hci_uart_tx *txe;
     os_sr_t sr;
diff --git a/nimble/transport/usb/src/ble_hci_usb.c b/nimble/transport/usb/src/ble_hci_usb.c
index 6518cd9..01c60b8 100644
--- a/nimble/transport/usb/src/ble_hci_usb.c
+++ b/nimble/transport/usb/src/ble_hci_usb.c
@@ -242,13 +242,13 @@ ble_hci_trans_ll_evt_tx(void *buf)
 }
 
 int
-ble_transport_to_hs_acl(struct os_mbuf *om)
+ble_transport_to_hs_acl_impl(struct os_mbuf *om)
 {
     return ble_hci_trans_ll_tx(&ble_hci_tx_acl_queue, om);
 }
 
 int
-ble_transport_to_hs_evt(void *buf)
+ble_transport_to_hs_evt_impl(void *buf)
 {
     return ble_hci_trans_ll_evt_tx(buf);
 }

[mynewt-nimble] 12/22: nimble/transport: Remove RAM transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 4ba36ff76fa5e448bcc72c927e94a1340707f40b
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:06:48 2022 +0100

    nimble/transport: Remove RAM transport
    
    Not needed anymore, "native" transport does not need any extra code.
---
 .../ram/include/transport/ram/ble_hci_ram.h        |  35 ---
 nimble/transport/ram/pkg.yml                       |  36 ----
 nimble/transport/ram/src/ble_hci_ram.c             | 238 ---------------------
 nimble/transport/ram/syscfg.yml                    |  33 ---
 4 files changed, 342 deletions(-)

diff --git a/nimble/transport/ram/include/transport/ram/ble_hci_ram.h b/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
deleted file mode 100644
index 3c37e32..0000000
--- a/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
+++ /dev/null
@@ -1,35 +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_BLE_HCI_RAM_
-#define H_BLE_HCI_RAM_
-
-#include "nimble/ble_hci_trans.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void ble_hci_ram_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/nimble/transport/ram/pkg.yml b/nimble/transport/ram/pkg.yml
deleted file mode 100644
index bb8397b..0000000
--- a/nimble/transport/ram/pkg.yml
+++ /dev/null
@@ -1,36 +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.
-#
-
-pkg.name: nimble/transport/ram
-pkg.description: XXX
-pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble
-    - bluetooth
-
-pkg.deps:
-    - "@apache-mynewt-core/kernel/os"
-    - nimble
-
-pkg.apis:
-    - ble_transport
-
-pkg.init:
-    ble_hci_ram_init: 'MYNEWT_VAL(BLE_TRANS_RAM_SYSINIT_STAGE)'
diff --git a/nimble/transport/ram/src/ble_hci_ram.c b/nimble/transport/ram/src/ble_hci_ram.c
deleted file mode 100644
index 3f10e9d..0000000
--- a/nimble/transport/ram/src/ble_hci_ram.c
+++ /dev/null
@@ -1,238 +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 <assert.h>
-#include <errno.h>
-#include <stddef.h>
-#include "syscfg/syscfg.h"
-#include "sysinit/sysinit.h"
-#include "os/os.h"
-#include "mem/mem.h"
-#include "nimble/ble.h"
-#include "nimble/ble_hci_trans.h"
-#include "transport/ram/ble_hci_ram.h"
-
-static ble_hci_trans_rx_cmd_fn *ble_hci_ram_rx_cmd_hs_cb;
-static void *ble_hci_ram_rx_cmd_hs_arg;
-
-static ble_hci_trans_rx_cmd_fn *ble_hci_ram_rx_cmd_ll_cb;
-static void *ble_hci_ram_rx_cmd_ll_arg;
-
-static ble_hci_trans_rx_acl_fn *ble_hci_ram_rx_acl_hs_cb;
-static void *ble_hci_ram_rx_acl_hs_arg;
-
-static ble_hci_trans_rx_acl_fn *ble_hci_ram_rx_acl_ll_cb;
-static void *ble_hci_ram_rx_acl_ll_arg;
-
-static struct os_mempool ble_hci_ram_cmd_pool;
-static os_membuf_t ble_hci_ram_cmd_buf[
-        OS_MEMPOOL_SIZE(1, BLE_HCI_TRANS_CMD_SZ)
-];
-
-static struct os_mempool ble_hci_ram_evt_hi_pool;
-static os_membuf_t ble_hci_ram_evt_hi_buf[
-    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_ram_evt_lo_pool;
-static os_membuf_t ble_hci_ram_evt_lo_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_ram_rx_cmd_hs_cb = cmd_cb;
-    ble_hci_ram_rx_cmd_hs_arg = cmd_arg;
-    ble_hci_ram_rx_acl_hs_cb = acl_cb;
-    ble_hci_ram_rx_acl_hs_arg = acl_arg;
-}
-
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_ram_rx_cmd_ll_cb = cmd_cb;
-    ble_hci_ram_rx_cmd_ll_arg = cmd_arg;
-    ble_hci_ram_rx_acl_ll_cb = acl_cb;
-    ble_hci_ram_rx_acl_ll_arg = acl_arg;
-}
-
-int
-ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
-{
-    int rc;
-
-    assert(ble_hci_ram_rx_cmd_ll_cb != NULL);
-
-    rc = ble_hci_ram_rx_cmd_ll_cb(cmd, ble_hci_ram_rx_cmd_ll_arg);
-    return rc;
-}
-
-int
-ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
-{
-    int rc;
-
-    assert(ble_hci_ram_rx_cmd_hs_cb != NULL);
-
-    rc = ble_hci_ram_rx_cmd_hs_cb(hci_ev, ble_hci_ram_rx_cmd_hs_arg);
-    return rc;
-}
-
-int
-ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
-{
-    int rc;
-
-    assert(ble_hci_ram_rx_acl_ll_cb != NULL);
-
-    rc = ble_hci_ram_rx_acl_ll_cb(om, ble_hci_ram_rx_acl_ll_arg);
-    return rc;
-}
-
-int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
-{
-    int rc;
-
-    assert(ble_hci_ram_rx_acl_hs_cb != NULL);
-
-    rc = ble_hci_ram_rx_acl_hs_cb(om, ble_hci_ram_rx_acl_hs_arg);
-    return rc;
-}
-
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        buf = os_memblock_get(&ble_hci_ram_cmd_pool);
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_ram_evt_hi_pool);
-        if (buf == NULL) {
-            /* If no high-priority event buffers remain, try to grab a
-             * low-priority one.
-             */
-            buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
-        }
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&ble_hci_ram_evt_lo_pool);
-        break;
-
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    /* XXX: this may look a bit odd, but the controller uses the command
-    * buffer to send back the command complete/status as an immediate
-    * response to the command. This was done to insure that the controller
-    * could always send back one of these events when a command was received.
-    * Thus, we check to see which pool the buffer came from so we can free
-    * it to the appropriate pool
-    */
-    if (os_memblock_from(&ble_hci_ram_evt_hi_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_ram_evt_hi_pool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_ram_evt_lo_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_ram_evt_lo_pool, buf);
-        assert(rc == 0);
-    } else {
-        assert(os_memblock_from(&ble_hci_ram_cmd_pool, buf));
-        rc = os_memblock_put(&ble_hci_ram_cmd_pool, buf);
-        assert(rc == 0);
-    }
-}
-
-/**
- * Unsupported; the RAM transport does not have a dedicated ACL data packet
- * pool.
- */
-int
-ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
-{
-    return BLE_ERR_UNSUPPORTED;
-}
-
-int
-ble_hci_trans_reset(void)
-{
-    /* No work to do.  All allocated buffers are owned by the host or
-     * controller, and they will get freed by their owners.
-     */
-    return 0;
-}
-
-void
-ble_hci_ram_init(void)
-{
-    int rc;
-
-    /* Ensure this function only gets called by sysinit. */
-    SYSINIT_ASSERT_ACTIVE();
-
-    /*
-     * Create memory pool of HCI command buffers. NOTE: we currently dont
-     * allow this to be configured. The controller will only allow one
-     * outstanding command. We decided to keep this a pool in case we allow
-     * allow the controller to handle more than one outstanding command.
-     */
-    rc = os_mempool_init(&ble_hci_ram_cmd_pool,
-                         1,
-                         BLE_HCI_TRANS_CMD_SZ,
-                         ble_hci_ram_cmd_buf,
-                         "ble_hci_ram_cmd_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_ram_evt_hi_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_ram_evt_hi_buf,
-                         "ble_hci_ram_evt_hi_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_ram_evt_lo_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_ram_evt_lo_buf,
-                         "ble_hci_ram_evt_lo_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-}
diff --git a/nimble/transport/ram/syscfg.yml b/nimble/transport/ram/syscfg.yml
deleted file mode 100644
index 6286dfe..0000000
--- a/nimble/transport/ram/syscfg.yml
+++ /dev/null
@@ -1,33 +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.
-#
-
-syscfg.defs:
-    BLE_TRANS_RAM_SYSINIT_STAGE:
-        description: >
-            Sysinit stage for the RAM BLE transport.
-        value: 100
-
-syscfg.vals:
-    BLE_HCI_EVT_HI_BUF_COUNT: 2
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_ACL_BUF_COUNT: 4
-    BLE_ACL_BUF_SIZE: 65535
-
-syscfg.vals.BLE_EXT_ADV:
-    BLE_HCI_EVT_BUF_SIZE: 257

[mynewt-nimble] 07/22: nimble/transport: Update nRF5340 transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 33c1ece041095dd93d039d2b68997b13b0efceb0
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:05:55 2022 +0100

    nimble/transport: Update nRF5340 transport
---
 nimble/transport/nrf5340/pkg.yml               |   6 +-
 nimble/transport/nrf5340/src/nrf5340_ble_hci.c | 492 ++++---------------------
 2 files changed, 79 insertions(+), 419 deletions(-)

diff --git a/nimble/transport/nrf5340/pkg.yml b/nimble/transport/nrf5340/pkg.yml
index 4db567c..73dfcf9 100644
--- a/nimble/transport/nrf5340/pkg.yml
+++ b/nimble/transport/nrf5340/pkg.yml
@@ -27,12 +27,10 @@ pkg.keywords:
     - nrf5340
 
 pkg.deps:
-    - "@apache-mynewt-nimble/nimble"
+    - nimble
+    - nimble/transport/common/hci_h4
     - "@apache-mynewt-core/kernel/os"
     - "@apache-mynewt-core/hw/drivers/ipc_nrf5340"
 
 pkg.apis:
     - ble_transport
-
-pkg.init:
-    nrf5340_ble_hci_init: 'MYNEWT_VAL(BLE_TRANS_NRF5340_SYSINIT_STAGE)'
diff --git a/nimble/transport/nrf5340/src/nrf5340_ble_hci.c b/nimble/transport/nrf5340/src/nrf5340_ble_hci.c
index 1f510e8..eee27c9 100644
--- a/nimble/transport/nrf5340/src/nrf5340_ble_hci.c
+++ b/nimble/transport/nrf5340/src/nrf5340_ble_hci.c
@@ -21,133 +21,24 @@
 #include <string.h>
 #include <sysinit/sysinit.h>
 #include <nimble/ble.h>
-#include <nimble/ble_hci_trans.h>
-#include <nimble/hci_common.h>
 #include <ipc_nrf5340/ipc_nrf5340.h>
-
-#define HCI_PKT_NONE    0x00
-#define HCI_PKT_CMD     0x01
-#define HCI_PKT_ACL     0x02
-#define HCI_PKT_EVT     0x04
-
-#define POOL_ACL_BLOCK_SIZE OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) +     \
-                                     BLE_MBUF_MEMBLOCK_OVERHEAD +       \
-                                     BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
+#include <nimble/transport.h>
+#include <nimble/transport/hci_h4.h>
 
 #if MYNEWT_VAL(BLE_CONTROLLER)
 #define IPC_TX_CHANNEL 0
 #define IPC_RX_CHANNEL 1
-#endif
-
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
+#else
 #define IPC_TX_CHANNEL 1
 #define IPC_RX_CHANNEL 0
 #endif
 
-struct nrf5340_ble_hci_api {
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    ble_hci_trans_rx_cmd_fn *cmd_cb;
-    void *cmd_arg;
-#endif
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    ble_hci_trans_rx_cmd_fn *evt_cb;
-    void *evt_arg;
-#endif
-    ble_hci_trans_rx_acl_fn *acl_cb;
-    void *acl_arg;
-};
-
-struct nrf5340_ble_hci_rx_data {
-    uint8_t type;
-    uint8_t hdr[4];
-    uint16_t len;
-    uint16_t expected_len;
-    union {
-        uint8_t *buf;
-        struct os_mbuf *om;
-    };
-};
-
-struct nrf5340_ble_hci_pool_cmd {
-    uint8_t cmd[BLE_HCI_TRANS_CMD_SZ];
-    bool allocated;
-};
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-/*
- * If controller-to-host flow control is enabled we need to hold an extra command
- * buffer for HCI_Host_Number_Of_Completed_Packets which can be sent at any time.
- */
-#if MYNEWT_VAL(BLE_HS_FLOW_CTRL) || MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
-#define HCI_CMD_COUNT   2
-#else
-#define HCI_CMD_COUNT   1
-#endif
-
-static uint8_t nrf5340_ble_hci_pool_cmd_mempool_buf[OS_MEMPOOL_BYTES(
-                                                        HCI_CMD_COUNT,
-                                                        BLE_HCI_TRANS_CMD_SZ)];
-static struct os_mempool nrf5340_ble_hci_pool_cmd_mempool;
-
-/* Pools for HCI events (high and low priority) */
-static uint8_t nrf5340_ble_hci_pool_evt_hi_buf[OS_MEMPOOL_BYTES(
-                                            MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                                            MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))];
-static struct os_mempool nrf5340_ble_hci_pool_evt_hi;
-static uint8_t nrf5340_ble_hci_pool_evt_lo_buf[OS_MEMPOOL_BYTES(
-                                            MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                                            MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))];
-static struct os_mempool nrf5340_ble_hci_pool_evt_lo;
-
-#endif
-
-/* Pool for ACL data */
-static uint8_t nrf5340_ble_hci_pool_acl_buf[OS_MEMPOOL_BYTES(
-                                            MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                                            POOL_ACL_BLOCK_SIZE)];
-static struct os_mempool_ext nrf5340_ble_hci_pool_acl;
-static struct os_mbuf_pool nrf5340_ble_hci_pool_acl_mbuf;
-
-/* Interface to host/ll */
-static struct nrf5340_ble_hci_api nrf5340_ble_hci_api;
-
-/* State of RX currently in progress (needs to reassemble frame) */
-static struct nrf5340_ble_hci_rx_data nrf5340_ble_hci_rx_data;
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-int
-ble_hci_trans_reset(void)
-{
-    /* XXX Should we do something with RF and/or BLE core? */
-    return 0;
-}
-#endif
-
-#if MYNEWT_VAL(BLE_HCI_BRIDGE)
-/*
- * TODO: Remove/fix functions ble_ll_data_buffer_overflow() ble_ll_hw_error()
- * Following two functions are added to allowed build of HCI bridge configurations.
- * Those functions are only used by UART transport, in RAM transport configuration
- * they can be called directly in bridge mode controller code is on other core
- * and those can't be called.
- */
-void
-ble_ll_data_buffer_overflow(void)
-{
-
-}
-
-void
-ble_ll_hw_error(uint8_t err)
-{
-    (void)err;
-}
-#endif
+static struct hci_h4_sm hci_nrf5340_h4sm;
 
 static int
-ble_hci_trans_acl_tx(struct os_mbuf *om)
+nrf5340_ble_hci_acl_tx(struct os_mbuf *om)
 {
-    uint8_t ind = HCI_PKT_ACL;
+    uint8_t ind = HCI_H4_ACL;
     struct os_mbuf *x;
     int rc;
 
@@ -168,25 +59,66 @@ ble_hci_trans_acl_tx(struct os_mbuf *om)
     return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0;
 }
 
-static void nrf5340_ble_hci_trans_rx(int channel, void *user_data);
+static int
+nrf5340_ble_hci_frame_cb(uint8_t pkt_type, void *data)
+{
+    int rc;
 
+    switch (pkt_type) {
 #if MYNEWT_VAL(BLE_CONTROLLER)
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb, void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb, void *acl_arg)
+    case HCI_H4_CMD:
+        rc = ble_transport_to_ll_cmd(data);
+        break;
+#endif
+    case HCI_H4_ACL:
+#if MYNEWT_VAL(BLE_CONTROLLER)
+        rc = ble_transport_to_ll_acl(data);
+#else
+        rc = ble_transport_to_hs_acl(data);
+#endif
+        break;
+#if !MYNEWT_VAL(BLE_CONTROLLER)
+    case HCI_H4_EVT:
+        rc = ble_transport_to_hs_evt(data);
+        break;
+#endif
+    default:
+        assert(0);
+        break;
+    }
+
+    return rc;
+}
+
+static void
+nrf5340_ble_hci_trans_rx(int channel, void *user_data)
+{
+    uint8_t byte;
+    int rlen;
+
+    while (ipc_nrf5340_available(channel) > 0) {
+        rlen = ipc_nrf5340_read(channel, &byte, 1);
+        assert(rlen == 1);
+
+        rlen = hci_h4_sm_rx(&hci_nrf5340_h4sm, &byte, 1);
+        assert(rlen == 1);
+    }
+}
+
+static void
+nrf5340_ble_hci_init(void)
 {
-    nrf5340_ble_hci_api.cmd_cb = cmd_cb;
-    nrf5340_ble_hci_api.cmd_arg = cmd_arg;
-    nrf5340_ble_hci_api.acl_cb = acl_cb;
-    nrf5340_ble_hci_api.acl_arg = acl_arg;
+    SYSINIT_ASSERT_ACTIVE();
 
     ipc_nrf5340_recv(IPC_RX_CHANNEL, nrf5340_ble_hci_trans_rx, NULL);
 }
 
+#if MYNEWT_VAL(BLE_CONTROLLER)
 int
-ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
+ble_transport_to_hs_evt(void *buf)
 {
-    uint8_t ind = HCI_PKT_EVT;
+    uint8_t ind = HCI_H4_EVT;
+    uint8_t* hci_ev = buf;
     int len = 2 + hci_ev[1];
     int rc;
 
@@ -195,35 +127,32 @@ ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
         rc = ipc_nrf5340_send(IPC_TX_CHANNEL, hci_ev, len);
     }
 
-    ble_hci_trans_buf_free(hci_ev);
+    ble_transport_free(buf);
 
     return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0;
 }
 
 int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
+ble_transport_to_hs_acl(struct os_mbuf *om)
 {
-    return ble_hci_trans_acl_tx(om);
+    return nrf5340_ble_hci_acl_tx(om);
 }
-#endif
 
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
 void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb, void *evt_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb, void *acl_arg)
+ble_transport_hs_init(void)
 {
-    nrf5340_ble_hci_api.evt_cb = evt_cb;
-    nrf5340_ble_hci_api.evt_arg = evt_arg;
-    nrf5340_ble_hci_api.acl_cb = acl_cb;
-    nrf5340_ble_hci_api.acl_arg = acl_arg;
-
-    ipc_nrf5340_recv(IPC_RX_CHANNEL, nrf5340_ble_hci_trans_rx, NULL);
+    hci_h4_sm_init(&hci_nrf5340_h4sm, &hci_h4_allocs_from_hs,
+                   nrf5340_ble_hci_frame_cb);
+    nrf5340_ble_hci_init();
 }
+#endif /* BLE_CONTROLLER */
 
+#if !MYNEWT_VAL(BLE_CONTROLLER)
 int
-ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
+ble_transport_to_ll_cmd(void *buf)
 {
-    uint8_t ind = HCI_PKT_CMD;
+    uint8_t ind = HCI_H4_CMD;
+    uint8_t *cmd = buf;
     int len = 3 + cmd[2];
     int rc;
 
@@ -232,289 +161,22 @@ ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
         rc = ipc_nrf5340_send(IPC_TX_CHANNEL, cmd, len);
     }
 
-    ble_hci_trans_buf_free(cmd);
+    ble_transport_free(buf);
 
     return (rc < 0) ? BLE_ERR_MEM_CAPACITY :  0;
 }
 
 int
-ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
+ble_transport_to_ll_acl(struct os_mbuf *om)
 {
-    return ble_hci_trans_acl_tx(om);
-}
-#endif
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        buf = os_memblock_get(&nrf5340_ble_hci_pool_cmd_mempool);
-        break;
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&nrf5340_ble_hci_pool_evt_hi);
-        if (buf) {
-            break;
-        }
-        /* no break */
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&nrf5340_ble_hci_pool_evt_lo);
-        break;
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
+    return nrf5340_ble_hci_acl_tx(om);
 }
 
 void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    if (os_memblock_from(&nrf5340_ble_hci_pool_cmd_mempool, buf)) {
-        rc = os_memblock_put(&nrf5340_ble_hci_pool_cmd_mempool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&nrf5340_ble_hci_pool_evt_hi, buf)) {
-        rc = os_memblock_put(&nrf5340_ble_hci_pool_evt_hi, buf);
-        assert(rc == 0);
-    } else {
-        assert(os_memblock_from(&nrf5340_ble_hci_pool_evt_lo, buf));
-        rc = os_memblock_put(&nrf5340_ble_hci_pool_evt_lo, buf);
-        assert(rc == 0);
-    }
-}
-#endif
-
-static void
-nrf5340_ble_hci_trans_rx_process(int channel)
+ble_transport_ll_init(void)
 {
-    struct nrf5340_ble_hci_rx_data *rxd = &nrf5340_ble_hci_rx_data;
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    int pool = BLE_HCI_TRANS_BUF_EVT_HI;
-#endif
-    int rc;
-
-    switch (rxd->type) {
-    case HCI_PKT_NONE:
-        ipc_nrf5340_read(channel, &rxd->type, 1);
-        rxd->len = 0;
-        rxd->expected_len = 0;
-
-#if MYNEWT_VAL(BLE_CONTROLLER)
-        assert((rxd->type == HCI_PKT_ACL) || (rxd->type == HCI_PKT_CMD));
-#endif
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-        assert((rxd->type == HCI_PKT_ACL) || (rxd->type == HCI_PKT_EVT));
-#endif
-        break;
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    case HCI_PKT_CMD:
-        /* header */
-        if (rxd->len < 3) {
-            rxd->len += ipc_nrf5340_read(channel, &rxd->hdr[rxd->len],
-                                         3 - rxd->len);
-            if (rxd->len < 3) {
-                break;
-            }
-        }
-
-        if (rxd->expected_len == 0) {
-            rxd->buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-            memcpy(rxd->buf, rxd->hdr, rxd->len);
-
-            rxd->expected_len = 3 + rxd->hdr[2];
-        }
-
-        if (rxd->len < rxd->expected_len) {
-            rxd->len += ipc_nrf5340_read(channel, &rxd->buf[rxd->len],
-                                         rxd->expected_len - rxd->len);
-            if (rxd->len < rxd->expected_len) {
-                break;
-            }
-        }
-
-        rc = nrf5340_ble_hci_api.cmd_cb(rxd->buf, nrf5340_ble_hci_api.cmd_arg);
-        if (rc != 0) {
-            ble_hci_trans_buf_free(rxd->buf);
-        }
-
-        rxd->type = HCI_PKT_NONE;
-        break;
-#endif
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case HCI_PKT_EVT:
-        /* header */
-        if (rxd->len < 2) {
-            rxd->len += ipc_nrf5340_read(channel, &rxd->hdr[rxd->len],
-                                         2 - rxd->len);
-            if (rxd->len < 2) {
-                break;
-            }
-        }
-
-        if (rxd->hdr[0] == BLE_HCI_EVCODE_LE_META) {
-            if (rxd->len < 3) {
-                /* For LE Meta event we need 3 bytes to parse header */
-                rxd->len += ipc_nrf5340_read(channel, &rxd->hdr[rxd->len], 1);
-                if (rxd->len < 3) {
-                    break;
-                }
-            }
-
-            /* Advertising reports shall be allocated from low-prio pool */
-            if ((rxd->hdr[2] == BLE_HCI_LE_SUBEV_ADV_RPT) ||
-                (rxd->hdr[2] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) {
-                pool = BLE_HCI_TRANS_BUF_EVT_LO;
-            }
-        }
-
-        if (rxd->expected_len == 0) {
-            rxd->buf = ble_hci_trans_buf_alloc(pool);
-            if (!rxd->buf) {
-                /*
-                 * Only care about valid buffer when shall be allocated from
-                 * high-prio pool, otherwise NULL is fine and we'll just skip
-                 * this event.
-                 */
-                if (pool != BLE_HCI_TRANS_BUF_EVT_LO) {
-                    rxd->buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
-                }
-            }
-
-            rxd->expected_len = 2 + rxd->hdr[1];
-
-            /* copy header */
-            if (rxd->buf) {
-                memcpy(rxd->buf, rxd->hdr, rxd->len);
-            }
-        }
-
-        if (rxd->buf) {
-            rxd->len += ipc_nrf5340_read(channel, &rxd->buf[rxd->len],
-                                         rxd->expected_len - rxd->len);
-            if (rxd->len < rxd->expected_len) {
-                break;
-            }
-
-            rc = nrf5340_ble_hci_api.evt_cb(rxd->buf,
-                                            nrf5340_ble_hci_api.evt_arg);
-            if (rc != 0) {
-                ble_hci_trans_buf_free(rxd->buf);
-            }
-        } else {
-            rxd->len += ipc_nrf5340_consume(channel,
-                                            rxd->expected_len - rxd->len);
-            if (rxd->len < rxd->expected_len) {
-                break;
-            }
-        }
-
-        rxd->type = HCI_PKT_NONE;
-        break;
-#endif
-    case HCI_PKT_ACL:
-        if (rxd->len < 4) {
-            rxd->len += ipc_nrf5340_read(channel, &rxd->hdr[rxd->len],
-                                         4 - rxd->len);
-            if (rxd->len < 4) {
-                break;
-            }
-        }
-
-        /* Parse header and allocate proper buffer if not done yet */
-        if (rxd->expected_len == 0) {
-            rxd->om = os_mbuf_get_pkthdr(&nrf5340_ble_hci_pool_acl_mbuf,
-                                         sizeof(struct ble_mbuf_hdr));
-            if (!rxd->om) {
-                /* TODO not much we can do here... */
-                assert(0);
-            }
-
-            os_mbuf_append(rxd->om, rxd->hdr, rxd->len);
-            rxd->expected_len = get_le16(&rxd->hdr[2]) + 4;
-        }
-
-        if (rxd->len != rxd->expected_len) {
-            rxd->len += ipc_nrf5340_read_om(channel, rxd->om,
-                                            rxd->expected_len - rxd->len);
-        }
-
-        if (rxd->len == rxd->expected_len) {
-            rc = nrf5340_ble_hci_api.acl_cb(rxd->om,
-                                            nrf5340_ble_hci_api.acl_arg);
-            if (rc != 0) {
-                os_mbuf_free_chain(rxd->om);
-            }
-            rxd->type = HCI_PKT_NONE;
-        }
-        break;
-    default:
-        assert(0);
-        break;
-    }
-}
-
-static void
-nrf5340_ble_hci_trans_rx(int channel, void *user_data)
-{
-    while (ipc_nrf5340_available(channel) > 0) {
-        nrf5340_ble_hci_trans_rx_process(channel);
-    }
-}
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-int
-ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
-{
-    nrf5340_ble_hci_pool_acl.mpe_put_cb = cb;
-    nrf5340_ble_hci_pool_acl.mpe_put_arg = arg;
-
-    return 0;
-}
-#endif
-
-void
-nrf5340_ble_hci_init(void)
-{
-    int rc;
-
-    SYSINIT_ASSERT_ACTIVE();
-
-    rc = os_mempool_ext_init(&nrf5340_ble_hci_pool_acl,
-                             MYNEWT_VAL(BLE_ACL_BUF_COUNT), POOL_ACL_BLOCK_SIZE,
-                             nrf5340_ble_hci_pool_acl_buf,
-                             "nrf5340_ble_hci_pool_acl");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&nrf5340_ble_hci_pool_acl_mbuf,
-                           &nrf5340_ble_hci_pool_acl.mpe_mp, POOL_ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-    rc = os_mempool_init(&nrf5340_ble_hci_pool_evt_hi,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         nrf5340_ble_hci_pool_evt_hi_buf,
-                         "nrf5340_ble_hci_pool_evt_hi");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&nrf5340_ble_hci_pool_evt_lo,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         nrf5340_ble_hci_pool_evt_lo_buf,
-                         "nrf5340_ble_hci_pool_evt_lo");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&nrf5340_ble_hci_pool_cmd_mempool,
-                         HCI_CMD_COUNT, BLE_HCI_TRANS_CMD_SZ,
-                         nrf5340_ble_hci_pool_cmd_mempool_buf,
-                         "nrf5340_ble_hci_pool_cmd_mempool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-#endif
+    hci_h4_sm_init(&hci_nrf5340_h4sm, &hci_h4_allocs_from_ll,
+                   nrf5340_ble_hci_frame_cb);
+    nrf5340_ble_hci_init();
 }
+#endif /* !BLE_CONTROLLER */

[mynewt-nimble] 18/22: apps/blehcibridge: Remove app

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit fc4b2deaad4c36f6f6c0e00d000c8e9d37fb886d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Mar 8 07:54:03 2022 +0100

    apps/blehcibridge: Remove app
    
    There's no need for separate bridge app, blehci can now work as a bridge
    using new transport architecture.
---
 apps/blehcibridge/pkg.yml    | 34 ----------------------
 apps/blehcibridge/src/main.c | 69 --------------------------------------------
 apps/blehcibridge/syscfg.yml | 29 -------------------
 3 files changed, 132 deletions(-)

diff --git a/apps/blehcibridge/pkg.yml b/apps/blehcibridge/pkg.yml
deleted file mode 100644
index 5acd2e7..0000000
--- a/apps/blehcibridge/pkg.yml
+++ /dev/null
@@ -1,34 +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.
-#
-pkg.name: apps/blehcibridge
-pkg.type: app
-pkg.description: BLE controller application exposing HCI over external interface
-pkg.author: "Jerzy Kasenberg <je...@codecoup.pl>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-
-pkg.deps:
-    - "@apache-mynewt-core/sys/console"
-    - "@apache-mynewt-core/sys/log/stub"
-    - "@apache-mynewt-core/sys/stats/full"
-    - "@apache-mynewt-core/kernel/os"
-    - "@apache-mynewt-core/sys/shell"
-    - nimble/transport
-
-pkg.req_apis:
-    - ble_transport
diff --git a/apps/blehcibridge/src/main.c b/apps/blehcibridge/src/main.c
deleted file mode 100644
index 620cc37..0000000
--- a/apps/blehcibridge/src/main.c
+++ /dev/null
@@ -1,69 +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 <assert.h>
-#include <os/mynewt.h>
-#include <nimble/ble_hci_trans.h>
-
-static int
-forward_cmd_to_controller(uint8_t *cmdbuf, void *arg)
-{
-    (void)arg;
-
-    return ble_hci_trans_hs_cmd_tx(cmdbuf);
-}
-
-int
-forward_acl_to_controller(struct os_mbuf *om, void *arg)
-{
-    (void)arg;
-
-    return ble_hci_trans_hs_acl_tx(om);
-}
-
-static int
-forward_evt_to_host(uint8_t *hci_ev, void *arg)
-{
-    (void)arg;
-
-    return ble_hci_trans_ll_evt_tx(hci_ev);
-}
-
-int
-forward_acl_to_host(struct os_mbuf *om, void *arg)
-{
-    (void)arg;
-
-    return ble_hci_trans_ll_acl_tx(om);
-}
-
-int
-main(void)
-{
-    /* Initialize OS */
-    sysinit();
-
-    ble_hci_trans_cfg_hs(forward_evt_to_host, NULL, forward_acl_to_host, NULL);
-    ble_hci_trans_cfg_ll(forward_cmd_to_controller, NULL, forward_acl_to_controller, NULL);
-
-    while (1) {
-        os_eventq_run(os_eventq_dflt_get());
-    }
-    return 0;
-}
diff --git a/apps/blehcibridge/syscfg.yml b/apps/blehcibridge/syscfg.yml
deleted file mode 100644
index 203ec25..0000000
--- a/apps/blehcibridge/syscfg.yml
+++ /dev/null
@@ -1,29 +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.
-#
-
-syscfg.vals:
-    # Default task settings
-    OS_MAIN_STACK_SIZE: 64
-    # Use USB transport by default
-    BLE_HCI_TRANSPORT: usb
-    # Stub console
-    CONSOLE_MODE: stub
-
-    SHELL_TASK: 1
-
-    BLE_HCI_BRIDGE: 1

[mynewt-nimble] 01/22: nimble/transport: Add common HCI H4 code

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit a8e4aeb87e79641a5ea046ba7cf900d1729dae26
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 16:10:31 2022 +0100

    nimble/transport: Add common HCI H4 code
    
    This can be shared by UART, CMAC and nRF5340.
---
 .../hci_h4/include/nimble/transport/hci_h4.h       |  68 +++++
 nimble/transport/common/hci_h4/pkg.yml             |  26 ++
 nimble/transport/common/hci_h4/src/hci_h4.c        | 304 +++++++++++++++++++++
 3 files changed, 398 insertions(+)

diff --git a/nimble/transport/common/hci_h4/include/nimble/transport/hci_h4.h b/nimble/transport/common/hci_h4/include/nimble/transport/hci_h4.h
new file mode 100644
index 0000000..139160a
--- /dev/null
+++ b/nimble/transport/common/hci_h4/include/nimble/transport/hci_h4.h
@@ -0,0 +1,68 @@
+/*
+ * 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 _HCI_H4_H_
+#define _HCI_H4_H_
+
+#include <stdint.h>
+
+#define HCI_H4_NONE      0x00
+#define HCI_H4_CMD       0x01
+#define HCI_H4_ACL       0x02
+#define HCI_H4_EVT       0x04
+#define HCI_H4_ISO       0x05
+
+typedef void *(hci_h4_alloc_cmd)(void);
+typedef void *(hci_h4_alloc_evt)(int);
+typedef struct os_mbuf *(hci_h4_alloc_acl)(void);
+
+struct hci_h4_allocators {
+    hci_h4_alloc_cmd *cmd;
+    hci_h4_alloc_acl *acl;
+    hci_h4_alloc_evt *evt;
+};
+
+extern const struct hci_h4_allocators hci_h4_allocs_from_ll;
+extern const struct hci_h4_allocators hci_h4_allocs_from_hs;
+
+typedef int (hci_h4_frame_cb)(uint8_t pkt_type, void *data);
+
+struct hci_h4_sm {
+    uint8_t state;
+    uint8_t pkt_type;
+    uint8_t min_len;
+    uint16_t len;
+    uint16_t exp_len;
+    uint8_t hdr[4];
+    union {
+        uint8_t *buf;
+        struct os_mbuf *om;
+    };
+
+    const struct hci_h4_allocators *allocs;
+    hci_h4_frame_cb *frame_cb;
+};
+
+void hci_h4_sm_init(struct hci_h4_sm *h4sm,
+                    const struct hci_h4_allocators *allocs,
+                    hci_h4_frame_cb *frame_cb);
+
+int hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len);
+
+#endif /* _HCI_H4_H_ */
diff --git a/nimble/transport/common/hci_h4/pkg.yml b/nimble/transport/common/hci_h4/pkg.yml
new file mode 100644
index 0000000..24c4b58
--- /dev/null
+++ b/nimble/transport/common/hci_h4/pkg.yml
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+pkg.name: nimble/transport/common/hci_h4
+pkg.description: HCI H4 protocol
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "https://mynewt.apache.org/"
+
+pkg.deps:
+    - nimble
diff --git a/nimble/transport/common/hci_h4/src/hci_h4.c b/nimble/transport/common/hci_h4/src/hci_h4.c
new file mode 100644
index 0000000..ac76ab0
--- /dev/null
+++ b/nimble/transport/common/hci_h4/src/hci_h4.c
@@ -0,0 +1,304 @@
+/*
+ * 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 <stdint.h>
+#include <string.h>
+#include <syscfg/syscfg.h>
+#include <os/os.h>
+#include <os/os_mbuf.h>
+#include <nimble/hci_common.h>
+#include <nimble/transport.h>
+#include <nimble/transport/hci_h4.h>
+
+#define HCI_H4_SM_W4_PKT_TYPE   0
+#define HCI_H4_SM_W4_HEADER     1
+#define HCI_H4_SM_W4_PAYLOAD    2
+#define HCI_H4_SM_COMPLETED     3
+
+const struct hci_h4_allocators hci_h4_allocs_from_ll = {
+    .acl = ble_transport_alloc_acl_from_ll,
+    .evt = ble_transport_alloc_evt,
+};
+const struct hci_h4_allocators hci_h4_allocs_from_hs = {
+    .cmd = ble_transport_alloc_cmd,
+    .acl = ble_transport_alloc_acl_from_hs,
+};
+
+struct hci_h4_input_buffer {
+    const uint8_t *buf;
+    uint16_t len;
+};
+
+static void
+hci_h4_frame_start(struct hci_h4_sm *rxs, uint8_t pkt_type)
+{
+    rxs->pkt_type = pkt_type;
+    rxs->len = 0;
+    rxs->exp_len = 0;
+
+    switch (rxs->pkt_type) {
+    case HCI_H4_CMD:
+        rxs->min_len = 3;
+        break;
+    case HCI_H4_ACL:
+        rxs->min_len = 4;
+        break;
+    case HCI_H4_EVT:
+        rxs->min_len = 2;
+        break;
+    default:
+        /* XXX sync loss */
+        assert(0);
+        break;
+    }
+}
+
+static int
+hci_h4_ib_consume(struct hci_h4_input_buffer *ib, uint16_t len)
+{
+    assert(ib->len >= len);
+
+    ib->buf += len;
+    ib->len -= len;
+
+    return len;
+}
+
+static int
+hci_h4_ib_pull_min_len(struct hci_h4_sm *rxs,
+                       struct hci_h4_input_buffer *ib)
+{
+    uint16_t len;
+
+    len = min(ib->len, rxs->min_len - rxs->len);
+    memcpy(&rxs->hdr[rxs->len], ib->buf, len);
+
+    rxs->len += len;
+    hci_h4_ib_consume(ib, len);
+
+    return rxs->len != rxs->min_len;
+}
+
+static int
+hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
+{
+    int rc;
+
+    rc = hci_h4_ib_pull_min_len(h4sm, ib);
+    if (rc) {
+        /* need more data */
+        return 1;
+    }
+
+    switch (h4sm->pkt_type) {
+    case HCI_H4_CMD:
+        assert(h4sm->allocs && h4sm->allocs->cmd);
+        h4sm->buf = h4sm->allocs->cmd();
+        if (!h4sm->buf) {
+            return -1;
+        }
+
+        memcpy(h4sm->buf, h4sm->hdr, h4sm->len);
+        h4sm->exp_len = h4sm->hdr[2] + 3;
+        break;
+    case HCI_H4_ACL:
+        assert(h4sm->allocs && h4sm->allocs->acl);
+        h4sm->om = h4sm->allocs->acl();
+        if (!h4sm->om) {
+            return -1;
+        }
+
+        os_mbuf_append(h4sm->om, h4sm->hdr, h4sm->len);
+        h4sm->exp_len = get_le16(&h4sm->hdr[2]) + 4;
+        break;
+    case HCI_H4_EVT:
+        if (h4sm->hdr[0] == BLE_HCI_EVCODE_LE_META) {
+            /* For LE Meta event we need 3 bytes to parse header */
+            h4sm->min_len = 3;
+            rc = hci_h4_ib_pull_min_len(h4sm, ib);
+            if (rc) {
+                /* need more data */
+                return 1;
+            }
+        }
+
+        /* TODO lo/hi pool? */
+
+        assert(h4sm->allocs && h4sm->allocs->evt);
+        h4sm->buf = h4sm->allocs->evt(0);
+        if (!h4sm->buf) {
+            return -1;
+        }
+
+        memcpy(h4sm->buf, h4sm->hdr, h4sm->len);
+
+        h4sm->exp_len = h4sm->hdr[1] + 2;
+        break;
+    default:
+        assert(0);
+        break;
+    }
+
+    return 0;
+}
+
+static int
+hci_h4_sm_w4_payload(struct hci_h4_sm *h4sm,
+                     struct hci_h4_input_buffer *ib)
+{
+    uint16_t mbuf_len;
+    uint16_t len;
+    int rc;
+
+    len = min(ib->len, h4sm->exp_len - h4sm->len);
+
+    switch (h4sm->pkt_type) {
+    case HCI_H4_CMD:
+    case HCI_H4_EVT:
+        if (h4sm->buf) {
+            memcpy(&h4sm->buf[h4sm->len], ib->buf, len);
+        }
+        break;
+    case HCI_H4_ACL:
+        assert(h4sm->om);
+
+        mbuf_len = OS_MBUF_PKTLEN(h4sm->om);
+        rc = os_mbuf_append(h4sm->om, ib->buf, len);
+        if (rc) {
+            /* Some data may already be appended so need to adjust h4sm only by
+             * the size of appended data.
+             */
+            len = OS_MBUF_PKTLEN(h4sm->om) - mbuf_len;
+            h4sm->len += len;
+            hci_h4_ib_consume(ib, len);
+
+            return -1;
+        }
+        break;
+    default:
+        assert(0);
+        break;
+    }
+
+    h4sm->len += len;
+    hci_h4_ib_consume(ib, len);
+
+    /* return 1 if need more data */
+    return h4sm->len != h4sm->exp_len;
+}
+
+static void
+hci_h4_sm_completed(struct hci_h4_sm *h4sm)
+{
+    int rc;
+
+    switch (h4sm->pkt_type) {
+    case HCI_H4_CMD:
+    case HCI_H4_EVT:
+        if (h4sm->buf) {
+            assert(h4sm->frame_cb);
+            rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->buf);
+            if (rc != 0) {
+                ble_transport_free(h4sm->buf);
+            }
+            h4sm->buf = NULL;
+        }
+        break;
+    case HCI_H4_ACL:
+        if (h4sm->om) {
+            assert(h4sm->frame_cb);
+            rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->om);
+            if (rc != 0) {
+                os_mbuf_free_chain(h4sm->om);
+            }
+            h4sm->om = NULL;
+        }
+        break;
+    default:
+        assert(0);
+        break;
+    }
+}
+
+int
+hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len)
+{
+    struct hci_h4_input_buffer ib = {
+        .buf = buf,
+        .len = len,
+    };
+
+    int rc = 0;
+    while (ib.len && (rc >= 0)) {
+        rc = 0;
+        switch (h4sm->state) {
+        case HCI_H4_SM_W4_PKT_TYPE:
+            hci_h4_frame_start(h4sm, ib.buf[0]);
+            hci_h4_ib_consume(&ib, 1);
+            h4sm->state = HCI_H4_SM_W4_HEADER;
+        /* no break */
+        case HCI_H4_SM_W4_HEADER:
+            rc = hci_h4_sm_w4_header(h4sm, &ib);
+            if (rc) {
+                break;
+            }
+            h4sm->state = HCI_H4_SM_W4_PAYLOAD;
+        /* no break */
+        case HCI_H4_SM_W4_PAYLOAD:
+            rc = hci_h4_sm_w4_payload(h4sm, &ib);
+            if (rc) {
+                break;
+            }
+            h4sm->state = HCI_H4_SM_COMPLETED;
+        /* no break */
+        case HCI_H4_SM_COMPLETED:
+            hci_h4_sm_completed(h4sm);
+            h4sm->state = HCI_H4_SM_W4_PKT_TYPE;
+            break;
+        default:
+            assert(0);
+            break;
+        }
+    }
+
+    /* Calculate consumed bytes
+     *
+     * Note: we should always consume some bytes unless there is an oom error.
+     * It's also possible that we have an oom error but already consumed some
+     * data, in such case just return success and error will be returned on next
+     * pass.
+     */
+    len = len - ib.len;
+    if (len == 0) {
+        assert(rc < 0);
+        return -1;
+    }
+
+    return len;
+}
+
+void
+hci_h4_sm_init(struct hci_h4_sm *h4sm, const struct hci_h4_allocators *allocs,
+               hci_h4_frame_cb *frame_cb)
+{
+    memset(h4sm, 0, sizeof(*h4sm));
+    h4sm->allocs = allocs;
+    h4sm->frame_cb = frame_cb;
+}

[mynewt-nimble] 19/22: nimble/test: Update for new transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit d7e5d6fc35748b1e97d51e5aa3b263ca48d22dfb
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 10 11:21:18 2022 +0100

    nimble/test: Update for new transport
---
 nimble/controller/test/syscfg.yml           |  1 -
 nimble/host/test/pkg.yml                    |  3 +++
 nimble/host/test/src/ble_hs_hci_test.c      |  4 ++--
 nimble/host/test/src/ble_hs_test_util.c     | 23 ++++++++++++-----------
 nimble/host/test/src/ble_hs_test_util_hci.c |  6 ++----
 nimble/host/test/src/ble_os_test.c          |  1 -
 nimble/host/test/syscfg.yml                 |  2 +-
 7 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/nimble/controller/test/syscfg.yml b/nimble/controller/test/syscfg.yml
index 4448a0e..6edad43 100644
--- a/nimble/controller/test/syscfg.yml
+++ b/nimble/controller/test/syscfg.yml
@@ -23,4 +23,3 @@ syscfg.vals:
     MCU_TIMER_POLLER_PRIO: 1
     MCU_UART_POLLER_PRIO: 2
     NATIVE_SOCKETS_PRIO: 3
-    BLE_HCI_TRANSPORT: ram
diff --git a/nimble/host/test/pkg.yml b/nimble/host/test/pkg.yml
index cb5d97c..1698043 100644
--- a/nimble/host/test/pkg.yml
+++ b/nimble/host/test/pkg.yml
@@ -32,3 +32,6 @@ pkg.deps.SELFTEST:
     - "@apache-mynewt-core/sys/log/full"
     - "@apache-mynewt-core/sys/stats/stub"
     - nimble/transport
+
+pkg.apis:
+    - ble_driver
diff --git a/nimble/host/test/src/ble_hs_hci_test.c b/nimble/host/test/src/ble_hs_hci_test.c
index 5f72742..8dd7c77 100644
--- a/nimble/host/test/src/ble_hs_hci_test.c
+++ b/nimble/host/test/src/ble_hs_hci_test.c
@@ -21,7 +21,7 @@
 #include <errno.h>
 #include <string.h>
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
+#include "nimble/transport.h"
 #include "ble_hs_test.h"
 #include "testutil/testutil.h"
 #include "ble_hs_test_util.h"
@@ -34,7 +34,7 @@ TEST_CASE_SELF(ble_hs_hci_test_event_bad)
     int rc;
 
     /*** Invalid event code. */
-    buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    buf = ble_transport_alloc_evt(0);
     TEST_ASSERT_FATAL(buf != NULL);
 
     buf[0] = 0xff;
diff --git a/nimble/host/test/src/ble_hs_test_util.c b/nimble/host/test/src/ble_hs_test_util.c
index 5ee17e7..6a83816 100644
--- a/nimble/host/test/src/ble_hs_test_util.c
+++ b/nimble/host/test/src/ble_hs_test_util.c
@@ -24,11 +24,9 @@
 #include "testutil/testutil.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "host/ble_hs_adv.h"
 #include "host/ble_hs_id.h"
 #include "store/config/ble_store_config.h"
-#include "transport/ram/ble_hci_ram.h"
 #include "ble_hs_test_util.h"
 
 /* Our global device address. */
@@ -1850,18 +1848,18 @@ ble_hs_test_util_assert_mbufs_freed(
     TEST_ASSERT(count == ble_hs_test_util_num_mbufs());
 }
 
-static int
-ble_hs_test_util_pkt_txed(struct os_mbuf *om, void *arg)
+int
+ble_transport_to_ll_acl(struct os_mbuf *om)
 {
     ble_hs_test_util_prev_tx_enqueue(om);
     return 0;
 }
 
-static int
-ble_hs_test_util_hci_txed(uint8_t *cmdbuf, void *arg)
+int
+ble_transport_to_ll_cmd(void *buf)
 {
-    ble_hs_test_util_hci_out_enqueue(cmdbuf);
-    ble_hci_trans_buf_free(cmdbuf);
+    ble_hs_test_util_hci_out_enqueue(buf);
+    ble_transport_free(buf);
     return 0;
 }
 
@@ -2003,9 +2001,6 @@ ble_hs_test_util_init_no_sysinit_no_start(void)
 
     ble_hs_hci_set_phony_ack_cb(NULL);
 
-    ble_hci_trans_cfg_ll(ble_hs_test_util_hci_txed, NULL,
-                         ble_hs_test_util_pkt_txed, NULL);
-
     ble_hs_test_util_hci_ack_set_startup();
 
     ble_hs_enabled_state = BLE_HS_ENABLED_STATE_OFF;
@@ -2046,3 +2041,9 @@ ble_hs_test_util_init(void)
     /* Clear random address. */
     ble_hs_id_rnd_reset();
 }
+
+void
+ble_transport_ll_init(void)
+{
+    /* nothing here */
+}
\ No newline at end of file
diff --git a/nimble/host/test/src/ble_hs_test_util_hci.c b/nimble/host/test/src/ble_hs_test_util_hci.c
index a53c5d9..e8054c2 100644
--- a/nimble/host/test/src/ble_hs_test_util_hci.c
+++ b/nimble/host/test/src/ble_hs_test_util_hci.c
@@ -20,7 +20,6 @@
 #include "testutil/testutil.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "transport/ram/ble_hci_ram.h"
 #include "ble_hs_test_util.h"
 
 #define BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN  (5)
@@ -522,14 +521,13 @@ ble_hs_test_util_hci_rx_evt(uint8_t *evt)
     totlen = BLE_HCI_EVENT_HDR_LEN + evt[1];
     TEST_ASSERT_FATAL(totlen <= UINT8_MAX + BLE_HCI_EVENT_HDR_LEN);
 
-    evbuf = ble_hci_trans_buf_alloc(
-        BLE_HCI_TRANS_BUF_EVT_LO);
+    evbuf = ble_transport_alloc_evt(1);
     TEST_ASSERT_FATAL(evbuf != NULL);
 
     memcpy(evbuf, evt, totlen);
 
     if (os_started()) {
-        rc = ble_hci_trans_ll_evt_tx(evbuf);
+        rc = ble_transport_to_hs_evt(evbuf);
     } else {
         rc = ble_hs_hci_evt_process((void *)evbuf);
     }
diff --git a/nimble/host/test/src/ble_os_test.c b/nimble/host/test/src/ble_os_test.c
index fa57571..6588c67 100644
--- a/nimble/host/test/src/ble_os_test.c
+++ b/nimble/host/test/src/ble_os_test.c
@@ -21,7 +21,6 @@
 #include "os/os.h"
 #include "testutil/testutil.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "ble_hs_test.h"
 #include "host/ble_gap.h"
 #include "ble_hs_test_util.h"
diff --git a/nimble/host/test/syscfg.yml b/nimble/host/test/syscfg.yml
index 45bc638..031b6c8 100644
--- a/nimble/host/test/syscfg.yml
+++ b/nimble/host/test/syscfg.yml
@@ -29,4 +29,4 @@ syscfg.vals:
     CONFIG_FCB: 1
     BLE_VERSION: 52
     BLE_L2CAP_ENHANCED_COC: 1
-    BLE_HCI_TRANSPORT: ram
+    BLE_TRANSPORT_LL: custom

[mynewt-nimble] 08/22: nimble/transport: Update UART transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit aefb9d4a90effefc77500e8968eafd3f336c7d06
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:06:04 2022 +0100

    nimble/transport: Update UART transport
---
 .../uart/include/transport/uart/ble_hci_uart.h     |   33 -
 nimble/transport/uart/pkg.yml                      |   11 +-
 nimble/transport/uart/src/ble_hci_uart.c           | 1187 --------------------
 nimble/transport/uart/src/hci_uart.c               |  247 ++++
 nimble/transport/uart/syscfg.yml                   |   62 +-
 5 files changed, 270 insertions(+), 1270 deletions(-)

diff --git a/nimble/transport/uart/include/transport/uart/ble_hci_uart.h b/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
deleted file mode 100644
index e5e1084..0000000
--- a/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
+++ /dev/null
@@ -1,33 +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_BLE_HCI_UART_
-#define H_BLE_HCI_UART_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void ble_hci_uart_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/nimble/transport/uart/pkg.yml b/nimble/transport/uart/pkg.yml
index fd16a08..2802961 100644
--- a/nimble/transport/uart/pkg.yml
+++ b/nimble/transport/uart/pkg.yml
@@ -18,20 +18,15 @@
 #
 
 pkg.name: nimble/transport/uart
-pkg.description: XXX
+pkg.description: HCI H4 transport over UART
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble
-    - bluetooth
+pkg.homepage: "https://mynewt.apache.org/"
 
 pkg.deps:
     - "@apache-mynewt-core/hw/hal"
     - "@apache-mynewt-core/kernel/os"
     - nimble
+    - nimble/transport/common/hci_h4
 
 pkg.apis:
     - ble_transport
-
-pkg.init:
-    ble_hci_uart_init: 'MYNEWT_VAL(BLE_TRANS_UART_SYSINIT_STAGE)'
diff --git a/nimble/transport/uart/src/ble_hci_uart.c b/nimble/transport/uart/src/ble_hci_uart.c
deleted file mode 100644
index 0b6e0e5..0000000
--- a/nimble/transport/uart/src/ble_hci_uart.c
+++ /dev/null
@@ -1,1187 +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 <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdint.h>
-#include "sysinit/sysinit.h"
-#include "syscfg/syscfg.h"
-#include "os/os_cputime.h"
-#include "bsp/bsp.h"
-#include "os/os.h"
-#include "hal/hal_uart.h"
-
-/* BLE */
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-
-#include "transport/uart/ble_hci_uart.h"
-
-#define BLE_HCI_UART_EVT_COUNT  \
-    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
-
-/***
- * NOTES:
- * The UART HCI transport doesn't use event buffer priorities.  All incoming
- * and outgoing events use buffers from the same pool.
- *
- * The "skip" definitions are here so that when buffers cannot be allocated,
- * the command or acl packets are simply skipped so that the HCI interface
- * does not lose synchronization and resets dont (necessarily) occur.
- */
-
-/* XXX: for now, define this here */
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-extern void ble_ll_data_buffer_overflow(void);
-extern void ble_ll_hw_error(void);
-
-static const uint8_t ble_hci_uart_reset_cmd[4] = { 0x01, 0x03, 0x0C, 0x00 };
-#endif
-
-/***
- * NOTES:
- * The "skip" definitions are here so that when buffers cannot be allocated,
- * the command or acl packets are simply skipped so that the HCI interface
- * does not lose synchronization and resets dont (necessarily) occur.
- */
-#define BLE_HCI_UART_H4_NONE        0x00
-#define BLE_HCI_UART_H4_CMD         0x01
-#define BLE_HCI_UART_H4_ACL         0x02
-#define BLE_HCI_UART_H4_SCO         0x03
-#define BLE_HCI_UART_H4_EVT         0x04
-#define BLE_HCI_UART_H4_SYNC_LOSS   0x80
-#define BLE_HCI_UART_H4_SKIP_CMD    0x81
-#define BLE_HCI_UART_H4_SKIP_ACL    0x82
-#define BLE_HCI_UART_H4_LE_EVT      0x83
-#define BLE_HCI_UART_H4_SKIP_EVT    0x84
-
-static ble_hci_trans_rx_cmd_fn *ble_hci_uart_rx_cmd_cb;
-static void *ble_hci_uart_rx_cmd_arg;
-
-static ble_hci_trans_rx_acl_fn *ble_hci_uart_rx_acl_cb;
-static void *ble_hci_uart_rx_acl_arg;
-
-static struct os_mempool ble_hci_uart_evt_hi_pool;
-static os_membuf_t ble_hci_uart_evt_hi_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_uart_evt_lo_pool;
-static os_membuf_t ble_hci_uart_evt_lo_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_uart_cmd_pool;
-static os_membuf_t ble_hci_uart_cmd_buf[
-	OS_MEMPOOL_SIZE(1, BLE_HCI_TRANS_CMD_SZ)
-];
-
-static struct os_mbuf_pool ble_hci_uart_acl_mbuf_pool;
-static struct os_mempool_ext ble_hci_uart_acl_pool;
-
-/*
- * The MBUF payload size must accommodate the HCI data header size plus the
- * maximum ACL data packet length. The ACL block size is the size of the
- * mbufs we will allocate.
- */
-#define ACL_BLOCK_SIZE  OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) \
-                                 + BLE_MBUF_MEMBLOCK_OVERHEAD \
-                                 + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-
-static os_membuf_t ble_hci_uart_acl_buf[
-	OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                        ACL_BLOCK_SIZE)
-];
-
-/**
- * A packet to be sent over the UART.  This can be a command, an event, or ACL
- * data.
- */
-struct ble_hci_uart_pkt {
-    STAILQ_ENTRY(ble_hci_uart_pkt) next;
-    void *data;
-    uint8_t type;
-};
-
-static struct os_mempool ble_hci_uart_pkt_pool;
-static os_membuf_t ble_hci_uart_pkt_buf[
-        OS_MEMPOOL_SIZE(BLE_HCI_UART_EVT_COUNT + 1 +
-                        MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
-                        sizeof (struct ble_hci_uart_pkt))
-];
-
-/**
- * An incoming or outgoing command or event.
- */
-struct ble_hci_uart_cmd {
-    uint8_t *data;      /* Pointer to ble_hci_uart_cmd data */
-    uint16_t cur;       /* Number of bytes read/written */
-    uint16_t len;       /* Total number of bytes to read/write */
-};
-
-/**
- * An incoming ACL data packet.
- */
-struct ble_hci_uart_acl {
-    struct os_mbuf *buf; /* Buffer containing the data */
-    uint8_t *dptr;       /* Pointer to where bytes should be placed */
-    uint16_t len;        /* Target size when buf is considered complete */
-    uint16_t rxd_bytes;  /* current count of bytes received for packet */
-};
-
-/**
- * Structure for transmitting ACL packets over UART
- *
- */
-struct ble_hci_uart_h4_acl_tx
-{
-    uint8_t *dptr;
-    struct os_mbuf *tx_acl;
-};
-
-static struct {
-    /*** State of data received over UART. */
-    uint8_t rx_type;    /* Pending packet type. 0 means nothing pending */
-    union {
-        struct ble_hci_uart_cmd rx_cmd;
-        struct ble_hci_uart_acl rx_acl;
-    };
-
-    /*** State of data transmitted over UART. */
-    uint8_t tx_type;    /* Pending packet type. 0 means nothing pending */
-    uint16_t rem_tx_len; /* Used for acl tx only currently */
-    union {
-        struct ble_hci_uart_cmd tx_cmd;
-        struct ble_hci_uart_h4_acl_tx tx_pkt;
-    };
-    STAILQ_HEAD(, ble_hci_uart_pkt) tx_pkts; /* Packet queue to send to UART */
-} ble_hci_uart_state;
-
-/**
- * Allocates a buffer (mbuf) for ACL operation.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-static struct os_mbuf *
-ble_hci_trans_acl_buf_alloc(void)
-{
-    struct os_mbuf *m;
-    uint8_t usrhdr_len;
-
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    usrhdr_len = sizeof(struct ble_mbuf_hdr);
-#else
-    usrhdr_len = 0;
-#endif
-
-    m = os_mbuf_get_pkthdr(&ble_hci_uart_acl_mbuf_pool, usrhdr_len);
-    return m;
-}
-
-static int
-ble_hci_uart_acl_tx(struct os_mbuf *om)
-{
-    struct ble_hci_uart_pkt *pkt;
-    os_sr_t sr;
-
-    /* If this packet is zero length, just free it */
-    if (OS_MBUF_PKTLEN(om) == 0) {
-        os_mbuf_free_chain(om);
-        return 0;
-    }
-
-    pkt = os_memblock_get(&ble_hci_uart_pkt_pool);
-    if (pkt == NULL) {
-        os_mbuf_free_chain(om);
-        return BLE_ERR_MEM_CAPACITY;
-    }
-
-    pkt->type = BLE_HCI_UART_H4_ACL;
-    pkt->data = om;
-
-    OS_ENTER_CRITICAL(sr);
-    STAILQ_INSERT_TAIL(&ble_hci_uart_state.tx_pkts, pkt, next);
-    OS_EXIT_CRITICAL(sr);
-
-    hal_uart_start_tx(MYNEWT_VAL(BLE_HCI_UART_PORT));
-
-    return 0;
-}
-
-static int
-ble_hci_uart_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
-{
-    struct ble_hci_uart_pkt *pkt;
-    os_sr_t sr;
-
-    pkt = os_memblock_get(&ble_hci_uart_pkt_pool);
-    if (pkt == NULL) {
-        ble_hci_trans_buf_free(hci_ev);
-        return BLE_ERR_MEM_CAPACITY;
-    }
-
-    pkt->type = h4_type;
-    pkt->data = hci_ev;
-
-    OS_ENTER_CRITICAL(sr);
-    STAILQ_INSERT_TAIL(&ble_hci_uart_state.tx_pkts, pkt, next);
-    OS_EXIT_CRITICAL(sr);
-
-    hal_uart_start_tx(MYNEWT_VAL(BLE_HCI_UART_PORT));
-
-    return 0;
-}
-
-/**
- * @return                      The packet type to transmit on success;
- *                              -1 if there is nothing to send.
- */
-static int
-ble_hci_uart_tx_pkt_type(void)
-{
-    struct ble_hci_uart_pkt *pkt;
-    struct os_mbuf *om;
-    os_sr_t sr;
-    int rc;
-
-    OS_ENTER_CRITICAL(sr);
-
-    pkt = STAILQ_FIRST(&ble_hci_uart_state.tx_pkts);
-    if (!pkt) {
-        OS_EXIT_CRITICAL(sr);
-        return -1;
-    }
-
-    STAILQ_REMOVE(&ble_hci_uart_state.tx_pkts, pkt, ble_hci_uart_pkt, next);
-
-    OS_EXIT_CRITICAL(sr);
-
-    rc = pkt->type;
-    switch (pkt->type) {
-    case BLE_HCI_UART_H4_CMD:
-        ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_CMD;
-        ble_hci_uart_state.tx_cmd.data = pkt->data;
-        ble_hci_uart_state.tx_cmd.cur = 0;
-        ble_hci_uart_state.tx_cmd.len = ble_hci_uart_state.tx_cmd.data[2] +
-                                        sizeof(struct ble_hci_cmd);
-        break;
-
-    case BLE_HCI_UART_H4_EVT:
-        ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_EVT;
-        ble_hci_uart_state.tx_cmd.data = pkt->data;
-        ble_hci_uart_state.tx_cmd.cur = 0;
-        ble_hci_uart_state.tx_cmd.len = ble_hci_uart_state.tx_cmd.data[1] +
-                                        sizeof(struct ble_hci_ev);
-        break;
-
-    case BLE_HCI_UART_H4_ACL:
-        ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_ACL;
-        om = (struct os_mbuf *)pkt->data;
-        /* NOTE: first mbuf must have non-zero length */
-        os_mbuf_trim_front(om);
-        ble_hci_uart_state.tx_pkt.tx_acl = om;
-        ble_hci_uart_state.tx_pkt.dptr = om->om_data;
-        ble_hci_uart_state.rem_tx_len = OS_MBUF_PKTLEN(om);
-        break;
-
-    default:
-        rc = -1;
-        break;
-    }
-
-    os_memblock_put(&ble_hci_uart_pkt_pool, pkt);
-
-    return rc;
-}
-
-/**
- * @return                      The byte to transmit on success;
- *                              -1 if there is nothing to send.
- */
-static int
-ble_hci_uart_tx_char(void *arg)
-{
-    uint8_t u8;
-    int rc;
-    struct os_mbuf *om;
-
-    switch (ble_hci_uart_state.tx_type) {
-    case BLE_HCI_UART_H4_NONE: /* No pending packet, pick one from the queue */
-        rc = ble_hci_uart_tx_pkt_type();
-        break;
-
-    case BLE_HCI_UART_H4_CMD:
-    case BLE_HCI_UART_H4_EVT:
-        rc = ble_hci_uart_state.tx_cmd.data[ble_hci_uart_state.tx_cmd.cur++];
-
-        if (ble_hci_uart_state.tx_cmd.cur == ble_hci_uart_state.tx_cmd.len) {
-            ble_hci_trans_buf_free(ble_hci_uart_state.tx_cmd.data);
-            ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
-        }
-        break;
-
-    case BLE_HCI_UART_H4_ACL:
-        /* Copy the first unsent byte from the tx buffer and remove it from the
-         * source.
-         */
-        u8 = ble_hci_uart_state.tx_pkt.dptr[0];
-        --ble_hci_uart_state.rem_tx_len;
-        if (ble_hci_uart_state.rem_tx_len == 0) {
-            os_mbuf_free_chain(ble_hci_uart_state.tx_pkt.tx_acl);
-            ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
-        } else {
-            om = ble_hci_uart_state.tx_pkt.tx_acl;
-            --om->om_len;
-            if (om->om_len == 0) {
-                /* Remove and free any zero mbufs */
-                while ((om != NULL) && (om->om_len == 0)) {
-                    ble_hci_uart_state.tx_pkt.tx_acl = SLIST_NEXT(om, om_next);
-                    os_mbuf_free(om);
-                    om = ble_hci_uart_state.tx_pkt.tx_acl;
-                }
-                /* NOTE: om should never be NULL! What to do? */
-                if (om == NULL) {
-                    assert(0);
-                    ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
-                } else {
-                    ble_hci_uart_state.tx_pkt.dptr = om->om_data;
-                }
-            } else {
-                ble_hci_uart_state.tx_pkt.dptr++;
-            }
-        }
-        rc = u8;
-        break;
-    default:
-        rc = -1;
-        break;
-    }
-
-    return rc;
-}
-
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-/**
- * HCI uart sync lost.
- *
- * This occurs when the controller receives an invalid packet type or a length
- * field that is out of range. The controller needs to send a HW error to the
- * host and wait to find a LL reset command.
- */
-static void
-ble_hci_uart_sync_lost(void)
-{
-    ble_hci_uart_state.rx_cmd.len = 0;
-    ble_hci_uart_state.rx_cmd.cur = 0;
-    ble_hci_uart_state.rx_cmd.data =
-        ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-    ble_ll_hw_error();
-    ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_SYNC_LOSS;
-}
-#endif
-
-/**
- * @return                      The type of packet to follow success;
- *                              -1 if there is no valid packet to receive.
- */
-static int
-ble_hci_uart_rx_pkt_type(uint8_t data)
-{
-    struct os_mbuf *m;
-
-    ble_hci_uart_state.rx_type = data;
-
-    switch (ble_hci_uart_state.rx_type) {
-    /* Host should never receive a command! */
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case BLE_HCI_UART_H4_CMD:
-        ble_hci_uart_state.rx_cmd.len = 0;
-        ble_hci_uart_state.rx_cmd.cur = 0;
-        ble_hci_uart_state.rx_cmd.data =
-            ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-        if (ble_hci_uart_state.rx_cmd.data == NULL) {
-            ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_SKIP_CMD;
-        }
-        break;
-#endif
-
-        /* Controller should never receive an event */
-#if MYNEWT_VAL(BLE_HOST)
-    case BLE_HCI_UART_H4_EVT:
-        /*
-         * The event code is unknown at the moment. Depending on event priority,
-         * buffer *shall* be allocated from ble_hci_uart_evt_hi_pool
-         * or "may* be allocated from ble_hci_uart_evt_lo_pool.
-         * Thus do not allocate the buffer yet.
-         */
-        ble_hci_uart_state.rx_cmd.data = NULL;
-        ble_hci_uart_state.rx_cmd.len = 0;
-        ble_hci_uart_state.rx_cmd.cur = 0;
-        break;
-#endif
-
-    case BLE_HCI_UART_H4_ACL:
-        ble_hci_uart_state.rx_acl.len = 0;
-        ble_hci_uart_state.rx_acl.rxd_bytes = 0;
-        m = ble_hci_trans_acl_buf_alloc();
-        if (m) {
-            ble_hci_uart_state.rx_acl.dptr = m->om_data;
-        } else {
-            ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_SKIP_ACL;
-        }
-        ble_hci_uart_state.rx_acl.buf = m;
-        break;
-
-    default:
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-        /*
-         * If we receive an unknown HCI packet type this is considered a loss
-         * of sync.
-         */
-        ble_hci_uart_sync_lost();
-#else
-        /*
-         * XXX: not sure what to do about host in this case. Just go back to
-         * none for now.
-         */
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-#endif
-        break;
-    }
-
-    return 0;
-}
-
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-/**
- * HCI uart sync loss.
- *
- * Find a LL reset command in the byte stream. The LL reset command is a
- * sequence of 4 bytes:
- *  0x01    HCI Packet Type = HCI CMD
- *  0x03    OCF for reset command
- *  0x0C    OGF for reset command (0x03 shifted left by two bits as the OGF
- *          occupies the uopper 6 bits of this byte.
- *  0x00    Parameter length of reset command (no parameters).
- *
- * @param data Byte received over serial port
- */
-void
-ble_hci_uart_rx_sync_loss(uint8_t data)
-{
-    int rc;
-    int index;
-
-    /*
-     * If we couldnt allocate a command buffer (should not occur but
-     * possible) try to allocate one on each received character. If we get
-     * a reset and buffer is not available we have to ignore reset.
-     */
-    if (ble_hci_uart_state.rx_cmd.data == NULL) {
-        ble_hci_uart_state.rx_cmd.data =
-            ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-    }
-
-    index = ble_hci_uart_state.rx_cmd.cur;
-    if (data == ble_hci_uart_reset_cmd[index]) {
-        if (index == 3) {
-            if (ble_hci_uart_state.rx_cmd.data == NULL) {
-                index = 0;
-            } else {
-                assert(ble_hci_uart_rx_cmd_cb != NULL);
-                ble_hci_uart_state.rx_cmd.data[0] = 0x03;
-                ble_hci_uart_state.rx_cmd.data[1] = 0x0C;
-                ble_hci_uart_state.rx_cmd.data[2] = 0x00;
-                rc = ble_hci_uart_rx_cmd_cb(ble_hci_uart_state.rx_cmd.data,
-                                            ble_hci_uart_rx_cmd_arg);
-                if (rc != 0) {
-                    ble_hci_trans_buf_free(ble_hci_uart_state.rx_cmd.data);
-                }
-                ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-            }
-        } else {
-            ++index;
-        }
-    } else {
-        index = 0;
-    }
-
-    ble_hci_uart_state.rx_cmd.cur = index;
-}
-
-static void
-ble_hci_uart_rx_cmd(uint8_t data)
-{
-    int rc;
-
-    ble_hci_uart_state.rx_cmd.data[ble_hci_uart_state.rx_cmd.cur++] = data;
-
-    if (ble_hci_uart_state.rx_cmd.cur < sizeof(struct ble_hci_cmd)) {
-        return;
-    }
-
-    if (ble_hci_uart_state.rx_cmd.cur == sizeof(struct ble_hci_cmd)) {
-        ble_hci_uart_state.rx_cmd.len = ble_hci_uart_state.rx_cmd.data[2] +
-                                        sizeof(struct ble_hci_cmd);
-    }
-
-    if (ble_hci_uart_state.rx_cmd.cur == ble_hci_uart_state.rx_cmd.len) {
-        assert(ble_hci_uart_rx_cmd_cb != NULL);
-        rc = ble_hci_uart_rx_cmd_cb(ble_hci_uart_state.rx_cmd.data,
-                                    ble_hci_uart_rx_cmd_arg);
-        if (rc != 0) {
-            ble_hci_trans_buf_free(ble_hci_uart_state.rx_cmd.data);
-        }
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-    }
-}
-
-static void
-ble_hci_uart_rx_skip_cmd(uint8_t data)
-{
-    ble_hci_uart_state.rx_cmd.cur++;
-
-    if (ble_hci_uart_state.rx_cmd.cur < sizeof(struct ble_hci_cmd)) {
-        return;
-    }
-
-    if (ble_hci_uart_state.rx_cmd.cur == sizeof(struct ble_hci_cmd)) {
-        ble_hci_uart_state.rx_cmd.len = data + sizeof(struct ble_hci_cmd);
-    }
-
-    if (ble_hci_uart_state.rx_cmd.cur == ble_hci_uart_state.rx_cmd.len) {
-        /*
-         * XXX: for now we simply skip the command and do nothing. This
-         * should not happen but at least we retain HCI synch. The host
-         * can decide what to do in this case. It may be appropriate for
-         * the controller to attempt to send back a command complete or
-         * command status in this case.
-         */
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-    }
-}
-#endif
-
-#if MYNEWT_VAL(BLE_HOST)
-static inline void
-ble_hci_uart_rx_evt_cb(void)
-{
-    int rc;
-
-    if (ble_hci_uart_state.rx_cmd.cur == ble_hci_uart_state.rx_cmd.len) {
-        assert(ble_hci_uart_rx_cmd_cb != NULL);
-        rc = ble_hci_uart_rx_cmd_cb(ble_hci_uart_state.rx_cmd.data,
-                                    ble_hci_uart_rx_cmd_arg);
-        if (rc != 0) {
-            ble_hci_trans_buf_free(ble_hci_uart_state.rx_cmd.data);
-        }
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-    }
-}
-
-static void
-ble_hci_uart_rx_evt(uint8_t data)
-{
-    /* Determine event priority to allocate buffer */
-    if (!ble_hci_uart_state.rx_cmd.data) {
-        /* In case of LE Meta Event priority might be still unknown */
-        if (data == BLE_HCI_EVCODE_LE_META) {
-            ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_LE_EVT;
-            ble_hci_uart_state.rx_cmd.cur++;
-            return;
-        }
-
-        ble_hci_uart_state.rx_cmd.data =
-            ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
-        assert(ble_hci_uart_state.rx_cmd.data != NULL);
-    }
-
-    ble_hci_uart_state.rx_cmd.data[ble_hci_uart_state.rx_cmd.cur++] = data;
-
-    if (ble_hci_uart_state.rx_cmd.cur < sizeof(struct ble_hci_ev)) {
-        return;
-    }
-
-    if (ble_hci_uart_state.rx_cmd.cur == sizeof(struct ble_hci_ev)) {
-        ble_hci_uart_state.rx_cmd.len = ble_hci_uart_state.rx_cmd.data[1] +
-                                        sizeof(struct ble_hci_ev);
-    }
-
-    ble_hci_uart_rx_evt_cb();
-}
-
-static void
-ble_hci_uart_rx_le_evt(uint8_t data)
-{
-    ble_hci_uart_state.rx_cmd.cur++;
-
-    if (ble_hci_uart_state.rx_cmd.cur == sizeof(struct ble_hci_ev)) {
-        /* LE Meta Event parameter length is never 0 */
-        assert(data != 0);
-        ble_hci_uart_state.rx_cmd.len = data + sizeof(struct ble_hci_ev);
-        return;
-    }
-
-    /* Determine event priority to allocate buffer */
-    if (!ble_hci_uart_state.rx_cmd.data) {
-        /* Determine event priority to allocate buffer */
-        if (data == BLE_HCI_LE_SUBEV_ADV_RPT ||
-                data == BLE_HCI_LE_SUBEV_EXT_ADV_RPT) {
-            ble_hci_uart_state.rx_cmd.data =
-                ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
-            if (ble_hci_uart_state.rx_cmd.data == NULL) {
-                ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_SKIP_EVT;
-                return;
-            }
-        } else {
-            ble_hci_uart_state.rx_cmd.data =
-                ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
-            assert(ble_hci_uart_state.rx_cmd.data != NULL);
-        }
-
-        ble_hci_uart_state.rx_cmd.data[0] = BLE_HCI_EVCODE_LE_META;
-        ble_hci_uart_state.rx_cmd.data[1] =
-                ble_hci_uart_state.rx_cmd.len - sizeof(struct ble_hci_ev);
-    }
-
-    ble_hci_uart_state.rx_cmd.data[ble_hci_uart_state.rx_cmd.cur - 1] = data;
-    ble_hci_uart_rx_evt_cb();
-}
-
-static void
-ble_hci_uart_rx_skip_evt(uint8_t data)
-{
-    if (++ble_hci_uart_state.rx_cmd.cur == ble_hci_uart_state.rx_cmd.len) {
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-    }
-}
-#endif
-
-static void
-ble_hci_uart_rx_acl(uint8_t data)
-{
-    uint16_t rxd_bytes;
-    uint16_t pktlen;
-
-    rxd_bytes = ble_hci_uart_state.rx_acl.rxd_bytes;
-    ble_hci_uart_state.rx_acl.dptr[rxd_bytes] = data;
-    ++rxd_bytes;
-    ble_hci_uart_state.rx_acl.rxd_bytes = rxd_bytes;
-
-    if (rxd_bytes < BLE_HCI_DATA_HDR_SZ) {
-        return;
-    }
-
-    if (rxd_bytes == BLE_HCI_DATA_HDR_SZ) {
-        pktlen = ble_hci_uart_state.rx_acl.dptr[3];
-        pktlen = (pktlen << 8) + ble_hci_uart_state.rx_acl.dptr[2];
-        ble_hci_uart_state.rx_acl.len = pktlen + BLE_HCI_DATA_HDR_SZ;
-
-        /*
-         * Data portion cannot exceed data length of acl buffer. If it does
-         * this is considered to be a loss of sync.
-         */
-        if (pktlen > MYNEWT_VAL(BLE_ACL_BUF_SIZE)) {
-            os_mbuf_free_chain(ble_hci_uart_state.rx_acl.buf);
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-            ble_hci_uart_sync_lost();
-#else
-        /*
-         * XXX: not sure what to do about host in this case. Just go back to
-         * none for now.
-         */
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-#endif
-        }
-    }
-
-    if (rxd_bytes == ble_hci_uart_state.rx_acl.len) {
-        assert(ble_hci_uart_rx_acl_cb != NULL);
-        /* XXX: can this callback fail? What if it does? */
-        OS_MBUF_PKTLEN(ble_hci_uart_state.rx_acl.buf) = rxd_bytes;
-        ble_hci_uart_state.rx_acl.buf->om_len = rxd_bytes;
-        ble_hci_uart_rx_acl_cb(ble_hci_uart_state.rx_acl.buf,
-                               ble_hci_uart_rx_acl_arg);
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-    }
-}
-
-static void
-ble_hci_uart_rx_skip_acl(uint8_t data)
-{
-    uint16_t rxd_bytes;
-    uint16_t pktlen;
-
-    rxd_bytes = ble_hci_uart_state.rx_acl.rxd_bytes;
-    ++rxd_bytes;
-    ble_hci_uart_state.rx_acl.rxd_bytes = rxd_bytes;
-
-    if (rxd_bytes == (BLE_HCI_DATA_HDR_SZ - 1)) {
-        ble_hci_uart_state.rx_acl.len = data;
-        return;
-    }
-
-    if (rxd_bytes == BLE_HCI_DATA_HDR_SZ) {
-        pktlen = data;
-        pktlen = (pktlen << 8) + ble_hci_uart_state.rx_acl.len;
-        ble_hci_uart_state.rx_acl.len = pktlen + BLE_HCI_DATA_HDR_SZ;
-    }
-
-    if (rxd_bytes == ble_hci_uart_state.rx_acl.len) {
-/* XXX: I dont like this but for now this denotes controller only */
-#if MYNEWT_VAL(BLE_CONTROLLER)
-#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
-        ble_ll_data_buffer_overflow();
-#endif
-#endif
-        ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-    }
-}
-
-static int
-ble_hci_uart_rx_char(void *arg, uint8_t data)
-{
-    switch (ble_hci_uart_state.rx_type) {
-    case BLE_HCI_UART_H4_NONE:
-        return ble_hci_uart_rx_pkt_type(data);
-#if MYNEWT_VAL(BLE_CONTROLLER) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case BLE_HCI_UART_H4_CMD:
-        ble_hci_uart_rx_cmd(data);
-        return 0;
-    case BLE_HCI_UART_H4_SKIP_CMD:
-        ble_hci_uart_rx_skip_cmd(data);
-        return 0;
-    case BLE_HCI_UART_H4_SYNC_LOSS:
-        ble_hci_uart_rx_sync_loss(data);
-        return 0;
-#endif
-#if MYNEWT_VAL(BLE_HOST)
-    case BLE_HCI_UART_H4_EVT:
-        ble_hci_uart_rx_evt(data);
-        return 0;
-    case BLE_HCI_UART_H4_LE_EVT:
-        ble_hci_uart_rx_le_evt(data);
-        return 0;
-    case BLE_HCI_UART_H4_SKIP_EVT:
-        ble_hci_uart_rx_skip_evt(data);
-        return 0;
-#endif
-    case BLE_HCI_UART_H4_ACL:
-        ble_hci_uart_rx_acl(data);
-        return 0;
-    case BLE_HCI_UART_H4_SKIP_ACL:
-        ble_hci_uart_rx_skip_acl(data);
-        return 0;
-    default:
-        /* This should never happen! */
-        assert(0);
-        return 0;
-    }
-}
-
-static void
-ble_hci_uart_set_rx_cbs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                        void *cmd_arg,
-                        ble_hci_trans_rx_acl_fn *acl_cb,
-                        void *acl_arg)
-{
-    ble_hci_uart_rx_cmd_cb = cmd_cb;
-    ble_hci_uart_rx_cmd_arg = cmd_arg;
-    ble_hci_uart_rx_acl_cb = acl_cb;
-    ble_hci_uart_rx_acl_arg = acl_arg;
-}
-
-static void
-ble_hci_uart_free_pkt(uint8_t type, uint8_t *cmdevt, struct os_mbuf *acl)
-{
-    switch (type) {
-    case BLE_HCI_UART_H4_NONE:
-        break;
-
-    case BLE_HCI_UART_H4_CMD:
-    case BLE_HCI_UART_H4_EVT:
-        ble_hci_trans_buf_free(cmdevt);
-        break;
-
-    case BLE_HCI_UART_H4_ACL:
-        os_mbuf_free_chain(acl);
-        break;
-
-    default:
-        assert(0);
-        break;
-    }
-}
-
-static int
-ble_hci_uart_config(void)
-{
-    int rc;
-
-    rc = hal_uart_init_cbs(MYNEWT_VAL(BLE_HCI_UART_PORT),
-                           ble_hci_uart_tx_char, NULL,
-                           ble_hci_uart_rx_char, NULL);
-    if (rc != 0) {
-        return BLE_ERR_UNSPECIFIED;
-    }
-
-    rc = hal_uart_config(MYNEWT_VAL(BLE_HCI_UART_PORT),
-                         MYNEWT_VAL(BLE_HCI_UART_BAUD),
-                         MYNEWT_VAL(BLE_HCI_UART_DATA_BITS),
-                         MYNEWT_VAL(BLE_HCI_UART_STOP_BITS),
-                         MYNEWT_VAL(BLE_HCI_UART_PARITY),
-                         MYNEWT_VAL(BLE_HCI_UART_FLOW_CTRL));
-    if (rc != 0) {
-        return BLE_ERR_HW_FAIL;
-    }
-
-    return 0;
-}
-
-/**
- * Sends an HCI event from the controller to the host.
- *
- * @param cmd                   The HCI event to send.  This buffer must be
- *                                  allocated via ble_hci_trans_buf_alloc().
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int
-ble_hci_trans_ll_evt_tx(uint8_t *cmd)
-{
-    int rc;
-
-    rc = ble_hci_uart_cmdevt_tx(cmd, BLE_HCI_UART_H4_EVT);
-    return rc;
-}
-
-/**
- * Sends ACL data from controller to host.
- *
- * @param om                    The ACL data packet to send.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
-{
-    int rc;
-
-    rc = ble_hci_uart_acl_tx(om);
-    return rc;
-}
-
-#if MYNEWT_VAL(BLE_HOST)
-/**
- * Sends an HCI command from the host to the controller.
- *
- * @param cmd                   The HCI command to send.  This buffer must be
- *                                  allocated via ble_hci_trans_buf_alloc().
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int
-ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
-{
-    int rc;
-
-    rc = ble_hci_uart_cmdevt_tx(cmd, BLE_HCI_UART_H4_CMD);
-    return rc;
-}
-
-/**
- * Sends ACL data from host to controller.
- *
- * @param om                    The ACL data packet to send.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int
-ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
-{
-    int rc;
-
-    rc = ble_hci_uart_acl_tx(om);
-    return rc;
-}
-
-/**
- * Configures the HCI transport to call the specified callback upon receiving
- * HCI packets from the controller.  This function should only be called by by
- * host.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_uart_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
-}
-#endif
-
-/**
- * Configures the HCI transport to operate with a host.  The transport will
- * execute specified callbacks upon receiving HCI packets from the controller.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_uart_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
-}
-
-/**
- * Allocates a flat buffer of the specified type.
- *
- * @param type                  The type of buffer to allocate; one of the
- *                                  BLE_HCI_TRANS_BUF_[...] constants.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        buf = os_memblock_get(&ble_hci_uart_cmd_pool);
-        break;
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_uart_evt_hi_pool);
-        if (buf == NULL) {
-            /* If no high-priority event buffers remain, try to grab a
-             * low-priority one.
-             */
-            buf = os_memblock_get(&ble_hci_uart_evt_lo_pool);
-        }
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&ble_hci_uart_evt_lo_pool);
-        break;
-
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-/**
- * Frees the specified flat buffer.  The buffer must have been allocated via
- * ble_hci_trans_buf_alloc().
- *
- * @param buf                   The buffer to free.
- */
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    /*
-     * XXX: this may look a bit odd, but the controller uses the command
-     * buffer to send back the command complete/status as an immediate
-     * response to the command. This was done to insure that the controller
-     * could always send back one of these events when a command was received.
-     * Thus, we check to see which pool the buffer came from so we can free
-     * it to the appropriate pool
-     */
-    if (os_memblock_from(&ble_hci_uart_evt_hi_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_uart_evt_hi_pool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_uart_evt_lo_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_uart_evt_lo_pool, buf);
-        assert(rc == 0);
-    } else {
-        assert(os_memblock_from(&ble_hci_uart_cmd_pool, buf));
-        rc = os_memblock_put(&ble_hci_uart_cmd_pool, buf);
-        assert(rc == 0);
-    }
-}
-
-/**
- * Configures a callback to get executed whenever an ACL data packet is freed.
- * The function is called in lieu of actually freeing the packet.
- *
- * @param cb                    The callback to configure.
- *
- * @return                      0 on success.
- */
-int
-ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
-{
-    ble_hci_uart_acl_pool.mpe_put_cb = cb;
-    ble_hci_uart_acl_pool.mpe_put_arg = arg;
-    return 0;
-}
-
-/**
- * Resets the HCI UART transport to a clean state.  Frees all buffers and
- * reconfigures the UART.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int
-ble_hci_trans_reset(void)
-{
-    struct ble_hci_uart_pkt *pkt;
-    int rc;
-
-    /* Close the UART to prevent race conditions as the buffers are freed. */
-    rc = hal_uart_close(MYNEWT_VAL(BLE_HCI_UART_PORT));
-    if (rc != 0) {
-        return BLE_ERR_HW_FAIL;
-    }
-
-    ble_hci_uart_free_pkt(ble_hci_uart_state.rx_type,
-                          ble_hci_uart_state.rx_cmd.data,
-                          ble_hci_uart_state.rx_acl.buf);
-    ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
-
-    ble_hci_uart_free_pkt(ble_hci_uart_state.tx_type,
-                          ble_hci_uart_state.tx_cmd.data,
-                          ble_hci_uart_state.tx_pkt.tx_acl);
-    ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
-
-    while ((pkt = STAILQ_FIRST(&ble_hci_uart_state.tx_pkts)) != NULL) {
-        STAILQ_REMOVE(&ble_hci_uart_state.tx_pkts, pkt, ble_hci_uart_pkt,
-                      next);
-        ble_hci_uart_free_pkt(pkt->type, pkt->data, pkt->data);
-        os_memblock_put(&ble_hci_uart_pkt_pool, pkt);
-    }
-
-    /* Reopen the UART. */
-    rc = ble_hci_uart_config();
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/**
- * Initializes the UART HCI transport module.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-void
-ble_hci_uart_init(void)
-{
-    int rc;
-
-    /* Ensure this function only gets called by sysinit. */
-    SYSINIT_ASSERT_ACTIVE();
-
-    rc = os_mempool_ext_init(&ble_hci_uart_acl_pool,
-                             MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                             ACL_BLOCK_SIZE,
-                             ble_hci_uart_acl_buf,
-                             "ble_hci_uart_acl_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&ble_hci_uart_acl_mbuf_pool,
-                           &ble_hci_uart_acl_pool.mpe_mp,
-                           ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    /*
-     * Create memory pool of HCI command buffers. NOTE: we currently dont
-     * allow this to be configured. The controller will only allow one
-     * outstanding command. We decided to keep this a pool in case we allow
-     * allow the controller to handle more than one outstanding command.
-     */
-    rc = os_mempool_init(&ble_hci_uart_cmd_pool,
-                         1,
-                         BLE_HCI_TRANS_CMD_SZ,
-                         ble_hci_uart_cmd_buf,
-                         "ble_hci_uart_cmd_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_uart_evt_hi_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_uart_evt_hi_buf,
-                         "ble_hci_uart_evt_hi_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_uart_evt_lo_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_uart_evt_lo_buf,
-                         "ble_hci_uart_evt_lo_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    /*
-     * Create memory pool of packet list nodes. NOTE: the number of these
-     * buffers should be, at least, the total number of event buffers (hi
-     * and lo), the number of command buffers (currently 1) and the total
-     * number of buffers that the controller could possibly hand to the host.
-     */
-    rc = os_mempool_init(&ble_hci_uart_pkt_pool,
-                         BLE_HCI_UART_EVT_COUNT + 1 +
-                         MYNEWT_VAL(BLE_HCI_ACL_OUT_COUNT),
-                         sizeof (struct ble_hci_uart_pkt),
-                         ble_hci_uart_pkt_buf,
-                         "ble_hci_uart_pkt_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = ble_hci_uart_config();
-    SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failure configuring UART HCI");
-
-    memset(&ble_hci_uart_state, 0, sizeof ble_hci_uart_state);
-    STAILQ_INIT(&ble_hci_uart_state.tx_pkts);
-}
diff --git a/nimble/transport/uart/src/hci_uart.c b/nimble/transport/uart/src/hci_uart.c
new file mode 100644
index 0000000..9ffcc90
--- /dev/null
+++ b/nimble/transport/uart/src/hci_uart.c
@@ -0,0 +1,247 @@
+/*
+ * 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 <errno.h>
+#include <stdint.h>
+#include <sysinit/sysinit.h>
+#include <syscfg/syscfg.h>
+#include "os/os_mbuf.h"
+#include "os/os_mempool.h"
+#include "hal/hal_uart.h"
+#include "nimble/transport.h"
+#include "nimble/transport/hci_h4.h"
+
+#define TX_Q_SIZE   (MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT) + \
+                     MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT) + \
+                     MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT))
+
+struct hci_uart_tx {
+    uint8_t type;
+    uint8_t sent_type;
+    uint16_t len;
+    uint16_t idx;
+
+    struct os_mbuf *om;
+    uint8_t *buf;
+
+    STAILQ_ENTRY(hci_uart_tx) tx_q_next;
+};
+
+static STAILQ_HEAD(, hci_uart_tx) tx_q;
+
+static struct os_mempool pool_tx_q;
+static uint8_t pool_tx_q_buf[ OS_MEMPOOL_BYTES(TX_Q_SIZE,
+                                               sizeof(struct hci_uart_tx)) ];
+
+struct hci_h4_sm hci_uart_h4sm;
+
+static int
+hci_uart_frame_cb(uint8_t pkt_type, void *data)
+{
+    switch (pkt_type) {
+    case HCI_H4_CMD:
+        return ble_transport_to_ll_cmd(data);
+    case HCI_H4_ACL:
+        return ble_transport_to_ll_acl(data);
+    default:
+        assert(0);
+        break;
+    }
+
+    return -1;
+}
+
+static int
+hci_uart_rx_char(void *arg, uint8_t data)
+{
+    hci_h4_sm_rx(&hci_uart_h4sm, &data, 1);
+
+    return 0;
+}
+
+static int
+hci_uart_tx_char(void *arg)
+{
+    struct hci_uart_tx *tx;
+    uint8_t ch;
+    os_sr_t sr;
+
+    OS_ENTER_CRITICAL(sr);
+    tx = STAILQ_FIRST(&tx_q);
+    OS_EXIT_CRITICAL(sr);
+    if (!tx) {
+        return -1;
+    }
+
+    if (!tx->sent_type) {
+        tx->sent_type = 1;
+        return tx->type;
+    }
+
+    switch (tx->type) {
+    case HCI_H4_EVT:
+        ch = tx->buf[tx->idx];
+        tx->idx++;
+        if (tx->idx == tx->len) {
+            ble_transport_free(tx->buf);
+            OS_ENTER_CRITICAL(sr);
+            STAILQ_REMOVE_HEAD(&tx_q, tx_q_next);
+            OS_EXIT_CRITICAL(sr);
+            os_memblock_put(&pool_tx_q, tx);
+        }
+        break;
+    case HCI_H4_ACL:
+        os_mbuf_copydata(tx->om, 0, 1, &ch);
+        os_mbuf_adj(tx->om, 1);
+        tx->len--;
+        if (tx->len == 0) {
+            os_mbuf_free_chain(tx->om);
+            OS_ENTER_CRITICAL(sr);
+            STAILQ_REMOVE_HEAD(&tx_q, tx_q_next);
+            OS_EXIT_CRITICAL(sr);
+            os_memblock_put(&pool_tx_q, tx);
+        }
+        break;
+    default:
+        assert(0);
+        OS_ENTER_CRITICAL(sr);
+        STAILQ_REMOVE_HEAD(&tx_q, tx_q_next);
+        OS_EXIT_CRITICAL(sr);
+        os_memblock_put(&pool_tx_q, tx);
+    }
+
+    return ch;
+}
+
+static int
+hci_uart_configure(void)
+{
+    enum hal_uart_parity parity;
+    enum hal_uart_flow_ctl flowctl;
+    int rc;
+
+    rc = hal_uart_init_cbs(MYNEWT_VAL(BLE_TRANSPORT_UART_PORT),
+                           hci_uart_tx_char, NULL,
+                           hci_uart_rx_char, NULL);
+    if (rc != 0) {
+        return -1;
+    }
+
+    if (MYNEWT_VAL_CHOICE(BLE_TRANSPORT_UART_PARITY, odd)) {
+        parity = HAL_UART_PARITY_ODD;
+    } else if (MYNEWT_VAL_CHOICE(BLE_TRANSPORT_UART_PARITY, even)) {
+        parity = HAL_UART_PARITY_EVEN;
+    } else {
+        parity = HAL_UART_PARITY_NONE;
+    }
+
+    if (MYNEWT_VAL_CHOICE(BLE_TRANSPORT_UART_FLOW_CONTROL, rtscts)) {
+        flowctl = HAL_UART_FLOW_CTL_RTS_CTS;
+    } else {
+        flowctl = HAL_UART_FLOW_CTL_NONE;
+    }
+
+    rc = hal_uart_config(MYNEWT_VAL(BLE_TRANSPORT_UART_PORT),
+                         MYNEWT_VAL(BLE_TRANSPORT_UART_BAUDRATE),
+                         MYNEWT_VAL(BLE_TRANSPORT_UART_DATA_BITS),
+                         MYNEWT_VAL(BLE_TRANSPORT_UART_STOP_BITS),
+                         parity, flowctl);
+    if (rc != 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
+int
+ble_transport_to_hs_evt(void *buf)
+{
+    struct hci_uart_tx *txe;
+    os_sr_t sr;
+
+    txe = os_memblock_get(&pool_tx_q);
+    if (!txe) {
+        assert(0);
+        return -ENOMEM;
+    }
+
+    txe->type = HCI_H4_EVT;
+    txe->sent_type = 0;
+    txe->len = 2 + ((uint8_t *)buf)[1];
+    txe->buf = buf;
+    txe->idx = 0;
+    txe->om = NULL;
+
+    OS_ENTER_CRITICAL(sr);
+    STAILQ_INSERT_TAIL(&tx_q, txe, tx_q_next);
+    OS_EXIT_CRITICAL(sr);
+
+    hal_uart_start_tx(MYNEWT_VAL(BLE_TRANSPORT_UART_PORT));
+
+    return 0;
+}
+
+int
+ble_transport_to_hs_acl(struct os_mbuf *om)
+{
+    struct hci_uart_tx *txe;
+    os_sr_t sr;
+
+    txe = os_memblock_get(&pool_tx_q);
+    if (!txe) {
+        assert(0);
+        return -ENOMEM;
+    }
+
+    txe->type = HCI_H4_ACL;
+    txe->sent_type = 0;
+    txe->len = 2 + OS_MBUF_PKTLEN(om);
+    txe->idx = 0;
+    txe->buf = NULL;
+    txe->om = om;
+
+    OS_ENTER_CRITICAL(sr);
+    STAILQ_INSERT_TAIL(&tx_q, txe, tx_q_next);
+    OS_EXIT_CRITICAL(sr);
+
+    hal_uart_start_tx(MYNEWT_VAL(BLE_TRANSPORT_UART_PORT));
+
+    return 0;
+}
+
+void
+ble_transport_hs_init(void)
+{
+    int rc;
+
+    SYSINIT_ASSERT_ACTIVE();
+
+    rc = hci_uart_configure();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = os_mempool_init(&pool_tx_q, TX_Q_SIZE, sizeof(struct hci_uart_tx),
+                         pool_tx_q_buf, "hci_uart_tx_q");
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    hci_h4_sm_init(&hci_uart_h4sm, &hci_h4_allocs_from_hs, hci_uart_frame_cb);
+
+    STAILQ_INIT(&tx_q);
+}
diff --git a/nimble/transport/uart/syscfg.yml b/nimble/transport/uart/syscfg.yml
index 7eff951..21d2177 100644
--- a/nimble/transport/uart/syscfg.yml
+++ b/nimble/transport/uart/syscfg.yml
@@ -17,45 +17,23 @@
 #
 
 syscfg.defs:
-    BLE_HCI_ACL_OUT_COUNT:
-        description: >
-            This count is used in creating a pool of elements used by the
-            code to enqueue various elements. In the case of the controller
-            only HCI, this number should be equal to the number of mbufs in
-            the msys pool. For host only, it is really dependent on the
-            number of ACL buffers that the controller tells the host it
-            has.
-        value: 12
-
-    BLE_HCI_UART_PORT:
-        description: 'The uart to use for the HCI uart interface'
-        value:            0
-    BLE_HCI_UART_BAUD:
-        description: 'The baud rate of the HCI uart interface'
-        value:            1000000
-    BLE_HCI_UART_DATA_BITS:
-        description: 'Number of data bits used for HCI uart interface'
-        value:       8
-    BLE_HCI_UART_STOP_BITS:
-        description: 'Number of stop bits used for HCI uart interface'
-        value:       1
-    BLE_HCI_UART_PARITY:
-        description: 'Parity used for HCI uart interface'
-        value:          HAL_UART_PARITY_NONE
-    BLE_HCI_UART_FLOW_CTRL:
-        description: 'Flow control used for HCI uart interface'
-        value:       HAL_UART_FLOW_CTL_RTS_CTS
-    BLE_TRANS_UART_SYSINIT_STAGE:
-        description: >
-            Sysinit stage for the UART BLE transport.
-        value: 500
-
-syscfg.vals.BLE_EXT_ADV:
-    BLE_HCI_EVT_BUF_SIZE: 257
-
-syscfg.vals:
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_HCI_EVT_HI_BUF_COUNT: 8
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_ACL_BUF_COUNT: 12
-    BLE_ACL_BUF_SIZE: 255
+    BLE_TRANSPORT_UART_PORT:
+        description: UART index to use for HCI interface
+        value: 0
+    BLE_TRANSPORT_UART_BAUDRATE:
+        description: Baudrate on UART
+        value: 1000000
+    BLE_TRANSPORT_UART_DATA_BITS:
+        description: Number of data bits on UART
+        value: 8
+    BLE_TRANSPORT_UART_STOP_BITS:
+        description: Number of stop bits on UART
+        value: 1
+    BLE_TRANSPORT_UART_PARITY:
+        description: Parity on UART
+        value: none
+        choices: none,even,odd
+    BLE_TRANSPORT_UART_FLOW_CONTROL:
+        description: Flow control on UART
+        choices: off,rtscts
+        value: rtscts

[mynewt-nimble] 03/22: nimble/doc: Add documentation for HCI transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit bb32f04b702e4cbf6f02ccff60d2ba5c9f94ad14
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Mar 7 14:50:51 2022 +0100

    nimble/doc: Add documentation for HCI transport
---
 nimble/doc/transport.md | 189 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 189 insertions(+)

diff --git a/nimble/doc/transport.md b/nimble/doc/transport.md
new file mode 100644
index 0000000..cd14993
--- /dev/null
+++ b/nimble/doc/transport.md
@@ -0,0 +1,189 @@
+<!--
+#
+# 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.
+#
+-->
+
+# NimBLE HCI transport
+
+## Overview
+
+Transport is split into host (HS) and controller (LL) sides. Those do not
+necessarily represent actual host/controller, they can be just interfaces to
+external host (e.g. UART or USB) or  controller (e.g.IPC to LL running on
+another core).
+
+```
++----------+                       +----------+
+| cmd pool |                       | evt pool |
++----------+                       +----------+
+| acl pool |                       | acl pool |
++----------+                       +----------+
+  ||                                       ||
++----+                                   +----+
+|    | <--- ble_transport_to_ll_acl ---- |    |
+|    | <--- ble_transport_to_ll_evt ---- |    |
+| HS |                                   | LL |
+|    | ---- ble_transport_to_ll_cmd ---> |    |
+|    | ---- ble_transport_to_ll_acl ---> |    |
++----+                                   +----+
+```
+
+HS side allocates buffers for HCI commands and ACL data from dedicated pools
+using `ble_transport_alloc_cmd` and `ble_transport_alloc_acl_from_hs` calls
+respectively, then sends them to LL side using `ble_transport_to_ll_cmd` and
+`ble_transport_to_ll_acl`.
+
+Similarly, LL side allocates buffers for HCI events and ACL data from dedicated
+pools using `ble_transport_alloc_evt` and `ble_transport_alloc_acl_from_ll`
+calls respectively, then sends them to HS side using `ble_transport_to_hs_evt`
+and `ble_transport_to_hs_acl`.
+
+Both HCI command and events buffers are freed using `ble_transport_free`, ACL
+data are freed as regular `os_mbuf`.
+
+Selecting `native` transport for either HS or LL side will use actual NimBLE
+host or controller respectively directly instead of transport implementation.
+Both NimBLE host and controller do not use decidated pools for ACL data and
+allocate data directly from msys pool - relevant ACL pools will be disabled
+automatically.
+
+Actual transport implementation for each side can be set using `BLE_TRANSPORT_HS`
+and `BLE_TRANSPORT_LL` syscfg for HS and LL sides respectively. Selecting
+transport in either direction will automatically add dependencies to required
+transport implementation packages, there's no need to do this manually.
+Selecting `native` transport for HS and/or LL side will automatically add
+dependencies to NimBLE host and/or controller packages. 
+
+The order of initialization is defined as follows:
+- `ble_transport_init` - generic transport initialization
+- `ble_transport_hs_init` - HS side initialization
+- `ble_transport_ll_init` - LL side initialization
+
+Initialization functions for HS and LL sides shall be implemented by transport
+implementation. There's no need to define those functions as sysinit stages
+since this is already done by generic transport implementation along with
+proper dependencies.
+
+
+## Application configuration
+
+To ensure that application can be easily run on different BSPs, it's strongly
+recommended not to put hard dependencies to any transport in `pkg.yml` and
+use automatic dependencies instead. That means an application that uses NimBLE
+host should only include `nimble/host` in its dependencies (i.e. no direct
+dependency to `nimble/controler` or any transport implementation). This will
+pull `nimble/transport` automatically, force `BLE_TRANSPORT_HS: native` and
+allow changing LL side using `BLE_TRANSPORT_LL` to any supported controller.
+
+
+## Multicore SoCs
+
+On multicore SoCs with dedicated application and network cores (e.g. nRF5340,
+DA1469x) NimBLE host and controller will run on different cores. In such setup
+application core uses LL transport implementation instead of an actual NimBLE
+controller and similarly network core uses HS transport implementation instead
+of NimBLE host. Both sides of transport implementation are provided by the same
+transport, e.g. `nrf5340` for nRF5340 or `dialog_cmac` for DA1469x, and exchange
+data via IPC. This process is transparent from application point of view,
+assuming it's properly configured (see above).
+
+```
+     Application core           |            Network core
++----+               +----+     |     +----+               +----+
+|    |               | LL |     |     | HS |               |    |
+|    | <- acl/evt -- |    |     |     |    | <- acl/evt -- |    |
+| HS |               | tr | <- ipc -> | tr |               | LL |
+|    | -- cmd/acl -> | an |     |     | an | -- cmd/acl -> |    |
+|    |               | sp |     |     | sp |               |    |
++----+               +----+     |     +----+               +----+
+```
+
+
+## Build configurations
+
+### Combined build
+
+This setup runs both NimBLE host and controller on the same core. It's a typical
+configuration when running application on SoCs like nRF51 or nRF52.
+
+Note: this is the default configuration, no need to set it explicitly.
+
+```yaml
+BLE_TRANSPORT_HS: native
+BLE_TRANSPORT_LL: native
+```
+
+### Controller-only build
+
+This setup makes NimBLE controller accessible to external host connected via
+e.g. UART or USB, so it can be used as an external Bluetooth LE controller.
+The controller runs on the same core as external interface. It's typically
+used with `blehci` application running on SoCs like nRF51 or nRF52.
+
+```yaml
+BLE_TRANSPORT_HS: uart
+BLE_TRANSPORT_LL: native
+```
+
+
+### Multicore build
+
+This is a variant of combined build but with NimBLE host and controller running
+on different cores, like e.g. nRF5340 or DA1469x. Application core can run
+any application while network core runs `blehci`.
+
+Note: BSPs for nRF5340 and DA1469x will automatically select proper transport
+      for LL side if NimBLE host or transport is included in build, so usually
+      there's no need to configure manually. 
+
+#### Application core
+```yaml
+BLE_TRANSPORT_HS: native
+BLE_TRANSPORT_LL: dialog_cmac
+```
+
+#### Network core
+```yaml
+BLE_TRANSPORT_HS: dialog_cmac
+BLE_TRANSPORT_LL: native
+```
+
+
+### Bridge build
+
+This is a variant of controller-only build but with NimBLE controller running
+on different core than external interface used to access it, like e.g. nRF5340
+or DA1469x. In this setup both cores run `blehci` application.
+
+Note: BSPs for nRF5340 and DA1469x will automatically select proper transport
+      for LL side if NimBLE host or transport is included in build, so usually
+      there's only need to select required transport for external interface on
+      application core.
+
+#### Application core
+```yaml
+BLE_TRANSPORT_HS: uart
+BLE_TRANSPORT_LL: nrf5340
+```
+
+#### Network core
+```yaml
+BLE_TRANSPORT_HS: nrf5340
+BLE_TRANSPORT_LL: native
+```

[mynewt-nimble] 16/22: apps: Update to new transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit e9a4a4fce2982c3b38c1548e6fb6010ff0a9a638
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Mar 8 07:38:47 2022 +0100

    apps: Update to new transport
    
    We do not need depedency to nimble/transport, this is automatically
    included by nimble/host.
---
 apps/advertiser/pkg.yml               | 2 +-
 apps/blecent/pkg.yml                  | 1 -
 apps/blecsc/pkg.yml                   | 1 -
 apps/blehr/pkg.yml                    | 1 -
 apps/blemesh/pkg.yml                  | 1 -
 apps/blemesh_light/pkg.yml            | 1 -
 apps/blemesh_models_example_1/pkg.yml | 1 -
 apps/blemesh_models_example_2/pkg.yml | 1 -
 apps/blemesh_shell/pkg.yml            | 1 -
 apps/bleprph/pkg.yml                  | 1 -
 apps/blestress/pkg.yml                | 1 -
 apps/btshell/pkg.yml                  | 1 -
 apps/bttester/pkg.yml                 | 1 -
 apps/central/pkg.yml                  | 1 -
 apps/ext_advertiser/pkg.yml           | 1 -
 apps/mesh_badge/pkg.yml               | 1 -
 apps/peripheral/pkg.yml               | 2 --
 apps/scanner/pkg.yml                  | 1 -
 18 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/apps/advertiser/pkg.yml b/apps/advertiser/pkg.yml
index 662e282..ad6f133 100644
--- a/apps/advertiser/pkg.yml
+++ b/apps/advertiser/pkg.yml
@@ -28,6 +28,6 @@ pkg.deps:
     - "@apache-mynewt-core/sys/log/full"
     - "@apache-mynewt-core/sys/stats/full"
     - "@apache-mynewt-core/sys/log/modlog"
+    - "@apache-mynewt-nimble/nimble/host"
     - "@apache-mynewt-nimble/nimble/host/util"
     - "@apache-mynewt-nimble/nimble/host/services/gap"
-    - "@apache-mynewt-nimble/nimble/transport"
diff --git a/apps/blecent/pkg.yml b/apps/blecent/pkg.yml
index 12d539e..86e3f01 100644
--- a/apps/blecent/pkg.yml
+++ b/apps/blecent/pkg.yml
@@ -33,4 +33,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/blecsc/pkg.yml b/apps/blecsc/pkg.yml
index a2119c1..d3768fc 100644
--- a/apps/blecsc/pkg.yml
+++ b/apps/blecsc/pkg.yml
@@ -36,4 +36,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/blehr/pkg.yml b/apps/blehr/pkg.yml
index 8212f8f..ace633b 100644
--- a/apps/blehr/pkg.yml
+++ b/apps/blehr/pkg.yml
@@ -36,4 +36,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/blemesh/pkg.yml b/apps/blemesh/pkg.yml
index afe419b..19fb478 100644
--- a/apps/blemesh/pkg.yml
+++ b/apps/blemesh/pkg.yml
@@ -33,4 +33,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/blemesh_light/pkg.yml b/apps/blemesh_light/pkg.yml
index 46b6d6c..bb37ffb 100644
--- a/apps/blemesh_light/pkg.yml
+++ b/apps/blemesh_light/pkg.yml
@@ -33,4 +33,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/blemesh_models_example_1/pkg.yml b/apps/blemesh_models_example_1/pkg.yml
index b8d77c4..44e2d79 100644
--- a/apps/blemesh_models_example_1/pkg.yml
+++ b/apps/blemesh_models_example_1/pkg.yml
@@ -30,4 +30,3 @@ pkg.deps:
     - nimble/host
     - nimble/host/services/gap
     - nimble/host/services/gatt
-    - nimble/transport
diff --git a/apps/blemesh_models_example_2/pkg.yml b/apps/blemesh_models_example_2/pkg.yml
index 020a961..194b554 100644
--- a/apps/blemesh_models_example_2/pkg.yml
+++ b/apps/blemesh_models_example_2/pkg.yml
@@ -32,7 +32,6 @@ pkg.deps:
     - nimble/host
     - nimble/host/services/gap
     - nimble/host/services/gatt
-    - nimble/transport
 
 pkg.lflags:
     - -DFLOAT_SUPPORT
diff --git a/apps/blemesh_shell/pkg.yml b/apps/blemesh_shell/pkg.yml
index f472fdf..a7e457e 100644
--- a/apps/blemesh_shell/pkg.yml
+++ b/apps/blemesh_shell/pkg.yml
@@ -33,4 +33,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/bleprph/pkg.yml b/apps/bleprph/pkg.yml
index 38b6e44..0bb0d9d 100644
--- a/apps/bleprph/pkg.yml
+++ b/apps/bleprph/pkg.yml
@@ -42,4 +42,3 @@ pkg.deps:
     - nimble/host/services/gatt
     - nimble/host/store/config
     - nimble/host/util
-    - nimble/transport
diff --git a/apps/blestress/pkg.yml b/apps/blestress/pkg.yml
index 53f99ed..21013eb 100644
--- a/apps/blestress/pkg.yml
+++ b/apps/blestress/pkg.yml
@@ -35,4 +35,3 @@ pkg.deps:
     - "@apache-mynewt-nimble/nimble/host/services/gap"
     - "@apache-mynewt-nimble/nimble/host/services/gatt"
     - "@apache-mynewt-nimble/nimble/host/store/config"
-    - "@apache-mynewt-nimble/nimble/transport"
diff --git a/apps/btshell/pkg.yml b/apps/btshell/pkg.yml
index be6d685..abbee73 100644
--- a/apps/btshell/pkg.yml
+++ b/apps/btshell/pkg.yml
@@ -34,7 +34,6 @@ pkg.deps:
     - nimble/host/services/gatt
     - nimble/host/store/config
     - nimble/host/util
-    - nimble/transport
 
 pkg.deps.BTSHELL_ANS:
     - nimble/host/services/ans
diff --git a/apps/bttester/pkg.yml b/apps/bttester/pkg.yml
index 270dc7e..219e529 100644
--- a/apps/bttester/pkg.yml
+++ b/apps/bttester/pkg.yml
@@ -37,7 +37,6 @@ pkg.deps:
     - "@apache-mynewt-nimble/nimble/host/services/gatt"
     - "@apache-mynewt-nimble/nimble/host/services/dis"
     - "@apache-mynewt-nimble/nimble/host/store/config"
-    - "@apache-mynewt-nimble/nimble/transport"
     - "@apache-mynewt-core/hw/drivers/uart"
     - "@apache-mynewt-core/hw/drivers/rtt"
 
diff --git a/apps/central/pkg.yml b/apps/central/pkg.yml
index c10ad93..5f5b27a 100644
--- a/apps/central/pkg.yml
+++ b/apps/central/pkg.yml
@@ -31,4 +31,3 @@ pkg.deps:
     - "@apache-mynewt-nimble/nimble/host"
     - "@apache-mynewt-nimble/nimble/host/util/"
     - "@apache-mynewt-nimble/nimble/host/store/config"
-    - "@apache-mynewt-nimble/nimble/transport"
diff --git a/apps/ext_advertiser/pkg.yml b/apps/ext_advertiser/pkg.yml
index 5a60b22..32df4ef 100644
--- a/apps/ext_advertiser/pkg.yml
+++ b/apps/ext_advertiser/pkg.yml
@@ -30,7 +30,6 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
     - "@apache-mynewt-core/kernel/os"
     - "@apache-mynewt-core/sys/console/full"
     - "@apache-mynewt-core/sys/log/full"
diff --git a/apps/mesh_badge/pkg.yml b/apps/mesh_badge/pkg.yml
index 96a42ba..d1276a5 100644
--- a/apps/mesh_badge/pkg.yml
+++ b/apps/mesh_badge/pkg.yml
@@ -35,4 +35,3 @@ pkg.deps:
     - nimble/host/services/gap
     - nimble/host/services/gatt
     - nimble/host/store/config
-    - nimble/transport
diff --git a/apps/peripheral/pkg.yml b/apps/peripheral/pkg.yml
index 6167eda..d5c862c 100644
--- a/apps/peripheral/pkg.yml
+++ b/apps/peripheral/pkg.yml
@@ -33,5 +33,3 @@ pkg.deps:
     - "@apache-mynewt-nimble/nimble/host/util/"
     - "@apache-mynewt-nimble/nimble/host/services/gap"
     - "@apache-mynewt-nimble/nimble/host/store/config"
-    - "@apache-mynewt-nimble/nimble/transport"
-
diff --git a/apps/scanner/pkg.yml b/apps/scanner/pkg.yml
index 15c2adb..442ab9d 100644
--- a/apps/scanner/pkg.yml
+++ b/apps/scanner/pkg.yml
@@ -32,4 +32,3 @@ pkg.deps:
     - "@apache-mynewt-nimble/nimble/host"
     - "@apache-mynewt-nimble/nimble/host/util/"
     - "@apache-mynewt-nimble/nimble/host/store/config"
-    - "@apache-mynewt-nimble/nimble/transport"
\ No newline at end of file

[mynewt-nimble] 20/22: porting: Update for new HCI transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit fd62bd71f9266a0fb7eb0783c611ac6220fbc02c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 10 12:50:14 2022 +0100

    porting: Update for new HCI transport
    
    Adds required files to build, updates Linux sample app and also
    regenerate syscfg.h.
---
 porting/examples/linux/include/syscfg/syscfg.h     | 130 +++++++--------
 .../examples/linux_blemesh/include/syscfg/syscfg.h | 130 +++++++--------
 porting/examples/nuttx/include/syscfg/syscfg.h     | 130 +++++++--------
 porting/nimble/Makefile.defs                       |   2 +
 porting/nimble/include/syscfg/syscfg.h             | 130 +++++++--------
 porting/nimble/src/nimble_port.c                   |   6 +-
 porting/npl/riot/include/syscfg/syscfg.h           | 180 +++++++++++++--------
 porting/targets/linux/syscfg.yml                   |   2 +-
 porting/targets/linux_blemesh/syscfg.yml           |   2 +-
 porting/targets/nuttx/syscfg.yml                   |   2 +-
 porting/targets/porting_default/syscfg.yml         |   2 +-
 porting/targets/riot/syscfg.yml                    |   5 +-
 12 files changed, 370 insertions(+), 351 deletions(-)

diff --git a/porting/examples/linux/include/syscfg/syscfg.h b/porting/examples/linux/include/syscfg/syscfg.h
index 31d3835..903163a 100644
--- a/porting/examples/linux/include/syscfg/syscfg.h
+++ b/porting/examples/linux/include/syscfg/syscfg.h
@@ -15,7 +15,6 @@
 #define MYNEWT_VAL(_name)                       MYNEWT_VAL_ ## _name
 #define MYNEWT_VAL_CHOICE(_name, _val)          MYNEWT_VAL_ ## _name ## __ ## _val
 
-/*** @apache-mynewt-core/crypto/tinycrypt */
 #ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE
 #define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200)
 #endif
@@ -1008,103 +1007,98 @@
 #endif
 
 /*** @apache-mynewt-nimble/nimble/transport */
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT
-#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_COUNT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE
-#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_SIZE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE
-#define MYNEWT_VAL_BLE_HCI_BRIDGE (0)
-#endif
+#undef MYNEWT_VAL_BLE_HCI_BRIDGE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac (0)
-#endif
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340 (0)
+#undef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_TRANSPORT
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT
+#define MYNEWT_VAL_BLE_TRANSPORT (1)
 #endif
-#undef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
-#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/porting/targets/linux (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE (255)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__custom
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__custom (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT (4)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT (16)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac (0)
+
+/* Overridden by @apache-mynewt-nimble/nimble/transport (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE (257)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__custom (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340 (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__ram
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__ram (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__native
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__native (1)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__socket
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__socket (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340 (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__uart
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__uart (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__uart
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__uart (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__usb
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__usb (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__usb
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__usb (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS
+#define MYNEWT_VAL_BLE_TRANSPORT_HS (1)
 #endif
 
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI (0)
+/* Overridden by @apache-mynewt-nimble/porting/targets/linux (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__custom (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__native
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__native (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340 (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_UART
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_UART (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__socket
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__socket (1)
 #endif
-
-/*** @apache-mynewt-nimble/nimble/transport/socket */
-#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT
-#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL
+#define MYNEWT_VAL_BLE_TRANSPORT_LL (1)
 #endif
 
+/*** @apache-mynewt-nimble/nimble/transport/socket */
 #ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE
 #define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500)
 #endif
diff --git a/porting/examples/linux_blemesh/include/syscfg/syscfg.h b/porting/examples/linux_blemesh/include/syscfg/syscfg.h
index 976151a..550ce53 100644
--- a/porting/examples/linux_blemesh/include/syscfg/syscfg.h
+++ b/porting/examples/linux_blemesh/include/syscfg/syscfg.h
@@ -15,7 +15,6 @@
 #define MYNEWT_VAL(_name)                       MYNEWT_VAL_ ## _name
 #define MYNEWT_VAL_CHOICE(_name, _val)          MYNEWT_VAL_ ## _name ## __ ## _val
 
-/*** @apache-mynewt-core/crypto/tinycrypt */
 #ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE
 #define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200)
 #endif
@@ -1583,103 +1582,98 @@
 #endif
 
 /*** @apache-mynewt-nimble/nimble/transport */
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT
-#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_COUNT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE
-#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_SIZE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE
-#define MYNEWT_VAL_BLE_HCI_BRIDGE (0)
-#endif
+#undef MYNEWT_VAL_BLE_HCI_BRIDGE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac (0)
-#endif
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340 (0)
+#undef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_TRANSPORT
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT
+#define MYNEWT_VAL_BLE_TRANSPORT (1)
 #endif
-#undef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
-#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/porting/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE (255)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__custom
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__custom (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT (4)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT (16)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac (0)
+
+/* Overridden by @apache-mynewt-nimble/nimble/transport (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE (257)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__custom (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340 (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__ram
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__ram (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__native
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__native (1)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__socket
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__socket (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340 (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__uart
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__uart (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__uart
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__uart (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__usb
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__usb (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__usb
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__usb (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS
+#define MYNEWT_VAL_BLE_TRANSPORT_HS (1)
 #endif
 
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI (0)
+/* Overridden by @apache-mynewt-nimble/porting/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__custom (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__native
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__native (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340 (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_UART
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_UART (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__socket
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__socket (1)
 #endif
-
-/*** @apache-mynewt-nimble/nimble/transport/socket */
-#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT
-#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL
+#define MYNEWT_VAL_BLE_TRANSPORT_LL (1)
 #endif
 
+/*** @apache-mynewt-nimble/nimble/transport/socket */
 #ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE
 #define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500)
 #endif
diff --git a/porting/examples/nuttx/include/syscfg/syscfg.h b/porting/examples/nuttx/include/syscfg/syscfg.h
index 9269e3a..11fa149 100644
--- a/porting/examples/nuttx/include/syscfg/syscfg.h
+++ b/porting/examples/nuttx/include/syscfg/syscfg.h
@@ -15,7 +15,6 @@
 #define MYNEWT_VAL(_name)                       MYNEWT_VAL_ ## _name
 #define MYNEWT_VAL_CHOICE(_name, _val)          MYNEWT_VAL_ ## _name ## __ ## _val
 
-/*** @apache-mynewt-core/crypto/tinycrypt */
 #ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE
 #define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200)
 #endif
@@ -1010,103 +1009,98 @@
 #endif
 
 /*** @apache-mynewt-nimble/nimble/transport */
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT
-#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_COUNT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE
-#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_SIZE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE
-#define MYNEWT_VAL_BLE_HCI_BRIDGE (0)
-#endif
+#undef MYNEWT_VAL_BLE_HCI_BRIDGE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac (0)
-#endif
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340 (0)
+#undef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_TRANSPORT
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT
+#define MYNEWT_VAL_BLE_TRANSPORT (1)
 #endif
-#undef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
-#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/porting/targets/nuttx (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE (255)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__custom
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__custom (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT (4)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT (16)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac (0)
+
+/* Overridden by @apache-mynewt-nimble/nimble/transport (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE (257)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__custom (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340 (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__ram
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__ram (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__native
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__native (1)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__socket
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__socket (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340 (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__uart
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__uart (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__uart
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__uart (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__usb
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__usb (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__usb
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__usb (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS
+#define MYNEWT_VAL_BLE_TRANSPORT_HS (1)
 #endif
 
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI (0)
+/* Overridden by @apache-mynewt-nimble/porting/targets/nuttx (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__custom (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__native
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__native (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340 (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_UART
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_UART (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__socket
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__socket (1)
 #endif
-
-/*** @apache-mynewt-nimble/nimble/transport/socket */
-#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT
-#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL
+#define MYNEWT_VAL_BLE_TRANSPORT_LL (1)
 #endif
 
+/*** @apache-mynewt-nimble/nimble/transport/socket */
 #ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE
 #define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500)
 #endif
diff --git a/porting/nimble/Makefile.defs b/porting/nimble/Makefile.defs
index 78f73fb..ad45897 100644
--- a/porting/nimble/Makefile.defs
+++ b/porting/nimble/Makefile.defs
@@ -38,6 +38,7 @@ NIMBLE_INCLUDE := \
 	$(NIMBLE_ROOT)/nimble/host/services/tps/include \
 	$(NIMBLE_ROOT)/nimble/host/store/ram/include \
 	$(NIMBLE_ROOT)/nimble/host/util/include \
+	$(NIMBLE_ROOT)/nimble/transport/include \
 	$(NIMBLE_ROOT)/porting/nimble/include \
 	$(NULL)
 
@@ -55,6 +56,7 @@ NIMBLE_SRC := \
 	$(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/lls/src/*.c)) \
 	$(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/tps/src/*.c)) \
 	$(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/store/ram/src/*.c)) \
+	$(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/transport/src/*.c)) \
 	$(NULL)
 
 ifneq (,$(NIMBLE_CFG_CONTROLLER))
diff --git a/porting/nimble/include/syscfg/syscfg.h b/porting/nimble/include/syscfg/syscfg.h
index 98c0775..55a7c8b 100644
--- a/porting/nimble/include/syscfg/syscfg.h
+++ b/porting/nimble/include/syscfg/syscfg.h
@@ -15,7 +15,6 @@
 #define MYNEWT_VAL(_name)                       MYNEWT_VAL_ ## _name
 #define MYNEWT_VAL_CHOICE(_name, _val)          MYNEWT_VAL_ ## _name ## __ ## _val
 
-/*** @apache-mynewt-core/crypto/tinycrypt */
 #ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE
 #define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200)
 #endif
@@ -1007,103 +1006,98 @@
 #endif
 
 /*** @apache-mynewt-nimble/nimble/transport */
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT
-#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_COUNT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE
-#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_SIZE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE
-#define MYNEWT_VAL_BLE_HCI_BRIDGE (0)
-#endif
+#undef MYNEWT_VAL_BLE_HCI_BRIDGE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac (0)
-#endif
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340 (0)
+#undef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_TRANSPORT
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT
+#define MYNEWT_VAL_BLE_TRANSPORT (1)
 #endif
-#undef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
-#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/socket (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT (10)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/porting/targets/porting_default (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE (255)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__custom
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__custom (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT (4)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT (16)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac (0)
+
+/* Overridden by @apache-mynewt-nimble/nimble/transport (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE (257)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__custom (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340 (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__ram
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__ram (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__native
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__native (1)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__socket
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__socket (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340 (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__uart
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__uart (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__uart
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__uart (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__usb
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__usb (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__usb
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__usb (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS
+#define MYNEWT_VAL_BLE_TRANSPORT_HS (1)
 #endif
 
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI (0)
+/* Overridden by @apache-mynewt-nimble/porting/targets/porting_default (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__custom (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__native
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__native (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340 (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_UART
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_UART (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__socket
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__socket (1)
 #endif
-
-/*** @apache-mynewt-nimble/nimble/transport/socket */
-#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT
-#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL
+#define MYNEWT_VAL_BLE_TRANSPORT_LL (1)
 #endif
 
+/*** @apache-mynewt-nimble/nimble/transport/socket */
 #ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE
 #define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500)
 #endif
diff --git a/porting/nimble/src/nimble_port.c b/porting/nimble/src/nimble_port.c
index d4824d0..2a81fd6 100644
--- a/porting/nimble/src/nimble_port.c
+++ b/porting/nimble/src/nimble_port.c
@@ -40,8 +40,10 @@ nimble_port_init(void)
     /* Initialize the global memory pool */
     os_mempool_module_init();
     os_msys_init();
+    /* Initialize transport */
+    ble_transport_init();
     /* Initialize the host */
-    ble_hs_init();
+    ble_transport_hs_init();
 
 #if NIMBLE_CFG_CONTROLLER
     ble_hci_ram_init();
@@ -49,7 +51,7 @@ nimble_port_init(void)
     hal_timer_init(5, NULL);
     os_cputime_init(32768);
 #endif
-    ble_ll_init();
+    ble_transport_ll_init();
 #endif
 }
 
diff --git a/porting/npl/riot/include/syscfg/syscfg.h b/porting/npl/riot/include/syscfg/syscfg.h
index a581a6d..d749339 100644
--- a/porting/npl/riot/include/syscfg/syscfg.h
+++ b/porting/npl/riot/include/syscfg/syscfg.h
@@ -15,7 +15,6 @@
 #define MYNEWT_VAL(_name)                       MYNEWT_VAL_ ## _name
 #define MYNEWT_VAL_CHOICE(_name, _val)          MYNEWT_VAL_ ## _name ## __ ## _val
 
-/*** @apache-mynewt-core/compiler/arm-none-eabi-m4 */
 #ifndef MYNEWT_VAL_HARDFLOAT
 #define MYNEWT_VAL_HARDFLOAT (0)
 #endif
@@ -110,6 +109,11 @@
 #endif
 
 /* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */
+#ifndef MYNEWT_VAL_MCU_COMMON_STARTUP
+#define MYNEWT_VAL_MCU_COMMON_STARTUP (1)
+#endif
+
+/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */
 #ifndef MYNEWT_VAL_MCU_DCDC_ENABLED
 #define MYNEWT_VAL_MCU_DCDC_ENABLED (1)
 #endif
@@ -951,8 +955,12 @@
 #define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_SCA_UPDATE (0)
 #endif
 
+#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_PERIPH_INIT_FEAT_XCHG
+#define MYNEWT_VAL_BLE_LL_CFG_FEAT_PERIPH_INIT_FEAT_XCHG (MYNEWT_VAL_BLE_LL_ROLE_CENTRAL || MYNEWT_VAL_BLE_LL_ROLE_PERIPHERAL)
+#endif
+
 #ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG
-#define MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG (MYNEWT_VAL_BLE_LL_ROLE_CENTRAL || MYNEWT_VAL_BLE_LL_ROLE_PERIPHERAL)
+#define MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG (0)
 #endif
 
 /* Overridden by @apache-mynewt-nimble/porting/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */
@@ -968,6 +976,34 @@
 #define MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS (4)
 #endif
 
+#ifndef MYNEWT_VAL_BLE_LL_CONN_PHY_DEFAULT_PREF_MASK
+#define MYNEWT_VAL_BLE_LL_CONN_PHY_DEFAULT_PREF_MASK (0x07)
+#endif
+
+#ifndef MYNEWT_VAL_BLE_LL_CONN_PHY_INIT_UPDATE
+#define MYNEWT_VAL_BLE_LL_CONN_PHY_INIT_UPDATE (0)
+#endif
+
+#ifndef MYNEWT_VAL_BLE_LL_CONN_PHY_PREFER_2M
+#define MYNEWT_VAL_BLE_LL_CONN_PHY_PREFER_2M (0)
+#endif
+
+#ifndef MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED
+#define MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED (0)
+#endif
+
+#ifndef MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED_FIXED
+#define MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED_FIXED (0)
+#endif
+
+#ifndef MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED_PERIOD_SLOTS
+#define MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED_PERIOD_SLOTS (8)
+#endif
+
+#ifndef MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED_SLOT_US
+#define MYNEWT_VAL_BLE_LL_CONN_STRICT_SCHED_SLOT_US (3750)
+#endif
+
 #ifndef MYNEWT_VAL_BLE_LL_DEBUG_GPIO_HCI_CMD
 #define MYNEWT_VAL_BLE_LL_DEBUG_GPIO_HCI_CMD (-1)
 #endif
@@ -1005,6 +1041,10 @@
 #define MYNEWT_VAL_BLE_LL_EXT_ADV_AUX_PTR_CNT (0)
 #endif
 
+#ifndef MYNEWT_VAL_BLE_LL_HBD_FAKE_DUAL_MODE
+#define MYNEWT_VAL_BLE_LL_HBD_FAKE_DUAL_MODE (0)
+#endif
+
 #ifndef MYNEWT_VAL_BLE_LL_HCI_LLCP_TRACE
 #define MYNEWT_VAL_BLE_LL_HCI_LLCP_TRACE (0)
 #endif
@@ -1014,6 +1054,10 @@
 #define MYNEWT_VAL_BLE_LL_HCI_VS (1)
 #endif
 
+#ifndef MYNEWT_VAL_BLE_LL_HCI_VS_CONN_STRICT_SCHED
+#define MYNEWT_VAL_BLE_LL_HCI_VS_CONN_STRICT_SCHED (0)
+#endif
+
 /* Value copied from BLE_LL_VND_EVENT_ON_ASSERT */
 #ifndef MYNEWT_VAL_BLE_LL_HCI_VS_EVENT_ON_ASSERT
 #define MYNEWT_VAL_BLE_LL_HCI_VS_EVENT_ON_ASSERT (0)
@@ -1109,8 +1153,9 @@
 #define MYNEWT_VAL_BLE_LL_SCA (60)
 #endif
 
+/* Value copied from BLE_LL_EXT_ADV_AUX_PTR_CNT */
 #ifndef MYNEWT_VAL_BLE_LL_SCAN_AUX_SEGMENT_CNT
-#define MYNEWT_VAL_BLE_LL_SCAN_AUX_SEGMENT_CNT (8)
+#define MYNEWT_VAL_BLE_LL_SCAN_AUX_SEGMENT_CNT (0)
 #endif
 
 #ifndef MYNEWT_VAL_BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY
@@ -1156,7 +1201,7 @@
 #endif
 
 #ifndef MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD
-#define MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD (3250)
+#define MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD (0)
 #endif
 
 #ifndef MYNEWT_VAL_BLE_LL_VND_EVENT_ON_ASSERT
@@ -1606,101 +1651,96 @@
 #endif
 
 /*** @apache-mynewt-nimble/nimble/transport */
-/* Overridden by @apache-mynewt-nimble/porting/targets/riot (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT
-#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_COUNT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/ram (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE
-#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (65535)
-#endif
+#undef MYNEWT_VAL_BLE_ACL_BUF_SIZE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE
-#define MYNEWT_VAL_BLE_HCI_BRIDGE (0)
-#endif
+#undef MYNEWT_VAL_BLE_HCI_BRIDGE
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
 
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__dialog_cmac (0)
+#undef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
+
+#undef MYNEWT_VAL_BLE_HCI_TRANSPORT
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT
+#define MYNEWT_VAL_BLE_TRANSPORT (1)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT__nrf5340 (0)
+
+/* Overridden by @apache-mynewt-nimble/porting/targets/riot (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_COUNT (24)
 #endif
-#undef MYNEWT_VAL_BLE_HCI_BRIDGE_TRANSPORT
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/ram (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE
-#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_HS_COUNT (24)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/porting/targets/riot (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (2)
+/* Value copied from BLE_TRANSPORT_ACL_COUNT */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_FROM_LL_COUNT (24)
 #endif
 
-/* Overridden by @apache-mynewt-nimble/nimble/transport/ram (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT
-#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE (255)
 #endif
 
 /* Overridden by @apache-mynewt-nimble/porting/targets/riot (defined by @apache-mynewt-nimble/nimble/transport) */
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__builtin (0)
-#endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__custom
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__custom (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_COUNT (2)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__da1469x (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_DISCARDABLE_COUNT (16)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__dialog_cmac (0)
+
+/* Overridden by @apache-mynewt-nimble/nimble/transport (defined by @apache-mynewt-nimble/nimble/transport) */
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE
+#define MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE (257)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__emspi (0)
+
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__custom (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__nrf5340 (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__dialog_cmac (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__ram
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__ram (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__native
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__native (1)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__socket
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__socket (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__nrf5340 (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__uart
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__uart (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__uart
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__uart (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT__usb
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT__usb (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS__usb
+#define MYNEWT_VAL_BLE_TRANSPORT_HS__usb (0)
 #endif
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT (1)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_HS
+#define MYNEWT_VAL_BLE_TRANSPORT_HS (1)
 #endif
 
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_EMSPI (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__custom
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__custom (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__dialog_cmac (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__native
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__native (1)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__nrf5340 (0)
 #endif
-
-#ifndef MYNEWT_VAL_BLE_HCI_TRANSPORT_UART
-#define MYNEWT_VAL_BLE_HCI_TRANSPORT_UART (0)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL__socket
+#define MYNEWT_VAL_BLE_TRANSPORT_LL__socket (0)
 #endif
-
-/*** @apache-mynewt-nimble/nimble/transport/ram */
-#ifndef MYNEWT_VAL_BLE_TRANS_RAM_SYSINIT_STAGE
-#define MYNEWT_VAL_BLE_TRANS_RAM_SYSINIT_STAGE (100)
+#ifndef MYNEWT_VAL_BLE_TRANSPORT_LL
+#define MYNEWT_VAL_BLE_TRANSPORT_LL (1)
 #endif
 
 /*** newt */
diff --git a/porting/targets/linux/syscfg.yml b/porting/targets/linux/syscfg.yml
index 5778ee7..e5faa62 100644
--- a/porting/targets/linux/syscfg.yml
+++ b/porting/targets/linux/syscfg.yml
@@ -17,7 +17,7 @@
 #
 
 syscfg.vals:
-    BLE_HCI_TRANSPORT: socket
+    BLE_TRANSPORT_LL: socket
     BLE_SOCK_USE_TCP: 0
     BLE_SOCK_USE_LINUX_BLUE: 1
     BLE_SOCK_TASK_PRIO: 3
diff --git a/porting/targets/linux_blemesh/syscfg.yml b/porting/targets/linux_blemesh/syscfg.yml
index 5e644d4..b5e48f4 100644
--- a/porting/targets/linux_blemesh/syscfg.yml
+++ b/porting/targets/linux_blemesh/syscfg.yml
@@ -43,7 +43,7 @@ syscfg.vals:
     BLE_MESH_SETTINGS: 0
     CONFIG_NFFS: 0
 
-    BLE_HCI_TRANSPORT: socket
+    BLE_TRANSPORT_LL: socket
     BLE_SOCK_USE_TCP: 0
     BLE_SOCK_USE_LINUX_BLUE: 1
     BLE_SOCK_TASK_PRIO: 3
diff --git a/porting/targets/nuttx/syscfg.yml b/porting/targets/nuttx/syscfg.yml
index d2c6de7..98ec29b 100644
--- a/porting/targets/nuttx/syscfg.yml
+++ b/porting/targets/nuttx/syscfg.yml
@@ -17,7 +17,7 @@
 #
 
 syscfg.vals:
-    BLE_HCI_TRANSPORT: socket
+    BLE_TRANSPORT_LL: socket
     BLE_SOCK_USE_TCP: 0
     BLE_SOCK_USE_NUTTX: 1
     BLE_SOCK_TASK_PRIO: 3
diff --git a/porting/targets/porting_default/syscfg.yml b/porting/targets/porting_default/syscfg.yml
index 3ffd4c2..7c6db1a 100644
--- a/porting/targets/porting_default/syscfg.yml
+++ b/porting/targets/porting_default/syscfg.yml
@@ -1,4 +1,4 @@
 syscfg.vals:
-    BLE_HCI_TRANSPORT: socket
+    BLE_TRANSPORT_LL: socket
     BLE_SOCK_USE_TCP: 0
     BLE_SOCK_USE_LINUX_BLUE: 1
diff --git a/porting/targets/riot/syscfg.yml b/porting/targets/riot/syscfg.yml
index 1d6939c..380c219 100644
--- a/porting/targets/riot/syscfg.yml
+++ b/porting/targets/riot/syscfg.yml
@@ -17,9 +17,9 @@
 #
 
 syscfg.vals:
-    BLE_ACL_BUF_COUNT: 24
     BLE_HCI_VS: 1
-    BLE_HCI_EVT_HI_BUF_COUNT: 2
+    BLE_TRANSPORT_ACL_COUNT: 24
+    BLE_TRANSPORT_EVT_COUNT: 2
     BLE_HW_WHITELIST_ENABLE: 0
     BLE_LL_CFG_FEAT_DATA_LEN_EXT: 0
     BLE_LL_CFG_FEAT_LE_CSA2: 1
@@ -31,7 +31,6 @@ syscfg.vals:
     BLE_SM_LEGACY: 0
     BLE_SM_SC: 0
     BLE_MAX_PERIODIC_SYNCS: 0
-    BLE_HCI_TRANSPORT: ram
     MSYS_1_BLOCK_COUNT: 5
     MSYS_1_BLOCK_SIZE: 88
     MCU_LFCLK_SOURCE: LFXO

[mynewt-nimble] 15/22: babblesim/edtt: Update EDTT transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit f5a26ab05c55b4dd5d54f62e5001577743e8f8e0
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sat Mar 5 17:34:03 2022 +0100

    babblesim/edtt: Update EDTT transport
---
 babblesim/edtt/hci_test/syscfg.yml              |   4 +-
 babblesim/edtt/hci_transport/pkg.yml            |   5 +-
 babblesim/edtt/hci_transport/src/ble_hci_edtt.c | 277 ++----------------------
 babblesim/edtt/hci_transport/syscfg.yml         |  21 +-
 4 files changed, 32 insertions(+), 275 deletions(-)

diff --git a/babblesim/edtt/hci_test/syscfg.yml b/babblesim/edtt/hci_test/syscfg.yml
index bdf21e7..8a7909a 100644
--- a/babblesim/edtt/hci_test/syscfg.yml
+++ b/babblesim/edtt/hci_test/syscfg.yml
@@ -18,8 +18,8 @@
 #
 
 syscfg.vals:
-    BLE_HOST: 0
-    BLE_HCI_TRANSPORT: custom
+    BLE_TRANSPORT_LL: native
+    BLE_TRANSPORT_HS: custom
 
     # EDTT requires 0x123456789ABC address for first device
     # and 0x456789ABCDEF for second
diff --git a/babblesim/edtt/hci_transport/pkg.yml b/babblesim/edtt/hci_transport/pkg.yml
index 8e1dd9f..8ad24cd 100644
--- a/babblesim/edtt/hci_transport/pkg.yml
+++ b/babblesim/edtt/hci_transport/pkg.yml
@@ -28,8 +28,11 @@ pkg.deps:
     - "@apache-mynewt-core/kernel/os"
     - nimble/controller
 
+# allows to override settings from nimble/transport
+pkg.subpriority: 1
+
 pkg.apis:
     - ble_transport
 
 pkg.init:
-    ble_hci_edtt_init: 500
+    ble_hci_edtt_init: 249
diff --git a/babblesim/edtt/hci_transport/src/ble_hci_edtt.c b/babblesim/edtt/hci_transport/src/ble_hci_edtt.c
index 36db846..aa70f05 100644
--- a/babblesim/edtt/hci_transport/src/ble_hci_edtt.c
+++ b/babblesim/edtt/hci_transport/src/ble_hci_edtt.c
@@ -17,7 +17,6 @@
 /* BLE */
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 
 #include "bs_symbols.h"
 #include "bs_types.h"
@@ -26,9 +25,6 @@
 #include "edtt_driver.h"
 #include "commands.h"
 
-#define BLE_HCI_EDTT_EVT_COUNT  \
-    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
-
 #define BLE_HCI_EDTT_NONE        0x00
 #define BLE_HCI_EDTT_CMD         0x01
 #define BLE_HCI_EDTT_ACL         0x02
@@ -36,49 +32,6 @@
 
 #define BT_HCI_OP_VS_WRITE_BD_ADDR 0xFC06
 
-/* Callbacks for sending commands and acl data to ble_ll task */
-static ble_hci_trans_rx_cmd_fn *ble_hci_edtt_rx_cmd_cb;
-static void *ble_hci_edtt_rx_cmd_arg;
-static ble_hci_trans_rx_acl_fn *ble_hci_edtt_rx_acl_cb;
-static void *ble_hci_edtt_rx_acl_arg;
-
-/* Memory pool for hci events (high prio). 16 blocks x 70 bytes */
-static struct os_mempool ble_hci_edtt_evt_hi_pool;
-static os_membuf_t ble_hci_edtt_evt_hi_buf[
-    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-/* Memory pool for hci events (low prio). 16 blocks x 70 bytes */
-static struct os_mempool ble_hci_edtt_evt_lo_pool;
-static os_membuf_t ble_hci_edtt_evt_lo_buf[
-    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                    MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-/* Memory pool for hci commands. Only 1 block, so supports only 1 command at once. */
-static struct os_mempool ble_hci_edtt_cmd_pool;
-static os_membuf_t ble_hci_edtt_cmd_buf[
-    OS_MEMPOOL_SIZE(1, BLE_HCI_TRANS_CMD_SZ)
-];
-
-/*
- * The MBUF payload size must accommodate the HCI data header size plus the
- * maximum ACL data packet length. The ACL block size is the size of the
- * mbufs we will allocate.
- */
-#define ACL_BLOCK_SIZE  OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) \
-                                 + BLE_MBUF_MEMBLOCK_OVERHEAD \
-                                 + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-
-/* mbuf pool for acl data. 15 buffers x (255 bytes + some hdrs len)  */
-static struct os_mbuf_pool ble_hci_edtt_acl_mbuf_pool;
-static struct os_mempool_ext ble_hci_edtt_acl_pool;
-static os_membuf_t ble_hci_edtt_acl_buf[
-    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                    ACL_BLOCK_SIZE)
-];
-
 /* A packet for queueing EDTT/HCI commands and events */
 struct ble_hci_edtt_pkt {
     struct os_event ev;
@@ -145,28 +98,6 @@ log_hci_init()
 }
 #endif
 
-/**
- * Allocates a buffer (mbuf) for ACL operation.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-static struct os_mbuf *
-ble_hci_trans_acl_buf_alloc(void)
-{
-    struct os_mbuf *m;
-    uint8_t usrhdr_len;
-
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    usrhdr_len = sizeof(struct ble_mbuf_hdr);
-#else
-    usrhdr_len = 0;
-#endif
-
-    m = os_mbuf_get_pkthdr(&ble_hci_edtt_acl_mbuf_pool, usrhdr_len);
-    return m;
-}
-
 static int
 ble_hci_edtt_acl_tx(struct os_mbuf *om)
 {
@@ -201,18 +132,6 @@ ble_hci_edtt_cmdevt_tx(uint8_t *hci_ev, uint8_t edtt_type)
     return 0;
 }
 
-static void
-ble_hci_edtt_set_rx_cbs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                        void *cmd_arg,
-                        ble_hci_trans_rx_acl_fn *acl_cb,
-                        void *acl_arg)
-{
-    ble_hci_edtt_rx_cmd_cb = cmd_cb;
-    ble_hci_edtt_rx_cmd_arg = cmd_arg;
-    ble_hci_edtt_rx_acl_cb = acl_cb;
-    ble_hci_edtt_rx_acl_arg = acl_arg;
-}
-
 /**
  * Sends an HCI event from the controller to the host.
  *
@@ -223,12 +142,9 @@ ble_hci_edtt_set_rx_cbs(ble_hci_trans_rx_cmd_fn *cmd_cb,
  *                              A BLE_ERR_[...] error code on failure.
  */
 int
-ble_hci_trans_ll_evt_tx(uint8_t *cmd)
+ble_transport_to_hs_evt(void *buf)
 {
-    int rc;
-
-    rc = ble_hci_edtt_cmdevt_tx(cmd, BLE_HCI_EDTT_EVT);
-    return rc;
+    return ble_hci_edtt_cmdevt_tx(buf, BLE_HCI_EDTT_EVT);
 }
 
 /**
@@ -240,120 +156,9 @@ ble_hci_trans_ll_evt_tx(uint8_t *cmd)
  *                              A BLE_ERR_[...] error code on failure.
  */
 int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
+ble_transport_to_hs_acl(struct os_mbuf *om)
 {
-    int rc;
-
-    rc = ble_hci_edtt_acl_tx(om);
-    return rc;
-}
-
-int
-ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
-{
-    int rc;
-
-    rc = ble_hci_edtt_cmdevt_tx(cmd, BLE_HCI_EDTT_CMD);
-    return rc;
-}
-
-int
-ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
-{
-    int rc;
-
-    rc = ble_hci_edtt_acl_tx(om);
-    return rc;
-}
-
-/**
- * Allocates a flat buffer of the specified type.
- *
- * @param type                  The type of buffer to allocate; one of the
- *                                  BLE_HCI_TRANS_BUF_[...] constants.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-uint8_t *
-ble_hci_trans_buf_alloc(int type) {
-    uint8_t *buf;
-
-    switch (type) {
-        case BLE_HCI_TRANS_BUF_CMD:
-            buf = os_memblock_get(&ble_hci_edtt_cmd_pool);
-            break;
-        case BLE_HCI_TRANS_BUF_EVT_HI:
-            buf = os_memblock_get(&ble_hci_edtt_evt_hi_pool);
-            if (buf == NULL) {
-                /* If no high-priority event buffers remain, try to grab a
-                 * low-priority one.
-                 */
-                buf = os_memblock_get(&ble_hci_edtt_evt_lo_pool);
-            }
-            break;
-
-        case BLE_HCI_TRANS_BUF_EVT_LO:
-            buf = os_memblock_get(&ble_hci_edtt_evt_lo_pool);
-            break;
-
-        default:
-            assert(0);
-            buf = NULL;
-    }
-
-    return buf;
-}
-
-/**
- * Frees the specified flat buffer.  The buffer must have been allocated via
- * ble_hci_trans_buf_alloc().
- *
- * @param buf                   The buffer to free.
- */
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    /*
-     * XXX: this may look a bit odd, but the controller uses the command
-     * buffer to send back the command complete/status as an immediate
-     * response to the command. This was done to insure that the controller
-     * could always send back one of these events when a command was received.
-     * Thus, we check to see which pool the buffer came from so we can free
-     * it to the appropriate pool
-     */
-    if (os_memblock_from(&ble_hci_edtt_evt_hi_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_edtt_evt_hi_pool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_edtt_evt_lo_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_edtt_evt_lo_pool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_edtt_cmd_pool, buf)) {
-        assert(os_memblock_from(&ble_hci_edtt_cmd_pool, buf));
-        rc = os_memblock_put(&ble_hci_edtt_cmd_pool, buf);
-        assert(rc == 0);
-    } else {
-        free(buf);
-    }
-}
-
-int
-ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
-{
-    ble_hci_edtt_acl_pool.mpe_put_cb = cb;
-    ble_hci_edtt_acl_pool.mpe_put_arg = arg;
-    return 0;
-}
-
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_edtt_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
+    return ble_hci_edtt_acl_tx(om);
 }
 
 /**
@@ -398,8 +203,7 @@ send_hci_cmd_to_ctrl(uint16_t opcode, uint8_t param_len, uint16_t response) {
     waiting_response = response;
     waiting_opcode = opcode;
 
-    buf = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-
+    buf = ble_transport_alloc_cmd();
     if (buf != NULL) {
         buf->opcode = opcode;
         buf->length = param_len;
@@ -412,9 +216,9 @@ send_hci_cmd_to_ctrl(uint16_t opcode, uint8_t param_len, uint16_t response) {
         log_hci_cmd(opcode, buf->data, param_len);
 #endif
 
-        err = ble_hci_edtt_rx_cmd_cb((uint8_t *) buf, NULL);
+        err = ble_transport_to_ll_cmd(buf);
         if (err) {
-            ble_hci_trans_buf_free((uint8_t *) buf);
+            ble_transport_free(buf);
             bs_trace_raw_time(3, "Failed to send HCI command %d (err %d)", opcode, err);
             error_response(err);
         }
@@ -454,7 +258,9 @@ command_complete(struct ble_hci_ev *evt)
     uint16_t response = waiting_response;
     uint16_t size = evt->length - sizeof(evt_cc->num_packets) - sizeof(evt_cc->opcode);
 
-    if (evt_cc->opcode == waiting_opcode) {
+    if (evt_cc->opcode == 0) {
+        /* ignore nop */
+    } else if (evt_cc->opcode == waiting_opcode) {
         bs_trace_raw_time(9, "Command complete for 0x%04x", waiting_opcode);
 
         edtt_write((uint8_t *) &response, sizeof(response), EDTTT_BLOCK);
@@ -507,7 +313,7 @@ static void
 free_event(struct ble_hci_edtt_pkt *pkt)
 {
     assert(pkt);
-    ble_hci_trans_buf_free((void *)pkt->data);
+    ble_transport_free(pkt->data);
     free(pkt);
 }
 
@@ -553,9 +359,10 @@ dup_complete_evt(void *evt)
 {
     struct ble_hci_ev *evt_copy;
 
-    evt_copy = calloc(1, BLE_HCI_TRANS_CMD_SZ);
-    memcpy(evt_copy, evt, BLE_HCI_TRANS_CMD_SZ);
-    ble_hci_trans_buf_free((void *)evt);
+    /* max evt size is always 257 */
+    evt_copy = ble_transport_alloc_evt(0);
+    memcpy(evt_copy, evt, 257);
+    ble_transport_free(evt);
 
     return evt_copy;
 }
@@ -598,14 +405,14 @@ service_events(void *arg)
                 assert(evt_ncp->count == 1);
                 if (evt_ncp->completed[0].packets == 0) {
                     /* Discard, because EDTT does not like it */
-                    ble_hci_trans_buf_free((void *)evt);
+                    ble_transport_free(evt);
                 } else {
                     queue_event(evt);
                 }
                 break;
             case BLE_HCI_OPCODE_NOP:
                 /* Ignore noop bytes from Link layer */
-                ble_hci_trans_buf_free((void *)evt);
+                ble_transport_free(evt);
                 break;
             default:
                 /* Queue HCI events. We will send them to EDTT
@@ -831,7 +638,7 @@ le_data_write(uint16_t size)
     int err;
 
     if (size >= sizeof(hdr)) {
-        om = ble_hci_trans_acl_buf_alloc();
+        om = ble_transport_alloc_acl_from_hs();
         if (om) {
             edtt_read((void *)&hdr, sizeof(hdr), EDTTT_BLOCK);
             size -= sizeof(hdr);
@@ -848,7 +655,7 @@ le_data_write(uint16_t size)
                 os_mbuf_append(om, tmp, hdr.hdh_len);
             }
 
-            err = ble_hci_edtt_rx_acl_cb(om, NULL);
+            err = ble_transport_to_ll_acl(om);
             if (err) {
                 bs_trace_raw_time(3, "Failed to send ACL Data (err %d)", err);
             }
@@ -874,7 +681,7 @@ fake_write_bd_addr_cc()
     waiting_opcode = BT_HCI_OP_VS_WRITE_BD_ADDR;
     waiting_response = CMD_WRITE_BD_ADDR_RSP;
 
-    hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    hci_ev = ble_transport_alloc_evt(0);
     if (hci_ev) {
         hci_ev->opcode = BLE_HCI_EVCODE_COMMAND_COMPLETE;
         hci_ev->length = sizeof(*ev);
@@ -997,53 +804,9 @@ edtt_init(void)
 void
 ble_hci_edtt_init(void)
 {
-    int rc;
-
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
-    rc = os_mempool_ext_init(&ble_hci_edtt_acl_pool,
-                             MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                             ACL_BLOCK_SIZE,
-                             ble_hci_edtt_acl_buf,
-                             "ble_hci_edtt_acl_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&ble_hci_edtt_acl_mbuf_pool,
-                           &ble_hci_edtt_acl_pool.mpe_mp,
-                           ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    /*
-     * Create memory pool of HCI command buffers. NOTE: we currently dont
-     * allow this to be configured. The controller will only allow one
-     * outstanding command. We decided to keep this a pool in case we allow
-     * allow the controller to handle more than one outstanding command.
-     */
-    rc = os_mempool_init(&ble_hci_edtt_cmd_pool,
-                         1,
-                         BLE_HCI_TRANS_CMD_SZ,
-                         ble_hci_edtt_cmd_buf,
-                         "ble_hci_edtt_cmd_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_edtt_evt_hi_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_edtt_evt_hi_buf,
-                         "ble_hci_edtt_evt_hi_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_edtt_evt_lo_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_edtt_evt_lo_buf,
-                         "ble_hci_edtt_evt_lo_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failure configuring edtt HCI");
-
     os_eventq_init(&edtt_q_svc);
     os_eventq_init(&edtt_q_event);
     os_eventq_init(&edtt_q_data);
diff --git a/babblesim/edtt/hci_transport/syscfg.yml b/babblesim/edtt/hci_transport/syscfg.yml
index b203361..ad12f7b 100644
--- a/babblesim/edtt/hci_transport/syscfg.yml
+++ b/babblesim/edtt/hci_transport/syscfg.yml
@@ -31,19 +31,10 @@ syscfg.defs:
         type: task_priority
         value: 2
 
-    BLE_HCI_ACL_OUT_COUNT:
-        description: >
-            This count is used in creating a pool of elements used by the
-            code to enqueue various elements. In the case of the controller
-            only HCI, this number should be equal to the number of mbufs in
-            the msys pool. For host only, it is really dependent on the
-            number of ACL buffers that the controller tells the host it
-            has.
-        value: 12
-
 syscfg.vals:
-    BLE_ACL_BUF_COUNT: 32
-    BLE_ACL_BUF_SIZE: 255
-    BLE_HCI_EVT_BUF_SIZE: 257
-    BLE_HCI_EVT_HI_BUF_COUNT: 32
-    BLE_HCI_EVT_LO_BUF_COUNT: 32
+    BLE_TRANSPORT_ACL_COUNT: 32
+    BLE_TRANSPORT_EVT_COUNT: 64
+
+syscfg.restrictions:
+    - BLE_TRANSPORT_HS == "custom"
+    - BLE_TRANSPORT_LL == "native"
\ No newline at end of file

[mynewt-nimble] 10/22: nimble/transport: Update socket transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 74d8f03a1a10b5261fac035fd61712084a9a7c64
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 10 12:48:35 2022 +0100

    nimble/transport: Update socket transport
    
    This only works for external controller, external host can be
    implemented if needed (not sure who would use that though).
---
 nimble/transport/pkg.yml                     |   2 +
 nimble/transport/socket/src/ble_hci_socket.c | 270 ++++-----------------------
 nimble/transport/socket/syscfg.yml           |  20 --
 nimble/transport/syscfg.yml                  |   1 +
 4 files changed, 41 insertions(+), 252 deletions(-)

diff --git a/nimble/transport/pkg.yml b/nimble/transport/pkg.yml
index 287ed97..e5dad56 100644
--- a/nimble/transport/pkg.yml
+++ b/nimble/transport/pkg.yml
@@ -36,6 +36,8 @@ pkg.deps.'BLE_TRANSPORT_HS == "dialog_cmac" || BLE_TRANSPORT_LL == "dialog_cmac"
     - nimble/transport/dialog_cmac
 pkg.deps.'BLE_TRANSPORT_HS == "nrf5340" || BLE_TRANSPORT_LL == "nrf5340"':
     - nimble/transport/nrf5340
+pkg.deps.'BLE_TRANSPORT_LL == "socket"':
+    - nimble/transport/socket
 pkg.deps.'BLE_TRANSPORT_HS == "uart"':
     - nimble/transport/uart
 pkg.deps.'BLE_TRANSPORT_HS == "usb"':
diff --git a/nimble/transport/socket/src/ble_hci_socket.c b/nimble/transport/socket/src/ble_hci_socket.c
index 8a73389..ee974ec 100644
--- a/nimble/transport/socket/src/ble_hci_socket.c
+++ b/nimble/transport/socket/src/ble_hci_socket.c
@@ -85,7 +85,7 @@ struct sockaddr_hci {
 #include "nimble/nimble_opt.h"
 #include "nimble/hci_common.h"
 #include "nimble/nimble_npl.h"
-#include "nimble/ble_hci_trans.h"
+#include "nimble/transport.h"
 #include "socket/ble_hci_socket.h"
 
 /***
@@ -155,45 +155,6 @@ struct os_task ble_sock_task;
 
 #endif
 
-static struct os_mempool ble_hci_sock_evt_hi_pool;
-static os_membuf_t ble_hci_sock_evt_hi_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_sock_evt_lo_pool;
-static os_membuf_t ble_hci_sock_evt_lo_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                        MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))
-];
-
-static struct os_mempool ble_hci_sock_cmd_pool;
-static os_membuf_t ble_hci_sock_cmd_buf[
-        OS_MEMPOOL_SIZE(1, BLE_HCI_TRANS_CMD_SZ)
-];
-
-static struct os_mempool ble_hci_sock_acl_pool;
-static struct os_mbuf_pool ble_hci_sock_acl_mbuf_pool;
-
-#define ACL_BLOCK_SIZE  OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) \
-                                 + BLE_MBUF_MEMBLOCK_OVERHEAD \
-                                 + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-/*
- * The MBUF payload size must accommodate the HCI data header size plus the
- * maximum ACL data packet length. The ACL block size is the size of the
- * mbufs we will allocate.
- */
-
-static os_membuf_t ble_hci_sock_acl_buf[
-        OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                        ACL_BLOCK_SIZE)
-];
-
-static ble_hci_trans_rx_cmd_fn *ble_hci_sock_rx_cmd_cb;
-static void *ble_hci_sock_rx_cmd_arg;
-static ble_hci_trans_rx_acl_fn *ble_hci_sock_rx_acl_cb;
-static void *ble_hci_sock_rx_acl_arg;
-
 static struct ble_hci_sock_state {
     int sock;
     struct ble_npl_eventq evq;
@@ -212,26 +173,6 @@ static int s_ble_hci_device = MYNEWT_VAL(BLE_SOCK_LINUX_DEV);
 static int s_ble_hci_device = 0;
 #endif
 
-/**
- * Allocates a buffer (mbuf) for ACL operation.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-static struct os_mbuf *
-ble_hci_trans_acl_buf_alloc(void)
-{
-    struct os_mbuf *m;
-
-    /*
-     * XXX: note that for host only there would be no need to allocate
-     * a user header. Address this later.
-     */
-    m = os_mbuf_get_pkthdr(&ble_hci_sock_acl_mbuf_pool,
-                           sizeof(struct ble_mbuf_hdr));
-    return m;
-}
-
 #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
 static int
 ble_hci_sock_acl_tx(struct os_mbuf *om)
@@ -365,7 +306,7 @@ ble_hci_sock_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
     STATS_INCN(hci_sock_stats, obytes, len + 1);
 
     i = sendmsg(ble_hci_sock_state.sock, &msg, 0);
-    ble_hci_trans_buf_free(hci_ev);
+    ble_transport_free(hci_ev);
     if (i != len + 1) {
         if (i < 0) {
             dprintf(1, "sendmsg() failed : %d\n", errno);
@@ -468,17 +409,17 @@ ble_hci_sock_rx_msg(void)
             }
             STATS_INC(hci_sock_stats, imsg);
             STATS_INC(hci_sock_stats, icmd);
-            data = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+            data = ble_transport_alloc_cmd();
             if (!data) {
                 STATS_INC(hci_sock_stats, ierr);
                 break;
             }
             memcpy(data, &bhss->rx_data[1], len - 1);
             OS_ENTER_CRITICAL(sr);
-            rc = ble_hci_sock_rx_cmd_cb(data, ble_hci_sock_rx_cmd_arg);
+            rc = ble_transport_to_ll_cmd(data);
             OS_EXIT_CRITICAL(sr);
             if (rc) {
-                ble_hci_trans_buf_free(data);
+                ble_transport_free(data);
                 STATS_INC(hci_sock_stats, ierr);
                 break;
             }
@@ -495,17 +436,17 @@ ble_hci_sock_rx_msg(void)
             }
             STATS_INC(hci_sock_stats, imsg);
             STATS_INC(hci_sock_stats, ievt);
-            data = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+            data = ble_transport_alloc_evt(0);
             if (!data) {
                 STATS_INC(hci_sock_stats, ierr);
                 break;
             }
             memcpy(data, &bhss->rx_data[1], len - 1);
             OS_ENTER_CRITICAL(sr);
-            rc = ble_hci_sock_rx_cmd_cb(data, ble_hci_sock_rx_cmd_arg);
+            rc = ble_transport_to_hs_evt(data);
             OS_EXIT_CRITICAL(sr);
             if (rc) {
-                ble_hci_trans_buf_free(data);
+                ble_transport_free(data);
                 STATS_INC(hci_sock_stats, ierr);
                 return 0;
             }
@@ -522,7 +463,11 @@ ble_hci_sock_rx_msg(void)
             }
             STATS_INC(hci_sock_stats, imsg);
             STATS_INC(hci_sock_stats, iacl);
-            m = ble_hci_trans_acl_buf_alloc();
+#if MYNEWT_VAL(BLE_CONTROLLER)
+            m = ble_transport_alloc_acl_from_hs();
+#else
+            m = ble_transport_alloc_acl_from_ll();
+#endif
             if (!m) {
                 STATS_INC(hci_sock_stats, imem);
                 break;
@@ -533,7 +478,11 @@ ble_hci_sock_rx_msg(void)
                 break;
             }
             OS_ENTER_CRITICAL(sr);
-            ble_hci_sock_rx_acl_cb(m, ble_hci_sock_rx_acl_arg);
+#if MYNEWT_VAL(BLE_CONTROLLER)
+            ble_transport_to_ll_acl(m);
+#else
+            ble_transport_to_hs_acl(m);
+#endif
             OS_EXIT_CRITICAL(sr);
             break;
         default:
@@ -786,129 +735,6 @@ ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
 }
 
 /**
- * Configures the HCI transport to call the specified callback upon receiving
- * HCI packets from the controller.  This function should only be called by by
- * host.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_sock_rx_cmd_cb = cmd_cb;
-    ble_hci_sock_rx_cmd_arg = cmd_arg;
-    ble_hci_sock_rx_acl_cb = acl_cb;
-    ble_hci_sock_rx_acl_arg = acl_arg;
-}
-
-/**
- * Configures the HCI transport to operate with a host.  The transport will
- * execute specified callbacks upon receiving HCI packets from the controller.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                     void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb,
-                     void *acl_arg)
-{
-    ble_hci_sock_rx_cmd_cb = cmd_cb;
-    ble_hci_sock_rx_cmd_arg = cmd_arg;
-    ble_hci_sock_rx_acl_cb = acl_cb;
-    ble_hci_sock_rx_acl_arg = acl_arg;
-}
-
-/**
- * Allocates a flat buffer of the specified type.
- *
- * @param type                  The type of buffer to allocate; one of the
- *                                  BLE_HCI_TRANS_BUF_[...] constants.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        buf = os_memblock_get(&ble_hci_sock_cmd_pool);
-        break;
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_sock_evt_hi_pool);
-        if (buf == NULL) {
-            /* If no high-priority event buffers remain, try to grab a
-             * low-priority one.
-             */
-            buf = os_memblock_get(&ble_hci_sock_evt_lo_pool);
-        }
-        break;
-
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&ble_hci_sock_evt_lo_pool);
-        break;
-
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-/**
- * Frees the specified flat buffer.  The buffer must have been allocated via
- * ble_hci_trans_buf_alloc().
- *
- * @param buf                   The buffer to free.
- */
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    /*
-     * XXX: this may look a bit odd, but the controller uses the command
-     * buffer to send back the command complete/status as an immediate
-     * response to the command. This was done to insure that the controller
-     * could always send back one of these events when a command was received.
-     * Thus, we check to see which pool the buffer came from so we can free
-     * it to the appropriate pool
-     */
-    if (os_memblock_from(&ble_hci_sock_evt_hi_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_sock_evt_hi_pool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_sock_evt_lo_pool, buf)) {
-        rc = os_memblock_put(&ble_hci_sock_evt_lo_pool, buf);
-        assert(rc == 0);
-    } else {
-        assert(os_memblock_from(&ble_hci_sock_cmd_pool, buf));
-        rc = os_memblock_put(&ble_hci_sock_cmd_pool, buf);
-        assert(rc == 0);
-    }
-}
-
-/**
  * Resets the HCI UART transport to a clean state.  Frees all buffers and
  * reconfigures the UART.
  *
@@ -997,46 +823,6 @@ ble_hci_sock_init(void)
     ble_hci_sock_init_task();
     ble_npl_event_init(&ble_hci_sock_state.ev, ble_hci_sock_rx_ev, NULL);
 
-    rc = os_mempool_init(&ble_hci_sock_acl_pool,
-                         MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                         ACL_BLOCK_SIZE,
-                         ble_hci_sock_acl_buf,
-                         "ble_hci_sock_acl_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&ble_hci_sock_acl_mbuf_pool,
-                           &ble_hci_sock_acl_pool,
-                           ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    /*
-     * Create memory pool of HCI command buffers. NOTE: we currently dont
-     * allow this to be configured. The controller will only allow one
-     * outstanding command. We decided to keep this a pool in case we allow
-     * allow the controller to handle more than one outstanding command.
-     */
-    rc = os_mempool_init(&ble_hci_sock_cmd_pool,
-                         1,
-                         BLE_HCI_TRANS_CMD_SZ,
-                         &ble_hci_sock_cmd_buf,
-                         "ble_hci_sock_cmd_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_sock_evt_hi_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         &ble_hci_sock_evt_hi_buf,
-                         "ble_hci_sock_evt_hi_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_sock_evt_lo_pool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_sock_evt_lo_buf,
-                         "ble_hci_sock_evt_lo_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
     rc = ble_hci_sock_config();
     SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failure configuring socket HCI");
 
@@ -1045,3 +831,23 @@ ble_hci_sock_init(void)
                             STATS_NAME_INIT_PARMS(hci_sock_stats), "hci_socket");
     SYSINIT_PANIC_ASSERT(rc == 0);
 }
+
+void
+ble_transport_ll_init(void)
+{
+    ble_hci_sock_init();
+}
+
+int
+ble_transport_to_ll_acl(struct os_mbuf *om)
+{
+    return ble_hci_trans_hs_acl_tx(om);
+}
+
+int
+ble_transport_to_ll_cmd(void *buf)
+{
+    return ble_hci_trans_hs_cmd_tx(buf);
+}
+
+/* TODO: add ll-to-hs side if needed */
diff --git a/nimble/transport/socket/syscfg.yml b/nimble/transport/socket/syscfg.yml
index 63b9cdd..c74f056 100644
--- a/nimble/transport/socket/syscfg.yml
+++ b/nimble/transport/socket/syscfg.yml
@@ -17,16 +17,6 @@
 #
 
 syscfg.defs:
-    BLE_HCI_ACL_OUT_COUNT:
-        description: >
-            This count is used in creating a pool of elements used by the
-            code to enqueue various elements. In the case of the controller
-            only HCI, this number should be equal to the number of mbufs in
-            the msys pool. For host only, it is really dependent on the
-            number of ACL buffers that the controller tells the host it
-            has.
-        value: 12
-
     BLE_SOCK_USE_TCP:
         description: 'Use TCP socket, connects to BLE_SOCK_TCP_PORT'
         value: 1
@@ -60,13 +50,3 @@ syscfg.defs:
         description: >
             Sysinit stage for the socket BLE transport.
         value: 500
-
-syscfg.vals.'!BLE_HCI_BRIDGE && BLE_EXT_ADV':
-    BLE_HCI_EVT_BUF_SIZE: 257
-
-syscfg.vals.'!BLE_HCI_BRIDGE && !BLE_EXT_ADV':
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_HCI_EVT_HI_BUF_COUNT: 8
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_ACL_BUF_COUNT: 24
-    BLE_ACL_BUF_SIZE: 255
diff --git a/nimble/transport/syscfg.yml b/nimble/transport/syscfg.yml
index d2404e1..cb9e07e 100644
--- a/nimble/transport/syscfg.yml
+++ b/nimble/transport/syscfg.yml
@@ -42,6 +42,7 @@ syscfg.defs:
             - native
             - dialog_cmac
             - nrf5340
+            - socket
             - custom
 
     BLE_TRANSPORT_ACL_COUNT:

[mynewt-nimble] 02/22: nimble/transport: Add common code for new HCI transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit d5201cb83bf0a5f3b9788b0721b656fb22a96223
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:07:56 2022 +0100

    nimble/transport: Add common code for new HCI transport
---
 nimble/include/nimble/ble_hci_trans.h       | 192 ------------------------
 nimble/transport/include/nimble/transport.h |  55 +++++++
 nimble/transport/pkg.yml                    |  48 +++---
 nimble/transport/src/transport.c            | 217 ++++++++++++++++++++++++++++
 nimble/transport/syscfg.defunct.yml         |  40 +++++
 nimble/transport/syscfg.yml                 | 153 ++++++++------------
 6 files changed, 394 insertions(+), 311 deletions(-)

diff --git a/nimble/include/nimble/ble_hci_trans.h b/nimble/include/nimble/ble_hci_trans.h
deleted file mode 100644
index e8d3ec0..0000000
--- a/nimble/include/nimble/ble_hci_trans.h
+++ /dev/null
@@ -1,192 +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_HCI_TRANSPORT_
-#define H_HCI_TRANSPORT_
-
-#include <inttypes.h>
-#include "os/os_mempool.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct os_mbuf;
-
-#define BLE_HCI_TRANS_CMD_SZ        260
-
-/*** Type of buffers for holding commands and events. */
-/**
- * Controller-to-host event buffers.  Events have one of two priorities:
- * o Low-priority   (BLE_HCI_TRANS_BUF_EVT_LO)
- * o High-priority  (BLE_HCI_TRANS_BUF_EVT_HI)
- *
- * Low-priority event buffers are only used for advertising reports.  If there
- * are no free low-priority event buffers, then an incoming advertising report
- * will get dropped.
- *
- * High-priority event buffers are for everything except advertising reports.
- * If there are no free high-priority event buffers, a request to allocate one
- * will try to allocate a low-priority buffer instead.
- *
- * If you want all events to be given equal treatment, then you should allocate
- * low-priority events only.
- *
- * Event priorities solve the problem of critical events getting dropped due to
- * a flood of advertising reports.  This solution is likely temporary: when
- * HCI flow control is added, event priorities may become obsolete.
- *
- * Not all transports distinguish between low and high priority events.  If the
- * transport does not have separate settings for low and high buffer counts,
- * then it treats all events with equal priority.
- */
-#define BLE_HCI_TRANS_BUF_EVT_LO    1
-#define BLE_HCI_TRANS_BUF_EVT_HI    2
-
-/* Host-to-controller command. */
-#define BLE_HCI_TRANS_BUF_CMD       3
-
-/** Callback function types; executed when HCI packets are received. */
-typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
-typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);
-
-/**
- * Sends an HCI event from the controller to the host.
- *
- * @param cmd                   The HCI event to send.  This buffer must be
- *                                  allocated via ble_hci_trans_buf_alloc().
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int ble_hci_trans_ll_evt_tx(uint8_t *hci_ev);
-
-/**
- * Sends ACL data from controller to host.
- *
- * @param om                    The ACL data packet to send.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int ble_hci_trans_ll_acl_tx(struct os_mbuf *om);
-
-/**
- * Sends an HCI command from the host to the controller.
- *
- * @param cmd                   The HCI command to send.  This buffer must be
- *                                  allocated via ble_hci_trans_buf_alloc().
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int ble_hci_trans_hs_cmd_tx(uint8_t *cmd);
-
-/**
- * Sends ACL data from host to controller.
- *
- * @param om                    The ACL data packet to send.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int ble_hci_trans_hs_acl_tx(struct os_mbuf *om);
-
-/**
- * Allocates a flat buffer of the specified type.
- *
- * @param type                  The type of buffer to allocate; one of the
- *                                  BLE_HCI_TRANS_BUF_[...] constants.
- *
- * @return                      The allocated buffer on success;
- *                              NULL on buffer exhaustion.
- */
-uint8_t *ble_hci_trans_buf_alloc(int type);
-
-/**
- * Frees the specified flat buffer.  The buffer must have been allocated via
- * ble_hci_trans_buf_alloc().
- *
- * @param buf                   The buffer to free.
- */
-void ble_hci_trans_buf_free(uint8_t *buf);
-
-/**
- * Configures a callback to get executed whenever an ACL data packet is freed.
- * The function is called immediately before the free occurs.
- *
- * @param cb                    The callback to configure.
- * @param arg                   An optional argument to pass to the callback.
- *
- * @return                      0 on success;
- *                              BLE_ERR_UNSUPPORTED if the transport does not
- *                                  support this operation.
- */
-int ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg);
-
-/**
- * Configures the HCI transport to operate with a controller.  The transport
- * will execute specified callbacks upon receiving HCI packets from the host.
- *
- * @param cmd_cb                The callback to execute upon receiving an HCI
- *                                  command.
- * @param cmd_arg               Optional argument to pass to the command
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                          void *cmd_arg,
-                          ble_hci_trans_rx_acl_fn *acl_cb,
-                          void *acl_arg);
-
-/**
- * Configures the HCI transport to operate with a host.  The transport will
- * execute specified callbacks upon receiving HCI packets from the controller.
- *
- * @param evt_cb                The callback to execute upon receiving an HCI
- *                                  event.
- * @param evt_arg               Optional argument to pass to the event
- *                                  callback.
- * @param acl_cb                The callback to execute upon receiving ACL
- *                                  data.
- * @param acl_arg               Optional argument to pass to the ACL
- *                                  callback.
- */
-void ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb,
-                          void *evt_arg,
-                          ble_hci_trans_rx_acl_fn *acl_cb,
-                          void *acl_arg);
-
-/**
- * Resets the HCI module to a clean state.  Frees all buffers and reinitializes
- * the underlying transport.
- *
- * @return                      0 on success;
- *                              A BLE_ERR_[...] error code on failure.
- */
-int ble_hci_trans_reset(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_HCI_TRANSPORT_ */
diff --git a/nimble/transport/include/nimble/transport.h b/nimble/transport/include/nimble/transport.h
new file mode 100644
index 0000000..98dba30
--- /dev/null
+++ b/nimble/transport/include/nimble/transport.h
@@ -0,0 +1,55 @@
+/*
+ * 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_NIMBLE_TRANSPORT_
+#define H_NIMBLE_TRANSPORT_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct os_mbuf;
+
+/* Init functions to be implemented for transport acting as HS/LL side */
+extern void ble_transport_ll_init(void);
+extern void ble_transport_hs_init(void);
+
+/* APIs to be implemented by HS/LL side of transports */
+extern int ble_transport_to_ll_cmd(void *buf);
+extern int ble_transport_to_ll_acl(struct os_mbuf *om);
+extern int ble_transport_to_hs_evt(void *buf);
+extern int ble_transport_to_hs_acl(struct os_mbuf *om);
+
+/* Allocators for supported data types */
+void *ble_transport_alloc_cmd(void);
+void *ble_transport_alloc_evt(int discardable);
+struct os_mbuf *ble_transport_alloc_acl_from_hs(void);
+struct os_mbuf *ble_transport_alloc_acl_from_ll(void);
+
+/* Generic deallocator for cmd/evt buffers */
+void ble_transport_free(void *buf);
+
+/* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
+int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_NIMBLE_TRANSPORT_ */
diff --git a/nimble/transport/pkg.yml b/nimble/transport/pkg.yml
index 5484002..287ed97 100644
--- a/nimble/transport/pkg.yml
+++ b/nimble/transport/pkg.yml
@@ -25,36 +25,26 @@ pkg.keywords:
     - ble
     - bluetooth
 
-pkg.deps.'BLE_HCI_TRANSPORT == "builtin"':
-    - nimble/transport/ram
-    - nimble/controller
-
-pkg.deps.'BLE_HCI_TRANSPORT == "emspi"':
-    - nimble/transport/emspi
-
-pkg.deps.'BLE_HCI_TRANSPORT == "ram"':
-    - nimble/transport/ram
-
-pkg.deps.'BLE_HCI_TRANSPORT == "socket"':
-    - nimble/transport/socket
+pkg.apis:
+    - ble_transport
 
-pkg.deps.'BLE_HCI_TRANSPORT == "uart"':
-    - nimble/transport/uart
-
-pkg.deps.'BLE_HCI_TRANSPORT == "da1469x"':
-    - nimble/transport/da1469x
-
-pkg.deps.'BLE_HCI_TRANSPORT == "dialog_cmac"':
+pkg.deps.'BLE_TRANSPORT_HS == "native"':
+    - nimble/host
+pkg.deps.'BLE_TRANSPORT_LL == "native"':
+    - nimble/controller
+pkg.deps.'BLE_TRANSPORT_HS == "dialog_cmac" || BLE_TRANSPORT_LL == "dialog_cmac"':
     - nimble/transport/dialog_cmac
-
-pkg.deps.'BLE_HCI_TRANSPORT == "usb"':
-    - nimble/transport/usb
-
-pkg.deps.'BLE_HCI_TRANSPORT == "nrf5340"':
-    - nimble/transport/nrf5340
-
-pkg.deps.'BLE_HCI_BRIDGE_TRANSPORT == "nrf5340"':
+pkg.deps.'BLE_TRANSPORT_HS == "nrf5340" || BLE_TRANSPORT_LL == "nrf5340"':
     - nimble/transport/nrf5340
+pkg.deps.'BLE_TRANSPORT_HS == "uart"':
+    - nimble/transport/uart
+pkg.deps.'BLE_TRANSPORT_HS == "usb"':
+    - nimble/transport/usb
 
-pkg.deps.'BLE_HCI_BRIDGE_TRANSPORT == "dialog_cmac"':
-    - nimble/transport/dialog_cmac
+pkg.init:
+    ble_transport_init: 250
+    ble_transport_hs_init:
+        - $after:ble_transport_init
+        - $before:ble_transport_ll_init
+    ble_transport_ll_init:
+        - $after:ble_transport_hs_init
diff --git a/nimble/transport/src/transport.c b/nimble/transport/src/transport.c
new file mode 100644
index 0000000..7c868f1
--- /dev/null
+++ b/nimble/transport/src/transport.c
@@ -0,0 +1,217 @@
+/*
+ * 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 <syscfg/syscfg.h>
+#include <sysinit/sysinit.h>
+#include <os/os_mbuf.h>
+#include <os/os_mempool.h>
+#include <nimble/ble.h>
+#include <nimble/hci_common.h>
+#include <nimble/transport.h>
+
+#define OMP_FLAG_FROM_HS        (0x01)
+#define OMP_FLAG_FROM_LL        (0x02)
+#define OMP_FLAG_FROM_MASK      (0x03)
+
+#if MYNEWT_VAL(BLE_HS_FLOW_CTRL) || \
+    MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
+#define POOL_CMD_COUNT      (2)
+#else
+#define POOL_CMD_COUNT      (1)
+#endif
+#define POOL_CMD_SIZE       (258)
+
+#define POOL_EVT_COUNT      (MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT))
+#define POOL_EVT_LO_COUNT   (MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT))
+#define POOL_EVT_SIZE       (MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE))
+
+#if MYNEWT_VAL_CHOICE(BLE_TRANSPORT_LL, native) && \
+   MYNEWT_VAL_CHOICE(BLE_TRANSPORT_HS, native)
+#define POOL_ACL_COUNT      (0)
+#elif !MYNEWT_VAL_CHOICE(BLE_TRANSPORT_LL, native) && \
+      !MYNEWT_VAL_CHOICE(BLE_TRANSPORT_HS, native)
+#define POOL_ACL_COUNT      ((MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_HS_COUNT)) + \
+                             (MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT)))
+#elif MYNEWT_VAL_CHOICE(BLE_TRANSPORT_LL, native)
+#define POOL_ACL_COUNT      (MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_HS_COUNT))
+#else
+#define POOL_ACL_COUNT      (MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_LL_COUNT))
+#endif
+#define POOL_ACL_SIZE       (OS_ALIGN( MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE) + \
+                                       BLE_MBUF_MEMBLOCK_OVERHEAD +         \
+                                       BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT))
+
+static uint8_t pool_cmd_buf[ OS_MEMPOOL_BYTES(POOL_CMD_COUNT, POOL_CMD_SIZE) ];
+static struct os_mempool pool_cmd;
+
+static uint8_t pool_evt_buf[ OS_MEMPOOL_BYTES(POOL_EVT_COUNT, POOL_EVT_SIZE) ];
+static struct os_mempool pool_evt;
+
+static uint8_t pool_evt_lo_buf[ OS_MEMPOOL_BYTES(POOL_EVT_LO_COUNT, POOL_EVT_SIZE) ];
+static struct os_mempool pool_evt_lo;
+
+static uint8_t pool_acl_buf[ OS_MEMPOOL_BYTES(POOL_ACL_COUNT, POOL_ACL_SIZE) ];
+static struct os_mempool_ext pool_acl;
+static struct os_mbuf_pool mpool_acl;
+
+static os_mempool_put_fn *transport_put_acl_from_ll_cb;
+
+void *
+ble_transport_alloc_cmd(void)
+{
+    return os_memblock_get(&pool_cmd);
+}
+
+void *
+ble_transport_alloc_evt(int discarcable)
+{
+    void *buf;
+
+    if (discarcable) {
+        buf = os_memblock_get(&pool_evt_lo);
+    } else {
+        buf = os_memblock_get(&pool_evt);
+        if (!buf) {
+            buf = os_memblock_get(&pool_evt_lo);
+        }
+    }
+
+    return buf;
+}
+
+struct os_mbuf *
+ble_transport_alloc_acl_from_hs(void)
+{
+    struct os_mbuf *om;
+    struct os_mbuf_pkthdr *pkthdr;
+    uint16_t usrhdr_len;
+
+#if MYNEWT_VAL_CHOICE(BLE_TRANSPORT_LL, native)
+    usrhdr_len = sizeof(struct ble_mbuf_hdr);
+#else
+    usrhdr_len = 0;
+#endif
+
+    om = os_mbuf_get_pkthdr(&mpool_acl, usrhdr_len);
+    if (om) {
+        pkthdr = OS_MBUF_PKTHDR(om);
+        pkthdr->omp_flags = OMP_FLAG_FROM_HS;
+    }
+
+    return om;
+}
+
+struct os_mbuf *
+ble_transport_alloc_acl_from_ll(void)
+{
+    struct os_mbuf *om;
+    struct os_mbuf_pkthdr *pkthdr;
+
+    om = os_mbuf_get_pkthdr(&mpool_acl, 0);
+    if (om) {
+        pkthdr = OS_MBUF_PKTHDR(om);
+        pkthdr->omp_flags = OMP_FLAG_FROM_LL;
+    }
+
+    return om;
+}
+
+void
+ble_transport_free(void *buf)
+{
+    if (os_memblock_from(&pool_cmd, buf)) {
+        os_memblock_put(&pool_cmd, buf);
+    } else if (os_memblock_from(&pool_evt, buf)) {
+        os_memblock_put(&pool_evt, buf);
+    } else if (os_memblock_from(&pool_evt_lo, buf)) {
+        os_memblock_put(&pool_evt_lo, buf);
+    } else {
+        assert(0);
+    }
+}
+
+static os_error_t
+ble_transport_acl_put(struct os_mempool_ext *mpe, void *data, void *arg)
+{
+    struct os_mbuf *om;
+    struct os_mbuf_pkthdr *pkthdr;
+    os_error_t err;
+
+    om = data;
+    pkthdr = OS_MBUF_PKTHDR(om);
+
+    switch (pkthdr->omp_flags & OMP_FLAG_FROM_MASK) {
+    case OMP_FLAG_FROM_LL:
+        if (transport_put_acl_from_ll_cb) {
+            return transport_put_acl_from_ll_cb(mpe, data, arg);
+        }
+        break;
+    case OMP_FLAG_FROM_HS:
+        break;
+    default:
+        assert(0);
+        break;
+    }
+
+    err = os_memblock_put_from_cb(&mpe->mpe_mp, data);
+    if (err) {
+        return err;
+    }
+
+    return 0;
+}
+
+void
+ble_transport_init(void)
+{
+    int rc;
+
+    SYSINIT_ASSERT_ACTIVE();
+
+    rc = os_mempool_init(&pool_cmd, POOL_CMD_COUNT, POOL_CMD_SIZE,
+                         pool_cmd_buf, "transport_pool_cmd");
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = os_mempool_init(&pool_evt, POOL_EVT_COUNT, POOL_EVT_SIZE,
+                         pool_evt_buf, "transport_pool_evt");
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = os_mempool_init(&pool_evt_lo, POOL_EVT_LO_COUNT, POOL_EVT_SIZE,
+                         pool_evt_lo_buf, "transport_pool_evt_lo");
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = os_mempool_ext_init(&pool_acl, POOL_ACL_COUNT, POOL_ACL_SIZE,
+                             pool_acl_buf, "transport_pool_acl");
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = os_mbuf_pool_init(&mpool_acl, &pool_acl.mpe_mp,
+                           POOL_ACL_SIZE, POOL_ACL_COUNT);
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    pool_acl.mpe_put_cb = ble_transport_acl_put;
+}
+
+int
+ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn (*cb))
+{
+    transport_put_acl_from_ll_cb = cb;
+
+    return 0;
+}
diff --git a/nimble/transport/syscfg.defunct.yml b/nimble/transport/syscfg.defunct.yml
new file mode 100644
index 0000000..dc18ef4
--- /dev/null
+++ b/nimble/transport/syscfg.defunct.yml
@@ -0,0 +1,40 @@
+# 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.
+#
+
+syscfg.defs:
+    BLE_HCI_TRANSPORT:
+        description: see doc/transport.md
+        defunct: 1
+    BLE_HCI_BRIDGE:
+        description: see doc/transport.md
+        defunct: 1
+    BLE_HCI_EVT_HI_BUF_COUNT:
+        description: use BLE_TRANSPORT_EVT_COUNT
+        defunct: 1
+    BLE_HCI_EVT_LO_BUF_COUNT:
+        description: use BLE_TRANSPORT_EVT_DISCARDABLE_COUNT
+        defunct: 1
+    BLE_HCI_EVT_BUF_SIZE:
+        description: use BLE_TRANSPORT_EVT_SIZE
+        defunct: 1
+    BLE_ACL_BUF_COUNT:
+        description: use BLE_TRANSPORT_ACL_COUNT
+        defunct: 1
+    BLE_ACL_BUF_SIZE:
+        description: use BLE_TRANSPORT_ACL_SIZE
+        defunct: 1
diff --git a/nimble/transport/syscfg.yml b/nimble/transport/syscfg.yml
index 7eed69b..d2404e1 100644
--- a/nimble/transport/syscfg.yml
+++ b/nimble/transport/syscfg.yml
@@ -17,103 +17,76 @@
 #
 
 syscfg.defs:
-    BLE_HCI_TRANSPORT:
+    BLE_TRANSPORT: 1
+
+    BLE_TRANSPORT_HS:
         description: >
-            Selects HCI transport to be included in build.
-            This has virtually the same effect as including package dependency
-            manually, but it allows to easily override HCI transport package in
-            application or target settings.
-        value: builtin
-        restrictions: $notnull
+            Select HCI transport used towards host.
+            "native" means NimBLE host is running on the same core and no
+            transport is required.
+        value: native
         choices:
-            - builtin           # Built-in NimBLE controller and RAM transport
-            - custom            # Custom transport, has to be included manually by user
-            - ram               # RAM transport
-            - uart              # UART HCI H4 transport
-            - socket            # Socket transport (for native builds)
-            - emspi             # SPI transport for EM Microelectionic controllers
-            - da1469x           # Dialog DA1469x integrated controller
-            - dialog_cmac       # Dialog CMAC via shared memory
-            - usb               # USB
-            - nrf5340           # nRF5340
-
-    BLE_HCI_BRIDGE_TRANSPORT:
+            - native
+            - dialog_cmac
+            - nrf5340
+            - uart
+            - usb
+            - custom
+    BLE_TRANSPORT_LL:
         description: >
-            Selects HCI transport to be included in bridge configuration build.
-            This applies to multi core configurations where controller runs
-            on separate core and main core forwards HCI traffic to external host.
-            This has virtually the same effect as including package dependency
-            manually, but it allows to easily override HCI transport package in
-            application or target settings.
-            This is the transport
-        value:
+            Select HCI transport used towards controller.
+            "native" means NimBLE controller is running on the same core and no
+            transport is required.
+        value: native
         choices:
-            - dialog_cmac       # Dialog CMAC via shared memory
-            - nrf5340           # nRF5340
+            - native
+            - dialog_cmac
+            - nrf5340
+            - custom
 
-    BLE_HCI_BRIDGE:
+    BLE_TRANSPORT_ACL_COUNT:
         description: >
-            External interface (UART/USB/Socket) bridged to second core controller.
-        value: 0
-
-    BLE_HCI_EVT_HI_BUF_COUNT:
-        description: 'Number of high-priority event buffers.'
-        value:
-
-    BLE_HCI_EVT_LO_BUF_COUNT:
-        description: 'Number of low-priority event buffers.'
-        value:
-
-    BLE_HCI_EVT_BUF_SIZE:
-        description: 'Size of each event buffer, in bytes.'
-        value:
-
-    BLE_ACL_BUF_COUNT:
-        description: 'The number of ACL data buffers'
-        value:
-
-    BLE_ACL_BUF_SIZE:
+            Number of ACL buffers available in transport. This determines
+            number of buffers used by host/controller for flow control.
+            Buffers pool is allocated for each non-native transport side
+            selected, unless overriden by BLE_TRANSPORT_ACL_FROM_[HS|LL]_COUNT.
+        value: 10
+    BLE_TRANSPORT_ACL_SIZE:
+        description: Size of each buffer in ACL pool.
+        value: 255
+    BLE_TRANSPORT_EVT_COUNT:
         description: >
-            This is the maximum size of the data portion of HCI ACL data
-            packets.
-        value:
-
-# Deprecated settings
-    BLE_HCI_TRANSPORT_NIMBLE_BUILTIN:
-        description: Use BLE_HCI_TRANSPORT instead.
-        value: 0
-        deprecated: 1
-    BLE_HCI_TRANSPORT_EMSPI:
-        description: Use BLE_HCI_TRANSPORT instead.
-        value: 0
-        deprecated: 1
-    BLE_HCI_TRANSPORT_RAM:
-        description: Use BLE_HCI_TRANSPORT instead.
-        value: 0
-        deprecated: 1
-    BLE_HCI_TRANSPORT_SOCKET:
-        description: Use BLE_HCI_TRANSPORT instead.
-        value: 0
-        deprecated: 1
-    BLE_HCI_TRANSPORT_UART:
-        description: Use BLE_HCI_TRANSPORT instead.
-        value: 0
-        deprecated: 1
-
-syscfg.vals.BLE_HCI_TRANSPORT_NIMBLE_BUILTIN:
-    BLE_HCI_TRANSPORT: builtin
-syscfg.vals.BLE_HCI_TRANSPORT_RAM:
-    BLE_HCI_TRANSPORT: ram
-syscfg.vals.BLE_HCI_TRANSPORT_UART:
-    BLE_HCI_TRANSPORT: uart
-syscfg.vals.BLE_HCI_TRANSPORT_SOCKET:
-    BLE_HCI_TRANSPORT: socket
-syscfg.vals.BLE_HCI_TRANSPORT_EMSPI:
-    BLE_HCI_TRANSPORT: emspi
+            Number of event buffers available in transport.
+        value: 4
+    BLE_TRANSPORT_EVT_DISCARDABLE_COUNT:
+        description: >
+            Number of discardable event buffers available in transport.
+            Discardable event buffers are used for events that can be safely
+            dropped by controller if there's no free buffer available, e.g.
+            advertising reports.
+        value: 16
+    BLE_TRANSPORT_EVT_SIZE:
+        description: >
+            Size of each buffer in events pool. This applies to both regular
+            and discardable buffers. Value is automatically adjusted if
+            extended advertising is enabled so in most cases it's better to
+            leave it at default settings.
+        value: 70
 
-syscfg.vals.'(MCU_TARGET == "DA14691" || MCU_TARGET == "DA14695" || MCU_TARGET == "DA14697" || MCU_TARGET == "DA14699")':
-    BLE_HCI_BRIDGE_TRANSPORT: dialog_cmac
+    BLE_TRANSPORT_ACL_FROM_HS_COUNT:
+        description: >
+            Overrides BLE_TRANSPORT_ACL_COUNT on host side, i.e. number
+            of ACL buffers available for host.
+        value: MYNEWT_VAL(BLE_TRANSPORT_ACL_COUNT)
+    BLE_TRANSPORT_ACL_FROM_LL_COUNT:
+        description: >
+            Overrides BLE_TRANSPORT_ACL_COUNT on controller side, i.e. number
+            of ACL buffers available for controller.
+        value: MYNEWT_VAL(BLE_TRANSPORT_ACL_COUNT)
 
-syscfg.vals.'(MCU_TARGET == "nRF5340_APP")':
-    BLE_HCI_BRIDGE_TRANSPORT: nrf5340
+# import defunct settings from separate file to reduce clutter in main file
+$import:
+    - "@apache-mynewt-nimble/nimble/transport/syscfg.defunct.yml"
 
+syscfg.vals."BLE_EXT_ADV || BLE_LL_CFG_FEAT_LL_EXT_ADV":
+    BLE_TRANSPORT_EVT_SIZE: 257

[mynewt-nimble] 04/22: nimble/ll: Update to new transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 83535eda40b1aca0cd111fe188f4b125a68d4773
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:09:47 2022 +0100

    nimble/ll: Update to new transport
---
 nimble/controller/include/controller/ble_ll_hci.h |  3 +-
 nimble/controller/pkg.yml                         |  4 +--
 nimble/controller/src/ble_ll.c                    | 29 ++++++++++++++----
 nimble/controller/src/ble_ll_adv.c                |  5 ++-
 nimble/controller/src/ble_ll_conn.c               |  8 ++---
 nimble/controller/src/ble_ll_conn_hci.c           | 13 ++++----
 nimble/controller/src/ble_ll_hci.c                |  7 ++---
 nimble/controller/src/ble_ll_hci_ev.c             | 37 +++++++++++------------
 nimble/controller/src/ble_ll_scan.c               |  9 +++---
 nimble/controller/src/ble_ll_scan_aux.c           |  7 ++---
 nimble/controller/src/ble_ll_sync.c               | 27 ++++++++---------
 nimble/controller/syscfg.yml                      |  7 ++---
 nimble/include/nimble/hci_common.h                |  5 +--
 13 files changed, 84 insertions(+), 77 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_hci.h b/nimble/controller/include/controller/ble_ll_hci.h
index a9ea3bb..f45aa3a 100644
--- a/nimble/controller/include/controller/ble_ll_hci.h
+++ b/nimble/controller/include/controller/ble_ll_hci.h
@@ -25,13 +25,14 @@ extern "C" {
 #endif
 
 #include "nimble/hci_common.h"
+#include "nimble/transport.h"
 
 /* For supported commands */
 #define BLE_LL_SUPP_CMD_LEN (45)
 extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
 
 /* The largest event the controller will send. */
-#define BLE_LL_MAX_EVT_LEN  MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE)
+#define BLE_LL_MAX_EVT_LEN  MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE)
 
 /*
  * This determines the number of outstanding commands allowed from the
diff --git a/nimble/controller/pkg.yml b/nimble/controller/pkg.yml
index 9661bb3..702f3d8 100644
--- a/nimble/controller/pkg.yml
+++ b/nimble/controller/pkg.yml
@@ -37,6 +37,4 @@ pkg.req_apis.BLE_LL_LNA:
 pkg.deps:
     - "@apache-mynewt-core/kernel/os"
     - nimble
-
-pkg.init:
-    ble_ll_init: 'MYNEWT_VAL(BLE_LL_SYSINIT_STAGE)'
+    - nimble/transport
diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 362d466..73168b4 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -28,7 +28,7 @@
 #include "nimble/ble.h"
 #include "nimble/nimble_opt.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
+#include "nimble/transport.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_phy.h"
 #include "controller/ble_phy_trace.h"
@@ -1394,9 +1394,6 @@ ble_ll_task(void *arg)
     /* Set output power to 1mW (0 dBm) */
     ble_phy_txpwr_set(g_ble_ll_tx_power);
 
-    /* Register callback for transport */
-    ble_hci_trans_cfg_ll(ble_ll_hci_cmd_rx, NULL, ble_ll_hci_acl_rx, NULL);
-
     /* Tell the host that we are ready to receive packets */
     ble_ll_hci_send_noop();
 
@@ -1817,8 +1814,8 @@ ble_ll_init(void)
 
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
     /* Set acl pkt size and number */
-    lldata->ll_num_acl_pkts = MYNEWT_VAL(BLE_ACL_BUF_COUNT);
-    lldata->ll_acl_pkt_size = MYNEWT_VAL(BLE_ACL_BUF_SIZE);
+    lldata->ll_num_acl_pkts = MYNEWT_VAL(BLE_TRANSPORT_ACL_FROM_HS_COUNT);
+    lldata->ll_acl_pkt_size = MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE);
 #endif
 
     /* Initialize eventq */
@@ -1967,3 +1964,23 @@ ble_ll_init(void)
 
 #endif
 }
+
+/* Transport APIs for LL side */
+
+int
+ble_transport_to_ll_cmd(void *buf)
+{
+    return ble_ll_hci_cmd_rx(buf, NULL);
+}
+
+int
+ble_transport_to_ll_acl(struct os_mbuf *om)
+{
+    return ble_ll_hci_acl_rx(om, NULL);
+}
+
+void
+ble_transport_ll_init(void)
+{
+    ble_ll_init();
+}
diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index bc04c8f..b3cf5f9 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -26,7 +26,6 @@
 #include "nimble/ble.h"
 #include "nimble/nimble_opt.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "controller/ble_phy.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_ll.h"
@@ -1947,7 +1946,7 @@ ble_ll_adv_sm_stop(struct ble_ll_adv_sm *advsm)
 #if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
         /* If there is an event buf we need to free it */
         if (advsm->conn_comp_ev) {
-            ble_hci_trans_buf_free(advsm->conn_comp_ev);
+            ble_transport_free(advsm->conn_comp_ev);
             advsm->conn_comp_ev = NULL;
         }
 #endif
@@ -2668,7 +2667,7 @@ ble_ll_adv_sm_start(struct ble_ll_adv_sm *advsm)
     if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE) {
         /* We expect this to be NULL but if not we wont allocate one... */
         if (advsm->conn_comp_ev == NULL) {
-            advsm->conn_comp_ev = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+            advsm->conn_comp_ev = ble_transport_alloc_evt(0);
             if (!advsm->conn_comp_ev) {
                 return BLE_ERR_MEM_CAPACITY;
             }
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index c41c35b..138f928 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -25,7 +25,7 @@
 #include "os/os.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
+#include "nimble/transport.h"
 #include "controller/ble_ll.h"
 #include "controller/ble_ll_conn.h"
 #include "controller/ble_ll_hci.h"
@@ -306,7 +306,7 @@ ble_ll_conn_cth_flow_error_fn(struct ble_npl_event *ev)
     struct ble_hci_ev_command_complete *hci_ev_cp;
     uint16_t opcode;
 
-    hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    hci_ev = ble_transport_alloc_evt(0);
     if (!hci_ev) {
         /* Not much we can do anyway... */
         return;
@@ -3261,7 +3261,7 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
         acl_hdr = (llid << 12) | connsm->conn_handle;
         put_le16(rxbuf, acl_hdr);
         put_le16(rxbuf + 2, acl_len);
-        ble_hci_trans_ll_acl_tx(rxpdu);
+        ble_transport_to_hs_acl(rxpdu);
     }
 
     /* NOTE: we dont free the mbuf since we handed it off! */
@@ -3916,7 +3916,7 @@ ble_ll_conn_module_reset(void)
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
     /* Free the global connection complete event if there is one */
     if (g_ble_ll_conn_comp_ev) {
-        ble_hci_trans_buf_free(g_ble_ll_conn_comp_ev);
+        ble_transport_free(g_ble_ll_conn_comp_ev);
         g_ble_ll_conn_comp_ev = NULL;
     }
 
diff --git a/nimble/controller/src/ble_ll_conn_hci.c b/nimble/controller/src/ble_ll_conn_hci.c
index 97d2421..82abdcb 100644
--- a/nimble/controller/src/ble_ll_conn_hci.c
+++ b/nimble/controller/src/ble_ll_conn_hci.c
@@ -24,7 +24,6 @@
 #include "os/os.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "controller/ble_ll.h"
 #include "controller/ble_ll_utils.h"
 #include "controller/ble_ll_hci.h"
@@ -76,7 +75,7 @@ ble_ll_init_alloc_conn_comp_ev(void)
     rc = 0;
     evbuf = g_ble_ll_conn_comp_ev;
     if (evbuf == NULL) {
-        evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        evbuf = ble_transport_alloc_evt(0);
         if (!evbuf) {
             rc = -1;
         } else {
@@ -263,7 +262,7 @@ ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status,
         return;
     }
 
-    ble_hci_trans_buf_free(evbuf);
+    ble_transport_free(evbuf);
 }
 
 /**
@@ -299,7 +298,7 @@ ble_ll_conn_num_comp_pkts_event_send(struct ble_ll_conn_sm *connsm)
          * entire active list every time.
          */
         if (connsm->completed_pkts) {
-            hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+            hci_ev = ble_transport_alloc_evt(0);
             if (hci_ev) {
                 hci_ev->opcode = BLE_HCI_EVCODE_NUM_COMP_PKTS;
                 hci_ev->length = sizeof(*ev);
@@ -333,7 +332,7 @@ skip_conn:
             (connsm->completed_pkts || !STAILQ_EMPTY(&connsm->conn_txq))) {
             /* If no buffer, get one, If cant get one, leave. */
             if (!hci_ev) {
-                hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+                hci_ev = ble_transport_alloc_evt(0);
                 if (!hci_ev) {
                     break;
                 }
@@ -389,7 +388,7 @@ ble_ll_auth_pyld_tmo_event_send(struct ble_ll_conn_sm *connsm)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_AUTH_PYLD_TMO)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_AUTH_PYLD_TMO;
             hci_ev->length = sizeof(*ev);
@@ -418,7 +417,7 @@ ble_ll_disconn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t reason)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_DISCONN_CMP)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_DISCONN_CMP;
             hci_ev->length = sizeof(*ev);
diff --git a/nimble/controller/src/ble_ll_hci.c b/nimble/controller/src/ble_ll_hci.c
index 3dfc4a0..bc9160f 100644
--- a/nimble/controller/src/ble_ll_hci.c
+++ b/nimble/controller/src/ble_ll_hci.c
@@ -24,7 +24,6 @@
 #include "nimble/ble.h"
 #include "nimble/nimble_opt.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_ll_adv.h"
 #include "controller/ble_ll_scan.h"
@@ -108,7 +107,7 @@ ble_ll_hci_event_send(struct ble_hci_ev *hci_ev)
     STATS_INC(ble_ll_stats, hci_events_sent);
 
     /* Send the event to the host */
-    rc = ble_hci_trans_ll_evt_tx((uint8_t *)hci_ev);
+    rc = ble_transport_to_hs_evt(hci_ev);
 
     BLE_LL_DEBUG_GPIO(HCI_EV, 0);
 
@@ -125,7 +124,7 @@ ble_ll_hci_send_noop(void)
     struct ble_hci_ev_command_complete_nop *ev;
     struct ble_hci_ev *hci_ev;
 
-    hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    hci_ev = ble_transport_alloc_evt(0);
     if (hci_ev) {
         /* Create a command complete event with a NO-OP opcode */
         hci_ev->opcode = BLE_HCI_EVCODE_COMMAND_COMPLETE;
@@ -1792,7 +1791,7 @@ ble_ll_hci_cmd_rx(uint8_t *cmdbuf, void *arg)
     if ((ogf == BLE_HCI_OGF_CTLR_BASEBAND) &&
         (ocf == BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS)) {
         ble_ll_conn_cth_flow_process_cmd(cmdbuf);
-        ble_hci_trans_buf_free(cmdbuf);
+        ble_transport_free(cmdbuf);
         return 0;
     }
 #endif
diff --git a/nimble/controller/src/ble_ll_hci_ev.c b/nimble/controller/src/ble_ll_hci_ev.c
index c39a833..8543d98 100644
--- a/nimble/controller/src/ble_ll_hci_ev.c
+++ b/nimble/controller/src/ble_ll_hci_ev.c
@@ -22,7 +22,6 @@
 #include "syscfg/syscfg.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "controller/ble_ll.h"
 #include "controller/ble_ll_hci.h"
 #include "controller/ble_ll_ctrl.h"
@@ -44,7 +43,7 @@ ble_ll_hci_ev_datalen_chg(struct ble_ll_conn_sm *connsm)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_DATA_LEN_CHG)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -76,7 +75,7 @@ ble_ll_hci_ev_rem_conn_parm_req(struct ble_ll_conn_sm *connsm,
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -107,7 +106,7 @@ ble_ll_hci_ev_conn_update(struct ble_ll_conn_sm *connsm, uint8_t status)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -135,7 +134,7 @@ ble_ll_hci_ev_encrypt_chg(struct ble_ll_conn_sm *connsm, uint8_t status)
 
     if (CONN_F_ENC_CHANGE_SENT(connsm) == 0) {
         if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_ENCRYPT_CHG)) {
-            hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+            hci_ev = ble_transport_alloc_evt(0);
             if (hci_ev) {
                 hci_ev->opcode = BLE_HCI_EVCODE_ENCRYPT_CHG;
                 hci_ev->length = sizeof(*ev_enc_chf);
@@ -154,7 +153,7 @@ ble_ll_hci_ev_encrypt_chg(struct ble_ll_conn_sm *connsm, uint8_t status)
     }
 
     if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_ENC_KEY_REFRESH)) {
-        hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_ENC_KEY_REFRESH;
             hci_ev->length = sizeof(*ev_key_refresh);
@@ -181,7 +180,7 @@ ble_ll_hci_ev_ltk_req(struct ble_ll_conn_sm *connsm)
     int rc;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_LT_KEY_REQ)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -215,7 +214,7 @@ ble_ll_hci_ev_rd_rem_used_feat(struct ble_ll_conn_sm *connsm, uint8_t status)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -239,7 +238,7 @@ ble_ll_hci_ev_rd_rem_ver(struct ble_ll_conn_sm *connsm, uint8_t status)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP;
             hci_ev->length = sizeof(*ev);
@@ -272,7 +271,7 @@ ble_ll_hci_ev_hw_err(uint8_t hw_err)
 
     rc = 0;
     if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_HW_ERROR)) {
-        hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_HW_ERROR;
             hci_ev->length = sizeof(*ev);
@@ -295,7 +294,7 @@ ble_ll_hci_ev_databuf_overflow(void)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_DATA_BUF_OVERFLOW)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_DATA_BUF_OVERFLOW;
             hci_ev->length = sizeof(*ev);
@@ -321,7 +320,7 @@ ble_ll_hci_ev_le_csa(struct ble_ll_conn_sm *connsm)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_CHAN_SEL_ALG)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -350,7 +349,7 @@ ble_ll_hci_ev_send_scan_req_recv(uint8_t adv_handle, const uint8_t *peer,
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -379,7 +378,7 @@ ble_ll_hci_ev_send_scan_timeout(void)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_SCAN_TIMEOUT)) {
-        hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -406,7 +405,7 @@ ble_ll_hci_ev_send_adv_set_terminated(uint8_t status, uint8_t adv_handle,
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -440,7 +439,7 @@ ble_ll_hci_ev_phy_update(struct ble_ll_conn_sm *connsm, uint8_t status)
 
     rc = 0;
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -473,7 +472,7 @@ ble_ll_hci_ev_sca_update(struct ble_ll_conn_sm *connsm, uint8_t status,
         return;
     }
 
-    hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    hci_ev = ble_transport_alloc_evt(0);
     if (!hci_ev) {
         return;
     }
@@ -508,7 +507,7 @@ ble_ll_hci_ev_send_vs_assert(const char *file, uint32_t line)
      */
     max_len = BLE_HCI_MAX_DATA_LEN - sizeof(*ev) - 6;
 
-    hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    hci_ev = ble_transport_alloc_evt(0);
     if (hci_ev) {
         hci_ev->opcode = BLE_HCI_EVCODE_VS_DEBUG;
         hci_ev->length = sizeof(*ev);
@@ -560,7 +559,7 @@ ble_ll_hci_ev_send_vs_llcp_trace(uint8_t type, uint16_t handle, uint16_t count,
     struct ble_hci_ev_vs_debug *ev;
     struct ble_hci_ev *hci_ev;
 
-    hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (hci_ev) {
         hci_ev->opcode = BLE_HCI_EVCODE_VS_DEBUG;
         hci_ev->length = sizeof(*ev) + 8 + length;
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 46e1cb6..27c0fea 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -25,7 +25,6 @@
 #include "os/os.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "controller/ble_phy.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_ll.h"
@@ -327,7 +326,7 @@ ble_ll_scan_get_ext_adv_report(struct ext_adv_report *copy_from)
     struct ext_adv_report *report;
     struct ble_hci_ev *hci_ev;
 
-    hci_ev = ( void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (!hci_ev) {
         return NULL;
     }
@@ -512,7 +511,7 @@ ble_ll_hci_send_legacy_ext_adv_report(uint8_t evtype,
         break;
     default:
         BLE_LL_ASSERT(0);
-        ble_hci_trans_buf_free((uint8_t *) hci_ev);
+        ble_transport_free(hci_ev);
         return -1;
     }
 
@@ -557,7 +556,7 @@ ble_ll_hci_send_adv_report(uint8_t evtype,
         return -1;
     }
 
-    hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (!hci_ev) {
         return -1;
     }
@@ -594,7 +593,7 @@ ble_ll_hci_send_dir_adv_report(const uint8_t *addr, uint8_t addr_type,
         return -1;
     }
 
-    hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (!hci_ev) {
         return -1;
     }
diff --git a/nimble/controller/src/ble_ll_scan_aux.c b/nimble/controller/src/ble_ll_scan_aux.c
index ed5ca81..ce2ac07 100644
--- a/nimble/controller/src/ble_ll_scan_aux.c
+++ b/nimble/controller/src/ble_ll_scan_aux.c
@@ -28,7 +28,6 @@
 #include "os/os.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 #include "controller/ble_phy.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_ll.h"
@@ -230,7 +229,7 @@ ble_ll_hci_ev_alloc_ext_adv_report_for_aux(struct ble_ll_scan_addr_data *addrd,
     struct ext_adv_report *report;
     struct ble_hci_ev *hci_ev;
 
-    hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (!hci_ev) {
         return NULL;
     }
@@ -286,7 +285,7 @@ ble_ll_hci_ev_dup_ext_adv_report(struct ble_hci_ev *hci_ev_src)
     struct ext_adv_report *report;
     struct ble_hci_ev *hci_ev;
 
-    hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (!hci_ev) {
         return NULL;
     }
@@ -639,7 +638,7 @@ ble_ll_hci_ev_send_ext_adv_report_for_ext(struct os_mbuf *rxpdu,
         return;
     }
 
-    hci_ev = (void *)ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+    hci_ev = ble_transport_alloc_evt(1);
     if (!hci_ev) {
         return;
     }
diff --git a/nimble/controller/src/ble_ll_sync.c b/nimble/controller/src/ble_ll_sync.c
index 43f328e..0adc67b 100644
--- a/nimble/controller/src/ble_ll_sync.c
+++ b/nimble/controller/src/ble_ll_sync.c
@@ -36,7 +36,6 @@
 
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
 
 #include "ble_ll_conn_priv.h"
 
@@ -201,7 +200,7 @@ ble_ll_sync_sm_clear(struct ble_ll_sync_sm *sm)
     }
 
     if (sm->next_report) {
-        ble_hci_trans_buf_free(sm->next_report);
+        ble_transport_free(sm->next_report);
     }
 
     if (g_ble_ll_sync_sm_current == sm) {
@@ -333,7 +332,7 @@ ble_ll_sync_transfer_received(struct ble_ll_sync_sm *sm, uint8_t status)
 
         ble_ll_hci_event_send(hci_ev);
     } else {
-        ble_hci_trans_buf_free(sm->transfer_received_ev);
+        ble_transport_free(sm->transfer_received_ev);
     }
 
     sm->transfer_received_ev = NULL;
@@ -371,7 +370,7 @@ ble_ll_sync_est_event_success(struct ble_ll_sync_sm *sm)
 
         ble_ll_hci_event_send(hci_ev);
     } else {
-        ble_hci_trans_buf_free(g_ble_ll_sync_create_comp_ev);
+        ble_transport_free(g_ble_ll_sync_create_comp_ev);
     }
 
     g_ble_ll_sync_create_comp_ev = NULL;
@@ -399,7 +398,7 @@ ble_ll_sync_est_event_failed(uint8_t status)
 
         ble_ll_hci_event_send(hci_ev);
     } else {
-        ble_hci_trans_buf_free(g_ble_ll_sync_create_comp_ev);
+        ble_transport_free(g_ble_ll_sync_create_comp_ev);
     }
 
     g_ble_ll_sync_create_comp_ev = NULL;
@@ -412,7 +411,7 @@ ble_ll_sync_lost_event(struct ble_ll_sync_sm *sm)
     struct ble_hci_ev *hci_ev;
 
     if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_LOST)) {
-        hci_ev = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        hci_ev = ble_transport_alloc_evt(0);
         if (hci_ev) {
             hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
             hci_ev->length = sizeof(*ev);
@@ -642,7 +641,7 @@ ble_ll_sync_send_truncated_per_adv_rpt(struct ble_ll_sync_sm *sm, uint8_t *evbuf
 
     if (!ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT) ||
         (sm->flags & BLE_LL_SYNC_SM_FLAG_DISABLED)) {
-        ble_hci_trans_buf_free(evbuf);
+        ble_transport_free(evbuf);
         return;
     }
 
@@ -679,7 +678,7 @@ ble_ll_sync_send_per_adv_rpt(struct ble_ll_sync_sm *sm, struct os_mbuf *rxpdu,
         hci_ev = (void *) sm->next_report;
         sm->next_report = NULL;
     } else {
-        hci_ev = (void * )ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+        hci_ev = ble_transport_alloc_evt(1);
         if (!hci_ev) {
             goto done;
         }
@@ -714,7 +713,7 @@ ble_ll_sync_send_per_adv_rpt(struct ble_ll_sync_sm *sm, struct os_mbuf *rxpdu,
 
         /* Need another event for next fragment of this PDU */
         if (offset < datalen) {
-            hci_ev_next = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+            hci_ev_next = ble_transport_alloc_evt(1);
             if (hci_ev_next) {
                 ev->data_status = BLE_HCI_PERIODIC_DATA_STATUS_INCOMPLETE;
             } else {
@@ -725,7 +724,7 @@ ble_ll_sync_send_per_adv_rpt(struct ble_ll_sync_sm *sm, struct os_mbuf *rxpdu,
             if (aux) {
                 if (aux_scheduled) {
                     /* if we scheduled aux, we need buffer for next report */
-                    hci_ev_next = (void *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+                    hci_ev_next = ble_transport_alloc_evt(1);
                     if (hci_ev_next) {
                         ev->data_status = BLE_HCI_PERIODIC_DATA_STATUS_INCOMPLETE;
                     } else {
@@ -1517,7 +1516,7 @@ ble_ll_sync_create(const uint8_t *cmdbuf, uint8_t len)
     }
 
     /* reserve buffer for sync complete event */
-    g_ble_ll_sync_create_comp_ev = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+    g_ble_ll_sync_create_comp_ev = ble_transport_alloc_evt(0);
     if (!g_ble_ll_sync_create_comp_ev) {
         return BLE_ERR_MEM_CAPACITY;
     }
@@ -1527,7 +1526,7 @@ ble_ll_sync_create(const uint8_t *cmdbuf, uint8_t len)
     /* reserve 1 SM for created sync */
     sm = ble_ll_sync_reserve();
     if (!sm) {
-        ble_hci_trans_buf_free(g_ble_ll_sync_create_comp_ev);
+        ble_transport_free(g_ble_ll_sync_create_comp_ev);
         g_ble_ll_sync_create_comp_ev = NULL;
         OS_EXIT_CRITICAL(sr);
         return BLE_ERR_MEM_CAPACITY;
@@ -1789,7 +1788,7 @@ ble_ll_sync_transfer_get(const uint8_t *addr, uint8_t addr_type, uint8_t sid)
 
         if (!sm->flags) {
             /* allocate event for transfer received event */
-            sm->transfer_received_ev = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+            sm->transfer_received_ev = ble_transport_alloc_evt(0);
             if (!sm->transfer_received_ev) {
                 break;
             }
@@ -2246,7 +2245,7 @@ ble_ll_sync_reset(void)
     g_ble_ll_sync_sm_current = NULL;
 
     if (g_ble_ll_sync_create_comp_ev) {
-        ble_hci_trans_buf_free(g_ble_ll_sync_create_comp_ev);
+        ble_transport_free(g_ble_ll_sync_create_comp_ev);
         g_ble_ll_sync_create_comp_ev = NULL;
     }
 }
diff --git a/nimble/controller/syscfg.yml b/nimble/controller/syscfg.yml
index a9b4321..ebf7e1d 100644
--- a/nimble/controller/syscfg.yml
+++ b/nimble/controller/syscfg.yml
@@ -17,11 +17,7 @@
 #
 
 syscfg.defs:
-    BLE_CONTROLLER:
-        description: >
-            Indicates that NimBLE controller is present. The default value for
-            this setting shall not be overriden.
-        value: 1
+    BLE_CONTROLLER: 1
 
     BLE_LL_ROLE_CENTRAL:
         description: 'Enables controller support for the Central role.'
@@ -556,6 +552,7 @@ syscfg.vals.!BLE_HOST:
     BLE_LL_HCI_VS_EVENT_ON_ASSERT: 1
 
 syscfg.restrictions:
+    - BLE_TRANSPORT_LL == "native"
     - BLE_LL_PUBLIC_DEV_ADDR <= 0xffffffffffff
     - BLE_LL_PA == 0 || BLE_LL_PA_GPIO >= 0
     - BLE_LL_LNA == 0 || BLE_LL_LNA_GPIO >= 0
diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h
index 8faebe4..eb5165c 100644
--- a/nimble/include/nimble/hci_common.h
+++ b/nimble/include/nimble/hci_common.h
@@ -21,13 +21,14 @@
 #define H_BLE_HCI_COMMON_
 
 #include "ble.h"
+#include "nimble/transport.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define BLE_HCI_MAX_DATA_LEN (MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE) - \
-                              sizeof(struct ble_hci_ev))
+#define BLE_HCI_MAX_DATA_LEN    (MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE) - \
+                                 sizeof(struct ble_hci_ev))
 
 /* Generic command header */
 struct ble_hci_cmd {

[mynewt-nimble] 06/22: nimble/transport: Update Dialog CMAC transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit ef597cc4b87059dd754c483e8a9e3a73d0291b24
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:05:44 2022 +0100

    nimble/transport: Update Dialog CMAC transport
---
 nimble/transport/dialog_cmac/.gitignore            |   2 -
 .../dialog_cmac/cmac_driver/diag/src/cmac_diag.c   |  46 ++-
 .../cmac_driver/include/cmac_driver/cmac_shared.h  |  12 +-
 nimble/transport/dialog_cmac/cmac_driver/pkg.yml   |   5 +-
 .../dialog_cmac/cmac_driver/src/cmac_host.c        |  10 +-
 .../dialog_cmac/cmac_driver/src/cmac_mbox.c        |  26 +-
 .../dialog_cmac/cmac_driver/src/cmac_rand.c        |   2 +-
 .../dialog_cmac/cmac_driver/src/cmac_shared.c      |  24 +-
 .../transport/dialog_cmac/cmac_driver/syscfg.yml   |   2 +-
 nimble/transport/dialog_cmac/pkg.yml               |   5 +-
 .../dialog_cmac/src/ble_hci_cmac_common.c          | 202 -------------
 nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c | 174 -----------
 nimble/transport/dialog_cmac/src/ble_hci_cmac_ll.c | 146 ---------
 .../transport/dialog_cmac/src/ble_hci_cmac_priv.h  |  29 --
 .../transport/dialog_cmac/src/ble_hci_trans_h4.c   | 332 ---------------------
 .../transport/dialog_cmac/src/ble_hci_trans_h4.h   |  49 ---
 nimble/transport/dialog_cmac/src/hci_cmac.c        | 213 +++++++++++++
 nimble/transport/dialog_cmac/syscfg.yml            |  27 --
 18 files changed, 274 insertions(+), 1032 deletions(-)

diff --git a/nimble/transport/dialog_cmac/.gitignore b/nimble/transport/dialog_cmac/.gitignore
deleted file mode 100644
index bba9f99..0000000
--- a/nimble/transport/dialog_cmac/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/src/libble_stack_da1469x.a
-
diff --git a/nimble/transport/dialog_cmac/cmac_driver/diag/src/cmac_diag.c b/nimble/transport/dialog_cmac/cmac_driver/diag/src/cmac_diag.c
index 0a4e27e..8329903 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/diag/src/cmac_diag.c
+++ b/nimble/transport/dialog_cmac/cmac_driver/diag/src/cmac_diag.c
@@ -20,30 +20,6 @@
 #include "syscfg/syscfg.h"
 #include "mcu/mcu.h"
 
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-void
-cmac_diag_setup_host(void)
-{
-    /* Setup pins for diagnostic signals */
-    mcu_gpio_set_pin_function(42, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAG0); /* DIAG_0 @ P1.10 */
-    mcu_gpio_set_pin_function(43, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAG1); /* DIAG_1 @ P1.11 */
-    mcu_gpio_set_pin_function(44, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAG2); /* DIAG_2 @ P1.12 */
-    mcu_gpio_set_pin_function(24, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_3 @ P0.24 */
-    mcu_gpio_set_pin_function(21, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_4 @ P0.21 */
-    mcu_gpio_set_pin_function(20, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_5 @ P0.20 */
-    mcu_gpio_set_pin_function(19, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_6 @ P0.19 */
-    mcu_gpio_set_pin_function(18, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_7 @ P0.18 */
-    mcu_gpio_set_pin_function(31, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_8 @ P0.31 */
-    mcu_gpio_set_pin_function(30, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_9 @ P0.30 */
-    mcu_gpio_set_pin_function(29, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_10 @ P0.29 */
-    mcu_gpio_set_pin_function(28, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_11 @ P0.28 */
-    mcu_gpio_set_pin_function(27, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_12 @ P0.27 */
-    mcu_gpio_set_pin_function(26, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_13 @ P0.26 */
-    mcu_gpio_set_pin_function(38, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_14 @ P1.06 */
-    mcu_gpio_set_pin_function(41, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_15 @ P1.09 */
-}
-#endif
-
 #if MYNEWT_VAL(BLE_CONTROLLER)
 void
 cmac_diag_setup_cmac(void)
@@ -65,4 +41,26 @@ cmac_diag_setup_cmac(void)
     MCU_DIAG_MAP(14, 4, SLEEPING);
     MCU_DIAG_MAP(15, 8, LL_TIMER1_00);
 }
+#else
+void
+cmac_diag_setup_host(void)
+{
+    /* Setup pins for diagnostic signals */
+    mcu_gpio_set_pin_function(42, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAG0); /* DIAG_0 @ P1.10 */
+    mcu_gpio_set_pin_function(43, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAG1); /* DIAG_1 @ P1.11 */
+    mcu_gpio_set_pin_function(44, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAG2); /* DIAG_2 @ P1.12 */
+    mcu_gpio_set_pin_function(24, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_3 @ P0.24 */
+    mcu_gpio_set_pin_function(21, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_4 @ P0.21 */
+    mcu_gpio_set_pin_function(20, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_5 @ P0.20 */
+    mcu_gpio_set_pin_function(19, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_6 @ P0.19 */
+    mcu_gpio_set_pin_function(18, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_7 @ P0.18 */
+    mcu_gpio_set_pin_function(31, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_8 @ P0.31 */
+    mcu_gpio_set_pin_function(30, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_9 @ P0.30 */
+    mcu_gpio_set_pin_function(29, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_10 @ P0.29 */
+    mcu_gpio_set_pin_function(28, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_11 @ P0.28 */
+    mcu_gpio_set_pin_function(27, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_12 @ P0.27 */
+    mcu_gpio_set_pin_function(26, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_13 @ P0.26 */
+    mcu_gpio_set_pin_function(38, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_14 @ P1.06 */
+    mcu_gpio_set_pin_function(41, MCU_GPIO_MODE_OUTPUT, MCU_GPIO_FUNC_CMAC_DIAGX); /* DIAG_15 @ P1.09 */
+}
 #endif
diff --git a/nimble/transport/dialog_cmac/cmac_driver/include/cmac_driver/cmac_shared.h b/nimble/transport/dialog_cmac/cmac_driver/include/cmac_driver/cmac_shared.h
index da3a3cf..887af25 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/include/cmac_driver/cmac_shared.h
+++ b/nimble/transport/dialog_cmac/cmac_driver/include/cmac_driver/cmac_shared.h
@@ -131,10 +131,10 @@ struct cmac_shared_data {
     uint8_t mbox_c2s_buf[ MYNEWT_VAL(CMAC_MBOX_SIZE_C2S) ];
 };
 
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-extern volatile struct cmac_shared_data *g_cmac_shared_data;
-#elif MYNEWT_VAL(BLE_CONTROLLER)
+#if MYNEWT_VAL(BLE_CONTROLLER)
 extern volatile struct cmac_shared_data g_cmac_shared_data;
+#else
+extern volatile struct cmac_shared_data *g_cmac_shared_data;
 #endif
 
 /* cmac_mbox */
@@ -162,10 +162,10 @@ void cmac_rand_set_isr_cb(cmac_rand_isr_cb_t cb);
 void cmac_shared_init(void);
 void cmac_shared_sync(void);
 
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-#define CMAC_SHARED_LOCK_VAL    0x40000000
-#elif MYNEWT_VAL(BLE_CONTROLLER)
+#if MYNEWT_VAL(BLE_CONTROLLER)
 #define CMAC_SHARED_LOCK_VAL    0xc0000000
+#else
+#define CMAC_SHARED_LOCK_VAL    0x40000000
 #endif
 
 static inline void
diff --git a/nimble/transport/dialog_cmac/cmac_driver/pkg.yml b/nimble/transport/dialog_cmac/cmac_driver/pkg.yml
index 00200b6..1fa003a 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/pkg.yml
+++ b/nimble/transport/dialog_cmac/cmac_driver/pkg.yml
@@ -35,8 +35,5 @@ pkg.ign_files.BLE_CONTROLLER:
 pkg.post_link_cmds.BLE_CONTROLLER:
     scripts/create_cmac_bin.sh: 100
 
-pkg.pre_link_cmds.BLE_HOST:
-    scripts/build_libcmac.sh: 100
-
-pkg.pre_link_cmds.BLE_HCI_BRIDGE:
+pkg.pre_link_cmds.!BLE_CONTROLLER:
     scripts/build_libcmac.sh: 100
diff --git a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_host.c b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_host.c
index 965db13..cdb0006 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_host.c
+++ b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_host.c
@@ -65,7 +65,7 @@ static struct os_event g_cmac_host_rand_ev = {
 
 static void cmac_host_rand_chk_fill(void);
 
-#if MYNEWT_VAL(BLE_HCI_BRIDGE) && MYNEWT_VAL_CHOICE(BLE_HCI_TRANSPORT, uart)
+#if MYNEWT_VAL_CHOICE(BLE_TRANSPORT_HS, uart)
 static void cmac_host_error_w4flush(struct os_event *ev);
 static struct os_event g_cmac_host_error_ev = {
         .ev_cb = cmac_host_error_w4flush
@@ -113,7 +113,7 @@ cmac2sys_isr(void)
         }
 #endif
 
-#if MYNEWT_VAL(BLE_HCI_BRIDGE) && MYNEWT_VAL_CHOICE(BLE_HCI_TRANSPORT, uart)
+#if MYNEWT_VAL_CHOICE(BLE_TRANSPORT_HS, uart)
         NVIC_DisableIRQ(CMAC2SYS_IRQn);
         /* Wait until UART is flushed and then assert */
         cmac_host_error_w4flush(NULL);
@@ -162,8 +162,8 @@ cmac_host_rand_chk_fill(void)
     }
 }
 
-#if MYNEWT_VAL(BLE_HCI_BRIDGE) && MYNEWT_VAL_CHOICE(BLE_HCI_TRANSPORT, uart)
-#if MYNEWT_VAL(BLE_HCI_UART_PORT) < 0 || MYNEWT_VAL(BLE_HCI_UART_PORT) > 2
+#if MYNEWT_VAL_CHOICE(BLE_TRANSPORT_HS, uart)
+#if MYNEWT_VAL(BLE_TRANSPORT_UART_PORT) < 0 || MYNEWT_VAL(BLE_TRANSPORT_UART_PORT) > 2
 #error Invalid BLE_HCI_UART_PORT
 #endif
 static void
@@ -183,7 +183,7 @@ cmac_host_error_w4flush(struct os_event *ev)
 
     do {
         cmac_mbox_read();
-        while ((regs[MYNEWT_VAL(BLE_HCI_UART_PORT)]->UART_LSR_REG &
+        while ((regs[MYNEWT_VAL(BLE_TRANSPORT_UART_PORT)]->UART_LSR_REG &
                 UART_UART_LSR_REG_UART_TEMT_Msk) == 0) {
             /* Wait until both FIFO and shift registers are empty */
         }
diff --git a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_mbox.c b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_mbox.c
index 36f4e25..d2ee9ac 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_mbox.c
+++ b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_mbox.c
@@ -49,10 +49,10 @@ cmac_mbox_set_write_notif_cb(cmac_mbox_write_notif_cb *cb)
 int
 cmac_mbox_has_data(void)
 {
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_c2s;
-#else
+#if MYNEWT_VAL(BLE_CONTROLLER)
     volatile struct cmac_mbox *mbox = &g_cmac_shared_data.mbox_s2c;
+#else
+    volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_c2s;
 #endif
 
     return mbox->rd_off != mbox->wr_off;
@@ -61,14 +61,14 @@ cmac_mbox_has_data(void)
 int
 cmac_mbox_read(void)
 {
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_c2s;
-    uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data->mbox_c2s_buf;
-    const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_C2S);
-#else
+#if MYNEWT_VAL(BLE_CONTROLLER)
     volatile struct cmac_mbox *mbox = &g_cmac_shared_data.mbox_s2c;
     uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data.mbox_s2c_buf;
     const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_S2C);
+#else
+    volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_c2s;
+    uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data->mbox_c2s_buf;
+    const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_C2S);
 #endif
     uint16_t rd_off;
     uint16_t wr_off;
@@ -108,14 +108,14 @@ cmac_mbox_read(void)
 int
 cmac_mbox_write(const void *data, uint16_t len)
 {
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_s2c;
-    uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data->mbox_s2c_buf;
-    const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_S2C);
-#else
+#if MYNEWT_VAL(BLE_CONTROLLER)
     volatile struct cmac_mbox *mbox = &g_cmac_shared_data.mbox_c2s;
     uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data.mbox_c2s_buf;
     const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_C2S);
+#else
+    volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_s2c;
+    uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data->mbox_s2c_buf;
+    const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_S2C);
 #endif
     uint16_t rd_off;
     uint16_t wr_off;
diff --git a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_rand.c b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_rand.c
index 1081097..dbb93e9 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_rand.c
+++ b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_rand.c
@@ -26,7 +26,7 @@
 #include "os/os_arch.h"
 #include "os/os.h"
 
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
+#if !MYNEWT_VAL(BLE_CONTROLLER)
 int
 cmac_rand_is_active(void)
 {
diff --git a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_shared.c b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_shared.c
index a4f2e37..cd7984a 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/src/cmac_shared.c
+++ b/nimble/transport/dialog_cmac/cmac_driver/src/cmac_shared.c
@@ -34,18 +34,18 @@
 #define min(_a, _b)     ((_a) < (_b) ? (_a) : (_b))
 #endif
 
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
+#if MYNEWT_VAL(BLE_CONTROLLER)
+volatile struct cmac_shared_data g_cmac_shared_data     __attribute__((section(".shdata")));
+#else
 volatile struct cmac_shared_data *g_cmac_shared_data;
 #include "mcu/da1469x_clock.h"
 #define MCU_DIAG_SER(_x)
-#elif MYNEWT_VAL(BLE_CONTROLLER)
-volatile struct cmac_shared_data g_cmac_shared_data     __attribute__((section(".shdata")));
 #endif
 
 void
 cmac_shared_init(void)
 {
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
+#if !MYNEWT_VAL(BLE_CONTROLLER)
     g_cmac_shared_data = (void *)(MCU_MEM_SYSRAM_START_ADDRESS +
                                   MEMCTRL->CMI_SHARED_BASE_REG);
 
@@ -77,15 +77,6 @@ cmac_shared_sync(void)
      * to wait until CMAC finished initialization as otherwise host may start
      * sending HCI packets which will timeout as there is no one to read them.
      */
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    assert(g_cmac_shared_data->magic_sys == 0);
-
-    while (g_cmac_shared_data->magic_cmac != CMAC_SHARED_MAGIC_CMAC);
-    g_cmac_shared_data->magic_sys = CMAC_SHARED_MAGIC_SYS;
-
-    NVIC_EnableIRQ(CMAC2SYS_IRQn);
-#endif
-
 #if MYNEWT_VAL(BLE_CONTROLLER)
     assert(g_cmac_shared_data.magic_cmac == 0);
 
@@ -94,5 +85,12 @@ cmac_shared_sync(void)
 
     NVIC_SetPriority(SYS2CMAC_IRQn, 3);
     NVIC_EnableIRQ(SYS2CMAC_IRQn);
+#else
+    assert(g_cmac_shared_data->magic_sys == 0);
+
+    while (g_cmac_shared_data->magic_cmac != CMAC_SHARED_MAGIC_CMAC);
+    g_cmac_shared_data->magic_sys = CMAC_SHARED_MAGIC_SYS;
+
+    NVIC_EnableIRQ(CMAC2SYS_IRQn);
 #endif
 }
diff --git a/nimble/transport/dialog_cmac/cmac_driver/syscfg.yml b/nimble/transport/dialog_cmac/cmac_driver/syscfg.yml
index a382c42..6ff3b44 100644
--- a/nimble/transport/dialog_cmac/cmac_driver/syscfg.yml
+++ b/nimble/transport/dialog_cmac/cmac_driver/syscfg.yml
@@ -100,5 +100,5 @@ syscfg.defs:
             priority.
         value: 0
 
-syscfg.restrictions.BLE_HOST:
+syscfg.restrictions.!BLE_CONTROLLER:
     - TRNG
diff --git a/nimble/transport/dialog_cmac/pkg.yml b/nimble/transport/dialog_cmac/pkg.yml
index ef8fc1e..2c02d7e 100644
--- a/nimble/transport/dialog_cmac/pkg.yml
+++ b/nimble/transport/dialog_cmac/pkg.yml
@@ -26,11 +26,8 @@ pkg.keywords:
     - bluetooth
 
 pkg.deps:
-    - nimble
+    - nimble/transport/common/hci_h4
     - nimble/transport/dialog_cmac/cmac_driver
 
 pkg.apis:
     - ble_transport
-
-pkg.init:
-    ble_hci_cmac_init: 100
diff --git a/nimble/transport/dialog_cmac/src/ble_hci_cmac_common.c b/nimble/transport/dialog_cmac/src/ble_hci_cmac_common.c
deleted file mode 100644
index 5a41ee6..0000000
--- a/nimble/transport/dialog_cmac/src/ble_hci_cmac_common.c
+++ /dev/null
@@ -1,202 +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 <assert.h>
-#include <string.h>
-
-#include "syscfg/syscfg.h"
-#include "os/mynewt.h"
-#include "nimble/ble.h"
-#include "nimble/ble_hci_trans.h"
-#include "nimble/hci_common.h"
-#include "ble_hci_cmac_priv.h"
-
-/*
- * If controller-to-host flow control is enabled we need to hold an extra command
- * buffer for HCI_Host_Number_Of_Completed_Packets which can be sent at any time.
- */
-#if MYNEWT_VAL(BLE_HS_FLOW_CTRL) || MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
-#define HCI_CMD_COUNT   2
-#else
-#define HCI_CMD_COUNT   1
-#endif
-
-#define POOL_ACL_BLOCK_SIZE     OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) +     \
-                                         BLE_MBUF_MEMBLOCK_OVERHEAD +       \
-                                         BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-static uint8_t ble_hci_pool_cmd_mempool_buf[
-    OS_MEMPOOL_BYTES(HCI_CMD_COUNT, BLE_HCI_TRANS_CMD_SZ)];
-static struct os_mempool ble_hci_pool_cmd_mempool;
-
-static uint8_t ble_hci_pool_evt_hi_mempool_buf[
-    OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                     MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))];
-static struct os_mempool ble_hci_pool_evt_hi_mempool;
-
-static uint8_t ble_hci_pool_evt_lo_mempool_buf[
-    OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                     MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))];
-static struct os_mempool ble_hci_pool_evt_lo_mempool;
-#endif
-
-static uint8_t ble_hci_pool_acl_mempool_buf[
-    OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                     POOL_ACL_BLOCK_SIZE)];
-static struct os_mempool_ext ble_hci_pool_acl_mempool;
-static struct os_mbuf_pool ble_hci_pool_acl_mbuf_pool;
-
-__attribute__((weak)) void ble_hci_trans_notify_free(void);
-
-static os_mempool_put_fn *g_ble_hci_pool_acl_mempool_put_cb;
-static void *g_ble_hci_pool_acl_mempool_put_arg;
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-int
-ble_hci_trans_reset(void)
-{
-    return 0;
-}
-
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        buf = os_memblock_get(&ble_hci_pool_cmd_mempool);
-        break;
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_pool_evt_hi_mempool);
-        if (buf) {
-            break;
-        }
-    /* no break */
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&ble_hci_pool_evt_lo_mempool);
-        break;
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    if (os_memblock_from(&ble_hci_pool_cmd_mempool, buf)) {
-        rc = os_memblock_put(&ble_hci_pool_cmd_mempool, buf);
-        assert(rc == 0);
-    } else if (os_memblock_from(&ble_hci_pool_evt_hi_mempool, buf)) {
-        rc = os_memblock_put(&ble_hci_pool_evt_hi_mempool, buf);
-        assert(rc == 0);
-    } else {
-        assert(os_memblock_from(&ble_hci_pool_evt_lo_mempool, buf));
-        rc = os_memblock_put(&ble_hci_pool_evt_lo_mempool, buf);
-        assert(rc == 0);
-    }
-
-    ble_hci_trans_notify_free();
-}
-#endif
-
-struct os_mbuf *
-ble_hci_cmac_alloc_acl_mbuf(void)
-{
-    return os_mbuf_get_pkthdr(&ble_hci_pool_acl_mbuf_pool,
-                              sizeof(struct ble_mbuf_hdr));
-}
-
-static os_error_t
-ble_hci_cmac_free_acl_cb(struct os_mempool_ext *mpe, void *data, void *arg)
-{
-    int rc;
-
-    if (g_ble_hci_pool_acl_mempool_put_cb) {
-        rc = g_ble_hci_pool_acl_mempool_put_cb(mpe, data,
-                                               g_ble_hci_pool_acl_mempool_put_arg);
-    } else {
-        rc = os_memblock_put_from_cb(&mpe->mpe_mp, data);
-    }
-
-    if (rc != 0) {
-        return rc;
-    }
-
-    ble_hci_trans_notify_free();
-
-    return 0;
-}
-
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-int
-ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
-{
-    g_ble_hci_pool_acl_mempool_put_cb = cb;
-    g_ble_hci_pool_acl_mempool_put_arg = arg;
-
-    return 0;
-}
-#endif
-
-void
-ble_hci_cmac_init(void)
-{
-    int rc;
-
-    SYSINIT_ASSERT_ACTIVE();
-
-#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
-    rc = os_mempool_init(&ble_hci_pool_cmd_mempool,
-                         HCI_CMD_COUNT, BLE_HCI_TRANS_CMD_SZ,
-                         ble_hci_pool_cmd_mempool_buf, "ble_hci_cmd");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_pool_evt_hi_mempool,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_pool_evt_hi_mempool_buf, "ble_hci_evt_hi");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&ble_hci_pool_evt_lo_mempool,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         ble_hci_pool_evt_lo_mempool_buf, "ble_hci_evt_lo");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-#endif
-
-    rc = os_mempool_ext_init(&ble_hci_pool_acl_mempool,
-                             MYNEWT_VAL(BLE_ACL_BUF_COUNT), POOL_ACL_BLOCK_SIZE,
-                             ble_hci_pool_acl_mempool_buf, "ble_hci_acl");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&ble_hci_pool_acl_mbuf_pool,
-                           &ble_hci_pool_acl_mempool.mpe_mp, POOL_ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    ble_hci_pool_acl_mempool.mpe_put_cb = ble_hci_cmac_free_acl_cb;
-}
diff --git a/nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c b/nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c
deleted file mode 100644
index 266637f..0000000
--- a/nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c
+++ /dev/null
@@ -1,174 +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 <assert.h>
-#include <string.h>
-#include "syscfg/syscfg.h"
-
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-
-#include "cmac_driver/cmac_shared.h"
-#include "cmac_driver/cmac_host.h"
-#include "nimble/ble_hci_trans.h"
-#include "os/os_mbuf.h"
-#include "ble_hci_trans_h4.h"
-#include "ble_hci_cmac_priv.h"
-
-struct ble_hci_cmac_hs_api {
-    ble_hci_trans_rx_cmd_fn *evt_cb;
-    void *evt_arg;
-    ble_hci_trans_rx_acl_fn *acl_cb;
-    void *acl_arg;
-};
-
-static struct ble_hci_cmac_hs_api g_ble_hci_cmac_hs_api;
-static struct ble_hci_trans_h4_rx_state g_ble_hci_cmac_hs_rx_state;
-static bool g_ble_hci_cmac_hs_read_err;
-
-#if MYNEWT_VAL(BLE_HCI_BRIDGE)
-/*
- * TODO: Remove/fix functions ble_ll_data_buffer_overflow() ble_ll_hw_error()
- * Following two functions are added to allowed build of HCI bridge configurations.
- * Those functions are only used by UART transport, in RAM transport configuration
- * they can be called directly in bridge mode controller code is on other core
- * and those can't be called.
- */
-void
-ble_ll_data_buffer_overflow(void)
-{
-
-}
-
-void
-ble_ll_hw_error(uint8_t err)
-{
-    (void)err;
-}
-#endif
-
-static int
-ble_hci_cmac_hs_frame_cb(uint8_t pkt_type, void *data)
-{
-    int rc;
-
-    switch (pkt_type) {
-    case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
-        rc = g_ble_hci_cmac_hs_api.acl_cb(data, g_ble_hci_cmac_hs_api.acl_arg);
-        break;
-    case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
-        rc = g_ble_hci_cmac_hs_api.evt_cb(data, g_ble_hci_cmac_hs_api.evt_arg);
-        break;
-    default:
-        assert(0);
-        break;
-    }
-
-    return rc;
-}
-
-static int
-ble_hci_cmac_hs_mbox_read_cb(const void *data, uint16_t len)
-{
-    int rlen;
-    os_sr_t sr;
-
-    rlen = ble_hci_trans_h4_rx(&g_ble_hci_cmac_hs_rx_state, data, len,
-                               ble_hci_cmac_hs_frame_cb);
-    if (rlen < 0) {
-        /*
-         * There was oom error, we need to wait for buffer to be freed and
-         * trigger another read.
-         */
-        OS_ENTER_CRITICAL(sr);
-        g_ble_hci_cmac_hs_read_err = true;
-        OS_EXIT_CRITICAL(sr);
-    }
-
-    return rlen;
-}
-
-static void
-ble_hci_cmac_hs_mbox_write_notif_cb(void)
-{
-    cmac_host_signal2cmac();
-}
-
-int
-ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
-{
-    uint8_t pkt_type = BLE_HCI_TRANS_H4_PKT_TYPE_CMD;
-
-    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
-    cmac_mbox_write(cmd, cmd[2] + 3);
-
-    ble_hci_trans_buf_free(cmd);
-
-    return 0;
-}
-
-int
-ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
-{
-    uint8_t pkt_type = BLE_HCI_TRANS_H4_PKT_TYPE_ACL;
-    struct os_mbuf *om_next;
-
-    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
-
-    while (om) {
-        om_next = SLIST_NEXT(om, om_next);
-
-        cmac_mbox_write(om->om_data, om->om_len);
-
-        os_mbuf_free(om);
-        om = om_next;
-    }
-
-    return 0;
-}
-
-void
-ble_hci_trans_notify_free(void)
-{
-    os_sr_t sr;
-
-    OS_ENTER_CRITICAL(sr);
-    if (g_ble_hci_cmac_hs_read_err) {
-        g_ble_hci_cmac_hs_read_err = false;
-        /* Just trigger an interrupt, it will trigger read */
-        NVIC_SetPendingIRQ(CMAC2SYS_IRQn);
-    }
-    OS_EXIT_CRITICAL(sr);
-}
-
-void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb, void *evt_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb, void *acl_arg)
-{
-    g_ble_hci_cmac_hs_api.evt_cb = evt_cb;
-    g_ble_hci_cmac_hs_api.evt_arg = evt_arg;
-    g_ble_hci_cmac_hs_api.acl_cb = acl_cb;
-    g_ble_hci_cmac_hs_api.acl_arg = acl_arg;
-
-    /* We can now handle data from CMAC, initialize it */
-    cmac_mbox_set_read_cb(ble_hci_cmac_hs_mbox_read_cb);
-    cmac_mbox_set_write_notif_cb(ble_hci_cmac_hs_mbox_write_notif_cb);
-    cmac_host_init();
-}
-
-#endif
diff --git a/nimble/transport/dialog_cmac/src/ble_hci_cmac_ll.c b/nimble/transport/dialog_cmac/src/ble_hci_cmac_ll.c
deleted file mode 100644
index 6b49158..0000000
--- a/nimble/transport/dialog_cmac/src/ble_hci_cmac_ll.c
+++ /dev/null
@@ -1,146 +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 "syscfg/syscfg.h"
-
-#if MYNEWT_VAL(BLE_CONTROLLER)
-
-#if !MYNEWT_VAL(MCU_DEBUG_DSER_BLE_HCI_CMAC_LL)
-#define MCU_DIAG_SER_DISABLE
-#endif
-
-#include <assert.h>
-#include <string.h>
-#include "mcu/mcu.h"
-#include "cmac_driver/cmac_shared.h"
-#include "nimble/ble_hci_trans.h"
-#include "os/os_mbuf.h"
-#include "ble_hci_trans_h4.h"
-#include "ble_hci_cmac_priv.h"
-
-struct ble_hci_cmac_ll_api {
-    ble_hci_trans_rx_cmd_fn *cmd_cb;
-    void *cmd_arg;
-    ble_hci_trans_rx_acl_fn *acl_cb;
-    void *acl_arg;
-};
-
-static struct ble_hci_cmac_ll_api g_ble_hci_cmac_ll_api;
-static struct ble_hci_trans_h4_rx_state g_ble_hci_cmac_ll_rx_state;
-
-static int
-ble_hci_cmac_ll_frame_cb(uint8_t pkt_type, void *data)
-{
-    int rc;
-
-    MCU_DIAG_SER('F');
-
-    switch (pkt_type) {
-    case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
-        rc = g_ble_hci_cmac_ll_api.cmd_cb(data, g_ble_hci_cmac_ll_api.cmd_arg);
-        break;
-    case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
-        rc = g_ble_hci_cmac_ll_api.acl_cb(data, g_ble_hci_cmac_ll_api.acl_arg);
-        break;
-    default:
-        assert(0);
-        break;
-    }
-
-    return rc;
-}
-
-static int
-ble_hci_cmac_ll_mbox_read_cb(const void *data, uint16_t len)
-{
-    int rlen;
-
-    MCU_DIAG_SER('R');
-    rlen = ble_hci_trans_h4_rx(&g_ble_hci_cmac_ll_rx_state, data, len,
-                               ble_hci_cmac_ll_frame_cb);
-
-    /* There should be no oom on LL side due to flow control used */
-    assert(rlen >= 0);
-
-    return rlen;
-}
-
-static void
-ble_hci_cmac_ll_mbox_write_notif_cb(void)
-{
-    MCU_DIAG_SER('W');
-    CMAC->CM_EV_SET_REG = CMAC_CM_EV_SET_REG_EV1C_CMAC2SYS_IRQ_SET_Msk;
-}
-
-int
-ble_hci_trans_ll_evt_tx(uint8_t *evt)
-{
-    uint8_t pkt_type = BLE_HCI_TRANS_H4_PKT_TYPE_EVT;
-    os_sr_t sr;
-
-    OS_ENTER_CRITICAL(sr);
-
-    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
-    cmac_mbox_write(evt, evt[1] + 2);
-
-    ble_hci_trans_buf_free(evt);
-
-    OS_EXIT_CRITICAL(sr);
-
-    return 0;
-}
-
-int
-ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
-{
-    uint8_t pkt_type = BLE_HCI_TRANS_H4_PKT_TYPE_ACL;
-    struct os_mbuf *om_next;
-
-    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
-
-    while (om) {
-        om_next = SLIST_NEXT(om, om_next);
-
-        cmac_mbox_write(om->om_data, om->om_len);
-
-        os_mbuf_free(om);
-        om = om_next;
-    }
-
-    return 0;
-}
-
-void
-ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb, void *cmd_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb, void *acl_arg)
-{
-    g_ble_hci_cmac_ll_api.cmd_cb = cmd_cb;
-    g_ble_hci_cmac_ll_api.cmd_arg = cmd_arg;
-    g_ble_hci_cmac_ll_api.acl_cb = acl_cb;
-    g_ble_hci_cmac_ll_api.acl_arg = acl_arg;
-
-    /* Setup callbacks for mailboxes */
-    cmac_mbox_set_read_cb(ble_hci_cmac_ll_mbox_read_cb);
-    cmac_mbox_set_write_notif_cb(ble_hci_cmac_ll_mbox_write_notif_cb);
-
-    /* Synchronize with SYS */
-    cmac_shared_sync();
-}
-
-#endif
diff --git a/nimble/transport/dialog_cmac/src/ble_hci_cmac_priv.h b/nimble/transport/dialog_cmac/src/ble_hci_cmac_priv.h
deleted file mode 100644
index 451053c..0000000
--- a/nimble/transport/dialog_cmac/src/ble_hci_cmac_priv.h
+++ /dev/null
@@ -1,29 +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 _BLE_HCI_CMAC_PRIV_H_
-#define _BLE_HCI_CMAC_PRIV_H_
-
-#include "os/os_mbuf.h"
-
-struct os_mbuf *ble_hci_cmac_alloc_acl_mbuf(void);
-
-void ble_hci_trans_notify_free(void);
-
-#endif /* _BLE_HCI_CMAC_PRIV_H_ */
diff --git a/nimble/transport/dialog_cmac/src/ble_hci_trans_h4.c b/nimble/transport/dialog_cmac/src/ble_hci_trans_h4.c
deleted file mode 100644
index 628ae75..0000000
--- a/nimble/transport/dialog_cmac/src/ble_hci_trans_h4.c
+++ /dev/null
@@ -1,332 +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 <assert.h>
-#include <stdbool.h>
-#include <string.h>
-#include "syscfg/syscfg.h"
-#include "os/os_mbuf.h"
-#include "nimble/ble_hci_trans.h"
-#include "nimble/hci_common.h"
-#include "ble_hci_trans_h4.h"
-#include "ble_hci_cmac_priv.h"
-
-#define RXS_STATE_W4_PKT_TYPE       0
-#define RXS_STATE_W4_HEADER         1
-#define RXS_STATE_W4_PAYLOAD        2
-#define RXS_STATE_COMPLETED         3
-
-struct input_buffer {
-    const uint8_t *buf;
-    uint16_t len;
-};
-
-static int
-ble_hci_trans_h4_ib_adjust(struct input_buffer *ib, uint16_t len)
-{
-    assert(ib->len >= len);
-
-    ib->buf += len;
-    ib->len -= len;
-
-    return len;
-}
-
-static void
-ble_hci_trans_h4_rxs_start(struct ble_hci_trans_h4_rx_state *rxs, uint8_t pkt_type)
-{
-    rxs->pkt_type = pkt_type;
-    rxs->len = 0;
-    rxs->expected_len = 0;
-
-    switch (rxs->pkt_type) {
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
-        rxs->min_len = 3;
-        break;
-#endif
-    case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
-        rxs->min_len = 4;
-        break;
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
-        rxs->min_len = 2;
-        break;
-#endif
-    default:
-        /* XXX sync loss */
-        assert(0);
-        break;
-    }
-}
-
-static int
-ble_hci_trans_h4_pull_min_len(struct ble_hci_trans_h4_rx_state *rxs,
-                              struct input_buffer *ib)
-{
-    uint16_t len;
-
-    len = min(ib->len, rxs->min_len - rxs->len);
-    memcpy(&rxs->hdr[rxs->len], ib->buf, len);
-
-    rxs->len += len;
-    ble_hci_trans_h4_ib_adjust(ib, len);
-
-    return rxs->len != rxs->min_len;
-}
-
-static int
-ble_hci_trans_h4_rx_state_w4_header(struct ble_hci_trans_h4_rx_state *rxs,
-                                    struct input_buffer *ib)
-{
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    int pool;
-#endif
-    int rc;
-
-    rc = ble_hci_trans_h4_pull_min_len(rxs, ib);
-    if (rc) {
-        /* need more data */
-        return 1;
-    }
-
-    switch (rxs->pkt_type) {
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
-        rxs->buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
-        if (!rxs->buf) {
-            return -1;
-        }
-
-        memcpy(rxs->buf, rxs->hdr, rxs->len);
-        rxs->expected_len = rxs->hdr[2] + 3;
-        break;
-#endif
-    case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
-        rxs->om = ble_hci_cmac_alloc_acl_mbuf();
-        if (!rxs->om) {
-            return -1;
-        }
-
-        os_mbuf_append(rxs->om, rxs->hdr, rxs->len);
-        rxs->expected_len = get_le16(&rxs->hdr[2]) + 4;
-        break;
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
-        pool = BLE_HCI_TRANS_BUF_EVT_HI;
-        if (rxs->hdr[0] == BLE_HCI_EVCODE_LE_META) {
-            /* For LE Meta event we need 3 bytes to parse header */
-            rxs->min_len = 3;
-            rc = ble_hci_trans_h4_pull_min_len(rxs, ib);
-            if (rc) {
-                /* need more data */
-                return 1;
-            }
-
-            /* Advertising reports shall be allocated from low-prio pool */
-            if ((rxs->hdr[2] == BLE_HCI_LE_SUBEV_ADV_RPT) ||
-                (rxs->hdr[2] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) {
-                pool = BLE_HCI_TRANS_BUF_EVT_LO;
-            }
-        }
-
-        /*
-         * XXX Events originally allocated from hi-pool can use lo-pool as
-         *     fallback and cannot be dropped. Events allocated from lo-pool
-         *     can be dropped to avoid oom while scanning which means that
-         *     any advertising or extended advertising report can be silently
-         *     discarded by transport. While this is perfectly fine for legacy
-         *     advertising, for extended advertising it means we can drop start
-         *     or end of chain report and host won't be able to reassemble
-         *     chain properly... so just need to make sure pool on host side is
-         *     large enough to catch up with controller.
-         */
-        rxs->buf = ble_hci_trans_buf_alloc(pool);
-        if (!rxs->buf && pool == BLE_HCI_TRANS_BUF_EVT_HI) {
-            rxs->buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
-            if (!rxs->buf) {
-                return -1;
-            }
-        }
-
-        if (rxs->buf) {
-            memcpy(rxs->buf, rxs->hdr, rxs->len);
-        }
-
-        rxs->expected_len = rxs->hdr[1] + 2;
-        break;
-#endif
-    default:
-        assert(0);
-        break;
-    }
-
-    return 0;
-}
-
-static int
-ble_hci_trans_h4_rx_state_w4_payload(struct ble_hci_trans_h4_rx_state *rxs,
-                                     struct input_buffer *ib)
-{
-    uint16_t mbuf_len;
-    uint16_t len;
-    int rc;
-
-    len = min(ib->len, rxs->expected_len - rxs->len);
-
-    switch (rxs->pkt_type) {
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
-#endif
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
-#endif
-        if (rxs->buf) {
-            memcpy(&rxs->buf[rxs->len], ib->buf, len);
-        }
-        break;
-    case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
-        assert(rxs->om);
-
-        mbuf_len = OS_MBUF_PKTLEN(rxs->om);
-        rc = os_mbuf_append(rxs->om, ib->buf, len);
-        if (rc) {
-            /*
-             * Some data may already be appended so need to adjust rxs only by
-             * the size of appended data.
-             */
-            len = OS_MBUF_PKTLEN(rxs->om) - mbuf_len;
-            rxs->len += len;
-            ble_hci_trans_h4_ib_adjust(ib, len);
-
-            return -1;
-        }
-        break;
-    default:
-        assert(0);
-        break;
-    }
-
-    rxs->len += len;
-    ble_hci_trans_h4_ib_adjust(ib, len);
-
-    /* return 1 if need more data */
-    return rxs->len != rxs->expected_len;
-}
-
-static void
-ble_hci_trans_h4_rx_state_completed(struct ble_hci_trans_h4_rx_state *rxs,
-                                    ble_hci_trans_h4_frame_cb *frame_cb)
-{
-    int rc;
-
-    switch (rxs->pkt_type) {
-#if MYNEWT_VAL(BLE_CONTROLLER)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
-#endif
-#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
-    case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
-#endif
-        if (rxs->buf) {
-            rc = frame_cb(rxs->pkt_type, rxs->buf);
-            if (rc != 0) {
-                ble_hci_trans_buf_free(rxs->buf);
-            }
-            rxs->buf = NULL;
-        }
-        break;
-    case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
-        if (rxs->om) {
-            rc = frame_cb(rxs->pkt_type, rxs->om);
-            if (rc != 0) {
-                os_mbuf_free_chain(rxs->om);
-            }
-            rxs->om = NULL;
-        }
-        break;
-    default:
-        assert(0);
-        break;
-    }
-}
-
-int
-ble_hci_trans_h4_rx(struct ble_hci_trans_h4_rx_state *rxs, const uint8_t *buf,
-                    uint16_t len, ble_hci_trans_h4_frame_cb *frame_cb)
-{
-    struct input_buffer ib = {
-        .buf = buf,
-        .len = len,
-    };
-    int rc = 0;
-
-    while (ib.len && (rc >= 0)) {
-        rc = 0;
-        switch (rxs->state) {
-        case RXS_STATE_W4_PKT_TYPE:
-            ble_hci_trans_h4_rxs_start(rxs, ib.buf[0]);
-            ble_hci_trans_h4_ib_adjust(&ib, 1);
-            rxs->state = RXS_STATE_W4_HEADER;
-        /* no break */
-
-        case RXS_STATE_W4_HEADER:
-            rc = ble_hci_trans_h4_rx_state_w4_header(rxs, &ib);
-            if (rc) {
-                break;
-            }
-            rxs->state = RXS_STATE_W4_PAYLOAD;
-        /* no break */
-
-        case RXS_STATE_W4_PAYLOAD:
-            rc = ble_hci_trans_h4_rx_state_w4_payload(rxs, &ib);
-            if (rc) {
-                break;
-            }
-            rxs->state = RXS_STATE_COMPLETED;
-        /* no break */
-
-        case RXS_STATE_COMPLETED:
-            ble_hci_trans_h4_rx_state_completed(rxs, frame_cb);
-            rxs->state = RXS_STATE_W4_PKT_TYPE;
-            break;
-
-        default:
-            assert(0);
-            /* consume all remaining data */
-            ble_hci_trans_h4_ib_adjust(&ib, ib.len);
-            break;
-        }
-    }
-
-    /*
-     * Calculate consumed bytes
-     *
-     * Note: we should always consume some bytes unless there is an oom error.
-     * It's also possible that we have an oom error but already consumed some
-     * data, in such case just return success and error will be returned on next
-     * pass.
-     */
-    len = len - ib.len;
-    if (len == 0) {
-        assert(rc < 0);
-        return -1;
-    }
-
-    return len;
-}
diff --git a/nimble/transport/dialog_cmac/src/ble_hci_trans_h4.h b/nimble/transport/dialog_cmac/src/ble_hci_trans_h4.h
deleted file mode 100644
index 5b83f6b..0000000
--- a/nimble/transport/dialog_cmac/src/ble_hci_trans_h4.h
+++ /dev/null
@@ -1,49 +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 _BLE_HCI_TRANS_H4_H_
-#define _BLE_HCI_TRANS_H4_H_
-
-#include <stdint.h>
-
-#define BLE_HCI_TRANS_H4_PKT_TYPE_NONE      0x00
-#define BLE_HCI_TRANS_H4_PKT_TYPE_CMD       0x01
-#define BLE_HCI_TRANS_H4_PKT_TYPE_ACL       0x02
-#define BLE_HCI_TRANS_H4_PKT_TYPE_EVT       0x04
-
-struct ble_hci_trans_h4_rx_state {
-    uint8_t state;
-    uint8_t pkt_type;
-    uint8_t min_len;
-    uint16_t len;
-    uint16_t expected_len;
-    uint8_t hdr[4];
-    union {
-        uint8_t *buf;
-        struct os_mbuf *om;
-    };
-};
-
-typedef int (ble_hci_trans_h4_frame_cb)(uint8_t pkt_type, void *data);
-
-int ble_hci_trans_h4_rx(struct ble_hci_trans_h4_rx_state *rxs,
-                        const uint8_t *buf, uint16_t len,
-                        ble_hci_trans_h4_frame_cb *frame_cb);
-
-#endif /* _BLE_HCI_TRANS_H4_H_ */
diff --git a/nimble/transport/dialog_cmac/src/hci_cmac.c b/nimble/transport/dialog_cmac/src/hci_cmac.c
new file mode 100644
index 0000000..254e0db
--- /dev/null
+++ b/nimble/transport/dialog_cmac/src/hci_cmac.c
@@ -0,0 +1,213 @@
+/*
+ * 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 <syscfg/syscfg.h>
+#if MYNEWT_VAL(BLE_CONTROLLER)
+/* to enable dser diag */
+#include <mcu/mcu.h>
+#endif /* BLE_CONTROLLER */
+#include <cmac_driver/cmac_shared.h>
+#if !MYNEWT_VAL(BLE_CONTROLLER)
+#include <cmac_driver/cmac_host.h>
+#endif /* !BLE_CONTROLLER */
+#include <os/os_mbuf.h>
+#include <os/os_mempool.h>
+#include <nimble/transport.h>
+#include <nimble/transport/hci_h4.h>
+
+static struct hci_h4_sm hci_cmac_h4sm;
+
+static int
+hci_cmac_acl_tx(struct os_mbuf *om)
+{
+    uint8_t pkt_type = HCI_H4_ACL;
+    struct os_mbuf *om_next;
+
+    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
+
+    while (om) {
+        om_next = SLIST_NEXT(om, om_next);
+
+        cmac_mbox_write(om->om_data, om->om_len);
+
+        os_mbuf_free(om);
+        om = om_next;
+    }
+
+    return 0;
+}
+
+#if !MYNEWT_VAL(BLE_CONTROLLER)
+static int
+hci_cmac_hs_frame_cb(uint8_t pkt_type, void *data)
+{
+    int rc;
+
+    switch (pkt_type) {
+    case HCI_H4_ACL:
+        rc = ble_transport_to_hs_acl(data);
+        break;
+    case HCI_H4_EVT:
+        rc = ble_transport_to_hs_evt(data);
+        break;
+    default:
+        assert(0);
+        break;
+    }
+
+    return rc;
+}
+
+static int
+hci_cmac_hs_mbox_read_cb(const void *data, uint16_t len)
+{
+    int rlen;
+
+    rlen = hci_h4_sm_rx(&hci_cmac_h4sm, data, len);
+    assert(rlen >= 0);
+
+    return rlen;
+}
+
+static void
+hci_cmac_hs_mbox_write_notif_cb(void)
+{
+    cmac_host_signal2cmac();
+}
+
+void
+ble_transport_ll_init(void)
+{
+    hci_h4_sm_init(&hci_cmac_h4sm, &hci_h4_allocs_from_ll, hci_cmac_hs_frame_cb);
+
+    /* We can now handle data from CMAC, initialize it */
+    cmac_mbox_set_read_cb(hci_cmac_hs_mbox_read_cb);
+    cmac_mbox_set_write_notif_cb(hci_cmac_hs_mbox_write_notif_cb);
+    cmac_host_init();
+}
+#endif /* !BLE_CONTROLLER */
+
+#if MYNEWT_VAL(BLE_CONTROLLER)
+#if !MYNEWT_VAL(MCU_DEBUG_DSER_BLE_HCI_CMAC_LL)
+#define MCU_DIAG_SER_DISABLE
+#endif
+
+static int
+hci_cmac_ll_frame_cb(uint8_t pkt_type, void *data)
+{
+    int rc;
+
+    switch (pkt_type) {
+    case HCI_H4_CMD:
+        rc = ble_transport_to_ll_cmd(data);
+        break;
+    case HCI_H4_ACL:
+        rc = ble_transport_to_ll_acl(data);
+        break;
+    default:
+        assert(0);
+        break;
+    }
+
+    return rc;
+}
+
+static int
+hci_cmac_ll_mbox_read_cb(const void *data, uint16_t len)
+{
+    int rlen;
+
+    MCU_DIAG_SER('R');
+    rlen = hci_h4_sm_rx(&hci_cmac_h4sm, data, len);
+    assert(rlen >= 0);
+
+    return rlen;
+}
+
+static void
+hci_cmac_ll_mbox_write_notif_cb(void)
+{
+    MCU_DIAG_SER('W');
+    CMAC->CM_EV_SET_REG = CMAC_CM_EV_SET_REG_EV1C_CMAC2SYS_IRQ_SET_Msk;
+}
+
+void
+ble_transport_hs_init(void)
+{
+    hci_h4_sm_init(&hci_cmac_h4sm, &hci_h4_allocs_from_hs, hci_cmac_ll_frame_cb);
+
+    /* Setup callbacks for mailboxes */
+    cmac_mbox_set_read_cb(hci_cmac_ll_mbox_read_cb);
+    cmac_mbox_set_write_notif_cb(hci_cmac_ll_mbox_write_notif_cb);
+
+    /* Synchronize with SYS */
+    cmac_shared_sync();
+}
+#endif
+
+#if !MYNEWT_VAL(BLE_CONTROLLER)
+int
+ble_transport_to_ll_cmd(void *buf)
+{
+    uint8_t pkt_type = HCI_H4_CMD;
+    uint8_t *cmd = buf;
+
+    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
+    cmac_mbox_write(cmd, cmd[2] + 3);
+
+    ble_transport_free(buf);
+
+    return 0;
+}
+
+int
+ble_transport_to_ll_acl(struct os_mbuf *om)
+{
+    return hci_cmac_acl_tx(om);
+}
+#endif
+
+#if MYNEWT_VAL(BLE_CONTROLLER)
+int
+ble_transport_to_hs_acl(struct os_mbuf *om)
+{
+    return hci_cmac_acl_tx(om);
+}
+
+int
+ble_transport_to_hs_evt(void *buf)
+{
+    uint8_t pkt_type = HCI_H4_EVT;
+    uint8_t *evt = buf;
+    os_sr_t sr;
+
+    OS_ENTER_CRITICAL(sr);
+
+    cmac_mbox_write(&pkt_type, sizeof(pkt_type));
+    cmac_mbox_write(evt, evt[1] + 2);
+
+    ble_transport_free(buf);
+
+    OS_EXIT_CRITICAL(sr);
+
+    return 0;
+}
+#endif /* BLE_CONTROLLER */
diff --git a/nimble/transport/dialog_cmac/syscfg.yml b/nimble/transport/dialog_cmac/syscfg.yml
deleted file mode 100644
index c67df3d..0000000
--- a/nimble/transport/dialog_cmac/syscfg.yml
+++ /dev/null
@@ -1,27 +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.
-#
-
-syscfg.vals.'!BLE_HCI_BRIDGE':
-    BLE_HCI_EVT_HI_BUF_COUNT: 2
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_ACL_BUF_COUNT: 4
-    BLE_ACL_BUF_SIZE: 255
-
-syscfg.vals.'!BLE_HCI_BRIDGE && (BLE_EXT_ADV || BLE_LL_CFG_FEAT_LL_EXT_ADV)':
-    BLE_HCI_EVT_BUF_SIZE: 257

[mynewt-nimble] 13/22: nimble/transport: Remove da1469x transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 0e2bb74f816d0534f4a44b9359c1320a6d391013
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sat Mar 5 17:37:34 2022 +0100

    nimble/transport: Remove da1469x transport
    
    We do not need transport for proprietary controller provided by Dialog
    since we can run our own controller on CMAC.
---
 nimble/transport/da1469x/.gitignore                |   2 -
 nimble/transport/da1469x/README                    |  13 -
 .../cmac_driver/include/cmac_driver/cmac_host.h    |  37 ---
 nimble/transport/da1469x/cmac_driver/pkg.yml       |  27 --
 .../da1469x/cmac_driver/scripts/build_libcmac.sh   |  51 ---
 .../transport/da1469x/cmac_driver/src/cmac_host.c  | 326 ------------------
 nimble/transport/da1469x/cmac_driver/syscfg.yml    |  23 --
 nimble/transport/da1469x/pkg.yml                   |  38 ---
 nimble/transport/da1469x/src/da1469x_ble_hci.c     | 368 ---------------------
 nimble/transport/da1469x/syscfg.yml                |  27 --
 10 files changed, 912 deletions(-)

diff --git a/nimble/transport/da1469x/.gitignore b/nimble/transport/da1469x/.gitignore
deleted file mode 100644
index bba9f99..0000000
--- a/nimble/transport/da1469x/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/src/libble_stack_da1469x.a
-
diff --git a/nimble/transport/da1469x/README b/nimble/transport/da1469x/README
deleted file mode 100644
index b30a01c..0000000
--- a/nimble/transport/da1469x/README
+++ /dev/null
@@ -1,13 +0,0 @@
-Integrated BLE Controller (CMAC) requires a binary firmware to be loaded. Such
-firmware is distributed by Dialog Semiconductor in SDK package which has to be
-obtained separately, see:
-https://www.dialog-semiconductor.com/products/da1469x-product-family
-
-Firmware is available as part of following library in SDK package:
-sdk/interfaces/ble/binaries/DA1469x-Release/libble_stack_da1469x.a
-
-By default, CMAC driver will look for this file in its package root directory
-(i.e. nimble/transport/da1469x/cmac_driver) but this can be changed using
-CMAC_IMAGE_FILE_NAME syscfg variable.
-
-Current version of CMAC driver was tested with SDK version 10.0.4.66.
diff --git a/nimble/transport/da1469x/cmac_driver/include/cmac_driver/cmac_host.h b/nimble/transport/da1469x/cmac_driver/include/cmac_driver/cmac_host.h
deleted file mode 100644
index f623a48..0000000
--- a/nimble/transport/da1469x/cmac_driver/include/cmac_driver/cmac_host.h
+++ /dev/null
@@ -1,37 +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 __CMAC_HOST_H_
-#define __CMAC_HOST_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef int (* cmac_mbox_read_cb)(const uint8_t *, uint16_t len);
-
-void cmac_host_init(void);
-void cmac_mbox_write(const uint8_t *buf, size_t len);
-void cmac_mbox_set_read_cb(cmac_mbox_read_cb cb);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CMAC_HOST_H_ */
diff --git a/nimble/transport/da1469x/cmac_driver/pkg.yml b/nimble/transport/da1469x/cmac_driver/pkg.yml
deleted file mode 100644
index 90a8931..0000000
--- a/nimble/transport/da1469x/cmac_driver/pkg.yml
+++ /dev/null
@@ -1,27 +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.
-#
-
-pkg.name: nimble/transport/da1469x/cmac_driver
-pkg.description: Driver for Dialog's BLE controller
-pkg.author:
-pkg.homepage:
-pkg.keywords:
-
-pkg.pre_link_cmds.BLE_HOST:
-    scripts/build_libcmac.sh: 100
diff --git a/nimble/transport/da1469x/cmac_driver/scripts/build_libcmac.sh b/nimble/transport/da1469x/cmac_driver/scripts/build_libcmac.sh
deleted file mode 100755
index 659c2b9..0000000
--- a/nimble/transport/da1469x/cmac_driver/scripts/build_libcmac.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/bin/bash
-
-# 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.
-
-if [ ! -f ${MYNEWT_VAL_CMAC_IMAGE_FILE_NAME} ]; then
-    >&2 echo ERROR: BLE stack library not found. Please check nimble/transport/da1469x/README for details.
-    exit 1
-fi
-
-OBJCOPY=${MYNEWT_OBJCOPY_PATH}
-AR=${MYNEWT_AR_PATH}
-LIBBLE_A=$(readlink -e ${MYNEWT_VAL_CMAC_IMAGE_FILE_NAME})
-LIBCMAC_A=${MYNEWT_USER_SRC_DIR}/libcmac.a
-
-BASENAME_ROM=cmac.rom
-BASENAME_RAM=cmac.ram
-
-cd ${MYNEWT_USER_WORK_DIR}
-
-# Extract firmware binary from .a since we do not need to link all other
-# objects with our image.
-${AR} x ${LIBBLE_A} cmac_fw.c.obj
-${OBJCOPY} -O binary --only-section=.cmi_fw_area cmac_fw.c.obj cmac.bin
-
-# We need separate copies for RAM and ROM image since section names are derived
-# from file names. For now files are the same, but it would be possible to
-# link ROM image without data and shared sections which contains zeroes anyway.
-cp cmac.bin ${BASENAME_ROM}.bin
-cp cmac.bin ${BASENAME_RAM}.bin
-
-# Convert both binaries to objects and create archive to link
-${OBJCOPY} -I binary -O elf32-littlearm -B armv8-m.main \
-    --rename-section .data=.libcmac.rom ${BASENAME_ROM}.bin ${BASENAME_ROM}.o
-${OBJCOPY} -I binary -O elf32-littlearm -B armv8-m.main \
-    --rename-section .data=.libcmac.ram ${BASENAME_RAM}.bin ${BASENAME_RAM}.o
-${AR} -rcs ${LIBCMAC_A} ${BASENAME_ROM}.o ${BASENAME_RAM}.o
diff --git a/nimble/transport/da1469x/cmac_driver/src/cmac_host.c b/nimble/transport/da1469x/cmac_driver/src/cmac_host.c
deleted file mode 100644
index 0bfb715..0000000
--- a/nimble/transport/da1469x/cmac_driver/src/cmac_host.c
+++ /dev/null
@@ -1,326 +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 <assert.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-#include "os/os.h"
-#include "mcu/cmsis_nvic.h"
-#include "mcu/da1469x_lpclk.h"
-#include "mcu/da1469x_hal.h"
-#include "mcu/da1469x_pdc.h"
-#include "mcu/mcu.h"
-#include "cmac_driver/cmac_host.h"
-
-#define CMAC_SYM_CONFIG     ((void *)(0x00818f20 + MEMCTRL->CMI_CODE_BASE_REG))
-#define CMAC_SYM_CONFIG_DYN ((void *)(0x00821af8 + MEMCTRL->CMI_CODE_BASE_REG))
-#define CMAC_SYM_MBOX_RX    ((void *)(0x008216b0 + MEMCTRL->CMI_CODE_BASE_REG))
-#define CMAC_SYM_MBOX_TX    ((void *)(0x008218b0 + MEMCTRL->CMI_CODE_BASE_REG))
-
-#define CMAC_MBOX_SIZE              504
-#define CMAC_MBOX_F_RESET           0x0008
-#define CMAC_MBOX_F_WRITEPENDING    0x0010
-
-struct cmac_config {
-    uint8_t  bdaddr[6];             /* Device address */
-
-    uint8_t  rf_calibration_delay;
-
-    uint8_t  lp_clock_freq;         /* Sleep clock frequency (0 = 32768Hz, 1 = 32000Hz) */
-    uint16_t lp_clock_sca;          /* Sleep clock accuracy [ppm] */
-
-    uint16_t rx_buf_len;            /* RX buffer size */
-    uint16_t tx_buf_len;            /* TX buffer size */
-    bool     initial_length_req;
-
-    /* Channel assessment algorithm settings */
-    uint16_t chan_assess_itvl;
-    uint8_t  chan_assess_itvl_mult;
-    int8_t   chan_assess_min_rssi;
-    uint16_t chan_assess_pkt_num;
-    uint16_t chan_assess_bad_pkt_num;
-
-    /* Calibration settings */
-    uint8_t  system_tcs_length;
-    uint8_t  synth_tcs_length;
-    uint8_t  rfcu_tcs_length;
-
-    uint8_t  default_tx_power;      /* Default TX power for connection/advertising */
-    bool     filter_dup_ov_discard; /* Discard unknown devices when filter buffer is full */
-    bool     use_hp_1m;
-    bool     use_hp_2m;
-};
-
-struct cmac_config_dynamic {
-    bool     enable_sleep;          /* Enable sleep */
-
-    /* More options here, don't care now */
-};
-
-struct cmac_mbox {
-    volatile uint16_t magic;
-    volatile uint16_t flags;
-    volatile uint16_t wr_off;
-    volatile uint16_t rd_off;
-    uint8_t data[CMAC_MBOX_SIZE];
-};
-
-/* CMAC data */
-extern char _binary_cmac_rom_bin_start[];
-extern char _binary_cmac_rom_bin_end;
-extern char _binary_cmac_ram_bin_start[];
-extern char _binary_cmac_ram_bin_end;
-
-struct cmac_image_info {
-    uint32_t _dummy1;
-    uint32_t size_rom;
-    uint32_t _dummy2;
-    uint32_t magic;
-    uint32_t _dummy3[5];
-};
-
-/* Mailboxes for SYS<->CMAC communication */
-static struct cmac_mbox *cmac_mbox_rx;
-static struct cmac_mbox *cmac_mbox_tx;
-
-/* PDC entry for waking up CMAC */
-static int8_t g_cmac_host_pdc_sys2cmac;
-/* PDC entry for waking up M33 */
-static int8_t g_cmac_host_pdc_cmac2sys;
-/* Callback for data ready from CMAC */
-static cmac_mbox_read_cb g_cmac_mbox_read_cb;
-
-static inline void
-cmac_host_signal2cmac(void)
-{
-    da1469x_pdc_set(g_cmac_host_pdc_sys2cmac);
-}
-
-static void
-cmac2sys_isr(void)
-{
-    uint16_t wr_off;
-    uint16_t rd_off;
-    uint16_t chunk;
-    uint16_t len;
-
-    os_trace_isr_enter();
-
-    /* Clear CMAC2SYS interrupt */
-    *(volatile uint32_t *)0x40002000 = 2;
-
-    if (*(volatile uint32_t *)0x40002000 & 0x1c00) {
-        /* XXX CMAC is in error state, need to recover */
-        assert(0);
-    }
-
-    if (cmac_mbox_rx->flags & CMAC_MBOX_F_RESET) {
-        cmac_mbox_rx->flags &= ~CMAC_MBOX_F_RESET;
-        goto done;
-    }
-
-    if (!g_cmac_mbox_read_cb) {
-        cmac_mbox_rx->rd_off = cmac_mbox_rx->wr_off;
-        goto done;
-    }
-
-    do {
-        rd_off = cmac_mbox_rx->rd_off;
-        wr_off = cmac_mbox_rx->wr_off;
-
-        if (rd_off <= wr_off) {
-            chunk = wr_off - rd_off;
-        } else {
-            chunk = CMAC_MBOX_SIZE - rd_off;
-        }
-
-        while (chunk) {
-            len = g_cmac_mbox_read_cb(&cmac_mbox_rx->data[rd_off], chunk);
-
-            rd_off += len;
-            chunk -= len;
-        };
-
-        cmac_mbox_rx->rd_off = rd_off % CMAC_MBOX_SIZE;
-    } while (cmac_mbox_rx->rd_off != cmac_mbox_rx->wr_off);
-
-done:
-
-    if (cmac_mbox_rx->flags & CMAC_MBOX_F_WRITEPENDING) {
-        cmac_host_signal2cmac();
-    }
-
-    os_trace_isr_exit();
-}
-
-static void
-cmac_host_lpclk_cb(uint32_t freq)
-{
-    struct cmac_config_dynamic *cmac_config_dyn;
-
-    cmac_config_dyn = CMAC_SYM_CONFIG_DYN;
-    cmac_config_dyn->enable_sleep = freq == 32768;
-}
-
-void
-cmac_mbox_write(const uint8_t *buf, size_t len)
-{
-    uint16_t wr_off;
-    uint16_t rd_off;
-    uint16_t chunk;
-    uint32_t primask;
-
-    __HAL_DISABLE_INTERRUPTS(primask);
-
-    while (len) {
-        rd_off = cmac_mbox_tx->rd_off;
-        wr_off = cmac_mbox_tx->wr_off;
-
-        if (rd_off > wr_off) {
-            chunk = min(len, rd_off - wr_off);
-        } else {
-            chunk = min(len, CMAC_MBOX_SIZE - wr_off);
-        }
-
-        if (chunk == 0) {
-            continue;
-        }
-
-        memcpy(&cmac_mbox_tx->data[wr_off], buf, chunk);
-
-        wr_off += chunk;
-        cmac_mbox_tx->wr_off = wr_off % CMAC_MBOX_SIZE;
-
-        cmac_host_signal2cmac();
-
-        len -= chunk;
-        buf += chunk;
-    }
-
-    __HAL_ENABLE_INTERRUPTS(primask);
-}
-
-void
-cmac_mbox_set_read_cb(cmac_mbox_read_cb cb)
-{
-    g_cmac_mbox_read_cb = cb;
-}
-
-void
-cmac_host_init(void)
-{
-    struct cmac_image_info ii;
-    uint32_t cmac_rom_size;
-    uint32_t cmac_ram_size;
-    struct cmac_config *cmac_config;
-    struct cmac_config_dynamic *cmac_config_dyn;
-
-    /* Add PDC entry to wake up CMAC from M33 */
-    g_cmac_host_pdc_sys2cmac = da1469x_pdc_add(MCU_PDC_TRIGGER_MAC_TIMER,
-                                             MCU_PDC_MASTER_CMAC,
-                                             MCU_PDC_EN_XTAL);
-    da1469x_pdc_set(g_cmac_host_pdc_sys2cmac);
-    da1469x_pdc_ack(g_cmac_host_pdc_sys2cmac);
-
-    /* Add PDC entry to wake up M33 from CMAC, if does not exist yet */
-    g_cmac_host_pdc_cmac2sys = da1469x_pdc_find(MCU_PDC_TRIGGER_COMBO,
-                                              MCU_PDC_MASTER_M33, 0);
-    if (g_cmac_host_pdc_cmac2sys < 0) {
-        g_cmac_host_pdc_cmac2sys = da1469x_pdc_add(MCU_PDC_TRIGGER_COMBO,
-                                                 MCU_PDC_MASTER_M33,
-                                                 MCU_PDC_EN_XTAL);
-        da1469x_pdc_set(g_cmac_host_pdc_cmac2sys);
-        da1469x_pdc_ack(g_cmac_host_pdc_cmac2sys);
-    }
-
-    /* Enable Radio LDO */
-    CRG_TOP->POWER_CTRL_REG |= CRG_TOP_POWER_CTRL_REG_LDO_RADIO_ENABLE_Msk;
-
-    /* Enable CMAC, but keep it in reset */
-    CRG_TOP->CLK_RADIO_REG = (1 << CRG_TOP_CLK_RADIO_REG_RFCU_ENABLE_Pos) |
-                             (1 << CRG_TOP_CLK_RADIO_REG_CMAC_SYNCH_RESET_Pos) |
-                             (0 << CRG_TOP_CLK_RADIO_REG_CMAC_CLK_SEL_Pos) |
-                             (1 << CRG_TOP_CLK_RADIO_REG_CMAC_CLK_ENABLE_Pos) |
-                             (0 << CRG_TOP_CLK_RADIO_REG_CMAC_DIV_Pos);
-
-    /* Calculate size of ROM and RAM area (for now they should be the same) */
-    cmac_rom_size = &_binary_cmac_rom_bin_end - &_binary_cmac_rom_bin_start[0];
-    cmac_ram_size = &_binary_cmac_ram_bin_end - &_binary_cmac_ram_bin_start[0];
-    assert(cmac_rom_size == cmac_ram_size);
-
-    /* Load image header and check if image can be loaded */
-    memcpy(&ii, &_binary_cmac_rom_bin_start, sizeof(ii));
-    assert(ii.magic == 0x43414d43); /* "CMAC" */
-
-    /* Copy CMAC image to RAM */
-    memset(&_binary_cmac_ram_bin_start, 0, cmac_ram_size);
-    memcpy(&_binary_cmac_ram_bin_start, &_binary_cmac_rom_bin_start[sizeof(ii)],
-           ii.size_rom);
-
-    /*
-     * Setup memory controller for CMAC
-     * Code and data are set to the same address initially since CMAC will
-     * update data address on init. Also shared address is updated on init.
-     */
-    MEMCTRL->CMI_CODE_BASE_REG = (uint32_t)&_binary_cmac_ram_bin_start;
-    MEMCTRL->CMI_DATA_BASE_REG = MEMCTRL->CMI_CODE_BASE_REG;
-    MEMCTRL->CMI_SHARED_BASE_REG = 0;
-    MEMCTRL->CMI_END_REG = (uint32_t)&_binary_cmac_ram_bin_end;
-
-    /* Symbols below are in shared memory, can update them now */
-    cmac_config = CMAC_SYM_CONFIG;
-    cmac_config_dyn = CMAC_SYM_CONFIG_DYN;
-    cmac_mbox_rx = CMAC_SYM_MBOX_RX;
-    cmac_mbox_tx = CMAC_SYM_MBOX_TX;
-
-    /* Update CMAC configuration */
-    cmac_config->lp_clock_freq = 0;
-    cmac_config->lp_clock_sca = 50;
-    cmac_config->rx_buf_len = 251 + 11;
-    cmac_config->tx_buf_len = 251 + 11;
-    cmac_config->initial_length_req = 0;
-    cmac_config->system_tcs_length = 0;
-    cmac_config->synth_tcs_length = 0;
-    cmac_config->rfcu_tcs_length = 0;
-    cmac_config->default_tx_power = 4;
-    cmac_config_dyn->enable_sleep = false;
-
-    /* Release CMAC from reset */
-    CRG_TOP->CLK_RADIO_REG &= ~CRG_TOP_CLK_RADIO_REG_CMAC_SYNCH_RESET_Msk;
-
-    /* Wait for CMAC to update registers */
-    while (MEMCTRL->CMI_DATA_BASE_REG == MEMCTRL->CMI_CODE_BASE_REG);
-    while (MEMCTRL->CMI_SHARED_BASE_REG != (MEMCTRL->CMI_END_REG & 0xfffffc00));
-
-    /* Initialize mailboxes and sync with CMAC */
-    cmac_mbox_tx->flags = CMAC_MBOX_F_RESET;
-    cmac_mbox_tx->wr_off = 0;
-    cmac_mbox_tx->rd_off = 0;
-    cmac_mbox_tx->magic = 0xa55a;
-    while (cmac_mbox_rx->magic != 0xa55a);
-
-    NVIC_SetVector(CMAC2SYS_IRQn, (uint32_t)cmac2sys_isr);
-    NVIC_SetPriority(CMAC2SYS_IRQn, 0);
-    NVIC_EnableIRQ(CMAC2SYS_IRQn);
-
-    cmac_host_signal2cmac();
-
-    da1469x_lpclk_register_cmac_cb(cmac_host_lpclk_cb);
-}
diff --git a/nimble/transport/da1469x/cmac_driver/syscfg.yml b/nimble/transport/da1469x/cmac_driver/syscfg.yml
deleted file mode 100644
index be2e62d..0000000
--- a/nimble/transport/da1469x/cmac_driver/syscfg.yml
+++ /dev/null
@@ -1,23 +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.
-#
-
-syscfg.defs:
-    CMAC_IMAGE_FILE_NAME:
-        description: >
-            Path to library with CMAC firmware. See README for details.
-        value: "libble_stack_da1469x.a"
diff --git a/nimble/transport/da1469x/pkg.yml b/nimble/transport/da1469x/pkg.yml
deleted file mode 100644
index 5d9b533..0000000
--- a/nimble/transport/da1469x/pkg.yml
+++ /dev/null
@@ -1,38 +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.
-#
-
-pkg.name: nimble/transport/da1469x
-pkg.description: HCI transport for DA1469x
-pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - ble
-    - bluetooth
-
-pkg.deps:
-    - "@apache-mynewt-nimble/nimble"
-    - "@apache-mynewt-nimble/nimble/transport/da1469x/cmac_driver"
-    - "@apache-mynewt-core/kernel/os"
-
-pkg.apis:
-    - ble_transport
-
-pkg.init:
-    da1469x_ble_hci_init: 100
-    da1469x_ble_hci_cmac_init: 201
diff --git a/nimble/transport/da1469x/src/da1469x_ble_hci.c b/nimble/transport/da1469x/src/da1469x_ble_hci.c
deleted file mode 100644
index 971d0cd..0000000
--- a/nimble/transport/da1469x/src/da1469x_ble_hci.c
+++ /dev/null
@@ -1,368 +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 <assert.h>
-#include <string.h>
-#include "os/mynewt.h"
-#include "nimble/ble.h"
-#include "nimble/ble_hci_trans.h"
-#include "nimble/hci_common.h"
-#include "cmac_driver/cmac_host.h"
-
-#define HCI_PKT_NONE    0x00
-#define HCI_PKT_CMD     0x01
-#define HCI_PKT_ACL     0x02
-#define HCI_PKT_EVT     0x04
-
-#define POOL_ACL_BLOCK_SIZE                                             \
-                        OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) +         \
-                                BLE_MBUF_MEMBLOCK_OVERHEAD +            \
-                                BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
-
-struct da1469x_ble_hci_host_api {
-    ble_hci_trans_rx_cmd_fn *evt_cb;
-    void *evt_arg;
-    ble_hci_trans_rx_acl_fn *acl_cb;
-    void *acl_arg;
-};
-
-struct da1469x_ble_hci_rx_data {
-    uint8_t type;
-    uint8_t hdr[4];
-    uint8_t min_len;
-    uint16_t len;
-    uint16_t expected_len;
-    union {
-        uint8_t *buf;
-        struct os_mbuf *om;
-    };
-};
-
-struct da1469x_ble_hci_pool_cmd {
-    uint8_t cmd[BLE_HCI_TRANS_CMD_SZ];
-    bool allocated;
-};
-
-/* (Pseudo)pool for HCI commands */
-static struct da1469x_ble_hci_pool_cmd da1469x_ble_hci_pool_cmd;
-
-/* Pools for HCI events (high and low priority) */
-static uint8_t da1469x_ble_hci_pool_evt_hi_buf[ OS_MEMPOOL_BYTES(
-                                            MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                                            MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE)) ];
-static struct os_mempool da1469x_ble_hci_pool_evt_hi;
-static uint8_t da1469x_ble_hci_pool_evt_lo_buf[ OS_MEMPOOL_BYTES(
-                                            MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                                            MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE)) ];
-static struct os_mempool da1469x_ble_hci_pool_evt_lo;
-
-/* Pool for ACL data */
-static uint8_t da1469x_ble_hci_pool_acl_buf[ OS_MEMPOOL_BYTES(
-                                            MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                                            POOL_ACL_BLOCK_SIZE) ];
-static struct os_mempool da1469x_ble_hci_pool_acl;
-static struct os_mbuf_pool da1469x_ble_hci_pool_acl_mbuf;
-
-/* Interface to host */
-static struct da1469x_ble_hci_host_api da1469x_ble_hci_host_api;
-
-/* State of RX currently in progress (needs to reassemble frame) */
-static struct da1469x_ble_hci_rx_data da1469x_ble_hci_rx_data;
-
-int
-ble_hci_trans_reset(void)
-{
-    /* XXX Should we do something with RF and/or BLE core? */
-    return 0;
-}
-
-void
-ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb, void *evt_arg,
-                     ble_hci_trans_rx_acl_fn *acl_cb, void *acl_arg)
-{
-    da1469x_ble_hci_host_api.evt_cb = evt_cb;
-    da1469x_ble_hci_host_api.evt_arg = evt_arg;
-    da1469x_ble_hci_host_api.acl_cb = acl_cb;
-    da1469x_ble_hci_host_api.acl_arg = acl_arg;
-}
-
-uint8_t *
-ble_hci_trans_buf_alloc(int type)
-{
-    uint8_t *buf;
-
-    switch (type) {
-    case BLE_HCI_TRANS_BUF_CMD:
-        assert(!da1469x_ble_hci_pool_cmd.allocated);
-        da1469x_ble_hci_pool_cmd.allocated = 1;
-        buf = da1469x_ble_hci_pool_cmd.cmd;
-        break;
-    case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&da1469x_ble_hci_pool_evt_hi);
-        if (buf) {
-            break;
-        }
-        /* no break */
-    case BLE_HCI_TRANS_BUF_EVT_LO:
-        buf = os_memblock_get(&da1469x_ble_hci_pool_evt_lo);
-        break;
-    default:
-        assert(0);
-        buf = NULL;
-    }
-
-    return buf;
-}
-
-void
-ble_hci_trans_buf_free(uint8_t *buf)
-{
-    int rc;
-
-    if (buf == da1469x_ble_hci_pool_cmd.cmd) {
-        assert(da1469x_ble_hci_pool_cmd.allocated);
-        da1469x_ble_hci_pool_cmd.allocated = 0;
-    } else if (os_memblock_from(&da1469x_ble_hci_pool_evt_hi, buf)) {
-        rc = os_memblock_put(&da1469x_ble_hci_pool_evt_hi, buf);
-        assert(rc == 0);
-    } else {
-        assert(os_memblock_from(&da1469x_ble_hci_pool_evt_lo, buf));
-        rc = os_memblock_put(&da1469x_ble_hci_pool_evt_lo, buf);
-        assert(rc == 0);
-    }
-}
-
-int
-ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
-{
-    uint8_t ind = HCI_PKT_CMD;
-    int len = 3 + cmd[2];
-
-    cmac_mbox_write(&ind, 1);
-    cmac_mbox_write(cmd, len);
-
-    ble_hci_trans_buf_free(cmd);
-
-    return 0;
-}
-
-int
-ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
-{
-    uint8_t ind = HCI_PKT_ACL;
-    struct os_mbuf *x;
-
-    cmac_mbox_write(&ind, 1);
-
-    x = om;
-    while (x) {
-        cmac_mbox_write(x->om_data, x->om_len);
-        x = SLIST_NEXT(x, om_next);
-    }
-
-    os_mbuf_free_chain(om);
-
-    return 0;
-}
-
-static int
-da1469x_ble_hci_trans_ll_rx(const uint8_t *buf, uint16_t len)
-{
-    struct da1469x_ble_hci_rx_data *rxd = &da1469x_ble_hci_rx_data;
-    void *data;
-    int pool = BLE_HCI_TRANS_BUF_EVT_HI;
-    int rc;
-
-    assert(len);
-
-    if (rxd->type == HCI_PKT_NONE) {
-        rxd->type = buf[0];
-        rxd->len = 0;
-        rxd->expected_len = 0;
-
-        switch (rxd->type) {
-        case HCI_PKT_ACL:
-            rxd->min_len = 4;
-            break;
-        case HCI_PKT_EVT:
-            rxd->min_len = 2;
-            break;
-        default:
-            assert(0);
-            break;
-        }
-
-        return 1;
-    }
-
-    /* Ensure we have minimum length of bytes required to process header */
-    if (rxd->len < rxd->min_len) {
-        len = min(len, rxd->min_len - rxd->len);
-        memcpy(&rxd->hdr[rxd->len], buf, len);
-        rxd->len += len;
-        return len;
-    }
-
-    /* Parse header and allocate proper buffer if not done yet */
-    if (rxd->expected_len == 0) {
-        switch (rxd->type) {
-        case HCI_PKT_ACL:
-            data = os_mbuf_get_pkthdr(&da1469x_ble_hci_pool_acl_mbuf,
-                                      sizeof(struct ble_mbuf_hdr));
-            if (!data) {
-                return 0;
-            }
-
-            rxd->om = data;
-            os_mbuf_append(rxd->om, rxd->hdr, rxd->len);
-            rxd->expected_len = get_le16(&rxd->hdr[2]) + 4;
-            break;
-        case HCI_PKT_EVT:
-            if (rxd->hdr[0] == BLE_HCI_EVCODE_LE_META) {
-                /* For LE Meta event we need 3 bytes to parse header */
-                if (rxd->min_len < 3) {
-                    rxd->min_len = 3;
-                    return 0;
-                }
-
-                /* Advertising reports shall be allocated from low-prio pool */
-                if ((rxd->hdr[2] == BLE_HCI_LE_SUBEV_ADV_RPT) ||
-                    (rxd->hdr[2] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) {
-                    pool = BLE_HCI_TRANS_BUF_EVT_LO;
-                }
-            }
-
-            data = ble_hci_trans_buf_alloc(pool);
-            if (!data) {
-                /*
-                 * Only care about valid buffer when shall be allocated from
-                 * high-prio pool, otherwise NULL is fine and we'll just skip
-                 * this event.
-                 */
-                if (pool != BLE_HCI_TRANS_BUF_EVT_LO) {
-                    data = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
-                    if (!data) {
-                        return 0;
-                    }
-                }
-            }
-
-            rxd->buf = data;
-            memcpy(rxd->buf, rxd->hdr, rxd->len);
-            rxd->expected_len = rxd->hdr[1] + 2;
-            break;
-        default:
-            assert(0);
-            return len;
-        }
-    }
-
-    len = min(len, rxd->expected_len - rxd->len);
-
-    switch (rxd->type) {
-    case HCI_PKT_ACL:
-        os_mbuf_append(rxd->om, buf, len);
-        rxd->len += len;
-
-        if (rxd->len == rxd->expected_len) {
-            rc = da1469x_ble_hci_host_api.acl_cb(rxd->om,
-                                                 da1469x_ble_hci_host_api.acl_arg);
-            if (rc != 0) {
-                os_mbuf_free_chain(rxd->om);
-            }
-            rxd->type = HCI_PKT_NONE;
-        }
-        break;
-    case HCI_PKT_EVT:
-        if (rxd->buf) {
-            memcpy(&rxd->buf[rxd->len], buf, len);
-        }
-        rxd->len += len;
-
-        if (rxd->len == rxd->expected_len) {
-            /*
-             * XXX for unknown reason at startup controller sends command
-             *     complete for a vendor specific command which we never sent
-             *     and this messes up with our ack code - just discard this
-             *     event
-             */
-            if ((rxd->buf[0] == 0x0E) && (get_le16(&rxd->buf[3]) == 0xfc11)) {
-                ble_hci_trans_buf_free(rxd->buf);
-            } else if (rxd->buf) {
-                rc = da1469x_ble_hci_host_api.evt_cb(rxd->buf,
-                                                     da1469x_ble_hci_host_api.evt_arg);
-                if (rc != 0) {
-                    ble_hci_trans_buf_free(rxd->buf);
-                }
-            }
-            rxd->type = HCI_PKT_NONE;
-        }
-        break;
-    default:
-        assert(0);
-        break;
-    }
-
-    return len;
-}
-
-static int
-da1469x_ble_hci_read_cb(const uint8_t *buf, uint16_t len)
-{
-    return da1469x_ble_hci_trans_ll_rx(buf, len);
-}
-
-void
-da1469x_ble_hci_init(void)
-{
-    int rc;
-
-    SYSINIT_ASSERT_ACTIVE();
-
-    rc = os_mempool_init(&da1469x_ble_hci_pool_acl, MYNEWT_VAL(BLE_ACL_BUF_COUNT),
-                         POOL_ACL_BLOCK_SIZE, da1469x_ble_hci_pool_acl_buf,
-                         "da1469x_ble_hci_pool_acl");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mbuf_pool_init(&da1469x_ble_hci_pool_acl_mbuf,
-                           &da1469x_ble_hci_pool_acl, POOL_ACL_BLOCK_SIZE,
-                           MYNEWT_VAL(BLE_ACL_BUF_COUNT));
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&da1469x_ble_hci_pool_evt_hi,
-                         MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         da1469x_ble_hci_pool_evt_hi_buf,
-                         "da1469x_ble_hci_pool_evt_hi");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
-    rc = os_mempool_init(&da1469x_ble_hci_pool_evt_lo,
-                         MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
-                         MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
-                         da1469x_ble_hci_pool_evt_lo_buf,
-                         "da1469x_ble_hci_pool_evt_lo");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-}
-
-void
-da1469x_ble_hci_cmac_init(void)
-{
-    cmac_mbox_set_read_cb(da1469x_ble_hci_read_cb);
-    cmac_host_init();
-}
diff --git a/nimble/transport/da1469x/syscfg.yml b/nimble/transport/da1469x/syscfg.yml
deleted file mode 100644
index 2ce8cd3..0000000
--- a/nimble/transport/da1469x/syscfg.yml
+++ /dev/null
@@ -1,27 +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.
-#
-
-syscfg.vals.'!BLE_HCI_BRIDGE && !BLE_EXT_ADV':
-    BLE_HCI_EVT_HI_BUF_COUNT: 2
-    BLE_HCI_EVT_LO_BUF_COUNT: 8
-    BLE_HCI_EVT_BUF_SIZE: 70
-    BLE_ACL_BUF_COUNT: 4
-    BLE_ACL_BUF_SIZE: 255
-
-syscfg.vals.'!BLE_HCI_BRIDGE && BLE_EXT_ADV':
-    BLE_HCI_EVT_BUF_SIZE: 274

[mynewt-nimble] 17/22: apps/blehci: Update configuration for new transport

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 1118fe21fe2f79d1116aaeb38d873855054205be
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 3 18:08:26 2022 +0100

    apps/blehci: Update configuration for new transport
    
    Dependency to nimble/controller is not needed since blehci can now run
    on both app (as a bridge to net core) and net core.
    
    For non-netcore build we select UART by default, otherwise keep whatever
    default was set by BSP.
---
 apps/blehci/pkg.yml    | 1 -
 apps/blehci/syscfg.yml | 6 ++++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/apps/blehci/pkg.yml b/apps/blehci/pkg.yml
index 2c63a04..e385d7d 100644
--- a/apps/blehci/pkg.yml
+++ b/apps/blehci/pkg.yml
@@ -27,7 +27,6 @@ pkg.deps:
     - "@apache-mynewt-core/sys/log/stub"
     - "@apache-mynewt-core/sys/stats/full"
     - "@apache-mynewt-core/kernel/os"
-    - nimble/controller
     - nimble/transport
 
 pkg.req_apis:
diff --git a/apps/blehci/syscfg.yml b/apps/blehci/syscfg.yml
index ee80623..ec20e68 100644
--- a/apps/blehci/syscfg.yml
+++ b/apps/blehci/syscfg.yml
@@ -19,7 +19,9 @@
 syscfg.vals:
     # Default task settings
     OS_MAIN_STACK_SIZE: 64
-    # Use UART transport by default
-    BLE_HCI_TRANSPORT: uart
     # Stub console
     CONSOLE_MODE: stub
+
+syscfg.vals.'!BLE_TRANSPORT_NETCORE':
+    # Use UART by default if not built on netcore
+    BLE_TRANSPORT_HS: uart