source: network-demos/telnetd/init.c @ 84b2a48

4.11network-demos-4-10-branchnetwork-demos-4-9-branch
Last change on this file since 84b2a48 was 84b2a48, checked in by Joel Sherrill <joel.sherrill@…>, on 11/09/07 at 21:39:43

2007-11-09 Joel Sherrill <joel.sherrill@…>

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