@@ -3147,6 +3147,76 @@ static inline void event_ping_prep(struct ll_conn *conn)
31473147#endif /* CONFIG_BT_CTLR_LE_PING */
31483148
31493149#if defined(CONFIG_BT_CTLR_DATA_LENGTH )
3150+ static inline void dle_max_time_get (const struct ll_conn * conn ,
3151+ u16_t * max_rx_time , u16_t * max_tx_time )
3152+ {
3153+ u32_t feature_coded_phy = 0 ;
3154+ u32_t feature_phy_2m = 0 ;
3155+ u16_t rx_time = 0 ;
3156+ u16_t tx_time = 0 ;
3157+
3158+ #if defined(CONFIG_BT_CTLR_PHY )
3159+ #if defined(CONFIG_BT_CTLR_PHY_CODED )
3160+ feature_coded_phy = (conn -> llcp_feature .features &
3161+ BIT (BT_LE_FEAT_BIT_PHY_CODED ));
3162+ #else
3163+ feature_coded_phy = 0 ;
3164+ #endif
3165+
3166+ #if defined(CONFIG_BT_CTLR_PHY_2M )
3167+ feature_phy_2m = (conn -> llcp_feature .features &
3168+ BIT (BT_LE_FEAT_BIT_PHY_2M ));
3169+ #else
3170+ feature_phy_2m = 0 ;
3171+ #endif
3172+ #else
3173+ feature_coded_phy = 0 ;
3174+ feature_phy_2m = 0 ;
3175+ #endif
3176+
3177+ if (!conn -> common .fex_valid ||
3178+ (!feature_coded_phy && !feature_phy_2m )) {
3179+ rx_time = PKT_US (LL_LENGTH_OCTETS_RX_MAX , 0 );
3180+ #if defined(CONFIG_BT_CTLR_PHY )
3181+ tx_time = MAX (MIN (PKT_US (LL_LENGTH_OCTETS_RX_MAX , 0 ),
3182+ conn -> default_tx_time ),
3183+ PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , 0 ));
3184+ #else /* !CONFIG_BT_CTLR_PHY */
3185+ tx_time = PKT_US (conn -> default_tx_octets , 0 );
3186+ #endif /* !CONFIG_BT_CTLR_PHY */
3187+
3188+ #if defined(CONFIG_BT_CTLR_PHY )
3189+ #if defined(CONFIG_BT_CTLR_PHY_CODED )
3190+ } else if (feature_coded_phy ) {
3191+ rx_time = MAX (PKT_US (LL_LENGTH_OCTETS_RX_MAX , BIT (2 )),
3192+ PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , BIT (2 )));
3193+ tx_time = MIN (PKT_US (LL_LENGTH_OCTETS_RX_MAX , BIT (2 )),
3194+ conn -> default_tx_time );
3195+ tx_time = MAX (PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , 0 ), tx_time );
3196+ #endif /* CONFIG_BT_CTLR_PHY_CODED */
3197+
3198+ #if defined(CONFIG_BT_CTLR_PHY_2M )
3199+ } else if (feature_phy_2m ) {
3200+ rx_time = MAX (PKT_US (LL_LENGTH_OCTETS_RX_MAX , BIT (1 )),
3201+ PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , BIT (1 )));
3202+ tx_time = MAX (PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , 0 ),
3203+ MIN (PKT_US (LL_LENGTH_OCTETS_RX_MAX , BIT (1 )),
3204+ conn -> default_tx_time ));
3205+ #endif /* CONFIG_BT_CTLR_PHY_2M */
3206+ #endif /* CONFIG_BT_CTLR_PHY */
3207+ }
3208+
3209+ /*
3210+ * see Vol. 6 Part B chapter 4.5.10
3211+ * minimum value for time is 328 us
3212+ */
3213+ rx_time = MAX (PDU_DC_PAYLOAD_TIME_MIN , rx_time );
3214+ tx_time = MAX (PDU_DC_PAYLOAD_TIME_MIN , tx_time );
3215+
3216+ * max_rx_time = rx_time ;
3217+ * max_tx_time = tx_time ;
3218+ }
3219+
31503220static inline void event_len_prep (struct ll_conn * conn )
31513221{
31523222 switch (conn -> llcp_length .state ) {
@@ -3155,39 +3225,17 @@ static inline void event_len_prep(struct ll_conn *conn)
31553225 struct pdu_data_llctrl_length_req * lr ;
31563226 struct pdu_data * pdu_ctrl_tx ;
31573227 struct node_tx * tx ;
3158- u16_t rx_time = 0 ;
3159- u16_t tx_time = 0 ;
31603228 /*
3161- * Using bool instead of u8_t increases code size
3162- * in this case.
3229+ * initialize to 0 to eliminate compiler warnings
31633230 */
3164- u8_t feature_coded_phy ;
3165- u8_t feature_phy_2m ;
3231+ u16_t rx_time = 0 ;
3232+ u16_t tx_time = 0 ;
31663233
31673234 tx = mem_acquire (& mem_conn_tx_ctrl .free );
31683235 if (!tx ) {
31693236 return ;
31703237 }
31713238
3172- #if defined(CONFIG_BT_CTLR_PHY )
3173- #if defined(CONFIG_BT_CTLR_PHY_CODED )
3174- feature_coded_phy = (conn -> llcp_feature .features &
3175- BIT (BT_LE_FEAT_BIT_PHY_CODED ));
3176- #else
3177- feature_coded_phy = 0 ;
3178- #endif
3179-
3180- #if defined(CONFIG_BT_CTLR_PHY_2M )
3181- feature_phy_2m = (conn -> llcp_feature .features &
3182- BIT (BT_LE_FEAT_BIT_PHY_2M ));
3183- #else
3184- feature_phy_2m = 0 ;
3185- #endif
3186- #else
3187- feature_coded_phy = 0 ;
3188- feature_phy_2m = 0 ;
3189- #endif
3190-
31913239 /* wait for resp before completing the procedure */
31923240 conn -> llcp_length .state = LLCP_LENGTH_STATE_REQ_ACK_WAIT ;
31933241
@@ -3196,7 +3244,7 @@ static inline void event_len_prep(struct ll_conn *conn)
31963244
31973245#if defined(CONFIG_BT_CTLR_PHY )
31983246 conn -> default_tx_time = conn -> llcp_length .tx_time ;
3199- #endif /* CONFIG_BT_CTLR_PHY */
3247+ #endif
32003248
32013249 /* place the length req packet as next in tx queue */
32023250 pdu_ctrl_tx = (void * ) tx -> pdu ;
@@ -3210,38 +3258,10 @@ static inline void event_len_prep(struct ll_conn *conn)
32103258 lr -> max_rx_octets = sys_cpu_to_le16 (LL_LENGTH_OCTETS_RX_MAX );
32113259 lr -> max_tx_octets = sys_cpu_to_le16 (conn -> default_tx_octets );
32123260
3213- if (!conn -> common .fex_valid ||
3214- (!feature_coded_phy && !feature_phy_2m )) {
3215- rx_time = PKT_US (LL_LENGTH_OCTETS_RX_MAX , 0 );
3216- #if defined(CONFIG_BT_CTLR_PHY )
3217- tx_time = MIN (PKT_US (LL_LENGTH_OCTETS_RX_MAX , 0 ),
3218- conn -> default_tx_time );
3219- #else /* !CONFIG_BT_CTLR_PHY */
3220- tx_time = PKT_US (conn -> default_tx_octets , 0 );
3221- #endif /* !CONFIG_BT_CTLR_PHY */
3222- #if defined(CONFIG_BT_CTLR_PHY )
3223- #if defined(CONFIG_BT_CTLR_PHY_CODED )
3224- } else if (feature_coded_phy ) {
3225- rx_time = PKT_US (LL_LENGTH_OCTETS_RX_MAX , BIT (2 ));
3226- tx_time = conn -> default_tx_time ;
3227- #endif /* CONFIG_BT_CTLR_PHY_CODED */
3228-
3229- #if defined(CONFIG_BT_CTLR_PHY_2M )
3230- } else if (feature_phy_2m ) {
3231- rx_time = PKT_US (LL_LENGTH_OCTETS_RX_MAX , BIT (1 ));
3232- if (conn -> default_tx_time > rx_time ) {
3233- tx_time = rx_time ;
3234- } else {
3235- tx_time = conn -> default_tx_time ;
3236- }
3237- #endif /* CONFIG_BT_CTLR_PHY_2M */
3238- #endif /* CONFIG_BT_CTLR_PHY */
3239- }
3240-
3261+ dle_max_time_get (conn , & rx_time , & tx_time );
32413262 lr -> max_rx_time = sys_cpu_to_le16 (rx_time );
32423263 lr -> max_tx_time = sys_cpu_to_le16 (tx_time );
32433264
3244-
32453265 ctrl_tx_enqueue (conn , tx );
32463266
32473267 /* Start Procedure Timeout (TODO: this shall not replace
@@ -4512,14 +4532,19 @@ static inline int length_req_rsp_recv(struct ll_conn *conn, memq_link_t *link,
45124532#if defined(CONFIG_BT_CTLR_PHY )
45134533 u16_t max_rx_time ;
45144534 u16_t max_tx_time ;
4535+ u16_t lr_rx_time , lr_tx_time ;
4536+
4537+ dle_max_time_get (conn , & max_rx_time , & max_tx_time );
45154538
45164539 /* use the minimal of our default_tx_time and
45174540 * peer max_rx_time
45184541 */
4519- max_rx_time = sys_le16_to_cpu (lr -> max_rx_time );
4520- if (max_rx_time >= PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , 0 )) {
4521- eff_tx_time = MIN (max_rx_time ,
4522- conn -> default_tx_time );
4542+
4543+ lr_rx_time = sys_le16_to_cpu (lr -> max_rx_time );
4544+ lr_tx_time = sys_le16_to_cpu (lr -> max_tx_time );
4545+
4546+ if (lr_rx_time >= PKT_US (PDU_DC_PAYLOAD_SIZE_MIN , 0 )) {
4547+ eff_tx_time = MIN (lr_rx_time , max_tx_time );
45234548#if defined(CONFIG_BT_CTLR_PHY_CODED )
45244549 eff_tx_time = MAX (eff_tx_time ,
45254550 PKT_US (PDU_DC_PAYLOAD_SIZE_MIN ,
@@ -4530,18 +4555,12 @@ static inline int length_req_rsp_recv(struct ll_conn *conn, memq_link_t *link,
45304555 /* use the minimal of our max supported and
45314556 * peer max_tx_time
45324557 */
4533- max_tx_time = sys_le16_to_cpu ( lr -> max_tx_time );
4534- if ( max_tx_time >= PKT_US ( PDU_DC_PAYLOAD_SIZE_MIN , 0 )) {
4558+ if ( lr_tx_time >= PKT_US ( PDU_DC_PAYLOAD_SIZE_MIN , 0 )) {
4559+ eff_rx_time = MIN ( lr_tx_time , max_rx_time );
45354560#if defined(CONFIG_BT_CTLR_PHY_CODED )
4536- eff_rx_time = MIN (max_tx_time ,
4537- PKT_US (LL_LENGTH_OCTETS_RX_MAX ,
4538- BIT (2 )));
45394561 eff_rx_time = MAX (eff_rx_time ,
45404562 PKT_US (PDU_DC_PAYLOAD_SIZE_MIN ,
45414563 conn -> lll .phy_rx ));
4542- #else /* !CONFIG_BT_CTLR_PHY_CODED */
4543- eff_rx_time = MIN (max_tx_time ,
4544- PKT_US (LL_LENGTH_OCTETS_RX_MAX , 0 ));
45454564#endif /* !CONFIG_BT_CTLR_PHY_CODED */
45464565 }
45474566#endif /* CONFIG_BT_CTLR_PHY */
0 commit comments