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

4.11network-demos-4-10-branchnetwork-demos-4-9-branch
Last change on this file since be2fc3e was be2fc3e, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 5, 2008 at 9:46:27 PM

2008-02-05 Joel Sherrill <joel.sherrill@…>

  • init.c: Now works.
  • Property mode set to 100644
File size: 4.4 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 STACK_CHECKER_ON
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
159void rtemsShell(
160  char *pty_name,
161  void *cmd_arg
162)
163{
164  printk("============== Starting Shell ==============\n");
165  rtems_shell_main_loop( NULL ); 
166  printk("============== Exiting Shell ==============\n");
167}
168
169#define SHELL_ENTRY rtemsShell
170
171#endif
172
173/*
174 *  Init task
175 */
176rtems_task Init(
177  rtems_task_argument argument
178)
179{
180  printf("\n\n*** Telnetd Server Test ***\n\r" );
181
182  printf("============== Initializing Network ==============\n");
183  rtems_bsdnet_initialize_network ();
184
185  printf("============== Add Route ==============\n");
186  rtems_bsdnet_show_inet_routes ();
187
188  printf("============== Start Telnetd ==============\n");
189
190  printk( SHELL_HELP_MSG );
191
192  rtems_telnetd_initialize(
193    SHELL_ENTRY,               /* "shell" function */
194    NULL,                      /* no context necessary for echoShell */
195    FALSE,                     /* spawn a new thread */
196    RTEMS_MINIMUM_STACK_SIZE * 20,  /* shell needs a large stack */
197    1,                         /* priority .. we feel important today */
198    0                          /* do not ask for password */
199  ); 
200
201  printf("============== Deleting Init Task ==============\n");
202  rtems_task_delete(RTEMS_SELF);
203}
204
Note: See TracBrowser for help on using the repository browser.