From 2e4c1850fcb53a9712e3f23b407c2a67d19c9bd9 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 Sep 2019 15:26:41 +0200 Subject: [PATCH] l2cap-ertm: assert that packet can be stored in fragment buffers in ertm --- CHANGELOG.md | 1 + src/l2cap.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6199b394..d174967f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Fixed +- L2CAP ERTM: assert that packet can be stored in fragment buffers in ertm ### Added - GAP: allow to reject GAP classic connection via gap_register_classic_connection_filter diff --git a/src/l2cap.c b/src/l2cap.c index 89c5b478a..ea0f8e252 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -2700,6 +2700,18 @@ static void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *c break; } if (l2cap_channel_ready_for_open(channel)){ + +#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE + // assert that packet can be stored in fragment buffers in ertm + if (channel->mode == L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION){ + uint16_t effective_mps = btstack_min(channel->remote_mps, channel->local_mps); + uint16_t usable_mtu = channel->num_tx_buffers == 1 ? effective_mps : channel->num_tx_buffers * effective_mps - 2; + if (usable_mtu < channel->remote_mtu){ + log_info("Remote MTU %u > max storable ERTM packet, only using MTU = %u", channel->remote_mtu, usable_mtu); + channel->remote_mtu = usable_mtu; + } + } +#endif // for open: channel->state = L2CAP_STATE_OPEN; l2cap_emit_channel_opened(channel, 0);