NetBurner 3.5.6
PDF Version
Telnet Command

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)

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 "logout" command to close connections
  • Command echo and response system
  • Graceful connection handling and cleanup

Configuration

Serial Port Settings

#define SERIALPORT_TO_USE (0) // Serial port 0
#define BAUDRATE_TO_USE (115200) // 115.2k baud
#define STOP_BITS (1) // 1 stop bit
#define DATA_BITS (8) // 8 data bits

Network Settings

#define TCP_PORT_TO_USE (23) // Standard Telnet 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 "logout" to disconnect

Sample Session

Hello!
Welcome to the NetBurner Test Command Program
Number of connections since boot since boot: 1
Please Log in
Username: admin
Password: password123
NB:Remote>help
# Remote Sent Cmd[help]
NB:Remote>logout
GoodBye

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.