Network Component
Version 6.6
MDK-Professional Middleware for IP Networking
|
Telnet Server routines allow command line access to an embedded module of an IP network. More...
Functions | |
uint32_t | telnet_server_message (telnetServerMessage msg, char *buf, uint32_t len) |
Request message for Telnet server session. | |
uint32_t | telnet_server_process (const char *cmd, char *buf, uint32_t buflen, uint32_t *pvar) |
Process and execute a command requested by the Telnet client. | |
bool | telnet_check_command (const char *cmd, const char *user_cmd) |
Check command string for a command. | |
bool | telnet_check_password (uint8_t user_id, const char *password) |
Check user account password in the user database. | |
uint8_t | telnet_check_username (const char *username) |
Check if an user account exist in the user database. | |
netStatus | telnet_server_set_delay (uint32_t delay) |
Set a delay between two consecutive calls to telnet_server_process function. | |
netStatus | telnet_server_get_client (uint8_t *ip_addr, uint8_t *mac_addr) |
Get IP and MAC address of connected remote machine. | |
int32_t | telnet_server_get_session (void) |
Get current session number of Telnet server. | |
uint8_t | telnet_get_user_id (void) |
Retrieve the user identification. | |
bool | telnet_server_message_poll (int32_t session) |
Poll the upper-layer user application for unsolicited messages. | |
bool | telnet_accept_client (const uint8_t *ip_addr, uint16_t port) |
Accept or deny connection from remote Telnet client. | |
enum | telnetServerMessage { telnetServerWelcome, telnetServerPrompt, telnetServerLogin, telnetServerUsername, telnetServerPassword, telnetServerLoginFailed, telnetServerLoginTimeout, telnetServerUnsolicitedMessage } |
Telnet Server Messages. More... | |
Telnet Server routines allow command line access to an embedded module of an IP network.
Telnet is most often used for remote login. A user typically opens a Telnet connection to a remote server. The server then treats the Telnet client like a local terminal and allows the user to log in and access the server's resources as if the user was using a directly-attached terminal. Telnet is used this way quite extensively by Linux users, who often need to log in to remote hosts from their local machines.
The following source code is part of the Telnet_Server_UIF.c template file. This code template enables the developer to define application specific commands, command responses and to create a list of hosts that are allowed to connect to the Telnet server:
The following source code is part of the Telnet_Server_Multiuser.c template file, which handles Multi-user Authentication for the Telnet server:
Parameter for:
enum telnetServerMessage |
Telnet Server Messages.
bool telnet_accept_client | ( | const uint8_t * | ip_addr, |
uint16_t | port | ||
) |
Accept or deny connection from remote Telnet client.
[in] | ip_addr | IP address of the remote Telnet client. |
[in] | port | port number of the remote Telnet client. |
The function telnet_accept_client checks if a connection from the remote client is allowed. This allows remote client filtering. You can selectively decide which clients are allowed to connect to the Telnet server.
The argument ip_addr points to a buffer containing the four octets that make up the IP address of the remote machine.
The argument port specifies the port on the remote machine.
The function is in the Telnet_Server_Access.c module.
Code Example
bool bool telnet_check_command | ( | const char * | cmd, |
const char * | user_cmd | ||
) |
Check command string for a command.
[in] | cmd | pointer to command string from Telnet client. |
[in] | user_cmd | user command to check for (in upper case). |
The function telnet_check_command compares the command in the buffer cmd with the string user_cmd.
Code Example
bool telnet_check_password | ( | uint8_t | user_id, |
const char * | password | ||
) |
Check user account password in the user database.
[in] | user_id | user identification number. |
[in] | password | pointer to password. |
The function telnet_check_password authenticates the password for a specified user ID on the server.
The argument user_id is the identification number of a user.
The argument password points to a 0-terminated string representing the password that gets checked.
The function is in the Telnet_Server_Multiuser.c module.
uint8_t telnet_check_username | ( | const char * | username | ) |
Check if an user account exist in the user database.
[in] | username | pointer to username. |
The function telnet_check_username authenticates the user name and returns the user identification number.
The argument username points to a 0-terminated string representing the user name that must be checked.
The function is in the Telnet_Server_Multiuser.c module.
uint8_t telnet_get_user_id | ( | void | ) |
Retrieve the user identification.
The function telnet_get_user_id retrieves the user identification number when the Telnet console is protected with user authentication. It can be used to disable restricted commands for unprivileged users.
Code Example
netStatus telnet_server_get_client | ( | uint8_t * | ip_addr, |
uint8_t * | mac_addr | ||
) |
Get IP and MAC address of connected remote machine.
[out] | ip_addr | pointer to IP address. |
[out] | mac_addr | pointer to MAC address. |
The function telnet_server_get_client provides information about the remote machine that has connected to the Telnet server.
The argument ip_addr points to the IP address of the remote machine.
The argument mac_addr points to the MAC address of the remote machine.
Code Example
int32_t telnet_server_get_session | ( | void | ) |
Get current session number of Telnet server.
The function telnet_server_get_session retrieves the current session number of the Telnet server for further usage.
Code Example
uint32_t telnet_server_message | ( | telnetServerMessage | msg, |
char * | buf, | ||
uint32_t | len | ||
) |
Request message for Telnet server session.
[in] | msg | code of requested message. |
[out] | buf | output buffer to write the message to. |
[in] | len | length of the output buffer in bytes. |
The function telnet_server_message provides the connection and login messages to the Telnet server, when requested. The Telnet server sends these messages to the Telnet client.
The argument msg specifies the type of message that the Telnet server requires:
Message | Description |
---|---|
telnetServerWelcome | To inform the user that the user's Telnet client has connected to the Telnet server. |
telnetServerPrompt | To inform the user that the Telnet server is ready and waiting for a command. |
telnetServerLogin | Displayed only when user authentication is enabled. |
telnetServerUsername | To inform the user to enter the username. |
telnetServerPassword | To inform the user to enter the password. |
telnetServerLoginFailed | To inform the user that the login is incorrect. |
telnetServerLoginTimeout | To inform the user that the login has timed out. |
telnetServerUnsolicitedMessage | To write unsolicited messages from the high-layer user application (for example a basic interpreter). |
The argument buf points to the output buffer where the telnet_server_message must write the message.
The argument buflen specifies the length of the output buffer in bytes.
You must customize the function in Telnet_Server_UIF.c.
Code Example
bool telnet_server_message_poll | ( | int32_t | session | ) |
Poll the upper-layer user application for unsolicited messages.
[in] | session | session identification, when multiple connections are active. |
The function telnet_server_message_poll polls the upper-layer user application for unsolicited messages.
The Telnet session handle parameter session identifies the remote host when many Telnet connections are active at the same time.
You may customize the function in Telnet_Server_UIF.c.
Code Example
uint32_t telnet_server_process | ( | const char * | cmd, |
char * | buf, | ||
uint32_t | buflen, | ||
uint32_t * | pvar | ||
) |
Process and execute a command requested by the Telnet client.
[in] | cmd | pointer to command string from Telnet client. |
[out] | buf | output buffer to write the return message to. |
[in] | buflen | length of the output buffer in bytes. |
[in,out] | pvar | pointer to a session's local buffer of 4 bytes.
|
The function telnet_server_process processes and executes the command requested by the Telnet client. The Network Component's Telnet server calls the unction when it receives the consecutive Carriage Return (CR) and Line Feed (LF) character sequence from the Telnet client (this is usually produced by the user pressing Enter on the Telnet client terminal).
The argument cmd points to the message containing the command that is received from the Telnet client.
The argument buf points to the output buffer where the tnet_process_cmd must write the message to be returned to the Telnet client.
The argument buflen specifies the length of the output buffer in bytes.
The argument pvar is a pointer to a variable that never gets altered by the Telnet Server. You can use *pvar as a repeat counter or simply to distinguish between different function calls.
You must customize the function in Telnet_Server_UIF.c.
Code Example
netStatus telnet_server_set_delay | ( | uint32_t | delay | ) |
Set a delay between two consecutive calls to telnet_server_process function.
[in] | delay | time period to wait in number of 100ms ticks. |
The function telnet_server_set_delay ensures that the Telnet server does not call the telnet_server_process function until a certain time period expires.
The argument delay specifies the time period to wait, in number of timer ticks.
Code Example