From 1b9d48d58087e8ef431934d59442673e631f066f Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Thu, 10 Mar 2022 15:18:53 +0100 Subject: [PATCH] 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} | 40 +++++++++-- .../transport/include/nimble/transport_impl.h | 47 ++++++++++++ .../transport/nrf5340/src/nrf5340_ble_hci.c | 8 +-- nimble/transport/pkg.yml | 6 ++ nimble/transport/socket/src/ble_hci_socket.c | 4 +- .../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, 230 insertions(+), 143 deletions(-) rename nimble/{host/include/host/ble_monitor.h => transport/include/nimble/transport/monitor.h} (60%) create mode 100644 nimble/transport/include/nimble/transport_impl.h 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/syscfg.monitor.yml diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c index 73168b43c..84b8a4e1c 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 b28979269..c069283cf 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 ba601b613..13b6fe29e 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 215761024..0624e387d 100644 --- a/nimble/host/src/ble_hs_hci.c +++ b/nimble/host/src/ble_hs_hci.c @@ -22,9 +22,7 @@ #include #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 33e1ae8bd..689cb1765 100644 --- a/nimble/host/src/ble_hs_hci_cmd.c +++ b/nimble/host/src/ble_hs_hci_cmd.c @@ -23,20 +23,13 @@ #include #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 3dba0bf65..62de50e0b 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 a57ec3cc8..044b30cc9 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 3033e05dd..526385278 100644 --- a/nimble/host/src/ble_l2cap_sig.c +++ b/nimble/host/src/ble_l2cap_sig.c @@ -45,7 +45,6 @@ #include #include #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 5f67c446d..ce2acc48d 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 254e0db0c..e0702a03b 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 e49d3d48a..d07820f7b 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 7149d8710..9e0eb6695 100644 --- a/nimble/transport/include/nimble/transport.h +++ b/nimble/transport/include/nimble/transport.h @@ -24,18 +24,11 @@ extern "C" { #endif +#include +#include + 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); @@ -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 61722f7db..6b56f123b 100644 --- a/nimble/host/include/host/ble_monitor.h +++ b/nimble/transport/include/nimble/transport/monitor.h @@ -22,16 +22,46 @@ #include -#undef BLE_MONITOR -#define BLE_MONITOR (MYNEWT_VAL(BLE_MONITOR_UART) || MYNEWT_VAL(BLE_MONITOR_RTT)) - #ifdef __cplusplus extern "C" { #endif -int ble_monitor_log(int level, const char *fmt, ...); +#define BLE_MONITOR (MYNEWT_VAL(BLE_MONITOR_RTT) || \ + MYNEWT_VAL(BLE_MONITOR_UART)) -int ble_monitor_out(int c); +#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); +} + +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_impl.h b/nimble/transport/include/nimble/transport_impl.h new file mode 100644 index 000000000..61d8cd68a --- /dev/null +++ b/nimble/transport/include/nimble/transport_impl.h @@ -0,0 +1,47 @@ +/* + * 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_IMPL_ +#define H_NIMBLE_TRANSPORT_IMPL_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* 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_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 */ +extern int ble_transport_int_flow_ctl_get(void); +extern void ble_transport_int_flow_ctl_put(void); +#endif + +#ifdef __cplusplus +} +#endif + +#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 eee27c9b6..111c04803 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 bedcb160e..12b9f40ac 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 ee974ec3f..5dd1d17df 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 b86e7771f..88309149b 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 -#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 +#include +#include +#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 935787040..0fb96509d 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 000000000..7cfbc416f --- /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 5f61a0193..4985250fd 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 9ffcc90f1..f44b9904c 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 6518cd948..01c60b88d 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); }