Skip to content

Commit fe14931

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: L2CAP: Derive MPS from connection MTU
This ensures the MPS can fit in a single HCI fragment so each segment don't have to be reassembled at HCI level, in addition to that also remove the debugfs entry to configure the MPS. Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent a357ea0 commit fe14931

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

include/net/bluetooth/l2cap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ struct l2cap_conn_param_update_rsp {
456456
#define L2CAP_CONN_PARAM_REJECTED 0x0001
457457

458458
#define L2CAP_LE_MAX_CREDITS 10
459-
#define L2CAP_LE_DEFAULT_MPS 230
460459

461460
struct l2cap_le_conn_req {
462461
__le16 psm;

net/bluetooth/l2cap_core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static LIST_HEAD(chan_list);
5252
static DEFINE_RWLOCK(chan_list_lock);
5353

5454
static u16 le_max_credits = L2CAP_LE_MAX_CREDITS;
55-
static u16 le_default_mps = L2CAP_LE_DEFAULT_MPS;
5655

5756
static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
5857
u8 code, u8 ident, u16 dlen, void *data);
@@ -520,7 +519,8 @@ static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
520519
chan->sdu_len = 0;
521520
chan->tx_credits = 0;
522521
chan->rx_credits = le_max_credits;
523-
chan->mps = min_t(u16, chan->imtu, le_default_mps);
522+
/* Derive MPS from connection MTU to stop HCI fragmentation */
523+
chan->mps = min_t(u16, chan->imtu, chan->conn->mtu - L2CAP_HDR_SIZE);
524524

525525
skb_queue_head_init(&chan->tx_q);
526526
}
@@ -1282,6 +1282,8 @@ static void l2cap_le_connect(struct l2cap_chan *chan)
12821282
if (test_and_set_bit(FLAG_LE_CONN_REQ_SENT, &chan->flags))
12831283
return;
12841284

1285+
l2cap_le_flowctl_init(chan);
1286+
12851287
req.psm = chan->psm;
12861288
req.scid = cpu_to_le16(chan->scid);
12871289
req.mtu = cpu_to_le16(chan->imtu);
@@ -5493,8 +5495,6 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
54935495
goto response_unlock;
54945496
}
54955497

5496-
l2cap_le_flowctl_init(chan);
5497-
54985498
bacpy(&chan->src, &conn->hcon->src);
54995499
bacpy(&chan->dst, &conn->hcon->dst);
55005500
chan->src_type = bdaddr_src_type(conn->hcon);
@@ -5506,6 +5506,9 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
55065506
chan->tx_credits = __le16_to_cpu(req->credits);
55075507

55085508
__l2cap_chan_add(conn, chan);
5509+
5510+
l2cap_le_flowctl_init(chan);
5511+
55095512
dcid = chan->scid;
55105513
credits = chan->rx_credits;
55115514

@@ -7102,7 +7105,6 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
71027105
case L2CAP_MODE_BASIC:
71037106
break;
71047107
case L2CAP_MODE_LE_FLOWCTL:
7105-
l2cap_le_flowctl_init(chan);
71067108
break;
71077109
case L2CAP_MODE_ERTM:
71087110
case L2CAP_MODE_STREAMING:
@@ -7647,8 +7649,6 @@ int __init l2cap_init(void)
76477649

76487650
debugfs_create_u16("l2cap_le_max_credits", 0644, bt_debugfs,
76497651
&le_max_credits);
7650-
debugfs_create_u16("l2cap_le_default_mps", 0644, bt_debugfs,
7651-
&le_default_mps);
76527652

76537653
return 0;
76547654
}

0 commit comments

Comments
 (0)