Network Component
Version 7.19.0
MDK Middleware for IPv4 and IPv6 Networking
|
Functions to notify the user application about events on the Telnet server. More...
Functions | |
uint32_t | netTELNETs_ProcessCommand (const char *cmd, char *buf, uint32_t buf_len, uint32_t *pvar) |
Process and execute a command requested by the Telnet client. [user-provided]. More... | |
uint32_t | netTELNETs_ProcessMessage (netTELNETs_Message msg, char *buf, uint32_t buf_len) |
Request a message for a Telnet server session. [user-provided]. More... | |
Functions to notify the user application about events on the Telnet server.
The netTELNETs_ProcessCommand function processes the Telnet command when it is received from a remote client. A command is any sequence of characters that is terminated by the CRLF sequence (the Enter key is pressed). The Telnet server assembles this command and passes it as an argument to the netTELNETs_ProcessCommand function. This function then generates a reply message and sends it back to the user. It is part of the Telnet_Server_UIF.c template file.
When the reply message is short, the whole message can be sent in a single TCP packet. However, when long reports are generated, multiple TCP packets must be sent to transfer the whole message. For example, when the log files are displayed this is often the case. Both single and multiple packets are supported by the Embedded Telnet Server.
In the following example, the Telnet command HELP is sent by the Telnet client:
This command is answered by the predefined help message telnet_help. This message is copied to the output buffer and sent to the remote Telnet client. The following code sends the reply message:
A long reply message requires multiple calls to the function netTELNETs_ProcessCommand. Each call to this function generates part of the reply message until the entire message is generated and sent. To distinguish between different calls to the function, the argument pvar is used. This argument is a pointer to a variable that is set to 0 on the first call and not altered on each subsequent call to this function. The function's return value, which specifies the number of bytes in the reply message, cannot exceed 1500. Hence the high bits of the function's return value are used to store the flags:
In the following example, the MEAS command is given by the user using the Telnet client.
When a new Telnet command is received, the function netTELNETs_ProcessCommand is called with the argument pvar set to 0. The command buffer cmd is checked to identify the command.
The above example uses 3 bytes of a storage variable pointed by pvar pointer for the following structure:
When the call to netTELNETs_ProcessCommand is repeated for the same command, the value of a storage variable pointed to by argument pvar is not altered any more. You can use the value of pvar to process the command differently. The pvar buffer now holds the private structure MYBUF
, which is valid for the lifetime of processing the command. When the command processing is finished, this buffer is not used any more until the next command.
After giving a meas
4
command, the Telnet Client screen looks like this:
uint32_t netTELNETs_ProcessCommand | ( | const char * | cmd, |
char * | buf, | ||
uint32_t | buf_len, | ||
uint32_t * | pvar | ||
) |
Process and execute a command requested by the Telnet client. [user-provided].
[in] | cmd | pointer to command string from Telnet client. |
[out] | buf | output buffer to write the return message to. |
[in] | buf_len | length of the output buffer in bytes. |
[in,out] | pvar | pointer to a session's local buffer of 4 bytes.
|
The callback function netTELNETs_ProcessCommand processes and executes the command requested by the Telnet client. The Network Component's Telnet server calls the function 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 netTELNETs_ProcessCommand must write the message to be returned to the Telnet client.
The argument buf_len specifies the length of the output buffer in bytes.
The argument pvar is a pointer to a local session buffer with a length of 4 bytes. The Telnet Server clears the data in the pvar pointer to 0 before the function is called for the first time in each session, and never changes it later. You can use *pvar as a repeat counter or simply to distinguish between different function calls.
Code Example
The following example is available in the user code template file Telnet_Server_UIF.c. Customize it to the application's needs.
uint32_t netTELNETs_ProcessMessage | ( | netTELNETs_Message | msg, |
char * | buf, | ||
uint32_t | buf_len | ||
) |
Request a message for a Telnet server session. [user-provided].
[in] | msg | code of requested message. |
[out] | buf | output buffer to write the message to. |
[in] | buf_len | length of the output buffer in bytes. |
The callback function netTELNETs_ProcessMessage 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 |
---|---|
netTELNETs_MessageWelcome | Initial welcome message |
netTELNETs_MessageLogin | Login message, if authentication is enabled |
netTELNETs_MessageUsername | Username request login message |
netTELNETs_MessagePassword | Password request login message |
netTELNETs_MessageLoginFailed | Incorrect login error message |
netTELNETs_MessageLoginTimeout | Login timeout error message |
netTELNETs_MessagePrompt | Prompt message |
netTELNETs_MessageUnsolicited | Unsolicited message (triggered by netTELNETs_RequestMessage) |
The argument buf points to the output buffer where the netTELNETs_ProcessMessage must write the message.
The argument buf_len specifies the length of the output buffer in bytes.
Code Example
The following example is available in the user code template file Telnet_Server_UIF.c. Customize it to the application's needs.