NetBurner 3.5.8
PDF Version
Telnet Command

Example Path: examples/telnetcmd

NetBurner Telnet Command Example

A demonstration application that implements a multi-interface command processor using the NetBurner Command Processor Library. This application provides remote command access through serial port, TCP/Telnet, and optionally SSH connections.

Overview

The TelnetCmd example showcases how to create a command-line interface that can accept connections and process user commands from multiple sources simultaneously:

  • Serial port (UART) connection
  • TCP/Telnet connection on port 23
  • SSH connection on port 22 (if SSH support is enabled)

Web Interface

The example also runs a small HTTP server (started with StartHttp()) that serves a single page describing the example, how SSH is enabled via the overload directory, and how to connect on each transport. Browse to http://<device-ip>/ to view it.

The page is built on a self-contained stylesheet (plain CSS, no framework or CDN). A <!--CPPCALL ShowServiceTable --> tag lets the device render its live status — current IP address, the Telnet/SSH ports, the idle timeout, and whether SSH was compiled in — straight into the page, and a <!--CPPCALL ShowDeviceAddr --> tag drops the board's real address into the sample connect commands.

The Overload Directory

SSH is enabled at compile time rather than in main.cpp. The example ships an overload/ directory:

overload/nbrtos/include/predef-overload.h

A NetBurner build searches each example's overload/ tree before the SDK's own include paths, so a header placed there shadows the stock SDK header of the same relative path. The SDK's predef.h includes predef-overload.h as the hook for per-application build settings; here it contains a single line:

#define NB_SSH_SUPPORTED (1) // Enable SSH on this example

Every #ifdef NB_SSH_SUPPORTED block in main.cpp compiles in because of that definition. Remove the line (or the whole overload/ directory) and the same source rebuilds as a serial-plus-Telnet example with no SSH dependencies.

Features

Multi-Interface Support

  • Serial Port: Direct UART connection at 115,200 baud, 8 data bits, 1 stop bit, no parity
  • Telnet: Standard TCP connection on port 23 with up to 5 concurrent connections
  • SSH: Encrypted connection on port 22 with up to 5 concurrent connections (optional)

Authentication System

  • Simple username/password authentication
  • Rejects credentials where username matches password (for testing)
  • Separate SSH authentication handler with support for key-based authentication
  • Configurable login prompts and timeouts

Session Management

  • Session tracking with unique identifiers
  • Connection counters and session state management
  • Customizable prompts showing connection type (Serial0, Serial1, or Remote)
  • Automatic timeout handling (60-second idle timeout)

Command Processing

  • Extensible command framework
  • Built-in help command that lists the available commands
  • Built-in logout / exit commands to close connections
  • Command echo and response system (any other input is echoed back)
  • Graceful connection handling and cleanup

Configuration

Serial Port Settings

The command processor attaches to the standard I/O serial port via CmdAddStdioFd(), so it inherits the system console settings (typically 115,200 baud, 8 data bits, 1 stop bit, no parity). To drive a different UART, open it yourself and register it with CmdAddCommandFd() instead.

Network Settings

#define TCP_PORT_TO_USE (23) // Standard Telnet port
#define SSH_PORT_TO_USE (22) // Standard SSH port

Callback Functions

The application implements five main callback functions:

Authentication Callbacks

  • ProcessTcpAndSerialAuth(): Handles TCP and serial authentication
  • ProcessSshAuth(): Handles SSH authentication with key/password support

Connection Management

  • ProcessConnect(): Called when new connections are established
  • ProcessDisconnect(): Handles connection cleanup and goodbye messages
  • ProcessPrompt(): Generates custom prompts for each session

Command Processing

  • ProcessCommand(): Processes all user commands and responses

Connection Types and Prompts

The application identifies different connection types and provides appropriate prompts:

  • Serial0: Direct serial connection on UART 0
  • Serial1: Direct serial connection on UART 1
  • Remote: TCP/Telnet or SSH network connections

Example session prompt: NB:Remote>

Disconnect Handling

The application handles various disconnect scenarios:

  • Timeout: 60-second idle timeout
  • Socket Closed: Network connection terminated
  • Authentication Failed: Invalid credentials provided
  • Manual Logout: User-initiated logout command
  • System Closed: Application-initiated disconnect

SSH Support (Optional)

When SSH support is enabled (NB_SSH_SUPPORTED):

  • Automatic certificate and key generation
  • Secure encrypted connections
  • Key-based authentication support
  • Automatic retry logic for SSH listener startup

Usage

  1. Serial Connection: Connect to the configured serial port at 115,200 baud
  2. Telnet Connection: telnet <device_ip> 23
  3. SSH Connection: ssh <username>@<device_ip> (if SSH enabled)

Authentication

  • Enter any username and password combination
  • Username and password must be different (test restriction)
  • Type help to list commands, or logout / exit to disconnect

Sample Session

Hello!
Welcome to the NetBurner Test Command Program
Number of connections since boot: 1
Please Log in
Username: admin
Password: password123
NB:Remote>help
Available commands:
help show this list
logout, exit close this session
Any other text is echoed back to demonstrate command handling.
NB:Remote>status
# Remote Sent Cmd[status]
NB:Remote>exit
GoodBye
int close(int fd)
Close the specified file descriptor and free the associated resources.

Build Requirements

  • NetBurner development environment
  • Command Processor Library
  • Optional: SSH support libraries (NB_SSH_SUPPORTED)

System Integration

The application integrates with NetBurner's RTOS:

  • Runs command processor at MAIN_PRIO + 1 priority
  • Uses system diagnostics (should be disabled for production)
  • Waits for active network before starting SSH services
  • Replaces standard I/O streams with serial port

Customization

To extend this application:

  1. Add Commands: Modify ProcessCommand() to handle new command strings
  2. Change Authentication: Update authentication callbacks for different credential checking
  3. Modify Prompts: Customize ProcessPrompt() for different prompt formats
  4. Add Connection Types: Extend connection handling for additional interfaces
  5. Configure Timeouts: Adjust CmdIdleTimeout for different session timeouts

Security Notes

  • This is a demonstration application with simplified authentication
  • Production deployments should implement secure credential storage
  • Consider disabling system diagnostics for production use
  • SSH provides encrypted communication when available

Related Documentation

See NetBurner Command Processor Library documentation for additional API details and advanced configuration options.