diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index 332bdc10703..604d6241476 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -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 diff --git a/net/bluetooth/att.c b/net/bluetooth/att.c index b0535824cc8..43c39fc0413 100644 --- a/net/bluetooth/att.c +++ b/net/bluetooth/att.c @@ -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: * diff --git a/net/bluetooth/att.h b/net/bluetooth/att.h index 2fc69542f32..62547b6d123 100644 --- a/net/bluetooth/att.h +++ b/net/bluetooth/att.h @@ -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; diff --git a/net/bluetooth/gatt.c b/net/bluetooth/gatt.c index 5cb7f6e7674..30417e6b09f 100644 --- a/net/bluetooth/gatt.c +++ b/net/bluetooth/gatt.c @@ -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); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 681be5cb5b4..085873a8024 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -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); diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index 446e869e08f..0fedbf0b2bb 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c @@ -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)