Bluetooth: Add option to log btsnoops over RTT

There is a choice to log btmon logs over UART or RTT.
You can choose number of RTT buffer, set its name and size.

Replaced CONFIG_BT_DEBUG_MONITOR with CONFIG_BT_DEBUG_MONITOR_UART
for UART usage and CONFIG_BT_DEBUG_MONITOR_RTT for RTT.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
This commit is contained in:
Magdalena Kasenberg 2021-04-17 13:33:20 +02:00 committed by Carles Cufí
commit d0e0af74da
23 changed files with 95 additions and 30 deletions

View file

@ -57,10 +57,10 @@ application:
.. code-block:: console
CONFIG_BT_DEBUG_MONITOR=y
CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_UART_CONSOLE=n
Setting :option:`CONFIG_BT_DEBUG_MONITOR` to ``y`` replaces the
Setting :option:`CONFIG_BT_DEBUG_MONITOR_UART` to ``y`` replaces the
:option:`CONFIG_BT_DEBUG_LOG` option, and setting :option:`CONFIG_UART_CONSOLE`
to ``n`` disables the default ``printk``/``printf`` hooks.

View file

@ -49,7 +49,7 @@ CONFIG_BT_MESH_MODEL_GROUP_COUNT=1
CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y

View file

@ -32,7 +32,7 @@ CONFIG_BT_MESH_MODEL_GROUP_COUNT=1
CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_SELF_TEST=y

View file

@ -64,7 +64,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_UART_CONSOLE=y
# this outputs btmon formatted data to the serial port
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_LOG=y

View file

@ -60,7 +60,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
#CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
##CONFIG_BT_MESH_DEBUG=y

View file

@ -18,7 +18,7 @@ config UART_PIPE_ON_DEV_NAME
depends on UART_PIPE
config BT_MONITOR_ON_DEV_NAME
default "UART_1" if BT_DEBUG_MONITOR
default "UART_1" if BT_DEBUG_MONITOR_UART
endif

View file

@ -84,6 +84,9 @@ config BT_DEBUG
# Hidden option to make the conditions more intuitive
bool
config BT_MONITOR
bool
choice
prompt "Bluetooth debug type"
default BT_DEBUG_NONE
@ -101,11 +104,12 @@ config BT_DEBUG_LOG
This option enables Bluetooth debug going to standard
serial console.
config BT_DEBUG_MONITOR
config BT_DEBUG_MONITOR_UART
bool "Monitor protocol over UART"
select BT_DEBUG
select LOG
select CONSOLE_HAS_DRIVER
select BT_MONITOR
help
Use a custom logging protocol over the console UART
instead of plain-text output. Requires a special application
@ -118,7 +122,45 @@ config BT_DEBUG_MONITOR
UART_CONSOLE needs to be disabled (in which case printk/printf
will get encoded into the monitor protocol).
endchoice
config BT_DEBUG_MONITOR_RTT
bool "Monitor protocol over RTT"
depends on USE_SEGGER_RTT
depends on SEGGER_RTT_MAX_NUM_UP_BUFFERS >= 2
select BT_DEBUG
select BT_MONITOR
help
Use a custom logging protocol over the RTT buffer instead of
plain-text output. Requires a special application
on the host side that can decode this protocol. Currently
the 'btmon' tool from BlueZ is capable of doing this.
if BT_DEBUG_MONITOR_RTT
config BT_DEBUG_MONITOR_RTT_BUFFER
int "Buffer number used for custom logger output."
range 1 SEGGER_RTT_MAX_NUM_UP_BUFFERS
default 1
help
Select index of up-buffer used for logger output.
Make sure the buffer number is not used by other logger,
e.g. in LOG_BACKEND_RTT_BUFFER, otherwise the buffer will be
overwritten.
config BT_DEBUG_MONITOR_RTT_BUFFER_NAME
string "Buffer name used for custom logger output."
default "btmonitor"
help
Select index of up-buffer used for logger output.
config BT_DEBUG_MONITOR_RTT_BUFFER_SIZE
int "Size of reserved up-buffer for custom logger output."
default 1024
help
Specify reserved size of up-buffer used for custom logger output.
endif # BT_DEBUG_MONITOR_RTT
endchoice # Bluetooth debug type
if BT_DEBUG
@ -127,7 +169,7 @@ DT_CHOSEN_Z_BT_MON_UART := zephyr,bt-mon-uart
config BT_MONITOR_ON_DEV_NAME
string "Device Name of Bluetooth monitor logging UART"
depends on BT_DEBUG_MONITOR
depends on BT_DEBUG_MONITOR_UART
default "$(dt_chosen_label,$(DT_CHOSEN_Z_BT_MON_UART))" if HAS_DTS
default "UART_0"
help

View file

@ -4,7 +4,7 @@ zephyr_library()
zephyr_library_link_libraries(subsys__bluetooth)
zephyr_library_sources_ifdef(CONFIG_BT_HCI_RAW hci_raw.c hci_common.c)
zephyr_library_sources_ifdef(CONFIG_BT_DEBUG_MONITOR monitor.c)
zephyr_library_sources_ifdef(CONFIG_BT_MONITOR monitor.c)
zephyr_library_sources_ifdef(CONFIG_BT_TINYCRYPT_ECC hci_ecc.c)
zephyr_library_sources_ifdef(CONFIG_BT_A2DP a2dp.c)
zephyr_library_sources_ifdef(CONFIG_BT_AVDTP avdtp.c)

View file

@ -27,6 +27,16 @@
#include "monitor.h"
#ifdef CONFIG_BT_DEBUG_MONITOR_RTT
#include <SEGGER_RTT.h>
#define RTT_BUFFER_NAME CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_NAME
#define RTT_BUF_SIZE CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_SIZE
static uint8_t rtt_buf[RTT_BUF_SIZE];
#elif CONFIG_BT_DEBUG_MONITOR_UART
static const struct device *monitor_dev;
#endif
/* This is the same default priority as for other console handlers,
* except that we're not exporting it as a Kconfig variable until a
* clear need arises.
@ -45,8 +55,6 @@
/* Maximum (string) length of a log message */
#define MONITOR_MSG_MAX 128
static const struct device *monitor_dev;
enum {
BT_LOG_BUSY,
BT_CONSOLE_BUSY,
@ -68,11 +76,15 @@ static struct {
static void monitor_send(const void *data, size_t len)
{
#ifdef CONFIG_BT_DEBUG_MONITOR_RTT
SEGGER_RTT_Write(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER, data, len);
#elif CONFIG_BT_DEBUG_MONITOR_UART
const uint8_t *buf = data;
while (len--) {
uart_poll_out(monitor_dev, *buf++);
}
#endif
}
static void encode_drops(struct bt_monitor_hdr *hdr, uint8_t type,
@ -179,6 +191,18 @@ void bt_monitor_new_index(uint8_t type, uint8_t bus, bt_addr_t *addr,
bt_monitor_send(BT_MONITOR_NEW_INDEX, &pkt, sizeof(pkt));
}
#ifdef CONFIG_BT_DEBUG_MONITOR_RTT
static int bt_monitor_init(const struct device *d)
{
ARG_UNUSED(d);
SEGGER_RTT_ConfigUpBuffer(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER,
RTT_BUFFER_NAME, rtt_buf, RTT_BUF_SIZE,
SEGGER_RTT_MODE_NO_BLOCK_SKIP);
return 0;
}
#elif CONFIG_BT_DEBUG_MONITOR_UART
#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_LOG_PRINTK)
static int monitor_console_out(int c)
{
@ -339,5 +363,6 @@ static int bt_monitor_init(const struct device *d)
return 0;
}
#endif /* CONFIG_BT_DEBUG_MONITOR_UART */
SYS_INIT(bt_monitor_init, PRE_KERNEL_1, MONITOR_INIT_PRIORITY);

View file

@ -8,7 +8,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#if defined(CONFIG_BT_DEBUG_MONITOR)
#if defined(CONFIG_BT_MONITOR)
#define BT_MONITOR_NEW_INDEX 0
#define BT_MONITOR_DEL_INDEX 1
@ -100,7 +100,7 @@ void bt_monitor_send(uint16_t opcode, const void *data, size_t len);
void bt_monitor_new_index(uint8_t type, uint8_t bus, bt_addr_t *addr,
const char *name);
#else /* !CONFIG_BT_DEBUG_MONITOR */
#else /* !CONFIG_BT_MONITOR */
#define bt_monitor_send(opcode, data, len)
#define bt_monitor_new_index(type, bus, addr, name)

View file

@ -8,7 +8,7 @@ CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_USE_DEBUG_KEYS=y
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_DEBUG_MONITOR=y
CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_UART_CONSOLE=n
CONFIG_BT_DEBUG_HCI_CORE=y
CONFIG_BT_DEBUG_CONN=y
@ -27,4 +27,3 @@ CONFIG_BT_A2DP=y
CONFIG_BT_HFP_HF=y
CONFIG_BT_DEBUG_HFP_HF=y
CONFIG_ZTEST=y

View file

@ -8,7 +8,7 @@ CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_USE_DEBUG_KEYS=y
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_DEBUG_MONITOR=y
CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_HCI_CORE=y
CONFIG_BT_DEBUG_CONN=y
CONFIG_BT_DEBUG_KEYS=y
@ -20,4 +20,3 @@ CONFIG_BT_DEBUG_ATT=y
CONFIG_BT_DEBUG_GATT=y
CONFIG_BT_BREDR=y
CONFIG_ZTEST=y

View file

@ -46,7 +46,7 @@ CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_USE_DEBUG_KEYS=y
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_DEBUG_MONITOR=y
CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_HCI_CORE=y
CONFIG_BT_DEBUG_CONN=y
CONFIG_BT_DEBUG_KEYS=y

View file

@ -43,7 +43,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y

View file

@ -44,7 +44,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y

View file

@ -38,7 +38,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
#CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y

View file

@ -43,7 +43,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
#CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y

View file

@ -43,7 +43,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y

View file

@ -45,7 +45,7 @@ CONFIG_BT_MESH_MODEL_GROUP_COUNT=1
CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y

View file

@ -24,7 +24,7 @@ CONFIG_BT_MESH_MODEL_GROUP_COUNT=2
CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y

View file

@ -43,7 +43,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
#CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y

View file

@ -45,7 +45,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y

View file

@ -43,7 +43,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_UART_CONSOLE=n
#CONFIG_BT_DEBUG_MONITOR=y
#CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y