This is an automated email from the ASF dual-hosted git repository.

mgorecki 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 1edcf65e1 nimble/ll: Add connection update support for CSS
1edcf65e1 is described below

commit 1edcf65e19f6b8aba26f7f53840a57cebe74c66f
Author: Michal Gorecki <[email protected]>
AuthorDate: Fri Nov 22 14:50:20 2024 +0100

    nimble/ll: Add connection update support for CSS
    
    Now we only reject connection update requests
    if host or peripheral tries to change connection
    interval
---
 nimble/controller/src/ble_ll_conn_hci.c | 17 +++++++++++----
 nimble/controller/src/ble_ll_ctrl.c     | 37 ++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/nimble/controller/src/ble_ll_conn_hci.c 
b/nimble/controller/src/ble_ll_conn_hci.c
index a7bb136f7..f3ac72380 100644
--- a/nimble/controller/src/ble_ll_conn_hci.c
+++ b/nimble/controller/src/ble_ll_conn_hci.c
@@ -1029,11 +1029,11 @@ ble_ll_conn_hci_update(const uint8_t *cmdbuf, uint8_t 
len)
     }
 
 #if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
-    /* Do not allow connection update if css in enabled, we only allow to move
-     * anchor point (i.e. change slot) via dedicated HCI command.
-     */
+    /* We only allow to change connection parameters if conn_itvl can stay 
unchanged */
     if (ble_ll_sched_css_is_enabled() &&
-        connsm->conn_role == BLE_LL_CONN_ROLE_CENTRAL) {
+        connsm->conn_role == BLE_LL_CONN_ROLE_CENTRAL &&
+        (connsm->conn_itvl < le16toh(cmd->conn_itvl_min) ||
+         connsm->conn_itvl > le16toh(cmd->conn_itvl_max))) {
         return BLE_ERR_CMD_DISALLOWED;
     }
 #endif
@@ -1098,8 +1098,13 @@ ble_ll_conn_hci_update(const uint8_t *cmdbuf, uint8_t 
len)
 
     /* Retrieve command data */
     hcu = &connsm->conn_param_req;
+#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
+    hcu->conn_itvl_max = connsm->conn_itvl;
+    hcu->conn_itvl_min = connsm->conn_itvl;
+#else
     hcu->conn_itvl_min = le16toh(cmd->conn_itvl_min);
     hcu->conn_itvl_max = le16toh(cmd->conn_itvl_max);
+#endif
     hcu->conn_latency = le16toh(cmd->conn_latency);
     hcu->supervision_timeout = le16toh(cmd->supervision_timeout);
     hcu->min_ce_len = le16toh(cmd->min_ce_len);
@@ -1116,6 +1121,10 @@ ble_ll_conn_hci_update(const uint8_t *cmdbuf, uint8_t 
len)
     if (!rc) {
         hcu->handle = handle;
 
+#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
+        connsm->css_slot_idx_pending = connsm->css_slot_idx;
+#endif
+
         /* Start the control procedure */
         ble_ll_ctrl_proc_start(connsm, ctrl_proc, NULL);
     }
diff --git a/nimble/controller/src/ble_ll_ctrl.c 
b/nimble/controller/src/ble_ll_ctrl.c
index 6902ba495..85f98417a 100644
--- a/nimble/controller/src/ble_ll_ctrl.c
+++ b/nimble/controller/src/ble_ll_ctrl.c
@@ -291,8 +291,25 @@ ble_ll_ctrl_conn_param_pdu_proc(struct ble_ll_conn_sm 
*connsm, uint8_t *dptr,
     req->offset4 = get_le16(dptr + 19);
     req->offset5 = get_le16(dptr + 21);
 
-    /* Check if parameters are valid */
     ble_err = BLE_ERR_SUCCESS;
+
+#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
+    /* Allow to change connection parameters only if conn_itvl can stay 
unchanged
+     * and anchor point change is not requested */
+    if (ble_ll_sched_css_is_enabled() &&
+        connsm->conn_role == BLE_LL_CONN_ROLE_CENTRAL &&
+        ((connsm->conn_itvl < le16toh(req->interval_min)) ||
+         (connsm->conn_itvl > le16toh(req->interval_max)) ||
+         (le16toh(req->offset0) != 0xffff))) {
+        ble_err = BLE_ERR_INV_LMP_LL_PARM;
+        goto conn_param_pdu_exit;
+    }
+
+    req->interval_min = connsm->conn_itvl;
+    req->interval_max = connsm->conn_itvl;
+#endif
+
+    /* Check if parameters are valid */
     rc = ble_ll_conn_hci_chk_conn_params(req->interval_min,
                                          req->interval_max,
                                          req->latency,
@@ -380,6 +397,13 @@ conn_param_pdu_exit:
         rspbuf[1] = opcode;
         rspbuf[2] = ble_err;
     }
+
+#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
+    if (!ble_err) {
+        connsm->css_slot_idx_pending = connsm->css_slot_idx;
+    }
+#endif
+
     return rsp_opcode;
 }
 
@@ -2259,17 +2283,6 @@ ble_ll_ctrl_rx_conn_param_req(struct ble_ll_conn_sm 
*connsm, uint8_t *dptr,
         return BLE_ERR_MAX;
     }
 
-#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
-    /* Reject any attempts to change connection parameters by peripheral */
-    if (ble_ll_sched_css_is_enabled() &&
-        connsm->conn_role == BLE_LL_CONN_ROLE_CENTRAL) {
-        rsp_opcode = BLE_LL_CTRL_REJECT_IND_EXT;
-        rspbuf[1] = BLE_LL_CTRL_CONN_PARM_REQ;
-        rspbuf[2] = BLE_ERR_UNSUPPORTED;
-        return rsp_opcode;
-    }
-#endif
-
     /* XXX: remember to deal with this on the central: if the peripheral has
      * initiated a procedure we may have received its connection parameter
      * update request and have signaled the host with an event. If that

Reply via email to