subsys: shell: add int ret_val to command handlers
1. Command handler can return command exectution status as int. 2. Existing command handlers rework. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
0ce966bc28
commit
0eea1ef212
13 changed files with 564 additions and 372 deletions
|
@ -74,7 +74,7 @@ struct shell;
|
||||||
/**
|
/**
|
||||||
* @brief Shell command handler prototype.
|
* @brief Shell command handler prototype.
|
||||||
*/
|
*/
|
||||||
typedef void (*shell_cmd_handler)(const struct shell *shell,
|
typedef int (*shell_cmd_handler)(const struct shell *shell,
|
||||||
size_t argc, char **argv);
|
size_t argc, char **argv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -19,11 +19,11 @@ static u8_t dynamic_cmd_cnt;
|
||||||
typedef int cmp_t(const void *, const void *);
|
typedef int cmp_t(const void *, const void *);
|
||||||
extern void qsort(void *a, size_t n, size_t es, cmp_t *cmp);
|
extern void qsort(void *a, size_t n, size_t es, cmp_t *cmp);
|
||||||
|
|
||||||
static void cmd_dynamic(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_dynamic(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if ((argc == 1) || shell_help_requested(shell)) {
|
if ((argc == 1) || shell_help_requested(shell)) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
|
@ -33,6 +33,8 @@ static void cmd_dynamic(const struct shell *shell, size_t argc, char **argv)
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"%s: please specify subcommand\r\n", argv[0]);
|
"%s: please specify subcommand\r\n", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function required by qsort */
|
/* function required by qsort */
|
||||||
|
@ -41,7 +43,7 @@ static int string_cmp(const void *p_a, const void *p_b)
|
||||||
return strcmp((const char *)p_a, (const char *)p_b);
|
return strcmp((const char *)p_a, (const char *)p_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_dynamic_add(const struct shell *shell,
|
static int cmd_dynamic_add(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
u8_t idx;
|
u8_t idx;
|
||||||
|
@ -49,25 +51,25 @@ static void cmd_dynamic_add(const struct shell *shell,
|
||||||
|
|
||||||
if (shell_help_requested(shell)) {
|
if (shell_help_requested(shell)) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"%s: bad parameter count\r\n", argv[0]);
|
"%s: bad parameter count\r\n", argv[0]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic_cmd_cnt >= MAX_CMD_CNT) {
|
if (dynamic_cmd_cnt >= MAX_CMD_CNT) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "command limit reached\r\n");
|
shell_fprintf(shell, SHELL_ERROR, "command limit reached\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_len = strlen(argv[1]);
|
cmd_len = strlen(argv[1]);
|
||||||
|
|
||||||
if (cmd_len >= MAX_CMD_LEN) {
|
if (cmd_len >= MAX_CMD_LEN) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "too long command\r\n");
|
shell_fprintf(shell, SHELL_ERROR, "too long command\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (idx = 0; idx < cmd_len; idx++) {
|
for (idx = 0; idx < cmd_len; idx++) {
|
||||||
|
@ -75,7 +77,7 @@ static void cmd_dynamic_add(const struct shell *shell,
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"bad command name - please use only"
|
"bad command name - please use only"
|
||||||
" alphanumerical characters\r\n");
|
" alphanumerical characters\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ static void cmd_dynamic_add(const struct shell *shell,
|
||||||
if (!strcmp(dynamic_cmd_buffer[idx], argv[1])) {
|
if (!strcmp(dynamic_cmd_buffer[idx], argv[1])) {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"duplicated command\r\n");
|
"duplicated command\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,26 +95,28 @@ static void cmd_dynamic_add(const struct shell *shell,
|
||||||
sizeof(dynamic_cmd_buffer[0]), string_cmp);
|
sizeof(dynamic_cmd_buffer[0]), string_cmp);
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "command added successfully\r\n");
|
shell_fprintf(shell, SHELL_NORMAL, "command added successfully\r\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_dynamic_show(const struct shell *shell,
|
static int cmd_dynamic_show(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (shell_help_requested(shell)) {
|
if (shell_help_requested(shell)) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"%s: bad parameter count\r\n", argv[0]);
|
"%s: bad parameter count\r\n", argv[0]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic_cmd_cnt == 0) {
|
if (dynamic_cmd_cnt == 0) {
|
||||||
shell_fprintf(shell, SHELL_WARNING,
|
shell_fprintf(shell, SHELL_WARNING,
|
||||||
"Please add some commands first.\r\n");
|
"Please add some commands first.\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Dynamic command list:\r\n");
|
shell_fprintf(shell, SHELL_NORMAL, "Dynamic command list:\r\n");
|
||||||
|
@ -121,46 +125,50 @@ static void cmd_dynamic_show(const struct shell *shell,
|
||||||
shell_fprintf(shell, SHELL_NORMAL,
|
shell_fprintf(shell, SHELL_NORMAL,
|
||||||
"[%3d] %s\r\n", i, dynamic_cmd_buffer[i]);
|
"[%3d] %s\r\n", i, dynamic_cmd_buffer[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_dynamic_execute(const struct shell *shell,
|
static int cmd_dynamic_execute(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (shell_help_requested(shell)) {
|
if (shell_help_requested(shell)) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"%s: bad parameter count\r\n", argv[0]);
|
"%s: bad parameter count\r\n", argv[0]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u8_t idx = 0; idx < dynamic_cmd_cnt; idx++) {
|
for (u8_t idx = 0; idx < dynamic_cmd_cnt; idx++) {
|
||||||
if (!strcmp(dynamic_cmd_buffer[idx], argv[1])) {
|
if (!strcmp(dynamic_cmd_buffer[idx], argv[1])) {
|
||||||
shell_fprintf(shell, SHELL_NORMAL,
|
shell_fprintf(shell, SHELL_NORMAL,
|
||||||
"dynamic command: %s\r\n", argv[1]);
|
"dynamic command: %s\r\n", argv[1]);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"%s: uknown parameter: %s\r\n", argv[0], argv[1]);
|
"%s: uknown parameter: %s\r\n", argv[0], argv[1]);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_dynamic_remove(const struct shell *shell, size_t argc,
|
static int cmd_dynamic_remove(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
if ((argc == 1) || shell_help_requested(shell)) {
|
if ((argc == 1) || shell_help_requested(shell)) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"%s: bad parameter count\r\n", argv[0]);
|
"%s: bad parameter count\r\n", argv[0]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u8_t idx = 0; idx < dynamic_cmd_cnt; idx++) {
|
for (u8_t idx = 0; idx < dynamic_cmd_cnt; idx++) {
|
||||||
|
@ -177,11 +185,13 @@ static void cmd_dynamic_remove(const struct shell *shell, size_t argc,
|
||||||
--dynamic_cmd_cnt;
|
--dynamic_cmd_cnt;
|
||||||
shell_fprintf(shell, SHELL_NORMAL,
|
shell_fprintf(shell, SHELL_NORMAL,
|
||||||
"command removed successfully\r\n");
|
"command removed successfully\r\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"did not find command: %s\r\n", argv[1]);
|
"did not find command: %s\r\n", argv[1]);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dynamic command creation */
|
/* dynamic command creation */
|
||||||
|
|
|
@ -29,41 +29,46 @@ void timer_expired_handler(struct k_timer *timer)
|
||||||
|
|
||||||
K_TIMER_DEFINE(log_timer, timer_expired_handler, NULL);
|
K_TIMER_DEFINE(log_timer, timer_expired_handler, NULL);
|
||||||
|
|
||||||
static void cmd_log_test_start(const struct shell *shell, size_t argc,
|
static int cmd_log_test_start(const struct shell *shell, size_t argc,
|
||||||
char **argv, u32_t period)
|
char **argv, u32_t period)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_timer_start(&log_timer, period, period);
|
k_timer_start(&log_timer, period, period);
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Log test started\r\n");
|
shell_fprintf(shell, SHELL_NORMAL, "Log test started\r\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_test_start_demo(const struct shell *shell, size_t argc,
|
static int cmd_log_test_start_demo(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
cmd_log_test_start(shell, argc, argv, 200);
|
cmd_log_test_start(shell, argc, argv, 200);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_test_start_flood(const struct shell *shell, size_t argc,
|
static int cmd_log_test_start_flood(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
cmd_log_test_start(shell, argc, argv, 10);
|
cmd_log_test_start(shell, argc, argv, 10);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_test_stop(const struct shell *shell, size_t argc,
|
static int cmd_log_test_stop(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_timer_stop(&log_timer);
|
k_timer_stop(&log_timer);
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Log test stopped\r\n");
|
shell_fprintf(shell, SHELL_NORMAL, "Log test stopped\r\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
SHELL_CREATE_STATIC_SUBCMD_SET(sub_log_test_start)
|
SHELL_CREATE_STATIC_SUBCMD_SET(sub_log_test_start)
|
||||||
{
|
{
|
||||||
|
@ -86,15 +91,17 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_log_test)
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(log_test, &sub_log_test, "Log test", NULL);
|
SHELL_CMD_REGISTER(log_test, &sub_log_test, "Log test", NULL);
|
||||||
|
|
||||||
static void cmd_demo_ping(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_demo_ping(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "pong\r\n");
|
shell_fprintf(shell, SHELL_NORMAL, "pong\r\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_demo_params(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_demo_params(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
int cnt;
|
int cnt;
|
||||||
|
|
||||||
|
@ -103,15 +110,17 @@ static void cmd_demo_params(const struct shell *shell, size_t argc, char **argv)
|
||||||
shell_fprintf(shell, SHELL_NORMAL,
|
shell_fprintf(shell, SHELL_NORMAL,
|
||||||
" argv[%d] = %s\r\n", cnt, argv[cnt]);
|
" argv[%d] = %s\r\n", cnt, argv[cnt]);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_version(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_version(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL,
|
shell_fprintf(shell, SHELL_NORMAL,
|
||||||
"Zephyr version %s\r\n", KERNEL_VERSION_STRING);
|
"Zephyr version %s\r\n", KERNEL_VERSION_STRING);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CREATE_STATIC_SUBCMD_SET(sub_demo)
|
SHELL_CREATE_STATIC_SUBCMD_SET(sub_demo)
|
||||||
|
|
|
@ -45,7 +45,7 @@ NET_BUF_POOL_DEFINE(data_pool, 1, DATA_BREDR_MTU, BT_BUF_USER_DATA_MIN,
|
||||||
NET_BUF_POOL_DEFINE(sdp_client_pool, CONFIG_BT_MAX_CONN,
|
NET_BUF_POOL_DEFINE(sdp_client_pool, CONFIG_BT_MAX_CONN,
|
||||||
SDP_CLIENT_USER_BUF_LEN, BT_BUF_USER_DATA_MIN, NULL);
|
SDP_CLIENT_USER_BUF_LEN, BT_BUF_USER_DATA_MIN, NULL);
|
||||||
|
|
||||||
static void cmd_auth_pincode(const struct shell *shell,
|
static int cmd_auth_pincode(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
|
@ -61,38 +61,40 @@ static void cmd_auth_pincode(const struct shell *shell,
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
print(shell, "Not connected\n");
|
print(shell, "Not connected\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(argv[1]) > max) {
|
if (strlen(argv[1]) > max) {
|
||||||
print(shell, "PIN code value invalid - enter max %u digits\n",
|
print(shell, "PIN code value invalid - enter max %u digits\n",
|
||||||
max);
|
max);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "PIN code \"%s\" applied\n", argv[1]);
|
print(shell, "PIN code \"%s\" applied\n", argv[1]);
|
||||||
|
|
||||||
bt_conn_auth_pincode_entry(conn, argv[1]);
|
bt_conn_auth_pincode_entry(conn, argv[1]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
bt_addr_t addr;
|
bt_addr_t addr;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = str2bt_addr(argv[1], &addr);
|
err = str2bt_addr(argv[1], &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "Invalid peer address (err %d)\n", err);
|
print(shell, "Invalid peer address (err %d)\n", err);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = bt_conn_create_br(&addr, BT_BR_CONN_PARAM_DEFAULT);
|
conn = bt_conn_create_br(&addr, BT_BR_CONN_PARAM_DEFAULT);
|
||||||
|
@ -105,6 +107,8 @@ static void cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
/* unref connection obj in advance as app user */
|
/* unref connection obj in advance as app user */
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void br_device_found(const bt_addr_t *addr, s8_t rssi,
|
static void br_device_found(const bt_addr_t *addr, s8_t rssi,
|
||||||
|
@ -169,12 +173,12 @@ static void br_discovery_complete(struct bt_br_discovery_result *results,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_discovery(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_discovery(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *action;
|
const char *action;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc >= 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc >= 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = argv[1];
|
action = argv[1];
|
||||||
|
@ -196,21 +200,22 @@ static void cmd_discovery(const struct shell *shell, size_t argc, char *argv[])
|
||||||
ARRAY_SIZE(br_discovery_results),
|
ARRAY_SIZE(br_discovery_results),
|
||||||
br_discovery_complete) < 0) {
|
br_discovery_complete) < 0) {
|
||||||
print(shell, "Failed to start discovery\n");
|
print(shell, "Failed to start discovery\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "Discovery started\n");
|
print(shell, "Discovery started\n");
|
||||||
} else if (!strcmp(action, "off")) {
|
} else if (!strcmp(action, "off")) {
|
||||||
if (bt_br_discovery_stop()) {
|
if (bt_br_discovery_stop()) {
|
||||||
print(shell, "Failed to stop discovery\n");
|
print(shell, "Failed to stop discovery\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "Discovery stopped\n");
|
print(shell, "Discovery stopped\n");
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||||
|
@ -268,16 +273,16 @@ static struct bt_l2cap_server br_server = {
|
||||||
.accept = l2cap_accept,
|
.accept = l2cap_accept,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_l2cap_register(const struct shell *shell,
|
static int cmd_l2cap_register(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (br_server.psm) {
|
if (br_server.psm) {
|
||||||
print(shell, "Already registered\n");
|
print(shell, "Already registered\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
br_server.psm = strtoul(argv[1], NULL, 16);
|
br_server.psm = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -285,19 +290,22 @@ static void cmd_l2cap_register(const struct shell *shell,
|
||||||
if (bt_l2cap_br_server_register(&br_server) < 0) {
|
if (bt_l2cap_br_server_register(&br_server) < 0) {
|
||||||
error(shell, "Unable to register psm\n");
|
error(shell, "Unable to register psm\n");
|
||||||
br_server.psm = 0;
|
br_server.psm = 0;
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "L2CAP psm %u registered\n", br_server.psm);
|
print(shell, "L2CAP psm %u registered\n", br_server.psm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_discoverable(const struct shell *shell,
|
static int cmd_discoverable(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
const char *action;
|
const char *action;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = argv[1];
|
action = argv[1];
|
||||||
|
@ -308,25 +316,28 @@ static void cmd_discoverable(const struct shell *shell,
|
||||||
err = bt_br_set_discoverable(false);
|
err = bt_br_set_discoverable(false);
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "BR/EDR set/reset discoverable failed (err %d)\n",
|
print(shell, "BR/EDR set/reset discoverable failed (err %d)\n",
|
||||||
err);
|
err);
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "BR/EDR set/reset discoverable done\n");
|
print(shell, "BR/EDR set/reset discoverable done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_connectable(const struct shell *shell,
|
static int cmd_connectable(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
const char *action;
|
const char *action;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = argv[1];
|
action = argv[1];
|
||||||
|
@ -337,18 +348,21 @@ static void cmd_connectable(const struct shell *shell,
|
||||||
err = bt_br_set_connectable(false);
|
err = bt_br_set_connectable(false);
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "BR/EDR set/rest connectable failed (err %d)\n",
|
print(shell, "BR/EDR set/rest connectable failed (err %d)\n",
|
||||||
err);
|
err);
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "BR/EDR set/reset connectable done\n");
|
print(shell, "BR/EDR set/reset connectable done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_oob(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_oob(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
char addr[BT_ADDR_STR_LEN];
|
char addr[BT_ADDR_STR_LEN];
|
||||||
struct bt_br_oob oob;
|
struct bt_br_oob oob;
|
||||||
|
@ -357,13 +371,14 @@ static void cmd_oob(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = bt_br_oob_get_local(&oob);
|
err = bt_br_oob_get_local(&oob);
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "BR/EDR OOB data failed\n");
|
print(shell, "BR/EDR OOB data failed\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_addr_to_str(&oob.addr, addr, sizeof(addr));
|
bt_addr_to_str(&oob.addr, addr, sizeof(addr));
|
||||||
|
|
||||||
print(shell, "BR/EDR OOB data:\n");
|
print(shell, "BR/EDR OOB data:\n");
|
||||||
print(shell, " addr %s\n", addr);
|
print(shell, " addr %s\n", addr);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8_t sdp_hfp_ag_user(struct bt_conn *conn,
|
static u8_t sdp_hfp_ag_user(struct bt_conn *conn,
|
||||||
|
@ -495,7 +510,7 @@ static struct bt_sdp_discover_params discov_a2src = {
|
||||||
|
|
||||||
static struct bt_sdp_discover_params discov;
|
static struct bt_sdp_discover_params discov;
|
||||||
|
|
||||||
static void cmd_sdp_find_record(const struct shell *shell,
|
static int cmd_sdp_find_record(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err = 0, res;
|
int err = 0, res;
|
||||||
|
@ -503,11 +518,11 @@ static void cmd_sdp_find_record(const struct shell *shell,
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
print(shell, "Not connected\n");
|
print(shell, "Not connected\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = argv[1];
|
action = argv[1];
|
||||||
|
@ -518,13 +533,13 @@ static void cmd_sdp_find_record(const struct shell *shell,
|
||||||
discov = discov_a2src;
|
discov = discov_a2src;
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "SDP UUID to resolve not valid (err %d)\n", err);
|
error(shell, "SDP UUID to resolve not valid (err %d)\n", err);
|
||||||
print(shell, "Supported UUID are \'HFPAG\' \'A2SRC\' only\n");
|
print(shell, "Supported UUID are \'HFPAG\' \'A2SRC\' only\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "SDP UUID \'%s\' gets applied\n", action);
|
print(shell, "SDP UUID \'%s\' gets applied\n", action);
|
||||||
|
@ -532,9 +547,12 @@ static void cmd_sdp_find_record(const struct shell *shell,
|
||||||
res = bt_sdp_discover(default_conn, &discov);
|
res = bt_sdp_discover(default_conn, &discov);
|
||||||
if (res) {
|
if (res) {
|
||||||
error(shell, "SDP discovery failed: result %d\n", res);
|
error(shell, "SDP discovery failed: result %d\n", res);
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "SDP discovery started\n");
|
print(shell, "SDP discovery started\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HELP_NONE "[none]"
|
#define HELP_NONE "[none]"
|
||||||
|
@ -554,19 +572,21 @@ SHELL_CREATE_STATIC_SUBCMD_SET(br_cmds) {
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_br(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_br(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
||||||
"unknown parameter: ", argv[1]);
|
"unknown parameter: ", argv[1]);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(br, &br_cmds, "Bluetooth BR/EDR shell commands", cmd_br);
|
SHELL_CMD_REGISTER(br, &br_cmds, "Bluetooth BR/EDR shell commands", cmd_br);
|
||||||
|
|
|
@ -314,7 +314,7 @@ static void bt_ready(int err)
|
||||||
#endif /* CONFIG_BT_CONN */
|
#endif /* CONFIG_BT_CONN */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_init(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_init(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -324,6 +324,8 @@ static void cmd_init(const struct shell *shell, size_t argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx_shell = shell;
|
ctx_shell = shell;
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_HCI) || defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
#if defined(CONFIG_BT_HCI) || defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
||||||
|
@ -355,7 +357,7 @@ void hexdump(const struct shell *shell, const u8_t *data, size_t len)
|
||||||
#endif /* CONFIG_BT_HCI || CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
#endif /* CONFIG_BT_HCI || CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
||||||
|
|
||||||
#if defined(CONFIG_BT_HCI)
|
#if defined(CONFIG_BT_HCI)
|
||||||
static void cmd_hci_cmd(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_hci_cmd(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u8_t ogf;
|
u8_t ogf;
|
||||||
u16_t ocf;
|
u16_t ocf;
|
||||||
|
@ -363,7 +365,7 @@ static void cmd_hci_cmd(const struct shell *shell, size_t argc, char *argv[])
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 3), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 3), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ogf = strtoul(argv[1], NULL, 16);
|
ogf = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -382,14 +384,17 @@ static void cmd_hci_cmd(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = bt_hci_cmd_send_sync(BT_OP(ogf, ocf), buf, &rsp);
|
err = bt_hci_cmd_send_sync(BT_OP(ogf, ocf), buf, &rsp);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "HCI command failed (err %d)", err);
|
error(shell, "HCI command failed (err %d)", err);
|
||||||
|
return err;
|
||||||
} else {
|
} else {
|
||||||
hexdump(shell, rsp->data, rsp->len);
|
hexdump(shell, rsp->data, rsp->len);
|
||||||
net_buf_unref(rsp);
|
net_buf_unref(rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_HCI */
|
#endif /* CONFIG_BT_HCI */
|
||||||
|
|
||||||
static void cmd_name(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_name(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -400,10 +405,13 @@ static void cmd_name(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = bt_set_name(argv[1]);
|
err = bt_set_name(argv[1]);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Unable to set name %s (err %d)", argv[1], err);
|
error(shell, "Unable to set name %s (err %d)", argv[1], err);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_id_create(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_id_create(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
int err;
|
int err;
|
||||||
|
@ -424,9 +432,11 @@ static void cmd_id_create(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
print(shell, "New identity (%d) created: %s", err,
|
print(shell, "New identity (%d) created: %s", err,
|
||||||
bt_addr_le_str(&addr));
|
bt_addr_le_str(&addr));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_id_reset(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_id_reset(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
u8_t id;
|
u8_t id;
|
||||||
|
@ -434,7 +444,7 @@ static void cmd_id_reset(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
error(shell, "Identity identifier not specified");
|
error(shell, "Identity identifier not specified");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = strtol(argv[1], NULL, 10);
|
id = strtol(argv[1], NULL, 10);
|
||||||
|
@ -443,7 +453,7 @@ static void cmd_id_reset(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = str2bt_addr_le(argv[2], "random", &addr);
|
err = str2bt_addr_le(argv[2], "random", &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "Invalid address");
|
print(shell, "Invalid address");
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bt_addr_le_copy(&addr, BT_ADDR_LE_ANY);
|
bt_addr_le_copy(&addr, BT_ADDR_LE_ANY);
|
||||||
|
@ -452,20 +462,22 @@ static void cmd_id_reset(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = bt_id_reset(id, &addr, NULL);
|
err = bt_id_reset(id, &addr, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
print(shell, "Resetting ID %u failed (err %d)", id, err);
|
print(shell, "Resetting ID %u failed (err %d)", id, err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "Identity %u reset: %s", id, bt_addr_le_str(&addr));
|
print(shell, "Identity %u reset: %s", id, bt_addr_le_str(&addr));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_id_delete(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_id_delete(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u8_t id;
|
u8_t id;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
error(shell, "Identity identifier not specified");
|
error(shell, "Identity identifier not specified");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = strtol(argv[1], NULL, 10);
|
id = strtol(argv[1], NULL, 10);
|
||||||
|
@ -473,13 +485,15 @@ static void cmd_id_delete(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = bt_id_delete(id);
|
err = bt_id_delete(id);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
error(shell, "Deleting ID %u failed (err %d)", id, err);
|
error(shell, "Deleting ID %u failed (err %d)", id, err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "Identity %u deleted", id);
|
print(shell, "Identity %u deleted", id);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_id_show(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_id_show(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_addr_le_t addrs[CONFIG_BT_ID_MAX];
|
bt_addr_le_t addrs[CONFIG_BT_ID_MAX];
|
||||||
size_t i, count = CONFIG_BT_ID_MAX;
|
size_t i, count = CONFIG_BT_ID_MAX;
|
||||||
|
@ -490,9 +504,11 @@ static void cmd_id_show(const struct shell *shell, size_t argc, char *argv[])
|
||||||
print(shell, "%s%zu: %s", i == selected_id ? "*" : " ", i,
|
print(shell, "%s%zu: %s", i == selected_id ? "*" : " ", i,
|
||||||
bt_addr_le_str(&addrs[i]));
|
bt_addr_le_str(&addrs[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_id_select(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_id_select(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_addr_le_t addrs[CONFIG_BT_ID_MAX];
|
bt_addr_le_t addrs[CONFIG_BT_ID_MAX];
|
||||||
size_t count = CONFIG_BT_ID_MAX;
|
size_t count = CONFIG_BT_ID_MAX;
|
||||||
|
@ -500,7 +516,7 @@ static void cmd_id_select(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = strtol(argv[1], NULL, 10);
|
id = strtol(argv[1], NULL, 10);
|
||||||
|
@ -508,15 +524,17 @@ static void cmd_id_select(const struct shell *shell, size_t argc, char *argv[])
|
||||||
bt_id_get(addrs, &count);
|
bt_id_get(addrs, &count);
|
||||||
if (count <= id) {
|
if (count <= id) {
|
||||||
error(shell, "Invalid identity");
|
error(shell, "Invalid identity");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "Selected identity: %s",
|
print(shell, "Selected identity: %s",
|
||||||
bt_addr_le_str(&addrs[id]));
|
bt_addr_le_str(&addrs[id]));
|
||||||
selected_id = id;
|
selected_id = id;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_active_scan_on(const struct shell *shell, int dups)
|
static int cmd_active_scan_on(const struct shell *shell, int dups)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct bt_le_scan_param param = {
|
struct bt_le_scan_param param = {
|
||||||
|
@ -533,13 +551,15 @@ static void cmd_active_scan_on(const struct shell *shell, int dups)
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Bluetooth set active scan failed "
|
error(shell, "Bluetooth set active scan failed "
|
||||||
"(err %d)", err);
|
"(err %d)", err);
|
||||||
return;
|
return err;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Bluetooth active scan enabled");
|
print(shell, "Bluetooth active scan enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_passive_scan_on(const struct shell *shell, int dups)
|
static int cmd_passive_scan_on(const struct shell *shell, int dups)
|
||||||
{
|
{
|
||||||
struct bt_le_scan_param param = {
|
struct bt_le_scan_param param = {
|
||||||
.type = BT_HCI_LE_SCAN_PASSIVE,
|
.type = BT_HCI_LE_SCAN_PASSIVE,
|
||||||
|
@ -556,31 +576,36 @@ static void cmd_passive_scan_on(const struct shell *shell, int dups)
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Bluetooth set passive scan failed "
|
error(shell, "Bluetooth set passive scan failed "
|
||||||
"(err %d)", err);
|
"(err %d)", err);
|
||||||
return;
|
return err;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Bluetooth passive scan enabled");
|
print(shell, "Bluetooth passive scan enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_scan_off(const struct shell *shell)
|
static int cmd_scan_off(const struct shell *shell)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = bt_le_scan_stop();
|
err = bt_le_scan_stop();
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Stopping scanning failed (err %d)", err);
|
error(shell, "Stopping scanning failed (err %d)", err);
|
||||||
|
return err;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Scan successfully stopped");
|
print(shell, "Scan successfully stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_scan(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_scan(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *action;
|
const char *action;
|
||||||
int dups = -1;
|
int dups = -1;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse duplicate filtering data */
|
/* Parse duplicate filtering data */
|
||||||
|
@ -593,28 +618,29 @@ static void cmd_scan(const struct shell *shell, size_t argc, char *argv[])
|
||||||
dups = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE;
|
dups = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE;
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
action = argv[1];
|
action = argv[1];
|
||||||
if (!strcmp(action, "on")) {
|
if (!strcmp(action, "on")) {
|
||||||
cmd_active_scan_on(shell, dups);
|
return cmd_active_scan_on(shell, dups);
|
||||||
} else if (!strcmp(action, "off")) {
|
} else if (!strcmp(action, "off")) {
|
||||||
cmd_scan_off(shell);
|
return cmd_scan_off(shell);
|
||||||
} else if (!strcmp(action, "passive")) {
|
} else if (!strcmp(action, "passive")) {
|
||||||
cmd_passive_scan_on(shell, dups);
|
return cmd_passive_scan_on(shell, dups);
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct bt_data ad_discov[] = {
|
static const struct bt_data ad_discov[] = {
|
||||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_advertise(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_advertise(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_le_adv_param param;
|
struct bt_le_adv_param param;
|
||||||
const struct bt_data *ad, *scan_rsp;
|
const struct bt_data *ad, *scan_rsp;
|
||||||
|
@ -622,17 +648,18 @@ static void cmd_advertise(const struct shell *shell, size_t argc, char *argv[])
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "off")) {
|
if (!strcmp(argv[1], "off")) {
|
||||||
if (bt_le_adv_stop() < 0) {
|
if (bt_le_adv_stop() < 0) {
|
||||||
error(shell, "Failed to stop advertising");
|
error(shell, "Failed to stop advertising");
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Advertising stopped");
|
print(shell, "Advertising stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
param.id = selected_id;
|
param.id = selected_id;
|
||||||
|
@ -674,18 +701,20 @@ static void cmd_advertise(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
error(shell, "Failed to start advertising (err %d)",
|
error(shell, "Failed to start advertising (err %d)",
|
||||||
err);
|
err);
|
||||||
|
return err;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Advertising started");
|
print(shell, "Advertising started");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_CONN)
|
#if defined(CONFIG_BT_CONN)
|
||||||
static void cmd_connect_le(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_connect_le(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
|
@ -693,19 +722,20 @@ static void cmd_connect_le(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Invalid peer address (err %d)", err);
|
error(shell, "Invalid peer address (err %d)", err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = bt_conn_create_le(&addr, BT_LE_CONN_PARAM_DEFAULT);
|
conn = bt_conn_create_le(&addr, BT_LE_CONN_PARAM_DEFAULT);
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
error(shell, "Connection failed");
|
error(shell, "Connection failed");
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
print(shell, "Connection pending");
|
print(shell, "Connection pending");
|
||||||
|
@ -713,9 +743,11 @@ static void cmd_connect_le(const struct shell *shell, size_t argc, char *argv[])
|
||||||
/* unref connection obj in advance as app user */
|
/* unref connection obj in advance as app user */
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
int err;
|
int err;
|
||||||
|
@ -727,14 +759,14 @@ static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Invalid peer address (err %d)",
|
error(shell, "Invalid peer address (err %d)",
|
||||||
err);
|
err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = bt_conn_lookup_addr_le(selected_id, &addr);
|
conn = bt_conn_lookup_addr_le(selected_id, &addr);
|
||||||
|
@ -742,45 +774,50 @@ static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
error(shell, "Not connected");
|
error(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
|
err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Disconnection failed (err %d)", err);
|
error(shell, "Disconnection failed (err %d)", err);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_auto_conn(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_auto_conn(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Invalid peer address (err %d)", err);
|
error(shell, "Invalid peer address (err %d)", err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT);
|
return bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT);
|
||||||
} else if (!strcmp(argv[3], "on")) {
|
} else if (!strcmp(argv[3], "on")) {
|
||||||
bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT);
|
return bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT);
|
||||||
} else if (!strcmp(argv[3], "off")) {
|
} else if (!strcmp(argv[3], "off")) {
|
||||||
bt_le_set_auto_conn(&addr, NULL);
|
return bt_le_set_auto_conn(&addr, NULL);
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_directed_adv(const struct shell *shell,
|
static int cmd_directed_adv(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -789,13 +826,13 @@ static void cmd_directed_adv(const struct shell *shell,
|
||||||
struct bt_le_adv_param *param = BT_LE_ADV_CONN_DIR;
|
struct bt_le_adv_param *param = BT_LE_ADV_CONN_DIR;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Invalid peer address (err %d)", err);
|
error(shell, "Invalid peer address (err %d)", err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
|
@ -803,41 +840,44 @@ static void cmd_directed_adv(const struct shell *shell,
|
||||||
param = BT_LE_ADV_CONN_DIR_LOW_DUTY;
|
param = BT_LE_ADV_CONN_DIR_LOW_DUTY;
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = bt_conn_create_slave_le(&addr, param);
|
conn = bt_conn_create_slave_le(&addr, param);
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
error(shell, "Failed to start directed advertising");
|
error(shell, "Failed to start directed advertising");
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Started directed advertising");
|
print(shell, "Started directed advertising");
|
||||||
|
|
||||||
/* unref connection obj in advance as app user */
|
/* unref connection obj in advance as app user */
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_select(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_select(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 3, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 3, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Invalid peer address (err %d)", err);
|
error(shell, "Invalid peer address (err %d)", err);
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &addr);
|
conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &addr);
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
error(shell, "No matching connection found");
|
error(shell, "No matching connection found");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (default_conn) {
|
if (default_conn) {
|
||||||
|
@ -845,16 +885,18 @@ static void cmd_select(const struct shell *shell, size_t argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
default_conn = conn;
|
default_conn = conn;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_conn_update(const struct shell *shell,
|
static int cmd_conn_update(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_le_conn_param param;
|
struct bt_le_conn_param param;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 5, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 5, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
param.interval_min = strtoul(argv[1], NULL, 16);
|
param.interval_min = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -868,9 +910,11 @@ static void cmd_conn_update(const struct shell *shell,
|
||||||
} else {
|
} else {
|
||||||
print(shell, "conn update initiated.");
|
print(shell, "conn update initiated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_oob(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_oob(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
char addr[BT_ADDR_LE_STR_LEN];
|
char addr[BT_ADDR_LE_STR_LEN];
|
||||||
struct bt_le_oob oob;
|
struct bt_le_oob oob;
|
||||||
|
@ -879,23 +923,25 @@ static void cmd_oob(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = bt_le_oob_get_local(selected_id, &oob);
|
err = bt_le_oob_get_local(selected_id, &oob);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "OOB data failed");
|
error(shell, "OOB data failed");
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_addr_le_to_str(&oob.addr, addr, sizeof(addr));
|
bt_addr_le_to_str(&oob.addr, addr, sizeof(addr));
|
||||||
|
|
||||||
print(shell, "OOB data:");
|
print(shell, "OOB data:");
|
||||||
print(shell, " addr %s", addr);
|
print(shell, " addr %s", addr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_clear(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_clear(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
error(shell, "Specify remote address or \"all\"");
|
error(shell, "Specify remote address or \"all\"");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[1], "all") == 0) {
|
if (strcmp(argv[1], "all") == 0) {
|
||||||
|
@ -903,11 +949,12 @@ static void cmd_clear(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Failed to clear pairings (err %d)",
|
error(shell, "Failed to clear pairings (err %d)",
|
||||||
err);
|
err);
|
||||||
|
return err;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Pairings successfully cleared");
|
print(shell, "Pairings successfully cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
|
@ -916,7 +963,7 @@ static void cmd_clear(const struct shell *shell, size_t argc, char *argv[])
|
||||||
err = str2bt_addr(argv[1], &addr.a);
|
err = str2bt_addr(argv[1], &addr.a);
|
||||||
#else
|
#else
|
||||||
print(shell, "Both address and address type needed");
|
print(shell, "Both address and address type needed");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
err = str2bt_addr_le(argv[1], argv[2], &addr);
|
||||||
|
@ -924,7 +971,7 @@ static void cmd_clear(const struct shell *shell, size_t argc, char *argv[])
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "Invalid address");
|
print(shell, "Invalid address");
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_unpair(selected_id, &addr);
|
err = bt_unpair(selected_id, &addr);
|
||||||
|
@ -933,21 +980,23 @@ static void cmd_clear(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Pairing successfully cleared");
|
print(shell, "Pairing successfully cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_chan_map(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_chan_map(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u8_t chan_map[5];
|
u8_t chan_map[5];
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = hexstr2array(argv[1], chan_map, 5);
|
err = hexstr2array(argv[1], chan_map, 5);
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Invalid channel map");
|
error(shell, "Invalid channel map");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_le_set_chan_map(chan_map);
|
err = bt_le_set_chan_map(chan_map);
|
||||||
|
@ -956,21 +1005,23 @@ static void cmd_chan_map(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Channel map set");
|
print(shell, "Channel map set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_CONN */
|
#endif /* CONFIG_BT_CONN */
|
||||||
|
|
||||||
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
|
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
|
||||||
static void cmd_security(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;
|
int err, sec;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected");
|
error(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sec = *argv[1] - '0';
|
sec = *argv[1] - '0';
|
||||||
|
@ -979,14 +1030,16 @@ static void cmd_security(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Setting security failed (err %d)", err);
|
error(shell, "Setting security failed (err %d)", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_bondable(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_bondable(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *bondable;
|
const char *bondable;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bondable = argv[1];
|
bondable = argv[1];
|
||||||
|
@ -997,6 +1050,8 @@ static void cmd_bondable(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
|
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
|
||||||
|
@ -1169,10 +1224,10 @@ static struct bt_conn_auth_cb auth_cb_all = {
|
||||||
.pairing_complete = auth_pairing_complete,
|
.pairing_complete = auth_pairing_complete,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_auth(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_auth(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "all")) {
|
if (!strcmp(argv[1], "all")) {
|
||||||
|
@ -1190,9 +1245,11 @@ static void cmd_auth(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_auth_cancel(const struct shell *shell,
|
static int cmd_auth_cancel(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
|
@ -1207,36 +1264,40 @@ static void cmd_auth_cancel(const struct shell *shell,
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
print(shell, "Not connected");
|
print(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_auth_cancel(conn);
|
bt_conn_auth_cancel(conn);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_auth_passkey_confirm(const struct shell *shell,
|
static int cmd_auth_passkey_confirm(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
print(shell, "Not connected");
|
print(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_auth_passkey_confirm(default_conn);
|
bt_conn_auth_passkey_confirm(default_conn);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_auth_pairing_confirm(const struct shell *shell,
|
static int cmd_auth_pairing_confirm(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
print(shell, "Not connected");
|
print(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_auth_pairing_confirm(default_conn);
|
bt_conn_auth_pairing_confirm(default_conn);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_FIXED_PASSKEY)
|
#if defined(CONFIG_BT_FIXED_PASSKEY)
|
||||||
static void cmd_fixed_passkey(const struct shell *shell,
|
static int cmd_fixed_passkey(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned int passkey;
|
unsigned int passkey;
|
||||||
|
@ -1245,43 +1306,46 @@ static void cmd_fixed_passkey(const struct shell *shell,
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
bt_passkey_set(BT_PASSKEY_INVALID);
|
bt_passkey_set(BT_PASSKEY_INVALID);
|
||||||
print(shell, "Fixed passkey cleared");
|
print(shell, "Fixed passkey cleared");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
passkey = atoi(argv[1]);
|
passkey = atoi(argv[1]);
|
||||||
if (passkey > 999999) {
|
if (passkey > 999999) {
|
||||||
print(shell, "Passkey should be between 0-999999");
|
print(shell, "Passkey should be between 0-999999");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_passkey_set(passkey);
|
err = bt_passkey_set(passkey);
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "Setting fixed passkey failed (err %d)", err);
|
print(shell, "Setting fixed passkey failed (err %d)", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void cmd_auth_passkey(const struct shell *shell,
|
static int cmd_auth_passkey(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned int passkey;
|
unsigned int passkey;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
print(shell, "Not connected");
|
print(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
passkey = atoi(argv[1]);
|
passkey = atoi(argv[1]);
|
||||||
if (passkey > 999999) {
|
if (passkey > 999999) {
|
||||||
print(shell, "Passkey should be between 0-999999");
|
print(shell, "Passkey should be between 0-999999");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_auth_passkey_entry(default_conn, passkey);
|
bt_conn_auth_passkey_entry(default_conn, passkey);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_SMP) || CONFIG_BT_BREDR */
|
#endif /* CONFIG_BT_SMP) || CONFIG_BT_BREDR */
|
||||||
|
|
||||||
|
@ -1348,18 +1412,19 @@ SHELL_CREATE_STATIC_SUBCMD_SET(bt_cmds) {
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_bt(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_bt(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
error(shell, "%s:%s%s", argv[0], "unknown parameter: ", argv[1]);
|
error(shell, "%s:%s%s", argv[0], "unknown parameter: ", argv[1]);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(bt, &bt_cmds, "Bluetooth shell commands", cmd_bt);
|
SHELL_CMD_REGISTER(bt, &bt_cmds, "Bluetooth shell commands", cmd_bt);
|
||||||
|
|
|
@ -36,14 +36,14 @@ static void exchange_func(struct bt_conn *conn, u8_t err,
|
||||||
|
|
||||||
static struct bt_gatt_exchange_params exchange_params;
|
static struct bt_gatt_exchange_params exchange_params;
|
||||||
|
|
||||||
static void cmd_exchange_mtu(const struct shell *shell,
|
static int cmd_exchange_mtu(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
print(shell, "Not connected\n");
|
print(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
exchange_params.func = exchange_func;
|
exchange_params.func = exchange_func;
|
||||||
|
@ -54,6 +54,8 @@ static void cmd_exchange_mtu(const struct shell *shell,
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Exchange pending\n");
|
print(shell, "Exchange pending\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_gatt_discover_params discover_params;
|
static struct bt_gatt_discover_params discover_params;
|
||||||
|
@ -146,13 +148,13 @@ static u8_t discover_func(struct bt_conn *conn,
|
||||||
return BT_GATT_ITER_CONTINUE;
|
return BT_GATT_ITER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_discover(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_discover(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
discover_params.func = discover_func;
|
discover_params.func = discover_func;
|
||||||
|
@ -192,6 +194,8 @@ static void cmd_discover(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Discover pending\n");
|
print(shell, "Discover pending\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_gatt_read_params read_params;
|
static struct bt_gatt_read_params read_params;
|
||||||
|
@ -210,19 +214,19 @@ static u8_t read_func(struct bt_conn *conn, u8_t err,
|
||||||
return BT_GATT_ITER_CONTINUE;
|
return BT_GATT_ITER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_read(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_read(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_params.func = read_func;
|
read_params.func = read_func;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_params.handle_count = 1;
|
read_params.handle_count = 1;
|
||||||
|
@ -239,26 +243,28 @@ static void cmd_read(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Read pending\n");
|
print(shell, "Read pending\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_mread(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_mread(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u16_t h[8];
|
u16_t h[8];
|
||||||
int i, err;
|
int i, err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 3), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 3), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc - 1 > ARRAY_SIZE(h)) {
|
if (argc - 1 > ARRAY_SIZE(h)) {
|
||||||
print(shell, "Enter max %lu handle items to read\n",
|
print(shell, "Enter max %lu handle items to read\n",
|
||||||
ARRAY_SIZE(h));
|
ARRAY_SIZE(h));
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc - 1; i++) {
|
for (i = 0; i < argc - 1; i++) {
|
||||||
|
@ -274,6 +280,8 @@ static void cmd_mread(const struct shell *shell, size_t argc, char *argv[])
|
||||||
error(shell, "GATT multiple read request failed (err %d)\n",
|
error(shell, "GATT multiple read request failed (err %d)\n",
|
||||||
err);
|
err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_gatt_write_params write_params;
|
static struct bt_gatt_write_params write_params;
|
||||||
|
@ -287,23 +295,23 @@ static void write_func(struct bt_conn *conn, u8_t err,
|
||||||
(void)memset(&write_params, 0, sizeof(write_params));
|
(void)memset(&write_params, 0, sizeof(write_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_write(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_write(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
u16_t handle, offset;
|
u16_t handle, offset;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_params.func) {
|
if (write_params.func) {
|
||||||
error(shell, "Write ongoing\n");
|
error(shell, "Write ongoing\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 4), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 4), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = strtoul(argv[1], NULL, 16);
|
handle = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -335,9 +343,11 @@ static void cmd_write(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Write pending\n");
|
print(shell, "Write pending\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_write_without_rsp(const struct shell *shell,
|
static int cmd_write_without_rsp(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u16_t handle;
|
u16_t handle;
|
||||||
|
@ -348,11 +358,11 @@ static void cmd_write_without_rsp(const struct shell *shell,
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 3), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 3), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sign = !strcmp(argv[0], "signed-write");
|
sign = !strcmp(argv[0], "signed-write");
|
||||||
|
@ -389,6 +399,7 @@ static void cmd_write_without_rsp(const struct shell *shell,
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "Write Complete (err %d)\n", err);
|
print(shell, "Write Complete (err %d)\n", err);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_gatt_subscribe_params subscribe_params;
|
static struct bt_gatt_subscribe_params subscribe_params;
|
||||||
|
@ -408,23 +419,23 @@ static u8_t notify_func(struct bt_conn *conn,
|
||||||
return BT_GATT_ITER_CONTINUE;
|
return BT_GATT_ITER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_subscribe(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_subscribe(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (subscribe_params.value_handle) {
|
if (subscribe_params.value_handle) {
|
||||||
error(shell, "Cannot subscribe: subscription to %x already "
|
error(shell, "Cannot subscribe: subscription to %x already "
|
||||||
"exists\n", subscribe_params.value_handle);
|
"exists\n", subscribe_params.value_handle);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc >= 3), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc >= 3), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe_params.ccc_handle = strtoul(argv[1], NULL, 16);
|
subscribe_params.ccc_handle = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -442,21 +453,23 @@ static void cmd_subscribe(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Subscribed\n");
|
print(shell, "Subscribed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_unsubscribe(const struct shell *shell,
|
static int cmd_unsubscribe(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected\n");
|
error(shell, "Not connected\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!subscribe_params.value_handle) {
|
if (!subscribe_params.value_handle) {
|
||||||
error(shell, "No subscription found\n");
|
error(shell, "No subscription found\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_gatt_unsubscribe(default_conn, &subscribe_params);
|
err = bt_gatt_unsubscribe(default_conn, &subscribe_params);
|
||||||
|
@ -465,6 +478,8 @@ static void cmd_unsubscribe(const struct shell *shell,
|
||||||
} else {
|
} else {
|
||||||
print(shell, "Unsubscribe success\n");
|
print(shell, "Unsubscribe success\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_GATT_CLIENT */
|
#endif /* CONFIG_BT_GATT_CLIENT */
|
||||||
|
|
||||||
|
@ -478,9 +493,10 @@ static u8_t print_attr(const struct bt_gatt_attr *attr, void *user_data)
|
||||||
return BT_GATT_ITER_CONTINUE;
|
return BT_GATT_ITER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_show_db(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_show_db(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_gatt_foreach_attr(0x0001, 0xffff, print_attr, (void *)shell);
|
bt_gatt_foreach_attr(0x0001, 0xffff, print_attr, (void *)shell);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Custom Service Variables */
|
/* Custom Service Variables */
|
||||||
|
@ -625,22 +641,24 @@ static struct bt_gatt_attr vnd1_attrs[] = {
|
||||||
|
|
||||||
static struct bt_gatt_service vnd1_svc = BT_GATT_SERVICE(vnd1_attrs);
|
static struct bt_gatt_service vnd1_svc = BT_GATT_SERVICE(vnd1_attrs);
|
||||||
|
|
||||||
static void cmd_register_test_svc(const struct shell *shell,
|
static int cmd_register_test_svc(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_gatt_service_register(&vnd_svc);
|
bt_gatt_service_register(&vnd_svc);
|
||||||
bt_gatt_service_register(&vnd1_svc);
|
bt_gatt_service_register(&vnd1_svc);
|
||||||
|
|
||||||
print(shell, "Registering test vendor services\n");
|
print(shell, "Registering test vendor services\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_unregister_test_svc(const struct shell *shell,
|
static int cmd_unregister_test_svc(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
bt_gatt_service_unregister(&vnd_svc);
|
bt_gatt_service_unregister(&vnd_svc);
|
||||||
bt_gatt_service_unregister(&vnd1_svc);
|
bt_gatt_service_unregister(&vnd1_svc);
|
||||||
|
|
||||||
print(shell, "Unregistering test vendor services\n");
|
print(shell, "Unregistering test vendor services\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_uuid_128 met_svc_uuid = BT_UUID_INIT_128(
|
static struct bt_uuid_128 met_svc_uuid = BT_UUID_INIT_128(
|
||||||
|
@ -715,7 +733,7 @@ static struct bt_gatt_attr met_attrs[] = {
|
||||||
|
|
||||||
static struct bt_gatt_service met_svc = BT_GATT_SERVICE(met_attrs);
|
static struct bt_gatt_service met_svc = BT_GATT_SERVICE(met_attrs);
|
||||||
|
|
||||||
static void cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -723,7 +741,7 @@ static void cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
||||||
print(shell, "Write: count= %u, len= %u, rate= %u bps.\n",
|
print(shell, "Write: count= %u, len= %u, rate= %u bps.\n",
|
||||||
write_count, write_len, write_rate);
|
write_count, write_len, write_rate);
|
||||||
|
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "on")) {
|
if (!strcmp(argv[1], "on")) {
|
||||||
|
@ -741,12 +759,14 @@ static void cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
error(shell, "Incorrect value: %s\n", argv[1]);
|
error(shell, "Incorrect value: %s\n", argv[1]);
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
print(shell, "GATT write cmd metrics %s.\n", argv[1]);
|
print(shell, "GATT write cmd metrics %s.\n", argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HELP_NONE "[none]"
|
#define HELP_NONE "[none]"
|
||||||
|
@ -791,18 +811,19 @@ SHELL_CREATE_STATIC_SUBCMD_SET(gatt_cmds) {
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_gatt(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_gatt(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
error(shell, "%s:%s%s\r\n", argv[0], "unknown parameter: ", argv[1]);
|
error(shell, "%s:%s%s\r\n", argv[0], "unknown parameter: ", argv[1]);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(gatt, &gatt_cmds, "Bluetooth GATT shell commands", cmd_gatt);
|
SHELL_CMD_REGISTER(gatt, &gatt_cmds, "Bluetooth GATT shell commands", cmd_gatt);
|
||||||
|
|
|
@ -163,16 +163,16 @@ static struct bt_l2cap_server server = {
|
||||||
.accept = l2cap_accept,
|
.accept = l2cap_accept,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_register(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_register(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc >= 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc >= 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.psm) {
|
if (server.psm) {
|
||||||
error(shell, "Already registered");
|
error(shell, "Already registered");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
server.psm = strtoul(argv[1], NULL, 16);
|
server.psm = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -184,29 +184,32 @@ static void cmd_register(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (bt_l2cap_server_register(&server) < 0) {
|
if (bt_l2cap_server_register(&server) < 0) {
|
||||||
error(shell, "Unable to register psm");
|
error(shell, "Unable to register psm");
|
||||||
server.psm = 0;
|
server.psm = 0;
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "L2CAP psm %u sec_level %u registered",
|
print(shell, "L2CAP psm %u sec_level %u registered",
|
||||||
server.psm, server.sec_level);
|
server.psm, server.sec_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u16_t psm;
|
u16_t psm;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected");
|
error(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2ch_chan.ch.chan.conn) {
|
if (l2ch_chan.ch.chan.conn) {
|
||||||
error(shell, "Channel already in use");
|
error(shell, "Channel already in use");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
psm = strtoul(argv[1], NULL, 16);
|
psm = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -218,9 +221,11 @@ static void cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "L2CAP connection pending");
|
print(shell, "L2CAP connection pending");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -228,9 +233,11 @@ static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (err) {
|
if (err) {
|
||||||
print(shell, "Unable to disconnect: %u", -err);
|
print(shell, "Unable to disconnect: %u", -err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_send(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_send(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
static u8_t buf_data[DATA_MTU] = { [0 ... (DATA_MTU - 1)] = 0xff };
|
static u8_t buf_data[DATA_MTU] = { [0 ... (DATA_MTU - 1)] = 0xff };
|
||||||
int ret, len, count = 1;
|
int ret, len, count = 1;
|
||||||
|
@ -251,12 +258,14 @@ static void cmd_send(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
print(shell, "Unable to send: %d", -ret);
|
print(shell, "Unable to send: %d", -ret);
|
||||||
net_buf_unref(buf);
|
net_buf_unref(buf);
|
||||||
break;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_recv(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_recv(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
l2cap_recv_delay = strtoul(argv[1], NULL, 10);
|
l2cap_recv_delay = strtoul(argv[1], NULL, 10);
|
||||||
|
@ -264,16 +273,18 @@ static void cmd_recv(const struct shell *shell, size_t argc, char *argv[])
|
||||||
print(shell, "l2cap receive delay: %u ms",
|
print(shell, "l2cap receive delay: %u ms",
|
||||||
l2cap_recv_delay);
|
l2cap_recv_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *action;
|
const char *action;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
print(shell, "l2cap rate: %u bps.", l2cap_rate);
|
print(shell, "l2cap rate: %u bps.", l2cap_rate);
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = argv[1];
|
action = argv[1];
|
||||||
|
@ -284,10 +295,11 @@ static void cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
|
||||||
l2cap_ops.recv = l2cap_recv;
|
l2cap_ops.recv = l2cap_recv;
|
||||||
} else {
|
} else {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(shell, "l2cap metrics %s.", action);
|
print(shell, "l2cap metrics %s.", action);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HELP_NONE "[none]"
|
#define HELP_NONE "[none]"
|
||||||
|
@ -302,18 +314,19 @@ SHELL_CREATE_STATIC_SUBCMD_SET(l2cap_cmds) {
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_l2cap(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_l2cap(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
error(shell, "%s:%s%s", argv[0], "unknown parameter: ", argv[1]);
|
error(shell, "%s:%s%s", argv[0], "unknown parameter: ", argv[1]);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(l2cap, &l2cap_cmds, "Bluetooth L2CAP shell commands",
|
SHELL_CMD_REGISTER(l2cap, &l2cap_cmds, "Bluetooth L2CAP shell commands",
|
||||||
|
|
|
@ -145,13 +145,13 @@ struct bt_rfcomm_server rfcomm_server = {
|
||||||
.accept = &rfcomm_accept,
|
.accept = &rfcomm_accept,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_register(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_register(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (rfcomm_server.channel) {
|
if (rfcomm_server.channel) {
|
||||||
error(shell, "Already registered");
|
error(shell, "Already registered");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
rf_shell = shell;
|
rf_shell = shell;
|
||||||
|
@ -161,25 +161,28 @@ static void cmd_register(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error(shell, "Unable to register channel %x", ret);
|
error(shell, "Unable to register channel %x", ret);
|
||||||
rfcomm_server.channel = 0;
|
rfcomm_server.channel = 0;
|
||||||
|
return -ENOEXEC;
|
||||||
} else {
|
} else {
|
||||||
print(shell, "RFCOMM channel %u registered",
|
print(shell, "RFCOMM channel %u registered",
|
||||||
rfcomm_server.channel);
|
rfcomm_server.channel);
|
||||||
bt_sdp_register_service(&spp_rec);
|
bt_sdp_register_service(&spp_rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u8_t channel;
|
u8_t channel;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!default_conn) {
|
if (!default_conn) {
|
||||||
error(shell, "Not connected");
|
error(shell, "Not connected");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
if (!shell_cmd_precheck(shell, argc == 2, NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = strtoul(argv[1], NULL, 16);
|
channel = strtoul(argv[1], NULL, 16);
|
||||||
|
@ -191,9 +194,11 @@ static void cmd_connect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
print(shell, "RFCOMM connection pending");
|
print(shell, "RFCOMM connection pending");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_send(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_send(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
u8_t buf_data[DATA_MTU] = { [0 ... (DATA_MTU - 1)] = 0xff };
|
u8_t buf_data[DATA_MTU] = { [0 ... (DATA_MTU - 1)] = 0xff };
|
||||||
int ret, len, count = 1;
|
int ret, len, count = 1;
|
||||||
|
@ -213,12 +218,14 @@ static void cmd_send(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error(shell, "Unable to send: %d", -ret);
|
error(shell, "Unable to send: %d", -ret);
|
||||||
net_buf_unref(buf);
|
net_buf_unref(buf);
|
||||||
break;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
static int cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -226,6 +233,8 @@ static void cmd_disconnect(const struct shell *shell, size_t argc, char *argv[])
|
||||||
if (err) {
|
if (err) {
|
||||||
error(shell, "Unable to disconnect: %u", -err);
|
error(shell, "Unable to disconnect: %u", -err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HELP_NONE "[none]"
|
#define HELP_NONE "[none]"
|
||||||
|
@ -239,18 +248,19 @@ SHELL_CREATE_STATIC_SUBCMD_SET(rfcomm_cmds) {
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_rfcomm(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_rfcomm(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
error(shell, "%s:%s%s", argv[0], "unknown parameter: ", argv[1]);
|
error(shell, "%s:%s%s", argv[0], "unknown parameter: ", argv[1]);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(rfcomm, &rfcomm_cmds, "Bluetooth RFCOMM shell commands",
|
SHELL_CMD_REGISTER(rfcomm, &rfcomm_cmds, "Bluetooth RFCOMM shell commands",
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef void (*log_backend_cmd_t)(const struct shell *shell,
|
typedef int (*log_backend_cmd_t)(const struct shell *shell,
|
||||||
const struct log_backend *backend,
|
const struct log_backend *backend,
|
||||||
size_t argc,
|
size_t argc,
|
||||||
char **argv);
|
char **argv);
|
||||||
|
@ -68,7 +68,7 @@ static bool shell_state_precheck(const struct shell *shell)
|
||||||
/**
|
/**
|
||||||
* @brief Function for executing command on given backend.
|
* @brief Function for executing command on given backend.
|
||||||
*/
|
*/
|
||||||
static void shell_backend_cmd_execute(const struct shell *shell,
|
static int shell_backend_cmd_execute(const struct shell *shell,
|
||||||
size_t argc,
|
size_t argc,
|
||||||
char **argv,
|
char **argv,
|
||||||
log_backend_cmd_t func)
|
log_backend_cmd_t func)
|
||||||
|
@ -84,11 +84,13 @@ static void shell_backend_cmd_execute(const struct shell *shell,
|
||||||
} else {
|
} else {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
"Invalid backend: %s\r\n", name);
|
"Invalid backend: %s\r\n", name);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void log_status(const struct shell *shell,
|
static int log_status(const struct shell *shell,
|
||||||
const struct log_backend *backend,
|
const struct log_backend *backend,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -118,23 +120,26 @@ static void log_status(const struct shell *shell,
|
||||||
severity_lvls[dynamic_lvl],
|
severity_lvls[dynamic_lvl],
|
||||||
severity_lvls[compiled_lvl]);
|
severity_lvls[compiled_lvl]);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cmd_log_self_status(const struct shell *shell,
|
static int cmd_log_self_status(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_state_precheck(shell)) {
|
if (!shell_state_precheck(shell)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_status(shell, shell->log_backend->backend, argc, argv);
|
log_status(shell, shell->log_backend->backend, argc, argv);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_backend_status(const struct shell *shell,
|
static int cmd_log_backend_status(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
shell_backend_cmd_execute(shell, argc, argv, log_status);
|
shell_backend_cmd_execute(shell, argc, argv, log_status);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int module_id_get(const char *name)
|
static int module_id_get(const char *name)
|
||||||
|
@ -217,7 +222,7 @@ static int severity_level_get(const char *str)
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
static void log_enable(const struct shell *shell,
|
static int log_enable(const struct shell *shell,
|
||||||
const struct log_backend *backend,
|
const struct log_backend *backend,
|
||||||
size_t argc,
|
size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
|
@ -225,7 +230,7 @@ static void log_enable(const struct shell *shell,
|
||||||
int severity_level;
|
int severity_level;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc > 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc > 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
severity_level = severity_level_get(argv[1]);
|
severity_level = severity_level_get(argv[1]);
|
||||||
|
@ -233,55 +238,57 @@ static void log_enable(const struct shell *shell,
|
||||||
if (severity_level < 0) {
|
if (severity_level < 0) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "Invalid severity: %s\r\n",
|
shell_fprintf(shell, SHELL_ERROR, "Invalid severity: %s\r\n",
|
||||||
argv[1]);
|
argv[1]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Arguments following severity level are interpreted as module names.*/
|
/* Arguments following severity level are interpreted as module names.*/
|
||||||
filters_set(shell, backend, argc - 2, &argv[2], severity_level);
|
filters_set(shell, backend, argc - 2, &argv[2], severity_level);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_self_enable(const struct shell *shell,
|
static int cmd_log_self_enable(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_state_precheck(shell)) {
|
if (!shell_state_precheck(shell)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_enable(shell, shell->log_backend->backend, argc, argv);
|
return log_enable(shell, shell->log_backend->backend, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_backend_enable(const struct shell *shell,
|
static int cmd_log_backend_enable(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
shell_backend_cmd_execute(shell, argc, argv, log_enable);
|
return shell_backend_cmd_execute(shell, argc, argv, log_enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_disable(const struct shell *shell,
|
static int log_disable(const struct shell *shell,
|
||||||
const struct log_backend *backend,
|
const struct log_backend *backend,
|
||||||
size_t argc,
|
size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc > 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc > 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
filters_set(shell, backend, argc - 1, &argv[1], LOG_LEVEL_NONE);
|
filters_set(shell, backend, argc - 1, &argv[1], LOG_LEVEL_NONE);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_self_disable(const struct shell *shell,
|
static int cmd_log_self_disable(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_state_precheck(shell)) {
|
if (!shell_state_precheck(shell)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_disable(shell, shell->log_backend->backend, argc, argv);
|
return log_disable(shell, shell->log_backend->backend, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_backend_disable(const struct shell *shell,
|
static int cmd_log_backend_disable(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
shell_backend_cmd_execute(shell, argc, argv, log_disable);
|
return shell_backend_cmd_execute(shell, argc, argv, log_disable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void module_name_get(size_t idx, struct shell_static_entry *entry);
|
static void module_name_get(size_t idx, struct shell_static_entry *entry);
|
||||||
|
@ -308,64 +315,66 @@ static void severity_lvl_get(size_t idx, struct shell_static_entry *entry)
|
||||||
|
|
||||||
SHELL_CREATE_DYNAMIC_CMD(dsub_severity_lvl, severity_lvl_get);
|
SHELL_CREATE_DYNAMIC_CMD(dsub_severity_lvl, severity_lvl_get);
|
||||||
|
|
||||||
static void log_halt(const struct shell *shell,
|
static int log_halt(const struct shell *shell,
|
||||||
const struct log_backend *backend,
|
const struct log_backend *backend,
|
||||||
size_t argc,
|
size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
log_backend_deactivate(backend);
|
log_backend_deactivate(backend);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cmd_log_self_halt(const struct shell *shell,
|
static int cmd_log_self_halt(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_state_precheck(shell)) {
|
if (!shell_state_precheck(shell)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_halt(shell, shell->log_backend->backend, argc, argv);
|
return log_halt(shell, shell->log_backend->backend, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_backend_halt(const struct shell *shell,
|
static int cmd_log_backend_halt(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
shell_backend_cmd_execute(shell, argc, argv, log_halt);
|
return shell_backend_cmd_execute(shell, argc, argv, log_halt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_go(const struct shell *shell,
|
static int log_go(const struct shell *shell,
|
||||||
const struct log_backend *backend,
|
const struct log_backend *backend,
|
||||||
size_t argc,
|
size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
log_backend_activate(backend, backend->cb->ctx);
|
log_backend_activate(backend, backend->cb->ctx);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cmd_log_self_go(const struct shell *shell,
|
static int cmd_log_self_go(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_state_precheck(shell)) {
|
if (!shell_state_precheck(shell)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_go(shell, shell->log_backend->backend, argc, argv);
|
return log_go(shell, shell->log_backend->backend, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_log_backend_go(const struct shell *shell,
|
static int cmd_log_backend_go(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
shell_backend_cmd_execute(shell, argc, argv, log_go);
|
return shell_backend_cmd_execute(shell, argc, argv, log_go);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cmd_log_backends_list(const struct shell *shell,
|
static int cmd_log_backends_list(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
int backend_count;
|
int backend_count;
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
backend_count = log_backend_count_get();
|
backend_count = log_backend_count_get();
|
||||||
|
@ -382,6 +391,7 @@ static void cmd_log_backends_list(const struct shell *shell,
|
||||||
backend->cb->id);
|
backend->cb->id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -439,15 +449,16 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_log_stat)
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_log(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_log(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if ((argc == 1) || shell_help_requested(shell)) {
|
if ((argc == 1) || shell_help_requested(shell)) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n",
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n",
|
||||||
argv[0], " unknown parameter: ", argv[1]);
|
argv[0], " unknown parameter: ", argv[1]);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(log, &sub_log_stat, "Commands for controlling logger",
|
SHELL_CMD_REGISTER(log, &sub_log_stat, "Commands for controlling logger",
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <misc/stack.h>
|
#include <misc/stack.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void cmd_kernel_version(const struct shell *shell,
|
static int cmd_kernel_version(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
u32_t version = sys_kernel_version_get();
|
u32_t version = sys_kernel_version_get();
|
||||||
|
@ -25,9 +25,10 @@ static void cmd_kernel_version(const struct shell *shell,
|
||||||
SYS_KERNEL_VER_MAJOR(version),
|
SYS_KERNEL_VER_MAJOR(version),
|
||||||
SYS_KERNEL_VER_MINOR(version),
|
SYS_KERNEL_VER_MINOR(version),
|
||||||
SYS_KERNEL_VER_PATCHLEVEL(version));
|
SYS_KERNEL_VER_PATCHLEVEL(version));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_kernel_uptime(const struct shell *shell,
|
static int cmd_kernel_uptime(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
|
@ -35,9 +36,10 @@ static void cmd_kernel_uptime(const struct shell *shell,
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Uptime: %u ms\r\n",
|
shell_fprintf(shell, SHELL_NORMAL, "Uptime: %u ms\r\n",
|
||||||
k_uptime_get_32());
|
k_uptime_get_32());
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_kernel_cycles(const struct shell *shell,
|
static int cmd_kernel_cycles(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
|
@ -45,6 +47,7 @@ static void cmd_kernel_cycles(const struct shell *shell,
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "cycles: %u hw cycles\r\n",
|
shell_fprintf(shell, SHELL_NORMAL, "cycles: %u hw cycles\r\n",
|
||||||
k_cycle_get_32());
|
k_cycle_get_32());
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_MONITOR) \
|
#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_MONITOR) \
|
||||||
|
@ -78,7 +81,7 @@ static void shell_tdata_dump(const struct k_thread *thread, void *user_data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_kernel_threads(const struct shell *shell,
|
static int cmd_kernel_threads(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
|
@ -86,6 +89,7 @@ static void cmd_kernel_threads(const struct shell *shell,
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Threads:\r\n");
|
shell_fprintf(shell, SHELL_NORMAL, "Threads:\r\n");
|
||||||
k_thread_foreach(shell_tdata_dump, (void *)shell);
|
k_thread_foreach(shell_tdata_dump, (void *)shell);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shell_stack_dump(const struct k_thread *thread, void *user_data)
|
static void shell_stack_dump(const struct k_thread *thread, void *user_data)
|
||||||
|
@ -108,30 +112,33 @@ static void shell_stack_dump(const struct k_thread *thread, void *user_data)
|
||||||
size, unused, size - unused, size, pcnt);
|
size, unused, size - unused, size, pcnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_kernel_stacks(const struct shell *shell,
|
static int cmd_kernel_stacks(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
k_thread_foreach(shell_stack_dump, (void *)shell);
|
k_thread_foreach(shell_stack_dump, (void *)shell);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_REBOOT)
|
#if defined(CONFIG_REBOOT)
|
||||||
static void cmd_kernel_reboot_warm(const struct shell *shell,
|
static int cmd_kernel_reboot_warm(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
sys_reboot(SYS_REBOOT_WARM);
|
sys_reboot(SYS_REBOOT_WARM);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_kernel_reboot_cold(const struct shell *shell,
|
static int cmd_kernel_reboot_cold(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
sys_reboot(SYS_REBOOT_COLD);
|
sys_reboot(SYS_REBOOT_COLD);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CREATE_STATIC_SUBCMD_SET(sub_kernel_reboot)
|
SHELL_CREATE_STATIC_SUBCMD_SET(sub_kernel_reboot)
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
/* Initial cursor position is: (1, 1). */
|
/* Initial cursor position is: (1, 1). */
|
||||||
#define SHELL_INITIAL_CURS_POS (1u)
|
#define SHELL_INITIAL_CURS_POS (1u)
|
||||||
|
|
||||||
static void shell_execute(const struct shell *shell);
|
static int shell_execute(const struct shell *shell);
|
||||||
|
|
||||||
extern const struct shell_cmd_entry __shell_root_cmds_start[0];
|
extern const struct shell_cmd_entry __shell_root_cmds_start[0];
|
||||||
extern const struct shell_cmd_entry __shell_root_cmds_end[0];
|
extern const struct shell_cmd_entry __shell_root_cmds_end[0];
|
||||||
|
@ -760,13 +760,15 @@ static void shell_state_collect(const struct shell *shell)
|
||||||
switch (shell->ctx->receive_state) {
|
switch (shell->ctx->receive_state) {
|
||||||
case SHELL_RECEIVE_DEFAULT:
|
case SHELL_RECEIVE_DEFAULT:
|
||||||
if (data == shell->newline_char) {
|
if (data == shell->newline_char) {
|
||||||
|
|
||||||
if (!shell->ctx->cmd_buff_len) {
|
if (!shell->ctx->cmd_buff_len) {
|
||||||
history_mode_exit(shell);
|
history_mode_exit(shell);
|
||||||
cursor_next_line_move(shell);
|
cursor_next_line_move(shell);
|
||||||
} else {
|
} else {
|
||||||
/* Command execution */
|
/* Command execution */
|
||||||
shell_execute(shell);
|
(void)shell_execute(shell);
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_state_set(shell, SHELL_STATE_ACTIVE);
|
shell_state_set(shell, SHELL_STATE_ACTIVE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -922,7 +924,7 @@ static const struct shell_cmd_entry *root_cmd_find(const char *syntax)
|
||||||
* invokes the last recognized command which has a handler and passes the rest
|
* invokes the last recognized command which has a handler and passes the rest
|
||||||
* of command buffer as arguments.
|
* of command buffer as arguments.
|
||||||
*/
|
*/
|
||||||
static void shell_execute(const struct shell *shell)
|
static int shell_execute(const struct shell *shell)
|
||||||
{
|
{
|
||||||
struct shell_static_entry d_entry; /* Memory for dynamic commands. */
|
struct shell_static_entry d_entry; /* Memory for dynamic commands. */
|
||||||
char *argv[CONFIG_SHELL_ARGC_MAX + 1]; /* +1 reserved for NULL */
|
char *argv[CONFIG_SHELL_ARGC_MAX + 1]; /* +1 reserved for NULL */
|
||||||
|
@ -931,6 +933,7 @@ static void shell_execute(const struct shell *shell)
|
||||||
size_t cmd_lvl = SHELL_CMD_ROOT_LVL;
|
size_t cmd_lvl = SHELL_CMD_ROOT_LVL;
|
||||||
size_t cmd_with_handler_lvl = 0;
|
size_t cmd_with_handler_lvl = 0;
|
||||||
bool wildcard_found = false;
|
bool wildcard_found = false;
|
||||||
|
int ret_val = 0;
|
||||||
size_t cmd_idx;
|
size_t cmd_idx;
|
||||||
size_t argc;
|
size_t argc;
|
||||||
char quote;
|
char quote;
|
||||||
|
@ -956,13 +959,13 @@ static void shell_execute(const struct shell *shell)
|
||||||
CONFIG_SHELL_ARGC_MAX);
|
CONFIG_SHELL_ARGC_MAX);
|
||||||
|
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quote != 0) {
|
if (quote != 0) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "not terminated: %c\r\n",
|
shell_fprintf(shell, SHELL_ERROR, "not terminated: %c\r\n",
|
||||||
quote);
|
quote);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Searching for a matching root command. */
|
/* Searching for a matching root command. */
|
||||||
|
@ -970,7 +973,7 @@ static void shell_execute(const struct shell *shell)
|
||||||
if (p_cmd == NULL) {
|
if (p_cmd == NULL) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s%s\r\n", argv[0],
|
||||||
SHELL_MSG_COMMAND_NOT_FOUND);
|
SHELL_MSG_COMMAND_NOT_FOUND);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Root command shall be always static. */
|
/* Root command shall be always static. */
|
||||||
|
@ -1047,7 +1050,7 @@ static void shell_execute(const struct shell *shell)
|
||||||
" executions\r\n");
|
" executions\r\n");
|
||||||
help_flag_clear(shell);
|
help_flag_clear(shell);
|
||||||
|
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1079,14 +1082,17 @@ static void shell_execute(const struct shell *shell)
|
||||||
} else {
|
} else {
|
||||||
shell_fprintf(shell, SHELL_ERROR,
|
shell_fprintf(shell, SHELL_ERROR,
|
||||||
SHELL_MSG_SPECIFY_SUBCOMMAND);
|
SHELL_MSG_SPECIFY_SUBCOMMAND);
|
||||||
|
ret_val = -ENOEXEC;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
shell->ctx->active_cmd.handler(shell,
|
ret_val = shell->ctx->active_cmd.handler(shell,
|
||||||
argc - cmd_with_handler_lvl,
|
argc - cmd_with_handler_lvl,
|
||||||
&argv[cmd_with_handler_lvl]);
|
&argv[cmd_with_handler_lvl]);
|
||||||
}
|
}
|
||||||
|
|
||||||
help_flag_clear(shell);
|
help_flag_clear(shell);
|
||||||
|
|
||||||
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shell_transport_evt_handler(enum shell_transport_evt evt_type,
|
static void shell_transport_evt_handler(enum shell_transport_evt evt_type,
|
||||||
|
|
|
@ -177,127 +177,137 @@ static int terminal_size_get(const struct shell *shell)
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_restore(shell);
|
cursor_restore(shell);
|
||||||
|
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_clear(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_clear(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
if ((argc == 2) && (shell_help_requested(shell))) {
|
if ((argc == 2) && (shell_help_requested(shell))) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
SHELL_VT100_CMD(shell, SHELL_VT100_CURSORHOME);
|
SHELL_VT100_CMD(shell, SHELL_VT100_CURSORHOME);
|
||||||
SHELL_VT100_CMD(shell, SHELL_VT100_CLEARSCREEN);
|
SHELL_VT100_CMD(shell, SHELL_VT100_CLEARSCREEN);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_shell(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_shell(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
if ((argc == 1) || ((argc == 2) && shell_help_requested(shell))) {
|
if ((argc == 1) || ((argc == 2) && shell_help_requested(shell))) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_ERROR, SHELL_MSG_SPECIFY_SUBCOMMAND);
|
shell_fprintf(shell, SHELL_ERROR, SHELL_MSG_SPECIFY_SUBCOMMAND);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_bacskpace_mode(const struct shell *shell, size_t argc,
|
static int cmd_bacskpace_mode(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
(void)shell_cmd_precheck(shell, (argc == 2), NULL, 0);
|
(void)shell_cmd_precheck(shell, (argc == 2), NULL, 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_bacskpace_mode_backspace(const struct shell *shell, size_t argc,
|
static int cmd_bacskpace_mode_backspace(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->ctx->internal.flags.mode_delete = 0;
|
shell->ctx->internal.flags.mode_delete = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_bacskpace_mode_delete(const struct shell *shell, size_t argc,
|
static int cmd_bacskpace_mode_delete(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->ctx->internal.flags.mode_delete = 1;
|
shell->ctx->internal.flags.mode_delete = 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_colors_off(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_colors_off(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->ctx->internal.flags.use_colors = 0;
|
shell->ctx->internal.flags.use_colors = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_colors_on(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_colors_on(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
shell->ctx->internal.flags.use_colors = 1;
|
shell->ctx->internal.flags.use_colors = 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_colors(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_colors(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
||||||
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_echo(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_echo(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc <= 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc <= 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
||||||
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Echo status: %s\r\n",
|
shell_fprintf(shell, SHELL_NORMAL, "Echo status: %s\r\n",
|
||||||
flag_echo_is_set(shell) ? "on" : "off");
|
flag_echo_is_set(shell) ? "on" : "off");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_echo_off(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_echo_off(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->ctx->internal.flags.echo = 0;
|
shell->ctx->internal.flags.echo = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_echo_on(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_echo_on(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->ctx->internal.flags.echo = 1;
|
shell->ctx->internal.flags.echo = 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_help(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_help(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Please press the <Tab> button to "
|
shell_fprintf(shell, SHELL_NORMAL, "Please press the <Tab> button to "
|
||||||
"see all available commands.\r\n"
|
"see all available commands.\r\n"
|
||||||
|
@ -307,21 +317,21 @@ static void cmd_help(const struct shell *shell, size_t argc, char **argv)
|
||||||
"You can try to call commands "
|
"You can try to call commands "
|
||||||
"with <-h> or <--help> parameter to "
|
"with <-h> or <--help> parameter to "
|
||||||
"get know what they are doing.\r\n");
|
"get know what they are doing.\r\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_history(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_history(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (!IS_ENABLED(CONFIG_SHELL_HISTORY)) {
|
if (!IS_ENABLED(CONFIG_SHELL_HISTORY)) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -338,84 +348,89 @@ static void cmd_history(const struct shell *shell, size_t argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->ctx->temp_buff[0] = '\0';
|
shell->ctx->temp_buff[0] = '\0';
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_shell_stats(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_shell_stats(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
||||||
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)shell_cmd_precheck(shell, (argc <= 2), NULL, 0);
|
(void)shell_cmd_precheck(shell, (argc <= 2), NULL, 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_shell_stats_show(const struct shell *shell, size_t argc,
|
static int cmd_shell_stats_show(const struct shell *shell, size_t argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
if (!IS_ENABLED(CONFIG_SHELL_STATS)) {
|
if (!IS_ENABLED(CONFIG_SHELL_STATS)) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL, "Lost logs: %u\r\n",
|
shell_fprintf(shell, SHELL_NORMAL, "Lost logs: %u\r\n",
|
||||||
shell->stats->log_lost_cnt);
|
shell->stats->log_lost_cnt);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_shell_stats_reset(const struct shell *shell,
|
static int cmd_shell_stats_reset(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!IS_ENABLED(CONFIG_SHELL_STATS)) {
|
if (!IS_ENABLED(CONFIG_SHELL_STATS)) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell->stats->log_lost_cnt = 0;
|
shell->stats->log_lost_cnt = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_resize_default(const struct shell *shell,
|
static int cmd_resize_default(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 1), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_VT100_CMD(shell, SHELL_VT100_SETCOL_80);
|
SHELL_VT100_CMD(shell, SHELL_VT100_SETCOL_80);
|
||||||
shell->ctx->vt100_ctx.cons.terminal_wid = SHELL_DEFAULT_TERMINAL_WIDTH;
|
shell->ctx->vt100_ctx.cons.terminal_wid = SHELL_DEFAULT_TERMINAL_WIDTH;
|
||||||
shell->ctx->vt100_ctx.cons.terminal_hei = SHELL_DEFAULT_TERMINAL_HEIGHT;
|
shell->ctx->vt100_ctx.cons.terminal_hei = SHELL_DEFAULT_TERMINAL_HEIGHT;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_resize(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_resize(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!IS_ENABLED(CONFIG_SHELL_CMDS_RESIZE)) {
|
if (!IS_ENABLED(CONFIG_SHELL_CMDS_RESIZE)) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
shell_fprintf(shell, SHELL_ERROR, "Command not supported.\r\n");
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc <= 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc <= 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
||||||
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
SHELL_MSG_UNKNOWN_PARAMETER, argv[1]);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = terminal_size_get(shell);
|
err = terminal_size_get(shell);
|
||||||
|
@ -428,6 +443,7 @@ static void cmd_resize(const struct shell *shell, size_t argc, char **argv)
|
||||||
"No response from the terminal, assumed 80x24 "
|
"No response from the terminal, assumed 80x24 "
|
||||||
"screen size\r\n");
|
"screen size\r\n");
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Warning!
|
/* Warning!
|
||||||
|
|
|
@ -34,11 +34,11 @@ SHELL_DEFINE(uart_shell, "uart:~$ ", &shell_transport_uart, '\r', 10);
|
||||||
#if defined(CONFIG_BT_CONN)
|
#if defined(CONFIG_BT_CONN)
|
||||||
static bool hrs_simulate;
|
static bool hrs_simulate;
|
||||||
|
|
||||||
static void cmd_hrs_simulate(const struct shell *shell,
|
static int cmd_hrs_simulate(const struct shell *shell,
|
||||||
size_t argc, char *argv[])
|
size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "on")) {
|
if (!strcmp(argv[1], "on")) {
|
||||||
|
@ -58,8 +58,10 @@ static void cmd_hrs_simulate(const struct shell *shell,
|
||||||
} else {
|
} else {
|
||||||
printk("Incorrect value: %s\n", argv[1]);
|
printk("Incorrect value: %s\n", argv[1]);
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_CONN */
|
#endif /* CONFIG_BT_CONN */
|
||||||
|
|
||||||
|
@ -75,19 +77,21 @@ SHELL_CREATE_STATIC_SUBCMD_SET(hrs_cmds) {
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cmd_hrs(const struct shell *shell, size_t argc, char **argv)
|
static int cmd_hrs(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
shell_help_print(shell, NULL, 0);
|
shell_help_print(shell, NULL, 0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
if (!shell_cmd_precheck(shell, (argc == 2), NULL, 0)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\r\n", argv[0],
|
||||||
"unknown parameter: ", argv[1]);
|
"unknown parameter: ", argv[1]);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_CMD_REGISTER(hrs, &hrs_cmds, "Heart Rate Service shell commands",
|
SHELL_CMD_REGISTER(hrs, &hrs_cmds, "Heart Rate Service shell commands",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue