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 <net/if.h> |
---|
33 | |
---|
34 | #include <assert.h> |
---|
35 | #include <ifaddrs.h> |
---|
36 | #include <stdio.h> |
---|
37 | #include <stdlib.h> |
---|
38 | #include <sysexits.h> |
---|
39 | |
---|
40 | #include <machine/rtems-bsd-commands.h> |
---|
41 | |
---|
42 | #include <rtems.h> |
---|
43 | #include <rtems/stackchk.h> |
---|
44 | #include <rtems/bsd/bsd.h> |
---|
45 | |
---|
46 | #ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
47 | #include <rtems/bsd/test/network-config.h> |
---|
48 | #endif |
---|
49 | |
---|
50 | #ifdef DEFAULT_NETWORK_SHELL |
---|
51 | #include <rtems/console.h> |
---|
52 | #include <rtems/shell.h> |
---|
53 | #endif |
---|
54 | |
---|
55 | static void |
---|
56 | default_network_set_self_prio(rtems_task_priority prio) |
---|
57 | { |
---|
58 | rtems_status_code sc; |
---|
59 | |
---|
60 | sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio); |
---|
61 | assert(sc == RTEMS_SUCCESSFUL); |
---|
62 | } |
---|
63 | |
---|
64 | static void |
---|
65 | default_network_ifconfig_lo0(void) |
---|
66 | { |
---|
67 | int exit_code; |
---|
68 | char *lo0[] = { |
---|
69 | "ifconfig", |
---|
70 | "lo0", |
---|
71 | "inet", |
---|
72 | "127.0.0.1", |
---|
73 | "netmask", |
---|
74 | "255.255.255.0", |
---|
75 | NULL |
---|
76 | }; |
---|
77 | char *lo0_inet6[] = { |
---|
78 | "ifconfig", |
---|
79 | "lo0", |
---|
80 | "inet6", |
---|
81 | "::1", |
---|
82 | "prefixlen", |
---|
83 | "128", |
---|
84 | NULL |
---|
85 | }; |
---|
86 | |
---|
87 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0), lo0); |
---|
88 | assert(exit_code == EX_OK); |
---|
89 | |
---|
90 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0_inet6), lo0_inet6); |
---|
91 | assert(exit_code == EX_OK); |
---|
92 | } |
---|
93 | |
---|
94 | static void |
---|
95 | default_network_ifconfig_hwif0(char *ifname) |
---|
96 | { |
---|
97 | int exit_code; |
---|
98 | char *ifcfg[] = { |
---|
99 | "ifconfig", |
---|
100 | ifname, |
---|
101 | #ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
102 | "up", |
---|
103 | #else |
---|
104 | "inet", |
---|
105 | NET_CFG_SELF_IP, |
---|
106 | "netmask", |
---|
107 | NET_CFG_NETMASK, |
---|
108 | #endif |
---|
109 | NULL |
---|
110 | }; |
---|
111 | |
---|
112 | exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg); |
---|
113 | assert(exit_code == EX_OK); |
---|
114 | } |
---|
115 | |
---|
116 | static void |
---|
117 | default_network_route_hwif0(char *ifname) |
---|
118 | { |
---|
119 | #ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
120 | int exit_code; |
---|
121 | char *dflt_route[] = { |
---|
122 | "route", |
---|
123 | "add", |
---|
124 | "-host", |
---|
125 | NET_CFG_GATEWAY_IP, |
---|
126 | "-iface", |
---|
127 | ifname, |
---|
128 | NULL |
---|
129 | }; |
---|
130 | char *dflt_route2[] = { |
---|
131 | "route", |
---|
132 | "add", |
---|
133 | "default", |
---|
134 | NET_CFG_GATEWAY_IP, |
---|
135 | NULL |
---|
136 | }; |
---|
137 | |
---|
138 | exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route), dflt_route); |
---|
139 | assert(exit_code == EXIT_SUCCESS); |
---|
140 | |
---|
141 | exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route2), dflt_route2); |
---|
142 | assert(exit_code == EXIT_SUCCESS); |
---|
143 | #endif |
---|
144 | } |
---|
145 | |
---|
146 | static void |
---|
147 | default_network_on_exit(int exit_code, void *arg) |
---|
148 | { |
---|
149 | rtems_stack_checker_report_usage_with_plugin(NULL, |
---|
150 | rtems_printf_plugin); |
---|
151 | |
---|
152 | if (exit_code == 0) { |
---|
153 | puts("*** END OF TEST " TEST_NAME " ***"); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | static void |
---|
158 | Init(rtems_task_argument arg) |
---|
159 | { |
---|
160 | rtems_status_code sc; |
---|
161 | #ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
162 | char ifnamebuf[IF_NAMESIZE]; |
---|
163 | #endif |
---|
164 | char *ifname; |
---|
165 | |
---|
166 | puts("*** " TEST_NAME " TEST ***"); |
---|
167 | |
---|
168 | on_exit(default_network_on_exit, NULL); |
---|
169 | |
---|
170 | /* Let other tasks run to complete background work */ |
---|
171 | default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1); |
---|
172 | |
---|
173 | #ifdef DEFAULT_NETWORK_SHELL |
---|
174 | sc = rtems_shell_init( |
---|
175 | "SHLL", |
---|
176 | 32 * 1024, |
---|
177 | 1, |
---|
178 | CONSOLE_DEVICE_NAME, |
---|
179 | false, |
---|
180 | false, |
---|
181 | NULL |
---|
182 | ); |
---|
183 | assert(sc == RTEMS_SUCCESSFUL); |
---|
184 | #endif |
---|
185 | |
---|
186 | rtems_bsd_initialize(); |
---|
187 | |
---|
188 | #ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG |
---|
189 | ifname = if_indextoname(1, &ifnamebuf[0]); |
---|
190 | assert(ifname != NULL); |
---|
191 | #else |
---|
192 | ifname = NET_CFG_INTERFACE_0; |
---|
193 | #endif |
---|
194 | |
---|
195 | /* Let the callout timer allocate its resources */ |
---|
196 | sc = rtems_task_wake_after(2); |
---|
197 | assert(sc == RTEMS_SUCCESSFUL); |
---|
198 | |
---|
199 | default_network_ifconfig_lo0(); |
---|
200 | default_network_ifconfig_hwif0(ifname); |
---|
201 | default_network_route_hwif0(ifname); |
---|
202 | |
---|
203 | test_main(); |
---|
204 | |
---|
205 | assert(0); |
---|
206 | } |
---|
207 | |
---|
208 | #include <machine/rtems-bsd-sysinit.h> |
---|
209 | |
---|
210 | SYSINIT_NEED_NET_PF_UNIX; |
---|
211 | |
---|
212 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
213 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
214 | #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER |
---|
215 | #define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER |
---|
216 | |
---|
217 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
218 | |
---|
219 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 |
---|
220 | |
---|
221 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
222 | |
---|
223 | #define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 32 |
---|
224 | #define CONFIGURE_UNLIMITED_OBJECTS |
---|
225 | #define CONFIGURE_UNIFIED_WORK_AREAS |
---|
226 | |
---|
227 | #define CONFIGURE_STACK_CHECKER_ENABLED |
---|
228 | |
---|
229 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
230 | |
---|
231 | #define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024) |
---|
232 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES |
---|
233 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
234 | |
---|
235 | #define CONFIGURE_INIT |
---|
236 | |
---|
237 | #include <rtems/confdefs.h> |
---|
238 | |
---|
239 | #ifdef DEFAULT_NETWORK_SHELL |
---|
240 | |
---|
241 | #define CONFIGURE_SHELL_COMMANDS_INIT |
---|
242 | |
---|
243 | #include <bsp/irq-info.h> |
---|
244 | |
---|
245 | #include <rtems/netcmds-config.h> |
---|
246 | |
---|
247 | #define CONFIGURE_SHELL_USER_COMMANDS \ |
---|
248 | &bsp_interrupt_shell_command, \ |
---|
249 | &rtems_shell_PING_Command, \ |
---|
250 | &rtems_shell_ROUTE_Command, \ |
---|
251 | &rtems_shell_NETSTAT_Command, \ |
---|
252 | &rtems_shell_IFCONFIG_Command |
---|
253 | |
---|
254 | #define CONFIGURE_SHELL_COMMAND_CPUUSE |
---|
255 | #define CONFIGURE_SHELL_COMMAND_PERIODUSE |
---|
256 | #define CONFIGURE_SHELL_COMMAND_STACKUSE |
---|
257 | |
---|
258 | #define CONFIGURE_SHELL_COMMAND_CP |
---|
259 | #define CONFIGURE_SHELL_COMMAND_PWD |
---|
260 | #define CONFIGURE_SHELL_COMMAND_LS |
---|
261 | #define CONFIGURE_SHELL_COMMAND_LN |
---|
262 | #define CONFIGURE_SHELL_COMMAND_LSOF |
---|
263 | #define CONFIGURE_SHELL_COMMAND_CHDIR |
---|
264 | #define CONFIGURE_SHELL_COMMAND_CD |
---|
265 | #define CONFIGURE_SHELL_COMMAND_MKDIR |
---|
266 | #define CONFIGURE_SHELL_COMMAND_RMDIR |
---|
267 | #define CONFIGURE_SHELL_COMMAND_CAT |
---|
268 | #define CONFIGURE_SHELL_COMMAND_MV |
---|
269 | #define CONFIGURE_SHELL_COMMAND_RM |
---|
270 | #define CONFIGURE_SHELL_COMMAND_MALLOC_INFO |
---|
271 | |
---|
272 | #include <rtems/shellconfig.h> |
---|
273 | |
---|
274 | #endif /* DEFAULT_NETWORK_SHELL */ |
---|