1 | /* |
---|
2 | * Copyright (c) 2010-2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * Redistribution and use in source and binary forms, with or without |
---|
11 | * modification, are permitted provided that the following conditions |
---|
12 | * are met: |
---|
13 | * 1. Redistributions of source code must retain the above copyright |
---|
14 | * notice, this list of conditions and the following disclaimer. |
---|
15 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer in the |
---|
17 | * documentation and/or other materials provided with the distribution. |
---|
18 | * |
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
29 | * SUCH DAMAGE. |
---|
30 | */ |
---|
31 | |
---|
32 | #include <sys/param.h> |
---|
33 | |
---|
34 | #include <assert.h> |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <string.h> |
---|
38 | |
---|
39 | #include <rtems/bdbuf.h> |
---|
40 | #include <rtems/console.h> |
---|
41 | #include <rtems/ftpd.h> |
---|
42 | #include <rtems/media.h> |
---|
43 | #include <rtems/shell.h> |
---|
44 | #include <rtems/telnetd.h> |
---|
45 | |
---|
46 | #define TEST_NAME "LIBBSD MEDIA 1" |
---|
47 | |
---|
48 | struct rtems_ftpd_configuration rtems_ftpd_configuration = { |
---|
49 | /* FTPD task priority */ |
---|
50 | .priority = 100, |
---|
51 | |
---|
52 | /* Maximum buffersize for hooks */ |
---|
53 | .max_hook_filesize = 0, |
---|
54 | |
---|
55 | /* Well-known port */ |
---|
56 | .port = 21, |
---|
57 | |
---|
58 | /* List of hooks */ |
---|
59 | .hooks = NULL, |
---|
60 | |
---|
61 | /* Root for FTPD or NULL for "/" */ |
---|
62 | .root = NULL, |
---|
63 | |
---|
64 | /* Max. connections depending on processor count */ |
---|
65 | .tasks_count = 0, |
---|
66 | |
---|
67 | /* Idle timeout in seconds or 0 for no (infinite) timeout */ |
---|
68 | .idle = 5 * 60, |
---|
69 | |
---|
70 | /* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */ |
---|
71 | .access = 0 |
---|
72 | }; |
---|
73 | |
---|
74 | static rtems_status_code |
---|
75 | media_listener(rtems_media_event event, rtems_media_state state, |
---|
76 | const char *src, const char *dest, void *arg) |
---|
77 | { |
---|
78 | if (dest == NULL) { |
---|
79 | dest = "NULL"; |
---|
80 | } |
---|
81 | |
---|
82 | printf( |
---|
83 | "media listener: event = %s, state = %s, src = %s, dest = %s\n", |
---|
84 | rtems_media_event_description(event), |
---|
85 | rtems_media_state_description(state), |
---|
86 | src, |
---|
87 | dest |
---|
88 | ); |
---|
89 | |
---|
90 | if (event == RTEMS_MEDIA_EVENT_MOUNT && state == RTEMS_MEDIA_STATE_SUCCESS) { |
---|
91 | char name[256]; |
---|
92 | int n = snprintf(&name[0], sizeof(name), "%s/test.txt", dest); |
---|
93 | FILE *file; |
---|
94 | |
---|
95 | assert(n < (int) sizeof(name)); |
---|
96 | |
---|
97 | printf("write file %s\n", &name[0]); |
---|
98 | file = fopen(&name[0], "w"); |
---|
99 | if (file != NULL) { |
---|
100 | const char hello[] = "Hello, world!\n"; |
---|
101 | |
---|
102 | fwrite(&hello[0], sizeof(hello) - 1, 1, file); |
---|
103 | fclose(file); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | return RTEMS_SUCCESSFUL; |
---|
108 | } |
---|
109 | |
---|
110 | static void |
---|
111 | telnet_shell(char *name, void *arg) |
---|
112 | { |
---|
113 | rtems_shell_env_t env; |
---|
114 | |
---|
115 | memset(&env, 0, sizeof(env)); |
---|
116 | |
---|
117 | env.devname = name; |
---|
118 | env.taskname = "TLNT"; |
---|
119 | env.login_check = NULL; |
---|
120 | env.forever = false; |
---|
121 | |
---|
122 | rtems_shell_main_loop(&env); |
---|
123 | } |
---|
124 | |
---|
125 | rtems_telnetd_config_table rtems_telnetd_config = { |
---|
126 | .command = telnet_shell, |
---|
127 | .arg = NULL, |
---|
128 | .priority = 0, |
---|
129 | .stack_size = 0, |
---|
130 | .login_check = NULL, |
---|
131 | .keep_stdio = false |
---|
132 | }; |
---|
133 | |
---|
134 | static void |
---|
135 | test_main(void) |
---|
136 | { |
---|
137 | int rv; |
---|
138 | rtems_status_code sc; |
---|
139 | |
---|
140 | rtems_ftpd_configuration.tasks_count = MAX(4, |
---|
141 | rtems_get_processor_count()); |
---|
142 | rv = rtems_initialize_ftpd(); |
---|
143 | assert(rv == 0); |
---|
144 | |
---|
145 | sc = rtems_telnetd_initialize(); |
---|
146 | assert(sc == RTEMS_SUCCESSFUL); |
---|
147 | |
---|
148 | sc = rtems_shell_init("SHLL", 16 * 1024, 1, CONSOLE_DEVICE_NAME, |
---|
149 | false, true, NULL); |
---|
150 | assert(sc == RTEMS_SUCCESSFUL); |
---|
151 | |
---|
152 | exit(0); |
---|
153 | } |
---|
154 | |
---|
155 | #define DEFAULT_EARLY_INITIALIZATION |
---|
156 | |
---|
157 | static void |
---|
158 | early_initialization(void) |
---|
159 | { |
---|
160 | rtems_status_code sc; |
---|
161 | |
---|
162 | sc = rtems_bdbuf_init(); |
---|
163 | assert(sc == RTEMS_SUCCESSFUL); |
---|
164 | |
---|
165 | sc = rtems_media_initialize(); |
---|
166 | assert(sc == RTEMS_SUCCESSFUL); |
---|
167 | |
---|
168 | sc = rtems_media_listener_add(media_listener, NULL); |
---|
169 | assert(sc == RTEMS_SUCCESSFUL); |
---|
170 | |
---|
171 | sc = rtems_media_server_initialize( |
---|
172 | 200, |
---|
173 | 32 * 1024, |
---|
174 | RTEMS_DEFAULT_MODES, |
---|
175 | RTEMS_DEFAULT_ATTRIBUTES |
---|
176 | ); |
---|
177 | assert(sc == RTEMS_SUCCESSFUL); |
---|
178 | } |
---|
179 | |
---|
180 | #define DEFAULT_NETWORK_DHCPCD_ENABLE |
---|
181 | |
---|
182 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
183 | |
---|
184 | #define CONFIGURE_MAXIMUM_DRIVERS 32 |
---|
185 | |
---|
186 | #define CONFIGURE_FILESYSTEM_DOSFS |
---|
187 | |
---|
188 | #define CONFIGURE_MAXIMUM_PROCESSORS 32 |
---|
189 | |
---|
190 | #include <rtems/bsd/test/default-network-init.h> |
---|
191 | |
---|
192 | #define CONFIGURE_SHELL_COMMANDS_INIT |
---|
193 | |
---|
194 | #include <bsp/irq-info.h> |
---|
195 | |
---|
196 | #include <rtems/netcmds-config.h> |
---|
197 | |
---|
198 | #ifdef RTEMS_BSD_MODULE_USR_SBIN_WPA_SUPPLICANT |
---|
199 | #define SHELL_WPA_SUPPLICANT_COMMANDS \ |
---|
200 | &rtems_shell_WPA_SUPPLICANT_Command, \ |
---|
201 | &rtems_shell_WPA_SUPPLICANT_FORK_Command, |
---|
202 | #else |
---|
203 | #define SHELL_WPA_SUPPLICANT_COMMANDS |
---|
204 | #endif |
---|
205 | |
---|
206 | #ifdef RTEMS_BSD_MODULE_NETIPSEC |
---|
207 | #define SHELL_NETIPSEC_COMMANDS \ |
---|
208 | &rtems_shell_RACOON_Command, \ |
---|
209 | &rtems_shell_SETKEY_Command, |
---|
210 | #else |
---|
211 | #define SHELL_NETIPSEC_COMMANDS |
---|
212 | #endif |
---|
213 | |
---|
214 | #define CONFIGURE_SHELL_USER_COMMANDS \ |
---|
215 | SHELL_WPA_SUPPLICANT_COMMANDS \ |
---|
216 | SHELL_NETIPSEC_COMMANDS \ |
---|
217 | &bsp_interrupt_shell_command, \ |
---|
218 | &rtems_shell_ARP_Command, \ |
---|
219 | &rtems_shell_HOSTNAME_Command, \ |
---|
220 | &rtems_shell_PING_Command, \ |
---|
221 | &rtems_shell_ROUTE_Command, \ |
---|
222 | &rtems_shell_NETSTAT_Command, \ |
---|
223 | &rtems_shell_SYSCTL_Command, \ |
---|
224 | &rtems_shell_IFCONFIG_Command, \ |
---|
225 | &rtems_shell_VMSTAT_Command |
---|
226 | |
---|
227 | #define CONFIGURE_SHELL_COMMAND_CPUINFO |
---|
228 | #define CONFIGURE_SHELL_COMMAND_CPUUSE |
---|
229 | #define CONFIGURE_SHELL_COMMAND_PERIODUSE |
---|
230 | #define CONFIGURE_SHELL_COMMAND_STACKUSE |
---|
231 | #define CONFIGURE_SHELL_COMMAND_PROFREPORT |
---|
232 | |
---|
233 | #define CONFIGURE_SHELL_COMMAND_CP |
---|
234 | #define CONFIGURE_SHELL_COMMAND_PWD |
---|
235 | #define CONFIGURE_SHELL_COMMAND_LS |
---|
236 | #define CONFIGURE_SHELL_COMMAND_LN |
---|
237 | #define CONFIGURE_SHELL_COMMAND_LSOF |
---|
238 | #define CONFIGURE_SHELL_COMMAND_CHDIR |
---|
239 | #define CONFIGURE_SHELL_COMMAND_CD |
---|
240 | #define CONFIGURE_SHELL_COMMAND_MKDIR |
---|
241 | #define CONFIGURE_SHELL_COMMAND_RMDIR |
---|
242 | #define CONFIGURE_SHELL_COMMAND_CAT |
---|
243 | #define CONFIGURE_SHELL_COMMAND_MV |
---|
244 | #define CONFIGURE_SHELL_COMMAND_RM |
---|
245 | #define CONFIGURE_SHELL_COMMAND_MALLOC_INFO |
---|
246 | |
---|
247 | #define CONFIGURE_SHELL_COMMAND_FDISK |
---|
248 | #define CONFIGURE_SHELL_COMMAND_BLKSTATS |
---|
249 | #define CONFIGURE_SHELL_COMMAND_BLKSYNC |
---|
250 | #define CONFIGURE_SHELL_COMMAND_MSDOSFMT |
---|
251 | #define CONFIGURE_SHELL_COMMAND_DF |
---|
252 | #define CONFIGURE_SHELL_COMMAND_MOUNT |
---|
253 | #define CONFIGURE_SHELL_COMMAND_UNMOUNT |
---|
254 | #define CONFIGURE_SHELL_COMMAND_MSDOSFMT |
---|
255 | |
---|
256 | #include <rtems/shellconfig.h> |
---|