Skip to content

Commit

Permalink
bluetooth: shell: Add CS to BT shell with set default settings command
Browse files Browse the repository at this point in the history
Use a new file and command for this where all CS commands
can live.

Added support for bt_cs_set_default_settings command.

Added test case where shell is built with CS to ensure code
is built in CI.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
  • Loading branch information
sean-madigan authored and aescolar committed Sep 16, 2024
1 parent aedb330 commit aa67cb2
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
4 changes: 4 additions & 0 deletions subsys/bluetooth/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ zephyr_library_sources_ifdef(
CONFIG_BT_ISO
iso.c
)
zephyr_library_sources_ifdef(
CONFIG_BT_CHANNEL_SOUNDING
cs.c
)
zephyr_library_sources_ifdef(
CONFIG_BT_IAS
ias.c
Expand Down
123 changes: 123 additions & 0 deletions subsys/bluetooth/shell/cs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/** @file
* @brief Bluetooth Channel Sounding (CS) shell
*
*/

/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/util.h>

#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/bluetooth/cs.h>
#include <errno.h>

#include "bt.h"

static int check_cs_sync_antenna_selection_input(uint16_t input)
{
if (input != BT_CS_ANTENNA_SELECTION_OPT_ONE && input != BT_CS_ANTENNA_SELECTION_OPT_TWO &&
input != BT_CS_ANTENNA_SELECTION_OPT_THREE &&
input != BT_CS_ANTENNA_SELECTION_OPT_FOUR &&
input != BT_CS_ANTENNA_SELECTION_OPT_REPETITIVE &&
input != BT_CS_ANTENNA_SELECTION_OPT_NO_RECOMMENDATION) {
return -EINVAL;
}

return 0;
}

static int cmd_set_default_settings(const struct shell *sh, size_t argc, char *argv[])
{
int err = 0;
struct bt_cs_set_default_settings_param params;
uint16_t antenna_input;
int16_t tx_power_input;

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

params.enable_initiator_role = shell_strtobool(argv[1], 10, &err);
if (err) {
shell_help(sh);
shell_error(sh, "Could not parse input 1, Enable initiator role");
return SHELL_CMD_HELP_PRINTED;
}

params.enable_reflector_role = shell_strtobool(argv[2], 10, &err);
if (err) {
shell_help(sh);
shell_error(sh, "Could not parse input 2, Enable reflector role");
return SHELL_CMD_HELP_PRINTED;
}

antenna_input = shell_strtoul(argv[3], 16, &err);
if (err) {
shell_help(sh);
shell_error(sh, "Could not parse input 3, CS_SYNC antenna selection");
return SHELL_CMD_HELP_PRINTED;
}

err = check_cs_sync_antenna_selection_input(antenna_input);
if (err) {
shell_help(sh);
shell_error(sh, "CS_SYNC antenna selection input invalid");
return SHELL_CMD_HELP_PRINTED;
}

tx_power_input = shell_strtol(argv[4], 10, &err);
if (err) {
shell_help(sh);
shell_error(sh, "Could not parse input 4, Max TX power");
return SHELL_CMD_HELP_PRINTED;
}

params.cs_sync_antenna_selection = antenna_input;
params.max_tx_power = tx_power_input;

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

return 0;
}

SHELL_STATIC_SUBCMD_SET_CREATE(
cs_cmds,
SHELL_CMD_ARG(
set_default_settings, NULL,
"<Enable initiator role: true, false> <Enable reflector role: true, false> "
" <CS_SYNC antenna selection: 0x01 - 0x04, 0xFE, 0xFF> <Max TX power: -127 - 20>",
cmd_set_default_settings, 5, 0),
SHELL_SUBCMD_SET_END);

static int cmd_cs(const struct shell *sh, size_t argc, char **argv)
{
if (argc == 1) {
shell_help(sh);

return SHELL_CMD_HELP_PRINTED;
}

shell_error(sh, "%s unknown parameter: %s", argv[0], argv[1]);

return -EINVAL;
}

SHELL_CMD_ARG_REGISTER(cs, &cs_cmds, "Bluetooth CS shell commands", cmd_cs, 1, 1);
7 changes: 7 additions & 0 deletions tests/bluetooth/shell/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ tests:
platform_allow:
- native_sim
build_only: true
bluetooth.shell.channel_sounding:
extra_configs:
- CONFIG_BT_CHANNEL_SOUNDING=y
- CONFIG_BT_CTLR=n
platform_allow:
- native_sim
build_only: true
bluetooth.shell.cdc_acm:
extra_args:
- OVERLAY_CONFIG=cdc_acm.conf
Expand Down

0 comments on commit aa67cb2

Please sign in to comment.