source: rtems-libbsd/testsuite/include/rtems/bsd/test/default-network-init.h @ 0aa7e63

5-freebsd-12
Last change on this file since 0aa7e63 was 0aa7e63, checked in by Sichen Zhao <1473996754@…>, on Oct 12, 2017 at 12:16:08 PM

Add wpa_supplicant command in test suite.

Add wpa supplicant command in media01.

  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*
2 * Copyright (c) 2013-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#include <sys/stat.h>
33#include <sys/socket.h>
34
35#include <net/if.h>
36
37#include <assert.h>
38#include <fcntl.h>
39#include <ifaddrs.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <sysexits.h>
43
44#include <machine/rtems-bsd-commands.h>
45
46#include <rtems.h>
47#include <rtems/printer.h>
48#include <rtems/stackchk.h>
49#include <rtems/bsd/bsd.h>
50
51#if defined(DEFAULT_NETWORK_DHCPCD_ENABLE) && \
52    !defined(DEFAULT_NETWORK_NO_STATIC_IFCONFIG)
53#define DEFAULT_NETWORK_NO_STATIC_IFCONFIG
54#endif
55
56#ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
57#include <rtems/bsd/test/network-config.h>
58#endif
59
60#ifdef DEFAULT_NETWORK_SHELL
61#include <rtems/console.h>
62#include <rtems/shell.h>
63#endif
64
65static void
66default_network_set_self_prio(rtems_task_priority prio)
67{
68        rtems_status_code sc;
69
70        sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio);
71        assert(sc == RTEMS_SUCCESSFUL);
72}
73
74#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
75static void
76default_network_ifconfig_hwif0(char *ifname)
77{
78        int exit_code;
79        char *ifcfg[] = {
80                "ifconfig",
81                ifname,
82#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
83                "up",
84#else
85                "inet",
86                NET_CFG_SELF_IP,
87                "netmask",
88                NET_CFG_NETMASK,
89#endif
90                NULL
91        };
92
93        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg);
94        assert(exit_code == EX_OK);
95}
96
97static void
98default_network_route_hwif0(char *ifname)
99{
100#ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
101        int exit_code;
102        char *dflt_route[] = {
103                "route",
104                "add",
105                "-host",
106                NET_CFG_GATEWAY_IP,
107                "-iface",
108                ifname,
109                NULL
110        };
111        char *dflt_route2[] = {
112                "route",
113                "add",
114                "default",
115                NET_CFG_GATEWAY_IP,
116                NULL
117        };
118
119        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route), dflt_route);
120        assert(exit_code == EXIT_SUCCESS);
121
122        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route2), dflt_route2);
123        assert(exit_code == EXIT_SUCCESS);
124#endif
125}
126#endif
127
128#ifdef DEFAULT_NETWORK_DHCPCD_ENABLE
129static void
130default_network_dhcpcd_task(rtems_task_argument arg)
131{
132        int exit_code;
133        char *dhcpcd[] = {
134                "dhcpcd",
135                NULL
136        };
137
138        (void)arg;
139
140#ifdef DEFAULT_NETWORK_DHCPCD_NO_DHCP_DISCOVERY
141        static const char cfg[] = "nodhcp\nnodhcp6\n";
142        int fd;
143        int rv;
144        ssize_t n;
145
146        fd = open("/etc/dhcpcd.conf", O_CREAT | O_WRONLY,
147            S_IRWXU | S_IRWXG | S_IRWXO);
148        assert(fd >= 0);
149
150        n = write(fd, cfg, sizeof(cfg));
151        assert(n == (ssize_t) sizeof(cfg));
152
153        rv = close(fd);
154        assert(rv == 0);
155#endif
156
157        exit_code = rtems_bsd_command_dhcpcd(RTEMS_BSD_ARGC(dhcpcd), dhcpcd);
158        assert(exit_code == EXIT_SUCCESS);
159}
160#endif
161
162static void
163default_network_dhcpcd(void)
164{
165#ifdef DEFAULT_NETWORK_DHCPCD_ENABLE
166        rtems_status_code sc;
167        rtems_id id;
168
169        sc = rtems_task_create(
170                rtems_build_name('D', 'H', 'C', 'P'),
171                RTEMS_MAXIMUM_PRIORITY - 1,
172                2 * RTEMS_MINIMUM_STACK_SIZE,
173                RTEMS_DEFAULT_MODES,
174                RTEMS_FLOATING_POINT,
175                &id
176        );
177        assert(sc == RTEMS_SUCCESSFUL);
178
179        sc = rtems_task_start(id, default_network_dhcpcd_task, 0);
180        assert(sc == RTEMS_SUCCESSFUL);
181#endif
182}
183
184static void
185default_network_on_exit(int exit_code, void *arg)
186{
187        rtems_printer printer;
188
189        (void)arg;
190
191        rtems_print_printer_printf(&printer);
192        rtems_stack_checker_report_usage_with_plugin(&printer);
193
194        if (exit_code == 0) {
195                puts("*** END OF TEST " TEST_NAME " ***");
196        }
197}
198
199static void
200Init(rtems_task_argument arg)
201{
202        rtems_status_code sc;
203#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
204#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
205        char ifnamebuf[IF_NAMESIZE];
206#endif
207        char *ifname;
208#endif
209
210        /*
211         * Default the syslog priority to 'debug' to aid developers.
212         */
213        rtems_bsd_setlogpriority("debug");
214
215        (void)arg;
216        puts("*** " TEST_NAME " TEST ***");
217
218        on_exit(default_network_on_exit, NULL);
219
220#ifdef DEFAULT_EARLY_INITIALIZATION
221        early_initialization();
222#endif
223
224        /* Let other tasks run to complete background work */
225        default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1U);
226
227#ifdef DEFAULT_NETWORK_SHELL
228        sc = rtems_shell_init(
229                "SHLL",
230                32 * 1024,
231                1,
232                CONSOLE_DEVICE_NAME,
233                false,
234                false,
235                NULL
236        );
237        assert(sc == RTEMS_SUCCESSFUL);
238#endif
239
240        rtems_bsd_initialize();
241
242#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
243#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
244        ifname = if_indextoname(1, &ifnamebuf[0]);
245        assert(ifname != NULL);
246#else
247        ifname = NET_CFG_INTERFACE_0;
248#endif
249#endif
250
251        /* Let the callout timer allocate its resources */
252        sc = rtems_task_wake_after(2);
253        assert(sc == RTEMS_SUCCESSFUL);
254
255        rtems_bsd_ifconfig_lo0();
256#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
257        default_network_ifconfig_hwif0(ifname);
258        default_network_route_hwif0(ifname);
259#endif
260        default_network_dhcpcd();
261
262        test_main();
263
264        assert(0);
265}
266
267/*
268 * Configure LibBSD.
269 */
270
271#if defined(LIBBSP_I386_PC386_BSP_H)
272#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (64 * 1024 * 1024)
273#elif defined(LIBBSP_POWERPC_QORIQ_BSP_H)
274#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (32 * 1024 * 1024)
275#endif
276
277#define RTEMS_BSD_CONFIG_NET_PF_UNIX
278#define RTEMS_BSD_CONFIG_NET_IP_MROUTE
279#define RTEMS_BSD_CONFIG_NET_IP6_MROUTE
280#define RTEMS_BSD_CONFIG_NET_IF_BRIDGE
281#define RTEMS_BSD_CONFIG_NET_IF_LAGG
282#define RTEMS_BSD_CONFIG_NET_IF_VLAN
283#define RTEMS_BSD_CONFIG_BSP_CONFIG
284#define RTEMS_BSD_CONFIG_INIT
285
286#include <machine/rtems-bsd-config.h>
287
288#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
289#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
290#define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
291#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER
292#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
293
294#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
295
296#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
297
298#define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 32
299#define CONFIGURE_UNLIMITED_OBJECTS
300#define CONFIGURE_UNIFIED_WORK_AREAS
301
302#define CONFIGURE_STACK_CHECKER_ENABLED
303
304#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (64 * 1024)
305#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4
306#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024)
307
308#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
309
310#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
311#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
312#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
313
314#define CONFIGURE_INIT
315
316#include <rtems/confdefs.h>
317
318#ifdef DEFAULT_NETWORK_SHELL
319
320#define CONFIGURE_SHELL_COMMANDS_INIT
321
322#include <bsp/irq-info.h>
323
324#include <rtems/netcmds-config.h>
325
326#define CONFIGURE_SHELL_USER_COMMANDS \
327  &bsp_interrupt_shell_command, \
328  &rtems_shell_ARP_Command, \
329  &rtems_shell_HOSTNAME_Command, \
330  &rtems_shell_PING_Command, \
331  &rtems_shell_ROUTE_Command, \
332  &rtems_shell_NETSTAT_Command, \
333  &rtems_shell_IFCONFIG_Command, \
334  &rtems_shell_TCPDUMP_Command, \
335  &rtems_shell_SYSCTL_Command, \
336  &rtems_shell_VMSTAT_Command, \
337  &rtems_shell_WLANSTATS_Command, \
338  &rtems_shell_WPA_SUPPLICANT_Command
339
340#define CONFIGURE_SHELL_COMMAND_CPUINFO
341#define CONFIGURE_SHELL_COMMAND_CPUUSE
342#define CONFIGURE_SHELL_COMMAND_PERIODUSE
343#define CONFIGURE_SHELL_COMMAND_STACKUSE
344#define CONFIGURE_SHELL_COMMAND_PROFREPORT
345
346#define CONFIGURE_SHELL_COMMAND_CP
347#define CONFIGURE_SHELL_COMMAND_PWD
348#define CONFIGURE_SHELL_COMMAND_LS
349#define CONFIGURE_SHELL_COMMAND_LN
350#define CONFIGURE_SHELL_COMMAND_LSOF
351#define CONFIGURE_SHELL_COMMAND_CHDIR
352#define CONFIGURE_SHELL_COMMAND_CD
353#define CONFIGURE_SHELL_COMMAND_MKDIR
354#define CONFIGURE_SHELL_COMMAND_RMDIR
355#define CONFIGURE_SHELL_COMMAND_CAT
356#define CONFIGURE_SHELL_COMMAND_MV
357#define CONFIGURE_SHELL_COMMAND_RM
358#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
359#define CONFIGURE_SHELL_COMMAND_SHUTDOWN
360
361#include <rtems/shellconfig.h>
362
363#endif /* DEFAULT_NETWORK_SHELL */
Note: See TracBrowser for help on using the repository browser.