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); } /**