Bluetooth: Make Kconfig buffer sizes follow MTU sizes

It's more intuitive to specify needed MTU sizes instead of raw buffer
sizes. The exact buffer size calculations can instead be made
internally in the code (using the BT_L2CAP_BUF_SIZE helper macro).

Change-Id: I0637340a7d99e04020f57f49ecd8e6dcfcc4bcf4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-11-06 12:19:26 +02:00 committed by Anas Nashif
commit 8167ababe0
6 changed files with 26 additions and 28 deletions

View file

@ -94,14 +94,22 @@ config BLUETOOTH_ACL_IN_COUNT
help
Number of buffers available for incoming ACL data.
config BLUETOOTH_ACL_IN_SIZE
int "Size of incoming ACL data buffers"
default 74 if BLUETOOTH_SMP
default 32 if !BLUETOOTH_SMP
range 74 1300 if BLUETOOTH_SMP
range 32 1300 if !BLUETOOTH_SMP
config BLUETOOTH_L2CAP_IN_MTU
int "Maximum supported L2CAP MTU for incoming data"
default 65 if BLUETOOTH_SMP
default 23 if !BLUETOOTH_SMP
range 65 1300 if BLUETOOTH_SMP
range 23 1300 if !BLUETOOTH_SMP
help
Maximum size of each incoming ACL data buffer.
Maximum size of each incoming L2CAP PDU.
config BLUETOOTH_ATT_MTU
int "Attribute Protocol (ATT) channel MTU"
default 23
range 23 BLUETOOTH_L2CAP_IN_MTU
help
The MTU for the ATT channel. The minimum and default is 23,
whereas the maximum is limited by CONFIG_BLUETOOTH_L2CAP_IN_MTU.
endif # BLUETOOTH_CONN
if BLUETOOTH_PERIPHERAL || BLUETOOTH_CENTRAL

View file

@ -83,7 +83,8 @@ static struct bt_att bt_att_pool[CONFIG_BLUETOOTH_MAX_CONN];
/* Pool for outgoing ATT packets, default MTU is 23 */
static struct nano_fifo att_buf;
static NET_BUF_POOL(att_pool, CONFIG_BLUETOOTH_MAX_CONN,
BT_L2CAP_BUF_SIZE(23), &att_buf, NULL, 0);
BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_ATT_MTU),
&att_buf, NULL, 0);
static const struct bt_uuid primary_uuid = {
.type = BT_UUID_16,
@ -156,7 +157,7 @@ static uint8_t att_mtu_req(struct bt_att *att, struct net_buf *buf)
return BT_ATT_ERR_UNLIKELY;
}
mtu_server = BT_ATT_MAX_LE_MTU;
mtu_server = CONFIG_BLUETOOTH_ATT_MTU;
BT_DBG("Server MTU %u\n", mtu_server);
@ -217,7 +218,7 @@ static uint8_t att_mtu_rsp(struct bt_att *att, struct net_buf *buf)
return att_handle_rsp(att, NULL, 0, BT_ATT_ERR_INVALID_PDU);
}
att->chan.rx.mtu = min(mtu, BT_ATT_MAX_LE_MTU);
att->chan.rx.mtu = min(mtu, CONFIG_BLUETOOTH_ATT_MTU);
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484:
*

View file

@ -18,14 +18,6 @@
#define BT_ATT_DEFAULT_LE_MTU 23
/* Size of MTU is based on the maximum amount of data the buffer can hold
* excluding L2CAP, ACL and driver headers.
*/
#define BT_ATT_MAX_LE_MTU (CONFIG_BLUETOOTH_ACL_IN_SIZE - \
sizeof(struct bt_l2cap_hdr) - \
sizeof(struct bt_hci_acl_hdr) - \
CONFIG_BLUETOOTH_HCI_RECV_RESERVE)
struct bt_att_hdr {
uint8_t code;
} __packed;

View file

@ -613,7 +613,7 @@ int bt_gatt_exchange_mtu(struct bt_conn *conn, bt_gatt_rsp_func_t func)
return -ENOMEM;
}
mtu = BT_ATT_MAX_LE_MTU;
mtu = CONFIG_BLUETOOTH_ATT_MTU;
BT_DBG("Client MTU %u\n", mtu);

View file

@ -116,8 +116,9 @@ static void report_completed_packet(struct net_buf *buf)
static struct nano_fifo avail_acl_in;
static NET_BUF_POOL(acl_in_pool, CONFIG_BLUETOOTH_ACL_IN_COUNT,
CONFIG_BLUETOOTH_ACL_IN_SIZE, &avail_acl_in,
report_completed_packet, sizeof(struct acl_data));
BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_L2CAP_IN_MTU),
&avail_acl_in, report_completed_packet,
sizeof(struct acl_data));
#endif /* CONFIG_BLUETOOTH_CONN */
/* Incoming buffer type lookup helper */
@ -736,9 +737,8 @@ static int set_flow_control(void)
hbs = net_buf_add(buf, sizeof(*hbs));
memset(hbs, 0, sizeof(*hbs));
hbs->acl_mtu = sys_cpu_to_le16(CONFIG_BLUETOOTH_ACL_IN_SIZE -
sizeof(struct bt_hci_acl_hdr) -
CONFIG_BLUETOOTH_HCI_RECV_RESERVE);
hbs->acl_mtu = sys_cpu_to_le16(CONFIG_BLUETOOTH_L2CAP_IN_MTU +
sizeof(struct bt_l2cap_hdr));
hbs->acl_pkts = sys_cpu_to_le16(CONFIG_BLUETOOTH_ACL_IN_COUNT);
err = bt_hci_cmd_send_sync(BT_HCI_OP_HOST_BUFFER_SIZE, buf, NULL);

View file

@ -49,10 +49,7 @@
/* Size of MTU is based on the maximum amount of data the buffer can hold
* excluding ACL and driver headers.
*/
#define BT_L2CAP_MAX_LE_MPS (CONFIG_BLUETOOTH_ACL_IN_SIZE - \
sizeof(struct bt_l2cap_hdr) - \
sizeof(struct bt_hci_acl_hdr) - \
CONFIG_BLUETOOTH_HCI_RECV_RESERVE)
#define BT_L2CAP_MAX_LE_MPS CONFIG_BLUETOOTH_L2CAP_IN_MTU
/* For now use MPS - SDU length to disable segmentation */
#define BT_L2CAP_MAX_LE_MTU (BT_L2CAP_MAX_LE_MPS - 2)