Skip to content

Commit

Permalink
[Backport-v2.2-branch] Bluetooth: controller: legacy: DLE timing
Browse files Browse the repository at this point in the history
Fixes #23482.

There is a bug in calculation of time for the DLE procedure:
the preamble size is incorrect for the 2M phy

This is for the legacy code, see PR #23570 for the split controller

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
  • Loading branch information
kruithofa authored and jhedberg committed Apr 22, 2020
1 parent 7e4bcff commit c5f9a2d
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions subsys/bluetooth/controller/ll_sw/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@
#define RADIO_PKT_TIME(octets, phy) \
(((phy) & BIT(2)) ? \
(80 + 256 + 16 + 24 + ((((2 + (octets) + 4) * 8) + 24 + 3) * 8)) : \
(((octets) + 14) * 8 / BIT(((phy) & 0x03) >> 1)))
(((octets) + 13 + PREAMBLE_SIZE(phy)) * 8 / \
BIT(((phy) & 0x03) >> 1)))
#else /* !CONFIG_BT_CTLR_PHY_CODED */
#define RADIO_PKT_TIME(octets, phy) \
(((octets) + 14) * 8 / BIT(((phy) & 0x03) >> 1))
(((octets) + 13 + PREAMBLE_SIZE(phy)) * 8 / BIT(((phy) & 0x03) >> 1))
#endif /* !CONFIG_BT_CTLR_PHY_CODED */

/* Inter Frame Space */
Expand Down Expand Up @@ -641,7 +642,8 @@ static void common_init(void)
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
/* Initialize the DLE defaults */
_radio.default_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN;
_radio.default_tx_time = RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0);
_radio.default_tx_time =
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0));
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */

#if defined(CONFIG_BT_CTLR_PHY)
Expand Down Expand Up @@ -2245,8 +2247,8 @@ isr_rx_conn_pkt_ctrl_rej_dle(struct radio_pdu_node_rx *node_rx,
lr->max_rx_octets = conn->max_rx_octets;
lr->max_tx_octets = conn->max_tx_octets;
#if !defined(CONFIG_BT_CTLR_PHY)
lr->max_rx_time = RADIO_PKT_TIME(conn->max_rx_octets, 0);
lr->max_tx_time = RADIO_PKT_TIME(conn->max_tx_octets, 0);
lr->max_rx_time = RADIO_PKT_TIME(conn->max_rx_octets, BIT(0));
lr->max_tx_time = RADIO_PKT_TIME(conn->max_tx_octets, BIT(0));
#else /* CONFIG_BT_CTLR_PHY */
lr->max_rx_time = conn->max_rx_time;
lr->max_tx_time = conn->max_tx_time;
Expand Down Expand Up @@ -2464,7 +2466,7 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx,
* peer max_rx_time
*/
if (lr->max_rx_time >=
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0)) {
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0))) {
eff_tx_time =
MIN(lr->max_rx_time,
_radio.conn_curr->default_tx_time);
Expand All @@ -2480,7 +2482,7 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx,
* peer max_tx_time
*/
if (lr->max_tx_time >=
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0)) {
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0))) {
eff_rx_time =
MIN(lr->max_tx_time,
RADIO_PKT_TIME(LL_LENGTH_OCTETS_RX_MAX,
Expand Down Expand Up @@ -2610,8 +2612,8 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx,
lr->max_tx_octets = eff_tx_octets;

#if !defined(CONFIG_BT_CTLR_PHY)
lr->max_rx_time = RADIO_PKT_TIME(eff_rx_octets, 0);
lr->max_tx_time = RADIO_PKT_TIME(eff_tx_octets, 0);
lr->max_rx_time = RADIO_PKT_TIME(eff_rx_octets, BIT(0));
lr->max_tx_time = RADIO_PKT_TIME(eff_tx_octets, BIT(0));
#else /* CONFIG_BT_CTLR_PHY */
lr->max_rx_time = eff_rx_time;
lr->max_tx_time = eff_tx_time;
Expand Down Expand Up @@ -4849,23 +4851,24 @@ static inline void isr_close_conn(void)
rx_time = conn->max_rx_time;
}
#else /* !CONFIG_BT_CTLR_DATA_LENGTH */
tx_time = MAX(RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0),
tx_time = MAX(RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0)),
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN,
conn->phy_tx));
rx_time = MAX(RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0),
rx_time = MAX(RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0)),
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN,
conn->phy_rx));
#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */
#else /* !CONFIG_BT_CTLR_PHY */
ready_delay = (conn->role) ?
radio_rx_ready_delay_get(0, 0) :
radio_tx_ready_delay_get(0, 0);
tx_time = RADIO_PKT_TIME(conn->max_tx_octets, 0);
tx_time = RADIO_PKT_TIME(conn->max_tx_octets, BIT(0));
if (conn->evt_len_adv) {
rx_time = RADIO_PKT_TIME(conn->llcp_length.rx_octets,
0);
BIT(0));
} else {
rx_time = RADIO_PKT_TIME(conn->max_rx_octets, 0);
rx_time = RADIO_PKT_TIME(conn->max_rx_octets,
BIT(0));
}
#endif /* !CONFIG_BT_CTLR_PHY */

Expand Down Expand Up @@ -8428,12 +8431,12 @@ static inline int event_len_prep(struct connection *conn)
#endif /* !CONFIG_BT_CTLR_PHY */
) {
lr->max_rx_time =
RADIO_PKT_TIME(LL_LENGTH_OCTETS_RX_MAX, 0);
RADIO_PKT_TIME(LL_LENGTH_OCTETS_RX_MAX, BIT(0));
#if defined(CONFIG_BT_CTLR_PHY)
lr->max_tx_time = conn->default_tx_time;
#else /* !CONFIG_BT_CTLR_PHY */
lr->max_tx_time =
RADIO_PKT_TIME(conn->default_tx_octets, 0);
RADIO_PKT_TIME(conn->default_tx_octets, BIT(0));
#endif /* !CONFIG_BT_CTLR_PHY */

#if defined(CONFIG_BT_CTLR_PHY)
Expand Down Expand Up @@ -8637,8 +8640,8 @@ static inline int event_len_prep(struct connection *conn)
lr->max_rx_octets = conn->max_rx_octets;
lr->max_tx_octets = tx_octets;
#if !defined(CONFIG_BT_CTLR_PHY)
lr->max_rx_time = RADIO_PKT_TIME(conn->max_rx_octets, 0);
lr->max_tx_time = RADIO_PKT_TIME(tx_octets, 0);
lr->max_rx_time = RADIO_PKT_TIME(conn->max_rx_octets, BIT(0));
lr->max_tx_time = RADIO_PKT_TIME(tx_octets, BIT(0));
#else /* CONFIG_BT_CTLR_PHY */
lr->max_rx_time = conn->max_rx_time;
lr->max_tx_time = tx_time;
Expand Down Expand Up @@ -8862,7 +8865,7 @@ static inline void event_phy_upd_ind_prep(struct connection *conn,
u16_t tx_time = RADIO_PKT_TIME(conn->max_tx_octets,
conn->phy_tx);
if (tx_time >=
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0)) {
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0))) {
eff_tx_time = MIN(tx_time,
conn->default_tx_time);
#if defined(CONFIG_BT_CTLR_PHY_CODED)
Expand All @@ -8873,7 +8876,7 @@ static inline void event_phy_upd_ind_prep(struct connection *conn,
} else {
eff_tx_time =
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN,
0);
BIT(0));
}
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */
}
Expand All @@ -8885,7 +8888,7 @@ static inline void event_phy_upd_ind_prep(struct connection *conn,
u16_t rx_time = RADIO_PKT_TIME(conn->max_rx_octets,
conn->phy_rx);
if (rx_time >=
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0)) {
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0))) {
eff_rx_time = MIN(rx_time,
RADIO_PKT_TIME(LL_LENGTH_OCTETS_RX_MAX,
BIT(2)));
Expand All @@ -8897,7 +8900,7 @@ static inline void event_phy_upd_ind_prep(struct connection *conn,
} else {
eff_rx_time =
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN,
0);
BIT(0));
}
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */
}
Expand Down Expand Up @@ -11043,9 +11046,9 @@ static void length_resp_send(struct connection *conn,

#if !defined(CONFIG_BT_CTLR_PHY)
pdu_ctrl_tx->llctrl.length_rsp.max_rx_time =
RADIO_PKT_TIME(eff_rx_octets, 0);
RADIO_PKT_TIME(eff_rx_octets, BIT(0));
pdu_ctrl_tx->llctrl.length_rsp.max_tx_time =
RADIO_PKT_TIME(eff_tx_octets, 0);
RADIO_PKT_TIME(eff_tx_octets, BIT(0));
#else /* CONFIG_BT_CTLR_PHY */
pdu_ctrl_tx->llctrl.length_rsp.max_rx_time = eff_rx_time;
pdu_ctrl_tx->llctrl.length_rsp.max_tx_time = eff_tx_time;
Expand Down Expand Up @@ -11536,9 +11539,9 @@ u32_t radio_adv_enable(u16_t interval, u8_t chan_map, u8_t filter_policy,
#if defined(CONFIG_BT_CTLR_PHY)
conn->default_tx_time = _radio.default_tx_time;
conn->max_tx_time =
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0);
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0));
conn->max_rx_time =
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0);
RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0));
#endif /* CONFIG_BT_CTLR_PHY */
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */

Expand Down Expand Up @@ -12075,8 +12078,8 @@ u32_t radio_connect_enable(u8_t adv_addr_type, u8_t *adv_addr, u16_t interval,

#if defined(CONFIG_BT_CTLR_PHY)
conn->default_tx_time = _radio.default_tx_time;
conn->max_tx_time = RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0);
conn->max_rx_time = RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0);
conn->max_tx_time = RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0));
conn->max_rx_time = RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, BIT(0));
#endif /* CONFIG_BT_CTLR_PHY */
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */

Expand Down

0 comments on commit c5f9a2d

Please sign in to comment.