summaryrefslogtreecommitdiffstats
path: root/testsuite/ppp01/test_main.c
blob: 078e96e2bf7f02d906389494ead9dc0853a73923 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
 * @file
 *
 * To test PPP connect the RTEMS target with your host.  Start PPP on the host
 * with something like this:
 *
 * pppd nodetach noauth 192.168.100.11:192.168.100.70 proxyarp 115200 dump \
 *   local nocrtscts debug mtu 296 mru 296 nolock ms-dns 192.168.96.1 novj \
 *   /dev/ttyS0
 *
 * Make sure IP forwarding is enabled and check the firewall settings if you
 * want to access the internet.
 */

/*
 * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <assert.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <stdio.h>
#include <sysexits.h>

#include <machine/rtems-bsd-commands.h>

#include <rtems.h>
#include <rtems/bsd/bsd.h>
#include <rtems/telnetd.h>
#include <rtems/ftpd.h>
#include <rtems/rtemspppd.h>

#define TEST_NAME "LIBBSD PPP 1"
#define TEST_STATE_USER_INPUT 1

#ifndef RTEMS_SMP

static void
set_pppd_options(void)
{
	int rv;

	rv = rtems_pppd_set_option("/dev/ttyS1", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("115200", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("crtscts", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("debug", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("defaultroute", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("local", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("noauth", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("noipdefault", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("usepeerdns", NULL);
	assert(rv == 1);

	rv = rtems_pppd_set_option("password", "wurst");
	assert(rv == 1);

	rv = rtems_pppd_set_option("user", "hans");
	assert(rv == 1);

	rv = rtems_pppd_set_option("mru", "296");
	assert(rv == 1);

	rv = rtems_pppd_set_option("mtu", "296");
	assert(rv == 1);

	rv = rtems_pppd_set_option("lcp-echo-failure", "5");
	assert(rv == 1);

	rv = rtems_pppd_set_option("lcp-echo-interval", "5");
	assert(rv == 1);
}

static void
linkup_hook(void)
{
	printf("linkup hook\n");
}

static void
linkdown_hook(void)
{
	printf("linkdown hook\n");
}

static void
ipup_hook(void)
{
	static bool first = true;

	printf("ipup hook\n");

	if (first) {
		int rv;
		rtems_status_code sc;

		first = false;

		sc = rtems_telnetd_initialize();
		assert(sc == RTEMS_SUCCESSFUL);

		rv = rtems_initialize_ftpd();
		assert(rv == 0);
	}
}

static void
ipdown_hook(void)
{
	printf("ipdown hook\n");
}

static void
exit_hook(void)
{
	printf("exit hook\n");
}

static void
error_hook(void)
{
	printf("error hook\n");
}

static void
set_pppd_hooks(void)
{
	int rv;

	rv = rtems_pppd_set_hook(RTEMS_PPPD_LINKUP_HOOK, linkup_hook);
	assert(rv == 0);

	rv = rtems_pppd_set_hook(RTEMS_PPPD_LINKDOWN_HOOK, linkdown_hook);
	assert(rv == 0);

	rv = rtems_pppd_set_hook(RTEMS_PPPD_IPUP_HOOK, ipup_hook);
	assert(rv == 0);

	rv = rtems_pppd_set_hook(RTEMS_PPPD_IPDOWN_HOOK, ipdown_hook);
	assert(rv == 0);

	rv = rtems_pppd_set_hook(RTEMS_PPPD_EXIT_HOOK, exit_hook);
	assert(rv == 0);

	rv = rtems_pppd_set_hook(RTEMS_PPPD_ERROR_HOOK, error_hook);
	assert(rv == 0);
}

static void
ifconfig_ppp0(void)
{
	int exit_code;
	char *ifcfg[] = {
		"ifconfig",
		"ppp0",
		"up",
		NULL
	};

	exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg);
	assert(exit_code == EX_OK);
}

static void
telnet_shell(char *name, void *arg)
{
	rtems_shell_env_t env;

	memset(&env, 0, sizeof(env));

	env.devname = name;
	env.taskname = "TLNT";
	env.login_check = NULL;
	env.forever = false;

	rtems_shell_main_loop(&env);
}

rtems_telnetd_config_table rtems_telnetd_config = {
	.command = telnet_shell,
	.arg = NULL,
	.priority = 0,
	.stack_size = 0,
	.login_check = NULL,
	.keep_stdio = false
};

struct rtems_ftpd_configuration rtems_ftpd_configuration = {
	/* FTPD task priority */
	.priority = 100,

	/* Maximum buffersize for hooks */
	.max_hook_filesize = 0,

	/* Well-known port */
	.port = 21,

	/* List of hooks */
	.hooks = NULL,

	/* Root for FTPD or NULL for "/" */
	.root = NULL,

	/* Max. connections */
	.tasks_count = 4,

	/* Idle timeout in seconds  or 0 for no (infinite) timeout */
	.idle = 5 * 60,

	/* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */
	.access = 0
};

static void
test_main(void)
{
	int rv;

	ifconfig_ppp0();

	rv = rtems_pppd_initialize();
	assert(rv == 0);

	set_pppd_options();
	set_pppd_hooks();

	rv = rtems_pppd_connect();
	assert(rv == 0);

	rtems_task_delete(RTEMS_SELF);
	assert(0);
}

RTEMS_BSD_DEFINE_NEXUS_DEVICE(ppp, 0, 0, NULL);

#else /* RTEMS_SMP */

static void
test_main(void)
{
	printf("PPP is not support on SMP configurations");
	exit(0);
}

#endif /* RTEMS_SMP */

#define CONFIGURE_MAXIMUM_DRIVERS 32

#define DEFAULT_NETWORK_SHELL
#define DEFAULT_NETWORK_DHCPCD_ENABLE
#define DEFAULT_NETWORK_NO_INTERFACE_0

#include <rtems/bsd/test/default-network-init.h>