source: rtems-libbsd/testsuite/ppp01/test_main.c @ 06d8316

5-freebsd-12freebsd-9.3
Last change on this file since 06d8316 was 06d8316, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 12, 2015 at 12:16:25 PM

testsuite/ppp01: Avoid build error on SMP

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