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:15 UTC

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

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"