This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
The following commit(s) were added to refs/heads/master by this push:
new a220f6679 nimble/ll: Check scheduler before sending connection request
a220f6679 is described below
commit a220f6679461ec25f280e3ba818ee924a0692ee7
Author: Andrzej Kaczmarek <[email protected]>
AuthorDate: Tue Nov 12 12:49:56 2024 +0100
nimble/ll: Check scheduler before sending connection request
We should not attempt to initiate connection if there's not enough time
left for connection req/rsp before next scheduling item, otherwise it
may be corrupted since scheduler will forcibly disable phy before
executing new item.
---
nimble/controller/src/ble_ll_conn.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/nimble/controller/src/ble_ll_conn.c
b/nimble/controller/src/ble_ll_conn.c
index 789b948aa..c671a3996 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -3221,24 +3221,46 @@ ble_ll_conn_send_connect_req(struct os_mbuf *rxpdu,
{
struct ble_ll_conn_sm *connsm;
struct ble_mbuf_hdr *rxhdr;
-#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
uint8_t phy;
-#endif
+ uint8_t phy_mode;
+ uint32_t sch_next;
+ uint32_t conn_req_us;
+ uint32_t conn_req_end;
int rc;
connsm = g_ble_ll_conn_create_sm.connsm;
rxhdr = BLE_MBUF_HDR_PTR(rxpdu);
-#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
- if (ext) {
#if MYNEWT_VAL(BLE_LL_PHY)
- phy = rxhdr->rxinfo.phy;
+ phy = rxhdr->rxinfo.phy;
+ phy_mode = rxhdr->rxinfo.phy_mode;
#else
- phy = BLE_PHY_1M;
+ phy = BLE_PHY_1M;
+ phy_mode = BLE_PHY_MODE_1M;
#endif
+
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+ if (ext) {
ble_ll_conn_create_set_params(connsm, phy);
}
+#else
+ (void)phy;
+#endif
+
+ rc = ble_ll_sched_next_time(&sch_next);
+ if (rc) {
+ conn_req_us = rxhdr->rem_usecs + ble_ll_pdu_us(34, phy_mode);
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+ if (ext) {
+ conn_req_us += BLE_LL_IFS + ble_ll_pdu_us(14, phy_mode);
+ }
#endif
+ conn_req_end = rxhdr->beg_cputime + ble_ll_tmr_u2t_up(conn_req_us);
+
+ if (LL_TMR_LEQ(sch_next, conn_req_end)) {
+ return -1;
+ }
+ }
if (ble_ll_sched_conn_central_new(connsm, rxhdr, 0)) {
return -1;