Skip to content

Commit

Permalink
nimble/ll: Add connection update support for CSS
Browse files Browse the repository at this point in the history
Now we only reject connection update requests
if host or peripheral tries to change connection
interval
  • Loading branch information
m-gorecki committed Nov 25, 2024
1 parent 284b784 commit 1edcf65
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
17 changes: 13 additions & 4 deletions nimble/controller/src/ble_ll_conn_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
37 changes: 25 additions & 12 deletions nimble/controller/src/ble_ll_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -380,6 +397,13 @@ ble_ll_ctrl_conn_param_pdu_proc(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1edcf65

Please sign in to comment.