|
@@ -1,6 +1,6 @@
|
|
|
/*shell.c
|
|
|
*
|
|
|
- * Copyright (C) 2006-2016 wolfSSL Inc.
|
|
|
+ * Copyright (C) 2006-2017 wolfSSL Inc.
|
|
|
*
|
|
|
* This file is part of wolfSSL.
|
|
|
*
|
|
@@ -19,9 +19,9 @@
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
|
|
*/
|
|
|
|
|
|
-
|
|
|
+
|
|
|
/*** tiny Shell for wolfSSL apps ***/
|
|
|
-
|
|
|
+
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
#include <config.h>
|
|
|
#endif
|
|
@@ -36,7 +36,7 @@
|
|
|
#include <stdlib.h>
|
|
|
#if defined(WOLFSSL_MDK5) || defined(WOLFSSL_KEIL_TCP_NET)
|
|
|
#include "cmsis_os.h"
|
|
|
- #include "rl_fs.h"
|
|
|
+ #include "rl_fs.h"
|
|
|
#else
|
|
|
#include <rtl.h>
|
|
|
#endif
|
|
@@ -192,7 +192,7 @@ extern void dh_test(void *arg) ;
|
|
|
#ifndef NO_DSA
|
|
|
extern void dsa_test(void *arg) ;
|
|
|
#endif
|
|
|
-
|
|
|
+
|
|
|
#ifndef NO_PWDBASED
|
|
|
extern void pwdbased_test(void *arg) ;
|
|
|
#endif
|
|
@@ -283,8 +283,8 @@ static struct {
|
|
|
#ifndef NO_DES3
|
|
|
"des", des_test,
|
|
|
"des3", des3_test,
|
|
|
-#endif
|
|
|
-#ifndef NO_AES
|
|
|
+#endif
|
|
|
+#ifndef NO_AES
|
|
|
"aes", aes_test,
|
|
|
#ifdef HAVE_AESGCM
|
|
|
"aesgcm", aesgcm_test,
|
|
@@ -306,10 +306,10 @@ static struct {
|
|
|
#endif
|
|
|
#ifndef NO_DSA
|
|
|
"dsa", dsa_test,
|
|
|
-#endif
|
|
|
+#endif
|
|
|
#ifndef NO_PWDBASED
|
|
|
"pwdbased", pwdbased_test,
|
|
|
-#endif
|
|
|
+#endif
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
"openssl", openssl_test,
|
|
|
#endif
|
|
@@ -328,29 +328,29 @@ enum jobtype { FORGROUND, BACKGROUND } ;
|
|
|
|
|
|
static int BackGround = 0 ; /* 1: background job is running */
|
|
|
|
|
|
-char * wolfssl_fgets ( char * str, int num, FILE * f )
|
|
|
+char * wolfssl_fgets ( char * str, int num, FILE * f )
|
|
|
{
|
|
|
int i ;
|
|
|
-
|
|
|
+
|
|
|
for(i = 0 ; i< num ; i++) {
|
|
|
while((str[i] = getchar()) == 0) {
|
|
|
#if defined (HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
|
|
|
os_tsk_pass ();
|
|
|
- #else
|
|
|
+ #else
|
|
|
osThreadYield ();
|
|
|
#endif
|
|
|
}
|
|
|
if(str[i] == '\n' || str[i] == '\012' || str[i] == '\015') {
|
|
|
putchar('\n') ;
|
|
|
- str[i++] = '\n' ;
|
|
|
- str[i] = '\0' ;
|
|
|
+ str[i++] = '\n' ;
|
|
|
+ str[i] = '\0' ;
|
|
|
break ;
|
|
|
} else if(str[i] == '\010') { /* BS */
|
|
|
if(i) { /* erace one char */
|
|
|
- putchar('\010') ; putchar(' ') ; putchar('\010') ;
|
|
|
+ putchar('\010') ; putchar(' ') ; putchar('\010') ;
|
|
|
i = (i>0 ? (i-2) : -1 ) ;
|
|
|
continue ;
|
|
|
- }
|
|
|
+ }
|
|
|
} else if(str[i] == '\033' || str[i] == '\004' ) { /* ESC or ^D */
|
|
|
str[i] = '\0' ;
|
|
|
return(0) ;
|
|
@@ -361,23 +361,23 @@ char * wolfssl_fgets ( char * str, int num, FILE * f )
|
|
|
}
|
|
|
|
|
|
/******* Get Command Line *****************************/
|
|
|
-static int getline(char * line, int sz, func_args *args, int*bf_flg)
|
|
|
+static int getline(char * line, int sz, func_args *args, int*bf_flg)
|
|
|
{
|
|
|
char * ret ;
|
|
|
int i ;
|
|
|
-
|
|
|
+
|
|
|
#define MAXARGS 10
|
|
|
#define MAXARGLEN 30
|
|
|
static char *argv[MAXARGS] ;
|
|
|
args->argv = argv ;
|
|
|
-
|
|
|
+
|
|
|
putchar('>') ;
|
|
|
fflush(stdout) ;
|
|
|
ret = wolfssl_fgets(line, sz, stdin) ;
|
|
|
-
|
|
|
+
|
|
|
#define SHELL_ERROR_FGETS -102
|
|
|
if(ret != line) return(SHELL_ERROR_FGETS) ;
|
|
|
-
|
|
|
+
|
|
|
if(line[strlen(line)-2] == '&') {
|
|
|
(*bf_flg) = BACKGROUND ;
|
|
|
line[strlen(line)-2] = '\n' ;
|
|
@@ -404,22 +404,22 @@ static int getline(char * line, int sz, func_args *args, int*bf_flg)
|
|
|
#define IP_SIZE 16
|
|
|
|
|
|
#ifdef WOLFSSL_KEIL_TCP_NET
|
|
|
-static void ipaddr_comm(void *args)
|
|
|
+static void ipaddr_comm(void *args)
|
|
|
{
|
|
|
if(((func_args *)args)->argc == 1) {
|
|
|
printf("IP addr: %s, port %d\n", wolfSSLIP, wolfSSLPort) ;
|
|
|
} else {
|
|
|
if(BackGround != 0) {
|
|
|
printf("Cannot change IP addr while background server is running\n") ;
|
|
|
- } else if(((func_args *)args)->argc == 3 &&
|
|
|
- ((func_args *)args)->argv[1][0] == '-'&&
|
|
|
+ } else if(((func_args *)args)->argc == 3 &&
|
|
|
+ ((func_args *)args)->argv[1][0] == '-'&&
|
|
|
((func_args *)args)->argv[1][1] == 'a' ) {
|
|
|
/* strcpy(yasslIP, ((func_args *)args)->argv[2]) ; */
|
|
|
- } else if(((func_args *)args)->argc == 3 &&
|
|
|
- ((func_args *)args)->argv[1][0] == '-' &&
|
|
|
+ } else if(((func_args *)args)->argc == 3 &&
|
|
|
+ ((func_args *)args)->argv[1][0] == '-' &&
|
|
|
((func_args *)args)->argv[1][1] == 'p' ) {
|
|
|
/* yasslPort = atoi(((func_args *)args)->argv[2]) ; */
|
|
|
- } else printf("Invalid argument\n") ;
|
|
|
+ } else printf("Invalid argument\n") ;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -430,7 +430,7 @@ static void ipaddr_comm(void *args)
|
|
|
#if defined(HAVE_KEIL_RTX)
|
|
|
static int stack_ck = 0 ;
|
|
|
|
|
|
-void stack_comm(void *args)
|
|
|
+void stack_comm(void *args)
|
|
|
{
|
|
|
if(stack_ck) {
|
|
|
printf("Stack Check: Off\n") ;
|
|
@@ -440,7 +440,7 @@ void stack_comm(void *args)
|
|
|
stack_ck = 1 ;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#define FILL_PATTERN 0xa596695a
|
|
|
void stack_fill(char * stack, int size)
|
|
|
{
|
|
@@ -451,13 +451,13 @@ void stack_fill(char * stack, int size)
|
|
|
((int *)stack)[i] = FILL_PATTERN ;
|
|
|
}
|
|
|
|
|
|
-void stack_check(char * stack, int size)
|
|
|
+void stack_check(char * stack, int size)
|
|
|
{
|
|
|
int i ;
|
|
|
-
|
|
|
+
|
|
|
if(stack_ck == 0)return ;
|
|
|
if(stack_ck == 1) {
|
|
|
- stack_ck ++ ; return ;
|
|
|
+ stack_ck ++ ; return ;
|
|
|
}
|
|
|
for(i=1; i<size/4 ; i++) {
|
|
|
if(((int *)stack)[i] != FILL_PATTERN) break ;
|
|
@@ -473,7 +473,7 @@ void stack_check(char * stack, int size)
|
|
|
|
|
|
static int for_iteration = 1 ;
|
|
|
|
|
|
-static void for_command(void *args)
|
|
|
+static void for_command(void *args)
|
|
|
{
|
|
|
if( args == NULL || ((func_args *)args)->argc == 1) {
|
|
|
printf("For %d times\n", for_iteration) ;
|
|
@@ -487,7 +487,7 @@ static void for_command(void *args)
|
|
|
|
|
|
static int wolfsslDebug = 1 ;
|
|
|
|
|
|
-static void dbg_comm(void *args)
|
|
|
+static void dbg_comm(void *args)
|
|
|
{
|
|
|
if(wolfsslDebug == 1) {
|
|
|
wolfsslDebug = 0 ;
|
|
@@ -501,10 +501,10 @@ static void dbg_comm(void *args)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-static void help_comm(void *args)
|
|
|
+static void help_comm(void *args)
|
|
|
{
|
|
|
static char *commands[] = {
|
|
|
- "test",
|
|
|
+ "test",
|
|
|
"benchmark",
|
|
|
"echoserver& : simple echo server in background mode",
|
|
|
"echoclient : simple echo client followed by any input string, or \"quit\", \"break\"",
|
|
@@ -513,7 +513,7 @@ static void help_comm(void *args)
|
|
|
"client -g -v [0123] -h xxx.xxx.xxx.xxx -p 443 : usage example",
|
|
|
"server/client -h : help for server/client command",
|
|
|
"help",
|
|
|
- ""
|
|
|
+ ""
|
|
|
} ;
|
|
|
|
|
|
int i ;
|
|
@@ -555,12 +555,12 @@ void exit_command(void) {
|
|
|
|
|
|
|
|
|
/*********** Invoke Forground Command *********************/
|
|
|
-static void command_invoke(void const *args)
|
|
|
+static void command_invoke(void const *args)
|
|
|
{
|
|
|
void (*func)(void const * ) ;
|
|
|
int i,iteration ;
|
|
|
-
|
|
|
- func = (void(*)(void const *))((func_args *)args)->argv[0] ;
|
|
|
+
|
|
|
+ func = (void(*)(void const *))((func_args *)args)->argv[0] ;
|
|
|
#if defined(HAVE_KEIL_RTX)
|
|
|
wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ;
|
|
|
#endif
|
|
@@ -570,15 +570,15 @@ static void command_invoke(void const *args)
|
|
|
#if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
|
|
|
stack_fill(command_stack, COMMAND_STACK_SIZE) ;
|
|
|
#endif
|
|
|
-
|
|
|
+
|
|
|
func(args) ; /* invoke command */
|
|
|
-
|
|
|
+
|
|
|
#if defined(HAVE_KEIL_RTX)&& !defined(WOLFSSL_CMSIS_RTOS)
|
|
|
stack_check(command_stack, COMMAND_STACK_SIZE) ;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
- if(iteration > 1)
|
|
|
+ if(iteration > 1)
|
|
|
for_iteration = 1 ;
|
|
|
osDelay(20000) ;
|
|
|
#ifdef HAVE_KEIL_RTX
|
|
@@ -593,26 +593,26 @@ static void command_invoke(void const *args)
|
|
|
|
|
|
#if defined(HAVE_KEIL_RTX) || defined(WOLFSSL_CMSIS_RTOS)
|
|
|
/******* Invoke Background Job *******************************/
|
|
|
-static void bg_job_invoke(void const *args)
|
|
|
+static void bg_job_invoke(void const *args)
|
|
|
{
|
|
|
void (*func)(void const * ) ;
|
|
|
- BackGround = 1 ;
|
|
|
+ BackGround = 1 ;
|
|
|
#if defined(HAVE_KEIL_RTX)&& !defined(WOLFSSL_CMSIS_RTOS)
|
|
|
stack_fill(bg_job_stack, BG_JOB_STACK_SIZE) ;
|
|
|
#endif
|
|
|
|
|
|
- func = (void(*)(void const *))((func_args *)args)->argv[0] ;
|
|
|
+ func = (void(*)(void const *))((func_args *)args)->argv[0] ;
|
|
|
func(args) ; /* invoke command */
|
|
|
#if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
|
|
|
stack_check(bg_job_stack, BG_JOB_STACK_SIZE) ;
|
|
|
#endif
|
|
|
-
|
|
|
+
|
|
|
osDelay(20000) ;
|
|
|
BackGround = 0 ;
|
|
|
|
|
|
#ifdef WOLFSSL_CMSIS_RTOS
|
|
|
osThreadTerminate(osThreadGetId()) ;
|
|
|
- #else
|
|
|
+ #else
|
|
|
os_tsk_delete_self() ; ;
|
|
|
#endif
|
|
|
}
|
|
@@ -627,18 +627,18 @@ static char line[LINESIZE] ;
|
|
|
#endif
|
|
|
/********* SHEULL MAIN LOOP ***********************************/
|
|
|
void shell_main(void *arg) {
|
|
|
- int i ;
|
|
|
+ int i ;
|
|
|
func_args args ;
|
|
|
int bf_flg ;
|
|
|
osThreadId cmd ;
|
|
|
- i = BackGround ;
|
|
|
+ i = BackGround ;
|
|
|
/* Dummy for avoiding warning: BackGround is defined but not used. */
|
|
|
-
|
|
|
- #if defined(HAVE_KEIL_RTX)
|
|
|
+
|
|
|
+ #if defined(HAVE_KEIL_RTX)
|
|
|
wc_InitMutex(&command_mutex) ;
|
|
|
#endif
|
|
|
help_comm(NULL) ;
|
|
|
-
|
|
|
+
|
|
|
printf("Starting Shell\n") ;
|
|
|
while(1) {
|
|
|
if(getline(line, LINESIZE, &args, &bf_flg) > 0) {
|
|
@@ -654,7 +654,7 @@ void shell_main(void *arg) {
|
|
|
#else
|
|
|
#if defined(WOLFSSL_CMSIS_RTOS)
|
|
|
wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ;
|
|
|
- cmd = osThreadCreate (osThread (command_invoke) , &args);
|
|
|
+ cmd = osThreadCreate (osThread (command_invoke) , &args);
|
|
|
if(cmd == NULL) {
|
|
|
printf("Cannon create command thread\n") ;
|
|
|
}
|
|
@@ -673,13 +673,13 @@ void shell_main(void *arg) {
|
|
|
if(BackGround != 0) {
|
|
|
printf("Multiple background servers not supported.\n") ;
|
|
|
} else {
|
|
|
- printf("\"%s\" is running with the background mode.\n",
|
|
|
+ printf("\"%s\" is running with the background mode.\n",
|
|
|
commandTable[i].command) ;
|
|
|
#if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
|
|
|
- os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke,
|
|
|
+ os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke,
|
|
|
6, bg_job_stack, BG_JOB_STACK_SIZE, &args) ;
|
|
|
#else
|
|
|
- osThreadCreate (osThread (bg_job_invoke), &args);
|
|
|
+ osThreadCreate (osThread (bg_job_invoke), &args);
|
|
|
osDelay (500) ;
|
|
|
#endif
|
|
|
}
|