|
@@ -148,8 +148,6 @@ static void cli_send(intptr_t fd, const char *str, unsigned len)
|
|
|
wolfSSH_stream_send((WOLFSSH *)fd, str, len);
|
|
|
}
|
|
|
|
|
|
-extern cli_state_t cli_states[MAX_SESSIONS];
|
|
|
-
|
|
|
static void *server_worker(void* vArgs)
|
|
|
{
|
|
|
int ret;
|
|
@@ -160,12 +158,13 @@ static void *server_worker(void* vArgs)
|
|
|
else
|
|
|
ret = NonBlockSSH_accept(threadCtx->ssh);
|
|
|
|
|
|
- if (ret == WS_SUCCESS) {
|
|
|
- // create the new CLI context
|
|
|
- cli_states[threadCtx->fd].num_connect = threadCtx->ssh;
|
|
|
- cli_states[threadCtx->fd].input_state = CLI_CMD;
|
|
|
- cli_states[threadCtx->fd].state = STATE_NORMAL;
|
|
|
- cli_states[threadCtx->fd].send = cli_send;
|
|
|
+ cli_state_t *cli_state;
|
|
|
+ // create the new CLI context
|
|
|
+ if (ret == WS_SUCCESS && (cli_state = alloc_state())) {
|
|
|
+ cli_state->num_connect = threadCtx->ssh;
|
|
|
+ cli_state->input_state = CLI_CMD;
|
|
|
+ cli_state->send = cli_send;
|
|
|
+ cli_state->state = STATE_NORMAL;
|
|
|
|
|
|
bool stop = false;
|
|
|
do {
|
|
@@ -179,14 +178,15 @@ static void *server_worker(void* vArgs)
|
|
|
} while (rxSz == WS_WANT_READ || rxSz == WS_WANT_WRITE);
|
|
|
|
|
|
if (rxSz > 0) {
|
|
|
- cli_getchar(cli_states + threadCtx->fd, buf[0]); // TODO handle rxSz > 1
|
|
|
- if (buf[0] == 3 || buf[0] == 4) {
|
|
|
+ cli_getchar(cli_state, buf[0]); // TODO handle rxSz > 1
|
|
|
+ if (buf[0] == 3 || buf[0] == 4 || cli_state->state == STATE_CLOSE) {
|
|
|
stop = 1;
|
|
|
}
|
|
|
} else {
|
|
|
stop = 1;
|
|
|
}
|
|
|
} while (!stop);
|
|
|
+ cli_state->state = STATE_UNUSED;
|
|
|
} else if (ret == WS_SCP_COMPLETE) {
|
|
|
printf("scp file transfer completed\n");
|
|
|
} else if (ret == WS_SFTP_COMPLETE) {
|
|
@@ -676,5 +676,5 @@ static void ssh_server(void *arg)
|
|
|
void ssh_server_init(void)
|
|
|
{
|
|
|
vRegisterCLICommands();
|
|
|
- xTaskCreate(ssh_server, ( char * ) "ssh_server", 16*configMINIMAL_STACK_SIZE + EXAMPLE_BUFFER_SZ, NULL, tskIDLE_PRIORITY + 1, NULL);
|
|
|
+ xTaskCreate(ssh_server, ( char * ) "ssh_server", 24*configMINIMAL_STACK_SIZE + EXAMPLE_BUFFER_SZ, NULL, tskIDLE_PRIORITY + 1, NULL);
|
|
|
}
|