Skip to content

Commit

Permalink
[nrf fromtree] bluetooth: shell: Add shell commands for LE Connection…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
alexstanoev-nordic authored and rlubos committed Aug 5, 2024
1 parent 1c041e8 commit 64796d7
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
108 changes: 108 additions & 0 deletions subsys/bluetooth/shell/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,27 @@ void path_loss_threshold_report(struct bt_conn *conn,
}
#endif

#if defined(CONFIG_BT_SUBRATING)
void subrate_changed(struct bt_conn *conn,
const struct bt_conn_le_subrate_changed *params)
{
if (params->status == BT_HCI_ERR_SUCCESS) {
shell_print(ctx_shell, "Subrate parameters changed: "
"Subrate Factor: %d "
"Continuation Number: %d "
"Peripheral latency: 0x%04x "
"Supervision timeout: 0x%04x (%d ms)",
params->factor,
params->continuation_number,
params->peripheral_latency,
params->supervision_timeout,
params->supervision_timeout * 10);
} else {
shell_print(ctx_shell, "Subrate change failed (HCI status 0x%02x)", params->status);
}
}
#endif

static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
Expand All @@ -1008,6 +1029,9 @@ static struct bt_conn_cb conn_callbacks = {
#if defined(CONFIG_BT_PATH_LOSS_MONITORING)
.path_loss_threshold_report = path_loss_threshold_report,
#endif
#if defined(CONFIG_BT_SUBRATING)
.subrate_changed = subrate_changed,
#endif
};
#endif /* CONFIG_BT_CONN */

Expand Down Expand Up @@ -3022,6 +3046,74 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg
}
#endif

#if defined(CONFIG_BT_SUBRATING)
static int cmd_subrate_set_defaults(const struct shell *sh, size_t argc, char *argv[])
{
int err = 0;

for (size_t argn = 1; argn < argc; argn++) {
(void)shell_strtoul(argv[argn], 10, &err);

if (err) {
shell_help(sh);
shell_error(sh, "Could not parse input number %d", argn);
return SHELL_CMD_HELP_PRINTED;
}
}

const struct bt_conn_le_subrate_param params = {
.subrate_min = shell_strtoul(argv[1], 10, &err),
.subrate_max = shell_strtoul(argv[2], 10, &err),
.max_latency = shell_strtoul(argv[3], 10, &err),
.continuation_number = shell_strtoul(argv[4], 10, &err),
.supervision_timeout = shell_strtoul(argv[5], 10, &err) * 100, /* 10ms units */
};

err = bt_conn_le_subrate_set_defaults(&params);
if (err) {
shell_error(sh, "bt_conn_le_subrate_set_defaults returned error %d", err);
return -ENOEXEC;
}

return 0;
}

static int cmd_subrate_request(const struct shell *sh, size_t argc, char *argv[])
{
int err = 0;

if (default_conn == NULL) {
shell_error(sh, "Conn handle error, at least one connection is required.");
return -ENOEXEC;
}

for (size_t argn = 1; argn < argc; argn++) {
(void)shell_strtoul(argv[argn], 10, &err);

if (err) {
shell_help(sh);
shell_error(sh, "Could not parse input number %d", argn);
return SHELL_CMD_HELP_PRINTED;
}
}

const struct bt_conn_le_subrate_param params = {
.subrate_min = shell_strtoul(argv[1], 10, &err),
.subrate_max = shell_strtoul(argv[2], 10, &err),
.max_latency = shell_strtoul(argv[3], 10, &err),
.continuation_number = shell_strtoul(argv[4], 10, &err),
.supervision_timeout = shell_strtoul(argv[5], 10, &err) * 100, /* 10ms units */
};

err = bt_conn_le_subrate_request(default_conn, &params);
if (err) {
shell_error(sh, "bt_conn_le_subrate_request returned error %d", err);
return -ENOEXEC;
}

return 0;
}
#endif

#if defined(CONFIG_BT_CONN)
#if defined(CONFIG_BT_CENTRAL)
Expand Down Expand Up @@ -3318,6 +3410,12 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
info.le.data_len->tx_max_time,
info.le.data_len->rx_max_len,
info.le.data_len->rx_max_time);
#endif
#if defined(CONFIG_BT_SUBRATING)
shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d"
" Continuation Number: %d",
info.le.subrate->factor,
info.le.subrate->continuation_number);
#endif
}

Expand Down Expand Up @@ -4719,6 +4817,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
SHELL_CMD_ARG(path-loss-monitoring-enable, NULL, "<enable: true, false>",
cmd_set_path_loss_reporting_enable, 2, 0),
#endif
#if defined(CONFIG_BT_SUBRATING)
SHELL_CMD_ARG(subrate-set-defaults, NULL,
"<min subrate factor> <max subrate factor> <max peripheral latency> "
"<min continuation number> <supervision timeout (seconds)>",
cmd_subrate_set_defaults, 6, 0),
SHELL_CMD_ARG(subrate-request, NULL,
"<min subrate factor> <max subrate factor> <max peripheral latency> "
"<min continuation number> <supervision timeout (seconds)>",
cmd_subrate_request, 6, 0),
#endif
#if defined(CONFIG_BT_BROADCASTER)
SHELL_CMD_ARG(advertise, NULL,
"<type: off, on, nconn> [mode: discov, non_discov] "
Expand Down
7 changes: 7 additions & 0 deletions tests/bluetooth/shell/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ tests:
platform_allow:
- native_posix
build_only: true
bluetooth.shell.subrating:
extra_configs:
- CONFIG_BT_SUBRATING=y
- CONFIG_BT_CTLR=n
platform_allow:
- native_posix
build_only: true
bluetooth.shell.cdc_acm:
extra_args:
- OVERLAY_CONFIG=cdc_acm.conf
Expand Down

0 comments on commit 64796d7

Please sign in to comment.