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