1
0

shell.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*shell.c
  2. *
  3. * Copyright (C) 2006-2021 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*** tiny Shell for wolfSSL apps ***/
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25. #include "wolfssl/internal.h"
  26. #include <wolfssl/wolfcrypt/logging.h>
  27. #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #if defined(WOLFSSL_MDK5) || defined(WOLFSSL_KEIL_TCP_NET)
  32. #include "cmsis_os.h"
  33. #include "rl_fs.h"
  34. #else
  35. #include <rtl.h>
  36. #endif
  37. #endif
  38. #ifdef WOLFSSL_KEIL_TCP_NET
  39. #include "wolfssl/test.h"
  40. #else
  41. typedef struct func_args {
  42. int argc;
  43. char** argv;
  44. int return_code;
  45. } func_args;
  46. #endif
  47. #if defined(WOLFSSL_CMSIS_RTOS)
  48. #define HAVE_KEIL_RTX
  49. #endif
  50. #ifdef NO_ECHOCLIENT
  51. #define echoclient_test command_not_found
  52. #endif
  53. #ifdef NO_ECHOSERVER
  54. #define echoserver_test command_not_found
  55. #endif
  56. #ifdef NO_SIMPLE_CLIENT
  57. #define client_test command_not_found
  58. #endif
  59. #ifdef NO_SIMPLE_SERVER
  60. #define server_test command_not_found
  61. #endif
  62. #ifdef NO_CRYPT_BENCHMARK
  63. #define benchmark_test command_not_found
  64. #endif
  65. #ifdef NO_CRYPT_TEST
  66. #define ctaocrypt_test command_not_found
  67. #endif
  68. #ifndef WOLFSSL_KEIL_TCP_NET
  69. #define ipaddr_comm command_not_found
  70. #endif
  71. #if !defined(HAVE_KEIL_RTX)
  72. #define stack_comm command_not_found
  73. #endif
  74. #if !defined(DEBUG_WOLFSSL)
  75. #define dbg_comm command_not_found
  76. #endif
  77. void command_not_found(void *argv) {
  78. printf("Command not found\n") ;
  79. }
  80. extern void echoclient_test(void *args) ;
  81. extern void echoserver_test(void *args) ;
  82. extern void benchmark_test(void *args) ;
  83. extern void wolfcrypt_test(void *args) ;
  84. extern void client_test(void *args) ;
  85. extern void server_test(void *args) ;
  86. extern void kill_task(void *args) ;
  87. extern void ipaddr_comm(void *args) ;
  88. extern void stack_comm(void *args) ;
  89. extern void for_command(void *args) ;
  90. extern void dbg_comm(void *arg) ;
  91. extern void help_comm(void *arg) ;
  92. #if !defined(NO_CRYPT_TEST)
  93. #ifndef NO_MD5
  94. extern void md5_test(void *arg) ;
  95. #endif
  96. #ifdef WOLFSSL_MD2
  97. extern void md2_test(void *arg) ;
  98. #endif
  99. #ifndef NO_MD4
  100. extern void md4_test(void *arg) ;
  101. #endif
  102. extern void sha_test(void *arg) ;
  103. #ifndef NO_SHA256
  104. extern void sha256_test(void *arg) ;
  105. #endif
  106. #ifdef WOLFSSL_SHA384
  107. extern void sha384_test(void *arg) ;
  108. #endif
  109. #ifdef WOLFSSL_SHA512
  110. extern void sha512_test(void *arg) ;
  111. #endif
  112. #ifdef WOLFSSL_RIPEMD
  113. extern void ripemd_test(void *arg) ;
  114. #endif
  115. #ifndef NO_HMAC
  116. #ifndef NO_MD5
  117. extern void hmac_md5_test(void *arg) ;
  118. #endif
  119. extern void hmac_sha_test(void *arg) ;
  120. #ifndef NO_SHA256
  121. extern void hmac_sha256_test(void *arg) ;
  122. #endif
  123. #ifdef WOLFSSL_SHA384
  124. extern void hmac_sha384_test(void *arg) ;
  125. #endif
  126. #endif
  127. #ifndef NO_RC4
  128. extern void arc4_test(void *arg) ;
  129. #endif
  130. #ifndef NO_HC128
  131. extern void hc128_test(void *arg) ;
  132. #endif
  133. #ifndef NO_RABBIT
  134. extern void rabbit_test(void *arg) ;
  135. #endif
  136. #ifndef NO_DES3
  137. extern void des_test(void *arg) ;
  138. extern void des3_test(void *arg) ;
  139. #endif
  140. #ifndef NO_AES
  141. extern void aes_test(void *arg) ;
  142. #ifdef HAVE_AESGCM
  143. extern void aesgcm_test(void *arg) ;
  144. #endif
  145. #ifdef HAVE_AESCCM
  146. extern void aesccm_test(void *arg) ;
  147. #endif
  148. #endif
  149. #ifdef HAVE_CAMELLIA
  150. extern void camellia_test(void *arg) ;
  151. #endif
  152. extern void random_test(void *arg) ;
  153. #ifndef NO_RSA
  154. extern void rsa_test(void *arg) ;
  155. #endif
  156. #ifndef NO_DH
  157. extern void dh_test(void *arg) ;
  158. #endif
  159. #ifndef NO_DSA
  160. extern void dsa_test(void *arg) ;
  161. #endif
  162. #ifndef NO_PWDBASED
  163. extern void pwdbased_test(void *arg) ;
  164. #endif
  165. #ifdef OPENSSL_EXTRA
  166. extern void openssl_test(void *arg) ;
  167. #endif
  168. #ifdef HAVE_ECC
  169. extern void ecc_test(void *arg) ;
  170. #endif
  171. #endif /* NO_CRYPT_TEST */
  172. static struct {
  173. const char *command ;
  174. void (*func)(void *args) ;
  175. } commandTable[] = {
  176. "echoclient", echoclient_test,
  177. "echoserver", echoserver_test,
  178. "benchmark", benchmark_test,
  179. "test", wolfcrypt_test,
  180. "client", client_test,
  181. "server", server_test,
  182. "ipaddr", ipaddr_comm, /* TBD */
  183. "stack", stack_comm, /* On/Off check stack size */
  184. "for", for_command, /* iterate next command X times */
  185. "debug", dbg_comm, /* On/Off debug message */
  186. "help", help_comm, /* Brief description about the commands */
  187. /** short name **/
  188. "ec", echoclient_test,
  189. "es", echoserver_test,
  190. "bm", benchmark_test,
  191. "te", wolfcrypt_test,
  192. "cl", client_test,
  193. "sv", server_test,
  194. "ip", ipaddr_comm,
  195. "st", stack_comm,
  196. "dbg", dbg_comm,
  197. "?", help_comm,
  198. /*** test suites ****/
  199. #if !defined(NO_CRYPT_TEST)
  200. #ifndef NO_MD5
  201. "md5", md5_test,
  202. #endif
  203. #ifdef WOLFSSL_MD2
  204. "md2", md2_test,
  205. #endif
  206. #ifndef NO_MD4
  207. "md4", md4_test,
  208. #endif
  209. "sha", sha_test,
  210. #ifndef NO_SHA256
  211. "sha256", sha256_test,
  212. #endif
  213. #ifdef WOLFSSL_SHA384
  214. "sha384", sha384_test,
  215. #endif
  216. #ifdef WOLFSSL_SHA512
  217. "sha512", sha512_test,
  218. #endif
  219. #ifdef WOLFSSL_RIPEMD
  220. "ripemd", ripemd_test,
  221. #endif
  222. #ifndef NO_HMAC
  223. #ifndef NO_MD5
  224. "hmac_md5", hmac_md5_test,
  225. #endif
  226. "hmac_sha", hmac_sha_test,
  227. #ifndef NO_SHA256
  228. "hmac_sha256", hmac_sha256_test,
  229. #endif
  230. #ifdef WOLFSSL_SHA384
  231. "hmac_sha384", hmac_sha384_test,
  232. #endif
  233. #endif
  234. #ifndef NO_RC4
  235. "arc4", arc4_test,
  236. #endif
  237. #ifndef NO_HC128
  238. "hc128", hc128_test,
  239. #endif
  240. #ifndef NO_RABBIT
  241. "rabbit", rabbit_test,
  242. #endif
  243. #ifndef NO_DES3
  244. "des", des_test,
  245. "des3", des3_test,
  246. #endif
  247. #ifndef NO_AES
  248. "aes", aes_test,
  249. #ifdef HAVE_AESGCM
  250. "aesgcm", aesgcm_test,
  251. #endif
  252. #ifdef HAVE_AESCCM
  253. "aesccm", aesccm_test,
  254. #endif
  255. #endif
  256. #ifdef HAVE_CAMELLIA
  257. "camellia", camellia_test,
  258. #endif
  259. "random", random_test,
  260. #ifndef NO_RSA
  261. "rsa", rsa_test,
  262. #endif
  263. #ifndef NO_DH
  264. "dh", dh_test,
  265. #endif
  266. #ifndef NO_DSA
  267. "dsa", dsa_test,
  268. #endif
  269. #ifndef NO_PWDBASED
  270. "pwdbased", pwdbased_test,
  271. #endif
  272. #ifdef OPENSSL_EXTRA
  273. "openssl", openssl_test,
  274. #endif
  275. #ifdef HAVE_ECC
  276. "ecc", ecc_test,
  277. #endif
  278. #endif /* NO_CRYPT_TEST */
  279. "", NULL
  280. } ;
  281. enum jobtype { FORGROUND, BACKGROUND } ;
  282. #define IF_DELIMITER(ch) ((ch) == ' ' || (ch) == '\n')
  283. static int BackGround = 0 ; /* 1: background job is running */
  284. char * wolfssl_fgets ( char * str, int num, FILE * f )
  285. {
  286. int i ;
  287. for(i = 0 ; i< num ; i++) {
  288. while((str[i] = getchar()) == 0) {
  289. #if defined (HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
  290. os_tsk_pass ();
  291. #else
  292. osThreadYield ();
  293. #endif
  294. }
  295. if(str[i] == '\n' || str[i] == '\012' || str[i] == '\015') {
  296. putchar('\n') ;
  297. str[i++] = '\n' ;
  298. str[i] = '\0' ;
  299. break ;
  300. } else if(str[i] == '\010') { /* BS */
  301. if(i) { /* erace one char */
  302. putchar('\010') ; putchar(' ') ; putchar('\010') ;
  303. i = (i>0 ? (i-2) : -1 ) ;
  304. continue ;
  305. }
  306. } else if(str[i] == '\033' || str[i] == '\004' ) { /* ESC or ^D */
  307. str[i] = '\0' ;
  308. return(0) ;
  309. }
  310. putchar(str[i]) ;
  311. }
  312. return(str) ;
  313. }
  314. /******* Get Command Line *****************************/
  315. static int getline(char * line, int sz, func_args *args, int*bf_flg)
  316. {
  317. char * ret ;
  318. int i ;
  319. #define MAXARGS 10
  320. #define MAXARGLEN 30
  321. static char *argv[MAXARGS] ;
  322. args->argv = argv ;
  323. putchar('>') ;
  324. fflush(stdout) ;
  325. ret = wolfssl_fgets(line, sz, stdin) ;
  326. #define SHELL_ERROR_FGETS -102
  327. if(ret != line) return(SHELL_ERROR_FGETS) ;
  328. if(line[strlen(line)-2] == '&') {
  329. (*bf_flg) = BACKGROUND ;
  330. line[strlen(line)-2] = '\n' ;
  331. } else {
  332. (*bf_flg) = FORGROUND ;
  333. }
  334. args->argc = 0 ;
  335. for(i=0; i<sz; i++) {
  336. args->argv[args->argc] = &(line[i]) ;
  337. while(!IF_DELIMITER(line[i])) i++ ;
  338. args->argc++ ;
  339. if(line[i] == '\n') {
  340. line[i] = '\0' ;
  341. break ;
  342. } else {
  343. line[i] = '\0' ;
  344. }
  345. }
  346. return i ;
  347. }
  348. /************* Embedded Shell Commands **********************************/
  349. #define IP_SIZE 16
  350. #ifdef WOLFSSL_KEIL_TCP_NET
  351. static void ipaddr_comm(void *args)
  352. {
  353. if(((func_args *)args)->argc == 1) {
  354. printf("IP addr: %s, port %d\n", wolfSSLIP, wolfSSLPort) ;
  355. } else {
  356. if(BackGround != 0) {
  357. printf("Cannot change IP addr while background server is running\n") ;
  358. } else if(((func_args *)args)->argc == 3 &&
  359. ((func_args *)args)->argv[1][0] == '-'&&
  360. ((func_args *)args)->argv[1][1] == 'a' ) {
  361. /* strcpy(yasslIP, ((func_args *)args)->argv[2]) ; */
  362. } else if(((func_args *)args)->argc == 3 &&
  363. ((func_args *)args)->argv[1][0] == '-' &&
  364. ((func_args *)args)->argv[1][1] == 'p' ) {
  365. /* yasslPort = atoi(((func_args *)args)->argv[2]) ; */
  366. } else printf("Invalid argument\n") ;
  367. }
  368. }
  369. #endif
  370. #if defined(HAVE_KEIL_RTX)
  371. static int stack_ck = 0 ;
  372. void stack_comm(void *args)
  373. {
  374. if(stack_ck) {
  375. printf("Stack Check: Off\n") ;
  376. stack_ck = 0 ;
  377. } else {
  378. printf("Stack Check: On\n") ;
  379. stack_ck = 1 ;
  380. }
  381. }
  382. #define FILL_PATTERN 0xa596695a
  383. void stack_fill(char * stack, int size)
  384. {
  385. int i ;
  386. if(stack_ck == 0)return ;
  387. for(i=1; i<size/4-10; i++)
  388. ((int *)stack)[i] = FILL_PATTERN ;
  389. }
  390. void stack_check(char * stack, int size)
  391. {
  392. int i ;
  393. if(stack_ck == 0)return ;
  394. if(stack_ck == 1) {
  395. stack_ck ++ ; return ;
  396. }
  397. for(i=1; i<size/4 ; i++) {
  398. if(((int *)stack)[i] != FILL_PATTERN) break ;
  399. }
  400. if(i < size/4) {
  401. printf("Stack is used %d bytes out of %d\n", size - i*4, size) ;
  402. } else {
  403. printf("Stack overflow. Stack size: %d\n", size) ;
  404. }
  405. }
  406. #endif /* HAVE_KEIL_RTX */
  407. static int for_iteration = 1 ;
  408. static void for_command(void *args)
  409. {
  410. if( args == NULL || ((func_args *)args)->argc == 1) {
  411. printf("For %d times\n", for_iteration) ;
  412. } else if(((func_args *)args)->argc == 2) {
  413. for_iteration = atoi(((func_args *)args)->argv[1]) ;
  414. } else printf("Invalid argument\n") ;
  415. }
  416. #if defined(DEBUG_WOLFSSL)
  417. static int wolfsslDebug = 1 ;
  418. static void dbg_comm(void *args)
  419. {
  420. if(wolfsslDebug == 1) {
  421. wolfsslDebug = 0 ;
  422. printf("Turning OFF Debug message\n") ;
  423. wolfSSL_Debugging_OFF() ;
  424. } else {
  425. wolfasslDebug = 1 ;
  426. printf("Turning ON Debug message\n") ;
  427. wolfSSL_Debugging_ON() ;
  428. }
  429. }
  430. #endif
  431. static void help_comm(void *args)
  432. {
  433. static char *commands[] = {
  434. "test",
  435. "benchmark",
  436. "echoserver& : simple echo server in background mode",
  437. "echoclient : simple echo client followed by any input string, or \"quit\", \"break\"",
  438. "server& : simple server in background mode",
  439. "client : simple client",
  440. "client -g -v [0123] -h xxx.xxx.xxx.xxx -p 443 : usage example",
  441. "server/client -h : help for server/client command",
  442. "help",
  443. ""
  444. } ;
  445. int i ;
  446. printf("Commands:\n") ;
  447. for(i=0; commands[i][0] ; i++)
  448. printf(" %s\n", commands[i]) ;
  449. }
  450. #define BG_JOB_STACK_SIZE 16000
  451. #if (!defined(NO_SIMPLE_SERVER) && !defined(NO_ECHOSERVER)) && \
  452. defined(HAVE_KEIL_RTX)
  453. #if !defined(WOLFSSL_CMSIS_RTOS)
  454. static char bg_job_stack[BG_JOB_STACK_SIZE] ;
  455. #endif
  456. #endif
  457. #define COMMAND_STACK_SIZE 24000
  458. #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
  459. static char command_stack[COMMAND_STACK_SIZE] ;
  460. #endif
  461. #if defined(HAVE_KEIL_RTX) || defined(WOLFSSL_CMSIS_RTOS)
  462. static wolfSSL_Mutex command_mutex ;
  463. #endif
  464. void exit_command(void) {
  465. printf("Command Aborted\n") ;
  466. #ifdef WOLFSSL_CMSIS_RTOS
  467. osThreadTerminate(osThreadGetId()) ;
  468. #else
  469. os_tsk_delete_self() ;
  470. #endif
  471. }
  472. /*********** Invoke Foreground Command *********************/
  473. static void command_invoke(void const *args)
  474. {
  475. void (*func)(void const * ) ;
  476. int i,iteration ;
  477. func = (void(*)(void const *))((func_args *)args)->argv[0] ;
  478. #if defined(HAVE_KEIL_RTX)
  479. wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ;
  480. #endif
  481. iteration = for_iteration ;
  482. for(i=0; i< iteration; i++) {
  483. if(iteration > 1) printf("--- Start for %d ---->\n", i) ;
  484. #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
  485. stack_fill(command_stack, COMMAND_STACK_SIZE) ;
  486. #endif
  487. func(args) ; /* invoke command */
  488. #if defined(HAVE_KEIL_RTX)&& !defined(WOLFSSL_CMSIS_RTOS)
  489. stack_check(command_stack, COMMAND_STACK_SIZE) ;
  490. #endif
  491. }
  492. if(iteration > 1)
  493. for_iteration = 1 ;
  494. osDelay(20000) ;
  495. #ifdef HAVE_KEIL_RTX
  496. wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ;
  497. #ifdef WOLFSSL_CMSIS_RTOS
  498. osThreadTerminate(osThreadGetId()) ;
  499. #else
  500. os_tsk_delete_self() ;
  501. #endif
  502. #endif
  503. }
  504. #if defined(HAVE_KEIL_RTX) || defined(WOLFSSL_CMSIS_RTOS)
  505. /******* Invoke Background Job *******************************/
  506. static void bg_job_invoke(void const *args)
  507. {
  508. void (*func)(void const * ) ;
  509. BackGround = 1 ;
  510. #if defined(HAVE_KEIL_RTX)&& !defined(WOLFSSL_CMSIS_RTOS)
  511. stack_fill(bg_job_stack, BG_JOB_STACK_SIZE) ;
  512. #endif
  513. func = (void(*)(void const *))((func_args *)args)->argv[0] ;
  514. func(args) ; /* invoke command */
  515. #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
  516. stack_check(bg_job_stack, BG_JOB_STACK_SIZE) ;
  517. #endif
  518. osDelay(20000) ;
  519. BackGround = 0 ;
  520. #ifdef WOLFSSL_CMSIS_RTOS
  521. osThreadTerminate(osThreadGetId()) ;
  522. #else
  523. os_tsk_delete_self() ; ;
  524. #endif
  525. }
  526. #endif
  527. #define LINESIZE 100
  528. static char line[LINESIZE] ;
  529. #if defined(WOLFSSL_CMSIS_RTOS)
  530. osThreadDef (command_invoke, osPriorityAboveNormal , 1, COMMAND_STACK_SIZE) ;
  531. osThreadDef (bg_job_invoke, osPriorityNormal , 1 , BG_JOB_STACK_SIZE) ;
  532. #endif
  533. /********* SHEULL MAIN LOOP ***********************************/
  534. void shell_main(void *arg) {
  535. int i ;
  536. func_args args ;
  537. int bf_flg ;
  538. #if defined(WOLFSSL_CMSIS_RTOS)
  539. osThreadId cmd ;
  540. #endif
  541. i = BackGround ;
  542. /* Dummy for avoiding warning: BackGround is defined but not used. */
  543. #if defined(HAVE_KEIL_RTX)
  544. wc_InitMutex(&command_mutex) ;
  545. #endif
  546. help_comm(NULL) ;
  547. printf("Starting Shell\n") ;
  548. while(1) {
  549. if(getline(line, LINESIZE, &args, &bf_flg) > 0) {
  550. for(i=0; commandTable[i].func != NULL; i++) {
  551. if(strcmp(commandTable[i].command, args.argv[0]) == 0) {
  552. args.argv[0] = (char *) commandTable[i].func ;
  553. if(bf_flg == FORGROUND) {
  554. #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
  555. wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ;
  556. os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7,
  557. command_stack, COMMAND_STACK_SIZE, &args) ;
  558. os_tsk_pass ();
  559. #else
  560. #if defined(WOLFSSL_CMSIS_RTOS)
  561. wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ;
  562. cmd = osThreadCreate (osThread (command_invoke) , &args);
  563. if(cmd == NULL) {
  564. printf("Cannon create command thread\n") ;
  565. }
  566. osThreadYield ();
  567. #else
  568. command_invoke(&args) ;
  569. #endif
  570. #endif
  571. #ifdef HAVE_KEIL_RTX
  572. wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ;
  573. #endif
  574. } else {
  575. #if (!defined(NO_SIMPLE_SERVER) && \
  576. !defined(NO_ECHOSERVER)) && \
  577. defined(HAVE_KEIL_RTX)
  578. if(BackGround != 0) {
  579. printf("Multiple background servers not supported.\n") ;
  580. } else {
  581. printf("\"%s\" is running with the background mode.\n",
  582. commandTable[i].command) ;
  583. #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
  584. os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke,
  585. 6, bg_job_stack, BG_JOB_STACK_SIZE, &args) ;
  586. #else
  587. osThreadCreate (osThread (bg_job_invoke), &args);
  588. osDelay (500) ;
  589. #endif
  590. }
  591. #else
  592. printf("Invalid Command: no background job\n") ;
  593. #endif
  594. }
  595. break ;
  596. }
  597. }
  598. if(commandTable[i].func == NULL)
  599. printf("Command not found\n") ;
  600. }
  601. }
  602. }