From 72c94d982caf2f419a28c84b4062b8d7ee0fa983 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 9 May 2023 20:57:32 +1000 Subject: [PATCH] bluetooth: hci: spi: warn about l2cap MTU values `CONFIG_BT_L2CAP_TX_MTU` drives the maximum supported MTU on a Bluetooth connection, but the SPI backend also imposes its own hidden limits. Display a warning if a value is chosen that can result in failures to send. This is done here instead of as a range on `BT_L2CAP_TX_MTU` as ranges on that symbol are already defined in terms of software features, which would conflict with this check. Signed-off-by: Jordan Yates --- drivers/bluetooth/hci/spi.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index ccabab969f2..b86f9ba35fb 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -58,6 +58,17 @@ LOG_MODULE_REGISTER(bt_driver); #define DATA_DELAY_US DT_INST_PROP(0, controller_data_delay_us) +/* Single byte header denoting the buffer type */ +#define H4_HDR_SIZE 1 + +/* Maximum L2CAP MTU that can fit in a single packet */ +#define MAX_MTU (SPI_MAX_MSG_LEN - H4_HDR_SIZE - BT_L2CAP_HDR_SIZE - BT_HCI_ACL_HDR_SIZE) + +#if CONFIG_BT_L2CAP_TX_MTU > MAX_MTU +#warning CONFIG_BT_L2CAP_TX_MTU is too large and can result in packets that cannot \ + be transmitted across this HCI link +#endif /* CONFIG_BT_L2CAP_TX_MTU > MAX_MTU */ + static uint8_t rxmsg[SPI_MAX_MSG_LEN]; static uint8_t txmsg[SPI_MAX_MSG_LEN]; @@ -403,7 +414,7 @@ static int bt_spi_send(struct net_buf *buf) /* Buffer needs an additional byte for type */ if (buf->len >= SPI_MAX_MSG_LEN) { - LOG_ERR("Message too long"); + LOG_ERR("Message too long (%d)", buf->len); return -EINVAL; }