diff options
Diffstat (limited to 'projects/hsm')
-rw-r--r-- | projects/hsm/mgmt-bootloader.c | 6 | ||||
-rw-r--r-- | projects/hsm/mgmt-cli.c | 132 | ||||
-rw-r--r-- | projects/hsm/mgmt-cli.h | 31 | ||||
-rw-r--r-- | projects/hsm/mgmt-firmware.c | 9 | ||||
-rw-r--r-- | projects/hsm/mgmt-fpga.c | 19 | ||||
-rw-r--r-- | projects/hsm/mgmt-fpga.h | 1 | ||||
-rw-r--r-- | projects/hsm/mgmt-keystore.c | 56 | ||||
-rw-r--r-- | projects/hsm/mgmt-keystore.h | 1 | ||||
-rw-r--r-- | projects/hsm/mgmt-masterkey.c | 19 | ||||
-rw-r--r-- | projects/hsm/mgmt-masterkey.h | 1 | ||||
-rw-r--r-- | projects/hsm/mgmt-misc.c | 2 | ||||
-rw-r--r-- | projects/hsm/mgmt-misc.h | 7 | ||||
-rw-r--r-- | projects/hsm/mgmt-show.c | 84 | ||||
-rw-r--r-- | projects/hsm/mgmt-show.h | 43 |
14 files changed, 95 insertions, 316 deletions
diff --git a/projects/hsm/mgmt-bootloader.c b/projects/hsm/mgmt-bootloader.c index a062fd9..a4783cc 100644 --- a/projects/hsm/mgmt-bootloader.c +++ b/projects/hsm/mgmt-bootloader.c @@ -75,7 +75,9 @@ static int cmd_bootloader_upload(struct cli_def *cli, const char *command, char void configure_cli_bootloader(struct cli_def *cli) { - cli_command_root(bootloader); + struct cli_command *c; - cli_command_node(bootloader, upload, "Upload new bootloader image"); + c = cli_register_command(cli, NULL, "bootloader", NULL, 0, 0, NULL); + + cli_register_command(cli, c, "upload", cmd_bootloader_upload, 0, 0, "Upload new bootloader image"); } diff --git a/projects/hsm/mgmt-cli.c b/projects/hsm/mgmt-cli.c index a610db6..539ba4c 100644 --- a/projects/hsm/mgmt-cli.c +++ b/projects/hsm/mgmt-cli.c @@ -47,7 +47,6 @@ #include "mgmt-bootloader.h" #include "mgmt-fpga.h" #include "mgmt-misc.h" -#include "mgmt-show.h" #include "mgmt-keystore.h" #include "mgmt-masterkey.h" @@ -62,7 +61,7 @@ typedef struct { int ridx; - volatile int widx; + volatile int widx; mgmt_cli_dma_state_t rx_state; uint8_t buf[CLI_UART_RECVBUF_SIZE]; } ringbuf_t; @@ -117,106 +116,38 @@ 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) { if (state == DMA_RX_START) { - if (uart_ringbuf.rx_state != DMA_RX_START) { + if (uart_ringbuf.rx_state != DMA_RX_START) { ringbuf_init(&uart_ringbuf); - HAL_UART_Receive_DMA(&huart_mgmt, &uart_rx, 1); - uart_ringbuf.rx_state = DMA_RX_START; - } - return 1; + HAL_UART_Receive_DMA(&huart_mgmt, &uart_rx, 1); + uart_ringbuf.rx_state = DMA_RX_START; + } + return 1; } else if (state == DMA_RX_STOP) { - if (HAL_UART_DMAStop(&huart_mgmt) != CMSIS_HAL_OK) return 0; - uart_ringbuf.rx_state = DMA_RX_STOP; - return 1; + if (HAL_UART_DMAStop(&huart_mgmt) != CMSIS_HAL_OK) return 0; + uart_ringbuf.rx_state = DMA_RX_STOP; + return 1; } return 0; } -static int embedded_cli_loop(struct cli_def *cli) -{ - 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) - break; - - /* 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); - 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"); - cli_set_hostname(cli, "cryptech"); - cli_telnet_protocol(cli, 0); -} - hal_user_t user; static int check_auth(const char *username, const char *password) @@ -242,27 +173,36 @@ 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 = cli_init(); + if (cli == NULL) + Error_Handler(); + + 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"); + cli_set_hostname(cli, "cryptech"); + cli_set_auth_callback(cli, check_auth); /* we don't have any privileged commands at the moment */ - cli_unregister_command(&cli, "enable"); + cli_unregister_command(cli, "enable"); - configure_cli_fpga(&cli); - configure_cli_keystore(&cli); - configure_cli_masterkey(&cli); - configure_cli_firmware(&cli); - configure_cli_bootloader(&cli); - configure_cli_misc(&cli); + configure_cli_fpga(cli); + configure_cli_keystore(cli); + configure_cli_masterkey(cli); + configure_cli_firmware(cli); + configure_cli_bootloader(cli); + configure_cli_misc(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/hsm/mgmt-cli.h b/projects/hsm/mgmt-cli.h index c96dae6..0b9c40c 100644 --- a/projects/hsm/mgmt-cli.h +++ b/projects/hsm/mgmt-cli.h @@ -35,39 +35,8 @@ #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, diff --git a/projects/hsm/mgmt-firmware.c b/projects/hsm/mgmt-firmware.c index 1a0e184..ec8a69d 100644 --- a/projects/hsm/mgmt-firmware.c +++ b/projects/hsm/mgmt-firmware.c @@ -35,10 +35,11 @@ /* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */ #define HAL_OK CMSIS_HAL_OK #include "stm-init.h" -#include "mgmt-cli.h" #include "stm-uart.h" #include "stm-flash.h" +#include "mgmt-cli.h" + #undef HAL_OK #define HAL_OK LIBHAL_OK #include "hal.h" @@ -63,7 +64,9 @@ static int cmd_firmware_upload(struct cli_def *cli, const char *command, char *a void configure_cli_firmware(struct cli_def *cli) { - cli_command_root(firmware); + struct cli_command *c; + + c = cli_register_command(cli, NULL, "firmware", NULL, 0, 0, NULL); - cli_command_node(firmware, upload, "Upload new firmware image"); + cli_register_command(cli, c, "upload", cmd_firmware_upload, 0, 0, "Upload new firmware image"); } diff --git a/projects/hsm/mgmt-fpga.c b/projects/hsm/mgmt-fpga.c index adb45b3..778ded9 100644 --- a/projects/hsm/mgmt-fpga.c +++ b/projects/hsm/mgmt-fpga.c @@ -145,19 +145,20 @@ static int cmd_fpga_show_cores(struct cli_def *cli, const char *command, char *a 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); - cli_command_branch(fpga, show); - /* show fpga cores*/ - cli_command_node(fpga_show, cores, "Show FPGA core names and versions"); + struct cli_command *c_show = cli_register_command(cli, c, "show", NULL, 0, 0, NULL); + struct cli_command *c_bitstream = cli_register_command(cli, c, "bitstream", NULL, 0, 0, NULL); + + /* fpga show cores */ + cli_register_command(cli, c_show, "cores", cmd_fpga_show_cores, 0, 0, "Show FPGA core names and versions"); /* fpga reset */ - cli_command_node(fpga, reset, "Reset FPGA (config reset)"); + cli_register_command(cli, c, "reset", cmd_fpga_reset, 0, 0, "Reset FPGA (config reset)"); - 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/hsm/mgmt-fpga.h b/projects/hsm/mgmt-fpga.h index ce185de..9d0aedc 100644 --- a/projects/hsm/mgmt-fpga.h +++ b/projects/hsm/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/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c index 0471430..c7e20b0 100644 --- a/projects/hsm/mgmt-keystore.c +++ b/projects/hsm/mgmt-keystore.c @@ -40,7 +40,6 @@ #include "stm-uart.h" #include "mgmt-cli.h" -#include "mgmt-show.h" #undef HAL_OK #define LIBHAL_OK HAL_OK @@ -54,7 +53,7 @@ #include <ctype.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 }; @@ -151,7 +150,7 @@ int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *command, ch } #if 0 -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; @@ -208,7 +207,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; @@ -251,7 +250,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; @@ -294,7 +293,7 @@ int cmd_keystore_rename_key(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; char *type; @@ -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,42 +392,37 @@ 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); + + struct cli_command *c_show = cli_register_command(cli, c, "show", NULL, 0, 0, NULL); + 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); + + /* 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 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"); - - /* keystore show keys */ - cli_command_node(keystore_show, keys, "Show what PINs and keys are in the keystore"); + cli_register_command(cli, c_clear, "pin", cmd_keystore_clear_pin, 0, 0, "Clear either 'wheel', 'user' or 'so' PIN"); #if 0 /* 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"); #endif /* 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 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 erase */ - cli_command_node(keystore, erase, "Erase the whole keystore"); + cli_register_command(cli, c, "erase", cmd_keystore_erase, 0, 0, "Erase the whole keystore"); } diff --git a/projects/hsm/mgmt-keystore.h b/projects/hsm/mgmt-keystore.h index 62efa51..9e14ac6 100644 --- a/projects/hsm/mgmt-keystore.h +++ b/projects/hsm/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/hsm/mgmt-masterkey.c b/projects/hsm/mgmt-masterkey.c index 6aa7338..33ce395 100644 --- a/projects/hsm/mgmt-masterkey.c +++ b/projects/hsm/mgmt-masterkey.c @@ -168,19 +168,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/hsm/mgmt-masterkey.h b/projects/hsm/mgmt-masterkey.h index 5d2624a..67835e9 100644 --- a/projects/hsm/mgmt-masterkey.h +++ b/projects/hsm/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/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index 15b2d13..31a1c49 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -114,6 +114,6 @@ static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], in void configure_cli_misc(struct cli_def *cli) { /* 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/hsm/mgmt-misc.h b/projects/hsm/mgmt-misc.h index b7eb4f4..862ca0c 100644 --- a/projects/hsm/mgmt-misc.h +++ b/projects/hsm/mgmt-misc.h @@ -35,15 +35,12 @@ #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/hsm/mgmt-show.c b/projects/hsm/mgmt-show.c deleted file mode 100644 index ac78f30..0000000 --- a/projects/hsm/mgmt-show.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * mgmt-show.c - * ----------- - * CLI 'show' functions. - * - * Copyright (c) 2016, NORDUnet A/S All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the NORDUnet nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "stm-init.h" -#include "stm-keystore.h" -#include "stm-fpgacfg.h" -#include "stm-uart.h" - -#include "mgmt-cli.h" -#include "mgmt-show.h" - -#include <string.h> - - -static int cmd_show_cpuspeed(struct cli_def *cli, const char *command, char *argv[], int argc) -{ - volatile uint32_t hclk; - - hclk = HAL_RCC_GetHCLKFreq(); - cli_print(cli, "HSE_VALUE: %li", HSE_VALUE); - cli_print(cli, "HCLK: %li (%i MHz)", hclk, (int) hclk / 1000 / 1000); - cli_print(cli, "SystemCoreClock: %li (%i MHz)", SystemCoreClock, (int) SystemCoreClock / 1000 / 1000); - return CLI_OK; -} - -static int cmd_show_fpga_status(struct cli_def *cli, const char *command, char *argv[], int argc) -{ - cli_print(cli, "FPGA has %sloaded a bitstream", fpgacfg_check_done() ? "":"NOT "); - return CLI_OK; -} - -static int cmd_show_keystore_status(struct cli_def *cli, const char *command, char *argv[], int argc) -{ - cli_print(cli, "Keystore memory is %sonline", (keystore_check_id() != 1) ? "NOT ":""); - return CLI_OK; -} - -void configure_cli_show(struct cli_def *cli) -{ - /* show */ - cli_command_root(show); - - /* show cpuspeed */ - cli_command_node(show, cpuspeed, "Show the speed at which the CPU currently operates"); - - cli_command_branch(show, fpga); - /* show fpga status*/ - cli_command_node(show_fpga, status, "Show status about the FPGA"); - - cli_command_branch(show, keystore); - /* show keystore status*/ - cli_command_node(show_keystore, status, "Show status of the keystore memory"); -} diff --git a/projects/hsm/mgmt-show.h b/projects/hsm/mgmt-show.h deleted file mode 100644 index e459acb..0000000 --- a/projects/hsm/mgmt-show.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * mgmt-show.h - * ----------- - * Management CLI 'show' functions. - * - * Copyright (c) 2016, NORDUnet A/S All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the NORDUnet nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#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); - -#endif /* __STM32_CLI_MGMT_SHOW_H */ |