shell_client.h File Reference

SSH secure shell client. More...

#include "ssh/ssh.h"

Go to the source code of this file.

Data Structures

struct  _ShellClientContext
 Shell client context. More...
 

Macros

#define SHELL_CLIENT_SUPPORT   DISABLED
 
#define SHELL_CLIENT_DEFAULT_TIMEOUT   20000
 
#define SHELL_CLIENT_BUFFER_SIZE   512
 
#define ShellClientContext   struct _ShellClientContext
 

Typedefs

typedef error_t(* ShellClientSshInitCallback) (ShellClientContext *context, SshContext *sshContext)
 SSH initialization callback function. More...
 

Enumerations

enum  ShellClientState {
  SHELL_CLIENT_STATE_DISCONNECTED = 0, SHELL_CLIENT_STATE_CONNECTING_1 = 1, SHELL_CLIENT_STATE_CONNECTING_2 = 2, SHELL_CLIENT_STATE_CONNECTED = 3,
  SHELL_CLIENT_STATE_CHANNEL_INIT = 4, SHELL_CLIENT_STATE_CHANNEL_OPEN = 5, SHELL_CLIENT_STATE_CHANNEL_REQUEST = 6, SHELL_CLIENT_STATE_CHANNEL_REPLY = 7,
  SHELL_CLIENT_STATE_CHANNEL_DATA = 8, SHELL_CLIENT_STATE_CHANNEL_CLOSE = 9, SHELL_CLIENT_STATE_DISCONNECTING_1 = 10, SHELL_CLIENT_STATE_DISCONNECTING_2 = 11
}
 Shell client state. More...
 

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.4

Definition in file shell_client.h.

Macro Definition Documentation

◆ SHELL_CLIENT_BUFFER_SIZE

#define SHELL_CLIENT_BUFFER_SIZE   512

Definition at line 53 of file shell_client.h.

◆ SHELL_CLIENT_DEFAULT_TIMEOUT

#define SHELL_CLIENT_DEFAULT_TIMEOUT   20000

Definition at line 46 of file shell_client.h.

◆ SHELL_CLIENT_SUPPORT

#define SHELL_CLIENT_SUPPORT   DISABLED

Definition at line 39 of file shell_client.h.

◆ ShellClientContext

#define ShellClientContext   struct _ShellClientContext

Definition at line 60 of file shell_client.h.

Typedef Documentation

◆ ShellClientSshInitCallback

typedef error_t(* ShellClientSshInitCallback) (ShellClientContext *context, SshContext *sshContext)

SSH initialization callback function.

Definition at line 93 of file shell_client.h.

Enumeration Type Documentation

◆ ShellClientState

Shell client state.

Enumerator
SHELL_CLIENT_STATE_DISCONNECTED 
SHELL_CLIENT_STATE_CONNECTING_1 
SHELL_CLIENT_STATE_CONNECTING_2 
SHELL_CLIENT_STATE_CONNECTED 
SHELL_CLIENT_STATE_CHANNEL_INIT 
SHELL_CLIENT_STATE_CHANNEL_OPEN 
SHELL_CLIENT_STATE_CHANNEL_REQUEST 
SHELL_CLIENT_STATE_CHANNEL_REPLY 
SHELL_CLIENT_STATE_CHANNEL_DATA 
SHELL_CLIENT_STATE_CHANNEL_CLOSE 
SHELL_CLIENT_STATE_DISCONNECTING_1 
SHELL_CLIENT_STATE_DISCONNECTING_2 

Definition at line 72 of file shell_client.h.

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.