Skip to content

Bluetooth: Classic: L2CAP: Disconn channel if proposed MTU is invalid #90158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lylezhu2012
Copy link
Collaborator

@lylezhu2012 lylezhu2012 commented May 19, 2025

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.

@gzh-terry
Copy link
Collaborator

Hi @lylezhu2012

It seems that the first part of the description (If the proposed MTU is less than MIN MTU) is not relevant to this PR.

} else if (mtu > BR_CHAN(chan)->rx.mtu) {
LOG_WRN("Proposed MTU is more than given value (%u > %u)", mtu,
BR_CHAN(chan)->rx.mtu);
result = BT_L2CAP_CONF_REJECT;
Copy link
Collaborator

@gzh-terry gzh-terry May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend to add goto done; after this.
Note that the future developers may add codes after line 3154.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think so. However, from the current implementation point of view, it makes no difference whether it is added or not. From the perspective of later maintenance, adding goto statements is easier to understand and maintain.

Updated.

@lylezhu2012 lylezhu2012 force-pushed the classic_l2cap_reject_if_mtu_is_less_than_min_mtu branch from 7f3b0da to 610b24c Compare May 20, 2025 03:19
@lylezhu2012
Copy link
Collaborator Author

It seems that the first part of the description (If the proposed MTU is less than MIN MTU) is not relevant to this PR.

Thanks. Added it.

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>
@lylezhu2012 lylezhu2012 force-pushed the classic_l2cap_reject_if_mtu_is_less_than_min_mtu branch from 610b24c to 29cf81b Compare May 20, 2025 03:28
Copy link

@lylezhu2012 lylezhu2012 requested a review from gzh-terry May 20, 2025 05:51
@lylezhu2012
Copy link
Collaborator Author

@gzh-terry Do you have any comments?

Copy link
Collaborator

@gzh-terry gzh-terry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kartben kartben merged commit d1deb20 into zephyrproject-rtos:main May 29, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants