source: network-demos/telnetd/init.c @ 52ce8e2

4.11network-demos-4-10-branchnetwork-demos-4-9-branch
Last change on this file since 52ce8e2 was 52ce8e2, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 19, 2007 at 2:37:06 PM

2007-12-19 Joel Sherrill <joel.sherrill@…>

  • init.c: Shell now has some commands that require filesystems with bdbuf support.
  • Property mode set to 100644
File size: 4.3 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#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
17
18#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS        20
19#define CONFIGURE_MAXIMUM_PTYS                          8
20
21#if defined(USE_RTEMS_SHELL)
22  #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
23#endif
24#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
25
26#define STACK_CHECKER_ON
27
28#define CONFIGURE_MEMORY_OVERHEAD         256
29#define CONFIGURE_MESSAGE_BUFFER_MEMORY   (32 * 1024)
30#define CONFIGURE_MAXIMUM_SEMAPHORES      40
31#define CONFIGURE_MAXIMUM_TASKS           20
32#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES  20
33
34#define CONFIGURE_MICROSECONDS_PER_TICK 1000
35
36#define CONFIGURE_INIT_TASK_STACK_SIZE  (64*1024)
37#define CONFIGURE_INIT_TASK_PRIORITY    120
38#define CONFIGURE_INIT_TASK_ATTRIBUTES    RTEMS_FLOATING_POINT
39#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
40                                           RTEMS_NO_TIMESLICE | \
41                                           RTEMS_NO_ASR | \
42                                           RTEMS_INTERRUPT_LEVEL(0))
43
44#define CONFIGURE_MAXIMUM_DRIVERS 10
45#define CONFIGURE_INIT
46
47#include <stdlib.h>
48#include <rtems.h>
49#include <rtems/telnetd.h>
50
51/* functions */
52
53rtems_task Init(
54  rtems_task_argument argument
55);
56
57/* configuration information */
58
59#include <rtems/confdefs.h>
60#include <bsp.h>
61
62#include <errno.h>
63#include <time.h>
64
65#include <rtems/confdefs.h>
66#include <stdio.h>
67#include <rtems/rtems_bsdnet.h>
68#include <rtems/telnetd.h>
69#include <rtems/shell.h>
70
71     
72#include <rtems/error.h>
73#include <rpc/rpc.h>
74#include <netinet/in.h>
75#include <time.h>
76
77#include <arpa/inet.h>
78#include <sys/socket.h>
79#include "../networkconfig.h"
80
81#if defined(USE_ECHO_SHELL)
82
83#define SHELL_HELP_MSG \
84  "Starting echoShell via telnetd -- default password is rtems\n"
85
86/*
87 *  Number of sessions
88 */
89int session = 0;
90
91/*
92 *  Macro to printf and printk the same arguments
93 */
94
95#define printKF( ... ) \
96  do { \
97    printf( __VA_ARGS__ ); \
98    printk( __VA_ARGS__ ); \
99  } while (0)
100 
101
102/*
103 *  echo shell
104 */
105void echoShell(
106  char *pty_name,
107  void *cmd_arg
108)
109{
110  int cmds = 0;
111  char line[256];
112  char *c;
113  int l;
114
115  ++session;
116  printKF( "Connected to %s with argument %p for session %d\n",
117          pty_name, cmd_arg, session );
118
119  while (1) {
120    cmds++;
121    printf( "> " );
122    c = fgets( line, 256, stdin );
123    if ( !c ) {
124      printKF( "Connection terminated\n");
125      return;
126    }
127    l = strlen( line );
128    if ( line[l-1] == '\n' ) {
129      line[l-1] = '\0';
130    }
131    if ( !strcmp( line, "bye" ) ) {
132      printKF( "%s", "Terminating connection\n");
133      return;
134    }
135    if ( !strcmp( line, "exit" ) ) {
136      printKF("\n\n*** End of Telnetd Server Test ***\n\r" );
137      exit(0);
138    }
139    printKF( "echo %d-%d> %s\n", session, cmds, line );
140  }
141}
142
143#define SHELL_ENTRY echoShell
144
145#endif
146
147#if defined(USE_RTEMS_SHELL)
148
149#include <rtems/shell.h>
150
151#define SHELL_HELP_MSG \
152  "Starting rtemsShell via telnetd -- default account is rtems w/no password\n"
153
154void rtemsShell(
155  char *pty_name,
156  void *cmd_arg
157)
158{
159  printk("============== Starting Shell ==============\n");
160  rtems_shell_main_loop( NULL ); 
161  printk("============== Exiting Shell ==============\n");
162}
163
164#define SHELL_ENTRY rtemsShell
165
166#endif
167
168/*
169 *  Init task
170 */
171rtems_task Init(
172  rtems_task_argument argument
173)
174{
175  printf("\n\n*** Telnetd Server Test ***\n\r" );
176
177  printf("============== Initializing Network ==============\n");
178  rtems_bsdnet_initialize_network ();
179
180  printf("============== Add Route ==============\n");
181  rtems_bsdnet_show_inet_routes ();
182
183  printf("============== Start Telnetd ==============\n");
184
185  printk( SHELL_HELP_MSG );
186
187  rtems_telnetd_initialize(
188    SHELL_ENTRY,               /* "shell" function */
189    NULL,                      /* no context necessary for echoShell */
190    FALSE,                     /* spawn a new thread */
191    RTEMS_MINIMUM_STACK_SIZE * 4,  /* default stack size please */
192    1,                         /* priority .. we feel important today */
193    0                          /* do not ask for password */
194  ); 
195
196  printf("============== Deleting Init Task ==============\n");
197  rtems_task_delete(RTEMS_SELF);
198}
199
Note: See TracBrowser for help on using the repository browser.