aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test
diff options
context:
space:
mode:
Diffstat (limited to 'projects/cli-test')
-rw-r--r--projects/cli-test/mgmt-cli.c99
-rw-r--r--projects/cli-test/mgmt-cli.h32
-rw-r--r--projects/cli-test/mgmt-dfu.c10
-rw-r--r--projects/cli-test/mgmt-dfu.h1
-rw-r--r--projects/cli-test/mgmt-fpga.c17
-rw-r--r--projects/cli-test/mgmt-fpga.h1
-rw-r--r--projects/cli-test/mgmt-keystore.c64
-rw-r--r--projects/cli-test/mgmt-keystore.h1
-rw-r--r--projects/cli-test/mgmt-masterkey.c24
-rw-r--r--projects/cli-test/mgmt-masterkey.h1
-rw-r--r--projects/cli-test/mgmt-misc.c5
-rw-r--r--projects/cli-test/mgmt-misc.h5
-rw-r--r--projects/cli-test/mgmt-show.c23
-rw-r--r--projects/cli-test/mgmt-show.h1
-rw-r--r--projects/cli-test/mgmt-test.c10
15 files changed, 102 insertions, 192 deletions
diff --git a/projects/cli-test/mgmt-cli.c b/projects/cli-test/mgmt-cli.c
index 073b045..8f5db9d 100644
--- a/projects/cli-test/mgmt-cli.c
+++ b/projects/cli-test/mgmt-cli.c
@@ -116,19 +116,19 @@ static void uart_cli_print(struct cli_def *cli __attribute__ ((unused)), const c
uart_send_string2(STM_UART_MGMT, crlf);
}
-static int uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void *buf, size_t count)
+static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void *buf, size_t count)
{
for (int i = 0; i < count; ++i) {
while (ringbuf_read_char(&uart_ringbuf, (uint8_t *)(buf + i)) == 0)
osSemaphoreWait(uart_sem, osWaitForever);
}
- return count;
+ return (ssize_t)count;
}
-static int uart_cli_write(struct cli_def *cli __attribute__ ((unused)), const void *buf, size_t count)
+static ssize_t uart_cli_write(struct cli_def *cli __attribute__ ((unused)), const void *buf, size_t count)
{
uart_send_bytes(STM_UART_MGMT, (uint8_t *) buf, count);
- return (int) count;
+ return (ssize_t)count;
}
int control_mgmt_uart_dma_rx(mgmt_cli_dma_state_t state)
@@ -148,72 +148,16 @@ int control_mgmt_uart_dma_rx(mgmt_cli_dma_state_t state)
return 0;
}
-static int embedded_cli_loop(struct cli_def *cli)
+static struct cli_def *mgmt_cli_init(void)
{
- unsigned char c;
- int n = 0;
- static struct cli_loop_ctx ctx;
-
- memset(&ctx, 0, sizeof(ctx));
- ctx.insertmode = 1;
-
- cli->state = CLI_STATE_LOGIN;
-
- /* start off in unprivileged mode */
- cli_set_privilege(cli, PRIVILEGE_UNPRIVILEGED);
- cli_set_configmode(cli, MODE_EXEC, NULL);
-
- cli_error(cli, "%s", cli->banner);
-
- while (1) {
- cli_loop_start_new_command(cli, &ctx);
-
- control_mgmt_uart_dma_rx(DMA_RX_START);
-
- while (1) {
- cli_loop_show_prompt(cli, &ctx);
-
- n = cli_loop_read_next_char(cli, &ctx, &c);
-
- /*
- cli_print(cli, "Next char: '%c'/%i, ringbuf ridx %i, widx %i",
- c, (int) c,
- uart_ringbuf.ridx,
- RINGBUF_WIDX(uart_ringbuf)
- */
- if (n == CLI_LOOP_CTRL_BREAK)
- break;
- if (n == CLI_LOOP_CTRL_CONTINUE)
- continue;
-
- n = cli_loop_process_char(cli, &ctx, c);
- if (n == CLI_LOOP_CTRL_BREAK)
- break;
- if (n == CLI_LOOP_CTRL_CONTINUE)
- continue;
- }
-
- if (ctx.l < 0)
- continue;
-
- /* cli_print(cli, "Process command: '%s'", ctx.cmd); */
- n = cli_loop_process_cmd(cli, &ctx);
- if (n == CLI_LOOP_CTRL_BREAK)
- break;
- }
-
- return CLI_OK;
-}
-
-static void mgmt_cli_init(struct cli_def *cli)
-{
- cli_init(cli);
+ struct cli_def *cli;
+ cli = cli_init();
cli_read_callback(cli, uart_cli_read);
cli_write_callback(cli, uart_cli_write);
cli_print_callback(cli, uart_cli_print);
cli_set_banner(cli, "Cryptech Alpha test CLI");
cli_set_hostname(cli, "cryptech");
- cli_telnet_protocol(cli, 0);
+ return cli;
}
hal_user_t user;
@@ -229,24 +173,25 @@ static int check_auth(const char *username, const char *password)
int cli_main(void)
{
- static struct cli_def cli;
-
uart_sem = osSemaphoreCreate(osSemaphore(uart_sem), 0);
- mgmt_cli_init(&cli);
- cli_set_auth_callback(&cli, check_auth);
+ struct cli_def *cli;
+ cli = mgmt_cli_init();
+ cli_set_auth_callback(cli, check_auth);
- configure_cli_show(&cli);
- configure_cli_fpga(&cli);
- configure_cli_misc(&cli);
- configure_cli_test(&cli);
- configure_cli_keystore(&cli);
- configure_cli_masterkey(&cli);
+ configure_cli_show(cli);
+ configure_cli_fpga(cli);
+ configure_cli_misc(cli);
+ configure_cli_test(cli);
+ configure_cli_keystore(cli);
+ configure_cli_masterkey(cli);
while (1) {
- embedded_cli_loop(&cli);
- /* embedded_cli_loop returns when the user enters 'quit' or 'exit' */
- cli_print(&cli, "\nLogging out...\n");
+ control_mgmt_uart_dma_rx(DMA_RX_START);
+
+ cli_loop(cli, 0);
+ /* cli_loop returns when the user enters 'quit' or 'exit' */
+ cli_print(cli, "\nLogging out...\n");
user = HAL_USER_NONE;
}
diff --git a/projects/cli-test/mgmt-cli.h b/projects/cli-test/mgmt-cli.h
index a50e092..0b9c40c 100644
--- a/projects/cli-test/mgmt-cli.h
+++ b/projects/cli-test/mgmt-cli.h
@@ -35,45 +35,15 @@
#ifndef __STM32_MGMT_CLI_H
#define __STM32_MGMT_CLI_H
-#include "stm-init.h"
#include <libcli.h>
-
-/* A bunch of defines to make it easier to add/maintain the CLI commands.
- *
- */
-#define _cli_cmd_struct(name, fullname, func, help) \
- static struct cli_command cmd_##fullname##_s = \
- {(char *) #name, func, 0, help, \
- PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}
-
-/* ROOT is a top-level label with no command */
-#define cli_command_root(name) \
- _cli_cmd_struct(name, name, NULL, NULL); \
- cli_register_command2(cli, &cmd_##name##_s, NULL)
-
-/* BRANCH is a label with a parent, but no command */
-#define cli_command_branch(parent, name) \
- _cli_cmd_struct(name, parent##_##name, NULL, NULL); \
- cli_register_command2(cli, &cmd_##parent##_##name##_s, &cmd_##parent##_s)
-
-/* NODE is a label with a parent and with a command associated with it */
-#define cli_command_node(parent, name, help) \
- _cli_cmd_struct(name, parent##_##name, cmd_##parent##_##name, (char *) help); \
- cli_register_command2(cli, &cmd_##parent##_##name##_s, &cmd_##parent##_s)
-
-/* ROOT NODE is a label without a parent, but with a command associated with it */
-#define cli_command_root_node(name, help) \
- _cli_cmd_struct(name, name, cmd_##name, (char *) help); \
- cli_register_command2(cli, &cmd_##name##_s, NULL)
-
-
typedef enum {
DMA_RX_STOP,
DMA_RX_START,
} mgmt_cli_dma_state_t;
extern int control_mgmt_uart_dma_rx(mgmt_cli_dma_state_t state);
+
extern int cli_main(void);
#endif /* __STM32_MGMT_CLI_H */
diff --git a/projects/cli-test/mgmt-dfu.c b/projects/cli-test/mgmt-dfu.c
index e57c521..8f258ea 100644
--- a/projects/cli-test/mgmt-dfu.c
+++ b/projects/cli-test/mgmt-dfu.c
@@ -115,9 +115,11 @@ static int cmd_dfu_jump(struct cli_def *cli, const char *command, char *argv[],
void configure_cli_dfu(struct cli_def *cli)
{
- cli_command_root(dfu);
+ struct cli_command *c;
- cli_command_node(dfu, dump, "Show the first 256 bytes of the loaded firmware");
- cli_command_node(dfu, jump, "Jump to the loaded firmware");
- cli_command_node(dfu, erase, "Erase the firmware memory (will crash the CLI)");
+ c = cli_register_command(cli, NULL, "dfu", NULL, 0, 0, NULL);
+
+ cli_register_command(cli, c, "dump", cmd_dfu_dump, 0, 0, "Show the first 256 bytes of the loaded firmware");
+ cli_register_command(cli, c, "jump", cmd_dfu_jump, 0, 0, "Jump to the loaded firmware");
+ cli_register_command(cli, c, "erase", cmd_dfu_erase, 0, 0, "Erase the firmware memory (will crash the CLI)");
}
diff --git a/projects/cli-test/mgmt-dfu.h b/projects/cli-test/mgmt-dfu.h
index 047e30a..6128b35 100644
--- a/projects/cli-test/mgmt-dfu.h
+++ b/projects/cli-test/mgmt-dfu.h
@@ -35,7 +35,6 @@
#ifndef __STM32_CLI_MGMT_DFU_H
#define __STM32_CLI_MGMT_DFU_H
-#include "stm-init.h"
#include <libcli.h>
/* symbols defined in the linker script (STM32F429BI.ld) */
diff --git a/projects/cli-test/mgmt-fpga.c b/projects/cli-test/mgmt-fpga.c
index 059e4a9..31a6e27 100644
--- a/projects/cli-test/mgmt-fpga.c
+++ b/projects/cli-test/mgmt-fpga.c
@@ -122,16 +122,19 @@ static int cmd_fpga_reset_registers(struct cli_def *cli, const char *command, ch
void configure_cli_fpga(struct cli_def *cli)
{
- /* fpga */
- cli_command_root(fpga);
+ struct cli_command *c = cli_register_command(cli, NULL, "fpga", NULL, 0, 0, NULL);
+
/* fpga reset */
- cli_command_node(fpga, reset, "Reset FPGA (config reset)");
+ struct cli_command *c_reset = cli_register_command(cli, c, "reset", cmd_fpga_reset, 0, 0, "Reset FPGA (config reset)");
+
/* fpga reset registers */
- cli_command_node(fpga_reset, registers, "Reset FPGA registers (soft reset)");
+ cli_register_command(cli, c_reset, "registers", cmd_fpga_reset_registers, 0, 0, "Reset FPGA registers (soft reset)");
+
+ struct cli_command *c_bitstream = cli_register_command(cli, c, "bitstream", NULL, 0, 0, NULL);
- cli_command_branch(fpga, bitstream);
/* fpga bitstream upload */
- cli_command_node(fpga_bitstream, upload, "Upload new FPGA bitstream");
+ cli_register_command(cli, c_bitstream, "upload", cmd_fpga_bitstream_upload, 0, 0, "Upload new FPGA bitstream");
+
/* fpga bitstream erase */
- cli_command_node(fpga_bitstream, erase, "Erase FPGA config memory");
+ cli_register_command(cli, c_bitstream, "erase", cmd_fpga_bitstream_erase, 0, 0, "Erase FPGA config memory");
}
diff --git a/projects/cli-test/mgmt-fpga.h b/projects/cli-test/mgmt-fpga.h
index ce185de..9d0aedc 100644
--- a/projects/cli-test/mgmt-fpga.h
+++ b/projects/cli-test/mgmt-fpga.h
@@ -35,7 +35,6 @@
#ifndef __STM32_CLI_MGMT_FPGA_H
#define __STM32_CLI_MGMT_FPGA_H
-#include "stm-init.h"
#include <libcli.h>
diff --git a/projects/cli-test/mgmt-keystore.c b/projects/cli-test/mgmt-keystore.c
index 01f3be2..72cc5da 100644
--- a/projects/cli-test/mgmt-keystore.c
+++ b/projects/cli-test/mgmt-keystore.c
@@ -32,8 +32,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */
#define HAL_OK CMSIS_HAL_OK
-
#include "stm-init.h"
#include "stm-keystore.h"
#include "stm-fpgacfg.h"
@@ -42,7 +42,6 @@
#include "mgmt-cli.h"
#include "mgmt-show.h"
-/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */
#undef HAL_OK
#define LIBHAL_OK HAL_OK
#include "hal.h"
@@ -54,7 +53,7 @@
#include <string.h>
-int cmd_keystore_set_pin(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_set_pin(struct cli_def *cli, const char *command, char *argv[], int argc)
{
const hal_ks_keydb_t *db;
hal_user_t user;
@@ -92,7 +91,7 @@ int cmd_keystore_set_pin(struct cli_def *cli, const char *command, char *argv[],
return CLI_OK;
}
-int cmd_keystore_clear_pin(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_clear_pin(struct cli_def *cli, const char *command, char *argv[], int argc)
{
const hal_ks_keydb_t *db;
hal_user_t user;
@@ -130,7 +129,7 @@ int cmd_keystore_clear_pin(struct cli_def *cli, const char *command, char *argv[
return CLI_OK;
}
-int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *command, char *argv[], int argc)
{
hal_error_t status;
hal_client_handle_t client = { -1 };
@@ -150,7 +149,7 @@ int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *command, ch
return CLI_OK;
}
-int cmd_keystore_set_key(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_set_key(struct cli_def *cli, const char *command, char *argv[], int argc)
{
hal_error_t status;
int hint = 0;
@@ -206,7 +205,7 @@ static int key_by_index(struct cli_def *cli, char *str, const uint8_t **name, si
return CLI_ERROR;
}
-int cmd_keystore_delete_key(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_delete_key(struct cli_def *cli, const char *command, char *argv[], int argc)
{
hal_error_t status;
int hint = 0;
@@ -242,7 +241,7 @@ int cmd_keystore_delete_key(struct cli_def *cli, const char *command, char *argv
return CLI_OK;
}
-int cmd_keystore_rename_key(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_rename_key(struct cli_def *cli, const char *command, char *argv[], int argc)
{
hal_error_t status;
int hint = 0;
@@ -278,7 +277,7 @@ int cmd_keystore_rename_key(struct cli_def *cli, const char *command, char *argv
return CLI_OK;
}
-int cmd_keystore_show_data(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_show_data(struct cli_def *cli, const char *command, char *argv[], int argc)
{
uint8_t buf[KEYSTORE_PAGE_SIZE];
uint32_t i;
@@ -300,7 +299,7 @@ int cmd_keystore_show_data(struct cli_def *cli, const char *command, char *argv[
return CLI_OK;
}
-int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[], int argc)
{
const hal_ks_keydb_t *db;
uint8_t name[HAL_RPC_PKEY_NAME_MAX + 1];
@@ -369,7 +368,7 @@ int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[
return CLI_OK;
}
-int cmd_keystore_erase(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *argv[], int argc)
{
int status;
@@ -393,43 +392,38 @@ int cmd_keystore_erase(struct cli_def *cli, const char *command, char *argv[], i
void configure_cli_keystore(struct cli_def *cli)
{
- /* keystore */
- cli_command_root(keystore);
- /* keystore set */
- cli_command_branch(keystore, set);
- /* keystore clear */
- cli_command_branch(keystore, clear);
- /* keystore delete */
- cli_command_branch(keystore, delete);
- /* keystore rename */
- cli_command_branch(keystore, rename);
- /* keystore show */
- cli_command_branch(keystore, show);
+ struct cli_command *c = cli_register_command(cli, NULL, "keystore", NULL, 0, 0, NULL);
- /* keystore erase */
- cli_command_node(keystore, erase, "Erase the whole keystore");
+ struct cli_command *c_set = cli_register_command(cli, c, "set", NULL, 0, 0, NULL);
+ struct cli_command *c_clear = cli_register_command(cli, c, "clear", NULL, 0, 0, NULL);
+ struct cli_command *c_delete = cli_register_command(cli, c, "delete", NULL, 0, 0, NULL);
+ struct cli_command *c_rename = cli_register_command(cli, c, "rename", NULL, 0, 0, NULL);
+ struct cli_command *c_show = cli_register_command(cli, c, "show", NULL, 0, 0, NULL);
+ /* keystore erase */
+ cli_register_command(cli, c, "erase", cmd_keystore_erase, 0, 0, "Erase the whole keystore");
/* keystore set pin */
- cli_command_node(keystore_set, pin, "Set either 'wheel', 'user' or 'so' PIN");
+ struct cli_command *c_set_pin = cli_register_command(cli, c_set, "pin", cmd_keystore_set_pin, 0, 0, "Set either 'wheel', 'user' or 'so' PIN");
/* keystore set pin iterations */
- cli_command_node(keystore_set_pin, iterations, "Set PBKDF2 iterations for PINs");
+ cli_register_command(cli, c_set_pin, "iterations", cmd_keystore_set_pin_iterations, 0, 0, "Set PBKDF2 iterations for PINs");
/* keystore clear pin */
- cli_command_node(keystore_clear, pin, "Clear either 'wheel', 'user' or 'so' PIN");
+ cli_register_command(cli, c_clear, "pin", cmd_keystore_clear_pin, 0, 0, "Clear either 'wheel', 'user' or 'so' PIN");
/* keystore set key */
- cli_command_node(keystore_set, key, "Set a key");
+ cli_register_command(cli, c_set, "key", cmd_keystore_set_key, 0, 0, "Set a key");
/* keystore delete key */
- cli_command_node(keystore_delete, key, "Delete a key");
+ cli_register_command(cli, c_delete, "key", cmd_keystore_delete_key, 0, 0, "Delete a key");
/* keystore rename key */
- cli_command_node(keystore_rename, key, "Rename a key");
-
+ cli_register_command(cli, c_rename, "key", cmd_keystore_rename_key, 0, 0, "Rename a key");
+
/* keystore show data */
- cli_command_node(keystore_show, data, "Dump the first page from the keystore memory");
+ cli_register_command(cli, c_show, "data", cmd_keystore_show_data, 0, 0, "Dump the first page from the keystore memory");
+
+ /* keystore show keys */
+ cli_register_command(cli, c_show, "keys", cmd_keystore_show_keys, 0, 0, "Show what PINs and keys are in the keystore");
- /* keystore show keys */
- cli_command_node(keystore_show, keys, "Show what PINs and keys are in the keystore");
}
diff --git a/projects/cli-test/mgmt-keystore.h b/projects/cli-test/mgmt-keystore.h
index 62efa51..9e14ac6 100644
--- a/projects/cli-test/mgmt-keystore.h
+++ b/projects/cli-test/mgmt-keystore.h
@@ -35,7 +35,6 @@
#ifndef __STM32_CLI_MGMT_KEYSTORE_H
#define __STM32_CLI_MGMT_KEYSTORE_H
-#include "stm-init.h"
#include <libcli.h>
extern void configure_cli_keystore(struct cli_def *cli);
diff --git a/projects/cli-test/mgmt-masterkey.c b/projects/cli-test/mgmt-masterkey.c
index 7938e33..69dc430 100644
--- a/projects/cli-test/mgmt-masterkey.c
+++ b/projects/cli-test/mgmt-masterkey.c
@@ -32,14 +32,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */
#define HAL_OK CMSIS_HAL_OK
-
#include "stm-init.h"
#include "stm-uart.h"
#include "mgmt-cli.h"
#include "mgmt-masterkey.h"
-/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */
#undef HAL_OK
#define LIBHAL_OK HAL_OK
#include <hal.h>
@@ -74,7 +73,7 @@ static int _parse_hex_groups(uint8_t *buf, size_t len, char *argv[], int argc)
for (i = 0; i < argc; i++) {
if (dst >= end) return -1;
- *dst++ = strtol(argv[i], &err_ptr, 16);
+ *dst++ = strtoul(argv[i], &err_ptr, 16);
if (*err_ptr) return -2;
}
@@ -191,19 +190,22 @@ static int cmd_masterkey_unsecure_erase(struct cli_def *cli, const char *command
void configure_cli_masterkey(struct cli_def *cli)
{
- /* masterkey */
- cli_command_root(masterkey);
+ struct cli_command *c = cli_register_command(cli, NULL, "masterkey", NULL, 0, 0, NULL);
+
/* masterkey status */
- cli_command_node(masterkey, status, "Show status of master key in RAM/flash");
+ cli_register_command(cli, c, "status", cmd_masterkey_status, 0, 0, "Show status of master key in RAM/flash");
/* masterkey set */
- cli_command_node(masterkey, set, "Set the master key in the volatile Master Key Memory");
+ cli_register_command(cli, c, "set", cmd_masterkey_set, 0, 0, "Set the master key in the volatile Master Key Memory");
+
/* masterkey erase */
- cli_command_node(masterkey, erase, "Erase the master key from the volatile Master Key Memory");
+ cli_register_command(cli, c, "erase", cmd_masterkey_erase, 0, 0, "Erase the master key from the volatile Master Key Memory");
+
+ struct cli_command *c_unsecure = cli_register_command(cli, c, "unsecure", NULL, 0, 0, NULL);
- cli_command_branch(masterkey, unsecure);
/* masterkey unsecure set */
- cli_command_node(masterkey_unsecure, set, "Set master key in unprotected flash memory (if unsure, DON'T)");
+ cli_register_command(cli, c_unsecure, "set", cmd_masterkey_unsecure_set, 0, 0, "Set master key in unprotected flash memory (if unsure, DON'T)");
+
/* masterkey unsecure erase */
- cli_command_node(masterkey_unsecure, erase, "Erase master key from unprotected flash memory");
+ cli_register_command(cli, c_unsecure, "erase", cmd_masterkey_unsecure_erase, 0, 0, "Erase master key from unprotected flash memory");
}
diff --git a/projects/cli-test/mgmt-masterkey.h b/projects/cli-test/mgmt-masterkey.h
index 5d2624a..67835e9 100644
--- a/projects/cli-test/mgmt-masterkey.h
+++ b/projects/cli-test/mgmt-masterkey.h
@@ -35,7 +35,6 @@
#ifndef __STM32_CLI_MGMT_MASTERKEY_H
#define __STM32_CLI_MGMT_MASTERKEY_H
-#include "stm-init.h"
#include <libcli.h>
extern void configure_cli_masterkey(struct cli_def *cli);
diff --git a/projects/cli-test/mgmt-misc.c b/projects/cli-test/mgmt-misc.c
index 67bc875..535f0af 100644
--- a/projects/cli-test/mgmt-misc.c
+++ b/projects/cli-test/mgmt-misc.c
@@ -131,8 +131,9 @@ static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], in
void configure_cli_misc(struct cli_def *cli)
{
/* filetransfer */
- cli_command_root_node(filetransfer, "Test file transfering");
+ cli_register_command(cli, NULL, "filetransfer", cmd_filetransfer, 0, 0, "Test file transfering");
+
/* reboot */
- cli_command_root_node(reboot, "Reboot the STM32");
+ cli_register_command(cli, NULL, "reboot", cmd_reboot, 0, 0, "Reboot the STM32");
}
diff --git a/projects/cli-test/mgmt-misc.h b/projects/cli-test/mgmt-misc.h
index b7eb4f4..c549f63 100644
--- a/projects/cli-test/mgmt-misc.h
+++ b/projects/cli-test/mgmt-misc.h
@@ -35,15 +35,14 @@
#ifndef __STM32_CLI_MGMT_MISC_H
#define __STM32_CLI_MGMT_MISC_H
-#include "stm-init.h"
#include <libcli.h>
-
#define FILETRANSFER_UPLOAD_CHUNK_SIZE 256
typedef int (*cli_data_callback)(uint8_t *, size_t);
-extern void configure_cli_misc(struct cli_def *cli);
extern int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_callback data_callback);
+extern void configure_cli_misc(struct cli_def *cli);
+
#endif /* __STM32_CLI_MGMT_MISC_H */
diff --git a/projects/cli-test/mgmt-show.c b/projects/cli-test/mgmt-show.c
index b918cce..e88b784 100644
--- a/projects/cli-test/mgmt-show.c
+++ b/projects/cli-test/mgmt-show.c
@@ -32,8 +32,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */
#define HAL_OK CMSIS_HAL_OK
-
#include "stm-init.h"
#include "stm-keystore.h"
#include "stm-fpgacfg.h"
@@ -42,7 +42,6 @@
#include "mgmt-cli.h"
#include "mgmt-show.h"
-/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */
#undef HAL_OK
#define LIBHAL_OK HAL_OK
#include "hal.h"
@@ -53,7 +52,6 @@
#include <string.h>
-
static int cmd_show_cpuspeed(struct cli_def *cli, const char *command, char *argv[], int argc)
{
volatile uint32_t hclk;
@@ -127,18 +125,21 @@ static int cmd_show_keystore_data(struct cli_def *cli, const char *command, char
void configure_cli_show(struct cli_def *cli)
{
- /* show */
- cli_command_root(show);
+ struct cli_command *c = cli_register_command(cli, NULL, "show", NULL, 0, 0, NULL);
/* show cpuspeed */
- cli_command_node(show, cpuspeed, "Show the speed at which the CPU currently operates");
+ cli_register_command(cli, c, "cpuspeed", cmd_show_cpuspeed, 0, 0, "Show the speed at which the CPU currently operates");
+
+ struct cli_command *c_fpga = cli_register_command(cli, c, "fpga", NULL, 0, 0, NULL);
- cli_command_branch(show, fpga);
/* show fpga status*/
- cli_command_node(show_fpga, status, "Show status about the FPGA");
+ cli_register_command(cli, c_fpga, "status", cmd_show_fpga_status, 0, 0, "Show status about the FPGA");
+
+ struct cli_command *c_keystore = cli_register_command(cli, c, "keystore", NULL, 0, 0, NULL);
- cli_command_branch(show, keystore);
/* show keystore status*/
- cli_command_node(show_keystore, status, "Show status of the keystore memory");
- cli_command_node(show_keystore, data, "Show the first page of the keystore memory");
+ cli_register_command(cli, c_keystore, "status", cmd_show_keystore_status, 0, 0, "Show status of the keystore memory");
+
+ /* show keystore data */
+ cli_register_command(cli, c_keystore, "data", cmd_show_keystore_data, 0, 0, "Show the first page of the keystore memory");
}
diff --git a/projects/cli-test/mgmt-show.h b/projects/cli-test/mgmt-show.h
index e459acb..7b80a30 100644
--- a/projects/cli-test/mgmt-show.h
+++ b/projects/cli-test/mgmt-show.h
@@ -35,7 +35,6 @@
#ifndef __STM32_CLI_MGMT_SHOW_H
#define __STM32_CLI_MGMT_SHOW_H
-#include "stm-init.h"
#include <libcli.h>
extern void configure_cli_show(struct cli_def *cli);
diff --git a/projects/cli-test/mgmt-test.c b/projects/cli-test/mgmt-test.c
index 35c6fb6..138982f 100644
--- a/projects/cli-test/mgmt-test.c
+++ b/projects/cli-test/mgmt-test.c
@@ -44,8 +44,7 @@
#include <stdlib.h>
-
-int cmd_test_sdram(struct cli_def *cli, const char *command, char *argv[], int argc)
+static int cmd_test_sdram(struct cli_def *cli, const char *command, char *argv[], int argc)
{
// run external memory initialization sequence
HAL_StatusTypeDef status;
@@ -110,12 +109,11 @@ int cmd_test_sdram(struct cli_def *cli, const char *command, char *argv[], int a
void configure_cli_test(struct cli_def *cli)
{
- /* test */
- cli_command_root(test);
+ struct cli_command *c = cli_register_command(cli, NULL, "test", NULL, 0, 0, NULL);
/* test sdram */
- cli_command_node(test, sdram, "Run SDRAM tests");
+ cli_register_command(cli, c, "sdram", cmd_test_sdram, 0, 0, "Run SDRAM tests");
/* test mkmif */
- cli_command_node(test, mkmif, "Run Master Key Memory Interface tests");
+ cli_register_command(cli, c, "mkmif", cmd_test_mkmif, 0, 0, "Run Master Key Memory Interface tests");
}