source: network-demos/telnetd/init.c @ 2da63bc

4.11
Last change on this file since 2da63bc was f3d1d96, checked in by Joel Sherrill <joel.sherrill@…>, on 07/04/10 at 15:52:12

2010-07-04 Joel Sherrill <joel.sherrilL@…>

  • init.c: Remove include of rtems_webserver.h.
  • Property mode set to 100644
File size: 5.2 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 USE_RTEMS_SHELL
9
10#include <bsp.h>
11
12#include <errno.h>
13#include <time.h>
14
15#include <stdio.h>
16#include <rtems/rtems_bsdnet.h>
17#include <rtems/telnetd.h>
18#include <rtems/shell.h>
19
20#include <rtems/error.h>
21#include <rpc/rpc.h>
22#include <netinet/in.h>
23#include <time.h>
24
25#include <arpa/inet.h>
26#include <sys/socket.h>
27#include "../networkconfig.h"
28
29/*
30 *  If true, listen on socket(s).
31 *  If false, remain on console.
32 */
33/* #define REMAIN_ON_CONSOLE */
34bool remain_on_console = false;
35
36#if defined(USE_ECHO_SHELL)
37
38#define SHELL_HELP_MSG \
39  "Starting echoShell via telnetd -- default password is rtems\n"
40
41/*
42 *  Number of sessions
43 */
44int session = 0;
45
46/*
47 *  Macro to printf and printk the same arguments
48 */
49
50#define printKF( ... ) \
51  do { \
52    printf( __VA_ARGS__ ); \
53    printk( __VA_ARGS__ ); \
54  } while (0)
55 
56
57/*
58 *  echo shell
59 */
60void echoShell(
61  char *pty_name,
62  void *cmd_arg
63)
64{
65  int cmds = 0;
66  char line[256];
67  char *c;
68  int l;
69
70  ++session;
71  printKF( "Connected to %s with argument %p for session %d\n",
72          pty_name, cmd_arg, session );
73
74  while (1) {
75    cmds++;
76    printf( "> " );
77    c = fgets( line, 256, stdin );
78    if ( !c ) {
79      printKF( "Connection terminated\n");
80      return;
81    }
82    l = strlen( line );
83    if ( line[l-1] == '\n' ) {
84      line[l-1] = '\0';
85    }
86    if ( !strcmp( line, "bye" ) ) {
87      printKF( "%s", "Terminating connection\n");
88      return;
89    }
90    if ( !strcmp( line, "exit" ) ) {
91      printKF("\n\n*** End of Telnetd Server Test ***\n\r" );
92      exit(0);
93    }
94    printKF( "echo %d-%d> %s\n", session, cmds, line );
95  }
96}
97
98#define SHELL_ENTRY echoShell
99
100#endif
101
102#if defined(USE_RTEMS_SHELL)
103
104#include <rtems/shell.h>
105
106#define SHELL_HELP_MSG \
107  "Starting rtemsShell via telnetd -- default account is rtems w/no password\n"
108
109#define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
110#define CONFIGURE_SHELL_COMMANDS_ALL
111#define CONFIGURE_SHELL_MOUNT_MSDOS
112
113#define CONFIGURE_SHELL_COMMANDS_INIT
114#include <rtems/shellconfig.h>
115
116
117static void rtemsShell(
118  char *pty_name,
119  void *cmd_arg
120)
121{
122  rtems_shell_env_t env = rtems_global_shell_env;
123 
124  env.devname = pty_name;
125  env.taskname = "TLNT";
126  env.login_check = rtems_shell_login_check;
127
128  if ( !remain_on_console )
129    printk("============== Starting Shell ==============\n");
130
131  rtems_shell_main_loop( &env );
132
133  if ( !remain_on_console )
134    printk("============== Exiting Shell ==============\n");
135}
136
137#define SHELL_ENTRY rtemsShell
138
139/*
140 *  Telnet demon configuration
141 */
142rtems_telnetd_config_table rtems_telnetd_config = {
143  .command = SHELL_ENTRY,
144  .arg = NULL,
145  .priority = 1, /* We feel important today */
146  .stack_size = 20 * RTEMS_MINIMUM_STACK_SIZE, /* Shell needs a large stack */
147  .login_check = NULL, /* Shell asks for user and password */
148  .keep_stdio = false
149};
150
151#endif
152
153/*
154 *  Init task
155 */
156rtems_task Init(
157  rtems_task_argument argument
158)
159{
160  fprintf(stderr, "\n\n*** Telnetd Server Test ***\n\r" );
161
162  fprintf(stderr, "============== Initializing Network ==============\n");
163  rtems_bsdnet_initialize_network ();
164
165  fprintf(stderr, "============== Add Route ==============\n");
166  rtems_bsdnet_show_inet_routes ();
167
168  fprintf(stderr, "============== Start Telnetd ==============\n");
169
170  printk( SHELL_HELP_MSG );
171
172  #if defined(REMAIN_ON_CONSOLE)
173    remain_on_console = true;
174  #endif
175
176  rtems_global_shell_env.login_check = rtems_shell_login_check;
177  rtems_telnetd_config.keep_stdio = remain_on_console;
178 
179  rtems_telnetd_initialize();
180
181  if ( !remain_on_console )
182    fprintf(stderr, "============== Deleting Init Task ==============\n");
183  rtems_task_delete(RTEMS_SELF);
184}
185
186/*
187 * Configuration parameters
188 */
189
190#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
191#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
192/*
193#ifdef RTEMS_BSP_HAS_IDE_DRIVER
194#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
195#endif
196*/
197#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
198
199#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
200
201#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS        20
202#define CONFIGURE_MAXIMUM_PTYS                          8
203
204#if defined(USE_RTEMS_SHELL)
205  #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
206#endif
207#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
208
209#define CONFIGURE_STACK_CHECKER_ENABLED
210
211#define CONFIGURE_MEMORY_OVERHEAD         256
212#define CONFIGURE_MESSAGE_BUFFER_MEMORY   (32 * 1024)
213#define CONFIGURE_MAXIMUM_SEMAPHORES      40
214#define CONFIGURE_MAXIMUM_TASKS           20
215#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES  20
216
217#define CONFIGURE_MICROSECONDS_PER_TICK 1000
218
219#define CONFIGURE_INIT_TASK_STACK_SIZE  (64*1024)
220#define CONFIGURE_INIT_TASK_PRIORITY    120
221#define CONFIGURE_INIT_TASK_ATTRIBUTES    RTEMS_FLOATING_POINT
222#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
223                                           RTEMS_NO_TIMESLICE | \
224                                           RTEMS_NO_ASR | \
225                                           RTEMS_INTERRUPT_LEVEL(0))
226
227#define CONFIGURE_MAXIMUM_DRIVERS 10
228#define CONFIGURE_INIT
229
230#include <stdlib.h>
231#include <rtems.h>
232#include <rtems/telnetd.h>
233
234/* functions */
235
236rtems_task Init(
237  rtems_task_argument argument
238);
239
240/* configuration information */
241
242#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.