Skip to content

Commit

Permalink
[#164] Added TC debug toggle command to standalone for demonstration …
Browse files Browse the repository at this point in the history
…purposes;
  • Loading branch information
jlucas9 committed Jun 15, 2023
1 parent 53f1128 commit 49039bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
44 changes: 35 additions & 9 deletions support/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
static volatile uint8_t keepRunning = CRYPTO_LIB_SUCCESS;
static volatile uint8_t tc_seq_num = 0;
static volatile uint8_t tc_vcid = CRYPTO_STANDALONE_FRAMING_VCID;
static volatile uint8_t tc_debug = 0;


/*
Expand Down Expand Up @@ -61,10 +62,11 @@ void crypto_standalone_print_help(void)
{
printf(CRYPTO_PROMPT "command [args]\n"
"----------------------------------------------------------------------\n"
"help - Display help \n"
"exit - Exit app \n"
"help - Display help \n"
"noop - No operation command to device \n"
"reset - Reset CryptoLib \n"
"tc - Toggle TC debug prints \n"
"vcid # - Change active TC virtual channel \n"
"\n"
);
Expand Down Expand Up @@ -98,6 +100,10 @@ int32_t crypto_standalone_get_command(const char* str)
{
status = CRYPTO_CMD_VCID;
}
else if(strcmp(lcmd, "tc") == 0)
{
status = CRYPTO_CMD_TC_DEBUG;
}
return status;
}

Expand Down Expand Up @@ -167,6 +173,22 @@ int32_t crypto_standalone_process_command(int32_t cc, int32_t num_tokens, char*
}
}
break;

case CRYPTO_CMD_TC_DEBUG:
if (crypto_standalone_check_number_arguments(num_tokens, 0) == CRYPTO_LIB_SUCCESS)
{
if (tc_debug == 0)
{
tc_debug = 1;
printf("Enabled TC debug prints! \n");
}
else
{
tc_debug = 1;
printf("Disabled TC debug prints! \n");
}
}
break;

default:
printf("Invalid command format, type 'help' for more info\n");
Expand Down Expand Up @@ -287,43 +309,46 @@ void* crypto_standalone_tc_apply(void* sock)
if (status != -1)
{
tc_in_len = status;
#ifdef CRYPTO_STANDALONE_TC_APPLY_DEBUG
if (tc_debug == 1)
{
printf("crypto_standalone_tc_apply - received[%d]: 0x", tc_in_len);
for(int i = 0; i < status; i++)
{
printf("%02x", tc_apply_in[i]);
}
printf("\n");
#endif
}

/* Frame */
#ifdef CRYPTO_STANDALONE_HANDLE_FRAMING
crypto_standalone_tc_frame(tc_apply_in, tc_in_len, tc_framed, &tc_out_len);
memcpy(tc_apply_in, tc_framed, tc_out_len);
tc_in_len = tc_out_len;
tc_out_len = 0;
#ifdef CRYPTO_STANDALONE_TC_APPLY_DEBUG
if (tc_debug == 1)
{
printf("crypto_standalone_tc_apply - framed[%d]: 0x", tc_in_len);
for(int i = 0; i < tc_in_len; i++)
{
printf("%02x", tc_apply_in[i]);
}
printf("\n");
#endif
}
#endif

/* Process */
status = Crypto_TC_ApplySecurity(tc_apply_in, tc_in_len, &tc_out_ptr, &tc_out_len);
if (status == CRYPTO_LIB_SUCCESS)
{
#ifdef CRYPTO_STANDALONE_TC_APPLY_DEBUG
if (tc_debug == 1)
{
printf("crypto_standalone_tc_apply - status = %d, encrypted[%d]: 0x", status, tc_out_len);
for(int i = 0; i < tc_out_len; i++)
{
printf("%02x", tc_out_ptr[i]);
}
printf("\n");
#endif
}

/* Reply */
status = sendto(tc_sock->sockfd, tc_out_ptr, tc_out_len, 0, (struct sockaddr*) &fwd_addr, sizeof(fwd_addr));
Expand All @@ -342,9 +367,10 @@ void* crypto_standalone_tc_apply(void* sock)
tc_in_len = 0;
tc_out_len = 0;
free(tc_out_ptr);
#ifdef CRYPTO_STANDALONE_TC_APPLY_DEBUG
if (tc_debug == 1)
{
printf("\n");
#endif
}
}

/* Delay */
Expand Down
1 change: 1 addition & 0 deletions support/standalone/standalone.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ extern "C"
#define CRYPTO_CMD_NOOP 2
#define CRYPTO_CMD_RESET 3
#define CRYPTO_CMD_VCID 4
#define CRYPTO_CMD_TC_DEBUG 5


/*
Expand Down

0 comments on commit 49039bf

Please sign in to comment.