Skip to content

Commit 52ffbd8

Browse files
alexstanoev-nordiccarlescufi
authored andcommitted
bluetooth: shell: Add shell commands for LE Connection Subrating
Add commands to allow requesting a subrate change via the BT shell. A new build configuration has been added to ensure this is tested in CI. Signed-off-by: Aleksandar Stanoev <[email protected]>
1 parent db9bcdc commit 52ffbd8

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

subsys/bluetooth/shell/bt.c

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,27 @@ void path_loss_threshold_report(struct bt_conn *conn,
974974
}
975975
#endif
976976

977+
#if defined(CONFIG_BT_SUBRATING)
978+
void subrate_changed(struct bt_conn *conn,
979+
const struct bt_conn_le_subrate_changed *params)
980+
{
981+
if (params->status == BT_HCI_ERR_SUCCESS) {
982+
shell_print(ctx_shell, "Subrate parameters changed: "
983+
"Subrate Factor: %d "
984+
"Continuation Number: %d "
985+
"Peripheral latency: 0x%04x "
986+
"Supervision timeout: 0x%04x (%d ms)",
987+
params->factor,
988+
params->continuation_number,
989+
params->peripheral_latency,
990+
params->supervision_timeout,
991+
params->supervision_timeout * 10);
992+
} else {
993+
shell_print(ctx_shell, "Subrate change failed (HCI status 0x%02x)", params->status);
994+
}
995+
}
996+
#endif
997+
977998
static struct bt_conn_cb conn_callbacks = {
978999
.connected = connected,
9791000
.disconnected = disconnected,
@@ -1000,6 +1021,9 @@ static struct bt_conn_cb conn_callbacks = {
10001021
#if defined(CONFIG_BT_PATH_LOSS_MONITORING)
10011022
.path_loss_threshold_report = path_loss_threshold_report,
10021023
#endif
1024+
#if defined(CONFIG_BT_SUBRATING)
1025+
.subrate_changed = subrate_changed,
1026+
#endif
10031027
};
10041028
#endif /* CONFIG_BT_CONN */
10051029

@@ -3019,6 +3043,74 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg
30193043
}
30203044
#endif
30213045

3046+
#if defined(CONFIG_BT_SUBRATING)
3047+
static int cmd_subrate_set_defaults(const struct shell *sh, size_t argc, char *argv[])
3048+
{
3049+
int err = 0;
3050+
3051+
for (size_t argn = 1; argn < argc; argn++) {
3052+
(void)shell_strtoul(argv[argn], 10, &err);
3053+
3054+
if (err) {
3055+
shell_help(sh);
3056+
shell_error(sh, "Could not parse input number %d", argn);
3057+
return SHELL_CMD_HELP_PRINTED;
3058+
}
3059+
}
3060+
3061+
const struct bt_conn_le_subrate_param params = {
3062+
.subrate_min = shell_strtoul(argv[1], 10, &err),
3063+
.subrate_max = shell_strtoul(argv[2], 10, &err),
3064+
.max_latency = shell_strtoul(argv[3], 10, &err),
3065+
.continuation_number = shell_strtoul(argv[4], 10, &err),
3066+
.supervision_timeout = shell_strtoul(argv[5], 10, &err) * 100, /* 10ms units */
3067+
};
3068+
3069+
err = bt_conn_le_subrate_set_defaults(&params);
3070+
if (err) {
3071+
shell_error(sh, "bt_conn_le_subrate_set_defaults returned error %d", err);
3072+
return -ENOEXEC;
3073+
}
3074+
3075+
return 0;
3076+
}
3077+
3078+
static int cmd_subrate_request(const struct shell *sh, size_t argc, char *argv[])
3079+
{
3080+
int err = 0;
3081+
3082+
if (default_conn == NULL) {
3083+
shell_error(sh, "Conn handle error, at least one connection is required.");
3084+
return -ENOEXEC;
3085+
}
3086+
3087+
for (size_t argn = 1; argn < argc; argn++) {
3088+
(void)shell_strtoul(argv[argn], 10, &err);
3089+
3090+
if (err) {
3091+
shell_help(sh);
3092+
shell_error(sh, "Could not parse input number %d", argn);
3093+
return SHELL_CMD_HELP_PRINTED;
3094+
}
3095+
}
3096+
3097+
const struct bt_conn_le_subrate_param params = {
3098+
.subrate_min = shell_strtoul(argv[1], 10, &err),
3099+
.subrate_max = shell_strtoul(argv[2], 10, &err),
3100+
.max_latency = shell_strtoul(argv[3], 10, &err),
3101+
.continuation_number = shell_strtoul(argv[4], 10, &err),
3102+
.supervision_timeout = shell_strtoul(argv[5], 10, &err) * 100, /* 10ms units */
3103+
};
3104+
3105+
err = bt_conn_le_subrate_request(default_conn, &params);
3106+
if (err) {
3107+
shell_error(sh, "bt_conn_le_subrate_request returned error %d", err);
3108+
return -ENOEXEC;
3109+
}
3110+
3111+
return 0;
3112+
}
3113+
#endif
30223114

30233115
#if defined(CONFIG_BT_CONN)
30243116
#if defined(CONFIG_BT_CENTRAL)
@@ -3315,6 +3407,12 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
33153407
info.le.data_len->tx_max_time,
33163408
info.le.data_len->rx_max_len,
33173409
info.le.data_len->rx_max_time);
3410+
#endif
3411+
#if defined(CONFIG_BT_SUBRATING)
3412+
shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d"
3413+
" Continuation Number: %d",
3414+
info.le.subrate->factor,
3415+
info.le.subrate->continuation_number);
33183416
#endif
33193417
}
33203418

@@ -4716,6 +4814,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
47164814
SHELL_CMD_ARG(path-loss-monitoring-enable, NULL, "<enable: true, false>",
47174815
cmd_set_path_loss_reporting_enable, 2, 0),
47184816
#endif
4817+
#if defined(CONFIG_BT_SUBRATING)
4818+
SHELL_CMD_ARG(subrate-set-defaults, NULL,
4819+
"<min subrate factor> <max subrate factor> <max peripheral latency> "
4820+
"<min continuation number> <supervision timeout (seconds)>",
4821+
cmd_subrate_set_defaults, 6, 0),
4822+
SHELL_CMD_ARG(subrate-request, NULL,
4823+
"<min subrate factor> <max subrate factor> <max peripheral latency> "
4824+
"<min continuation number> <supervision timeout (seconds)>",
4825+
cmd_subrate_request, 6, 0),
4826+
#endif
47194827
#if defined(CONFIG_BT_BROADCASTER)
47204828
SHELL_CMD_ARG(advertise, NULL,
47214829
"<type: off, on, nconn> [mode: discov, non_discov] "

tests/bluetooth/shell/testcase.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ tests:
2929
platform_allow:
3030
- native_posix
3131
build_only: true
32+
bluetooth.shell.subrating:
33+
extra_configs:
34+
- CONFIG_BT_SUBRATING=y
35+
- CONFIG_BT_CTLR=n
36+
platform_allow:
37+
- native_posix
38+
build_only: true
3239
bluetooth.shell.cdc_acm:
3340
extra_args:
3441
- OVERLAY_CONFIG=cdc_acm.conf

0 commit comments

Comments
 (0)