Skip to content

Commit 64796d7

Browse files
alexstanoev-nordicrlubos
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 52ffbd8)
1 parent 1c041e8 commit 64796d7

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
@@ -982,6 +982,27 @@ void path_loss_threshold_report(struct bt_conn *conn,
982982
}
983983
#endif
984984

985+
#if defined(CONFIG_BT_SUBRATING)
986+
void subrate_changed(struct bt_conn *conn,
987+
const struct bt_conn_le_subrate_changed *params)
988+
{
989+
if (params->status == BT_HCI_ERR_SUCCESS) {
990+
shell_print(ctx_shell, "Subrate parameters changed: "
991+
"Subrate Factor: %d "
992+
"Continuation Number: %d "
993+
"Peripheral latency: 0x%04x "
994+
"Supervision timeout: 0x%04x (%d ms)",
995+
params->factor,
996+
params->continuation_number,
997+
params->peripheral_latency,
998+
params->supervision_timeout,
999+
params->supervision_timeout * 10);
1000+
} else {
1001+
shell_print(ctx_shell, "Subrate change failed (HCI status 0x%02x)", params->status);
1002+
}
1003+
}
1004+
#endif
1005+
9851006
static struct bt_conn_cb conn_callbacks = {
9861007
.connected = connected,
9871008
.disconnected = disconnected,
@@ -1008,6 +1029,9 @@ static struct bt_conn_cb conn_callbacks = {
10081029
#if defined(CONFIG_BT_PATH_LOSS_MONITORING)
10091030
.path_loss_threshold_report = path_loss_threshold_report,
10101031
#endif
1032+
#if defined(CONFIG_BT_SUBRATING)
1033+
.subrate_changed = subrate_changed,
1034+
#endif
10111035
};
10121036
#endif /* CONFIG_BT_CONN */
10131037

@@ -3022,6 +3046,74 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg
30223046
}
30233047
#endif
30243048

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

30263118
#if defined(CONFIG_BT_CONN)
30273119
#if defined(CONFIG_BT_CENTRAL)
@@ -3318,6 +3410,12 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
33183410
info.le.data_len->tx_max_time,
33193411
info.le.data_len->rx_max_len,
33203412
info.le.data_len->rx_max_time);
3413+
#endif
3414+
#if defined(CONFIG_BT_SUBRATING)
3415+
shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d"
3416+
" Continuation Number: %d",
3417+
info.le.subrate->factor,
3418+
info.le.subrate->continuation_number);
33213419
#endif
33223420
}
33233421

@@ -4719,6 +4817,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
47194817
SHELL_CMD_ARG(path-loss-monitoring-enable, NULL, "<enable: true, false>",
47204818
cmd_set_path_loss_reporting_enable, 2, 0),
47214819
#endif
4820+
#if defined(CONFIG_BT_SUBRATING)
4821+
SHELL_CMD_ARG(subrate-set-defaults, NULL,
4822+
"<min subrate factor> <max subrate factor> <max peripheral latency> "
4823+
"<min continuation number> <supervision timeout (seconds)>",
4824+
cmd_subrate_set_defaults, 6, 0),
4825+
SHELL_CMD_ARG(subrate-request, NULL,
4826+
"<min subrate factor> <max subrate factor> <max peripheral latency> "
4827+
"<min continuation number> <supervision timeout (seconds)>",
4828+
cmd_subrate_request, 6, 0),
4829+
#endif
47224830
#if defined(CONFIG_BT_BROADCASTER)
47234831
SHELL_CMD_ARG(advertise, NULL,
47244832
"<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)