TrustCore SDK NanoSSH API reference  version 7.0
Sync Server Management Functions

Functions

MOC_EXTERN void SSH_disconnectAllClients (void)
 Disconnect all NanoSSH server clients. More...
 
MOC_EXTERN sbyte4 SSH_startServer (void)
 Start the NanoSSH server. More...
 
MOC_EXTERN void SSH_stopServer (void)
 Stop NanoSSH server from accepting any new client connections. More...
 

Detailed Description

Function Documentation

◆ SSH_disconnectAllClients()

MOC_EXTERN void SSH_disconnectAllClients ( void  )

This function disconnects all the NanoSSH server's clients.

Warning
To avoid race conditions that could occur if code is actively serving a session, be cautious about using this function to forcefully terminate sessions. Better alternatives are using the upper-layer CLI to terminate sessions or calling SSH_stopServer().
Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__
  • __USE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__

ssh.h

Returns
None.
Remarks
This function is applicable to synchronous servers.

ssh.h

◆ SSH_startServer()

MOC_EXTERN sbyte4 SSH_startServer ( void  )

This function starts the NanoSSH server.

You can use the NanoSSH SSH daemon or your own CLI daemon to listen for and accept connections. To run multiple SSH Server instances, you can use your existing code or adapt the ssh_server.c sample code.

Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__
  • __USE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__

ssh.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous servers.
Note
By default, the NanoSSH server is multi-threaded. To change the NanoSSH server to single-threaded, define the SINGLE_THREAD_SSH_SERVER flag in moptions.h.
void SSH_EXAMPLE_main(void)
{
#ifdef __ENABLE_ALL_DEBUGGING__
printf("SSH_EXAMPLE_main: Starting up SSH Server\n");
#endif
// initialize the SSH tables and structures
if (0 > SSH_init(MAX_SSH_CONNECTIONS_ALLOWED))
goto exit;
// if necessary, create host keys
if (0 > SSH_EXAMPLE_computeHostKeys())
goto exit;
#ifdef __ENABLE_MOCANA_SSH_FTP_SERVER__
SFTP_EXAMPLE_init();
#endif
// startup the SSH Server
exit:
}

ssh.h

◆ SSH_stopServer()

MOC_EXTERN void SSH_stopServer ( void  )

This function stops the NanoSSH server from accepting any new client connections. (Existing active connection sessions remain active.)

Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__
  • __USE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__

ssh.h

Returns
None.
Remarks
This function is applicable to synchronous servers.
extern void SSH_stopServer (void);

ssh.h