From e0c8081a4c23c44e1433ee7f5660d2b508139e82 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 8 Jan 2021 11:27:54 +0100 Subject: [PATCH 1/3] Bluetooth: hci_raw: Move BT_ISO to common Kconfig and fix ISO buffers This commit moves the BT_ISO to a common (host and controller) Kconfig and fixes the ISO buffers in hci_raw.c Signed-off-by: Emil Gydesen --- subsys/bluetooth/Kconfig | 58 ++++++++++++++++++++ subsys/bluetooth/host/Kconfig | 6 ++ subsys/bluetooth/host/audio/Kconfig | 64 ---------------------- subsys/bluetooth/host/audio/iso.c | 18 +++--- subsys/bluetooth/host/audio/iso_internal.h | 8 +-- subsys/bluetooth/host/hci_core.c | 2 +- subsys/bluetooth/host/hci_raw.c | 15 ++--- 7 files changed, 86 insertions(+), 85 deletions(-) diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 6f41d6f44f2b1..4cac060761209 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -222,6 +222,64 @@ config BT_DATA_LEN_UPDATE Enable support for Bluetooth v4.2 LE Data Length Update procedure. endif # BT_CONN + +config BT_ISO + bool "Bluetooth Isochronous Channel Support [EXPERIMENTAL]" + help + Select this to enable Isochronous Channel support. + +if BT_ISO + +config BT_ISO_MAX_CHAN + int "Maximum number of simultaneous ISO channels" + depends on BT_ISO + default BT_MAX_CONN + range 1 64 + help + Maximum number of simultaneous Bluetooth isochronous channels + supported. + +config BT_ISO_TX_BUF_COUNT + int "Number of Isochronous TX buffers" + default 1 + range 1 255 + help + Number of buffers available for outgoing Isochronous channel SDUs. + +config BT_ISO_TX_FRAG_COUNT + int "Number of ISO TX fragment buffers" + default 2 + range 0 255 + help + Number of buffers available for fragments of TX buffers. Warning: + setting this to 0 means that the application must ensure that + queued TX buffers never need to be fragmented, i.e. that the + controller's buffer size is large enough. If this is not ensured, + and there are no dedicated fragment buffers, a deadlock may occur. + In most cases the default value of 2 is a safe bet. + +config BT_ISO_TX_MTU + int "Maximum supported MTU for Isochronous TX buffers" + default 251 + range 23 4095 + help + Maximum MTU for Isochronous channels TX buffers. + +config BT_ISO_RX_BUF_COUNT + int "Number of Isochronous RX buffers" + default 1 + range 1 255 + help + Number of buffers available for incoming Isochronous channel SDUs. + +config BT_ISO_RX_MTU + int "Maximum supported MTU for Isochronous RX buffers" + default 251 + range 23 4095 + help + Maximum MTU for Isochronous channels RX buffers. +endif # BT_ISO + # Workaround for not being able to have commas in macro arguments DT_CHOSEN_Z_BT_C2H_UART := zephyr,bt-c2h-uart diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index cc072b295a6ed..cd400d4c01f83 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -668,6 +668,12 @@ config BT_DEBUG_CONN This option enables debug support for Bluetooth connection handling. +config BT_DEBUG_ISO + bool "ISO channel debug" + help + Use this option to enable ISO channels debug logs for the + Bluetooth Audio functionality. + config BT_DEBUG_KEYS bool "Bluetooth security keys debug" depends on BT_HCI_HOST diff --git a/subsys/bluetooth/host/audio/Kconfig b/subsys/bluetooth/host/audio/Kconfig index a1f710def6ae6..277bf5f2af6e5 100644 --- a/subsys/bluetooth/host/audio/Kconfig +++ b/subsys/bluetooth/host/audio/Kconfig @@ -17,9 +17,6 @@ menuconfig BT_AUDIO if BT_AUDIO -config BT_ISO - bool - if BT_CONN config BT_AUDIO_UNICAST @@ -35,58 +32,6 @@ config BT_AUDIO_UNICAST This option enables support for Bluetooth Unicast Audio using Isochronous channels. -if BT_AUDIO_UNICAST - -config BT_MAX_ISO_CONN - int "Maximum number of simultaneous ISO connections" - depends on BT_ISO - default BT_MAX_CONN - range 1 64 - help - Maximum number of simultaneous Bluetooth isochronous connections - supported. - -config BT_ISO_TX_BUF_COUNT - int "Numer of Isochronous TX buffers" - default 1 - range 1 255 - help - Number of buffers available for outgoing Isochronous channel packets. - -config BT_ISO_TX_FRAG_COUNT - int "Number of ISO TX fragment buffers" - default 2 - range 0 255 - help - Number of buffers available for fragments of TX buffers. Warning: - setting this to 0 means that the application must ensure that - queued TX buffers never need to be fragmented, i.e. that the - controller's buffer size is large enough. If this is not ensured, - and there are no dedicated fragment buffers, a deadlock may occur. - In most cases the default value of 2 is a safe bet. - -config BT_ISO_TX_MTU - int "Maximum supported MTU for Isochronous TX buffers" - default 251 - range 23 2000 - help - Maximum MTU for Isochronous channels TX buffers. - -config BT_ISO_RX_BUF_COUNT - int "Numer of Isochronous RX buffers" - default 1 - range 1 255 - help - Number of buffers available for incoming Isochronous channel packets. - -config BT_ISO_RX_MTU - int "Maximum supported MTU for Isochronous RX buffers" - default 251 - range 23 2000 - help - Maximum MTU for Isochronous channels RX buffers. - -endif # BT_AUDIO_UNICAST endif # BT_CONN config BT_AUDIO_DEBUG @@ -96,13 +41,4 @@ config BT_AUDIO_DEBUG Use this option to enable debug logs for the Bluetooth Audio functionality. -if BT_AUDIO_DEBUG - -config BT_AUDIO_DEBUG_ISO - bool "ISO channel debug" - help - Use this option to enable ISO channels debug logs for the - Bluetooth Audio functionality. - -endif # BT_AUDIO_DEBUG endif # BT_AUDIO diff --git a/subsys/bluetooth/host/audio/iso.c b/subsys/bluetooth/host/audio/iso.c index 71dd52a757a71..31a3aeb754348 100644 --- a/subsys/bluetooth/host/audio/iso.c +++ b/subsys/bluetooth/host/audio/iso.c @@ -18,7 +18,7 @@ #include "host/conn_internal.h" #include "iso_internal.h" -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_ISO) +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_ISO) #define LOG_MODULE_NAME bt_iso #include "common/log.h" @@ -34,7 +34,7 @@ NET_BUF_POOL_FIXED_DEFINE(iso_frag_pool, CONFIG_BT_ISO_TX_FRAG_COUNT, /* TODO: Allow more than one server? */ static struct bt_iso_server *iso_server; -struct bt_conn iso_conns[CONFIG_BT_MAX_ISO_CONN]; +struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; struct bt_iso_data_path { @@ -257,7 +257,7 @@ void bt_iso_cleanup(struct bt_conn *conn) conn->iso.acl = NULL; /* Check if conn is last of CIG */ - for (i = 0; i < CONFIG_BT_MAX_ISO_CONN; i++) { + for (i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { if (conn == &iso_conns[i]) { continue; } @@ -268,7 +268,7 @@ void bt_iso_cleanup(struct bt_conn *conn) } } - if (i == CONFIG_BT_MAX_ISO_CONN) { + if (i == CONFIG_BT_ISO_MAX_CHAN) { hci_le_remove_cig(conn->iso.cig_id); } @@ -417,7 +417,7 @@ int bt_conn_bind_iso(struct bt_iso_create_param *param) return -ENOTSUP; } - if (!param->num_conns || param->num_conns > CONFIG_BT_MAX_ISO_CONN) { + if (!param->num_conns || param->num_conns > CONFIG_BT_ISO_MAX_CHAN) { return -EINVAL; } @@ -520,7 +520,7 @@ int bt_conn_connect_iso(struct bt_conn **conns, uint8_t num_conns) return -ENOTSUP; } - if (num_conns > CONFIG_BT_MAX_ISO_CONN) { + if (num_conns > CONFIG_BT_ISO_MAX_CHAN) { return -EINVAL; } @@ -783,7 +783,7 @@ int bt_iso_server_register(struct bt_iso_server *server) return 0; } -#if defined(CONFIG_BT_AUDIO_DEBUG_ISO) +#if defined(CONFIG_BT_DEBUG_ISO) const char *bt_iso_chan_state_str(uint8_t state) { switch (state) { @@ -847,7 +847,7 @@ void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state) { chan->state = state; } -#endif /* CONFIG_BT_AUDIO_DEBUG_ISO */ +#endif /* CONFIG_BT_DEBUG_ISO */ void bt_iso_chan_remove(struct bt_conn *conn, struct bt_iso_chan *chan) { @@ -898,7 +898,7 @@ int bt_iso_chan_bind(struct bt_conn **conns, uint8_t num_conns, int bt_iso_chan_connect(struct bt_iso_chan **chans, uint8_t num_chans) { - struct bt_conn *conns[CONFIG_BT_MAX_ISO_CONN]; + struct bt_conn *conns[CONFIG_BT_ISO_MAX_CHAN]; int i, err; __ASSERT_NO_MSG(chans); diff --git a/subsys/bluetooth/host/audio/iso_internal.h b/subsys/bluetooth/host/audio/iso_internal.h index 4c1d22ec3f75f..f98be6c0fc0c5 100644 --- a/subsys/bluetooth/host/audio/iso_internal.h +++ b/subsys/bluetooth/host/audio/iso_internal.h @@ -28,8 +28,8 @@ struct iso_data { #define iso(buf) ((struct iso_data *)net_buf_user_data(buf)) -#if defined(CONFIG_BT_MAX_ISO_CONN) -extern struct bt_conn iso_conns[CONFIG_BT_MAX_ISO_CONN]; +#if defined(CONFIG_BT_ISO_MAX_CHAN) +extern struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; #endif /* Process ISO buffer */ @@ -97,14 +97,14 @@ struct net_buf *bt_iso_create_frag_timeout(size_t reserve, k_timeout_t timeout); bt_iso_create_frag_timeout(_reserve, K_FOREVER) #endif -#if defined(CONFIG_BT_AUDIO_DEBUG_ISO) +#if defined(CONFIG_BT_DEBUG_ISO) void bt_iso_chan_set_state_debug(struct bt_iso_chan *chan, uint8_t state, const char *func, int line); #define bt_iso_chan_set_state(_chan, _state) \ bt_iso_chan_set_state_debug(_chan, _state, __func__, __LINE__) #else void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state); -#endif /* CONFIG_BT_AUDIO_DEBUG_ISO */ +#endif /* CONFIG_BT_DEBUG_ISO */ /* Process incoming data for a connection */ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 8a44507fc28bd..7c9ea433c7ad7 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -5206,7 +5206,7 @@ static void process_events(struct k_poll_event *ev, int count) #if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_ISO) /* command FIFO + conn_change signal + MAX_CONN + MAX_ISO_CONN */ -#define EV_COUNT (2 + CONFIG_BT_MAX_CONN + CONFIG_BT_MAX_ISO_CONN) +#define EV_COUNT (2 + CONFIG_BT_MAX_CONN + CONFIG_BT_ISO_MAX_CHAN) #else /* command FIFO + conn_change signal + MAX_CONN */ #define EV_COUNT (2 + CONFIG_BT_MAX_CONN) diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index c8b433e7dcf43..0be6db2638c5c 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -43,9 +43,9 @@ NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT, NET_BUF_POOL_FIXED_DEFINE(hci_acl_pool, BT_HCI_ACL_COUNT, BT_BUF_ACL_SIZE, NULL); #if defined(CONFIG_BT_ISO) -NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, BT_ISO_TX_BUF_COUNT, - BT_ISO_TX_MTU, NULL); -#endif +NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, CONFIG_BT_ISO_TX_BUF_COUNT, + CONFIG_BT_ISO_TX_MTU, NULL); +#endif /* CONFIG_BT_ISO */ struct bt_dev_raw bt_dev; struct bt_hci_raw_cmd_ext *cmd_ext; @@ -78,9 +78,10 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) switch (type) { case BT_BUF_EVT: case BT_BUF_ACL_IN: + case BT_BUF_ISO_IN: break; default: - BT_ERR("Invalid type: %u", type); + BT_ERR("Invalid rx type: %u", type); return NULL; } @@ -112,7 +113,7 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, case BT_BUF_ISO_OUT: pool = &hci_iso_pool; break; -#endif +#endif /* CONFIG_BT_ISO */ case BT_BUF_H4: if (IS_ENABLED(CONFIG_BT_HCI_RAW_H4) && raw_mode == BT_HCI_RAW_MODE_H4) { @@ -130,7 +131,7 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, type = BT_BUF_ISO_OUT; pool = &hci_iso_pool; break; -#endif +#endif /* CONFIG_BT_ISO */ default: LOG_ERR("Unknown H4 type %u", type); return NULL; @@ -143,7 +144,7 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, } __fallthrough; default: - BT_ERR("Invalid type: %u", type); + BT_ERR("Invalid tx type: %u", type); return NULL; } From a1f718f99617074ed48caa978d6750a63730f376 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 20 Jan 2021 14:11:01 +0100 Subject: [PATCH 2/3] Bluetooth: Seperate BT_ISO and BT_AUDIO ISO is a building block for BT_AUDIO but it is not only useful for AUDIO, and as such should be possible to enable without enabling BT_AUDIO. This commit moves iso.c and iso_internal.h to the host directory (from host/audio) and removes the CMakeLists.txt. The /audio directory is left intact for the Kconfig options it provides, and as a directory for future BLE Audio content. Signed-off-by: Emil Gydesen --- subsys/bluetooth/Kconfig | 1 + subsys/bluetooth/host/CMakeLists.txt | 7 +++++-- subsys/bluetooth/host/audio/CMakeLists.txt | 6 ------ subsys/bluetooth/host/buf.c | 2 +- subsys/bluetooth/host/conn.c | 2 +- subsys/bluetooth/host/conn_internal.h | 2 +- subsys/bluetooth/host/hci_core.c | 2 +- subsys/bluetooth/host/{audio => }/iso.c | 0 subsys/bluetooth/host/{audio => }/iso_internal.h | 0 9 files changed, 10 insertions(+), 12 deletions(-) delete mode 100644 subsys/bluetooth/host/audio/CMakeLists.txt rename subsys/bluetooth/host/{audio => }/iso.c (100%) rename subsys/bluetooth/host/{audio => }/iso_internal.h (100%) diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 4cac060761209..5dd15141a592b 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -225,6 +225,7 @@ endif # BT_CONN config BT_ISO bool "Bluetooth Isochronous Channel Support [EXPERIMENTAL]" + depends on BT_CONN help Select this to enable Isochronous Channel support. diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index 408431f9420ca..21bc9dd568026 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -60,6 +60,11 @@ if(CONFIG_BT_HCI_HOST) endif() endif() + zephyr_library_sources_ifdef( + CONFIG_BT_ISO + iso.c + ) + if(CONFIG_BT_DF) zephyr_library_sources( direction.c @@ -101,5 +106,3 @@ if(CONFIG_BT_CONN_DISABLE_SECURITY) Do not use in production." ) endif() - -add_subdirectory_ifdef(CONFIG_BT_AUDIO audio) diff --git a/subsys/bluetooth/host/audio/CMakeLists.txt b/subsys/bluetooth/host/audio/CMakeLists.txt deleted file mode 100644 index 24a92c4451911..0000000000000 --- a/subsys/bluetooth/host/audio/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -zephyr_library() -zephyr_library_link_libraries(subsys__bluetooth) - -zephyr_library_sources_ifdef(CONFIG_BT_ISO iso.c) diff --git a/subsys/bluetooth/host/buf.c b/subsys/bluetooth/host/buf.c index a1e7addf96ebd..513e0cda65bf2 100644 --- a/subsys/bluetooth/host/buf.c +++ b/subsys/bluetooth/host/buf.c @@ -10,7 +10,7 @@ #include "hci_core.h" #include "conn_internal.h" -#include "audio/iso_internal.h" +#include "iso_internal.h" #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE) #define LOG_MODULE_NAME bt_buf diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index c03851b060456..12ce2e2ef7dea 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -35,7 +35,7 @@ #include "ssp.h" #include "att_internal.h" #include "gatt_internal.h" -#include "audio/iso_internal.h" +#include "iso_internal.h" /* Peripheral timeout to initialize Connection Parameter Update procedure */ #define CONN_UPDATE_TIMEOUT K_MSEC(CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT) diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index d9e1b4f5f7d41..c73e9ebbb0095 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -182,7 +182,7 @@ struct bt_conn { struct bt_conn_br br; struct bt_conn_sco sco; #endif -#if defined(CONFIG_BT_AUDIO) +#if defined(CONFIG_BT_ISO) struct bt_conn_iso iso; #endif }; diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 7c9ea433c7ad7..acbfa85475e7f 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -40,7 +40,7 @@ #include "ecc.h" #include "conn_internal.h" -#include "audio/iso_internal.h" +#include "iso_internal.h" #include "l2cap_internal.h" #include "gatt_internal.h" #include "smp.h" diff --git a/subsys/bluetooth/host/audio/iso.c b/subsys/bluetooth/host/iso.c similarity index 100% rename from subsys/bluetooth/host/audio/iso.c rename to subsys/bluetooth/host/iso.c diff --git a/subsys/bluetooth/host/audio/iso_internal.h b/subsys/bluetooth/host/iso_internal.h similarity index 100% rename from subsys/bluetooth/host/audio/iso_internal.h rename to subsys/bluetooth/host/iso_internal.h From 28b3421bbd6ed3320ce7cced936c7e4385c84b5a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 28 Jan 2021 13:18:24 +0100 Subject: [PATCH 3/3] Bluetooth: Audio: Fixed bad L2CAP Kconfig for ISO fragmentation A line of code was guarded by CONFIG_BT_L2CAP_TX_FRAG_COUNT instead of CONFIG_BT_ISO_TX_FRAG_COUNT. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/iso.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 31a3aeb754348..ff61a2e63e5af 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -330,9 +330,9 @@ struct net_buf *bt_iso_create_frag_timeout(size_t reserve, k_timeout_t timeout) { struct net_buf_pool *pool = NULL; -#if CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0 +#if CONFIG_BT_ISO_TX_FRAG_COUNT > 0 pool = &iso_frag_pool; -#endif +#endif /* CONFIG_BT_ISO_TX_FRAG_COUNT > 0 */ #if defined(CONFIG_NET_BUF_LOG) return bt_conn_create_pdu_timeout_debug(pool, reserve, timeout, func,