shell_client.c File Reference

SSH secure shell client. More...

#include <stdarg.h>
#include "ssh/ssh.h"
#include "ssh/ssh_connection.h"
#include "ssh/ssh_transport.h"
#include "ssh/ssh_request.h"
#include "shell/shell_client.h"
#include "shell/shell_client_misc.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SHELL_TRACE_LEVEL
 

Functions

error_t shellClientInit (ShellClientContext *context)
 Initialize shell client context. More...
 
error_t shellClientRegisterSshInitCallback (ShellClientContext *context, ShellClientSshInitCallback callback)
 Register SSH initialization callback function. More...
 
error_t shellClientSetTimeout (ShellClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t shellClientBindToInterface (ShellClientContext *context, NetInterface *interface)
 Bind the shell client to a particular network interface. More...
 
error_t shellClientConnect (ShellClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
 Establish a connection with the specified SSH server. More...
 
error_t shellClientFormatCommand (ShellClientContext *context, const char_t *command,...)
 Format a command line. More...
 
error_t shellClientExecuteCommand (ShellClientContext *context, const char_t *command)
 Execute a command line. More...
 
error_t shellClientWriteStream (ShellClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Write to stdin stream. More...
 
error_t shellClientFlushStream (ShellClientContext *context)
 Flush stdin stream. More...
 
error_t shellClientReadStream (ShellClientContext *context, void *data, size_t size, size_t *received, uint_t flags)
 Read from stdout stream. More...
 
error_t shellClientCloseStream (ShellClientContext *context)
 Close stream. More...
 
uint32_t shellClientGetExitStatus (ShellClientContext *context)
 Retrieve exit status. More...
 
error_t shellClientDisconnect (ShellClientContext *context)
 Gracefully disconnect from the SSH server. More...
 
error_t shellClientClose (ShellClientContext *context)
 Close the connection with the SSH server. More...
 
void shellClientDeinit (ShellClientContext *context)
 Release shell client context. More...
 

Detailed Description

SSH secure shell client.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneSSH Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file shell_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SHELL_TRACE_LEVEL

Definition at line 32 of file shell_client.c.

Function Documentation

◆ shellClientBindToInterface()

error_t shellClientBindToInterface ( ShellClientContext context,
NetInterface interface 
)

Bind the shell client to a particular network interface.

Parameters
[in]contextPointer to the shell client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 123 of file shell_client.c.

◆ shellClientClose()

error_t shellClientClose ( ShellClientContext context)

Close the connection with the SSH server.

Parameters
[in]contextPointer to the shell client context
Returns
Error code

Definition at line 964 of file shell_client.c.

◆ shellClientCloseStream()

error_t shellClientCloseStream ( ShellClientContext context)

Close stream.

Parameters
[in]contextPointer to the shell client context
Returns
Error code

Definition at line 737 of file shell_client.c.

◆ shellClientConnect()

error_t shellClientConnect ( ShellClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort 
)

Establish a connection with the specified SSH server.

Parameters
[in]contextPointer to the shell client context
[in]serverIpAddrIP address of the SSH server to connect to
[in]serverPortPort number
Returns
Error code

Definition at line 146 of file shell_client.c.

◆ shellClientDeinit()

void shellClientDeinit ( ShellClientContext context)

Release shell client context.

Parameters
[in]contextPointer to the shell client context

Definition at line 985 of file shell_client.c.

◆ shellClientDisconnect()

error_t shellClientDisconnect ( ShellClientContext context)

Gracefully disconnect from the SSH server.

Parameters
[in]contextPointer to the shell client context
Returns
Error code

Definition at line 865 of file shell_client.c.

◆ shellClientExecuteCommand()

error_t shellClientExecuteCommand ( ShellClientContext context,
const char_t command 
)

Execute a command line.

Parameters
[in]contextPointer to the shell client context
[in]commandNULL-terminating string containing the command line
Returns
Error code

Definition at line 317 of file shell_client.c.

◆ shellClientFlushStream()

error_t shellClientFlushStream ( ShellClientContext context)

Flush stdin stream.

Parameters
[in]contextPointer to the shell client context
Returns
Error code

Definition at line 612 of file shell_client.c.

◆ shellClientFormatCommand()

error_t shellClientFormatCommand ( ShellClientContext context,
const char_t command,
  ... 
)

Format a command line.

Parameters
[in]contextPointer to the shell client context
[in]commandNULL-terminating string containing the command line
[in]...Optional arguments
Returns
Error code

Definition at line 238 of file shell_client.c.

◆ shellClientGetExitStatus()

uint32_t shellClientGetExitStatus ( ShellClientContext context)

Retrieve exit status.

Parameters
[in]contextPointer to the shell client context
Returns
Exit status

Definition at line 838 of file shell_client.c.

◆ shellClientInit()

error_t shellClientInit ( ShellClientContext context)

Initialize shell client context.

Parameters
[in]contextPointer to the shell client context
Returns
Error code

Definition at line 54 of file shell_client.c.

◆ shellClientReadStream()

error_t shellClientReadStream ( ShellClientContext context,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Read from stdout stream.

Parameters
[in]contextPointer to the shell client context
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be read
[out]receivedActual number of bytes that have been read
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 650 of file shell_client.c.

◆ shellClientRegisterSshInitCallback()

error_t shellClientRegisterSshInitCallback ( ShellClientContext context,
ShellClientSshInitCallback  callback 
)

Register SSH initialization callback function.

Parameters
[in]contextPointer to the shell client context
[in]callbackSSH initialization callback function
Returns
Error code

Definition at line 80 of file shell_client.c.

◆ shellClientSetTimeout()

error_t shellClientSetTimeout ( ShellClientContext context,
systime_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the shell client context
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 102 of file shell_client.c.

◆ shellClientWriteStream()

error_t shellClientWriteStream ( ShellClientContext context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Write to stdin stream.

Parameters
[in]contextPointer to the shell client context
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of data bytes to write
[in]writtenNumber of bytes that have been written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 520 of file shell_client.c.