| Description | The tnet_cbfunc function provides the connection and login messages to the telnet server running on TCPnet, when requested. The telnet server sends these messages to the telnet client. The argument code specifies the type of message that the telnet server requires. This is shown in the table. | Code | Message | Description |
|---|
| 0 | Initial header | To inform the user that the user's telnet client has connected to the telnet server running on TCPnet. | | 1 | Prompt string | To inform the user that the telnet server is ready and waiting for a command. | | 2 | Login header | Displayed only when user authentication is enabled. | | 3 | Login username | To inform the user to enter the username. | | 4 | Login password | To inform the user to enter the password. | | 5 | Incorrect login | To inform the user that the login is incorrect. | | 6 | Timeout login | To inform the user that the login has timed out. | | 7 | Unsolicited message | 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 tnet_cbfunc must write the message. The argument buflen specifies the length of the output buffer in bytes. The tnet_cbfunc function is part of RL-TCPnet. The prototype is defined in net_config.h. You must customize the function in telnet_uif.c. note - The length of the output buffer, buflen, might vary because buffer length is determined by the TCP socket Maximum Segment Size (MSS) negotiation. The buffer length is normally around 1400 bytes for local LAN. But this can be reduced to 500 bytes or even less.
- If the tnet_cbfunc function writes more bytes than buflen into the output buffer, then a system crash resulting from corruption of memory link pointers is highly likely.
- The telnet server does not automatically expand the carriage return (CR) character. The tnet_cbfunc function must write the carriage return and line feed (LF) characters into the the buffer to indicate the end of each message.
|
| Example |
U16 tnet_cbfunc (U8 code, U8 *buf, U16 buflen) {
U16 len = 0;
switch (code) {
case 0:
/* Write initial header after login. */
len = str_copy (buf, tnet_header);
break;
case 1:
/* Write a prompt string. */
len = str_copy (buf, "\r\nMcb2100> ");
break;
case 2:
/* Write Login header. */
len = str_copy (buf, CLS "\r\nKeil Embedded Telnet Server V1.00,"
" please login...\r\n");
break;
case 3:
/* Write 'username' prompt. */
len = str_copy (buf, "\r\nUsername: ");
break;
case 4:
/* Write 'Password' prompt. */
len = str_copy (buf, "\r\nPassword: ");
break;
case 5:
/* Write 'Login incorrect'.message. */
len = str_copy (buf, "\r\nLogin incorrect");
break;
case 6:
/* Write 'Login Timeout' message. */
len = str_copy (buf, "\r\nLogin timed out after 60 seconds.\r\n");
break;
case 7:
/* Write Unsolicited messages from the Application Layer above. */
len = sprintf ((S8 *)buf, "\r\nUnsolicited message nr. %d\r\n",
unsol_msg++);
break;
}
return (len);
}
|