From 835b1c1425397b798bf0457bf44112ec1397be69 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 29 Jul 2019 11:35:23 +0200 Subject: [PATCH] Bluetooth: Shell: Update sec level help text and validate input Update bluetooth help text to include FIPS level in help text. Also validate input range for the different connection types Bluetooth security level for LE is from 1-4, while BR/EDR is 0-3 Signed-off-by: Joakim Andersson --- subsys/bluetooth/shell/bt.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index bce851182ef..5e64e68a1fa 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -1048,14 +1048,27 @@ static int cmd_clear(const struct shell *shell, size_t argc, char *argv[]) static int cmd_security(const struct shell *shell, size_t argc, char *argv[]) { int err, sec; + struct bt_conn_info info; - if (!default_conn) { + if (!default_conn || (bt_conn_get_info(default_conn, &info) < 0)) { shell_error(shell, "Not connected"); return -ENOEXEC; } sec = *argv[1] - '0'; + if ((info.type == BT_CONN_TYPE_BR && + (sec < BT_SECURITY_NONE || sec > BT_SECURITY_HIGH))) { + shell_error(shell, "Invalid BR/EDR security level (%d)", sec); + return -ENOEXEC; + } + + if ((info.type == BT_CONN_TYPE_LE && + (sec < BT_SECURITY_LOW || sec > BT_SECURITY_FIPS))) { + shell_error(shell, "Invalid LE security level (%d)", sec); + return -ENOEXEC; + } + err = bt_conn_security(default_conn, sec); if (err) { shell_error(shell, "Setting security failed (err %d)", err); @@ -1492,7 +1505,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, SHELL_CMD_ARG(oob, NULL, NULL, cmd_oob, 1, 0), SHELL_CMD_ARG(clear, NULL, "", cmd_clear, 2, 1), #if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) - SHELL_CMD_ARG(security, NULL, "", + SHELL_CMD_ARG(security, NULL, "", cmd_security, 2, 0), SHELL_CMD_ARG(bondable, NULL, "", cmd_bondable, 2, 0),