From ab1d58a2f4164c0aa95c24bd45de199a01aee88b Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Sun, 24 Sep 2017 23:30:44 +0200 Subject: [PATCH] nimble/ll: Enforce minimum payload length for coded phy Lower bound of connEffectiveMaxTxTime depends on current phy but it is always at least the time required to send 27 bytes of payload. This patch enforces this. Without this fix we were sending control packets with no payload after phy has changed from uncoded to coded which had really strange results. X-Original-Commit: 5344b77d4e5f3663c239d13b2f2d7a7f8ad80ad1 --- nimble/controller/src/ble_ll.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c index 8f2b8e593..6456b8179 100644 --- a/nimble/controller/src/ble_ll.c +++ b/nimble/controller/src/ble_ll.c @@ -1283,9 +1283,20 @@ ble_ll_pdu_max_tx_octets_get(uint32_t usecs, int phy_mode) header_tx_time = g_ble_ll_pdu_header_tx_time[phy_mode]; + /* + * Current conn max tx time can be too short to even send a packet header + * and this can happen if we changed connection form uncoded to coded phy. + * However, the lower bound for conn max tx time (all of them) depends on + * current phy (uncoded/coded) but it always allows to send at least 27 + * bytes of payload thus we alwyas return at least 27 from here. + * + * Reference: + * Core v5.0, Vol 6, Part B, section 4.5.10 + * see connEffectiveMaxTxTime and connEffectiveMaxRxTime definitions + */ + if (usecs < header_tx_time) { - // XXX: this is obviously incorrect, what should we do? - return 0; + return 27; } usecs -= header_tx_time; @@ -1306,7 +1317,8 @@ ble_ll_pdu_max_tx_octets_get(uint32_t usecs, int phy_mode) assert(0); } - return octets; + /* see comment at the beginning */ + return max(27, octets); } /**