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