telnetio.c File Reference

Telnet server. More...

#include <BoardSupport/inc/stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <Libs/NETlib/net.h>
#include <BoardSupport/inc/BoardSpecific.h>
#include <Common/Common.h>
#include <Common/uartio.h>
#include <Common/timer.h>
#include <Common/CPrintf.h>
#include "telnetio.h"

Functions

int TelnetPrintf (const char *format,...)
 Custom Telnet printf function. More...
 
void TelnetWriteStr (const char *buffer)
 append a zero terminated string to telnet write buffer More...
 
int32_t TelnetWriteChar (char c)
 append a char to telnet write buffer More...
 
void Telnet_send_option (SOCKET *tcp_server, unsigned char option, unsigned char c)
 send a Telnet option More...
 
int Telnet_check_message (telnet_server_type *telnet)
 Parse user commands. More...
 
uint32_t Telnet_initialize_server (user_type *user, char *hello_msg, int16_t(*InputParser)(T_ComDevice *, char), T_Handle CmdTab)
 initialize Telnet Server More...
 
telnet_return_typeTelnet_server (void)
 handle Telnet Server More...
 

Variables

unsigned char telnet_option_msg [] = { TELNET_IAC, TELNET_WILL, 1, 0 }
 
uint32_t telnet_active = 0
 
static telnet_server_type telnet
 

Detailed Description

                          _         _             _
                       __| |    ___(_) ____ _ __ | |_
                      / _` |   / __| |/ _` | '_ \| __|
                     | (_| | _ \__ \ | (_| | | | | |_
                      \__,_|(_) ___/_|\__, |_| |_|\__|
                     Signalprocessing |___/ Technology
Author
D.SignT GmbH & Co. KG, Claus Hermbusche
Date
2017-03-28 10:00 AM

This module provides a telnet server on port 23. Each received charcter is passed to a user defined callback function for further processing (e.g. command processing). The output functions TelnetPrintf(), TelnetWriteStr()and TelnetWriteChar() use a local data buffer for all characters that should be sent over the active telnet connection. This buffer is polled for new data every 100ms (TELNET_OUTPUT_SCAN_INTERVAL). If you observe BUFFEROVERFLOW_ERROR while you try to send out multiple messages, then either try to decrease TELNET_OUTPUT_SCAN_INTERVAL or increase the used buffer (TELNET_OUTPUT_BUFFER_SIZE).

Function Documentation

void TelnetWriteStr ( const char *  buffer)
Parameters
buffer- buffer to send
Returns
nothing
214 {
215  int cnt = 0;
216 
217  /***************************************************************************
218  print only if connection established
219  ***************************************************************************/
220  if ( tcp_get_state (telnet.server) != TCP_ESTABLISHED ) return;
221 
222  /***************************************************************************
223  print to buffer
224  ***************************************************************************/
225  cnt = strlen (buffer);
226  strncpy (&telnet.outbuffer[telnet.out_wptr], buffer, cnt);
227 
228  /***************************************************************************
229  The user buffer size is limited to TELNET_OUTPUT_BUFFER_SIZE. Check for
230  buffer overflow and exit if necessary.
231  ***************************************************************************/
232  telnet.out_wptr+=cnt;
235  {
237  prg_exit ("buffer overflow");
238  }
239 
240  return;
241 }
#define prg_exit(s)
Definition: Common.h:267
uint32_t exit_code
Definition: Common.c:104
int16_t tcp_get_state(SOCKET *so)
Determine tcp state.
#define BUFFEROVERFLOW_ERROR
Definition: Common.h:383
static telnet_server_type telnet
Definition: telnetio.c:147
static char buffer[100]
Definition: blocksend.c:158
#define TELNET_OUTPUT_BUFFER_SIZE
Definition: telnetio.h:72
#define TCP_ESTABLISHED
Definition: net.h:693
SOCKET * server
Definition: telnetio.h:134
uint32_t out_wptr
Definition: telnetio.h:137
char outbuffer[TELNET_OUTPUT_BUFFER_SIZE]
Definition: telnetio.h:136

Variable Documentation

unsigned char telnet_option_msg[] = { TELNET_IAC, TELNET_WILL, 1, 0 }
telnet_server_type telnet
static