Skip to content

Commit d1deb20

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Classic: L2CAP: Disconn channel if proposed MTU is invalid
Disconnect the L2CAP channel connection if the proposed MTU is less than min MTU or more than local supported MTU. The main scenes are as follows. If the proposed MTU is less than MIN MTU. 1. The channel connection of client and server is established, 2. Client/server sends channel config REQ (MTU=50), 3. Peer replies channel config RQP (Unaccepted/success with MTU=30), 4. The client/server will repeat step 3~4 if the RSP is unacceptable. With the change applied, the local will disconnect the L2CAP channel connection in step 3. If the proposed MTU is more than local supported MTU. 1. The channel connection of client and server is established, 2. Client/server sends channel config REQ (MTU=50), 3. Peer replies channel config RQP (Unaccepted/success with MTU=80), 4. The client/server will repeat step 3~4 if the RSP is unacceptable. With the change applied, the local will disconnect the L2CAP channel connection in step 3. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 858e64c commit d1deb20

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

subsys/bluetooth/host/classic/l2cap_br.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ static uint16_t l2cap_br_conf_rsp_opt_mtu(struct bt_l2cap_chan *chan, struct net
26522652

26532653
/* Core 4.2 [Vol 3, Part A, 5.1] MTU payload length */
26542654
if (len != sizeof(*opt_mtu)) {
2655-
LOG_ERR("tx MTU length %zu invalid", len);
2655+
LOG_ERR("Proposed MTU length %zu invalid", len);
26562656
result = BT_L2CAP_CONF_REJECT;
26572657
goto done;
26582658
}
@@ -2661,14 +2661,22 @@ static uint16_t l2cap_br_conf_rsp_opt_mtu(struct bt_l2cap_chan *chan, struct net
26612661

26622662
mtu = sys_le16_to_cpu(opt_mtu->mtu);
26632663
if (mtu < L2CAP_BR_MIN_MTU) {
2664-
result = BT_L2CAP_CONF_UNACCEPT;
2664+
result = BT_L2CAP_CONF_REJECT;
26652665
opt_mtu->mtu = sys_cpu_to_le16(BR_CHAN(chan)->rx.mtu);
2666-
LOG_DBG("tx MTU %u invalid", mtu);
2666+
LOG_WRN("Proposed MTU %u invalid", mtu);
26672667
goto done;
26682668
}
26692669

26702670
if (mtu < BR_CHAN(chan)->rx.mtu) {
26712671
BR_CHAN(chan)->rx.mtu = mtu;
2672+
} else if (mtu > BR_CHAN(chan)->rx.mtu) {
2673+
LOG_WRN("Proposed MTU is more than given value (%u > %u)", mtu,
2674+
BR_CHAN(chan)->rx.mtu);
2675+
result = BT_L2CAP_CONF_REJECT;
2676+
goto done;
2677+
} else {
2678+
LOG_WRN("Proposed MTU is the same as given value (%u == %u)", mtu,
2679+
BR_CHAN(chan)->rx.mtu);
26722680
}
26732681

26742682
LOG_DBG("rx MTU %u", BR_CHAN(chan)->rx.mtu);
@@ -3120,7 +3128,7 @@ static uint16_t l2cap_br_conf_rsp_unaccept_opt_mtu(struct bt_l2cap_chan *chan, s
31203128

31213129
/* Core 4.2 [Vol 3, Part A, 5.1] MTU payload length */
31223130
if (len != sizeof(*opt_mtu)) {
3123-
LOG_ERR("tx MTU length %zu invalid", len);
3131+
LOG_ERR("Proposed MTU length %zu invalid", len);
31243132
result = BT_L2CAP_CONF_REJECT;
31253133
goto done;
31263134
}
@@ -3129,12 +3137,21 @@ static uint16_t l2cap_br_conf_rsp_unaccept_opt_mtu(struct bt_l2cap_chan *chan, s
31293137

31303138
mtu = sys_le16_to_cpu(opt_mtu->mtu);
31313139
if (mtu < L2CAP_BR_MIN_MTU) {
3132-
LOG_DBG("tx MTU %u invalid", mtu);
3140+
LOG_WRN("Proposed MTU %u invalid", mtu);
3141+
result = BT_L2CAP_CONF_REJECT;
31333142
goto done;
31343143
}
31353144

31363145
if (mtu < BR_CHAN(chan)->rx.mtu) {
31373146
BR_CHAN(chan)->rx.mtu = mtu;
3147+
} else if (mtu > BR_CHAN(chan)->rx.mtu) {
3148+
LOG_WRN("Proposed MTU is more than given value (%u > %u)", mtu,
3149+
BR_CHAN(chan)->rx.mtu);
3150+
result = BT_L2CAP_CONF_REJECT;
3151+
goto done;
3152+
} else {
3153+
LOG_WRN("Proposed MTU is the same as given value (%u == %u)", mtu,
3154+
BR_CHAN(chan)->rx.mtu);
31383155
}
31393156

31403157
done:

0 commit comments

Comments
 (0)