diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 95766335bee..ae80938a51a 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -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, @@ -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 */ @@ -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(¶ms); + 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, ¶ms); + 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) @@ -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 } @@ -4719,6 +4817,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, SHELL_CMD_ARG(path-loss-monitoring-enable, NULL, "", cmd_set_path_loss_reporting_enable, 2, 0), #endif +#if defined(CONFIG_BT_SUBRATING) + SHELL_CMD_ARG(subrate-set-defaults, NULL, + " " + " ", + cmd_subrate_set_defaults, 6, 0), + SHELL_CMD_ARG(subrate-request, NULL, + " " + " ", + cmd_subrate_request, 6, 0), +#endif #if defined(CONFIG_BT_BROADCASTER) SHELL_CMD_ARG(advertise, NULL, " [mode: discov, non_discov] " diff --git a/tests/bluetooth/shell/testcase.yaml b/tests/bluetooth/shell/testcase.yaml index 3ddde520a86..eb6c7412053 100644 --- a/tests/bluetooth/shell/testcase.yaml +++ b/tests/bluetooth/shell/testcase.yaml @@ -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