1.2.1.21 Telnet Module

Telnet, which runs over a TCP connection, provides bidirectional, interactive communication between two nodes on the Internet or on a Local Area Network. The Telnet code included with Harmony TCP/IP stack is a demonstration of the possible utilization of a Telnet server module. The server listens for a Telnet connection. When a client attempts to make one, the server will prompt the client for a username and password, and if the correct one is provided, it will_connect_the client.

The server registers itself with the system command processor and acts as a communication channel capable of issuing commands and receiving replies.

From this moment on, the Telnet connection can be used for various system and TCP/IP related commands, just as the regular system console is used.

The commands currently implemented and processed by the command processor can be dynamically updated, new commands can be added, etc. See the tcpip_commands.c file for the list of TCP/IP-related commands.

Based on this skeleton Telnet code, completely new behavior can be implemented for the Telnet server.

Abstraction Model

Currently, the Telnet TCP/IP Library runs in the background as a server and does not expose any API functions.

It serves incoming connections by sending the received data string to the command processor, which outputs each command reply to the Telnet channel.

TCPIP TELNET telnet_flow

Library Interface

NameDescription
Macros
TCPIP_TELNET_MAX_CONNECTIONSMaximum number of Telnet connections
TCPIP_TELNET_LISTEN_PORTPort on which the telnet server is listening Default is TCPIP_TELNET_SERVER_PORT (23) or TCPIP_TELNET_SERVER_SECURE_PORT (992). Adjust as needed
TCPIP_TELNET_SKT_RX_BUFF_SIZESize of the telnet socket RX buffer If long messages are sent over the telnet connection the socket should have a large enough buffer to receive the data. Leave 0 for default TCP RX buffer size
TCPIP_TELNET_SKT_TX_BUFF_SIZESize of the telnet socket TX buffer if long messages are sent over the telnet connection the socket should have a large enough buffer to write the data at once. Leave 0 for default TCP TX buffer size
TCPIP_TELNET_PRINT_BUFF_SIZESize of the internal print buffer This buffer is used when the telnet console printf style function is called Adjust based on the length of the messages to be formatted with print statements. This buffer is created in the automatic stack. Make sure that there's enough stack space for this buffer
TCPIP_TELNET_LINE_BUFF_SIZESize of the internal line buffer This buffer is used for receiving and assembling the password, authentication and regular characters Adjust based on the length of the commands sent to the telnet server. This buffer is created in the automatic stack. Make sure that there's enough stack space for this buffer
TCPIP_TELNET_TASK_TICK_RATEtelnet task rate, milliseconds. The default value is 100 milliseconds. The lower the rate (higher the frequency) the higher the module priority and higher module performance can be obtained. The value cannot be lower than the TCPIP_STACK_TICK_RATE.
TCPIP_TELNET_USERNAME_SIZEMaximum size of the internal buffer to store the user name Adjust based on the length of the user names allowed for the telnet connections. A buffer of this size if allocated for each connection to store the login user name. Longer user names will be truncated to this size
TCPIP_TELNET_OBSOLETE_AUTHENTICATIONtelnet obsolete authentication method disable/enable. If false This is the default and the PREFERRED case! The telnet module will call a registrated callback to authenticate the users. Is is the preferred authentication method. It requires the run time registration of an authentication handler. Until the moment the authentication handler is registered any login attempts will fail!. If true The old OBSOLETE authentication method using the build symbols TCPIP_TELNET_USERNAME and TCPIP_TELNET_PASSWORD is used This method is DEPRECATED and it will be eventually removed!. It is recommended that you leave the setting to false!
TCPIP_TELNET_AUTHENTICATION_CONN_INFOUse the telnet connection information data as part of the authentication callback. If false no connection info data is provided to the authentication callback This is useful for the default case when all connections will use the same username/password.. If true the authentication callback will contain the connection info data to allow different processing based on the source of the authentication request. This flag is relevant only when TCPIP_TELNET_OBSOLETE_AUTHENTICATION == false
TCPIP_TELNET_USERNAMEDefault Telnet user name. DEPRECATED. this is used only when there's no authentication callback defined!. Use only when TCPIP_TELNET_OBSOLETE_AUTHENTICATION == true
TCPIP_TELNET_PASSWORDDefault Telnet password DEPRECATED. this is used only when there's no authentication callback defined!. Use only when TCPIP_TELNET_OBSOLETE_AUTHENTICATION == true
Functions
TCPIP_TELNET_TaskStandard TCP/IP stack module task function.
TCPIP_TELNET_AuthenticationDeregisterDeregisters a previously registered authentication handler.
TCPIP_TELNET_AuthenticationRegisterSets a new telnet authentication handler.
TCPIP_TELNET_ConnectionInfoGetGets information about a telnet connection
TCPIP_TELNET_ConnectionsGetGets the number of the telnet connections
Data Types and Constants
TCPIP_TELNET_MODULE_CONFIGtelnet module run time configuration/initialization data.
TCPIP_TELNET_AUTH_HANDLERPointer to a function (handler) that will get called to process telnet authentication
TCPIP_TELNET_CONN_INFOtelnet connection information.
TCPIP_TELNET_FLAGStelnet configuration flags.
TCPIP_TELNET_HANDLEDefines a telnet handle.
TCPIP_TELNET_STATETelnet connection state.