source: network-demos/telnetd/init.c @ c88644c

4.11network-demos-4-10-branchnetwork-demos-4-9-branch
Last change on this file since c88644c was c88644c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/25/07 at 16:52:12

2007-09-25 Joel Sherrill <joel.sherrill@…>

  • .cvsignore, ChangeLog?, Makefile, init.c: New files.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*  Init
2 *
3 *  This routine is the initialization task for this test program.
4 *
5 *  Don't forget to change the IP addresses
6 */
7
8#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
9#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
10#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
11#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS        20
12#define CONFIGURE_MAXIMUM_PTYS                          1
13#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
14
15#define CONFIGURE_MEMORY_OVERHEAD       256
16#define CONFIGURE_MESSAGE_BUFFER_MEMORY 32 * 1024
17#define CONFIGURE_MAXIMUM_SEMAPHORES    40
18#define CONFIGURE_MAXIMUM_TASKS         20
19#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES        20
20
21#define CONFIGURE_MICROSECONDS_PER_TICK 1000
22
23#define CONFIGURE_INIT_TASK_STACK_SIZE  (64*1024)
24#define CONFIGURE_INIT_TASK_PRIORITY    120
25#define CONFIGURE_INIT_TASK_ATTRIBUTES    RTEMS_FLOATING_POINT
26#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
27                                           RTEMS_NO_TIMESLICE | \
28                                           RTEMS_NO_ASR | \
29                                           RTEMS_INTERRUPT_LEVEL(0))
30
31#define CONFIGURE_MAXIMUM_DRIVERS 10
32#define CONFIGURE_INIT
33
34#include <stdlib.h>
35#include <rtems.h>
36#include <rtems/telnetd.h>
37
38/* functions */
39
40rtems_task Init(
41  rtems_task_argument argument
42);
43
44/* configuration information */
45
46#include <rtems/confdefs.h>
47#include <bsp.h>
48
49#include <errno.h>
50#include <time.h>
51
52#include <rtems/confdefs.h>
53#include <stdio.h>
54#include <rtems/rtems_bsdnet.h>
55#include <rtems/telnetd.h>
56#include <rtems/shell.h>
57
58     
59#include <rtems/error.h>
60#include <rpc/rpc.h>
61#include <netinet/in.h>
62#include <time.h>
63
64#include <arpa/inet.h>
65#include <sys/socket.h>
66#include "../networkconfig.h"
67
68/*
69 *  Number of sessions
70 */
71int session = 0;
72
73/*
74 *  Macro to printf and printk the same arguments
75 */
76
77#define printKF( ... ) \
78  do { \
79    printf( __VA_ARGS__ ); \
80    printk( __VA_ARGS__ ); \
81  } while (0)
82 
83
84/*
85 *  echo shell
86 */
87void echoShell(
88  char *pty_name,
89  void *cmd_arg
90)
91{
92  int cmds = 0;
93  char line[256];
94  char *c;
95  int l;
96
97  ++session;
98  printKF( "Connected to %s with argument %p for session %d\n",
99          pty_name, cmd_arg, session );
100
101  while (1) {
102    cmds++;
103    printf( "> " );
104    c = fgets( line, 256, stdin );
105    if ( !c ) {
106      printKF( "Connection terminated\n");
107      return;
108    }
109    l = strlen( line );
110    if ( line[l-1] == '\n' ) {
111      line[l-1] = '\0';
112    }
113    if ( !strcmp( line, "bye" ) ) {
114      printKF( "%s", "Terminating connection\n");
115      return;
116    }
117    if ( !strcmp( line, "exit" ) ) {
118      printKF("\n\n*** End of Telnetd Server Test ***\n\r" );
119      exit(0);
120    }
121    printKF( "echo %d-%d> %s\n", session, cmds, line );
122  }
123}
124
125/*
126 *  Init task
127 */
128rtems_task Init(
129  rtems_task_argument argument
130)
131{
132  printf("\n\n*** Telnetd Server Test ***\n\r" );
133
134  printf("============== Initializing Network ==============\n");
135  rtems_bsdnet_initialize_network ();
136
137  printf("============== Add Route ==============\n");
138  rtems_bsdnet_show_inet_routes ();
139
140  printf("============== Start Telnetd ==============\n");
141  printk( "Starting echoShell via telnetd -- default password is rtems\n" );
142  rtems_telnetd_initialize(
143    echoShell,                 /* "shell" function */
144    NULL,                      /* no context necessary for echoShell */
145    FALSE,                     /* spawn a new thread */
146    RTEMS_MINIMUM_STACK_SIZE,  /* default stack size please */
147    1                          /* priority .. we feel important today */
148  );
149
150  printf("============== Deleting Init Task ==============\n");
151  rtems_task_delete(RTEMS_SELF);
152}
153
Note: See TracBrowser for help on using the repository browser.