Skip to content

Commit 94daf9c

Browse files
committed
nimble/ll: Add LE CS Set Default Settings command
The HCI_LE_CS_Set_Default_Settings command is used by a Host to set default CS settings in the local Controller for the connection.
1 parent 3097809 commit 94daf9c

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

nimble/controller/src/ble_ll_cs.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,67 @@ int
285285
ble_ll_cs_hci_set_def_settings(const uint8_t *cmdbuf, uint8_t cmdlen,
286286
uint8_t *rspbuf, uint8_t *rsplen)
287287
{
288-
return BLE_ERR_UNSUPPORTED;
288+
const struct ble_hci_le_cs_set_def_settings_cp *cmd = (const void *)cmdbuf;
289+
struct ble_hci_le_cs_set_def_settings_rp *rsp = (void *)rspbuf;
290+
const struct ble_ll_cs_supp_cap *cap = &g_ble_ll_cs_local_cap;
291+
struct ble_ll_conn_sm *connsm;
292+
struct ble_ll_cs_sm *cssm;
293+
294+
connsm = ble_ll_conn_find_by_handle(le16toh(cmd->conn_handle));
295+
if (!connsm) {
296+
return BLE_ERR_UNK_CONN_ID;
297+
}
298+
299+
cssm = connsm->cssm;
300+
301+
/* Check if a disabled role is used in CS configs */
302+
for (int i = 0; i < ARRAY_SIZE(cssm->config); i++) {
303+
struct ble_ll_cs_config *conf = &cssm->config[i];
304+
305+
if (conf->config_enabled && (1 << conf->role) & ~cmd->role_enable) {
306+
return BLE_ERR_INV_HCI_CMD_PARMS;
307+
}
308+
}
309+
310+
if ((cmd->role_enable & ~cap->roles_supported) != 0 ||
311+
(cap->number_of_antennas < cmd->cs_sync_antenna_selection &&
312+
cmd->cs_sync_antenna_selection < 0xFE)) {
313+
/* Unsupported role or antenna selection used */
314+
return BLE_ERR_UNSUPPORTED;
315+
}
316+
317+
cssm->roles_enabled = cmd->role_enable;
318+
cssm->cs_sync_antenna_selection = cmd->cs_sync_antenna_selection;
319+
320+
/* Allowed Transmit_Power_Level range: -127 to +20,
321+
* (Complement system + special meaning for 0x7E and 0x7F)
322+
*/
323+
if (!(IN_RANGE(cmd->max_tx_power, 0x00, 0x14) ||
324+
IN_RANGE(cmd->max_tx_power, 0x7E, 0xFF))) {
325+
return BLE_ERR_INV_HCI_CMD_PARMS;
326+
}
327+
328+
if (cmd->max_tx_power == 0x7E) {
329+
/* TODO: Set transmitter to minimum transmit power level
330+
* supported by the board.
331+
*/
332+
cssm->max_tx_power = 0x80;
333+
} else if (cmd->max_tx_power == 0x7F) {
334+
/* TODO: Set transmitter to maximum transmit power level
335+
* supported by the board.
336+
*/
337+
cssm->max_tx_power = 0x14;
338+
} else {
339+
/* TODO: Set transmitter to the nearest transmit power level
340+
* supported by the board.
341+
*/
342+
cssm->max_tx_power = cmd->max_tx_power;
343+
}
344+
345+
rsp->conn_handle = cmd->conn_handle;
346+
*rsplen = sizeof(*rsp);
347+
348+
return BLE_ERR_SUCCESS;
289349
}
290350

291351
int

nimble/controller/src/ble_ll_cs_priv.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
extern "C" {
2828
#endif
2929

30+
#define BLE_LL_CS_CONFIG_MAX_NUM 4
31+
3032
struct ble_ll_cs_supp_cap {
3133
uint8_t mode_types;
3234
uint8_t roles_supported;
@@ -52,9 +54,24 @@ struct ble_ll_cs_supp_cap {
5254
uint8_t tx_snr_capablity;
5355
};
5456

57+
struct ble_ll_cs_config {
58+
bool config_enabled;
59+
/* The role to use in CS procedure
60+
* 0x00 = Initiator,
61+
* 0x01 = Reflector
62+
*/
63+
uint8_t role;
64+
};
65+
5566
struct ble_ll_cs_sm {
5667
struct ble_ll_conn_sm *connsm;
5768
struct ble_ll_cs_supp_cap remote_cap;
69+
struct ble_ll_cs_config config[BLE_LL_CS_CONFIG_MAX_NUM];
70+
71+
/* Default Settings */
72+
uint8_t roles_enabled;
73+
uint8_t cs_sync_antenna_selection;
74+
uint8_t max_tx_power;
5875
};
5976

6077
#ifdef __cplusplus

0 commit comments

Comments
 (0)