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

4.11network-demos-4-10-branch
Last change on this file since ab15736 was ab15736, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on May 5, 2009 at 1:06:24 PM

Enable shell login checks.

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