1 | /* |
---|
2 | * Copyright (c) 2014, 2018 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 | /* |
---|
33 | * To test PPP connect the RTEMS target with your host. Start PPP on the host |
---|
34 | * with something like this: |
---|
35 | * |
---|
36 | * pppd nodetach noauth 192.168.100.11:192.168.100.70 proxyarp 115200 dump \ |
---|
37 | * local nocrtscts debug mtu 296 mru 296 nolock ms-dns 192.168.96.1 novj \ |
---|
38 | * /dev/ttyS0 |
---|
39 | * |
---|
40 | * Make sure IP forwarding is enabled and check the firewall settings if you |
---|
41 | * want to access the internet. |
---|
42 | */ |
---|
43 | |
---|
44 | #include <assert.h> |
---|
45 | #include <stdlib.h> |
---|
46 | #include <sys/stat.h> |
---|
47 | #include <fcntl.h> |
---|
48 | #include <termios.h> |
---|
49 | #include <string.h> |
---|
50 | #include <stdio.h> |
---|
51 | #include <sysexits.h> |
---|
52 | |
---|
53 | #include <machine/rtems-bsd-commands.h> |
---|
54 | |
---|
55 | #include <rtems.h> |
---|
56 | #include <rtems/bsd/bsd.h> |
---|
57 | #include <rtems/telnetd.h> |
---|
58 | #include <rtems/ftpd.h> |
---|
59 | #include <rtems/rtemspppd.h> |
---|
60 | |
---|
61 | #define TEST_NAME "LIBBSD PPP 1" |
---|
62 | |
---|
63 | #ifndef RTEMS_SMP |
---|
64 | |
---|
65 | static void |
---|
66 | set_pppd_options(void) |
---|
67 | { |
---|
68 | int rv; |
---|
69 | |
---|
70 | rv = rtems_pppd_set_option("/dev/ttyS1", NULL); |
---|
71 | assert(rv == 1); |
---|
72 | |
---|
73 | rv = rtems_pppd_set_option("115200", NULL); |
---|
74 | assert(rv == 1); |
---|
75 | |
---|
76 | rv = rtems_pppd_set_option("crtscts", NULL); |
---|
77 | assert(rv == 1); |
---|
78 | |
---|
79 | rv = rtems_pppd_set_option("debug", NULL); |
---|
80 | assert(rv == 1); |
---|
81 | |
---|
82 | rv = rtems_pppd_set_option("defaultroute", NULL); |
---|
83 | assert(rv == 1); |
---|
84 | |
---|
85 | rv = rtems_pppd_set_option("local", NULL); |
---|
86 | assert(rv == 1); |
---|
87 | |
---|
88 | rv = rtems_pppd_set_option("noauth", NULL); |
---|
89 | assert(rv == 1); |
---|
90 | |
---|
91 | rv = rtems_pppd_set_option("noipdefault", NULL); |
---|
92 | assert(rv == 1); |
---|
93 | |
---|
94 | rv = rtems_pppd_set_option("usepeerdns", NULL); |
---|
95 | assert(rv == 1); |
---|
96 | |
---|
97 | rv = rtems_pppd_set_option("password", "wurst"); |
---|
98 | assert(rv == 1); |
---|
99 | |
---|
100 | rv = rtems_pppd_set_option("user", "hans"); |
---|
101 | assert(rv == 1); |
---|
102 | |
---|
103 | rv = rtems_pppd_set_option("mru", "296"); |
---|
104 | assert(rv == 1); |
---|
105 | |
---|
106 | rv = rtems_pppd_set_option("mtu", "296"); |
---|
107 | assert(rv == 1); |
---|
108 | |
---|
109 | rv = rtems_pppd_set_option("lcp-echo-failure", "5"); |
---|
110 | assert(rv == 1); |
---|
111 | |
---|
112 | rv = rtems_pppd_set_option("lcp-echo-interval", "5"); |
---|
113 | assert(rv == 1); |
---|
114 | } |
---|
115 | |
---|
116 | static void |
---|
117 | linkup_hook(void) |
---|
118 | { |
---|
119 | printf("linkup hook\n"); |
---|
120 | } |
---|
121 | |
---|
122 | static void |
---|
123 | linkdown_hook(void) |
---|
124 | { |
---|
125 | printf("linkdown hook\n"); |
---|
126 | } |
---|
127 | |
---|
128 | static void |
---|
129 | ipup_hook(void) |
---|
130 | { |
---|
131 | static bool first = true; |
---|
132 | |
---|
133 | printf("ipup hook\n"); |
---|
134 | |
---|
135 | if (first) { |
---|
136 | int rv; |
---|
137 | rtems_status_code sc; |
---|
138 | |
---|
139 | first = false; |
---|
140 | |
---|
141 | sc = rtems_telnetd_initialize(); |
---|
142 | assert(sc == RTEMS_SUCCESSFUL); |
---|
143 | |
---|
144 | rv = rtems_initialize_ftpd(); |
---|
145 | assert(rv == 0); |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | static void |
---|
150 | ipdown_hook(void) |
---|
151 | { |
---|
152 | printf("ipdown hook\n"); |
---|
153 | } |
---|
154 | |
---|
155 | static void |
---|
156 | exit_hook(void) |
---|
157 | { |
---|
158 | printf("exit hook\n"); |
---|
159 | } |
---|
160 | |
---|
161 | static void |
---|
162 | error_hook(void) |
---|
163 | { |
---|
164 | printf("error hook\n"); |
---|
165 | } |
---|
166 | |
---|
167 | static void |
---|
168 | set_pppd_hooks(void) |
---|
169 | { |
---|
170 | int rv; |
---|
171 | |
---|
172 | rv = rtems_pppd_set_hook(RTEMS_PPPD_LINKUP_HOOK, linkup_hook); |
---|
173 | assert(rv == 0); |
---|
174 | |
---|
175 | rv = rtems_pppd_set_hook(RTEMS_PPPD_LINKDOWN_HOOK, linkdown_hook); |
---|
176 | assert(rv == 0); |
---|
177 | |
---|
178 | rv = rtems_pppd_set_hook(RTEMS_PPPD_IPUP_HOOK, ipup_hook); |
---|
179 | assert(rv == 0); |
---|
180 | |
---|
181 | rv = rtems_pppd_set_hook(RTEMS_PPPD_IPDOWN_HOOK, ipdown_hook); |
---|
182 | assert(rv == 0); |
---|
183 | |
---|
184 | rv = rtems_pppd_set_hook(RTEMS_PPPD_EXIT_HOOK, exit_hook); |
---|
185 | assert(rv == 0); |
---|
186 | |
---|
187 | rv = rtems_pppd_set_hook(RTEMS_PPPD_ERROR_HOOK, error_hook); |
---|
188 | assert(rv == 0); |
---|
189 | } |
---|
190 | |
---|
191 | static void |
---|
192 | ifconfig_ppp0(void) |
---|
193 | { |
---|
194 | int exit_code; |
---|
195 | char *ifcfg[] = { |
---|
196 | "ifconfig", |
---|
197 | "ppp0", |
---|
198 | "up", |
---|
199 | NULL |
---|
200 | }; |
---|
201 | |
---|
202 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg); |
---|
203 | assert(exit_code == EX_OK); |
---|
204 | } |
---|
205 | |
---|
206 | static void |
---|
207 | telnet_shell(char *name, void *arg) |
---|
208 | { |
---|
209 | rtems_shell_env_t env; |
---|
210 | |
---|
211 | memset(&env, 0, sizeof(env)); |
---|
212 | |
---|
213 | env.devname = name; |
---|
214 | env.taskname = "TLNT"; |
---|
215 | env.login_check = NULL; |
---|
216 | env.forever = false; |
---|
217 | |
---|
218 | rtems_shell_main_loop(&env); |
---|
219 | } |
---|
220 | |
---|
221 | rtems_telnetd_config_table rtems_telnetd_config = { |
---|
222 | .command = telnet_shell, |
---|
223 | .arg = NULL, |
---|
224 | .priority = 0, |
---|
225 | .stack_size = 0, |
---|
226 | .login_check = NULL, |
---|
227 | .keep_stdio = false |
---|
228 | }; |
---|
229 | |
---|
230 | struct rtems_ftpd_configuration rtems_ftpd_configuration = { |
---|
231 | /* FTPD task priority */ |
---|
232 | .priority = 100, |
---|
233 | |
---|
234 | /* Maximum buffersize for hooks */ |
---|
235 | .max_hook_filesize = 0, |
---|
236 | |
---|
237 | /* Well-known port */ |
---|
238 | .port = 21, |
---|
239 | |
---|
240 | /* List of hooks */ |
---|
241 | .hooks = NULL, |
---|
242 | |
---|
243 | /* Root for FTPD or NULL for "/" */ |
---|
244 | .root = NULL, |
---|
245 | |
---|
246 | /* Max. connections */ |
---|
247 | .tasks_count = 4, |
---|
248 | |
---|
249 | /* Idle timeout in seconds or 0 for no (infinite) timeout */ |
---|
250 | .idle = 5 * 60, |
---|
251 | |
---|
252 | /* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */ |
---|
253 | .access = 0 |
---|
254 | }; |
---|
255 | |
---|
256 | static void |
---|
257 | test_main(void) |
---|
258 | { |
---|
259 | int rv; |
---|
260 | |
---|
261 | ifconfig_ppp0(); |
---|
262 | |
---|
263 | rv = rtems_pppd_initialize(); |
---|
264 | assert(rv == 0); |
---|
265 | |
---|
266 | set_pppd_options(); |
---|
267 | set_pppd_hooks(); |
---|
268 | |
---|
269 | rv = rtems_pppd_connect(); |
---|
270 | assert(rv == 0); |
---|
271 | |
---|
272 | rtems_task_delete(RTEMS_SELF); |
---|
273 | assert(0); |
---|
274 | } |
---|
275 | |
---|
276 | RTEMS_BSD_DEFINE_NEXUS_DEVICE(ppp, 0, 0, NULL); |
---|
277 | |
---|
278 | #else /* RTEMS_SMP */ |
---|
279 | |
---|
280 | static void |
---|
281 | test_main(void) |
---|
282 | { |
---|
283 | printf("PPP is not support on SMP configurations"); |
---|
284 | exit(0); |
---|
285 | } |
---|
286 | |
---|
287 | #endif /* RTEMS_SMP */ |
---|
288 | |
---|
289 | #define CONFIGURE_MAXIMUM_DRIVERS 32 |
---|
290 | |
---|
291 | #define DEFAULT_NETWORK_SHELL |
---|
292 | #define DEFAULT_NETWORK_DHCPCD_ENABLE |
---|
293 | #define DEFAULT_NETWORK_NO_INTERFACE_0 |
---|
294 | |
---|
295 | #include <rtems/bsd/test/default-network-init.h> |
---|