Bluetooth: Add BT_ATT_MAX_LE_MTU define

This patch cleans up the code a bit. BT_ATT_MAX_LE_MTU defines
MTU that can be used over LE ATT.

Change-Id: Ie433f33f3bcba3275f51e1bea826bb0fd061c45f
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
Mariusz Skamra 2015-10-15 11:53:46 +02:00 committed by Anas Nashif
commit 83fe7c7d71
3 changed files with 12 additions and 16 deletions

View file

@ -151,10 +151,7 @@ static uint8_t att_mtu_req(struct bt_att *att, struct bt_buf *buf)
return BT_ATT_ERR_UNLIKELY; return BT_ATT_ERR_UNLIKELY;
} }
/* Select MTU based on the amount of room we have in bt_buf including mtu_server = BT_ATT_MAX_LE_MTU;
* one extra byte for ATT header.
*/
mtu_server = bt_buf_tailroom(pdu) + 1;
BT_DBG("Server MTU %u\n", mtu_server); BT_DBG("Server MTU %u\n", mtu_server);
@ -215,14 +212,7 @@ static uint8_t att_mtu_rsp(struct bt_att *att, struct bt_buf *buf)
return att_handle_rsp(att, NULL, 0, BT_ATT_ERR_INVALID_PDU); return att_handle_rsp(att, NULL, 0, BT_ATT_ERR_INVALID_PDU);
} }
/* Clip MTU based on the maximum amount of data bt_buf can hold att->chan.rx.mtu = min(mtu, BT_ATT_MAX_LE_MTU);
* excluding L2CAP, ACL and driver headers.
*/
att->chan.rx.mtu = min(mtu, BT_BUF_MAX_DATA -
(sizeof(struct bt_l2cap_hdr) +
sizeof(struct bt_hci_acl_hdr) +
bt_dev.drv->head_reserve));
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484: /* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484:
* *

View file

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

View file

@ -31,6 +31,7 @@
#include <bluetooth/buf.h> #include <bluetooth/buf.h>
#include <bluetooth/uuid.h> #include <bluetooth/uuid.h>
#include <bluetooth/gatt.h> #include <bluetooth/gatt.h>
#include <bluetooth/driver.h>
#include "hci_core.h" #include "hci_core.h"
#include "conn_internal.h" #include "conn_internal.h"
@ -538,10 +539,7 @@ int bt_gatt_exchange_mtu(struct bt_conn *conn, bt_gatt_rsp_func_t func)
return -ENOMEM; return -ENOMEM;
} }
/* Select MTU based on the amount of room we have in bt_buf including mtu = BT_ATT_MAX_LE_MTU;
* one extra byte for ATT header.
*/
mtu = bt_buf_tailroom(buf) + 1;
BT_DBG("Client MTU %u\n", mtu); BT_DBG("Client MTU %u\n", mtu);