aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test
diff options
context:
space:
mode:
Diffstat (limited to 'projects/cli-test')
-rw-r--r--projects/cli-test/Makefile1
-rw-r--r--projects/cli-test/crc32.c62
-rw-r--r--projects/cli-test/mgmt-dfu.c2
-rw-r--r--projects/cli-test/mgmt-keystore.c25
-rw-r--r--projects/cli-test/mgmt-misc.c30
5 files changed, 31 insertions, 89 deletions
diff --git a/projects/cli-test/Makefile b/projects/cli-test/Makefile
index 1f7faf1..22c8133 100644
--- a/projects/cli-test/Makefile
+++ b/projects/cli-test/Makefile
@@ -1,7 +1,6 @@
TEST = cli-test
OBJS = \
- crc32.o \
mgmt-cli.o \
mgmt-dfu.o \
mgmt-fpga.o \
diff --git a/projects/cli-test/crc32.c b/projects/cli-test/crc32.c
deleted file mode 100644
index 4d1a0bc..0000000
--- a/projects/cli-test/crc32.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Reference code from RFC1952. Not meant to be used outside test code. */
-
-#include "stm32f4xx_hal.h"
-
-
-/* Table of CRCs of all 8-bit messages. */
-unsigned long crc_table[256];
-
-/* Flag: has the table been computed? Initially false. */
-int crc_table_computed = 0;
-
-/* Make the table for a fast CRC. */
-void make_crc_table(void)
-{
- unsigned long c;
-
- int n, k;
- for (n = 0; n < 256; n++) {
- c = (unsigned long) n;
- for (k = 0; k < 8; k++) {
- if (c & 1) {
- c = 0xedb88320L ^ (c >> 1);
- } else {
- c = c >> 1;
- }
- }
- crc_table[n] = c;
- }
- crc_table_computed = 1;
-}
-
-/*
- Update a running crc with the bytes buf[0..len-1] and return
- the updated crc. The crc should be initialized to zero. Pre- and
- post-conditioning (one's complement) is performed within this
- function so it shouldn't be done by the caller. Usage example:
-
- unsigned long crc = 0L;
-
- while (read_buffer(buffer, length) != EOF) {
- crc = update_crc(crc, buffer, length);
- }
- if (crc != original_crc) error();
-*/
-uint32_t update_crc(uint32_t crc, uint8_t *buf, int len)
-{
- unsigned long c = crc ^ 0xffffffffL;
- int n;
-
- if (!crc_table_computed)
- make_crc_table();
- for (n = 0; n < len; n++) {
- c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
- }
- return c ^ 0xffffffffL;
-}
-
-/* Return the CRC of the bytes buf[0..len-1]. */
-unsigned long crc(unsigned char *buf, int len)
-{
- return update_crc(0L, buf, len);
-}
diff --git a/projects/cli-test/mgmt-dfu.c b/projects/cli-test/mgmt-dfu.c
index 851c8ea..5c9b4b7 100644
--- a/projects/cli-test/mgmt-dfu.c
+++ b/projects/cli-test/mgmt-dfu.c
@@ -45,8 +45,6 @@
#define DFU_UPLOAD_CHUNK_SIZE 256
#define HARDWARE_EARLY_DFU_JUMP 0xBADABADA
-extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len);
-
/* Linker symbols are strange in C. Make regular pointers for sanity. */
__IO uint32_t *dfu_control = &CRYPTECH_DFU_CONTROL;
__IO uint32_t *dfu_firmware = &CRYPTECH_FIRMWARE_START;
diff --git a/projects/cli-test/mgmt-keystore.c b/projects/cli-test/mgmt-keystore.c
index 09d512e..e11ef76 100644
--- a/projects/cli-test/mgmt-keystore.c
+++ b/projects/cli-test/mgmt-keystore.c
@@ -33,17 +33,17 @@
*/
/* 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"
#include "stm-uart.h"
-
#include "mgmt-cli.h"
#include "mgmt-show.h"
-
#undef HAL_OK
-#define LIBHAL_OK HAL_OK
+
+#define HAL_OK LIBHAL_OK
#include "hal.h"
#warning Really should not be including hal_internal.h here, fix API instead of bypassing it
#include "hal_internal.h"
@@ -198,7 +198,7 @@ static int cmd_keystore_delete_key(struct cli_def *cli, const char *command, cha
return CLI_ERROR;
}
- if ((status = hal_rpc_pkey_open(client, session, &pkey, &name, HAL_KEY_FLAG_TOKEN)) != LIBHAL_OK ||
+ if ((status = hal_rpc_pkey_open(client, session, &pkey, &name)) != LIBHAL_OK ||
(status = hal_rpc_pkey_delete(pkey)) != LIBHAL_OK) {
cli_print(cli, "Failed deleting key: %s", hal_error_string(status));
return CLI_ERROR;
@@ -231,7 +231,7 @@ static int cmd_keystore_show_data(struct cli_def *cli, const char *command, char
return CLI_OK;
}
-static int show_keys(struct cli_def *cli, const char *title, const hal_key_flags_t qflags)
+static int show_keys(struct cli_def *cli, const char *title)
{
const hal_client_handle_t client = { -1 };
const hal_session_handle_t session = { HAL_HANDLE_NONE };
@@ -240,10 +240,10 @@ static int show_keys(struct cli_def *cli, const char *title, const hal_key_flags
hal_pkey_handle_t pkey;
hal_curve_name_t curve;
hal_key_flags_t flags;
+ unsigned n, state = 0;
hal_key_type_t type;
hal_error_t status;
hal_uuid_t uuids[50];
- unsigned n;
int done = 0;
cli_print(cli, title);
@@ -251,7 +251,8 @@ static int show_keys(struct cli_def *cli, const char *title, const hal_key_flags
while (!done) {
if ((status = hal_rpc_pkey_match(client, session, HAL_KEY_TYPE_NONE, HAL_CURVE_NONE,
- qflags, NULL, 0, uuids, &n, sizeof(uuids)/sizeof(*uuids),
+ 0, 0, NULL, 0, &state, uuids, &n,
+ sizeof(uuids)/sizeof(*uuids),
&previous_uuid)) != LIBHAL_OK) {
cli_print(cli, "Could not fetch UUID list: %s", hal_error_string(status));
return 0;
@@ -270,7 +271,7 @@ static int show_keys(struct cli_def *cli, const char *title, const hal_key_flags
return 0;
}
- if ((status = hal_rpc_pkey_open(client, session, &pkey, &uuids[i], qflags)) != LIBHAL_OK) {
+ if ((status = hal_rpc_pkey_open(client, session, &pkey, &uuids[i])) != LIBHAL_OK) {
cli_print(cli, "Could not open key %s: %s",
key_name, hal_error_string(status));
return 0;
@@ -317,10 +318,10 @@ static int show_keys(struct cli_def *cli, const char *title, const hal_key_flags
static int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[], int argc)
{
- int ok = 1;
- ok &= show_keys(cli, "Memory keystore:", 0);
- ok &= show_keys(cli, "Token keystore:", HAL_KEY_FLAG_TOKEN);
- return ok ? CLI_OK : CLI_ERROR;
+ if (show_keys(cli, "Keystore:"))
+ return CLI_OK;
+ else
+ return CLI_ERROR;
}
static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *argv[], int argc)
diff --git a/projects/cli-test/mgmt-misc.c b/projects/cli-test/mgmt-misc.c
index b7b4fcc..7db08f2 100644
--- a/projects/cli-test/mgmt-misc.c
+++ b/projects/cli-test/mgmt-misc.c
@@ -32,28 +32,32 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#define HAL_OK CMSIS_HAL_OK
#include "stm-init.h"
#include "stm-uart.h"
-
#include "mgmt-cli.h"
#include "mgmt-misc.h"
+#undef HAL_OK
-#include <string.h>
-
+#define HAL_OK LIBHAL_OK
+#include "hal.h"
+#include "hal_internal.h"
+#undef HAL_OK
-extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len);
+#include <string.h>
-static volatile uint32_t demo_crc = 0;
+static volatile hal_crc32_t demo_crc;
static int _count_bytes_callback(uint8_t *buf, size_t len) {
- demo_crc = update_crc(demo_crc, buf, len);
+ demo_crc = hal_crc32_update(demo_crc, buf, len);
return 1;
}
int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_callback data_callback)
{
- uint32_t filesize = 0, crc = 0, my_crc = 0, counter = 0;
+ hal_crc32_t crc = 0, my_crc = hal_crc32_init();
+ uint32_t filesize = 0, counter = 0;
size_t n = len;
if (! control_mgmt_uart_dma_rx(DMA_RX_STOP)) {
@@ -63,7 +67,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
cli_print(cli, "OK, write size (4 bytes), data in %li byte chunks, CRC-32 (4 bytes)", (uint32_t) n);
- if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, 4, 1000) != HAL_OK) {
+ if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) {
cli_print(cli, "Receive timed out");
goto fail;
}
@@ -78,12 +82,12 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
if (filesize < n) n = filesize;
- if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != HAL_OK) {
+ if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != CMSIS_HAL_OK) {
cli_print(cli, "Receive timed out");
goto fail;
}
filesize -= n;
- my_crc = update_crc(my_crc, buf, n);
+ my_crc = hal_crc32_update(my_crc, buf, n);
/* After reception of a chunk but before ACKing we have "all" the time in the world to
* calculate CRC and invoke the data_callback.
@@ -97,8 +101,9 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4);
}
+ my_crc = hal_crc32_finalize(my_crc);
cli_print(cli, "Send CRC-32");
- uart_receive_bytes(STM_UART_MGMT, (void *) &crc, 4, 1000);
+ uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 1000);
cli_print(cli, "CRC-32 0x%x, calculated CRC 0x%x", (unsigned int) crc, (unsigned int) my_crc);
if (crc == my_crc) {
cli_print(cli, "CRC checksum MATCHED");
@@ -115,8 +120,9 @@ static int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv
{
uint8_t buf[FILETRANSFER_UPLOAD_CHUNK_SIZE];
- demo_crc = 0;
+ demo_crc = hal_crc32_init();
cli_receive_data(cli, &buf[0], sizeof(buf), _count_bytes_callback);
+ demo_crc = hal_crc32_finalize(demo_crc);
cli_print(cli, "Demo CRC is: %li/0x%x", demo_crc, (unsigned int) demo_crc);
return CLI_OK;
}