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