From 3bc43254e0a3b7eabe010b53c64b036623b93d1c Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 6 Nov 2015 12:44:40 +0200 Subject: [PATCH] Bluetooth: Use event/cmd lengths instead of buffer sizes in KConfig It's more intuitive to specify needed command or event lengths rather than the raw buffer size in Kconfig. The exact buffer size calculation can be done in the code itself. Change-Id: I2760cc1182a689b26405e4c2b1428f140b4aa88a Signed-off-by: Johan Hedberg --- net/bluetooth/Kconfig | 23 +++++++++++++---------- net/bluetooth/hci_core.c | 13 +++++++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index 604d6241476..00d72ec7259 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -62,12 +62,12 @@ config BLUETOOTH_HCI_CMD_COUNT help Number of buffers available for HCI commands. -config BLUETOOTH_HCI_CMD_SIZE - int "Size of HCI command buffers" - default 68 - range 68 260 +config BLUETOOTH_MAX_CMD_LEN + int "Maximum supported HCI command length" + default 64 + range 64 255 help - Maximum size of each HCI command buffer. + Maximum length of each HCI command. config BLUETOOTH_HCI_EVT_COUNT int "Number of HCI event buffers" @@ -79,12 +79,15 @@ config BLUETOOTH_HCI_EVT_COUNT sure we've got enough buffers to handle bursts of Number of Completed Packets HCI events. -config BLUETOOTH_HCI_EVT_SIZE - int "Size of HCI event buffers" - default 72 - range 72 260 +config BLUETOOTH_MAX_EVT_LEN + int "Maximum supported HCI event length" + default 68 + range 68 255 help - Maximum size of each HCI event buffer. + Maximum size of each HCI event buffer. E.g. one big event + for LE is the Command Complete for Read Local Supported + Commands. It is a 3 byte Command Complete header + 65 byte + return parameters = 68 bytes in total. if BLUETOOTH_CONN config BLUETOOTH_ACL_IN_COUNT diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 085873a8024..e8f61eee41b 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -75,15 +75,20 @@ struct acl_data { #define acl(buf) ((struct acl_data *)net_buf_user_data(buf)) /* HCI command buffers */ +#define CMD_BUF_SIZE (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \ + sizeof(struct bt_hci_cmd_hdr) + \ + CONFIG_BLUETOOTH_MAX_CMD_LEN) static struct nano_fifo avail_hci_cmd; -static NET_BUF_POOL(hci_cmd_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, - CONFIG_BLUETOOTH_HCI_CMD_SIZE, &avail_hci_cmd, NULL, - sizeof(struct cmd_data)); +static NET_BUF_POOL(hci_cmd_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE, + &avail_hci_cmd, NULL, sizeof(struct cmd_data)); /* HCI event buffers */ +#define EVT_BUF_SIZE (CONFIG_BLUETOOTH_HCI_RECV_RESERVE + \ + sizeof(struct bt_hci_evt_hdr) + \ + CONFIG_BLUETOOTH_MAX_EVT_LEN) static struct nano_fifo avail_hci_evt; static NET_BUF_POOL(hci_evt_pool, CONFIG_BLUETOOTH_HCI_EVT_COUNT, - CONFIG_BLUETOOTH_HCI_EVT_SIZE, &avail_hci_evt, NULL, 0); + CONFIG_BLUETOOTH_MAX_EVT_LEN, &avail_hci_evt, NULL, 0); #if defined(CONFIG_BLUETOOTH_CONN) static void report_completed_packet(struct net_buf *buf)