source: network-demos/telnetd/init.c @ 09fc233

4.11network-demos-4-10-branch
Last change on this file since 09fc233 was 09fc233, checked in by Joel Sherrill <joel.sherrill@…>, on 09/17/08 at 19:31:51

2008-09-17 Joel Sherrill <joel.sherrill@…>

  • init.c: Rename STACK_CHECKER_ON to more appropriate CONFIGURE_STACK_CHECKER_ENABLED.
  • Property mode set to 100644
File size: 4.6 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#if defined(USE_ECHO_SHELL)
87
88#define SHELL_HELP_MSG \
89  "Starting echoShell via telnetd -- default password is rtems\n"
90
91/*
92 *  Number of sessions
93 */
94int session = 0;
95
96/*
97 *  Macro to printf and printk the same arguments
98 */
99
100#define printKF( ... ) \
101  do { \
102    printf( __VA_ARGS__ ); \
103    printk( __VA_ARGS__ ); \
104  } while (0)
105 
106
107/*
108 *  echo shell
109 */
110void echoShell(
111  char *pty_name,
112  void *cmd_arg
113)
114{
115  int cmds = 0;
116  char line[256];
117  char *c;
118  int l;
119
120  ++session;
121  printKF( "Connected to %s with argument %p for session %d\n",
122          pty_name, cmd_arg, session );
123
124  while (1) {
125    cmds++;
126    printf( "> " );
127    c = fgets( line, 256, stdin );
128    if ( !c ) {
129      printKF( "Connection terminated\n");
130      return;
131    }
132    l = strlen( line );
133    if ( line[l-1] == '\n' ) {
134      line[l-1] = '\0';
135    }
136    if ( !strcmp( line, "bye" ) ) {
137      printKF( "%s", "Terminating connection\n");
138      return;
139    }
140    if ( !strcmp( line, "exit" ) ) {
141      printKF("\n\n*** End of Telnetd Server Test ***\n\r" );
142      exit(0);
143    }
144    printKF( "echo %d-%d> %s\n", session, cmds, line );
145  }
146}
147
148#define SHELL_ENTRY echoShell
149
150#endif
151
152#if defined(USE_RTEMS_SHELL)
153
154#include <rtems/shell.h>
155
156#define SHELL_HELP_MSG \
157  "Starting rtemsShell via telnetd -- default account is rtems w/no password\n"
158
159#define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
160#define CONFIGURE_SHELL_COMMANDS_ALL
161
162#define CONFIGURE_SHELL_COMMANDS_INIT
163#include <rtems/shellconfig.h>
164
165
166void rtemsShell(
167  char *pty_name,
168  void *cmd_arg
169)
170{
171  printk("============== Starting Shell ==============\n");
172  rtems_shell_main_loop( NULL );
173  printk("============== Exiting Shell ==============\n");
174}
175
176#define SHELL_ENTRY rtemsShell
177
178#endif
179
180/*
181 *  Init task
182 */
183rtems_task Init(
184  rtems_task_argument argument
185)
186{
187  printf("\n\n*** Telnetd Server Test ***\n\r" );
188
189  printf("============== Initializing Network ==============\n");
190  rtems_bsdnet_initialize_network ();
191
192  printf("============== Add Route ==============\n");
193  rtems_bsdnet_show_inet_routes ();
194
195  printf("============== Start Telnetd ==============\n");
196
197  printk( SHELL_HELP_MSG );
198
199  rtems_telnetd_initialize(
200    SHELL_ENTRY,               /* "shell" function */
201    NULL,                      /* no context necessary for echoShell */
202    FALSE,                     /* spawn a new thread */
203    RTEMS_MINIMUM_STACK_SIZE * 20,  /* shell needs a large stack */
204    1,                         /* priority .. we feel important today */
205    0                          /* do not ask for password */
206  );
207
208  printf("============== Deleting Init Task ==============\n");
209  rtems_task_delete(RTEMS_SELF);
210}
211
Note: See TracBrowser for help on using the repository browser.